Repository navigation
fix(plan): backport PR24289 range merge fixes to 4.0-dev - #24419
Conversation
PR matrixorigin#24289 added prefix range PK filters for composite keys, but its paired range pre-merge step was applied before checking whether the range column belongs to the composite sort key. As a result, ordinary predicates like `col > x AND col < y` on non-sort-key columns could be rewritten into `in_range` during normal table-scan filter normalization. That rewrite expands the new readutil/ObjectMeta fast-filter path beyond the intended composite-key optimization. In large TPCH scans, low-selectivity ordinary range filters can then spend extra time loading object metadata, building block lists, and shipping larger pipeline block-list messages. This matches the TPCH slowdown and higher post-TPCH RSS observed after matrixorigin#24289, which later leaves too little memory headroom for TPCC under the 55Gi limit. This PR limits the paired range merge to the intended scope: - skip this paired-range rewrite for single-part sort keys; - only merge paired ranges when the range column is one of the composite sort-key parts; - preserve matrixorigin#24289's intended optimization for cases such as `pk_a = ? AND pk_b > ? AND pk_b < ?`; - keep ordinary non-sort-key ranges as their original comparison filters. Added planner tests for both sides: non-sort-key ranges stay as `>`/`<`, while composite sort-key ranges still merge into `in_range`. Approved by: @ouyuanning, @aunjgr
Choose among multiple paired-range index candidates by filter order instead of Go map iteration so EXPLAIN and plan selection stay stable. Co-authored-by: Copilot <[email protected]>
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? |
There was a problem hiding this comment.
Pull request overview
This PR backports planner fixes for paired range handling, limiting composite-key range merging and adding deterministic secondary-index paired-range selection.
Changes:
- Restricts paired range merging in composite-key filter optimization to composite sort-key parts.
- Adds secondary-index paired range detection/lowering via a new range condition type.
- Adds unit tests for composite-key range merging and deterministic paired-range index choice.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
pkg/sql/plan/expr_opt.go |
Narrows paired range merging scope for composite sort keys. |
pkg/sql/plan/expr_opt_test.go |
Adds tests for sort-key vs non-sort-key range merging. |
pkg/sql/plan/apply_indices.go |
Adds paired range index selection and replacement logic. |
pkg/sql/plan/apply_indices_test.go |
Adds tests for paired range index detection and replacement. |
Integrate paired-range detection into the normal filter-order scan so earlier IN/BETWEEN/single-range candidates keep their previous priority while paired ranges remain deterministic. Co-authored-by: Copilot <[email protected]>
XuPeng-SH
left a comment
There was a problem hiding this comment.
Requesting changes due to two issues found in review:
-
Planner selection risk: In pkg/sql/plan/apply_indices.go, the paired-range early return bypasses the single-range Outcnt guard (InFilterCardLimitNonPK). On large tables this can pick an expensive index join. Please evaluate node.Stats.Outcnt against InFilterCardLimitNonPK before returning paired-range or apply equivalent gating.
-
Missing BVT coverage: Add BVT cases for:
- composite PK / CLUSTER BY tables with range predicates on non-PK columns (e.g., PK(a,b); WHERE a=1 AND c>5 AND c<10) to prevent predicate loss;
- secondary-index range + residual non-indexed filter (e.g., WHERE val BETWEEN x AND y AND flag=1) to ensure residual filters are applied.
Please address these and re-request review.
|
Pushed I kept this follow-up narrow on purpose: it adds a focused unit test for the paired-range guard, and does not expand into new distributed BVT cases. The existing |
Merge Queue Status
This pull request spent 53 minutes 50 seconds in the queue, including 4 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
Ref #24348
What this PR does / why we need it:
This PR brings the PR #24289 fix set to
4.0-dev.It includes:
main, which limits paired range rewrite inexpr_opt.goto composite sort-key parts only, while preserving the intended secondary-index paired-range lowering inapply_indices.go;getIndexForNonEquiCond, so when multiple indexed columns each form a paired range, index selection followsnode.FilterListorder instead of Go map iteration order.Together these changes keep the root-cause fix for the TPCH slowdown / TPCH->TPCC OOM path, preserve the intended
prefix_between/prefix_in_rangebehavior on regular index scans, and avoid plan / EXPLAIN drift from nondeterministic paired-range candidate selection.Validation