Skip to content

Commit

Permalink
schemadiff: DROP COLUMN not eligible for INSTANT if covered by an index
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
  • Loading branch information
shlomi-noach committed Apr 15, 2024
1 parent f118ba2 commit 282947f
Show file tree
Hide file tree
Showing 2 changed files with 20 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
6 changes: 6 additions & 0 deletions go/vt/schemadiff/capability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ 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: "add two columns",
create: "create table t(id int, i1 int not null, primary key(id))",
Expand Down

0 comments on commit 282947f

Please sign in to comment.