Skip to content

[Bug] IVF l2_only pre-filter recall hangs with severe CN read amplification on 10M wiki dataset #24962

Closed

Description

@Ariznawlll

Summary

Nightly run stuck for more than 5 hours in IVF PRE POST FILTER VECTOR RECALL TEST, specifically at step Recall l2_only pre-filter.

Run/job: https://github.com/matrixorigin/mo-nightly-regression/actions/runs/27359437757/job/80930011420

This does not look like a GitHub runner issue, pod restart, OOM, or RPC queue blockage. Metrics and profiles point to severe read amplification in MO while executing IVF l2_only pre-filter recall on the 10M wiki dataset.

Failed/stuck step

Workflow step:

python run_wiki.py recall --config "${WIKI_CFG}" \
  --sql-mode l2_only --filter-mode pre \
  --gt-source ann -n "${WIKI_N}" -k "${WIKI_K}" --concurrency "${WIKI_CONCURRENCY}" \
  | tee "${GITHUB_WORKSPACE}/wiki_recall_l2_only_pre.log"

Parameters:

WIKI_N=10000
WIKI_K=10
WIKI_CONCURRENCY=100

The generated SQL shape is:

SELECT file_id, id
FROM historical_file_blocks_wiki_ivfflat10m
ORDER BY l2_distance(embedding, ?) ASC
LIMIT 10
BY RANK WITH OPTION 'mode=pre';

The benchmark client uses ThreadPoolExecutor(max_workers=100) and waits through as_completed(...) without a per-query timeout. If some queries become extremely slow or stuck, the whole CI step waits until the workflow timeout.

Environment

  • MO image/version: commit-516e55d88
  • Namespace: mo-main-commit-516e55d88-20260611
  • MO service IP: 172.16.96.178
  • Pods:
    • DN: nightly-regression-dis-dn-0
    • CNs: nightly-regression-dis-tp-cn-2g287, nightly-regression-dis-tp-cn-j74fr, nightly-regression-dis-tp-cn-w5h4b

Metric evidence

Window: from 2026-06-12 08:43:02 CST, when Recall l2_only pre-filter started.

Basic health checks:

  • Pod restarts: 0 for CN/DN/proxy
  • RPC write queue: 0
  • Cache pressure: nearly 0

CN CPU shortly after recall started:

  • tp-cn-j74fr: peak 13.908 cores at 08:53 CST
  • tp-cn-w5h4b: peak 13.876 cores at 08:53 CST
  • tp-cn-2g287: peak 13.812 cores at 08:53 CST

Container filesystem read throughput:

  • tp-cn-2g287: peak 2342.9 MiB/s at 09:08 CST
  • tp-cn-j74fr: peak 2139.9 MiB/s at 09:08 CST
  • tp-cn-w5h4b: peak 1994.5 MiB/s at 09:08 CST

MO FS read rate:

  • tp-cn-w5h4b: peak 11581.574 ops/s at 09:08 CST
  • tp-cn-j74fr: peak 9954.574 ops/s at 09:08 CST
  • tp-cn-2g287: peak 8986.163 ops/s at 09:08 CST

Pipeline/statement duration also spiked soon after recall started:

  • mo_pipeline_server_duration_seconds 5-min avg peak:
    • tp-cn-j74fr: 49.525s
    • tp-cn-w5h4b: 48.571s
    • tp-cn-2g287: 42.732s
  • mo_txn_statement_duration_seconds{type="execute"} 5-min avg peak:
    • tp-cn-j74fr: 14.191s
    • tp-cn-2g287: 10.035s
    • tp-cn-w5h4b: 9.076s

DN also had heavy background read/merge activity:

  • DN S3/network read peak: about 741 MiB/s
  • DN cache evict peak: about 34 ops/s

Profile evidence

Pyroscope CPU profile window: 2026-06-12 08:43:02 CST to 2026-06-12 14:45:00 CST, before manual profiling polluted the runtime.

CN hot paths were dominated by table scan/read/projection/top rather than IVF search itself:

  • tp-cn-2g287
    • self CPU: runtime.memmove 37.47%, internal/runtime/syscall.Syscall6 25.04%
    • total hot paths: table_scan.(*TableScan).Call 61.64%, blockio.BlockDataRead 61.60%, BlockDataReadInner 60.44%, readutil.(*reader).Read 61.63%, top.(*Top).Call 61.64%
  • tp-cn-j74fr
    • self CPU: runtime.memmove 39.86%, internal/runtime/syscall.Syscall6 26.59%
    • total hot paths: table_scan.(*TableScan).Call 65.72%, blockio.BlockDataRead 65.52%, BlockDataReadInner 64.43%, readutil.(*reader).Read 65.69%, top.(*Top).Call 65.50%

IVF-related functions are present in the profile, but they are not the dominant CPU path:

  • table_function.(*ivfSearchState).start
  • table_function.runIvfSearchVector
  • ivfflat.(*IvfflatSearch).Search
  • ivfflat.(*IvfflatSearchIndex).Search
  • blockio.HandleOrderByLimitOnIVFFlatIndex
  • vectorindex/metric.L2DistanceSq

DN profile shows heavy merge/read activity at the same time:

  • mergeObjectsTask.Execute: 80.73%
  • mergeObjectsTask.LoadNextBatch: 73.81%
  • mergesort.DoMergeAndWrite: 80.45%
  • mergesort.mergeObjs: 80.44%
  • fileservice.(*readCloser).Read: 143.24%

Conclusion

The stuck step is caused by MO-side execution behavior for IVF l2_only pre-filter recall. Under 100 concurrency on the 10M wiki dataset, the query path triggers very high CN read amplification. CN profiles are dominated by TableScan -> BlockDataRead/readutil -> Projection -> Top, with memmove and syscall cost very high. DN is also doing heavy merge/S3 read work concurrently, which likely worsens IO pressure.

This is not caused by runner failure, pod restart/OOM, RPC queue blockage, or cache pressure. The benchmark step then appears to hang because the client has no per-query timeout and waits for all futures to finish.

Expected behavior

l2_only pre-filter recall should complete within a bounded time, or the execution plan should avoid falling back to a high-read table-scan/top path for this workload.

Suggested next steps

  1. Check why BY RANK WITH OPTION 'mode=pre' for ORDER BY l2_distance(...) LIMIT 10 still spends most CPU in table scan/block read/projection/top.
  2. Check whether IVFFLAT pre-filter path is reading too many blocks or failing to prune candidates effectively.
  3. Consider adding server-side/query timeout protection for this vector recall workload.
  4. Consider adding client-side per-query timeout in the benchmark to avoid CI hanging for many hours when individual queries are stuck.

Activity

  1. added
    kind/bug
    on Jun 12, 2026
  2. added theissue type on Jun 12, 2026
  3. added this to the MO-202606 milestone on Jun 12, 2026
  4. Ariznawlll commented on Jun 12, 2026

    @Ariznawlll
    CollaboratorAuthor

    Additional code-level analysis for the four follow-up questions:

    1. Why does BY RANK WITH OPTION 'mode=pre' still spend most CPU in table_scan / BlockDataRead / projection / top?

    For the failing case, the benchmark mode is l2_only. Its SQL template has no normal filter predicate:

    SELECT `file_id`,`id`
    FROM historical_file_blocks_wiki_ivfflat10m
    ORDER BY l2_distance(`embedding`, ?) ASC
    LIMIT 10
    BY RANK WITH OPTION 'mode=pre'

    In the planner, mode=pre only enables the pre-filter nested join path when the original scan still has filters:

    pushdownEnabled := ivfCtx.pushdownEnabled && len(scanNode.FilterList) > 0

    Source: pkg/sql/plan/apply_indices_ivfflat.go.

    There is also a unit test that explicitly documents this behavior: NoFilters_DisablePushdown uses rankOption: mode=pre, but verifies the plan is:

    PROJECT -> SORT -> JOIN(SCAN, FUNCTION_SCAN)
    

    instead of the nested pre-filter join.

    So in this workload, mode=pre is syntactically present, but because l2_only has no WHERE filter, there is no pre-filter candidate set to build. The query therefore still spends time in scan/read/top paths.

    2. Is IVFFLAT pre-filter reading too many blocks or failing to prune candidates effectively?

    For this exact failing l2_only case, the pre-filter membership path is not active.

    ivfflat.getBloomFilter() returns immediately if there are no runtime filter specs:

    if len(sqlproc.RuntimeFilterSpecs) == 0 {
        return
    }

    Without a runtime membership filter, IVFFLAT uses the standard centroid path:

    SELECT pk, l2_distance(entry, query) AS vec_dist
    FROM entries
    WHERE version = ? AND entry_id IN (<selected centroids>)
    ORDER BY vec_dist
    LIMIT ?

    That internal ORDER BY vec_dist LIMIT can be pushed into the entries table scan as IndexReaderParam. The reader path then calls HandleOrderByLimitOnIVFFlatIndex, which loops over selected rows, decodes vector bytes, computes distance row by row, and maintains a TopK heap.

    This matches the profile: TableScan -> BlockDataRead/readutil -> Projection -> Top, with heavy runtime.memmove and syscall cost.

    Therefore the concrete issue seen here is not “pre-filter membership pruning failed”, but:

    • l2_only has no filter, so pre-filter membership pruning is bypassed by design.
    • The remaining centroid-based entries scan appears to read/compute too much under 100 concurrency.
    • The profile and metrics show severe read amplification in this entries/base-table scan path.

    3. Server-side timeout protection

    There is a max_execution_time system variable definition, but code search only found the variable definition, not execution-time enforcement that wraps query execution context with a deadline. So it does not currently look like this workload is protected by a real statement timeout.

    Relevant finding:

    • pkg/frontend/variables.go defines max_execution_time, default 0.
    • No matching execution path was found that applies it as context.WithTimeout for normal SQL execution.

    So adding server-side protection would require wiring a real query deadline into the frontend/compile/process context, or adding a targeted timeout/cancellation guard for vector index internal SQL.

    4. Client-side benchmark timeout

    The benchmark client also has no per-query timeout.

    In eval_vector_search_from_table.py:

    • l2_only template has no WHERE filter.
    • DB connection is pymysql.connect(**DB_CONFIG) without default read_timeout / write_timeout.
    • Concurrent execution uses ThreadPoolExecutor and as_completed(future_to_i) without timeout.

    If one or more SQLs become extremely slow or stuck, the process keeps waiting for those futures, so the GitHub Action step can hang for hours until workflow timeout.

    Current conclusion

    The immediate cause of the 5h stuck step is: l2_only + mode=pre does not actually activate pre-filter membership pruning because there is no WHERE filter. The query falls back to the normal IVF centroid entries path, where ORDER BY vec_dist LIMIT is executed through scan/block-read/distance-calculation/top-k logic. Under 100 concurrency on 10M wiki data, this causes severe CN read amplification. The benchmark then has no client-side query timeout, so slow/stuck queries hang the CI step.

    Recommended fixes:

    1. Product side: investigate why the centroid entries path reads so much under ORDER BY vec_dist LIMIT 10, especially with probe_limit and 100 concurrency.
    2. Product side: clarify or adjust mode=pre behavior for no-filter SQL. If no pre-filter can be built, EXPLAIN/logs should make that obvious.
    3. Product side: implement real statement/query timeout support, or at least timeout/cancellation for vector index internal SQL.
    4. Benchmark side: add per-query timeout / PyMySQL read_timeout / fail-fast behavior so CI reports a bounded failure instead of hanging for hours.
  5. assigned and unassigned on Jun 12, 2026
  6. aunjgr commented on Jun 12, 2026

    @aunjgr
    Contributor

    昨天进去的PR都跟ivf不相关。最近的相关PR是上周的 #24787 。等一下看今晚的nightly能否复现

  7. Ariznawlll commented on Jun 13, 2026

    @Ariznawlll
    CollaboratorAuthor

    Additional goroutine analysis from a newer hung run. This points to a pipeline cleanup hang, not only a slow table scan issue.

    New hung run

    Run: https://github.com/matrixorigin/mo-nightly-regression/actions/runs/27426252619
    Job: https://github.com/matrixorigin/mo-nightly-regression/actions/runs/27426252619/job/81125307035

    The stuck step in this run is different from the original l2_only pre-filter case. This time it stopped at:

    IVF PRE POST FILTER VECTOR RECALL TEST / Recall l2_filter pre-filter
    

    Timeline:

    Job started: 2026-06-13 05:31:20 CST
    Recall l2_filter pre-filter started: 2026-06-13 06:53:26 CST
    Last progress: processed 4885/10000 queries
    Step cancelled: 2026-06-13 08:01:33 CST
    

    SQL shape printed by the benchmark:

    SELECT `file_id`, `id`, l2_distance(`embedding`, ?) AS dist
    FROM `jst_app_wiki`.`historical_file_blocks_wiki_ivfflat10m`
    WHERE `file_id` = ?
    ORDER BY dist ASC
    LIMIT ? BY RANK WITH OPTION 'mode=pre'

    Goroutine dump summary

    The uploaded goroutine.zip contains 6000 CN goroutine dumps. The dump timestamps are:

    2026-06-13 09:42:00 CST ~ 2026-06-13 09:58:48 CST
    

    So these dumps were collected about 1 hour 40 minutes after the GitHub step was cancelled, not exactly at the cancellation time. However, they still contain long-running SQL goroutines whose start time falls inside the Recall l2_filter pre-filter window.

    The most important finding is on CN 38653536-6362-6534-3235-626632363730: several frontend SQL goroutines were stuck for a very long time.

    doComQuery max duration: 165 minutes
    state: chan receive
    

    For example, in the 09:58:06 dump, three SQL goroutines have the following stack:

    goroutine 2647591 [chan receive, 165 minutes]:
    github.com/matrixorigin/matrixone/pkg/sql/compile.(*Compile).runOnce
        /go/src/github.com/matrixorigin/matrixone/pkg/sql/compile/compile.go:553
    github.com/matrixorigin/matrixone/pkg/sql/compile.(*Compile).Run
    github.com/matrixorigin/matrixone/pkg/frontend.executeResultRowStmt
    github.com/matrixorigin/matrixone/pkg/frontend.executeStmt
    github.com/matrixorigin/matrixone/pkg/frontend.doComQuery
    

    09:58:06 minus 165 minutes is around 07:13 CST, which is inside the Recall l2_filter pre-filter execution window. This means these are not just idle background goroutines; they are SQL requests that did not return from the server side.

    The corresponding worker goroutines are stuck during pipeline cleanup:

    goroutine 2647276 [select, 164 minutes]:
    github.com/matrixorigin/matrixone/pkg/vm/process.(*PipelineSignalReceiver).listenToSingleEntry
        /go/src/github.com/matrixorigin/matrixone/pkg/vm/process/process_spoolr.go:259
    github.com/matrixorigin/matrixone/pkg/vm/process.(*PipelineSignalReceiver).GetNextBatch
    github.com/matrixorigin/matrixone/pkg/vm/process.(*PipelineSignalReceiver).WaitingEnd
    github.com/matrixorigin/matrixone/pkg/sql/colexec/merge.(*Merge).Reset
        /go/src/github.com/matrixorigin/matrixone/pkg/sql/colexec/merge/types.go:87
    github.com/matrixorigin/matrixone/pkg/vm/pipeline.(*Pipeline).cleanupInOrder
    github.com/matrixorigin/matrixone/pkg/vm/pipeline.(*Pipeline).Cleanup
    github.com/matrixorigin/matrixone/pkg/sql/compile.(*Scope).Run.func1
    github.com/matrixorigin/matrixone/pkg/sql/compile.(*Scope).Run
    github.com/matrixorigin/matrixone/pkg/sql/compile.(*Compile).runOnce.func2
    

    This matches the code path:

    compile.go:553 waits on errC
    pipeline/types.go:70 cleanupInOrder -> op.Reset
    merge/types.go:87 Merge.Reset -> receiver.WaitingEnd()
    process_spoolr.go:249 WaitingEnd uses context.TODO() and loops until receiver.alive == 0
    

    Conclusion

    The direct hang point shown by the goroutine dump is not simply TableScan or BlockDataRead being slow. The hour-level hang is:

    frontend.doComQuery
      -> Compile.runOnce waits for a scope worker
      -> the worker is stuck in Pipeline.Cleanup
      -> Merge.Reset waits in PipelineSignalReceiver.WaitingEnd
      -> the SQL request never returns
    

    In other words, some IVFFLAT recall queries never returned because MO got stuck during pipeline cleanup. The stuck point is Merge.Reset -> PipelineSignalReceiver.WaitingEnd. This blocks Compile.runOnce, then blocks frontend.doComQuery, and finally causes the benchmark client to wait forever for unfinished futures until the GitHub Actions step is cancelled.

    The dump also contains many IVFFLAT/pre-filter related execution stacks, so the workload is still exercising the expected scan/hash/runtime-filter/IVFFLAT path:

    TableScan: 57508 blocks
    BlockDataRead: 56139 blocks
    HashBuild: 49067 blocks
    MessageReceiver.ReceiveMessage: 46240 blocks
    ReceiveJoinMap: 7961 blocks
    HashJoin.build: 7597 blocks
    IVFFlat related: 12324 blocks
    HandleOrderByLimitOnIVFFlatIndex: 280 blocks
    

    But these TableScan, BlockDataRead, HashBuild, and ReceiveMessage stacks mostly have short goroutine state durations, usually around 1~3 minutes. They show the active workload shape, but they are not the direct hour-level hang point. The direct hour-level hang is the frontend query waiting on pipeline cleanup.

    Useful goroutine files to inspect

    Most useful file:

    goroutine/CN_38653536-6362-6534-3235-626632363730_goroutine_019ebea1-5987-7bbb-b481-275eebd10d90.gz
    

    This file contains three doComQuery [chan receive, 165 minutes] goroutines and the corresponding Pipeline.Cleanup -> Merge.Reset -> WaitingEnd [select, 164 minutes] worker stacks.

    Neighboring dumps from the same CN, useful for confirming that the same query stayed stuck across samples:

    goroutine/CN_38653536-6362-6534-3235-626632363730_goroutine_019ebea0-e455-75be-86be-20344ed2fdeb.gz
    goroutine/CN_38653536-6362-6534-3235-626632363730_goroutine_019ebea0-6f3e-79a2-a50e-c7126e74d137.gz
    goroutine/CN_38653536-6362-6534-3235-626632363730_goroutine_019ebe9f-84f4-7e7f-9609-ad19ff7ea40f.gz
    goroutine/CN_38653536-6362-6534-3235-626632363730_goroutine_019ebe9f-0f98-75bc-b74b-147c222ff6ab.gz
    

    Representative runtime-filter / hash / table-scan stacks:

    goroutine/CN_38653536-6362-6534-3235-626632363730_goroutine_019ebcd6-a9c7-7ec0-94b3-e40f103bc72c.gz
    

    Representative IVFFLAT top-k stack plus frontend waiting stack:

    goroutine/CN_38653536-6362-6534-3235-626632363730_goroutine_019ebe61-b89f-7ac1-b800-4583cf42c518.gz
    

    CN_38653536-6362-6534-3235-626632363730_goroutine_019ebe9f-0f98-75bc-b74b-147c222ff6ab.gz
    CN_38653536-6362-6534-3235-626632363730_goroutine_019ebe9f-84f4-7e7f-9609-ad19ff7ea40f.gz
    CN_38653536-6362-6534-3235-626632363730_goroutine_019ebea0-6f3e-79a2-a50e-c7126e74d137.gz
    CN_38653536-6362-6534-3235-626632363730_goroutine_019ebea0-e455-75be-86be-20344ed2fdeb.gz
    CN_38653536-6362-6534-3235-626632363730_goroutine_019ebea1-5987-7bbb-b481-275eebd10d90.gz

  8. 1 remaining item

  9. Ariznawlll commented on Aug 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    Regression observed in 2026-08-22 nightly

    This issue has regressed and is being reopened. The same 10M Wiki IVF-FLAT workload again hangs in the first `l2_only` + `mode=pre` recall phase.

    The failing query shape is:

    ```sql
    SELECT file_id, id
    FROM jst_app_wiki.historical_file_blocks_wiki_ivfflat10m
    ORDER BY l2_distance(embedding, ?) ASC
    LIMIT 10 BY RANK WITH OPTION 'mode=pre';
    ```

    Actual behavior

    The S3 data load and IVF-FLAT index build completed successfully:

    • `LOAD DATA`: `2035.08s`
    • `CREATE INDEX`: `1271.68s`

    The following recall then ran at only about `0.48 QPS`:

    ```bash
    python run_wiki.py recall --config "${WIKI_CFG}" \
    --sql-mode l2_only --filter-mode pre \
    --gt-source ann -n 10000 -k 10 --concurrency 100
    ```

    After roughly one hour it had completed only `1720/10000` requests. The job was cancelled by its configured `timeout-minutes: 200` before the first recall pass completed, so the remaining pre/post-filter scenarios and final `EXPLAIN ANALYZE` were not executed.

    The job log contains no MO panic, OOM, connection failure, or index-build failure.

    Passing control

    The previous nightly run used the same vector benchmark commit and the same workload parameters, but an earlier MatrixOne commit:

    The current run is therefore about 46x slower (`0.48 QPS` vs `20.25 QPS`). At the current throughput one recall pass needs roughly 5.8 hours, so raising the CI timeout would only mask the regression.

    Code correlation

    The current product commit contains #27297, while the passing control does not. That PR replaced the query-time IVF search TVF with the optimizer-visible `VECTOR_INDEX_SCAN` path.

    This is a strong regression candidate, not yet a line-level root cause: the failed job did not reach its final `EXPLAIN ANALYZE`, so the current evidence cannot prove whether the new path misses index pruning, expands the candidate scan, or blocks in distributed execution.

    Expected behavior

    The 10M IVF-FLAT `l2_only` recall should complete in a bounded time comparable to the previous control run, without leaving the benchmark waiting for long-running SQL futures until the workflow is cancelled.

    Suggested verification

    1. Compare the SQL above on `7fa4a36aa` and `dd040ad6` with `EXPLAIN ANALYZE`, first at a small query count and then at 100 concurrent clients.
    2. Capture profile/read metrics during the current `VECTOR_INDEX_SCAN` path.
    3. Add a per-query client timeout to the benchmark so a recurrence produces actionable SQL-level evidence rather than consuming the entire job timeout.
  10. Ariznawlll commented on Aug 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    Re-closing this historical issue to preserve its resolved status after #24972.

    The current failure is being tracked as a new regression in #27474 because it appears after the later `VECTOR_INDEX_SCAN` refactor #27297. The new issue contains the current main commit, baseline comparison, and nightly evidence.

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

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions