Repository navigation
fix(plan): bound serialized regular-index range scans - #32503
Conversation
Match a suffix range after a composite equality prefix, preserve exact residuals and nullable-unique completeness, and route hinted range aggregates through regular-index range planning. Related to matrixorigin#32209.
Apply the regular-index stability guard before serialized range access for scoped FORCE INDEX hints. Throwing bounds must retain decoded filter short-circuiting; literal bounds continue to use serialized ranges. Add order/group regressions for throwing and literal bounds.
|
@XuPeng-SH Fixed in Automatic composite suffix matching now calls The exact unhinted SQL case is now in |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 9103f5188a418fbf4863d948ee32734519641617
Assessment: approve
The change coherently reuses existing index matching, normalization and scan builders. Combined bounds reduce suffix-range scans while exact residuals and stability/completeness guards preserve SQL semantics. The prior error-domain finding is resolved; no actionable findings remain.
Model: gpt-6.1-sol / max
Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0
Validation:
-
All 11 selected planner tests passed. Independent frontend SQL probes passed memory/persisted cases and two same-instance cycles with teardown verified.
-
The same composite query read 4 blocks/7 rows at the merge-base and 2 blocks/4 rows at HEAD, with identical results. Empty-range and forced-aggregate work controls passed.
-
Reviewed all four changed files, six discussion entries and linked issue context. Native inputs, formatting, source fingerprints, receipts and logs are reconciled in receipt-reconciliation.json.
-
Reused frozen-head CI successes for build, owning UT, SCA, coverage and active BVT.
Limitations:
-
Local SQL probes used one CN. Broad CI evidence comes from the supplied status snapshot and source selection; raw CI logs were unavailable.
-
The original 30M-row, three-CN latency benchmark was not rerun; no wall-clock improvement is asserted.
|
@Mergifyio queue |
❌ Left the queue ·
|
|
The Ubuntu/x86 UT failure is tracked in existing issue #32424. Run 42956686144 attempt 1, job 130313413109, failed |
What type of PR is this?
Which issue(s) this PR fixes:
Related to #32209.
What this PR does / why we need it:
Root causes
FORCE INDEXprocessing could select the hinted covering fallback before ordinary range planning, causing bounded aggregates such asCOUNT(DISTINCT a)to scan the whole covering index.INbound that the decoded filter order would short-circuit, as exposed by UT Coverage run 42903327705.KEY ix(a,b), an emptya=99prefix and a throwingbsuffix selectedprefix_in_rangeand raised error 20203 instead of retaining the equality-prefix scan.BETWEENand open comparison pairs but lacked the reachable closed-pair spelling>=plus<=.Changes
prefix_between/prefix_in_range, or full-keybetween/in_range, serialized bounds. Retain decoded predicates as exact row-side residuals and preserve ordered-LIMIT safeguards.COUNT(DISTINCT)queries. Require stable filter evaluation before using that serialized access; throwing bounds retain decoded filters, while literal bounds retainprefix_in.regularIndexFiltersHaveStableEvaluationbefore automatic composite suffix selection. Unstable filters retain equality-prefix scans, while stable literal suffixes retain serializedprefix_in_rangebounds.composite_index_rangeBVT coverage for indexed-versus-unindexed results, scan work, boundaries, duplicates, NULLs, unique completeness, byte strings, decimals, and fallback behavior. Include unique and non-unique closed comparison pairs, asserting both serialized bounds and exact residual operators.Issue-to-test proof
prefix_eq; it passes with serialized bounds and exact residuals. SQL returnsSUM(k)=34on indexed and unindexed tables, with 2 blocks/4 rows for the selective range and 0/0 for the empty range.BETWEEN; it passes with a bounded lookup. ExactCOUNT(DISTINCT a)plans both useidx_a, return 2/3 for bounded/full queries and their unindexed controls, and reduce boundedinputRowsfrom 12 to 9.prefix_infor throwing bounds; with the guard, they retain decodedIN, and literal controls retainprefix_in. The exact CI SQL case passes in both memory and persisted modes, and the clean-base memory control also passes.prefix_in_range; it now retainsprefix_eq, and its literal control retainsprefix_in_range. The exact unhinted SQL BVT returns no rows without error, while the stable control returns(9,y).(93,99); repaired indexed and unindexed queries return(91,92,93,94,99), or(93,99)withc IS NOT NULL. All four independent coveringSELECT b ... ORDER BY bcases passed.b>90queries return only(HEX 61,91), whileb>=90returns(61,90),(61,91), matching unindexed controls and excluding escaped-NUL peers.Validation
Composite and forced-aggregate base red/green tests:
Nullable-unique and byte-string correctness red/green:
.agents/skills/mo-dev/scripts/mo-cgo-test -v -run '^(TestRegularIndexUniqueSuffixRangeRequiresCompleteRowSource|TestRegularIndexCompositeSuffixRangeBounds)$' -count=1 -timeout=10m -o /tmp/issue-32209-review-validation/plan.test ./pkg/sql/planScoped error-domain planner regression, all four order/group throwing/literal cases passed in 2.065s:
.agents/skills/mo-dev/scripts/mo-cgo-test -o /tmp/issue-32209-ci-repair/plan-post-fix.test -v -count=1 -timeout=10m -run '^TestScopedForceIndexPreservesFilterEvaluationDomain$' ./pkg/sql/planExact public SQL regression, memory and persisted modes passed in 16.423s:
.agents/skills/mo-dev/scripts/mo-cgo-test -o /tmp/issue-32209-ci-repair/sqlintegration-post-fix.test -v -count=1 -timeout=15m -run '^TestLikePrefixIndex$/^(memory|persisted)$/^alternative_preserves_error_domains$' ./pkg/tests/sqlintegrationAutomatic suffix error-domain regression, with the throwing case failing before the guard and both throwing/literal cases passing afterward:
.agents/skills/mo-dev/scripts/mo-cgo-test -run '^TestRegularIndexCompositeSuffixRangePreservesFilterEvaluationDomain$' -count=1 -timeout=180s -o /tmp/issue-32209-plan-review.test ./pkg/sql/planCoverage-gate regression: both new closed comparison-pair cases passed. Replaying the CI parser with the failed run's profile and the new focused profile passes the strict gate at 98/130 changed lines (75.38%):
.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s -run '^TestRegularIndexCompositeSuffixRangeBounds$' -coverprofile=/tmp/issue-32209-coverage-repair/focused-cover.out -o /tmp/issue-32209-coverage-repair/plan-focused.test ./pkg/sql/planComplete owning package after the automatic-path repair, passed in 226.105s:
BVT normal comparison mode, two runs with 111/111 statements passing each time, with database teardown verified after both runs (
ARTis the isolated runtime directory andWTis the worktree). Generated results were reviewed and contain only the new empty-result and stable-literal cases:Whole-binary build and incremental static checks passed. The latest repair also passed
gofmt, vet, and lint with no diagnostics:Residual risks
serial_extractcomparison and intentional<opaque>literal redaction. This PR does not change those behaviors or restrict legitimate join output.