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: support subquery in `Do` statement #8343

Merged
merged 4 commits into from Nov 20, 2018

Conversation

@eurekaka
Copy link
Contributor

commented Nov 16, 2018

What problem does this PR solve?

Before this PR:

mysql> select * from t1;
+------+
| id   |
+------+
|    1 |
+------+
1 row in set (0.01 sec)

mysql> select 1 in (select * from t1);
+-------------------------+
| 1 in (select * from t1) |
+-------------------------+
|                       1 |
+-------------------------+
1 row in set (0.00 sec)

mysql> do 1 in (select * from t1);
ERROR 2013 (HY000): Lost connection to MySQL server during query

while in MySQL:

mysql> select * from t1;
+--------------+
| processor_id |
+--------------+
|            1 |
+--------------+
1 row in set (0.00 sec)

mysql> do 1 in (select * from t1);
Query OK, 0 rows affected (0.00 sec)

MySQL states in https://dev.mysql.com/doc/refman/5.7/en/do.html that:

DO only executes expressions. It cannot be used in all cases where SELECT can be used. For example, DO id FROM t1 is invalid because it references a table.

The documentation does not explicitly specify the boundary to which Do is compatible with SELECT. Since this case experimentally works in MySQL, we support it in TiDB.

What is changed and how it works?

  • involve full expression rewriting in plan building for Do;
  • prevent Projection specially added for Do being eliminated in optimizer;

Check List

Tests

  • Unit test

Side effects

N/A

Related changes

  • Need to cherry-pick to the release branch

This change is Reviewable

@eurekaka

This comment has been minimized.

Copy link
Contributor Author

commented Nov 16, 2018

/run-all-tests

@eurekaka

This comment has been minimized.

Copy link
Contributor Author

commented Nov 16, 2018

@@ -34,7 +35,7 @@ func getUsedList(usedCols []*expression.Column, schema *expression.Schema) []boo
for _, col := range usedCols {
idx := schema.ColumnIndex(col)
if idx == -1 {
log.Errorf("Can't find column %s from schema %s.", col, schema)
panic(fmt.Sprintf("Can't find column %s from schema %s.", col, schema))

This comment has been minimized.

Copy link
@lamxTyler

lamxTyler Nov 16, 2018

Member

Why panic?

This comment has been minimized.

Copy link
@eurekaka

eurekaka Nov 19, 2018

Author Contributor

Because if idx == -1, in line 40, used[idx] = true would panic also, to make the error message in log clearer, I made this change.

Copy link
Member

left a comment

LGTM

Copy link
Member

left a comment

LGTM

@zz-jason zz-jason added status/LGT2 and removed status/LGT1 labels Nov 20, 2018
@eurekaka eurekaka merged commit 3e0e7d5 into pingcap:master Nov 20, 2018
4 checks passed
4 checks passed
ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
jenkins-ci-tidb/build Jenkins job succeeded.
Details
license/cla Contributor License Agreement is signed.
Details
@eurekaka eurekaka deleted the eurekaka:do_crash branch Nov 20, 2018
lysu added a commit that referenced this pull request Nov 20, 2018
eurekaka added a commit to eurekaka/tidb that referenced this pull request Mar 25, 2019
eurekaka added a commit to eurekaka/tidb that referenced this pull request Mar 25, 2019
eurekaka added a commit to eurekaka/tidb that referenced this pull request Mar 25, 2019
zz-jason added a commit that referenced this pull request Mar 25, 2019
zz-jason added a commit that referenced this pull request Mar 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.