Skip to content

perf: speed up sparse row-stream reads (ANN 4.1-10.6x, indexed FTS 11x, scalar ~1x) - #11252

Merged
Xuanwo merged 1 commit into
lance-format:mainfrom
xiaguanglei:filter-read-target-fragments
Nov 19, 2026
Merged

Xuanwo merged 1 commit into
lance-format:mainfrom
xiaguanglei:filter-read-target-fragments

Conversation

@xiaguanglei

Copy link
Copy Markdown
Contributor

Summary

LanceRead resolves physical row addresses first and prepares only candidate fragments. This reduces the cost of sparse reads for vector refinement, final projection, and full-text search.

The measurements use upstream 7bc65a9f6 as the baseline. The table reports local warm-cache P50 ratios at 22,379 fragments as baseline time divided by optimized time.

Workload Query P50 ratio Row-stream P50 ratio
Fixed-address read of 10 rows 46.23× with planning 47.66× execution only
Indexed ANN with exact refinement 5.41–10.56× 19.77–33.45×
Indexed ANN without refinement 4.09–7.27× 18.54–30.75×
Indexed FTS, address-encoded row IDs 11.03–11.20× 43.27–44.18×
Unindexed exact vector search 0.90–1.03× 26.27–26.52×
Unindexed filter with late projection 1.01–1.04× 38.05–44.58×
Unindexed FTS 0.93–1.09× 37.38–50.36×

At 6,525 fragments, indexed ANN query P50 improved 2.85–4.89× with refinement and 2.89–4.18× for ANN-only. Full projection scans, BTree mask reads, and direct Dataset.take calls measured 0.99–1.06× at 22,379 fragments.

Related work prunes fragment metadata for scalar-index scans. #8587

Change

  • Resolve the fragment IDs in _rowaddr or address-encoded _rowid against the dataset manifest or the caller's fragment scope.
  • Apply any physical row selection before loading candidate fragment metadata. Schedule reads from the fragments that have live rows in the resulting batch plan.
  • Preserve the caller's fragment scope and restore input row order and duplicates when attaching the fetched columns.

Benchmark

Fixed-address row-stream read

The baseline is 7bc65a9f6. A warm in-memory fixture returns the same 10 rows from the same physical files at every snapshot size. The table reports execution-only P50 over 61 measured queries per case, after eight warmups. Both versions use Rust 1.98.1 and release-with-debug on an Apple M4 Pro.

Visible fragments Baseline P50 Optimized P50
10 0.172 ms 0.157 ms
1,000 0.430 ms 0.156 ms
6,525 2.242 ms 0.156 ms
22,379 7.530 ms 0.158 ms

On the same 22,379-fragment snapshot with an explicit fragment scope, P50 including construction of the read plan decreases from 7.554 ms to 0.592 ms.

Indexed search with refinement and full projection

Run a normal Scanner Top-10 query with full projection against snapshots fully covered by IVF_FLAT. The fixture uses 16-dimensional L2 vectors, four fixed centroids, one probe, and a refine factor of two. Each A/B pair uses the same query, data files, and index. The plan includes ANN, exact refinement, and two row-stream reads in both variants.

The timer starts at scanner construction and ends when the full result batch is available. The dataset handle and cache are warm. Each variant has 101 measured queries per size after eight warmups. A/B order alternates within one Apple M4 Pro process. The benchmark binary uses Rust 1.98.1 and release-no-lto for both paths, with a benchmark-only switch to the 7bc65a9f6 metadata preparation path.

Visible fragments Baseline P50 Optimized P50 P50 speedup Baseline P95 Optimized P95
10 0.972 ms 1.026 ms 0.95x 1.168 ms 1.377 ms
1,000 1.586 ms 0.958 ms 1.66x 1.902 ms 1.214 ms
6,525 5.814 ms 1.213 ms 4.79x 6.491 ms 1.512 ms
22,379 19.484 ms 2.058 ms 9.47x 21.253 ms 2.424 ms

An independent repeat at 22,379 fragments yielded 21.863 ms to 2.476 ms P50 (8.83x) and 24.575 ms to 3.605 ms P95.

Vector indices and other read paths

The matrix uses warm in-memory snapshots with 6,525 and 22,379 fragments, identical inputs within each A/B pair, and the same local release-no-lto binary per driver. It covers all eight single-vector index families on a 16-dimensional L2 fixture, with and without exact refinement, plus unindexed exact vector search. Each indexed case has 51 samples per arm after eight warmups. The unindexed vector cases have 11 samples per arm.

A row-stream sample measures the batch's own planning, reading, attachment and materialization after its input arrives. It excludes work in the child plan. The non-vector row-stream column sums the recorded batch durations for a query. A dash indicates that the plan uses a different read path.

Indexed vector search at 22,379 fragments

All durations are milliseconds and use baseline → optimized.

Index Refined E2E P50 Refined E2E P95 Refine read P50 Final read P50 ANN-only E2E P50 ANN-only final read P50
IVF_FLAT 21.924 → 3.001 (7.31×) 28.678 → 9.687 8.618 → 0.313 8.677 → 0.293 11.697 → 1.926 (6.07×) 8.947 → 0.369
IVF_PQ 21.428 → 2.561 (8.37×) 28.319 → 9.472 8.762 → 0.279 8.711 → 0.273 13.068 → 2.884 (4.53×) 9.903 → 0.534
IVF_SQ 23.281 → 3.070 (7.58×) 32.683 → 10.059 9.156 → 0.347 9.165 → 0.312 11.239 → 1.742 (6.45×) 8.766 → 0.330
IVF_RQ 22.691 → 2.804 (8.09×) 26.411 → 10.136 9.042 → 0.306 8.992 → 0.273 11.252 → 1.784 (6.31×) 8.743 → 0.336
IVF_HNSW_FLAT 21.210 → 2.698 (7.86×) 42.308 → 5.527 8.713 → 0.334 8.750 → 0.280 11.737 → 2.129 (5.51×) 8.951 → 0.453
IVF_HNSW_PQ 26.593 → 4.919 (5.41×) 69.659 → 19.037 10.588 → 0.591 10.336 → 0.452 10.300 → 1.417 (7.27×) 8.025 → 0.261
IVF_HNSW_SQ 18.968 → 1.797 (10.56×) 19.879 → 2.169 7.847 → 0.238 7.821 → 0.219 10.908 → 1.672 (6.52×) 8.430 → 0.343
IVF_HNSW_RQ 21.989 → 2.439 (9.02×) 23.048 → 3.002 8.928 → 0.284 8.804 → 0.270 13.789 → 3.371 (4.09×) 9.323 → 0.499

At 6,525 fragments, refined indexed E2E improves by 2.85–4.89x and combined row-stream work improves by 5.86–9.83x across the eight indices. Unindexed exact vector search measures 263.685 → 189.732 ms E2E and 2.774 → 0.322 ms in the final row stream.

At 22,379 fragments, refined indexed E2E improves by 5.41–10.56x and combined row-stream work improves by 19.77–33.45x across the eight indices. Unindexed exact vector search measures 706.399 → 781.230 ms E2E and 8.806 → 0.332 ms in the final row stream.

Non-vector reads

Narrow cases use 41 samples per arm and scan-heavy cases use 11. The main table uses 22,379 fragments. The legacy V1 control uses 6,525 fragments. All durations are milliseconds and use baseline → optimized.

Workload Row-stream nodes E2E P50 E2E P95 Row-stream batch work P50
Metadata count 0 0.042 → 0.042 (1.00×) 0.043 → 0.043 —
Full projection scan 0 373.030 → 350.834 (1.06×) 867.203 → 672.416 —
Scan LIMIT 10 0 0.536 → 0.652 (0.82×) 1.093 → 1.186 —
Scanner physical selection 0 1.341 → 2.140 (0.63×) 6.507 → 5.538 —
Dataset take by offset 0 1.811 → 1.801 (1.01×) 5.609 → 6.114 —
Dataset take by row ID 0 0.215 → 0.217 (0.99×) 2.522 → 5.188 —
Dataset take by address 0 0.211 → 0.214 (0.99×) 0.738 → 0.575 —
BTree filter and projection 0 6.598 → 6.622 (1.00×) 7.417 → 7.442 —
BTree filter with ordered limit 0 7.972 → 7.905 (1.01×) 8.769 → 9.103 —
Unindexed filter with early projection 0 429.418 → 418.155 (1.03×) 938.078 → 923.244 —
Unindexed filter with late projection 1 288.818 → 279.046 (1.04×) 1355.332 → 398.143 7.712 → 0.173
Scanner ORDER BY LIMIT 0 270.030 → 276.054 (0.98×) 283.843 → 285.086 —
Indexed FTS, address-encoded row IDs 2 18.854 → 1.709 (11.03×) 19.466 → 2.002 15.728 → 0.356
Unindexed FTS with ordered projection 2 286.432 → 263.600 (1.09×) 311.808 → 295.216 15.107 → 0.300
Indexed FTS control, stable logical row IDs 2 37.561 → 36.377 (1.03×) 39.068 → 37.834 34.198 → 33.316
Indexed FTS, legacy V1 TakeExec 0 0.637 → 0.644 (0.99×) 0.686 → 0.686 —

Independent scan and FTS repeat

At 22,379 fragments, the independent exact vector scan repeat measured 545.051 → 526.808 ms E2E and 8.907 → 0.339 ms in the final row stream. The two trials show consistent savings in the row stream. End-to-end scan timings vary between trials.

The repeat below reports P50 in milliseconds at 22,379 fragments. The legacy V1 control uses 6,525 fragments. The row-stream labels identify the columns fetched by each operator.

Workload E2E Fetch id Fetch payload Combined row stream
Full projection scan 354.774 → 352.154 — — —
Scanner physical selection 0.523 → 0.537 — — —
Unindexed filter with late projection 354.312 → 351.860 — 9.133 → 0.240 9.133 → 0.240
Indexed FTS, address-encoded row IDs 21.166 → 1.889 8.738 → 0.218 8.732 → 0.190 17.567 → 0.406
Unindexed FTS 352.464 → 380.723 8.509 → 0.256 8.364 → 0.188 16.857 → 0.451
Indexed FTS control, stable logical row IDs 41.458 → 40.194 18.719 → 18.401 18.897 → 18.175 37.677 → 36.631
Indexed FTS, legacy V1 TakeExec 0.778 → 0.828 — — —

Indexed FTS with address-encoded row IDs measured an 11.03–11.20× end-to-end P50 speedup. The separate stable logical row ID control uses row-ID sequences to resolve addresses and measured about 1.03×. For scan-heavy cases, saving several milliseconds in row-stream reads is a small part of the total query time. Plain scans, BTree mask reads, physical selections and the direct take APIs use other execution paths.

Correctness and limitations

The optimization applies to physical addresses. Streams keyed by stable logical row IDs resolve them through the dataset's row-ID sequences. An explicit fragment scope is indexed once when the row-stream plan is constructed. Fragment routing runs per batch. The benchmarks measure sparse Top-10 queries one at a time on an in-memory store.

The new regression cases keep an unrequested fragment visible while making its metadata unreadable. They cover physical addresses, address-encoded row IDs, physical addresses on a stable-ID table, and an explicit fragment scope.

Validation

  • After rebasing onto upstream 4e9620bac, 198 filtered-read, vector scan, and version-column tests passed.
  • cargo fmt --all -- --check and git diff --check passed.
  • The standalone regression checks passed in three key configurations. They checked output order, repeated keys, and omission of stale keys while an unrelated fragment's metadata was unreadable.
  • The fixed-address benchmark checked every returned row and payload in both variants.
  • Both indexed query trials verified the complete output, row order, payloads, vectors, and exact distances against the deterministic fixture and between paths.
  • The read matrix validated identical A/B plans where the Scanner exposes a plan, and identical returned results for all workload pairs. Vector tests also checked recall at 10 and verified per-stage row-stream sample counts.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Gate recommendation: approve.

Candidate-fragment routing addresses the sparse-read preparation cost while preserving fragment scope, deletion filtering, and input order and duplicates. The focused local row-stream tests passed.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 19, 2026
@Xuanwo
Xuanwo merged commit ecfa565 into lance-format:main Nov 19, 2026
44 of 48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

K-approved Latest Gatekeeper recommendation permits acceptance. performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants