Skip to content

fix(plan): intersect BETWEEN selectivity with column domain - #32224

Merged
mergify[bot] merged 1 commit into
matrixorigin:mainfrom
ck89119:issue-32046-main
Nov 5, 2026
Merged

mergify[bot] merged 1 commit into
matrixorigin:mainfrom
ck89119:issue-32046-main

Conversation

@ck89119

@ck89119 ck89119 commented Nov 5, 2026

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 #32046

What this PR does / why we need it:

The numeric and decimal min/max estimators score BETWEEN predicates by the query range's width, even when it does not intersect the column's observed domain.

Reuse the existing interval estimator in both paths to clip the range to the column domain, return near-zero selectivity for empty intersections, and correctly handle full coverage and singleton domains. Preserve decimal literal scaling and leave the separate fixed-selectivity behavior tracked in #31994 unchanged.

Add deterministic boundary/type tests, a parse/bind/build regression, and a four-row SQL regression checking scan selectivity and actual results for integer, Decimal64, and Decimal128 columns.

Validation (Go 1.27.1, macOS arm64):

  • Confirmed the new regressions fail before the fix and pass afterward.
  • Focused tests and the complete pkg/sql/plan test package passed through mo-cgo-test; both changed production statements are covered (100%).
  • gofmt, package-scoped go vet, and incremental golangci-lint 2.14.0 passed.
  • Built mo-service; mo-tester generated the reviewed result and passed normal comparison twice on the same isolated instance (22/22 each), with teardown verified.

@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 →

@XuPeng-SH

XuPeng-SH commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 4c5942ab6ce38c85b9684a7a9472c4f0f2192ed5

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH 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.

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

Commit: 4c5942ab6ce38c85b9684a7a9472c4f0f2192ed5

Assessment: approve

Both estimators correctly reuse the existing interval estimator to clip BETWEEN ranges, preserving conversions and fallbacks without adding production mechanisms. Boundary tests and SQL regressions cover the defect; no actionable findings remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed the complete delta, linked issues, discussion, interval helper, binding path and statistics consumers.

  • Reused frozen-head CI successes for Linux UT/coverage, arm64 static analysis and both BVT groups.

  • Local source-audit.py passed: clean frozen source, diff/gofmt checks, 24 boundary expectations and seven SQL selectivity/result pairs; receipt checks/1793857366677901778-2.json and source-audit.log.

Limitations:

  • No local Go or service tests were rerun. Detailed author execution logs were not supplied; separate prefix-selectivity behavior remains outside this fix.

@mergify mergify Bot added the queued label Nov 5, 2026
@mergify

mergify Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as 3820136 at 06:52 UTC

1 h 8 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Thu 5 Nov, 05:44 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged 06:52 · 3820136 · squash
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

@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.

Reviewed the complete diff and the existing interval estimator/callers. Both numeric and decimal BETWEEN/in_range paths now intersect the column domain, with the existing unsupported-literal fallback and decimal endpoint scaling preserved. The boundary, binder and SQL regressions cover disjoint/overlap/full-coverage cases without changing query evaluation semantics.

No blocking findings. Reused the successful latest head CI (UT, SCA, coverage and both BVT topologies); superseded canceled runs were not treated as current failures. No local execution was performed.

@mergify
mergify Bot merged commit 3820136 into matrixorigin:main Nov 5, 2026
@mergify mergify Bot removed the queued label Nov 5, 2026
@ck89119
ck89119 deleted the issue-32046-main branch November 5, 2026 06:53

This branch was previously deployed

1 inactive deployment
ci — 4c5942ab Deployed Nov 5, 2026 by ck89119
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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance]: BETWEEN min/max selectivity never checks range intersection

4 participants