Skip to content

fix(planner): merge secondary indexes for OR predicates - #32086

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
ck89119:issue-31863-main
Nov 3, 2026
Merged

mergify[bot] merged 3 commits into
matrixorigin:mainfrom
ck89119:issue-31863-main

Conversation

@ck89119

@ck89119 ck89119 commented Nov 3, 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 #31863

What this PR does / why we need it:

Add a cost-gated access path for OR predicates across secondary indexes, after existing single-index alternatives. Each branch produces physical primary keys; one distinct union removes overlapping matches. Exact PK-covered queries avoid the base table, while other queries use one existing INDEX join and retain residual predicates.

Candidate discovery is capped at eight branches without DNF expansion. Unsupported branches, unreliable statistics, excessive cardinality, or unfavorable physical costs retain the existing scan path. Preserve NULL and bag semantics, hints, snapshots, and deduplication before pagination. Backfill retains the existing single-CN policy.

Design: approved v1.

Local validation (Go 1.27.1, macOS arm64):

  • Full planner suite, focused union/INDEX and lifecycle consumer tests, vet, and incremental lint passed. New core file statement coverage: 89.5%.
  • BVT passed 68/68 statements twice; two-CN covering execution and backfill result comparisons passed.
  • Deterministic 200,000-row k=3 OR v=10 case: scan input reduced from 200,000 rows / 25 blocks to 401 rows / 2 index blocks, with COUNT=401 and no base-table scan. No FORCE INDEX or explicit ANALYZE was needed; overlap/NULL controls matched the scan results.

@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 3, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 224ce6f830c89e43c7e6fcc4e61ce8d430e1440a

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: 224ce6f830c89e43c7e6fcc4e61ce8d430e1440a

Assessment: approve

The bounded OR access path coherently reuses regular-index safety/cost matching, physical primary keys, global union deduplication and one existing INDEX backfill. Exact branch predicates, residuals, NULL/bag semantics, snapshots, hints and pagination boundaries are preserved; failed construction does not publish partial plans. Existing single-index precedence remains intact. The approved design matches the frozen document, and the added planning/query-local complexity is justified without a new executor or persistent mechanism. No actionable correctness or design defect remains.

Model: gpt-6.1-sol / max

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

Validation:

  • All six new planner tests passed with -count=1: 38 cases including subtests, no skips. Named output in index-merge-focused.jsonl proves default selection, fallback/cost controls, composite identity, branch budget and construction rollback.

  • Full pkg/sql/plan passed with -count=1: 4646 top-level cases and 22563 including subcases; two unrelated preexisting subtests skipped. planner-normal.jsonl retains terminal output and exact selection.

  • Nine focused compile/INDEX/group consumer tests passed across three packages, 20 cases including subtests and no skips. They cover global distinct merge, broadcast INDEX ownership, generation reset, allocation recovery, spill cleanup and cancellation. See consumer-focused.jsonl.

  • Preflight, native provenance/current-input verification and frozen-range diff check passed. validation-audit.json reconciles clean-head command receipts, assigned caches/executor, terminal exits, log hashes, both discussion keys and the exact approved design blob.

  • Reviewed the complete SQL case/result against its explicit data and independent IGNORE INDEX controls. Frozen current-head CI reports successful UT, build, SCA and applicable BVT checks; author reports repeated BVT, two-CN execution and the unhinted 200000-row case. Skipped/neutral CI jobs are not counted as validation.

Limitations:

  • Live SQL/BVT and the large-table performance experiment were not rerun locally; author raw artifacts and external CI command logs were not supplied. The reported 401-row/two-index-block result is distinguished from independently reproduced local planner/consumer checks.

  • Full planner validation skipped preexisting HNSW cosine-similarity and interval-frame subcases; changed tests ran without skips.

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

mergify Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as 54a6b17 at 14:10 UTC

2 h 37 min in the queue, 1 h 4 min of it CI.

So far

  • ✅ Entered the queue Tue 3 Nov, 11:34 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Passed · in place
  • ✅ Merged 14:10 · 54a6b17 · 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

@mergify
mergify Bot merged commit 54a6b17 into matrixorigin:main Nov 3, 2026
@ck89119
ck89119 deleted the issue-31863-main branch November 3, 2026 14:11
@mergify mergify Bot removed the queued label Nov 3, 2026
gouhongshen added a commit to gouhongshen/matrixone that referenced this pull request Nov 3, 2026
…upstream's new buildRegularIndexOnlyScan builder (matrixorigin#32086 split applyRegularIndexOnlyScan into build-then-publish and made the new secondary-index OR merge reuse it), so single-index and OR-merge locking reads both carry locking-read roles; take upstream OR-index merge, bounded backfill work estimates, MinIO range-read bounds, readutil pk-filter changes, incomplete-exponent literals, python SQLAlchemy/numeric-score fixes, ivfpq/cuVS ignored rows, pagination/rollup BVT, HA deployment kit docs and CI shallow clones

This branch was previously deployed

1 inactive deployment
ci — b1d9e467 Deployed Nov 3, 2026 by mergify[bot]
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/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance]: OR across two indexed columns scans the full table

3 participants