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

plan: build anti semi join for NOT EXISTS #7842

Merged
merged 9 commits into from
Oct 9, 2018

Conversation

eurekaka
Copy link
Contributor

@eurekaka eurekaka commented Oct 9, 2018

What problem does this PR solve?

Fix #7837

What is changed and how it works?

remove Not UnaryOperationExpr from AST, and store NOT in ExistsSubqueryExpr.

After this PR:

mysql> explain select * from t1 where not exists (select * from t2 where t1.a = t2.a);
+------------------------+----------+------+------------------------------------------------------------------------+
| id                     | count    | task | operator info                                                          |
+------------------------+----------+------+------------------------------------------------------------------------+
| HashLeftJoin_9         | 8000.00  | root | anti semi join, inner:TableReader_13, equal:[eq(test.t1.a, test.t2.a)] |
| ├─TableReader_11       | 10000.00 | root | data:TableScan_10                                                      |
| │ └─TableScan_10       | 10000.00 | cop  | table:t1, range:[-inf,+inf], keep order:false, stats:pseudo            |
| └─TableReader_13       | 10000.00 | root | data:TableScan_12                                                      |
|   └─TableScan_12       | 10000.00 | cop  | table:t2, range:[-inf,+inf], keep order:false, stats:pseudo            |
+------------------------+----------+------+------------------------------------------------------------------------+
5 rows in set (0.00 sec)

Check List

Tests

  • Unit test
  • Integration test

Side effects

N/A

Related changes

N/A

@eurekaka eurekaka added type/enhancement The issue or PR belongs to an enhancement. status/WIP sig/planner SIG: Planner labels Oct 9, 2018
@eurekaka
Copy link
Contributor Author

eurekaka commented Oct 9, 2018

/run-all-tests

@eurekaka
Copy link
Contributor Author

eurekaka commented Oct 9, 2018

/run-all-tests

@eurekaka
Copy link
Contributor Author

eurekaka commented Oct 9, 2018

@zz-jason @winoros @XuHuaiyu PTAL

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

zz-jason commented Oct 9, 2018

/run-all-tests

@zz-jason zz-jason added the status/LGT1 Indicates that a PR has LGTM 1. label Oct 9, 2018
@@ -562,7 +562,7 @@ func (er *expressionRewriter) handleExistSubquery(v *ast.ExistsSubqueryExpr) (as
er.err = errors.Trace(err)
return v, true
}
if len(rows) > 0 {
if (len(rows) > 0 && !v.Not) || (len(rows) == 0 && v.Not) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this check mean?

Copy link
Member

Choose a reason for hiding this comment

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

rows is the result of the subquery evaluated by EvalSubquery(), it directly set the result of exists subquery according to rows.

@XuHuaiyu XuHuaiyu changed the title [WIP] plan: build anti semi join for NOT EXISTS plan: build anti semi join for NOT EXISTS Oct 9, 2018
Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

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

lgtm

@XuHuaiyu XuHuaiyu added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Oct 9, 2018
@eurekaka
Copy link
Contributor Author

eurekaka commented Oct 9, 2018

/run-mybatis-test
/run-sqllogic-test

@jingyugao
Copy link
Contributor

Can this really make performance? Is there some test cases or benckmark ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner 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.

build anti semi join for NOT EXISTS instead of left outer semi join with NOT selection
5 participants