Skip to content

[Bug]: IVFFLAT distance filtering panics when storage Top-K leaves an empty embedding slot #29381

Closed

Description

@LeftHandCold

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Searched recent issues for IVF/threshold/panic, index out of range, Shrink, and the exact filterEntryDistanceRange symbol. #29040 concerns distance-boundary semantics, #29038 concerns cached distance-function identity, and #27757 concerns connection failures. None accurately tracks this empty-column batch compaction panic.

Branch Name

main

Commit ID

7ce783464806490263c184f22aaf5d307225adef

Other Environment Information

  • Main Weekly run 36089256712, IVF job 107976971342.
  • Workflow revision: 152893c2e851e45db1ef2146060ba1afa7f123e9, profile weekly-shadow-1x2.
  • Namespace: mo-main-family-36089256712-1; 1 TP CN + 2 AP CN + 1 TN.
  • CN memory limit 55 GiB, FileService memory cache 16 GiB, GOMEMLIMIT 25000 MiB.
  • Wiki 10M, VECF32(768), IVFFLAT L2, lists=3162, probe_limit=5, ivf_preload_entries=0, k=10, concurrency=100, 10000 requests per round.
  • SQL entered through AP nightly-regression-dis-ap-cn-4l2k5; the recovered pipeline panic was logged on remote AP nightly-regression-dis-ap-cn-xfk5l.

Actual Behavior

During the first l2_filter_threshold / mode=post round, the job recorded 240 failed queries. 239 were backend-create/connection failures tracked separately under #27757; one was an independent recovered MO execution panic. They must not all be classified as network errors.

The target AP logged the panic at 2026-09-25 08:08:45.180257 UTC / 16:08:45.180257 CST. The coordinating AP returned it to SQL at 08:08:45.568541 UTC:

internal error: panic runtime error: index out of range [0] with length 0
  vector.shrinkFixed                vector.go:10101
  (*Vector).Shrink                  vector.go:6076
  (*Batch).Shrink                   batch.go:1687
  (*IvfflatSearchIndex).filterEntryDistanceRange
                                   relation_search.go:583
  (*IvfflatSearchIndex).scanEntriesInDomain.func1
                                   relation_search.go:226
  (*relationScanner).ScanRelation   plan_reader.go:865
  ...
  (*Pipeline).Run

Correlation identifiers:

  • Statement: 01a0d79c-1372-7521-aa89-99bf8fb4a29e
  • Transaction: 22955069869267a218d872fb8b06e044
  • Trace: 720f92e6-e9d5-f82c-20ed-7c62aa81541c

All nine cluster pods had zero restart-count increases over the checked IVF window. This is a recovered query-level panic, not evidence that the CN process crashed or that stored data was corrupted.

Expected Behavior

A valid distance-threshold query must filter the selected rows without attempting to shrink a deliberately unmaterialized embedding column. Correct SQL execution must not depend on whether a storage Top-K batch passes the exact distance range wholly or only partially.

Steps to Reproduce

The observed workload has this SQL shape (the runtime statement log truncates the long query vector, so this is a parameterized shape, not a standalone copy of the exact failing vector):

SELECT file_id, id, l2_distance(embedding, ?) AS dist
FROM historical_file_blocks_wiki_ivfflat10m
WHERE file_id = ? AND l2_distance(embedding, ?) <= 2.5
ORDER BY dist ASC
LIMIT 10 BY RANK WITH OPTION 'mode=post';
  1. Prepare the Wiki 10M IVFFLAT index using the linked job configuration.
  2. Run its existing l2_filter_threshold / post workload at concurrency 100.
  3. Inspect query errors individually rather than combining the non-connection panic with the backend timeouts.

The full TKE workload was not rerun in this investigation. A narrow local batch-contract reproducer at the exact deployed SHA did reproduce the same panic deterministically:

Go 1.26.4, darwin/arm64, repository CGo test wrapper
TestDistanceRangeFiltersStorageTopNBatchWithEmptyEntry
FAIL: index out of range [0] with length 0
filterEntryDistanceRange -> Batch.Shrink -> Vector.Shrink -> shrinkFixed

The local test obtains two scores with the real objectio.TopNVector, constructs the documented storage Top-K output layout (materialized scalar columns and distance column, empty typed entry column), and applies a distance range that retains only the first row. It uses a small VECF64 fixture to exercise the common batch contract; it does not claim to reproduce the original 768-dimensional input or the separate TCP timeouts. Test code and output are preserved in the investigation evidence bundle.

Additional information

Concrete code-level contract violation

  1. Persisted Top-K intentionally does not materialize the high-width embedding column after calculating scores. materializeVectorTopNRows skips topColPos, then calls outputBat.Vecs[topColPos].CleanOnlyData() while returning row-aligned scalar columns and appended distances. The exact-membership path has the same empty-slot contract.
  2. scanEntriesInDomain's BatchTransform recognizes storage-provided distances and calls filterEntryDistanceRange on that batch. The typed-empty embedding is legal at this boundary, not malformed client data.
  3. The partial-survivor branch uses bat.Shrink(sels, false) whenever 0 < len(sels) < bat.RowCount().
  4. Batch.Shrink shrinks every column, including the zero-length entry slot. shrinkFixed[types.Varlena] indexes that empty slot and panics. The all-survive and none-survive branches avoid this call, explaining why many queries succeed.

The runtime stack and local contract reproduction identify the unsafe compaction operation. The exact original candidate values that made the final range retain only a subset are not preserved in the truncated SQL log; conservative storage bounds followed by exact source-domain filtering are a legitimate reason for such a subset.

Main status and evidence boundaries

Activity

  1. added
    severity/s0
    and removed on Sep 25, 2026
  2. slyunnn commented on Sep 28, 2026

    @slyunnn

    Additional main evidence: stable query-level 20101 in Wiki threshold/post

    This is additional correlation evidence, not a claim that the exact panic stack in this issue has already been captured again.

    All three post-filter rounds completed their accounting but each recorded the same two query-level failures:

    query_id=9460  OperationalError 20101
    query_id=9617  OperationalError 20101
    

    The corresponding l2_filter_threshold + mode=pre rounds completed with zero failures. The job preserved the client receipt and workflow logs, but this run did not retain the server-side error string/stack for these two query IDs. Therefore this evidence should be triaged against the existing filterEntryDistanceRange/empty-slot panic here, rather than asserted as a confirmed duplicate of its root cause.

  3. added and removed
    severity/s0
    on Sep 30, 2026
  4. added a commit that references this issue on Oct 1, 2026
    112f7f3
  5. slyunnn commented on Oct 8, 2026

    @slyunnn

    Regression and extended verification for #29381 (2026-10-08)

    Verification Environment

    • Latest origin/main: 8929ab4946fbc7d44b6757fe5b12de6c74118c21 — fix(sql): preserve DECIMAL pruning for prepared integer comparisons (#29667).
    • Related fix: #29535, merged as 112f7f396351ff34b63af8b66e15f6d1a39befde; the directly relevant change is 0dfe50bd6508335ad2dd459d44357f4706254c9f (fix(ivfflat): preserve unloaded entries during distance filtering).
    • A fresh local topology was launched from a Linux mo-service built from that exact main commit: 2 CN / 1 TN / 1 Log service / Proxy.
    • The binary reported branch main and commit 8929ab4946fbc7d44b6757fe5b12de6c74118c21. Client protocol was the MySQL text protocol through the MySQL CLI.
    • Connectivity was verified to Proxy, CN1, and CN2. The original SQL was executed through Proxy and then independently through CN1 and CN2; the direct CN executions were not merely health checks.

    What Was Covered

    • OK Original persisted-entries partial-survivor query: l2_distance(v, [1,1,1]) <= 1.73205077 returned only id = 1 through Proxy, with no 20101 panic.
    • OK CN1 and CN2 reran that same original query and each returned only id = 1; subsequent reads remained healthy.
    • OK Boundary contrast: <= 1.7320508 returned 1,2, while <= 1.73205077 returned 1; this exercises the widened storage candidate followed by exact filtering path.
    • OK Happy path: < 5 returned 1,2 through the IVFFLAT index.
    • OK Unhappy/null path: a prepared upper bound was executed with 5, NULL, then 1; results were 1,2, empty, then 1 without connection or service failure.
    • OK Prepared statement and plan behavior: EXPLAIN showed Vector Index Scan and no Table Scan for the indexable distance predicate.
    • OK Focused IVFFLAT unit coverage previously passed at the same commit: TestCompactRelationTopBoundsRowsWithClearedEntryVector, TestDistanceRangeFiltersBeforeTopInSourceUnits, and TestRelationSearchBoundaryBranches.
    • Not covered TKE 10M workload reproduction. A large-data rerun is not required: the defect depends on an unloaded embedding slot plus a partial survivor during storage Top-K compaction, not row count, block or batch size, memory or spill, concurrency, skew, network transfer, or resource scale. The persisted 4-row boundary case is the minimal stable execution boundary.

    Findings

    The fix preserves sparse batch layout while compacting scalar and distance columns after exact distance filtering. All three MySQL endpoints completed the original partial-survivor regression without a panic, and the service stayed healthy afterwards. No 20101, index out of range, or actual panic signature was observed in the isolated service logs.

    MOTR / BVT Coverage

    Existing BVT coverage is present in test/distributed/cases/vector/vector_ivf_prepare_dist_range.sql, including the #29381 persisted-entry narrow-boundary query and its expected result. Existing targeted unit coverage directly asserts that a cleared embedding vector entry remains valid while the result batch is compacted. No MOTR change is needed because the existing product BVT and unit cases already cover the regression contract; no test source was modified.

    Final Conclusion

    Fixed. The repair is in current main, and real MySQL-protocol regression on the fresh 2 CN / 1 TN / 1 Log service / Proxy topology passed through Proxy, CN1, and CN2. Large-data regression is not required for this issue because scale is not a causal dimension of the sparse-batch compaction bug.

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s-1

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions