public class CanonicalPlanner extends Object implements Planner
query command
.
A canonical plan always has the same structure:
LIMIT if row limit or offset are used
|
SORTING if 'ORDER BY' is used
|
DUP_REMOVE if 'SELECT DISTINCT' is used
|
PROJECT with the list of columns being SELECTed
|
GROUP if 'GROUP BY' is used
|
SELECT1
| One or more SELECT plan nodes that each have
SELECT2 a single non-join constraint that are then all AND-ed
| together (see separateAndConstraints(Constraint, List)
)
SELECTn
|
SOURCE or JOIN A single SOURCE or JOIN node, depending upon the query
/ \
/ \
SOJ SOJ A SOURCE or JOIN node for the left and right side of the JOIN
There leaves of the tree are always SOURCE nodes, so conceptually data always flows through this plan from the bottom SOURCE nodes, is adjusted/filtered as it trickles up through the plan, and is then ready to be used by the caller as it emerges from the top node of the plan.
This canonical plan, however, is later optimized and rearranged so that it performs faster.
Constructor and Description |
---|
CanonicalPlanner() |
Modifier and Type | Method and Description |
---|---|
protected void |
allColumnsFor(Schemata.Table table,
SelectorName tableName,
List<Column> columns,
List<String> columnTypes,
boolean includeSelectorNameInColumnName) |
protected PlanNode |
attachCriteria(QueryContext context,
PlanNode plan,
Constraint constraint,
List<? extends Column> columns,
Map<String,Subquery> subqueriesByVariableName)
Attach all criteria above the join nodes.
|
protected PlanNode |
attachDuplicateRemoval(QueryContext context,
PlanNode plan)
Attach DUP_REMOVE node at top of tree.
|
protected PlanNode |
attachLimits(QueryContext context,
PlanNode plan,
Limit limit)
Attach a LIMIT node at the top of the plan tree.
|
protected PlanNode |
attachProject(QueryContext context,
PlanNode plan,
List<? extends Column> columns,
Map<SelectorName,Schemata.Table> selectors)
Attach a PROJECT node at the top of the plan tree.
|
protected PlanNode |
attachSorting(QueryContext context,
PlanNode plan,
List<? extends Ordering> orderings)
Attach SORT node at top of tree.
|
protected PlanNode |
attachSubqueries(QueryContext context,
PlanNode plan,
Map<String,Subquery> subqueriesByVariableName)
Attach plan nodes for each subquery, resulting with the first subquery at the top of the plan tree.
|
protected PlanNode |
createCanonicalPlan(QueryContext context,
Query query)
Create a canonical query plan for the given query.
|
protected PlanNode |
createCanonicalPlan(QueryContext context,
SetQuery query)
Create a canonical query plan for the given set query.
|
PlanNode |
createPlan(QueryContext context,
QueryCommand query)
Create a canonical query plan for the given command.
|
protected PlanNode |
createPlanNode(QueryContext context,
Source source,
Map<SelectorName,Schemata.Table> usedSelectors)
Create a JOIN or SOURCE node that contain the source information.
|
protected void |
separateAndConstraints(Constraint constraint,
List<Constraint> andableConstraints)
Walk the supplied constraint to extract a list of the constraints that can be AND-ed together.
|
protected void |
setSubqueryVariableName(PlanNode subqueryPlan,
String varName) |
protected void |
validate(QueryContext context,
QueryCommand query,
Map<SelectorName,Schemata.Table> usedSelectors)
Validate the supplied query.
|
public PlanNode createPlan(QueryContext context, QueryCommand query)
Planner
createPlan
in interface Planner
context
- the context in which the query is being plannedquery
- the query command to be plannedprotected PlanNode createCanonicalPlan(QueryContext context, Query query)
context
- the context in which the query is being plannedquery
- the query to be plannedprotected void validate(QueryContext context, QueryCommand query, Map<SelectorName,Schemata.Table> usedSelectors)
context
- the context in which the query is being plannedquery
- the set query to be plannedusedSelectors
- the map of SelectorName
s (aliases or names) used in the query.protected PlanNode createCanonicalPlan(QueryContext context, SetQuery query)
context
- the context in which the query is being plannedquery
- the set query to be plannedprotected PlanNode createPlanNode(QueryContext context, Source source, Map<SelectorName,Schemata.Table> usedSelectors)
context
- the execution contextsource
- the source to be processed; may not be nullusedSelectors
- the map of SelectorName
s (aliases or names) used in the query.protected PlanNode attachCriteria(QueryContext context, PlanNode plan, Constraint constraint, List<? extends Column> columns, Map<String,Subquery> subqueriesByVariableName)
context
- the context in which the query is being plannedplan
- the existing plan, which joins all source groupsconstraint
- the criteria or constraint from the querycolumns
- the columns in the select (that may have aliases)subqueriesByVariableName
- the subqueries by variable nameprotected void separateAndConstraints(Constraint constraint, List<Constraint> andableConstraints)
andConstraints
list will contain Constraint objects that all must be true.constraint
- the input constraintandableConstraints
- the collection into which all non-AND
constraints should be placedprotected PlanNode attachSorting(QueryContext context, PlanNode plan, List<? extends Ordering> orderings)
context
- the context in which the query is being plannedplan
- the existing planorderings
- list of orderings from the queryprotected PlanNode attachLimits(QueryContext context, PlanNode plan, Limit limit)
context
- the context in which the query is being plannedplan
- the existing planlimit
- the limit definition; may be nullprotected PlanNode attachProject(QueryContext context, PlanNode plan, List<? extends Column> columns, Map<SelectorName,Schemata.Table> selectors)
context
- the context in which the query is being plannedplan
- the existing plancolumns
- the columns being projected; may be nullselectors
- the selectors keyed by their alias or nameprotected void allColumnsFor(Schemata.Table table, SelectorName tableName, List<Column> columns, List<String> columnTypes, boolean includeSelectorNameInColumnName)
protected PlanNode attachDuplicateRemoval(QueryContext context, PlanNode plan)
context
- the context in which the query is being plannedplan
- the existing planprotected PlanNode attachSubqueries(QueryContext context, PlanNode plan, Map<String,Subquery> subqueriesByVariableName)
context
- the context in which the query is being plannedplan
- the existing plansubqueriesByVariableName
- the queries by the variable name used in substitutionCopyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.