Skip to main content

Prepared

Struct Prepared 

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

One or more bound expressions, flattened and resolved against a schema.

Built once per pipeline with Prepared::new and evaluated per chunk with Prepared::evaluate or Prepared::evaluate_one, each of which wants the Scratch that Prepared::scratch hands out.

Implementations§

Source§

impl Prepared

Source

pub fn new(plan: &Plan, exprs: &[ExprRef], schema: &Schema) -> Result<Self>

Prepares exprs against schema.

§Errors

If a column reference names a binding the schema does not have, or if an aggregate appears where an ordinary expression was expected. Both are failures of the plan rather than of the data, which is why they are found here, once, rather than on some chunk in the middle of a scan.

Source

pub fn one(plan: &Plan, expr: ExprRef, schema: &Schema) -> Result<Self>

Prepares one expression, which is the common case and saves the caller a slice.

§Errors

Whatever Prepared::new reports.

Source

pub fn scratch(&self) -> Scratch

Working space sized for this expression.

Source

pub fn len(&self) -> usize

How many expressions this was built from.

Source

pub fn is_empty(&self) -> bool

Whether it was built from no expressions at all.

Source

pub fn evaluate( &self, chunk: &Chunk, scratch: &mut Scratch, out: &mut Vec<Vector>, ) -> Result<()>

Evaluates every expression over chunk, appending one vector each to out.

Appends rather than returns a Vec, so a caller in a loop reuses one buffer.

§Errors

Anything a kernel reports, on the first expression that reports it.

Source

pub fn evaluate_one<'s>( &'s self, chunk: &'s Chunk, scratch: &'s mut Scratch, ) -> Result<&'s Vector>

Evaluates a single expression over chunk, handing back a reference to the answer.

A reference rather than a vector, because the caller of this is a filter, which reads the flags to build a selection and then drops them. Nothing about that wants ownership, and a predicate that is a bare column reference, which WHERE flag is, would otherwise copy the column to hand it over.

§Errors

Anything a kernel reports, and an internal error if this was not built from exactly one expression.

Source

pub fn evaluate_filter( &self, chunk: &Chunk, scratch: &mut Scratch, ) -> Result<Selection>

Evaluates a single expression as a filter, handing back the rows it keeps.

The difference between this and evaluate_one followed by selection is the whole of what a threaded filter is. An AND evaluated as an expression runs every conjunct over every row and then combines the flag vectors, so a predicate of four conjuncts that each pass a fifth of the rows does five times the work of one that stops looking at a row as soon as a conjunct rejects it. TPC-H Q6 is exactly that predicate.

So the conjuncts of a top level AND are run one at a time, each over the rows the ones before it left, and the moment nothing is left the rest of the predicate is not run at all. The order is the order the plan gives, which is the optimizer’s business rather than this one’s until the adaptive reordering of #57 lands.

What is threaded is the conjunct’s own comparison rather than the whole of its subtree. A conjunct of a + b > 5 still adds over the whole chunk, because the scalar kernels take a vector rather than a selection, and it is the comparison and everything downstream of it that reads only the rows still in play. A conjunct that is a bare column, a function or a nested OR produces flags over the chunk and is intersected with refine_flags, which is what keeps one awkward conjunct from putting the others back on the unthreaded path.

§Errors

Anything a kernel reports, and an internal error if this was not built from exactly one expression.

Trait Implementations§

Source§

impl Debug for Prepared

Source§

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

Formats the value using the given formatter. Read more

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> 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, 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.