class SortResultSet extends NoPutResultSetImpl implements CursorResultSet
If aggregate is true, then it feeds any number of aggregates to the sorter. Each aggregate is an instance of GenericAggregator which knows which Aggregator to call to perform the aggregation.
Brief background on the sorter and aggregates: the sorter has some rudimentary knowledge about aggregates. If it is passed aggregates, it will eliminate duplicates on the ordering columns. In the process it will call the aggregator on each row that is discarded.
Note that a DISTINCT on the SELECT list and an aggregate cannot be processed by the same SortResultSet(), if there are both aggregates (distinct or otherwise) and a DISTINCT on the select list, then 2 separate SortResultSets are required (the DISTINCT is a sort on the output of the sort with the aggregation).
Currently, all rows are fed through the sorter. This is true even if there is no sorting needed. In this case we feed every row in and just pull every row out (this is an obvious area for a performance improvement). We'll need to know if the rows are sorted before we can make any optimizations in this area.
CLONING: Cloning and sorts are an important topic. Currently we do a lot of cloning. We clone the following:
There are two cloning APIs: cloning by the sorter on rows that are not discarded as duplicates or cloning in the SortResultSet prior to inserting into the sorter. If we have any aggregates at all we always clone prior to inserting into the sorter. We need to do this because we have to set up the aggregators before passing them into the sorter. When we don't have aggregates we let the sorter to the cloning to avoid unnecessary clones on duplicate rows that are going to be discarded anyway.
BasicNoPutResultSetImpl.FieldComparator
Modifier and Type | Field and Description |
---|---|
private ExecRow |
currSortedRow |
boolean |
distinct |
private boolean |
dropGenericSort |
private long |
genericSortId |
boolean |
isInSortedOrder |
private int |
maxRowSize |
private boolean |
nextCalled |
private int |
numColumns |
private SortObserver |
observer |
private ColumnOrdering[] |
order |
private NoPutResultSet |
originalSource |
int |
rowsInput |
int |
rowsReturned |
private ColumnOrdering[] |
savedOrder |
private ScanController |
scanController |
private boolean |
sorted |
java.util.Properties |
sortProperties |
private ExecRow |
sortResultRow |
private ExecRow |
sortTemplateRow |
NoPutResultSet |
source |
checkNullCols, clonedExecRow, cncLen, resultSetNumber, targetResultSet
activation, beginTime, closeTime, compactRow, constructorTime, currentRow, endExecutionTime, finished, isOpen, isTopResultSet, nextTime, numOpens, openTime, optimizerEstimatedCost, optimizerEstimatedRowCount, resultDescription, rowsFiltered, rowsSeen, startExecutionTime, subqueryTrackingArray
CURRENT_RESULTSET_ONLY, ENTIRE_RESULTSET_TREE, ISAFTERLAST, ISBEFOREFIRST, ISFIRST, ISLAST
ABSOLUTE, FIRST, LAST, NEXT, PREVIOUS, RELATIVE, TEMPORARY_RESULT_SET_NUMBER
Constructor and Description |
---|
SortResultSet(NoPutResultSet s,
boolean distinct,
boolean isInSortedOrder,
int orderingItem,
Activation a,
int ra,
int maxRowSize,
int resultSetNumber,
double optimizerEstimatedRowCount,
double optimizerEstimatedCost)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
close()
If the result set has been opened,
close the open scan.
|
private void |
closeSource()
Close the source of whatever we have been scanning.
|
private boolean |
filterRow(ExecRow currRow,
ExecRow newRow)
Filter out the new row if it has the same contents as
the current row.
|
void |
finish()
Tells the system that there will be no more access
to any database information via this result set;
in particular, no more calls to open().
|
ExecRow |
getCurrentRow()
This result set has its row from the last fetch done.
|
ExecRow |
getNextRowCore()
Return the next row.
|
private ExecRow |
getNextRowFromRS()
Get the next output row for processing
|
private ExecRow |
getRowFromResultSet()
Get a row from the input result set.
|
private ExecRow |
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 ScanController |
loadSorter()
Load up the sorter.
|
void |
openCore()
Open the scan.
|
clearCurrentRow, clearOrderableCache, closeRowSource, getCursorName, getNextRowFromRowSource, getResultDescription, getValidColumns, isForUpdate, markRowAsDeleted, needsRowLocation, needsRowLocationForDeferredCheckConstraints, needsToClone, offendingRowLocation, positionScanAtRowLocation, printQualifiers, resultSetNumber, rowLocation, setCurrentRow, setHasDeferrableChecks, setNeedsRowLocation, setTargetResultSet, skipRow, skipScan, unpackHashValue, updateRow
addWarning, attachStatementContext, checkCancellationFlag, checkRowPosition, childrenToXML, cleanUp, dumpTimeStats, finishAndRTS, getAbsoluteRow, getActivation, getAutoGeneratedKeysResultset, getBeginExecutionTimestamp, getCompactRow, getCurrentTimeMillis, getElapsedMillis, getEndExecutionTimestamp, getEstimatedRowCount, getExecuteTime, getExecutionFactory, getFirstRow, getLanguageConnectionContext, getLastRow, getNextRow, getPointOfAttachment, getPreviousRow, getRelativeRow, getRowNumber, getScanIsolationLevel, getSubqueryTrackingArray, getTransactionController, getWarnings, isClosed, isXplainOnlyMode, markAsTopResultSet, modifiedRowCount, open, recordConstructorTime, reopenCore, requiresRelocking, returnsRows, setAfterLastRow, setBeforeFirstRow, setCompactRow, setCompatRow, toXML, toXML
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addWarning, checkRowPosition, cleanUp, clearCurrentRow, getAbsoluteRow, getActivation, getAutoGeneratedKeysResultset, getBeginExecutionTimestamp, getCursorName, getEndExecutionTimestamp, getExecuteTime, getFirstRow, getLastRow, getNextRow, getPreviousRow, getRelativeRow, getResultDescription, getRowNumber, getSubqueryTrackingArray, getWarnings, isClosed, modifiedRowCount, open, returnsRows, setAfterLastRow, setBeforeFirstRow, toXML
public int rowsInput
public int rowsReturned
public boolean distinct
public NoPutResultSet source
private ColumnOrdering[] order
private ColumnOrdering[] savedOrder
private SortObserver observer
private ExecRow sortTemplateRow
public boolean isInSortedOrder
private NoPutResultSet originalSource
private int maxRowSize
private ScanController scanController
private ExecRow sortResultRow
private ExecRow currSortedRow
private boolean nextCalled
private int numColumns
private long genericSortId
private boolean dropGenericSort
private boolean sorted
public java.util.Properties sortProperties
public SortResultSet(NoPutResultSet s, boolean distinct, boolean isInSortedOrder, int orderingItem, Activation a, int ra, int maxRowSize, int resultSetNumber, double optimizerEstimatedRowCount, double optimizerEstimatedCost) throws StandardException
s
- input result setdistinct
- if this is a DISTINCT select list.
Also set to true for a GROUP BY w/o aggretatesisInSortedOrder
- true if the source results are in sorted orderorderingItem
- indicates the number of the
SavedObject off of the PreparedStatement that holds the
ColumOrdering array used by this routinea
- activationra
- saved object that generates an empty rowmaxRowSize
- approx row size, passed to sorterresultSetNumber
- The resultSetNumber for this result setStandardException
- Thrown on errorpublic 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 boolean filterRow(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 void finish() throws StandardException
ResultSet
finish
in interface ResultSet
finish
in class BasicNoPutResultSetImpl
StandardException
- 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 ExecRow getNextRowFromRS() throws StandardException
StandardException
private ExecRow getRowFromResultSet() throws StandardException
StandardException
private ExecRow getRowFromSorter() throws StandardException
StandardException
private void closeSource() throws StandardException
StandardException
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.