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
[Bug]: Recursive CTE rejects UNION DISTINCT with a single self-reference #25955
Latest main at 3046f14d94b3f1a25839eeeb65729b64f85ac647.
What happened?
A recursive CTE with a single recursive-table reference is rejected when the set operator is UNION or UNION DISTINCT. The error claims that the recursive table is referenced more than once, although it appears exactly once.
The equivalent UNION ALL statement succeeds, and MySQL 8.0.45 accepts both UNION and UNION DISTINCT variants.
How to reproduce
WITH RECURSIVE r(n) AS (
SELECT1UNION DISTINCT
SELECT n +1FROM r WHERE n <10
)
SELECTCOUNT(*), SUM(n), MAX(n) FROM r;
Actual result
ERROR 1064 (HY000): SQL parser error: In recursive query block of Recursive Common Table Expression r, the recursive table must be referenced only once, and not in any subquery
Expected result
The statement should succeed and return:
10 55 10
Additional notes
Replacing UNION DISTINCT with UNION produces the same failure.
Replacing it with UNION ALL succeeds.
The MySQL grammar in MatrixOne parses UNION DISTINCT; the failure occurs later while binding the recursive CTE.
Activity
Ariznawlll commentedon Aug 5, 2026
测试版本
maine31ee06042bc708ac5620a579715e07ec31c21b6原问题验证
递归 CTE 使用
UNION DISTINCT的原始能力已恢复。数列用例正确返回 10 行、SUM=55, MAX=10,没有重复或提前终止。Happy Path 覆盖
UNION DISTINCT递归数列返回 10 行、SUM=55, MAX=10。UNION同义写法得到相同结果。1,未发生死循环。UNION ALL对照路径保持原有语义。Unhappy Path 覆盖
白盒验证
Focused planner UT
TestRecursiveUnionDistinctPlan与TestRecursiveUnionRejectsMixedModes均通过。回归测试
测试证据
b770136206c88435a51599e4b317e522eddfd085。15a2d07c687a62a0984cf62846b092912a28c0f1。测试结论
测试通过。