|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl
org.apache.derby.impl.sql.execute.NoPutResultSetImpl
org.apache.derby.impl.sql.execute.GenericAggregateResultSet
org.apache.derby.impl.sql.execute.GroupedAggregateResultSet
class GroupedAggregateResultSet
This ResultSet evaluates grouped, non distinct aggregates. It will scan the entire source result set and calculate the grouped aggregates when scanning the source during the first call to next(). The implementation is capable of computing multiple levels of grouping in a single result set (this is requested using GROUP BY ROLLUP). This implementation has 3 variations, which it chooses according to the following rules: - If the data are guaranteed to arrive already in sorted order, we make a single pass over the data, computing the aggregates in-line as the data are read. - If the statement requests either multiple ROLLUP levels, or a DISTINCT grouping, then the data are first sorted, then we make a single pass over the data as above. - Otherwise, the data are sorted, and a SortObserver is used to compute the aggregations inside the sort, and the results are read back directly from the sorter. Note that, as of the introduction of the ROLLUP support, we no longer ALWAYS compute the aggregates using a SortObserver, which is an arrangement by which the sorter calls back into the aggregates during the sort process each time it consolidates two rows with the same sort key. Using aggregate sort observers is an efficient technique, but it was complex to extend it to the ROLLUP case, so to simplify the code we just have one path for both already-sorted and un-sorted data sources in the ROLLUP case.
Field Summary | |
---|---|
private java.util.HashSet[][] |
distinctValues
|
private java.util.List |
finishedResults
|
private long |
genericSortId
|
boolean |
hasDistinctAggregate
|
boolean |
isInSortedOrder
|
private int |
maxRowSize
|
private ColumnOrdering[] |
order
|
private ExecIndexRow[] |
resultRows
|
private boolean |
resultsComplete
|
private boolean |
rollup
|
int |
rowsInput
|
int |
rowsReturned
|
private ScanController |
scanController
|
java.util.Properties |
sortProperties
|
private ExecIndexRow |
sortResultRow
|
private ExecIndexRow |
sortTemplateRow
|
private ExecIndexRow |
sourceExecIndexRow
|
private TransactionController |
tc
|
private boolean |
usingAggregateObserver
|
Fields inherited from class org.apache.derby.impl.sql.execute.GenericAggregateResultSet |
---|
aggInfoList, aggregates, originalSource, rowAllocator, source |
Fields inherited from class org.apache.derby.impl.sql.execute.NoPutResultSetImpl |
---|
checkNullCols, clonedExecRow, cncLen, resultSetNumber, targetResultSet |
Fields inherited from class org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl |
---|
activation, beginTime, closeTime, compactRow, constructorTime, currentRow, endExecutionTime, finished, isOpen, isTopResultSet, nextTime, numOpens, openTime, optimizerEstimatedCost, optimizerEstimatedRowCount, resultDescription, rowsFiltered, rowsSeen, startExecutionTime, subqueryTrackingArray |
Fields inherited from interface org.apache.derby.iapi.sql.ResultSet |
---|
CURRENT_RESULTSET_ONLY, ENTIRE_RESULTSET_TREE, ISAFTERLAST, ISBEFOREFIRST, ISFIRST, ISLAST |
Fields inherited from interface org.apache.derby.iapi.sql.execute.NoPutResultSet |
---|
ABSOLUTE, FIRST, LAST, NEXT, PREVIOUS, RELATIVE |
Constructor Summary | |
---|---|
GroupedAggregateResultSet(NoPutResultSet s,
boolean isInSortedOrder,
int aggregateItem,
int orderingItem,
Activation a,
GeneratedMethod ra,
int maxRowSize,
int resultSetNumber,
double optimizerEstimatedRowCount,
double optimizerEstimatedCost,
boolean isRollup)
Constructor |
Method Summary | |
---|---|
void |
close()
If the result set has been opened, close the open scan. |
void |
closeSource()
Close the source of whatever we have been scanning. |
private void |
dumpAllRows(int cR)
|
private java.lang.String |
dumpRow(ExecRow r)
|
private ExecRow |
finalizeResults()
|
ExecRow |
getCurrentRow()
This result set has its row from the last fetch done. |
ExecRow |
getNextRowCore()
Return the next row. |
private ExecIndexRow |
getNextRowFromRS()
Get the next output row for processing |
private ExecIndexRow |
getRowFromResultSet()
Get a row from the input result set. |
private ExecIndexRow |
getRowFromSorter()
Get a row from the sorter. |
RowLocation |
getRowLocation()
This result set has its row location from the last fetch done. |
long |
getTimeSpent(int type)
Return the total amount of time spent in this ResultSet |
private void |
initializeDistinctMaps(int r,
boolean allocate)
|
private void |
initializeVectorAggregation(ExecRow row)
Run the aggregator initialization method for each aggregator in the row. |
private ScanController |
loadSorter()
Load up the sorter. |
private ExecRow |
makeCurrent(java.lang.Object row)
|
private void |
mergeVectorAggregates(ExecRow newRow,
ExecRow currRow,
int level)
Run the aggregator merge method for each aggregator in the row. |
void |
openCore()
Open the scan. |
private int |
sameGroupingValues(ExecRow currRow,
ExecRow newRow)
Return whether or not the new row has the same values for the grouping columns as the current row. |
private void |
setRollupColumnsToNull(ExecRow row,
int resultNum)
|
Methods inherited from class org.apache.derby.impl.sql.execute.GenericAggregateResultSet |
---|
finish, finishAggregation, getSortAggregators |
Methods inherited from class org.apache.derby.impl.sql.execute.NoPutResultSetImpl |
---|
clearCurrentRow, clearOrderableCache, closeRowSource, getCursorName, getNextRowFromRowSource, getResultDescription, getValidColumns, isForUpdate, markRowAsDeleted, needsRowLocation, needsToClone, positionScanAtRowLocation, printQualifiers, resultSetNumber, rowLocation, setCurrentRow, setNeedsRowLocation, setTargetResultSet, skipRow, skipScan, updateRow |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.apache.derby.iapi.sql.ResultSet |
---|
checkRowPosition, cleanUp, clearCurrentRow, finish, getAbsoluteRow, getActivation, getAutoGeneratedKeysResultset, getBeginExecutionTimestamp, getCursorName, getEndExecutionTimestamp, getExecuteTime, getFirstRow, getLastRow, getNextRow, getPreviousRow, getRelativeRow, getResultDescription, getRowNumber, getSubqueryTrackingArray, getWarnings, isClosed, modifiedRowCount, open, returnsRows, setAfterLastRow, setBeforeFirstRow |
Field Detail |
---|
public int rowsInput
public int rowsReturned
private ColumnOrdering[] order
private ExecIndexRow sortTemplateRow
public boolean hasDistinctAggregate
public boolean isInSortedOrder
private int maxRowSize
private ScanController scanController
private ExecIndexRow sourceExecIndexRow
private ExecIndexRow sortResultRow
private boolean resultsComplete
private java.util.List finishedResults
private ExecIndexRow[] resultRows
private java.util.HashSet[][] distinctValues
private boolean rollup
private boolean usingAggregateObserver
private long genericSortId
private TransactionController tc
public java.util.Properties sortProperties
Constructor Detail |
---|
GroupedAggregateResultSet(NoPutResultSet s, boolean isInSortedOrder, int aggregateItem, int orderingItem, Activation a, GeneratedMethod ra, int maxRowSize, int resultSetNumber, double optimizerEstimatedRowCount, double optimizerEstimatedCost, boolean isRollup) throws StandardException
s
- input result setisInSortedOrder
- true if the source results are in sorted orderaggregateItem
- indicates the number of the
SavedObject off of the PreparedStatement that holds the
AggregatorInfoList used by this routine.orderingItem
- indicates the number of the
SavedObject off of the PreparedStatement that holds the
ColumOrdering array used by this routinea
- activationra
- generated method to build an empty
output rowmaxRowSize
- approx row size, passed to sorterresultSetNumber
- The resultSetNumber for this result set
StandardException
- Thrown on errorMethod Detail |
---|
public void openCore() throws StandardException
openCore
in interface NoPutResultSet
StandardException
- thrown if cursor finished.private ScanController loadSorter() throws StandardException
StandardException
- thrown on failure.public ExecRow getNextRowCore() throws StandardException
getNextRowCore
in interface NoPutResultSet
getNextRowCore
in class BasicNoPutResultSetImpl
StandardException
- thrown on failure.
StandardException
- ResultSetNotOpen thrown if not yet open.NoPutResultSet.getNextRowCore()
private ExecRow makeCurrent(java.lang.Object row) throws StandardException
StandardException
private ExecRow finalizeResults() throws StandardException
StandardException
private int sameGroupingValues(ExecRow currRow, ExecRow newRow) throws StandardException
currRow
- The current row.newRow
- The new row.
StandardException
- thrown on failure to get row locationpublic void close() throws StandardException
close
in interface ResultSet
close
in class NoPutResultSetImpl
StandardException
- thrown on errorpublic long getTimeSpent(int type)
getTimeSpent
in interface ResultSet
type
- CURRENT_RESULTSET_ONLY - time spent only in this ResultSet
ENTIRE_RESULTSET_TREE - time spent in this ResultSet and below.
public RowLocation getRowLocation() throws StandardException
getRowLocation
in interface CursorResultSet
StandardException
- thrown on failure to get row locationCursorResultSet
public ExecRow getCurrentRow() throws StandardException
getCurrentRow
in interface CursorResultSet
StandardException
- thrown on failure.CursorResultSet
private ExecIndexRow getNextRowFromRS() throws StandardException
StandardException
private ExecIndexRow getRowFromResultSet() throws StandardException
StandardException
private void setRollupColumnsToNull(ExecRow row, int resultNum) throws StandardException
StandardException
private ExecIndexRow getRowFromSorter() throws StandardException
StandardException
public void closeSource() throws StandardException
StandardException
- thrown on errorprivate void initializeVectorAggregation(ExecRow row) throws StandardException
row
- the row to initialize
standard
- Derby exception
StandardException
private void mergeVectorAggregates(ExecRow newRow, ExecRow currRow, int level) throws StandardException
newRow
- the row to mergecurrRow
- the row to merge into
standard
- Derby exception
StandardException
private void initializeDistinctMaps(int r, boolean allocate) throws StandardException
StandardException
private void dumpAllRows(int cR) throws StandardException
StandardException
private java.lang.String dumpRow(ExecRow r) throws StandardException
StandardException
|
Built on Thu 2010-12-23 20:49:13+0000, from revision ??? | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |