public interface LogicalPlan extends Plan
#build(PlannerContext, ProjectionBuilder, int, int, OrderBy, Integer, Row, Map)
is used to create the
actual "physical" execution plan.
A Operator is something like Limit, OrderBy, HashAggregate, Join, Union, Collect
select x, y, z from t1 where x = 10 order by x limit 10: Limit 10 | Order By x | Collect [x, y, z]
#build(PlannerContext, ProjectionBuilder, int, int, OrderBy, Integer, Row, Map)
is called
on the "root" and flows down.
Each time each operator may provide "hints" to the children so that they can decide to eagerly apply parts of the
operations
This allows us to create execution plans as follows::
select x, y, z from t1 where order by x limit 10; Merge / limit10 / \ Collect Collect limit 10 limit 10
Modifier and Type | Interface and Description |
---|---|
static interface |
LogicalPlan.Builder |
Modifier and Type | Method and Description |
---|---|
<C,R> R |
accept(LogicalPlanVisitor<C,R> visitor,
C context) |
java.util.List<AbstractTableRelation> |
baseTables() |
ExecutionPlan |
build(PlannerContext plannerContext,
ProjectionBuilder projectionBuilder,
int limit,
int offset,
OrderBy order,
java.lang.Integer pageSizeHint,
Row params,
SubQueryResults subQueryResults)
Uses the current shard allocation information to create a physical execution plan.
|
java.util.Map<LogicalPlan,SelectSymbol> |
dependencies()
SubQueries that this plan depends on to be able to execute it.
|
long |
estimatedRowSize()
Returns an estimation of the size (in bytes) of each row returned by the plan.
|
default void |
execute(DependencyCarrier executor,
PlannerContext plannerContext,
RowConsumer consumer,
Row params,
SubQueryResults subQueryResults) |
java.util.Map<Symbol,Symbol> |
expressionMapping()
A mapping from from symbol to symbol.
|
long |
numExpectedRows() |
java.util.List<Symbol> |
outputs() |
default boolean |
preferShardProjections()
Indicates if the operators which are added on top of this LogicalPlan should operate on a shard level.
|
LogicalPlan |
tryOptimize(LogicalPlan pushDown,
io.crate.planner.operators.SymbolMapper mapper)
Tried to optimize the plan and its dependencies to execute more efficiently.
|
executeBulk
@Nullable LogicalPlan tryOptimize(@Nullable LogicalPlan pushDown, io.crate.planner.operators.SymbolMapper mapper)
*Order* Union | / \ | / \ Union *Order* *Order* / \ | | / \ => | | Collect Order Collect Order | | | | Collect CollectThen combining two Order(s):
Union Union / \ / \ / \ / \ Order *Order* Order *Order* | | | | | | => | | Order *Order* Collect Collect | | Collect
pushDown
- The LogicalPlan which gets "pushed down". null
if currently
no plan gets pushed. If null, recurses to find other push down candidates.mapper
- a function used to map symbols from the previous source to the new source.
For example in a Join:
If the OrderBy that is above of a join is moved beneath the join on one side
the orderBySymbols must be changed to be based on the new outputs (For example, from Field[t2.x] to Reference[x].
To accomplish that, the Join operator can pass on an appropriate SymbolMapper when calling tryOptimize on its sources.ExecutionPlan build(PlannerContext plannerContext, ProjectionBuilder projectionBuilder, int limit, int offset, @Nullable OrderBy order, @Nullable java.lang.Integer pageSizeHint, Row params, SubQueryResults subQueryResults)
limit
, offset
, order
can be passed from one operator to another. Depending on the
operators implementation. Operator may choose to make use of this information, but can also ignore it.java.util.List<Symbol> outputs()
default boolean preferShardProjections()
java.util.Map<Symbol,Symbol> expressionMapping()
select tt.bb from (select t.b + t.b as bb from t) tt expressionMapping tt.bb -> t.b + t.b
java.util.List<AbstractTableRelation> baseTables()
java.util.Map<LogicalPlan,SelectSymbol> dependencies()
execute(DependencyCarrier, PlannerContext, RowConsumer, Row, SubQueryResults)
must receive 1 entry per selectSymbol contained in the dependencies here.
Note that currently MultiPhase
is injected into the operator-tree to declare the dependencies.
It's not necessary for each operator to expose it's own SelectSymbols; propagation is usually sufficient.long numExpectedRows()
long estimatedRowSize()
default void execute(DependencyCarrier executor, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults)
<C,R> R accept(LogicalPlanVisitor<C,R> visitor, C context)