QueryArena

Struct QueryArena 

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

Query-lifetime arena allocator

Provides fast bump-pointer allocation for temporary buffers during query execution. All allocations are freed together when the arena is dropped (end of query).

§Thread Safety

QueryArena is NOT thread-safe (no Sync/Send). Each thread should have its own arena for parallel query execution. Use thread_local! or pass per-thread.

§Examples

// Create arena at query start
let arena = QueryArena::new();

// Allocate filter bitmap (fast O(1) bump allocation)
let bitmap = arena.alloc_bitmap(10000);
for i in 0..10000 {
    bitmap[i] = evaluate_predicate(i);
}

// Allocate temp buffer for expression results
let results = arena.alloc_values(10000);
for i in 0..10000 {
    results[i] = evaluate_expression(i);
}

// Arena automatically freed at end of query (drop)

Implementations§

Source§

impl QueryArena

Source

pub fn new() -> Self

Create a new query arena with default capacity (1 MB)

The arena pre-allocates a large chunk to serve many small allocations without frequent system calls.

Source

pub fn with_capacity(bytes: usize) -> Self

Create a new query arena with specified initial capacity

Use this if you have a good estimate of memory needs:

  • Small queries (< 10K rows): 128 KB
  • Medium queries (10K-100K rows): 1 MB
  • Large queries (> 100K rows): 10 MB

Arena will grow automatically if needed.

Source

pub fn alloc_bitmap(&self, len: usize) -> &mut [bool]

Allocate a boolean bitmap with specified length

Common use: Filter bitmaps marking rows that pass predicates

§Example
let bitmap = arena.alloc_bitmap(1000);
for i in 0..1000 {
    bitmap[i] = row_passes_filter(i);
}
Source

pub fn alloc_bitmap_filled(&self, len: usize, value: bool) -> &mut [bool]

Allocate a bitmap and initialize with a specific value

More efficient than alloc_bitmap + fill for large bitmaps.

§Example
// All rows pass by default, then mark failures
let bitmap = arena.alloc_bitmap_filled(1000, true);
for i in failing_rows {
    bitmap[i] = false;
}
Source

pub fn alloc_slice<T: Default + Copy>(&self, len: usize) -> &mut [T]

Allocate an array of values

Use for temporary expression results, intermediate calculations, etc.

§Example
let temps: &mut [f64] = arena.alloc_slice(1000);
for i in 0..1000 {
    temps[i] = calculate(i);
}
Source

pub fn alloc_slice_filled<T: Copy>(&self, len: usize, value: T) -> &mut [T]

Allocate an array and initialize with a specific value

Source

pub fn alloc<T>(&self, value: T) -> &mut T

Allocate a single value

Use sparingly - arena allocation is optimized for bulk allocations. For single values, normal heap allocation may be comparable.

Source

pub fn alloc_vec<T>(&self) -> Vec<'_, T>

Allocate a Vec-like collection with specified capacity

The returned Vec will allocate from the arena’s chunk, not the heap.

§Example
let mut results = arena.alloc_vec();
for row in rows {
    if predicate(row) {
        results.push(row);
    }
}
Source

pub fn alloc_vec_with_capacity<T>(&self, capacity: usize) -> Vec<'_, T>

Allocate a Vec with specified capacity

Source

pub fn reset(&mut self)

Reset the arena, freeing all allocations at once

This is much faster than freeing individual allocations. Use between queries when reusing the same arena.

§Safety

All references to arena-allocated data become invalid after reset. The borrow checker prevents this at compile time for normal usage.

§Example
let arena = QueryArena::new();

for query in queries {
    let bitmap = arena.alloc_bitmap(1000);
    // ... execute query ...
    arena.reset(); // Free all at once for next query
}
Source

pub fn allocated_bytes(&self) -> usize

Get the number of bytes allocated from the arena

Useful for profiling and capacity tuning.

Trait Implementations§

Source§

impl Default for QueryArena

Source§

fn default() -> Self

Returns the “default value” for a type. 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

Source§

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

Source§

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