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? |
|
The review is valid and has been addressed in
Validation: |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-reviewed the latest head after the requested changes. The previous correctness blocker is resolved: static reader LIMIT pushdown is now explicitly disabled across FILTER and cardinality-reducing INNER/SEMI JOIN paths, while TopValue messaging and ordered scanning remain available. The added regressions cover those unsafe paths and the direct-scan positive path.
I also rechecked range-bound construction, reversed comparisons, open/closed flags, cursor type/stability guards, OFFSET/rank/non-literal LIMIT fallbacks, and the persisted/in-memory/unsorted reader behavior. No blocking findings remain.
Local validation on the latest main merge passed for pkg/sql/plan, pkg/vm/engine/readutil, and pkg/vm/engine/tae/blockio, including targeted race repetitions and go vet. CI is green.
Non-blocking follow-up: an execution-level assertion that the cursor case keeps index-scan inputRows near LIMIT would protect the performance objective in addition to the current result-correctness BVT.
## 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]>
## 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]>
## 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]>
What type of PR is this?
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:
<,<=,>, or>=on the base-table primary key;The planner combines the fixed prefix and cursor into a
prefix_in_rangepredicate 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
Testing
go test -count=1 ./pkg/sql/plango test -count=1 ./pkg/vm/engine/readutilgo test -count=1 ./pkg/vm/engine/tae/blockioregular_index_order_limit_cursorBVT coverage for<,<=,>, and>=cursor boundaries.