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: disallow subquery in insert values clause reference upper scope (#16872) #16952

Merged
merged 3 commits into from
May 6, 2020

Conversation

sre-bot
Copy link
Contributor

@sre-bot sre-bot commented Apr 30, 2020

cherry-pick #16872 to release-4.0


What problem does this PR solve?

Problem Summary:
Insert statements with subquery in value clause write incorrect values

mysql root@127.0.0.1:test> select * from t2;
+---+---+---+
| a | b | c |
+---+---+---+
0 rows in set
Time: 0.013s
mysql root@127.0.0.1:test> show create table t2;
+-------+-------------------------------------------------------------+
| Table | Create Table                                                |
+-------+-------------------------------------------------------------+
| t2    | CREATE TABLE `t2` (                                         |
|       |   `a` int(11) NOT NULL,                                     |
|       |   `b` int(11) DEFAULT NULL,                                 |
|       |   `c` int(11) DEFAULT NULL,                                 |
|       |   PRIMARY KEY (`a`)                                         |
|       | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+-------------------------------------------------------------+
1 row in set
Time: 0.014s
mysql root@127.0.0.1:test> insert into t2 values (11, 8, (select not b));
Query OK, 1 row affected
Time: 0.001s
mysql root@127.0.0.1:test> select * from t2;
+----+---+----+
| a  | b | c  |
+----+---+----+
| 11 | 8 | 11 |
+----+---+----+
1 row in set
Time: 0.018s

What is changed and how it works?

What's Changed:
Prevent subquery in insert values clause referencing upper scope columns, these column expressions will not be treated as correlated columns.

This change is compatible with pg but not mysql , the inserted table is not allowed to be used in insert value clause, eg:

mysql> insert into t2 values (11, 8, (select c from t2 limit 1));
ERROR 1093 (HY000): You can't specify target table 't2' for update in FROM clause

How it Works:

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test

Side effects

Release note

Fix the problem that subquery in insert value clause could reference upper scope resolved information

@sre-bot sre-bot requested review from a team as code owners April 30, 2020 06:33
@sre-bot
Copy link
Contributor Author

sre-bot commented Apr 30, 2020

/run-all-tests

Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@eurekaka eurekaka left a comment

Choose a reason for hiding this comment

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

LGTM

@eurekaka eurekaka added the status/can-merge Indicates a PR has been approved by a committer. label Apr 30, 2020
@sre-bot
Copy link
Contributor Author

sre-bot commented Apr 30, 2020

/run-all-tests

@sre-bot
Copy link
Contributor Author

sre-bot commented Apr 30, 2020

/run-all-tests

@sre-bot
Copy link
Contributor Author

sre-bot commented Apr 30, 2020

@sre-bot merge failed.

@jackysp
Copy link
Member

jackysp commented May 6, 2020

/merge

@sre-bot
Copy link
Contributor Author

sre-bot commented May 6, 2020

/run-all-tests

@sre-bot
Copy link
Contributor Author

sre-bot commented May 6, 2020

@sre-bot merge failed.

@jackysp
Copy link
Member

jackysp commented May 6, 2020

/run-check_release_note

@jackysp
Copy link
Member

jackysp commented May 6, 2020

/rebuild

@jackysp
Copy link
Member

jackysp commented May 6, 2020

/merge

@sre-bot
Copy link
Contributor Author

sre-bot commented May 6, 2020

/run-all-tests

@jackysp jackysp merged commit eccb800 into pingcap:release-4.0 May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution status/can-merge Indicates a PR has been approved by a committer. type/bugfix This PR fixes a bug. type/4.0-cherry-pick
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants