org.apache.derby.impl.sql.compile
Class NestedLoopJoinStrategy

java.lang.Object
  extended byorg.apache.derby.impl.sql.compile.BaseJoinStrategy
      extended byorg.apache.derby.impl.sql.compile.NestedLoopJoinStrategy
All Implemented Interfaces:
JoinStrategy

public class NestedLoopJoinStrategy
extends BaseJoinStrategy


Constructor Summary
NestedLoopJoinStrategy()
           
 
Method Summary
 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 acbi, int bulkFetch, MethodBuilder resultRowAllocator, int colRefItem, int indexColItem, int lockMode, boolean tableLocked, int isolationLevel, int maxMemoryPerTable)
          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
 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)
          Get the name of the result set method for base table scans
 int scanCostType()
          Get the costing type, for use with StoreCostController.getScanCost
 java.lang.String toString()
           
protected  boolean validForOutermostTable()
          Can this join strategy be used on the outermost table of a join.
 
Methods inherited from class org.apache.derby.impl.sql.compile.BaseJoinStrategy
bulkFetchOK, fillInScanArgs1, fillInScanArgs2, ignoreBulkFetch, isHashJoin
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NestedLoopJoinStrategy

public NestedLoopJoinStrategy()
Method Detail

feasible

public boolean feasible(Optimizable innerTable,
                        OptimizablePredicateList predList,
                        Optimizer optimizer)
                 throws StandardException
Description copied from interface: JoinStrategy
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
See Also:
JoinStrategy.feasible(org.apache.derby.iapi.sql.compile.Optimizable, org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.compile.Optimizer)

multiplyBaseCostByOuterRows

public boolean multiplyBaseCostByOuterRows()
Description copied from interface: JoinStrategy
Returns true if the base cost of scanning the conglomerate should be multiplied by the number of outer rows.

See Also:
JoinStrategy.multiplyBaseCostByOuterRows()

getBasePredicates

public OptimizablePredicateList getBasePredicates(OptimizablePredicateList predList,
                                                  OptimizablePredicateList basePredicates,
                                                  Optimizable innerTable)
                                           throws StandardException
Description copied from interface: JoinStrategy
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
See Also:
JoinStrategy.getBasePredicates(org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.compile.Optimizable)

nonBasePredicateSelectivity

public double nonBasePredicateSelectivity(Optimizable innerTable,
                                          OptimizablePredicateList predList)
Description copied from interface: JoinStrategy
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
See Also:
JoinStrategy.nonBasePredicateSelectivity(org.apache.derby.iapi.sql.compile.Optimizable, org.apache.derby.iapi.sql.compile.OptimizablePredicateList)

putBasePredicates

public void putBasePredicates(OptimizablePredicateList predList,
                              OptimizablePredicateList basePredicates)
                       throws StandardException
Description copied from interface: JoinStrategy
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
See Also:
JoinStrategy.putBasePredicates(org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.compile.OptimizablePredicateList)

estimateCost

public void estimateCost(Optimizable innerTable,
                         OptimizablePredicateList predList,
                         ConglomerateDescriptor cd,
                         CostEstimate outerCost,
                         Optimizer optimizer,
                         CostEstimate costEstimate)
Description copied from interface: JoinStrategy
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.

maxCapacity

public 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
See Also:
JoinStrategy.maxCapacity(int, int, double)

getName

public java.lang.String getName()
Description copied from interface: JoinStrategy
Get the name of this join strategy

See Also:
JoinStrategy.getName()

scanCostType

public int scanCostType()
Description copied from interface: JoinStrategy
Get the costing type, for use with StoreCostController.getScanCost

See Also:
JoinStrategy.scanCostType()

resultSetMethodName

public java.lang.String resultSetMethodName(boolean bulkFetch)
Description copied from interface: JoinStrategy
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
See Also:
JoinStrategy.resultSetMethodName(boolean)

joinResultSetMethodName

public java.lang.String joinResultSetMethodName()
Description copied from interface: JoinStrategy
Get the name of the join result set method for the join

See Also:
JoinStrategy.joinResultSetMethodName()

halfOuterJoinResultSetMethodName

public java.lang.String halfOuterJoinResultSetMethodName()
Description copied from interface: JoinStrategy
Get the name of the join result set method for the half outerjoin

See Also:
JoinStrategy.halfOuterJoinResultSetMethodName()

getScanArgs

public int getScanArgs(TransactionController tc,
                       MethodBuilder mb,
                       Optimizable innerTable,
                       OptimizablePredicateList storeRestrictionList,
                       OptimizablePredicateList nonStoreRestrictionList,
                       ExpressionClassBuilderInterface acbi,
                       int bulkFetch,
                       MethodBuilder resultRowAllocator,
                       int colRefItem,
                       int indexColItem,
                       int lockMode,
                       boolean tableLocked,
                       int isolationLevel,
                       int maxMemoryPerTable)
                throws StandardException
Description copied from interface: JoinStrategy
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
acbi - 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
Returns:
Count of the expressions pushed to use as the parameters to the result set for the inner table
Throws:
StandardException - Thrown on error
See Also:
JoinStrategy.getScanArgs(org.apache.derby.iapi.store.access.TransactionController, org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.sql.compile.Optimizable, org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.compile.ExpressionClassBuilderInterface, int, org.apache.derby.iapi.services.compiler.MethodBuilder, int, int, int, boolean, int, int)

divideUpPredicateLists

public void divideUpPredicateLists(Optimizable innerTable,
                                   OptimizablePredicateList originalRestrictionList,
                                   OptimizablePredicateList storeRestrictionList,
                                   OptimizablePredicateList nonStoreRestrictionList,
                                   OptimizablePredicateList requalificationRestrictionList,
                                   DataDictionary dd)
                            throws StandardException
Description copied from interface: JoinStrategy
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
See Also:
JoinStrategy.divideUpPredicateLists(org.apache.derby.iapi.sql.compile.Optimizable, org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.dictionary.DataDictionary)

doesMaterialization

public boolean doesMaterialization()
Description copied from interface: JoinStrategy
Is materialization built in to the join strategy?

Returns:
Whether or not materialization is built in to the join strategy
See Also:
JoinStrategy.doesMaterialization()

toString

public java.lang.String toString()

validForOutermostTable

protected boolean validForOutermostTable()
Can this join strategy be used on the outermost table of a join.

Overrides:
validForOutermostTable in class BaseJoinStrategy
Returns:
Whether or not this join strategy can be used on the outermose table of a join.

Built on Tue 2006-10-10 19:23:47+0200, from revision exported

Apache Derby V10.1 Engine Documentation - Copyright © 1997,2005 The Apache Software Foundation or its licensors, as applicable.