Repository navigation
fix(plan): guard paired range index selection - #24437
mergify[bot] merged 1 commit into
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? |
a40b9a8 to
2bbdc74
Compare
There was a problem hiding this comment.
Pull request overview
This PR is a follow-up fix in the SQL planner’s secondary-index selection logic to ensure paired range candidates (e.g., col >= a AND col <= b) are subject to the same large-range stats guard as single-range candidates, preventing expensive index-join choices on large tables.
Changes:
- Moves paired-range selection into the ordered filter scan so it can’t bypass the existing non-PK large-range stats cutoff.
- Factors the large-range decision into a shared helper (
shouldSkipLargeRangeIndexByStats) and applies it to both single-range and paired-range candidates. - Adds unit coverage to verify large paired ranges are skipped and that selection remains deterministic by filter order.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/sql/plan/apply_indices.go | Applies the existing non-PK large-range stats guard to paired-range index candidates via an ordered scan and a shared helper. |
| pkg/sql/plan/apply_indices_test.go | Adds focused unit tests covering “skip large paired range” and deterministic paired-range selection behavior. |
aunjgr
left a comment
There was a problem hiding this comment.
LGTM. The earlier review note is non-blocking.
Apply the same large-range stats guard to paired secondary-index range candidates so they do not bypass the non-PK Outcnt/selectivity cutoff added for single-range scans. Co-authored-by: Copilot <[email protected]>
2bbdc74 to
663dd78
Compare
Merge Queue Status
This pull request spent 42 seconds in the queue, including 5 seconds running CI. Required conditions to merge
|
Ref matrixorigin#24348 The deterministic paired-range path in `getIndexForNonEquiCond` still returned before the existing non-PK range guard ran, so a large secondary-index paired range could bypass the `InFilterCardLimitNonPK` / selectivity cutoff that already protected single-range candidates. On large tables that can reopen the same expensive index-join choice the earlier guard was meant to avoid. This change applies the same stats guard to paired-range candidates and adds a focused unit test for the large-range case. The planner behavior for small/selective paired ranges is unchanged. To keep this follow-up low risk, it does not add new distributed BVT cases: the existing `expr_opt_test.go` coverage already checks that non-sort-key composite filters are preserved, and this PR only touches the local secondary-index candidate selection guard. Approved by: @ouyuanning, @aunjgr
Ref matrixorigin#24348 The deterministic paired-range path in `getIndexForNonEquiCond` still returned before the existing non-PK range guard ran, so a large secondary-index paired range could bypass the `InFilterCardLimitNonPK` / selectivity cutoff that already protected single-range candidates. On large tables that can reopen the same expensive index-join choice the earlier guard was meant to avoid. This change applies the same stats guard to paired-range candidates and adds a focused unit test for the large-range case. The planner behavior for small/selective paired ranges is unchanged. To keep this follow-up low risk, it does not add new distributed BVT cases: the existing `expr_opt_test.go` coverage already checks that non-sort-key composite filters are preserved, and this PR only touches the local secondary-index candidate selection guard. Approved by: @ouyuanning, @aunjgr
Ref matrixorigin#24348 The deterministic paired-range path in `getIndexForNonEquiCond` still returned before the existing non-PK range guard ran, so a large secondary-index paired range could bypass the `InFilterCardLimitNonPK` / selectivity cutoff that already protected single-range candidates. On large tables that can reopen the same expensive index-join choice the earlier guard was meant to avoid. This change applies the same stats guard to paired-range candidates and adds a focused unit test for the large-range case. The planner behavior for small/selective paired ranges is unchanged. To keep this follow-up low risk, it does not add new distributed BVT cases: the existing `expr_opt_test.go` coverage already checks that non-sort-key composite filters are preserved, and this PR only touches the local secondary-index candidate selection guard. Approved by: @ouyuanning, @aunjgr
What type of PR is this?
Which issue(s) this PR fixes:
Ref #24348
What this PR does / why we need it:
Ref #24348
The deterministic paired-range path in
getIndexForNonEquiCondstill returned before the existing non-PK range guard ran, so a large secondary-index paired range could bypass theInFilterCardLimitNonPK/ selectivity cutoff that already protected single-range candidates. On large tables that can reopen the same expensive index-join choice the earlier guard was meant to avoid.This change applies the same stats guard to paired-range candidates and adds a focused unit test for the large-range case. The planner behavior for small/selective paired ranges is unchanged.
To keep this follow-up low risk, it does not add new distributed BVT cases: the existing
expr_opt_test.gocoverage already checks that non-sort-key composite filters are preserved, and this PR only touches the local secondary-index candidate selection guard.Validation