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

Projects
None yet
4 participants
@eurekaka
Copy link
Contributor

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 added some commits Oct 9, 2018

@eurekaka

This comment has been minimized.

Copy link
Contributor Author

eurekaka commented Oct 9, 2018

/run-all-tests

@eurekaka

This comment has been minimized.

Copy link
Contributor Author

eurekaka commented Oct 9, 2018

/run-all-tests

@eurekaka

This comment has been minimized.

Copy link
Contributor Author

eurekaka commented Oct 9, 2018

@zz-jason
Copy link
Member

zz-jason left a comment

LGTM

@zz-jason

This comment has been minimized.

Copy link
Member

zz-jason commented Oct 9, 2018

/run-all-tests

@zz-jason zz-jason added the status/LGT1 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) {

This comment has been minimized.

Copy link
@XuHuaiyu

XuHuaiyu Oct 9, 2018

Contributor

what does this check mean?

This comment has been minimized.

Copy link
@zz-jason

zz-jason Oct 9, 2018

Member

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

@winoros
Copy link
Member

winoros left a comment

lgtm

@XuHuaiyu XuHuaiyu added status/LGT2 and removed status/LGT1 labels Oct 9, 2018

@eurekaka

This comment has been minimized.

Copy link
Contributor Author

eurekaka commented Oct 9, 2018

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

@eurekaka eurekaka merged commit d60a1a2 into pingcap:master Oct 9, 2018

2 of 4 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
jenkins-ci-tidb/build Jenkins job is running.
Details
ci/circleci Your tests passed on CircleCI!
Details
license/cla Contributor License Agreement is signed.
Details

@eurekaka eurekaka deleted the eurekaka:not_exists_anti branch Oct 9, 2018

@eurekaka

This comment has been minimized.

Copy link
Contributor Author

eurekaka commented on 1a0d399 Oct 9, 2018

@Apollo1993 what is this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.