org.apache.derby.impl.sql.execute
Class TableScanResultSet

java.lang.Object
  extended by org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl
      extended by org.apache.derby.impl.sql.execute.NoPutResultSetImpl
          extended by org.apache.derby.impl.sql.execute.ScanResultSet
              extended by org.apache.derby.impl.sql.execute.TableScanResultSet
All Implemented Interfaces:
java.lang.Cloneable, CursorResultSet, NoPutResultSet, ResultSet, RowLocationRetRowSource, RowSource
Direct Known Subclasses:
BulkTableScanResultSet, MultiProbeTableScanResultSet

 class TableScanResultSet
extends ScanResultSet
implements CursorResultSet, java.lang.Cloneable

Takes a table and a table filter and returns the table's rows satisfying the filter as a result set. There are several things we could do during object construction that are done in the open & next calls, to improve performance.


Field Summary
 boolean coarserLock
           
protected  boolean compareToLastKey
           
protected  long conglomId
           
private  boolean currentRowIsValid
           
protected  boolean currentRowPrescanned
           
protected  DynamicCompiledOpenConglomInfo dcoci
           
private  long estimatedRowCount
           
protected  boolean firstScan
           
 boolean forUpdate
           
protected  TemporaryRowHolder futureForUpdateRows
           
protected  TemporaryRowHolderResultSet futureRowResultSet
           
protected  int[] indexCols
           
 java.lang.String indexName
           
 boolean isConstraint
           
protected  boolean isKeyed
           
protected  ExecRow lastCursorKey
           
private  boolean nextDone
           
 boolean oneRowScan
           
protected  java.util.Hashtable past2FutureTbl
           
 Qualifier[][] qualifiers
           
private  boolean qualify
           
protected  GeneratedMethod resultRowAllocator
           
private  RowLocation rlTemplate
           
 int rowsPerRead
           
protected  long rowsThisScan
           
protected  boolean runTimeStatisticsOn
           
(package private)  boolean sameStartStopPosition
           
protected  ScanController scanController
           
protected  boolean scanControllerOpened
           
private  java.util.Properties scanProperties
           
private  boolean scanRepositioned
           
protected  StaticCompiledOpenConglomInfo scoci
           
protected  boolean skipFutureRowHolder
           
protected  boolean sourceDrained
           
private  ExecRow sparseRow
           
private  FormatableBitSet sparseRowMap
           
protected  GeneratedMethod startKeyGetter
           
protected  ExecIndexRow startPosition
           
 java.lang.String startPositionString
           
protected  int startSearchOperator
           
protected  GeneratedMethod stopKeyGetter
           
protected  ExecIndexRow stopPosition
           
 java.lang.String stopPositionString
           
protected  int stopSearchOperator
           
 java.lang.String tableName
           
 java.lang.String userSuppliedOptimizerOverrides
           
 
Fields inherited from class org.apache.derby.impl.sql.execute.ScanResultSet
accessedCols, candidate, isolationLevel, lockMode
 
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
TableScanResultSet(long conglomId, StaticCompiledOpenConglomInfo scoci, Activation activation, GeneratedMethod resultRowAllocator, int resultSetNumber, GeneratedMethod startKeyGetter, int startSearchOperator, GeneratedMethod stopKeyGetter, int stopSearchOperator, boolean sameStartStopPosition, Qualifier[][] qualifiers, java.lang.String tableName, java.lang.String userSuppliedOptimizerOverrides, java.lang.String indexName, boolean isConstraint, boolean forUpdate, int colRefItem, int indexColItem, int lockMode, boolean tableLocked, int isolationLevel, int rowsPerRead, boolean oneRowScan, double optimizerEstimatedRowCount, double optimizerEstimatedCost)
           
 
Method Summary
protected  boolean canGetInstantaneousLocks()
          Can we get instantaneous locks when getting share row locks at READ COMMITTED.
 java.lang.Object clone()
          Shallow clone this result set.
 void close()
          If the result set has been opened, close the open scan.
 ExecRow getCurrentRow()
          This result set has its row from the last fetch done.
 ExecRow getNextRowCore()
          Return the next row (if any) from the scan (if open).
 RowLocation getRowLocation()
          This result set has its row location from the last fetch done.
 java.util.Properties getScanProperties()
           
private  void getSparseRowAndMap()
          Check and make sure sparse heap row and accessed bit map are created.
 long getTimeSpent(int type)
          Return the total amount of time spent in this ResultSet
(package private)  void initStartAndStopKey()
          Initialize the startPosition and stopPosition fields which are used to limit the rows returned by the scan.
 boolean isForUpdate()
          Is this ResultSet or it's source result set for update
 void openCore()
          open a scan on the table. scan parameters are evaluated at each open, so there is probably some way of altering their values...
protected  void openScanController(TransactionController tc)
           
 void positionScanAtRowLocation(RowLocation rl)
          Positions the cursor in the specified rowLocation.
private  java.lang.String printPosition(int searchOperator, GeneratedMethod positionGetter, ExecIndexRow positioner)
          Return a start or stop positioner as a String.
 java.lang.String printStartPosition()
          Print an array of Qualifiers to the trace stream.
 java.lang.String printStopPosition()
           
 void reopenCore()
          Reopen a table scan.
protected  void reopenScanController()
           
 boolean requiresRelocking()
          Do we need to relock the row when going to the heap.
protected  void setRowCountIfPossible(long rowsThisScan)
          Update the number of rows in the scan controller.
 
Methods inherited from class org.apache.derby.impl.sql.execute.ScanResultSet
getScanIsolationLevel, initIsolationLevel
 
Methods inherited from class org.apache.derby.impl.sql.execute.NoPutResultSetImpl
clearCurrentRow, clearOrderableCache, closeRowSource, getCursorName, getNextRowFromRowSource, getResultDescription, getValidColumns, markRowAsDeleted, needsRowLocation, needsToClone, printQualifiers, resultSetNumber, rowLocation, setCurrentRow, setNeedsRowLocation, setTargetResultSet, skipRow, skipScan, updateRow
 
Methods inherited from class org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl
addWarning, attachStatementContext, checkCancellationFlag, checkRowPosition, 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, markAsTopResultSet, modifiedRowCount, open, recordConstructorTime, returnsRows, setAfterLastRow, setBeforeFirstRow, setCompactRow, setCompatRow
 
Methods inherited from class java.lang.Object
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

scanController

protected ScanController scanController

scanControllerOpened

protected boolean scanControllerOpened

isKeyed

protected boolean isKeyed

firstScan

protected boolean firstScan

startPosition

protected ExecIndexRow startPosition

stopPosition

protected ExecIndexRow stopPosition

conglomId

protected long conglomId

dcoci

protected DynamicCompiledOpenConglomInfo dcoci

scoci

protected StaticCompiledOpenConglomInfo scoci

resultRowAllocator

protected GeneratedMethod resultRowAllocator

startKeyGetter

protected GeneratedMethod startKeyGetter

startSearchOperator

protected int startSearchOperator

stopKeyGetter

protected GeneratedMethod stopKeyGetter

stopSearchOperator

protected int stopSearchOperator

qualifiers

public Qualifier[][] qualifiers

tableName

public java.lang.String tableName

userSuppliedOptimizerOverrides

public java.lang.String userSuppliedOptimizerOverrides

indexName

public java.lang.String indexName

runTimeStatisticsOn

protected boolean runTimeStatisticsOn

indexCols

protected int[] indexCols

rowsPerRead

public int rowsPerRead

forUpdate

public boolean forUpdate

sameStartStopPosition

final boolean sameStartStopPosition

nextDone

private boolean nextDone

rlTemplate

private RowLocation rlTemplate

scanProperties

private java.util.Properties scanProperties

startPositionString

public java.lang.String startPositionString

stopPositionString

public java.lang.String stopPositionString

isConstraint

public boolean isConstraint

coarserLock

public boolean coarserLock

oneRowScan

public boolean oneRowScan

rowsThisScan

protected long rowsThisScan

estimatedRowCount

private long estimatedRowCount

past2FutureTbl

protected java.util.Hashtable past2FutureTbl

futureForUpdateRows

protected TemporaryRowHolder futureForUpdateRows

futureRowResultSet

protected TemporaryRowHolderResultSet futureRowResultSet

skipFutureRowHolder

protected boolean skipFutureRowHolder

sourceDrained

protected boolean sourceDrained

currentRowPrescanned

protected boolean currentRowPrescanned

compareToLastKey

protected boolean compareToLastKey

lastCursorKey

protected ExecRow lastCursorKey

sparseRow

private ExecRow sparseRow

sparseRowMap

private FormatableBitSet sparseRowMap

qualify

private boolean qualify

currentRowIsValid

private boolean currentRowIsValid

scanRepositioned

private boolean scanRepositioned
Constructor Detail

TableScanResultSet

TableScanResultSet(long conglomId,
                   StaticCompiledOpenConglomInfo scoci,
                   Activation activation,
                   GeneratedMethod resultRowAllocator,
                   int resultSetNumber,
                   GeneratedMethod startKeyGetter,
                   int startSearchOperator,
                   GeneratedMethod stopKeyGetter,
                   int stopSearchOperator,
                   boolean sameStartStopPosition,
                   Qualifier[][] qualifiers,
                   java.lang.String tableName,
                   java.lang.String userSuppliedOptimizerOverrides,
                   java.lang.String indexName,
                   boolean isConstraint,
                   boolean forUpdate,
                   int colRefItem,
                   int indexColItem,
                   int lockMode,
                   boolean tableLocked,
                   int isolationLevel,
                   int rowsPerRead,
                   boolean oneRowScan,
                   double optimizerEstimatedRowCount,
                   double optimizerEstimatedCost)
             throws StandardException
Throws:
StandardException
Method Detail

openCore

public void openCore()
              throws StandardException
open a scan on the table. scan parameters are evaluated at each open, so there is probably some way of altering their values...

Specified by:
openCore in interface NoPutResultSet
Throws:
StandardException - thrown on failure to open

initStartAndStopKey

void initStartAndStopKey()
                   throws StandardException
Initialize the startPosition and stopPosition fields which are used to limit the rows returned by the scan.

Throws:
StandardException

openScanController

protected void openScanController(TransactionController tc)
                           throws StandardException
Throws:
StandardException

reopenScanController

protected void reopenScanController()
                             throws StandardException
Throws:
StandardException

reopenCore

public void reopenCore()
                throws StandardException
Reopen 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:
reopenCore in interface NoPutResultSet
Overrides:
reopenCore in class BasicNoPutResultSetImpl
Throws:
StandardException - thrown on failure to open
See Also:
NoPutResultSet.openCore()

getSparseRowAndMap

private void getSparseRowAndMap()
                         throws StandardException
Check and make sure sparse heap row and accessed bit map are created. beetle 3865, update cursor using index.

Throws:
StandardException - thrown on failure

getNextRowCore

public ExecRow getNextRowCore()
                       throws StandardException
Return the next row (if any) from the scan (if open).

Specified by:
getNextRowCore in interface NoPutResultSet
Specified by:
getNextRowCore in class BasicNoPutResultSetImpl
Returns:
the next row in the result
Throws:
StandardException - thrown on failure to get next row
See Also:
NoPutResultSet.getNextRowCore()

close

public void close()
           throws StandardException
If the result set has been opened, close the open scan.

Specified by:
close in interface ResultSet
Overrides:
close in class ScanResultSet
Throws:
StandardException - on error

getTimeSpent

public long getTimeSpent(int type)
Return the total amount of time spent in this ResultSet

Specified by:
getTimeSpent in interface ResultSet
Parameters:
type - CURRENT_RESULTSET_ONLY - time spent only in this ResultSet ENTIRE_RESULTSET_TREE - time spent in this ResultSet and below.
Returns:
long The total amount of time spent (in milliseconds).

getRowLocation

public RowLocation getRowLocation()
                           throws StandardException
This result set has its row location from the last fetch done. If the cursor is closed, or the row has been deleted a null is returned.

Specified by:
getRowLocation in interface CursorResultSet
Returns:
the row location of the current cursor row.
Throws:
StandardException - thrown on failure to get row location
See Also:
CursorResultSet

getCurrentRow

public ExecRow getCurrentRow()
                      throws StandardException
This result set has its row from the last fetch done. If the cursor is closed, the row has been deleted, or no longer qualifies (for forward only result sets) a null is returned.

Specified by:
getCurrentRow in interface CursorResultSet
Returns:
the last row returned;
Throws:
StandardException - thrown on failure.
See Also:
CursorResultSet

positionScanAtRowLocation

public void positionScanAtRowLocation(RowLocation rl)
                               throws StandardException
Description copied from interface: NoPutResultSet
Positions the cursor in the specified rowLocation. Used for scrollable insensitive result sets in order to position the cursor back to a row that has already be visited.

Specified by:
positionScanAtRowLocation in interface NoPutResultSet
Overrides:
positionScanAtRowLocation in class NoPutResultSetImpl
Parameters:
rl - row location of the current cursor row
Throws:
StandardException - thrown on failure to get location from storage engine
See Also:
Also sets qualify to false so that later calls to getCurrentRow will not attempt to re-qualify the current row.

printStartPosition

public java.lang.String printStartPosition()
Print an array of Qualifiers to the trace stream.


printStopPosition

public java.lang.String printStopPosition()

printPosition

private java.lang.String printPosition(int searchOperator,
                                       GeneratedMethod positionGetter,
                                       ExecIndexRow positioner)
Return a start or stop positioner as a String. If we already generated the information, then use that. Otherwise, invoke the activation to get it.


getScanProperties

public java.util.Properties getScanProperties()

requiresRelocking

public boolean requiresRelocking()
Description copied from interface: NoPutResultSet
Do we need to relock the row when going to the heap.

Specified by:
requiresRelocking in interface NoPutResultSet
Overrides:
requiresRelocking in class BasicNoPutResultSetImpl
Returns:
Whether or not we need to relock the row when going to the heap.
See Also:
NoPutResultSet.requiresRelocking()

setRowCountIfPossible

protected final void setRowCountIfPossible(long rowsThisScan)
                                    throws StandardException
Update the number of rows in the scan controller. NOTE: It would be more efficient to only update the scan controller if the optimizer's estimated number of rows were wrong by more than some threshold (like 10%). This would require a little more work than I have the time for now, however, as the row estimate that is given to this result set is the total number of rows for all scans, not the number of rows per scan.

Parameters:
rowsThisScan - The number of rows to update the scanController to
Throws:
StandardException - Thrown on error

canGetInstantaneousLocks

protected boolean canGetInstantaneousLocks()
Can we get instantaneous locks when getting share row locks at READ COMMITTED.

Specified by:
canGetInstantaneousLocks in class ScanResultSet

isForUpdate

public boolean isForUpdate()
Is this ResultSet or it's source result set for update

Specified by:
isForUpdate in interface NoPutResultSet
Overrides:
isForUpdate in class NoPutResultSetImpl
Returns:
Whether or not the result set is for update.

clone

public java.lang.Object clone()
Shallow clone this result set. Used in trigger reference. beetle 4373.

Overrides:
clone in class java.lang.Object

Built on Thu 2012-03-29 21:53:33+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.