From 1b2061840c97017582fd67acd86eea5170d643d6 Mon Sep 17 00:00:00 2001 From: tangenta Date: Thu, 19 Jun 2025 11:08:22 +0800 Subject: [PATCH] executor: report error when admin check on multiple tables Signed-off-by: tangenta --- pkg/ddl/db_test.go | 6 ++++-- pkg/executor/test/admintest/admin_test.go | 4 ++++ pkg/executor/test/executor/executor_test.go | 5 ++--- pkg/planner/core/planbuilder.go | 3 +++ tests/integrationtest/r/ddl/foreign_key.result | 3 ++- tests/integrationtest/t/ddl/foreign_key.test | 3 ++- 6 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pkg/ddl/db_test.go b/pkg/ddl/db_test.go index c4aeb0ce5589e..b8d3635b96ee4 100644 --- a/pkg/ddl/db_test.go +++ b/pkg/ddl/db_test.go @@ -635,7 +635,8 @@ func TestTxnSavepointWithDDL(t *testing.T) { tk2.MustExec("alter table t2 add index idx2(c2)") tk.MustExec("commit") tk.MustQuery("select * from t2").Check(testkit.Rows()) - tk.MustExec("admin check table t1, t2") + tk.MustExec("admin check table t1") + tk.MustExec("admin check table t2") prepareFn() tk.MustExec("truncate table t1") @@ -651,7 +652,8 @@ func TestTxnSavepointWithDDL(t *testing.T) { require.Error(t, err) require.Regexp(t, ".*8028.*Information schema is changed during the execution of the statement.*", err.Error()) tk.MustQuery("select * from t1").Check(testkit.Rows()) - tk.MustExec("admin check table t1, t2") + tk.MustExec("admin check table t1") + tk.MustExec("admin check table t2") } func TestSnapshotVersion(t *testing.T) { diff --git a/pkg/executor/test/admintest/admin_test.go b/pkg/executor/test/admintest/admin_test.go index 66aab286beabf..93de196328ee3 100644 --- a/pkg/executor/test/admintest/admin_test.go +++ b/pkg/executor/test/admintest/admin_test.go @@ -1495,6 +1495,10 @@ func TestAdminCheckTableFailed(t *testing.T) { require.EqualError(t, err, "[admin:8223]data inconsistency in table: admin_test, index: c2, handle: ‹10›, index-values:‹\"handle: 10, values: [KindInt64 19]\"› != record-values:‹\"handle: 10, values: [KindInt64 20]\"›") tk.MustExec("set @@tidb_redact_log=0;") + tk.MustExec("create table other (a int);") + tk.MustGetErrMsg("admin check table other, admin_test;", + "admin check only supports one table at a time") + // Recover records. txn, err = store.Begin() require.NoError(t, err) diff --git a/pkg/executor/test/executor/executor_test.go b/pkg/executor/test/executor/executor_test.go index 886277be290ee..c93aeab7e26f3 100644 --- a/pkg/executor/test/executor/executor_test.go +++ b/pkg/executor/test/executor/executor_test.go @@ -2564,9 +2564,8 @@ func TestAdmin(t *testing.T) { // check table test tk.MustExec("create table admin_test1 (c1 int, c2 int default 1, index (c1))") tk.MustExec("insert admin_test1 (c1) values (21),(22)") - r, err = tk.Exec("admin check table admin_test, admin_test1") - require.NoError(t, err) - require.Nil(t, r) + tk.MustExec("admin check table admin_test") + tk.MustExec("admin check table admin_test1") // error table name require.Error(t, tk.ExecToErr("admin check table admin_test_error")) // different index values diff --git a/pkg/planner/core/planbuilder.go b/pkg/planner/core/planbuilder.go index d7351be2b4da8..11a16873dae61 100644 --- a/pkg/planner/core/planbuilder.go +++ b/pkg/planner/core/planbuilder.go @@ -1847,6 +1847,9 @@ func (b *PlanBuilder) buildPhysicalIndexLookUpReaders(ctx context.Context, dbNam } func (b *PlanBuilder) buildAdminCheckTable(ctx context.Context, as *ast.AdminStmt) (*CheckTable, error) { + if len(as.Tables) > 1 { + return nil, errors.New("admin check only supports one table at a time") + } tblName := as.Tables[0] tnW := b.resolveCtx.GetTableName(tblName) tableInfo := tnW.TableInfo diff --git a/tests/integrationtest/r/ddl/foreign_key.result b/tests/integrationtest/r/ddl/foreign_key.result index 40aec792188d6..8483108774731 100644 --- a/tests/integrationtest/r/ddl/foreign_key.result +++ b/tests/integrationtest/r/ddl/foreign_key.result @@ -205,7 +205,8 @@ id b select * from t2; id b 2 2 -admin check table t1,t2; +admin check table t1; +admin check table t2; create database test_db_1; create database test_db_2; create database test_db_3; diff --git a/tests/integrationtest/t/ddl/foreign_key.test b/tests/integrationtest/t/ddl/foreign_key.test index 5e5d68312f055..f29422a843c12 100644 --- a/tests/integrationtest/t/ddl/foreign_key.test +++ b/tests/integrationtest/t/ddl/foreign_key.test @@ -211,7 +211,8 @@ alter table t2 rename index idx to idx0; delete from t1 where id=1; select * from t1; select * from t2; -admin check table t1,t2; +admin check table t1; +admin check table t2; # TestCheckFKDatabaseRefWithSchemaSimpleTableInfos create database test_db_1;