Skip to main content

QueryPlanner

Struct QueryPlanner 

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

Query planner that integrates statistics-based optimization

Implementations§

Source§

impl QueryPlanner

Source

pub fn new(engine: Arc<MVCCEngine>) -> Self

Create a new query planner

Source

pub fn invalidate_stats_cache(&self, table_name: &str)

Invalidate cached statistics for a table

Call this after ANALYZE to ensure fresh statistics are used.

Source

pub fn clear_stats_cache(&self)

Clear all cached statistics

Source

pub fn get_table_stats(&self, table_name: &str) -> Option<TableStats>

Get or load statistics for a table

If cached stats are stale (older than TTL), they will be refreshed from the system tables.

Returns None if:

  • No statistics have been collected (ANALYZE not run)
  • Statistics have row_count == 0 (empty/invalid stats)
Source

pub fn get_table_stats_with_fallback(&self, table: &dyn Table) -> TableStats

Get table statistics with fallback to runtime estimation

If ANALYZE hasn’t been run, computes basic statistics from the table. This ensures the optimizer always has some statistics to work with.

Source

pub fn get_column_stats( &self, table_name: &str, column_name: &str, ) -> Option<ColumnStatsCache>

Get column statistics

If cached stats are stale (older than TTL), they will be refreshed.

Source

pub fn get_zone_maps(&self, table: &dyn Table) -> Option<Arc<TableZoneMap>>

Get zone maps for a table (from table, not system tables) Uses Arc to avoid cloning on high QPS workloads

Source

pub fn can_prune_entire_scan( &self, table: &dyn Table, expr: &dyn Expression, ) -> bool

Check if zone maps indicate that no rows can possibly match the expression

Returns true if the entire scan can be skipped (zone maps show no match possible). Returns false if:

  • Zone maps are not available
  • Some segments might match
  • Expression cannot be evaluated against zone maps

This enables early exit optimization for range queries on ordered data.

Source

pub fn stats_health(&self, table_name: &str) -> StatsHealth

Get overall health of statistics for a table

Source

pub fn estimate_scan_rows( &self, table_name: &str, predicate: Option<&Expression>, ) -> Option<u64>

Estimate the number of rows that will be returned by a scan with a predicate

This method uses table statistics and column statistics to estimate selectivity of predicates. It also applies cardinality feedback corrections if available from previous query executions.

§Arguments
  • table_name - Name of the table being scanned
  • predicate - Optional WHERE clause predicate
§Returns

Estimated number of rows, or None if stats are unavailable

Source

pub fn estimate_with_feedback( &self, table_name: &str, predicate: Option<&Expression>, base_estimate: u64, ) -> u64

Estimate row count with cardinality feedback correction

This method combines statistics-based estimation with learned corrections from previous query executions. When similar predicates have been executed before, the correction factor improves accuracy.

§Arguments
  • table_name - Name of the table being scanned
  • predicate - The WHERE clause predicate (for fingerprinting)
  • base_estimate - Initial row count estimate from statistics
§Returns

Corrected row count estimate

Source

pub fn record_feedback( &self, table_name: &str, predicate: &Expression, column_name: Option<String>, estimated_rows: u64, actual_rows: u64, )

Record cardinality feedback after query execution

This method stores the difference between estimated and actual row counts, enabling future queries with similar predicates to benefit from the correction.

§Arguments
  • table_name - Name of the table that was scanned
  • predicate - The WHERE clause predicate (for fingerprinting)
  • column_name - Optional column name for more specific feedback
  • estimated_rows - Row count estimate used during planning
  • actual_rows - Actual row count observed during execution
Source

pub fn get_feedback_correction( &self, table_name: &str, predicate: &Expression, ) -> f64

Get the correction factor for a predicate (for debugging/EXPLAIN)

Returns 1.0 if no feedback is available or if feedback is not yet reliable.

Source§

impl QueryPlanner

Source

pub fn plan_runtime_join( &self, left_rows: usize, right_rows: usize, has_equality_keys: bool, ) -> RuntimeJoinDecision

Make a runtime join algorithm decision based on actual row counts

This is called during execution with the actual materialized row counts, enabling adaptive decisions that account for runtime conditions. Also consults the EdgeAwarePlanner for workload-learned hints.

§Arguments
  • left_rows - Actual row count from left side
  • right_rows - Actual row count from right side
  • has_equality_keys - Whether join has equality conditions (a.x = b.x)
§Returns

Decision on which algorithm to use and whether to swap sides

Source

pub fn plan_runtime_join_with_sort_info( &self, left_rows: usize, right_rows: usize, has_equality_keys: bool, left_sorted: bool, right_sorted: bool, ) -> RuntimeJoinDecision

Make a runtime join algorithm decision with sort information

Extended version that also considers whether inputs are pre-sorted, which enables merge join optimization.

§Arguments
  • left_rows - Actual row count from left side
  • right_rows - Actual row count from right side
  • has_equality_keys - Whether join has equality conditions (a.x = b.x)
  • left_sorted - Whether left input is sorted on join keys
  • right_sorted - Whether right input is sorted on join keys

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> CompactArcDrop for T

Source§

unsafe fn drop_and_dealloc(ptr: *mut u8)

Drop the contained data and deallocate the header+data allocation. 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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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