Repository navigation
fix(plan): preserve forced index access for ORDER BY - #26851
Conversation
|
Fresh evidence for commit
The isolated service used private localhost ports and task-local data only; the shared service was not switched or used. CI was not monitored. |
|
Independent triple-candidate acceptance on 55 passed the original semantics with a 300k-row noncovering table. Plain |
18091e7 to
45cb6e5
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
Blocking review finding. This is submitted as COMMENT because the authenticated account is the PR author and GitHub forbids a self REQUEST_CHANGES review.
The equality-prefix optimization is sound only when each skipped leading key part has one value for the whole scan. isRuntimeConstExpr also accepts volatile row-dependent functions. A public planner witness with a DOUBLE leading key and WHERE a = floor(rand() * 2) ORDER BY b, id selects the order-scoped forced (a,b,id) index and publishes OrderBy, even though rand() produces a different value per row. The explicit Sort currently remains as a correctness backstop, but the claimed order capability and order-scoped access selection are false.
Please require a genuinely row-invariant, non-volatile equality operand in both commuted forms and add this negative regression.
No other blockers were found. Full pkg/sql/plan, latest-main focused tests, build, vet, diff checks, and required CI passed on exact head 45cb6e5.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Blocking review finding. This review is COMMENTED only because the authenticated account is the PR author and GitHub forbids a self REQUEST_CHANGES review.
The equality-prefix optimization is sound only when each skipped leading key part has one value for the whole scan. isRuntimeConstExpr also accepts volatile row-dependent functions. A public planner witness with a DOUBLE leading key and WHERE a = floor(rand() * 2) ORDER BY b, id selects the order-scoped forced (a,b,id) index and publishes OrderBy, even though rand() produces a different value per row. The explicit Sort currently remains as a correctness backstop, but the claimed order capability and order-scoped access selection are false.
Please require a genuinely row-invariant, non-volatile equality operand in both commuted forms and add this negative regression.
No other blockers were found. Full pkg/sql/plan, latest-main focused tests, build, vet, diff checks, and required CI passed on exact head 45cb6e5.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Final complete deep review of 06acd00 against latest main 5430351: no blocking findings.
I reviewed the full four-file diff, not only the follow-up commit. The review covered plain and ORDER-scoped FORCE precedence, equality-fixed composite-index prefixes, covering and backfill paths, compatible and incompatible ORDER BY shapes, ascending/descending order, literal/parameter/volatile operands in both commuted forms, malformed/unknown expression fail-closed behavior, and the distributed SQL/result fixtures. I also cross-checked the newly merged #26848 index-range residual path; it does not conflict with this rewrite.
The prior volatile-expression finding is fixed: skipped index parts now require one statement-stable value for the scan, and nested rand() no longer claims ordered-index capability. No resource ownership, cleanup, wait-for, retry, concurrency, restart-generation, or unbounded-growth edges are introduced.
Validation on the exact rebased head: the new regression failed before the fix and passes after it; focused planner tests pass; go test ./pkg/sql/plan/... passes; go vet ./pkg/sql/plan/... passes; diff checks are clean; and range-diff confirms the original PR commit did not drift during rebase. The branch was 0 behind latest main at review time. CI was not polled.
GitHub does not allow the PR author to approve their own PR, so this no-finding result is submitted as COMMENT; the requested non-author reviewer remains the approval gate.
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? |
) ## Summary - let forced ORDER BY access skip a contiguous leading index prefix fixed by single-value equality - preserve plain `FORCE INDEX` as an access-path constraint when the named index cannot provide ordering, leaving `Sort` to enforce order - keep `FORCE INDEX FOR ORDER BY` order-scoped and leave ordinary optimization unchanged ## Root cause The force-index ORDER BY prepass required ORDER columns to match the physical index from part zero. For an index such as `(status, amount, id)`, it therefore rejected a fixed status prefix followed by `ORDER BY amount, id` even though that prefix is order-neutral. When the order match failed, base-scan protection also caused an unscoped plain `FORCE INDEX` to be silently discarded. The matcher now skips only a contiguous prefix fixed by `column = runtime_constant`. IN, range, and unconstrained or gapped parts remain order-incompatible. If an unscoped plain force cannot satisfy order, the planner still builds the named covering scan or index backfill join without marking it ordered, so the existing Sort remains authoritative. ## Validation Fresh validation from isolated worktree `/home/xupeng/github/matrixone-issue-26814`, based on `origin/main` `0676200da47052659cf46ad9e22d67ab9654e393`: - regression reproduced before the production change: equality-prefix and plain-force fallback cases failed to retain the index - focused force/order planner tests: pass - full `pkg/sql/plan` suite: pass - package `go build` and `go vet` with repository-local CGo paths: pass - whole `make build`: pass - isolated candidate-binary BVT `optimizer/index_hint.sql`: 53/53 statements pass - pairwise merge plus focused/full planner suites with draft matrixorigin#26848: pass - pairwise merge plus focused/full planner suites with draft matrixorigin#26850 (for matrixorigin#26803): pass The regression matrix covers ASC/DESC, LIMIT/no LIMIT, equality/IN/range/gapped leading parts, covering/backfill access, invalid hints, unhinted optimization, and exact/distinct row checks. No row-path benchmark was added: the new work is planner-only and bounded by index parts times scan filters plus ORDER columns. Fixes matrixorigin#26814
) ## Summary - let forced ORDER BY access skip a contiguous leading index prefix fixed by single-value equality - preserve plain `FORCE INDEX` as an access-path constraint when the named index cannot provide ordering, leaving `Sort` to enforce order - keep `FORCE INDEX FOR ORDER BY` order-scoped and leave ordinary optimization unchanged ## Root cause The force-index ORDER BY prepass required ORDER columns to match the physical index from part zero. For an index such as `(status, amount, id)`, it therefore rejected a fixed status prefix followed by `ORDER BY amount, id` even though that prefix is order-neutral. When the order match failed, base-scan protection also caused an unscoped plain `FORCE INDEX` to be silently discarded. The matcher now skips only a contiguous prefix fixed by `column = runtime_constant`. IN, range, and unconstrained or gapped parts remain order-incompatible. If an unscoped plain force cannot satisfy order, the planner still builds the named covering scan or index backfill join without marking it ordered, so the existing Sort remains authoritative. ## Validation Fresh validation from isolated worktree `/home/xupeng/github/matrixone-issue-26814`, based on `origin/main` `0676200da47052659cf46ad9e22d67ab9654e393`: - regression reproduced before the production change: equality-prefix and plain-force fallback cases failed to retain the index - focused force/order planner tests: pass - full `pkg/sql/plan` suite: pass - package `go build` and `go vet` with repository-local CGo paths: pass - whole `make build`: pass - isolated candidate-binary BVT `optimizer/index_hint.sql`: 53/53 statements pass - pairwise merge plus focused/full planner suites with draft matrixorigin#26848: pass - pairwise merge plus focused/full planner suites with draft matrixorigin#26850 (for matrixorigin#26803): pass The regression matrix covers ASC/DESC, LIMIT/no LIMIT, equality/IN/range/gapped leading parts, covering/backfill access, invalid hints, unhinted optimization, and exact/distinct row checks. No row-path benchmark was added: the new work is planner-only and bounded by index parts times scan filters plus ORDER columns. Fixes matrixorigin#26814
) ## Summary - let forced ORDER BY access skip a contiguous leading index prefix fixed by single-value equality - preserve plain `FORCE INDEX` as an access-path constraint when the named index cannot provide ordering, leaving `Sort` to enforce order - keep `FORCE INDEX FOR ORDER BY` order-scoped and leave ordinary optimization unchanged ## Root cause The force-index ORDER BY prepass required ORDER columns to match the physical index from part zero. For an index such as `(status, amount, id)`, it therefore rejected a fixed status prefix followed by `ORDER BY amount, id` even though that prefix is order-neutral. When the order match failed, base-scan protection also caused an unscoped plain `FORCE INDEX` to be silently discarded. The matcher now skips only a contiguous prefix fixed by `column = runtime_constant`. IN, range, and unconstrained or gapped parts remain order-incompatible. If an unscoped plain force cannot satisfy order, the planner still builds the named covering scan or index backfill join without marking it ordered, so the existing Sort remains authoritative. ## Validation Fresh validation from isolated worktree `/home/xupeng/github/matrixone-issue-26814`, based on `origin/main` `0676200da47052659cf46ad9e22d67ab9654e393`: - regression reproduced before the production change: equality-prefix and plain-force fallback cases failed to retain the index - focused force/order planner tests: pass - full `pkg/sql/plan` suite: pass - package `go build` and `go vet` with repository-local CGo paths: pass - whole `make build`: pass - isolated candidate-binary BVT `optimizer/index_hint.sql`: 53/53 statements pass - pairwise merge plus focused/full planner suites with draft matrixorigin#26848: pass - pairwise merge plus focused/full planner suites with draft matrixorigin#26850 (for matrixorigin#26803): pass The regression matrix covers ASC/DESC, LIMIT/no LIMIT, equality/IN/range/gapped leading parts, covering/backfill access, invalid hints, unhinted optimization, and exact/distinct row checks. No row-path benchmark was added: the new work is planner-only and bounded by index parts times scan filters plus ORDER columns. Fixes matrixorigin#26814
Summary
FORCE INDEXas an access-path constraint when the named index cannot provide ordering, leavingSortto enforce orderFORCE INDEX FOR ORDER BYorder-scoped and leave ordinary optimization unchangedRoot cause
The force-index ORDER BY prepass required ORDER columns to match the physical index from part zero. For an index such as
(status, amount, id), it therefore rejected a fixed status prefix followed byORDER BY amount, ideven though that prefix is order-neutral. When the order match failed, base-scan protection also caused an unscoped plainFORCE INDEXto be silently discarded.The matcher now skips only a contiguous prefix fixed by
column = runtime_constant. IN, range, and unconstrained or gapped parts remain order-incompatible. If an unscoped plain force cannot satisfy order, the planner still builds the named covering scan or index backfill join without marking it ordered, so the existing Sort remains authoritative.Validation
Fresh validation from isolated worktree
/home/xupeng/github/matrixone-issue-26814, based onorigin/main0676200da47052659cf46ad9e22d67ab9654e393:pkg/sql/plansuite: passgo buildandgo vetwith repository-local CGo paths: passmake build: passoptimizer/index_hint.sql: 53/53 statements passThe regression matrix covers ASC/DESC, LIMIT/no LIMIT, equality/IN/range/gapped leading parts, covering/backfill access, invalid hints, unhinted optimization, and exact/distinct row checks.
No row-path benchmark was added: the new work is planner-only and bounded by index parts times scan filters plus ORDER columns.
Fixes #26814