Skip to content

Commit

Permalink
executor: reset hasMatch flag for each outer row in merge join (#9046)
Browse files Browse the repository at this point in the history
  • Loading branch information
eurekaka authored and zz-jason committed Jan 14, 2019
1 parent 3c98f69 commit 463d44c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions executor/merge_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ func (e *MergeJoinExec) joinToChunk(ctx context.Context, chk *chunk.Chunk) (hasM
e.joiner.onMissMatch(e.outerTable.row, chk)
}
e.outerTable.row = e.outerTable.iter.Next()
e.outerTable.hasMatch = false
e.innerIter4Row.Begin()
}

Expand Down
21 changes: 21 additions & 0 deletions executor/merge_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,27 @@ func (s *testSuite1) TestMergeJoin(c *C) {
"2 1",
"2 2",
))

tk.MustExec("drop table if exists t")
tk.MustExec("drop table if exists s")
tk.MustExec("create table t(a int, b int)")
tk.MustExec("insert into t values(1,1),(1,2)")
tk.MustExec("create table s(a int, b int)")
tk.MustExec("insert into s values(1,1)")
tk.MustQuery("explain select /*+ TIDB_SMJ(t, s) */ a in (select a from s where s.b >= t.b) from t").Check(testkit.Rows(
"Projection_7 10000.00 root 6_aux_0",
"└─MergeJoin_8 10000.00 root left outer semi join, left key:test.t.a, right key:test.s.a, other cond:ge(test.s.b, test.t.b)",
" ├─Sort_12 10000.00 root test.t.a:asc",
" │ └─TableReader_11 10000.00 root data:TableScan_10",
" │ └─TableScan_10 10000.00 cop table:t, range:[-inf,+inf], keep order:false, stats:pseudo",
" └─Sort_16 10000.00 root test.s.a:asc",
" └─TableReader_15 10000.00 root data:TableScan_14",
" └─TableScan_14 10000.00 cop table:s, range:[-inf,+inf], keep order:false, stats:pseudo",
))
tk.MustQuery("select /*+ TIDB_SMJ(t, s) */ a in (select a from s where s.b >= t.b) from t").Check(testkit.Rows(
"1",
"0",
))
}

func (s *testSuite1) Test3WaysMergeJoin(c *C) {
Expand Down

0 comments on commit 463d44c

Please sign in to comment.