Skip to content

fix(plan): guard paired range index selection - #24437

Merged
mergify[bot] merged 1 commit into
matrixorigin:mainfrom
LeftHandCold:fix/pr24289-paired-range-guard-main
May 19, 2026
Merged

mergify[bot] merged 1 commit into
matrixorigin:mainfrom
LeftHandCold:fix/pr24289-paired-range-guard-main

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented May 18, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Ref #24348

What this PR does / why we need it:

Ref #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.

Validation

source /Users/shenjiangwei/Work/code/matrixone/setup_env.sh && go test ./pkg/sql/plan ./pkg/vm/engine/readutil -count=1

Copilot AI review requested due to automatic review settings May 18, 2026 08:18
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added kind/bug Something isn't working kind/enhancement kind/test-ci labels May 18, 2026
@LeftHandCold
LeftHandCold force-pushed the fix/pr24289-paired-range-guard-main branch from a40b9a8 to 2bbdc74 Compare May 18, 2026 08:22
@matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label May 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 aunjgr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@mergify

mergify Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-05-19 07:28 UTC · Rule: main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-05-19 07:29 UTC · at 663dd780746c0c678d99a92a7dbbf100457d1314 · squash

This pull request spent 42 seconds in the queue, including 5 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage

@mergify
mergify Bot merged commit 90d4065 into matrixorigin:main May 19, 2026
23 of 24 checks passed
@mergify mergify Bot removed the queued label May 19, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
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
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
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
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
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

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/enhancement kind/test-ci size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants