Top Description Fields Constructors Methods
org.apache.derby.impl.store.access.btree

public Class BTreeMaxScan

extends BTreeScan
Class Inheritance
Known Direct Subclasses
org.apache.derby.impl.store.access.btree.index.B2IMaxScan
Imports
org.apache.derby.shared.common.reference.SQLState, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.store.raw.Page, .RecordHandle, org.apache.derby.iapi.types.DataValueDescriptor, .RowLocation, org.apache.derby.iapi.store.access.BackingStoreHashtable

A BTreeScan implementation that provides the 95% solution to the max on btree problem. If the row is the last row in the btree it works very efficiently. This implementation will be removed once backward scan is fully functional. The current implementation only exports to the user the ability to call fetchMax() and get back one row, none of the generic scan ablities are exported. To return the maximum row this implementation does the following: 1) calls positionAtStartPosition() which returns with the a latch on the rightmost leaf page and a lock on the rightmost leaf row on that page. It will loop until it can get the lock without waiting while holding the latch. At this point the slot position is just right of the locked row. 2) in fetchMax() it loops backward on the last leaf page, locking rows as it does so, until it finds the first non-deleted, non-NULL row. 3) If it is not successful in this last page search it attempts to latch the left sibling page, without waiting to avoid deadlocks with forward scans, and continue the search on that page. 4) If the sibling page couldn't be latched without waiting, save the current position, release all latches, and restart the scan from the saved position.

Field Summary

Inherited from org.apache.derby.impl.store.access.btree.BTreeScan:
fetchNext_one_slot_arrayinit_fetchDescinit_forUpdateinit_holdinit_lock_fetch_descinit_qualifierinit_rawtraninit_scanColumnListinit_startKeyValueinit_startSearchOperatorinit_stopKeyValueinit_stopSearchOperatorinit_templateinit_useUpdateLockslock_operationSCAN_DONESCAN_HOLD_INITSCAN_HOLD_INPROGRESSSCAN_INITSCAN_INPROGRESSscan_positionscan_statestat_numdeleted_rows_visitedstat_numpages_visitedstat_numrows_qualifiedstat_numrows_visited

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
fetchMax(DataValueDescriptor[] fetch_row)

Fetch the maximum row in the table.

protected int
fetchRows(BTreeRowPosition pos, DataValueDescriptor[][] row_array, RowLocation[] rowloc_array, BackingStoreHashtable hash_table, long max_rowcnt, int[] key_column_numbers)

Implements abstract org.apache.derby.impl.store.access.btree.BTreeScan.fetchRows.

disallow fetchRows on this scan type, caller should only be able to call fetchMax().

private boolean

Returns:

true if the position was successfully moved, false if we had to wait for a latch
moveToLeftSibling
()

Move the current position to the page to the left of the current page, right after the last slot on that page.

protected void
positionAtStartPosition(BTreeRowPosition pos)

Implements abstract org.apache.derby.impl.store.access.btree.BTreeScan.positionAtStartPosition.

Position scan at "start" position of the MAX scan.

Inherited from org.apache.derby.impl.store.access.btree.BTreeScan:
closecloseForEndTransactiondeletedidNotQualifydoesCurrentPositionQualifyfetchfetchLocationfetchNextfetchNextGroupfetchNextGroupfetchSetfetchWithoutQualifygetCurrentRecordHandleForDebugginggetScanInfoinitisCurrentPositionDeletedisEmptyisHeldAfterCommitisKeyednewRowLocationTemplatenextpositionAtDoneScanpositionAtDoneScanFromClosepositionAtNextPagepositionAtPreviousPagepositionAtRowLocationpositionAtStartForForwardScanprocess_qualifierreopenScanreopenScanByRowLocationreplacerepositionsavePositionAndReleasePagesavePositionAndReleasePagetoString

Constructor Detail

BTreeMaxScanback to summary
public BTreeMaxScan()

Method Detail

fetchMaxback to summary
public boolean fetchMax(DataValueDescriptor[] fetch_row) throws StandardException

Fetch the maximum row in the table. Call positionAtStartPosition() to quickly position on rightmost row of rightmost leaf of tree. Search last page for last non deleted row, and if one is found return it as max. If no row found on last page, or could not find row without losing latch then call fetchMaxRowFromBeginning() to search from left to right for maximum value in index.

Exceptions
StandardException:
Standard exception policy.
fetchRowsback to summary
protected int fetchRows(BTreeRowPosition pos, DataValueDescriptor[][] row_array, RowLocation[] rowloc_array, BackingStoreHashtable hash_table, long max_rowcnt, int[] key_column_numbers) throws StandardException

Implements abstract org.apache.derby.impl.store.access.btree.BTreeScan.fetchRows.

disallow fetchRows on this scan type, caller should only be able to call fetchMax().

Exceptions
StandardException:
Standard exception policy.
moveToLeftSiblingback to summary
private boolean moveToLeftSibling() throws StandardException

Move the current position to the page to the left of the current page, right after the last slot on that page. If we have to wait for a latch, give up the latch on the current leaf and give up. The caller will have to reposition and retry.

Returns:boolean

true if the position was successfully moved, false if we had to wait for a latch

positionAtStartPositionback to summary
protected void positionAtStartPosition(BTreeRowPosition pos) throws StandardException

Implements abstract org.apache.derby.impl.store.access.btree.BTreeScan.positionAtStartPosition.

Position scan at "start" position of the MAX scan.

Positions the scan to the slot just after the last record on the rightmost leaf of the index. Returns the rightmost leaf page latched, the rightmost row on the page locked and sets "current_slot" to the slot number just right of the last row on the page.

Exceptions
StandardException:
Standard exception policy.