[Enhancement] Add Window skew optimization for multiple column partition expressions #73592
[Enhancement] Add Window skew optimization for multiple column partition expressions #73592martinr0x wants to merge 2 commits into
Conversation
b3b9512 to
d765390
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
ae0bfb5 to
a63168f
Compare
a63168f to
82f4031
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
91b618a to
b1a0cae
Compare
|
@codex review |
b1a0cae to
21ae88a
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b1a0cae53d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a “merge_sort” execution path for window functions to mitigate skew on composite partition keys, controllable via a new analytic hint and new session variables, with FE/BE propagation and tests.
Changes:
- Introduce
[merge_sort]analytic hint and propagateforce_merge_sortthrough AST → optimizer operators → plan nodes → thrift. - Add
WindowSkewToMergeSortRuleplus new session variablesenable_window_skew_merge_sort/force_window_merge_sort. - Add FE/BE and SQL regression tests for explain/pipeline behavior.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/sql/test_window_function/T/test_window_merge_sort | Adds SQL test cases covering default, hinted, forced, and skew-enabled modes |
| test/sql/test_window_function/R/test_window_merge_sort | Captures expected results and explain assertions for the new SQL tests |
| gensrc/thrift/PlanNodes.thrift | Adds force_merge_sort to TAnalyticNode for FE→BE propagation |
| fe/fe-parser/src/main/java/com/starrocks/sql/ast/HintNode.java | Adds merge_sort constant for analytic hint parsing |
| fe/fe-core/src/test/java/com/starrocks/sql/plan/WindowSkewToMergeSortRuleTest.java | Adds optimizer plan tests for merge-sort skew rule, force mode, and hint behavior |
| fe/fe-core/src/main/java/com/starrocks/sql/plan/PlanFragmentBuilder.java | Passes forceMergeSort into AnalyticEvalNode construction |
| fe/fe-core/src/main/java/com/starrocks/sql/optimizer/transformer/WindowTransformer.java | Preserves forceMergeSort when reordering window operators |
| fe/fe-core/src/main/java/com/starrocks/sql/optimizer/transformer/QueryTransformer.java | Propagates forceMergeSort between rewritten window operators |
| fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/tree/lowcardinality/DecodeRewriter.java | Propagates forceMergeSort through decode rewrite of physical window ops |
| fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/transformation/WindowSkewToMergeSortRule.java | Introduces transformation rule that sets forceMergeSort based on skew detection or force var |
| fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/transformation/SplitWindowSkewToUnionRule.java | Prevents union-splitting when merge-sort is forced |
| fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/implementation/WindowImplementationRule.java | Propagates forceMergeSort into physical window operator |
| fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/RuleType.java | Registers new rule type TF_WINDOW_SKEW_TO_MERGE_SORT |
| fe/fe-core/src/main/java/com/starrocks/sql/optimizer/operator/physical/PhysicalWindowOperator.java | Adds forceMergeSort field and includes it in equals/hashCode |
| fe/fe-core/src/main/java/com/starrocks/sql/optimizer/operator/logical/LogicalWindowOperator.java | Adds forceMergeSort field and builder support |
| fe/fe-core/src/main/java/com/starrocks/sql/optimizer/RequiredPropertyDeriver.java | Forces gather distribution when forceMergeSort is set |
| fe/fe-core/src/main/java/com/starrocks/sql/optimizer/QueryOptimizer.java | Schedules new rule under session-variable control |
| fe/fe-core/src/main/java/com/starrocks/sql/ast/expression/AnalyticExpr.java | Parses [merge_sort] hint and stores forceMergeSort |
| fe/fe-core/src/main/java/com/starrocks/qe/SessionVariable.java | Adds new invisible session variables to control feature |
| fe/fe-core/src/main/java/com/starrocks/planner/AnalyticEvalNode.java | Persists/writes force_merge_sort into thrift and normal form |
| be/test/exec/pipeline/analytic_node_pipeline_test.cpp | Adds pipeline tests verifying ordered partition exchange with force/skew |
| be/test/CMakeLists.txt | Registers the new BE pipeline unit test |
| be/src/exec/analytic_node.cpp | Applies ordered partition exchange when force_merge_sort is set |
496e1d1 to
d19a07b
Compare
d19a07b to
db87504
Compare
|
No new undocumented parameters detected by the param-drift check. |
|
@codex review |
1af5565 to
a83db62
Compare
|
@codex review |
|
Module-risk briefing for PR #73592 —
|
a83db62 to
554e7e2
Compare
|
@codex review |
|
Module-risk briefing for PR #73592 — history-backed review focus for the window/analytic skew optimization area (from 2 merged bugfixes). Window skew optimization (fe/sql/optimizer/rule/transformation)Review pitfalls
from 2 merged bugfixes (#71622, #70341) — history-backed heuristic; verify each pitfall against the actual change before acting on it. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 554e7e2d24
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b8737842e2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
b873784 to
8d87674
Compare
|
@codex review |
|
Module-risk briefing for PR #73592 (window skew merge-sort optimization) — from 20 merged bugfixes in
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d87674879
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @VariableMgr.VarAttr(name = ENABLE_WINDOW_SKEW_MERGE_SORT, flag = VariableMgr.INVISIBLE) | ||
| private boolean enableWindowSkewMergeSort = false; |
There was a problem hiding this comment.
Document the new window merge-sort session knob
The repo-wide AGENTS.md requires user-facing config changes to update the matching docs in docs/en/ and docs/zh/ when applicable. This adds a settable session variable, and the same change also introduces the [merge_sort] window hint, but no documentation was added, so users and operators have no supported reference for when to use it or what plan behavior it changes.
Useful? React with 👍 / 👎.
8d87674 to
a95d5f3
Compare
|
History-backed review focus for PR #73592 — module: Review pitfall: Verify column references are fully remapped in DecodeRewriterWhy it applies here: What to check: In
Review pitfall: Empty analytic operators after column pruningWhy it applies here: What to check: Verify there is a guard — either in
This is a history-backed heuristic derived from 20 merged bugfixes in the |
a95d5f3 to
e3ffa89
Compare
|
Module-risk briefing for PR #73592 — history-backed review focus from Pitfall: Verify
|
e3ffa89 to
e6b12c3
Compare
|
Module-risk briefing for PR #73592 — history-backed review focus for
|
e6b12c3 to
da10983
Compare
|
Module-risk briefing for PR #73592 — Pitfall 1 — Empty analytic operator → BE
|
fbe9ad7 to
6818f5c
Compare
Signed-off-by: m.bogusz <m.bogusz@celonis.com>
e89d2ff to
8282790
Compare
[Java-Extensions Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[FE Incremental Coverage Report]✅ pass : 86 / 100 (86.00%) file detail
|
|
[BE Incremental Coverage Report]✅ pass : 8 / 8 (100.00%) file detail
|



Why I'm doing:
Similar to
SplitWindowSkewToUnionRule, this PR adds another optimization for skewed window partitions.SplitWindowSkewToUnionRuleneeds the optimizer to identify the exact skewed value, because it splits the input into skewed and non-skewed branches based on that value. This is feasible for a single partition column, but does not work for multi-column partition expressions without multi-column statistics.How it works:
This optimization avoids that requirement by forcing a sort-merge path before partitioning the data by the window partition expressions. After the merge sort,
local_ordered_partition_exchangedistributes partitions across multiple pipeline drivers on one node while preserving the required order and partition boundaries.How is it different from
skewedoptimization:The skewed optimization is a similar option that is less aggressive. Instead of having a distributed sort of all data, data is first partitioned by p and then sorted by each backend. Once the data is partitioned each node adds a sort + gather and then uses the
local_ordered_partition_exchangeto distribute partitions across pipelines.This optimization is useful if some partitions are slightly skewed but for large skew the new optimization is preferred.
What I'm doing:
Im adding the rule
WindowSkewToMergeSortRule.This rule can be enabled by the
enable_window_skew_merge_sortsession variable or by the[merge_sort]hint.What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: