Top Description Inners Fields Constructors Methods
org.apache.derby.impl.sql.compile

pack-priv Class PredicateList

extends QueryTreeNodeVector<Predicate>
implements OptimizablePredicateList
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.sql.compile.OptimizablePredicateList
Imports
java.lang.reflect.Modifier, java.util.ArrayList, .List, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.ClassName, org.apache.derby.iapi.services.classfile.VMOpcode, org.apache.derby.iapi.services.compiler.LocalField, .MethodBuilder, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.compile.AccessPath, .CompilerContext, .ExpressionClassBuilderInterface, .Optimizable, .OptimizablePredicate, .OptimizablePredicateList, .RequiredRowOrdering, .RowOrdering, org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor, .TableDescriptor, org.apache.derby.iapi.sql.execute.ExecutionFactory, org.apache.derby.iapi.store.access.ScanController, org.apache.derby.iapi.types.DataValueDescriptor, org.apache.derby.iapi.util.JBitSet

A PredicateList represents the list of top level predicates. Each top level predicate consists of an AndNode whose leftOperand is the top level predicate and whose rightOperand is true. It extends QueryTreeNodeVector.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
PredicateList.PredicateWrapper

Inner class which helps statistics routines do their work.

private static class
PredicateList.PredicateWrapperList

Another inner class which is basically a List of Predicate Wrappers.

Field Summary

Modifier and TypeField and Description
private int
private int
private int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
Inherited from org.apache.derby.impl.sql.compile.QueryTreeNodeVector:
eltClass

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

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

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.addOptPredicate.

Add the given OptimizablePredicate to the end of this list.

public void
addOptPredicate(OptimizablePredicate optPredicate, int position)

Another flavor of addOptPredicate that inserts the given predicate at a given position.

pack-priv void
addPredicate(Predicate
A Predicate to add to the list
predicate
)

Add a Predicate to the list.

public void
adjustForSortElimination(RequiredRowOrdering ordering)

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.adjustForSortElimination.

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

pack-priv boolean

Returns:

Whether or not all of the predicates in the list are pushable.
allPushable
()

Check if all of the predicates in the list are pushable.

pack-priv boolean

Returns:

true if the table is referenced by all predicates, false otherwise
allReference
(FromBaseTable
the FromBaseTable to check for
fbt
)

Check if all the predicates reference a given FromBaseTable.

private void
calculateWeight(PredicateList.PredicateWrapperList[] pwList, int numUsefulPredicates)

pack-priv void
categorize()

Categorize the predicates in the list.

pack-priv void
checkTopPredicatesForEqualsConditions(int
The tableNumber of the table from which the columns of interest come from.
tableNumber
,
boolean[]
Array of booleans for noting which columns are in = predicates with constants or correlation columns.
eqOuterCols
,
int[]
Array of table numbers in this query block.
tableNumbers
,
JBitSet[] tableColMap, boolean
tableNumber is the table the result columns are coming from
resultColTable
)

Update the array of columns in = conditions with constants or correlation or join columns.

private int
chooseLongestMatch(PredicateList.PredicateWrapperList[] predArray, List<Predicate> ret, int numWorkingPredicates)

choose the statistic which has the maximum match with the predicates.

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
)

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.classify.

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

pack-priv boolean
public void
copyPredicatesToOtherList(OptimizablePredicateList
The predicateList to xfer to
otherList
)

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.copyPredicatesToOtherList.

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

private void
pack-priv void
decrementLevel(FromList
The subquery's FROM list.
fromList
,
int
Decrement size.
decrement
)

Decrement the level of any CRs from the subquery's FROM list that are interesting to transitive closure.

pack-priv void
eliminateBooleanTrueAndBooleanTrue()

Eliminate predicates of the form: AndNode / \ true BooleanConstantNode true BooleanConstantNode This is useful when checking for a NOP PRN as the Like transformation on c1 like 'ASDF%' can leave one of these predicates in the list.

private void
finishKey(ExpressionClassBuilder
The ActivationClassBuilder for the class we're building
acb
,
MethodBuilder mb, MethodBuilder
The MethodBuilder for the method we're building
exprFun
,
LocalField
The name of the field that holds the indexable row
rowField
)

Finish generating a start or stop key

private LocalField

Returns:

The field that holds the indexable row
generateIndexableRow
(ExpressionClassBuilder
The ActivationClassBuilder for the class we're building
acb
,
int
The number of columns in the key
numberOfColumns
)

Generate the indexable row for a start key or stop key.

pack-priv void
generateInListValues(ExpressionClassBuilder
The ActivationClassBuilder for the class we're building
acb
,
MethodBuilder
The MethodBuilder for the method we're building
mb
)

If there is an IN-list probe predicate in this list then generate the corresponding IN-list values as a DataValueDescriptor array, to be used for probing at execution time.

public void
generateQualifiers(ExpressionClassBuilderInterface
The ExpressionClassBuilderInterface for the class we are building
acbi
,
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
)

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.generateQualifiers.

Generate the qualifiers for a scan.

private void
generateSetColumn(ExpressionClassBuilder
The ActivationClassBuilder for the class we're building
acb
,
MethodBuilder
The MethodBuilder for the method we're building
exprFun
,
int
The position number of the column we're setting the value in (zero-based)
columnNumber
,
Predicate
The Predicate with the value to put in the index column
pred
,
Optimizable
The Optimizable table the column is in
optTable
,
LocalField
The field that holds the indexable row
rowField
,
boolean
Are we generating start or stop key? This information is useful for "in"'s dynamic start/stop key, bug 3858
isStartKey
)

Generate the code to set the value from a predicate in an index column.

private void
generateSingleQualifierCode(MethodBuilder consMB, Optimizable optTable, boolean absolute, ExpressionClassBuilder acb, RelationalOperator or_node, LocalField qualField, int array_idx_1, int array_idx_2)

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

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.generateStartKey.

Generate the start key for a heap or index scan.

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

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.generateStopKey.

Generate the stop key for a heap or index scan.

public OptimizablePredicate
getOptPredicate(int
"index" (0 based) into the list.
index
)

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.getOptPredicate.

Return the nth OptimizablePredicate in the list.

pack-priv PredicateList

Returns:

A list of pushable predicates, if any, that satisfy the referencedTableMap.
getPushablePredicates
(JBitSet
The referenced table map
referencedTableMap
)

Build a list of pushable predicates, if any, that satisfy the referencedTableMap.

public int
hasEqualityPredicateOnOrderedColumn(Optimizable optTable, int columnNumber, boolean isNullOkay)

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.hasEqualityPredicateOnOrderedColumn.

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

public boolean
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
)

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.hasOptimizableEqualityPredicate.

Is there an optimizable equality predicate on the specified column?

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

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.hasOptimizableEquijoin.

Is there an optimizable equijoin on the specified column?

private static boolean

Returns:

true if the node is a constant or a parameter, false otherwise
isConstantOrParameterNode
(ValueNode
the node to check
node
)

Check if a node is representing a constant or a parameter.

public boolean
isRedundantPredicate(int
The entry in the list
predNum
)

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.isRedundantPredicate.

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

pack-priv void
joinClauseTransitiveClosure(int
The number of tables in the query
numTables
,
FromList
The FromList in question.
fromList
,
CompilerContext
The CompilerContext to use
cc
)

Perform transitive closure on join clauses.

public void
markAllPredicatesQualifiers()

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.markAllPredicatesQualifiers.

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

pack-priv void
markReferencedColumns()

Mark all of the RCs and the RCs in their RC/VCN chain referenced in the predicate list as referenced.

private void
private void
orderUsefulPredicates(Optimizable optTable, ConglomerateDescriptor cd, boolean pushPreds, boolean nonMatchingIndexScan, boolean coveringIndexScan)

pack-priv void
pullExpressions(int
Number of tables in the DML Statement
numTables
,
ValueNode
The search clause to operate on.
searchClause
)

Break apart the search clause into matching a PredicateList where each top level predicate is a separate element in the list.

pack-priv void
pushExpressionsIntoSelect(SelectNode
The underlying SelectNode.
select
,
boolean
Whether to make a copy of the predicate before pushing
copyPredicate
)

Push all predicates, which can be pushed, into the underlying select.

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

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.pushUsefulPredicates.

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
)

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.putOptimizableEqualityPredicateFirst.

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

pack-priv void
remapColumnReferencesToExpressions()

Remap all ColumnReferences in this tree to be clones of the underlying expression.

public final void
removeOptPredicate(int
The index.
predCtr
)

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.removeOptPredicate.

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

public final void
removeOptPredicate(OptimizablePredicate pred)

Another version of removeOptPredicate that takes the Predicate to be removed, rather than the position of the Predicate.

pack-priv void
removeRedundantPredicates()

Remove redundant predicates.

pack-priv ValueNode

Returns:

ValueNode The rebuilt expression tree.
restoreConstantPredicates
()

Rebuild a constant expression tree from the remaining constant predicates and delete those entries from the PredicateList.

pack-priv ValueNode

Returns:

ValueNode The rebuilt expression tree.
restorePredicates
()

Rebuild an expression tree from the remaining predicates and delete those entries from the PredicateList.

public boolean
sameStartStopPosition()

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.sameStartStopPosition.

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

pack-priv void
searchClauseTransitiveClosure(int
The number of tables in the query
numTables
,
boolean
Whether or not user specified a hash join
hashJoinSpecified
)

Perform transitive closure on search clauses.

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

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.selectivity.

calculate the selectivity for a set of predicates.

private double
selectivityNoStatistics(Optimizable optTable)

Compute selectivity the old fashioned way.

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

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.setPredicatesAndProperties.

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
startOperator(Optimizable optTable)

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.startOperator.

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

public int
stopOperator(Optimizable optTable)

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.stopOperator.

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

public void
transferAllPredicates(OptimizablePredicateList otherList)

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.transferAllPredicates.

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

protected void
transferNonQualifiers(Optimizable
The optimizable that we want qualifiers for
optTable
,
PredicateList
ParameterList for non-qualifiers
otherPL
)

Transfer the non-qualifiers from this predicate list to the specified predicate 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
)

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.transferPredicates.

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

public boolean
useful(Optimizable
An Optimizable for the table in question
optTable
,
ConglomerateDescriptor
A ConglomerateDescriptor for the conglomerate in question
cd
)

Implements org.apache.derby.iapi.sql.compile.OptimizablePredicateList.useful.

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

pack-priv void
xorReferencedSet(JBitSet
The JBitSet to XOR with.
fromMap
)

XOR fromMap with the referenced table map in every remaining Predicate in the list.

Inherited from org.apache.derby.impl.sql.compile.QueryTreeNodeVector:
acceptChildrenaddElementdestructiveAppendelementAtindexOfinsertElementAtiteratornondestructiveAppendprintSubNodesremoveAllElementsremoveElementremoveElementAtsetElementAtsize