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

Tidb allow updates to a table when you are also using that same table in an inner select as your update criteria. #31363

Open
ramanich1 opened this issue Jan 5, 2022 · 3 comments · May be fixed by #33565
Assignees
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.0 good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/minor sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@ramanich1
Copy link
Collaborator

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

drop table if exists t1;
CREATE TABLE t1 (x int);
INSERT INTO t1 (x) VALUES ((SELECT x FROM t1));

2. What did you expect to see? (Required)

mysql> INSERT INTO t1 (x) VALUES ((SELECT x FROM t1));
ERROR 1093 (HY000): You can't specify target table 't1' for update in FROM clause

3. What did you see instead (Required)

mysql> INSERT INTO t1 (x) VALUES ((SELECT x FROM t1));
Query OK, 1 row affected (0.00 sec)

4. What is your TiDB version? (Required)

| Release Version: v5.4.0-alpha-264-g6efa36df6
Edition: Community
Git Commit Hash: 6efa36df6cff325106f67ecfe3d79816ba37ca6a
Git Branch: master
UTC Build Time: 2021-12-28 02:03:55
GoVersion: go1.17.2
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
@ramanich1 ramanich1 added the type/bug The issue is confirmed as a bug. label Jan 5, 2022
@morgo
Copy link
Contributor

morgo commented Jan 5, 2022

Verified as described. Note that MySQL can execute this if t1 in the subquery is aliased:

mysql [localhost:5735] {msandbox} (test) > INSERT INTO t1 (x) VALUES ((SELECT x FROM t1));
ERROR 1093 (HY000): You can't specify target table 't1' for update in FROM clause
mysql [localhost:5735] {msandbox} (test) > INSERT INTO t1 (x) VALUES ((SELECT x FROM t1 as t));
Query OK, 1 row affected (0.00 sec)

@jebter jebter added affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. labels Jan 11, 2022
@winoros
Copy link
Member

winoros commented Mar 21, 2022

This is just a compatibility problem and is one that would not cause a write error. We downgrade the severity first.

@winoros winoros added help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/moderate good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. severity/minor and removed severity/major severity/moderate labels Mar 21, 2022
@fanrenhoo
Copy link
Contributor

/assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.0 good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/minor sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants