From 1274082cbbc60d79906953940953a59401476294 Mon Sep 17 00:00:00 2001 From: Kenan Yao Date: Wed, 16 Oct 2019 16:03:50 +0800 Subject: [PATCH] planner: handle single partition in IndexJoin correctly (#12581) (#12711) Conflicts: planner/core/exhaust_physical_plans.go --- executor/index_lookup_join_test.go | 8 ++++++++ planner/core/exhaust_physical_plans.go | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/executor/index_lookup_join_test.go b/executor/index_lookup_join_test.go index 2fec9fa6e5e13..098e0cfded8c4 100644 --- a/executor/index_lookup_join_test.go +++ b/executor/index_lookup_join_test.go @@ -160,3 +160,11 @@ func (s *testSuite2) TestIssue11061(c *C) { tk.MustExec("insert into t1 (c) values('7_chars'), ('13_characters')") tk.MustQuery("SELECT /*+ TIDB_INLJ(t1) */ SUM(LENGTH(c)) FROM t1 WHERE c IN (SELECT t1.c FROM t1)").Check(testkit.Rows("20")) } + +func (s *testSuite2) TestIndexJoinPartitionTable(c *C) { + tk := testkit.NewTestKitWithInit(c, s.store) + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a int, b int not null, c int, key idx(c)) partition by hash(b) partitions 30") + tk.MustExec("insert into t values(1, 27, 2)") + tk.MustQuery("SELECT /*+ TIDB_INLJ(t1) */ count(1) FROM t t1 INNER JOIN (SELECT a, max(c) AS c FROM t WHERE b = 27 AND a = 1 GROUP BY a) t2 ON t1.a = t2.a AND t1.c = t2.c WHERE t1.b = 27").Check(testkit.Rows("1")) +} diff --git a/planner/core/exhaust_physical_plans.go b/planner/core/exhaust_physical_plans.go index fbd7699176511..38deafb25f663 100644 --- a/planner/core/exhaust_physical_plans.go +++ b/planner/core/exhaust_physical_plans.go @@ -544,6 +544,8 @@ func (p *LogicalJoin) constructInnerIndexScan(ds *DataSource, idx *model.IndexIn KeepOrder: false, Ranges: ranger.FullRange(), rangeInfo: rangeInfo, + isPartition: ds.isPartition, + physicalTableID: ds.physicalTableID, }.Init(ds.ctx) var rowCount float64 @@ -564,7 +566,13 @@ func (p *LogicalJoin) constructInnerIndexScan(ds *DataSource, idx *model.IndexIn } if !isCoveringIndex(ds.schema.Columns, is.Index.Columns, is.Table.PKIsHandle) { // On this way, it's double read case. - ts := PhysicalTableScan{Columns: ds.Columns, Table: is.Table, TableAsName: ds.TableAsName}.Init(ds.ctx) + ts := PhysicalTableScan{ + Columns: ds.Columns, + Table: is.Table, + TableAsName: ds.TableAsName, + isPartition: ds.isPartition, + physicalTableID: ds.physicalTableID, + }.Init(ds.ctx) ts.SetSchema(is.dataSourceSchema) cop.tablePlan = ts }