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

Abierto
#868 13 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@zhourrr ya está trabajando en esto.

Desde el 2/11/2026.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

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

Lenguaje dominante
C++
Estrellas
16.3k
Forks
1k
Merge medio
2 d 10 h
PR fusionados (30 d)
32

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de alibaba/zvec

Todos los issues de alibaba/zvec

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.