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

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.IntersectOrExceptNode
All Implemented Interfaces:
Optimizable, Visitable

public class IntersectOrExceptNode
extends SetOperatorNode

A IntersectOrExceptNode represents an INTERSECT or EXCEPT DML statement.

Author:
Jack Klebanoff

Field Summary
private  boolean addNewNodesCalled
           
static int EXCEPT_OP
           
private  int[] intermediateOrderByColumns
           
private  int[] intermediateOrderByDirection
           
static int INTERSECT_OP
           
private  int opType
           
 
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
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.
(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, enhanceRCLForInsert, ensurePredicateList, flattenableInFromSubquery, getFromTableByName, getParamColumnTypes, init, performMaterialization, pushOrderByList, setParamColumnTypes, setResultToBooleanTrueNode, toString, verifySelectStarSubquery
 
Methods inherited from class org.apache.derby.impl.sql.compile.TableOperatorNode
accept, bindExpressions, bindExpressionsWithTables, bindNonVTITables, bindVTITables, decrementLevel, getExposedName, getLeftmostResultSet, getLeftResultSet, getNestedInParens, getRightResultSet, init, markOrderingDependent, needsSpecialRCLBinding, optimize, optimizeSource, printSubNodes, projectResultColumns, referencesSessionSchema, referencesTarget, rejectParameters, replaceDefaults, setLeftmostResultSet, setLevel, setNestedInParens, setReferencedColumns, verifyProperties
 
Methods inherited from class org.apache.derby.impl.sql.compile.FromTable
areAllColumnsProjected, assignCostEstimate, canBeOrdered, considerSortAvoidancePath, convertAbsoluteToRelativeColumnPosition, cursorTargetTable, 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, optimizeIt, 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, setTableConstructorTypes, 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

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

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

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 Mon 2007-06-04 09:58:47+0400, from revision ???

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