Class Planner.QueryTableSetPlanner

  • Enclosing class:
    Planner

    private static class Planner.QueryTableSetPlanner
    extends java.lang.Object
    A table set planner that maintains a list of table dependence lists and progressively constructs a plan tree from the bottom up.
    • Field Detail

      • table_list

        private java.util.ArrayList table_list
        The list of PlanTableSource objects for each source being planned.
      • has_join_occurred

        private boolean has_join_occurred
        If a join has occurred since the planner was constructed or copied then this is set to true.
    • Constructor Detail

      • QueryTableSetPlanner

        public QueryTableSetPlanner()
        Constructor.
    • 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.

      • 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.

      • 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.

      • 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.
      • printDebugInfo

        void printDebugInfo()