Class Planner.QueryTableSetPlanner
- java.lang.Object
-
- com.mckoi.database.interpret.Planner.QueryTableSetPlanner
-
- Enclosing class:
- Planner
private static class Planner.QueryTableSetPlanner extends java.lang.ObjectA table set planner that maintains a list of table dependence lists and progressively constructs a plan tree from the bottom up.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classPlanner.QueryTableSetPlanner.ComplexSingleExpressionPlanprivate classPlanner.QueryTableSetPlanner.ConstantExpressionPlanprivate classPlanner.QueryTableSetPlanner.ExhaustiveJoinExpressionPlanprivate classPlanner.QueryTableSetPlanner.ExhaustiveSelectExpressionPlanprivate classPlanner.QueryTableSetPlanner.ExhaustiveSubQueryExpressionPlanprivate classPlanner.QueryTableSetPlanner.SimplePatternExpressionPlanprivate classPlanner.QueryTableSetPlanner.SimpleSelectExpressionPlanprivate classPlanner.QueryTableSetPlanner.SimpleSingleExpressionPlanprivate classPlanner.QueryTableSetPlanner.SimpleSubQueryExpressionPlanprivate static classPlanner.QueryTableSetPlanner.SingleVarPlanConvenience class that stores an expression to evaluate for a table.private classPlanner.QueryTableSetPlanner.StandardJoinExpressionPlanprivate classPlanner.QueryTableSetPlanner.SubLogicExpressionPlan
-
Field Summary
Fields Modifier and Type Field Description private booleanhas_join_occurredIf a join has occurred since the planner was constructed or copied then this is set to true.private java.util.ArrayListtable_listThe list of PlanTableSource objects for each source being planned.
-
Constructor Summary
Constructors Constructor Description QueryTableSetPlanner()Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddPlanTableSource(Planner.PlanTableSource source)Add a PlanTableSource to this planner.private voidaddSingleVarPlanTo(java.util.ArrayList list, Planner.PlanTableSource table, Variable variable, Variable single_var, Expression[] exp_parts, Operator op)Adds a single var plan to the given list.voidaddTableSource(QueryPlanNode plan, FromTableInterface from_def)Adds a new table source to the planner given a Plan that 'creates' the source, and a FromTableInterface that describes the source created by the plan.private intcanPlansBeNaturallyJoined(Planner.PlanTableSource plan1, Planner.PlanTableSource plan2)Returns true if it is possible to naturally join the two plans.static Planner.PlanTableSourceconcatTableSources(Planner.PlanTableSource left, Planner.PlanTableSource right, QueryPlanNode plan)Forms a new PlanTableSource that's the concatination of the given two PlanTableSource objects.private Planner.QueryTableSetPlannercopy()Makes an exact duplicate copy (deep clone) of this planner object.private java.util.ArrayListcreateAndList(java.util.ArrayList list, Expression exp)Given an Expression, this will return a list of expressions that can be safely executed as a set of 'and' operations.(package private) voidevaluateConstants(java.util.ArrayList constant_vars, java.util.ArrayList evaluate_order)Evaluates a list of constant conditional exressions of the form '3 + 2 = 0', 'true = true', etc.(package private) voidevaluateMultiples(java.util.ArrayList multi_vars, java.util.ArrayList evaluate_order)Evaluates a list of expressions containing multiple variable expression.(package private) voidevaluatePatterns(java.util.ArrayList pattern_exprs, java.util.ArrayList evaluate_order)Evaluates a list of expressions that are pattern searches (eg.(package private) voidevaluateSingles(java.util.ArrayList single_vars, java.util.ArrayList evaluate_order)Evaluates a list of single variable conditional expressions of the form a = 3, a > 1 + 2, a - 2 = 1, 3 = a, concat(a, 'a') = '3a', etc.(package private) voidevaluateSubLogic(java.util.ArrayList sublogic_exprs, java.util.ArrayList evaluate_order)Evaluates a list of expressions that are sub-expressions themselves.(package private) voidevaluateSubQueries(java.util.ArrayList expressions, java.util.ArrayList evaluate_order)Evaluates a list of expressions containing sub-queries.Planner.PlanTableSourcefindCommonTableSource(java.util.List var_list)Finds a common PlanTableSource that contains the list of variables given.Planner.PlanTableSourcefindTableSource(Variable ref)Finds and returns the PlanTableSource in the list of tables that contains the given Variable reference.Planner.PlanTableSourcefindTableSourceWithUniqueKey(java.lang.String key)Finds and returns the PlanTableSource in the list of table that contains the given unique key name.private Planner.PlanTableSourcegetSingleTableSource()Returns the single PlanTableSource for this planner.booleanhasJoinOccured()Returns true if a join has occurred ('table_list' has been modified).private intindexOfPlanTableSource(Planner.PlanTableSource source)Returns the index of the given PlanTableSource in the table list.private Planner.PlanTableSourcejoinAllPlansToSingleSource(java.util.List all_plans)Given a list of PlanTableSource objects, this will produce a plan that naturally joins all the tables together into a single plan.private Planner.PlanTableSourcejoinAllPlansWithVariables(java.util.List all_vars)Creates a single PlanTableSource that encapsulates all the given variables in a single table.(package private) QueryPlanNodelogicalEvaluate(Expression exp)Evaluates a search Expression clause.Planner.PlanTableSourcemergeTables(Planner.PlanTableSource left, Planner.PlanTableSource right, QueryPlanNode merge_plan)Joins two tables when a plan is generated for joining the two tables.private Planner.PlanTableSourcenaturalJoinAll()Naturally joins all remaining tables sources to make a final single plan which is returned.private Planner.PlanTableSourcenaturallyJoinPlans(Planner.PlanTableSource plan1, Planner.PlanTableSource plan2)Naturally joins two PlanTableSource objects in this planner.private voidplanAllOuterJoins()Plans all outer joins.(package private) voidplanForExpression(Expression exp)Evaluates the search Expression clause and alters the banches of the plans in this object as necessary.(package private) voidplanForExpressionList(java.util.List and_list)Generates a plan to evaluate the given list of expressions (logically separated with AND).(package private) QueryPlanNodeplanSearchExpression(SearchExpression search_expression)Evalutes the WHERE clause of the table expression.(package private) voidprintDebugInfo()private voidsetCachePoints()Sets a CachePointNode with the given key on all of the plan table sources in 'table_list'.voidsetJoinInfoBetweenSources(int between_index, int join_type, Expression on_expr)Links the last added table source to the previous added table source through this joining information.
-
-
-
Method Detail
-
addPlanTableSource
private void addPlanTableSource(Planner.PlanTableSource source)
Add a PlanTableSource to this planner.
-
hasJoinOccured
public boolean hasJoinOccured()
Returns true if a join has occurred ('table_list' has been modified).
-
addTableSource
public void addTableSource(QueryPlanNode plan, FromTableInterface from_def)
Adds a new table source to the planner given a Plan that 'creates' the source, and a FromTableInterface that describes the source created by the plan.
-
indexOfPlanTableSource
private int indexOfPlanTableSource(Planner.PlanTableSource source)
Returns the index of the given PlanTableSource in the table list.
-
setJoinInfoBetweenSources
public void setJoinInfoBetweenSources(int between_index, int join_type, Expression on_expr)Links the last added table source to the previous added table source through this joining information.'between_index' represents the point in between the table sources that the join should be setup for. For example, to set the join between TableSource 0 and 1, use 0 as the between index. A between index of 3 represents the join between TableSource index 2 and 2.
-
concatTableSources
public static Planner.PlanTableSource concatTableSources(Planner.PlanTableSource left, Planner.PlanTableSource right, QueryPlanNode plan)
Forms a new PlanTableSource that's the concatination of the given two PlanTableSource objects.
-
mergeTables
public Planner.PlanTableSource mergeTables(Planner.PlanTableSource left, Planner.PlanTableSource right, QueryPlanNode merge_plan)
Joins two tables when a plan is generated for joining the two tables.
-
findTableSource
public Planner.PlanTableSource findTableSource(Variable ref)
Finds and returns the PlanTableSource in the list of tables that contains the given Variable reference.
-
findCommonTableSource
public Planner.PlanTableSource findCommonTableSource(java.util.List var_list)
Finds a common PlanTableSource that contains the list of variables given. If the list is 0 or there is no common source then null is returned.
-
findTableSourceWithUniqueKey
public Planner.PlanTableSource findTableSourceWithUniqueKey(java.lang.String key)
Finds and returns the PlanTableSource in the list of table that contains the given unique key name.
-
getSingleTableSource
private Planner.PlanTableSource getSingleTableSource()
Returns the single PlanTableSource for this planner.
-
setCachePoints
private void setCachePoints()
Sets a CachePointNode with the given key on all of the plan table sources in 'table_list'. Note that this does not change the 'update' status of the table sources. If there is currently a CachePointNode on any of the sources then no update is made.
-
joinAllPlansWithVariables
private Planner.PlanTableSource joinAllPlansWithVariables(java.util.List all_vars)
Creates a single PlanTableSource that encapsulates all the given variables in a single table. If this means a table must be joined with another using the natural join conditions then this happens here.The intention of this function is to produce a plan that encapsulates all the variables needed to perform a specific evaluation.
Note, this has the potential to cause 'natural join' situations which are bad performance. It is a good idea to perform joins using other methods before this is used.
Note, this will change the 'table_list' variable in this class if tables are joined.
-
canPlansBeNaturallyJoined
private int canPlansBeNaturallyJoined(Planner.PlanTableSource plan1, Planner.PlanTableSource plan2)
Returns true if it is possible to naturally join the two plans. Two plans can be joined under the following sitations; 1) The left or right plan of the first source points to the second source. 2) Either one has no left plan and the other has no right plan, or one has no right plan and the other has no left plan.
-
joinAllPlansToSingleSource
private Planner.PlanTableSource joinAllPlansToSingleSource(java.util.List all_plans)
Given a list of PlanTableSource objects, this will produce a plan that naturally joins all the tables together into a single plan. The join algorithm used is determined by the information in the FROM clause. An OUTER JOIN, for example, will join depending on the conditions provided in the ON clause. If no explicit join method is provided then a natural join will be planned.Care should be taken with this because this method can produce natural joins which are often optimized out by more appropriate join expressions that can be processed before this is called.
Note, this will change the 'table_list' variable in this class if tables are joined.
Returns null if no plans are provided.
-
naturallyJoinPlans
private Planner.PlanTableSource naturallyJoinPlans(Planner.PlanTableSource plan1, Planner.PlanTableSource plan2)
Naturally joins two PlanTableSource objects in this planner. When this method returns the actual plans will be joined together. This method modifies 'table_list'.
-
planAllOuterJoins
private void planAllOuterJoins()
Plans all outer joins.Note, this will change the 'table_list' variable in this class if tables are joined.
-
naturalJoinAll
private Planner.PlanTableSource naturalJoinAll()
Naturally joins all remaining tables sources to make a final single plan which is returned.Note, this will change the 'table_list' variable in this class if tables are joined.
-
addSingleVarPlanTo
private void addSingleVarPlanTo(java.util.ArrayList list, Planner.PlanTableSource table, Variable variable, Variable single_var, Expression[] exp_parts, Operator op)Adds a single var plan to the given list.
-
evaluateConstants
void evaluateConstants(java.util.ArrayList constant_vars, java.util.ArrayList evaluate_order)Evaluates a list of constant conditional exressions of the form '3 + 2 = 0', 'true = true', etc.
-
evaluateSingles
void evaluateSingles(java.util.ArrayList single_vars, java.util.ArrayList evaluate_order)Evaluates a list of single variable conditional expressions of the form a = 3, a > 1 + 2, a - 2 = 1, 3 = a, concat(a, 'a') = '3a', etc. The rule is there must be only one variable, a conditional operator, and a constant on one side.This method takes the list and modifies the plan as necessary.
-
evaluatePatterns
void evaluatePatterns(java.util.ArrayList pattern_exprs, java.util.ArrayList evaluate_order)Evaluates a list of expressions that are pattern searches (eg. LIKE, NOT LIKE and REGEXP). Note that the LHS or RHS may be complex expressions with variables, but we are guarenteed that there are no sub-expressions in the expression.
-
evaluateSubQueries
void evaluateSubQueries(java.util.ArrayList expressions, java.util.ArrayList evaluate_order)Evaluates a list of expressions containing sub-queries. Non-correlated sub-queries can often be optimized in to fast searches. Correlated queries, or expressions containing multiple sub-queries are put through the ExhaustiveSelect plan.
-
evaluateMultiples
void evaluateMultiples(java.util.ArrayList multi_vars, java.util.ArrayList evaluate_order)Evaluates a list of expressions containing multiple variable expression. For example, 'a = b', 'a > b + c', 'a + 5 * b = 2', etc. If an expression represents a simple join condition then a join plan is made to the query plan tree. If an expression represents a more complex joining condition then an exhaustive search must be used.
-
evaluateSubLogic
void evaluateSubLogic(java.util.ArrayList sublogic_exprs, java.util.ArrayList evaluate_order)Evaluates a list of expressions that are sub-expressions themselves. This is typically called when we have OR queries in the expression.
-
planForExpressionList
void planForExpressionList(java.util.List and_list)
Generates a plan to evaluate the given list of expressions (logically separated with AND).
-
planForExpression
void planForExpression(Expression exp)
Evaluates the search Expression clause and alters the banches of the plans in this object as necessary. Unlike the 'logicalEvaluate' method, this does not result in a single QueryPlanNode. It is the responsibility of the callee to join branches as required.
-
logicalEvaluate
QueryPlanNode logicalEvaluate(Expression exp)
Evaluates a search Expression clause. Note that is some cases this will generate a plan tree that has many identical branches that can be optimized out.
-
createAndList
private java.util.ArrayList createAndList(java.util.ArrayList list, Expression exp)Given an Expression, this will return a list of expressions that can be safely executed as a set of 'and' operations. For example, an expression of 'a=9 and b=c and d=2' would return the list; 'a=9','b=c', 'd=2'.If non 'and' operators are found then the reduction stops.
-
planSearchExpression
QueryPlanNode planSearchExpression(SearchExpression search_expression)
Evalutes the WHERE clause of the table expression.
-
copy
private Planner.QueryTableSetPlanner copy()
Makes an exact duplicate copy (deep clone) of this planner object.
-
printDebugInfo
void printDebugInfo()
-
-