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.
| Modifier and Type | Field and Description |
|---|---|
| private ExecRow | |
| public boolean | |
| private boolean | |
| private long | |
| public boolean | |
| private int | |
| private boolean | |
| private int | |
| private SortObserver | |
| private ColumnOrdering[] | |
| private NoPutResultSet | |
| public int | |
| public int | |
| private ColumnOrdering[] | |
| private ScanController | |
| private boolean | |
| public Properties | |
| private ExecRow | |
| private ExecRow | |
| public NoPutResultSet |
| Access | Constructor and Description |
|---|---|
| public | SortResultSet(NoPutResultSet
input result set s, boolean if this is a DISTINCT select list.
Also set to true for a GROUP BY w/o aggretates distinct, boolean true if the source results are in sorted order isInSortedOrder, int indicates the number of the
SavedObject off of the PreparedStatement that holds the
ColumOrdering array used by this routine orderingItem, Activation activation a, int saved object that generates an empty row ra, int approx row size, passed to sorter maxRowSize, int The resultSetNumber for this result set resultSetNumber, double optimizerEstimatedRowCount, double optimizerEstimatedCost)Constructor |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Overrides org. Implements org. If the result set has been opened, close the open scan. |
| private void | |
| private boolean | |
| public void | finish()
Overrides org. Implements org. 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(). |
| public ExecRow | Returns: the last row returned;Implements org. This result set has its row from the last fetch done. |
| public ExecRow | Returns: the next row in the resultImplements abstract org. Implements org. Return the next row. |
| private ExecRow | |
| private ExecRow | |
| private ExecRow | |
| public RowLocation | Returns: the row location of the current cursor row.Implements org. This result set has its row location from the last fetch done. |
| public long | Returns: long The total amount of time spent (in milliseconds).CURRENT_RESULTSET_ONLY - time spent only in this ResultSet
ENTIRE_RESULTSET_TREE - time spent in this ResultSet and below. type)Implements org. Return the total amount of time spent in this ResultSet |
| private ScanController | |
| public void |
| currSortedRow | back to summary |
|---|---|
| private ExecRow currSortedRow | |
| distinct | back to summary |
|---|---|
| public boolean distinct | |
| dropGenericSort | back to summary |
|---|---|
| private boolean dropGenericSort | |
| genericSortId | back to summary |
|---|---|
| private long genericSortId | |
| isInSortedOrder | back to summary |
|---|---|
| public boolean isInSortedOrder | |
| maxRowSize | back to summary |
|---|---|
| private int maxRowSize | |
| nextCalled | back to summary |
|---|---|
| private boolean nextCalled | |
| numColumns | back to summary |
|---|---|
| private int numColumns | |
| observer | back to summary |
|---|---|
| private SortObserver observer | |
| order | back to summary |
|---|---|
| private ColumnOrdering[] order | |
| originalSource | back to summary |
|---|---|
| private NoPutResultSet originalSource | |
| rowsInput | back to summary |
|---|---|
| public int rowsInput | |
| rowsReturned | back to summary |
|---|---|
| public int rowsReturned | |
| savedOrder | back to summary |
|---|---|
| private ColumnOrdering[] savedOrder | |
| scanController | back to summary |
|---|---|
| private ScanController scanController | |
| sorted | back to summary |
|---|---|
| private boolean sorted | |
| sortProperties | back to summary |
|---|---|
| public Properties sortProperties | |
| sortResultRow | back to summary |
|---|---|
| private ExecRow sortResultRow | |
| sortTemplateRow | back to summary |
|---|---|
| private ExecRow sortTemplateRow | |
| source | back to summary |
|---|---|
| public NoPutResultSet source | |
| SortResultSet | back to summary |
|---|---|
| public SortResultSet(NoPutResultSet s, boolean distinct, boolean isInSortedOrder, int orderingItem, Activation a, int ra, int maxRowSize, int resultSetNumber, double optimizerEstimatedRowCount, double optimizerEstimatedCost) throws StandardException Constructor
| |
| close | back to summary |
|---|---|
| public void close() throws StandardException Overrides org. Implements org. If the result set has been opened, close the open scan.
| |
| closeSource | back to summary |
|---|---|
| private void closeSource() throws StandardException Close the source of whatever we have been scanning. | |
| filterRow | back to summary |
|---|---|
| private boolean filterRow(ExecRow currRow, ExecRow newRow) throws StandardException Filter out the new row if it has the same contents as the current row. (This allows us to process in-order distincts without a sorter.)
| |
| finish | back to summary |
|---|---|
| public void finish() throws StandardException Overrides org. Implements org. Doc from org. 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(). Will close the result set if it is not already closed.
| |
| getCurrentRow | back to summary |
|---|---|
| public ExecRow getCurrentRow() throws StandardException Implements org. This result set has its row from the last fetch done. If the cursor is closed, a null is returned.
| |
| getNextRowCore | back to summary |
|---|---|
| public ExecRow getNextRowCore() throws StandardException Implements abstract org. Implements org. Return the next row.
| |
| getNextRowFromRS | back to summary |
|---|---|
| private ExecRow getNextRowFromRS() throws StandardException Get the next output row for processing | |
| getRowFromResultSet | back to summary |
|---|---|
| private ExecRow getRowFromResultSet() throws StandardException Get a row from the input result set. | |
| getRowFromSorter | back to summary |
|---|---|
| private ExecRow getRowFromSorter() throws StandardException Get a row from the sorter. Side effects: sets currentRow. | |
| getRowLocation | back to summary |
|---|---|
| public RowLocation getRowLocation() throws StandardException Implements org. This result set has its row location from the last fetch done. If the cursor is closed, a null is returned.
| |
| getTimeSpent | back to summary |
|---|---|
| public long getTimeSpent(int type) Implements org. Return the total amount of time spent in this ResultSet
| |
| loadSorter | back to summary |
|---|---|
| private ScanController loadSorter() throws StandardException Load up the sorter. Feed it every row from the source scan. When done, close the source scan and open the sort. Return the sort scan controller.
| |
| openCore | back to summary |
|---|---|
| public void openCore() throws StandardException Implements org. Open the scan. Load the sorter and prepare to get rows from it.
| |