Class PredicateList
- java.lang.Object
-
- org.apache.derby.impl.sql.compile.QueryTreeNode
-
- org.apache.derby.impl.sql.compile.QueryTreeNodeVector<Predicate>
-
- org.apache.derby.impl.sql.compile.PredicateList
-
- All Implemented Interfaces:
java.lang.Iterable<Predicate>
,OptimizablePredicateList
,Visitable
class PredicateList extends QueryTreeNodeVector<Predicate> implements OptimizablePredicateList
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 Class Summary
Nested Classes Modifier and Type Class 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
Fields Modifier and Type Field Description private int
numberOfQualifiers
private int
numberOfStartPredicates
private int
numberOfStopPredicates
private static int
QUALIFIER_NUM_CATEGORIES
private static int
QUALIFIER_ORDER_EQUALS
private static int
QUALIFIER_ORDER_NON_QUAL
private static int
QUALIFIER_ORDER_NOT_EQUALS
private static int
QUALIFIER_ORDER_OR_CLAUSE
private static int
QUALIFIER_ORDER_OTHER_RELOP
-
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNodeVector
eltClass
-
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX
-
-
Constructor Summary
Constructors Constructor Description PredicateList(ContextManager cm)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addOptPredicate(OptimizablePredicate optPredicate)
Add the given OptimizablePredicate to the end of this list.void
addOptPredicate(OptimizablePredicate optPredicate, int position)
Another flavor of addOptPredicate that inserts the given predicate at a given position.(package private) void
addPredicate(Predicate predicate)
Add a Predicate to the list.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.(package private) boolean
allPushable()
Check if all of the predicates in the list are pushable.(package private) boolean
allReference(FromBaseTable fbt)
Check if all the predicates reference a givenFromBaseTable
.private void
calculateWeight(PredicateList.PredicateWrapperList[] pwList, int numUsefulPredicates)
(package private) void
categorize()
Categorize the predicates in the list.(package private) void
checkTopPredicatesForEqualsConditions(int tableNumber, boolean[] eqOuterCols, int[] tableNumbers, JBitSet[] tableColMap, boolean resultColTable)
Update the array of columns in = conditions with constants or correlation or join columns.private int
chooseLongestMatch(PredicateList.PredicateWrapperList[] predArray, java.util.List<Predicate> ret, int numWorkingPredicates)
choose the statistic which has the maximum match with the predicates.void
classify(Optimizable optTable, ConglomerateDescriptor cd)
Classify the predicates in this list according to the given table and conglomerate.(package private) boolean
constantColumn(ColumnReference colRef)
void
copyPredicatesToOtherList(OptimizablePredicateList otherList)
Non-destructive copy of all of the predicates from this list to the other list.private void
countScanFlags()
(package private) void
decrementLevel(FromList fromList, int decrement)
Decrement the level of any CRs from the subquery's FROM list that are interesting to transitive closure.(package private) 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 acb, MethodBuilder mb, MethodBuilder exprFun, LocalField rowField)
Finish generating a start or stop keyprivate LocalField
generateIndexableRow(ExpressionClassBuilder acb, int numberOfColumns)
Generate the indexable row for a start key or stop key.(package private) void
generateInListValues(ExpressionClassBuilder acb, MethodBuilder 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.void
generateQualifiers(ExpressionClassBuilderInterface acbi, MethodBuilder mb, Optimizable optTable, boolean absolute)
Generate the qualifiers for a scan.private void
generateSetColumn(ExpressionClassBuilder acb, MethodBuilder exprFun, int columnNumber, Predicate pred, Optimizable optTable, LocalField rowField, boolean 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)
void
generateStartKey(ExpressionClassBuilderInterface acbi, MethodBuilder mb, Optimizable optTable)
Generate the start key for a heap or index scan.void
generateStopKey(ExpressionClassBuilderInterface acbi, MethodBuilder mb, Optimizable optTable)
Generate the stop key for a heap or index scan.OptimizablePredicate
getOptPredicate(int index)
Return the nth OptimizablePredicate in the list.(package private) PredicateList
getPushablePredicates(JBitSet referencedTableMap)
Build a list of pushable predicates, if any, that satisfy the referencedTableMap.int
hasEqualityPredicateOnOrderedColumn(Optimizable optTable, int columnNumber, boolean isNullOkay)
Check into the predicate list if the passed column has an equijoin predicate on it.boolean
hasOptimizableEqualityPredicate(Optimizable optTable, int columnNumber, boolean isNullOkay)
Is there an optimizable equality predicate on the specified column?boolean
hasOptimizableEquijoin(Optimizable optTable, int columnNumber)
Is there an optimizable equijoin on the specified column?private static boolean
isConstantOrParameterNode(ValueNode node)
Check if a node is representing a constant or a parameter.boolean
isRedundantPredicate(int predNum)
Return whether or not the specified entry in the list is a redundant predicate.(package private) void
joinClauseTransitiveClosure(int numTables, FromList fromList, CompilerContext cc)
Perform transitive closure on join clauses.void
markAllPredicatesQualifiers()
Mark all of the predicates as Qualifiers and set the numberOfQualifiers to reflect this.(package private) void
markReferencedColumns()
Mark all of the RCs and the RCs in their RC/VCN chain referenced in the predicate list as referenced.private void
orderQualifiers()
private void
orderUsefulPredicates(Optimizable optTable, ConglomerateDescriptor cd, boolean pushPreds, boolean nonMatchingIndexScan, boolean coveringIndexScan)
(package private) void
pullExpressions(int numTables, ValueNode searchClause)
Break apart the search clause into matching a PredicateList where each top level predicate is a separate element in the list.(package private) void
pushExpressionsIntoSelect(SelectNode select, boolean copyPredicate)
Push all predicates, which can be pushed, into the underlying select.void
pushUsefulPredicates(Optimizable optTable)
Determine which predicates in this list are useful for limiting the scan on the given table using its best conglomerate.void
putOptimizableEqualityPredicateFirst(Optimizable optTable, int columnNumber)
Find the optimizable equality predicate on the specified column and make it the first predicate in this list.(package private) void
remapColumnReferencesToExpressions()
Remap all ColumnReferences in this tree to be clones of the underlying expression.void
removeOptPredicate(int predCtr)
Remove the OptimizablePredicate at the specified index (0-based) from the list.void
removeOptPredicate(OptimizablePredicate pred)
Another version of removeOptPredicate that takes the Predicate to be removed, rather than the position of the Predicate.(package private) void
removeRedundantPredicates()
Remove redundant predicates.(package private) ValueNode
restoreConstantPredicates()
Rebuild a constant expression tree from the remaining constant predicates and delete those entries from the PredicateList.(package private) ValueNode
restorePredicates()
Rebuild an expression tree from the remaining predicates and delete those entries from the PredicateList.boolean
sameStartStopPosition()
Can we use the same key for both the start and stop key.(package private) void
searchClauseTransitiveClosure(int numTables, boolean hashJoinSpecified)
Perform transitive closure on search clauses.double
selectivity(Optimizable optTable)
calculate the selectivity for a set of predicates.private double
selectivityNoStatistics(Optimizable optTable)
Compute selectivity the old fashioned way.void
setPredicatesAndProperties(OptimizablePredicateList 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.int
startOperator(Optimizable optTable)
Get the start operator for the given Optimizable for a heap or index scan.int
stopOperator(Optimizable optTable)
Get the stop operator for the given Optimizable for a heap or index scan.void
transferAllPredicates(OptimizablePredicateList otherList)
Transfer all the predicates from this list to the given list.protected void
transferNonQualifiers(Optimizable optTable, PredicateList otherPL)
Transfer the non-qualifiers from this predicate list to the specified predicate list.void
transferPredicates(OptimizablePredicateList otherList, JBitSet referencedTableMap, Optimizable table)
Transfer the predicates whose referenced set is contained by the specified referencedTableMap from this list to the other list.boolean
useful(Optimizable optTable, ConglomerateDescriptor cd)
Return true if this predicate list is useful for limiting the scan on the given table using the given conglomerate.(package private) void
xorReferencedSet(JBitSet fromMap)
XOR fromMap with the referenced table map in every remaining Predicate in the list.-
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNodeVector
acceptChildren, addElement, destructiveAppend, elementAt, indexOf, insertElementAt, iterator, nondestructiveAppend, printSubNodes, removeAllElements, removeElement, removeElementAt, setElementAt, size
-
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, addTag, addUDTUsagePriv, addUDTUsagePriv, bindOffsetFetch, bindRowMultiSet, bindUserCatalogType, bindUserType, checkReliability, checkReliability, convertDefaultNode, copyTagsFrom, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, generate, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContext, getContextManager, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getLongProperty, getNullNode, getOffsetOrderedNodes, getOptimizerFactory, getOptimizerTracer, getParameterTypes, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, getUDTDesc, isAtomic, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, optimizerTracingIsOn, orReliability, parseSearchCondition, parseStatement, printLabel, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setEndOffset, setRefActionInfo, stackPrint, taggedWith, toString, treePrint, treePrint, verifyClassExist
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.derby.iapi.sql.compile.OptimizablePredicateList
size
-
-
-
-
Field Detail
-
numberOfStartPredicates
private int numberOfStartPredicates
-
numberOfStopPredicates
private int numberOfStopPredicates
-
numberOfQualifiers
private int numberOfQualifiers
-
QUALIFIER_ORDER_EQUALS
private static final int QUALIFIER_ORDER_EQUALS
- See Also:
- Constant Field Values
-
QUALIFIER_ORDER_OTHER_RELOP
private static final int QUALIFIER_ORDER_OTHER_RELOP
- See Also:
- Constant Field Values
-
QUALIFIER_ORDER_NOT_EQUALS
private static final int QUALIFIER_ORDER_NOT_EQUALS
- See Also:
- Constant Field Values
-
QUALIFIER_ORDER_NON_QUAL
private static final int QUALIFIER_ORDER_NON_QUAL
- See Also:
- Constant Field Values
-
QUALIFIER_ORDER_OR_CLAUSE
private static final int QUALIFIER_ORDER_OR_CLAUSE
- See Also:
- Constant Field Values
-
QUALIFIER_NUM_CATEGORIES
private static final int QUALIFIER_NUM_CATEGORIES
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PredicateList
PredicateList(ContextManager cm)
-
-
Method Detail
-
getOptPredicate
public OptimizablePredicate getOptPredicate(int index)
Description copied from interface:OptimizablePredicateList
Return the nth OptimizablePredicate in the list.- Specified by:
getOptPredicate
in interfaceOptimizablePredicateList
- Parameters:
index
- "index" (0 based) into the list.- Returns:
- OptimizablePredicate The nth OptimizablePredicate in the list.
- See Also:
OptimizablePredicateList.getOptPredicate(int)
-
removeOptPredicate
public final void removeOptPredicate(int predCtr) throws StandardException
Description copied from interface:OptimizablePredicateList
Remove the OptimizablePredicate at the specified index (0-based) from the list.- Specified by:
removeOptPredicate
in interfaceOptimizablePredicateList
- Parameters:
predCtr
- The index.- Throws:
StandardException
- Thrown on error- See Also:
OptimizablePredicateList.removeOptPredicate(int)
-
removeOptPredicate
public final void removeOptPredicate(OptimizablePredicate pred)
Another version of removeOptPredicate that takes the Predicate to be removed, rather than the position of the Predicate. This is not part any interface (yet).
-
addOptPredicate
public void addOptPredicate(OptimizablePredicate optPredicate)
Description copied from interface:OptimizablePredicateList
Add the given OptimizablePredicate to the end of this list.- Specified by:
addOptPredicate
in interfaceOptimizablePredicateList
- Parameters:
optPredicate
- The predicate to add- See Also:
OptimizablePredicateList.addOptPredicate(org.apache.derby.iapi.sql.compile.OptimizablePredicate)
-
addOptPredicate
public void addOptPredicate(OptimizablePredicate optPredicate, int position)
Another flavor of addOptPredicate that inserts the given predicate at a given position. This is not yet part of any interface.
-
useful
public boolean useful(Optimizable optTable, ConglomerateDescriptor cd) throws StandardException
Description copied from interface:OptimizablePredicateList
Return true if this predicate list is useful for limiting the scan on the given table using the given conglomerate.- Specified by:
useful
in interfaceOptimizablePredicateList
- Parameters:
optTable
- An Optimizable for the table in questioncd
- A ConglomerateDescriptor for the conglomerate in question- Returns:
- true if this predicate list can limit the scan
- Throws:
StandardException
- Thrown on error- See Also:
OptimizablePredicateList.useful(org.apache.derby.iapi.sql.compile.Optimizable, org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)
-
pushUsefulPredicates
public void pushUsefulPredicates(Optimizable optTable) throws StandardException
Description copied from interface:OptimizablePredicateList
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.- Specified by:
pushUsefulPredicates
in interfaceOptimizablePredicateList
- Parameters:
optTable
- An Optimizable for the table in question- Throws:
StandardException
- Thrown on error- See Also:
OptimizablePredicateList.pushUsefulPredicates(org.apache.derby.iapi.sql.compile.Optimizable)
-
classify
public void classify(Optimizable optTable, ConglomerateDescriptor cd) throws StandardException
Description copied from interface:OptimizablePredicateList
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.- Specified by:
classify
in interfaceOptimizablePredicateList
- Parameters:
optTable
- The Optimizable table for which to classify the predicates in this list.cd
- The ConglomerateDescriptor for which to classify the predicates in this list.- Throws:
StandardException
- Thrown on error- See Also:
OptimizablePredicateList.classify(org.apache.derby.iapi.sql.compile.Optimizable, org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)
-
markAllPredicatesQualifiers
public void markAllPredicatesQualifiers()
Description copied from interface:OptimizablePredicateList
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.- Specified by:
markAllPredicatesQualifiers
in interfaceOptimizablePredicateList
- See Also:
OptimizablePredicateList.markAllPredicatesQualifiers()
-
hasEqualityPredicateOnOrderedColumn
public int hasEqualityPredicateOnOrderedColumn(Optimizable optTable, int columnNumber, boolean isNullOkay) throws StandardException
Description copied from interface:OptimizablePredicateList
Check into the predicate list if the passed column has an equijoin predicate on it.- Specified by:
hasEqualityPredicateOnOrderedColumn
in interfaceOptimizablePredicateList
- 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
- Throws:
StandardException
- Thrown on error- See Also:
OptimizablePredicateList.hasEqualityPredicateOnOrderedColumn(org.apache.derby.iapi.sql.compile.Optimizable, int, boolean)
-
hasOptimizableEqualityPredicate
public boolean hasOptimizableEqualityPredicate(Optimizable optTable, int columnNumber, boolean isNullOkay) throws StandardException
Description copied from interface:OptimizablePredicateList
Is there an optimizable equality predicate on the specified column?- Specified by:
hasOptimizableEqualityPredicate
in interfaceOptimizablePredicateList
- Parameters:
optTable
- The optimizable the column comes from.columnNumber
- The column number within the base table.isNullOkay
- boolean, whether or not the IS NULL operator satisfies the search- Returns:
- Whether or not there is an optimizable equality predicate on the specified column.
- Throws:
StandardException
- Thrown on error- See Also:
OptimizablePredicateList.hasOptimizableEqualityPredicate(org.apache.derby.iapi.sql.compile.Optimizable, int, boolean)
-
hasOptimizableEquijoin
public boolean hasOptimizableEquijoin(Optimizable optTable, int columnNumber) throws StandardException
Description copied from interface:OptimizablePredicateList
Is there an optimizable equijoin on the specified column?- Specified by:
hasOptimizableEquijoin
in interfaceOptimizablePredicateList
- Parameters:
optTable
- The optimizable the column comes from.columnNumber
- The column number within the base table.- Returns:
- Whether or not there is an optimizable equijoin on the specified column.
- Throws:
StandardException
- Thrown on error- See Also:
OptimizablePredicateList.hasOptimizableEquijoin(org.apache.derby.iapi.sql.compile.Optimizable, int)
-
putOptimizableEqualityPredicateFirst
public void putOptimizableEqualityPredicateFirst(Optimizable optTable, int columnNumber) throws StandardException
Description copied from interface:OptimizablePredicateList
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.- Specified by:
putOptimizableEqualityPredicateFirst
in interfaceOptimizablePredicateList
- Parameters:
optTable
- The optimizable the column comes from.columnNumber
- The column number within the base table.- Throws:
StandardException
- Thrown on error- See Also:
OptimizablePredicateList.putOptimizableEqualityPredicateFirst(org.apache.derby.iapi.sql.compile.Optimizable, int)
-
orderUsefulPredicates
private void orderUsefulPredicates(Optimizable optTable, ConglomerateDescriptor cd, boolean pushPreds, boolean nonMatchingIndexScan, boolean coveringIndexScan) throws StandardException
- Throws:
StandardException
-
addPredicate
void addPredicate(Predicate predicate) throws StandardException
Add a Predicate to the list.- Parameters:
predicate
- A Predicate to add to the list- Throws:
StandardException
- Thrown on error
-
transferNonQualifiers
protected void transferNonQualifiers(Optimizable optTable, PredicateList otherPL) throws StandardException
Transfer the non-qualifiers from this predicate list to the specified predicate list. This is useful for arbitrary hash join, where we need to separate the 2 as the qualifiers get applied when probing the hash table and the non-qualifiers get * applied afterwards.- Parameters:
optTable
- The optimizable that we want qualifiers forotherPL
- ParameterList for non-qualifiers- Throws:
StandardException
- Thrown on error
-
categorize
void categorize() throws StandardException
Categorize the predicates in the list. Initially, this means building a bit map of the referenced tables for each predicate.- Throws:
StandardException
- Thrown on error
-
eliminateBooleanTrueAndBooleanTrue
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.
-
restoreConstantPredicates
ValueNode restoreConstantPredicates() throws StandardException
Rebuild a constant expression tree from the remaining constant predicates and delete those entries from the PredicateList. The rightOperand of every top level AndNode is always a true BooleanConstantNode, so we can blindly overwrite that pointer. Optimizations: We take this opportunity to eliminate: AndNode / \ true BooleanConstantNode true BooleanConstantNode We remove the AndNode if the predicate list is a single AndNode: AndNode / \ LeftOperand RightOperand becomes: LeftOperand If the leftOperand of any AndNode is False, then the entire expression will be False. The expression simple becomes: false BooleanConstantNode- Returns:
- ValueNode The rebuilt expression tree.
- Throws:
StandardException
-
restorePredicates
ValueNode restorePredicates() throws StandardException
Rebuild an expression tree from the remaining predicates and delete those entries from the PredicateList. The rightOperand of every top level AndNode is always a true BooleanConstantNode, so we can blindly overwrite that pointer. Optimizations: We take this opportunity to eliminate: AndNode / \ true BooleanConstantNode true BooleanConstantNode We remove the AndNode if the predicate list is a single AndNode: AndNode / \ LeftOperand RightOperand becomes: LeftOperand If the leftOperand of any AndNode is False, then the entire expression will be False. The expression simple becomes: false BooleanConstantNode- Returns:
- ValueNode The rebuilt expression tree.
- Throws:
StandardException
-
remapColumnReferencesToExpressions
void remapColumnReferencesToExpressions() throws StandardException
Remap all ColumnReferences in this tree to be clones of the underlying expression.- Throws:
StandardException
- Thrown on error
-
pullExpressions
void pullExpressions(int numTables, ValueNode searchClause) throws StandardException
Break apart the search clause into matching a PredicateList where each top level predicate is a separate element in the list. Build a bit map to represent the FromTables referenced within each top level predicate. NOTE: We want the rightOperand of every AndNode to be true, in order to simplify the algorithm for putting the predicates back into the tree. (As we put an AndNode back into the tree, we can ignore it's rightOperand.)- Parameters:
numTables
- Number of tables in the DML StatementsearchClause
- The search clause to operate on.- Throws:
StandardException
- Thrown on error
-
xorReferencedSet
void xorReferencedSet(JBitSet fromMap)
XOR fromMap with the referenced table map in every remaining Predicate in the list. This is useful when pushing down multi-table predicates.- Parameters:
fromMap
- The JBitSet to XOR with.
-
countScanFlags
private void countScanFlags()
-
isConstantOrParameterNode
private static boolean isConstantOrParameterNode(ValueNode node)
Check if a node is representing a constant or a parameter.- Parameters:
node
- the node to check- Returns:
true
if the node is a constant or a parameter,false
otherwise
-
pushExpressionsIntoSelect
void pushExpressionsIntoSelect(SelectNode select, boolean copyPredicate) throws StandardException
Push all predicates, which can be pushed, into the underlying select. A predicate can be pushed into an underlying select if the source of every ColumnReference in the predicate is itself a ColumnReference. This is useful when attempting to push predicates into non-flattenable views or derived tables or into unions.- Parameters:
select
- The underlying SelectNode.copyPredicate
- Whether to make a copy of the predicate before pushing- Throws:
StandardException
- Thrown on error
-
markReferencedColumns
void markReferencedColumns() throws StandardException
Mark all of the RCs and the RCs in their RC/VCN chain referenced in the predicate list as referenced.- Throws:
StandardException
- Thrown on error
-
checkTopPredicatesForEqualsConditions
void checkTopPredicatesForEqualsConditions(int tableNumber, boolean[] eqOuterCols, int[] tableNumbers, JBitSet[] tableColMap, boolean resultColTable) throws StandardException
Update the array of columns in = conditions with constants or correlation or join columns. This is useful when doing subquery flattening on the basis of an equality condition.- Parameters:
tableNumber
- The tableNumber of the table from which the columns of interest come from.eqOuterCols
- Array of booleans for noting which columns are in = predicates with constants or correlation columns.tableNumbers
- Array of table numbers in this query block.resultColTable
- tableNumber is the table the result columns are coming from- Throws:
StandardException
- Thrown on error
-
allPushable
boolean allPushable()
Check if all of the predicates in the list are pushable.- Returns:
- Whether or not all of the predicates in the list are pushable.
-
allReference
boolean allReference(FromBaseTable fbt)
Check if all the predicates reference a givenFromBaseTable
.- Parameters:
fbt
- theFromBaseTable
to check for- Returns:
true
if the table is referenced by all predicates,false
otherwise
-
getPushablePredicates
PredicateList getPushablePredicates(JBitSet referencedTableMap) throws StandardException
Build a list of pushable predicates, if any, that satisfy the referencedTableMap.- Parameters:
referencedTableMap
- The referenced table map- Returns:
- A list of pushable predicates, if any, that satisfy the referencedTableMap.
- Throws:
StandardException
- Thrown on error
-
decrementLevel
void decrementLevel(FromList fromList, int decrement)
Decrement the level of any CRs from the subquery's FROM list that are interesting to transitive closure.- Parameters:
fromList
- The subquery's FROM list.decrement
- Decrement size.
-
joinClauseTransitiveClosure
void joinClauseTransitiveClosure(int numTables, FromList fromList, CompilerContext cc) throws StandardException
Perform transitive closure on join clauses. For each table in the query, we build a list of equijoin clauses of the form: ColumnReference relop ColumnReference Each join clause is put on 2 lists since it joins 2 tables. We then walk the array of lists. We first walk it as the outer list. For each equijoin predicate, we assign an equivalence class if it does not yet have one. We then walk the predicate list (as middle) for the other table, searching for other equijoins with the middle table number and column number. All such predicates are assigned the same equivalence class. We then walk the predicate list (as inner) for the other side of the middle predicate to see if we can find an equijoin between outer and inner. If so, then we simply assign it to the same equivalence class. If not, then we add the new equijoin clause. Note that an equijoin predicate between two tables CANNOT be used for transitive closure, if either of the tables is in the fromlist for NOT EXISTS. In that case, the join predicate actually specifies that the rows from the indicated table must NOT exist, and therefore those non-existent rows cannot be transitively joined to the other matching tables. See DERBY-3033 for a description of a situation in which this actually arises.- Parameters:
numTables
- The number of tables in the queryfromList
- The FromList in question.cc
- The CompilerContext to use- Throws:
StandardException
- Thrown on error
-
searchClauseTransitiveClosure
void searchClauseTransitiveClosure(int numTables, boolean hashJoinSpecified) throws StandardException
Perform transitive closure on search clauses. We build a list of search clauses of the form:[ ] We also build a list of equijoin conditions of form: = where both columns are from different tables in the same query block. For each search clause in the list, we search the equijoin list to see if there is an equijoin clause on the same column. If so, then we search the search clause list for a search condition on the column being joined against with the same relation operator and constant. If a match is found, then there is no need to add a new predicate. Otherwise, we add a new search condition on the column being joined with. In either case, if the relational operator in the search clause is an "=" then we mark the equijoin clause as being redundant. Redundant equijoin clauses will be removed at the end of the search as they are * unnecessary. - Parameters:
numTables
- The number of tables in the queryhashJoinSpecified
- Whether or not user specified a hash join- Throws:
StandardException
- Thrown on error
-
removeRedundantPredicates
void removeRedundantPredicates()
Remove redundant predicates. A redundant predicate has an equivalence class (!= -1) and there are other predicates in the same equivalence class after it in the list. (Actually, we remove all of the predicates in the same equivalence class that appear after this one.)
-
transferPredicates
public void transferPredicates(OptimizablePredicateList otherList, JBitSet referencedTableMap, Optimizable table) throws StandardException
Description copied from interface:OptimizablePredicateList
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.- Specified by:
transferPredicates
in interfaceOptimizablePredicateList
- Parameters:
otherList
- The predicateList to xfer toreferencedTableMap
- The table map to check againsttable
- The table to order the new predicates against- Throws:
StandardException
- Thrown on error- See Also:
OptimizablePredicateList.transferPredicates(org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.util.JBitSet, org.apache.derby.iapi.sql.compile.Optimizable)
-
transferAllPredicates
public void transferAllPredicates(OptimizablePredicateList otherList) throws StandardException
Description copied from interface:OptimizablePredicateList
Transfer all the predicates from this list to the given list.- Specified by:
transferAllPredicates
in interfaceOptimizablePredicateList
- Throws:
StandardException
- Thrown on error- See Also:
OptimizablePredicateList.transferAllPredicates(org.apache.derby.iapi.sql.compile.OptimizablePredicateList)
-
copyPredicatesToOtherList
public void copyPredicatesToOtherList(OptimizablePredicateList otherList) throws StandardException
Description copied from interface:OptimizablePredicateList
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.- Specified by:
copyPredicatesToOtherList
in interfaceOptimizablePredicateList
- Parameters:
otherList
- The predicateList to xfer to- Throws:
StandardException
- Thrown on error- See Also:
OptimizablePredicateList.copyPredicatesToOtherList(org.apache.derby.iapi.sql.compile.OptimizablePredicateList)
-
isRedundantPredicate
public boolean isRedundantPredicate(int predNum)
Description copied from interface:OptimizablePredicateList
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.- Specified by:
isRedundantPredicate
in interfaceOptimizablePredicateList
- Parameters:
predNum
- The entry in the list- Returns:
- Whether or not the specified entry in the list is a redundant predicate.
- See Also:
OptimizablePredicateList.isRedundantPredicate(int)
-
setPredicatesAndProperties
public void setPredicatesAndProperties(OptimizablePredicateList otherList) throws StandardException
Description copied from interface:OptimizablePredicateList
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.- Specified by:
setPredicatesAndProperties
in interfaceOptimizablePredicateList
- Parameters:
otherList
- The list to set the same as this one.- Throws:
StandardException
- Thrown on error- See Also:
OptimizablePredicateList.setPredicatesAndProperties(org.apache.derby.iapi.sql.compile.OptimizablePredicateList)
-
startOperator
public int startOperator(Optimizable optTable)
Description copied from interface:OptimizablePredicateList
Get the start operator for the given Optimizable for a heap or index scan.- Specified by:
startOperator
in interfaceOptimizablePredicateList
- See Also:
OptimizablePredicateList.startOperator(org.apache.derby.iapi.sql.compile.Optimizable)
-
generateStopKey
public void generateStopKey(ExpressionClassBuilderInterface acbi, MethodBuilder mb, Optimizable optTable) throws StandardException
Description copied from interface:OptimizablePredicateList
Generate the stop key for a heap or index scan.- Specified by:
generateStopKey
in interfaceOptimizablePredicateList
- Parameters:
acbi
- The ExpressionClassBuilderInterface for the class we're buildingmb
- the method the generated code is to go intooptTable
- The Optimizable table the stop key is for- Throws:
StandardException
- Thrown on error- See Also:
OptimizablePredicateList.generateStopKey(org.apache.derby.iapi.sql.compile.ExpressionClassBuilderInterface, org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.sql.compile.Optimizable)
-
stopOperator
public int stopOperator(Optimizable optTable)
Description copied from interface:OptimizablePredicateList
Get the stop operator for the given Optimizable for a heap or index scan.- Specified by:
stopOperator
in interfaceOptimizablePredicateList
- See Also:
OptimizablePredicateList.stopOperator(org.apache.derby.iapi.sql.compile.Optimizable)
-
generateSingleQualifierCode
private void generateSingleQualifierCode(MethodBuilder consMB, Optimizable optTable, boolean absolute, ExpressionClassBuilder acb, RelationalOperator or_node, LocalField qualField, int array_idx_1, int array_idx_2) throws StandardException
- Throws:
StandardException
-
generateInListValues
void generateInListValues(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException
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. Also generate a boolean value indicating whether or not the values are already in sorted order. Assumption is that by the time we get here there is at most one IN-list probe predicate in this list.- Parameters:
acb
- The ActivationClassBuilder for the class we're buildingmb
- The MethodBuilder for the method we're building- Throws:
StandardException
-
generateQualifiers
public void generateQualifiers(ExpressionClassBuilderInterface acbi, MethodBuilder mb, Optimizable optTable, boolean absolute) throws StandardException
Description copied from interface:OptimizablePredicateList
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.- Specified by:
generateQualifiers
in interfaceOptimizablePredicateList
- Parameters:
acbi
- The ExpressionClassBuilderInterface for the class we are buildingmb
- The method the generated code is going intooptTable
- The Optimizable table the Qualifiers are onabsolute
- Generate absolute column positions if true, else relative column positions (within the underlying row)- Throws:
StandardException
- Thrown on error- See Also:
OptimizablePredicateList.generateQualifiers(org.apache.derby.iapi.sql.compile.ExpressionClassBuilderInterface, org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.sql.compile.Optimizable, boolean)
-
orderQualifiers
private void orderQualifiers()
-
generateStartKey
public void generateStartKey(ExpressionClassBuilderInterface acbi, MethodBuilder mb, Optimizable optTable) throws StandardException
Description copied from interface:OptimizablePredicateList
Generate the start key for a heap or index scan.- Specified by:
generateStartKey
in interfaceOptimizablePredicateList
- Parameters:
acbi
- The ExpressionClassBuilderInterface for the class we're buildingmb
- The method the generated code is to go intooptTable
- The Optimizable table the start key is for- Throws:
StandardException
- Thrown on error- See Also:
OptimizablePredicateList.generateStartKey(org.apache.derby.iapi.sql.compile.ExpressionClassBuilderInterface, org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.sql.compile.Optimizable)
-
sameStartStopPosition
public boolean sameStartStopPosition() throws StandardException
Description copied from interface:OptimizablePredicateList
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.- Specified by:
sameStartStopPosition
in interfaceOptimizablePredicateList
- Returns:
- Whether or not we can use the same key for both the start and stop key.
- Throws:
StandardException
- Thrown on error- See Also:
OptimizablePredicateList.sameStartStopPosition()
-
generateIndexableRow
private LocalField generateIndexableRow(ExpressionClassBuilder acb, int numberOfColumns)
Generate the indexable row for a start key or stop key.- Parameters:
acb
- The ActivationClassBuilder for the class we're buildingnumberOfColumns
- The number of columns in the key- Returns:
- The field that holds the indexable row
-
generateSetColumn
private void generateSetColumn(ExpressionClassBuilder acb, MethodBuilder exprFun, int columnNumber, Predicate pred, Optimizable optTable, LocalField rowField, boolean isStartKey) throws StandardException
Generate the code to set the value from a predicate in an index column.- Parameters:
acb
- The ActivationClassBuilder for the class we're buildingexprFun
- The MethodBuilder for the method we're buildingcolumnNumber
- The position number of the column we're setting the value in (zero-based)pred
- The Predicate with the value to put in the index columnoptTable
- The Optimizable table the column is inrowField
- The field that holds the indexable rowisStartKey
- Are we generating start or stop key? This information is useful for "in"'s dynamic start/stop key, bug 3858- Throws:
StandardException
- Thrown on error
-
finishKey
private void finishKey(ExpressionClassBuilder acb, MethodBuilder mb, MethodBuilder exprFun, LocalField rowField)
Finish generating a start or stop key- Parameters:
acb
- The ActivationClassBuilder for the class we're buildingexprFun
- The MethodBuilder for the method we're buildingrowField
- The name of the field that holds the indexable row
-
constantColumn
boolean constantColumn(ColumnReference colRef)
-
adjustForSortElimination
public void adjustForSortElimination(RequiredRowOrdering ordering) throws StandardException
Description copied from interface:OptimizablePredicateList
Walk through the predicates in this list and make any adjustments that are required to allow for proper handling of an ORDER BY clause.- Specified by:
adjustForSortElimination
in interfaceOptimizablePredicateList
- Throws:
StandardException
- See Also:
Currently this method only accounts for IN list multi-probing predicates (DERBY-3279).
-
selectivity
public double selectivity(Optimizable optTable) throws StandardException
Description copied from interface:OptimizablePredicateList
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.- Specified by:
selectivity
in interfaceOptimizablePredicateList
- Parameters:
optTable
- the Optimizable that the predicate list restricts.- Throws:
StandardException
- See Also:
OptimizablePredicateList.selectivity(org.apache.derby.iapi.sql.compile.Optimizable)
-
calculateWeight
private void calculateWeight(PredicateList.PredicateWrapperList[] pwList, int numUsefulPredicates)
-
chooseLongestMatch
private int chooseLongestMatch(PredicateList.PredicateWrapperList[] predArray, java.util.List<Predicate> ret, int numWorkingPredicates)
choose the statistic which has the maximum match with the predicates. value is returned in ret.
-
selectivityNoStatistics
private double selectivityNoStatistics(Optimizable optTable) throws StandardException
Compute selectivity the old fashioned way.- Throws:
StandardException
-
-