org.apache.derby.impl.sql.compile
Class UnionNode

java.lang.Object
  extended byorg.apache.derby.impl.sql.compile.QueryTreeNode
      extended byorg.apache.derby.impl.sql.compile.ResultSetNode
          extended byorg.apache.derby.impl.sql.compile.FromTable
              extended byorg.apache.derby.impl.sql.compile.TableOperatorNode
                  extended byorg.apache.derby.impl.sql.compile.SetOperatorNode
                      extended byorg.apache.derby.impl.sql.compile.UnionNode
All Implemented Interfaces:
Optimizable, Visitable

public 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.

Author:
Jeff Lichtman

Field Summary
private  boolean addNewNodesCalled
           
(package private)  boolean tableConstructor
           
(package private)  boolean topTableConstructor
           
 
Fields inherited from class org.apache.derby.impl.sql.compile.SetOperatorNode
all, orderByList
 
Fields inherited from class org.apache.derby.impl.sql.compile.TableOperatorNode
leftOptimizer, leftResultSet, nestedInParens, rightOptimizer, rightResultSet
 
Fields inherited from class org.apache.derby.impl.sql.compile.FromTable
bestAccessPath, bestCostEstimate, bestSortAvoidancePath, correlationName, corrTableName, currentAccessPath, hashKeyColumns, initialCapacity, level, loadFactor, maxCapacity, tableNumber, tableProperties, trulyTheBestAccessPath, userSpecifiedJoinStrategy
 
Fields inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
costEstimate, cursorTargetTable, insertSource, optimizer, referencedTableMap, resultColumns, resultSetNumber, scratchCostEstimate, statementResultSet
 
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, beginOffset, endOffset
 
Constructor Summary
UnionNode()
           
 
Method Summary
private  ResultSetNode addNewNodes()
          Add any new ResultSetNodes that are necessary to the tree.
 void bindExpressions(FromList fromListParam)
          Bind the expressions under this TableOperatorNode.
 void generate(ActivationClassBuilder acb, MethodBuilder mb)
          Generate the code for this UnionNode.
(package private)  java.lang.String getOperatorName()
           
 void init(java.lang.Object leftResult, java.lang.Object rightResult, java.lang.Object all, java.lang.Object tableConstructor, java.lang.Object tableProperties)
          Initializer for a UnionNode.
 void markTopTableConstructor()
          Mark this as the top node of a table constructor.
 Optimizable modifyAccessPath(JBitSet outerTables)
          Modify the access path for this Optimizable, as necessary.
 ResultSetNode modifyAccessPaths()
          Modify the access paths according to the decisions the optimizer made.
 CostEstimate optimizeIt(Optimizer optimizer, OptimizablePredicateList predList, CostEstimate outerCost, RowOrdering rowOrdering)
          Choose the best access path for this Optimizable.
 void rejectParameters()
          Check for (and reject) ?
(package private)  void setTableConstructorTypes(ResultColumnList typeColumns)
          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).
(package private)  boolean tableConstructor()
          Tell whether this is a UNION for a table constructor.
 java.lang.String toString()
          Convert this object to a String.
 
Methods inherited from class org.apache.derby.impl.sql.compile.SetOperatorNode
bindResultColumns, bindResultColumns, bindTargetExpressions, bindUntypedNullsToResultColumns, enhanceRCLForInsert, ensurePredicateList, flattenableInFromSubquery, getFromTableByName, getParamColumnTypes, init, performMaterialization, preprocess, pushOrderByList, setParamColumnTypes, setResultToBooleanTrueNode, verifySelectStarSubquery
 
Methods inherited from class org.apache.derby.impl.sql.compile.TableOperatorNode
accept, bindExpressionsWithTables, bindNonVTITables, bindVTITables, decrementLevel, getExposedName, getLeftmostResultSet, getLeftResultSet, getNestedInParens, getRightResultSet, init, markOrderingDependent, needsSpecialRCLBinding, optimize, optimizeSource, printSubNodes, projectResultColumns, referencesSessionSchema, referencesTarget, replaceDefaults, setLeftmostResultSet, setLevel, setNestedInParens, setReferencedColumns, verifyProperties
 
Methods inherited from class org.apache.derby.impl.sql.compile.FromTable
areAllColumnsProjected, assignCostEstimate, canBeOrdered, considerSortAvoidancePath, convertAbsoluteToRelativeColumnPosition, cursorTargetTable, estimateCost, feasibleJoinStrategy, fillInReferencedTableMap, flatten, forUpdate, getBaseTableName, getBestAccessPath, getBestSortAvoidancePath, getCostEstimate, getCurrentAccessPath, getLevel, getName, getNumColumnsReturned, getProperties, getResultColumnsForList, getSchemaDescriptor, getSchemaDescriptor, getScratchCostEstimate, getTableDescriptor, getTableName, getTableNumber, getTrulyTheBestAccessPath, getUserSpecifiedJoinStrategy, hashKeyColumns, hasTableNumber, init, initAccessPaths, initialCapacity, isBaseTable, isCoveringIndex, isFlattenableJoinNode, isMaterializable, isOneRowScan, isTargetTable, legalJoinOrder, loadFactor, LOJ_reorderable, markUpdatableByCursor, maxCapacity, memoryUsageOK, nextAccessPath, optimizeSubqueries, pullOptPredicates, pushExpressions, pushOptPredicate, rememberAsBest, rememberJoinStrategyAsBest, rememberSortAvoidancePath, resetJoinStrategies, setAllColumnsProjected, setCostEstimate, setHashKeyColumns, setProperties, setTableNumber, startOptimizing, supportsMultipleInstantiations, tellRowOrderingAboutConstantColumns, transformOuterJoins, uniqueJoin
 
Methods inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
addNewPredicate, assignResultSetNumber, changeAccessPath, closeMethodArgument, columnTypesAndLengthsMatch, considerMaterialization, generateNormalizationResultSet, generateResultSet, genNewRCForInsert, genNormalizeResultSetNode, genProjectRestrict, genProjectRestrict, genProjectRestrictForReordering, getAllResultColumns, getCostEstimate, getCursorTargetTable, getFinalCostEstimate, getFromList, getMatchingColumn, getNewCostEstimate, getOptimizer, getReferencedTableMap, getResultColumns, getResultSetNumber, isNotExists, isOneRowResultSet, isOrderedOn, isPossibleDistinctScan, isUpdatableCursor, LOJgetReferencedTables, makeResultDescription, makeResultDescriptors, markAsCursorTargetTable, markForDistinctScan, markStatementResultSet, notCursorTargetTable, notFlattenableJoin, numDistinctAggregates, parseDefault, rejectXMLValues, renameGeneratedResultNames, returnsAtMostOneRow, setInsertSource, setReferencedTableMap, setResultColumns, subqueryReferencesTarget, updateTargetLockMode
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
bind, convertDefaultNode, debugFlush, debugPrint, executeSchemaName, executeStatementName, formatNodeString, foundString, generate, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getSPSName, getStatementType, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, isAtomic, isInstanceOf, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, needsSavepoint, nodeHeader, optimize, parseQueryText, printLabel, resolveTableToSynonym, setBeginOffset, setContextManager, setEndOffset, setNodeType, setRefActionInfo, treePrint, treePrint, verifyClassExist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.derby.iapi.sql.compile.Optimizable
getDataDictionary, getReferencedTableMap, getResultSetNumber
 

Field Detail

addNewNodesCalled

private boolean addNewNodesCalled

tableConstructor

boolean tableConstructor

topTableConstructor

boolean topTableConstructor
Constructor Detail

UnionNode

public UnionNode()
Method Detail

init

public void init(java.lang.Object leftResult,
                 java.lang.Object rightResult,
                 java.lang.Object all,
                 java.lang.Object tableConstructor,
                 java.lang.Object tableProperties)
          throws StandardException
Initializer for a UnionNode.

Overrides:
init in class QueryTreeNode
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

markTopTableConstructor

public 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

public 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
Returns:
Nothing
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

optimizeIt

public CostEstimate optimizeIt(Optimizer optimizer,
                               OptimizablePredicateList predList,
                               CostEstimate outerCost,
                               RowOrdering rowOrdering)
                        throws StandardException
Description copied from interface: Optimizable
Choose the best access path for this Optimizable.

Specified by:
optimizeIt in interface Optimizable
Overrides:
optimizeIt in class FromTable
Throws:
StandardException - Thrown on error
See Also:
Optimizable.optimizeIt(org.apache.derby.iapi.sql.compile.Optimizer, org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.compile.CostEstimate, org.apache.derby.iapi.sql.compile.RowOrdering)

modifyAccessPath

public Optimizable modifyAccessPath(JBitSet outerTables)
                             throws StandardException
Description copied from interface: Optimizable
Modify the access path for this Optimizable, as necessary. This includes things like adding a result set to translate from index rows to base rows

Specified by:
modifyAccessPath in interface Optimizable
Overrides:
modifyAccessPath in class TableOperatorNode
Throws:
StandardException - Thrown on error
See Also:
Optimizable.modifyAccessPath(org.apache.derby.iapi.util.JBitSet)

modifyAccessPaths

public ResultSetNode modifyAccessPaths()
                                throws StandardException
Description copied from class: ResultSetNode
Modify the access paths according to the decisions the optimizer made. This can include adding project/restrict nodes, index-to-base-row nodes, etc.

Overrides:
modifyAccessPaths in class TableOperatorNode
Throws:
StandardException - Thrown on error
See Also:
ResultSetNode.modifyAccessPaths()

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 TableOperatorNode
Returns:
Nothing
Throws:
StandardException - Thrown on error

generate

public void generate(ActivationClassBuilder acb,
                     MethodBuilder mb)
              throws StandardException
Generate the code for this UnionNode.

Overrides:
generate in class QueryTreeNode
Parameters:
acb - The ActivationClassBuilder for the class being built
mb - The method for the generated code to go into
Throws:
StandardException - Thrown on error

getOperatorName

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

Built on Tue 2006-10-10 19:23:47+0200, from revision exported

Apache Derby V10.1 Engine Documentation - Copyright © 1997,2005 The Apache Software Foundation or its licensors, as applicable.