From 1133a0e490b5f98cba8ed9e1e2696caa2973cf61 Mon Sep 17 00:00:00 2001 From: Xiang Gu Date: Wed, 7 Sep 2022 16:24:41 -0400 Subject: [PATCH] scbuildstmt: fix `ADD COLUMN` minimal supported version Previously, the minimal supported version for stmt `ADD COLUMN` in the new schema changer was incorrectly labeled as v22.1, but this stmt was not fully supported and we added much functionality to it in v22.2. It was incompatible with the version gating elements commit (e.g. in a mixed version state, if we want to use new schema changer for an `ADD COLUMN` but the element `IndexColumn` was excluded due to the gating, then we will run into issues). This PR changes the minimal supported version of `ADD COLUMN` to v22.2. Release justification: bug fix Release note: None --- .../logictest/testdata/logic_test/new_schema_changer_mixed | 6 +++--- .../scbuild/internal/scbuildstmt/alter_table.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/new_schema_changer_mixed b/pkg/sql/logictest/testdata/logic_test/new_schema_changer_mixed index 7785d61e731a..1673e8f1d4d3 100644 --- a/pkg/sql/logictest/testdata/logic_test/new_schema_changer_mixed +++ b/pkg/sql/logictest/testdata/logic_test/new_schema_changer_mixed @@ -24,6 +24,9 @@ statement ok SET use_declarative_schema_changer = unsafe_always; # Verify that DDL stmts only supported in v22.2 will cause a panic. +statement error pq: \*tree\.AlterTable not implemented in the new schema changer +ALTER TABLE testdb.testsc.t ADD COLUMN j INT NOT NULL DEFAULT 30; + statement error pq: \*tree\.AlterTable not implemented in the new schema changer ALTER TABLE testdb.testsc.t DROP COLUMN j; @@ -61,9 +64,6 @@ statement error pq: \*tree\.DropIndex not implemented in the new schema changer DROP INDEX testdb.testsc.t@idx # Verify that DDL stmts supported in v22.1 will succeed. -statement ok -ALTER TABLE testdb.testsc.t ADD COLUMN j INT NOT NULL DEFAULT 30; - statement ok DROP TYPE testdb.testsc.typ; diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table.go index 61abef4987b0..fb6ead021d4e 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table.go @@ -47,7 +47,7 @@ type supportedAlterTableCommand struct { // declarative schema changer. Operations marked as non-fully supported can // only be with the use_declarative_schema_changer session variable. var supportedAlterTableStatements = map[reflect.Type]supportedAlterTableCommand{ - reflect.TypeOf((*tree.AlterTableAddColumn)(nil)): {fn: alterTableAddColumn, on: true, minSupportedClusterVersion: clusterversion.V22_1}, + reflect.TypeOf((*tree.AlterTableAddColumn)(nil)): {fn: alterTableAddColumn, on: true, minSupportedClusterVersion: clusterversion.Start22_2}, reflect.TypeOf((*tree.AlterTableDropColumn)(nil)): {fn: alterTableDropColumn, on: true, minSupportedClusterVersion: clusterversion.Start22_2}, reflect.TypeOf((*tree.AlterTableAlterPrimaryKey)(nil)): {fn: alterTableAlterPrimaryKey, on: true, minSupportedClusterVersion: clusterversion.Start22_2}, reflect.TypeOf((*tree.AlterTableAddConstraint)(nil)): {fn: alterTableAddConstraint, on: true, extraChecks: func(