pingcap / pingcap/tidb

sql returns incorrect msg: Column 'xx' in field list is ambiguous

Open
#60,609 1 comment 0 reactions 0 assignees View on GitHub
affects-8.5 may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 may-affects-8.1 severity/major sig/execution 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)

DROP TABLE /*! IF EXISTS*/ mysql_1;
CREATE TABLE `mysql_1` (
`col_int_auto_increment` int(10) AUTO_INCREMENT,
`col_pk_char` char(60) not null,
`col_pk_varchar` varchar(60) not null,
`col_pk_date` date not null,
`col_int` int,
`col_int__1` int,
`col_int_8` int(8),
`col_int_8__1` int(8),
`col_bigint` bigint,
`col_smallint` smallint,
`col_tinyint` tinyint,
`col_float` float,
`col_double` double,
`col_numeric` numeric,
`col_bit` bit,
`col_bit__1` bit,
`col_enum` enum ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'),
`col_set` set ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'),
`col_char_3` char(3),
`col_char_255` char(255),
`col_varchar_1` varchar(1),
`col_varchar_64` varchar(64),
`col_varchar_2048` varchar(2048),
`col_binary_8` binary(8),
`col_varbinary_8` varbinary(8),
`col_date` date,
`col_time` time,
`col_datetime` datetime,
`col_timestamp` timestamp ,
`col_year` year,
`col_text` text,
`col_bool` bool,
`col_boolean` boolean,
`col_longtext` longtext,
`col_mediumtext` mediumtext,
`col_tinyblob` tinyblob,
`col_mediumblob` mediumblob,
`col_longblob` longblob,
`col_blob` blob,
/*Indices*/
KEY `prefix_index2` (`col_char_255`(10)),
KEY `prefix_index1` (`col_text`(15)),
KEY `functional_index2` (`col_datetime`,`col_date`),
KEY `functional_index1` (`col_enum`,`col_year`,`col_int`),
KEY k2 (`col_int`,`col_char_255`),
KEY k1 (`col_pk_varchar`),
primary key (`col_int_auto_increment`,`col_pk_varchar`,`col_datetime`,`col_int`,`col_date`)) ;
ALTER TABLE `mysql_1` DISABLE KEYS;

select * from mysql_1 t1 where col_pk_date = '1999-05-27' and exists ( SELECT 1 FROM ( mysql_1 a1 RIGHT OUTER JOIN mysql_1 a2 ON ( t1.col_int_auto_increment IN ( SELECT col_bigint FROM ( SELECT DISTINCT a1.col_bigint FROM ( SELECT DISTINCT a1.col_bigint FROM mysql_1 a1 NATURAL RIGHT JOIN mysql_1 a2 NATURAL RIGHT JOIN mysql_1 a4 WHERE ( a4.col_int IS NULL ) ) a1 ) mm ) AND t1.col_bit IS NULL ) ) ) /* QNO 15070 CON_ID 2407531720 */ ;

### 2. What did you expect to see? (Required)
results from mysql8:
MySQL [test1]> select * from mysql_partition_list_subpartition_key_1 t1 where col_pk_date = '1999-05-27' and exists ( SELECT 1 FROM ( mysql_partition_list_subpartition_hash_1 a1 RIGHT OUTER JOIN mysql_partition_list_subpartition_hash_2 a2 ON ( t1.col_int_auto_increment IN ( SELECT col_bigint FROM ( SELECT DISTINCT a1.col_bigint FROM ( SELECT DISTINCT a1.col_bigint FROM mysql_partition_range_subpartition_key_3 a1 NATURAL RIGHT JOIN mysql_partition_list_subpartition_hash_2 a2 NATURAL RIGHT JOIN mysql_partition_range_subpartition_hash_2 a4 WHERE ( a4.col_int IS NULL ) ) a1 ) mm ) AND t1.col_bit IS NULL ) ) ) /* QNO 15070 CON_ID 2407531720 */ ;
Empty set (0.01 sec)

### 3. What did you see instead (Required)
mysql> select * from mysql_1 t1 where col_pk_date = '1999-05-27' and exists ( SELECT 1 FROM ( mysql_1 a1 RIGHT OUTER JOIN mysql_1 a2 ON ( t1.col_int_auto_increment IN ( SELECT col_bigint FROM ( SELECT DISTINCT a1.col_bigint FROM ( SELECT DISTINCT a1.col_bigint FROM mysql_1 a1 NATURAL RIGHT JOIN mysql_1 a2 NATURAL RIGHT JOIN mysql_1 a4 WHERE ( a4.col_int IS NULL ) ) a1 ) mm ) AND t1.col_bit IS NULL ) ) ) /* QNO 15070 CON_ID 2407531720 */ ;
ERROR 1052 (23000): Column 'col_bigint' in field list is ambiguous

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

mysql> select tidb_version();
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.5.1
Edition: Community
Git Commit Hash: fea86c8e35ad4a86a5e1160701f99493c2ee547c
Git Branch: HEAD
UTC Build Time: 2025-01-16 07:38:34
GoVersion: go1.23.4
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

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.