Skip to content

Commit

Permalink
planner: handle single partition in IndexJoin correctly (pingcap#12581)
Browse files Browse the repository at this point in the history
  • Loading branch information
eurekaka authored and sre-bot committed Oct 15, 2019
1 parent ae71823 commit 4a43daa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions executor/index_lookup_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,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"))
}
10 changes: 9 additions & 1 deletion planner/core/exhaust_physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,8 @@ func (p *LogicalJoin) constructInnerIndexScanTask(
Ranges: ranger.FullRange(),
rangeInfo: rangeInfo,
Desc: desc,
isPartition: ds.isPartition,
physicalTableID: ds.physicalTableID,
}.Init(ds.ctx, ds.blockOffset)
is.stats = ds.tableStats.ScaleByExpectCnt(rowCount)
cop := &copTask{
Expand All @@ -746,7 +748,13 @@ func (p *LogicalJoin) constructInnerIndexScanTask(
}
if !isCoveringIndex(ds.schema.Columns, path.fullIdxCols, path.fullIdxColLens, 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, ds.blockOffset)
ts := PhysicalTableScan{
Columns: ds.Columns,
Table: is.Table,
TableAsName: ds.TableAsName,
isPartition: ds.isPartition,
physicalTableID: ds.physicalTableID,
}.Init(ds.ctx, ds.blockOffset)
ts.schema = is.dataSourceSchema.Clone()
// If inner cop task need keep order, the extraHandleCol should be set.
if cop.keepOrder {
Expand Down

0 comments on commit 4a43daa

Please sign in to comment.