Top Description Methods
org.apache.derby.iapi.sql.compile

public Interface JoinStrategy

Known Direct Implementers
org.apache.derby.impl.sql.compile.BaseJoinStrategy
Imports
org.apache.derby.iapi.sql.dictionary.DataDictionary, .ConglomerateDescriptor, org.apache.derby.iapi.store.access.TransactionController, org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.shared.common.error.StandardException

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

Modifier and TypeMethod and Description
public boolean
bulkFetchOK()

Is it OK to use bulk fetch with this join strategy?

public void
divideUpPredicateLists(Optimizable
The inner table of the join
innerTable
,
OptimizablePredicateList
Initially contains all predicates. This method removes predicates from this list and moves them to other lists, as appropriate.
originalRestrictionList
,
OptimizablePredicateList
To be filled in with predicates to be pushed down to store.
storeRestrictionList
,
OptimizablePredicateList
To be filled in with predicates that are not pushed down to the store.
nonStoreRestrictionList
,
OptimizablePredicateList
Copy of predicates used to re-qualify rows, if necessary.
requalificationRestrictionList
,
DataDictionary
The DataDictionary
dd
)

Divide up the predicates into different lists for different phases of the operation.

public boolean

Returns:

Whether or not materialization is built in to the join strategy
doesMaterialization
()

Is materialization built in to the join strategy?

public void
estimateCost(Optimizable
The inner table to join with
innerTable
,
OptimizablePredicateList
The predicate list for the join
predList
,
ConglomerateDescriptor
The conglomerate descriptor (if appropriate) to get the cost of
cd
,
CostEstimate
The estimated cost of the part of the plan outer to the inner table
outerCost
,
Optimizer
The optimizer to use to help estimate the cost
optimizer
,
CostEstimate
The estimated cost of doing a single scan of the inner table, to be filled in with the cost of doing the join.
costEstimate
)

Get the estimated cost for the join.

public boolean

Returns:

true means the strategy is feasible, false means it isn't
feasible
(Optimizable
The inner table of the join
innerTable
,
OptimizablePredicateList
The predicateList for the join
predList
,
Optimizer
The optimizer to use
optimizer
)

Is this join strategy feasible under the circumstances?

public OptimizablePredicateList

Returns:

The base predicate list. If no predicates are pulled, it may return the source predList without doing anything.
getBasePredicates
(OptimizablePredicateList
The predicate list to pull from.
predList
,
OptimizablePredicateList
The list to put the base predicates in.
basePredicates
,
Optimizable
The inner table of the join
innerTable
)

Get the base predicates for this join strategy.

public String
getName()

Get the name of this join strategy

public String
getOperatorSymbol()

Get the operator symbol used to represent this join strategy in optimizer traces

public int

Returns:

Count of the expressions pushed to use as the parameters to the result set for the inner table
getScanArgs
(TransactionController
The TransactionController
tc
,
MethodBuilder
The method to generate the arguments in
mb
,
Optimizable
The inner table of the join
innerTable
,
OptimizablePredicateList
The predicate list to be evaluated in the store
storeRestrictionList
,
OptimizablePredicateList
The predicate list to be evaluated outside of the store
nonStoreRestrictionList
,
ExpressionClassBuilderInterface
The expression class builder for the activation class we're building
acb
,
int
The amount of bulk fetch to do
bulkFetch
,
int
The saved object index of a result row template
resultRowTemplate
,
int
The item number of the column reference bit map
colRefItem
,
int indexColItem, int
The lock mode to use when scanning the table (see TransactionController).
lockMode
,
boolean
Whether or not the table is marked (in sys.systables) as always using table locking
tableLocked
,
int
Isolation level specified (or not) for scans
isolationLevel
,
int
Max memory per table
maxMemoryPerTable
,
boolean
Whether or not we are going to generate IN-list values with which to probe the inner table.
genInListVals
)

Get the appropriate arguments to the scan for this type of join.

public String
halfOuterJoinResultSetMethodName()

Get the name of the join result set method for the half outerjoin

public boolean
ignoreBulkFetch()

Should we just ignore bulk fetch with this join strategy?

public boolean

Returns:

Whether or not this strategy is a form of hash join.
isHashJoin
()

Is this a form of hash join?

public String
joinResultSetMethodName()

Get the name of the join result set method for the join

public int

Returns:

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

public boolean
multiplyBaseCostByOuterRows()

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

public double

Returns:

The extra selectivity due to non-base predicates
nonBasePredicateSelectivity
(Optimizable
The inner table of the join.
innerTable
,
OptimizablePredicateList
The original predicate list that was passed to getBasePredicates(), from which some base predicates may have been pulled.
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.

public void
putBasePredicates(OptimizablePredicateList
The list of predicates to put the base predicates back in.
predList
,
OptimizablePredicateList
The base predicates to put back in the list.
basePredicates
)

Put back and base predicates that were removed from the list by getBasePredicates (see above).

public String
resultSetMethodName(boolean
True means bulk fetch is being done on the inner table
bulkFetch
,
boolean
True means we are probing the inner table for rows matching a specified list of values.
multiprobe
,
boolean
True of this is a special scan to validate a check constraint.
validatingCheckConstraint
)

Get the name of the result set method for base table scans

public int
scanCostType()

Get the costing type, for use with StoreCostController.getScanCost

Method Detail

bulkFetchOKback to summary
public boolean bulkFetchOK()

Is it OK to use bulk fetch with this join strategy?

divideUpPredicateListsback to summary
public 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:Optimizable

The inner table of the join

originalRestrictionList:OptimizablePredicateList

Initially contains all predicates. This method removes predicates from this list and moves them to other lists, as appropriate.

storeRestrictionList:OptimizablePredicateList

To be filled in with predicates to be pushed down to store.

nonStoreRestrictionList:OptimizablePredicateList

To be filled in with predicates that are not pushed down to the store.

requalificationRestrictionList:OptimizablePredicateList

Copy of predicates used to re-qualify rows, if necessary.

dd:DataDictionary

The DataDictionary

Exceptions
StandardException:
Thrown on error
doesMaterializationback to summary
public boolean doesMaterialization()

Is materialization built in to the join strategy?

Returns:boolean

Whether or not materialization is built in to the join strategy

estimateCostback to summary
public void estimateCost(Optimizable innerTable, OptimizablePredicateList predList, ConglomerateDescriptor cd, CostEstimate outerCost, Optimizer optimizer, CostEstimate costEstimate) throws StandardException

Get the estimated cost for the join.

Parameters
innerTable:Optimizable

The inner table to join with

predList:OptimizablePredicateList

The predicate list for the join

cd:ConglomerateDescriptor

The conglomerate descriptor (if appropriate) to get the cost of

outerCost:CostEstimate

The estimated cost of the part of the plan outer to the inner table

optimizer:Optimizer

The optimizer to use to help estimate the cost

costEstimate:CostEstimate

The estimated cost of doing a single scan of the inner table, to be filled in with the cost of doing the join.

Exceptions
StandardException:
Thrown on error
feasibleback to summary
public boolean feasible(Optimizable innerTable, OptimizablePredicateList predList, Optimizer optimizer) throws StandardException

Is this join strategy feasible under the circumstances?

Parameters
innerTable:Optimizable

The inner table of the join

predList:OptimizablePredicateList

The predicateList for the join

optimizer:Optimizer

The optimizer to use

Returns:boolean

true means the strategy is feasible, false means it isn't

Exceptions
StandardException:
Thrown on error
getBasePredicatesback to summary
public 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:OptimizablePredicateList

The predicate list to pull from.

basePredicates:OptimizablePredicateList

The list to put the base predicates in.

innerTable:Optimizable

The inner table of the join

Returns:OptimizablePredicateList

The base predicate list. If no predicates are pulled, it may return the source predList without doing anything.

Exceptions
StandardException:
Thrown on error
getNameback to summary
public String getName()

Get the name of this join strategy

getOperatorSymbolback to summary
public String getOperatorSymbol()

Get the operator symbol used to represent this join strategy in optimizer traces

getScanArgsback to summary
public int getScanArgs(TransactionController tc, MethodBuilder mb, Optimizable innerTable, OptimizablePredicateList storeRestrictionList, OptimizablePredicateList nonStoreRestrictionList, ExpressionClassBuilderInterface acb, int bulkFetch, int resultRowTemplate, 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:TransactionController

The TransactionController

mb:MethodBuilder

The method to generate the arguments in

innerTable:Optimizable

The inner table of the join

storeRestrictionList:OptimizablePredicateList

The predicate list to be evaluated in the store

nonStoreRestrictionList:OptimizablePredicateList

The predicate list to be evaluated outside of the store

acb:ExpressionClassBuilderInterface

The expression class builder for the activation class we're building

bulkFetch:int

The amount of bulk fetch to do

resultRowTemplate:int

The saved object index of a result row template

colRefItem:int

The item number of the column reference bit map

lockMode:int

The lock mode to use when scanning the table (see TransactionController).

tableLocked:boolean

Whether or not the table is marked (in sys.systables) as always using table locking

isolationLevel:int

Isolation level specified (or not) for scans

maxMemoryPerTable:int

Max memory per table

genInListVals:boolean

Whether or not we are going to generate IN-list values with which to probe the inner table.

Returns:int

Count of the expressions pushed to use as the parameters to the result set for the inner table

Exceptions
StandardException:
Thrown on error
halfOuterJoinResultSetMethodNameback to summary
public String halfOuterJoinResultSetMethodName()

Get the name of the join result set method for the half outerjoin

ignoreBulkFetchback to summary
public boolean ignoreBulkFetch()

Should we just ignore bulk fetch with this join strategy?

isHashJoinback to summary
public boolean isHashJoin()

Is this a form of hash join?

Returns:boolean

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

joinResultSetMethodNameback to summary
public String joinResultSetMethodName()

Get the name of the join result set method for the join

maxCapacityback to summary
public int maxCapacity(int userSpecifiedCapacity, int maxMemoryPerTable, double perRowUsage)
Parameters
maxMemoryPerTable:int

maximum number of bytes per table

perRowUsage:double

number of bytes per row

Returns:int

The maximum number of rows that can be handled by this join strategy

multiplyBaseCostByOuterRowsback to summary
public boolean multiplyBaseCostByOuterRows()

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

nonBasePredicateSelectivityback to summary
public 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:Optimizable

The inner table of the join.

predList:OptimizablePredicateList

The original predicate list that was passed to getBasePredicates(), from which some base predicates may have been pulled.

Returns:double

The extra selectivity due to non-base predicates

putBasePredicatesback to summary
public 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:OptimizablePredicateList

The list of predicates to put the base predicates back in.

basePredicates:OptimizablePredicateList

The base predicates to put back in the list.

Exceptions
StandardException:
Thrown on error
resultSetMethodNameback to summary
public String resultSetMethodName(boolean bulkFetch, boolean multiprobe, boolean validatingCheckConstraint)

Get the name of the result set method for base table scans

Parameters
bulkFetch:boolean

True means bulk fetch is being done on the inner table

multiprobe:boolean

True means we are probing the inner table for rows matching a specified list of values.

validatingCheckConstraint:boolean

True of this is a special scan to validate a check constraint.

scanCostTypeback to summary
public int scanCostType()

Get the costing type, for use with StoreCostController.getScanCost