Class RowResultSetNode

  • All Implemented Interfaces:
    Optimizable, Visitable

    class RowResultSetNode
    extends FromTable
    A RowResultSetNode represents the result set for a VALUES clause.
    • Constructor Detail

      • RowResultSetNode

        RowResultSetNode​(ResultColumnList valuesClause,
                         java.util.Properties tableProperties,
                         ContextManager cm)
        Constructor for a RowResultSetNode.
        Parameters:
        valuesClause - The result column list for the VALUES clause.
        tableProperties - Properties list associated with the table
        cm - The context manager
    • Method Detail

      • statementToString

        java.lang.String statementToString()
      • 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
      • enhanceRCLForInsert

        ResultSetNode enhanceRCLForInsert​(InsertNode target,
                                          boolean inOrder,
                                          int[] colMap)
                                   throws StandardException
        Modify the RCL of this node to match the target of the insert.
        Overrides:
        enhanceRCLForInsert in class ResultSetNode
        Parameters:
        target - the target node for the insert
        inOrder - are source cols in same order as target cols?
        colMap - int array representation of correspondence between RCLs - colmap[i] = -1 -> missing in current RCL colmap[i] = j -> targetRCL(i) <-> thisRCL(j+1)
        Returns:
        a node that replaces this node and whose RCL matches the target RCL. May return this node if no changes to the RCL are needed, or if the RCL is modified in-place.
        Throws:
        StandardException - Thrown on error
      • bindNonVTITables

        ResultSetNode bindNonVTITables​(DataDictionary dataDictionary,
                                       FromList fromListParam)
                                throws StandardException
        Bind the non VTI tables in this ResultSetNode. This includes getting their descriptors from the data dictionary and numbering them.
        Overrides:
        bindNonVTITables in class ResultSetNode
        Parameters:
        dataDictionary - The DataDictionary to use for binding
        fromListParam - FromList to use/append to.
        Returns:
        ResultSetNode
        Throws:
        StandardException - Thrown on error
      • bindExpressions

        void bindExpressions​(FromList fromListParam)
                      throws StandardException
        Bind the expressions in this RowResultSetNode. 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
      • 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
      • bindTargetExpressions

        void bindTargetExpressions​(FromList fromListParam)
                            throws StandardException
        Bind the expressions in the target list. This means binding the sub-expressions, as well as figuring out what the return type is for each expression. This is useful for EXISTS subqueries, where we need to validate the target list before blowing it away and replacing it with a SELECT true.
        Overrides:
        bindTargetExpressions in class ResultSetNode
        Throws:
        StandardException - Thrown on error
      • getMatchingColumn

        ResultColumn getMatchingColumn​(ColumnReference columnReference)
                                throws StandardException
        Try to find a ResultColumn in the table represented by this FromTable that matches the name in the given ColumnReference.
        Overrides:
        getMatchingColumn in class ResultSetNode
        Parameters:
        columnReference - The columnReference whose name we're looking for in the given table.
        Returns:
        A ResultColumn whose expression is the ColumnNode that matches the ColumnReference. Returns null if there is no match.
        Throws:
        StandardException - Thrown on error
      • getExposedName

        java.lang.String getExposedName()
                                 throws StandardException
        Get the exposed name for this table, which is the name that can be used to refer to it in the rest of the query.
        Overrides:
        getExposedName in class FromTable
        Returns:
        The exposed name of this table.
        Throws:
        StandardException - Thrown on error
      • verifySelectStarSubquery

        void verifySelectStarSubquery​(FromList outerFromList,
                                      int subqueryType)
                               throws StandardException
        Verify that a SELECT * is valid for this type of subquery.
        Overrides:
        verifySelectStarSubquery in class ResultSetNode
        Parameters:
        outerFromList - The FromList from the outer query block(s)
        subqueryType - The subquery type
        Throws:
        StandardException - Thrown on error
      • pushOrderByList

        void pushOrderByList​(OrderByList orderByList)
        Push the order by list down from the cursor node into its child result set so that the optimizer has all of the information that it needs to consider sort avoidance.
        Overrides:
        pushOrderByList in class ResultSetNode
        Parameters:
        orderByList - The order by list
      • pushOffsetFetchFirst

        void pushOffsetFetchFirst​(ValueNode offset,
                                  ValueNode fetchFirst,
                                  boolean hasJDBClimitClause)
        Push down the offset and fetch first parameters, if any, to this node.
        Overrides:
        pushOffsetFetchFirst in class ResultSetNode
        Parameters:
        offset - the OFFSET, if any
        fetchFirst - the OFFSET FIRST, if any
        hasJDBClimitClause - true if the clauses were added by (and have the semantics of) a JDBC limit clause
      • 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
      • ensurePredicateList

        ResultSetNode ensurePredicateList​(int numTables)
                                   throws StandardException
        Ensure that the top of the RSN tree has a PredicateList.
        Overrides:
        ensurePredicateList in class ResultSetNode
        Parameters:
        numTables - The number of tables in the query.
        Returns:
        ResultSetNode A RSN tree with a node which has a PredicateList on top.
        Throws:
        StandardException - Thrown on error
      • addNewPredicate

        ResultSetNode addNewPredicate​(Predicate predicate)
                               throws StandardException
        Add a new predicate to the list. This is useful when doing subquery transformations, when we build a new predicate with the left side of the subquery operator and the subquery's result column.
        Overrides:
        addNewPredicate in class ResultSetNode
        Parameters:
        predicate - The predicate to add
        Returns:
        ResultSetNode The new top of the tree.
        Throws:
        StandardException - Thrown on error
      • flattenableInFromSubquery

        boolean flattenableInFromSubquery​(FromList fromList)
        Evaluate whether or not the subquery in a FromSubquery is flattenable. Currently, a FSqry is flattenable if all of the following are true: o Subquery is a SelectNode or a RowResultSetNode (not a UnionNode) o It contains no top level subqueries. (RESOLVE - we can relax this) o It does not contain a group by or having clause o It does not contain aggregates. o There is at least one result set in the from list that is not a RowResultSetNode (the reason is to avoid having an outer SelectNode with an empty FromList.
        Overrides:
        flattenableInFromSubquery in class ResultSetNode
        Parameters:
        fromList - The outer from list
        Returns:
        boolean Whether or not the FromSubquery is flattenable.
      • optimize

        ResultSetNode optimize​(DataDictionary dataDictionary,
                               PredicateList predicateList,
                               double outerRows)
                        throws StandardException
        Optimize this SelectNode. This means choosing the best access path for each table, among other things.
        Overrides:
        optimize in class ResultSetNode
        Parameters:
        dataDictionary - The DataDictionary to use for optimization
        predicateList - The predicate list to optimize against
        outerRows - The number of outer joining rows
        Returns:
        ResultSetNode The top of the optimized tree
        Throws:
        StandardException - Thrown on error
      • returnsAtMostOneRow

        boolean returnsAtMostOneRow()
        Return whether or not this ResultSet tree is guaranteed to return at most 1 row based on heuristics. (A RowResultSetNode and a SELECT with a non-grouped aggregate will return at most 1 row.)
        Overrides:
        returnsAtMostOneRow in class ResultSetNode
        Returns:
        Whether or not this ResultSet tree is guaranteed to return at most 1 row based on heuristics.
      • replaceOrForbidDefaults

        void replaceOrForbidDefaults​(TableDescriptor ttd,
                                     ResultColumnList tcl,
                                     boolean allowDefaults)
                              throws StandardException
        Replace any DEFAULTs with the associated tree for the default if allowed, or flag (when inside top level set operator nodes). Subqueries are checked for illegal DEFAULTs elsewhere.
        Overrides:
        replaceOrForbidDefaults in class ResultSetNode
        Parameters:
        ttd - The TableDescriptor for the target table.
        tcl - The RCL for the target table.
        allowDefaults - true if allowed
        Throws:
        StandardException - Thrown on error
      • optimizeSubqueries

        void optimizeSubqueries​(DataDictionary dd,
                                double rowCount)
                         throws StandardException
        Optimize any subqueries that haven't been optimized any where else. This is useful for a RowResultSetNode as a derived table because it doesn't get optimized otherwise.
        Overrides:
        optimizeSubqueries in class FromTable
        Throws:
        StandardException - Thrown on error
      • 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()