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
impl Prepared
Sourcepub fn new(plan: &Plan, exprs: &[ExprRef], schema: &Schema) -> Result<Self>
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.
Sourcepub fn one(plan: &Plan, expr: ExprRef, schema: &Schema) -> Result<Self>
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.
Sourcepub fn evaluate(
&self,
chunk: &Chunk,
scratch: &mut Scratch,
out: &mut Vec<Vector>,
) -> Result<()>
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.
Sourcepub fn evaluate_one<'s>(
&'s self,
chunk: &'s Chunk,
scratch: &'s mut Scratch,
) -> Result<&'s Vector>
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.
Sourcepub fn evaluate_filter(
&self,
chunk: &Chunk,
scratch: &mut Scratch,
) -> Result<Selection>
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.