Optimizable
, Visitable
IntersectOrExceptNode
, UnionNode
abstract class SetOperatorNode extends TableOperatorNode
ResultSetNode.QueryExpressionClauses
Modifier and Type | Field | Description |
---|---|---|
(package private) boolean |
all |
Tells whether to eliminate duplicate rows.
|
private PredicateList |
leftOptPredicates |
|
private java.util.HashMap<Predicate,Predicate> |
leftScopedPreds |
|
private PredicateList |
pushedPredicates |
|
(package private) ResultSetNode.QueryExpressionClauses |
qec |
|
private PredicateList |
rightOptPredicates |
|
private java.util.HashMap<Predicate,Predicate> |
rightScopedPreds |
ADD_PLAN, bestAccessPath, bestCostEstimate, bestSortAvoidancePath, correlationName, corrTableName, currentAccessPath, hashKeyColumns, initialCapacity, level, LOAD_PLAN, loadFactor, maxCapacity, origTableName, REMOVE_PLAN, tableNumber, tableProperties, trulyTheBestAccessPath, userSpecifiedJoinStrategy
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX
leftOptimizer, leftResultSet, rightOptimizer, rightResultSet
Constructor | Description |
---|---|
SetOperatorNode(ResultSetNode leftResult,
ResultSetNode rightResult,
boolean all,
java.util.Properties tableProperties,
ContextManager cm) |
Constructor for a SetOperatorNode.
|
Modifier and Type | Method | Description |
---|---|---|
void |
bindExpressions(FromList fromList) |
Bind the expressions under this TableOperatorNode.
|
(package private) void |
bindResultColumns(TableDescriptor targetTableDescriptor,
FromVTI targetVTI,
ResultColumnList targetColumnList,
DMLStatementNode statement,
FromList fromListParam) |
Bind the result columns for this ResultSetNode to a base table.
|
(package private) void |
bindResultColumns(FromList fromListParam) |
Bind the result columns of this ResultSetNode when there is no
base table to bind them to.
|
(package private) void |
bindTargetExpressions(FromList fromListParam) |
Bind the expressions in the target list.
|
(package private) void |
bindUntypedNullsToResultColumns(ResultColumnList rcl) |
Bind the result columns of a table constructor to the types in the
given ResultColumnList.
|
private void |
buildRCL() |
Build the RCL for this node.
|
(package private) ResultSetNode |
ensurePredicateList(int numTables) |
Ensure that the top of the RSN tree has a PredicateList.
|
(package private) boolean |
flattenableInFromSubquery(FromList fromList) |
Evaluate whether or not the subquery in a FromSubquery is flattenable.
|
(package private) FromTable |
getFromTableByName(java.lang.String name,
java.lang.String schemaName,
boolean exactMatch) |
Determine whether or not the specified name is an exposed name in
the current query block.
|
(package private) PredicateList |
getLeftOptPredicateList() |
Retrieve the list of optimizable predicates that are
targeted for the left child.
|
(package private) abstract java.lang.String |
getOperatorName() |
|
(package private) int |
getParamColumnTypes(DataTypeDescriptor[] types,
RowResultSetNode rrsn) |
Get the parameter types from the given RowResultSetNode into the
given array of types.
|
(package private) PredicateList |
getRightOptPredicateList() |
Retrieve the list of optimizable predicates that are
targeted for the right child.
|
protected boolean |
hasUnPushedPredicates() |
It's possible that we tried to push predicates to this node's
children but failed to do so.
|
Optimizable |
modifyAccessPath(JBitSet outerTables,
PredicateList predList) |
|
(package private) boolean |
performMaterialization(JBitSet outerTables) |
Return whether or not to materialize this ResultSet tree.
|
(package private) ResultSetNode |
preprocess(int numTables,
GroupByList gbl,
FromList fromList) |
Put a ProjectRestrictNode on top of each FromTable in the FromList.
|
(package private) void |
printSubNodes(int depth) |
Prints the sub-nodes of this object.
|
void |
pullOptPredicates(OptimizablePredicateList optimizablePredicates) |
Pull all the OptimizablePredicates from this Optimizable and put them
in the given OptimizablePredicateList.
|
(package private) void |
pushOffsetFetchFirst(ValueNode offset,
ValueNode fetchFirst,
boolean hasJDBClimitClause) |
Push down the offset and fetch first parameters, if any, to this node.
|
boolean |
pushOptPredicate(OptimizablePredicate optimizablePredicate) |
Push an OptimizablePredicate down, if this node accepts it.
|
(package private) void |
pushOrderByList(OrderByList orderByList) |
Push the order by list down from the cursor node
into its child result set so that the optimizer
has all of the information that it needs to
consider sort avoidance.
|
void |
pushQueryExpressionSuffix() |
Set up a new level for order by and fetch/offset clauses.
|
(package private) void |
replaceOrForbidDefaults(TableDescriptor ttd,
ResultColumnList tcl,
boolean allowDefaults) |
Replace any DEFAULTs with the associated tree for the default if
allowed, or flag (when inside top level set operator nodes).
|
(package private) void |
setParamColumnTypes(DataTypeDescriptor[] types,
RowResultSetNode rrsn) |
Set the type of each ?
|
(package private) ResultSetNode |
setResultToBooleanTrueNode(boolean onlyConvertAlls) |
Set the result column for the subquery to a boolean true,
Useful for transformations such as
changing:
where exists (select ... from ...)
|
java.lang.String |
toString() |
Convert this object to a String.
|
(package private) void |
verifySelectStarSubquery(FromList outerFromList,
int subqueryType) |
Verify that a SELECT * is valid for this type of subquery.
|
assignCostEstimate, canBeOrdered, columnsAreUpdatable, considerSortAvoidancePath, convertAbsoluteToRelativeColumnPosition, cursorTargetTable, estimateCost, feasibleJoinStrategy, fillInReferencedTableMap, flatten, forUpdate, getBaseTableName, getBestAccessPath, getBestSortAvoidancePath, getCorrelationName, getCostEstimate, getCurrentAccessPath, getFinalCostEstimate, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getDataDictionary, getOptimizerTracer, getReferencedTableMap, getResultSetNumber, optimizerTracingIsOn
accept, addTag, addUDTUsagePriv, addUDTUsagePriv, bindOffsetFetch, bindRowMultiSet, bindUserCatalogType, bindUserType, checkReliability, checkReliability, convertDefaultNode, copyTagsFrom, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, generate, 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
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
acceptChildren, adjustForSortElimination, adjustForSortElimination, bindExpressionsWithTables, bindNonVTITables, bindVTITables, decrementLevel, getExposedName, getLeftmostResultSet, getLeftResultSet, getRightResultSet, modifyAccessPath, modifyAccessPaths, needsSpecialRCLBinding, optimize, optimizeSource, projectResultColumns, referencesSessionSchema, referencesTarget, rejectParameters, setLeftmostResultSet, setLevel, setNestedInParens, setReferencedColumns, updateBestPlanMap, verifyProperties
accept, addTag, taggedWith
boolean all
private PredicateList leftOptPredicates
private PredicateList rightOptPredicates
private PredicateList pushedPredicates
SetOperatorNode(ResultSetNode leftResult, ResultSetNode rightResult, boolean all, java.util.Properties tableProperties, ContextManager cm) throws StandardException
leftResult
- The ResultSetNode on the left side of this unionrightResult
- The ResultSetNode on the right side of this unionall
- Whether or not this is an ALL.tableProperties
- Properties list associated with the tablecm
- The context managerStandardException
- Thrown on errorpublic Optimizable modifyAccessPath(JBitSet outerTables, PredicateList predList) throws StandardException
StandardException
- Thrown on errorOptimizable.modifyAccessPath(org.apache.derby.iapi.util.JBitSet)
public boolean pushOptPredicate(OptimizablePredicate optimizablePredicate) throws StandardException
Optimizable
pushOptPredicate
in interface Optimizable
pushOptPredicate
in class FromTable
optimizablePredicate
- OptimizablePredicate to push down.StandardException
- Thrown on errorTake a predicate and push it down to both the left AND right result
sets. Return "true" if we successfully pushed it to both sides,
and "false" otherwise. The assumption is that if we return "true",
the caller will take the predicate and remove it from its own list
of predicates to evaluate; if we return false, then the predicate
will be evaluated at the level of the caller. So returning "false"
means that the left and right result sets for this node will be fully
returned, and then the predicate will be evaluated against the
set-operator of those result sets (as of DERBY-805, the only set
operator calling this method is UnionNode). If we can push the
predicate down to both children, though, we can evaluate it closer
to store, which means that each child result set returns only the
correctly qualified rows, and thus the calling set operator will
have a smaller result set on which to operate, which can boost
performance.
That said, if we can't push the predicate to _both_ sides, we don't
push it at all. The reason is that if we push to one side but not
to the other, we would have to ask the question of whether we should
return "true" (meaning that the predicate would be removed from the
caller's list and thus would _not_ be evaluated at the set-operator
level) or "false" (meaning that the caller would keep the predicate
and evaluate it at the set-operator level). Depending on the query
in question, both answers could end up returning incorrect results.
For example, if we push it to the right but not to the left, then
leave it in the caller's list, the optimizer for the caller might
decide to use the predicate to do a hash join with some outer result
set (if the predicate is an equijoin predicate). That would result
in materialization of the calling node and of its children--but since
we pushed a predicate that depends on the outer table down into the
right child, materialization of the right child will only return the
rows that join with the _first_ row of the outer result set, which
is wrong.
If, on the other hand, we push the predicate to one side and then tell
the caller to remove it from its list, the side to which we did _not_
push the predicate could return rows that aren't qualified. Then,
since the caller removed the predicate from its list, it (the caller)
will not evaluate the predicate on its own result set--and thus we
can end up returning rows that we weren't supposed to return.
So all of that said, only push (and return "true") if we think we
can push the predicate to both sides.
public void pullOptPredicates(OptimizablePredicateList optimizablePredicates) throws StandardException
Optimizable
pullOptPredicates
in interface Optimizable
pullOptPredicates
in class FromTable
optimizablePredicates
- The list to put the pulled predicates
in.StandardException
- Thrown on errorOptimizable.pullOptPredicates(org.apache.derby.iapi.sql.compile.OptimizablePredicateList)
protected boolean hasUnPushedPredicates()
public java.lang.String toString()
toString
in class TableOperatorNode
void printSubNodes(int depth)
printSubNodes
in class TableOperatorNode
depth
- The depth of this node in the treevoid bindResultColumns(FromList fromListParam) throws StandardException
bindResultColumns
in class TableOperatorNode
fromListParam
- FromList to use/append to.StandardException
- Thrown on errorvoid bindResultColumns(TableDescriptor targetTableDescriptor, FromVTI targetVTI, ResultColumnList targetColumnList, DMLStatementNode statement, FromList fromListParam) throws StandardException
bindResultColumns
in class TableOperatorNode
targetTableDescriptor
- The TableDescriptor for the table being
updated or inserted intotargetColumnList
- For INSERT statements, the user
does not have to supply column
names (for example, "insert into t
values (1,2,3)". When this
parameter is null, it means that
the user did not supply column
names, and so the binding should
be done based on order. When it
is not null, it means do the binding
by name, not position.statement
- Calling DMLStatementNode (Insert or Update)fromListParam
- FromList to use/append to.StandardException
- Thrown on errorprivate void buildRCL() throws StandardException
StandardException
- Thrown on errorvoid bindUntypedNullsToResultColumns(ResultColumnList rcl) throws StandardException
bindUntypedNullsToResultColumns
in class TableOperatorNode
rcl
- The ResultColumnList with the types to bind toStandardException
- Thrown on error.void replaceOrForbidDefaults(TableDescriptor ttd, ResultColumnList tcl, boolean allowDefaults) throws StandardException
replaceOrForbidDefaults
in class ResultSetNode
ttd
- The TableDescriptor for the target table.tcl
- The RCL for the target table.allowDefaults
- true if allowedStandardException
- Thrown on errorint getParamColumnTypes(DataTypeDescriptor[] types, RowResultSetNode rrsn) throws StandardException
types
- The array of types to fill inrrsn
- The RowResultSetNode from which to take the param typesStandardException
void setParamColumnTypes(DataTypeDescriptor[] types, RowResultSetNode rrsn) throws StandardException
types
- An array of types containing the proper type for each
? parameter, by ordinal position.rrsn
- A RowResultSetNode that could contain ? parameters whose
types need to be set.StandardException
- Thrown on errorpublic void bindExpressions(FromList fromList) throws StandardException
TableOperatorNode
bindExpressions
in class TableOperatorNode
fromList
- FromList to use/append to.StandardException
- Thrown on errorvoid bindTargetExpressions(FromList fromListParam) throws StandardException
bindTargetExpressions
in class ResultSetNode
StandardException
- Thrown on errorpublic void pushQueryExpressionSuffix()
ResultSetNode
ResultSetNode.QueryExpressionClauses
.
Overridden by implementors of pushOrderByNode, pushOffsetFetchFirst.pushQueryExpressionSuffix
in class ResultSetNode
void pushOrderByList(OrderByList orderByList)
pushOrderByList
in class ResultSetNode
orderByList
- The order by listvoid pushOffsetFetchFirst(ValueNode offset, ValueNode fetchFirst, boolean hasJDBClimitClause)
pushOffsetFetchFirst
in class ResultSetNode
offset
- the OFFSET, if anyfetchFirst
- the OFFSET FIRST, if anyhasJDBClimitClause
- true if the clauses were added by (and have the semantics of) a JDBC limit clauseResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList) throws StandardException
preprocess
in class TableOperatorNode
numTables
- Number of tables in the DML Statementgbl
- The group by list, if anyfromList
- The from list, if anyStandardException
- Thrown on errorResultSetNode ensurePredicateList(int numTables) throws StandardException
ensurePredicateList
in class ResultSetNode
numTables
- The number of tables in the query.StandardException
- Thrown on errorvoid verifySelectStarSubquery(FromList outerFromList, int subqueryType) throws StandardException
verifySelectStarSubquery
in class ResultSetNode
outerFromList
- The FromList from the outer query block(s)subqueryType
- The subquery typeStandardException
- Thrown on errorFromTable getFromTableByName(java.lang.String name, java.lang.String schemaName, boolean exactMatch) throws StandardException
getFromTableByName
in class TableOperatorNode
name
- The specified name to search for as an exposed name.schemaName
- Schema name, if non-null.exactMatch
- Whether or not we need an exact match on specified schema and table
names or match on table id.StandardException
- Thrown on errorResultSetNode setResultToBooleanTrueNode(boolean onlyConvertAlls) throws StandardException
setResultToBooleanTrueNode
in class ResultSetNode
onlyConvertAlls
- Boolean, whether or not to just convert *'sStandardException
- Thrown on errorboolean flattenableInFromSubquery(FromList fromList)
flattenableInFromSubquery
in class ResultSetNode
fromList
- The outer from listboolean performMaterialization(JBitSet outerTables) throws StandardException
performMaterialization
in class ResultSetNode
StandardException
- Thrown on errorabstract java.lang.String getOperatorName()
PredicateList getLeftOptPredicateList() throws StandardException
StandardException
PredicateList getRightOptPredicateList() throws StandardException
StandardException
Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.