fix: optimize regular index order-by limit#23966
Open
LeftHandCold wants to merge 4 commits intomatrixorigin:3.0-devfrom
Open
fix: optimize regular index order-by limit#23966LeftHandCold wants to merge 4 commits intomatrixorigin:3.0-devfrom
LeftHandCold wants to merge 4 commits intomatrixorigin:3.0-devfrom
Conversation
Address matrixorigin#23965 by teaching the planner to reuse the physical order of non-unique regular secondary indexes for ORDER BY primary-key LIMIT queries when all non-PK key parts are fixed by equality filters. Rewrite the sort anchor to the hidden serialized key, wire top-value messaging directly between sort and scan, and add focused planner tests for the optimized and non-optimized cases. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add an explicit index-table layout guard for the regular secondary index ORDER BY LIMIT rewrite and extend planner coverage to validate ASC ordering as well. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ouyuanning
approved these changes
Mar 26, 2026
Make the regular secondary index ORDER BY pk LIMIT optimization effective on the real Sort -> Index Table Scan plan shape after projection removal. Reuse the hidden serialized index key only when the scan is a non-unique regular index scan, the ORDER BY column is the index-table PK column, and all non-PK key parts are fixed by prefix equality. Keep the scan-side ordering on the physical hidden key while preserving the original visible sort key name in EXPLAIN, and extend planner tests for both project-preserving and projection-removed paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
eec672d to
5a5bab3
Compare
- set OrderBy on parallel local readers for ordered scans - push block-top pruning into regular index hidden-key scan path - trim sorted filtered block rows before feeding Top Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
aunjgr
approved these changes
Mar 27, 2026
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.
What type of PR is this?
Which issue(s) this PR fixes:
issue #23965
What this PR does / why we need it:
Address #23965 by teaching the planner to reuse the physical order of non-unique regular secondary indexes for ORDER BY primary-key LIMIT queries when all non-PK key parts are fixed by equality filters.
Rewrite the sort anchor to the hidden serialized key, wire top-value messaging directly between sort and scan, and add focused planner tests for the optimized and non-optimized cases.