Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schemadiff: DROP COLUMN not eligible for INSTANT algorithm if covered by an index #15714

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading