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

executor: reset hasMatch flag for each outer row in merge join #9046

Merged
merged 3 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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