pub struct ExecutionPlanCache { /* private fields */ }Expand description
Cache for query execution plans.
This cache stores not just SQL strings but also execution hints and performance metrics for each query, enabling adaptive optimization.
§Example
use prax_query::cache::{ExecutionPlanCache, PlanHint};
let cache = ExecutionPlanCache::new(1000);
// Register a plan with an index hint
let plan = cache.register(
"find_user_by_email",
"SELECT * FROM users WHERE email = $1",
PlanHint::IndexScan("idx_users_email".into()),
);
// Get the plan later
if let Some(plan) = cache.get("find_user_by_email") {
println!("Using plan with hint: {:?}", plan.hint);
}Implementations§
Source§impl ExecutionPlanCache
impl ExecutionPlanCache
Sourcepub fn register(
&self,
key: impl Into<Cow<'static, str>>,
sql: impl AsRef<str>,
hint: PlanHint,
) -> Arc<ExecutionPlan>
pub fn register( &self, key: impl Into<Cow<'static, str>>, sql: impl AsRef<str>, hint: PlanHint, ) -> Arc<ExecutionPlan>
Register a new execution plan.
Sourcepub fn register_with_cost(
&self,
key: impl Into<Cow<'static, str>>,
sql: impl AsRef<str>,
hint: PlanHint,
cost: f64,
) -> Arc<ExecutionPlan>
pub fn register_with_cost( &self, key: impl Into<Cow<'static, str>>, sql: impl AsRef<str>, hint: PlanHint, cost: f64, ) -> Arc<ExecutionPlan>
Register a plan with estimated cost.
Sourcepub fn get_by_hash(&self, hash: u64) -> Option<Arc<ExecutionPlan>>
pub fn get_by_hash(&self, hash: u64) -> Option<Arc<ExecutionPlan>>
Get a plan by its hash.
Sourcepub fn get_or_register<F>(
&self,
key: impl Into<Cow<'static, str>>,
sql_fn: F,
hint: PlanHint,
) -> Arc<ExecutionPlan>
pub fn get_or_register<F>( &self, key: impl Into<Cow<'static, str>>, sql_fn: F, hint: PlanHint, ) -> Arc<ExecutionPlan>
Get or create a plan.
Sourcepub fn record_execution(&self, key: &str, duration_us: u64)
pub fn record_execution(&self, key: &str, duration_us: u64)
Record execution timing for a plan.
Sourcepub fn slowest_queries(&self, limit: usize) -> Vec<Arc<ExecutionPlan>>
pub fn slowest_queries(&self, limit: usize) -> Vec<Arc<ExecutionPlan>>
Get plans sorted by average execution time (slowest first).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ExecutionPlanCache
impl !RefUnwindSafe for ExecutionPlanCache
impl Send for ExecutionPlanCache
impl Sync for ExecutionPlanCache
impl Unpin for ExecutionPlanCache
impl UnwindSafe for ExecutionPlanCache
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
Mutably borrows from an owned value. Read more