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 v6.1: ERROR 1105 (HY000): Can't find column test.tbl.id in schema Column: [Column#7] Unique key: [[test.tbl.id]] #35404

Closed
shawn0915 opened this issue Jun 15, 2022 · 4 comments · Fixed by #35415
Assignees
Labels
affects-6.0 affects-6.1 This bug affects the 6.1.x(LTS) versions. severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@shawn0915
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

drop table if exists tbl;
create table tbl (id int);
with t1 as (select id from tbl), t2 as (select a.id from t1 a join t1 b on a.id = b.id) select * from t2 where id in (select id from t2);

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

return success with empty set.

3. What did you see instead (Required)

ERROR 1105 (HY000): Can't find column test.tbl.id in schema Column: [Column#7] Unique key: [[test.tbl.id]]

4. What is your TiDB version? (Required)

SELECT tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v6.1.0
Edition: Community
Git Commit Hash: 1a89dec
Git Branch: heads/refs/tags/v6.1.0
UTC Build Time: 2022-06-05 05:15:11
GoVersion: go1.18.2
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.001 sec)

@shawn0915 shawn0915 added the type/bug The issue is confirmed as a bug. label Jun 15, 2022
@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.0 may-affects-6.1 labels Jun 15, 2022
@aytrack aytrack added affects-6.0 affects-6.1 This bug affects the 6.1.x(LTS) versions. and removed may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-6.0 may-affects-6.1 labels Jun 15, 2022
@AilinKid
Copy link
Contributor

AilinKid commented Jun 15, 2022

This is because the main select clause referred to the CTE t2 twice and cloned its schema in buildTableRef and BuildSelectSubq respectively. Nonetheless, it just forgets the wipe out the old schema column's hashcode, which will be used to map the parent column and child's column directly when doing the projection elimination. As a consequence, the join EQ-condition's columns will be mapped to a same left-child column causing resolveIndices chaos.

@AilinKid
Copy link
Contributor

I will file a PR later

@shawn0915
Copy link
Contributor Author

@aytrack @AilinKid thanks for following.

@shawn0915
Copy link
Contributor Author

mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v6.2.0-alpha
Edition: Community
Git Commit Hash: 9a77892ac8e513eba25813963de808310295d1ec
Git Branch: heads/refs/tags/v6.2.0-alpha
UTC Build Time: 2022-06-17 14:31:04
GoVersion: go1.18.2
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
Store: tikv
1 row in set (0.00 sec)

mysql> drop table if exists tbl;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> create table tbl (id int);
Query OK, 0 rows affected (0.10 sec)

mysql> with t1 as (select id from tbl), t2 as (select a.id from t1 a join t1 b on a.id = b.id) select * from t2 where id in (select id from t2);
Empty set (0.01 sec)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.0 affects-6.1 This bug affects the 6.1.x(LTS) versions. severity/major 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.

4 participants