seesion: skip invisible index when selecting shard column for non-transactional DML (#34102)

ref pingcap/tidb#33485
This commit is contained in:
Ziqian Qin
2022-04-20 14:36:03 +08:00
committed by GitHub
parent 715acbfbd6
commit 281aa9c17b
2 changed files with 21 additions and 1 deletions

View File

@ -450,7 +450,7 @@ func selectShardColumn(stmt *ast.NonTransactionalDeleteStmt, se Session, tableNa
}
for _, index := range tbl.Indices() {
if index.Meta().State != model.StatePublic {
if index.Meta().State != model.StatePublic || index.Meta().Invisible {
continue
}
indexColumns := index.Meta().Columns

View File

@ -206,3 +206,23 @@ func TestNonTransactionalDeleteAutoDetectShardColumn(t *testing.T) {
testFunc(table, false)
}
}
func TestNonTransactionalDeleteInvisibleIndex(t *testing.T) {
store, clean := createStorage(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("set @@tidb_max_chunk_size=35")
tk.MustExec("use test")
tk.MustExec("create table t(a int, b int)")
for i := 0; i < 100; i++ {
tk.MustExec(fmt.Sprintf("insert into t values (%d, %d)", i, i*2))
}
err := tk.ExecToErr("split on a limit 10 delete from t")
require.Error(t, err)
tk.MustExec("CREATE UNIQUE INDEX c1 ON t (a) INVISIBLE")
err = tk.ExecToErr("split on a limit 10 delete from t")
require.Error(t, err)
tk.MustExec("CREATE UNIQUE INDEX c2 ON t (a)")
tk.MustExec("split on a limit 10 delete from t")
tk.MustQuery("select count(*) from t").Check(testkit.Rows("0"))
}