Skip to content

[Performance]: IVFFLAT PRE hybrid queries execute the same MATCH search twice #30165

Closed

Description

@XuPeng-SH

Is there an existing issue for performance?

  • I have checked the existing issues.

Searched fulltext/hybrid/redundant-work reports; no direct duplicate-MATCH-execution report found. #25132 concerns repeated SQL re-entry per widening round; this witness has one vector search round and duplicate fulltext branches inside that round. #30164 tracks unnecessary relevance sorting separately.

Environment

  • Version or commit-id: main, 8586fa08715c868cab997d11d2687a76b8cc360f (actual tested binary; not a claim about today's main).
  • Hardware parameters: CPU-only local test; GOMAXPROCS=4, GOMEMLIMIT=6GiB. Physical CPU model was not recorded.
  • OS type: Linux amd64; Go1.27.1, GOAMD64=v3, GOEXPERIMENT=simd.
  • Others: 1 LogService / 1 TN / 1 CN; mysql-connector-python, use_pure=True, autocommit=True. Independent synthetic fixtures, no production source edits.

Details of Performance

IVFFLAT PRE filtering combined with MATCH executes the same fulltext hit production separately for its membership side and its final-result side.

In an actual single-list, single-probe test with 1026 rows and 16 rare-word hits, EXPLAIN ANALYZE shows two Fulltext Index Scan instances for ix_ft. Both consume/output 16 hits; both matching base-table scans consume/output 16 rows. The membership branch additionally relevance-sorts all 16 hits. The final vector Top returns IDs 1010..1016 correctly.

Vector execution reports one search, one round, 16 vectors scored. Background Queries reports four rounds, consistent with duplicated fulltext metadata/token work. This report does not equate every background round with a vector round or infer a fixed latency multiplier.

Fixture / reproduction

The SQL generator below expresses the executed insertion loop's same rows. It has not been independently rerun on today's main.

CREATE DATABASE hybrid_repro;
USE hybrid_repro;
SET experimental_fulltext_index=1;
SET experimental_ivf_index=1;
SET experimental_hnsw_index=1;

CREATE TABLE docs(
  id BIGINT PRIMARY KEY,body TEXT,tag INT,v VECF32(2) NOT NULL
);
INSERT INTO docs
SELECT result,
       CASE WHEN result=1026 THEN NULL
            WHEN result>1009 THEN 'needle omega'
            WHEN result%3=0 THEN 'alpha beta'
            ELSE 'alpha plain' END,
       CASE WHEN result=1026 OR result%17=0 THEN NULL ELSE result%7 END,
       CONCAT('[',result,',0]')
FROM generate_series(1,1026,1) g;
CREATE FULLTEXT INDEX ix_ft ON docs(body);
SET probe_limit=1;
CREATE INDEX ix_v USING ivfflat ON docs(v)
  LISTS=1 OP_TYPE 'vector_l2_ops';
SELECT mo_ctl('dn','flush','hybrid_repro.docs');

EXPLAIN ANALYZE
SELECT id FROM docs
WHERE MATCH(body) AGAINST('needle')
ORDER BY l2_distance(v,'[0,0]')
LIMIT 7 BY RANK WITH OPTION 'mode=pre';

Observed shape:

Top(distance, LIMIT 7)
  result Join
    Join(base, Fulltext Index Scan ix_ft)       FT input/output=16/16
    membership SEMI Join
      Vector Index Scan ix_v                  vectors scored=16
      relevance Sort
        Join(base, Fulltext Index Scan ix_ft)   FT input/output=16/16

Desired performance: when both consumers require the same MATCH set at the same snapshot, avoid repeating its index search and base fetch solely because the vector PRE rewrite generated two branches. Share or otherwise safely reuse the proven common hit set. Preserve valid matches and exact final distance order.

Additional information

Whitebox context: the shared search design describes early vector rewrite followed by late fulltext rewrite. The analyzed PRE topology contains a membership subtree and a result subtree that each receive the same MATCH rewrite. This identifies the common-work opportunity; a complete source-level causal trace or sharing patch was not implemented.

Any reuse must prove equal index/query/mode/score-range/tenant/snapshot semantics and retain independent consumer lifetimes, cancellation, late errors and cleanup. Avoid unbounded whole-hit-set materialization; preserve streaming and memory accounting. Benchmark rare and common terms, small/large eligible sets, prepared term changes, zero/positive LIMIT, selective scalar predicates and multi-consumer cancellation. DML/DDL/snapshot changes must not reuse a stale set.

Retained receipt: hybrid-results.jsonl, hybrid/ft_ivf/needle/all/pre/analyze. Current results are correct; this is an efficiency finding. No GPU, multi-CN, cold-cache or production throughput validation is claimed. The broader candidate-completion feature #28988 is not a substitute for this duplicate-work issue.

Activity

  1. added
    severity/s0
    on Oct 14, 2026
  2. added
    ai-light
    on Oct 15, 2026
  3. slyunnn commented on Oct 21, 2026

    @slyunnn

    Regression and extended verification for #30165 (2026-10-21)

    Verification Environment

    • Freshly fetched MatrixOne origin/main: 40300d10e5b67dfc166c0646dbe4262fcca585a0, fix(vectorindex): isolate AVX-512 kernels from CPU dispatch (#30630).
    • Clean checkout built with make build TYPECHECK=1; the running binary reports 40300d10e5, Go 1.27.1, Linux/arm64, CPU-only.
    • Isolated local topology: 2 CN / 1 TN / 1 Log service / 1 Proxy, using local shared-disk storage. Proxy 127.0.0.1:6001, CN1 127.0.0.1:16001, and CN2 127.0.0.1:16002 were individually connected and used for the original query and extended verification.
    • Clients: MOTR/PyMySQL text protocol and Go database/sql with go-sql-driver/mysql, interpolateParams=false, including real COM_STMT_PREPARE / COM_STMT_EXECUTE on a pinned connection.

    What Was Covered

    • OK — Original 1,026-row fixture, LISTS=1, probe_limit=1, flush, and LIMIT 7 BY RANK WITH OPTION 'mode=pre': each endpoint returned IDs 1010 through 1016. EXPLAIN ANALYZE showed exactly 1 Fulltext Index Scan, 1 vector search round, and 16 vectors scored.
    • OK — Rare, common, and absent terms; scalar and NULL filters; score thresholds; Boolean search; mixed predicates; separate search terms; projected body; LIMIT 0; and offset pagination.
    • OK — fulltext and fulltext2 compatibility, compared with identical fulltext-only reference tables for exact PRE rows, order, and projected scores. Score comparisons use tolerance 1e-5.
    • OK — Projected/wrapped score controls retained 2 required fulltext producers; separate terms retained their distinct searches. POST mode was checked as an ordered subset rather than incorrectly requiring PRE completion.
    • OK — Native binary prepared statement reused with rare/common/absent/rare parameters, then after UPDATE, DELETE, and INSERT. FULLTEXT2 FORCE_SYNC established the indexed state before the post-DML check; independent expected IDs were 1012 through 1018.
    • OK — Invalid negative LIMIT was rejected with 1149; the same connection remained usable. Test databases were removed.
    • OK — Direct protocol verification passed 40/40 checks per endpoint, 120/120 overall. Isolated endpoint databases ran concurrently. MOTR SQL and protocol cases also passed with -j 2; this describes test scheduling, not an engine-parallel performance claim.
    • Not covered — Production/TKE throughput, cold-cache latency, GPU execution, asynchronous FULLTEXT2 convergence, and cancellation/fault injection. No latency multiplier or general score-sharing claim is made.

    Findings

    • Related fix: #30178, merge commit 43ae1edafafa5749315d567a3f18a38ff53d3eaa, perf(plan): avoid duplicate MATCH searches in IVFFLAT PRE.
    • The fix uses exact primary-key membership and row-fetch joins to remove redundant deterministic MATCH predicates from the final fetch while preserving the membership producer and external score consumers.
    • The original duplicate filter-only search no longer reproduces. A remaining relevance sort belongs to the separately tracked #30164 optimization and is outside this result.

    MOTR / BVT Coverage

    • Branch: test/issue-30165-ivf-pre-single-match; source commit bb2ad95a61448ba7e932be1daceb970cfb560236, pushed to matrixorigin/motr and verified remotely.
    • SQL/result: suites/14_issue_regression/{t,r}/issue_30165_ivf_pre_single_match.{test,result}; companion Go protocol test and launcher under script/14_issue_regression/.
    • SQL recording passed 19/19 statements; normal replay passed twice. Final SQL/protocol parallel replay passed 2/2 cases, also after the daily cherry-pick.
    • Included in MOTR daily PR #251, daily commit d5957c21fbe8169be4613e80ee10e80eff5b8ff9. No MatrixOne service source changed.

    Final Conclusion

    Fixed for the filter-only duplicate MATCH execution reported in #30165 on the tested main commit.

    Additional large-data regression is not required for this bounded planner optimization: the original 1,026-row fixture exercises the real IVFFLAT PRE path and directly asserts producer cardinality. Larger datasets would increase cost without proving a new execution boundary; production performance benchmarking remains separate.

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

Metadata

Metadata

Assignees

Labels

ai-lightkind/performanceseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions