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

public Class BTreeCostController

extends OpenBTree
implements StoreCostController
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.store.access.StoreCostController, org.apache.derby.iapi.store.access.RowCountable
Known Direct Subclasses
org.apache.derby.impl.store.access.btree.index.B2ICostController
Imports
org.apache.derby.shared.common.reference.Property, .SQLState, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.store.access.conglomerate.Conglomerate, .LogicalUndo, .TransactionManager, org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo, .ScanController, .StoreCostController, .StoreCostResult, org.apache.derby.iapi.store.raw.ContainerHandle, .Transaction, org.apache.derby.iapi.types.DataValueDescriptor, .RowLocation, org.apache.derby.iapi.services.io.FormatableBitSet, java.util.Properties

The StoreCostController interface provides methods that an access client (most likely the system optimizer) can use to get store's estimated cost of various operations on the conglomerate the StoreCostController was opened for.

It is likely that the implementation of StoreCostController will open the conglomerate and will leave the conglomerate open until the StoreCostController is closed. This represents a significant amount of work, so the caller if possible should attempt to open the StoreCostController once per unit of work and rather than close and reopen the controller. For instance if the optimizer needs to cost 2 different scans against a single conglomerate, it should use one instance of the StoreCostController.

The locking behavior of the implementation of a StoreCostController is undefined, it may or may not get locks on the underlying conglomerate. It may or may not hold locks until end of transaction. An optimal implementation will not get any locks on the underlying conglomerate, thus allowing concurrent access to the table by a executing query while another query is optimizing.

See Also
org.apache.derby.iapi.store.access.TransactionController#openStoreCost

Field Summary

Modifier and TypeField and Description
private static final double
private static final double
private static final double
pack-priv Conglomerate
pack-priv Transaction
pack-priv TransactionManager
pack-priv long
num_pages

Only lookup these estimates from raw store once.

pack-priv long
pack-priv long
pack-priv int
Inherited from org.apache.derby.impl.store.access.btree.OpenBTree:
btree_undocontainererr_containeridinit_lock_levelinit_open_user_scansruntime_mem

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public double

Returns:

The cost of the fetch.
getFetchFromFullKeyCost
(FormatableBitSet
A description of which columns to return from row on the page into "templateRow." templateRow, and validColumns work together to describe the row to be returned by the fetch - see RowUtil for description of how these three parameters work together to describe a fetched "row".
validColumns
,
int
Describe the type of access the query will be performing to the ScanController. STORECOST_CLUSTERED - The location of one scan is likely clustered "close" to the previous scan. For instance if the query plan were to used repeated "reopenScan()'s" to probe for the next key in an index, then this flag should be be specified. If this flag is not set then each scan will be costed independant of any other predicted scan access.
access_type
)

Implements org.apache.derby.iapi.store.access.StoreCostController.getFetchFromFullKeyCost.

Return the cost of exact key lookup.

public double

Returns:

The cost of the fetch.
getFetchFromRowLocationCost
(FormatableBitSet
A description of which columns to return from row on the page into "templateRow." templateRow, and validColumns work together to describe the row to be returned by the fetch - see RowUtil for description of how these three parameters work together to describe a fetched "row".
validColumns
,
int
Describe the type of access the query will be performing to the ConglomerateController. STORECOST_CLUSTERED - The location of one fetch is likely clustered "close" to the next fetch. For instance if the query plan were to sort the RowLocations of a heap and then use those RowLocations sequentially to probe into the heap, then this flag should be specified. If this flag is not set then access to the table is assumed to be random - ie. the type of access one gets if you scan an index and probe each row in turn into the base table is "random".
access_type
)

Implements org.apache.derby.iapi.store.access.StoreCostController.getFetchFromRowLocationCost.

Return the cost of calling ConglomerateController.fetch().

public void
getScanCost(int
The type of scan that will be executed. There are currently 2 types: STORECOST_SCAN_NORMAL - scans will be executed using the standard next/fetch, where each fetch can retrieve 1 or many rows (if fetchNextGroup() interface is used). STORECOST_SCAN_SET - The entire result set will be retrieved using the the fetchSet() interface.
scan_type
,
long
Estimated total row count of the table. The current system tracks row counts in heaps better than btree's (btree's have "rows" which are not user rows - branch rows, control rows), so if available the client should pass in the base table's row count into this routine to be used as the index's row count. If the caller has no idea, pass in -1.
row_count
,
int
The number of rows to be returned by a single fetch call for STORECOST_SCAN_NORMAL scans.
group_size
,
boolean
Should be true if the caller intends to update through the scan.
forUpdate
,
FormatableBitSet
A description of which columns to return from every fetch in the scan. template, and scanColumnList work together to describe the row to be returned by the scan - see RowUtil for description of how these three parameters work together to describe a "row".
scanColumnList
,
DataValueDescriptor[]
A prototypical row which the scan may use to maintain its position in the conglomerate. Not all access method scan types will require this, if they don't it's ok to pass in null. In order to scan a conglomerate one must allocate 2 separate "row" templates. The "row" template passed into openScan is for the private use of the scan itself, and no access to it should be made by the caller while the scan is still open. Because of this the scanner must allocate another "row" template to hold the values returned from fetch(). Note that this template must be for the full row, whether a partial row scan is being executed or not.
template
,
DataValueDescriptor[]
An indexable row which holds a (partial) key value which, in combination with the startSearchOperator, defines the starting position of the scan. If null, the starting position of the scan is the first row of the conglomerate. The startKeyValue must only reference columns included in the scanColumnList.
startKeyValue
,
int
an operator which defines how the startKeyValue is to be searched for. If startSearchOperation is ScanController.GE, the scan starts on the first row which is greater than or equal to the startKeyValue. If startSearchOperation is ScanController.GT, the scan starts on the first row whose key is greater than startKeyValue. The startSearchOperation parameter is ignored if the startKeyValue parameter is null.
startSearchOperator
,
DataValueDescriptor[]
An indexable row which holds a (partial) key value which, in combination with the stopSearchOperator, defines the ending position of the scan. If null, the ending position of the scan is the last row of the conglomerate. The stopKeyValue must only reference columns included in the scanColumnList.
stopKeyValue
,
int
an operator which defines how the stopKeyValue is used to determine the scan stopping position. If stopSearchOperation is ScanController.GE, the scan stops just before the first row which is greater than or equal to the stopKeyValue. If stopSearchOperation is ScanController.GT, the scan stops just before the first row whose key is greater than startKeyValue. The stopSearchOperation parameter is ignored if the stopKeyValue parameter is null.
stopSearchOperator
,
boolean reopen_scan, int
Describe the type of access the query will be performing to the ScanController. STORECOST_CLUSTERED - The location of one scan is likely clustered "close" to the previous scan. For instance if the query plan were to used repeated "reopenScan()'s" to probe for the next key in an index, then this flag should be be specified. If this flag is not set then each scan will be costed independant of any other predicted scan access.
access_type
,
StoreCostResult cost_result)

Implements org.apache.derby.iapi.store.access.StoreCostController.getScanCost.

Calculate the cost of a scan.

public void
init(TransactionManager
access manager transaction.
xact_manager
,
BTree conglomerate, Transaction
Raw store transaction.
rawtran
)

Initialize the cost controller.

public RowLocation

Returns:

The empty Rowlocation.
newRowLocationTemplate
()

Implements org.apache.derby.iapi.store.access.StoreCostController.newRowLocationTemplate.

Return an "empty" row location object of the correct type.

Inherited from org.apache.derby.impl.store.access.btree.OpenBTree:
checkConsistencydebugConglomerategetColumnSortOrderInfogetConglomerategetContainergetContainerHandlegetEstimatedRowCountgetHeightgetHoldgetLockingPolicygetLockLevelgetOpenModegetRawTrangetRuntimeMemgetSpaceInfogetXactMgrinitisClosedisIndexableRowConsistentisTableLockedreopensetEstimatedRowCountsetLockingPolicytest_errors

Field Detail

BTREE_CACHED_FETCH_BY_KEY_PER_LEVELback to summary
private static final double BTREE_CACHED_FETCH_BY_KEY_PER_LEVEL
BTREE_SORTMERGE_FETCH_BY_KEY_PER_LEVELback to summary
private static final double BTREE_SORTMERGE_FETCH_BY_KEY_PER_LEVEL
BTREE_UNCACHED_FETCH_BY_KEY_PER_LEVELback to summary
private static final double BTREE_UNCACHED_FETCH_BY_KEY_PER_LEVEL
init_conglomerateback to summary
pack-priv Conglomerate init_conglomerate

Hides org.apache.derby.impl.store.access.btree.OpenBTree.init_conglomerate.

init_rawtranback to summary
pack-priv Transaction init_rawtran

Hides org.apache.derby.impl.store.access.btree.OpenBTree.init_rawtran.

init_xact_managerback to summary
pack-priv TransactionManager init_xact_manager

Hides org.apache.derby.impl.store.access.btree.OpenBTree.init_xact_manager.

num_pagesback to summary
pack-priv long num_pages

Only lookup these estimates from raw store once.

num_rowsback to summary
pack-priv long num_rows
page_sizeback to summary
pack-priv long page_size
tree_heightback to summary
pack-priv int tree_height

Constructor Detail

BTreeCostControllerback to summary
public BTreeCostController()

Method Detail

closeback to summary
public void close() throws StandardException

Overrides org.apache.derby.impl.store.access.btree.OpenBTree.close.

Implements org.apache.derby.iapi.store.access.StoreCostController.close.

Close the controller.

Close the open controller. This method always succeeds, and never throws any exceptions. Callers must not use the StoreCostController Cost controller after closing it; they are strongly advised to clear out the scan controller reference after closing.

Exceptions
StandardException:

Doc from org.apache.derby.iapi.store.access.StoreCostController.close.

Standard exception policy.

getFetchFromFullKeyCostback to summary
public double getFetchFromFullKeyCost(FormatableBitSet validColumns, int access_type) throws StandardException

Implements org.apache.derby.iapi.store.access.StoreCostController.getFetchFromFullKeyCost.

Return the cost of exact key lookup.

Return the estimated cost of calling ScanController.fetch() on the current conglomerate, with start and stop positions set such that an exact match is expected.

This call returns the cost of a fetchNext() performed on a scan which has been positioned with a start position which specifies exact match on all keys in the row.

Example:

In the case of a btree this call can be used to determine the cost of doing an exact probe into btree, giving all key columns. This cost can be used if the client knows it will be doing an exact key probe but does not have the key's at optimize time to use to make a call to getScanCost()

Parameters
validColumns:FormatableBitSet

A description of which columns to return from row on the page into "templateRow." templateRow, and validColumns work together to describe the row to be returned by the fetch - see RowUtil for description of how these three parameters work together to describe a fetched "row".

access_type:int

Describe the type of access the query will be performing to the ScanController. STORECOST_CLUSTERED - The location of one scan is likely clustered "close" to the previous scan. For instance if the query plan were to used repeated "reopenScan()'s" to probe for the next key in an index, then this flag should be be specified. If this flag is not set then each scan will be costed independant of any other predicted scan access.

Returns:double

The cost of the fetch.

Exceptions
StandardException:
Standard exception policy.
See Also
org.apache.derby.iapi.store.access.RowUtil
getFetchFromRowLocationCostback to summary
public double getFetchFromRowLocationCost(FormatableBitSet validColumns, int access_type) throws StandardException

Implements org.apache.derby.iapi.store.access.StoreCostController.getFetchFromRowLocationCost.

Return the cost of calling ConglomerateController.fetch().

Return the estimated cost of calling ConglomerateController.fetch() on the current conglomerate. This gives the cost of finding a record in the conglomerate given the exact RowLocation of the record in question.

The validColumns parameter describes what kind of row is being fetched, ie. it may be cheaper to fetch a partial row than a complete row.

Parameters
validColumns:FormatableBitSet

A description of which columns to return from row on the page into "templateRow." templateRow, and validColumns work together to describe the row to be returned by the fetch - see RowUtil for description of how these three parameters work together to describe a fetched "row".

access_type:int

Describe the type of access the query will be performing to the ConglomerateController. STORECOST_CLUSTERED - The location of one fetch is likely clustered "close" to the next fetch. For instance if the query plan were to sort the RowLocations of a heap and then use those RowLocations sequentially to probe into the heap, then this flag should be specified. If this flag is not set then access to the table is assumed to be random - ie. the type of access one gets if you scan an index and probe each row in turn into the base table is "random".

Returns:double

The cost of the fetch.

Exceptions
StandardException:
Standard exception policy.
See Also
org.apache.derby.iapi.store.access.RowUtil
getScanCostback to summary
public void getScanCost(int scan_type, long row_count, int group_size, boolean forUpdate, FormatableBitSet scanColumnList, DataValueDescriptor[] template, DataValueDescriptor[] startKeyValue, int startSearchOperator, DataValueDescriptor[] stopKeyValue, int stopSearchOperator, boolean reopen_scan, int access_type, StoreCostResult cost_result) throws StandardException

Implements org.apache.derby.iapi.store.access.StoreCostController.getScanCost.

Calculate the cost of a scan.

Cause this object to calculate the cost of performing the described scan. The interface is setup such that first a call is made to calcualteScanCost(), and then subsequent calls to accessor routines are made to get various pieces of information about the cost of the scan.

For the purposes of costing this routine is going to assume that a page will remain in cache between the time one next()/fetchNext() call and a subsequent next()/fetchNext() call is made within a scan.

The result of costing the scan is placed in the "cost_result". The cost of the scan is stored by calling cost_result.setEstimatedCost(cost). The estimated row count is stored by calling cost_result.setEstimatedRowCount(row_count).

The estimated cost of the scan assumes the caller will execute a fetchNext() loop for every row that qualifies between start and stop position. Note that this cost is different than execution a next(),fetch() loop; or if the scan is going to be terminated by client prior to reaching the stop condition.

The estimated number of rows returned from the scan assumes the caller will execute a fetchNext() loop for every row that qualifies between start and stop position.

Parameters
scan_type:int

The type of scan that will be executed. There are currently 2 types: STORECOST_SCAN_NORMAL - scans will be executed using the standard next/fetch, where each fetch can retrieve 1 or many rows (if fetchNextGroup() interface is used). STORECOST_SCAN_SET - The entire result set will be retrieved using the the fetchSet() interface.

row_count:long

Estimated total row count of the table. The current system tracks row counts in heaps better than btree's (btree's have "rows" which are not user rows - branch rows, control rows), so if available the client should pass in the base table's row count into this routine to be used as the index's row count. If the caller has no idea, pass in -1.

group_size:int

The number of rows to be returned by a single fetch call for STORECOST_SCAN_NORMAL scans.

forUpdate:boolean

Should be true if the caller intends to update through the scan.

scanColumnList:FormatableBitSet

A description of which columns to return from every fetch in the scan. template, and scanColumnList work together to describe the row to be returned by the scan - see RowUtil for description of how these three parameters work together to describe a "row".

template:DataValueDescriptor[]

A prototypical row which the scan may use to maintain its position in the conglomerate. Not all access method scan types will require this, if they don't it's ok to pass in null. In order to scan a conglomerate one must allocate 2 separate "row" templates. The "row" template passed into openScan is for the private use of the scan itself, and no access to it should be made by the caller while the scan is still open. Because of this the scanner must allocate another "row" template to hold the values returned from fetch(). Note that this template must be for the full row, whether a partial row scan is being executed or not.

startKeyValue:DataValueDescriptor[]

An indexable row which holds a (partial) key value which, in combination with the startSearchOperator, defines the starting position of the scan. If null, the starting position of the scan is the first row of the conglomerate. The startKeyValue must only reference columns included in the scanColumnList.

startSearchOperator:int

an operator which defines how the startKeyValue is to be searched for. If startSearchOperation is ScanController.GE, the scan starts on the first row which is greater than or equal to the startKeyValue. If startSearchOperation is ScanController.GT, the scan starts on the first row whose key is greater than startKeyValue. The startSearchOperation parameter is ignored if the startKeyValue parameter is null.

stopKeyValue:DataValueDescriptor[]

An indexable row which holds a (partial) key value which, in combination with the stopSearchOperator, defines the ending position of the scan. If null, the ending position of the scan is the last row of the conglomerate. The stopKeyValue must only reference columns included in the scanColumnList.

stopSearchOperator:int

an operator which defines how the stopKeyValue is used to determine the scan stopping position. If stopSearchOperation is ScanController.GE, the scan stops just before the first row which is greater than or equal to the stopKeyValue. If stopSearchOperation is ScanController.GT, the scan stops just before the first row whose key is greater than startKeyValue. The stopSearchOperation parameter is ignored if the stopKeyValue parameter is null.

access_type:int

Describe the type of access the query will be performing to the ScanController. STORECOST_CLUSTERED - The location of one scan is likely clustered "close" to the previous scan. For instance if the query plan were to used repeated "reopenScan()'s" to probe for the next key in an index, then this flag should be be specified. If this flag is not set then each scan will be costed independant of any other predicted scan access.

Exceptions
StandardException:
Standard exception policy.
See Also
org.apache.derby.iapi.store.access.RowUtil
initback to summary
public void init(TransactionManager xact_manager, BTree conglomerate, Transaction rawtran) throws StandardException

Initialize the cost controller.

Save initialize parameters away, and open the underlying container.

Parameters
xact_manager:TransactionManager

access manager transaction.

rawtran:Transaction

Raw store transaction.

Exceptions
StandardException:
Standard exception policy.
newRowLocationTemplateback to summary
public RowLocation newRowLocationTemplate() throws StandardException

Implements org.apache.derby.iapi.store.access.StoreCostController.newRowLocationTemplate.

Return an "empty" row location object of the correct type.

Returns:RowLocation

The empty Rowlocation.

Exceptions
StandardException:
Standard exception policy.