Class TableOperatorNode

  • All Implemented Interfaces:
    Optimizable, Visitable
    Direct Known Subclasses:
    JoinNode, SetOperatorNode

    abstract class TableOperatorNode
    extends FromTable
    A TableOperatorNode represents a relational operator like UNION, INTERSECT, JOIN, etc. that takes two tables as parameters and returns a table. The parameters it takes are represented as ResultSetNodes. Currently, all known table operators are binary operators, so there are no subclasses of this node type called "BinaryTableOperatorNode" and "UnaryTableOperatorNode".
    • Field Detail

      • leftModifyAccessPathsDone

        private boolean leftModifyAccessPathsDone
      • rightModifyAccessPathsDone

        private boolean rightModifyAccessPathsDone
    • Constructor Detail

      • TableOperatorNode

        TableOperatorNode​(ResultSetNode leftResultSet,
                          ResultSetNode rightResultSet,
                          java.util.Properties tableProperties,
                          ContextManager cm)
                   throws StandardException
        Constructor for a TableOperatorNode.
        Parameters:
        leftResultSet - The ResultSetNode on the left side of this node
        rightResultSet - The ResultSetNode on the right side of this node
        tableProperties - Properties list associated with the table
        cm - The context manager
        Throws:
        StandardException - Thrown on error
    • Method Detail

      • updateBestPlanMap

        public void updateBestPlanMap​(short action,
                                      java.lang.Object planKey)
                               throws StandardException
        Description copied from interface: Optimizable
        When remembering "truly the best" access path for an Optimizable, we have to keep track of which OptimizerImpl the "truly the best" access is for. In most queries there will only be one OptimizerImpl in question, but in cases where there are nested subqueries, there will be one OptimizerImpl for every level of nesting, and each OptimizerImpl might have its own idea of what this Optimizable's "truly the best path" access path really is. In addition, there could be Optimizables above this Optimizable that might need to override the best path chosen during optimization. So whenever we save a "truly the best" path, we take note of which Optimizer/Optimizable told us to do so. Then as each level of subquery finishes optimization, the corresponding OptimizerImpl/Optimizable can load its preferred access path into this Optimizable's trulyTheBestAccessPath field and pass it up the tree, until eventually the outer-most OptimizerImpl can choose to either use the best path that it received from below (by calling "rememberAsBest()") or else use the path that it found to be "best" for itself. This method is what allows us to keep track of which OptimizerImpl or Optimizable saved which "best plan", and allows us to load the appropriate plans after each round of optimization.
        Specified by:
        updateBestPlanMap in interface Optimizable
        Overrides:
        updateBestPlanMap in class FromTable
        Parameters:
        action - Indicates whether we're adding, loading, or removing a best plan for the OptimizerImpl/Optimizable.
        planKey - Object to use as the map key when adding/looking up a plan. If it is an instance of OptimizerImpl then it corresponds to an outer query; otherwise it's some Optimizable above this Optimizable that could potentially reject plans chosen by the OptimizerImpl to which this Optimizable belongs.
        Throws:
        StandardException
        See Also:
        Makes a call to add/load/remove the plan mapping for this node, and then makes the necessary call to recurse on this node's left and right child, in order to ensure that we've handled the full plan all the way down this node's subtree.
      • toString

        public java.lang.String toString()
        Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.
        Overrides:
        toString in class FromTable
        Returns:
        This object as a String
      • printSubNodes

        void printSubNodes​(int depth)
        Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.
        Overrides:
        printSubNodes in class ResultSetNode
        Parameters:
        depth - The depth of this node in the tree
      • getLeftResultSet

        ResultSetNode getLeftResultSet()
        Get the leftResultSet from this node.
        Returns:
        ResultSetNode The leftResultSet from this node.
      • getRightResultSet

        ResultSetNode getRightResultSet()
        Get the rightResultSet from this node.
        Returns:
        ResultSetNode The rightResultSet from this node.
      • setLeftmostResultSet

        void setLeftmostResultSet​(ResultSetNode newLeftResultSet)
      • setLevel

        void setLevel​(int level)
        Set the (query block) level (0-based) for this FromTable.
        Overrides:
        setLevel in class FromTable
        Parameters:
        level - The query block level for this FromTable.
      • getExposedName

        java.lang.String getExposedName()
        Return the exposed name for this table, which is the name that can be used to refer to this table in the rest of the query.
        Overrides:
        getExposedName in class FromTable
        Returns:
        The exposed name for this table.
      • setNestedInParens

        void setNestedInParens​(boolean nestedInParens)
        Mark whether or not this node is nested in parens. (Useful to parser since some trees get created left deep and others right deep.) The resulting state of this cal was never used so its field was removed to save runtimespace for this node. Further cleanup can be done including parser changes if this call is really nor required.
        Parameters:
        nestedInParens - Whether or not this node is nested in parens.
      • bindNonVTITables

        ResultSetNode bindNonVTITables​(DataDictionary dataDictionary,
                                       FromList fromListParam)
                                throws StandardException
        Bind the non VTI tables in this TableOperatorNode. This means getting their TableDescriptors from the DataDictionary. We will build an unbound RCL for this node. This RCL must be "bound by hand" after the underlying left and right RCLs are bound.
        Overrides:
        bindNonVTITables in class ResultSetNode
        Parameters:
        dataDictionary - The DataDictionary to use for binding
        fromListParam - FromList to use/append to.
        Returns:
        ResultSetNode Returns this.
        Throws:
        StandardException - Thrown on error
      • bindVTITables

        ResultSetNode bindVTITables​(FromList fromListParam)
                             throws StandardException
        Bind the VTI tables in this TableOperatorNode. This means getting their TableDescriptors from the DataDictionary. We will build an unbound RCL for this node. This RCL must be "bound by hand" after the underlying left and right RCLs are bound.
        Overrides:
        bindVTITables in class ResultSetNode
        Parameters:
        fromListParam - FromList to use/append to.
        Returns:
        ResultSetNode Returns this.
        Throws:
        StandardException - Thrown on error
      • bindExpressions

        void bindExpressions​(FromList fromListParam)
                      throws StandardException
        Bind the expressions under this TableOperatorNode. This means binding the sub-expressions, as well as figuring out what the return type is for each expression.
        Overrides:
        bindExpressions in class ResultSetNode
        Parameters:
        fromListParam - FromList to use/append to.
        Throws:
        StandardException - Thrown on error
      • rejectParameters

        void rejectParameters()
                       throws StandardException
        Check for (and reject) ? parameters directly under the ResultColumns. This is done for SELECT statements. For TableOperatorNodes, we simply pass the check through to the left and right children.
        Overrides:
        rejectParameters in class ResultSetNode
        Throws:
        StandardException - Thrown if a ? parameter found directly under a ResultColumn
      • bindExpressionsWithTables

        void bindExpressionsWithTables​(FromList fromListParam)
                                throws StandardException
        Bind the expressions in this ResultSetNode if it has tables. This means binding the sub-expressions, as well as figuring out what the return type is for each expression.
        Overrides:
        bindExpressionsWithTables in class ResultSetNode
        Parameters:
        fromListParam - FromList to use/append to.
        Throws:
        StandardException - Thrown on error
      • bindResultColumns

        void bindResultColumns​(FromList fromListParam)
                        throws StandardException
        Bind the result columns of this ResultSetNode when there is no base table to bind them to. This is useful for SELECT statements, where the result columns get their types from the expressions that live under them.
        Overrides:
        bindResultColumns in class ResultSetNode
        Parameters:
        fromListParam - FromList to use/append to.
        Throws:
        StandardException - Thrown on error
      • bindResultColumns

        void bindResultColumns​(TableDescriptor targetTableDescriptor,
                               FromVTI targetVTI,
                               ResultColumnList targetColumnList,
                               DMLStatementNode statement,
                               FromList fromListParam)
                        throws StandardException
        Bind the result columns for this ResultSetNode to a base table. This is useful for INSERT and UPDATE statements, where the result columns get their types from the table being updated or inserted into. If a result column list is specified, then the verification that the result column list does not contain any duplicates will be done when binding them by name.
        Overrides:
        bindResultColumns in class ResultSetNode
        Parameters:
        targetTableDescriptor - The TableDescriptor for the table being updated or inserted into
        targetColumnList - For INSERT statements, the user does not have to supply column names (for example, "insert into t values (1,2,3)". When this parameter is null, it means that the user did not supply column names, and so the binding should be done based on order. When it is not null, it means do the binding by name, not position.
        statement - Calling DMLStatementNode (Insert or Update)
        fromListParam - FromList to use/append to.
        Throws:
        StandardException - Thrown on error
      • getFromTableByName

        FromTable getFromTableByName​(java.lang.String name,
                                     java.lang.String schemaName,
                                     boolean exactMatch)
                              throws StandardException
        Determine whether or not the specified name is an exposed name in the current query block.
        Overrides:
        getFromTableByName in class FromTable
        Parameters:
        name - The specified name to search for as an exposed name.
        schemaName - Schema name, if non-null.
        exactMatch - Whether or not we need an exact match on specified schema and table names or match on table id.
        Returns:
        The FromTable, if any, with the exposed name.
        Throws:
        StandardException - Thrown on error
      • preprocess

        ResultSetNode preprocess​(int numTables,
                                 GroupByList gbl,
                                 FromList fromList)
                          throws StandardException
        Put a ProjectRestrictNode on top of each FromTable in the FromList. ColumnReferences must continue to point to the same ResultColumn, so that ResultColumn must percolate up to the new PRN. However, that ResultColumn will point to a new expression, a VirtualColumnNode, which points to the FromTable and the ResultColumn that is the source for the ColumnReference. (The new PRN will have the original of the ResultColumnList and the ResultColumns from that list. The FromTable will get shallow copies of the ResultColumnList and its ResultColumns. ResultColumn.expression will remain at the FromTable, with the PRN getting a new VirtualColumnNode for each ResultColumn.expression.) We then project out the non-referenced columns. If there are no referenced columns, then the PRN's ResultColumnList will consist of a single ResultColumn whose expression is 1.
        Overrides:
        preprocess in class ResultSetNode
        Parameters:
        numTables - Number of tables in the DML Statement
        gbl - The group by list, if any
        fromList - The from list, if any
        Returns:
        The generated ProjectRestrictNode atop the original FromTable.
        Throws:
        StandardException - Thrown on error
      • setReferencedColumns

        void setReferencedColumns()
        Set the referenced columns in the column list if it may not be correct.
      • optimize

        ResultSetNode optimize​(DataDictionary dataDictionary,
                               PredicateList predicateList,
                               double outerRows)
                        throws StandardException
        Optimize a TableOperatorNode.
        Overrides:
        optimize in class ResultSetNode
        Parameters:
        dataDictionary - The DataDictionary to use for optimization
        predicateList - The PredicateList to apply.
        outerRows - The number of outer joining rows
        Returns:
        ResultSetNode The top of the optimized query tree
        Throws:
        StandardException - Thrown on error
      • referencesTarget

        boolean referencesTarget​(java.lang.String name,
                                 boolean baseTable)
                          throws StandardException
        Search to see if a query references the specifed table name.
        Overrides:
        referencesTarget in class ResultSetNode
        Parameters:
        name - Table name (String) to search for.
        baseTable - Whether or not name is for a base table
        Returns:
        true if found, else false
        Throws:
        StandardException - Thrown on error
      • decrementLevel

        void decrementLevel​(int decrement)
        Decrement (query block) level (0-based) for all of the tables in this ResultSet tree. This is useful when flattening a subquery.
        Overrides:
        decrementLevel in class FromTable
        Parameters:
        decrement - The amount to decrement by.
      • adjustForSortElimination

        void adjustForSortElimination()
        Description copied from class: ResultSetNode
        Notify the underlying result set tree that the optimizer has chosen to "eliminate" a sort. Sort elimination can happen as part of preprocessing (see esp. SelectNode.preprocess(...)) or it can happen if the optimizer chooses an access path that inherently returns the rows in the correct order (also known as a "sort avoidance" plan). In either case we drop the sort and rely on the underlying result set tree to return its rows in the correct order. For most types of ResultSetNodes we automatically get the rows in the correct order if the sort was eliminated. One exception to this rule, though, is the case of an IndexRowToBaseRowNode, for which we have to disable bulk fetching on the underlying base table. Otherwise the index scan could return rows out of order if the base table is updated while the scan is "in progress" (i.e. while the result set is open). In order to account for this (and potentially other, similar issues in the future) this method exists to notify the result set node that it is expected to return rows in the correct order. The result set can then take necessary action to satsify this requirement--such as disabling bulk fetch in the case of IndexRowToBaseRowNode. All of that said, any ResultSetNodes for which we could potentially eliminate sorts should override this method accordingly. So we don't ever expect to get here.
        Overrides:
        adjustForSortElimination in class ResultSetNode
        See Also:
        ResultSetNode.adjustForSortElimination()
      • needsSpecialRCLBinding

        boolean needsSpecialRCLBinding()
        apparently something special needs to be done for me....
        Overrides:
        needsSpecialRCLBinding in class FromTable