Repository navigation
plan: bound composite unique index trailing IN lookups - #32577
mergify[bot] merged 4 commits into
Conversation
Support finite trailing IN key sets on composite unique secondary indexes while preserving exact residuals, backfill, and forced-index prefix safety. Prefer complete unique equality over trailing IN candidates when statistics are unavailable. Add focused planner regressions and public SQL coverage for bounded access, prepared and boundary inputs, prefix and competing indexes, and both catalog orders. Related to matrixorigin#32410
|
UT Coverage and its downstream Coverage merge are blocked by a |
|
Queue requested — the merge queue status continues in this comment ↓. |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 077180db16e546726608424ff224303e1961486d
Assessment: approve
The scoped rewrite reuses existing serialization and index-join machinery while preserving residual filters, backfill, NULL semantics, prefix-index safety and singleton equality preference. No actionable findings remain.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
Validation:
-
Reviewed the complete four-file delta, baseline behavior, affected consumers and all four discussion entries.
-
Reused the reported merged-head planner build, vet and full-suite success, 55/55 public SQL regression, and successful frozen-head CI reports.
-
Historical coverage blockage is superseded by current successful coverage reports.
-
Local artifact audit passed: checks/1794476512463483629-3.json and final-audit.log confirm clean frozen source, matching patch and complete discussion coverage.
Limitations:
-
No local Go or SQL tests were run; supplied author and CI reports were reused.
-
Performance evidence establishes bounded row access, not latency or throughput.
|
@Mergifyio queue |
🚫 Left the queue · queue conditions no longer match1 min in the queue, with no time running CI. So far
Reason Pull request #32577 has been dequeued Queue conditions are not satisfied:
To get back in the queue
Requeue requested — the merge queue status continues in this comment ↓. Times in UTC · dashboard · how the merge queue works |
|
mo-bot review · Commit: New discussion was assessed; the previous review remains unchanged. |
Resolve the apply_indices.go conflict by integrating the PR with the target's general composite key-set implementation. Preserve forced filter access only for eligible full-value bounded unique key sets and prefer complete unique equality over a multi-key set when statistics are unavailable. Adapt the planner regressions to exact literal vectors and typed comparison expressions, and retain prefix-index fallback coverage.
✅ Merged into
|
## What type of PR is this? - [ ] API-change - [x] 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 - **#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](https://github.com/matrixorigin/matrixone/actions/runs/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 b815a4c ./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. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
Related to #32410
What this PR does / why we need it:
A query with equalities on the leading columns of a composite unique secondary index and a finite
INlist on the remaining key part must be able to use bounded exact-key access, including when a forced index cannot supply a requestedORDER BY/GROUP BYand when competing unique indexes have no useful statistics.The updated
4.2-devbase now contains the general composite key-set implementation, exact serialization, comparison/prefix guards, admission controls, and work budgets. This PR integrates with that implementation and retains only the two remaining deltas:The regression suite covers the reported 5,000-row reproduction, exact rows and bounded index/base access, duplicates and absent keys,
NULL, prepared execution, residual predicates, nontrailingIN, full and declared-prefix indexes, forced hints, unmatched ordering, competing declaration orders, and unavailable statistics.Validation
.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=20m ./pkg/sql/plan(retained test binary): full package passed after the merge resolution.go list -mod=readonly ./pkg/sql/plan,go build -mod=readonly ./pkg/sql/plan, andgo vet -mod=readonly ./pkg/sql/plan: passed with the repository CGo environment.go build -mod=readonly ./cmd/mo-service: passed with the resolved merge.test/distributed/cases/optimizer/composite_unique_in_index.sqlagainst the resolved binary and checked-in expected results: 55/55 statements passed; no result regeneration was used.Residual risks and validation limits