Skip to main content

PhysicalPlan

Struct PhysicalPlan 

Source
pub struct PhysicalPlan {
    pub sources: Vec<PlannedSource>,
    pub residuals: Vec<Option<BoundExpr>>,
    pub constant_filter: Option<BoundExpr>,
    pub select: BoundSelect,
    pub aggregation: AggregationMode,
    pub needs_sort: bool,
    pub reverse: bool,
    pub grouped_walk: bool,
    pub distinct_walk: bool,
    pub compounds: Vec<(CompoundOp, PhysicalPlan)>,
    pub levers: Levers,
    pub subqueries: bool,
}
Expand description

A physical plan for a read-only statement.

Fields§

§sources: Vec<PlannedSource>

The FROM terms, in the order the nested loops visit them.

§residuals: Vec<Option<BoundExpr>>

The predicates the loops must still evaluate, one per nesting level.

A predicate is attached to the innermost term it reads, so it is tested as soon as it can be rather than after every loop has been entered.

§constant_filter: Option<BoundExpr>

A predicate over no columns at all, tested once before the loops.

§select: BoundSelect

The bound statement the plan came from.

§aggregation: AggregationMode

How the rows are aggregated.

§needs_sort: bool

Whether the results have to pass through a sorter.

§reverse: bool

Whether the outermost term is walked backwards.

A B-tree read from its last entry to its first produces exactly the reverse of what it produces read forwards, so a descending ORDER BY over an ascending structure is a direction rather than a sort. Only ever set when needs_sort is false: a plan that sorts does not care which way its input arrived.

§grouped_walk: bool

Whether the walk already brings the rows of each group together.

Grouping needs adjacency, not order: if every row of a group arrives before the next group starts, the aggregate can be finished and emitted as the key changes and nothing has to be collected first. A walk whose leading keys are exactly the GROUP BY columns delivers that, whichever direction it runs in.

§distinct_walk: bool

Whether the walk already brings duplicate result rows together.

The same property for DISTINCT: adjacent duplicates can be dropped by comparing each row with the one before it, where a set has to remember every row it has seen.

§compounds: Vec<(CompoundOp, PhysicalPlan)>

The later arms of a compound, each with the operator that joined it.

§levers: Levers

Which optimizations were on when this plan was chosen.

Carried on the plan rather than looked up by the executor, because a plan is cached and a lever that changed after it was built must not change what it does - a plan that consulted the connection at execution time would answer one way today and another tomorrow with no recompilation in between. The connection throws its compiled statements away when a lever moves, which is what makes this field the truth.

§subqueries: bool

Whether any expression in this plan holds a subquery used as a value.

Decided here because it is a property of the statement and not of the data, and because the alternative was deciding it per execution: the executor folds uncorrelated subqueries on the way into each run, and it has to ask this question first every time. Walking the expression tree to ask it cost about 0.07 us per execution - measurable against a point.rowid that takes 0.78 - because BoundExpr::children allocates a vector per node. Asked once per compiled statement instead, it costs nothing a statement runs.

Implementations§

Source§

impl PhysicalPlan

Source

pub fn max_source_id(&self) -> usize

Returns the highest statement-wide source id anywhere in the plan.

The compiler sizes its cursor map from this, so a nested block’s cursor has a slot before the block that encloses it is compiled.

Source

pub fn describe(&self) -> Vec<String>

Returns the EXPLAIN QUERY PLAN lines this plan renders as.

Trait Implementations§

Source§

impl Clone for PhysicalPlan

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PhysicalPlan

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for PhysicalPlan

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PhysicalPlan

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.