pingcap / pingcap/tidb

INSERT … AS new ON DUPLICATE KEY UPDATE c = new.c: alias parsed but never bound

Open
#70,814 2 comments 0 reactions 1 assignee Claimed by @bb7133 View on GitHub
contribution may-affects-25.10 may-affects-26.3 may-affects-7.5 may-affects-8.1 may-affects-8.5 severity/major sig/sql-infra type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

```
CREATE TABLE ir(id INT PRIMARY KEY, c INT);
INSERT INTO ir VALUES (1, 10);

INSERT INTO ir VALUES (1, 99) AS new ON DUPLICATE KEY UPDATE c = new.c;
-- ERROR 1054 (42S22): Unknown column 'new.c' in 'field list'

INSERT INTO ir VALUES (1, 99) AS new(a, b) ON DUPLICATE KEY UPDATE c = b;
-- ERROR 1054: Unknown column 'b' in 'field list'

INSERT INTO ir SET id=1, c=99 AS new ON DUPLICATE KEY UPDATE c = new.c; -- 同断
PREPARE s FROM 'INSERT INTO ir VALUES (?, ?) AS new ON DUPLICATE KEY UPDATE c = new.c';
-- ERROR 1054(PREPARE 阶段即失败)
```

### 2. What did you expect to see? (Required)
The MySQL 8.0.19 row-alias syntax is accepted by the parser but the executor never binds the alias — precisely the feature's core use case (referencing the would-be inserted row). Column-name aliases (AS new(m,n)) and the PREPARE path fail identically; alias column-count mismatch is not validated. The upstream commit touched only parser/AST with no executor wiring.

```
mysql> select version()
-> ;
+-----------+
| version() |
+-----------+
| 9.7.2 |
+-----------+
1 row in set (0.00 sec)

mysql> CREATE TABLE ir(id INT PRIMARY KEY, c INT);
Query OK, 0 rows affected (0.02 sec)

mysql> INSERT INTO ir VALUES (1, 10);
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> INSERT INTO ir VALUES (1, 99) AS new ON DUPLICATE KEY UPDATE c = new.c;
Query OK, 2 rows affected (0.00 sec)

mysql> -- ERROR 1054 (42S22): Unknown column 'new.c' in 'field list'
mysql>
mysql> INSERT INTO ir VALUES (1, 99) AS new(a, b) ON DUPLICATE KEY UPDATE c = b;
Query OK, 0 rows affected (0.00 sec)

mysql> -- ERROR 1054: Unknown column 'b' in 'field list'
mysql>
mysql> INSERT INTO ir SET id=1, c=99 AS new ON DUPLICATE KEY UPDATE c = new.c; -- 同断
Query OK, 0 rows affected (0.00 sec)

mysql> PREPARE s FROM 'INSERT INTO ir VALUES (?, ?) AS new ON DUPLICATE KEY UPDATE c = new.c';
Query OK, 0 rows affected (0.01 sec)
Statement prepared

mysql> -- ERROR 1054(PREPARE 阶段即失败)
```

### 3. What did you see instead (Required)
```
mysql> CREATE TABLE ir(id INT PRIMARY KEY, c INT);
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO ir VALUES (1, 10);
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> INSERT INTO ir VALUES (1, 99) AS new ON DUPLICATE KEY UPDATE c = new.c;
ERROR 1054 (42S22): Unknown column 'new.c' in 'field list'
```

### 4. What is your TiDB version? (Required)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.