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

java.lang.Object
  extended byorg.apache.derby.impl.sql.compile.QueryTreeNode
      extended byorg.apache.derby.impl.sql.compile.ValueNode
All Implemented Interfaces:
Visitable
Direct Known Subclasses:
BaseColumnNode, BinaryListOperatorNode, BinaryOperatorNode, CastNode, CoalesceFunctionNode, ColumnReference, ConditionalNode, ConstantNode, CurrentDatetimeOperatorNode, CurrentRowLocationNode, DefaultNode, JavaToSQLValueNode, 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.

Author:
Jeff Lichtman

Field Summary
protected  int clause
           
protected  DataTypeDescriptor dataTypeServices
           
static int IN_HAVING_CLAUSE
           
static int IN_SELECT_LIST
           
static int IN_UNKNOWN_CLAUSE
           
static int IN_WHERE_CLAUSE
           
(package private)  boolean transformed
           
private  TypeCompiler typeCompiler
           
private  TypeId typeId
           
 
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
  ValueNode()
           
(package private) 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.
 void checkReliability(int fragmentBitMask, java.lang.String fragmentType)
          Bind time logic.
 void checkReliability(java.lang.String fragmentType, int fragmentBitMask)
          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.
 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.
 int getClause()
          Get the clause that this node appears in.
 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.
 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.
 boolean isParameterNode()
          Returns TRUE if this is a parameter node.
 boolean isRelationalOperator()
          Returns true if this ValueNode is a relational operator.
 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.
 double selectivity(Optimizable optTable)
          The default selectivity for value nodes is 50%.
 void setClause(int clause)
          Set the clause that this node appears in.
 void setDescriptor(DataTypeDescriptor descriptor)
          Set the DataTypeServices for this ValueNode.
(package private)  void setTransformed()
          Mark this predicate has having been transformed (other predicates were generated from it).
 void setType(DataTypeDescriptor dataTypeServices)
          Set the DataTypeServices in this ValueNode.
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.
private  void throwReliabilityException(java.lang.String fragmentType)
          Common code for the 2 checkReliability functions.
 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, bind, convertDefaultNode, debugFlush, debugPrint, executeSchemaName, executeStatementName, formatNodeString, foundString, 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, printSubNodes, 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

IN_UNKNOWN_CLAUSE

public static final int IN_UNKNOWN_CLAUSE
See Also:
Constant Field Values

IN_SELECT_LIST

public static final int IN_SELECT_LIST
See Also:
Constant Field Values

IN_WHERE_CLAUSE

public static final int IN_WHERE_CLAUSE
See Also:
Constant Field Values

IN_HAVING_CLAUSE

public static final int IN_HAVING_CLAUSE
See Also:
Constant Field Values

dataTypeServices

protected DataTypeDescriptor dataTypeServices

typeId

private TypeId typeId

typeCompiler

private TypeCompiler typeCompiler

clause

protected int clause

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

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
Returns:
Nothing
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.

getTypeId

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

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

getDataValueFactory

protected final DataValueFactory getDataValueFactory()
Return the DataValueFactory


getTypeCompiler

public TypeCompiler getTypeCompiler()
Get the TypeCompiler from this ValueNode, based on its TypeId.

Returns:
This ValueNode's TypeCompiler

setType

public void setType(DataTypeDescriptor dataTypeServices)
Set the DataTypeServices in this ValueNode.

Parameters:
dataTypeServices - The DataTypeServices to set in this ValueNode
Returns:
Nothing

setDescriptor

public void setDescriptor(DataTypeDescriptor descriptor)
Set the DataTypeServices for this ValueNode. This method is overridden in ParameterNode.

Parameters:
descriptor - The DataTypeServices to set for this ValueNode
Returns:
Nothing

getSourceResultColumn

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

Returns:
The source of this ValueNode.

getClause

public int getClause()
Get the clause that this node appears in.

Returns:
int The clause that this node appears in.

setClause

public void setClause(int clause)
Set the clause that this node appears in.

Parameters:
clause - The clause that this node appears in.
Returns:
Nothing.

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.

Returns:
Nothing.

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

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)
Copy all of the "appropriate fields" for a shallow copy.

Parameters:
oldVN - The ValueNode to copy from.

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.

checkReliability

public void checkReliability(java.lang.String fragmentType,
                             int fragmentBitMask)
                      throws StandardException
Bind time logic. Raises an error if this ValueNode, once compiled, returns unstable results AND if we're in a context where unstable results are forbidden. Called by children who may NOT appear in the WHERE subclauses of ADD TABLE clauses.

Parameters:
fragmentType - Type of fragment as a String, for inclusion in error messages.
fragmentBitMask - Type of fragment as a bitmask of possible fragment types
Throws:
StandardException - Thrown on error

checkReliability

public void checkReliability(int fragmentBitMask,
                             java.lang.String fragmentType)
                      throws StandardException
Bind time logic. Raises an error if this ValueNode, once compiled, returns unstable results AND if we're in a context where unstable results are forbidden. Called by children who may NOT appear in the WHERE subclauses of ADD TABLE clauses.

Parameters:
fragmentBitMask - Type of fragment as a bitmask of possible fragment types
fragmentType - Type of fragment as a String, to be fetch for the error message.
Throws:
StandardException - Thrown on error

throwReliabilityException

private void throwReliabilityException(java.lang.String fragmentType)
                                throws StandardException
Common code for the 2 checkReliability functions. Always throws StandardException.

Parameters:
fragmentType - Type of fragment as a string, for inclusion in error messages.
Throws:
StandardException - Throws an error, always.

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)
The default selectivity for value nodes is 50%. This is overridden in specific cases, such as the RelationalOperators.


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
Returns:
Nothing.
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:
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()

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

isParameterNode

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


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.