pub struct BitmapIndex { /* private fields */ }Expand description
Bitmap Index for low-cardinality columns
Optimized for BOOLEAN, status, and category columns where the number of distinct values is small (< 1000).
§Key features:
- One RoaringBitmap per distinct value
- O(n/64) AND/OR/NOT operations for multi-predicate queries
- Automatic compression (array, bitmap, or RLE per 8KB chunk)
- Thread-safe with RwLock
§Memory efficiency:
For 1M rows with 10 distinct values:
- B-tree: ~80 MB
- Bitmap: ~500KB - 2.5MB (30-160x savings)
§Row ID Support:
Uses RoaringTreemap which supports full i64 row IDs (up to u64::MAX). This is implemented as a BTreeMap of RoaringBitmaps for efficient storage while supporting the full 64-bit range.
Implementations§
Source§impl BitmapIndex
impl BitmapIndex
Sourcepub fn new(
name: String,
table_name: String,
column_names: Vec<String>,
column_ids: Vec<i32>,
data_types: Vec<DataType>,
is_unique: bool,
) -> Self
pub fn new( name: String, table_name: String, column_names: Vec<String>, column_ids: Vec<i32>, data_types: Vec<DataType>, is_unique: bool, ) -> Self
Create a new BitmapIndex
Sourcepub fn cardinality(&self) -> usize
pub fn cardinality(&self) -> usize
Get the current cardinality (number of distinct values)
Sourcepub fn is_high_cardinality(&self) -> bool
pub fn is_high_cardinality(&self) -> bool
Check if cardinality is too high for efficient bitmap operations
Sourcepub fn get_bitmap(&self, value: &Value) -> Option<RoaringTreemap>
pub fn get_bitmap(&self, value: &Value) -> Option<RoaringTreemap>
Get the bitmap for a specific value (for AND/OR operations)
Sourcepub fn and_values(&self, values: &[Value]) -> RoaringTreemap
pub fn and_values(&self, values: &[Value]) -> RoaringTreemap
Perform AND operation on multiple values (for multi-predicate queries) Returns row IDs that match ALL values
Sourcepub fn or_values(&self, values: &[Value]) -> RoaringTreemap
pub fn or_values(&self, values: &[Value]) -> RoaringTreemap
Perform OR operation on multiple values Returns row IDs that match ANY value
Sourcepub fn not_value(&self, value: &Value) -> RoaringTreemap
pub fn not_value(&self, value: &Value) -> RoaringTreemap
Perform NOT operation on a value Returns row IDs that do NOT match the value Note: Requires knowing all row IDs in the table
Trait Implementations§
Source§impl Debug for BitmapIndex
impl Debug for BitmapIndex
Source§impl Index for BitmapIndex
impl Index for BitmapIndex
Source§fn table_name(&self) -> &str
fn table_name(&self) -> &str
Source§fn add(&self, values: &[Value], row_id: i64, _ref_id: i64) -> Result<()>
fn add(&self, values: &[Value], row_id: i64, _ref_id: i64) -> Result<()>
Source§fn add_arc(
&self,
values: &[CompactArc<Value>],
row_id: i64,
_ref_id: i64,
) -> Result<()>
fn add_arc( &self, values: &[CompactArc<Value>], row_id: i64, _ref_id: i64, ) -> Result<()>
Source§fn add_batch(&self, entries: &FxHashMap<i64, Vec<Value>>) -> Result<()>
fn add_batch(&self, entries: &FxHashMap<i64, Vec<Value>>) -> Result<()>
Source§fn remove(&self, values: &[Value], row_id: i64, _ref_id: i64) -> Result<()>
fn remove(&self, values: &[Value], row_id: i64, _ref_id: i64) -> Result<()>
Source§fn remove_arc(
&self,
values: &[CompactArc<Value>],
row_id: i64,
_ref_id: i64,
) -> Result<()>
fn remove_arc( &self, values: &[CompactArc<Value>], row_id: i64, _ref_id: i64, ) -> Result<()>
Source§fn remove_batch(&self, entries: &FxHashMap<i64, Vec<Value>>) -> Result<()>
fn remove_batch(&self, entries: &FxHashMap<i64, Vec<Value>>) -> Result<()>
Source§fn column_ids(&self) -> &[i32]
fn column_ids(&self) -> &[i32]
Source§fn column_names(&self) -> &[String]
fn column_names(&self) -> &[String]
Source§fn data_types(&self) -> &[DataType]
fn data_types(&self) -> &[DataType]
Source§fn index_type(&self) -> IndexType
fn index_type(&self) -> IndexType
Source§fn find(&self, values: &[Value]) -> Result<Vec<IndexEntry>>
fn find(&self, values: &[Value]) -> Result<Vec<IndexEntry>>
Source§fn find_range(
&self,
_min: &[Value],
_max: &[Value],
_min_inclusive: bool,
_max_inclusive: bool,
) -> Result<Vec<IndexEntry>>
fn find_range( &self, _min: &[Value], _max: &[Value], _min_inclusive: bool, _max_inclusive: bool, ) -> Result<Vec<IndexEntry>>
Source§fn find_with_operator(
&self,
op: Operator,
values: &[Value],
) -> Result<Vec<IndexEntry>>
fn find_with_operator( &self, op: Operator, values: &[Value], ) -> Result<Vec<IndexEntry>>
Source§fn get_row_ids_equal(&self, values: &[Value]) -> Vec<i64>
fn get_row_ids_equal(&self, values: &[Value]) -> Vec<i64>
Source§fn get_row_ids_equal_into(&self, values: &[Value], buffer: &mut Vec<i64>)
fn get_row_ids_equal_into(&self, values: &[Value], buffer: &mut Vec<i64>)
Source§fn get_row_ids_in_range(
&self,
_min_value: &[Value],
_max_value: &[Value],
_include_min: bool,
_include_max: bool,
) -> Vec<i64>
fn get_row_ids_in_range( &self, _min_value: &[Value], _max_value: &[Value], _include_min: bool, _include_max: bool, ) -> Vec<i64>
Source§fn get_filtered_row_ids(&self, expr: &dyn Expression) -> Vec<i64>
fn get_filtered_row_ids(&self, expr: &dyn Expression) -> Vec<i64>
Source§fn get_all_values(&self) -> Vec<Value>
fn get_all_values(&self) -> Vec<Value>
Source§fn get_row_ids_in(&self, value_list: &[Value]) -> Vec<i64>
fn get_row_ids_in(&self, value_list: &[Value]) -> Vec<i64>
Source§fn get_min_value(&self) -> Option<Value>
fn get_min_value(&self) -> Option<Value>
Source§fn get_max_value(&self) -> Option<Value>
fn get_max_value(&self) -> Option<Value>
Source§fn get_row_ids_ordered(
&self,
_ascending: bool,
_limit: usize,
_offset: usize,
) -> Option<Vec<i64>>
fn get_row_ids_ordered( &self, _ascending: bool, _limit: usize, _offset: usize, ) -> Option<Vec<i64>>
Auto Trait Implementations§
impl !Freeze for BitmapIndex
impl RefUnwindSafe for BitmapIndex
impl Send for BitmapIndex
impl Sync for BitmapIndex
impl Unpin for BitmapIndex
impl UnwindSafe for BitmapIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more