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

java.lang.Object
  extended by org.apache.derby.impl.sql.compile.QueryTreeNode
      extended by org.apache.derby.impl.sql.compile.ValueNode
All Implemented Interfaces:
Visitable
Direct Known Subclasses:
BaseColumnNode, BinaryListOperatorNode, BinaryOperatorNode, CastNode, CoalesceFunctionNode, ColumnReference, ConditionalNode, ConstantNode, CurrentDatetimeOperatorNode, CurrentRowLocationNode, DefaultNode, GenerationClauseNode, JavaToSQLValueNode, NextSequenceNode, ParameterNode, ResultColumn, SpecialFunctionNode, SubqueryNode, TernaryOperatorNode, UnaryOperatorNode, VirtualColumnNode

public abstract class ValueNode
extends QueryTreeNode

A ValueNode is an abstract class for all nodes that can represent data values, that is, constants, columns, and expressions.


Field Summary
private  DataTypeDescriptor dataTypeServices
          The data type for this node.
(package private)  boolean transformed
           
 
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, isPrivilegeCollectionRequired
 
Constructor Summary
ValueNode()
           
ValueNode(java.lang.Object tcf, java.lang.Object typeId, java.lang.Object isNullable, java.lang.Object maximumWidth)
          Initializer for non-numeric types.
 
Method Summary
 ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.Vector aggregateVector)
           
 ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.Vector aggregateVector, boolean forQueryRewrite)
          Bind this expression.
 boolean categorize(JBitSet referencedTabs, boolean simplePredsOnly)
          Categorize this predicate.
 ValueNode changeToCNF(boolean underTopAndNode)
          Finish putting an expression into conjunctive normal form.
 ValueNode checkIsBoolean()
          Bind time logic.
(package private)  void checkTopPredicatesForEqualsConditions(int tableNumber, boolean[] eqOuterCols, int[] tableNumbers, JBitSet[] tableColMap, boolean resultColTable)
          Update the array of columns in = conditions with expressions without column references from the same table.
 boolean constantExpression(PredicateList whereClause)
          Return whether or not this expression tree represents a constant value.
 void copyFields(ValueNode oldVN)
          Copy all of the "appropriate fields" for a shallow copy.
(package private)  ValueNode eliminateNots(boolean underNotNode)
          Eliminate NotNodes in the current query block.
(package private)  ValueNode evaluateConstantExpressions()
          If this node is known to always evaluate to the same value, return a node that represents that known value as a constant.
 ValueNode genEqualsFalseTree()
          Transform this into this = false.
protected  void generate(ActivationClassBuilder acb, MethodBuilder mb)
          Do the code generation for this node.
 void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb)
          Generate code for this calculation.
 void generateFilter(ExpressionClassBuilder ecb, MethodBuilder mb)
          The only reason this routine exists is so that I don't have to change the protection on generateExpression() and rototill all of QueryTree.
 ValueNode genIsNullTree()
          Transform this into this is null.
 ValueNode genSQLJavaSQLTree()
          Generate a SQL->Java->SQL conversion tree above the current node and bind the new nodes individually.
 ValueNode getClone()
          Return a clone of this node.
 java.lang.String getColumnName()
          This is null so that the caller will substitute in the resultset generated name as needed.
(package private)  java.lang.Object getConstantValueAsObject()
          Return an Object representing the bind time value of this expression tree.
protected  DataValueFactory getDataValueFactory()
          Return the DataValueFactory
protected  int getOrderableVariantType()
          Return the variant type for the underlying expression.
 java.lang.String getSchemaName()
          This returns the user-supplied schema name of the column.
 ResultColumn getSourceResultColumn()
          Get the source for this ValueNode.
 java.lang.String getTableName()
          This returns the user-supplied table name of the column.
(package private)  JBitSet getTablesReferenced()
          Get a bit map of table references in this expression
(package private)  boolean getTransformed()
          Return whether or not this predicate has been transformed.
 TypeCompiler getTypeCompiler()
          Get the TypeCompiler from this ValueNode, based on its TypeId using getTypeId().
 TypeId getTypeId()
          Get the TypeId from this ValueNode.
 DataTypeDescriptor getTypeServices()
          Get the DataTypeServices from this ValueNode.
 void init(java.lang.Object typeId, java.lang.Object precision, java.lang.Object scale, java.lang.Object isNullable, java.lang.Object maximumWidth)
          Initializer for numeric types.
 boolean isBinaryEqualsOperatorNode()
          Returns true if this value node is a equals operator.
(package private)  boolean isBooleanFalse()
          Does this represent a false constant.
(package private)  boolean isBooleanTrue()
          Does this represent a true constant.
 boolean isCloneable()
          Return whether or not this expression tree is cloneable.
 boolean isConstantExpression()
          Return whether or not this expression tree represents a constant expression.
protected abstract  boolean isEquivalent(ValueNode other)
          Tests if this node is equivalent to the specified ValueNode.
 boolean isInListProbeNode()
          Returns true if this value node is an operator created for optimized performance of an IN list.
 boolean isParameterNode()
          Returns TRUE if this is a parameter node.
 boolean isRelationalOperator()
          Returns true if this ValueNode is a relational operator.
protected  boolean isSameNodeType(ValueNode other)
          Tests if this node is of the same type as the specified node as reported by QueryTreeNode.getNodeType().
 boolean optimizableEqualityNode(Optimizable optTable, int columnNumber, boolean isNullOkay)
          Return true if the predicate represents an optimizable equality node.
 ValueNode preprocess(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList)
          Preprocess an expression tree.
 ValueNode putAndsOnTop()
          Do the 1st step in putting an expression into conjunctive normal form.
 ValueNode remapColumnReferencesToExpressions()
          Remap all ColumnReferences in this tree to be clones of the underlying expression.
 boolean requiresTypeFromContext()
          Returns TRUE if the type of this node will be determined from the context in which it is getting used.
 double selectivity(Optimizable optTable)
          The default selectivity for value nodes is 50%.
 void setCollationInfo(DataTypeDescriptor collationInfoType)
          Set the collation type and derivation of this node based upon the collation information in the passed in type.
 void setCollationInfo(int collationType, int collationDerivation)
          Set the collation type and derivation of this node based upon the collation information passed in.
protected  void setCollationUsingCompilationSchema()
          Set the collation based upon the current schema with derivation type implicit.
protected  void setCollationUsingCompilationSchema(int collationDerivation)
          There are many subclasses of ValueNode where we want the DataTypeDescriptor of the node to have the same collation type as the compilation schema's collation type.
 void setNullability(boolean nullability)
          Set the nullability of this value.
(package private)  void setTransformed()
          Mark this predicate has having been transformed (other predicates were generated from it).
 void setType(DataTypeDescriptor dataTypeServices)
          Set the DataTypeServices for this ValueNode.
(package private)  void setType(TypeId typeId, boolean isNullable, int maximumWidth)
          Set this node's type from type components.
(package private)  void setType(TypeId typeId, int precision, int scale, boolean isNullable, int maximumWidth)
          Set this node's type from type components.
private  void setValueCols(JBitSet[] tableColMap, boolean[] eqOuterCols, int colReference, int resultTable)
          Set eqOuterCols and the column in all the tables for constants, parmeters and correlation columns The column in the tableColMap is set only for the current table if the table is the result column table.
 java.lang.String toString()
          Convert this object to a String.
 boolean updatableByCursor()
           
private  void updateMaps(JBitSet[] tableColMap, boolean[] eqOuterCols, int[] tableNumbers, int tableNumber, int resultTable, ValueNode arg1, ValueNode arg2)
          Set the correct bits in tableColMap and set the boolean value in eqOuterCols given two arguments to an = predicate tableColMap[t] - bit is set if the column is in an = predicate with a column in table t, or a bit is set if the column is in an = predicate with a constant,parameter or correlation variable (for all table t, if this tableColMap is not for the table with the result columns) eqOuterCols[c] - is true if the column is in an = predicate with a constant, parameter or correlation variable
 boolean verifyChangeToCNF()
          Verify that changeToCNF() did its job correctly.
(package private)  boolean verifyEliminateNots()
          Verify that eliminateNots() did its job correctly.
 boolean verifyPutAndsOnTop()
          Verify that putAndsOnTop() did its job correctly.
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, acceptChildren, bindOffsetFetch, bindRowMultiSet, bindUserType, checkReliability, checkReliability, convertDefaultNode, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, foundString, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, init, init, init, isAtomic, isInstanceOf, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, orReliability, parseStatement, printLabel, printSubNodes, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setContextManager, setEndOffset, setNodeType, setRefActionInfo, stackPrint, treePrint, treePrint, verifyClassExist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

dataTypeServices

private DataTypeDescriptor dataTypeServices
The data type for this node.


transformed

boolean transformed
Constructor Detail

ValueNode

public ValueNode()

ValueNode

ValueNode(java.lang.Object tcf,
          java.lang.Object typeId,
          java.lang.Object isNullable,
          java.lang.Object maximumWidth)
    throws StandardException
Initializer for non-numeric types.

Parameters:
tcf - The factory to get the DataTypeServicesFactory from
typeId - The TypeID of this new node
isNullable - The nullability of this new node
maximumWidth - The maximum width of this new node
Throws:
StandardException
Method Detail

setType

final void setType(TypeId typeId,
                   boolean isNullable,
                   int maximumWidth)
            throws StandardException
Set this node's type from type components.

Throws:
StandardException

setType

final void setType(TypeId typeId,
                   int precision,
                   int scale,
                   boolean isNullable,
                   int maximumWidth)
            throws StandardException
Set this node's type from type components.

Throws:
StandardException

init

public void init(java.lang.Object typeId,
                 java.lang.Object precision,
                 java.lang.Object scale,
                 java.lang.Object isNullable,
                 java.lang.Object maximumWidth)
          throws StandardException
Initializer for numeric types.

Overrides:
init in class QueryTreeNode
Parameters:
typeId - The TypeID of this new node
precision - The precision of this new node
scale - The scale of this new node
isNullable - The nullability of this new node
maximumWidth - The maximum width of this new node
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

getTypeServices

public DataTypeDescriptor getTypeServices()
Get the DataTypeServices from this ValueNode.

Returns:
The DataTypeServices from this ValueNode. This may be null if the node isn't bound yet.

setNullability

public void setNullability(boolean nullability)
                    throws StandardException
Set the nullability of this value.

Throws:
StandardException

setCollationInfo

public void setCollationInfo(DataTypeDescriptor collationInfoType)
                      throws StandardException
Set the collation type and derivation of this node based upon the collation information in the passed in type. Note that the base type of this node is not changed (e.g. INTEGER), only its collation settings. This may result in a different object being returned from getTypeServices().

Parameters:
collationInfoType - Type to take collation type and derivation from.
Throws:
StandardException - Error setting type.

setCollationInfo

public void setCollationInfo(int collationType,
                             int collationDerivation)
                      throws StandardException
Set the collation type and derivation of this node based upon the collation information passed in. This may result in a different object being returned from getTypeServices().

Parameters:
collationType - Collation type
collationDerivation - Collation derivation
Throws:
StandardException - Error setting type

getTypeId

public TypeId getTypeId()
                 throws StandardException
Get the TypeId from this ValueNode.

Returns:
The TypeId from this ValueNode. This may be null if the node isn't bound yet.
Throws:
StandardException

getDataValueFactory

protected final DataValueFactory getDataValueFactory()
Return the DataValueFactory


getTypeCompiler

public final TypeCompiler getTypeCompiler()
                                   throws StandardException
Get the TypeCompiler from this ValueNode, based on its TypeId using getTypeId().

Returns:
This ValueNode's TypeCompiler
Throws:
StandardException

setType

public void setType(DataTypeDescriptor dataTypeServices)
             throws StandardException
Set the DataTypeServices for this ValueNode. This method is overridden in ParameterNode.

Parameters:
dataTypeServices - The DataTypeServices to set in this ValueNode
Throws:
StandardException

setCollationUsingCompilationSchema

protected final void setCollationUsingCompilationSchema()
                                                 throws StandardException
Set the collation based upon the current schema with derivation type implicit.

Throws:
StandardException

setCollationUsingCompilationSchema

protected final void setCollationUsingCompilationSchema(int collationDerivation)
                                                 throws StandardException
There are many subclasses of ValueNode where we want the DataTypeDescriptor of the node to have the same collation type as the compilation schema's collation type. For that purpose, this method in the baseclass here can be utilized by the subclasses. In addition, the subclasses can pass the collationDerivation that they expect the DataTypeDescriptor to have.

Parameters:
collationDerivation - This can be StringDataValue#COLLATION_DERIVATION_IMPLICIT StringDataValue#COLLATION_DERIVATION_NONE StringDataValue#COLLATION_DERIVATION_EXPLICIT
Throws:
StandardException

getSourceResultColumn

public ResultColumn getSourceResultColumn()
Get the source for this ValueNode.

Returns:
The source of this ValueNode, null if this node is not sourced by a column.

setTransformed

void setTransformed()
Mark this predicate has having been transformed (other predicates were generated from it). This will help us with ensure that the predicate does not get calculated into the selectivity multiple times.


getTransformed

boolean getTransformed()
Return whether or not this predicate has been transformed.

Returns:
Whether or not this predicate has been transformed.

bindExpression

public ValueNode bindExpression(FromList fromList,
                                SubqueryList subqueryList,
                                java.util.Vector aggregateVector)
                         throws StandardException
Throws:
StandardException

bindExpression

public ValueNode bindExpression(FromList fromList,
                                SubqueryList subqueryList,
                                java.util.Vector aggregateVector,
                                boolean forQueryRewrite)
                         throws StandardException
Bind this expression. This is a place-holder method - it should never be called.

Parameters:
fromList - The FROM list to use for binding
subqueryList - The SubqueryList we are building as we hit SubqueryNodes.
aggregateVector - The aggregate vector being built as we find AggregateNodes
Returns:
The new top of the expression tree.
Throws:
StandardException - Thrown on error

genSQLJavaSQLTree

public ValueNode genSQLJavaSQLTree()
                            throws StandardException
Generate a SQL->Java->SQL conversion tree above the current node and bind the new nodes individually. This is useful when doing comparisons, built-in functions, etc. on java types which have a direct mapping to system built-in types.

Returns:
ValueNode The new tree.
Throws:
StandardException - Thrown on error

preprocess

public ValueNode preprocess(int numTables,
                            FromList outerFromList,
                            SubqueryList outerSubqueryList,
                            PredicateList outerPredicateList)
                     throws StandardException
Preprocess an expression tree. We do a number of transformations here (including subqueries, IN lists, LIKE and BETWEEN) plus subquery flattening. NOTE: This is done before the outer ResultSetNode is preprocessed.

Parameters:
numTables - Number of tables in the DML Statement
outerFromList - FromList from outer query block
outerSubqueryList - SubqueryList from outer query block
outerPredicateList - PredicateList from outer query block
Returns:
The modified expression
Throws:
StandardException - Thrown on error

evaluateConstantExpressions

ValueNode evaluateConstantExpressions()
                                throws StandardException
If this node is known to always evaluate to the same value, return a node that represents that known value as a constant. Typically used to transform operators with constant operands into constants.

Returns:
a constant representing the value to which this node is guaranteed to evaluate, or this if the value is not known
Throws:
StandardException - if an error occurs during evaluation
See Also:
ConstantExpressionVisitor

eliminateNots

ValueNode eliminateNots(boolean underNotNode)
                  throws StandardException
Eliminate NotNodes in the current query block. We traverse the tree, inverting ANDs and ORs and eliminating NOTs as we go. We stop at ComparisonOperators and boolean expressions. We invert ComparisonOperators and replace boolean expressions with boolean expression = false. NOTE: Since we do not recurse under ComparisonOperators, there still could be NotNodes left in the tree.

Parameters:
underNotNode - Whether or not we are under a NotNode.
Returns:
The modified expression
Throws:
StandardException - Thrown on error

genEqualsFalseTree

public ValueNode genEqualsFalseTree()
                             throws StandardException
Transform this into this = false. Useful for NOT elimination.

Returns:
The modified expression
Throws:
StandardException - Thrown on error

genIsNullTree

public ValueNode genIsNullTree()
                        throws StandardException
Transform this into this is null. Useful for NOT elimination.

Returns:
The modified expression
Throws:
StandardException - Thrown on error

verifyEliminateNots

boolean verifyEliminateNots()
Verify that eliminateNots() did its job correctly. Verify that there are no NotNodes above the top level comparison operators and boolean expressions.

Returns:
Boolean which reflects validity of the tree.

putAndsOnTop

public ValueNode putAndsOnTop()
                       throws StandardException
Do the 1st step in putting an expression into conjunctive normal form. This step ensures that the top level of the expression is a chain of AndNodes.

Returns:
The modified expression
Throws:
StandardException - Thrown on error

verifyPutAndsOnTop

public boolean verifyPutAndsOnTop()
Verify that putAndsOnTop() did its job correctly. Verify that the top level of the expression is a chain of AndNodes.

Returns:
Boolean which reflects validity of the tree.

changeToCNF

public ValueNode changeToCNF(boolean underTopAndNode)
                      throws StandardException
Finish putting an expression into conjunctive normal form. An expression tree in conjunctive normal form meets the following criteria: o If the expression tree is not null, the top level will be a chain of AndNodes terminating in a true BooleanConstantNode. o The left child of an AndNode will never be an AndNode. o Any right-linked chain that includes an AndNode will be entirely composed of AndNodes terminated by a true BooleanConstantNode. o The left child of an OrNode will never be an OrNode. o Any right-linked chain that includes an OrNode will be entirely composed of OrNodes terminated by a false BooleanConstantNode. o ValueNodes other than AndNodes and OrNodes are considered leaf nodes for purposes of expression normalization. In other words, we won't do any normalization under those nodes. In addition, we track whether or not we are under a top level AndNode. SubqueryNodes need to know this for subquery flattening.

Parameters:
underTopAndNode - Whether or not we are under a top level AndNode.
Returns:
The modified expression
Throws:
StandardException - Thrown on error

verifyChangeToCNF

public boolean verifyChangeToCNF()
Verify that changeToCNF() did its job correctly. Verify that: o AndNode - rightOperand is not instanceof OrNode leftOperand is not instanceof AndNode o OrNode - rightOperand is not instanceof AndNode leftOperand is not instanceof OrNode

Returns:
Boolean which reflects validity of the tree.

categorize

public boolean categorize(JBitSet referencedTabs,
                          boolean simplePredsOnly)
                   throws StandardException
Categorize this predicate. Initially, this means building a bit map of the referenced tables for each predicate. If the source of this ColumnReference (at the next underlying level) is not a ColumnReference or a VirtualColumnNode then this predicate will not be pushed down. For example, in: select * from (select 1 from s) a (x) where x = 1 we will not push down x = 1. NOTE: It would be easy to handle the case of a constant, but if the inner SELECT returns an arbitrary expression, then we would have to copy that tree into the pushed predicate, and that tree could contain subqueries and method calls. RESOLVE - revisit this issue once we have views.

Parameters:
referencedTabs - JBitSet with bit map of referenced FromTables
simplePredsOnly - Whether or not to consider method calls, field references and conditional nodes when building bit map
Returns:
boolean Whether or not source.expression is a ColumnReference or a VirtualColumnNode.
Throws:
StandardException - Thrown on error

getSchemaName

public java.lang.String getSchemaName()
                               throws StandardException
This returns the user-supplied schema name of the column. At this class level, it simply returns null. But, the subclasses of ValueNode will overwrite this method to return the user-supplied schema name. When the value node is in a result column of a select list, the user can request metadata information. The result column won't have a column descriptor, so we return some default information through the expression. This lets expressions that are simply columns return all of the info, and others use this supertype's default values.

Returns:
the default schema name for an expression -- null
Throws:
StandardException

getTableName

public java.lang.String getTableName()
This returns the user-supplied table name of the column. At this class level, it simply returns null. But, the subclasses of ValueNode will overwrite this method to return the user-supplied table name. When the value node is in a result column of a select list, the user can request metadata information. The result column won't have a column descriptor, so we return some default information through the expression. This lets expressions that are simply columns return all of the info, and others use this supertype's default values.

Returns:
the default table name for an expression -- null

updatableByCursor

public boolean updatableByCursor()
Returns:
the default updatability for an expression - false

getColumnName

public java.lang.String getColumnName()
This is null so that the caller will substitute in the resultset generated name as needed.

Returns:
the default column name for an expression -- null.

getTablesReferenced

JBitSet getTablesReferenced()
                      throws StandardException
Get a bit map of table references in this expression

Returns:
A bit map of table numbers referred to in this expression
Throws:
StandardException - Thrown on error

isCloneable

public boolean isCloneable()
Return whether or not this expression tree is cloneable.

Returns:
boolean Whether or not this expression tree is cloneable.

getClone

public ValueNode getClone()
                   throws StandardException
Return a clone of this node.

Returns:
ValueNode A clone of this node.
Throws:
StandardException - Thrown on error

copyFields

public void copyFields(ValueNode oldVN)
                throws StandardException
Copy all of the "appropriate fields" for a shallow copy.

Parameters:
oldVN - The ValueNode to copy from.
Throws:
StandardException

remapColumnReferencesToExpressions

public ValueNode remapColumnReferencesToExpressions()
                                             throws StandardException
Remap all ColumnReferences in this tree to be clones of the underlying expression.

Returns:
ValueNode The remapped expression tree.
Throws:
StandardException - Thrown on error

isConstantExpression

public boolean isConstantExpression()
Return whether or not this expression tree represents a constant expression.

Returns:
Whether or not this expression tree represents a constant expression.

constantExpression

public boolean constantExpression(PredicateList whereClause)
Return whether or not this expression tree represents a constant value. In this case, "constant" means that it will always evaluate to the same thing, even if it includes columns. A column is constant if it is compared to a constant expression.

Returns:
True means this expression tree represents a constant value.

getOrderableVariantType

protected int getOrderableVariantType()
                               throws StandardException
Return the variant type for the underlying expression. The variant type can be: VARIANT - variant within a scan (method calls and non-static field access) SCAN_INVARIANT - invariant within a scan (column references from outer tables) QUERY_INVARIANT - invariant within the life of a query (constant expressions)

Returns:
The variant type for the underlying expression.
Throws:
StandardException - Thrown on error

checkIsBoolean

public ValueNode checkIsBoolean()
                         throws StandardException
Bind time logic. Raises an error if this ValueNode does not resolve to a boolean value. This method is called by WHERE clauses.

Returns:
bound coercion of this node to a builtin type as necessary
Throws:
StandardException - Thrown on error

getConstantValueAsObject

java.lang.Object getConstantValueAsObject()
                                    throws StandardException
Return an Object representing the bind time value of this expression tree. If the expression tree does not evaluate to a constant at bind time then we return null. This is useful for bind time resolution of VTIs. RESOLVE: What do we do for primitives?

Returns:
An Object representing the bind time value of this expression tree. (null if not a bind time constant.)
Throws:
StandardException - Thrown on error

generate

protected final void generate(ActivationClassBuilder acb,
                              MethodBuilder mb)
                       throws StandardException
Do the code generation for this node. Call the more general routine that generates expressions.

Overrides:
generate in class QueryTreeNode
Parameters:
acb - The ActivationClassBuilder for the class being built
mb - The method the expression will go into
Throws:
StandardException - Thrown on error

generateFilter

public void generateFilter(ExpressionClassBuilder ecb,
                           MethodBuilder mb)
                    throws StandardException
The only reason this routine exists is so that I don't have to change the protection on generateExpression() and rototill all of QueryTree.

Parameters:
ecb - The ExpressionClassBuilder for the class being built
mb - The method the expression will go into
Throws:
StandardException - Thrown on error

selectivity

public double selectivity(Optimizable optTable)
                   throws StandardException
The default selectivity for value nodes is 50%. This is overridden in specific cases, such as the RelationalOperators.

Throws:
StandardException

checkTopPredicatesForEqualsConditions

void checkTopPredicatesForEqualsConditions(int tableNumber,
                                           boolean[] eqOuterCols,
                                           int[] tableNumbers,
                                           JBitSet[] tableColMap,
                                           boolean resultColTable)
                                     throws StandardException
Update the array of columns in = conditions with expressions without column references from the same table. This is useful when doing subquery flattening on the basis of an equality condition. eqOuterCols or tableColMap may be null if the calling routine doesn't need the information provided

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 without columns from the subquery block. May be null.
tableNumbers - Array of table numbers in this query block.
tableColMap - Array of bits for noting which columns are in = predicates for each table in the query block. May be null.
resultColTable - True if tableNumber is the table containing result columns
Throws:
StandardException - Thrown on error

isBooleanTrue

boolean isBooleanTrue()
Does this represent a true constant.

Returns:
Whether or not this node represents a true constant.

isBooleanFalse

boolean isBooleanFalse()
Does this represent a false constant.

Returns:
Whether or not this node represents a false constant.

generateExpression

public void generateExpression(ExpressionClassBuilder acb,
                               MethodBuilder mb)
                        throws StandardException
Generate code for this calculation. This is a place-holder method - it should not be called.

Parameters:
acb - The ExpressionClassBuilder for the class being built
mb - The method the expression will go into
Throws:
StandardException - Thrown on error

updateMaps

private void updateMaps(JBitSet[] tableColMap,
                        boolean[] eqOuterCols,
                        int[] tableNumbers,
                        int tableNumber,
                        int resultTable,
                        ValueNode arg1,
                        ValueNode arg2)
                 throws StandardException
Set the correct bits in tableColMap and set the boolean value in eqOuterCols given two arguments to an = predicate tableColMap[t] - bit is set if the column is in an = predicate with a column in table t, or a bit is set if the column is in an = predicate with a constant,parameter or correlation variable (for all table t, if this tableColMap is not for the table with the result columns) eqOuterCols[c] - is true if the column is in an = predicate with a constant, parameter or correlation variable

Parameters:
tableColMap - Array of bitmaps for noting which columns are in = predicates with columns from each table
eqOuterCols - Array of booleans for noting which columns are in = predicates without columns from the subquery block.
tableNumber - table number for which we are setting up the Maps
resultTable - -1 if this table is not the result table; otherwise the index into tableNumbers for the result table
arg1 - one side of the = predicate
arg2 - other side of the = predicate
Throws:
StandardException - Thrown on error

setValueCols

private void setValueCols(JBitSet[] tableColMap,
                          boolean[] eqOuterCols,
                          int colReference,
                          int resultTable)
Set eqOuterCols and the column in all the tables for constants, parmeters and correlation columns The column in the tableColMap is set only for the current table if the table is the result column table. For other tables in the query we set the column for all the tables since the constant will reduced the number of columns required in a unique multicolumn index for distinctness. For example, given an unique index on t1(a,b), setting b=1 means that t1(a) is unique since there can be no duplicates for a where b=1 without destroying the uniqueness of t1(a,b). However, for the result columns setting b=1, does not mean that a select list of t1.a is distinct if t1.a is the only column used in joining with another table e.g. select t1.a from t1, t2 where t1.a = t2.a and t1.b = 1; t1 t2 result a b a a 1 1 1 1 1 2 2 1 2 1

Parameters:
tableColMap - Array of bitmaps for noting which columns are in = predicates with columns from each table
eqOuterCols - Array of booleans for noting which columns are in = predicates without columns from the subquery block.
colReference - The column to set
resultTable - If -1 set all the bit for all the tables for that column; otherwise set the bit for the specified table

isRelationalOperator

public boolean isRelationalOperator()
Returns true if this ValueNode is a relational operator. Relational Operators are <, <=, =, >, >=, <> as well as IS NULL and IS NOT NULL. This is the preferred way of figuring out if a ValueNode is relational or not.

See Also:
RelationalOperator, BinaryRelationalOperatorNode, IsNullNode

isBinaryEqualsOperatorNode

public boolean isBinaryEqualsOperatorNode()
Returns true if this value node is a equals operator.

See Also:
isRelationalOperator()

isInListProbeNode

public boolean isInListProbeNode()
Returns true if this value node is an operator created for optimized performance of an IN list. Or more specifically, returns true if this value node is an equals operator of the form "col = ?" that we generated during preprocessing to allow index multi-probing.


optimizableEqualityNode

public boolean optimizableEqualityNode(Optimizable optTable,
                                       int columnNumber,
                                       boolean isNullOkay)
                                throws StandardException
Return true if the predicate represents an optimizable equality node. an expression is considered to be an optimizable equality node if all the following conditions are met:
  1. the operator is an = or IS NULL operator
  2. one of the operands is a column specified by optTable/columnNumber
  3. Both operands are not the same column; i.e tab.col = tab.col
  4. There are no implicit varchar comparisons of the operands; i.e either both operands are string like (varchar, char, longvarchar) or neither operand is string like

Parameters:
optTable - the table being optimized. Column reference must be from this table.
columnNumber - the column number. One of the operands of this predicate must be the column number specified by optTable/columnNumber
isNullOkay - if set to true we also consider IS NULL predicates; otherwise consider only = predicates.
Throws:
StandardException

requiresTypeFromContext

public boolean requiresTypeFromContext()
Returns TRUE if the type of this node will be determined from the context in which it is getting used. If true is returned then after bindExpression() is called on the node, its type must be set (from the relevant context) using setType().

Returns:
Whether this node's type will be determined from the context

isParameterNode

public boolean isParameterNode()
Returns TRUE if this is a parameter node. We do lots of special things with Parameter Nodes.


isEquivalent

protected abstract boolean isEquivalent(ValueNode other)
                                 throws StandardException
Tests if this node is equivalent to the specified ValueNode. Two ValueNodes are considered equivalent if they will evaluate to the same value during query execution.

This method provides basic expression matching facility for the derived class of ValueNode and it is used by the language layer to compare the node structural form of the two expressions for equivalence at bind phase.

Note that it is not comparing the actual row values at runtime to produce a result; hence, when comparing SQL NULLs, they are considered to be equivalent and not unknown.

One usage case of this method in this context is to compare the select column expression against the group by expression to check if they are equivalent. e.g.:

SELECT c1+c2 FROM t1 GROUP BY c1+c2

In general, node equivalence is determined by the derived class of ValueNode. But they generally abide to the rules below:

Parameters:
other - the node to compare this ValueNode against.
Returns:
true if the two nodes are equivalent, false otherwise.
Throws:
StandardException

isSameNodeType

protected final boolean isSameNodeType(ValueNode other)
Tests if this node is of the same type as the specified node as reported by QueryTreeNode.getNodeType().

Parameters:
other - the node to compare this value node against.
Returns:
true if the two nodes are of the same type.

Built on Thu 2012-03-29 21:53:33+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.