From 0da2cfb6ddeb2634412fd05371f13ba08d2e1961 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Thu, 30 May 2024 07:54:49 +0300 Subject: [PATCH] schemadiff: ALTER TABLE is not INSTANT-able if adding column with default expression value Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/vt/schemadiff/capability.go | 4 ++++ go/vt/schemadiff/capability_test.go | 36 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/go/vt/schemadiff/capability.go b/go/vt/schemadiff/capability.go index ad93e40838f..9ce985c71d9 100644 --- a/go/vt/schemadiff/capability.go +++ b/go/vt/schemadiff/capability.go @@ -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 diff --git a/go/vt/schemadiff/capability_test.go b/go/vt/schemadiff/capability_test.go index 39134ea7a8a..ca3387bb1a7 100644 --- a/go/vt/schemadiff/capability_test.go +++ b/go/vt/schemadiff/capability_test.go @@ -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,