Class FromSubquery

  • All Implemented Interfaces:
    Optimizable, Visitable

    class FromSubquery
    extends FromTable
    A FromSubquery represents a subquery in the FROM list of a DML statement. The current implementation of this class is only sufficient for Insert's need to push a new select on top of the one the user specified, to make the selected structure match that of the insert target table.
    • Field Detail

      • hasJDBClimitClause

        private boolean hasJDBClimitClause
      • origCompilationSchema

        private SchemaDescriptor origCompilationSchema
        DERBY-3270: If this subquery represents an expanded view, this holds the current compilation schema at view definition time.
    • Constructor Detail

      • FromSubquery

        FromSubquery​(ResultSetNode subquery,
                     OrderByList orderByList,
                     ValueNode offset,
                     ValueNode fetchFirst,
                     boolean hasJDBClimitClause,
                     java.lang.String correlationName,
                     ResultColumnList derivedRCL,
                     java.util.Properties tableProperties,
                     ContextManager cm)
        Constructor for a table in a FROM list.
        Parameters:
        subquery - The subquery
        orderByList - ORDER BY list if any, or null
        offset - OFFSET if any, or null
        fetchFirst - FETCH FIRST if any, or null
        hasJDBClimitClause - True if the offset/fetchFirst clauses come from JDBC limit/offset escape syntax
        correlationName - The correlation name
        derivedRCL - The derived column list
        tableProperties - Properties list associated with the table
        cm - The context manager
    • Method Detail

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

        ResultSetNode getSubquery()
        Return the "subquery" from this node.
        Returns:
        ResultSetNode The "subquery" from this node.
      • 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
      • rejectParameters

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

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

        ResultColumn getMatchingColumn​(ColumnReference columnReference)
                                throws StandardException
        Try to find a ResultColumn in the table represented by this FromBaseTable 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
      • 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.
        Overrides:
        preprocess in class ResultSetNode
        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
      • extractSubquery

        ResultSetNode extractSubquery​(int numTables)
                               throws StandardException
        Extract out and return the subquery, with a PRN on top. (See FromSubquery.preprocess() for more details.)
        Parameters:
        numTables - The number of tables in the DML Statement
        Returns:
        ResultSetNode at top of extracted tree.
        Throws:
        StandardException - Thrown on error
      • flatten

        FromList flatten​(ResultColumnList rcl,
                         PredicateList outerPList,
                         SubqueryList sql,
                         GroupByList gbl,
                         ValueNode havingClause)
                  throws StandardException
        Flatten this FSqry into the outer query block. The steps in flattening are: o Mark all ResultColumns as redundant, so that they are "skipped over" at generate(). o Append the wherePredicates to the outer list. o Return the fromList so that the caller will merge the 2 lists RESOLVE - FSqrys with subqueries are currently not flattenable. Some of them can be flattened, however. We need to merge the subquery list when we relax this restriction. NOTE: This method returns NULL when flattening RowResultSetNodes (the node for a VALUES clause). The reason is that no reference is left to the RowResultSetNode after flattening is done - the expressions point directly to the ValueNodes in the RowResultSetNode's ResultColumnList.
        Overrides:
        flatten in class FromTable
        Parameters:
        rcl - The RCL from the outer query
        outerPList - PredicateList to append wherePredicates to.
        sql - The SubqueryList from the outer query
        gbl - The group by list, if any
        havingClause - The HAVING clause, if any
        Returns:
        FromList The fromList from the underlying SelectNode.
        Throws:
        StandardException - Thrown on error
      • getExposedName

        java.lang.String getExposedName()
        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 for this table.
      • getAllResultColumns

        ResultColumnList getAllResultColumns​(TableName allTableName)
                                      throws StandardException
        Expand a "*" into a ResultColumnList with all of the result columns from the subquery.
        Overrides:
        getAllResultColumns in class ResultSetNode
        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
      • 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 this FromTable. This is useful when flattening a subquery.
        Overrides:
        decrementLevel in class FromTable
        Parameters:
        decrement - The amount to decrement by.
      • setOrigCompilationSchema

        void setOrigCompilationSchema​(SchemaDescriptor sd)
        Associate this subquery with the original compilation schema of a view.
        Parameters:
        sd - schema descriptor of the original compilation schema of the view.