From 06d2b13b4a38101371fccb0d5126107841277626 Mon Sep 17 00:00:00 2001 From: wjhuang2016 Date: Thu, 11 Mar 2021 13:25:09 +0800 Subject: [PATCH 1/5] done Signed-off-by: wjhuang2016 --- planner/core/plan_to_pb.go | 3 --- table/tables/tables.go | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/planner/core/plan_to_pb.go b/planner/core/plan_to_pb.go index f199c3dd9cf19..e3b16957ee519 100644 --- a/planner/core/plan_to_pb.go +++ b/planner/core/plan_to_pb.go @@ -197,9 +197,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/table/tables/tables.go b/table/tables/tables.go index 0a29dd7f4cf28..022ce65db7250 100644 --- a/table/tables/tables.go +++ b/table/tables/tables.go @@ -1746,5 +1746,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 } From 7206ce02b07627a710d0092b15c791d1b9589618 Mon Sep 17 00:00:00 2001 From: wjhuang2016 Date: Fri, 12 Mar 2021 13:42:19 +0800 Subject: [PATCH 2/5] test Signed-off-by: wjhuang2016 --- session/clustered_index_test.go | 18 ++++++++++++++++++ table/tables/tables.go | 6 +++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/session/clustered_index_test.go b/session/clustered_index_test.go index e30491bfa0224..4f7c84755e7ac 100644 --- a/session/clustered_index_test.go +++ b/session/clustered_index_test.go @@ -381,3 +381,21 @@ func (s *testClusteredSerialSuite) TestClusteredIndexSyntax(c *C) { assertPkType("create table t (a int, b varchar(255), primary key(b, a) /*T![clustered_index] clustered */);", clustered) } } + +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") +} diff --git a/table/tables/tables.go b/table/tables/tables.go index 022ce65db7250..f085527cf28da 100644 --- a/table/tables/tables.go +++ b/table/tables/tables.go @@ -1746,8 +1746,8 @@ func BuildTableScanFromInfos(tableInfo *model.TableInfo, columnInfos []*model.Co Columns: util.ColumnsToProto(columnInfos, tableInfo.PKIsHandle), PrimaryColumnIds: pkColIds, } - if tableInfo.IsCommonHandle { - tsExec.PrimaryPrefixColumnIds = PrimaryPrefixColumnIDs(tableInfo) - } + //if tableInfo.IsCommonHandle { + // tsExec.PrimaryPrefixColumnIds = PrimaryPrefixColumnIDs(tableInfo) + //} return tsExec } From e2c46dc258fa91a09e13472579fbaca569d44c13 Mon Sep 17 00:00:00 2001 From: wjhuang2016 Date: Fri, 12 Mar 2021 13:42:54 +0800 Subject: [PATCH 3/5] 1 Signed-off-by: wjhuang2016 --- planner/core/plan_to_pb.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/planner/core/plan_to_pb.go b/planner/core/plan_to_pb.go index e3b16957ee519..b529453de073a 100644 --- a/planner/core/plan_to_pb.go +++ b/planner/core/plan_to_pb.go @@ -196,6 +196,9 @@ func (p *PhysicalTableScan) ToPB(ctx sessionctx.Context, storeType kv.StoreType) if storeType == kv.TiFlash { executorID = p.ExplainID().String() } + if p.Table.IsCommonHandle { + tsExec.PrimaryPrefixColumnIds = tables.PrimaryPrefixColumnIDs(p.Table) + } err := SetPBColumnsDefaultValue(ctx, tsExec.Columns, p.Columns) return &tipb.Executor{Tp: tipb.ExecType_TypeTableScan, TblScan: tsExec, ExecutorId: &executorID}, err } From e3eef9428db377956f38f2791acdf30c0f3a480f Mon Sep 17 00:00:00 2001 From: wjhuang2016 Date: Fri, 12 Mar 2021 13:44:05 +0800 Subject: [PATCH 4/5] 2 Signed-off-by: wjhuang2016 --- planner/core/plan_to_pb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner/core/plan_to_pb.go b/planner/core/plan_to_pb.go index b529453de073a..f199c3dd9cf19 100644 --- a/planner/core/plan_to_pb.go +++ b/planner/core/plan_to_pb.go @@ -196,10 +196,10 @@ func (p *PhysicalTableScan) ToPB(ctx sessionctx.Context, storeType kv.StoreType) if storeType == kv.TiFlash { executorID = p.ExplainID().String() } + err := SetPBColumnsDefaultValue(ctx, tsExec.Columns, p.Columns) if p.Table.IsCommonHandle { tsExec.PrimaryPrefixColumnIds = tables.PrimaryPrefixColumnIDs(p.Table) } - err := SetPBColumnsDefaultValue(ctx, tsExec.Columns, p.Columns) return &tipb.Executor{Tp: tipb.ExecType_TypeTableScan, TblScan: tsExec, ExecutorId: &executorID}, err } From f03a96ef72cea6425572ee5423fbe75f3ed4fa77 Mon Sep 17 00:00:00 2001 From: wjhuang2016 Date: Fri, 12 Mar 2021 14:20:52 +0800 Subject: [PATCH 5/5] fix Signed-off-by: wjhuang2016 --- planner/core/plan_to_pb.go | 3 --- table/tables/tables.go | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/planner/core/plan_to_pb.go b/planner/core/plan_to_pb.go index f199c3dd9cf19..e3b16957ee519 100644 --- a/planner/core/plan_to_pb.go +++ b/planner/core/plan_to_pb.go @@ -197,9 +197,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/table/tables/tables.go b/table/tables/tables.go index f085527cf28da..022ce65db7250 100644 --- a/table/tables/tables.go +++ b/table/tables/tables.go @@ -1746,8 +1746,8 @@ func BuildTableScanFromInfos(tableInfo *model.TableInfo, columnInfos []*model.Co Columns: util.ColumnsToProto(columnInfos, tableInfo.PKIsHandle), PrimaryColumnIds: pkColIds, } - //if tableInfo.IsCommonHandle { - // tsExec.PrimaryPrefixColumnIds = PrimaryPrefixColumnIDs(tableInfo) - //} + if tableInfo.IsCommonHandle { + tsExec.PrimaryPrefixColumnIds = PrimaryPrefixColumnIDs(tableInfo) + } return tsExec }