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

public Interface OptimizablePredicateList

Known Direct Implementers
org.apache.derby.impl.sql.compile.PredicateList
Imports
org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor, org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.util.JBitSet

OptimizablePredicateList provides services for optimizing a table in a query. RESOLVE - the methods for this interface need to get defined.

Method Summary

Modifier and TypeMethod and Description
public void
addOptPredicate(OptimizablePredicate
The predicate to add
optPredicate
)

Add the given OptimizablePredicate to the end of this list.

public void
adjustForSortElimination(RequiredRowOrdering ordering)

Walk through the predicates in this list and make any adjustments that are required to allow for proper handling of an ORDER BY clause.

public void
classify(Optimizable
The Optimizable table for which to classify the predicates in this list.
optTable
,
ConglomerateDescriptor
The ConglomerateDescriptor for which to classify the predicates in this list.
cd
)

Classify the predicates in this list according to the given table and conglomerate.

public void
copyPredicatesToOtherList(OptimizablePredicateList
The predicateList to xfer to
otherList
)

Non-destructive copy of all of the predicates from this list to the other list.

public void
generateQualifiers(ExpressionClassBuilderInterface
The ExpressionClassBuilderInterface for the class we are building
acb
,
MethodBuilder
The method the generated code is going into
mb
,
Optimizable
The Optimizable table the Qualifiers are on
optTable
,
boolean
Generate absolute column positions if true, else relative column positions (within the underlying row)
absolute
)

Generate the qualifiers for a scan.

public void
generateStartKey(ExpressionClassBuilderInterface
The ExpressionClassBuilderInterface for the class we're building
acb
,
MethodBuilder
The method the generated code is to go into
mb
,
Optimizable
The Optimizable table the start key is for
optTable
)

Generate the start key for a heap or index scan.

public void
generateStopKey(ExpressionClassBuilderInterface
The ExpressionClassBuilderInterface for the class we're building
acb
,
MethodBuilder
the method the generated code is to go into
mb
,
Optimizable
The Optimizable table the stop key is for
optTable
)

Generate the stop key for a heap or index scan.

public OptimizablePredicate

Returns:

OptimizablePredicate The nth OptimizablePredicate in the list.
getOptPredicate
(int
"index" (0 based) into the list.
n
)

Return the nth OptimizablePredicate in the list.

public int

Returns:

the position of the predicate in the list which corresponds to the equijoin. If no quijoin predicate found, then the return value will be -1
hasEqualityPredicateOnOrderedColumn
(Optimizable optTable, int columnNumber, boolean isNullOkay)

Check into the predicate list if the passed column has an equijoin predicate on it.

public boolean

Returns:

Whether or not there is an optimizable equality predicate on the specified column.
hasOptimizableEqualityPredicate
(Optimizable
The optimizable the column comes from.
optTable
,
int
The column number within the base table.
columnNumber
,
boolean
boolean, whether or not the IS NULL operator satisfies the search
isNullOkay
)

Is there an optimizable equality predicate on the specified column?

public boolean

Returns:

Whether or not there is an optimizable equijoin on the specified column.
hasOptimizableEquijoin
(Optimizable
The optimizable the column comes from.
optTable
,
int
The column number within the base table.
columnNumber
)

Is there an optimizable equijoin on the specified column?

public boolean

Returns:

Whether or not the specified entry in the list is a redundant predicate.
isRedundantPredicate
(int
The entry in the list
predNum
)

Return whether or not the specified entry in the list is a redundant predicate.

public void
markAllPredicatesQualifiers()

Mark all of the predicates as Qualifiers and set the numberOfQualifiers to reflect this.

public void
pushUsefulPredicates(Optimizable
An Optimizable for the table in question
optTable
)

Determine which predicates in this list are useful for limiting the scan on the given table using its best conglomerate.

public void
putOptimizableEqualityPredicateFirst(Optimizable
The optimizable the column comes from.
optTable
,
int
The column number within the base table.
columnNumber
)

Find the optimizable equality predicate on the specified column and make it the first predicate in this list.

public void
removeOptPredicate(int
The index.
predCtr
)

Remove the OptimizablePredicate at the specified index (0-based) from the list.

public boolean

Returns:

Whether or not we can use the same key for both the start and stop key.
sameStartStopPosition
()

Can we use the same key for both the start and stop key.

public double
selectivity(Optimizable
the Optimizable that the predicate list restricts.
optTable
)

calculate the selectivity for a set of predicates.

public void
setPredicatesAndProperties(OptimizablePredicateList
The list to set the same as this one.
otherList
)

Sets the given list to have the same elements as this one, and the same properties as this one (number of qualifiers and start and stop predicates.

public int

Returns:

integer The number of OptimizablePredicates in the list.
size
()

Return the number of OptimizablePredicates in the list.

public int
startOperator(Optimizable optTable)

Get the start operator for the given Optimizable for a heap or index scan.

public int
stopOperator(Optimizable optTable)

Get the stop operator for the given Optimizable for a heap or index scan.

public void
transferAllPredicates(OptimizablePredicateList otherList)

Transfer all the predicates from this list to the given list.

public void
transferPredicates(OptimizablePredicateList
The predicateList to xfer to
otherList
,
JBitSet
The table map to check against
referencedTableMap
,
Optimizable
The table to order the new predicates against
table
)

Transfer the predicates whose referenced set is contained by the specified referencedTableMap from this list to the other list.

public boolean

Returns:

true if this predicate list can limit the scan
useful
(Optimizable
An Optimizable for the table in question
optTable
,
ConglomerateDescriptor
A ConglomerateDescriptor for the conglomerate in question
cd
)

Return true if this predicate list is useful for limiting the scan on the given table using the given conglomerate.

Method Detail

addOptPredicateback to summary
public void addOptPredicate(OptimizablePredicate optPredicate)

Add the given OptimizablePredicate to the end of this list.

Parameters
optPredicate:OptimizablePredicate

The predicate to add

adjustForSortEliminationback to summary
public void adjustForSortElimination(RequiredRowOrdering ordering) throws StandardException

Walk through the predicates in this list and make any adjustments that are required to allow for proper handling of an ORDER BY clause.

classifyback to summary
public void classify(Optimizable optTable, ConglomerateDescriptor cd) throws StandardException

Classify the predicates in this list according to the given table and conglomerate. Each predicate can be a start key, stop key, and/or qualifier, or it can be none of the above. This method also orders the predicates to match the order of the columns in a keyed conglomerate. No ordering is done for heaps.

Parameters
optTable:Optimizable

The Optimizable table for which to classify the predicates in this list.

cd:ConglomerateDescriptor

The ConglomerateDescriptor for which to classify the predicates in this list.

Exceptions
StandardException:
Thrown on error
copyPredicatesToOtherListback to summary
public void copyPredicatesToOtherList(OptimizablePredicateList otherList) throws StandardException

Non-destructive copy of all of the predicates from this list to the other list. This is useful when splitting out a set of predicates from a larger set, like when generating a HashScanResultSet.

Parameters
otherList:OptimizablePredicateList

The predicateList to xfer to

Exceptions
StandardException:
Thrown on error
generateQualifiersback to summary
public void generateQualifiers(ExpressionClassBuilderInterface acb, MethodBuilder mb, Optimizable optTable, boolean absolute) throws StandardException

Generate the qualifiers for a scan. This method generates an array of Qualifiers, and fills them in with calls to the factory method for generating Qualifiers in the constructor for the activation. It stores the array of Qualifiers in a field in the activation, and returns a reference to that field. If there are no qualifiers, it initializes the array of Qualifiers to null.

Parameters
acb:ExpressionClassBuilderInterface

The ExpressionClassBuilderInterface for the class we are building

mb:MethodBuilder

The method the generated code is going into

optTable:Optimizable

The Optimizable table the Qualifiers are on

absolute:boolean

Generate absolute column positions if true, else relative column positions (within the underlying row)

Exceptions
StandardException:
Thrown on error
generateStartKeyback to summary
public void generateStartKey(ExpressionClassBuilderInterface acb, MethodBuilder mb, Optimizable optTable) throws StandardException

Generate the start key for a heap or index scan.

Parameters
acb:ExpressionClassBuilderInterface

The ExpressionClassBuilderInterface for the class we're building

mb:MethodBuilder

The method the generated code is to go into

optTable:Optimizable

The Optimizable table the start key is for

Exceptions
StandardException:
Thrown on error
generateStopKeyback to summary
public void generateStopKey(ExpressionClassBuilderInterface acb, MethodBuilder mb, Optimizable optTable) throws StandardException

Generate the stop key for a heap or index scan.

Parameters
acb:ExpressionClassBuilderInterface

The ExpressionClassBuilderInterface for the class we're building

mb:MethodBuilder

the method the generated code is to go into

optTable:Optimizable

The Optimizable table the stop key is for

Exceptions
StandardException:
Thrown on error
getOptPredicateback to summary
public OptimizablePredicate getOptPredicate(int n)

Return the nth OptimizablePredicate in the list.

Parameters
n:int

"index" (0 based) into the list.

Returns:OptimizablePredicate

OptimizablePredicate The nth OptimizablePredicate in the list.

hasEqualityPredicateOnOrderedColumnback to summary
public int hasEqualityPredicateOnOrderedColumn(Optimizable optTable, int columnNumber, boolean isNullOkay) throws StandardException

Check into the predicate list if the passed column has an equijoin predicate on it.

Returns:int

the position of the predicate in the list which corresponds to the equijoin. If no quijoin predicate found, then the return value will be -1

hasOptimizableEqualityPredicateback to summary
public boolean hasOptimizableEqualityPredicate(Optimizable optTable, int columnNumber, boolean isNullOkay) throws StandardException

Is there an optimizable equality predicate on the specified column?

Parameters
optTable:Optimizable

The optimizable the column comes from.

columnNumber:int

The column number within the base table.

isNullOkay:boolean

boolean, whether or not the IS NULL operator satisfies the search

Returns:boolean

Whether or not there is an optimizable equality predicate on the specified column.

Exceptions
StandardException:
Thrown on error
hasOptimizableEquijoinback to summary
public boolean hasOptimizableEquijoin(Optimizable optTable, int columnNumber) throws StandardException

Is there an optimizable equijoin on the specified column?

Parameters
optTable:Optimizable

The optimizable the column comes from.

columnNumber:int

The column number within the base table.

Returns:boolean

Whether or not there is an optimizable equijoin on the specified column.

Exceptions
StandardException:
Thrown on error
isRedundantPredicateback to summary
public boolean isRedundantPredicate(int predNum)

Return whether or not the specified entry in the list is a redundant predicate. This is useful for selectivity calculations because we do not want redundant predicates included in the selectivity calculation.

Parameters
predNum:int

The entry in the list

Returns:boolean

Whether or not the specified entry in the list is a redundant predicate.

markAllPredicatesQualifiersback to summary
public void markAllPredicatesQualifiers()

Mark all of the predicates as Qualifiers and set the numberOfQualifiers to reflect this. This is useful for hash joins where all of the predicates in the list to be evaluated during the probe into the hash table on a next are qualifiers.

pushUsefulPredicatesback to summary
public void pushUsefulPredicates(Optimizable optTable) throws StandardException

Determine which predicates in this list are useful for limiting the scan on the given table using its best conglomerate. Remove those predicates from this list and push them down to the given Optimizable table. The predicates are pushed down in the order of the index columns that they qualify. Also, the predicates are "marked" as start predicates, stop predicates, or qualifier predicates. Finally, the start and stop operators are set in the given Optimizable.

Parameters
optTable:Optimizable

An Optimizable for the table in question

Exceptions
StandardException:
Thrown on error
putOptimizableEqualityPredicateFirstback to summary
public void putOptimizableEqualityPredicateFirst(Optimizable optTable, int columnNumber) throws StandardException

Find the optimizable equality predicate on the specified column and make it the first predicate in this list. This is useful for hash joins where Qualifier[0] is assumed to be on the hash key.

Parameters
optTable:Optimizable

The optimizable the column comes from.

columnNumber:int

The column number within the base table.

Exceptions
StandardException:
Thrown on error
removeOptPredicateback to summary
public void removeOptPredicate(int predCtr) throws StandardException

Remove the OptimizablePredicate at the specified index (0-based) from the list.

Parameters
predCtr:int

The index.

Exceptions
StandardException:
Thrown on error
sameStartStopPositionback to summary
public boolean sameStartStopPosition() throws StandardException

Can we use the same key for both the start and stop key. This is possible when doing an exact match on an index where there are no other sargable predicates.

Returns:boolean

Whether or not we can use the same key for both the start and stop key.

Exceptions
StandardException:
Thrown on error
selectivityback to summary
public double selectivity(Optimizable optTable) throws StandardException

calculate the selectivity for a set of predicates. If statistics exist for the predicates this method uses the statistics. If statistics do not exist, then simply call selectivity for each of the predicates and return the result.

Parameters
optTable:Optimizable

the Optimizable that the predicate list restricts.

setPredicatesAndPropertiesback to summary
public void setPredicatesAndProperties(OptimizablePredicateList otherList) throws StandardException

Sets the given list to have the same elements as this one, and the same properties as this one (number of qualifiers and start and stop predicates.

Parameters
otherList:OptimizablePredicateList

The list to set the same as this one.

Exceptions
StandardException:
Thrown on error
sizeback to summary
public int size()

Return the number of OptimizablePredicates in the list.

Returns:int

integer The number of OptimizablePredicates in the list.

startOperatorback to summary
public int startOperator(Optimizable optTable)

Get the start operator for the given Optimizable for a heap or index scan.

stopOperatorback to summary
public int stopOperator(Optimizable optTable)

Get the stop operator for the given Optimizable for a heap or index scan.

transferAllPredicatesback to summary
public void transferAllPredicates(OptimizablePredicateList otherList) throws StandardException

Transfer all the predicates from this list to the given list.

Exceptions
StandardException:
Thrown on error
transferPredicatesback to summary
public void transferPredicates(OptimizablePredicateList otherList, JBitSet referencedTableMap, Optimizable table) throws StandardException

Transfer the predicates whose referenced set is contained by the specified referencedTableMap from this list to the other list. This is useful when splitting out a set of predicates from a larger set, like when generating a HashScanResultSet.

Parameters
otherList:OptimizablePredicateList

The predicateList to xfer to

referencedTableMap:JBitSet

The table map to check against

table:Optimizable

The table to order the new predicates against

Exceptions
StandardException:
Thrown on error
usefulback to summary
public boolean useful(Optimizable optTable, ConglomerateDescriptor cd) throws StandardException

Return true if this predicate list is useful for limiting the scan on the given table using the given conglomerate.

Parameters
optTable:Optimizable

An Optimizable for the table in question

cd:ConglomerateDescriptor

A ConglomerateDescriptor for the conglomerate in question

Returns:boolean

true if this predicate list can limit the scan

Exceptions
StandardException:
Thrown on error