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

ERROR 1054 (42S22): Unknown column 't2.a' in 'field list' (insert_update.test) #29261

Open
Alkaagr81 opened this issue Oct 29, 2021 · 1 comment · May be fixed by #34623
Open

ERROR 1054 (42S22): Unknown column 't2.a' in 'field list' (insert_update.test) #29261

Alkaagr81 opened this issue Oct 29, 2021 · 1 comment · May be fixed by #34623
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 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 affects-6.3 affects-6.4 affects-6.5 affects-6.6 affects-7.0 affects-7.1 affects-7.5 affects-8.1 severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@Alkaagr81
Copy link
Collaborator

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

DROP TABLE if exists t0, t1,t2;
CREATE TABLE t0 (k INTEGER PRIMARY KEY);
CREATE TABLE t1(a INTEGER);
CREATE TABLE t2(a INTEGER);
INSERT INTO t1 VALUES (1), (2);
INSERT INTO t2 VALUES (1), (3);
INSERT INTO t0 SELECT a FROM t1 ON DUPLICATE KEY UPDATE k= a + t1.a + 10;
INSERT INTO t0 SELECT a FROM t1 JOIN t2 USING (a) ON DUPLICATE KEY UPDATE k= t1.a + t2.a + 10; 

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

mysql> CREATE TABLE t0 (k INTEGER PRIMARY KEY);
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE TABLE t1(a INTEGER);
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE TABLE t2(a INTEGER);
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO t1 VALUES (1), (2);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> INSERT INTO t2 VALUES (1), (3);
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> INSERT INTO t0 SELECT a FROM t1 ON DUPLICATE KEY UPDATE k= a + t1.a + 10;
Query OK, 3 rows affected (0.00 sec)
Records: 2  Duplicates: 1  Warnings: 0

mysql> INSERT INTO t0  SELECT a FROM t1 JOIN t2 USING (a) ON DUPLICATE KEY UPDATE k= t1.a + t2.a + 10;
Query OK, 2 rows affected (0.00 sec)
Records: 1  Duplicates: 1  Warnings: 0

3. What did you see instead (Required)

mysql> CREATE TABLE t0 (k INTEGER PRIMARY KEY);
Query OK, 0 rows affected (0.12 sec)

mysql> CREATE TABLE t1(a INTEGER);
Query OK, 0 rows affected (0.08 sec)

mysql> CREATE TABLE t2(a INTEGER);
Query OK, 0 rows affected (0.12 sec)

mysql> INSERT INTO t1 VALUES (1), (2);
Query OK, 2 rows affected (0.02 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> INSERT INTO t2 VALUES (1), (3);
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> INSERT INTO t0 SELECT a FROM t1 ON DUPLICATE KEY UPDATE k= a + t1.a + 10;
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> INSERT INTO t0 SELECT a FROM t1 JOIN t2 USING (a) ON DUPLICATE KEY UPDATE k= t1.a + t2.a + 10; 
ERROR 1054 (42S22): Unknown column 't2.a' in 'field list'

4. What is your TiDB version? (Required)

| Release Version: v5.2.1
Edition: Community
Git Commit Hash: cd8fb24c5f7ebd9d479ed228bb41848bd5e97445
Git Branch: heads/refs/tags/v5.2.1
UTC Build Time: 2021-09-08 02:29:53
GoVersion: go1.16.4
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
@Alkaagr81 Alkaagr81 added the type/bug The issue is confirmed as a bug. label Oct 29, 2021
@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 5.4.x versions. labels Jan 11, 2022
@AilinKid
Copy link
Contributor

AilinKid commented May 11, 2022

even with INSERT INTO t0 SELECT a FROM t1 JOIN t2 USING (a) ON DUPLICATE KEY UPDATE k= t1.a + t2.b + 10; TiDB still gets a error.
ERROR 1054 (42S22): Unknown column t2.b in 'field list' while MySQL succeeds.

So the problem must be: the clause behind the ON DUPLICATE KEY UPDATE should see the from scope, which means t1 JOIN t2 here (of course a is not deduplicated). TiDB will extract what it needs from the bottom up.

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 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 affects-6.3 affects-6.4 affects-6.5 affects-6.6 affects-7.0 affects-7.1 affects-7.5 affects-8.1 severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
7 participants