Class IntersectOrExceptNode
- java.lang.Object
-
- org.apache.derby.impl.sql.compile.QueryTreeNode
-
- org.apache.derby.impl.sql.compile.ResultSetNode
-
- org.apache.derby.impl.sql.compile.FromTable
-
- org.apache.derby.impl.sql.compile.TableOperatorNode
-
- org.apache.derby.impl.sql.compile.SetOperatorNode
-
- 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
ResultSetNode.QueryExpressionClauses
-
-
Field Summary
Fields Modifier and Type Field Description 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, qec
-
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.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX
-
-
Constructor Summary
Constructors Constructor Description IntersectOrExceptNode(int opType, ResultSetNode leftResult, ResultSetNode rightResult, boolean all, java.util.Properties tableProperties, ContextManager cm)
Constructor for a SetOperatorNode.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.(package private) void
generate(ActivationClassBuilder acb, MethodBuilder mb)
Generate the code.(package private) 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)
Optimizable
modifyAccessPath(JBitSet outerTables)
Modify the access path for this Optimizable, as necessary.(package private) ResultSetNode
modifyAccessPaths()
Modify the access paths according to the decisions the optimizer made.(package private) 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
bindExpressions, bindResultColumns, bindResultColumns, bindTargetExpressions, bindUntypedNullsToResultColumns, ensurePredicateList, flattenableInFromSubquery, getFromTableByName, getLeftOptPredicateList, getParamColumnTypes, getRightOptPredicateList, hasUnPushedPredicates, modifyAccessPath, performMaterialization, printSubNodes, pullOptPredicates, pushOffsetFetchFirst, pushOptPredicate, pushOrderByList, pushQueryExpressionSuffix, replaceOrForbidDefaults, setParamColumnTypes, setResultToBooleanTrueNode, toString, verifySelectStarSubquery
-
Methods inherited from class org.apache.derby.impl.sql.compile.TableOperatorNode
acceptChildren, adjustForSortElimination, adjustForSortElimination, bindExpressionsWithTables, bindNonVTITables, bindVTITables, decrementLevel, getExposedName, getLeftmostResultSet, getLeftResultSet, getRightResultSet, 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, columnsAreUpdatable, considerSortAvoidancePath, convertAbsoluteToRelativeColumnPosition, cursorTargetTable, feasibleJoinStrategy, fillInReferencedTableMap, flatten, forUpdate, getBaseTableName, getBestAccessPath, getBestSortAvoidancePath, getCorrelationName, getCostEstimate, getCurrentAccessPath, getLevel, getMergeTableID, getName, getNumColumnsReturned, getOrigTableName, getProperties, getResultColumnsForList, getSchemaDescriptor, getSchemaDescriptor, getScratchCostEstimate, getTableDescriptor, getTableName, getTableNumber, getTrulyTheBestAccessPath, getUserSpecifiedJoinStrategy, hashKeyColumns, hasLargeObjectColumns, hasTableNumber, initAccessPaths, initialCapacity, isBaseTable, isCoveringIndex, isFlattenableJoinNode, isJoinColumnForRightOuterJoin, isMaterializable, isOneRowScan, isTargetTable, legalJoinOrder, loadFactor, LOJ_reorderable, markUpdatableByCursor, maxCapacity, memoryUsageOK, nextAccessPath, optimizeIt, optimizeSubqueries, pushExpressions, rememberAsBest, rememberJoinStrategyAsBest, rememberSortAvoidancePath, resetJoinStrategies, setCostEstimateCost, setHashKeyColumns, setMergeTableID, setOrigTableName, setProperties, setTableNumber, startOptimizing, supportsMultipleInstantiations, tellRowOrderingAboutConstantColumns, transformOuterJoins, uniqueJoin
-
Methods inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
addNewPredicate, assignResultSetNumber, changeAccessPath, columnTypesAndLengthsMatch, considerMaterialization, enhanceRCLForInsert, generateNormalizationResultSet, generateResultSet, genProjectRestrict, genProjectRestrict, genProjectRestrictForReordering, getAllResultColumns, getCandidateFinalCostEstimate, getCostEstimate, getCursorTargetTable, getFromList, getMatchingColumn, getNewCostEstimate, getOptimizer, getOptimizerImpl, getRCLForInsert, getReferencedTableMap, getResultColumns, getResultSetNumber, getScratchCostEstimate, isCursorTargetTable, isInsertSource, isNotExists, isOneRowResultSet, isOrderedOn, isPossibleDistinctScan, isStatementResultSet, isUpdatableCursor, LOJgetReferencedTables, makeResultDescription, makeResultDescriptors, markAsCursorTargetTable, markForDistinctScan, markStatementResultSet, modifyAccessPaths, notCursorTargetTable, notFlattenableJoin, numDistinctAggregates, parseDefault, printQueryExpressionSuffixClauses, rejectXMLValues, renameGeneratedResultNames, returnsAtMostOneRow, setCandidateFinalCostEstimate, setCostEstimate, setCursorTargetTable, setInsertSource, setOptimizer, setReferencedTableMap, setResultColumns, setResultSetNumber, setScratchCostEstimate, setTableConstructorTypes, subqueryReferencesTarget, updateTargetLockMode
-
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, addTag, addUDTUsagePriv, addUDTUsagePriv, bindOffsetFetch, bindRowMultiSet, bindUserCatalogType, bindUserType, checkReliability, checkReliability, convertDefaultNode, copyTagsFrom, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContext, getContextManager, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getLongProperty, getNullNode, getOffsetOrderedNodes, getOptimizerFactory, getOptimizerTracer, getParameterTypes, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, getUDTDesc, isAtomic, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, optimizerTracingIsOn, orReliability, parseSearchCondition, parseStatement, printLabel, resolveTableToSynonym, setBeginOffset, setEndOffset, setRefActionInfo, stackPrint, taggedWith, 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, getOptimizerTracer, getReferencedTableMap, getResultSetNumber, optimizerTracingIsOn
-
Methods inherited from interface org.apache.derby.iapi.sql.compile.Visitable
accept, addTag, taggedWith
-
-
-
-
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
IntersectOrExceptNode(int opType, ResultSetNode leftResult, ResultSetNode rightResult, boolean all, java.util.Properties tableProperties, ContextManager cm) throws StandardException
Constructor for a SetOperatorNode.- Parameters:
opType
- The operator type: one ofEXCEPT_OP
orINTERSECT_OP
.leftResult
- The ResultSetNode on the left side of this unionrightResult
- The ResultSetNode on the right side of this unionall
-true
if this is an ALL set operation.tableProperties
- Properties list associated with the tablecm
- The context manager- Throws:
StandardException
- Thrown on error
-
-
Method Detail
-
getOpType
private int getOpType()
-
preprocess
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 classSetOperatorNode
- Parameters:
numTables
- Number of tables in the DML Statementgbl
- The group by list, if anyfromList
- 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 interfaceOptimizable
- Overrides:
estimateCost
in classFromTable
- Parameters:
predList
- The predicate list to optimize againstcd
- The conglomerate descriptor to get the cost ofouterCost
- The estimated cost of the part of the plan outer to this optimizable.optimizer
- The optimizer to use to help estimate the costrowOrdering
- 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 interfaceOptimizable
- Overrides:
modifyAccessPath
in classTableOperatorNode
- 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
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 classTableOperatorNode
- 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
void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException
Generate the code.- Overrides:
generate
in classQueryTreeNode
- Parameters:
acb
- The ActivationClassBuilder for the class being builtmb
- The method for the generated code to go into- Throws:
StandardException
- Thrown on error
-
getFinalCostEstimate
CostEstimate getFinalCostEstimate() throws StandardException
Description copied from class:FromTable
Get the final CostEstimate for this FromTable.- Overrides:
getFinalCostEstimate
in classFromTable
- 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 classSetOperatorNode
- Returns:
- the operator name: "UNION", "INTERSECT", or "EXCEPT"
-
getRowCountEstimate
double getRowCountEstimate(double leftRowCount, double rightRowCount)
-
getSingleScanRowCountEstimate
double getSingleScanRowCountEstimate(double leftSingleScanRowCount, double rightSingleScanRowCount)
-
-