Class SingleChildResultSetNode
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.SingleChildResultSetNode
- All Implemented Interfaces:
Optimizable
,Visitable
- Direct Known Subclasses:
DistinctNode
,GroupByNode
,HashTableNode
,MaterializeResultSetNode
,NormalizeResultSetNode
,OrderByNode
,ProjectRestrictNode
,RowCountNode
,ScrollInsensitiveResultSetNode
,WindowResultSetNode
A SingleChildResultSetNode represents a result set with a single child.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
ResultSetNode.QueryExpressionClauses
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) ResultSetNode
ResultSetNode under the SingleChildResultSetNodeprotected boolean
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
ConstructorsConstructorDescriptionSingleChildResultSetNode
(ResultSetNode childResult, Properties tableProperties, ContextManager cm) -
Method Summary
Modifier and TypeMethodDescription(package private) void
Accept the visitor for all visitable children of this node.(package private) ResultSetNode
addNewPredicate
(Predicate predicate) Add a new predicate to the list.(package private) void
Notify the underlying result set tree that the optimizer has chosen to "eliminate" a sort.(package private) void
adjustForSortElimination
(RequiredRowOrdering rowOrdering) Same goal as adjustForSortElimination above, but this version takes a RequiredRowOrdering to allow nodes to adjust based on the ORDER BY clause, if needed.(package private) ResultSetNode
The optimizer's decision on the access path for a result set may require the generation of extra result sets.(package private) void
decrementLevel
(int decrement) Decrement (query block) level (0-based) for this FromTable.(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.boolean
Return true if this is the target table of an update(package private) ResultSetNode
Return the childResult from this node.(package private) CostEstimate
Get the final CostEstimate for this node.(package private) FromTable
getFromTableByName
(String name, String schemaName, boolean exactMatch) Determine whether or not the specified name is an exposed name in the current query block.Get the best access path overall for this Optimizable.void
initAccessPaths
(Optimizer optimizer) Init the access paths for this optimizable.(package private) boolean
Return whether or not the underlying ResultSet tree is for a NOT EXISTS join.(package private) boolean
Return whether or not the underlying ResultSet tree will return a single row, at most.(package private) boolean
isOrderedOn
(ColumnReference[] crs, boolean permuteOrdering, List<FromBaseTable> fbtHolder) Return whether or not the underlying ResultSet tree is ordered on the specified columns.(package private) ResultSetNode
Modify the access paths according to the decisions the optimizer made.(package private) ResultSetNode
optimize
(DataDictionary dataDictionary, PredicateList predicates, double outerRows) Optimize this SingleChildResultSetNode.(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
pushExpressions
(PredicateList predicateList) Push expressions down to the first ResultSetNode which can do expression evaluation and has the same referenced table map.boolean
Return true if the node references SESSION schema tables (temporary or permanent)(package private) boolean
referencesTarget
(String name, boolean baseTable) Search to see if a query references the specifed table name.protected boolean
Determine whether we need to do reflection in order to do the projection.(package private) void
setChildResult
(ResultSetNode childResult) Set the childResult for this node.(package private) void
setLevel
(int level) Set the (query block) level (0-based) for this FromTable.(package private) boolean
subqueryReferencesTarget
(String name, boolean baseTable) Return whether or not this ResultSetNode contains a subquery with a reference to the specified target.void
updateBestPlanMap
(short action, Object planKey) When remembering "truly the best" access path for an Optimizable, we have to keep track of which OptimizerImpl the "truly the best" access is for.(package private) int
Get the lock mode for the target of an update statement (a delete or update).Methods inherited from class org.apache.derby.impl.sql.compile.FromTable
assignCostEstimate, canBeOrdered, columnsAreUpdatable, considerSortAvoidancePath, convertAbsoluteToRelativeColumnPosition, cursorTargetTable, estimateCost, feasibleJoinStrategy, fillInReferencedTableMap, flatten, getBaseTableName, getBestAccessPath, getBestSortAvoidancePath, getCorrelationName, getCostEstimate, getCurrentAccessPath, getExposedName, getLevel, getMergeTableID, getName, getNumColumnsReturned, getOrigTableName, getProperties, getResultColumnsForList, getSchemaDescriptor, getSchemaDescriptor, getScratchCostEstimate, getTableDescriptor, getTableName, getTableNumber, getUserSpecifiedJoinStrategy, hashKeyColumns, hasLargeObjectColumns, hasTableNumber, initialCapacity, isBaseTable, isCoveringIndex, isFlattenableJoinNode, isJoinColumnForRightOuterJoin, isMaterializable, isOneRowScan, isTargetTable, legalJoinOrder, loadFactor, LOJ_reorderable, markUpdatableByCursor, maxCapacity, memoryUsageOK, modifyAccessPath, needsSpecialRCLBinding, nextAccessPath, optimizeIt, optimizeSubqueries, pushOptPredicate, rememberAsBest, rememberJoinStrategyAsBest, rememberSortAvoidancePath, resetJoinStrategies, setCostEstimateCost, setHashKeyColumns, setMergeTableID, setOrigTableName, setProperties, setTableNumber, startOptimizing, supportsMultipleInstantiations, tellRowOrderingAboutConstantColumns, toString, transformOuterJoins, uniqueJoin, verifyProperties
Methods inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
assignResultSetNumber, bindExpressions, bindExpressionsWithTables, bindNonVTITables, bindResultColumns, bindResultColumns, bindTargetExpressions, bindUntypedNullsToResultColumns, bindVTITables, columnTypesAndLengthsMatch, considerMaterialization, enhanceRCLForInsert, generateNormalizationResultSet, generateResultSet, genProjectRestrict, genProjectRestrict, genProjectRestrictForReordering, getAllResultColumns, getCandidateFinalCostEstimate, getCostEstimate, getCursorTargetTable, getFromList, getMatchingColumn, getNewCostEstimate, getOptimizer, getOptimizerImpl, getRCLForInsert, getReferencedTableMap, getResultColumns, getResultSetNumber, getScratchCostEstimate, isCursorTargetTable, isInsertSource, isPossibleDistinctScan, isStatementResultSet, isUpdatableCursor, LOJgetReferencedTables, makeResultDescription, makeResultDescriptors, markAsCursorTargetTable, markForDistinctScan, markStatementResultSet, modifyAccessPaths, notCursorTargetTable, notFlattenableJoin, numDistinctAggregates, parseDefault, performMaterialization, printQueryExpressionSuffixClauses, projectResultColumns, pushOffsetFetchFirst, pushOrderByList, pushQueryExpressionSuffix, rejectParameters, rejectXMLValues, renameGeneratedResultNames, replaceOrForbidDefaults, returnsAtMostOneRow, setCandidateFinalCostEstimate, setCostEstimate, setCursorTargetTable, setInsertSource, setOptimizer, setReferencedTableMap, setResultColumns, setResultSetNumber, setResultToBooleanTrueNode, setScratchCostEstimate, setTableConstructorTypes, verifySelectStarSubquery
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, 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
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 Details
-
childResult
ResultSetNode childResultResultSetNode under the SingleChildResultSetNode -
hasTrulyTheBestAccessPath
protected boolean hasTrulyTheBestAccessPath
-
-
Constructor Details
-
SingleChildResultSetNode
SingleChildResultSetNode(ResultSetNode childResult, Properties tableProperties, ContextManager cm)
-
-
Method Details
-
getTrulyTheBestAccessPath
Description copied from interface:Optimizable
Get the best access path overall for this Optimizable.- Specified by:
getTrulyTheBestAccessPath
in interfaceOptimizable
- Overrides:
getTrulyTheBestAccessPath
in classFromTable
- See Also:
-
getChildResult
ResultSetNode getChildResult()Return the childResult from this node.- Returns:
- ResultSetNode The childResult from this node.
-
setChildResult
Set the childResult for this node.- Parameters:
childResult
- The new childResult for this node.
-
pullOptPredicates
public void pullOptPredicates(OptimizablePredicateList optimizablePredicates) throws StandardException Description copied from interface:Optimizable
Pull all the OptimizablePredicates from this Optimizable and put them in the given OptimizablePredicateList.- Specified by:
pullOptPredicates
in interfaceOptimizable
- Overrides:
pullOptPredicates
in classFromTable
- Parameters:
optimizablePredicates
- The list to put the pulled predicates in.- Throws:
StandardException
- Thrown on error- See Also:
-
forUpdate
public boolean forUpdate()Description copied from interface:Optimizable
Return true if this is the target table of an update- Specified by:
forUpdate
in interfaceOptimizable
- Overrides:
forUpdate
in classFromTable
- See Also:
-
initAccessPaths
Description copied from interface:Optimizable
Init the access paths for this optimizable.- Specified by:
initAccessPaths
in interfaceOptimizable
- Overrides:
initAccessPaths
in classFromTable
- Parameters:
optimizer
- The optimizer being used.- See Also:
-
updateBestPlanMap
Description copied from interface:Optimizable
When remembering "truly the best" access path for an Optimizable, we have to keep track of which OptimizerImpl the "truly the best" access is for. In most queries there will only be one OptimizerImpl in question, but in cases where there are nested subqueries, there will be one OptimizerImpl for every level of nesting, and each OptimizerImpl might have its own idea of what this Optimizable's "truly the best path" access path really is. In addition, there could be Optimizables above this Optimizable that might need to override the best path chosen during optimization. So whenever we save a "truly the best" path, we take note of which Optimizer/Optimizable told us to do so. Then as each level of subquery finishes optimization, the corresponding OptimizerImpl/Optimizable can load its preferred access path into this Optimizable's trulyTheBestAccessPath field and pass it up the tree, until eventually the outer-most OptimizerImpl can choose to either use the best path that it received from below (by calling "rememberAsBest()") or else use the path that it found to be "best" for itself. This method is what allows us to keep track of which OptimizerImpl or Optimizable saved which "best plan", and allows us to load the appropriate plans after each round of optimization.- Specified by:
updateBestPlanMap
in interfaceOptimizable
- Overrides:
updateBestPlanMap
in classFromTable
- Parameters:
action
- Indicates whether we're adding, loading, or removing a best plan for the OptimizerImpl/Optimizable.planKey
- Object to use as the map key when adding/looking up a plan. If it is an instance of OptimizerImpl then it corresponds to an outer query; otherwise it's some Optimizable above this Optimizable that could potentially reject plans chosen by the OptimizerImpl to which this Optimizable belongs.- Throws:
StandardException
- See Also:
-
printSubNodes
void printSubNodes(int depth) Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.- Overrides:
printSubNodes
in classResultSetNode
- Parameters:
depth
- The depth of this node in the tree
-
referencesTarget
Search to see if a query references the specifed table name.- Overrides:
referencesTarget
in classResultSetNode
- Parameters:
name
- Table name (String) to search for.baseTable
- Whether or not name is for a base table- Returns:
- true if found, else false
- Throws:
StandardException
- Thrown on error
-
referencesSessionSchema
Return true if the node references SESSION schema tables (temporary or permanent)- Overrides:
referencesSessionSchema
in classQueryTreeNode
- Returns:
- true if references SESSION schema tables, else false
- Throws:
StandardException
- Thrown on error
-
setLevel
void setLevel(int level) Set the (query block) level (0-based) for this FromTable. -
subqueryReferencesTarget
Return whether or not this ResultSetNode contains a subquery with a reference to the specified target.- Overrides:
subqueryReferencesTarget
in classResultSetNode
- Parameters:
name
- The table name.baseTable
- Whether or not the name is for a base table.- Returns:
- boolean Whether or not a reference to the table was found.
- Throws:
StandardException
- Thrown on error
-
preprocess
ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList) throws StandardException Put a ProjectRestrictNode on top of each FromTable in the FromList. ColumnReferences must continue to point to the same ResultColumn, so that ResultColumn must percolate up to the new PRN. However, that ResultColumn will point to a new expression, a VirtualColumnNode, which points to the FromTable and the ResultColumn that is the source for the ColumnReference. (The new PRN will have the original of the ResultColumnList and the ResultColumns from that list. The FromTable will get shallow copies of the ResultColumnList and its ResultColumns. ResultColumn.expression will remain at the FromTable, with the PRN getting a new VirtualColumnNode for each ResultColumn.expression.) We then project out the non-referenced columns. If there are no referenced columns, then the PRN's ResultColumnList will consist of a single ResultColumn whose expression is 1.- Overrides:
preprocess
in classResultSetNode
- Parameters:
numTables
- Number of tables in the DML Statementgbl
- The group by list, if anyfromList
- The from list, if any- Returns:
- The generated ProjectRestrictNode atop the original FromTable.
- Throws:
StandardException
- Thrown on error
-
addNewPredicate
Add a new predicate to the list. This is useful when doing subquery transformations, when we build a new predicate with the left side of the subquery operator and the subquery's result column.- Overrides:
addNewPredicate
in classResultSetNode
- Parameters:
predicate
- The predicate to add- Returns:
- ResultSetNode The new top of the tree.
- Throws:
StandardException
- Thrown on error
-
pushExpressions
Push expressions down to the first ResultSetNode which can do expression evaluation and has the same referenced table map. RESOLVE - This means only pushing down single table expressions to DistinctNodes today. Once we have a better understanding of how the optimizer will work, we can push down join clauses.- Overrides:
pushExpressions
in classFromTable
- Parameters:
predicateList
- The PredicateList.- Throws:
StandardException
- Thrown on error
-
flattenableInFromSubquery
Evaluate whether or not the subquery in a FromSubquery is flattenable. Currently, a FSqry is flattenable if all of the following are true: o Subquery is a SelectNode. o It contains no top level subqueries. (RESOLVE - we can relax this) o It does not contain a group by or having clause o It does not contain aggregates.- Overrides:
flattenableInFromSubquery
in classResultSetNode
- Parameters:
fromList
- The outer from list- Returns:
- boolean Whether or not the FromSubquery is flattenable.
-
ensurePredicateList
Ensure that the top of the RSN tree has a PredicateList.- Overrides:
ensurePredicateList
in classResultSetNode
- Parameters:
numTables
- The number of tables in the query.- Returns:
- ResultSetNode A RSN tree with a node which has a PredicateList on top.
- Throws:
StandardException
- Thrown on error
-
optimize
ResultSetNode optimize(DataDictionary dataDictionary, PredicateList predicates, double outerRows) throws StandardException Optimize this SingleChildResultSetNode.- Overrides:
optimize
in classResultSetNode
- Parameters:
dataDictionary
- The DataDictionary to use for optimizationpredicates
- The PredicateList to optimize. This should be a join predicate.outerRows
- The number of outer joining rows- Returns:
- ResultSetNode The top of the optimized subtree
- Throws:
StandardException
- Thrown on error
-
modifyAccessPaths
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 classResultSetNode
- Returns:
- The modified query tree
- Throws:
StandardException
- Thrown on error- See Also:
-
changeAccessPath
Description copied from class:ResultSetNode
The optimizer's decision on the access path for a result set may require the generation of extra result sets. For example, if it chooses an index for a FromBaseTable, we need an IndexToBaseRowNode above the FromBaseTable (and the FromBaseTable has to change its column list to match the index. This method in the parent class does not generate any extra result sets. It may be overridden in child classes.- Overrides:
changeAccessPath
in classResultSetNode
- Returns:
- A ResultSetNode tree modified to do any extra processing for the chosen access path
- Throws:
StandardException
- Thrown on error- See Also:
-
getFromTableByName
FromTable getFromTableByName(String name, String schemaName, boolean exactMatch) throws StandardException Determine whether or not the specified name is an exposed name in the current query block.- Overrides:
getFromTableByName
in classFromTable
- Parameters:
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.- Returns:
- The FromTable, if any, with the exposed name.
- Throws:
StandardException
- Thrown on error
-
decrementLevel
void decrementLevel(int decrement) Decrement (query block) level (0-based) for this FromTable. This is useful when flattening a subquery.- Overrides:
decrementLevel
in classFromTable
- Parameters:
decrement
- The amount to decrement by.
-
updateTargetLockMode
int updateTargetLockMode()Get the lock mode for the target of an update statement (a delete or update). The update mode will always be row for CurrentOfNodes. It will be table if there is no where clause.- Overrides:
updateTargetLockMode
in classResultSetNode
- Returns:
- The lock mode
- See Also:
-
isOrderedOn
boolean isOrderedOn(ColumnReference[] crs, boolean permuteOrdering, List<FromBaseTable> fbtHolder) throws StandardException Return whether or not the underlying ResultSet tree is ordered on the specified columns. RESOLVE - This method currently only considers the outermost table of the query block.- Overrides:
isOrderedOn
in classResultSetNode
- Parameters:
crs
- The specified ColumnReference[]permuteOrdering
- Whether or not the order of the CRs in the array can be permutedfbtHolder
- List that is to be filled with the FromBaseTable- Returns:
- Whether the underlying ResultSet tree is ordered on the specified column.
- Throws:
StandardException
- Thrown on error
-
isOneRowResultSet
Return whether or not the underlying ResultSet tree will return a single row, at most. This is important for join nodes where we can save the extra next on the right side if we know that it will return at most 1 row.- Overrides:
isOneRowResultSet
in classResultSetNode
- Returns:
- Whether or not the underlying ResultSet tree will return a single row.
- Throws:
StandardException
- Thrown on error
-
isNotExists
boolean isNotExists()Return whether or not the underlying ResultSet tree is for a NOT EXISTS join.- Overrides:
isNotExists
in classResultSetNode
- Returns:
- Whether or not the underlying ResultSet tree is for a NOT EXISTS.
-
reflectionNeededForProjection
protected boolean reflectionNeededForProjection()Determine whether we need to do reflection in order to do the projection. Reflection is only needed if there is at least 1 column which is not simply selecting the source column.- Returns:
- Whether or not we need to do reflection in order to do the projection.
-
adjustForSortElimination
void adjustForSortElimination()Description copied from class:ResultSetNode
Notify the underlying result set tree that the optimizer has chosen to "eliminate" a sort. Sort elimination can happen as part of preprocessing (see esp. SelectNode.preprocess(...)) or it can happen if the optimizer chooses an access path that inherently returns the rows in the correct order (also known as a "sort avoidance" plan). In either case we drop the sort and rely on the underlying result set tree to return its rows in the correct order. For most types of ResultSetNodes we automatically get the rows in the correct order if the sort was eliminated. One exception to this rule, though, is the case of an IndexRowToBaseRowNode, for which we have to disable bulk fetching on the underlying base table. Otherwise the index scan could return rows out of order if the base table is updated while the scan is "in progress" (i.e. while the result set is open). In order to account for this (and potentially other, similar issues in the future) this method exists to notify the result set node that it is expected to return rows in the correct order. The result set can then take necessary action to satsify this requirement--such as disabling bulk fetch in the case of IndexRowToBaseRowNode. All of that said, any ResultSetNodes for which we could potentially eliminate sorts should override this method accordingly. So we don't ever expect to get here.- Overrides:
adjustForSortElimination
in classResultSetNode
- See Also:
-
adjustForSortElimination
Description copied from class:ResultSetNode
Same goal as adjustForSortElimination above, but this version takes a RequiredRowOrdering to allow nodes to adjust based on the ORDER BY clause, if needed.- Overrides:
adjustForSortElimination
in classResultSetNode
- Throws:
StandardException
- See Also:
-
getFinalCostEstimate
Get the final CostEstimate for this node.- Overrides:
getFinalCostEstimate
in classFromTable
- Returns:
- The final CostEstimate for this node, which is the final cost estimate for the child node.
- Throws:
StandardException
-
acceptChildren
Accept the visitor for all visitable children of this node.- Overrides:
acceptChildren
in classFromTable
- Parameters:
v
- the visitor- Throws:
StandardException
- on error
-