Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.derby.impl.sql.compile
Class GroupByNode  view GroupByNode download GroupByNode.java

java.lang.Object
  extended byorg.apache.derby.impl.sql.compile.QueryTreeNode
      extended byorg.apache.derby.impl.sql.compile.ResultSetNode
          extended byorg.apache.derby.impl.sql.compile.FromTable
              extended byorg.apache.derby.impl.sql.compile.SingleChildResultSetNode
                  extended byorg.apache.derby.impl.sql.compile.GroupByNode
All Implemented Interfaces:
org.apache.derby.iapi.sql.compile.Optimizable, org.apache.derby.iapi.sql.compile.Visitable

public class GroupByNode
extends SingleChildResultSetNode

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  org.apache.derby.impl.sql.execute.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
 org.apache.derby.iapi.sql.compile.Visitable accept(org.apache.derby.iapi.sql.compile.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.
 org.apache.derby.iapi.sql.compile.CostEstimate estimateCost(org.apache.derby.iapi.sql.compile.OptimizablePredicateList predList, org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor cd, org.apache.derby.iapi.sql.compile.CostEstimate outerCost, org.apache.derby.iapi.sql.compile.Optimizer optimizer, org.apache.derby.iapi.sql.compile.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, org.apache.derby.iapi.services.compiler.MethodBuilder mb)
          generate the sort result set operating over the source resultset.
private  void genGroupedAggregateResultSet(ActivationClassBuilder acb, org.apache.derby.iapi.services.compiler.MethodBuilder mb)
          Generate the code to evaluate grouped aggregates.
private  void genScalarAggregateResultSet(ActivationClassBuilder acb, org.apache.derby.iapi.services.compiler.MethodBuilder mb)
          Generate the code to evaluate scalar aggregates.
 ResultSetNode getChildResult()
          Return the childResult from this node.
private  ResultColumn getColumnReference(ResultColumn targetRC, org.apache.derby.iapi.sql.dictionary.DataDictionary dd)
          Method for creating a new result column referencing the one passed in.
 org.apache.derby.iapi.sql.compile.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.
 org.apache.derby.iapi.sql.compile.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(org.apache.derby.iapi.sql.compile.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)  org.apache.derby.iapi.sql.ResultColumnDescriptor[] makeResultDescriptors(org.apache.derby.iapi.sql.execute.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(org.apache.derby.iapi.sql.dictionary.DataDictionary dataDictionary, PredicateList predicates, double outerRows)
          Optimize this GroupByNode.
 org.apache.derby.iapi.sql.compile.CostEstimate optimizeIt(org.apache.derby.iapi.sql.compile.Optimizer optimizer, org.apache.derby.iapi.sql.compile.OptimizablePredicateList predList, org.apache.derby.iapi.sql.compile.CostEstimate outerCost, org.apache.derby.iapi.sql.compile.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(org.apache.derby.iapi.sql.compile.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(org.apache.derby.iapi.sql.compile.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(org.apache.derby.iapi.sql.dictionary.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 org.apache.derby.impl.sql.compile.FromTable
areAllColumnsProjected, assignCostEstimate, canBeOrdered, considerSortAvoidancePath, convertAbsoluteToRelativeColumnPosition, cursorTargetTable, feasibleJoinStrategy, fillInReferencedTableMap, flatten, getBaseTableName, getBestAccessPath, getBestSortAvoidancePath, getCostEstimate, getCurrentAccessPath, getExposedName, getLevel, getName, getNumColumnsReturned, getProperties, getResultColumnsForList, getSchemaDescriptor, getSchemaDescriptor, getScratchCostEstimate, getTableDescriptor, getTableName, getTableNumber, getUserSpecifiedJoinStrategy, hashKeyColumns, hasTableNumber, initialCapacity, isBaseTable, isCoveringIndex, isFlattenableJoinNode, isMaterializable, isOneRowScan, isTargetTable, legalJoinOrder, loadFactor, LOJ_reorderable, markUpdatableByCursor, maxCapacity, memoryUsageOK, modifyAccessPath, needsSpecialRCLBinding, nextAccessPath, optimizeSubqueries, rememberAsBest, rememberJoinStrategyAsBest, rememberSortAvoidancePath, resetJoinStrategies, setAllColumnsProjected, setCostEstimate, setHashKeyColumns, setProperties, setTableNumber, startOptimizing, supportsMultipleInstantiations, tellRowOrderingAboutConstantColumns, transformOuterJoins, uniqueJoin, verifyProperties
 
Methods inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
assignResultSetNumber, bindExpressions, bindExpressionsWithTables, bindNonVTITables, bindResultColumns, bindResultColumns, bindTargetExpressions, bindUntypedNullsToResultColumns, bindVTITables, closeMethodArgument, columnTypesAndLengthsMatch, considerMaterialization, enhanceRCLForInsert, generateNormalizationResultSet, generateResultSet, genNewRCForInsert, genNormalizeResultSetNode, genProjectRestrict, genProjectRestrict, genProjectRestrictForReordering, getAllResultColumns, getCostEstimate, getCursorTargetTable, getFromList, getMatchingColumn, getNewCostEstimate, getOptimizer, getReferencedTableMap, getResultColumns, getResultSetNumber, isPossibleDistinctScan, isUpdatableCursor, LOJgetReferencedTables, makeResultDescription, markAsCursorTargetTable, markForDistinctScan, markStatementResultSet, notCursorTargetTable, notFlattenableJoin, numDistinctAggregates, parseDefault, performMaterialization, projectResultColumns, pushOrderByList, rejectParameters, rejectXMLValues, renameGeneratedResultNames, returnsAtMostOneRow, setInsertSource, setReferencedTableMap, setResultColumns, setResultToBooleanTrueNode, setTableConstructorTypes, verifySelectStarSubquery
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
bind, convertDefaultNode, debugFlush, debugPrint, executeSchemaName, executeStatementName, formatNodeString, foundString, generate, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getSPSName, getStatementType, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, init, init, isAtomic, isInstanceOf, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, needsSavepoint, nodeHeader, optimize, parseQueryText, printLabel, resolveTableToSynonym, setBeginOffset, setContextManager, setEndOffset, setNodeType, setRefActionInfo, 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, getReferencedTableMap, getResultSetNumber
 

Field Detail

groupingList

GroupByList groupingList
The GROUP BY list


aggregateVector

java.util.Vector aggregateVector
The list of all aggregates in the query block that contains this group by.


aggInfo

private org.apache.derby.impl.sql.execute.AggregatorInfoList aggInfo
Information that is used at execution time to process aggregates.


parent

FromTable parent
The parent to the GroupByNode. If we need to generate a ProjectRestrict over the group by then this is set to that node. Otherwise it is null.


addDistinctAggregate

private boolean addDistinctAggregate

singleInputRowOptimization

private boolean singleInputRowOptimization

addDistinctAggregateColumnNum

private int addDistinctAggregateColumnNum

isInSortedOrder

private boolean isInSortedOrder

childResult

ResultSetNode childResult
ResultSetNode under the SingleChildResultSetNode


hasTrulyTheBestAccessPath

protected boolean hasTrulyTheBestAccessPath
Constructor Detail

GroupByNode

public GroupByNode()
Method Detail

init

public void init(java.lang.Object bottomPR,
                 java.lang.Object groupingList,
                 java.lang.Object aggregateVector,
                 java.lang.Object tableProperties)
          throws org.apache.derby.iapi.error.StandardException
Intializer for a GroupByNode.

Overrides:
init in class QueryTreeNode

getIsInSortedOrder

boolean getIsInSortedOrder()
Get whether or not the source is in sorted order.


addAggregates

private void addAggregates()
                    throws org.apache.derby.iapi.error.StandardException
Add the extra result columns required by the aggregates to the result list.


addDistinctAggregatesToOrderBy

private void addDistinctAggregatesToOrderBy()
Add any distinct aggregates to the order by list. Asserts that there are 0 or more distincts.


addNewPRNode

private void addNewPRNode()
                   throws org.apache.derby.iapi.error.StandardException
Add a new PR node for aggregation. Put the new PR under the sort.


addNewColumnsForAggregation

private void addNewColumnsForAggregation()
                                  throws org.apache.derby.iapi.error.StandardException
Add a whole slew of columns needed for aggregation. Basically, for each aggregate we add 2 columns: the aggregate input expression and the aggregator column. The input expression is taken directly from the aggregator node. The aggregator is the run time aggregator. We add it to the RC list as a new object coming into the sort node.

At this point this is invoked, we have the following tree:

    PR - (PARENT): RCL is the original select list | PR - GROUP BY: RCL is empty | PR - FROM TABLE: RCL is empty

For each ColumnReference in PR RCL

  • clone the ref
  • create a new RC in the bottom RCL and set it to the col ref
  • create a new RC in the GROUPBY RCL and set it to point to the bottom RC
  • reset the top PR ref to point to the new GROUPBY RC For each aggregate in aggregateVector
    • create RC in FROM TABLE. Fill it with aggs Operator.
    • create RC in FROM TABLE for agg result
    • create RC in FROM TABLE for aggregator
    • create RC in GROUPBY for agg input, set it to point to FROM TABLE RC
    • create RC in GROUPBY for agg result
    • create RC in GROUPBY for aggregator
    • replace Agg with reference to RC for agg result

getParent

public FromTable getParent()
Return the parent node to this one, if there is one. It will return 'this' if there is no generated node above this one.


optimizeIt

public org.apache.derby.iapi.sql.compile.CostEstimate optimizeIt(org.apache.derby.iapi.sql.compile.Optimizer optimizer,
                                                                 org.apache.derby.iapi.sql.compile.OptimizablePredicateList predList,
                                                                 org.apache.derby.iapi.sql.compile.CostEstimate outerCost,
                                                                 org.apache.derby.iapi.sql.compile.RowOrdering rowOrdering)
                                                          throws org.apache.derby.iapi.error.StandardException
Description copied from interface: org.apache.derby.iapi.sql.compile.Optimizable
Choose the best access path for this Optimizable.

Specified by:
optimizeIt in interface org.apache.derby.iapi.sql.compile.Optimizable
Overrides:
optimizeIt in class FromTable

estimateCost

public org.apache.derby.iapi.sql.compile.CostEstimate estimateCost(org.apache.derby.iapi.sql.compile.OptimizablePredicateList predList,
                                                                   org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor cd,
                                                                   org.apache.derby.iapi.sql.compile.CostEstimate outerCost,
                                                                   org.apache.derby.iapi.sql.compile.Optimizer optimizer,
                                                                   org.apache.derby.iapi.sql.compile.RowOrdering rowOrdering)
                                                            throws org.apache.derby.iapi.error.StandardException
Description copied from interface: org.apache.derby.iapi.sql.compile.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 interface org.apache.derby.iapi.sql.compile.Optimizable
Overrides:
estimateCost in class FromTable

pushOptPredicate

public boolean pushOptPredicate(org.apache.derby.iapi.sql.compile.OptimizablePredicate optimizablePredicate)
                         throws org.apache.derby.iapi.error.StandardException
Description copied from interface: org.apache.derby.iapi.sql.compile.Optimizable
Push an OptimizablePredicate down, if this node accepts it.

Specified by:
pushOptPredicate in interface org.apache.derby.iapi.sql.compile.Optimizable
Overrides:
pushOptPredicate in class FromTable

toString

public java.lang.String toString()
Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.

Overrides:
toString in class FromTable

flattenableInFromSubquery

public boolean flattenableInFromSubquery(FromList fromList)
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 class SingleChildResultSetNode

optimize

public ResultSetNode optimize(org.apache.derby.iapi.sql.dictionary.DataDictionary dataDictionary,
                              PredicateList predicates,
                              double outerRows)
                       throws org.apache.derby.iapi.error.StandardException
Optimize this GroupByNode.

Overrides:
optimize in class SingleChildResultSetNode

makeResultDescriptors

org.apache.derby.iapi.sql.ResultColumnDescriptor[] makeResultDescriptors(org.apache.derby.iapi.sql.execute.ExecutionContext ec)
Overrides:
makeResultDescriptors in class ResultSetNode

isOneRowResultSet

public boolean isOneRowResultSet()
                          throws org.apache.derby.iapi.error.StandardException
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 class SingleChildResultSetNode

generate

public void generate(ActivationClassBuilder acb,
                     org.apache.derby.iapi.services.compiler.MethodBuilder mb)
              throws org.apache.derby.iapi.error.StandardException
generate the sort result set operating over the source resultset. Adds distinct aggregates to the sort if necessary.

Overrides:
generate in class QueryTreeNode

genScalarAggregateResultSet

private void genScalarAggregateResultSet(ActivationClassBuilder acb,
                                         org.apache.derby.iapi.services.compiler.MethodBuilder mb)
Generate the code to evaluate scalar aggregates.


genGroupedAggregateResultSet

private void genGroupedAggregateResultSet(ActivationClassBuilder acb,
                                          org.apache.derby.iapi.services.compiler.MethodBuilder mb)
                                   throws org.apache.derby.iapi.error.StandardException
Generate the code to evaluate grouped aggregates.


getColumnReference

private ResultColumn getColumnReference(ResultColumn targetRC,
                                        org.apache.derby.iapi.sql.dictionary.DataDictionary dd)
                                 throws org.apache.derby.iapi.error.StandardException
Method for creating a new result column referencing the one passed in.


considerPostOptimizeOptimizations

void considerPostOptimizeOptimizations(boolean selectHasPredicates)
                                 throws org.apache.derby.iapi.error.StandardException
Consider any optimizations after the optimizer has chosen a plan. Optimizations include: o min optimization for scalar aggregates o max optimization for scalar aggregates


init

public void init(java.lang.Object childResult,
                 java.lang.Object tableProperties)
Initialilzer for a SingleChildResultSetNode.

Overrides:
init in class FromTable

getTrulyTheBestAccessPath

public org.apache.derby.iapi.sql.compile.AccessPath getTrulyTheBestAccessPath()
Description copied from interface: org.apache.derby.iapi.sql.compile.Optimizable
Get the best access path overall for this Optimizable.

Specified by:
getTrulyTheBestAccessPath in interface org.apache.derby.iapi.sql.compile.Optimizable
Overrides:
getTrulyTheBestAccessPath in class FromTable

getChildResult

public ResultSetNode getChildResult()
Return the childResult from this node.


setChildResult

void setChildResult(ResultSetNode childResult)
Set the childResult for this node.


pullOptPredicates

public void pullOptPredicates(org.apache.derby.iapi.sql.compile.OptimizablePredicateList optimizablePredicates)
                       throws org.apache.derby.iapi.error.StandardException
Description copied from interface: org.apache.derby.iapi.sql.compile.Optimizable
Pull all the OptimizablePredicates from this Optimizable and put them in the given OptimizablePredicateList.

Specified by:
pullOptPredicates in interface org.apache.derby.iapi.sql.compile.Optimizable
Overrides:
pullOptPredicates in class FromTable

forUpdate

public boolean forUpdate()
Description copied from interface: org.apache.derby.iapi.sql.compile.Optimizable
Return true if this is the target table of an update

Specified by:
forUpdate in interface org.apache.derby.iapi.sql.compile.Optimizable
Overrides:
forUpdate in class FromTable

initAccessPaths

public void initAccessPaths(org.apache.derby.iapi.sql.compile.Optimizer optimizer)
Description copied from interface: org.apache.derby.iapi.sql.compile.Optimizable
Init the access paths for this optimizable.

Specified by:
initAccessPaths in interface org.apache.derby.iapi.sql.compile.Optimizable
Overrides:
initAccessPaths in class FromTable

printSubNodes

public 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 class ResultSetNode

referencesTarget

public boolean referencesTarget(java.lang.String name,
                                boolean baseTable)
                         throws org.apache.derby.iapi.error.StandardException
Search to see if a query references the specifed table name.

Overrides:
referencesTarget in class ResultSetNode

referencesSessionSchema

public boolean referencesSessionSchema()
                                throws org.apache.derby.iapi.error.StandardException
Return true if the node references SESSION schema tables (temporary or permanent)

Overrides:
referencesSessionSchema in class QueryTreeNode

setLevel

public void setLevel(int level)
Set the (query block) level (0-based) for this FromTable.

Overrides:
setLevel in class FromTable

subqueryReferencesTarget

boolean subqueryReferencesTarget(java.lang.String name,
                                 boolean baseTable)
                           throws org.apache.derby.iapi.error.StandardException
Return whether or not this ResultSetNode contains a subquery with a reference to the specified target.

Overrides:
subqueryReferencesTarget in class ResultSetNode

preprocess

public ResultSetNode preprocess(int numTables,
                                GroupByList gbl,
                                FromList fromList)
                         throws org.apache.derby.iapi.error.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 class ResultSetNode

addNewPredicate

public ResultSetNode addNewPredicate(Predicate predicate)
                              throws org.apache.derby.iapi.error.StandardException
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 class ResultSetNode

pushExpressions

public void pushExpressions(PredicateList predicateList)
                     throws org.apache.derby.iapi.error.StandardException
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 class FromTable

ensurePredicateList

public ResultSetNode ensurePredicateList(int numTables)
                                  throws org.apache.derby.iapi.error.StandardException
Ensure that the top of the RSN tree has a PredicateList.

Overrides:
ensurePredicateList in class ResultSetNode

modifyAccessPaths

public ResultSetNode modifyAccessPaths()
                                throws org.apache.derby.iapi.error.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 class ResultSetNode

changeAccessPath

public ResultSetNode changeAccessPath()
                               throws org.apache.derby.iapi.error.StandardException
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 class ResultSetNode

getFromTableByName

protected FromTable getFromTableByName(java.lang.String name,
                                       java.lang.String schemaName,
                                       boolean exactMatch)
                                throws org.apache.derby.iapi.error.StandardException
Determine whether or not the specified name is an exposed name in the current query block.

Overrides:
getFromTableByName in class FromTable

decrementLevel

void decrementLevel(int decrement)
Decrement (query block) level (0-based) for this FromTable. This is useful when flattening a subquery.

Overrides:
decrementLevel in class FromTable

updateTargetLockMode

public 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 class ResultSetNode

isOrderedOn

boolean isOrderedOn(ColumnReference[] crs,
                    boolean permuteOrdering,
                    java.util.Vector fbtVector)
              throws org.apache.derby.iapi.error.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 class ResultSetNode

isNotExists

public boolean isNotExists()
Return whether or not the underlying ResultSet tree is for a NOT EXISTS join.

Overrides:
isNotExists in class ResultSetNode

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.


replaceDefaults

void replaceDefaults(org.apache.derby.iapi.sql.dictionary.TableDescriptor ttd,
                     ResultColumnList tcl)
               throws org.apache.derby.iapi.error.StandardException
Replace any DEFAULTs with the associated tree for the default.

Overrides:
replaceDefaults in class ResultSetNode

markOrderingDependent

void markOrderingDependent()
Notify the underlying result set tree that the result is ordering dependent. (For example, no bulk fetch on an index if under an IndexRowToBaseRow.)

Overrides:
markOrderingDependent in class ResultSetNode

getFinalCostEstimate

public org.apache.derby.iapi.sql.compile.CostEstimate getFinalCostEstimate()
Get the final CostEstimate for this node.

Overrides:
getFinalCostEstimate in class ResultSetNode

accept

public org.apache.derby.iapi.sql.compile.Visitable accept(org.apache.derby.iapi.sql.compile.Visitor v)
                                                   throws org.apache.derby.iapi.error.StandardException
Accept a visitor, and call v.visit() on child nodes as necessary.

Specified by:
accept in interface org.apache.derby.iapi.sql.compile.Visitable
Overrides:
accept in class ResultSetNode