Skip to content

Commit

Permalink
schemadiff: DROP COLUMN not eligible for INSTANT algorithm if c…
Browse files Browse the repository at this point in the history
…overed by an index (#15714)

Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach authored Apr 15, 2024
1 parent cc6b5a6 commit 113b975
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions go/vt/schemadiff/capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ func alterOptionCapableOfInstantDDL(alterOption sqlparser.AlterOption, createTab
}
return nil
}
findIndexCoveringColumn := func(colName string) *sqlparser.IndexDefinition {
for _, index := range createTable.TableSpec.Indexes {
for _, col := range index.Columns {
if col.Column.String() == colName {
return index
}
}
}
return nil
}
findTableOption := func(optName string) *sqlparser.TableOption {
if createTable == nil {
return nil
Expand Down Expand Up @@ -90,6 +100,10 @@ func alterOptionCapableOfInstantDDL(alterOption sqlparser.AlterOption, createTab
return false, nil
}
}
if findIndexCoveringColumn(opt.Name.Name.String()) != nil {
// not supported if the column is part of an index
return false, nil
}
if isVirtualColumn(opt.Name.Name.String()) {
// supported by all 8.0 versions
return capableOf(capabilities.InstantAddDropVirtualColumnFlavorCapability)
Expand Down
12 changes: 12 additions & 0 deletions go/vt/schemadiff/capability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ func TestAlterTableCapableOfInstantDDL(t *testing.T) {
alter: "alter table t drop column i1",
expectCapableOfInstantDDL: false,
},
{
name: "drop column fail due to index",
create: "create table t(id int, i1 int not null, i2 int not null, primary key(id), key i1_idx (i1))",
alter: "alter table t drop column i1",
expectCapableOfInstantDDL: false,
},
{
name: "drop column fail due to multicolumn index",
create: "create table t(id int, i1 int not null, i2 int not null, primary key(id), key i21_idx (i2, i1))",
alter: "alter table t drop column i1",
expectCapableOfInstantDDL: false,
},
{
name: "add two columns",
create: "create table t(id int, i1 int not null, primary key(id))",
Expand Down

0 comments on commit 113b975

Please sign in to comment.