diff --git a/planner/core/plan_to_pb.go b/planner/core/plan_to_pb.go index c6a9e48c612f7..185e750c0974c 100644 --- a/planner/core/plan_to_pb.go +++ b/planner/core/plan_to_pb.go @@ -198,9 +198,6 @@ func (p *PhysicalTableScan) ToPB(ctx sessionctx.Context, storeType kv.StoreType) executorID = p.ExplainID().String() } err := SetPBColumnsDefaultValue(ctx, tsExec.Columns, p.Columns) - if p.Table.IsCommonHandle { - tsExec.PrimaryPrefixColumnIds = tables.PrimaryPrefixColumnIDs(p.Table) - } return &tipb.Executor{Tp: tipb.ExecType_TypeTableScan, TblScan: tsExec, ExecutorId: &executorID}, err } diff --git a/session/clustered_index_test.go b/session/clustered_index_test.go index d189f12a2ccbd..9589d58426c0f 100644 --- a/session/clustered_index_test.go +++ b/session/clustered_index_test.go @@ -437,6 +437,24 @@ func (s *testClusteredSerialSuite) TestClusteredIndexSyntax(c *C) { } } +func (s *testClusteredSerialSuite) TestPrefixClusteredIndexAddIndexAndRecover(c *C) { + tk1 := testkit.NewTestKit(c, s.store) + tk1.MustExec("use test;") + tk1.MustExec("drop table if exists t;") + defer func() { + tk1.MustExec("drop table if exists t;") + }() + + tk1.MustExec("create table t(a char(3), b char(3), primary key(a(1)) clustered)") + tk1.MustExec("insert into t values ('aaa', 'bbb')") + tk1.MustExec("alter table t add index idx(b)") + tk1.MustQuery("select * from t use index(idx)").Check(testkit.Rows("aaa bbb")) + tk1.MustExec("admin check table t") + tk1.MustExec("admin recover index t idx") + tk1.MustQuery("select * from t use index(idx)").Check(testkit.Rows("aaa bbb")) + tk1.MustExec("admin check table t") +} + // https://github.com/pingcap/tidb/issues/23106 func (s *testClusteredSerialSuite) TestClusteredIndexDecodeRestoredDataV5(c *C) { tk := testkit.NewTestKitWithInit(c, s.store) diff --git a/table/tables/tables.go b/table/tables/tables.go index 50c332e92bfcf..7dd3894898a52 100644 --- a/table/tables/tables.go +++ b/table/tables/tables.go @@ -1756,5 +1756,8 @@ func BuildTableScanFromInfos(tableInfo *model.TableInfo, columnInfos []*model.Co Columns: util.ColumnsToProto(columnInfos, tableInfo.PKIsHandle), PrimaryColumnIds: pkColIds, } + if tableInfo.IsCommonHandle { + tsExec.PrimaryPrefixColumnIds = PrimaryPrefixColumnIDs(tableInfo) + } return tsExec }