Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion session/nontransactional.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions session/nontransactional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}