org.apache.derby.iapi.sql.compile
Interface Optimizable

All Known Implementing Classes:
CurrentOfNode, DistinctNode, FromBaseTable, FromSubquery, FromTable, FromVTI, GroupByNode, HalfOuterJoinNode, HashTableNode, IndexToBaseRowNode, IntersectOrExceptNode, JoinNode, MaterializeResultSetNode, NormalizeResultSetNode, OrderByNode, ProjectRestrictNode, RowCountNode, RowResultSetNode, ScrollInsensitiveResultSetNode, SetOperatorNode, SingleChildResultSetNode, TableOperatorNode, UnionNode, WindowResultSetNode

public interface Optimizable

Optimizable provides services for optimizing a table in a query.


Method Summary
 boolean considerSortAvoidancePath()
          Check whether this optimizable's sort avoidance path should be considered.
 int convertAbsoluteToRelativeColumnPosition(int absolutePosition)
          Convert an absolute to a relative 0-based column position.
 CostEstimate estimateCost(OptimizablePredicateList predList, ConglomerateDescriptor cd, CostEstimate outerCost, Optimizer optimizer, RowOrdering rowOrdering)
          Estimate the cost of scanning this Optimizable using the given predicate list with the given conglomerate.
 boolean feasibleJoinStrategy(OptimizablePredicateList predList, Optimizer optimizer)
          Is the current proposed join strategy for this optimizable feasible given the predicate list?
 boolean forUpdate()
          Return true if this is the target table of an update
 java.lang.String getBaseTableName()
          Get the table name of this Optimizable.
 AccessPath getBestAccessPath()
          Get the best access path for this Optimizable.
 AccessPath getBestSortAvoidancePath()
          Get the best sort-avoidance path for this Optimizable.
 AccessPath getCurrentAccessPath()
          Get the current access path under consideration for this Optimizable
 DataDictionary getDataDictionary()
          Get the DataDictionary from this Optimizable.
 java.lang.String getName()
          Get the (exposed) name of this Optimizable
 int getNumColumnsReturned()
          Get the number of the number of columns returned by this Optimizable.
 java.util.Properties getProperties()
          Get the Properties list, if any, associated with this optimizable.
 JBitSet getReferencedTableMap()
          Get the map of referenced tables for this Optimizable.
 int getResultSetNumber()
          Get this Optimizable's result set number
 TableDescriptor getTableDescriptor()
          Get the table descriptor for this table (if any).
 int getTableNumber()
          Get this Optimizable's table number
 AccessPath getTrulyTheBestAccessPath()
          Get the best access path overall for this Optimizable.
 int[] hashKeyColumns()
          Return the hash key column numbers, for hash join strategy
 boolean hasTableNumber()
          Return true if this Optimizable has a table number
 void initAccessPaths(Optimizer optimizer)
          Init the access paths for this optimizable.
 int initialCapacity()
          Return the initial capacity of the hash table, for hash join strategy
 boolean isBaseTable()
          Tell whether this Optimizable represents a base table
 boolean isCoveringIndex(ConglomerateDescriptor cd)
          Return whether or not this is a covering index.
 boolean isMaterializable()
          Tell whether this Optimizable is materializable
 boolean isOneRowScan()
          Will the optimizable return at most 1 row per scan?
 boolean isTargetTable()
          Is the optimizable the target table of an update or delete?
 boolean legalJoinOrder(JBitSet assignedTableMap)
          Can this Optimizable appear at the current location in the join order.
 float loadFactor()
          Return the load factor of the hash table, for hash join strategy
 int maxCapacity(JoinStrategy joinStrategy, int maxMemoryPerTable)
          Return the maximum capacity of the hash table, for hash join strategy
 boolean memoryUsageOK(double rowCount, int maxMemoryPerTable)
           
 Optimizable modifyAccessPath(JBitSet outerTables)
          Modify the access path for this Optimizable, as necessary.
 boolean nextAccessPath(Optimizer optimizer, OptimizablePredicateList predList, RowOrdering rowOrdering)
          Choose the next access path to evaluate for this Optimizable.
 CostEstimate optimizeIt(Optimizer optimizer, OptimizablePredicateList predList, CostEstimate outerCost, RowOrdering rowOrdering)
          Choose the best access path for this Optimizable.
 void pullOptPredicates(OptimizablePredicateList optimizablePredicates)
          Pull all the OptimizablePredicates from this Optimizable and put them in the given OptimizablePredicateList.
 boolean pushOptPredicate(OptimizablePredicate optimizablePredicate)
          Push an OptimizablePredicate down, if this node accepts it.
 void rememberAsBest(int planType, Optimizer optimizer)
          Remember the current access path as the best one (so far).
 void rememberJoinStrategyAsBest(AccessPath ap)
          Remember the current join strategy as the best one so far in this join order.
 void rememberSortAvoidancePath()
          Mark this optimizable so that its sort avoidance path will be considered.
 void setHashKeyColumns(int[] columnNumbers)
          Set the hash key column numbers, for hash join strategy
 void setProperties(java.util.Properties tableProperties)
          Set the Properties list for this optimizalbe.
 void startOptimizing(Optimizer optimizer, RowOrdering rowOrdering)
          Begin the optimization process for this Optimizable.
 boolean supportsMultipleInstantiations()
          Tell whether this Optimizable can be instantiated multiple times
 double uniqueJoin(OptimizablePredicateList predList)
          Does this optimizable have a uniqueness condition on the given predicate list, and if so, how many unique keys will be returned per scan.
 void updateBestPlanMap(short action, java.lang.Object planKey)
          When remembering "truly the best" access path for an Optimizable, we have to keep track of which OptimizerImpl the "truly the best" access is for.
 void verifyProperties(DataDictionary dDictionary)
          Verify that the Properties list with optimizer overrides, if specified, is valid
 

Method Detail

nextAccessPath

boolean nextAccessPath(Optimizer optimizer,
                       OptimizablePredicateList predList,
                       RowOrdering rowOrdering)
                       throws StandardException
Choose the next access path to evaluate for this Optimizable.

Parameters:
optimizer - Optimizer to use.
predList - The predicate list for this optimizable. The optimizer always passes null, and it is up to the optimizable object to pass along its own predicate list, if appropriate, when delegating this method.
rowOrdering - The row ordering for all the outer tables in the join order. This method will add the ordering of the next access path to the given RowOrdering.
Returns:
true means another access path was chosen, false means no more access paths to evaluate.
Throws:
StandardException - Thrown on error

optimizeIt

CostEstimate optimizeIt(Optimizer optimizer,
                        OptimizablePredicateList predList,
                        CostEstimate outerCost,
                        RowOrdering rowOrdering)
                        throws StandardException
Choose the best access path for this Optimizable.

Parameters:
optimizer - Optimizer to use.
predList - The predicate list to optimize against
outerCost - The CostEstimate for the outer tables in the join order, telling how many times this Optimizable will be scanned.
rowOrdering - The row ordering for all the tables in the join order, including this one.
Returns:
The optimizer's estimated cost of the best access path.
Throws:
StandardException - Thrown on error

getCurrentAccessPath

AccessPath getCurrentAccessPath()
Get the current access path under consideration for this Optimizable


getBestAccessPath

AccessPath getBestAccessPath()
Get the best access path for this Optimizable.


getBestSortAvoidancePath

AccessPath getBestSortAvoidancePath()
Get the best sort-avoidance path for this Optimizable.


getTrulyTheBestAccessPath

AccessPath getTrulyTheBestAccessPath()
Get the best access path overall for this Optimizable.


rememberSortAvoidancePath

void rememberSortAvoidancePath()
Mark this optimizable so that its sort avoidance path will be considered.


considerSortAvoidancePath

boolean considerSortAvoidancePath()
Check whether this optimizable's sort avoidance path should be considered.


rememberJoinStrategyAsBest

void rememberJoinStrategyAsBest(AccessPath ap)
Remember the current join strategy as the best one so far in this join order.


getTableDescriptor

TableDescriptor getTableDescriptor()
Get the table descriptor for this table (if any). Only base tables have table descriptors - for the rest of the optimizables, this method returns null.


getReferencedTableMap

JBitSet getReferencedTableMap()
Get the map of referenced tables for this Optimizable.

Returns:
JBitSet Referenced table map.

pushOptPredicate

boolean pushOptPredicate(OptimizablePredicate optimizablePredicate)
                         throws StandardException
Push an OptimizablePredicate down, if this node accepts it.

Parameters:
optimizablePredicate - OptimizablePredicate to push down.
Returns:
Whether or not the predicate was pushed down.
Throws:
StandardException - Thrown on error

pullOptPredicates

void pullOptPredicates(OptimizablePredicateList optimizablePredicates)
                       throws StandardException
Pull all the OptimizablePredicates from this Optimizable and put them in the given OptimizablePredicateList.

Parameters:
optimizablePredicates - The list to put the pulled predicates in.
Throws:
StandardException - Thrown on error

modifyAccessPath

Optimizable modifyAccessPath(JBitSet outerTables)
                             throws StandardException
Modify the access path for this Optimizable, as necessary. This includes things like adding a result set to translate from index rows to base rows

Parameters:
outerTables - Bit map of the tables that are outer to this one in the join order.
Returns:
The (potentially new) Optimizable at the top of the tree.
Throws:
StandardException - Thrown on error

isCoveringIndex

boolean isCoveringIndex(ConglomerateDescriptor cd)
                        throws StandardException
Return whether or not this is a covering index. We expect to call this during generation, after access path selection is complete.

Parameters:
cd - ConglomerateDesriptor for index to consider
Returns:
boolean Whether or not this is a covering index.
Throws:
StandardException - Thrown on error

getProperties

java.util.Properties getProperties()
Get the Properties list, if any, associated with this optimizable.

Returns:
The Properties list, if any, associated with this optimizable.

setProperties

void setProperties(java.util.Properties tableProperties)
Set the Properties list for this optimizalbe.

Parameters:
tableProperties - The Properties list for this optimizable.

verifyProperties

void verifyProperties(DataDictionary dDictionary)
                      throws StandardException
Verify that the Properties list with optimizer overrides, if specified, is valid

Parameters:
dDictionary - The DataDictionary to use.
Throws:
StandardException - Thrown on error

getName

java.lang.String getName()
                         throws StandardException
Get the (exposed) name of this Optimizable

Returns:
The name of this Optimizable.
Throws:
StandardException - Thrown on error

getBaseTableName

java.lang.String getBaseTableName()
Get the table name of this Optimizable. Only base tables have table names (by the time we use this method, all views will have been resolved).


convertAbsoluteToRelativeColumnPosition

int convertAbsoluteToRelativeColumnPosition(int absolutePosition)
Convert an absolute to a relative 0-based column position. This is useful when generating qualifiers for partial rows from the store.

Parameters:
absolutePosition - The absolute 0-based column position for the column.
Returns:
The relative 0-based column position for the column.

updateBestPlanMap

void updateBestPlanMap(short action,
                       java.lang.Object planKey)
                       throws StandardException
When remembering "truly the best" access path for an Optimizable, we have to keep track of which OptimizerImpl the "truly the best" access is for. In most queries there will only be one OptimizerImpl in question, but in cases where there are nested subqueries, there will be one OptimizerImpl for every level of nesting, and each OptimizerImpl might have its own idea of what this Optimizable's "truly the best path" access path really is. In addition, there could be Optimizables above this Optimizable that might need to override the best path chosen during optimization. So whenever we save a "truly the best" path, we take note of which Optimizer/Optimizable told us to do so. Then as each level of subquery finishes optimization, the corresponding OptimizerImpl/Optimizable can load its preferred access path into this Optimizable's trulyTheBestAccessPath field and pass it up the tree, until eventually the outer-most OptimizerImpl can choose to either use the best path that it received from below (by calling "rememberAsBest()") or else use the path that it found to be "best" for itself. This method is what allows us to keep track of which OptimizerImpl or Optimizable saved which "best plan", and allows us to load the appropriate plans after each round of optimization.

Parameters:
action - Indicates whether we're adding, loading, or removing a best plan for the OptimizerImpl/Optimizable.
planKey - Object to use as the map key when adding/looking up a plan. If it is an instance of OptimizerImpl then it corresponds to an outer query; otherwise it's some Optimizable above this Optimizable that could potentially reject plans chosen by the OptimizerImpl to which this Optimizable belongs.
Throws:
StandardException

rememberAsBest

void rememberAsBest(int planType,
                    Optimizer optimizer)
                    throws StandardException
Remember the current access path as the best one (so far).

Parameters:
planType - The type of plan (one of Optimizer.NORMAL_PLAN or Optimizer.SORT_AVOIDANCE_PLAN)
optimizer - The OptimizerImpl that is telling this Optimizable to remember its current path as "truly the best".
Throws:
StandardException - thrown on error.

startOptimizing

void startOptimizing(Optimizer optimizer,
                     RowOrdering rowOrdering)
Begin the optimization process for this Optimizable. This can be called many times for an Optimizable while optimizing a query - it will typically be called every time the Optimizable is placed in a potential join order.


estimateCost

CostEstimate estimateCost(OptimizablePredicateList predList,
                          ConglomerateDescriptor cd,
                          CostEstimate outerCost,
                          Optimizer optimizer,
                          RowOrdering rowOrdering)
                          throws StandardException
Estimate the cost of scanning this Optimizable using the given predicate list with the given conglomerate. It is assumed that the predicate list has already been classified. This cost estimate is just for one scan, not for the life of the query.

Parameters:
predList - The predicate list to optimize against
cd - The conglomerate descriptor to get the cost of
outerCost - The estimated cost of the part of the plan outer to this optimizable.
optimizer - The optimizer to use to help estimate the cost
rowOrdering - The row ordering for all the tables in the join order, including this one.
Returns:
The estimated cost of doing the scan
Throws:
StandardException - Thrown on error
See Also:
OptimizablePredicateList.classify(org.apache.derby.iapi.sql.compile.Optimizable, org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)

isBaseTable

boolean isBaseTable()
Tell whether this Optimizable represents a base table


isMaterializable

boolean isMaterializable()
                         throws StandardException
Tell whether this Optimizable is materializable

Throws:
StandardException - Thrown on error

supportsMultipleInstantiations

boolean supportsMultipleInstantiations()
Tell whether this Optimizable can be instantiated multiple times


getResultSetNumber

int getResultSetNumber()
Get this Optimizable's result set number


getTableNumber

int getTableNumber()
Get this Optimizable's table number


hasTableNumber

boolean hasTableNumber()
Return true if this Optimizable has a table number


forUpdate

boolean forUpdate()
Return true if this is the target table of an update


initialCapacity

int initialCapacity()
Return the initial capacity of the hash table, for hash join strategy


loadFactor

float loadFactor()
Return the load factor of the hash table, for hash join strategy


hashKeyColumns

int[] hashKeyColumns()
Return the hash key column numbers, for hash join strategy


setHashKeyColumns

void setHashKeyColumns(int[] columnNumbers)
Set the hash key column numbers, for hash join strategy


feasibleJoinStrategy

boolean feasibleJoinStrategy(OptimizablePredicateList predList,
                             Optimizer optimizer)
                             throws StandardException
Is the current proposed join strategy for this optimizable feasible given the predicate list?

Parameters:
predList - The predicate list that has been pushed down to this optimizable
optimizer - The optimizer to use.
Returns:
true means feasible
Throws:
StandardException - Thrown on error

memoryUsageOK

boolean memoryUsageOK(double rowCount,
                      int maxMemoryPerTable)
                      throws StandardException
Parameters:
rowCount -
maxMemoryPerTable -
Returns:
true if the memory usage of the proposed access path is OK, false if not.
Throws:
StandardException - standard error policy

maxCapacity

int maxCapacity(JoinStrategy joinStrategy,
                int maxMemoryPerTable)
                throws StandardException
Return the maximum capacity of the hash table, for hash join strategy

Parameters:
maxMemoryPerTable - The maximum number of bytes to be used. Ignored if the user has set a maximum number of rows for the Optimizable.
Throws:
StandardException - Standard error policy

legalJoinOrder

boolean legalJoinOrder(JBitSet assignedTableMap)
Can this Optimizable appear at the current location in the join order. In other words, have the Optimizable's dependencies been satisfied?

Parameters:
assignedTableMap - The tables that have been placed so far in the join order.
Returns:
Where or not this Optimizable can appear at the current location in the join order.

getDataDictionary

DataDictionary getDataDictionary()
                                 throws StandardException
Get the DataDictionary from this Optimizable. This is useful for code generation because we need to get the constraint name if scanning a back index so that RunTimeStatistics can display the correct info.

Returns:
The DataDictionary to use.
Throws:
StandardException - Thrown on error

isTargetTable

boolean isTargetTable()
Is the optimizable the target table of an update or delete?

Returns:
Whether or not the optimizable the target table of an update or delete.

getNumColumnsReturned

int getNumColumnsReturned()
Get the number of the number of columns returned by this Optimizable.

Returns:
The number of the number of columns returned by this Optimizable.

isOneRowScan

boolean isOneRowScan()
                     throws StandardException
Will the optimizable return at most 1 row per scan?

Returns:
Whether or not the optimizable will return at most 1 row per scan?
Throws:
StandardException - Thrown on error

initAccessPaths

void initAccessPaths(Optimizer optimizer)
Init the access paths for this optimizable.

Parameters:
optimizer - The optimizer being used.

uniqueJoin

double uniqueJoin(OptimizablePredicateList predList)
                  throws StandardException
Does this optimizable have a uniqueness condition on the given predicate list, and if so, how many unique keys will be returned per scan.

Parameters:
predList - The predicate list to check
Returns:
<= 0 means there is no uniqueness condition > 0 means there is a uniqueness condition, and the return value is the number of rows per scan.
Throws:
StandardException - Thrown on error

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.