SelectionVector

Struct SelectionVector 

Source
pub struct SelectionVector { /* private fields */ }
Expand description

A selection vector tracks qualifying row indices

This is the core data structure for late materialization. Instead of copying row data, we track which row indices qualify and only materialize when needed.

§Memory Layout

Uses u32 indices (4 bytes each) instead of full rows (potentially hundreds of bytes each). For a 1M row table filtered to 10K rows:

  • Old: 1M × sizeof(Row) = potentially gigabytes
  • New: 10K × 4 bytes = 40KB

§Example

// Create from filter bitmap
let selection = SelectionVector::from_bitmap(&[true, false, true, true, false]);
assert_eq!(selection.len(), 3);
assert_eq!(selection.indices(), &[0, 2, 3]);

// Iterate over qualifying indices
for idx in selection.iter() {
    let row = &source_rows[idx as usize];
    // Process row...
}

Implementations§

Source§

impl SelectionVector

Source

pub fn empty() -> Self

Create an empty selection vector

Source

pub fn all(count: usize) -> Self

Create a selection vector that selects all rows in range [0, count)

Source

pub fn from_range(range: Range<usize>) -> Self

Create a selection vector from a range

Source

pub fn from_indices(indices: Vec<u32>) -> Self

Create from pre-computed indices (assumes sorted, unique)

Source

pub fn from_bitmap(bitmap: &[bool]) -> Self

Create from a boolean filter bitmap

This is the most common creation path after evaluating predicates.

§Example
let bitmap = vec![true, false, true, true, false];
let selection = SelectionVector::from_bitmap(&bitmap);
assert_eq!(selection.indices(), &[0, 2, 3]);
Source

pub fn from_bitmap_with_capacity(bitmap: &[bool], capacity_hint: usize) -> Self

Create from a bitmap with pre-allocated capacity hint

Use when you have an estimate of how many rows will match.

Source

pub fn len(&self) -> usize

Number of selected rows

Source

pub fn is_empty(&self) -> bool

Check if no rows are selected

Source

pub fn indices(&self) -> &[u32]

Get the underlying indices slice

Source

pub fn into_indices(self) -> Vec<u32>

Consume and return the indices vector

Source

pub fn get(&self, pos: usize) -> Option<u32>

Get index at position

Source

pub fn iter(&self) -> impl Iterator<Item = u32> + '_

Iterate over selected indices

Source

pub fn intersect(&self, other: &SelectionVector) -> SelectionVector

Intersect with another selection vector (AND operation)

Returns indices that appear in both selections. Useful for combining multiple filter conditions.

Source

pub fn union(&self, other: &SelectionVector) -> SelectionVector

Union with another selection vector (OR operation)

Returns indices that appear in either selection.

Source

pub fn remap(&self, base: &SelectionVector) -> SelectionVector

Remap indices through another selection

If self contains indices [0, 2, 3] and base contains [10, 20, 30, 40, 50], returns [10, 30, 40] (indices 0, 2, 3 from base).

This is used when chaining operations: if we filter a filtered result, we need to map back to original row indices.

Source

pub fn to_bitmap(&self, total_count: usize) -> Vec<bool>

Create a dense bitmap representation

Returns a boolean vector where result[i] = true iff i is in the selection. total_count is the total number of rows in the source.

Source

pub fn filter<T, F>(&self, data: &[T], predicate: F) -> SelectionVector
where F: Fn(&T) -> bool,

Filter this selection based on a predicate applied to a slice of data

This is useful for applying additional filters without materializing rows.

Source

pub fn map<T, F>(&self, f: F) -> Vec<T>
where F: FnMut(u32) -> T,

Apply a function to each selected index, collecting results

Source

pub fn selectivity(&self, total_count: usize) -> f64

Selectivity ratio (selected / total)

Returns a value between 0.0 and 1.0 indicating what fraction of the total rows are selected.

Source

pub fn is_contiguous(&self) -> bool

Compact representation check

Returns true if this selection represents a contiguous range, which allows for more efficient processing.

Source

pub fn as_range(&self) -> Option<Range<usize>>

Get the range if this selection is contiguous

Trait Implementations§

Source§

impl Clone for SelectionVector

Source§

fn clone(&self) -> SelectionVector

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SelectionVector

Source§

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

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

impl Default for SelectionVector

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<Vec<u32>> for SelectionVector

Source§

fn from(indices: Vec<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<usize>> for SelectionVector

Source§

fn from(indices: Vec<usize>) -> Self

Converts to this type from the input type.
Source§

impl<'a> IntoIterator for &'a SelectionVector

Source§

type Item = &'a u32

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, u32>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for SelectionVector

Source§

type Item = u32

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<u32>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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

Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,