pub struct StorageQueryPlanner { /* private fields */ }Expand description
Production-grade query planner that optimizes storage access patterns.
§Examples
use ipfrs_storage::storage_query_planner::{
StorageQueryPlanner, SqpPlannerConfig, SqpQuery, SqpPredicate, SqpOp, SqpValue,
};
let planner = StorageQueryPlanner::new(SqpPlannerConfig::default());
let mut query = SqpQuery::new(1);
query.predicates.push(SqpPredicate::new("age", SqpOp::Gt, SqpValue::Int(18)));
let plan = planner.plan(&query);
assert!(plan.estimated_rows > 0);Implementations§
Source§impl StorageQueryPlanner
impl StorageQueryPlanner
Sourcepub fn new(config: SqpPlannerConfig) -> Self
pub fn new(config: SqpPlannerConfig) -> Self
Create a new planner with the given configuration.
Sourcepub fn register_index(
&self,
name: impl Into<String>,
cardinality: u64,
selectivity: f64,
) -> SqpIndexId
pub fn register_index( &self, name: impl Into<String>, cardinality: u64, selectivity: f64, ) -> SqpIndexId
Register a new index and return its assigned SqpIndexId.
If an index with the same name already exists its statistics are updated in place and the existing ID is returned.
Sourcepub fn index_stat(&self, id: SqpIndexId) -> Option<SqpIndexStat>
pub fn index_stat(&self, id: SqpIndexId) -> Option<SqpIndexStat>
Look up the stat record for a registered index.
Sourcepub fn plan(&self, query: &SqpQuery) -> SqpQueryPlan
pub fn plan(&self, query: &SqpQuery) -> SqpQueryPlan
Generate an optimised plan for query (no caching).
Sourcepub fn plan_cached(&self, query: &SqpQuery) -> SqpQueryPlan
pub fn plan_cached(&self, query: &SqpQuery) -> SqpQueryPlan
Generate or retrieve a cached plan for query.
Sourcepub fn invalidate_cache(&self)
pub fn invalidate_cache(&self)
Invalidate the entire plan cache.
Sourcepub fn invalidate_for_index(&self, id: SqpIndexId)
pub fn invalidate_for_index(&self, id: SqpIndexId)
Remove all cached plans that reference the given index.
Sourcepub fn estimate_cost(&self, plan: &SqpQueryPlan) -> f64
pub fn estimate_cost(&self, plan: &SqpQueryPlan) -> f64
Re-estimate the cost of an already-built plan.
This applies the configured cost model independently of plan generation, making it useful for comparing alternative plans.
Sourcepub fn explain(&self, plan: &SqpQueryPlan) -> String
pub fn explain(&self, plan: &SqpQueryPlan) -> String
Produce a human-readable description of a plan.
Sourcepub fn planner_stats(&self) -> SqpPlannerStats
pub fn planner_stats(&self) -> SqpPlannerStats
Return aggregate planner statistics.
Sourcepub fn recent_history(&self, n: usize) -> Vec<SqpQueryRecord>
pub fn recent_history(&self, n: usize) -> Vec<SqpQueryRecord>
Return the most recent N planning records from history.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for StorageQueryPlanner
impl !RefUnwindSafe for StorageQueryPlanner
impl Send for StorageQueryPlanner
impl Sync for StorageQueryPlanner
impl Unpin for StorageQueryPlanner
impl UnsafeUnpin for StorageQueryPlanner
impl UnwindSafe for StorageQueryPlanner
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> 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 more