Class CardinalityBasedJoinOrderingBase
java.lang.Object
se.liu.ida.hefquin.engine.queryproc.impl.loptimizer.heuristics.CardinalityBasedJoinOrderingBase
- All Implemented Interfaces:
HeuristicForLogicalOptimization
- Direct Known Subclasses:
CardinalityBasedJoinOrderingWithRequests
public abstract class CardinalityBasedJoinOrderingBase
extends Object
implements HeuristicForLogicalOptimization
Base class for heuristics that use cardinality estimates to decide on
a join order for the subplans of a multiway join or a binary join. The
heuristic is applied recursively to all joins within the given plan.
The actual join ordering algorithm implemented in this class is a greedy
one. It first determines cardinality estimates for all the subplans of
the corresponding join. Given these estimates, the algorithm picks the
subplan with the lowest cardinality estimate to become the first plan
in the join order. Thereafter, the algorithm performs an iteration where
each step picks the next subplan for the join. This decision is based on
estimated join cardinalities. However, as candidates to be picked as the
next subplan, the algorithm considers only the subplans that have a join
variable with the subplans that have already been selected so far, which
is done to avoid cross products (unless a cross product is unavoidable).
The actual cardinality estimation approach, both for the cardinalities
of the subplans and for the join cardinalities, may be different for each
subclass.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionprotected LogicalPlan_apply(LogicalPlan inputPlan) apply(LogicalPlan inputPlan) Applies this heuristics to the given plan and returns the resulting, potentially rewritten plan.protected static booleancontainsJoinOp(LogicalPlan logicalPlan) Recursively checks whether the given logical plan contains any join operators (LogicalOpJoin or LogicalOpMultiwayJoin).protected intCompares the given plans in terms of their estimated cardinalities and, for the plan that has the smallest estimated cardinality, returns the index of this plan within the given list.protected Pair<LogicalPlan, Integer> determineNextPlan(List<LogicalPlan> selectedPlans, int joinCardOfSelectedPlans, List<LogicalPlan> nextCandidates) Returns the plan from the given list of next candidates that has the lowest join cardinality with a plan consisting of the given selected plans, and that join cardinality will be returned as well.protected abstract intestimateJoinCardinality(List<LogicalPlan> selectedPlans, int joinCardOfSelectedPlans, LogicalPlan nextCandidate) Implementations of this function estimate the cardinality of the join between the result of joining the given selected plans and the result of the given next candidate.protected booleanreorder(LogicalPlan[] plans) Changes the order of the subplans in the given array by using the greedy algorithm described above for this class.
-
Field Details
-
cardEst
-
-
Constructor Details
-
CardinalityBasedJoinOrderingBase
-
CardinalityBasedJoinOrderingBase
-
-
Method Details
-
apply
Description copied from interface:HeuristicForLogicalOptimizationApplies this heuristics to the given plan and returns the resulting, potentially rewritten plan.- Specified by:
applyin interfaceHeuristicForLogicalOptimization- Throws:
LogicalOptimizationException
-
_apply
- Throws:
LogicalOptimizationException
-
reorder
Changes the order of the subplans in the given array by using the greedy algorithm described above for this class.- Parameters:
plans- - the list of plans that should be reordered- Returns:
trueif the order of the plans in the given list has indeed been changed- Throws:
LogicalOptimizationException
-
determineIdxOfSmallestCardinality
Compares the given plans in terms of their estimated cardinalities and, for the plan that has the smallest estimated cardinality, returns the index of this plan within the given list. -
determineNextPlan
protected Pair<LogicalPlan,Integer> determineNextPlan(List<LogicalPlan> selectedPlans, int joinCardOfSelectedPlans, List<LogicalPlan> nextCandidates) Returns the plan from the given list of next candidates that has the lowest join cardinality with a plan consisting of the given selected plans, and that join cardinality will be returned as well. The implementation of this function assumes that the given list of next candidates is nonempty. -
estimateJoinCardinality
protected abstract int estimateJoinCardinality(List<LogicalPlan> selectedPlans, int joinCardOfSelectedPlans, LogicalPlan nextCandidate) Implementations of this function estimate the cardinality of the join between the result of joining the given selected plans and the result of the given next candidate. Implementations that require the individual cardinality estimates for each of the plans can get these estimates by accessingQueryPlan.getQueryPlanningInfo(). The estimated join cardinality of joining the given selected plans is also passed to this function, in case it is needed by some implementation. -
containsJoinOp
Recursively checks whether the given logical plan contains any join operators (LogicalOpJoin or LogicalOpMultiwayJoin).This method inspects the root operator of the given plan and, if it is neither a
LogicalOpJoinnor aLogicalOpMultiwayJoin, it traverses all subplans to perform the same check.- Parameters:
logicalPlan- the logical plan to inspect- Returns:
trueif the plan contains at least oneLogicalOpJoinorLogicalOpMultiwayJoinoperator,falseotherwise
-