Skip to main content

PlanCache

Struct PlanCache 

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

LRU cache for compiled physical plans.

The cache stores physical plans keyed by their logical plan fingerprint. When the cache is full, the least recently used entry is evicted.

Implementations§

Source§

impl PlanCache

Source

pub fn new(max_size: usize) -> Self

Creates a new plan cache with the given maximum size.

Source

pub fn default_size() -> Self

Creates a plan cache with default size (64 entries).

Source

pub fn get(&mut self, fingerprint: u64) -> Option<&PhysicalPlan>

Gets a cached plan by fingerprint, or returns None if not cached.

Source

pub fn insert(&mut self, fingerprint: u64, plan: PhysicalPlan)

Inserts a plan into the cache. If the cache is full, evicts the least recently used entry.

Source

pub fn get_or_insert_with<F>( &mut self, fingerprint: u64, compile: F, ) -> &PhysicalPlan
where F: FnOnce() -> PhysicalPlan,

Gets a cached plan or compiles and caches a new one.

Source

pub fn clear(&mut self)

Clears the cache.

Source

pub fn len(&self) -> usize

Returns the number of cached plans.

Source

pub fn is_empty(&self) -> bool

Returns true if the cache is empty.

Source

pub fn hits(&self) -> u64

Returns cache hit count.

Source

pub fn misses(&self) -> u64

Returns cache miss count.

Source

pub fn hit_rate(&self) -> f64

Returns cache hit rate (0.0 to 1.0).

Source

pub fn invalidate_table(&mut self, _table: &str)

Invalidates all cached plans for a specific table. Call this when table schema or data changes significantly.

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, 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.