pub struct QueryPlanCache { /* private fields */ }Implementations§
Source§impl QueryPlanCache
impl QueryPlanCache
Sourcepub fn new(config: PlanCacheConfig) -> Self
pub fn new(config: PlanCacheConfig) -> Self
Create a new query plan cache.
pub fn with_stats_manager(self, stats_manager: Arc<StatsManager>) -> Self
Sourcepub fn set_stats_manager(&self, stats_manager: Arc<StatsManager>)
pub fn set_stats_manager(&self, stats_manager: Arc<StatsManager>)
Set the stats manager after creation
Sourcepub fn get_with_space(
&self,
query: &str,
space_name: Option<String>,
schema_version: Option<u64>,
) -> Option<Arc<CachedPlan>>
pub fn get_with_space( &self, query: &str, space_name: Option<String>, schema_version: Option<u64>, ) -> Option<Arc<CachedPlan>>
Look up a cached plan with space, schema, and parameter type context.
space_name and schema_version are incorporated into the cache key to prevent cross-space plan reuse and stale plans after DDL.
param_type_signature is a hash of parameter types so that the same query with different param types gets a different cache key.
index_version forces replan after index DDL (use the same value
that was passed to put_with_context to ensure key matching).
Sourcepub fn get_with_full_space(
&self,
query: &str,
space_name: Option<String>,
schema_version: Option<u64>,
index_version: Option<u64>,
) -> Option<Arc<CachedPlan>>
pub fn get_with_full_space( &self, query: &str, space_name: Option<String>, schema_version: Option<u64>, index_version: Option<u64>, ) -> Option<Arc<CachedPlan>>
Look up with space, schema version, AND index version.
the index_version dimension ensures that a plan compiled with a certain index state is not reused after index DDL.
Sourcepub fn get_with_full_context(
&self,
query: &str,
space_name: Option<String>,
schema_version: Option<u64>,
param_type_signature: Option<u64>,
index_version: Option<u64>,
) -> Option<Arc<CachedPlan>>
pub fn get_with_full_context( &self, query: &str, space_name: Option<String>, schema_version: Option<u64>, param_type_signature: Option<u64>, index_version: Option<u64>, ) -> Option<Arc<CachedPlan>>
Full-context cache lookup with parameter type signature and index version.
pub fn get_with_context( &self, query: &str, context: PlanCacheContext, ) -> Option<Arc<CachedPlan>>
Sourcepub fn put(
&self,
query: &str,
plan: Arc<PhysicalPlan>,
param_positions: Vec<ParamPosition>,
)
pub fn put( &self, query: &str, plan: Arc<PhysicalPlan>, param_positions: Vec<ParamPosition>, )
Put the plan in the cache.
stores an Arc<PhysicalPlan> instead of [ExecutionPlan].
§Parameters
query: Query textplan: Arena-based physical planparam_positions: Information about the positions of the parameters
Sourcepub fn put_with_tables(
&self,
query: &str,
plan: Arc<PhysicalPlan>,
param_positions: Vec<ParamPosition>,
dependent_tables: Vec<String>,
)
pub fn put_with_tables( &self, query: &str, plan: Arc<PhysicalPlan>, param_positions: Vec<ParamPosition>, dependent_tables: Vec<String>, )
Put the plan in the cache with dependent tables.
Sourcepub fn put_with_context(
&self,
query: &str,
plan: Arc<PhysicalPlan>,
param_positions: Vec<ParamPosition>,
context: PlanCachePutContext,
)
pub fn put_with_context( &self, query: &str, plan: Arc<PhysicalPlan>, param_positions: Vec<ParamPosition>, context: PlanCachePutContext, )
Put the plan with full context (space, schema version, index version, tables).
space_name and schema_version are incorporated into the cache key to prevent cross-space reuse and stale plans after DDL.
param_type_signature is derived from the parameter type
declarations (not values) and is included in the cache key.
index_version is incorporated into the cache key to force replan after index DDL (CREATE/DROP index) even when schema_version is unchanged.
stores Arc<PhysicalPlan> — the immutable arena plan.
Sourcepub fn get_with_partition(
&self,
query: &str,
spec: &PartitionSpec,
) -> Option<Arc<CachedPlan>>
pub fn get_with_partition( &self, query: &str, spec: &PartitionSpec, ) -> Option<Arc<CachedPlan>>
Look up a cached plan keyed by its physical partition layout.
The key incorporates the layout fingerprint (ranges, source, layout version), so a plan cached under one layout is never reused for a different one. This is the lookup used by callers that already know the current layout (e.g. re-planning against a previous execution’s metadata); plain-text lookups deliberately miss partitioned entries.
Sourcepub fn get_with_partition_context(
&self,
query: &str,
spec: &PartitionSpec,
context: PlanCacheContext,
) -> Option<Arc<CachedPlan>>
pub fn get_with_partition_context( &self, query: &str, spec: &PartitionSpec, context: PlanCacheContext, ) -> Option<Arc<CachedPlan>>
Partition-keyed lookup that additionally scopes by the full
compatibility context, matching put_with_partition.
Sourcepub fn put_with_partition(
&self,
query: &str,
spec: &PartitionSpec,
plan: Arc<PhysicalPlan>,
param_positions: Vec<ParamPosition>,
context: PlanCachePutContext,
)
pub fn put_with_partition( &self, query: &str, spec: &PartitionSpec, plan: Arc<PhysicalPlan>, param_positions: Vec<ParamPosition>, context: PlanCachePutContext, )
Store a plan under its physical partition layout key.
Only partitioned plans should use this; the plain-text key is left free so a subsequent lookup that cannot provide the layout does not silently reuse a layout-dependent plan.
Sourcepub fn record_execution(&self, query: &str, execution_time_ms: f64)
pub fn record_execution(&self, query: &str, execution_time_ms: f64)
Record the statistics on the execution of the plan.
§Parameter
query: Query contentexecution_time_ms: Execution time (in milliseconds)
Sourcepub fn record_execution_with_space(
&self,
query: &str,
execution_time_ms: f64,
space_name: Option<String>,
schema_version: Option<u64>,
index_version: Option<u64>,
param_type_signature: Option<u64>,
)
pub fn record_execution_with_space( &self, query: &str, execution_time_ms: f64, space_name: Option<String>, schema_version: Option<u64>, index_version: Option<u64>, param_type_signature: Option<u64>, )
Record execution with space context.
index_version must match the value used during put_with_context to
locate the cached plan; otherwise the keys will differ and the record
will miss.
param_type_signature must match the signature used during
put_with_context (i.e. the hash of the parameter types) or the
record will miss for parameterized queries.
Sourcepub fn invalidate(&self, query: &str) -> bool
pub fn invalidate(&self, query: &str) -> bool
Invalidate the cache entry
Sourcepub fn invalidate_space(&self, space_name: &str) -> usize
pub fn invalidate_space(&self, space_name: &str) -> usize
Invalidate all cache entries for a given space.
called after DDL/index/schema changes to force replanning. Iterates all entries and removes those matching the space name.
Sourcepub fn get_cache_entries(&self) -> Vec<(Arc<PlanCacheKey>, f64, usize)>
pub fn get_cache_entries(&self) -> Vec<(Arc<PlanCacheKey>, f64, usize)>
Get cache entries for eviction (internal use)
Sourcepub fn increment_eviction_count(&self, count: u64)
pub fn increment_eviction_count(&self, count: u64)
Increment eviction count (internal use)
Sourcepub fn stats(&self) -> Arc<PlanCacheStats> ⓘ
pub fn stats(&self) -> Arc<PlanCacheStats> ⓘ
Obtain statistical information
Sourcepub fn record_memo_hit(&self)
pub fn record_memo_hit(&self)
Record a hit without a cache lookup, for the Level 2 same-shape DML
memo that short-circuits before get_with_context. Keeps the hit rate
accounting consistent with the regular lookup path.
Sourcepub fn stats_snapshot(&self) -> PlanCacheStatsSnapshot
pub fn stats_snapshot(&self) -> PlanCacheStatsSnapshot
Get statistics snapshot
Sourcepub fn cleanup_expired(&self)
pub fn cleanup_expired(&self)
Clean up expired entries. Note: moka handles TTL automatically, so this is a no-op
Sourcepub fn config(&self) -> &PlanCacheConfig
pub fn config(&self) -> &PlanCacheConfig
Get the configuration
Trait Implementations§
Source§impl Debug for QueryPlanCache
impl Debug for QueryPlanCache
Auto Trait Implementations§
impl !Freeze for QueryPlanCache
impl !RefUnwindSafe for QueryPlanCache
impl !UnwindSafe for QueryPlanCache
impl Send for QueryPlanCache
impl Sync for QueryPlanCache
impl Unpin for QueryPlanCache
impl UnsafeUnpin for QueryPlanCache
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.