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: ALTER TABLE is not INSTANT-able if adding column with default expression value #16028

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
4 changes: 4 additions & 0 deletions go/vt/schemadiff/capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func alterOptionCapableOfInstantDDL(alterOption sqlparser.AlterOption, createTab
return false, nil
}
}
if column.Type.Options.Default != nil && !column.Type.Options.DefaultLiteral {
// Expression default values are not supported
return false, nil
}
}
if opt.First || opt.After != nil {
// not a "last" column. Only supported as of 8.0.29
Expand Down
36 changes: 36 additions & 0 deletions go/vt/schemadiff/capability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,42 @@ func TestAlterTableCapableOfInstantDDL(t *testing.T) {
alter: "alter table t1 add column i2 int",
expectCapableOfInstantDDL: false,
},
{
name: "add column with default value",
create: "create table t1 (id int, i1 int)",
alter: "alter table t1 add column i2 int not null default 17",
expectCapableOfInstantDDL: true,
},
{
name: "add column with expression default value",
create: "create table t1 (id int, i1 int)",
alter: "alter table t1 add column i2 int not null default (17)",
expectCapableOfInstantDDL: false,
},
{
name: "add column with complex expression default value",
create: "create table t1 (id int, i1 int)",
alter: "alter table t1 add column i2 int not null default ((17+2))",
expectCapableOfInstantDDL: false,
},
{
name: "add varchar column with default literal value",
create: "create table t1 (id int, i1 int)",
alter: "alter table t1 add column v2 varchar(10) not null default '17'",
expectCapableOfInstantDDL: true,
},
{
name: "add varchar column with default expression value",
create: "create table t1 (id int, i1 int)",
alter: "alter table t1 add column v2 varchar(10) not null default ('17')",
expectCapableOfInstantDDL: false,
},
{
name: "add varchar column with default expression null value",
create: "create table t1 (id int, i1 int)",
alter: "alter table t1 add column v2 varchar(10) not null default (null)",
expectCapableOfInstantDDL: false,
},
{
name: "add columns max capacity",
create: `create table t(i1 int, i2 int, i3 int, i4 int, i5 int, i6 int, i7 int, i8 int, i9 int, i10 int, i11 int, i12 int, i13 int, i14 int, i15 int, i16 int, i17 int, i18 int, i19 int, i20 int, i21 int, i22 int, i23 int, i24 int, i25 int, i26 int, i27 int, i28 int, i29 int, i30 int, i31 int, i32 int, i33 int, i34 int, i35 int, i36 int, i37 int, i38 int, i39 int, i40 int, i41 int, i42 int, i43 int, i44 int, i45 int, i46 int, i47 int, i48 int, i49 int, i50 int, i51 int, i52 int, i53 int, i54 int, i55 int, i56 int, i57 int, i58 int, i59 int, i60 int, i61 int, i62 int, i63 int, i64 int, i65 int, i66 int, i67 int, i68 int, i69 int, i70 int, i71 int, i72 int, i73 int, i74 int, i75 int, i76 int, i77 int, i78 int, i79 int, i80 int, i81 int, i82 int, i83 int, i84 int, i85 int, i86 int, i87 int, i88 int, i89 int, i90 int, i91 int, i92 int, i93 int, i94 int, i95 int, i96 int, i97 int, i98 int, i99 int, i100 int, i101 int, i102 int, i103 int, i104 int, i105 int, i106 int, i107 int, i108 int, i109 int, i110 int, i111 int, i112 int, i113 int, i114 int, i115 int, i116 int, i117 int, i118 int, i119 int, i120 int, i121 int, i122 int, i123 int, i124 int, i125 int, i126 int, i127 int, i128 int, i129 int, i130 int, i131 int, i132 int, i133 int, i134 int, i135 int, i136 int, i137 int, i138 int, i139 int, i140 int, i141 int, i142 int, i143 int, i144 int, i145 int, i146 int, i147 int, i148 int, i149 int, i150 int, i151 int, i152 int, i153 int, i154 int, i155 int, i156 int, i157 int, i158 int, i159 int, i160 int, i161 int, i162 int, i163 int, i164 int, i165 int, i166 int, i167 int, i168 int, i169 int, i170 int, i171 int, i172 int, i173 int, i174 int, i175 int, i176 int, i177 int, i178 int, i179 int, i180 int, i181 int, i182 int, i183 int, i184 int, i185 int, i186 int, i187 int, i188 int, i189 int, i190 int, i191 int, i192 int, i193 int, i194 int, i195 int, i196 int, i197 int, i198 int, i199 int, i200 int,
Expand Down
Loading