Repository navigation
feat(plan): support IVF-FLAT Top-K under equi INNER JOINs - #29767
Conversation
Preserve INNER JOIN multiplicity and final pagination by applying exact eligibility before vector candidate selection. Reuse existing index hooks with conservative fallback and one-CN placement. Add planner and public SQL regression coverage with the approved design. Fixes matrixorigin#29702
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Protect consumer commands and producer-side target ownership release, reset, and close with the same sinker-local mutex. An observable error does not prove that the consumer has finished unwinding its pinned session. Add owner-fence barrier coverage for release, reset, and close competitors.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review: APPROVE on 39979b3664983c34b5a1d1acb40546b1a832de4f. All 10 changed files/hunks reviewed directly, without subagents. No blocking finding remains.
Design and behavior:
- The original INNER JOIN remains responsible for duplicate expansion and B-side projections. A cloned SEMI eligibility subtree feeds the existing IVF candidate/membership machinery, with K+OFFSET at candidate selection and the original final LIMIT/OFFSET retained. This avoids incorrectly replacing an ordinary JOIN with a SEMI result.
- Eligibility is deliberately narrow: ordinary unpartitioned scans, deterministic cross-column equi predicates, supported ascending distance, non-null indexed vector, constant non-null query vector and supported rank mode. Existing registry capability checks own index dispatch. Unsupported joins, volatile/sequence expressions, dynamic/null vector expressions, unsafe offsets and unsupported modes fall back without mutating the original scan/tag owners.
- Exact required membership, residual filtering, candidate replay, and one-CN placement reuse existing owners. Private clone/rebinding precedes node registration, protecting original tag mappings. Computed B-side result metadata is resolved through the correct local projection slot rather than a sibling relation's column ordinal. No new storage, wire capability or execution state machine is introduced.
- The v1/v1.1 design records user acceptance and explicit deferral of the complete JOIN cost model. This does not promise a speedup for every query: the extra B-side scan/domain construction and one-CN constraint can cost more for small or highly duplicated inputs. That accepted scope is not being reopened as a new design blocker.
The adjacent CDC repair was reviewed independently. The sinker's mutex now owns executor access through command completion and producer cleanup; observing Error() alone is not treated as an unwind barrier. Close waits for senders/consumer before taking the executor mutex, and neither channel sends nor consumer shutdown wait while holding it. The durable owner-fence callback has a separate bounded task-service check. No new lock cycle was identified.
Tests/evidence:
- Reviewer ran native
make -j8 cgo, then.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=120s -run '^TestMysqlSinker2_TargetOwnershipCleanupSerializesWithCommand$' ./pkg/cdc: PASS, 4.288s. This tests real Executor ownership publication plus release/reset/close terminal resource state with the DB boundary mocked. Native artifacts were rebuilt for this checkout; the pinned cached ONNX library was checksum-verified by Make after the network download timed out. - Reused the author's owning planner/compiler results, canonical BVT 65/65 twice, and real two-CN/both-ingress comparisons against FORCE-table controls, including duplicate expansion, offsets, reversed indexed side and required one-CN placement. These are author evidence, not fresh reviewer performance measurements.
- Reviewed real-parser/public planner tests, prepared limit reuse, unsupported-shape controls, metadata controls and BVT cleanup. Existing membership cancellation/generation/placement behavior is reused; no new executor lifecycle is added.
- Exact-head Required CI run 37907975699 succeeds; diff whitespace check passes. There were no prior review findings on this PR to close.
Incremental footprint: production 4 files +283/-16; tests/BVT 4 files +905; design 2 files +226. Planner qualification and construction remain bounded additions to existing ownership; no unnecessary runtime abstraction or duplicate validator was identified.
## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [x] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Related to #29702. ## What this PR does / why we need it: Reimplements the IVF-FLAT equi-join capability from #29767 natively on `4.2-dev`. This is **not a cherry-pick**: it does not import the mainline dependency chain or the unrelated CDC changes. - Build a private `A SEMI JOIN B` eligibility relation and feed its exact membership into existing IVF-FLAT candidate selection. - Reconnect candidates to the original `INNER JOIN`, preserving duplicate multiplicity, right-side projections, final ordering, and pagination. Candidate budget includes `OFFSET`. - Keep distance predicates in the membership qualification path: the 4.2 executor does not consume `DistRange` annotations, so an annotation alone cannot enforce upper or lower bounds before candidate truncation. - Use conservative shape, equality, nullability, replay-safety, and plugin-capability checks. Reuse existing membership protocol/version checks and resource handling. ### Scope and compatibility The new optimization supports ordinary `LIMIT` and explicit `PRE`. Unsupported shapes and modes retain their existing behavior; `FORCE` remains the exact-query opt-out. This does not add a JOIN cost model or promise ANN recall/performance improvements for every workload. No index-format, CDC, or global scheduler changes are included. ### Validation - Go 1.26.4 with the repository CGo wrapper: complete `pkg/sql/plan` tests, `-vet=all`, native build, formatting, and diff checks passed. - Changed-production statement-block coverage: **170/183 = 92.90%** (excluding tests/generated files). - New BVT: **73/73 through each of two CN entry points**, including duplicate joins, right projections, integer/string primary keys, exact `FORCE` comparisons, distance bounds, pagination, empty results, and prepared execution. - Existing IVF membership/mode/retry BVT: **275/275**. ### Integration note This branch is independently based on `4.2-dev`; it does not depend on the scalar-query reimplementation in #30012. The two implementations overlap at guard/dispatch registration in `pkg/sql/plan/apply_indices.go`; merging both must retain both registrations. A combined merge on base `7ca3113da9` passed planner/compiler/parser tests, native build, and **440/440 BVT statements through each CN entry point**, with no observed mpool leak or pipeline cleanup timeout. The temporary integration merge is not included in this PR. ### Follow-up: preserve scalar-index hint ownership - Fix the remaining A-side hint loss identified in review. The eligibility scan inherits hints from the original vector input; the existing common `copyNode` path forwards the same scoped hint set and logical owner to later membership copies. No additional hint state, access-path implementation, runtime protocol, or index-format change is introduced. - Add public BuildPlan regressions for INNER, reversed INNER and SEMI shapes, with unhinted and scoped controls. Every reachable scan must obey A-side IGNORE/USE restrictions while retaining IVF eligibility. Cover recursive copying, hint scopes and logical ownership. Extend the existing BVT with scalar-index negatives, IVF positives and exact duplicate-preserving FORCE FOR JOIN row checks in both JOIN directions. Validation for this follow-up (`ce814c96de`, Go 1.26.4, linux/amd64, fresh matching CPU CGo libraries): - Before the fix, the public BuildPlan regression failed in all six A-side IGNORE/USE cases; the three unhinted controls passed. After the fix, all 12 public hint cases and eight scoped copy cases passed, alongside retained planner regressions. - Complete planner normal UT passed. Complete planner race passed using the existing CI runner method: eight serial groups on one host, all 1,649 discovered tests executed and passed, zero skipped or omitted. Focused compiler candidate/membership/CN-dispatch/offset tests passed in normal and race modes. - Incremental configured SCA across planner and compiler passed: formatting, `-vet=all`, and diff-based lint (golangci-lint 2.14.0, zero issues). This is not a claim that a full repository or CI SCA has completed. An optional whole-file scan reported four preallocation suggestions in untouched code. - The complete existing-plus-extended BVT case passed twice through each of two CN entry points, 116/116 statements per comparison, on the canonical 3-CN cluster. Schema cleanup was checked between comparisons; the final direct-JVM validation also passed cluster close. Earlier monolithic race and Bash-wrapped validation attempts failed and are excluded from completion evidence. - Solution and overall review: `gpt-6.1-sol` / `xhigh`. No unresolved material source/design findings. The fix adds planner-time metadata propagation only; no measured production latency gain is claimed. Earlier validation above is author-reported evidence for earlier revisions. CI for the updated head remains pending. --------- Co-authored-by: XuPeng-SH <[email protected]>
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #29702
What this PR does / why we need it:
Enable IVF-FLAT vector Top-K index access for supported ordinary equi INNER JOINs, including unique and duplicate join keys.
K + OFFSETvector candidates, then retain the original INNER JOIN and final pagination. This preserves duplicate matches and right-side projections instead of changing JOIN semantics to IN/SEMI semantics.Validation
pkg/sql/planandpkg/sql/compileowning tests passed; changed executable-line coverage: 95.5%.make buildwithGOEXPERIMENT=simdpassed.Approved design and cost-policy clarification are included under
docs/design/CLAUDE_20261008-vector-equi-join-topk-v1*.md. Local TODO, review notes, and execution artifacts are not included.