Skip to content

[4.2-dev] fix(plan): bound covering index range scans - #32930

Merged
XuPeng-SH merged 3 commits into
matrixorigin:4.2-devfrom
XuPeng-SH:codex/issue-32928-42
Nov 20, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:4.2-devfrom
XuPeng-SH:codex/issue-32928-42

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

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

Which issue(s) this PR fixes:

Fixes #32928.

What this PR does / why we need it:

On 4.2, a forced covering index scan could evaluate a leading range only after decoding every index entry, while an equality-prefix covering scan could leave the next-column range as a row filter. Build serialized bounds at those scan owners and combine compatible opposing endpoints, including for index backfill. Preserve exact SQL rechecks, existing narrower bounds and the previous fallback for unsupported or potentially throwing expressions and invalid range flags.

On the same persisted 30M-entry dataset, the forced COUNT(DISTINCT) range returned 100 before and after, while index input fell from 3,720 blocks / 30M rows to 480 blocks / 3M rows. This was a single-CN local scan-work comparison, not a latency benchmark. New covering and paired-bound lowering is conservative for dynamic or non-integer expressions; prepared statements retain their existing fallback where applicable.

Validation:

  • Full ./pkg/sql/plan unit suite, normal and -race.
  • Incremental gofmt, go vet and golangci-lint for ./pkg/sql/plan.
  • 58/58 SQL regression statements, including indexed controls, open/closed/invalid bounds, NULL, nullable unique indexes, embedded NUL and prepared reuse.
  • Persisted-data replays for covering and noncovering paired ranges, default JOINs at four thresholds, and 72 indexed-versus-unindexed boundary comparisons.

@XuPeng-SH
XuPeng-SH requested a review from aunjgr as a code owner November 19, 2026 09:36
@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 →

@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Nov 19, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Nov 19, 2026
@mergify

mergify Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: c5e1d11405cedeb484bf45a062c0d3d7424a1964

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

mo-bot review · mo-bot-local · review

Commit: c5e1d11405cedeb484bf45a062c0d3d7424a1964

Assessment: approve

Reviewed against the pinned 4.2-dev target at 5d0c7e6, with merge-base 7d1cacc. The change reuses the existing serialized-key operators and shares suffix-bound construction across covering scans and index backfill. Matched persisted-data checks confirmed less scan work and identical SQL results.

Model: gpt-6.2-sol / xhigh

Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3

Validation:

  • The full planner suite and focused SQL-function and storage-reader range tests passed. See planner.log, range-consumers.log, and receipts 1795082083215415869-2.json and 1795082120203576922-2.json.

  • An embedded SQL run executed all 58 committed statements, compared 29 result sets, checked four representative plans, and verified database cleanup. On matched flushed fixtures, the forced leading range fell from 9 blocks and 65,539 input rows to 1 block and 5 rows. Selective default JOINs already pruned on the base and had identical scan counts at head. See sql-base-metrics.log, sql-candidate-metrics.log, and receipts 1795082226583406838-2.json and 1795082227131603173-2.json.

  • The paired composite suffix fell from 6 blocks and 49,152 input rows to 1 block and 99 rows on both default and forced covering scans. Covering and backfill results matched the unindexed controls. See sql-base-suffix.log, sql-candidate-suffix.log, and receipts 1795082294896732177-2.json and 1795082296863780411-2.json.

  • Diff hygiene, runtime preflight, and the native prerequisite build passed.

Limitations:

  • The embedded SQL probe checked results and stable plan fragments. The full mo-tester comparison, restart coverage, and the author's 30-million-entry run were outside local validation. Planner and BVT CI coverage was incomplete in the frozen snapshot.

  • A larger probe with out-of-domain in_range flag 4 returned different results on the sorted index and base-table paths on both revisions. The new bound guard preserves the existing fallback for that flag. Early probe failures and the corrected fixture runs are retained in the diagnostic directory.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Commit: c5e1d11405cedeb484bf45a062c0d3d7424a1964

Independent static design review · gpt-6.1-terra / max

No additional confirmed defect was identified within the source paths reviewed. I traced the new integer/literal eligibility and serialized-domain guards, opposing endpoint merging, NULL and composite-prefix handling, and the in-memory and persisted range consumers. Unsupported or potentially throwing expressions and prepared/dynamic operands were checked against the existing fallback paths.

One scope distinction matters: suffix predicates retain decoded row-level conditions, but not every leading integer bound retains the original SQL predicate; some cases rely on the serialized comparison being exact. The nullable one-sided upper-bound path retains a decoded recheck. This review does not establish encoding correctness for every untested value or type.

The same-head Required, x86 UT, arm64 SCA and the proxy/pessimistic multi-CN BVT jobs passed. Upgrade compatibility jobs were skipped. I did not independently run SQL, prepared-statement, restart, extreme-value, multi-CN, persisted-data or performance tests. The author's 30-million-entry result and the other reviewer's smaller persisted-data probes remain their reported evidence, not executions from this review.

@XuPeng-SH

XuPeng-SH commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: c5e1d11405cedeb484bf45a062c0d3d7424a1964

New discussion was assessed; the previous review remains unchanged.

This branch was successfully deployed

No deployments
ci — 8bf856a8 Deployed Nov 20, 2026 by XuPeng-SH
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 size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants