pingcap / tidb

TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
https://pingcap.com
Apache License 2.0
37.34k stars 5.85k forks source link

Unexpected syntax error: Unknown column 'ref_0.c1' in 'where clause' #57594

Open r33s3n6 opened 1 day ago

r33s3n6 commented 1 day ago

Bug Report

1. Minimal reproduce step (Required)

create table t1 (c1 text);

-- good
select case when (EXISTS (select 1)) 
      then count(*) over (partition by 1) else 1 end from t1 as ref_0;
-- good
select case when (EXISTS (select 1 where ref_0.c1)) 
      then 1 else 1 end from t1 as ref_0;
-- bad
select case when (EXISTS (select 1 where ref_0.c1)) 
      then count(*) over (partition by 1) else 1 end from t1 as ref_0;

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

empty set.

3. What did you see instead (Required)

ERROR 1054 (42S22): Unknown column 'ref_0.c1' in 'where clause'

4. What is your TiDB version? (Required)

Release Version: v8.5.0-alpha-184-g1c059a1216
Edition: Community
Git Commit Hash: 1c059a1216db711e2cb56ea9f3d1ad8c23db6327
Git Branch: HEAD
UTC Build Time: 2024-11-21 04:56:22
GoVersion: go1.23.3
Race Enabled: false
Check Table Before Drop: false
Store: tikv