feat(frontend): add binder support for recursive CTE (WITH RECURSIVE)#24982
Open
faketygg wants to merge 1 commit intorisingwavelabs:mainfrom
Open
feat(frontend): add binder support for recursive CTE (WITH RECURSIVE)#24982faketygg wants to merge 1 commit intorisingwavelabs:mainfrom
faketygg wants to merge 1 commit intorisingwavelabs:mainfrom
Conversation
This is Phase 1 of recursive CTE support (tracking issue risingwavelabs#15135). It implements the binder changes to correctly parse, validate, and bind recursive CTEs. Planning/execution will be added in subsequent phases. Changes: - Remove the "RECURSIVE CTE is not supported" rejection in bind_with() - Add BindingCteState::Init and BindingCteState::RecursiveUnion variants - Implement two-pass binding: bind anchor first, register CTE schema, then bind recursive branch with self-reference resolution - Add BoundBackCteRef for recursive self-references inside CTE body - Add BoundShareInput::RecursiveCte for external references to bound recursive CTEs - Add Relation::BackCteRef variant with planner stub (bail_not_implemented) - Validate: must be UNION ALL, no ORDER BY/LIMIT/OFFSET/FETCH in CTE definition, schema column count must match between anchor and recursive - Add e2e tests for error cases and binding validation Signed-off-by: Yingjun_Wu (agent, powered by Claude Opus 4.6) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
|
Hi @yezizp2012 @chenzl25 @BugenZhao @kwannoel — this is Phase 1 of the recursive CTE feature (#15135). It implements binder-level support only (no planner/executor yet). Would appreciate a review when you have time! See the RFC at #15135 (comment) for the full implementation plan. — Yingjun_Wu (agent) |
Contributor
Author
|
CI Status: 17/18 jobs passed. The only failure is — Yingjun_Wu (agent) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 1 of recursive CTE support (tracking issue #15135).
This PR implements binder-level support for
WITH RECURSIVE, enabling the frontend to correctly parse, validate, and bind recursive CTEs. Planning and execution will be added in subsequent phases.What's changed:
RECURSIVE CTE is not supportedrejection inbind_with()BindingCteState::Init(placeholder during recursive binding) andBindingCteState::RecursiveUnion(fully-bound recursive CTE)Initstate, then bind recursive branch where self-references resolve viaBackCteRefBoundBackCteReffor recursive self-references inside the CTE bodyBoundShareInput::RecursiveCtefor external references to fully-bound recursive CTEsRelation::BackCteRefvariant withbail_not_implemented!planner stubUNION ALL, noORDER BY/LIMIT/OFFSET/FETCHin CTE definition, column count must match between anchor and recursive termsDesign decisions:
WITH RECURSIVEis only treated as recursive if its body isUNION ALL— non-recursive CTEs work normally even with theRECURSIVEkeyword (matching PostgreSQL behavior)UNION(withoutALL) gives a clear error message rather than a confusing "table not found"bail_not_implemented!for recursive CTE nodes — Phase 2 will addLogicalRecursiveUnionandLogicalCteRefplan nodesRelated:
Test plan
e2e_test/batch/basic/recursive_cte.slt.partwith tests for:not yet implementedat planning stage)UNIONwithoutALLerrorORDER BY/LIMITin CTE definition errorWITH RECURSIVEworks normallySigned-off-by: Yingjun_Wu (agent, powered by Claude Opus 4.6)
🤖 Generated with Claude Code