Repository navigation
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
LeftHandCold
force-pushed
the
agent/fix-regular-index-cursor-limit-main
branch
from
July 8, 2026 15:31
8f9d834 to
c7dea57
Compare
ouyuanning
approved these changes
Jul 9, 2026
2 of 7 tasks
XuPeng-SH
added a commit
that referenced
this pull request
Jul 10, 2026
## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue #23965 ## What this PR does / why we need it: This completes the safe index-reader LIMIT pushdown for regular secondary-index cursor pagination when: - every secondary-index prefix part is fixed by equality; - the only residual predicate is `<`, `<=`, `>`, or `>=` on the base-table primary key; - the query orders by that primary key and uses a positive literal LIMIT without OFFSET or rank semantics. The planner combines the fixed prefix and cursor into a `prefix_in_range` predicate on the hidden serialized index key. The range is evaluated before the ordered reader LIMIT, so the reader can continue from the cursor boundary and return the requested rows without scanning and sorting the full prefix group. The original primary-key cursor predicate remains in the scan filter list as a correctness recheck. ## Root Cause PR #25545 correctly disabled static reader LIMIT pushdown whenever an index scan had residual filters. Before that guard, the reader could take the first N entries in hidden-key order and only then apply `id < cursor`, which could return too few rows or zero rows. That guard restored correctness but also disabled early termination for cursor predicates that can be represented exactly as a range on the same hidden ordered key. As a result, the cursor query still read the complete prefix group before the final Top-N sort. ## Safety and compatibility - No storage, index format, reader API, or SQL semantics are changed. - The optimization is enabled only by the cursor-range rewrite performed in the two existing regular-index ORDER BY LIMIT planner paths. - Static reader LIMIT is applied only when the SORT path reaches the table scan directly. A FILTER or cardinality-reducing INNER/SEMI JOIN on that path disables static LIMIT pushdown. - TopValue messaging and ordered scanning remain enabled across those FILTER/JOIN paths, preserving the existing dynamic optimization without risking an incomplete result. - Additional residual filters, incomplete index prefixes, non-primary-key predicates, computed cursor expressions, float primary keys, type mismatches, OFFSET, rank semantics, and non-literal LIMIT values retain the existing conservative behavior. - Prepared cursor parameters and casts over stable literal/parameter values are supported. - In-memory and unsorted-block behavior continues to use the existing fallback paths. ## Testing - `go test -count=1 ./pkg/sql/plan` - `go test -count=1 ./pkg/vm/engine/readutil` - `go test -count=1 ./pkg/vm/engine/tae/blockio` - Added planner regressions proving static reader LIMIT is not pushed through FILTER, INNER JOIN, or SEMI JOIN. - Extended `regular_index_order_limit_cursor` BVT coverage for `<`, `<=`, `>`, and `>=` cursor boundaries. --------- Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#23965 ## What this PR does / why we need it: The regular secondary index ORDER BY primary-key LIMIT optimization can push a static limit down to the scan/index reader when the secondary-index prefix is fixed. With an extra primary-key cursor predicate, for example `id < ...`, the scan candidates no longer exactly match the SQL filter. Applying the static limit before the residual filter can return too few rows, or even zero rows. This PR keeps the hidden-key ordering rewrite and TopValue message path, but only enables static limit pushdown when the index scan filter list is exactly the full-prefix equality filter. Residual filters continue to be applied before the final LIMIT semantics are observed. Added a BVT regression case: `test/distributed/cases/optimizer/regular_index_order_limit_cursor.sql` Tested with: `env GOCACHE=/private/tmp/mo-go-build-cache CGO_CFLAGS='-I/Users/shenjiangwei/Work/code/view/matrixone/cgo -I/Users/shenjiangwei/Work/code/view/matrixone/thirdparties/install/include' CGO_LDFLAGS='-Wl,-w,-rpath,/Users/shenjiangwei/Work/code/view/matrixone/cgo -Wl,-rpath,/Users/shenjiangwei/Work/code/view/matrixone/thirdparties/install/lib -L/Users/shenjiangwei/Work/code/view/matrixone/thirdparties/install/lib -L/Users/shenjiangwei/Work/code/view/matrixone/cgo -lmo' go test ./pkg/sql/plan -count=1` Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#23965 ## What this PR does / why we need it: This completes the safe index-reader LIMIT pushdown for regular secondary-index cursor pagination when: - every secondary-index prefix part is fixed by equality; - the only residual predicate is `<`, `<=`, `>`, or `>=` on the base-table primary key; - the query orders by that primary key and uses a positive literal LIMIT without OFFSET or rank semantics. The planner combines the fixed prefix and cursor into a `prefix_in_range` predicate on the hidden serialized index key. The range is evaluated before the ordered reader LIMIT, so the reader can continue from the cursor boundary and return the requested rows without scanning and sorting the full prefix group. The original primary-key cursor predicate remains in the scan filter list as a correctness recheck. ## Root Cause PR matrixorigin#25545 correctly disabled static reader LIMIT pushdown whenever an index scan had residual filters. Before that guard, the reader could take the first N entries in hidden-key order and only then apply `id < cursor`, which could return too few rows or zero rows. That guard restored correctness but also disabled early termination for cursor predicates that can be represented exactly as a range on the same hidden ordered key. As a result, the cursor query still read the complete prefix group before the final Top-N sort. ## Safety and compatibility - No storage, index format, reader API, or SQL semantics are changed. - The optimization is enabled only by the cursor-range rewrite performed in the two existing regular-index ORDER BY LIMIT planner paths. - Static reader LIMIT is applied only when the SORT path reaches the table scan directly. A FILTER or cardinality-reducing INNER/SEMI JOIN on that path disables static LIMIT pushdown. - TopValue messaging and ordered scanning remain enabled across those FILTER/JOIN paths, preserving the existing dynamic optimization without risking an incomplete result. - Additional residual filters, incomplete index prefixes, non-primary-key predicates, computed cursor expressions, float primary keys, type mismatches, OFFSET, rank semantics, and non-literal LIMIT values retain the existing conservative behavior. - Prepared cursor parameters and casts over stable literal/parameter values are supported. - In-memory and unsorted-block behavior continues to use the existing fallback paths. ## Testing - `go test -count=1 ./pkg/sql/plan` - `go test -count=1 ./pkg/vm/engine/readutil` - `go test -count=1 ./pkg/vm/engine/tae/blockio` - Added planner regressions proving static reader LIMIT is not pushed through FILTER, INNER JOIN, or SEMI JOIN. - Extended `regular_index_order_limit_cursor` BVT coverage for `<`, `<=`, `>`, and `>=` cursor boundaries. --------- Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#23965 ## What this PR does / why we need it: The regular secondary index ORDER BY primary-key LIMIT optimization can push a static limit down to the scan/index reader when the secondary-index prefix is fixed. With an extra primary-key cursor predicate, for example `id < ...`, the scan candidates no longer exactly match the SQL filter. Applying the static limit before the residual filter can return too few rows, or even zero rows. This PR keeps the hidden-key ordering rewrite and TopValue message path, but only enables static limit pushdown when the index scan filter list is exactly the full-prefix equality filter. Residual filters continue to be applied before the final LIMIT semantics are observed. Added a BVT regression case: `test/distributed/cases/optimizer/regular_index_order_limit_cursor.sql` Tested with: `env GOCACHE=/private/tmp/mo-go-build-cache CGO_CFLAGS='-I/Users/shenjiangwei/Work/code/view/matrixone/cgo -I/Users/shenjiangwei/Work/code/view/matrixone/thirdparties/install/include' CGO_LDFLAGS='-Wl,-w,-rpath,/Users/shenjiangwei/Work/code/view/matrixone/cgo -Wl,-rpath,/Users/shenjiangwei/Work/code/view/matrixone/thirdparties/install/lib -L/Users/shenjiangwei/Work/code/view/matrixone/thirdparties/install/lib -L/Users/shenjiangwei/Work/code/view/matrixone/cgo -lmo' go test ./pkg/sql/plan -count=1` Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#23965 ## What this PR does / why we need it: This completes the safe index-reader LIMIT pushdown for regular secondary-index cursor pagination when: - every secondary-index prefix part is fixed by equality; - the only residual predicate is `<`, `<=`, `>`, or `>=` on the base-table primary key; - the query orders by that primary key and uses a positive literal LIMIT without OFFSET or rank semantics. The planner combines the fixed prefix and cursor into a `prefix_in_range` predicate on the hidden serialized index key. The range is evaluated before the ordered reader LIMIT, so the reader can continue from the cursor boundary and return the requested rows without scanning and sorting the full prefix group. The original primary-key cursor predicate remains in the scan filter list as a correctness recheck. ## Root Cause PR matrixorigin#25545 correctly disabled static reader LIMIT pushdown whenever an index scan had residual filters. Before that guard, the reader could take the first N entries in hidden-key order and only then apply `id < cursor`, which could return too few rows or zero rows. That guard restored correctness but also disabled early termination for cursor predicates that can be represented exactly as a range on the same hidden ordered key. As a result, the cursor query still read the complete prefix group before the final Top-N sort. ## Safety and compatibility - No storage, index format, reader API, or SQL semantics are changed. - The optimization is enabled only by the cursor-range rewrite performed in the two existing regular-index ORDER BY LIMIT planner paths. - Static reader LIMIT is applied only when the SORT path reaches the table scan directly. A FILTER or cardinality-reducing INNER/SEMI JOIN on that path disables static LIMIT pushdown. - TopValue messaging and ordered scanning remain enabled across those FILTER/JOIN paths, preserving the existing dynamic optimization without risking an incomplete result. - Additional residual filters, incomplete index prefixes, non-primary-key predicates, computed cursor expressions, float primary keys, type mismatches, OFFSET, rank semantics, and non-literal LIMIT values retain the existing conservative behavior. - Prepared cursor parameters and casts over stable literal/parameter values are supported. - In-memory and unsorted-block behavior continues to use the existing fallback paths. ## Testing - `go test -count=1 ./pkg/sql/plan` - `go test -count=1 ./pkg/vm/engine/readutil` - `go test -count=1 ./pkg/vm/engine/tae/blockio` - Added planner regressions proving static reader LIMIT is not pushed through FILTER, INNER JOIN, or SEMI JOIN. - Extended `regular_index_order_limit_cursor` BVT coverage for `<`, `<=`, `>`, and `>=` cursor boundaries. --------- Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#23965 ## What this PR does / why we need it: The regular secondary index ORDER BY primary-key LIMIT optimization can push a static limit down to the scan/index reader when the secondary-index prefix is fixed. With an extra primary-key cursor predicate, for example `id < ...`, the scan candidates no longer exactly match the SQL filter. Applying the static limit before the residual filter can return too few rows, or even zero rows. This PR keeps the hidden-key ordering rewrite and TopValue message path, but only enables static limit pushdown when the index scan filter list is exactly the full-prefix equality filter. Residual filters continue to be applied before the final LIMIT semantics are observed. Added a BVT regression case: `test/distributed/cases/optimizer/regular_index_order_limit_cursor.sql` Tested with: `env GOCACHE=/private/tmp/mo-go-build-cache CGO_CFLAGS='-I/Users/shenjiangwei/Work/code/view/matrixone/cgo -I/Users/shenjiangwei/Work/code/view/matrixone/thirdparties/install/include' CGO_LDFLAGS='-Wl,-w,-rpath,/Users/shenjiangwei/Work/code/view/matrixone/cgo -Wl,-rpath,/Users/shenjiangwei/Work/code/view/matrixone/thirdparties/install/lib -L/Users/shenjiangwei/Work/code/view/matrixone/thirdparties/install/lib -L/Users/shenjiangwei/Work/code/view/matrixone/cgo -lmo' go test ./pkg/sql/plan -count=1` Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#23965 ## What this PR does / why we need it: This completes the safe index-reader LIMIT pushdown for regular secondary-index cursor pagination when: - every secondary-index prefix part is fixed by equality; - the only residual predicate is `<`, `<=`, `>`, or `>=` on the base-table primary key; - the query orders by that primary key and uses a positive literal LIMIT without OFFSET or rank semantics. The planner combines the fixed prefix and cursor into a `prefix_in_range` predicate on the hidden serialized index key. The range is evaluated before the ordered reader LIMIT, so the reader can continue from the cursor boundary and return the requested rows without scanning and sorting the full prefix group. The original primary-key cursor predicate remains in the scan filter list as a correctness recheck. ## Root Cause PR matrixorigin#25545 correctly disabled static reader LIMIT pushdown whenever an index scan had residual filters. Before that guard, the reader could take the first N entries in hidden-key order and only then apply `id < cursor`, which could return too few rows or zero rows. That guard restored correctness but also disabled early termination for cursor predicates that can be represented exactly as a range on the same hidden ordered key. As a result, the cursor query still read the complete prefix group before the final Top-N sort. ## Safety and compatibility - No storage, index format, reader API, or SQL semantics are changed. - The optimization is enabled only by the cursor-range rewrite performed in the two existing regular-index ORDER BY LIMIT planner paths. - Static reader LIMIT is applied only when the SORT path reaches the table scan directly. A FILTER or cardinality-reducing INNER/SEMI JOIN on that path disables static LIMIT pushdown. - TopValue messaging and ordered scanning remain enabled across those FILTER/JOIN paths, preserving the existing dynamic optimization without risking an incomplete result. - Additional residual filters, incomplete index prefixes, non-primary-key predicates, computed cursor expressions, float primary keys, type mismatches, OFFSET, rank semantics, and non-literal LIMIT values retain the existing conservative behavior. - Prepared cursor parameters and casts over stable literal/parameter values are supported. - In-memory and unsorted-block behavior continues to use the existing fallback paths. ## Testing - `go test -count=1 ./pkg/sql/plan` - `go test -count=1 ./pkg/vm/engine/readutil` - `go test -count=1 ./pkg/vm/engine/tae/blockio` - Added planner regressions proving static reader LIMIT is not pushed through FILTER, INNER JOIN, or SEMI JOIN. - Extended `regular_index_order_limit_cursor` BVT coverage for `<`, `<=`, `>`, and `>=` cursor boundaries. --------- Co-authored-by: XuPeng-SH <[email protected]>
This branch was previously deployed
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:
The regular secondary index ORDER BY primary-key LIMIT optimization can push a static limit down to the scan/index reader when the secondary-index prefix is fixed.
With an extra primary-key cursor predicate, for example
id < ..., the scan candidates no longer exactly match the SQL filter. Applying the static limit before the residual filter can return too few rows, or even zero rows.This PR keeps the hidden-key ordering rewrite and TopValue message path, but only enables static limit pushdown when the index scan filter list is exactly the full-prefix equality filter.
Residual filters continue to be applied before the final LIMIT semantics are observed.
Added a BVT regression case:
test/distributed/cases/optimizer/regular_index_order_limit_cursor.sqlTested with:
env GOCACHE=/private/tmp/mo-go-build-cache CGO_CFLAGS='-I/Users/shenjiangwei/Work/code/view/matrixone/cgo -I/Users/shenjiangwei/Work/code/view/matrixone/thirdparties/install/include' CGO_LDFLAGS='-Wl,-w,-rpath,/Users/shenjiangwei/Work/code/view/matrixone/cgo -Wl,-rpath,/Users/shenjiangwei/Work/code/view/matrixone/thirdparties/install/lib -L/Users/shenjiangwei/Work/code/view/matrixone/thirdparties/install/lib -L/Users/shenjiangwei/Work/code/view/matrixone/cgo -lmo' go test ./pkg/sql/plan -count=1