Repository navigation
fix(plan): preserve prepared regular-index range performance - #27122
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review: no blocking findings at ce661a3884e9cb9901b68eed9f5abfb6223c6bed.
I checked the change as four separate contracts:
- Physical non-unique regular-index keys and join runtime-filter materialization still use
serial_full; only SQL comparison operands move to NULL-propagatingserial. Non-NULL encodings remain byte-identical. - NULL truth-table closure is preserved: NULL equality/range bounds reject through
serial;prefix_indrops NULL needles; nullable stored keys retain the decoded residual only for the strict-upper-bound case that physical NULL ordering can over-admit. Byte-string prefix ambiguity still retains an exact residual. prefix_innow owns cloned non-NULL bytes before compaction. Its cached state is per executor, andResetForNextQueryrecreates the function op, so prepared executions cannot reuse an earlier needle set.- The prepared-range uncertainty lower bound now charges stable index-only output/decode work without changing the backfill lower bound; broad known ranges can still reject the index, while all-parameter covering and non-covering ranges retain an eligible candidate.
Validation on the exact head:
git diff --check- CGo-configured
go buildandgo vetfor./pkg/sql/plan/function ./pkg/sql/plan - Full uncached tests for both packages
- Focused
-racetests covering serialization compatibility, NULL/prefix semantics, residual selection, and prepared cost crossovers
The latest CI run has no failures at review time; Ubuntu UT, SCA, coverage, BVT, Iceberg, and CodeQL C/C++ are still in progress.
|
@aunjgr @aptend @LeftHandCold 麻烦帮忙 review 一下当前 PR,重点关注 prepared regular-index range 的 NULL 语义、prefix lookup residual,以及成本模型边界。当前 head: |
…rigin#27122) ## What changed - Separate physical index-key serialization from SQL comparison-bound serialization. Physical non-unique composite keys continue to use `serial_full`, while lookup bounds use NULL-propagating `serial`. - Make `prefix_in` ignore NULL needles and compact only owned, non-NULL prefixes. - Keep only residual predicates that are still required for encoded row-side NULL ordering or byte-string prefix ambiguity. - Include stable index-only output/decode work in the lower bound of prepared-range cost uncertainty. - Propagate expression-binding failures instead of silently accepting incomplete rewrites. ## Root cause The previous fix used physical stored-key serialization (`serial_full`) for SQL comparison operands. Prepared NULL bounds therefore needed decoded residual predicates to recover SQL three-valued semantics. For OR-ed random ranges this duplicated parameter folding and serialized extraction work on every execution, and the cost model also undercounted stable downstream work when evaluating an uncertain prepared range. The fix models the two contracts independently: stored keys must preserve NULL components, but comparison bounds must reject NULL. `serial` and `serial_full` are byte-identical for non-NULL components, so using `serial` for bounds preserves index compatibility without row-by-row NULL guards. ## Compatibility and regression coverage - Non-unique index storage and join runtime-filter materialization still use `serial_full`. - Nullable strict upper bounds and ambiguous varchar/varbinary prefixes retain exact decoded residuals. - Broad literal ranges still reject the index; uncertain prepared ranges keep the index when cost intervals overlap. - Covering scans remain covering, while non-covering prepared ranges still select an index join. - Prepared equality, IN, BETWEEN, mixed OR, update, delete, and replace paths are covered. ## Validation - `mo-cgo-test -count=1 ./pkg/sql/plan/function ./pkg/sql/plan` - Focused `-race` coverage for all changed planner and function cases - CGo-configured `go vet ./pkg/sql/plan ./pkg/sql/plan/function` - Scoped molint and golangci-lint: clean - a55, 2M rows, 100 threads, 4 GiB memory cache: - intermediate decoded-guard implementation: 22,906.80 TPS, p95 24.83 ms - systemic serialization fix: 28,260.18 TPS, p95 19.65 ms - +23.37% TPS and -20.86% p95, with zero errors - a55 CPU profile: `EvalFoldExpr` 16.25% -> 10.77%, `tryFoldParameter` 11.71% -> 7.73% - `EXPLAIN ANALYZE`: narrow prepared ranges use the covering index; broad covering ranges use the base table scan The historical CI comparison used 10M rows and 1000 threads, so its absolute TPS is intentionally not compared with the a55 2M/100-thread validation. Fixes matrixorigin#26971
…rigin#27122) ## What changed - Separate physical index-key serialization from SQL comparison-bound serialization. Physical non-unique composite keys continue to use `serial_full`, while lookup bounds use NULL-propagating `serial`. - Make `prefix_in` ignore NULL needles and compact only owned, non-NULL prefixes. - Keep only residual predicates that are still required for encoded row-side NULL ordering or byte-string prefix ambiguity. - Include stable index-only output/decode work in the lower bound of prepared-range cost uncertainty. - Propagate expression-binding failures instead of silently accepting incomplete rewrites. ## Root cause The previous fix used physical stored-key serialization (`serial_full`) for SQL comparison operands. Prepared NULL bounds therefore needed decoded residual predicates to recover SQL three-valued semantics. For OR-ed random ranges this duplicated parameter folding and serialized extraction work on every execution, and the cost model also undercounted stable downstream work when evaluating an uncertain prepared range. The fix models the two contracts independently: stored keys must preserve NULL components, but comparison bounds must reject NULL. `serial` and `serial_full` are byte-identical for non-NULL components, so using `serial` for bounds preserves index compatibility without row-by-row NULL guards. ## Compatibility and regression coverage - Non-unique index storage and join runtime-filter materialization still use `serial_full`. - Nullable strict upper bounds and ambiguous varchar/varbinary prefixes retain exact decoded residuals. - Broad literal ranges still reject the index; uncertain prepared ranges keep the index when cost intervals overlap. - Covering scans remain covering, while non-covering prepared ranges still select an index join. - Prepared equality, IN, BETWEEN, mixed OR, update, delete, and replace paths are covered. ## Validation - `mo-cgo-test -count=1 ./pkg/sql/plan/function ./pkg/sql/plan` - Focused `-race` coverage for all changed planner and function cases - CGo-configured `go vet ./pkg/sql/plan ./pkg/sql/plan/function` - Scoped molint and golangci-lint: clean - a55, 2M rows, 100 threads, 4 GiB memory cache: - intermediate decoded-guard implementation: 22,906.80 TPS, p95 24.83 ms - systemic serialization fix: 28,260.18 TPS, p95 19.65 ms - +23.37% TPS and -20.86% p95, with zero errors - a55 CPU profile: `EvalFoldExpr` 16.25% -> 10.77%, `tryFoldParameter` 11.71% -> 7.73% - `EXPLAIN ANALYZE`: narrow prepared ranges use the covering index; broad covering ranges use the base table scan The historical CI comparison used 10M rows and 1000 threads, so its absolute TPS is intentionally not compared with the a55 2M/100-thread validation. Fixes matrixorigin#26971
…rigin#27122) ## What changed - Separate physical index-key serialization from SQL comparison-bound serialization. Physical non-unique composite keys continue to use `serial_full`, while lookup bounds use NULL-propagating `serial`. - Make `prefix_in` ignore NULL needles and compact only owned, non-NULL prefixes. - Keep only residual predicates that are still required for encoded row-side NULL ordering or byte-string prefix ambiguity. - Include stable index-only output/decode work in the lower bound of prepared-range cost uncertainty. - Propagate expression-binding failures instead of silently accepting incomplete rewrites. ## Root cause The previous fix used physical stored-key serialization (`serial_full`) for SQL comparison operands. Prepared NULL bounds therefore needed decoded residual predicates to recover SQL three-valued semantics. For OR-ed random ranges this duplicated parameter folding and serialized extraction work on every execution, and the cost model also undercounted stable downstream work when evaluating an uncertain prepared range. The fix models the two contracts independently: stored keys must preserve NULL components, but comparison bounds must reject NULL. `serial` and `serial_full` are byte-identical for non-NULL components, so using `serial` for bounds preserves index compatibility without row-by-row NULL guards. ## Compatibility and regression coverage - Non-unique index storage and join runtime-filter materialization still use `serial_full`. - Nullable strict upper bounds and ambiguous varchar/varbinary prefixes retain exact decoded residuals. - Broad literal ranges still reject the index; uncertain prepared ranges keep the index when cost intervals overlap. - Covering scans remain covering, while non-covering prepared ranges still select an index join. - Prepared equality, IN, BETWEEN, mixed OR, update, delete, and replace paths are covered. ## Validation - `mo-cgo-test -count=1 ./pkg/sql/plan/function ./pkg/sql/plan` - Focused `-race` coverage for all changed planner and function cases - CGo-configured `go vet ./pkg/sql/plan ./pkg/sql/plan/function` - Scoped molint and golangci-lint: clean - a55, 2M rows, 100 threads, 4 GiB memory cache: - intermediate decoded-guard implementation: 22,906.80 TPS, p95 24.83 ms - systemic serialization fix: 28,260.18 TPS, p95 19.65 ms - +23.37% TPS and -20.86% p95, with zero errors - a55 CPU profile: `EvalFoldExpr` 16.25% -> 10.77%, `tryFoldParameter` 11.71% -> 7.73% - `EXPLAIN ANALYZE`: narrow prepared ranges use the covering index; broad covering ranges use the base table scan The historical CI comparison used 10M rows and 1000 threads, so its absolute TPS is intentionally not compared with the a55 2M/100-thread validation. Fixes matrixorigin#26971
What changed
Physical non-unique composite keys continue to use
serial_full, while lookup bounds use NULL-propagatingserial.prefix_inignore NULL needles and compact only owned, non-NULL prefixes.Root cause
The previous fix used physical stored-key serialization (
serial_full) for SQL comparison operands. Prepared NULL bounds therefore needed decoded residual predicates to recover SQL three-valued semantics. For OR-ed random ranges this duplicated parameter folding and serialized extraction work on every execution, and the cost model also undercounted stable downstream work when evaluating an uncertain prepared range.The fix models the two contracts independently: stored keys must preserve NULL components, but comparison bounds must reject NULL.
serialandserial_fullare byte-identical for non-NULL components, so usingserialfor bounds preserves index compatibility without row-by-row NULL guards.Compatibility and regression coverage
serial_full.Validation
mo-cgo-test -count=1 ./pkg/sql/plan/function ./pkg/sql/plan-racecoverage for all changed planner and function casesgo vet ./pkg/sql/plan ./pkg/sql/plan/functionEvalFoldExpr16.25% -> 10.77%,tryFoldParameter11.71% -> 7.73%EXPLAIN ANALYZE: narrow prepared ranges use the covering index; broad covering ranges use the base table scanThe historical CI comparison used 10M rows and 1000 threads, so its absolute TPS is intentionally not compared with the a55 2M/100-thread validation.
Fixes #26971