From e0bc0caf3b63135ac7bd2f601bc06bfcc39aa9ca Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Wed, 8 Jan 2025 15:53:43 +0200 Subject: [PATCH] schemadiff: more index expression validations Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- .../onlineddl/revert/onlineddl_revert_test.go | 5 +++++ go/vt/schemadiff/onlineddl_test.go | 5 +++++ go/vt/schemadiff/table_test.go | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/go/test/endtoend/onlineddl/revert/onlineddl_revert_test.go b/go/test/endtoend/onlineddl/revert/onlineddl_revert_test.go index a13077ef87b..e052762cd13 100644 --- a/go/test/endtoend/onlineddl/revert/onlineddl_revert_test.go +++ b/go/test/endtoend/onlineddl/revert/onlineddl_revert_test.go @@ -259,6 +259,11 @@ func testRevertible(t *testing.T) { toSchema: `id int primary key, i2 int default null`, removedUniqueKeyNames: `i1_uidx`, }, + { + name: "removed expression unique key, skipped", + fromSchema: `id int primary key, i1 int default null, unique key idx1 ((id + 1))`, + toSchema: `id int primary key, i2 int default null`, + }, { name: "expanding unique key removes unique constraint", fromSchema: `id int primary key, i1 int default null, unique key i1_uidx(i1)`, diff --git a/go/vt/schemadiff/onlineddl_test.go b/go/vt/schemadiff/onlineddl_test.go index f5309b4f943..fb8710f8498 100644 --- a/go/vt/schemadiff/onlineddl_test.go +++ b/go/vt/schemadiff/onlineddl_test.go @@ -937,6 +937,11 @@ func TestRevertible(t *testing.T) { fromSchema: "id int, primary key (id), key idx1 ((id + 1))", toSchema: "id int, primary key (id), key idx2 ((id + 2))", }, + { + name: "remove unique index with expression, add another, skip both", + fromSchema: "id int, i int, primary key (id), unique key idx1 ((id + 1))", + toSchema: "id int, i int, primary key (id), unique key idx2 ((i + 2))", + }, } var ( diff --git a/go/vt/schemadiff/table_test.go b/go/vt/schemadiff/table_test.go index ac871dbd4af..c1d8d8c241e 100644 --- a/go/vt/schemadiff/table_test.go +++ b/go/vt/schemadiff/table_test.go @@ -2582,6 +2582,24 @@ func TestValidate(t *testing.T) { alter: "alter table t add key idx2 ((id + 2))", to: "create table t (id int, primary key (id), key idx1 ((id + 1)), key idx2 ((id + 2)))", }, + { + name: "key with multicolumn expression", + from: "create table t (id int, i int, primary key (id), key idx1 ((id + 1), (i + 2)))", + alter: "alter table t add key idx2 ((id + 2))", + to: "create table t (id int, i int, primary key (id), key idx1 ((id + 1), (i + 2)), key idx2 ((id + 2)))", + }, + { + name: "key with expression and unknown columns", + from: "create table t (id int, i int, primary key (id), key idx1 ((id + 1), (i + 2)))", + alter: "alter table t add key idx2 ((i2 + 2))", + expectErr: &InvalidColumnInKeyError{Table: "t", Column: "i2", Key: "idx2"}, + }, + { + name: "drop column used in expression", + from: "create table t (id int, i int, primary key (id), key idx1 ((id + 1), (i + 2)))", + alter: "alter table t drop column i", + expectErr: &InvalidColumnInKeyError{Table: "t", Column: "i", Key: "idx1"}, + }, // partitions { name: "drop column used by partitions",