Skip to content

fix(planner): account for probe fanout in join index costing - #32231

Merged
XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
ck89119:issue-32013-main
Nov 5, 2026
Merged

XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
ck89119:issue-32013-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 #32013

What this PR does / why we need it:

A small semijoin build can match many rows of a low-NDV probe index. Admitting index backfill based on build cardinality alone can overflow the backfill runtime filter, leaving a full table scan behind an extra dependency and a single-CN placement constraint.

Estimate matching probe rows before publishing join-index candidates, then apply the existing backfill capacity and preparation-cost model. Preserve selective indexes, FORCE/IGNORE hints, and the existing fallback for unavailable statistics. Composite-key estimates do not assume independent columns. Only reject an existing index path when every probe-scan residual has proven stable evaluation; otherwise retain the path so invalid JSON on nonmatching rows is not newly evaluated. No runtime-filter execution protocol changes are needed.

Validation (Go 1.27.1, darwin/arm64):

  • SQL-to-plan regressions cover low-NDV costing and unsafe residuals (JSON cast, JSON extraction, and nested predicates), with failures on their respective unfixed revisions. The full pkg/sql/plan suite passes through mo-cgo-test after merging the latest main.
  • Changed-production-code coverage blocks: 44/46 statements (95.7%); helper coverage: 94.6%. The residual-safety guard has 100% changed-statement coverage.
  • Service build, gofmt, vet, and repository-configured incremental lint pass.
  • The extended BVT was regenerated and passed comparison twice (55/55 each) on a verified isolated instance, with teardown checked between runs. Covers duplicates, NULLs, empty builds, hints, persisted residuals, and JSON evaluation scope. A reduced-capacity 10-row fixture proves that nonmatching invalid JSON is not evaluated, while matching invalid JSON still reports error 20301; the original capacity is restored.
  • Both CN coordinators return correct results with forced distributed execution; physical plans confirm cross-CN receivers.

Paired local measurements of the initial cost-admission change (before the residual-safety follow-up), on the same persisted/analyzed data, with two warmups and seven interleaved samples per query:

1M-row low-NDV query Baseline IN Fixed IN Fixed DISTINCT JOIN
Single CN 2.871 ms 2.232 ms 2.040 ms
Two CNs 2.920 ms 2.071 ms 1.953 ms

Low-NDV plans no longer have the index-backfill dependency or its ForceOneCN constraint. The high-NDV control retains index access and reads 100 probe rows. These are local medians, not a claim to reproduce the original report's exact 27x ratio; estimates remain conservative for skewed/correlated data.

@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: 9a78ab47fd030942d654f47caa8526e7aaea8c04

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: 9a78ab47fd030942d654f47caa8526e7aaea8c04

Assessment: approve

Join-index admission now accounts for estimated probe fanout through the existing cost model. It preserves hints and statistics fallbacks, and retains established plans when residual evaluation safety is unproven. The added logic stays within the existing planner owner; no actionable defects found.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • Reviewed all four changed files, linked issue #32013 and both discussion items, including independent plan and SQL oracles.

  • Reused exact-head successful build, UT, SCA, coverage and proxy/pessimistic BVT results after confirming planner and optimizer-case selection.

  • Local formatting, whitespace and source/discussion/55-statement SQL-pair audits passed. Receipts and retained logs are reconciled in validation-ledger.json.

  • Assessed the supplied paired performance measurements, high-NDV control and reported two-CN execution evidence.

Limitations:

  • Local Go, SQL and benchmark runs were not repeated; frozen-head CI and supplied author evidence were assessed separately.

  • NDV-based estimates remain approximate for skewed or correlated data. Reported timings predate the residual-safety follow-up and do not establish the original incident's exact speedup ratio.

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

mergify Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

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

So far

  • ✅ Entered the queue Thu 5 Nov, 15:21 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 16:42 · 1611efd

Reason

Pull request #32231 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

To get back in the queue

  • Push a change if one is needed: the pull request is queued again once its queue conditions match.
  • If no change is needed, tick the box below to queue it again as it is.

Merge conditions not met when it left the queue

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request
2 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection

Times in UTC · dashboard · how the merge queue works

This branch was successfully deployed

No deployments
ci — 1611efd3 Deployed Nov 5, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued 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]: IN-subquery semijoin is 27x slower than equivalent JOIN

3 participants