BitmapIndex

Struct BitmapIndex 

Source
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

Source

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

Source

pub fn cardinality(&self) -> usize

Get the current cardinality (number of distinct values)

Source

pub fn is_high_cardinality(&self) -> bool

Check if cardinality is too high for efficient bitmap operations

Source

pub fn get_bitmap(&self, value: &Value) -> Option<RoaringTreemap>

Get the bitmap for a specific value (for AND/OR operations)

Source

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

Source

pub fn or_values(&self, values: &[Value]) -> RoaringTreemap

Perform OR operation on multiple values Returns row IDs that match ANY value

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Index for BitmapIndex

Source§

fn name(&self) -> &str

Returns the name of the index
Source§

fn table_name(&self) -> &str

Returns the name of the table this index belongs to
Source§

fn build(&mut self) -> Result<()>

Builds the index from existing data
Source§

fn add(&self, values: &[Value], row_id: i64, _ref_id: i64) -> Result<()>

Adds values to the index with the given row IDs Read more
Source§

fn add_arc( &self, values: &[CompactArc<Value>], row_id: i64, _ref_id: i64, ) -> Result<()>

Adds CompactArc references to the index - shares ownership without cloning Read more
Source§

fn add_batch(&self, entries: &FxHashMap<i64, Vec<Value>>) -> Result<()>

Adds multiple entries to the index in a single batch operation Read more
Source§

fn remove(&self, values: &[Value], row_id: i64, _ref_id: i64) -> Result<()>

Removes values from the index Read more
Source§

fn remove_arc( &self, values: &[CompactArc<Value>], row_id: i64, _ref_id: i64, ) -> Result<()>

Removes CompactArc references from the index - avoids cloning when you have Arc refs Read more
Source§

fn remove_batch(&self, entries: &FxHashMap<i64, Vec<Value>>) -> Result<()>

Removes multiple entries from the index in a single batch operation Read more
Source§

fn column_ids(&self) -> &[i32]

Returns the column IDs for this index
Source§

fn column_names(&self) -> &[String]

Returns the column names for this index
Source§

fn data_types(&self) -> &[DataType]

Returns the data types for the indexed columns
Source§

fn index_type(&self) -> IndexType

Returns the type of index (BTree, Bitmap, Hash)
Source§

fn is_unique(&self) -> bool

Returns true if this is a unique index
Source§

fn find(&self, values: &[Value]) -> Result<Vec<IndexEntry>>

Finds all entries where the columns equal the given values Read more
Source§

fn find_range( &self, _min: &[Value], _max: &[Value], _min_inclusive: bool, _max_inclusive: bool, ) -> Result<Vec<IndexEntry>>

Finds all entries where the columns are in the given range Read more
Source§

fn find_with_operator( &self, op: Operator, values: &[Value], ) -> Result<Vec<IndexEntry>>

Finds all entries matching the given operator and values Read more
Source§

fn get_row_ids_equal(&self, values: &[Value]) -> Vec<i64>

Returns row IDs with the given values (convenience method) Read more
Source§

fn get_row_ids_equal_into(&self, values: &[Value], buffer: &mut Vec<i64>)

Appends row IDs with the given values to the provided buffer Read more
Source§

fn get_row_ids_in_range( &self, _min_value: &[Value], _max_value: &[Value], _include_min: bool, _include_max: bool, ) -> Vec<i64>

Returns row IDs with values in the given range (convenience method) Read more
Source§

fn get_filtered_row_ids(&self, expr: &dyn Expression) -> Vec<i64>

Returns row IDs that match the given expression Read more
Source§

fn get_all_values(&self) -> Vec<Value>

Returns all unique values in the index (for ORDER BY optimization) Read more
Source§

fn close(&mut self) -> Result<()>

Closes the index and releases any resources
Source§

fn get_row_ids_in(&self, value_list: &[Value]) -> Vec<i64>

Returns row IDs for values in the given list (IN clause optimization) Read more
Source§

fn get_min_value(&self) -> Option<Value>

Returns the minimum value in the index (for MIN aggregate optimization) Read more
Source§

fn get_max_value(&self) -> Option<Value>

Returns the maximum value in the index (for MAX aggregate optimization) Read more
Source§

fn get_row_ids_ordered( &self, _ascending: bool, _limit: usize, _offset: usize, ) -> Option<Vec<i64>>

Returns row IDs in sorted order by index value (for ORDER BY optimization) Read more
Source§

fn get_grouped_row_ids(&self) -> Option<Vec<(Value, Vec<i64>)>>

Returns grouped row IDs in sorted order by index value (for GROUP BY optimization) Read more
Source§

fn for_each_group( &self, _callback: &mut dyn FnMut(&Value, &[i64]) -> Result<bool>, ) -> Option<Result<()>>

Iterates through groups in sorted order, calling the callback for each group. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V