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: getNewJoinResult after handling a task for orderd IndexHashJoin #13451

Merged
merged 5 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
10 changes: 10 additions & 0 deletions executor/index_lookup_hash_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,16 @@ func (iw *indexHashJoinInnerWorker) run(ctx context.Context, cancelFunc context.
joinResult.err = err
break
}
if task.keepOuterOrder {
// We need to get a new result holder here because the old
// `joinResult` hash been sent to the `resultCh` or to the
// `joinChkResourceCh`.
joinResult, ok = iw.getNewJoinResult(ctx)
if !ok {
cancelFunc()
return
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to put it in doJoinInOrder or handleTask?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about putting it here, the first defer function in doJoinInOrder?

}
if joinResult.err != nil {
cancelFunc()
Expand Down
24 changes: 24 additions & 0 deletions executor/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,30 @@ func (s *testSuiteJoin1) TestIndexNestedLoopHashJoin(c *C) {
}
}

func (s *testSuiteJoin3) TestIssue13449(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t, s;")
tk.MustExec("create table t(a int, index(a));")
tk.MustExec("create table s(a int, index(a));")
for i := 1; i <= 128; i++ {
tk.MustExec(fmt.Sprintf("insert into t values(%d)", i))
}
tk.MustExec("insert into s values(1), (128)")
tk.MustExec("set @@tidb_max_chunk_size=32;")
tk.MustExec("set @@tidb_index_lookup_join_concurrency=1;")
tk.MustExec("set @@tidb_index_join_batch_size=32;")

tk.MustQuery("desc select /*+ INL_HASH_JOIN(s) */ * from t join s on t.a=s.a order by t.a;").Check(testkit.Rows(
"IndexHashJoin_35 12487.50 root inner join, inner:IndexReader_27, outer key:Column#1, inner key:Column#3",
"├─IndexReader_37 9990.00 root index:IndexScan_36",
"│ └─IndexScan_36 9990.00 cop[tikv] table:t, index:a, range:[-inf,+inf], keep order:true, stats:pseudo",
"└─IndexReader_27 1.25 root index:Selection_26",
" └─Selection_26 1.25 cop[tikv] not(isnull(Column#3))",
" └─IndexScan_25 1.25 cop[tikv] table:s, index:a, range: decided by [eq(Column#3, Column#1)], keep order:false, stats:pseudo"))
tk.MustQuery("select /*+ INL_HASH_JOIN(s) */ * from t join s on t.a=s.a order by t.a;").Check(testkit.Rows("1 1", "128 128"))
}

func (s *testSuiteJoin3) TestMergejoinOrder(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down