Skip to content

fix: use bounded composite unique index key sets - #32830

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-32410-main-f4f49a73
Nov 17, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-32410-main-f4f49a73

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Nov 16, 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:

Related to #32410.

What this PR does / why we need it:

Root cause

A complete composite unique secondary index had ordinary equality/range access, but no key-set candidate for equality-bound key parts plus one finite IN dimension. The planner therefore could not lower the predicate to exact serialized keys or cap candidate work by the finite key count. A less selective secondary index or table scan could win and read the entire run history. Forced-index fallback and unknown-statistics candidate ordering also lacked the guards needed to expose bounded access safely.

This adapts merged PR #32577 and its required composite key-set support from #32567 to main.

Changes

  • Add KeySetIndexCondition candidate matching, cost/cardinality caps, index-only and base-row backfill integration, forced-hint and declared-prefix safety, unknown-statistics ranking, bounded reservation/retry handling, and cancellation propagation.
  • Recognize complete full-value composite unique keys with equality on every other part and one finite non-NULL constant IN; reject dynamic values, multiple set dimensions, malformed metadata, and declared prefixes.
  • Bound admitted sets to 128 points, 1 MiB of planning work, and 8 MiB of wire data. Serialize sorted, deduplicated exact keys and retain ordinary access fallback when admission fails.
  • Add focused planner coverage for fixed-width and string key encoding, duplicates, absent and NULL values, residual filters, index-only/backfill plans, hints, competing indexes, missing statistics, incomplete keys, prefixes, resource limits, retries, revalidation, and cancellation.
  • Cover every supported literal-bound variant against the authoritative serial encoded-size contract, plus malformed metadata, runtime values, NULL, unsupported types, string byte boundaries, and planning-budget rejection.
  • Add the 5,000-row SQL reproduction and semantic/plan controls, including a nine-input/eight-distinct fast-path case.

Issue-to-test proof

  • [Performance]: IN on trailing composite unique-index key scans entire run history #32410 red/green: on base b815a4cfb5b2, the focused trailing-IN planner case selected idx_c instead of uk_abc; the same case passes after this change with an exact unique-key set. Equality and fallback controls retained their expected behavior.
  • The real 5,000-row SQL reproduction now selects uq_user_run_key for ordinary and forced trailing-IN queries. Base-table and unique-index inputRows=3 outputRows=3 bound work by the three requested keys instead of scanning 5,000 history rows. The query returns event_idx 1, 2, and 3 with residual filtering, noncovered projection, backfill, and ordering preserved.
  • Duplicate and absent keys do not fabricate rows; prepared reuse and NULL retain SQL three-valued semantics. Declared prefixes, incomplete/nontrailing key shapes, mixed hints, competing indexes, and missing-statistics controls return the intended rows.
  • Direct fixed-width and string encoder tests compare every generated key byte-for-byte with authoritative serial folding after sorting and deduplication. Nine raw values produce eight distinct exact keys; the strengthened SQL case returns event_idx 1 through 7.
  • Independent black-box Challenge PASS: all 12 retained regressions passed against the approved tree, including reproduction, related, happy, unhappy, and corner coverage.

Validation

  • RED baseline: .agents/skills/mo-dev/scripts/mo-cgo-test -o /tmp/issue-32410-main-plan-baseline.test -v -count=1 -timeout=10m -run '^(TestCompositeUniqueTrailingInPointAccess|TestCompositeUniqueTrailingInRejectsPrefixLengths|TestCompositeUniqueForcedOrderRejectsPrefixPointAccess|TestCompositeUniqueForcedOrderRejectsCompetingPrefixAccess|TestCompositeUniqueMissingStatsPreferCompleteEquality)$' ./pkg/sql/plan — intended bounded-access failures on the clean base.
  • Focused encoder proof: .agents/skills/mo-dev/scripts/mo-cgo-test -o /tmp/issue-32410-main-fast-path-review.test -v -count=1 -timeout=10m -run '^(TestFastExactKeySetMatchesSerialFolding|TestCompositeUniqueKeySetCardinalityAndFastPath)$' ./pkg/sql/plan — PASS in 2.026s.
  • Coverage-repair focused proof: .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s -run '^(TestIndexKeySetLiteralBoundVariants|TestIndexKeySetLiteralBoundRejectsInvalidInputs)$' -coverprofile=/Users/ghs-mo/MOWorkSpace/tmp/issue-fix/issue-fix-loop/state/artifacts/issue-32410/pr-event-focused-literal-tests.cover.out ./pkg/sql/plan — PASS; both tests and all 34 subtests passed.
  • Coverage-gate projection: overlaying that focused profile on the failed CI changed-code profile covers 22 previously uncovered blocks in index_key_set.go, raising changed-code coverage from 293/412 (71.12%) to a projected 315/412 (76.46%), above the strict 75% gate. Production files are unchanged between the profiles. Exact-head CI run 43970538694 subsequently passed Coverage and CI Required on bb3ee9b9132463de9e894b76fbd18f7fac08ab0b.
  • Complete owning package, without -run: .agents/skills/mo-dev/scripts/mo-cgo-test -o /tmp/issue-32410-main-plan-ci-fix.test -v -count=1 -timeout=30m ./pkg/sql/plan — PASS in 159.218s.
  • Related planner regressions: .agents/skills/mo-dev/scripts/mo-cgo-test -o /tmp/issue-32410-main-plan-related.test -v -count=1 -timeout=10m -run '^(TestRegularIndexSelector.*|TestEncodedIndex.*|TestIndexHint.*|TestForceIndex.*|TestScopedForceIndex.*|TestApplyIndicesForFilters.*|TestApplyExtraFiltersOnIndex.*|TestResolveRegularIndexBackfillResidualAccess|TestRangeBackfill.*|TestRegularIndexOnly.*|TestReplaceEqualCondition.*|TestReplaceNonEqualCondition.*)$' ./pkg/sql/plan — PASS in 2.420s; also included in the final unfiltered package run.
  • Real SQL BVT: java -Xms1024M -Xmx1024M -cp /Users/ghs-mo/MOWorkSpace/mo-tester:/Users/ghs-mo/MOWorkSpace/mo-tester/lib/* -Dconf.yml=/Users/ghs-mo/MOWorkSpace/tmp/issue-fix/issue-fix-loop/state/artifacts/issue-32410/main-runtime/mo.yml -Drun.yml=/Users/ghs-mo/MOWorkSpace/tmp/issue-fix/issue-fix-loop/state/artifacts/issue-32410/main-runtime/run.yml io.mo.Tester method=run rate=100 — 56/56 success, 0 failed, 0 abnormal after result generation and manual review.
  • Build: make -j8 build-with-prebuilt-native — PASS.
  • Vet: go vet -mod=readonly ./pkg/sql/plan with the repository CGo environment — PASS.
  • Scoped lint: golangci-lint run -c .golangci.yml --new-from-rev b815a4cfb5b2eee24b620f7c078dab6f42b12537 ./pkg/sql/plan — 0 issues.
  • Final gofmt, tracked/untracked whitespace, and delivery-scope checks passed.

Residual risks and limits

  • Admission remains conservative for dynamic or NULL-containing inputs, multiple IN dimensions, declared prefixes, malformed metadata, broad estimates, and resource-limit excess; these cases preserve semantics through ordinary fallback.
  • The complete owning planner package and focused real-SQL case passed. A repository-wide test suite was not run and remains for CI.
  • EXPLAIN ANALYZE row counts establish bounded operator work for this fixture; they are not latency or throughput benchmarks.

Add exact-key access for complete composite unique indexes when all
other key parts have equality predicates and one part has a finite IN.
Preserve residual filtering, backfill, index-only plans, hint safety,
statistics ordering, resource bounds, retry handling, and fallback.

Related to matrixorigin#32410.
Exercise all supported literal variants against the serial encoding size contract, and reject malformed, dynamic, unsupported, and over-budget inputs. This closes the changed-code coverage gap reported on PR matrixorigin#32830 without changing production behavior.
@mergify

mergify Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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

@XuPeng-SH

XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: bb3ee9b9132463de9e894b76fbd18f7fac08ab0b

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: bb3ee9b9132463de9e894b76fbd18f7fac08ab0b

Assessment: approve

The bounded key-set path preserves complete unique-key semantics and existing residual/backfill behavior. It reuses the serial codec and access builders; per-scan reservations and revalidation justify the added helper by bounding optional materialization and fallback work.

Model: gpt-6.1-sol / max

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

Validation:

  • Reviewed all five changed files, linked #32410 and its comments, and all three discussion entries; retained the change map, closure analysis and complete discussion ledger.

  • Static audit passed with receipt checks/1794877304765424400-2.json and retained stdout/stderr: clean pinned head, patch matches frozen range, diff-check and gofmt passed.

  • Reused the frozen PR's reported complete planner package PASS (159.218s), encoder equivalence tests, related planner checks and 56/56 real-SQL BVT after checking their selection and independent result/work oracles.

  • Frozen CI snapshot records Coverage and CI Required SUCCESS; pending/skipped checks were not counted as passes. Static-audit.json preserves the check snapshot and source hashes.

Limitations:

  • No local Go/native/SQL execution was performed; local_validation contains no retained execution artifacts. Author-run results are attributed evidence, not independently reproduced runs.

  • The reported RED control uses b815a4c rather than the assigned merge-base. Baseline source independently establishes the missing key-set path; operator row counts demonstrate bounded work, not latency or throughput.

@gouhongshen

Copy link
Copy Markdown
Contributor Author

The attempt-2 TestStartupQueryReadiness teardown/heartbeat timeout matches existing issue #32745, FLAKY-002. The PR leaves the embedded fixture and heartbeat paths unchanged, and the same head passed pkg/embed in run 43970538694. I added the exact run/job evidence to that issue; no PR code change addresses this unrelated failure.

@gouhongshen

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

2 h 54 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Tue 17 Nov, 11:06 · rule main · triggered by @gouhongshen with the @mergifyio queue command
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 14:00 · 731df58

Reason

Pull request #32830 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.

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

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added the queued label Nov 17, 2026
@XuPeng-SH

XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 56ee1cf3ac5db52e2b38988f24a41ae028d35d3f

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: 56ee1cf3ac5db52e2b38988f24a41ae028d35d3f

Assessment: approve

The complete composite-unique IN path preserves residuals, hints, NULL/dynamic fallback and prefix-index safety. It reuses canonical serial encoders and existing access builders; per-scan reservations and declined-candidate tracking justify the added local state by bounding encoding and retries. Complete source, tests and discussion review found no actionable defect.

Model: gpt-6.1-sol / max

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

Validation:

  • Preflight passed. Native prerequisites were built through repository Makefiles in the diagnostic directory; source-audit.json verifies all 196 native input hashes, artifact provenance and the clean frozen head.

  • Focused normal Go run passed all 16 selected roots, including all 14 added roots, with no skips/failures; focused-normal.jsonl and its check receipt are reconciled in validation-review.json.

  • Full ./pkg/sql/plan normal Go run passed: 5,076 test roots, 49.798s test execution; two existing unrelated subtests skipped. Every added root executed. See planner-package.jsonl and validation-review.json.

  • Public MySQL SQL-integration probe passed twice in one process using the existing single-CN fixture and a diagnostic Go overlay: all 56 original regression statements per iteration, 12 original plan/work regexes and 23 independently derived result sets, prepared reuse and database teardown. See public-normal.jsonl, public-overlay.json and validation-review.json.

  • Frozen current-head evidence records successful UT, static analysis, coverage and compose BVT checks. All eight discussion keys are reconciled in discussion-assessment.json; changed Go files pass gofmt and the frozen delta passes git diff --check.

Limitations:

  • The public diagnostic probe verifies SQL results and plan/work assertions, not mo-tester's result metadata/format rendering. Local execution used one CN; multi-CN BVT success is supplied CI evidence.

  • External reusable CI workflow bodies and raw old-head author runs were not supplied. Their detailed selection/performance claims are not treated as local proof; no latency or throughput improvement is claimed.

This branch was successfully deployed

No deployments
ci — 731df583 Deployed Nov 17, 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/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants