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

All Known Implementing Classes:
BaseJoinStrategy, HashJoinStrategy, NestedLoopJoinStrategy

public interface JoinStrategy

A JoinStrategy represents a strategy like nested loop, hash join, merge join, etc. It tells the optimizer whether the strategy is feasible in a given situation, how much the strategy costs, whether the strategy requires the data from the source result sets to be ordered, etc.


Method Summary
 boolean bulkFetchOK()
          Is it OK to use bulk fetch with this join strategy?
 void divideUpPredicateLists(Optimizable innerTable, OptimizablePredicateList originalRestrictionList, OptimizablePredicateList storeRestrictionList, OptimizablePredicateList nonStoreRestrictionList, OptimizablePredicateList requalificationRestrictionList, DataDictionary dd)
          Divide up the predicates into different lists for different phases of the operation.
 boolean doesMaterialization()
          Is materialization built in to the join strategy?
 void estimateCost(Optimizable innerTable, OptimizablePredicateList predList, ConglomerateDescriptor cd, CostEstimate outerCost, Optimizer optimizer, CostEstimate costEstimate)
          Get the estimated cost for the join.
 boolean feasible(Optimizable innerTable, OptimizablePredicateList predList, Optimizer optimizer)
          Is this join strategy feasible under the circumstances?
 OptimizablePredicateList getBasePredicates(OptimizablePredicateList predList, OptimizablePredicateList basePredicates, Optimizable innerTable)
          Get the base predicates for this join strategy.
 java.lang.String getName()
          Get the name of this join strategy
 int getScanArgs(TransactionController tc, MethodBuilder mb, Optimizable innerTable, OptimizablePredicateList storeRestrictionList, OptimizablePredicateList nonStoreRestrictionList, ExpressionClassBuilderInterface acb, int bulkFetch, MethodBuilder resultRowAllocator, int colRefItem, int indexColItem, int lockMode, boolean tableLocked, int isolationLevel, int maxMemoryPerTable, boolean genInListVals)
          Get the appropriate arguments to the scan for this type of join.
 java.lang.String halfOuterJoinResultSetMethodName()
          Get the name of the join result set method for the half outerjoin
 boolean ignoreBulkFetch()
          Should we just ignore bulk fetch with this join strategy?
 boolean isHashJoin()
          Is this a form of hash join?
 java.lang.String joinResultSetMethodName()
          Get the name of the join result set method for the join
 int maxCapacity(int userSpecifiedCapacity, int maxMemoryPerTable, double perRowUsage)
           
 boolean multiplyBaseCostByOuterRows()
          Returns true if the base cost of scanning the conglomerate should be multiplied by the number of outer rows.
 double nonBasePredicateSelectivity(Optimizable innerTable, OptimizablePredicateList predList)
          Get the extra selectivity of the non-base predicates (those that were left in the predicate list by getBasePredicates() that are not applied to the scan of the base conglomerate.
 void putBasePredicates(OptimizablePredicateList predList, OptimizablePredicateList basePredicates)
          Put back and base predicates that were removed from the list by getBasePredicates (see above).
 java.lang.String resultSetMethodName(boolean bulkFetch, boolean multiprobe)
          Get the name of the result set method for base table scans
 int scanCostType()
          Get the costing type, for use with StoreCostController.getScanCost
 

Method Detail

feasible

boolean feasible(Optimizable innerTable,
                 OptimizablePredicateList predList,
                 Optimizer optimizer)
                 throws StandardException
Is this join strategy feasible under the circumstances?

Parameters:
innerTable - The inner table of the join
predList - The predicateList for the join
optimizer - The optimizer to use
Returns:
true means the strategy is feasible, false means it isn't
Throws:
StandardException - Thrown on error

bulkFetchOK

boolean bulkFetchOK()
Is it OK to use bulk fetch with this join strategy?


ignoreBulkFetch

boolean ignoreBulkFetch()
Should we just ignore bulk fetch with this join strategy?


multiplyBaseCostByOuterRows

boolean multiplyBaseCostByOuterRows()
Returns true if the base cost of scanning the conglomerate should be multiplied by the number of outer rows.


getBasePredicates

OptimizablePredicateList getBasePredicates(OptimizablePredicateList predList,
                                           OptimizablePredicateList basePredicates,
                                           Optimizable innerTable)
                                           throws StandardException
Get the base predicates for this join strategy. The base predicates are the ones that can be used while scanning the table. For some join strategies (for example, nested loop), all predicates are base predicates. For other join strategies (for example, hash join), the base predicates are those that involve comparisons with constant expressions. Also, order the base predicates according to the order in the proposed conglomerate descriptor for the inner table.

Parameters:
predList - The predicate list to pull from.
basePredicates - The list to put the base predicates in.
innerTable - The inner table of the join
Returns:
The base predicate list. If no predicates are pulled, it may return the source predList without doing anything.
Throws:
StandardException - Thrown on error

nonBasePredicateSelectivity

double nonBasePredicateSelectivity(Optimizable innerTable,
                                   OptimizablePredicateList predList)
                                   throws StandardException
Get the extra selectivity of the non-base predicates (those that were left in the predicate list by getBasePredicates() that are not applied to the scan of the base conglomerate. NOTE: For some types of join strategy, it may not remove any predicates from the original predicate list. The join strategy is expected to know when it does this, and to return 1.0 as the extra selectivity in these cases.

Parameters:
innerTable - The inner table of the join.
predList - The original predicate list that was passed to getBasePredicates(), from which some base predicates may have been pulled.
Returns:
The extra selectivity due to non-base predicates
Throws:
StandardException

putBasePredicates

void putBasePredicates(OptimizablePredicateList predList,
                       OptimizablePredicateList basePredicates)
                       throws StandardException
Put back and base predicates that were removed from the list by getBasePredicates (see above). NOTE: Those join strategies that treat all predicates as base predicates may treat the get and put methods as no-ops.

Parameters:
predList - The list of predicates to put the base predicates back in.
basePredicates - The base predicates to put back in the list.
Throws:
StandardException - Thrown on error

estimateCost

void estimateCost(Optimizable innerTable,
                  OptimizablePredicateList predList,
                  ConglomerateDescriptor cd,
                  CostEstimate outerCost,
                  Optimizer optimizer,
                  CostEstimate costEstimate)
                  throws StandardException
Get the estimated cost for the join.

Parameters:
predList - The predicate list for the join
innerTable - The inner table to join with
cd - The conglomerate descriptor (if appropriate) to get the cost of
outerCost - The estimated cost of the part of the plan outer to the inner table
optimizer - The optimizer to use to help estimate the cost
costEstimate - The estimated cost of doing a single scan of the inner table, to be filled in with the cost of doing the join.
Throws:
StandardException - Thrown on error

maxCapacity

int maxCapacity(int userSpecifiedCapacity,
                int maxMemoryPerTable,
                double perRowUsage)
Parameters:
userSpecifiedCapacity -
maxMemoryPerTable - maximum number of bytes per table
perRowUsage - number of bytes per row
Returns:
The maximum number of rows that can be handled by this join strategy

getName

java.lang.String getName()
Get the name of this join strategy


scanCostType

int scanCostType()
Get the costing type, for use with StoreCostController.getScanCost


resultSetMethodName

java.lang.String resultSetMethodName(boolean bulkFetch,
                                     boolean multiprobe)
Get the name of the result set method for base table scans

Parameters:
bulkFetch - True means bulk fetch is being done on the inner table
multiprobe - True means we are probing the inner table for rows matching a specified list of values.

joinResultSetMethodName

java.lang.String joinResultSetMethodName()
Get the name of the join result set method for the join


halfOuterJoinResultSetMethodName

java.lang.String halfOuterJoinResultSetMethodName()
Get the name of the join result set method for the half outerjoin


getScanArgs

int getScanArgs(TransactionController tc,
                MethodBuilder mb,
                Optimizable innerTable,
                OptimizablePredicateList storeRestrictionList,
                OptimizablePredicateList nonStoreRestrictionList,
                ExpressionClassBuilderInterface acb,
                int bulkFetch,
                MethodBuilder resultRowAllocator,
                int colRefItem,
                int indexColItem,
                int lockMode,
                boolean tableLocked,
                int isolationLevel,
                int maxMemoryPerTable,
                boolean genInListVals)
                throws StandardException
Get the appropriate arguments to the scan for this type of join.

Parameters:
tc - The TransactionController
mb - The method to generate the arguments in
innerTable - The inner table of the join
storeRestrictionList - The predicate list to be evaluated in the store
nonStoreRestrictionList - The predicate list to be evaluated outside of the store
acb - The expression class builder for the activation class we're building
bulkFetch - The amount of bulk fetch to do
resultRowAllocator - A completed method to allocate the result row
colRefItem - The item number of the column reference bit map
lockMode - The lock mode to use when scanning the table (see TransactionController).
tableLocked - Whether or not the table is marked (in sys.systables) as always using table locking
isolationLevel - Isolation level specified (or not) for scans
maxMemoryPerTable - Max memory per table
genInListVals - Whether or not we are going to generate IN-list values with which to probe the inner table.
Returns:
Count of the expressions pushed to use as the parameters to the result set for the inner table
Throws:
StandardException - Thrown on error

divideUpPredicateLists

void divideUpPredicateLists(Optimizable innerTable,
                            OptimizablePredicateList originalRestrictionList,
                            OptimizablePredicateList storeRestrictionList,
                            OptimizablePredicateList nonStoreRestrictionList,
                            OptimizablePredicateList requalificationRestrictionList,
                            DataDictionary dd)
                            throws StandardException
Divide up the predicates into different lists for different phases of the operation. When this method is called, all of the predicates will be in restrictionList. The effect of this method is to remove all of the predicates from restrictionList except those that will be pushed down to the store as start/stop predicates or Qualifiers. The remaining predicates will be put into nonBaseTableRestrictionList. All predicate lists will be ordered as necessary for use with the conglomerate. Some operations (like hash join) materialize results, and so require requalification of rows when doing a non-covering index scan. The predicates to use for requalification are copied into baseTableRestrictionList.

Parameters:
innerTable - The inner table of the join
originalRestrictionList - Initially contains all predicates. This method removes predicates from this list and moves them to other lists, as appropriate.
storeRestrictionList - To be filled in with predicates to be pushed down to store.
nonStoreRestrictionList - To be filled in with predicates that are not pushed down to the store.
requalificationRestrictionList - Copy of predicates used to re-qualify rows, if necessary.
dd - The DataDictionary
Throws:
StandardException - Thrown on error

isHashJoin

boolean isHashJoin()
Is this a form of hash join?

Returns:
Whether or not this strategy is a form of hash join.

doesMaterialization

boolean doesMaterialization()
Is materialization built in to the join strategy?

Returns:
Whether or not materialization is built in to the join strategy

Built on Thu 2010-12-23 20:49:13+0000, from revision ???

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