Skip to content

[Feature Request]: Support vector Top-K index access under ordinary equi INNER JOINs #29702

Closed

Description

@ck89119

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:

  1. Prove joined-side uniqueness and output restrictions, then reduce an eligible equi join to existing membership filtering.
  2. 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:

Activity

  1. self-assigned this
    on Oct 8, 2026
  2. added
    severity/s0
    priority/p0
    and removed
    severity/s0
    on Oct 8, 2026
  3. added a commit that references this issue on Oct 9, 2026
    a04c6fb
  4. slyunnn commented on Oct 30, 2026

    @slyunnn

    Feature verification for #29702 (IVF Top-K under equi INNER JOINs) (2026-10-30)

    Test environment

    • Tested MatrixOne main d39d8a40343ccd40bf665036388df7a40ee867f8 — tae: flush eligible AObject prefixes before busy tails (#31723). The feature was merged by PR #29767, commit a04c6fbfc9c57c2856c942ae640d766c42aef58d; Git ancestry confirms that merge is included in the tested commit.
    • Fresh local darwin/arm64 build with Go 1.27.1. The mo-service binary SHA-256 was 423821c2a8725d46f72297964d8e0ad2700d44a446d81ebd92e3552142973676; both tested SQL endpoints reported git_version() = d39d8a4034.
    • One isolated local process hosted 1 LOG, 1 TN and 2 CNs. Functional SQL was executed through both CN endpoints over the MySQL protocol using PyMySQL 1.2.0. Host: Apple M2 Pro, 12 logical CPUs, 16 GiB RAM. The data directory was newly created for this run.
    • The MatrixOne git fetch origin attempt timed out with a low-speed error. The isolated checkout used the workspace's cached origin/main ref, 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

    • Original query shape: A synthetic 120-row fixture used a 1536-dimensional literal query vector, lists=10, duplicate matching document IDs, unmatched nearer rows, a NULL document key, l2_distance(...) <= 0.5 and LIMIT 10. On both CNs, ordinary LIMIT and mode=pre used Vector Index Scan and returned c001,c001,c003,c003,c005,c005,c007,c007,c009,c009, matching the independently enumerated expectation and the mode=force control. The plan reported NProbe: 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.
    • JOIN semantics and pagination: Independent row-level assertions covered nearest ineligible rows, duplicate and unique matches, right-side projection and column metadata, reversed JOIN direction, composite equality, empty results, LIMIT 0, large OFFSET, and distance filtering. The selected results matched expectations. A negative control using IN returned distinct chunks and differed from the duplicate-preserving INNER JOIN, demonstrating why membership alone is not an equivalent replacement.
    • Fallback and errors: mode=force used no vector index and returned the exact control rows. Selected LEFT JOIN, non-equi JOIN, cross-side residual filters, DISTINCT, descending order, extra sort keys, mode=auto and mode=post used relational fallback plans with expected results. Nullable vectors fell back unless explicitly filtered with IS NOT NULL; a mismatched vector dimension returned 20301 on both CNs.
    • Existing behavior and index interactions: Selected existing IN membership, scalar query-vector and query-vector-provider JOIN queries used vector index plans and returned expected rows on both CNs. The 1536-dimensional query also produced the expected result with two ordinary indexes and a gojieba fulltext index present.
    • Sessions and persistence: A prepared LIMIT query 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 performed 240 indexed 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.
    • Test correction: The first DISTINCT test input failed with 1149 because its ORDER BY expression 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

    • 145 direct assertions passed on the tested commit, including independent expected rows, execution plans and a 1,032-row fixture. The row count alone does not prove that a particular physical block, batch, spill or worker boundary was exercised.
    • Existing vector_ivf_equi_join.sql was executed through a custom PyMySQL adapter: 63 statements, 7 plan assertions and 28 explicit row assertions passed. The full repository BVT runner and complete golden comparison were not run.
    • Six selected TestEquiVectorTopK* planner tests passed with the repository CGo wrapper. Duplicate-library and rpath linker warnings were retained in the log.
    • Added MOTR PR #299, test commit 14f8f20a08c3463fd06cca35004b1c19378bcdd8, based on MOTR main 391df8d2a9d100ba04095ec6ae9128cb69624ea1. 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.
    • A physical multi-block or persisted-object regression would be useful because candidate membership and index reads can be affected by data layout. No such boundary was demonstrated here, and no large-data or nightly regression was claimed.

    Evidence and not covered

    Original scripts, row-level results, EXPLAIN plans, build and server logs, the initial and corrected DISTINCT records, 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.

  5. slyunnn commented on Nov 2, 2026

    @slyunnn

    TKE 大数据补测结论

    结果:通过。 针对 MatrixOne commit d39d8a40343ccd40bf665036388df7a40ee867f8,在 TKE 1 TP + 2 AP 环境执行 IVF equi-JOIN + TopK 补测;工作流及资源清理均成功。测试 job 使用独立数据库,测试后删除。

    • 数据:100 万行、128 维、IVF 64 lists;原表持久化为 126 个 block,索引 entries 持久化为 123 个 block。
    • 覆盖两个不同 CN 的直接入口;JOIN 使用重复键,并覆盖高匹配率和低匹配率(分别 980,100、9,900 个源行匹配,每行 JOIN 出两条结果);前 10,000 个最近向量不匹配。
    • 每个 CN、每种匹配率分别检查 probe 8 和 64 的索引计划与 Top 20,使用 FORCE 精确查询作为基线;8 个查询的 recall@20 均为 100%,probe 64 的结果集合与精确基线一致。两种匹配率在两个 CN 的 probe 64 实际均读取 123 个 entries block。
    • 共 39 项脚本断言通过;测试库清理成功。该数据是人为构造、单次查询,召回和耗时不代表真实业务数据或性能基准;本次没有进行并发、持续压测和故障注入。

    运行与证据:TKE job #41401136415,artifact tke-family-motr-debug-1x2-motr-41401136415-1 中的 feature29702-scale.json 和计划文件。未发现可确认的产品缺陷。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/featurepriority/p0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions