Skip to content

Commit

Permalink
sql/schemachanger: Remove feature gate for ALTER COLUMN TYPE
Browse files Browse the repository at this point in the history
Previously, altering a column’s type requiring a backfill required the
enable_experimental_alter_column_type_general setting to be enabled.
This restriction has been removed, as full support for ALTER COLUMN TYPE
has been implemented in the Declarative Schema Changer (DSC).

The setting is still checked in mixed-version clusters, as the operation
relies on 25.1 dependency rules, and when using the legacy schema
changer.

Epic: CRDB-25314
Informs cockroachdb#49329
Release note (sql change): Altering a column’s type no longer requires
enabling the enable_experimental_alter_column_type_general setting. This
change makes the feature generally available.
  • Loading branch information
spilchen committed Nov 22, 2024
1 parent feec8b9 commit 1c84fb7
Show file tree
Hide file tree
Showing 51 changed files with 23 additions and 67 deletions.
3 changes: 3 additions & 0 deletions pkg/ccl/logictestccl/testdata/logic_test/refcursor
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ SELECT * FROM xy;
statement ok
DROP TABLE IF EXISTS xy;
CREATE TABLE xy (x INT, y TEXT);

onlyif config local-legacy-schema-changer local-mixed-24.2 local-mixed-24.3
statement ok
SET enable_experimental_alter_column_type_general=true;

statement ok
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/logictest/testdata/logic_test/alter_column_type
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ CREATE TABLE t1 (date string)
statement ok
INSERT INTO t1 VALUES ('2024-07-26')

onlyif config local-mixed-24.2 local-mixed-24.3
statement error pq: ALTER COLUMN TYPE from string to date is only supported experimentally
ALTER TABLE t1 ALTER COLUMN date TYPE DATE USING date::DATE

Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/drop_type
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
statement ok
SET sql_safe_updates = false;

onlyif config local-legacy-schema-changer local-mixed-24.2 local-mixed-24.3
statement ok
SET enable_experimental_alter_column_type_general = true;

# Basic test -- create and drop a type.
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/logictest/testdata/logic_test/enums
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ statement error pq: foreign key violation: "enum_origin" row x='hello' has no ma
ALTER TABLE enum_origin ADD FOREIGN KEY (x) REFERENCES enum_referenced (x)

# Tests for ALTER COLUMN SET DATA TYPE.
onlyif config local-legacy-schema-changer local-mixed-24.2 local-mixed-24.3
statement ok
SET enable_experimental_alter_column_type_general = true;

Expand Down
6 changes: 0 additions & 6 deletions pkg/sql/logictest/testdata/logic_test/row_level_ttl
Original file line number Diff line number Diff line change
Expand Up @@ -909,15 +909,9 @@ ALTER TABLE tbl_alter_table_ttl_expiration_expression DROP COLUMN expire_at
statement ok
SET use_declarative_schema_changer = 'on'

statement ok
SET enable_experimental_alter_column_type_general = 'on'

statement error cannot alter type of column "expire_at" referenced by row-level TTL expiration expression "expire_at"\nHINT: use ALTER TABLE .*
ALTER TABLE tbl_alter_table_ttl_expiration_expression ALTER expire_at TYPE TIMESTAMP USING (expire_at AT TIME ZONE 'UTC')

statement ok
SET enable_experimental_alter_column_type_general = 'off'

query T
SELECT create_statement FROM [SHOW CREATE TABLE tbl_alter_table_ttl_expiration_expression]
----
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/logictest/testdata/logic_test/show_create
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ c CREATE TABLE public.c (

subtest alter_column_type_not_break_show_create

onlyif config local-legacy-schema-changer local-mixed-24.2 local-mixed-24.3
statement ok
SET enable_experimental_alter_column_type_general = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ CREATE TABLE t5(a int primary key, b int);
statement ok
SET CLUSTER SETTING jobs.debug.pausepoints = 'schemachanger.before.exec,newschemachanger.before.exec';

onlyif config local-legacy-schema-changer local-mixed-24.2 local-mixed-24.3
statement ok
SET enable_experimental_alter_column_type_general = true;

Expand Down
1 change: 1 addition & 0 deletions pkg/sql/logictest/testdata/logic_test/udf_schema_change
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ SELECT f_rtbl();
----
(1,foobar,2)

onlyif config local-legacy-schema-changer local-mixed-24.2 local-mixed-24.3
statement ok
SET enable_experimental_alter_column_type_general=true

Expand Down
10 changes: 0 additions & 10 deletions pkg/sql/pgwire/testdata/pgtest/row_description
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,6 @@ ReadyForQuery
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
{"Type":"ReadyForQuery","TxStatus":"I"}

send crdb_only
Query {"String": "SET enable_experimental_alter_column_type_general = true"}
----

until crdb_only
ReadyForQuery
----
{"Type":"CommandComplete","CommandTag":"SET"}
{"Type":"ReadyForQuery","TxStatus":"I"}

send crdb_only
Query {"String": "ALTER TABLE tab3 ALTER COLUMN b TYPE STRING"}
----
Expand Down
2 changes: 0 additions & 2 deletions pkg/sql/schemachanger/dml_injection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ func TestAlterTableDMLInjection(t *testing.T) {
{
desc: "alter column type general",
setup: []string{
"SET enable_experimental_alter_column_type_general=TRUE",
"ALTER TABLE tbl ADD COLUMN new_col BIGINT NOT NULL DEFAULT 100",
},
schemaChange: "ALTER TABLE tbl ALTER COLUMN new_col SET DATA TYPE TEXT",
Expand All @@ -191,7 +190,6 @@ func TestAlterTableDMLInjection(t *testing.T) {
{
desc: "alter column type general compute",
setup: []string{
"SET enable_experimental_alter_column_type_general=TRUE",
"ALTER TABLE tbl ADD COLUMN new_col DATE NOT NULL DEFAULT '2013-05-06', " +
"ADD COLUMN new_comp DATE AS (new_col) STORED",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,11 @@ func updateColumnType(b BuildCtx, oldColType, newColType *scpb.ColumnType) {
b.Add(newColType)
}

// failIfExperimentalSettingNotSet checks if the setting that allows altering
// types is enabled. If the setting is not enabled, this function will panic.
// failIfExperimentalSettingNotSet checks if the current version requires a
// setting to be enabled to perform an ALTER COLUMN TYPE operation.
func failIfExperimentalSettingNotSet(b BuildCtx, oldColType, newColType *scpb.ColumnType) {
if !b.SessionData().AlterColumnTypeGeneralEnabled {
if !b.SessionData().AlterColumnTypeGeneralEnabled &&
!b.EvalCtx().Settings.Version.ActiveVersion(b).IsActive(clusterversion.V25_1) {
panic(pgerror.WithCandidateCode(
errors.WithHint(
errors.WithIssueLink(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ CREATE TABLE defaultdb.act (
k INT PRIMARY KEY,
c1 INT4
);
SET enable_experimental_alter_column_type_general=TRUE;
----

ops
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
setup
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');
----

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');

/* test */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');

/* test */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');
----
...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');

/* test */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');

/* test */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');

/* test */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');

/* test */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');

/* test */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');

/* test */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');

/* test */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');

/* test */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');

/* test */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');

/* test */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');

/* test */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');

/* test */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');

/* test */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');

/* test */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* setup */
CREATE TABLE t (i INT PRIMARY KEY, j TEXT);
SET enable_experimental_alter_column_type_general=TRUE;
INSERT INTO t VALUES (1,NULL),(2,'1'),(3,'2');

/* test */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
setup
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);
----
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);
----
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* setup */
SET enable_experimental_alter_column_type_general=TRUE;
CREATE TABLE t (i INT PRIMARY KEY, j INT DEFAULT 99 ON UPDATE -1);
INSERT INTO t VALUES (1,NULL),(2,1),(3,2);

Expand Down
Loading

0 comments on commit 1c84fb7

Please sign in to comment.