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 Details

    • subquery

      ResultSetNode subquery
    • orderByList

      private OrderByList orderByList
    • offset

      private ValueNode offset
    • fetchFirst

      private ValueNode fetchFirst
    • 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 Details

    • FromSubquery

      FromSubquery(ResultSetNode subquery, OrderByList orderByList, ValueNode offset, ValueNode fetchFirst, boolean hasJDBClimitClause, String correlationName, ResultColumnList derivedRCL, 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 Details

    • 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(String name, 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
    • bindNonVTITables

      ResultSetNode bindNonVTITables(DataDictionary dataDictionary, FromList fromListParam) throws StandardException
      Bind this subquery that appears in the FROM list.
      Overrides:
      bindNonVTITables in class ResultSetNode
      Parameters:
      dataDictionary - The DataDictionary to use for binding
      fromListParam - FromList to use/append to.
      Returns:
      ResultSetNode The bound FromSubquery.
      Throws:
      StandardException - Thrown on error
    • bindVTITables

      ResultSetNode bindVTITables(FromList fromListParam) throws StandardException
      Bind this subquery that appears in the FROM list.
      Overrides:
      bindVTITables in class ResultSetNode
      Parameters:
      fromListParam - FromList to use/append to.
      Returns:
      ResultSetNode The bound FromSubquery.
      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

      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(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
    • referencesSessionSchema

      public boolean referencesSessionSchema() throws StandardException
      Return true if the node references SESSION schema tables (temporary or permanent)
      Overrides:
      referencesSessionSchema in class QueryTreeNode
      Returns:
      true if references SESSION schema tables, else false
      Throws:
      StandardException - Thrown on error
    • bindUntypedNullsToResultColumns

      void bindUntypedNullsToResultColumns(ResultColumnList bindingRCL) throws StandardException
      Bind any untyped null nodes to the types in the given ResultColumnList.
      Overrides:
      bindUntypedNullsToResultColumns in class ResultSetNode
      Parameters:
      bindingRCL - The ResultColumnList with the types to bind to.
      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.
    • acceptChildren

      void acceptChildren(Visitor v) throws StandardException
      Description copied from class: ResultSetNode
      Accept the visitor for all visitable children of this node.
      Overrides:
      acceptChildren in class FromTable
      Parameters:
      v - the visitor
      Throws:
      StandardException - on error
      See Also: