Skip to content

recursive CTE / correlated aggregate: non-equality predicate in scalar subquery still blocked by 20102 #30872

Closed as not planned

Description

@XuPeng-SH

Summary

After #30082 (commit 75ff736, "allow GROUP BY and HAVING in recursive CTE scalar subqueries"), the equality-predicate form works, but the non-equality predicate form is still rejected with 20102.

Repro (fresh main@3ad9adbb4c, single-node mo-service -launch)

with recursive r(n) as (select 1 union all select n+1 from r where n < 5)
select n,
       (select count(*) from r r2 where r2.n <= r.n group by r2.n having r2.n > 0) as cnt
from r order by n;

Actual:

ERROR 20102 (HY000): aggregation with non equal predicate in scalar subquery
will be supported in future version is not yet implemented

The equality variant of the same shape is accepted and returns correct rows:

with recursive r(n) as (select 1 union all select n+1 from r where n < 5)
select n, (select count(*) from r r2 where r2.n = r.n group by r2.n having r2.n > 0) as cnt
from r order by n;
-- 1|1  2|1  3|1  4|1  5|1

A plain (non-recursive) table with the same non-equality correlated aggregate in a scalar subquery is also rejected, so this is not specific to CTEs:

create table t (g int, x int);
insert into t values (1,10),(1,20),(2,5);
select g, (select sum(x) from t t2 where t2.x <= t.x group by t2.g having sum(x) > 0) from t;
-- ERROR 20102 ...

Expected

MySQL 8.0 evaluates the correlated aggregate per outer row:

  • r.n = 3 → rows of r with n <= 3 grouped by n → count(*) = 1.

Notes

Please confirm whether the non-equality predicate can be routed through the same correlated-aggregate path, or whether this should be tracked as a separate planned limitation.

Evidence: local CGo build of main@3ad9adbb4c, isolated instance, differential run against base 7b911aea68.

Activity

  1. added
    kind/bug
    on Oct 22, 2026
  2. XuPeng-SH commented on Oct 23, 2026

    @XuPeng-SH
    ContributorAuthor

    Duplicate of #28298. That issue tracks the same non-equality correlated scalar-aggregate restriction, including GROUP BY/HAVING shapes. This recursive CTE case and the plain-table reproducer are retained as additional evidence on #28298. Closing this report is tracking consolidation only; no fix is claimed.

  3. added
    duplicate
    and removed on Oct 23, 2026
  4. XuPeng-SH commented on Oct 23, 2026

    @XuPeng-SH
    ContributorAuthor

    Duplicate tracking is consolidated in #28298. The recursive CTE and plain-table reproductions are preserved there as additional coverage; this closure does not indicate a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

duplicatekind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions