Repository navigation
fix: only push filters on partition-by columns below WINDOW node (#24020) - #24050
Conversation
…rixorigin#24020) Previously, any filter not referencing the window tag was pushed below the WINDOW node. This is incorrect because filtering on non-partition-by columns changes the window function's input rows, producing wrong ROW_NUMBER()/RANK()/etc. results. Now only filters whose column references are a subset of the PARTITION BY columns are pushed down. Other non-window-tag filters stay above the WINDOW node.
Review Summary by QodoFix filter pushdown for WINDOW nodes to only push partition-by column filters
WalkthroughsDescription• Fix incorrect filter pushdown below WINDOW nodes that changed partition contents • Only push filters referencing partition-by columns below WINDOW node • Filters on non-partition-by columns now stay above WINDOW node • Add comprehensive test for non-partition-by filter behavior Diagramflowchart LR
Filter["Filter on non-partition-by column"]
Window["WINDOW node with PARTITION BY"]
Child["Child node"]
Filter -->|Previously pushed down incorrectly| Window
Filter -->|Now stays above| Window
Window -->|Only partition-by filters pushed| Child
File Changes1. pkg/sql/plan/pushdown.go
|
Code Review by Qodo
1.
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merge Queue Status
This pull request spent 9 seconds in the queue, including 1 second running CI. Required conditions to merge
|
…rixorigin#24020) (matrixorigin#24050) Previously, `pushdownFilters` for `Node_WINDOW` pushed any filter not referencing the window tag below the WINDOW node. This is incorrect because filtering on non-partition-by columns changes the window function's input rows, producing wrong `ROW_NUMBER()`/`RANK()`/etc. results. **Root cause:** The outer filter `INDUSTRY_NAME='Consumer Discretionary'` was pushed below the WINDOW node with `ROW_NUMBER() OVER (PARTITION BY STOCK_CODE ...)`, changing the partition contents and thus the row numbering. **Fix:** Only push filters whose column references are a subset of the PARTITION BY columns. Other non-window-tag filters stay above the WINDOW node. ### Changes - `pkg/sql/plan/pushdown.go`: Collect partition-by column refs; classify filters into three categories (window-tag / partition-by-only / other) - `pkg/sql/plan/pushdown_test.go`: Add `TestWindowNonPartitionFilterNotPushedDown` Approved by: @ouyuanning
What type of PR is this?
Which issue(s) does this PR fix:
Fixes #24020
What this PR does / why we need it:
Previously,
pushdownFiltersforNode_WINDOWpushed any filter not referencing the window tag below the WINDOW node. This is incorrect because filtering on non-partition-by columns changes the window function's input rows, producing wrongROW_NUMBER()/RANK()/etc. results.Root cause: The outer filter
INDUSTRY_NAME='Consumer Discretionary'was pushed below the WINDOW node withROW_NUMBER() OVER (PARTITION BY STOCK_CODE ...), changing the partition contents and thus the row numbering.Fix: Only push filters whose column references are a subset of the PARTITION BY columns. Other non-window-tag filters stay above the WINDOW node.
Changes
pkg/sql/plan/pushdown.go: Collect partition-by column refs; classify filters into three categories (window-tag / partition-by-only / other)pkg/sql/plan/pushdown_test.go: AddTestWindowNonPartitionFilterNotPushedDown