Class BTreeMaxScan
java.lang.Object
org.apache.derby.impl.store.access.btree.OpenBTree
org.apache.derby.impl.store.access.btree.BTreeScan
org.apache.derby.impl.store.access.btree.BTreeMaxScan
- All Implemented Interfaces:
ScanManager, GenericScanController, GroupFetchScanController, RowCountable, ScanController
- Direct Known Subclasses:
B2IMaxScan
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
Fields inherited from class BTreeScan
fetchNext_one_slot_array, init_fetchDesc, init_forUpdate, init_hold, init_lock_fetch_desc, init_qualifier, init_rawtran, init_scanColumnList, init_startKeyValue, init_startSearchOperator, init_stopKeyValue, init_stopSearchOperator, init_template, init_useUpdateLocks, lock_operation, SCAN_DONE, SCAN_HOLD_INIT, SCAN_HOLD_INPROGRESS, SCAN_INIT, SCAN_INPROGRESS, scan_position, scan_state, stat_numdeleted_rows_visited, stat_numpages_visited, stat_numrows_qualified, stat_numrows_visitedFields inherited from class OpenBTree
btree_undo, container, err_containerid, init_lock_level, init_open_user_scans, runtime_memFields inherited from interface ScanController
GE, GT, NA -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanfetchMax(DataValueDescriptor[] fetch_row) Fetch the maximum row in the table.protected intfetchRows(BTreeRowPosition pos, DataValueDescriptor[][] row_array, RowLocation[] rowloc_array, BackingStoreHashtable hash_table, long max_rowcnt, int[] key_column_numbers) disallow fetchRows on this scan type, caller should only be able to call fetchMax().private booleanMove the current position to the page to the left of the current page, right after the last slot on that page.protected voidPosition scan at "start" position of the MAX scan.Methods inherited from class BTreeScan
close, closeForEndTransaction, delete, didNotQualify, doesCurrentPositionQualify, fetch, fetchLocation, fetchNext, fetchNextGroup, fetchNextGroup, fetchSet, fetchWithoutQualify, getCurrentRecordHandleForDebugging, getScanInfo, init, isCurrentPositionDeleted, isEmpty, isHeldAfterCommit, isKeyed, newRowLocationTemplate, next, positionAtDoneScan, positionAtDoneScanFromClose, positionAtNextPage, positionAtPreviousPage, positionAtRowLocation, positionAtStartForForwardScan, process_qualifier, reopenScan, reopenScanByRowLocation, replace, reposition, savePositionAndReleasePage, savePositionAndReleasePage, toStringMethods inherited from class OpenBTree
checkConsistency, debugConglomerate, getColumnSortOrderInfo, getConglomerate, getContainer, getContainerHandle, getEstimatedRowCount, getHeight, getHold, getLockingPolicy, getLockLevel, getOpenMode, getRawTran, getRuntimeMem, getSpaceInfo, getXactMgr, init, isClosed, isIndexableRowConsistent, isTableLocked, reopen, setEstimatedRowCount, setLockingPolicy, test_errorsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface GenericScanController
isTableLockedMethods inherited from interface RowCountable
getEstimatedRowCount, setEstimatedRowCount
-
Constructor Details
-
BTreeMaxScan
public BTreeMaxScan()
-
-
Method Details
-
moveToLeftSibling
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:
- true if the position was successfully moved, false if we had to wait for a latch
- Throws:
StandardException
-
fetchRows
protected int fetchRows(BTreeRowPosition pos, DataValueDescriptor[][] row_array, RowLocation[] rowloc_array, BackingStoreHashtable hash_table, long max_rowcnt, int[] key_column_numbers) throws StandardException disallow fetchRows on this scan type, caller should only be able to call fetchMax().- Specified by:
fetchRowsin classBTreeScan- Throws:
StandardException- Standard exception policy.
-
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.
- Specified by:
positionAtStartPositionin classBTreeScan- Throws:
StandardException- Standard exception policy.
-
fetchMax
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.- Throws:
StandardException- Standard exception policy.
-