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
Merged

Conversation

eurekaka
Copy link
Contributor

@eurekaka eurekaka 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 eurekaka added type/bugfix This PR fixes a bug. sig/planner SIG: Planner labels Nov 16, 2018
@eurekaka
Copy link
Contributor Author

/run-all-tests

@eurekaka
Copy link
Contributor Author

@zz-jason @winoros @lamxTyler PTAL

@@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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
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

@alivxxx alivxxx added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 20, 2018
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 zz-jason added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Nov 20, 2018
@eurekaka eurekaka merged commit 3e0e7d5 into pingcap:master Nov 20, 2018
@eurekaka eurekaka deleted the do_crash branch November 20, 2018 06:10
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
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/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants