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

planner, table: set PrimaryPrefixColumnIds correctly #23250

Merged
merged 12 commits into from
Mar 12, 2021
3 changes: 0 additions & 3 deletions planner/core/plan_to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 18 additions & 0 deletions session/clustered_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions table/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}