Skip to content

fix(plan): reject recursive CTE anchor self-references - #32831

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
aptend:fix/astra-meow-32795
Nov 17, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:mainfrom
aptend:fix/astra-meow-32795

Conversation

@aptend

@aptend aptend commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #32795.

What this PR does / why we need it:

Reject a table reference that resolves to the exact recursive CTE declaration while its anchor is still being bound. This prevents repeated anchor binding from overflowing the planner stack. Same-name inner CTEs and aliases, schema-qualified real tables, legal recursive members, and existing recursive-member diagnostics retain their behavior.

Historical validation on upstream main f491aaab4519b29313c5747d3ce3b3f84e865c71 plus this change (the SQL service/BVT results below are not claimed as a new service run on e765c5fd44e842167d4271c37af6d25586511e16):

  • Native-provenance/CGO-enabled mo-cgo-test -mod=readonly -v -count=1 -timeout=300s -run '^TestRecursiveCteAnchorReentry$' ./pkg/sql/plan: 17/17 subtests passed, including typed errors, lexical controls and compiler-context reuse after rejection.
  • Full owning package mo-cgo-test -mod=readonly -v -count=1 -timeout=1500s ./pkg/sql/plan: 5045 top-level and 17949 direct subtests passed; exit 0.
  • Local pinned molint (147a3f213653) and golangci-lint (2.14.0) incremental SCA: changed package/tests plus 111 affected reverse-dependent packages; exit 0, 0 issues. Exact selector/command below.
  • Real source-bound service: the bad anchor returns 1064, followed by successful queries and finite recursion on the same typed connection. The exact public BVT passes 3/3 with nometa and 3/3 with strict metadata on the same instance. Both client processes and MO stop cleanly; implicit DB absence, the full TCP/TCP6/UDP/UDP6 window and removal of this run's owned data root were verified.

Current validation on upstream main e765c5fd44e842167d4271c37af6d25586511e16 plus the unchanged five-file change (single linear commit a6e41bd5698985730a7e470609d25c094663716e):

  • Rebase-only: no product or test source edits; all five approved file hashes and the complete diff are unchanged.
  • Current explicit 111-package incremental SCA with the repository-pinned molint and golangci-lint: exit 0, 0 issues.; exact command below.
  • Normal matching target, .agents/skills/mo-dev/scripts/mo-cgo-test -mod=readonly -v -count=1 -timeout=360s -short -tags matrixone_test -run '^TestPreparedTimeArithmeticOverMySQLProtocol$' ./pkg/embed: 19 RUN records, parent/package PASS, exit 0.
  • Matching CI race target, .agents/skills/mo-dev/scripts/mo-cgo-test -mod=readonly -race -v -count=1 -timeout=360s -short -tags matrixone_test -run '^TestPreparedTimeArithmeticOverMySQLProtocol$' ./pkg/embed: 19 RUN, 19 PASS, 0 FAIL, 0 race warnings, exit 0.

Limit: the original CI failure was a deferred DROP DATABASE timeout accompanied by log-service checker/heartbeat/propose timeouts. It was not reproduced by either standalone target. This rebase-only phase made no product/test-code change and does not claim an infrastructure diagnosis or complete parallel CI recovery.

Current e765 incremental SCA command (explicit 111-package selector)
make --no-print-directory static-check-selected STATIC_CHECK_PACKAGES="./cmd/mo-inspect ./cmd/mo-object-tool/ckp ./cmd/mo-service ./cmd/mo-tool ./pkg/backup ./pkg/bootstrap ./pkg/bootstrap/versions/v1_2_0 ./pkg/bootstrap/versions/v2_0_0 ./pkg/bootstrap/versions/v2_0_1 ./pkg/bootstrap/versions/v2_0_2 ./pkg/bootstrap/versions/v2_2_0 ./pkg/bootstrap/versions/v3_0_0 ./pkg/bootstrap/versions/v4_0_0 ./pkg/bootstrap/versions/v4_0_7 ./pkg/cdc ./pkg/cnservice ./pkg/datasync ./pkg/embed ./pkg/fileservice ./pkg/frontend ./pkg/frontend/test/mock_moserver ./pkg/fulltext/plugin/iscp ./pkg/fulltext2/plugin/iscp ./pkg/indexplugin/iscp ./pkg/iscp ./pkg/partitionprune ./pkg/proxy ./pkg/publication ./pkg/sql/colexec ./pkg/sql/colexec/adaptivetop ./pkg/sql/colexec/apply ./pkg/sql/colexec/deletion ./pkg/sql/colexec/dependent ./pkg/sql/colexec/dispatch ./pkg/sql/colexec/external ./pkg/sql/colexec/filter ./pkg/sql/colexec/fuzzyfilter ./pkg/sql/colexec/group ./pkg/sql/colexec/hashbuild ./pkg/sql/colexec/insert ./pkg/sql/colexec/limit ./pkg/sql/colexec/lockop ./pkg/sql/colexec/merge ./pkg/sql/colexec/mergeblock ./pkg/sql/colexec/mergeorder ./pkg/sql/colexec/mergetop ./pkg/sql/colexec/multi_update ./pkg/sql/colexec/offset ./pkg/sql/colexec/order ./pkg/sql/colexec/partition ./pkg/sql/colexec/postdml ./pkg/sql/colexec/preinsert ./pkg/sql/colexec/productl2 ./pkg/sql/colexec/sample ./pkg/sql/colexec/shuffle ./pkg/sql/colexec/spillutil ./pkg/sql/colexec/table_clone ./pkg/sql/colexec/table_function ./pkg/sql/colexec/table_scan ./pkg/sql/colexec/top ./pkg/sql/colexec/value_scan ./pkg/sql/colexec/vectorquery ./pkg/sql/colexec/vectorscan ./pkg/sql/colexec/window ./pkg/sql/compile ./pkg/sql/compile/siriusbridge ./pkg/sql/crt ./pkg/sql/plan ./pkg/sql/plan/explain ./pkg/sql/plan/substrait ./pkg/tests/arrowload ./pkg/tests/dml ./pkg/tests/issues ./pkg/tests/issues/internal/joinspill ./pkg/tests/issues/isolated ./pkg/tests/partition ./pkg/tests/service ./pkg/tests/shard ./pkg/tests/sqlintegration ./pkg/tests/sqlintegration/multicn ./pkg/tests/testutils ./pkg/tests/txn ./pkg/tests/upgrade ./pkg/tnservice ./pkg/tools/checkpointtool ./pkg/tools/checkpointtool/interactive ./pkg/txn/storage/tae ./pkg/util/status ./pkg/util/test ./pkg/vectorindex/hnsw/plugin/iscp ./pkg/vectorindex/indexfile ./pkg/vectorindex/ivfflat/plugin/iscp ./pkg/vm/engine/ckputil ./pkg/vm/engine/disttae ./pkg/vm/engine/disttae/cache ./pkg/vm/engine/disttae/logtailreplay ./pkg/vm/engine/readutil ./pkg/vm/engine/tae/db ./pkg/vm/engine/tae/db/checkpoint ./pkg/vm/engine/tae/db/gc/v3 ./pkg/vm/engine/tae/db/test ./pkg/vm/engine/tae/db/test/compatibility ./pkg/vm/engine/tae/db/testutil ./pkg/vm/engine/tae/logtail ./pkg/vm/engine/tae/logtail/service ./pkg/vm/engine/tae/rpc ./pkg/vm/engine/tae/testutils/config ./pkg/vm/engine/test ./pkg/vm/engine/test/testutil ./pkg/vm/pipeline ./test/manual/issue28140"

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: a6e41bd5698985730a7e470609d25c094663716e

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: a6e41bd5698985730a7e470609d25c094663716e

Assessment: approve

The narrow guard reuses CTE declaration identity and existing binding state to reject anchor reentry while preserving lexical shadowing and valid recursion. No actionable findings remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • Reviewed all five changed files, affected binding consumers, linked issue 32795 and all three discussion entries. Saved review-plan.md and discussion-assessment.json.

  • Reused frozen exact-head successful UT, SCA, coverage and both multi-CN BVT statuses; traced repository selectors to the planner package and recursive_cte fixtures.

  • git diff --check and gofmt -d passed with no output; receipts: checks/1794885944516644601-2.json and checks/1794885950717492757-2.json.

  • Corrected integrity audit passed: source clean, all five files match HEAD, frozen delta matches apart from its terminal newline, and discussion coverage is complete. Receipt: checks/1794886095601158606-2.json.

Limitations:

  • No fresh local Go or server execution. Raw CI per-test logs and external reusable-workflow definitions were not supplied; historical author test counts were not treated as current-head results.

@mergify mergify Bot added the queued label Nov 17, 2026
@mergify

mergify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as 27bb33d at 05:14 UTC

1 h 44 min in the queue, 1 h 43 min of it CI.

So far

  • ✅ Entered the queue Tue 17 Nov, 03:29 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Passed · in place
  • ✅ Merged 05:14 · 27bb33d · squash
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

This branch was previously deployed

1 inactive deployment
ci — 9fd5fcd2 Deployed Nov 17, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WITH RECURSIVE CTE referencing recursive table twice crashes server (fatal error: stack overflow)

3 participants