|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.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
org.apache.derby.impl.sql.compile.GroupByNode
A GroupByNode represents a result set for a grouping operation on a select. Note that this includes a SELECT with aggregates and no grouping columns (in which case the select list is null) It has the same description as its input result set.
For the most part, it simply delegates operations to its bottomPRSet, which is currently expected to be a ProjectRestrictResultSet generated for a SelectNode.
NOTE: A GroupByNode extends FromTable since it can exist in a FromList.
There is a lot of room for optimizations here:
| Field Summary | |
private boolean |
addDistinctAggregate
|
private int |
addDistinctAggregateColumnNum
|
private AggregatorInfoList |
aggInfo
Information that is used at execution time to process aggregates. |
(package private) java.util.Vector |
aggregateVector
The list of all aggregates in the query block that contains this group by. |
(package private) ResultSetNode |
childResult
ResultSetNode under the SingleChildResultSetNode |
(package private) GroupByList |
groupingList
The GROUP BY list |
protected boolean |
hasTrulyTheBestAccessPath
|
private boolean |
isInSortedOrder
|
(package private) FromTable |
parent
The parent to the GroupByNode. |
private boolean |
singleInputRowOptimization
|
| 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 | |
GroupByNode()
|
|
| Method Summary | |
Visitable |
accept(Visitor v)
Accept a visitor, and call v.visit() on child nodes as necessary. |
private void |
addAggregates()
Add the extra result columns required by the aggregates to the result list. |
private void |
addDistinctAggregatesToOrderBy()
Add any distinct aggregates to the order by list. |
private void |
addNewColumnsForAggregation()
Add a whole slew of columns needed for aggregation. |
ResultSetNode |
addNewPredicate(Predicate predicate)
Add a new predicate to the list. |
private void |
addNewPRNode()
Add a new PR node for aggregation. |
ResultSetNode |
changeAccessPath()
The optimizer's decision on the access path for a result set may require the generation of extra result sets. |
(package private) void |
considerPostOptimizeOptimizations(boolean selectHasPredicates)
Consider any optimizations after the optimizer has chosen a plan. |
(package private) void |
decrementLevel(int decrement)
Decrement (query block) level (0-based) for this FromTable. |
ResultSetNode |
ensurePredicateList(int numTables)
Ensure that the top of the RSN tree has a PredicateList. |
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. |
boolean |
flattenableInFromSubquery(FromList fromList)
Evaluate whether or not the subquery in a FromSubquery is flattenable. |
boolean |
forUpdate()
Return true if this is the target table of an update |
void |
generate(ActivationClassBuilder acb,
MethodBuilder mb)
generate the sort result set operating over the source resultset. |
private void |
genGroupedAggregateResultSet(ActivationClassBuilder acb,
MethodBuilder mb)
Generate the code to evaluate grouped aggregates. |
private void |
genScalarAggregateResultSet(ActivationClassBuilder acb,
MethodBuilder mb)
Generate the code to evaluate scalar aggregates. |
ResultSetNode |
getChildResult()
Return the childResult from this node. |
private ResultColumn |
getColumnReference(ResultColumn targetRC,
DataDictionary dd)
Method for creating a new result column referencing the one passed in. |
CostEstimate |
getFinalCostEstimate()
Get the final CostEstimate for this node. |
protected 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) boolean |
getIsInSortedOrder()
Get whether or not the source is in sorted order. |
FromTable |
getParent()
Return the parent node to this one, if there is one. |
AccessPath |
getTrulyTheBestAccessPath()
Get the best access path overall for this Optimizable. |
void |
init(java.lang.Object childResult,
java.lang.Object tableProperties)
Initialilzer for a SingleChildResultSetNode. |
void |
init(java.lang.Object bottomPR,
java.lang.Object groupingList,
java.lang.Object aggregateVector,
java.lang.Object tableProperties)
Intializer for a GroupByNode. |
void |
initAccessPaths(Optimizer optimizer)
Init the access paths for this optimizable. |
boolean |
isNotExists()
Return whether or not the underlying ResultSet tree is for a NOT EXISTS join. |
boolean |
isOneRowResultSet()
Return whether or not the underlying ResultSet tree will return a single row, at most. |
(package private) boolean |
isOrderedOn(ColumnReference[] crs,
boolean permuteOrdering,
java.util.Vector fbtVector)
Return whether or not the underlying ResultSet tree is ordered on the specified columns. |
(package private) ResultColumnDescriptor[] |
makeResultDescriptors(ExecutionContext ec)
|
(package private) void |
markOrderingDependent()
Notify the underlying result set tree that the result is ordering dependent. |
ResultSetNode |
modifyAccessPaths()
Modify the access paths according to the decisions the optimizer made. |
ResultSetNode |
optimize(DataDictionary dataDictionary,
PredicateList predicates,
double outerRows)
Optimize this GroupByNode. |
CostEstimate |
optimizeIt(Optimizer optimizer,
OptimizablePredicateList predList,
CostEstimate outerCost,
RowOrdering rowOrdering)
Choose the best access path for this Optimizable. |
ResultSetNode |
preprocess(int numTables,
GroupByList gbl,
FromList fromList)
Put a ProjectRestrictNode on top of each FromTable in the FromList. |
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. |
void |
pushExpressions(PredicateList predicateList)
Push expressions down to the first ResultSetNode which can do expression evaluation and has the same referenced table map. |
boolean |
pushOptPredicate(OptimizablePredicate optimizablePredicate)
Push an OptimizablePredicate down, if this node accepts it. |
boolean |
referencesSessionSchema()
Return true if the node references SESSION schema tables (temporary or permanent) |
boolean |
referencesTarget(java.lang.String name,
boolean baseTable)
Search to see if a query references the specifed table name. |
protected boolean |
reflectionNeededForProjection()
Determine whether we need to do reflection in order to do the projection. |
(package private) void |
replaceDefaults(TableDescriptor ttd,
ResultColumnList tcl)
Replace any DEFAULTs with the associated tree for the default. |
(package private) void |
setChildResult(ResultSetNode childResult)
Set the childResult for this node. |
void |
setLevel(int level)
Set the (query block) level (0-based) for this FromTable. |
(package private) boolean |
subqueryReferencesTarget(java.lang.String name,
boolean baseTable)
Return whether or not this ResultSetNode contains a subquery with a reference to the specified target. |
java.lang.String |
toString()
Convert this object to a String. |
int |
updateTargetLockMode()
Get the lock mode for the target of an update statement (a delete or update). |
| 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 |
GroupByList groupingList
java.util.Vector aggregateVector
private AggregatorInfoList aggInfo
FromTable parent
private boolean addDistinctAggregate
private boolean singleInputRowOptimization
private int addDistinctAggregateColumnNum
private boolean isInSortedOrder
ResultSetNode childResult
protected boolean hasTrulyTheBestAccessPath
| Constructor Detail |
public GroupByNode()
| Method Detail |
public void init(java.lang.Object bottomPR,
java.lang.Object groupingList,
java.lang.Object aggregateVector,
java.lang.Object tableProperties)
throws StandardException
init in class QueryTreeNodebottomPR - The child FromTablegroupingList - The groupingListaggregateVector - The vector of aggregates from
the query block. Since aggregation is done
at the same time as grouping, we need them
here.tableProperties - Properties list associated with the table
StandardException - Thrown on errorboolean getIsInSortedOrder()
private void addAggregates()
throws StandardException
standard - exception
StandardExceptionprivate void addDistinctAggregatesToOrderBy()
private void addNewPRNode()
throws StandardException
standard - exception
StandardException
private void addNewColumnsForAggregation()
throws StandardException
At this point this is invoked, we have the following tree:
For each ColumnReference in PR RCL
standard - exception
StandardExceptionpublic FromTable getParent()
public CostEstimate optimizeIt(Optimizer optimizer,
OptimizablePredicateList predList,
CostEstimate outerCost,
RowOrdering rowOrdering)
throws StandardException
Optimizable
optimizeIt in interface OptimizableoptimizeIt in class FromTableStandardException - Thrown on errorOptimizable.optimizeIt(org.apache.derby.iapi.sql.compile.Optimizer, org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.compile.CostEstimate, org.apache.derby.iapi.sql.compile.RowOrdering)
public CostEstimate estimateCost(OptimizablePredicateList predList,
ConglomerateDescriptor cd,
CostEstimate outerCost,
Optimizer optimizer,
RowOrdering rowOrdering)
throws StandardException
Optimizable
estimateCost in interface OptimizableestimateCost in class FromTableStandardException - Thrown on errorOptimizable.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)
public boolean pushOptPredicate(OptimizablePredicate optimizablePredicate)
throws StandardException
Optimizable
pushOptPredicate in interface OptimizablepushOptPredicate in class FromTableStandardException - Thrown on errorOptimizable.pushOptPredicate(org.apache.derby.iapi.sql.compile.OptimizablePredicate)public java.lang.String toString()
toString in class FromTablepublic boolean flattenableInFromSubquery(FromList fromList)
flattenableInFromSubquery in class SingleChildResultSetNodefromList - The outer from list
public ResultSetNode optimize(DataDictionary dataDictionary,
PredicateList predicates,
double outerRows)
throws StandardException
optimize in class SingleChildResultSetNodedataDictionary - The DataDictionary to use for optimizationouterRows - The number of outer joining rows
StandardException - Thrown on errorResultColumnDescriptor[] makeResultDescriptors(ExecutionContext ec)
makeResultDescriptors in class ResultSetNode
public boolean isOneRowResultSet()
throws StandardException
isOneRowResultSet in class SingleChildResultSetNodeStandardException - Thrown on error
public void generate(ActivationClassBuilder acb,
MethodBuilder mb)
throws StandardException
generate in class QueryTreeNodeacb - The ActivationClassBuilder for the class being builtmb - The method for the generated code to go into
StandardException - Thrown on error
private void genScalarAggregateResultSet(ActivationClassBuilder acb,
MethodBuilder mb)
private void genGroupedAggregateResultSet(ActivationClassBuilder acb,
MethodBuilder mb)
throws StandardException
StandardException
private ResultColumn getColumnReference(ResultColumn targetRC,
DataDictionary dd)
throws StandardException
targetRC - the sourcedd -
StandardException - on error
void considerPostOptimizeOptimizations(boolean selectHasPredicates)
throws StandardException
selectHasPredicates - true if SELECT containing this
vector/scalar aggregate has a restriction
StandardException - on error
public void init(java.lang.Object childResult,
java.lang.Object tableProperties)
init in class FromTablechildResult - The child ResultSetNodetableProperties - Properties list associated with the tablepublic AccessPath getTrulyTheBestAccessPath()
Optimizable
getTrulyTheBestAccessPath in interface OptimizablegetTrulyTheBestAccessPath in class FromTableOptimizable.getTrulyTheBestAccessPath()public ResultSetNode getChildResult()
void setChildResult(ResultSetNode childResult)
childResult - The new childResult for this node.
public void pullOptPredicates(OptimizablePredicateList optimizablePredicates)
throws StandardException
Optimizable
pullOptPredicates in interface OptimizablepullOptPredicates in class FromTableStandardException - Thrown on errorOptimizable.pullOptPredicates(org.apache.derby.iapi.sql.compile.OptimizablePredicateList)public boolean forUpdate()
Optimizable
forUpdate in interface OptimizableforUpdate in class FromTableOptimizable.forUpdate()public void initAccessPaths(Optimizer optimizer)
Optimizable
initAccessPaths in interface OptimizableinitAccessPaths in class FromTableOptimizable.initAccessPaths(org.apache.derby.iapi.sql.compile.Optimizer)public void printSubNodes(int depth)
printSubNodes in class ResultSetNodedepth - The depth of this node in the tree
public boolean referencesTarget(java.lang.String name,
boolean baseTable)
throws StandardException
referencesTarget in class ResultSetNodename - Table name (String) to search for.baseTable - Whether or not name is for a base table
StandardException - Thrown on error
public boolean referencesSessionSchema()
throws StandardException
referencesSessionSchema in class QueryTreeNodeStandardException - Thrown on errorpublic void setLevel(int level)
setLevel in class FromTablelevel - The query block level for this FromTable.
boolean subqueryReferencesTarget(java.lang.String name,
boolean baseTable)
throws StandardException
subqueryReferencesTarget in class ResultSetNodename - The table name.baseTable - Whether or not the name is for a base table.
StandardException - Thrown on error
public ResultSetNode preprocess(int numTables,
GroupByList gbl,
FromList fromList)
throws StandardException
preprocess in class ResultSetNodenumTables - Number of tables in the DML Statementgbl - The group by list, if anyfromList - The from list, if any
StandardException - Thrown on error
public ResultSetNode addNewPredicate(Predicate predicate)
throws StandardException
addNewPredicate in class ResultSetNodepredicate - The predicate to add
StandardException - Thrown on error
public void pushExpressions(PredicateList predicateList)
throws StandardException
pushExpressions in class FromTablepredicateList - The PredicateList.
StandardException - Thrown on error
public ResultSetNode ensurePredicateList(int numTables)
throws StandardException
ensurePredicateList in class ResultSetNodenumTables - The number of tables in the query.
StandardException - Thrown on error
public ResultSetNode modifyAccessPaths()
throws StandardException
ResultSetNode
modifyAccessPaths in class ResultSetNodeStandardException - Thrown on errorResultSetNode.modifyAccessPaths()
public ResultSetNode changeAccessPath()
throws StandardException
ResultSetNode
changeAccessPath in class ResultSetNodeStandardException - Thrown on errorResultSetNode.changeAccessPath()
protected FromTable getFromTableByName(java.lang.String name,
java.lang.String schemaName,
boolean exactMatch)
throws StandardException
getFromTableByName in class FromTablename - 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 errorvoid decrementLevel(int decrement)
decrementLevel in class FromTabledecrement - The amount to decrement by.public int updateTargetLockMode()
updateTargetLockMode in class ResultSetNodeTransactionController
boolean isOrderedOn(ColumnReference[] crs,
boolean permuteOrdering,
java.util.Vector fbtVector)
throws StandardException
isOrderedOn in class ResultSetNodecrs - The specified ColumnReference[]permuteOrdering - Whether or not the order of the CRs in the array can be permutedfbtVector - Vector that is to be filled with the FromBaseTable
StandardException - Thrown on errorpublic boolean isNotExists()
isNotExists in class ResultSetNodeprotected boolean reflectionNeededForProjection()
void replaceDefaults(TableDescriptor ttd,
ResultColumnList tcl)
throws StandardException
replaceDefaults in class ResultSetNodettd - The TableDescriptor for the target table.tcl - The RCL for the target table.
StandardException - Thrown on errorvoid markOrderingDependent()
markOrderingDependent in class ResultSetNodepublic CostEstimate getFinalCostEstimate()
getFinalCostEstimate in class ResultSetNode
public Visitable accept(Visitor v)
throws StandardException
accept in interface Visitableaccept in class ResultSetNodev - the visitor
StandardException - on error
|
Built on Tue 2006-10-10 19:23:47+0200, from revision exported | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||