Skip to content

Commit

Permalink
schemadiff INSTANT DDL: impossible changes on tables with `FULLTEXT…
Browse files Browse the repository at this point in the history
…` index (#15725)

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
  • Loading branch information
shlomi-noach committed May 1, 2024
1 parent 1c4cd97 commit 2066acc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
33 changes: 29 additions & 4 deletions go/vt/schemadiff/capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import (
// alterOptionAvailableViaInstantDDL checks if the specific alter option is eligible to run via ALGORITHM=INSTANT
// reference: https://dev.mysql.com/doc/refman/8.0/en/innodb-online-ddl-operations.html
func alterOptionCapableOfInstantDDL(alterOption sqlparser.AlterOption, createTable *sqlparser.CreateTable, capableOf capabilities.CapableOf) (bool, error) {
// A table with FULLTEXT index won't support adding/removing columns instantly.
tableHasFulltextIndex := false
for _, key := range createTable.TableSpec.Indexes {
if key.Info.Type == sqlparser.IndexTypeFullText {
tableHasFulltextIndex = true
break
}
}
findColumn := func(colName string) *sqlparser.ColumnDefinition {
if createTable == nil {
return nil
Expand Down Expand Up @@ -42,6 +50,13 @@ func alterOptionCapableOfInstantDDL(alterOption sqlparser.AlterOption, createTab
}
return nil
}
tableIsCompressed := false
if opt := findTableOption("ROW_FORMAT"); opt != nil {
if strings.EqualFold(opt.String, "COMPRESSED") {
tableIsCompressed = true
}
}

isVirtualColumn := func(colName string) bool {
col := findColumn(colName)
if col == nil {
Expand Down Expand Up @@ -87,18 +102,28 @@ func alterOptionCapableOfInstantDDL(alterOption sqlparser.AlterOption, createTab
// in another table. Which is a bit too much to compute here.
return false, nil
case *sqlparser.AddColumns:
if tableHasFulltextIndex {
// not supported if the table has a FULLTEXT index
return false, nil
}
// Not supported in COMPRESSED tables
if tableIsCompressed {
return false, nil
}
if opt.First || opt.After != nil {
// not a "last" column. Only supported as of 8.0.29
return capableOf(capabilities.InstantAddDropColumnFlavorCapability)
}
// Adding a *last* column is supported in 8.0
return capableOf(capabilities.InstantAddLastColumnFlavorCapability)
case *sqlparser.DropColumn:
if tableHasFulltextIndex {
// not supported if the table has a FULLTEXT index
return false, nil
}
// Not supported in COMPRESSED tables
if opt := findTableOption("ROW_FORMAT"); opt != nil {
if strings.EqualFold(opt.String, "COMPRESSED") {
return false, nil
}
if tableIsCompressed {
return false, nil
}
if findIndexCoveringColumn(opt.Name.Name.String()) != nil {
// not supported if the column is part of an index
Expand Down
24 changes: 24 additions & 0 deletions go/vt/schemadiff/capability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ func TestAlterTableCapableOfInstantDDL(t *testing.T) {
capableOf: incapableOf,
expectCapableOfInstantDDL: false,
},
{
name: "add column fails on COMPRESSED tables",
create: "create table t1 (id int, i1 int) row_format=compressed",
alter: "alter table t1 add column i2 int",
expectCapableOfInstantDDL: false,
},
{
name: "add column fails on table with FULLTEXT index",
create: "create table t(id int, name varchar(128), primary key(id), fulltext key (name))",
alter: "alter table t1 add column i2 int",
expectCapableOfInstantDDL: false,
},
{
name: "drop virtual column",
create: "create table t(id int, i1 int not null, i2 int generated always as (i1 + 1) virtual, primary key(id))",
Expand Down Expand Up @@ -97,6 +109,12 @@ func TestAlterTableCapableOfInstantDDL(t *testing.T) {
alter: "alter table t drop column i1",
expectCapableOfInstantDDL: false,
},
{
name: "drop column fail due to fulltext index in table",
create: "create table t(id int, i1 int not null, name varchar(128), primary key(id), fulltext key (name))",
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 All @@ -122,6 +140,12 @@ func TestAlterTableCapableOfInstantDDL(t *testing.T) {
alter: "alter table t modify column i1 int not null default 3",
expectCapableOfInstantDDL: true,
},
{
name: "change a default column value on a table with FULLTEXT index",
create: "create table t(id int, i1 int not null, name varchar(128), primary key(id), fulltext key (name))",
alter: "alter table t modify column i1 int not null default 3",
expectCapableOfInstantDDL: true,
},
{
name: "change default column value to null",
create: "create table t(id int, i1 int not null, primary key(id))",
Expand Down

0 comments on commit 2066acc

Please sign in to comment.