Class UnionNode

  • All Implemented Interfaces:
    Optimizable, Visitable

    class UnionNode
    extends SetOperatorNode
    A UnionNode represents a UNION in a DML statement. It contains a boolean telling whether the union operation should eliminate duplicate rows.
    • Field Detail

      • addNewNodesCalled

        private boolean addNewNodesCalled
      • tableConstructor

        boolean tableConstructor
      • topTableConstructor

        boolean topTableConstructor
    • Constructor Detail

      • UnionNode

        UnionNode​(ResultSetNode leftResult,
                  ResultSetNode rightResult,
                  boolean all,
                  boolean tableConstructor,
                  java.util.Properties tableProperties,
                  ContextManager cm)
           throws StandardException
        Constructor for a UnionNode.
        Parameters:
        leftResult - The ResultSetNode on the left side of this union
        rightResult - The ResultSetNode on the right side of this union
        all - Whether or not this is a UNION ALL.
        tableConstructor - Whether or not this is from a table constructor.
        tableProperties - Properties list associated with the table
        Throws:
        StandardException - Thrown on error
    • Method Detail

      • markTopTableConstructor

        void markTopTableConstructor()
        Mark this as the top node of a table constructor.
      • tableConstructor

        boolean tableConstructor()
        Tell whether this is a UNION for a table constructor.
      • rejectParameters

        void rejectParameters()
                       throws StandardException
        Check for (and reject) ? parameters directly under the ResultColumns. This is done for SELECT statements. Don't reject parameters that are in a table constructor - these are allowed, as long as the table constructor is in an INSERT statement or each column of the table constructor has at least one non-? column. The latter case is checked below, in bindExpressions().
        Overrides:
        rejectParameters in class TableOperatorNode
        Throws:
        StandardException - Thrown if a ? parameter found directly under a ResultColumn
      • setTableConstructorTypes

        void setTableConstructorTypes​(ResultColumnList typeColumns)
                               throws StandardException
        Set the type of column in the result column lists of each source of this union tree to the type in the given result column list (which represents the result columns for an insert). This is only for table constructors that appear in insert statements.
        Overrides:
        setTableConstructorTypes in class ResultSetNode
        Parameters:
        typeColumns - The ResultColumnList containing the desired result types.
        Throws:
        StandardException - Thrown on error
      • enhanceRCLForInsert

        ResultSetNode enhanceRCLForInsert​(InsertNode target,
                                          boolean inOrder,
                                          int[] colMap)
                                   throws StandardException
        Make the RCL of this node match the target node for the insert. If this node represents a table constructor (a VALUES clause), we replace the RCL with an enhanced one if necessary, and recursively enhance the RCL of each child node. For table constructors, we also need to check that we don't attempt to override auto-increment columns in each child node (checking the top-level RCL isn't sufficient since a table constructor may contain the DEFAULT keyword, which makes it possible to specify a column without overriding its value). If this node represents a regular UNION, put a ProjectRestrictNode on top of this node and enhance the RCL in that node.
        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
      • pushExpressions

        void pushExpressions​(PredicateList predicateList)
                      throws StandardException
        DERBY-649: Handle pushing predicates into UnionNodes. It is possible to push single table predicates that are binaryOperations or inListOperations. Predicates of the form or IN are currently handled. Since these predicates would allow optimizer to pick available indices, pushing them provides maximum benifit. It should be possible to expand this logic to cover more cases. Even pushing expressions (like a+b = 10) into SELECTs would improve performance, even if they don't allow use of index. It would mean evaluating expressions closer to data and hence could avoid sorting or other overheads that UNION may require. Note that the predicates are not removed after pushing. This is to ensure if pushing is not possible or only partially feasible.
        Overrides:
        pushExpressions in class FromTable
        Parameters:
        predicateList - List of single table predicates to push
        Throws:
        StandardException - Thrown on error
      • addNewNodes

        private ResultSetNode addNewNodes()
                                   throws StandardException
        Add any new ResultSetNodes that are necessary to the tree. We wait until after optimization to do this in order to make it easier on the optimizer.
        Returns:
        (Potentially new) head of the ResultSetNode tree.
        Throws:
        StandardException - Thrown on error
      • 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 SetOperatorNode
        Returns:
        This object as a String
      • bindExpressions

        public 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 SetOperatorNode
        Parameters:
        fromListParam - FromList to use/append to.
        Throws:
        StandardException - Thrown on error
      • getOperatorName

        java.lang.String getOperatorName()
        Specified by:
        getOperatorName in class SetOperatorNode
        Returns:
        the operator name: "UNION", "INTERSECT", or "EXCEPT"