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

Got can't find column error when IN/NOT IN is used #37032

Closed
guo-shaoge opened this issue Aug 10, 2022 · 3 comments · Fixed by #37117
Closed

Got can't find column error when IN/NOT IN is used #37032

guo-shaoge opened this issue Aug 10, 2022 · 3 comments · Fixed by #37117
Assignees
Labels
affects-4.0 This bug affects 4.0.x versions. 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 severity/major sig/planner SIG: Planner type/bug This issue is a bug.

Comments

@guo-shaoge
Copy link
Collaborator

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

drop table if exists stu;
drop table if exists exam;

create table stu(id int, name varchar(100));
insert into stu values(1, null);

create table exam(stu_id int, course varchar(100), grade int);
insert into exam values(1, 'math', 100);

select * from stu where stu.name not in (select 'guo' from exam where exam.stu_id = stu.id);

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

select * from stu where stu.name not in (select 'guo' from exam where exam.stu_id = stu.id);
Empty set (0.001 sec)

3. What did you see instead (Required)

MySQL [test]> explain select * from stu where stu.name not in (select 'guo' from exam where exam.stu_id = stu.id);
ERROR 1105 (HY000): Can't find column Column#8 in schema Column: [test.stu.id,test.stu.name,test.exam.stu_id] Unique key: []

4. What is your TiDB version? (Required)

MySQL [test]> select tidb_version();
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()
   |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v6.2.0-alpha-671-gb150be820
Edition: Community
Git Commit Hash: b150be8200f3d44dbea20b09cd6521190bd3bcb1
Git Branch: master
UTC Build Time: 2022-08-10 13:08:34
GoVersion: go1.18
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: unistore |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.001 sec)
@guo-shaoge guo-shaoge added the type/bug This issue is a bug. label Aug 10, 2022
@ChenPeng2013
Copy link
Contributor

release-4.0、release-5.0、release-5.1、release-5.2、release-5.3 and release-5.4

MySQL [test]> select * from stu where stu.name not in (select 'guo' from exam where exam.stu_id = stu.id);
+------+------+
| id   | name |
+------+------+
|    1 | NULL |
+------+------+
1 row in set (0.00 sec)

@guo-shaoge
Copy link
Collaborator Author

release-4.0、release-5.0、release-5.1、release-5.2、release-5.3 and release-5.4

MySQL [test]> select * from stu where stu.name not in (select 'guo' from exam where exam.stu_id = stu.id);
+------+------+
| id   | name |
+------+------+
|    1 | NULL |
+------+------+
1 row in set (0.00 sec)

The old version doesn't give error, but its result is still wrong. (We expect empty result, like MySQL8.0).

@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 may-affects-6.2 labels Aug 10, 2022
@ChenPeng2013 ChenPeng2013 added affects-4.0 This bug affects 4.0.x versions. 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 labels Aug 10, 2022
@ti-chi-bot ti-chi-bot 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.0 This bug maybe affects 5.0.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.1 labels Aug 10, 2022
@winoros
Copy link
Member

winoros commented Aug 11, 2022

You can use NOT EXISTS as a workaround.

ti-chi-bot pushed a commit that referenced this issue Aug 24, 2022
…ubstitute in projection elimination of Apply de-correlation (#37117)

close #37032
ti-chi-bot pushed a commit that referenced this issue Jan 18, 2023
…ubstitute in projection elimination of Apply de-correlation (#37117) (#37354)

close #37032
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-4.0 This bug affects 4.0.x versions. 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 severity/major sig/planner SIG: Planner type/bug This issue is a bug.
Projects
None yet
6 participants