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

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

public class IntersectOrExceptNode
extends SetOperatorNode

A IntersectOrExceptNode represents an INTERSECT or EXCEPT DML statement.


Field Summary
private  boolean addNewNodesCalled
           
static int EXCEPT_OP
           
private  int[] intermediateOrderByColumns
           
private  int[] intermediateOrderByDirection
           
private  boolean[] intermediateOrderByNullsLow
           
static int INTERSECT_OP
           
private  int opType
           
 
Fields inherited from class org.apache.derby.impl.sql.compile.SetOperatorNode
all, fetchFirst, offset, orderByList
 
Fields inherited from class org.apache.derby.impl.sql.compile.TableOperatorNode
leftOptimizer, leftResultSet, rightOptimizer, rightResultSet
 
Fields inherited from class org.apache.derby.impl.sql.compile.FromTable
ADD_PLAN, bestAccessPath, bestCostEstimate, bestSortAvoidancePath, correlationName, corrTableName, currentAccessPath, hashKeyColumns, initialCapacity, level, LOAD_PLAN, loadFactor, maxCapacity, origTableName, REMOVE_PLAN, tableNumber, tableProperties, trulyTheBestAccessPath, userSpecifiedJoinStrategy
 
Fields inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
costEstimate, cursorTargetTable, finalCostEstimate, insertSource, optimizer, referencedTableMap, resultColumns, resultSetNumber, scratchCostEstimate, statementResultSet
 
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, isPrivilegeCollectionRequired
 
Constructor Summary
IntersectOrExceptNode()
           
 
Method Summary
private  ResultSetNode addNewNodes()
          Add any new ResultSetNodes that are necessary to the tree.
 CostEstimate estimateCost(OptimizablePredicateList predList, ConglomerateDescriptor cd, CostEstimate outerCost, Optimizer optimizer, RowOrdering rowOrdering)
          Estimate the cost of scanning this Optimizable using the given predicate list with the given conglomerate.
 void generate(ActivationClassBuilder acb, MethodBuilder mb)
          Generate the code.
 CostEstimate getFinalCostEstimate()
          Get the final CostEstimate for this FromTable.
(package private)  java.lang.String getOperatorName()
           
private  int getOpType()
           
(package private)  double getRowCountEstimate(double leftRowCount, double rightRowCount)
           
(package private)  double getSingleScanRowCountEstimate(double leftSingleScanRowCount, double rightSingleScanRowCount)
           
 void init(java.lang.Object opType, java.lang.Object leftResult, java.lang.Object rightResult, java.lang.Object all, java.lang.Object tableProperties)
          Initializer for a SetOperatorNode.
 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.
 ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList)
          Push order by lists down to the children so that we can implement the intersect/except by scan of the two sorted inputs.
private  void pushOrderingDown(ResultSetNode rsn)
           
 
Methods inherited from class org.apache.derby.impl.sql.compile.SetOperatorNode
bindResultColumns, bindResultColumns, bindTargetExpressions, bindUntypedNullsToResultColumns, ensurePredicateList, flattenableInFromSubquery, getFromTableByName, getLeftOptPredicateList, getParamColumnTypes, getRightOptPredicateList, hasUnPushedPredicates, init, modifyAccessPath, performMaterialization, printSubNodes, pullOptPredicates, pushOffsetFetchFirst, pushOptPredicate, pushOrderByList, replaceOrForbidDefaults, setParamColumnTypes, setResultToBooleanTrueNode, toString, verifySelectStarSubquery
 
Methods inherited from class org.apache.derby.impl.sql.compile.TableOperatorNode
acceptChildren, adjustForSortElimination, adjustForSortElimination, bindExpressions, bindExpressionsWithTables, bindNonVTITables, bindVTITables, decrementLevel, getExposedName, getLeftmostResultSet, getLeftResultSet, getRightResultSet, init, needsSpecialRCLBinding, optimize, optimizeSource, projectResultColumns, referencesSessionSchema, referencesTarget, rejectParameters, setLeftmostResultSet, setLevel, setNestedInParens, setReferencedColumns, updateBestPlanMap, verifyProperties
 
Methods inherited from class org.apache.derby.impl.sql.compile.FromTable
assignCostEstimate, canBeOrdered, considerSortAvoidancePath, convertAbsoluteToRelativeColumnPosition, cursorTargetTable, feasibleJoinStrategy, fillInReferencedTableMap, flatten, forUpdate, getBaseTableName, getBestAccessPath, getBestSortAvoidancePath, getCorrelationName, getCostEstimate, getCurrentAccessPath, getLevel, getName, getNumColumnsReturned, getOrigTableName, 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, optimizeIt, optimizeSubqueries, pushExpressions, rememberAsBest, rememberJoinStrategyAsBest, rememberSortAvoidancePath, resetJoinStrategies, setCostEstimate, setHashKeyColumns, setOrigTableName, setProperties, setTableNumber, startOptimizing, supportsMultipleInstantiations, tellRowOrderingAboutConstantColumns, transformOuterJoins, uniqueJoin
 
Methods inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
addNewPredicate, assignResultSetNumber, changeAccessPath, columnTypesAndLengthsMatch, considerMaterialization, disablePrivilegeCollection, enhanceRCLForInsert, generateNormalizationResultSet, generateResultSet, genProjectRestrict, genProjectRestrict, genProjectRestrictForReordering, getAllResultColumns, getCostEstimate, getCursorTargetTable, getFromList, getMatchingColumn, getNewCostEstimate, getOptimizer, getOptimizerImpl, getRCLForInsert, getReferencedTableMap, getResultColumns, getResultSetNumber, isNotExists, isOneRowResultSet, isOrderedOn, isPossibleDistinctScan, isUpdatableCursor, LOJgetReferencedTables, makeResultDescription, makeResultDescriptors, markAsCursorTargetTable, markForDistinctScan, markStatementResultSet, modifyAccessPaths, notCursorTargetTable, notFlattenableJoin, numDistinctAggregates, parseDefault, rejectXMLValues, renameGeneratedResultNames, returnsAtMostOneRow, setInsertSource, setReferencedTableMap, setResultColumns, setTableConstructorTypes, subqueryReferencesTarget, updateTargetLockMode
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, bindOffsetFetch, bindRowMultiSet, bindUserType, checkReliability, checkReliability, convertDefaultNode, createTypeDependency, debugFlush, debugPrint, formatNodeString, foundString, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, isAtomic, isInstanceOf, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, orReliability, parseStatement, printLabel, resolveTableToSynonym, setBeginOffset, setContextManager, setEndOffset, setNodeType, setRefActionInfo, stackPrint, 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

opType

private int opType

INTERSECT_OP

public static final int INTERSECT_OP
See Also:
Constant Field Values

EXCEPT_OP

public static final int EXCEPT_OP
See Also:
Constant Field Values

addNewNodesCalled

private boolean addNewNodesCalled

intermediateOrderByColumns

private int[] intermediateOrderByColumns

intermediateOrderByDirection

private int[] intermediateOrderByDirection

intermediateOrderByNullsLow

private boolean[] intermediateOrderByNullsLow
Constructor Detail

IntersectOrExceptNode

public IntersectOrExceptNode()
Method Detail

init

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

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 an ALL.
tableProperties - Properties list associated with the table
Throws:
StandardException - Thrown on error

getOpType

private int getOpType()

preprocess

public ResultSetNode preprocess(int numTables,
                                GroupByList gbl,
                                FromList fromList)
                         throws StandardException
Push order by lists down to the children so that we can implement the intersect/except by scan of the two sorted inputs.

Overrides:
preprocess in class SetOperatorNode
Parameters:
numTables - Number of tables in the DML Statement
gbl - The group by list, if any
fromList - The from list, if any
Returns:
The preprocessed ResultSetNode that can be optimized
Throws:
StandardException - Thrown on error

pushOrderingDown

private void pushOrderingDown(ResultSetNode rsn)
                       throws StandardException
Throws:
StandardException

estimateCost

public CostEstimate estimateCost(OptimizablePredicateList predList,
                                 ConglomerateDescriptor cd,
                                 CostEstimate outerCost,
                                 Optimizer optimizer,
                                 RowOrdering rowOrdering)
                          throws StandardException
Description copied from interface: Optimizable
Estimate the cost of scanning this Optimizable using the given predicate list with the given conglomerate. It is assumed that the predicate list has already been classified. This cost estimate is just for one scan, not for the life of the query.

Specified by:
estimateCost in interface Optimizable
Overrides:
estimateCost in class FromTable
Parameters:
predList - The predicate list to optimize against
cd - The conglomerate descriptor to get the cost of
outerCost - The estimated cost of the part of the plan outer to this optimizable.
optimizer - The optimizer to use to help estimate the cost
rowOrdering - The row ordering for all the tables in the join order, including this one.
Returns:
The estimated cost of doing the scan
Throws:
StandardException - Thrown on error
See Also:
Optimizable.estimateCost(org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor, org.apache.derby.iapi.sql.compile.CostEstimate, org.apache.derby.iapi.sql.compile.Optimizer, 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
Parameters:
outerTables - Bit map of the tables that are outer to this one in the join order.
Returns:
The (potentially new) Optimizable at the top of the tree.
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
Returns:
The modified query tree
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

generate

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

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

getFinalCostEstimate

public CostEstimate getFinalCostEstimate()
                                  throws StandardException
Description copied from class: FromTable
Get the final CostEstimate for this FromTable.

Overrides:
getFinalCostEstimate in class FromTable
Returns:
The final CostEstimate for this IntersectOrExceptNode, which is the sum of the two child costs. The final number of rows depends on whether this is an INTERSECT or EXCEPT (see getRowCountEstimate() in this class for more).
Throws:
StandardException
See Also:
Get the final CostEstimate for this IntersectOrExceptNode.

getOperatorName

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

getRowCountEstimate

double getRowCountEstimate(double leftRowCount,
                           double rightRowCount)

getSingleScanRowCountEstimate

double getSingleScanRowCountEstimate(double leftSingleScanRowCount,
                                     double rightSingleScanRowCount)

Built on Thu 2011-03-10 11:54:14+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.