Repository navigation
Description
Description
An invalid recursive CTE whose two UNION members both read the CTE, with no nonrecursive anchor, causes the entire MatrixOne service process to exit with fatal error: stack overflow. MySQL 8.0 rejects the statement normally with error 3574. A SQL validation error must never take down the service.
Environment
- Branch:
main - Commit:
c8accd138bb91144050ff173100afd7a71a02888(fixed Nov 12 daily main) - Deployment: task-owned local isolated cluster, one LogService, one TN, two CN listeners at 16001/16002 in one
mo-serviceprocess; MySQL 8.0.45 local socket as oracle.
Steps to reproduce
No table or data is needed:
SELECT 1;
WITH RECURSIVE qn AS (
SELECT 1 FROM qn
UNION ALL
SELECT 1 FROM qn
)
SELECT * FROM qn;Run the invalid query from either CN listener. Then reconnect and run SELECT 1 again.
Actual behavior
- Client receives
ERROR 2013: Lost connection to MySQL server during query. - Both local CN listeners refuse new connections because the
mo-serviceprocess exited. - Service log contains
runtime: goroutine stack exceeds 1000000000-byte limitfollowed byfatal error: stack overflow. - The repeated stack segment is
QueryBuilder.buildTable→bindRecursiveCte→bindCte→buildTable, includingpkg/sql/plan/query_builder.go:13852,:14335,:14390,:6037, and:6305.
Expected behavior
Reject the SQL with a normal syntax/recursive-CTE validation error, keep the service available, and leave state unchanged. MySQL 8.0.45 returns:
ERROR 3574: Recursive Common Table Expression 'qn' should have one or more non-recursive query blocks followed by one or more recursive ones
Stability and controls
- Reproducer: 3/3 service exits. First from the adapted official MySQL
mysql-test/include/with_recursive.inc:31case on CN1; then minimal stand-alone SQL on CN2 and CN1 after independent service restarts. - Before each minimal run, MO
SELECT 1succeeded; MySQL returned the expected error and stayed available. A bounded legal recursive CTE returned(1),(2),(3)in both databases in three independent fresh schemas. After each MO crash, reconnect failed; after restarting the owned service, both CN listeners returnedgit_version() = c8accd138bandSELECT 1normally. - The failing SQL is read-only, requires no fixture, and cannot alter data. No data atomicity claim beyond this read-only case is made.
Evidence
- Official source case:
mysql-test/include/with_recursive.inc:31at MySQL source SHA9fc8d60003b4eee32767c1e30942f222c3508c31(8.0.46 test source). The adapted replay recorded both MySQL error 3574 and MO connection loss at event 17. - Local artifacts:
/private/tmp/mo-group32455-H2kxsk/mysql-cte-replay-20261112-132952/events.jsonl,/private/tmp/mo-group32455-H2kxsk/cte-stack-probe-16002-1794461625949621000.json,/private/tmp/mo-group32455-H2kxsk/cte-stack-probe-16001-1794461690065478000.json. - Local owned service log:
/private/tmp/mo-group32455-H2kxsk/sdk-main-20261112-run/server.log, threefatal error: stack overflowoccurrences. Relevant excerpt:
runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow
github.com/matrixorigin/matrixone/pkg/sql/plan.(*QueryBuilder).buildTable
pkg/sql/plan/query_builder.go:14390
github.com/matrixorigin/matrixone/pkg/sql/plan.(*QueryBuilder).bindRecursiveCte
pkg/sql/plan/query_builder.go:6037
github.com/matrixorigin/matrixone/pkg/sql/plan.(*QueryBuilder).bindCte
pkg/sql/plan/query_builder.go:6305
Code analysis
The stack proves unbounded planner recursion while binding a CTE with no anchor; it is not an executor error or expected SQL rejection. In pkg/sql/plan/query_builder.go:13041, splitRecursiveMemberWithMode removes the self-referencing right UNION member, but the remaining left member also references qn. There is no check that the final left member is nonrecursive before bindRecursiveCte binds it as the initial/anchor statement at :6023-6037. That binding resolves qn through buildTable/bindCte and repeats indefinitely. This is the confirmed planner path for this shape; the appropriate validation/error placement still needs a fix design.
Regression coverage
Add a SQL BVT/MOTR case based on the minimal statement, asserting a bounded SQL error and SELECT 1 on both CN listeners afterward; add a planner unit test for two self-referencing UNION members with no anchor. Preserve a legal bounded recursive CTE control.
Related
- Different closed issues: [Bug]: Recursive CTE self-reference in a subquery returns an internal planner error #25958 is a nested recursive self-reference producing an internal planner error but not a process exit; Critical Bug: Panic error in recursive CTE with WHERE conditions #23080 is an executor vector index-out-of-range panic on a valid recursive CTE. Neither covers this no-anchor planner stack overflow.
- This reproducer came from MySQL's
with_recursive.testcorpus, not from [Bug]: Controlled tombstone/data merge interleaving resurrects rows; UPDATE amplifies 256 leases to 2.15M rows #31853. No comment was added to [Bug]: Controlled tombstone/data merge interleaving resurrects rows; UPDATE amplifies 256 leases to 2.15M rows #31853.
Activity
XuPeng-SH commentedon Nov 29, 2026
Consolidated duplicate #32601 here before its requested deletion.
Additional independent evidence retained from #32601:
e2459cc55f4b514893e19732743460bc5f16d552(2026-11-09), macOS arm64 with 16 GiB RAM, using the single-node-launch etc/launch.tomldeployment. The same no-anchorUNION ALLstatement terminated the combinedmo-serviceprocess in two standalone runs and once during official-suite replay.ERROR 2013; later connections were refused. No panic or stack trace was emitted to fd. That missing log does not establish a different root cause: the SQL and failure boundary are the same as above, while this issue retains the independently captured stack-overflow trace.SELECT 1 AS a UNION ALL SELECT 1 FROM qn) succeeds; the no-UNION pure self-reference (WITH RECURSIVE qn AS (SELECT 1 FROM qn) ...) is rejected without crashing. This further isolates the failure to the UNION shape's missing anchor validation.Ariznawlll commentedon Nov 30, 2026
QA 验收通过(最新 main)
版本与方法
383c17fb4bc6e150bd5b5fe8a2408ce298dc4c6c;关闭前再次解析仍为该 SHA。SELECT git_version()核对到上述完整 SHA。逐轮覆盖与结果:3/3 PASS
initial statement of Recursive Common Table Expression,没有连接丢失或服务退出。(7);合法递归 CTE 精确返回(1),(2),(3)。fatal error、stack overflow或goroutine stack exceeds,最终 runner 正常退出。三轮日志 SHA256:
ae04eab871a4c087fc703d37cc5e61361bc92ead2d014cc64a489303aaaa7054319e0b88ac612e2716ec9571dcd1e7af379e462fb89cbe3171af50553ebdc2207bdbd96408e170d6cf9af2d4716b58dcac9655a1e8cbff8956751c6ef692f00cMOTR 回归与 CI 状态
原始 canonical Issue #32600 的回归已存在于
issue_32601_recursive_anchor.py,并已进入 matrixorigin/motr PR 374,当前 head65059e95c10936aeb601a81a99a974ef351d2377;无需新增重复用例。截至评论时,hashbuild-boundary为 FAILED,linux、HA、两个branch-acceptance、main-native-sql、main-native-engine等仍为 pending(queued/in_progress),daily-42为 SKIPPED。本单关闭依据是上述当前 SHA 的真实服务验收,不把其他 workflow 或 pending 状态当作通过证据。结论:无 anchor recursive CTE 导致整个服务退出的原始问题已在最新 main 按双 CN 原始复现、扩展形态、合法对照和拒绝后健康检查通过验收,关闭为
COMPLETED。