-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[refactor](rec_cte)recursive-CTE refactor #59872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
|
run buildall |
b51cdc7 to
9f75bd8
Compare
|
run buildall |
TPC-H: Total hot run time: 31820 ms |
TPC-DS: Total hot run time: 173839 ms |
ClickBench: Total hot run time: 26.76 s |
FE UT Coverage ReportIncrement line coverage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the recursive CTE implementation in Apache Doris's Frontend by replacing the legacy RecursiveCTE model with a clearer RecursiveUnion model. The refactor separates anchor (initial rows) and producer (recursive body) responsibilities and makes work-table references explicit.
Changes:
- Introduced new RecursiveUnion model with anchor/producer/work-table reference sentinel nodes
- Removed legacy RecursiveCte/RecursiveCteScan classes and replaced with new implementation
- Updated type equality checks for recursive CTE compatibility
Reviewed changes
Copilot reviewed 56 out of 56 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| PhysicalWorkTableReference.java | New physical node for work table reference |
| LogicalWorkTableReference.java | New logical node for work table reference |
| PhysicalRecursiveUnion*.java | New physical nodes for recursive union, anchor, and producer |
| LogicalRecursiveUnion*.java | New logical nodes for recursive union, anchor, and producer |
| RecursiveCteScanNode.java | Simplified scan node, removed ScanNode inheritance |
| ThriftPlansBuilder.java | Enhanced documentation for recursive CTE handling |
| StatsCalculator.java | Updated statistics calculation for new nodes |
| ColumnPruning.java | Removed legacy recursive CTE pruning logic |
| Test files | Updated to use new API |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return false; | ||
| } | ||
| PhysicalWorkTableReference that = (PhysicalWorkTableReference) o; | ||
| return cteId.equals(that.cteId) && nameParts.equals(that.nameParts) && outputs.equals(outputs); |
Copilot
AI
Jan 15, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the equals method, outputs.equals(outputs) compares outputs to itself instead of comparing to that.outputs. This should be outputs.equals(that.outputs).
| return false; | ||
| } | ||
| LogicalWorkTableReference that = (LogicalWorkTableReference) o; | ||
| return cteId.equals(that.cteId) && nameParts.equals(that.nameParts) && outputs.equals(outputs); |
Copilot
AI
Jan 15, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the equals method, outputs.equals(outputs) compares outputs to itself instead of comparing to that.outputs. This should be outputs.equals(that.outputs).
|
|
||
| @Override | ||
| public String toString() { | ||
| return Utils.toSqlStringSkipNull("PhysicalRecursiveCteRecursiveChild", |
Copilot
AI
Jan 15, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The toString() method uses an outdated class name 'PhysicalRecursiveCteRecursiveChild' instead of the current class name 'PhysicalRecursiveUnionAnchor'.
| public static double DEFAULT_AGGREGATE_RATIO = 1 / 3.0; | ||
| public static double AGGREGATE_COLUMN_CORRELATION_COEFFICIENT = 0.75; | ||
| public static double DEFAULT_COLUMN_NDV_RATIO = 0.5; | ||
| public static double RECURSIVE_CTE_EXPAND_RATION = 5.0; |
Copilot
AI
Jan 15, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'RATION' to 'RATIO'.
| public static double RECURSIVE_CTE_EXPAND_RATION = 5.0; | |
| public static double RECURSIVE_CTE_EXPAND_RATIO = 5.0; | |
| @Deprecated | |
| public static double RECURSIVE_CTE_EXPAND_RATION = RECURSIVE_CTE_EXPAND_RATIO; |
| */ | ||
| public Statistics computeRecursiveCte(RecursiveCte recursiveCte, List<Statistics> childStats) { | ||
| // TODO: refactor this for one row relation | ||
| // simliar as computeUnion |
Copilot
AI
Jan 15, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'simliar' to 'similar'.
| // simliar as computeUnion | |
| // similar as computeUnion |
|
run buildall |
FE UT Coverage ReportIncrement line coverage |
TPC-H: Total hot run time: 31750 ms |
TPC-DS: Total hot run time: 174446 ms |
ClickBench: Total hot run time: 26.66 s |
FE Regression Coverage ReportIncrement line coverage |
FE Regression Coverage ReportIncrement line coverage |
|
PR approved by at least one committer and no changes requested. |
|
PR approved by anyone and no changes requested. |
Refactor recursive-CTE fe part.
Related PR: #58916
Summary
High-Level Design Changes
Logical / Physical Nodes Added
Removed / Renamed
LogicalRecursiveCteScan,PhysicalRecursiveCteScan,UnassignedRecursiveCteScanJobwere deleted.Visitor / Copier / Planner Updates
Rewrite / Optimization Rules
Distribution / Job Builder
Statistics / Cost
Type Equality
Analyzer / CTE handling
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)