Skip to content

Commit

Permalink
ddl: check the index state before altering it (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta committed Jul 7, 2022
1 parent e55a010 commit e0acbf2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions ddl/multi_schema_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e0acbf2

Please sign in to comment.