Skip to main content

PlannerPlugin

Trait PlannerPlugin 

Source
pub trait PlannerPlugin: Send + Sync {
    // Required method
    fn rewrite(
        &self,
        node: &mut PlanNode,
        ctx: &QueryContext,
    ) -> Result<(), ComputeError>;

    // Provided methods
    fn pins_through_optimizer(&self, expression: &Expression) -> bool { ... }
    fn keeps_variable_when_ground(&self, expression: &Expression) -> bool { ... }
}
Expand description

Plan-rewrite hook over the LOWERED plan tree.

Required Methods§

Source

fn rewrite( &self, node: &mut PlanNode, ctx: &QueryContext, ) -> Result<(), ComputeError>

Walk node in place. ctx carries the running query’s view of the store — MVCC snapshot, engine knobs — so a plugin can gate an index-only rewrite on index freshness (the geo plugin skips its rewrite below the persisted geo-index rebuild epoch). Geo inspects PlanNode::Filter::residual conjuncts and recurses into inner plans and EXISTS clause bodies; repeat executions of the injected childless op are covered by the query-local CustomOp memo. Must not drop rows unless the injected op is a complete implementation of every stripped conjunct.

Provided Methods§

Source

fn pins_through_optimizer(&self, expression: &Expression) -> bool

Whether the algebra optimizer must not duplicate this FILTER conjunct.

true means the conjunct expands into a candidate producer when the plan is rewritten — a childless scan op (text / geo / temporal) joined into the plan — and a producer built more than once is never worth its cost. The algebra optimizer (sparopt) clones a conjunct into both inputs of an inner join that binds its variables, and into every UNION arm; a subject-mode text:query on a seven-arm dimension union therefore becomes one full candidate semi-join per binding site of the subject.

Pinned conjuncts are substituted behind a variable bound nowhere before the optimizer runs, reinstated afterwards, and each placed at the lowest common ancestor of its binding sites (see plan::prepare_algebra and plan::sink_pinned_conjunct).

The test must be purely syntactic: the algebra carries no query context, so a plugin cannot check index trust, configuration gates, or whether the filtered variable is bound to an indexed predicate. A conjunct pinned but not rewritten stays an ordinary filter evaluated at its binding-site ancestor — the same placement the optimizer would pick whenever the variable has a single binding site.

Source

fn keeps_variable_when_ground(&self, expression: &Expression) -> bool

Whether a candidate producer needs its filtered variable to survive the lowering’s ground-value substitution.

The lowering folds a sibling VALUES row or ground BIND into the conjunct before plan rewrites run (so VALUES ?poly { … } FILTER(geof:sfContains(?poly, ?g)) indexes like the inline form). A producer whose rewrite joins its filtered variable back to the store has nothing to join on once that variable is grounded, so it answers per row instead. Geo answers true for its geof:sf* comparisons; text answers true for text:query (both modes), whose rewrite needs the variable. A producer that only compares a value (temporal) can be folded into a constant and leaves the default, as do text’s string functions, which ground to an exact per-row predicate.

The answer is a property of the source expression the plugin claims: the guard asks it before substituting, because a shape-sensitive predicate stops matching the substituted form.

Implementors§