Class ResultSetNode

  • All Implemented Interfaces:
    Visitable
    Direct Known Subclasses:
    FromTable, MaterializeSubqueryNode, SelectNode

    public abstract class ResultSetNode
    extends QueryTreeNode
    A ResultSetNode represents a result set, that is, a set of rows. It is analogous to a ResultSet in the LanguageModuleExternalInterface. In fact, code generation for a a ResultSetNode will create a "new" call to a constructor for a ResultSet.
    • Field Detail

      • resultSetNumber

        private int resultSetNumber
      • referencedTableMap

        private JBitSet referencedTableMap
      • statementResultSet

        private boolean statementResultSet
      • cursorTargetTable

        private boolean cursorTargetTable
      • insertSource

        private boolean insertSource
      • scratchCostEstimate

        private CostEstimate scratchCostEstimate
      • candidateFinalCostEstimate

        private CostEstimate candidateFinalCostEstimate
    • Method Detail

      • 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 QueryTreeNode
        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 QueryTreeNode
        Parameters:
        depth - The depth of this node in the tree
      • isStatementResultSet

        boolean isStatementResultSet()
        Return true if this is a statement result set
      • isCursorTargetTable

        boolean isCursorTargetTable()
        Return true if this is a cursor target table
      • setCursorTargetTable

        void setCursorTargetTable​(boolean yesOrNo)
        Set whether this is a cursor target table
      • getScratchCostEstimate

        CostEstimate getScratchCostEstimate()
        Get the scratch estimate
      • setScratchCostEstimate

        void setScratchCostEstimate​(CostEstimate ce)
        Set the scratch estimate
      • getResultSetNumber

        public int getResultSetNumber()
        Get the resultSetNumber in this ResultSetNode. Expected to be set during generate(). Must be public in order to satisfy the Optimizable contract.
        Returns:
        int The resultSetNumber.
      • setResultSetNumber

        void setResultSetNumber​(int rsn)
      • getCostEstimate

        CostEstimate getCostEstimate()
        Get the CostEstimate for this ResultSetNode.
        Returns:
        The CostEstimate for this ResultSetNode.
      • setCostEstimate

        void setCostEstimate​(CostEstimate ce)
        Set the CostEstimate for this ResultSetNode
      • getCandidateFinalCostEstimate

        CostEstimate getCandidateFinalCostEstimate()
        Get the final cost estimate which we've set so far
      • setCandidateFinalCostEstimate

        void setCandidateFinalCostEstimate​(CostEstimate ce)
        Set the final cost estimate
      • assignResultSetNumber

        void assignResultSetNumber()
                            throws StandardException
        Assign the next resultSetNumber to the resultSetNumber in this ResultSetNode. Expected to be done during generate().
        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.
        Parameters:
        dataDictionary - The DataDictionary to use for binding
        fromListParam - FromList to use/append to.
        Returns:
        ResultSetNode
        Throws:
        StandardException - Thrown on error
      • bindVTITables

        ResultSetNode bindVTITables​(FromList fromListParam)
                             throws StandardException
        Bind the VTI tables in this ResultSetNode. This includes getting their descriptors from the data dictionary and numbering them.
        Parameters:
        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 ResultSetNode. This means binding the sub-expressions, as well as figuring out what the return type is for each expression.
        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.
        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.
        Throws:
        StandardException - Thrown on error
      • setTableConstructorTypes

        void setTableConstructorTypes​(ResultColumnList typeColumns)
                               throws StandardException
        Set the type of each parameter in the result column list for this table constructor.
        Parameters:
        typeColumns - The ResultColumnList containing the desired result types.
        Throws:
        StandardException - Thrown on error
      • setInsertSource

        void setInsertSource()
        Remember that this node is the source result set for an INSERT.
      • isInsertSource

        boolean isInsertSource()
        Return true if this is the source result set for an INSERT
      • verifySelectStarSubquery

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

        ResultColumnList getAllResultColumns​(TableName allTableName)
                                      throws StandardException
        Expand "*" into a ResultColumnList with all of the columns in the table's result list.
        Parameters:
        allTableName - The qualifier on the "*"
        Returns:
        ResultColumnList The expanded list, or null if allTableName is non-null and doesn't match a table name in this result set
        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.
        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
      • setResultToBooleanTrueNode

        ResultSetNode setResultToBooleanTrueNode​(boolean onlyConvertAlls)
                                          throws StandardException
        Set the result column for the subquery to a boolean true, Useful for transformations such as changing: where exists (select ... from ...) to: where (select true from ...) NOTE: No transformation is performed if the ResultColumn.expression is already the correct boolean constant.
        Parameters:
        onlyConvertAlls - Boolean, whether or not to just convert *'s
        Returns:
        ResultSetNode whose resultColumn was transformed; defaults to "this" here, but can be overridden by subclasses.
        Throws:
        StandardException - Thrown on error
      • getFromList

        FromList getFromList()
                      throws StandardException
        Get the FromList. Create and return an empty FromList. (Subclasses which actuall have FromLists will override this.) This is useful because there is a FromList parameter to bindExpressions() which is used as the common FromList to bind against, allowing us to support correlation columns under unions in subqueries.
        Returns:
        FromList
        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.
        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.
        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
      • bindUntypedNullsToResultColumns

        void bindUntypedNullsToResultColumns​(ResultColumnList rcl)
                                      throws StandardException
        Bind untyped nulls to the types in the given ResultColumnList. This is used for binding the nulls in row constructors and table constructors. In all other cases (as of the time of this writing), we do nothing.
        Parameters:
        rcl - The ResultColumnList with the types to bind nulls to
        Throws:
        StandardException - Thrown on error
      • preprocess

        ResultSetNode preprocess​(int numTables,
                                 GroupByList gbl,
                                 FromList fromList)
                          throws StandardException
        Preprocess a ResultSetNode - this currently means: o Generating a referenced table map for each ResultSetNode. o Putting the WHERE and HAVING clauses in conjunctive normal form (CNF). o Converting the WHERE and HAVING clauses into PredicateLists and classifying them. o Ensuring that a ProjectRestrictNode is generated on top of every FromBaseTable and generated in place of every FromSubquery. o Pushing single table predicates down to the new ProjectRestrictNodes.
        Parameters:
        numTables - The number of tables in the DML Statement
        gbl - The group by list, if any
        fromList - The from list, if any
        Returns:
        ResultSetNode at top of preprocessed tree.
        Throws:
        StandardException - Thrown on error
      • ensurePredicateList

        ResultSetNode ensurePredicateList​(int numTables)
                                   throws StandardException
        Ensure that the top of the RSN tree has a PredicateList.
        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.
        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. (ie, not a RowResultSetNode or 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.
        Parameters:
        fromList - The outer from list
        Returns:
        boolean Whether or not the FromSubquery is flattenable.
      • genProjectRestrictForReordering

        ResultSetNode genProjectRestrictForReordering()
                                               throws StandardException
        Get a parent ProjectRestrictNode above us. This is useful when we need to preserve the user specified column order when reordering the columns in the distinct when we combine an order by with a distinct.
        Returns:
        A parent ProjectRestrictNode to do column reordering
        Throws:
        StandardException - Thrown on error
      • optimize

        ResultSetNode optimize​(DataDictionary dataDictionary,
                               PredicateList predicates,
                               double outerRows)
                        throws StandardException
        Optimize a ResultSetNode. This means choosing the best access path for each table under the ResultSetNode, among other things. The only RSNs that need to implement their own optimize() are a SelectNode and those RSNs that can appear above a SelectNode in the query tree. Currently, a ProjectRestrictNode is the only RSN that can appear above a SelectNode.
        Parameters:
        dataDictionary - The DataDictionary to use for optimization
        predicates - 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
      • modifyAccessPaths

        ResultSetNode modifyAccessPaths()
                                 throws StandardException
        Modify the access paths according to the decisions the optimizer made. This can include adding project/restrict nodes, index-to-base-row nodes, etc.
        Returns:
        The modified query tree
        Throws:
        StandardException - Thrown on error
      • modifyAccessPaths

        ResultSetNode modifyAccessPaths​(PredicateList predList)
                                 throws StandardException
        Modify the access paths according to the decisions the optimizer made. This can include adding project/restrict nodes, index-to-base-row nodes, etc.
        Parameters:
        predList - A list of optimizable predicates that should be pushed to this ResultSetNode, as determined by optimizer.
        Returns:
        The modified query tree
        Throws:
        StandardException - Thrown on error
      • setResultColumns

        void setResultColumns​(ResultColumnList newRCL)
        Set the resultColumns in this ResultSetNode
        Parameters:
        newRCL - The new ResultColumnList for this ResultSetNode
      • getResultColumns

        ResultColumnList getResultColumns()
        Get the resultColumns for this ResultSetNode
        Returns:
        ResultColumnList for this ResultSetNode
      • setReferencedTableMap

        void setReferencedTableMap​(JBitSet newRTM)
        Set the referencedTableMap in this ResultSetNode
        Parameters:
        newRTM - The new referencedTableMap for this ResultSetNode
      • getReferencedTableMap

        public JBitSet getReferencedTableMap()
        Get the referencedTableMap for this ResultSetNode. Must be public in order to satisfy the Optimizable contract.
        Returns:
        JBitSet Referenced table map for this ResultSetNode
      • fillInReferencedTableMap

        void fillInReferencedTableMap​(JBitSet passedMap)
        Fill the referencedTableMap with this ResultSetNode.
        Parameters:
        passedMap - The table map to fill in.
      • rejectParameters

        void rejectParameters()
                       throws StandardException
        Check for (and reject) ? parameters directly under the ResultColumns. This is done for SELECT statements.
        Throws:
        StandardException - Thrown if a ? parameter found directly under a ResultColumn
      • rejectXMLValues

        void rejectXMLValues()
                      throws StandardException
        Check for (and reject) XML values directly under the ResultColumns. This is done for SELECT/VALUES statements. We reject values in this case because JDBC does not define an XML type/binding and thus there's no standard way to pass such a type back to a JDBC application.
        Throws:
        StandardException - Thrown if an XML value found directly under a ResultColumn
      • renameGeneratedResultNames

        void renameGeneratedResultNames()
                                 throws StandardException
        Rename generated result column names as '1', '2' etc... These will be the result column names seen by JDBC clients.
        Throws:
        StandardException
      • markStatementResultSet

        void markStatementResultSet()
        This method is overridden to allow a resultset node to know if it is the one controlling the statement -- i.e., it is the outermost result set node for the statement.
      • enhanceRCLForInsert

        ResultSetNode enhanceRCLForInsert​(InsertNode target,
                                          boolean inOrder,
                                          int[] colMap)
                                   throws StandardException
        This ResultSet is the source for an Insert. The target RCL is in a different order and/or a superset of this RCL. In most cases we will add a ProjectRestrictNode on top of the source with an RCL that matches the target RCL. NOTE - The new or enhanced RCL will be fully bound.
        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
      • getRCLForInsert

        ResultColumnList getRCLForInsert​(InsertNode target,
                                         int[] colMap)
                                  throws StandardException
        Generate an RCL that can replace the original RCL of this node to match the RCL of the target for the insert.
        Parameters:
        target - the target node for the insert
        colMap - int array representation of correspondence between RCLs - colmap[i] = -1 -> missing in current RCL colmap[i] = j -> targetRCL(i) <-> thisRCL(j+1)
        Returns:
        an RCL that matches the target RCL
        Throws:
        StandardException
      • genNewRCForInsert

        private ResultColumn genNewRCForInsert​(TableDescriptor targetTD,
                                               FromVTI targetVTI,
                                               int columnNumber,
                                               DataDictionary dataDictionary)
                                        throws StandardException
        Generate the RC/expression for an unspecified column in an insert. Use the default if one exists.
        Parameters:
        targetTD - Target TableDescriptor if the target is not a VTI, null if a VTI.
        targetVTI - Target description if it is a VTI, null if not a VTI
        columnNumber - The column number
        dataDictionary - The DataDictionary
        Returns:
        The RC/expression for the unspecified column.
        Throws:
        StandardException - Thrown on error
      • generateProjectRestrictForInsert

        private ResultSetNode generateProjectRestrictForInsert​(InsertNode target,
                                                               int[] colMap)
                                                        throws StandardException
        Generate a ProjectRestrictNode to put on top of this node if it's the source for an insert, and the RCL needs reordering and/or addition of columns in order to match the target RCL.
        Parameters:
        target - the target node for the insert
        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 ProjectRestrictNode whos RCL matches the target RCL
        Throws:
        StandardException
      • parseDefault

        public ValueNode parseDefault​(java.lang.String defaultText)
                               throws StandardException
        Parse a default and turn it into a query tree.
        Parameters:
        defaultText - Text of Default.
        Returns:
        The parsed default as a query tree.
        Throws:
        StandardException - Thrown on failure
      • makeResultDescription

        public ResultDescription makeResultDescription()
        Make a ResultDescription for use in a ResultSet. This is useful when generating/executing a NormalizeResultSet, since it can appear anywhere in the tree.
        Returns:
        A ResultDescription for this ResultSetNode.
      • isUpdatableCursor

        boolean isUpdatableCursor​(DataDictionary dd)
                           throws StandardException
        Determine if this result set is updatable or not, for a cursor (i.e., is it a cursor-updatable select). This returns false and we expect selectnode to refine it for further checking.
        Throws:
        StandardException - Thrown on error
      • getCursorTargetTable

        FromTable getCursorTargetTable()
        return the target table of an updatable cursor result set. since this is not updatable, just return null.
      • markAsCursorTargetTable

        boolean markAsCursorTargetTable()
        Mark this ResultSetNode as the target table of an updatable cursor. Most types of ResultSetNode can't be target tables.
        Returns:
        true if the target table supports positioned updates.
      • notCursorTargetTable

        void notCursorTargetTable()
        Mark this ResultSetNode as *not* the target table of an updatable cursor.
      • genProjectRestrict

        ResultSetNode genProjectRestrict()
                                  throws StandardException
        Put a ProjectRestrictNode on top of this ResultSetNode. 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.) This is useful for UNIONs, where we want to generate a DistinctNode above the UnionNode to eliminate the duplicates, because DistinctNodes expect their immediate child to be a PRN.
        Returns:
        The generated ProjectRestrictNode atop the original ResultSetNode.
        Throws:
        StandardException - Thrown on error
      • genProjectRestrict

        ResultSetNode genProjectRestrict​(int numTables)
                                  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.
        Parameters:
        numTables - Number of tables in the DML Statement
        Returns:
        The generated ProjectRestrictNode atop the original FromTable.
        Throws:
        StandardException - Thrown on error
      • generateNormalizationResultSet

        void generateNormalizationResultSet​(ActivationClassBuilder acb,
                                            MethodBuilder mb,
                                            int resultSetNumber,
                                            ResultDescription resultDescription)
                                     throws StandardException
        Generate the code for a NormalizeResultSet. The call must push two items before calling this method
        1. pushGetResultSetFactoryExpression
        2. the expression to normalize
        Parameters:
        acb - The ActivationClassBuilder
        mb - The method to put the generated code in
        resultSetNumber - The result set number for the NRS
        resultDescription - The ERD for the ResultSet
        Throws:
        StandardException - Thrown on error
      • changeAccessPath

        ResultSetNode changeAccessPath()
                                throws StandardException
        The optimizer's decision on the access path for a result set may require the generation of extra result sets. For example, if it chooses an index for a FromBaseTable, we need an IndexToBaseRowNode above the FromBaseTable (and the FromBaseTable has to change its column list to match the index. This method in the parent class does not generate any extra result sets. It may be overridden in child classes.
        Returns:
        A ResultSetNode tree modified to do any extra processing for the chosen access path
        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.
        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
      • subqueryReferencesTarget

        boolean subqueryReferencesTarget​(java.lang.String name,
                                         boolean baseTable)
                                  throws StandardException
        Return whether or not this ResultSetNode contains a subquery with a reference to the specified target.
        Parameters:
        name - The table name.
        Returns:
        boolean Whether or not a reference to the table was found.
        Throws:
        StandardException - Thrown on error
      • isOneRowResultSet

        boolean isOneRowResultSet()
                           throws StandardException
        Return whether or not the underlying ResultSet tree will return a single row, at most. This is important for join nodes where we can save the extra next on the right side if we know that it will return at most 1 row.
        Returns:
        Whether or not the underlying ResultSet tree will return a single row.
        Throws:
        StandardException - Thrown on error
      • isNotExists

        boolean isNotExists()
        Return whether or not the underlying ResultSet tree is for a NOT EXISTS join.
        Returns:
        Whether or not the underlying ResultSet tree if for NOT EXISTS.
      • getOptimizerImpl

        protected OptimizerImpl getOptimizerImpl()
        Get the optimizer for this result set.
        Returns:
        If this.optimizer has has already been created by the getOptimizer() method above, then return it; otherwise, return null.
      • getOptimizer

        Optimizer getOptimizer()
        Get the optimizer being used on this result set
      • setOptimizer

        void setOptimizer​(Optimizer opt)
        Set the optimizer for use on this result set
      • considerMaterialization

        ResultSetNode considerMaterialization​(JBitSet outerTables)
                                       throws StandardException
        Consider materialization for this ResultSet tree if it is valid and cost effective (It is not valid if incorrect results would be returned.)
        Returns:
        Top of the new/same ResultSet tree.
        Throws:
        StandardException - Thrown on error
      • performMaterialization

        boolean performMaterialization​(JBitSet outerTables)
                                throws StandardException
        Return whether or not to materialize this ResultSet tree.
        Returns:
        Whether or not to materialize this ResultSet tree. would return valid results.
        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.
        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
      • decrementLevel

        abstract 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.
        Parameters:
        decrement - The amount to decrement by.
      • 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. Presumes a new level has been initialized by pushQueryExpressionSuffix().
        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. This method should be overridden by the result sets that need this. Presumes a new level has been initialized by pushQueryExpressionSuffix().
        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
      • generateResultSet

        void generateResultSet​(ExpressionClassBuilder acb,
                               MethodBuilder mb)
                        throws StandardException
        General logic shared by Core compilation and by the Replication Filter compiler. A couple ResultSets (the ones used by PREPARE SELECT FILTER) implement this method.
        Parameters:
        acb - The ExpressionClassBuilder for the class being built
        mb - The method the expression will go into
        Throws:
        StandardException - Thrown on error
      • updateTargetLockMode

        int updateTargetLockMode()
        Get the lock mode for the target of an update statement (a delete or update). The update mode will always be row for CurrentOfNodes. It will be table if there is no where clause.
        Returns:
        The lock mode
        See Also:
        TransactionController
      • notFlattenableJoin

        void notFlattenableJoin()
        Mark this node and its children as not being a flattenable join.
      • isOrderedOn

        boolean isOrderedOn​(ColumnReference[] crs,
                            boolean permuteOrdering,
                            java.util.List<FromBaseTable> fbtHolder)
                     throws StandardException
        Return whether or not the underlying ResultSet tree is ordered on the specified columns. RESOLVE - This method currently only considers the outermost table of the query block.
        Parameters:
        crs - The specified ColumnReference[]
        permuteOrdering - Whether or not the order of the CRs in the array can be permuted
        fbtHolder - List that is to be filled with the FromBaseTable
        Returns:
        Whether the underlying ResultSet tree is ordered on the specified column.
        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.)
        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.
        Parameters:
        ttd - The TableDescriptor for the target table.
        tcl - The RCL for the target table.
        allowDefaults - true if allowed
        Throws:
        StandardException - Thrown on error
      • isPossibleDistinctScan

        boolean isPossibleDistinctScan​(java.util.Set<BaseColumnNode> distinctColumns)
        Is it possible to do a distinct scan on this ResultSet tree. (See SelectNode for the criteria.)
        Parameters:
        distinctColumns - the set of distinct columns
        Returns:
        Whether or not it is possible to do a distinct scan on this ResultSet tree.
      • markForDistinctScan

        void markForDistinctScan()
        Mark the underlying scan as a distinct scan.
      • adjustForSortElimination

        void adjustForSortElimination()
        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.
      • adjustForSortElimination

        void adjustForSortElimination​(RequiredRowOrdering rowOrdering)
                               throws StandardException
        Same goal as adjustForSortElimination above, but this version takes a RequiredRowOrdering to allow nodes to adjust based on the ORDER BY clause, if needed.
        Throws:
        StandardException
      • numDistinctAggregates

        static int numDistinctAggregates​(java.util.List<AggregateNode> aggregates)
        Count the number of distinct aggregates in the list. By 'distinct' we mean aggregates of the form: SELECT MAX(DISTINCT x) FROM T
        Returns:
        number of aggregates
      • pushQueryExpressionSuffix

        void pushQueryExpressionSuffix()
        Set up a new level for order by and fetch/offset clauses. See Javadoc for ResultSetNode.QueryExpressionClauses. Overridden by implementors of pushOrderByNode, pushOffsetFetchFirst.