Repository navigation
fix(plan): relax index-only scan selectivity guard to fix random_ranges regression - #24338
Merged
mergify[bot] merged 2 commits intoMay 11, 2026
Merged
Conversation
The guard added in matrixorigin#24309 to prevent OOM from non-selective range scans used InFilterCardLimitNonPK (10000) as the outcnt threshold in tryIndexOnlyScan. This is too aggressive for index-only scans which don't access the base table — queries like sysbench random_ranges (OR of BETWEENs on an indexed column) produce ~10k rows from 10M and were incorrectly rejected, causing a 45% TPS regression. Use GetInFilterCardLimitOnPK (which scales with table size, up to 1M) instead. The selectivity check (>= 0.3) alone is sufficient to prevent the OOM scenario of scanning 30%+ of the index table. Fixes matrixorigin#24335 Co-Authored-By: Claude Opus 4.6 <[email protected]>
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one. |
Verifies that the tryIndexOnlyScan selectivity guard uses the PK card limit (scales with table size) instead of the fixed InFilterCardLimitNonPK. The test confirms: random_ranges (10M rows, outcnt=10000) passes the guard, while truly non-selective queries (outcnt=2M or selectivity>=0.3) are rejected. Co-Authored-By: Claude Opus 4.6 <[email protected]>
ouyuanning
approved these changes
May 11, 2026
Contributor
Merge Queue Status
This pull request spent 20 seconds in the queue, including 2 seconds running CI. Required conditions to merge
|
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
…es regression (matrixorigin#24338) PR matrixorigin#24309 added a selectivity guard in `tryIndexOnlyScan` to prevent OOM from non-selective secondary index range scans. However, the guard used `InFilterCardLimitNonPK` (10000) as the outcnt threshold, which is too aggressive for index-only scans. For sysbench `random_ranges` (10 random `BETWEEN` ranges on column `k` with a secondary index, 10M row table): - The query only reads the indexed column → ideal for index-only scan - Estimated outcnt ≈ 10000 (10 ranges × ~1000 rows each) - The guard rejects the index-only scan, forcing a full table scan → **45% TPS regression** Index-only scans don't access the base table, so the OOM scenario (excessive metadata/bloom filter re-reads from base table join) doesn't apply. The fix uses `GetInFilterCardLimitOnPK` (scales with table size, up to 1M) instead of the fixed 10000 threshold. The selectivity check (`>= 0.3`) alone is sufficient to prevent the OOM case of scanning 30%+ of the index table. Approved by: @ouyuanning
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
…es regression (matrixorigin#24338) PR matrixorigin#24309 added a selectivity guard in `tryIndexOnlyScan` to prevent OOM from non-selective secondary index range scans. However, the guard used `InFilterCardLimitNonPK` (10000) as the outcnt threshold, which is too aggressive for index-only scans. For sysbench `random_ranges` (10 random `BETWEEN` ranges on column `k` with a secondary index, 10M row table): - The query only reads the indexed column → ideal for index-only scan - Estimated outcnt ≈ 10000 (10 ranges × ~1000 rows each) - The guard rejects the index-only scan, forcing a full table scan → **45% TPS regression** Index-only scans don't access the base table, so the OOM scenario (excessive metadata/bloom filter re-reads from base table join) doesn't apply. The fix uses `GetInFilterCardLimitOnPK` (scales with table size, up to 1M) instead of the fixed 10000 threshold. The selectivity check (`>= 0.3`) alone is sufficient to prevent the OOM case of scanning 30%+ of the index table. Approved by: @ouyuanning
VioletQwQ-0
pushed a commit
to VioletQwQ-0/matrixone
that referenced
this pull request
Sep 17, 2026
…es regression (matrixorigin#24338) PR matrixorigin#24309 added a selectivity guard in `tryIndexOnlyScan` to prevent OOM from non-selective secondary index range scans. However, the guard used `InFilterCardLimitNonPK` (10000) as the outcnt threshold, which is too aggressive for index-only scans. For sysbench `random_ranges` (10 random `BETWEEN` ranges on column `k` with a secondary index, 10M row table): - The query only reads the indexed column → ideal for index-only scan - Estimated outcnt ≈ 10000 (10 ranges × ~1000 rows each) - The guard rejects the index-only scan, forcing a full table scan → **45% TPS regression** Index-only scans don't access the base table, so the OOM scenario (excessive metadata/bloom filter re-reads from base table join) doesn't apply. The fix uses `GetInFilterCardLimitOnPK` (scales with table size, up to 1M) instead of the fixed 10000 threshold. The selectivity check (`>= 0.3`) alone is sufficient to prevent the OOM case of scanning 30%+ of the index table. Approved by: @ouyuanning
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) does this PR fix?
Fixes #24335
What this PR does / why we need it:
PR #24309 added a selectivity guard in
tryIndexOnlyScanto prevent OOM from non-selective secondary index range scans. However, the guard usedInFilterCardLimitNonPK(10000) as the outcnt threshold, which is too aggressive for index-only scans.For sysbench
random_ranges(10 randomBETWEENranges on columnkwith a secondary index, 10M row table):Index-only scans don't access the base table, so the OOM scenario (excessive metadata/bloom filter re-reads from base table join) doesn't apply. The fix uses
GetInFilterCardLimitOnPK(scales with table size, up to 1M) instead of the fixed 10000 threshold. The selectivity check (>= 0.3) alone is sufficient to prevent the OOM case of scanning 30%+ of the index table.Summary of changes
pkg/sql/plan/apply_indices.go: IntryIndexOnlyScan, replaceInFilterCardLimitNonPKwithGetInFilterCardLimitOnPK(service, tableCnt)in the non-equality leading condition guard.🤖 Generated with Claude Code