|
||||||||||
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.SortResultSet
Takes a source result set, sends it to the sorter, and returns the results. If distinct is true, removes all but one copy of duplicate rows using DistinctAggregator, which really doesn't aggregate anything at all -- the sorter assumes that the presence of an aggregator means that it should return a single row for each set with identical ordering columns.
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.
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 | |
SortResultSet(NoPutResultSet s,
boolean distinct,
boolean isInSortedOrder,
int orderingItem,
Activation a,
GeneratedMethod ra,
int maxRowSize,
int resultSetNumber,
double optimizerEstimatedRowCount,
double optimizerEstimatedCost,
GeneratedMethod c)
Constructor |
Method Summary | |
protected void |
addWarning(java.sql.SQLWarning w)
|
protected void |
attachStatementContext()
Attach this result set to the top statement context on the stack. |
boolean |
checkRowPosition(int isType)
Determine if the cursor is before the first row in the result set. |
void |
cleanUp()
Clean up on error |
void |
clearCurrentRow()
Clear the current row |
protected void |
clearOrderableCache(Qualifier[][] qualifiers)
Clear the Orderable cache for each qualifier. |
void |
close()
If the result set has been opened, close the open scan. |
void |
closeRowSource()
closeRowSource tells the RowSource that it will no longer need to return any rows and it can release any resource it may have. |
private void |
closeSource()
Close the source of whatever we have been scanning. |
protected java.lang.String |
dumpTimeStats(java.lang.String indent,
java.lang.String subIndent)
Dump out the time information for run time stats. |
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(). |
protected void |
finishAndRTS()
|
ExecRow |
getAbsoluteRow(int row)
Returns the row at the absolute position from the query, and returns NULL when there is no such position. |
ResultSet |
getAutoGeneratedKeysResultset()
ResultSet for rows inserted into the table (contains auto-generated keys columns only) |
java.sql.Timestamp |
getBeginExecutionTimestamp()
Get the Timestamp for the beginning of execution. |
protected ExecRow |
getCompactRow(ExecRow candidate,
FormatableBitSet accessedCols,
FormatableBitSet otherCols,
boolean isKeyed)
Get a compacted version of the candidate row according to the columns specified in the bit map. |
ExecRow |
getCurrentRow()
This result set has its row from the last fetch done. |
protected long |
getCurrentTimeMillis()
Return the current time in milliseconds, if DEBUG and RunTimeStats is on, else return 0. |
java.lang.String |
getCursorName()
Return my cursor name for JDBC. |
protected long |
getElapsedMillis(long beginTime)
Return the elapsed time in milliseconds, between now and the beginTime, if DEBUG and RunTimeStats is on, else return 0. |
java.sql.Timestamp |
getEndExecutionTimestamp()
Get the Timestamp for the end of execution. |
double |
getEstimatedRowCount()
Get the estimated row count from this result set. |
long |
getExecuteTime()
Get the execution time in milliseconds. |
(package private) ExecutionFactory |
getExecutionFactory()
Get a execution factory |
ExecRow |
getFirstRow()
Returns the first row from the query, and returns NULL when there are no rows. |
protected LanguageConnectionContext |
getLanguageConnectionContext()
Cache the language connection context. |
ExecRow |
getLastRow()
Returns the last row from the query, and returns NULL when there are no rows. |
ExecRow |
getNextRow()
Return the requested values computed from the next row (if any) for which the restriction evaluates to true. |
ExecRow |
getNextRowCore()
Return the next row. |
DataValueDescriptor[] |
getNextRowFromRowSource()
Get the next row as an array of column objects. |
private ExecRow |
getNextRowFromRS()
Get the next output row for processing |
int |
getPointOfAttachment()
Return the point of attachment for this subquery. |
ExecRow |
getPreviousRow()
Returns the previous row from the query, and returns NULL when there are no more previous rows. |
ExecRow |
getRelativeRow(int row)
Returns the row at the relative position from the current cursor position, and returns NULL when there is no such position. |
ResultDescription |
getResultDescription()
Returns the description of the table's rows |
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. |
int |
getRowNumber()
Returns the row number of the current row. |
int |
getScanIsolationLevel()
Return the isolation level of the scan in the result set. |
NoPutResultSet[] |
getSubqueryTrackingArray(int numSubqueries)
Get the subquery ResultSet tracking array from the top ResultSet. |
long |
getTimeSpent(int type)
Return the total amount of time spent in this ResultSet |
(package private) TransactionController |
getTransactionController()
Get the current transaction controller. |
FormatableBitSet |
getValidColumns()
getValidColumns describes the DataValueDescriptor[] returned by all calls to the getNextRowFromRowSource() call. |
java.sql.SQLWarning |
getWarnings()
Return the set of warnings generated during the execution of this result set. |
boolean |
isClosed()
Report if closed. |
boolean |
isForUpdate()
Is this ResultSet or it's source result set for update This method will be overriden in the inherited Classes if it is true |
private ScanController |
loadSorter()
Load up the sorter. |
void |
markAsTopResultSet()
Mark the ResultSet as the topmost one in the ResultSet tree. |
int |
modifiedRowCount()
Returns the number of rows affected by the statement. |
boolean |
needsRowLocation()
needsRowLocation returns true iff this the row source expects the drainer of the row source to call rowLocation after getting a row from getNextRowFromRowSource. |
boolean |
needsToClone()
Does the caller of getNextRowFromRowSource() need to clone the row in order to keep a reference to the row past the getNextRowFromRowSource() call which returned the row. |
void |
open()
open a scan on the table. scan parameters are evaluated at each open, so there is probably some way of altering their values... |
void |
openCore()
Open the scan. |
static java.lang.String |
printQualifiers(Qualifier[][] qualifiers)
Return a 2-d array of Qualifiers as a String |
void |
reopenCore()
This is the default implementation of reopenCore(). |
boolean |
requiresRelocking()
Do we need to relock the row when going to the heap. |
int |
resultSetNumber()
Get the number of this ResultSet, which is guaranteed to be unique within a statement. |
boolean |
returnsRows()
Returns true. |
void |
rowLocation(RowLocation rl)
rowLocation is a callback for the drainer of the row source to return the rowLocation of the current row, i.e, the row that is being returned by getNextRowFromRowSource. |
ExecRow |
setAfterLastRow()
Sets the current position to after the last row and returns NULL because there is no current row. |
ExecRow |
setBeforeFirstRow()
Sets the current position to before the first row and returns NULL because there is no current row. |
protected void |
setCheckConstraints(GeneratedMethod checkGM)
Set the GeneratedMethod for enforcing check constraints |
protected ExecRow |
setCompactRow(ExecRow candidateRow,
ExecRow compactRow)
Copy columns from the candidate row from the store to the given compact row. |
protected void |
setCompatRow(ExecRow compactRow,
java.lang.Object[] sourceRow)
|
void |
setCurrentRow(ExecRow row)
Set the current row to the row passed in. |
protected void |
setHeapConglomerate(long heapConglomerate)
Set the heap conglomerate number (used in enforcing check constraints) |
void |
setNeedsRowLocation(boolean needsRowLocation)
Set whether or not the NPRS need the row location when acting as a row source. |
void |
setTargetResultSet(TargetResultSet trs)
Notify a NPRS that it is the source for the specified TargetResultSet. |
protected boolean |
skipRow(ExecRow row)
Return true if we should skip the scan due to nulls in the row when the start or stop positioners on the columns containing null do not implement ordered null semantics. |
protected boolean |
skipScan(ExecIndexRow startPosition,
ExecIndexRow stopPosition)
Return true if we should skip the scan due to nulls in the start or stop position when the predicate on the column(s) in question do not implement ordered null semantics. beetle 4464, we also compact the areNullsOrdered flags into checkNullCols here. |
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, getAbsoluteRow, 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
public boolean distinct
public NoPutResultSet source
private GeneratedMethod closeCleanup
private GeneratedMethod rowAllocator
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 final int resultSetNumber
protected java.lang.String indent
protected java.lang.String subIndent
protected int sourceDepth
protected ExecRow clonedExecRow
GeneratedMethod checkGM
long heapConglomerate
protected TargetResultSet targetResultSet
protected int[] checkNullCols
protected int cncLen
protected boolean isOpen
protected boolean finished
protected ExecRow currentRow
protected boolean isTopResultSet
protected LanguageConnectionContext lcc
public int numOpens
public int rowsSeen
public int rowsFiltered
protected long startExecutionTime
protected long endExecutionTime
public long beginTime
public long constructorTime
public long openTime
public long nextTime
public long closeTime
public double optimizerEstimatedRowCount
public double optimizerEstimatedCost
public NoPutResultSet[] subqueryTrackingArray
ExecRow compactRow
protected Activation activation
ResultDescription resultDescription
Constructor Detail |
public SortResultSet(NoPutResultSet s, boolean distinct, boolean isInSortedOrder, int orderingItem, Activation a, GeneratedMethod ra, int maxRowSize, int resultSetNumber, double optimizerEstimatedRowCount, double optimizerEstimatedCost, GeneratedMethod c) 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
- 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
openCore
in class BasicNoPutResultSetImpl
StandardException
- thrown if cursor finished.NoPutResultSet.openCore()
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
public 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
public ResultDescription getResultDescription()
getResultDescription
in interface ResultSet
getResultDescription
in class BasicNoPutResultSetImpl
public java.lang.String getCursorName()
public int resultSetNumber()
NoPutResultSet
resultSetNumber
in interface NoPutResultSet
resultSetNumber
in class BasicNoPutResultSetImpl
NoPutResultSet.resultSetNumber()
public void setTargetResultSet(TargetResultSet trs)
NoPutResultSet
trs
- The TargetResultSet.
NoPutResultSet.setTargetResultSet(org.apache.derby.iapi.sql.execute.TargetResultSet)
public void setNeedsRowLocation(boolean needsRowLocation)
NoPutResultSet
NoPutResultSet.setNeedsRowLocation(boolean)
public FormatableBitSet getValidColumns()
RowSource
RowSource.getValidColumns()
public DataValueDescriptor[] getNextRowFromRowSource() throws StandardException
RowSource
A null column can be specified by leaving the object null, or indicated by returning a non-null getValidColumns. On streaming columns, it can be indicated by returning a non-null get FieldStates.
If RowSource.needToClone() is true then the returned row (the DataValueDescriptor[]) is guaranteed not to be modified by drainer of the RowSource (except that the input stream will be read, of course) and drainer will keep no reference to it before making the subsequent nextRow call. So it is safe to return the same DataValueDescriptor[] in subsequent nextRow calls if that is desirable for performance reasons.
If RowSource.needToClone() is false then the returned row (the DataValueDescriptor[]) may be be modified by drainer of the RowSource, and the drainer may keep a reference to it after making the subsequent nextRow call. In this case the client should severe all references to the row after returning it from getNextRowFromRowSource().
StandardException
- on errorRowSource.getNextRowFromRowSource()
public boolean needsToClone()
RowSource
RowSource.needsToClone()
public void closeRowSource()
RowSource
RowSource.closeRowSource()
public boolean needsRowLocation()
RowLocationRetRowSource
RowLocationRetRowSource.needsRowLocation()
public void rowLocation(RowLocation rl) throws StandardException
RowLocationRetRowSource
boolean needsRL = rowSource.needsRowLocation(); DataValueDescriptor[] row; while((row = rowSource.getNextRowFromRowSource()) != null) { RowLocation rl = heapConglomerate.insertRow(row); if (needsRL) rowSource.rowLocation(rl); }
StandardException
- on errorRowLocationRetRowSource.rowLocation(org.apache.derby.iapi.types.RowLocation)
protected void clearOrderableCache(Qualifier[][] qualifiers) throws StandardException
qualifiers
- The Qualifiers to clear
StandardException
protected void setCheckConstraints(GeneratedMethod checkGM)
checkGM
- The GeneratedMethod for enforcing any check constraints.
protected void setHeapConglomerate(long heapConglomerate)
heapConglomerate
- The heap conglomerate number.
public final void setCurrentRow(ExecRow row)
row
- the new current rowpublic final void clearCurrentRow()
public boolean isForUpdate()
isForUpdate
in interface NoPutResultSet
isForUpdate
in class BasicNoPutResultSetImpl
protected boolean skipScan(ExecIndexRow startPosition, ExecIndexRow stopPosition) throws StandardException
startPosition
- An index row for the start positionstopPosition
- An index row for the stop position
StandardException
protected boolean skipRow(ExecRow row) throws StandardException
row
- An index row
StandardException
public static java.lang.String printQualifiers(Qualifier[][] qualifiers)
public void reopenCore() throws StandardException
reopenCore
in interface NoPutResultSet
StandardException
- thrown if cursor finished.NoPutResultSet.openCore()
public int getPointOfAttachment()
NoPutResultSet
getPointOfAttachment
in interface NoPutResultSet
NoPutResultSet.getPointOfAttachment()
public void markAsTopResultSet()
markAsTopResultSet
in interface NoPutResultSet
public int getScanIsolationLevel()
NoPutResultSet
getScanIsolationLevel
in interface NoPutResultSet
NoPutResultSet.getScanIsolationLevel()
public double getEstimatedRowCount()
NoPutResultSet
getEstimatedRowCount
in interface NoPutResultSet
NoPutResultSet.getEstimatedRowCount()
public boolean requiresRelocking()
NoPutResultSet
requiresRelocking
in interface NoPutResultSet
NoPutResultSet.requiresRelocking()
public final void open() throws StandardException
open
in interface ResultSet
StandardException
- thrown if cursor finished.public ExecRow getAbsoluteRow(int row) throws StandardException
getAbsoluteRow
in interface ResultSet
row
- The position.
StandardException
- Thrown on failureRow
public ExecRow getRelativeRow(int row) throws StandardException
getRelativeRow
in interface ResultSet
row
- The position.
StandardException
- Thrown on failureRow
public ExecRow setBeforeFirstRow() throws StandardException
setBeforeFirstRow
in interface ResultSet
StandardException
- Thrown on failureRow
public boolean checkRowPosition(int isType) throws StandardException
checkRowPosition
in interface ResultSet
StandardException
- Thrown on error.public int getRowNumber()
getRowNumber
in interface ResultSet
public ExecRow getFirstRow() throws StandardException
getFirstRow
in interface ResultSet
StandardException
- Thrown on failureRow
public final ExecRow getNextRow() throws StandardException
restriction and projection parameters are evaluated for each row. NOTE: This method should only be called on the top ResultSet of a ResultSet tree to ensure that the entire ResultSet tree gets closed down on an error. the getNextRowCore() method will be called for all other ResultSets in the tree.
getNextRow
in interface ResultSet
StandardException
- thrown on failure.
StandardException
- ResultSetNotOpen thrown if not yet open.Row
public ExecRow getPreviousRow() throws StandardException
getPreviousRow
in interface ResultSet
StandardException
- Thrown on failureRow
public ExecRow getLastRow() throws StandardException
getLastRow
in interface ResultSet
StandardException
- Thrown on failureRow
public ExecRow setAfterLastRow() throws StandardException
setAfterLastRow
in interface ResultSet
StandardException
- Thrown on failureRow
public boolean returnsRows()
returnsRows
in interface ResultSet
public final int modifiedRowCount()
ResultSet
modifiedRowCount
in interface ResultSet
public void cleanUp() throws StandardException
cleanUp
in interface ResultSet
StandardException
- Thrown on failurepublic boolean isClosed()
isClosed
in interface ResultSet
protected final void finishAndRTS() throws StandardException
StandardException
- on errorpublic long getExecuteTime()
getExecuteTime
in interface ResultSet
public java.sql.Timestamp getBeginExecutionTimestamp()
getBeginExecutionTimestamp
in interface ResultSet
public java.sql.Timestamp getEndExecutionTimestamp()
getEndExecutionTimestamp
in interface ResultSet
public final NoPutResultSet[] getSubqueryTrackingArray(int numSubqueries)
ResultSet
getSubqueryTrackingArray
in interface ResultSet
numSubqueries
- The size of the array (For allocation on demand.)
ResultSet.getSubqueryTrackingArray(int)
protected final long getCurrentTimeMillis()
public ResultSet getAutoGeneratedKeysResultset()
ResultSet
getAutoGeneratedKeysResultset
in interface ResultSet
ResultSet.getAutoGeneratedKeysResultset()
protected final long getElapsedMillis(long beginTime)
protected final java.lang.String dumpTimeStats(java.lang.String indent, java.lang.String subIndent)
protected void attachStatementContext() throws StandardException
StandardException
- thrown if cursor finished.protected final LanguageConnectionContext getLanguageConnectionContext()
final ExecutionFactory getExecutionFactory()
final TransactionController getTransactionController()
protected ExecRow getCompactRow(ExecRow candidate, FormatableBitSet accessedCols, FormatableBitSet otherCols, boolean isKeyed) throws StandardException
candidate
- The row to get the columns fromaccessedCols
- A bit map of the columns that are accessed in
the candidate rowotherCols
- An bit map of other column ids - this is used
in case columns from an index row will be
copied into a heap row - in this case, we
need to be sure there are enough columns in
the compact row. This parameter is null if
columns will not be copied from an index row
to a compact heap row. The column numbers in
the bit map are zero-based.isKeyed
- Tells whether to return a ValueRow or an IndexRow
StandardException
protected ExecRow setCompactRow(ExecRow candidateRow, ExecRow compactRow)
candidateRow
- The candidate row from the storecompactRow
- The compact row to fill in
protected final void setCompatRow(ExecRow compactRow, java.lang.Object[] sourceRow)
protected final void addWarning(java.sql.SQLWarning w)
public final java.sql.SQLWarning getWarnings()
ResultSet
getWarnings
in interface ResultSet
|
Built on Mon 2007-06-04 09:58:47+0400, from revision ??? | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |