Repository navigation
Description
Is there an existing issue for the same feature request?
- I have checked the existing issues.
Is your feature request related to a problem?
An ordinary equi INNER JOIN used to filter a vector-bearing table prevents IVF-FLAT Top-K index access. Users should not have to change JOIN semantics or split a statement into application-side queries to use a vector index.
Requested query shape:
SELECT chunks.chunk_id
FROM haip_doc_chunks_998 AS chunks
INNER JOIN b_document AS filters
ON filters.document_id = chunks.document_id
WHERE l2_distance(chunks.embedding, '<1536-dimensional query vector>') <= 0.5
ORDER BY l2_distance(chunks.embedding, '<same query vector>') ASC
LIMIT 10;The tested table has a VARCHAR chunk_id primary key, document_id varchar(128) NOT NULL, embedding vecf32(1536) NOT NULL, and:
KEY id_doc_chunks_embedding USING ivfflat (embedding)
lists = 10 op_type 'vector_l2_ops'It also has a gojieba fulltext index and ordinary indexes on (document_id, seq_prefix, seq) and (document_id, start_time).
Verified local evidence: a clean standalone build at d2a3391, Go 1.26.4, darwin/arm64; SQL git_version() returned d2a3391. The fixture used 120 chunks, a literal 1536-dimensional zero query vector, and two duplicate eligible document IDs plus NULL in b_document.
Both plain LIMIT 10 and LIMIT 10 BY RANK WITH OPTION 'mode=pre' produced:
TP QUERY PLAN
Project
-> Sort
Sort Key: l2_distance(chunks.embedding, ) ASC
Limit: 10
-> Join
Join Type: INNER
Join Cond: (filters.document_id = chunks.document_id)
-> Table Scan on claude_ivf_explain.b_document
-> Table Scan on claude_ivf_explain.haip_doc_chunks_998
Filter Cond: (l2_distance(chunks.embedding, ) <= 0.5)
The empty-looking distance argument above is the original EXPLAIN rendering; the executed SQL used a complete literal vector.
Controls at the same revision:
| Shape | IVF index access |
|---|---|
| Equi INNER JOIN + plain LIMIT | No |
| Equi INNER JOIN + explicit PRE | No |
| No JOIN + explicit PRE | Yes: ivf_search, DistRange: (-Inf,0.5] |
| No JOIN + FORCE | No, intentionally |
mode=force explicitly requests brute-force execution; index support must not change that contract. This request concerns ordinary/PRE Top-K queries, not overriding FORCE.
Describe the feature you'd like
Allow eligible ordinary equi INNER JOINs to use a vector Top-K index access path when ordering by a supported distance between an indexed vector column and a query vector. Selection should remain cost-based, not mandatory for every JOIN.
Preserve these contracts:
- JOIN eligibility participates in candidate generation/refill: globally nearest but ineligible rows must not exhaust the candidate budget.
- Preserve match multiplicity. If a joined document ID appears twice, each matching chunk contributes two result rows. Apply the final LIMIT to the joined result, not to a deduplicated substitute.
- Preserve distance predicates and existing approximate versus exact/FORCE behavior; do not silently claim exact recall for ANN.
- Support uniqueness-proven joins as a simpler eligible subset. When the joined key is proven unique and only chunk-side columns are needed, a semantics-preserving SEMI/membership rewrite may be possible.
- Leave unsupported shapes on the original relational plan.
Suggested regression coverage: unique/duplicate joined keys, NULL/unmatched keys, empty inputs, nearest ineligible chunks, fewer qualifying results than K, distance-boundary filtering, and explicit FORCE remaining non-indexed.
Describe implementation you've considered
At the tested revision, buildVectorSortContextThroughJoin recognizes SEMI membership joins and vector-provider joins. The latter require INNER with a trivial/constant-true ON condition (isVectorProviderJoin); an ordinary filters.document_id = chunks.document_id predicate is not eligible.
Possible approaches, subject to design review:
- Prove joined-side uniqueness and output restrictions, then reduce an eligible equi join to existing membership filtering.
- For non-unique joins, use join-aware candidate filtering/refill and multiplicity-preserving expansion, keeping final Top-K above the semantic JOIN.
Simply replacing INNER JOIN with IN is not generally correct. In the tested duplicate-key fixture, JOIN Top-10 returned c001,c001,c003,c003,c005,c005,c007,c007,c009,c009, while IN Top-10 returned ten distinct chunks.
Application-side ID collection and multiplicity expansion is a workaround for small sets, but adds snapshot-consistency, payload-size, and result-expansion responsibilities.
Documentation, Adoption, Use Case, Migration Strategy
Use case: vector similarity search restricted through a relational eligibility, authorization, or document table. The query vector comes from a literal/bound input; the other relation filters candidates rather than providing the query vector.
Document supported JOIN shapes, multiplicity handling, index-selection eligibility, and approximate-search behavior. No new requirement to use mode=force is intended.
Additional information
Related context, but distinct scopes:
- [Bug]: vector index didn't take effect #23158 SQL2 uses JOIN (...) ref_vec ON 1=1 to provide the query vector. This request uses an ordinary equi JOIN to filter candidates and preserve match multiplicity.
- feat(vector): enable ANN indexes for scalar subquery vectors #29493 explicitly implements [Bug]: vector index didn't take effect #23158 SQL1 (scalar-subquery query vectors). Its final head 8805218 was separately tested with IN + LIMIT and did use Vector Index Scan. That does not establish ordinary equi INNER JOIN support; this JOIN query was not executed at that head.
- No performance benchmark or production-scale recall guarantee is claimed by the small-fixture validation above.
Activity
feat(plan): support IVF-FLAT Top-K under equi INNER JOINs (#29767)
[4.2-dev] Support IVF-FLAT Top-K through equi-joins (#30013)
slyunnn commentedon Oct 30, 2026
Feature verification for #29702 (IVF Top-K under equi INNER JOINs) (2026-10-30)
Test environment
d39d8a40343ccd40bf665036388df7a40ee867f8—tae: flush eligible AObject prefixes before busy tails (#31723). The feature was merged by PR #29767, commita04c6fbfc9c57c2856c942ae640d766c42aef58d; Git ancestry confirms that merge is included in the tested commit.darwin/arm64build with Go1.27.1. Themo-servicebinary SHA-256 was423821c2a8725d46f72297964d8e0ad2700d44a446d81ebd92e3552142973676; both tested SQL endpoints reportedgit_version() = d39d8a4034.1LOG,1TN and2CNs. Functional SQL was executed through both CN endpoints over the MySQL protocol using PyMySQL1.2.0. Host: Apple M2 Pro,12logical CPUs,16 GiBRAM. The data directory was newly created for this run.git fetch originattempt timed out with a low-speed error. The isolated checkout used the workspace's cachedorigin/mainref, whose SHA matched the GitHub main commit retrieved at the start of verification; the remote Git fetch itself did not succeed. The first build attempt was interrupted after Go toolchain verification timed out; the successful rebuild used the locally cached Go toolchain. Both build logs were retained.Test results
120-row fixture used a1536-dimensional literal query vector,lists=10, duplicate matching document IDs, unmatched nearer rows, a NULL document key,l2_distance(...) <= 0.5andLIMIT 10. On both CNs, ordinaryLIMITandmode=preusedVector Index Scanand returnedc001,c001,c003,c003,c005,c005,c007,c007,c009,c009, matching the independently enumerated expectation and themode=forcecontrol. The plan reportedNProbe: 5; this observed result does not prove exact recall for approximate search. The issue does not specify every fixture value, and the ordinary and fulltext indexes were added after table creation, so this was not a byte-for-byte replay of the original fixture.LIMIT 0, largeOFFSET, and distance filtering. The selected results matched expectations. A negative control usingINreturned distinct chunks and differed from the duplicate-preservingINNER JOIN, demonstrating why membership alone is not an equivalent replacement.mode=forceused no vector index and returned the exact control rows. SelectedLEFT JOIN, non-equi JOIN, cross-side residual filters,DISTINCT, descending order, extra sort keys,mode=autoandmode=postused relational fallback plans with expected results. Nullable vectors fell back unless explicitly filtered withIS NOT NULL; a mismatched vector dimension returned20301on both CNs.INmembership, scalar query-vector and query-vector-provider JOIN queries used vector index plans and returned expected rows on both CNs. The1536-dimensional query also produced the expected result with two ordinary indexes and a gojieba fulltext index present.LIMITquery was executed repeatedly, including after an eligibility-table change through the other CN. A vector update and rollback preserved the expected results. Eight independent sessions across both CNs performed240indexed reads with the expected rows. After a graceful stop and restart using the same test data directory, both CNs again returned the expected indexed result. These checks do not establish crash recovery, HA or a throughput guarantee.DISTINCTtest input failed with1149because itsORDER BYexpression was missing from the select list. The original result was retained; the corrected legal query passed on both CNs and used the relational fallback.Bugs
No reproducible product bug was found.
Regression coverage
145direct assertions passed on the tested commit, including independent expected rows, execution plans and a1,032-row fixture. The row count alone does not prove that a particular physical block, batch, spill or worker boundary was exercised.vector_ivf_equi_join.sqlwas executed through a custom PyMySQL adapter:63statements,7plan assertions and28explicit row assertions passed. The full repository BVT runner and complete golden comparison were not run.TestEquiVectorTopK*planner tests passed with the repository CGo wrapper. Duplicate-library and rpath linker warnings were retained in the log.14f8f20a08c3463fd06cca35004b1c19378bcdd8, based on MOTR main391df8d2a9d100ba04095ec6ae9128cb69624ea1. Recording passed once, and replay passed twice through each CN (4/4, no skips). The single case was run serially. The PR remains open and unmerged; its four offline contract checks passed, but those checks do not constitute a database integration run.Evidence and not covered
Original scripts, row-level results, EXPLAIN plans, build and server logs, the initial and corrected
DISTINCTrecords, cleanup records and a verified SHA-256 manifest were retained in the isolated local workspace. The local evidence is not a public attachment. Only the test databases created by this run were dropped; the isolated cluster was stopped. MatrixOne service source was not modified.The issue requested cost-based selection. The approved implementation design explicitly deferred a complete JOIN cost model and adopted the existing eligible-index preference for this implementation. A complete cost-based selector is therefore a follow-up, not a failure in this verification scope.
Production-scale recall or performance, long-running stability, independent-process CN failure, network faults, HA failover, concurrent-writer stress, every unsupported SQL shape and physical multi-block/spill boundaries were not tested. Cross-system connector and exactly-once recovery matrices are not applicable to this SQL optimizer feature.
Conclusion
Passed for the approved equi-INNER-JOIN IVF Top-K feature scope and the local configurations described above. The deferred cost model, unmerged MOTR PR and untested extensions remain separately identified; this conclusion does not claim exact ANN recall, a speedup or HA qualification.
slyunnn commentedon Nov 2, 2026
TKE 大数据补测结论
结果:通过。 针对 MatrixOne commit
d39d8a40343ccd40bf665036388df7a40ee867f8,在 TKE 1 TP + 2 AP 环境执行 IVF equi-JOIN + TopK 补测;工作流及资源清理均成功。测试 job 使用独立数据库,测试后删除。运行与证据:TKE job #41401136415,artifact
tke-family-motr-debug-1x2-motr-41401136415-1中的feature29702-scale.json和计划文件。未发现可确认的产品缺陷。