Skip to content

Commit

Permalink
schemadiff: INSTANT algorithm not supported for CHANGE COLUMN and MOD…
Browse files Browse the repository at this point in the history
…IFY COLUMN which specify FIRST or AFTER

Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach committed Aug 29, 2024
1 parent e785c32 commit facaf5d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions go/vt/schemadiff/capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ func alterOptionCapableOfInstantDDL(alterOption sqlparser.AlterOption, createTab
}
return capableOf(capabilities.InstantAddDropColumnFlavorCapability)
case *sqlparser.ChangeColumn:
if opt.First || opt.After != nil {
return false, nil
}
// We do not support INSTANT for renaming a column (ALTER TABLE ...CHANGE) because:
// 1. We discourage column rename
// 2. We do not produce CHANGE statements in declarative diff
Expand All @@ -198,6 +201,9 @@ func alterOptionCapableOfInstantDDL(alterOption sqlparser.AlterOption, createTab
}
return false, nil
case *sqlparser.ModifyColumn:
if opt.First || opt.After != nil {
return false, nil
}
if col := findColumn(opt.NewColDefinition.Name.String()); col != nil {
return changeModifyColumnCapableOfInstantDDL(col, opt.NewColDefinition)
}
Expand Down
26 changes: 25 additions & 1 deletion go/vt/schemadiff/capability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,23 @@ func TestAlterTableCapableOfInstantDDL(t *testing.T) {
expectCapableOfInstantDDL: false,
},
{
name: "set column dfault value to null",
name: "set column default value to null",
create: "create table t(id int, i1 int, primary key(id))",
alter: "alter table t modify column i1 int default null",
expectCapableOfInstantDDL: true,
},
{
name: "rearrange column after",
create: "create table t(id int, i1 int, i2 int, primary key(id))",
alter: "alter table t modify column i1 int after i2",
expectCapableOfInstantDDL: false,
},
{
name: "rearrange column first",
create: "create table t(id int, i1 int, i2 int, primary key(id))",
alter: "alter table t modify column i1 int first",
expectCapableOfInstantDDL: false,
},
// enum/set:
{
name: "change enum default value",
Expand Down Expand Up @@ -291,6 +303,18 @@ func TestAlterTableCapableOfInstantDDL(t *testing.T) {
alter: "alter table t1 change column i1 i2 int visible",
expectCapableOfInstantDDL: false,
},
{
name: "change column, first",
create: "create table t1 (id int, i1 int, i2 int)",
alter: "alter table t1 change column i1 i1 int first",
expectCapableOfInstantDDL: false,
},
{
name: "change column, after",
create: "create table t1 (id int, i1 int, i2 int)",
alter: "alter table t1 change column i1 i1 int after i2",
expectCapableOfInstantDDL: false,
},
{
name: "make a column invisible via SET",
create: "create table t1 (id int, i1 int)",
Expand Down

0 comments on commit facaf5d

Please sign in to comment.