From e0acbf2476a6d8b3c488dbc2b4797fa4e211e7eb Mon Sep 17 00:00:00 2001 From: tangenta Date: Thu, 7 Jul 2022 21:08:15 +0800 Subject: [PATCH] ddl: check the index state before altering it (#124) --- ddl/index.go | 2 +- ddl/multi_schema_change_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ddl/index.go b/ddl/index.go index 9af9ee785a437..8fd856349924d 100644 --- a/ddl/index.go +++ b/ddl/index.go @@ -340,7 +340,7 @@ func onRenameIndex(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error) func validateAlterIndexVisibility(ctx sessionctx.Context, indexName model.CIStr, invisible bool, tbl *model.TableInfo) (bool, error) { var idx *model.IndexInfo - if idx = tbl.FindIndexByName(indexName.L); idx == nil { + if idx = tbl.FindIndexByName(indexName.L); idx == nil || idx.State != model.StatePublic { return false, errors.Trace(infoschema.ErrKeyNotExists.GenWithStackByArgs(indexName.O, tbl.Name)) } if ctx == nil || ctx.GetSessionVars() == nil || ctx.GetSessionVars().StmtCtx.MultiSchemaInfo == nil { diff --git a/ddl/multi_schema_change_test.go b/ddl/multi_schema_change_test.go index a7c6465035557..048381e8a645f 100644 --- a/ddl/multi_schema_change_test.go +++ b/ddl/multi_schema_change_test.go @@ -1060,6 +1060,7 @@ func TestMultiSchemaChangeAlterIndexVisibility(t *testing.T) { tk.MustExec("create table t (a int, b int, index idx(b));") tk.MustExec("alter table t add index idx2(a), alter index idx visible;") tk.MustQuery("select * from t use index (idx, idx2);").Check(testkit.Rows( /* no rows */ )) + tk.MustGetErrCode("alter table t drop column b, alter index idx invisible;", errno.ErrKeyDoesNotExist) } func TestMultiSchemaChangeWithExpressionIndex(t *testing.T) {