Skip to content

Commit

Permalink
schemadiff: INSTANT support for setting a column VISIBLE/INVISIBLE
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 Jul 30, 2024
1 parent fab9071 commit f61bde0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
13 changes: 8 additions & 5 deletions go/vt/schemadiff/capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func alterOptionCapableOfInstantDDL(alterOption sqlparser.AlterOption, createTab
}
return true, col.Type.Options.Storage
}
colStringStrippedDown := func(col *sqlparser.ColumnDefinition, stripDefault bool, stripEnum bool) string {
colStringStrippedDown := func(col *sqlparser.ColumnDefinition, stripDefault bool, stripEnum bool, stripVisibility bool) string {
strippedCol := sqlparser.Clone(col)
if stripDefault {
strippedCol.Type.Options.Default = nil
Expand All @@ -82,6 +82,9 @@ func alterOptionCapableOfInstantDDL(alterOption sqlparser.AlterOption, createTab
if stripEnum {
strippedCol.Type.EnumValues = nil
}
if stripVisibility {
strippedCol.Type.Options.Invisible = nil
}
return sqlparser.CanonicalString(strippedCol)
}
hasPrefix := func(vals []string, prefix []string) bool {
Expand Down Expand Up @@ -164,8 +167,8 @@ func alterOptionCapableOfInstantDDL(alterOption sqlparser.AlterOption, createTab
// table and ALTER statement, and compare the columns: if they're otherwise equal,
// then the only change can be an addition/change/removal of DEFAULT, which
// is instant-table.
tableColDefinition := colStringStrippedDown(col, true, false)
newColDefinition := colStringStrippedDown(opt.NewColDefinition, true, false)
tableColDefinition := colStringStrippedDown(col, true, false, true)
newColDefinition := colStringStrippedDown(opt.NewColDefinition, true, false, true)
if tableColDefinition == newColDefinition {
return capableOf(capabilities.InstantChangeColumnDefaultFlavorCapability)
}
Expand Down Expand Up @@ -194,8 +197,8 @@ func alterOptionCapableOfInstantDDL(alterOption sqlparser.AlterOption, createTab
}
}
// Now don't care about change of default:
tableColDefinition := colStringStrippedDown(col, true, true)
newColDefinition := colStringStrippedDown(opt.NewColDefinition, true, true)
tableColDefinition := colStringStrippedDown(col, true, true, true)
newColDefinition := colStringStrippedDown(opt.NewColDefinition, true, true, true)
if tableColDefinition == newColDefinition {
return capableOf(capabilities.InstantExpandEnumCapability)
}
Expand Down
18 changes: 18 additions & 0 deletions go/vt/schemadiff/capability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,24 @@ func TestAlterTableCapableOfInstantDDL(t *testing.T) {
alter: "alter table t modify column c1 set('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i')",
expectCapableOfInstantDDL: false,
},
{
name: "make a column invisible",
create: "create table t1 (id int, i1 int)",
alter: "alter table t1 modify column i1 int invisible",
expectCapableOfInstantDDL: true,
},
{
name: "make a column visible",
create: "create table t1 (id int, i1 int)",
alter: "alter table t1 change column i1 i1 int visible",
expectCapableOfInstantDDL: true,
},
{
name: "make a column invisible via SET, unsupported",
create: "create table t1 (id int, i1 int)",
alter: "alter table t1 alter column i1 set invisible",
expectCapableOfInstantDDL: false,
},
}
for _, tcase := range tcases {
t.Run(tcase.name, func(t *testing.T) {
Expand Down

0 comments on commit f61bde0

Please sign in to comment.