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 't1.col1' in 'having clause' #29084

Open
Alkaagr81 opened this issue Oct 25, 2021 · 3 comments
Open

ERROR 1054 (42S22): Unknown column 't1.col1' in 'having clause' #29084

Alkaagr81 opened this issue Oct 25, 2021 · 3 comments
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 refactor/new-name-resolution 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 t1,t2,t3;
create table t1 (col1 int, col2 varchar(5), col_t1 int);
create table t2 (col1 int, col2 varchar(5), col_t2 int);
create table t3 (col1 int, col2 varchar(5), col_t3 int);
insert into t1 values(10,'hello',10);
insert into t1 values(20,'hello',20);
insert into t1 values(30,'hello',30);
insert into t1 values(10,'bye',10);
insert into t1 values(10,'sam',10);
insert into t1 values(10,'bob',10);
insert into t2 select * from t1;
select sum(col1) from t1 group by col_t1,col1 having col_t1 in
 (select sum(t2.col1) from t2 group by t2.col2, t2.col1 having t2.col1 = t1.col1);

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

mysql> select sum(col1) from t1 group by col_t1,col1 having col_t1 in
 (select sum(t2.col1) from t2 group by t2.col2, t2.col1 having t2.col1 = t1.col1);
+-----------+
| sum(col1) |
+-----------+
|        40 |
|        20 |
|        30 |
+-----------+
3 rows in set (0.00 sec)

3. What did you see instead (Required)

mysql> select sum(col1) from t1 group by col_t1,col1 having col_t1 in 
(select sum(t2.col1) from t2 group by t2.col2, t2.col1 having t2.col1 = t1.col1);
ERROR 1054 (42S22): Unknown column 't1.col1' in 'having clause'

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 25, 2021
@morgo
Copy link
Contributor

morgo commented Oct 25, 2021

Verified against master:

tidb> select sum(col1) from t1 group by col_t1,col1 having col_t1 in
    ->  (select sum(t2.col1) from t2 group by t2.col2, t2.col1 having t2.col1 = t1.col1);
ERROR 1054 (42S22): Unknown column 't1.col1' in 'having clause'
tidb> SELECT tidb_version()\G
*************************** 1. row ***************************
tidb_version(): 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:32:56
GoVersion: go1.16.4
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)

@morgo morgo changed the title ERROR 1054 (42S22): for having clause ERROR 1054 (42S22): Unknown column 't1.col1' in 'having clause' Oct 25, 2021
@Yisaer
Copy link
Contributor

Yisaer commented Oct 26, 2021

/assign

@winoros winoros assigned winoros and unassigned Yisaer Nov 23, 2021
@winoros
Copy link
Member

winoros commented Nov 23, 2021

Seems that this one is something related with #26945. Let me have a deeper look.

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 refactor/new-name-resolution severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

9 participants