From 7292ec6a3968378d9cc5e825a092f632571d4db2 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Tue, 21 Nov 2023 16:34:10 +0800 Subject: [PATCH] planner: disallow split clustered index with SPLIT TABLE .. INDEX (#47412) (#47435) close pingcap/tidb#47350 --- executor/splittest/split_table_test.go | 4 ++++ planner/core/planbuilder.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/executor/splittest/split_table_test.go b/executor/splittest/split_table_test.go index cec687ec40fad..2ac03611350b8 100644 --- a/executor/splittest/split_table_test.go +++ b/executor/splittest/split_table_test.go @@ -177,6 +177,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 67690124387d9..274ff4ed4dbfe 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -4221,7 +4221,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())