Class RowResultSetNode
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.RowResultSetNode
- All Implemented Interfaces:
Optimizable, Visitable
A RowResultSetNode represents the result set for a VALUES clause.
-
Nested Class Summary
Nested classes/interfaces inherited from class ResultSetNode
ResultSetNode.QueryExpressionClauses -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate List<AggregateNode> (package private) ResultSetNode.QueryExpressionClauses(package private) SubqueryListFields inherited from class FromTable
ADD_PLAN, bestAccessPath, bestCostEstimate, bestSortAvoidancePath, correlationName, corrTableName, currentAccessPath, hashKeyColumns, initialCapacity, level, LOAD_PLAN, loadFactor, maxCapacity, origTableName, REMOVE_PLAN, tableNumber, tableProperties, trulyTheBestAccessPath, userSpecifiedJoinStrategyFields inherited from class QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX -
Constructor Summary
ConstructorsConstructorDescriptionRowResultSetNode(ResultColumnList valuesClause, Properties tableProperties, ContextManager cm) Constructor for a RowResultSetNode. -
Method Summary
Modifier and TypeMethodDescription(package private) ResultSetNodeaddNewPredicate(Predicate predicate) Add a new predicate to the list.(package private) voidNotify the underlying result set tree that the optimizer has chosen to "eliminate" a sort.(package private) voidbindExpressions(FromList fromListParam) Bind the expressions in this RowResultSetNode.(package private) voidbindExpressionsWithTables(FromList fromListParam) Bind the expressions in this ResultSetNode if it has tables.(package private) ResultSetNodebindNonVTITables(DataDictionary dataDictionary, FromList fromListParam) Bind the non VTI tables in this ResultSetNode.(package private) voidbindTargetExpressions(FromList fromListParam) Bind the expressions in the target list.(package private) voidbindUntypedNullsToResultColumns(ResultColumnList bindingRCL) Bind any untyped null nodes to the types in the given ResultColumnList.private boolean(package private) ResultSetNodeenhanceRCLForInsert(InsertNode target, boolean inOrder, int[] colMap) Modify the RCL of this node to match the target of the insert.(package private) ResultSetNodeensurePredicateList(int numTables) Ensure that the top of the RSN tree has a PredicateList.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) booleanflattenableInFromSubquery(FromList fromList) Evaluate whether or not the subquery in a FromSubquery is flattenable.(package private) voidgenerate(ActivationClassBuilder acb, MethodBuilder mb) The generated ResultSet will be: RowResultSet -- for the VALUES clause(package private) StringGet the exposed name for this table, which is the name that can be used to refer to it in the rest of the query.(package private) ResultColumngetMatchingColumn(ColumnReference columnReference) Try to find a ResultColumn in the table represented by this FromTable that matches the name in the given ColumnReference.modifyAccessPath(JBitSet outerTables) Modify the access path for this Optimizable, as necessary.(package private) ResultSetNodeModify the access paths according to the decisions the optimizer made.(package private) ResultSetNodeoptimize(DataDictionary dataDictionary, PredicateList predicateList, double outerRows) Optimize this SelectNode.(package private) voidoptimizeSubqueries(DataDictionary dd, double rowCount) Optimize any subqueries that haven't been optimized any where else.(package private) ResultSetNodepreprocess(int numTables, GroupByList gbl, FromList fromList) Put a ProjectRestrictNode on top of each FromTable in the FromList.(package private) voidprintSubNodes(int depth) Prints the sub-nodes of this object.(package private) voidpushOffsetFetchFirst(ValueNode offset, ValueNode fetchFirst, boolean hasJDBClimitClause) Push down the offset and fetch first parameters, if any, to this node.(package private) voidpushOrderByList(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.voidSet up a new level for order by and fetch/offset clauses.booleanReturn true if the node references SESSION schema tables (temporary or permanent)(package private) voidreplaceOrForbidDefaults(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) booleanReturn whether or not this ResultSet tree is guaranteed to return at most 1 row based on heuristics.(package private) voidsetTableConstructorTypes(ResultColumnList typeColumns) Set the type of each parameter in the result column list for this table constructor.(package private) String(package private) voidverifySelectStarSubquery(FromList outerFromList, int subqueryType) Verify that a SELECT * is valid for this type of subquery.Methods inherited from class FromTable
acceptChildren, assignCostEstimate, canBeOrdered, columnsAreUpdatable, considerSortAvoidancePath, convertAbsoluteToRelativeColumnPosition, cursorTargetTable, decrementLevel, feasibleJoinStrategy, fillInReferencedTableMap, flatten, forUpdate, getBaseTableName, getBestAccessPath, getBestSortAvoidancePath, getCorrelationName, getCostEstimate, getCurrentAccessPath, getFinalCostEstimate, getFromTableByName, 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, needsSpecialRCLBinding, nextAccessPath, optimizeIt, pullOptPredicates, pushExpressions, pushOptPredicate, rememberAsBest, rememberJoinStrategyAsBest, rememberSortAvoidancePath, resetJoinStrategies, setCostEstimateCost, setHashKeyColumns, setLevel, setMergeTableID, setOrigTableName, setProperties, setTableNumber, startOptimizing, supportsMultipleInstantiations, tellRowOrderingAboutConstantColumns, toString, transformOuterJoins, uniqueJoin, updateBestPlanMap, verifyPropertiesMethods inherited from class ResultSetNode
adjustForSortElimination, assignResultSetNumber, bindResultColumns, bindResultColumns, bindVTITables, changeAccessPath, columnTypesAndLengthsMatch, considerMaterialization, generateNormalizationResultSet, generateResultSet, genProjectRestrict, genProjectRestrict, genProjectRestrictForReordering, getAllResultColumns, getCandidateFinalCostEstimate, getCostEstimate, getCursorTargetTable, getFromList, 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, performMaterialization, printQueryExpressionSuffixClauses, projectResultColumns, referencesTarget, rejectParameters, rejectXMLValues, renameGeneratedResultNames, setCandidateFinalCostEstimate, setCostEstimate, setCursorTargetTable, setInsertSource, setOptimizer, setReferencedTableMap, setResultColumns, setResultSetNumber, setResultToBooleanTrueNode, setScratchCostEstimate, subqueryReferencesTarget, updateTargetLockModeMethods inherited from class 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, verifyClassExistMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Optimizable
getDataDictionary, getOptimizerTracer, getReferencedTableMap, getResultSetNumber, optimizerTracingIsOnMethods inherited from interface Visitable
accept, addTag, taggedWith
-
Field Details
-
subquerys
SubqueryList subquerys -
aggregates
-
qec
-
-
Constructor Details
-
RowResultSetNode
RowResultSetNode(ResultColumnList valuesClause, Properties tableProperties, ContextManager cm) Constructor for a RowResultSetNode.- Parameters:
valuesClause- The result column list for the VALUES clause.tableProperties- Properties list associated with the tablecm- The context manager
-
-
Method Details
-
statementToString
String statementToString() -
printSubNodes
void printSubNodes(int depth) Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.- Overrides:
printSubNodesin classResultSetNode- Parameters:
depth- The depth of this node in the tree
-
referencesSessionSchema
Description copied from class:QueryTreeNodeReturn true if the node references SESSION schema tables (temporary or permanent)- Overrides:
referencesSessionSchemain classQueryTreeNode- Returns:
- true if references SESSION schema tables, else false
- Throws:
StandardException- Thrown on error
-
enhanceRCLForInsert
ResultSetNode enhanceRCLForInsert(InsertNode target, boolean inOrder, int[] colMap) throws StandardException Modify the RCL of this node to match the target of the insert.- Overrides:
enhanceRCLForInsertin classResultSetNode- Parameters:
target- the target node for the insertinOrder- are source cols in same order as target cols?colMap- int array representation of correspondence between RCLs - colmap[i] = -1 -> missing in current RCL colmap[i] = j -> targetRCL(i) <-> thisRCL(j+1)- Returns:
- a node that replaces this node and whose RCL matches the target RCL. May return this node if no changes to the RCL are needed, or if the RCL is modified in-place.
- Throws:
StandardException- Thrown on error
-
estimateCost
public CostEstimate estimateCost(OptimizablePredicateList predList, ConglomerateDescriptor cd, CostEstimate outerCost, Optimizer optimizer, RowOrdering rowOrdering) throws StandardException Description copied from interface:OptimizableEstimate 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:
estimateCostin interfaceOptimizable- Overrides:
estimateCostin 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:
-
bindNonVTITables
ResultSetNode bindNonVTITables(DataDictionary dataDictionary, FromList fromListParam) throws StandardException Bind the non VTI tables in this ResultSetNode. This includes getting their descriptors from the data dictionary and numbering them.- Overrides:
bindNonVTITablesin classResultSetNode- Parameters:
dataDictionary- The DataDictionary to use for bindingfromListParam- FromList to use/append to.- Returns:
- ResultSetNode
- Throws:
StandardException- Thrown on error
-
bindExpressions
Bind the expressions in this RowResultSetNode. This means binding the sub-expressions, as well as figuring out what the return type is for each expression.- Overrides:
bindExpressionsin classResultSetNode- Parameters:
fromListParam- FromList to use/append to.- Throws:
StandardException- Thrown on error
-
bindExpressionsWithTables
Bind the expressions in this ResultSetNode if it has tables. This means binding the sub-expressions, as well as figuring out what the return type is for each expression.- Overrides:
bindExpressionsWithTablesin classResultSetNode- Parameters:
fromListParam- FromList to use/append to.- Throws:
StandardException- Thrown on error
-
bindTargetExpressions
Bind the expressions in the target list. This means binding the sub-expressions, as well as figuring out what the return type is for each expression. This is useful for EXISTS subqueries, where we need to validate the target list before blowing it away and replacing it with a SELECT true.- Overrides:
bindTargetExpressionsin classResultSetNode- Throws:
StandardException- Thrown on error
-
bindUntypedNullsToResultColumns
Bind any untyped null nodes to the types in the given ResultColumnList.- Overrides:
bindUntypedNullsToResultColumnsin classResultSetNode- Parameters:
bindingRCL- The ResultColumnList with the types to bind to.- Throws:
StandardException- Thrown on error
-
getMatchingColumn
Try to find a ResultColumn in the table represented by this FromTable that matches the name in the given ColumnReference.- Overrides:
getMatchingColumnin classResultSetNode- Parameters:
columnReference- The columnReference whose name we're looking for in the given table.- Returns:
- A ResultColumn whose expression is the ColumnNode that matches the ColumnReference. Returns null if there is no match.
- Throws:
StandardException- Thrown on error
-
getExposedName
Get the exposed name for this table, which is the name that can be used to refer to it in the rest of the query.- Overrides:
getExposedNamein classFromTable- Returns:
- The exposed name of this table.
- Throws:
StandardException- Thrown on error
-
verifySelectStarSubquery
Verify that a SELECT * is valid for this type of subquery.- Overrides:
verifySelectStarSubqueryin classResultSetNode- Parameters:
outerFromList- The FromList from the outer query block(s)subqueryType- The subquery type- Throws:
StandardException- Thrown on error
-
pushQueryExpressionSuffix
public void pushQueryExpressionSuffix()Description copied from class:ResultSetNodeSet up a new level for order by and fetch/offset clauses. See Javadoc forResultSetNode.QueryExpressionClauses. Overridden by implementors of pushOrderByNode, pushOffsetFetchFirst.- Overrides:
pushQueryExpressionSuffixin classResultSetNode
-
pushOrderByList
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.- Overrides:
pushOrderByListin classResultSetNode- Parameters:
orderByList- The order by list
-
pushOffsetFetchFirst
Push down the offset and fetch first parameters, if any, to this node.- Overrides:
pushOffsetFetchFirstin classResultSetNode- Parameters:
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 clause
-
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:
preprocessin 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
-
ensurePredicateList
Ensure that the top of the RSN tree has a PredicateList.- Overrides:
ensurePredicateListin 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
-
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:
addNewPredicatein classResultSetNode- Parameters:
predicate- The predicate to add- Returns:
- ResultSetNode The new top of the tree.
- 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 or a RowResultSetNode (not a UnionNode) 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. o There is at least one result set in the from list that is not a RowResultSetNode (the reason is to avoid having an outer SelectNode with an empty FromList.- Overrides:
flattenableInFromSubqueryin classResultSetNode- Parameters:
fromList- The outer from list- Returns:
- boolean Whether or not the FromSubquery is flattenable.
-
optimize
ResultSetNode optimize(DataDictionary dataDictionary, PredicateList predicateList, double outerRows) throws StandardException Optimize this SelectNode. This means choosing the best access path for each table, among other things.- Overrides:
optimizein classResultSetNode- Parameters:
dataDictionary- The DataDictionary to use for optimizationpredicateList- The predicate list to optimize againstouterRows- The number of outer joining rows- Returns:
- ResultSetNode The top of the optimized tree
- Throws:
StandardException- Thrown on error
-
modifyAccessPath
Description copied from interface:OptimizableModify 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:
modifyAccessPathin interfaceOptimizable- Overrides:
modifyAccessPathin classFromTable- 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:
-
modifyAccessPaths
Description copied from class:ResultSetNodeModify the access paths according to the decisions the optimizer made. This can include adding project/restrict nodes, index-to-base-row nodes, etc.- Overrides:
modifyAccessPathsin classResultSetNode- Returns:
- The modified query tree
- Throws:
StandardException- Thrown on error- See Also:
-
returnsAtMostOneRow
boolean returnsAtMostOneRow()Return whether or not this ResultSet tree is guaranteed to return at most 1 row based on heuristics. (A RowResultSetNode and a SELECT with a non-grouped aggregate will return at most 1 row.)- Overrides:
returnsAtMostOneRowin classResultSetNode- Returns:
- Whether or not this ResultSet tree is guaranteed to return at most 1 row based on heuristics.
-
setTableConstructorTypes
Set the type of each parameter in the result column list for this table constructor.- Overrides:
setTableConstructorTypesin classResultSetNode- Parameters:
typeColumns- The ResultColumnList containing the desired result types.- Throws:
StandardException- Thrown on error
-
generate
The generated ResultSet will be: RowResultSet -- for the VALUES clause- Overrides:
generatein classQueryTreeNode- Parameters:
acb- The ActivationClassBuilder for the class being builtmb- The method for the generated code to go into- Throws:
StandardException- Thrown on error
-
replaceOrForbidDefaults
void replaceOrForbidDefaults(TableDescriptor ttd, ResultColumnList tcl, boolean allowDefaults) throws StandardException Replace any DEFAULTs with the associated tree for the default if allowed, or flag (when inside top level set operator nodes). Subqueries are checked for illegal DEFAULTs elsewhere.- Overrides:
replaceOrForbidDefaultsin classResultSetNode- Parameters:
ttd- The TableDescriptor for the target table.tcl- The RCL for the target table.allowDefaults- true if allowed- Throws:
StandardException- Thrown on error
-
optimizeSubqueries
Optimize any subqueries that haven't been optimized any where else. This is useful for a RowResultSetNode as a derived table because it doesn't get optimized otherwise.- Overrides:
optimizeSubqueriesin classFromTable- Throws:
StandardException- Thrown on error
-
adjustForSortElimination
void adjustForSortElimination()Description copied from class:ResultSetNodeNotify 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:
adjustForSortEliminationin classResultSetNode- See Also:
-
canWeCacheResults
- Throws:
StandardException
-