[Performance]:High-selectivity range filter materializes a full bitmap — `bitset_set_list` ~49% CPU, dwarfing the ANN search

オープン
#868 コメント 13 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@zhourrr がすでに取り組んでいます。

2026年11月2日 から。

評価

この issue はまだ評価されていません。

説明

enhancement
Affected Component

inverted index,HNSW index

Current Behavior
Summary

A hybrid query (scalar range filter + top-k vector search) becomes bottlenecked by bitmap materialization in the pre-filter stage, not by the vector search. bitset_set_list alone consumes ~49% of CPU. Throughput is capped far below expectations.(zvec v0.7.0)

Repro
  • Collection schema (3 columns):
    • mail: string (email)
    • vector: 62-dim float vector (cosine / inner-product metric)
    • dataTime: int32, timestamp in hours
  • Data: 10M rows covering the last 4 days (96 hourly buckets), inserted and optimized.
  • Query: dataTime >= (now - 3 days) (matches ~7.5M rows ≈ 75% selectivity), then top-21 vector search, returning mail.
  • Hardware: 8-core machine.

Measured ~500 QPS (target 1000+).

Perf profile (sudo perf top)
Overhead Symbol
48.70% bitset_set_list
7.52% compute_one_to_many_inner_product (distance)
7.52% dual_heap_search_neighbors<...Hnsw...> (HNSW traversal)
2.48% roaring_bitmap_portable_deserialize_frozen
2.08% BaseDistanceBatchWithScoreUnquantized<CosineMinusInnerProduct, signed char, ...>
2.01% roaring_bitmap_lazy_or_inplace
1.78% db_index_sprig_traverse (host app)

Roaring bitmap work (bitset_set_list + deserialize_frozen + lazy_or_inplace) ≈ 53%; the actual ANN search + distance ≈ 19%.

Root cause
  1. The range filter is routed to the inverted index. invert_to_forward_scan_ratio defaults to 0.9 (src/db/common/config.cc:39). In src/db/sqlengine/planner/optimizer.cc:84 a condition stays inverted when ratio < 0.9. At 75% selectivity, 0.75 < 0.9, so a bitmap is built instead of scanning forward.
  2. get_bitmap_gt / get_bitmap_lt (src/db/index/column/inverted_column/inverted_column_indexer_search.cc:209/321) merge ~72 hourly posting lists via merge_or → roaring_bitmap_or → bitset_set_list (thirdparty/CRoaring/.../roaring.c), producing a bitmap with ~7.5M bits set over the full 10M-id range (~1.25 MB bitset).
  3. bitset_set_list is an O(num-matches) read-modify-write: each word set requires an exclusive cache line (RFO). On a cold ~1.25 MB bitmap this is ~100+ cycles per miss; with millions of matches per query it dominates.
  4. The existing complement-and-flip optimization range_covers_most_values (threshold 0.7, ..._search.cc:955) does not avoid the cost — it still builds a full-range bitmap and then roaring_bitmap_flip_inplace over [0, max_id+1] (flip_bitmap, :977). It also only applies to sealed indexes with a range histogram.
Desired Improvement

target QPS 1000+
Any guidance on the recommended approach for this workload would be appreciated.

Impact

faster queries

主要言語
C++
スター
16.3k
フォーク
1k
平均マージ
2日 10時間
マージ済み PR(30日)
32

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

alibaba/zvec のほかの issue

alibaba/zvec の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。