Class MultiProbeTableScanResultSet
java.lang.Object
org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl
org.apache.derby.impl.sql.execute.NoPutResultSetImpl
org.apache.derby.impl.sql.execute.ScanResultSet
org.apache.derby.impl.sql.execute.TableScanResultSet
org.apache.derby.impl.sql.execute.MultiProbeTableScanResultSet
- All Implemented Interfaces:
Cloneable, CursorResultSet, NoPutResultSet, ResultSet, RowLocationRetRowSource, RowSource
Result set that fetches rows from a scan by "probing" the underlying
table with a given list of values. Repeated calls to getNextRowCore()
will first return all rows matching probeValues[0], then all rows matching
probeValues[1], and so on (duplicate probe values are ignored). Once all
matching rows for all values in probeValues have been returned, the call
to getNextRowCore() will return null, thereby ending the scan. The
expectation is that this kind of result set only ever appears beneath
some other top-level result set (esp. IndexRowToBaseRowResultSet), in
which case all result sets higher up in the result set tree will just
see a stream of rows satisfying the list of probe values.
Currently this type of result is used for evaluation of IN lists, where
the user wants to retrieve all rows for which some target column has a
value that equals one of values in the IN list. In that case the IN list
values are represented by the probeValues array.
Most of the work for this class is inherited from TableScanResultSet.
This class overrides four public methods and two protected methods
from TableScanResultSet. In all cases the methods here set probing
state and then call the corresponding methods on "super".
-
Nested Class Summary
Nested classes/interfaces inherited from class BasicNoPutResultSetImpl
BasicNoPutResultSetImpl.FieldComparator -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DataValueDescriptor[]The values with which we will probe the table, as they were passed to the constructor.protected int0-based position of the next value to lookup w.r.t. the probe values list.protected DataValueDescriptor[]The values with which we will probe the table.private booleanTells whether or not we should skip the next attempt to (re)open the scan controller.private intIndicator as to which type of sort we need: ASCENDING, DESCENDING, or NONE (NONE is represented by "RowOrdering.DONTCARE" and is used for cases where all necessary sorting occurred at compilation time).Fields inherited from class TableScanResultSet
coarserLock, conglomId, currentRowIsValid, dcoci, firstScan, forUpdate, indexCols, isConstraint, isKeyed, nextDone, oneRowScan, past2FutureTbl, qualifiers, qualify, rowsPerRead, rowsThisScan, runTimeStatisticsOn, sameStartStopPosition, scanController, scanControllerOpened, scanRepositioned, scoci, startKeyGetter, startPosition, startPositionString, startSearchOperator, stopKeyGetter, stopPosition, stopPositionString, stopSearchOperator, userSuppliedOptimizerOverridesFields inherited from class ScanResultSet
accessedCols, candidate, fetchRowLocations, indexName, isolationLevel, lockMode, resultRowBuilder, tableNameFields inherited from class NoPutResultSetImpl
checkNullCols, clonedExecRow, cncLen, resultSetNumber, targetResultSetFields inherited from class BasicNoPutResultSetImpl
activation, beginTime, closeTime, compactRow, constructorTime, currentRow, endExecutionTime, finished, isOpen, isTopResultSet, nextTime, numOpens, openTime, optimizerEstimatedCost, optimizerEstimatedRowCount, resultDescription, rowsFiltered, rowsSeen, startExecutionTime, subqueryTrackingArrayFields inherited from interface NoPutResultSet
ABSOLUTE, FIRST, LAST, NEXT, PREVIOUS, RELATIVE, TEMPORARY_RESULT_SET_NUMBERFields inherited from interface ResultSet
CURRENT_RESULTSET_ONLY, ENTIRE_RESULTSET_TREE, ISAFTERLAST, ISBEFOREFIRST, ISFIRST, ISLAST -
Constructor Summary
ConstructorsConstructorDescriptionMultiProbeTableScanResultSet(long conglomId, StaticCompiledOpenConglomInfo scoci, Activation activation, int resultRowTemplate, int resultSetNumber, GeneratedMethod startKeyGetter, int startSearchOperator, GeneratedMethod stopKeyGetter, int stopSearchOperator, boolean sameStartStopPosition, Qualifier[][] qualifiers, DataValueDescriptor[] probingVals, int sortRequired, String tableName, String userSuppliedOptimizerOverrides, String indexName, boolean isConstraint, boolean forUpdate, int colRefItem, int indexColItem, int lockMode, boolean tableLocked, int isolationLevel, boolean oneRowScan, double optimizerEstimatedRowCount, double optimizerEstimatedCost) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()If the result set has been opened, close the open scan.private DataValueDescriptorReturn the next non-duplicate value from the probe list.Return the next row (if any) from the scan (if open).(package private) voidInitialize the start key and the stop key used in the scan.private booleanFigure out whether or not we can (re-)position the scan controller based on the next value in probeValues.voidopenCore()open a scan on the table. scan parameters are evaluated at each open, so there is probably some way of altering their values...voidReopen a table scan.private voidreopenCore(boolean forNextProbe) There are two scenarios for which we reopen this kind of scan: A - The first is for join processing.protected voidReopen the scan controllerprotected booleanskipScan(ExecIndexRow startPosition, ExecIndexRow stopPosition) Check if the scan should be skipped.Methods inherited from class TableScanResultSet
canGetInstantaneousLocks, clone, getCurrentRow, getRowLocation, getScanProperties, getTimeSpent, isForUpdate, loopControl, openScanController, positionScanAtRowLocation, printStartPosition, printStopPosition, requiresRelocking, setRowCountIfPossibleMethods inherited from class ScanResultSet
getScanIsolationLevel, initIsolationLevel, setRowLocationsState, toXMLMethods inherited from class NoPutResultSetImpl
clearCurrentRow, clearOrderableCache, closeRowSource, getCursorName, getNextRowFromRowSource, getResultDescription, getValidColumns, markRowAsDeleted, needsRowLocation, needsRowLocationForDeferredCheckConstraints, needsToClone, offendingRowLocation, printQualifiers, resultSetNumber, rowLocation, setCurrentRow, setHasDeferrableChecks, setNeedsRowLocation, setTargetResultSet, skipRow, unpackHashValue, updateRowMethods inherited from class BasicNoPutResultSetImpl
addWarning, attachStatementContext, checkCancellationFlag, checkRowPosition, childrenToXML, cleanUp, dumpTimeStats, finish, finishAndRTS, getAbsoluteRow, getActivation, getAutoGeneratedKeysResultset, getBeginExecutionTimestamp, getCompactRow, getCurrentTimeMillis, getElapsedMillis, getEndExecutionTimestamp, getEstimatedRowCount, getExecuteTime, getExecutionFactory, getFirstRow, getLanguageConnectionContext, getLastRow, getNextRow, getPointOfAttachment, getPreviousRow, getRelativeRow, getRowNumber, getSubqueryTrackingArray, getTransactionController, getWarnings, isClosed, isXplainOnlyMode, markAsTopResultSet, modifiedRowCount, open, recordConstructorTime, returnsRows, setAfterLastRow, setBeforeFirstRow, setCompactRow, setCompatRow, toXMLMethods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CursorResultSet
getCurrentRow, getRowLocationMethods inherited from interface ResultSet
addWarning, checkRowPosition, cleanUp, clearCurrentRow, finish, getAbsoluteRow, getActivation, getAutoGeneratedKeysResultset, getBeginExecutionTimestamp, getCursorName, getEndExecutionTimestamp, getExecuteTime, getFirstRow, getLastRow, getNextRow, getPreviousRow, getRelativeRow, getResultDescription, getRowNumber, getSubqueryTrackingArray, getTimeSpent, getWarnings, isClosed, modifiedRowCount, open, returnsRows, setAfterLastRow, setBeforeFirstRow, toXML
-
Field Details
-
probeValues
The values with which we will probe the table. -
origProbeValues
The values with which we will probe the table, as they were passed to the constructor. We need to keep them unchanged in case the result set is reused when a statement is re-executed (see DERBY-827). -
probeValIndex
protected int probeValIndex0-based position of the next value to lookup w.r.t. the probe values list. -
sortRequired
private int sortRequiredIndicator as to which type of sort we need: ASCENDING, DESCENDING, or NONE (NONE is represented by "RowOrdering.DONTCARE" and is used for cases where all necessary sorting occurred at compilation time). -
skipNextScan
private boolean skipNextScanTells whether or not we should skip the next attempt to (re)open the scan controller. If it istrueit means that the previous call toinitStartAndStopKey()did not find a new probe value, which means that the probe list is exhausted and we shouldn't perform a scan.
-
-
Constructor Details
-
MultiProbeTableScanResultSet
MultiProbeTableScanResultSet(long conglomId, StaticCompiledOpenConglomInfo scoci, Activation activation, int resultRowTemplate, int resultSetNumber, GeneratedMethod startKeyGetter, int startSearchOperator, GeneratedMethod stopKeyGetter, int stopSearchOperator, boolean sameStartStopPosition, Qualifier[][] qualifiers, DataValueDescriptor[] probingVals, int sortRequired, String tableName, String userSuppliedOptimizerOverrides, String indexName, boolean isConstraint, boolean forUpdate, int colRefItem, int indexColItem, int lockMode, boolean tableLocked, int isolationLevel, boolean oneRowScan, double optimizerEstimatedRowCount, double optimizerEstimatedCost) throws StandardException Constructor. Just save off the relevant probing state and pass everything else up to TableScanResultSet.- Throws:
StandardException- thrown on failure to open- See Also:
-
-
Method Details
-
openCore
Description copied from class:TableScanResultSetopen a scan on the table. scan parameters are evaluated at each open, so there is probably some way of altering their values...- Specified by:
openCorein interfaceNoPutResultSet- Overrides:
openCorein classTableScanResultSet- Throws:
StandardException- thrown on failure to open- See Also:
-
reopenCore
Description copied from class:TableScanResultSetReopen a table scan. Here we take advantage of the reopenScan() interface on scanController for optimimal performance on joins where we are an inner table.- Specified by:
reopenCorein interfaceNoPutResultSet- Overrides:
reopenCorein classTableScanResultSet- Throws:
StandardException- thrown on failure to open- See Also:
-
reopenCore
There are two scenarios for which we reopen this kind of scan: A - The first is for join processing. In this case we have a(nother) row from some outer table and we want to reopen this scan to look for rows matching the new outer row. B - The second is for multi-probing. Here we want to reopen the scan on this table to look for rows matching the next value in the probe list. If we are reopening the scan for scenario A (join processing) then we need to reset our position within the probe list. If we are reopening the scan for scenario B then we do *not* want to reset our position within the probe list because that position tells us where to find the next probe value. That said, this method does the work of reopenCore() using the received boolean to determine which of the two scenarios we are in. Note that if our current position (i.e. the value of probeValIndex) is beyond the length of the probe list then we know that we are reopening the scan for scenario A. Or put another away, we should never get here for scenario B if probeValIndex is greater than or equal to the length of the probe list. The reason is that the call to reopenCore() for scenario B will only ever happen when moreInListVals() returns true--and in that case we know that probeValIndex will be less than the length of the probeValues. But the opposite is not true: i.e. it is *not* safe to say that a probeValIndex which is less than the length of probe list is always for scenario B. That's not true because it's possible that the join to which this scan belongs is a "oneRowRightSide" join, meaning that this, the "right" side scan, will be "interrupted" after we return a single row for the current outer row. If we then come back with a new outer row we need to reset our position-- even though probeValIndex will be less than probeValues.length in that case. DERBY-3603.- Throws:
StandardException
-
reopenScanController
Reopen the scan controller- Overrides:
reopenScanControllerin classTableScanResultSet- Throws:
StandardException- thrown on failure to open
-
initStartAndStopKey
Initialize the start key and the stop key used in the scan. Both keys will be set to the probe value. If no new probe value was found (the probe list was exhausted), the flag skipNextScan will betruewhen the method returns to prevent a new scan from being reopened with a missing or incorrect probe value.- Overrides:
initStartAndStopKeyin classTableScanResultSet- Throws:
StandardException
-
skipScan
protected boolean skipScan(ExecIndexRow startPosition, ExecIndexRow stopPosition) throws StandardException Check if the scan should be skipped. It should be skipped if (1)initStartAndStopKey()exhausted the probe list, or (2) the scan should return no results because of nulls in the start key or stop key. SeeNoPutResultSetImpl.skipScan(ExecIndexRow,ExecIndexRow)for details about (2).- Overrides:
skipScanin classNoPutResultSetImpl- Parameters:
startPosition- the key on which to start the scanstopPosition- the key on which to stop the scan- Returns:
trueif scan should be skipped,falseotherwise- Throws:
StandardException
-
getNextRowCore
Return the next row (if any) from the scan (if open). More specifically we do the following: 1 - See if we have a row to read from the current scan position. If so, return that row (done). 2 - If there are no more rows to read from the current scan position AND if there are more probe values to look at, then a) reposition the scan using the next probe value as the start/stop key and b) go back to step 1. Otherwise proceed to step 3. 3 - Return null (no more rows). Note that step 1 is important for cases where multiple rows in this table match a single probe value. In such a scenario we have to be sure that we do *not* move on to the next probe value until we have returned all of the rows for the _current_ probe value.- Specified by:
getNextRowCorein interfaceNoPutResultSet- Overrides:
getNextRowCorein classTableScanResultSet- Returns:
- the next row in the result
- Throws:
StandardException- thrown on failure to get next row- See Also:
-
close
Description copied from class:TableScanResultSetIf the result set has been opened, close the open scan.- Specified by:
closein interfaceResultSet- Overrides:
closein classTableScanResultSet- Throws:
StandardException- on error- See Also:
-
moreInListVals
private boolean moreInListVals()Figure out whether or not we can (re-)position the scan controller based on the next value in probeValues. This will return false when we have exhausted the probe list (i.e. when we've gone through all of the values). -
getNextProbeValue
Return the next non-duplicate value from the probe list. Assumption is that the list is sorted so that duplicates appear next to each other, and that probeValIndex is the index of the next value. If we've exhausted the probe list then just return null.
-