diff --git a/executor/test/splittest/split_table_test.go b/executor/test/splittest/split_table_test.go index 3f86a84daf967..4fe38cb3bea3f 100644 --- a/executor/test/splittest/split_table_test.go +++ b/executor/test/splittest/split_table_test.go @@ -163,6 +163,10 @@ func TestClusterIndexSplitTableIntegration(t *testing.T) { tk.MustExec("create table t (a varchar(255), b decimal, c int, primary key (a, b));") errMsg = "[types:1265]Incorrect value: '' for column 'b'" tk.MustGetErrMsg("split table t by ('aaa', '')", errMsg) + + tk.MustExec("drop table t;") + tk.MustExec("CREATE TABLE t (`id` varchar(10) NOT NULL, primary key (`id`) CLUSTERED);") + tk.MustGetErrCode("split table t index `primary` between (0) and (1000) regions 2;", errno.ErrKeyDoesNotExist) } func TestClusterIndexShowTableRegion(t *testing.T) { diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index 0213a79d79ccb..869908b963bc8 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -4596,7 +4596,7 @@ func (b *PlanBuilder) buildSplitRegion(node *ast.SplitRegionStmt) (Plan, error) func (b *PlanBuilder) buildSplitIndexRegion(node *ast.SplitRegionStmt) (Plan, error) { tblInfo := node.Table.TableInfo indexInfo := tblInfo.FindIndexByName(node.IndexName.L) - if indexInfo == nil { + if indexInfo == nil || indexInfo.Primary && tblInfo.IsCommonHandle { return nil, ErrKeyDoesNotExist.GenWithStackByArgs(node.IndexName, tblInfo.Name) } mockTablePlan := LogicalTableDual{}.Init(b.ctx, b.getSelectOffset())