Skip to content

fix: preserve composite index access for joins - #32490

Merged
mergify[bot] merged 4 commits into
matrixorigin:4.2-devfrom
gouhongshen:agent/issue-32460-4.2-dev-279c76a6
Nov 13, 2026
Merged

mergify[bot] merged 4 commits into
matrixorigin:4.2-devfrom
gouhongshen:agent/issue-32460-4.2-dev-279c76a6

Conversation

@gouhongshen

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:

Related to #32460.

What this PR does / why we need it:

Root causes

  • applyIndicesForJoins required equality conditions for every declared secondary-index key part. A VALUES join supplying a valid contiguous leading prefix of idx_control(user_id, run_id, event_type, event_idx) therefore received no index-join candidate and scanned the base table despite FORCE INDEX.
  • The initial prefix admission retained first-admitted-candidate termination in catalog order. Without a hint, a broad partial prefix could displace a later selective complete-key index.

Changes

  • Admit nonempty contiguous leading composite-key prefixes for join-index selection.
  • Require the existing exact runtime-filter contract for partial prefixes, retain the complete-key FORCE INDEX fallback, and keep residual base-scan predicates authoritative.
  • Evaluate eligible complete declared-key candidates before partial-prefix candidates, preserving catalog order within each class so prefix support does not regress existing complete-key lookups.
  • Add planner regressions for the exact VALUES query, serialized two-key bounds, residual filters, non-leading keys, unsupported partial unique prefixes, complete-key forced fallback, and competing indexes in both catalog orders.
  • Add the distributed SQL case covering empty/populated tables, scalar and UNION ALL equivalence, range boundaries, duplicate and partial prefixes, unmatched/NULL keys, residual predicates, and IGNORE INDEX.

Issue-to-test proof for #32460

  • The exact planner regression failed on unchanged base c8264f1e6fa6cbe79eb8734677bc147a7482184d because no idx_control scan existed. It now requires the explicit idx_control scan, retained filtered base scan, matching build/probe tags, MatchPrefix, RUNTIME_FILTER_KEY_SERIAL_FULL_V1, two varchar probe components, and a two-argument serial_full build expression.
  • The competing-index regression failed before the final ordering repair when idx_tenant_unused(tenant, unused) preceded idx_lookup(lookup), selecting the broad prefix. Both catalog orders now select idx_lookup; the original forced VALUES regression and all prefix-safety controls still pass.
  • The distributed case independently checks public SQL results and hint behavior. Its 11 statements passed against the isolated implementation service before the final candidate-order revision. The SQL inputs and forced-single-index path are unchanged by that revision, and the current exact planner regression and complete planner package pass.

Validation

Original base proof (expected exit 1: no idx_control scan):

.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=180s -run '^TestForceIndexJoinUsesLeadingCompositePrefix$' ./pkg/sql/plan

Competing-index pre-repair proof (expected exit 1: broad prefix selected when ordered first):

.agents/skills/mo-dev/scripts/mo-cgo-test -o /tmp/issue-32460-go/plan-review.test -v -count=1 -timeout=180s -run '^TestIndexJoinPrefersCompleteKeyOverPartialPrefix$' ./pkg/sql/plan

Current focused proof (exit 0: both catalog orders, exact issue regression, and all safety controls):

.agents/skills/mo-dev/scripts/mo-cgo-test -o /tmp/issue-32460-go/plan-review.test -v -count=1 -timeout=180s -run '^(TestIndexJoinPrefersCompleteKeyOverPartialPrefix|TestForceIndexJoinUsesLeadingCompositePrefix|TestIndexJoinCompositePrefixSafetyBoundaries)$' ./pkg/sql/plan

Complete planner package (exit 0; PASS, ok github.com/matrixorigin/matrixone/pkg/sql/plan 18.795s):

.agents/skills/mo-dev/scripts/mo-cgo-test -o /tmp/issue-32460-go/plan-review.test -v -count=1 -timeout=20m ./pkg/sql/plan

Package selection and build (exit 0):

GOWORK=off go list -mod=readonly ./pkg/sql/plan
GOWORK=off CGO_CFLAGS="-I$PWD/cgo -I$PWD/thirdparties/install/include" CGO_LDFLAGS="-L$PWD/cgo -lmo -L$PWD/thirdparties/install/lib -Wl,-rpath,@executable_path/lib" go build -mod=readonly ./pkg/sql/plan

Vet (exit 0, empty output):

GOWORK=off CGO_CFLAGS="-I$PWD/cgo -I$PWD/thirdparties/install/include" CGO_LDFLAGS="-L$PWD/thirdparties/install/lib" go vet -mod=readonly ./pkg/sql/plan

Distributed SQL proof (supporting run before the final candidate-order revision; total 11, success 11, failed 0, ignored 0, abnormal 0). Executed from the isolated mo-tester runtime directory with method=run and exactly issue_32460.sql:

java -Xms1024M -Xmx1024M -cp "$scratch:/Users/ghs-mo/MOWorkSpace/mo-tester/lib/*" -Dconf.yml="$scratch/mo.yml" -Drun.yml="$scratch/run.yml" io.mo.Tester

gofmt produced no diff. The Go and SQL source diff checks passed. The generated BVT result retains two trailing spaces emitted by EXPLAIN for Values Scan "*VALUES*", consistent with existing result files.

Residual risks

  • The competing-index regression proves deterministic access-path selection with a 1,000,000-row-statistics fixture; it does not measure production latency or scanned-row totals.
  • The focused distributed SQL case was not rerun after the candidate-order revision. Broader distributed optimizer suites remain for CI; the current complete pkg/sql/plan package passed.

Allow contiguous leading composite-key prefixes to drive index joins with exact runtime filters. Preserve complete-key candidate priority so partial prefixes do not displace selective lookups.

Related to matrixorigin#32460
@gouhongshen

gouhongshen commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Unrelated CI blocker: the COMPOSE/PESSIMISTIC multi-CN BVT job failed only on the four protected-database privilege checks at tenant/privilege/protected_database.sql:186-189. Each expected a privilege error and returned null. This exactly matches the clean-4.2-dev cross-CN global-variable cache reproduction tracked in #26270; I recorded this occurrence in #26270 (comment).

The PR's exact diff changes only join-index planning and its tests, and its new optimizer/issue_32460.sql passed all 11 statements in the same job. No rerun was requested because this is a reproduced product defect rather than an established transient failure.

The downstream Coverage job also failed its prerequisites because that required pessimistic BVT producer failed. No coverage verdict was calculated; this is the same unresolved blocker recorded above. The blocker marker and original tracked_at are unchanged.

After run completion, the downstream CI Required job rejected the same two failed inputs (matrixone-standalone-ci and matrixone-coverage-merge) and raised matrixone-standalone-ci: failure. It adds no independent product failure; the single #26270 blocker and its original tracked_at remain unchanged.

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

@mergify

mergify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 6fb6fabf7e1edd1c2a6176c58db0a03d2cdb66f7

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: 6fb6fabf7e1edd1c2a6176c58db0a03d2cdb66f7

Assessment: approve

No actionable defects remain. The change reuses existing serialized runtime-filter machinery while preserving complete-key priority, residual predicates and unsupported-prefix safeguards.

Model: gpt-6.1-sol / max

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

Validation:

  • Eight focused test roots passed, including all three added regressions: focused-plan.log; checks/1794354193731255043-3.json.

  • Full planner package passed: owning-plan.log; checks/1794354265524401054-3.json.

  • Isolation preflight, native provenance, unchanged source and all four discussion entries verified. Receipts and logs reconciled in review-validation.json.

  • Frozen current-head CI reports successful UT, SCA, coverage and both multi-CN BVT lanes.

Limitations:

  • Three preexisting unrelated planner subcases skipped.

  • No local distributed BVT rerun or production latency benchmark was performed.

@gouhongshen

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into 4.2-dev as e64edc5 at 04:35 UTC

1 h 16 min in the queue, 1 h 14 min of it CI.

So far

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

@XuPeng-SH

XuPeng-SH commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 6fb6fabf7e1edd1c2a6176c58db0a03d2cdb66f7

New discussion was assessed; the previous review remains unchanged.

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

This branch was previously deployed

1 inactive deployment
ci — bb0e0556 Deployed Nov 13, 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/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants