Skip to content

[Bug]: correlated column in CTE not supported #3304

Closed

Description

@aressu1985

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Environment

- Version or commit-id (e.g. v0.1.0 or 8b23a93):0.5.0
- Hardware parameters:
- OS type:
- Others:

Actual Behavior

[ERROR]
[SCRIPT FILE]: cases/expression/cte.sql
[ROW NUMBER]: 146
[SQL STATEMENT]: SELECT (WITH qn AS (SELECT t2.aa as a FROM t1),
qn2 AS (SELECT 3
a AS b FROM qn)
SELECT * from qn2 LIMIT 1)
FROM t1 as t2;
[EXPECT RESULT]:
(WITH qn AS (SELECT t2.aa as a FROM t1),
qn2 AS (SELECT 3
a AS b FROM qn)
SELECT * from qn2 LIMIT 1)
null
null
null
[ACTUAL RESULT]:
correlated column in CTE is not yet supported

[ERROR]
[SCRIPT FILE]: cases/expression/cte.sql
[ROW NUMBER]: 238
[SQL STATEMENT]: with qn as (SELECT s1 FROM t2)
select s1, s1 = ANY (select * from qn) from t1;
[EXPECT RESULT]:
s1 s1 = ANY (select * from qn)
a1 1
a2 1
a3 0
[ACTUAL RESULT]:
non-scalar subquery in SELECT clause will be supported in future version.

[ERROR]
[SCRIPT FILE]: cases/expression/cte.sql
[ROW NUMBER]: 242
[SQL STATEMENT]: with qn as (SELECT s1 FROM t2)
select s1, s1 = ANY (select * from qn) from t1;
[EXPECT RESULT]:
s1 s1 = ANY (select * from qn)
a1 1
a2 1
a3 0
[ACTUAL RESULT]:
non-scalar subquery in SELECT clause will be supported in future version.

[ERROR]
[SCRIPT FILE]: cases/expression/cte.sql
[ROW NUMBER]: 281
[SQL STATEMENT]: with qn as (select * from t2 where t2.b=t3.a)
select * from t3 where exists (select * from qn);
[EXPECT RESULT]:
Unknown column 't3.a' in 'where clause'
[ACTUAL RESULT]:
correlated column in CTE is not yet supported

[ERROR]
[SCRIPT FILE]: cases/expression/cte.sql
[ROW NUMBER]: 283
[SQL STATEMENT]: with qn as (select * from t2 where t2.b=t3.a)
select * from t3 where not exists (select * from qn);
[EXPECT RESULT]:
Unknown column 't3.a' in 'where clause'
[ACTUAL RESULT]:
correlated column in CTE is not yet supported

Expected Behavior

No response

Steps to Reproduce

No response

Additional information

No response

Activity

  1. added
    kind/bug
    bvt
    on Jun 23, 2022
  2. added this to the v0.5.0 milestone on Jun 23, 2022
  3. assigned and unassigned on Jun 24, 2022
  4. modified the milestones: v0.5.0, v0.6.0 on Jun 24, 2022
  5. assigned and unassigned on Jun 24, 2022
  6. aunjgr commented on Jun 24, 2022

    @aunjgr
    Contributor

    CTEs and literal subqueries are handled through different code path. Please create two separate issues.

  7. domingozhang commented on Jul 1, 2022

    @domingozhang
    Contributor

    correlated column is not in filter part of CTE. It can be not supported.

  8. added
    severity/s1
    on Jul 17, 2022
  9. changed the title [-][Bug]: correlated column in CTE and non-scalar subquery in SELECT clause not supported[/-] [+][Bug]: correlated column in CTE not supported[/+] on Jul 21, 2022
  10. aunjgr commented on Jul 21, 2022

    @aunjgr
    Contributor

    Non-scalar subquery in SELECT clause falls within the scope of #3312, and will be resolved by the same modification.

  11. added 2 commits that reference this issue on Jul 21, 2022
  12. sukki37 commented on Oct 29, 2022

    @sukki37
    Contributor

    @aunjgr any updates?

  13. assigned and unassigned on Nov 5, 2022
  14. aressu1985 commented on Nov 8, 2022

    @aressu1985
    ContributorAuthor

    fixed: e23e00f

    mysql> -- @bvt:issue#3304
    mysql> with qn as (select * from t2 where t2.b=t3.a)
    -> select * from t3 where exists (select * from qn);
    ERROR 20301 (HY000): invalid input: missing FROM-clause entry for table 't3'
    mysql>
    mysql> with qn as (select * from t2 where t2.b=t3.a)
    -> select * from t3 where not exists (select * from qn)
    -> ;
    ERROR 20301 (HY000): invalid input: missing FROM-clause entry for table 't3'
    mysql>

  15. added a commit that references this issue on May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bvtkind/bugseverity/s1triage/accepted

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions