org.apache.derby.impl.sql.compile
Class DistinctNode

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

public class DistinctNode
extends SingleChildResultSetNode

A DistinctNode represents a result set for a disinct operation on a select. It has the same description as its input result set. For the most part, it simply delegates operations to its childResultSet, which is currently expected to be a ProjectRestrictResultSet generated for a SelectNode. NOTE: A DistinctNode extends FromTable since it can exist in a FromList.


Field Summary
(package private)  boolean inSortedOrder
           
 
Fields inherited from class org.apache.derby.impl.sql.compile.SingleChildResultSetNode
childResult, hasTrulyTheBestAccessPath
 
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.ResultSetNode
costEstimate, cursorTargetTable, finalCostEstimate, insertSource, optimizer, referencedTableMap, resultColumns, resultSetNumber, scratchCostEstimate, statementResultSet
 
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, isPrivilegeCollectionRequired
 
Constructor Summary
DistinctNode()
           
 
Method Summary
 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.
 void generate(ActivationClassBuilder acb, MethodBuilder mb)
          generate the distinct result set operating over the source resultset.
 void init(java.lang.Object childResult, java.lang.Object inSortedOrder, java.lang.Object tableProperties)
          Initializer for a DistinctNode.
(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.
 ResultSetNode optimize(DataDictionary dataDictionary, PredicateList predicates, double outerRows)
          Optimize this DistinctNode.
 CostEstimate optimizeIt(Optimizer optimizer, OptimizablePredicateList predList, CostEstimate outerCost, RowOrdering rowOrdering)
          Choose the best access path for this Optimizable.
 boolean pushOptPredicate(OptimizablePredicate optimizablePredicate)
          Push an OptimizablePredicate down, if this node accepts it.
 
Methods inherited from class org.apache.derby.impl.sql.compile.SingleChildResultSetNode
acceptChildren, addNewPredicate, adjustForSortElimination, adjustForSortElimination, changeAccessPath, decrementLevel, ensurePredicateList, flattenableInFromSubquery, forUpdate, getChildResult, getFinalCostEstimate, getFromTableByName, getTrulyTheBestAccessPath, init, initAccessPaths, isNotExists, isOneRowResultSet, modifyAccessPaths, preprocess, printSubNodes, pullOptPredicates, pushExpressions, referencesSessionSchema, referencesTarget, reflectionNeededForProjection, setChildResult, setLevel, subqueryReferencesTarget, updateBestPlanMap, updateTargetLockMode
 
Methods inherited from class org.apache.derby.impl.sql.compile.FromTable
assignCostEstimate, canBeOrdered, considerSortAvoidancePath, convertAbsoluteToRelativeColumnPosition, cursorTargetTable, feasibleJoinStrategy, fillInReferencedTableMap, flatten, getBaseTableName, getBestAccessPath, getBestSortAvoidancePath, getCorrelationName, getCostEstimate, getCurrentAccessPath, getExposedName, getLevel, getName, getNumColumnsReturned, getOrigTableName, 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, setCostEstimate, setHashKeyColumns, 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, disablePrivilegeCollection, enhanceRCLForInsert, generateNormalizationResultSet, generateResultSet, genProjectRestrict, genProjectRestrict, genProjectRestrictForReordering, getAllResultColumns, getCostEstimate, getCursorTargetTable, getFromList, getMatchingColumn, getNewCostEstimate, getOptimizer, getOptimizerImpl, getRCLForInsert, getReferencedTableMap, getResultColumns, getResultSetNumber, isPossibleDistinctScan, isUpdatableCursor, LOJgetReferencedTables, makeResultDescription, makeResultDescriptors, markAsCursorTargetTable, markForDistinctScan, markStatementResultSet, modifyAccessPaths, notCursorTargetTable, notFlattenableJoin, numDistinctAggregates, parseDefault, performMaterialization, projectResultColumns, pushOffsetFetchFirst, pushOrderByList, rejectParameters, rejectXMLValues, renameGeneratedResultNames, replaceOrForbidDefaults, returnsAtMostOneRow, setInsertSource, setReferencedTableMap, setResultColumns, setResultToBooleanTrueNode, setTableConstructorTypes, verifySelectStarSubquery
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, bindOffsetFetch, bindRowMultiSet, bindUserType, checkReliability, checkReliability, convertDefaultNode, createTypeDependency, debugFlush, debugPrint, formatNodeString, foundString, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, init, init, isAtomic, isInstanceOf, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, orReliability, parseStatement, printLabel, resolveTableToSynonym, setBeginOffset, setContextManager, setEndOffset, setNodeType, setRefActionInfo, stackPrint, 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

inSortedOrder

boolean inSortedOrder
Constructor Detail

DistinctNode

public DistinctNode()
Method Detail

init

public void init(java.lang.Object childResult,
                 java.lang.Object inSortedOrder,
                 java.lang.Object tableProperties)
          throws StandardException
Initializer for a DistinctNode.

Overrides:
init in class QueryTreeNode
Parameters:
childResult - The child ResultSetNode
inSortedOrder - Whether or not the child ResultSetNode returns its output in sorted order.
tableProperties - Properties list associated with the table
Throws:
StandardException - Thrown on error

optimizeIt

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

Specified by:
optimizeIt in interface Optimizable
Overrides:
optimizeIt in class FromTable
Parameters:
optimizer - Optimizer to use.
predList - The predicate list to optimize against
outerCost - The CostEstimate for the outer tables in the join order, telling how many times this Optimizable will be scanned.
rowOrdering - The row ordering for all the tables in the join order, including this one.
Returns:
The optimizer's estimated cost of the best access path.
Throws:
StandardException - Thrown on error
See Also:
Optimizable.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)

estimateCost

public CostEstimate estimateCost(OptimizablePredicateList predList,
                                 ConglomerateDescriptor cd,
                                 CostEstimate outerCost,
                                 Optimizer optimizer,
                                 RowOrdering rowOrdering)
                          throws StandardException
Description copied from interface: 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 Optimizable
Overrides:
estimateCost in class FromTable
Parameters:
predList - The predicate list to optimize against
cd - The conglomerate descriptor to get the cost of
outerCost - The estimated cost of the part of the plan outer to this optimizable.
optimizer - The optimizer to use to help estimate the cost
rowOrdering - 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:
Optimizable.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)

pushOptPredicate

public boolean pushOptPredicate(OptimizablePredicate optimizablePredicate)
                         throws StandardException
Description copied from interface: Optimizable
Push an OptimizablePredicate down, if this node accepts it.

Specified by:
pushOptPredicate in interface Optimizable
Overrides:
pushOptPredicate in class FromTable
Parameters:
optimizablePredicate - OptimizablePredicate to push down.
Returns:
Whether or not the predicate was pushed down.
Throws:
StandardException - Thrown on error
See Also:
Optimizable.pushOptPredicate(org.apache.derby.iapi.sql.compile.OptimizablePredicate)

optimize

public ResultSetNode optimize(DataDictionary dataDictionary,
                              PredicateList predicates,
                              double outerRows)
                       throws StandardException
Optimize this DistinctNode.

Overrides:
optimize in class SingleChildResultSetNode
Parameters:
dataDictionary - The DataDictionary to use for optimization
predicates - 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

isOrderedOn

boolean isOrderedOn(ColumnReference[] crs,
                    boolean permuteOrdering,
                    java.util.Vector fbtVector)
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 SingleChildResultSetNode
Parameters:
crs - The specified ColumnReference[]
permuteOrdering - Whether or not the order of the CRs in the array can be permuted
fbtVector - Vector that is to be filled with the FromBaseTable
Returns:
Whether the underlying ResultSet tree is ordered on the specified column.

generate

public void generate(ActivationClassBuilder acb,
                     MethodBuilder mb)
              throws StandardException
generate the distinct result set operating over the source resultset.

Overrides:
generate in class QueryTreeNode
Parameters:
acb - The ActivationClassBuilder for the class being built
mb - The method for the generated code to go into
Throws:
StandardException - Thrown on error

Built on Thu 2010-12-23 20:49:13+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.