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

java.lang.Object
  extended byorg.apache.derby.impl.sql.compile.QueryTreeNode
      extended byorg.apache.derby.impl.sql.compile.Predicate
All Implemented Interfaces:
java.lang.Comparable, OptimizablePredicate, Visitable

public final class Predicate
extends QueryTreeNode
implements OptimizablePredicate, java.lang.Comparable

A Predicate represents a top level predicate.

Author:
Jerry Brenner

Field Summary
(package private)  AndNode andNode
           
(package private)  int equivalenceClass
           
(package private)  int indexPosition
           
protected  boolean isQualifier
           
(package private)  boolean pushable
           
(package private)  JBitSet referencedSet
           
private  java.util.Hashtable searchClauseHT
           
protected  boolean startKey
           
protected  boolean stopKey
           
 
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, beginOffset, endOffset
 
Constructor Summary
Predicate()
           
 
Method Summary
 Visitable accept(Visitor v)
          Accept a visitor, and call v.visit() on child nodes as necessary.
 void categorize()
          Categorize this predicate.
(package private)  void clearQualifierFlag()
          Clear the qualifier flag.
(package private)  void clearScanFlags()
          Clear the start/stop position and qualifier flags
 int compareTo(java.lang.Object other)
           
 boolean compareWithKnownConstant(Optimizable optTable, boolean considerParameters)
          Is this predicate a comparison with a known constant value?
 void copyFields(Predicate otherPred)
          Copy all fields of this Predicate (except the two that are set from 'init').
 boolean equalsComparisonWithConstantExpression(Optimizable optTable)
          Is this predicate an equality comparison with a constant expression?
(package private)  void generateAbsoluteColumnId(MethodBuilder mb, Optimizable optTable)
           
(package private)  void generateExpressionOperand(Optimizable optTable, int columnPosition, ExpressionClassBuilder acb, MethodBuilder mb)
           
(package private)  void generateNegate(MethodBuilder mb, Optimizable optTable)
           
(package private)  void generateOperator(MethodBuilder mb, Optimizable optTable)
           
(package private)  void generateOrderableVariantType(MethodBuilder mb, Optimizable optTable)
           
(package private)  void generateOrderedNulls(MethodBuilder mb)
           
(package private)  void generateQualMethod(ExpressionClassBuilder acb, MethodBuilder mb, Optimizable optTable)
           
(package private)  void generateRelativeColumnId(MethodBuilder mb, Optimizable optTable)
           
 AndNode getAndNode()
          Return the andNode.
 DataValueDescriptor getCompareValue(Optimizable optTable)
          Get an Object representing the known constant value that the given Optimizable is being compared to.
(package private)  int getEquivalenceClass()
          Get the equivalenceClass for this predicate.
 int getIndexPosition()
          Get the position of the index column that this predicate restricts.
 boolean getPushable()
          Return the pushable.
 JBitSet getReferencedMap()
          Get the map of referenced tables for this OptimizablePredicate.
 JBitSet getReferencedSet()
          Return the referencedSet.
 RelationalOperator getRelop()
          Get the RelationalOperator on the left side of the AND node, if there is one.
 java.util.Hashtable getSearchClauseHT()
          Get the search clause Hash Table.
(package private)  int getStartOperator(Optimizable optTable)
          Get the start operator for this predicate for a scan.
(package private)  int getStopOperator(Optimizable optTable)
           
 int hasEqualOnColumnList(int[] baseColumnPositions, Optimizable optTable)
          Returns if the predicate involves an equal operator on one of the columns specified in the baseColumnPositions.
 boolean hasMethodCall()
          Return whether or not an OptimizablePredicate contains a method call.
 boolean hasSubquery()
          Return whether or not an OptimizablePredicate contains a subquery.
 void init(java.lang.Object andNode, java.lang.Object referencedSet)
          Initializer.
 boolean isOrList()
           
 boolean isPushableOrClause(Optimizable optTable)
          Is this predicate an pushable OR list?
 boolean isQualifier()
          Is this predicate a qualifier?
 boolean isStartKey()
          Is this predicate a start key?
 boolean isStopKey()
          Is this predicate a stop key?
 boolean isStoreQualifier()
          Is this predicate a possible Qualifier for store?
 void markQualifier()
          Tell the predicate that it is to be used as a qualifier in an index scan.
 void markStartKey()
          Tell the predicate that it is to be used as a column in the start key value for an index scan.
 void markStopKey()
          Tell the predicate that it is to be used as a column in the stop key value for an index scan.
 void printSubNodes(int depth)
          Prints the sub-nodes of this object.
 double selectivity(Optimizable optTable)
          Get a (crude) estimate of the selectivity of this predicate.
 void setAndNode(AndNode andNode)
          Set the andNode.
(package private)  void setEquivalenceClass(int equivalenceClass)
          Set the equivalence class, if any, for this predicate.
(package private)  void setIndexPosition(int indexPosition)
          Set the position of the index column that this predicate restricts
(package private)  void setTransitiveSearchClauseAdded(RelationalOperator ro)
          Mark this predicate as having been used to add a new predicate of the specified type via transitive closure on search clauses.
 java.lang.String toString()
          Convert this object to a String.
(package private)  boolean transitiveSearchClauseAdded(RelationalOperator ro)
          Return whether or not this predicate has been used to add a new search clause of the specified type via transitive closure.
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
bind, convertDefaultNode, debugFlush, debugPrint, executeSchemaName, executeStatementName, formatNodeString, foundString, generate, generate, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getSPSName, getStatementType, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, init, init, init, isAtomic, isInstanceOf, isSessionSchema, isSessionSchema, makeConstantAction, makeResultDescription, makeTableName, needsSavepoint, nodeHeader, optimize, parseQueryText, printLabel, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setContextManager, setEndOffset, setNodeType, setRefActionInfo, treePrint, treePrint, verifyClassExist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

andNode

AndNode andNode

pushable

boolean pushable

referencedSet

JBitSet referencedSet

equivalenceClass

int equivalenceClass

indexPosition

int indexPosition

startKey

protected boolean startKey

stopKey

protected boolean stopKey

isQualifier

protected boolean isQualifier

searchClauseHT

private java.util.Hashtable searchClauseHT
Constructor Detail

Predicate

public Predicate()
Method Detail

init

public void init(java.lang.Object andNode,
                 java.lang.Object referencedSet)
Initializer.

Overrides:
init in class QueryTreeNode
Parameters:
andNode - The top of the predicate
referencedSet - Bit map of referenced tables

getReferencedMap

public JBitSet getReferencedMap()
Description copied from interface: OptimizablePredicate
Get the map of referenced tables for this OptimizablePredicate.

Specified by:
getReferencedMap in interface OptimizablePredicate
Returns:
JBitSet Referenced table map.
See Also:
OptimizablePredicate.getReferencedMap()

hasSubquery

public boolean hasSubquery()
Description copied from interface: OptimizablePredicate
Return whether or not an OptimizablePredicate contains a subquery.

Specified by:
hasSubquery in interface OptimizablePredicate
Returns:
boolean Whether or not an OptimizablePredicate includes a subquery.
See Also:
OptimizablePredicate.hasSubquery()

hasMethodCall

public boolean hasMethodCall()
Description copied from interface: OptimizablePredicate
Return whether or not an OptimizablePredicate contains a method call.

Specified by:
hasMethodCall in interface OptimizablePredicate
Returns:
boolean Whether or not an OptimizablePredicate includes a method call.
See Also:
OptimizablePredicate.hasMethodCall()

markStartKey

public void markStartKey()
Description copied from interface: OptimizablePredicate
Tell the predicate that it is to be used as a column in the start key value for an index scan.

Specified by:
markStartKey in interface OptimizablePredicate
See Also:
OptimizablePredicate.markStartKey()

isStartKey

public boolean isStartKey()
Description copied from interface: OptimizablePredicate
Is this predicate a start key?

Specified by:
isStartKey in interface OptimizablePredicate
See Also:
OptimizablePredicate.isStartKey()

markStopKey

public void markStopKey()
Description copied from interface: OptimizablePredicate
Tell the predicate that it is to be used as a column in the stop key value for an index scan.

Specified by:
markStopKey in interface OptimizablePredicate
See Also:
OptimizablePredicate.markStopKey()

isStopKey

public boolean isStopKey()
Description copied from interface: OptimizablePredicate
Is this predicate a stop key?

Specified by:
isStopKey in interface OptimizablePredicate
See Also:
OptimizablePredicate.isStopKey()

markQualifier

public void markQualifier()
Description copied from interface: OptimizablePredicate
Tell the predicate that it is to be used as a qualifier in an index scan.

Specified by:
markQualifier in interface OptimizablePredicate
See Also:
OptimizablePredicate.markQualifier()

isQualifier

public boolean isQualifier()
Description copied from interface: OptimizablePredicate
Is this predicate a qualifier?

Specified by:
isQualifier in interface OptimizablePredicate
See Also:
OptimizablePredicate.isQualifier()

compareWithKnownConstant

public boolean compareWithKnownConstant(Optimizable optTable,
                                        boolean considerParameters)
Description copied from interface: OptimizablePredicate
Is this predicate a comparison with a known constant value?

Specified by:
compareWithKnownConstant in interface OptimizablePredicate
Parameters:
optTable - The Optimizable that we want to know whether we are comparing to a known constant.
considerParameters - Whether or not to consider parameters with defaults as known constants.
See Also:
OptimizablePredicate.compareWithKnownConstant(org.apache.derby.iapi.sql.compile.Optimizable, boolean)

hasEqualOnColumnList

public int hasEqualOnColumnList(int[] baseColumnPositions,
                                Optimizable optTable)
                         throws StandardException
Description copied from interface: OptimizablePredicate
Returns if the predicate involves an equal operator on one of the columns specified in the baseColumnPositions.

Specified by:
hasEqualOnColumnList in interface OptimizablePredicate
Parameters:
baseColumnPositions - the column numbers on which the user wants to check if the equality condition exists.
optTable - the table for which baseColumnPositions are given.
Returns:
returns the index into baseColumnPositions of the column that has the equality operator.
Throws:
StandardException

getCompareValue

public DataValueDescriptor getCompareValue(Optimizable optTable)
                                    throws StandardException
Description copied from interface: OptimizablePredicate
Get an Object representing the known constant value that the given Optimizable is being compared to.

Specified by:
getCompareValue in interface OptimizablePredicate
Throws:
StandardException - Thrown on error
See Also:
OptimizablePredicate.getCompareValue(org.apache.derby.iapi.sql.compile.Optimizable)

equalsComparisonWithConstantExpression

public boolean equalsComparisonWithConstantExpression(Optimizable optTable)
Description copied from interface: OptimizablePredicate
Is this predicate an equality comparison with a constant expression? (IS NULL is considered to be an = comparison with a constant expression).

Specified by:
equalsComparisonWithConstantExpression in interface OptimizablePredicate
Parameters:
optTable - The Optimizable for which we want to know whether it is being equality-compared to a constant expression.
See Also:
OptimizablePredicate.equalsComparisonWithConstantExpression(org.apache.derby.iapi.sql.compile.Optimizable)

selectivity

public double selectivity(Optimizable optTable)
Description copied from interface: OptimizablePredicate
Get a (crude) estimate of the selectivity of this predicate. This is to be used when no better technique is available for estimating the selectivity - this method's estimate is a hard- wired number based on the type of predicate and the datatype (the selectivity of boolean is always 50%).

Specified by:
selectivity in interface OptimizablePredicate
Parameters:
optTable - The Optimizable that this predicate restricts
See Also:
OptimizablePredicate.selectivity(org.apache.derby.iapi.sql.compile.Optimizable)

getIndexPosition

public int getIndexPosition()
Description copied from interface: OptimizablePredicate
Get the position of the index column that this predicate restricts. NOTE: This assumes that this predicate is part of an OptimizablePredicateList, and that classify() has been called on the OptimizablePredicateList.

Specified by:
getIndexPosition in interface OptimizablePredicate
Returns:
The index position that this predicate restricts (zero-based)
See Also:
OptimizablePredicate.getIndexPosition()

compareTo

public int compareTo(java.lang.Object other)
Specified by:
compareTo in interface java.lang.Comparable

getAndNode

public AndNode getAndNode()
Return the andNode.

Returns:
AndNode The andNode.

setAndNode

public void setAndNode(AndNode andNode)
Set the andNode.

Parameters:
andNode - The new andNode.
Returns:
Nothing.

getPushable

public boolean getPushable()
Return the pushable.

Returns:
boolean Whether or not the predicate is pushable.

getReferencedSet

public JBitSet getReferencedSet()
Return the referencedSet.

Returns:
JBitSet The referencedSet.

setEquivalenceClass

void setEquivalenceClass(int equivalenceClass)
Set the equivalence class, if any, for this predicate.

Parameters:
equivalenceClass - The equivalence class for this predicate.
Returns:
Nothing.

getEquivalenceClass

int getEquivalenceClass()
Get the equivalenceClass for this predicate.

Returns:
The equivalenceClass for this predicate.

categorize

public void categorize()
                throws StandardException
Categorize this predicate. Initially, this means building a bit map of the referenced tables for each predicate.

Returns:
None.
Throws:
StandardException - Thrown on error

getRelop

public RelationalOperator getRelop()
Get the RelationalOperator on the left side of the AND node, if there is one. If the left side is not a RelationalOperator, return null.

Returns:
The RelationalOperator on the left side of the AND node, if any.

isOrList

public final boolean isOrList()

isStoreQualifier

public final boolean isStoreQualifier()
Is this predicate a possible Qualifier for store?

Current 2 types of predicates can be pushed to store: 1) RelationalOperator - represented with by left operand as instance of RelationalOperator. 2) A single And'd term of a list of OR terms represented by left operand as instance of OrNode. More checking specific operator's terms to see if they are finally pushable to store. In the final push at execution each term of the AND or OR must be a Relational operator with a column reference on one side and a constant on the other.

Returns:
true if term is wither a AND of a RelationalOperator, or an OR of one or more Relational Operators.
Throws:
StandardException - Standard exception policy.

isPushableOrClause

public final boolean isPushableOrClause(Optimizable optTable)
                                 throws StandardException
Is this predicate an pushable OR list?

Does the predicate represent a AND'd list of OR term's, all of which are pushable. To be pushable each of OR terms must be a legal qualifier, which is a column reference on one side of a Relational operator and a constant on the other.

Returns:
true if the predicate is a pushable set of OR clauses.
Throws:
StandardException - Standard exception policy.

transitiveSearchClauseAdded

boolean transitiveSearchClauseAdded(RelationalOperator ro)
Return whether or not this predicate has been used to add a new search clause of the specified type via transitive closure. NOTE: This can only be true if this is an equijoin between 2 column references.

Parameters:
ro - The search clause that we are currently considering as the source for transitive closure
Returns:
Whether or not this predicate has been used to add a new search clause of the specified type via transitive closure.

setTransitiveSearchClauseAdded

void setTransitiveSearchClauseAdded(RelationalOperator ro)
Mark this predicate as having been used to add a new predicate of the specified type via transitive closure on search clauses.

Parameters:
ro - The search clause that we are currently considering as the source for transitive closure
Returns:
Nothing.

getStartOperator

int getStartOperator(Optimizable optTable)
Get the start operator for this predicate for a scan.

Parameters:
optTable - The optimizable table, so we can tell which side of the operator the search column is on.
Returns:
The start operator for a start key on this column.

getStopOperator

int getStopOperator(Optimizable optTable)

setIndexPosition

void setIndexPosition(int indexPosition)
Set the position of the index column that this predicate restricts

Parameters:
indexPosition - The position of the index column that this predicate restricts.

clearScanFlags

void clearScanFlags()
Clear the start/stop position and qualifier flags

Returns:
Nothing.

clearQualifierFlag

void clearQualifierFlag()
Clear the qualifier flag.

Returns:
Nothing.

generateExpressionOperand

void generateExpressionOperand(Optimizable optTable,
                               int columnPosition,
                               ExpressionClassBuilder acb,
                               MethodBuilder mb)
                         throws StandardException
Throws:
StandardException

generateAbsoluteColumnId

void generateAbsoluteColumnId(MethodBuilder mb,
                              Optimizable optTable)

generateRelativeColumnId

void generateRelativeColumnId(MethodBuilder mb,
                              Optimizable optTable)

generateOperator

void generateOperator(MethodBuilder mb,
                      Optimizable optTable)

generateQualMethod

void generateQualMethod(ExpressionClassBuilder acb,
                        MethodBuilder mb,
                        Optimizable optTable)
                  throws StandardException
Throws:
StandardException

generateOrderedNulls

void generateOrderedNulls(MethodBuilder mb)

generateNegate

void generateNegate(MethodBuilder mb,
                    Optimizable optTable)

generateOrderableVariantType

void generateOrderableVariantType(MethodBuilder mb,
                                  Optimizable optTable)
                            throws StandardException
Throws:
StandardException

toString

public java.lang.String toString()
Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.

Overrides:
toString in class QueryTreeNode
Returns:
This object as a String

printSubNodes

public void printSubNodes(int depth)
Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.

Overrides:
printSubNodes in class QueryTreeNode
Parameters:
depth - The depth of this node in the tree
Returns:
Nothing

accept

public Visitable accept(Visitor v)
                 throws StandardException
Accept a visitor, and call v.visit() on child nodes as necessary.

Specified by:
accept in interface Visitable
Overrides:
accept in class QueryTreeNode
Parameters:
v - the visitor
Throws:
StandardException - on error

copyFields

public void copyFields(Predicate otherPred)
Copy all fields of this Predicate (except the two that are set from 'init').


getSearchClauseHT

public java.util.Hashtable getSearchClauseHT()
Get the search clause Hash Table.


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

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