ORCA: Fix window function cost model producing zero local cost when no ORDER BY#1573
Merged
yjhjstz merged 1 commit intoapache:mainfrom Feb 24, 2026
Merged
ORCA: Fix window function cost model producing zero local cost when no ORDER BY#1573yjhjstz merged 1 commit intoapache:mainfrom
yjhjstz merged 1 commit intoapache:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the ORCA cost model where window functions without an ORDER BY clause had zero local cost, causing the optimizer to incorrectly prefer non-hash variants due to tie-breaking by insertion order.
Changes:
- Modified window function cost calculations to use
max(ulSortCols, 1)ensuring non-zero cost even without ORDER BY - Fixed function header comment for CostHashSequenceProject (previously incorrectly labeled as CostSequenceProject)
- Added explanatory comments documenting the rationale for the minimum cost factor
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5e27aa3 to
7698573
Compare
leborchuk
approved these changes
Feb 12, 2026
Contributor
leborchuk
left a comment
There was a problem hiding this comment.
ulSortCols by default is 0 and SQL could not have ORDER BY in WINDOW CLAUSE, it's unusual but make sense in some cases. For those queries we produce zero cost bacause of default ulSortCols value.
Need to be fixed, LGTM
reshke
approved these changes
Feb 24, 2026
…o ORDER BY When a window function has no ORDER BY clause (empty Order Spec), ulSortCols is 0, causing the local cost of SequenceProject operators to be zero. This makes CostHashSequenceProject and CPhysicalSequenceProject have identical costs. Fix by using max(ulSortCols, 1) so the window function evaluation cost is never zero.
7698573 to
862ea4d
Compare
reshke
pushed a commit
that referenced
this pull request
Mar 11, 2026
…o ORDER BY (#1573) When a window function has no ORDER BY clause (empty Order Spec), ulSortCols is 0, causing the local cost of SequenceProject operators to be zero. This makes CostHashSequenceProject and CPhysicalSequenceProject have identical costs. Fix by using max(ulSortCols, 1) so the window function evaluation cost is never zero.
reshke
pushed a commit
to reshke/cloudberrydb
that referenced
this pull request
Mar 11, 2026
…o ORDER BY (apache#1573) When a window function has no ORDER BY clause (empty Order Spec), ulSortCols is 0, causing the local cost of SequenceProject operators to be zero. This makes CostHashSequenceProject and CPhysicalSequenceProject have identical costs. Fix by using max(ulSortCols, 1) so the window function evaluation cost is never zero.
reshke
pushed a commit
to reshke/cloudberrydb
that referenced
this pull request
Mar 11, 2026
…o ORDER BY (apache#1573) When a window function has no ORDER BY clause (empty Order Spec), ulSortCols is 0, causing the local cost of SequenceProject operators to be zero. This makes CostHashSequenceProject and CPhysicalSequenceProject have identical costs. Fix by using max(ulSortCols, 1) so the window function evaluation cost is never zero.
reshke
pushed a commit
that referenced
this pull request
Mar 12, 2026
…o ORDER BY (#1573) When a window function has no ORDER BY clause (empty Order Spec), ulSortCols is 0, causing the local cost of SequenceProject operators to be zero. This makes CostHashSequenceProject and CPhysicalSequenceProject have identical costs. Fix by using max(ulSortCols, 1) so the window function evaluation cost is never zero.
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.
When a window function has no ORDER BY clause (empty Order Spec),
ulSortCols is 0, causing the local cost of SequenceProject operators
to be zero. This makes CostHashSequenceProject and
CPhysicalSequenceProject have identical costs.
Fixes #ISSUE_Number
What does this PR do?
Type of Change
Breaking Changes
Test Plan
make installcheckmake -C src/test installcheck-cbdb-parallelImpact
Performance:
User-facing changes:
Dependencies:
Checklist
Additional Context
CI Skip Instructions