You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
recursive CTE / correlated aggregate: non-equality predicate in scalar subquery still blocked by 20102 #30872
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.
with recursive r(n) as (select1union allselect n+1from r where n <5)
select n,
(selectcount(*) from r r2 wherer2.n<=r.ngroup byr2.nhavingr2.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 (select1union allselect n+1from r where n <5)
select n, (selectcount(*) from r r2 wherer2.n=r.ngroup byr2.nhavingr2.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:
createtablet (g int, x int);
insert into t values (1,10),(1,20),(2,5);
select g, (selectsum(x) from t t2 wheret2.x<=t.xgroup byt2.ghavingsum(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.
The gate looks like a planning-time predicate-shape restriction rather than a semantic impossibility (the equality form reuses the same machinery).
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.
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.
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.
Activity
XuPeng-SH commentedon Oct 23, 2026
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.
XuPeng-SH commentedon Oct 23, 2026
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.