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, cmd: refine HashJoinExec for specific JoinType if outer/inner is nil #8296

Merged
merged 3 commits into from
Nov 14, 2018

Conversation

XuHuaiyu
Copy link
Contributor

@XuHuaiyu XuHuaiyu commented Nov 13, 2018

What problem does this PR solve?

  1. Exit HashJoinExec immediately when the inner table is nil for InnerJoin and SemiJoin.
  2. Exit HashJoinExec immediately when the outer table is nil for all the join types.

What is changed and how it works?

Check List

Tests

  • Integration test
  • Manual test
drop table if exists t1, t2;
create table t1(a int, b int);
create table t2(a int, b int);
insert into t1 values(1,1),(2,2),(3,3),(4,4),(5,5);
select count(*) from t1;
count(*)
5
select count(*) from t2;
count(*)
0
set @@tidb_max_chunk_size=1;
explain analyze select /*+ TIDB_HJ(t1, t2) */ * from t1 where exists (select a from t2 where t1.a = t2.a);
id	count	task	operator info	execution info
HashLeftJoin_9	8000.00	root	semi join, inner:TableReader_13, equal:[eq(test.t1.a, test.t2.a)]	time:1.036712ms, loops:1, rows:0
├─TableReader_11	10000.00	root	data:TableScan_10	time:441.096µs, loops:1, rows:1
│ └─TableScan_10	10000.00	cop	table:t1, range:[-inf,+inf], keep order:false, stats:pseudo	
└─TableReader_13	10000.00	root	data:TableScan_12	time:212.376µs, loops:1, rows:0
  └─TableScan_12	10000.00	cop	table:t2, range:[-inf,+inf], keep order:false, stats:pseudo	
insert into t2 select * from t1;
delete from t1;
select count(*) from t1;
count(*)
0
select count(*) from t2;
count(*)
5
explain analyze select /*+ TIDB_HJ(t1, t2) */ * from t1 where not exists (select a from t2 where t1.a = t2.a);
id	count	task	operator info	execution info
HashLeftJoin_9	8000.00	root	anti semi join, inner:TableReader_13, equal:[eq(test.t1.a, test.t2.a)]	time:534.643µs, loops:1, rows:0
├─TableReader_11	10000.00	root	data:TableScan_10	time:35.042µs, loops:1, rows:0
│ └─TableScan_10	10000.00	cop	table:t1, range:[-inf,+inf], keep order:false, stats:pseudo	
└─TableReader_13	10000.00	root	data:TableScan_12	time:0s, loops:0, rows:0
  └─TableScan_12	10000.00	cop	table:t2, range:[-inf,+inf], keep order:false, stats:pseudo	
explain analyze select /*+ TIDB_HJ(t1, t2) */ * from t1 left outer join t2 on t1.a = t2.a;
id	count	task	operator info	execution info
HashLeftJoin_6	12500.00	root	left outer join, inner:TableReader_10, equal:[eq(test.t1.a, test.t2.a)]	time:502.553µs, loops:1, rows:0
├─TableReader_8	10000.00	root	data:TableScan_7	time:27.302µs, loops:1, rows:0
│ └─TableScan_7	10000.00	cop	table:t1, range:[-inf,+inf], keep order:false, stats:pseudo	
└─TableReader_10	10000.00	root	data:TableScan_9	time:0s, loops:0, rows:0
  └─TableScan_9	10000.00	cop	table:t2, range:[-inf,+inf], keep order:false, stats:pseudo	

Code changes

  • Has exported function/method change

Side effects

Related changes

  • Need to cherry-pick to the release branch
    release-2.1

@XuHuaiyu XuHuaiyu added type/enhancement The issue or PR belongs to an enhancement. sig/execution SIG execution labels Nov 13, 2018
Copy link
Contributor

@alivxxx alivxxx left a comment

Choose a reason for hiding this comment

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

LGTM

.gitignore Outdated
@@ -14,3 +14,4 @@ explain_test
cmd/explaintest/explain-test.out
_tools/
*.fail.go
cmd/explaintest/explaintest_tidb-server
Copy link
Member

Choose a reason for hiding this comment

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

it's better to put this together with cmd/explaintest/explain-test.out

@zz-jason
Copy link
Member

please fix ci.

@XuHuaiyu
Copy link
Contributor Author

/run-all-tests

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason
Copy link
Member

/run-common-test

@zz-jason zz-jason added the status/LGT2 Indicates that a PR has LGTM 2. label Nov 14, 2018
@zz-jason zz-jason merged commit d6796b3 into pingcap:master Nov 14, 2018
@zz-jason
Copy link
Member

@XuHuaiyu This PR needs to be cherry-picked to release-2.1 branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants