Repository navigation
Description
Description
A valid recursive CTE with multiple recursive UNION ALL members silently omits a row when a later recursive member consumes a row produced in the preceding recursive round. The query succeeds, but MatrixOne returns an incomplete result compared with MySQL 8.0.45.
Environment
- Branch:
main - Commit:
bbfc12bab4f410c26dbf06aa694acba51aba1734 - Deployment: isolated local MatrixOne service with one LogService, one TN, and one CN listener (
127.0.0.1:16111).SELECT git_version()returnedbbfc12bab4. - Oracle: MySQL 8.0.45.
Steps to reproduce
Run this SQL; it needs no tables or fixture data:
WITH RECURSIVE r(step, v) AS (
SELECT 0, 10
UNION ALL
SELECT 1, v + 1 FROM r WHERE step = 0
UNION ALL
SELECT 2, v + 3 FROM r WHERE step = 1
)
SELECT step, v FROM r ORDER BY step;Actual behavior
MatrixOne returns only:
(0, 10)
(1, 11)
The statement succeeds, but (2, 14) is missing. This was reproduced 3/3 on the commit above. Swapping the order of the two recursive members still reproduces the missing row 3/3.
Expected behavior
MySQL 8.0.45 returns all three rows, on 3/3 executions:
(0, 10)
(1, 11)
(2, 14)
MatrixOne should also return (2, 14), because the second recursive member matches the row (1, 11) produced by the prior recursive round.
Stability and controls
- The multi-member reproducer: MySQL 3/3 returns 3 rows; MatrixOne 3/3 returns 2 rows.
- A logically equivalent single-recursive-member chain returns all 3 rows on both engines in 3/3 executions.
- A two-member control where both members consume the anchor/frontier returns all expected rows on both engines in 3/3 executions.
- No table or persistent data is changed by these read-only queries.
Evidence
The row sets above are from direct executions against MySQL 8.0.45 and the isolated service reporting git_version() = bbfc12bab4. The wrong result was stable with the original and member-order-swapped forms; the controls remained correct.
Code analysis
The current planner creates a recursive source step for each member in pkg/sql/plan/query_builder.go:6063-6157. Runtime frontier scheduling is implemented in pkg/sql/colexec/dependent/recursive.go:135-179, with recursive-member selection at :157 and the next-round reset at :179; MergeCTE consumes and caches recursive batches in pkg/sql/colexec/mergecte/mergecte.go:111-166. These are the first paths to inspect for the missing later-generation row. The SQL-level result mismatch is confirmed; the precise root cause is not asserted here.
Regression coverage
Add a runtime SQL regression with two recursive members where the later member can only produce a row from the preceding recursive round. Keep controls for the equivalent single-member chain and for two members that both consume the same frontier; assert the full ordered row set.
Related
This is distinct from #32600 and #32601: those report invalid recursive CTE shapes that terminate the service, while this valid anchored CTE succeeds and returns incomplete data.
Activity
[Bug] Fix multi-member recursive CTE frontier handling (#32828)
XuPeng-SH commentedon Nov 17, 2026
修复已合入 main,转交 QA 验证,不代表验收通过或关闭。
关联 PR:#32828;merge SHA:
43addc16ba30c3e5a0feb11447078092a5fc3953(2026-11-17 08:23 UTC),PR head:a05ccabc2682f69c5343b61af82f2e6bcf3e9c4c。修复范围:recursive member 即使当前 frontier 为空也继续转发 round marker,由共享 recursive sink 在全局 post-DISTINCT frontier 为空时终止;包含 recursive scan 的 join 避开可能让 marker 越过缓冲数据的 shuffle,保留 broadcast 路径。
已有验证证据:PR 作者报告 dispatch/planner 全量 race、嵌入集群取消及 prepared statement 复用回归、2 CN 上 mo-tester 分布式用例 11/11 两轮通过,以及 vet/molint/增量 lint。review 对
74545ab8a1e547bc251d1d1ea95028b89cb7c684的记录为 approve:6 个定向回归、5 个相关包普通测试,dispatch 回归各 100 次,取消/复用 2 次;两个 CN coordinator 各执行 11 条维护 SQL 并断言 6 组精确结果,base-dispatch 负对照按预期失败。首次 planner race 超过 240 秒,未改包后在 600 秒界限内通过。这些是已记录的历史验证,本次仅核对正文、完整评论/review 与补丁,未重新跑测试,不能据此声称最终 merge SHA 已独立复测。QA 边界:复验原始用例完整返回
(0,10),(1,11),(2,14),并验证成员换序、单成员链/共同消费 frontier 对照、多轮空成员、UNION DISTINCT 收敛;同时覆盖 #32799 跨代消费不挂起、recursive table join、LIMIT、取消和 prepared statement 复用。递归 join 使用 broadcast 可能增加 build-side 内存,不具备 shuffle-only spill/retry;大 build、内存压力与性能未由上述测试证明,应单独验证,不作性能提升承诺。无已核实当前反例或未完成开发 follow-up,交接 Ariznawlll 继续验收。Ariznawlll commentedon Nov 17, 2026
Still reproducing on latest main tip (919c9fc32f) — re-verified 2026-11-17.
Ran the exact repro on a self-built main@919c9fc32f instance (isolated ports;
git_version()confirmed):Actual (3/3): returns only
(0,10), (1,11)— row(2,14)is still missing. Member-order swapped variant also still loses the row (3/3).Also re-verified on the 4.2-dev branch tip (
e8fd84b331f): identical behavior —(2,14)missing (3/3). So the multi-member later-generation consumption defect is present on both current branch tips; the fix has not landed on either branch yet.Ariznawlll commentedon Nov 18, 2026
验收结论:main 修复有效;4.2-dev 仍缺后续代行,本 issue 保持 OPEN
本轮使用包含 #32828 的新 main 实例重新验证,纠正此前基于旧 main 实例的“仍缺行”结论。版本由实际 SQL 查询确认,并检查了修复 commit 的祖先关系。
1. main:原 issue 及换序场景已通过
git_version() = 7fc45a2be2424d887199c5949362855cbacfe30fversion() = 8.0.30-MatrixOne-v1.3.043addc16ba30c3e5a0feb11447078092a5fc3953已确认是该 main 的祖先。原始 SQL 和交换两个 recursive member 顺序的 SQL 均完整返回:
相关扩展场景也实际执行通过:
s IN (0,1):完整 5 行,及时返回;UNION DISTINCT跨代消费及全局 DISTINCT 收敛:行集正确;(0,0),(1,0),(2,0),(2,1),(3,0),(3,0);(0,0),(1,10),(2,30),(3,60),(100,110);LIMIT 1:返回(0,0)。2. 取消、prepared 与代码路径:实际 PASS
以下测试均先用
-test.list确认存在,再实际运行:TestRecursiveCTEMultiMemberCancellationAndPreparedReuse:PASS (4.28s)。真实 embedded 1-CN 集群、fault point、第二连接KILL QUERY、中断错误及 SQLSTATE70100、同 prepared statement 复用得到 5、同 connection id 和SELECT 1恢复均通过。TestDispatchRecursiveCTEMemberForwardsEmptyRoundMarker、TestDispatchIntermediateForwardsRecursiveRoundMarker、TestDispatchRecursiveSinkStopsOnlyAfterEmptyGlobalFrontier:3/3 PASS。TestCompileRecursiveProbeJoinUsesUnshuffledBroadcast:PASS。TestDetermineShuffleForJoinSkipsRecursiveSubtrees:PASS,含 remap 前后及左右子树的 4 个子场景。3. 4.2-dev:原问题仍然可复现,验收失败
运行实例:
git_version() = 7400cae392e90fa94b8cf54dc8520c3c13647884,version() = 8.0.30-MatrixOne-v4.2.9。同一原始查询独立执行时只返回:
缺少
(2,14)。本轮又连续执行两次,均得到相同的两行。该失败是结果集不完整,不是超时,也不是 crash。同一 4.2 实例上的 #32799 原始跨代查询另有客户端 20 秒超时且未返回结果的反例,服务随后仍可连接。远端
4.2-dev当前为1920dc5c25758003315af6617b6ff6b37bf3fbf7,不包含 #32828;7400cae392..1920dc5c对相关dispatch.go/shuffle.go没有差异。此处没有把源码检查冒充为对1920dc5c实例的运行验证。请完成 4.2-dev 的适配/移植,再复验原始及换序场景。4. motr 回归
14_issue_regression.issue_32799_32612_recursive_cte_members,提交9139e7e16e51caa54abedf56e0c4bac4553a8f16。run-1794979502515422000:1/1 PASS;replayrun-1794979508415319000:1/1 PASS;repeat 2run-1794979509820925000:2/2 PASS,SKIP=0。累计 repeat 内部断言 20/20 PASS;脚本的stmts=1只是包装层计数。5. 未覆盖边界及交接
本轮没有重新执行真实多 CN BVT、重启、race、大 build 内存压力、shuffle-only spill/retry 或性能测试,PR 作者的 2-CN/race 历史记录不计为本轮实测。MySQL 对照端口本轮无服务,未重新执行 MySQL;行集依据原始确定性递归语义。
最终结论:main 的 #32612 原始及扩展回归通过,但 4.2-dev 仍明确缺
(2,14),所以双分支验收不通过、不能关闭。请研发处理 4.2-dev 修复后转回 QA。