Class ValueNode
- java.lang.Object
-
- org.apache.derby.impl.sql.compile.QueryTreeNode
-
- org.apache.derby.impl.sql.compile.ValueNode
-
- All Implemented Interfaces:
Visitable
- Direct Known Subclasses:
BaseColumnNode
,BinaryListOperatorNode
,CachedValueNode
,CastNode
,CoalesceFunctionNode
,ColumnReference
,ConditionalNode
,ConstantNode
,CurrentDatetimeOperatorNode
,CurrentRowLocationNode
,DefaultNode
,GenerationClauseNode
,JavaToSQLValueNode
,NextSequenceNode
,OperatorNode
,ParameterNode
,ResultColumn
,SpecialFunctionNode
,SubqueryNode
,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
Fields Modifier and Type Field Description 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_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX
-
-
Constructor Summary
Constructors Constructor Description ValueNode(ContextManager cm)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) ValueNode
bindExpression(FromList fromList, SubqueryList subqueryList, java.util.List<AggregateNode> aggregates)
(package private) ValueNode
bindExpression(FromList fromList, SubqueryList subqueryList, java.util.List<AggregateNode> aggregates, boolean forQueryRewrite)
Bind this expression.(package private) boolean
categorize(JBitSet referencedTabs, boolean simplePredsOnly)
Categorize this predicate.(package private) 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.(package private) boolean
constantExpression(PredicateList whereClause)
Return whether or not this expression tree represents a constant value.(package private) 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.(package private) ValueNode
genEqualsFalseTree()
Transform this into this = false.(package private) void
generate(ActivationClassBuilder acb, MethodBuilder mb)
Do the code generation for this node.(package private) void
generateExpression(ExpressionClassBuilder acb, MethodBuilder mb)
Generate code for this calculation.(package private) ValueNode
genIsNullTree(boolean notNull)
Transform this into this IS NULL or IS NOT NULL.(package private) ValueNode
genSQLJavaSQLTree()
Generate a SQL->Java->SQL conversion tree above the current node and bind the new nodes individually.(package private) ValueNode
getClone()
Return a clone of this node.(package private) 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 DataValueFactoryprotected int
getOrderableVariantType()
Return the variant type for the underlying expression.(package private) java.lang.String
getSchemaName()
This returns the user-supplied schema name of the column.(package private) ResultColumn
getSourceResultColumn()
Get the source for this ValueNode.(package private) 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.(package private) TypeCompiler
getTypeCompiler()
Get the TypeCompiler from this ValueNode, based on its TypeId using getTypeId().(package private) TypeId
getTypeId()
Get the TypeId from this ValueNode.(package private) DataTypeDescriptor
getTypeServices()
Get the DataTypeServices from this ValueNode.(package private) 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.(package private) boolean
isCloneable()
Return whether or not this expression tree is cloneable.(package private) boolean
isConstantExpression()
Return whether or not this expression tree represents a constant expression.(package private) abstract boolean
isEquivalent(ValueNode other)
Tests if this node is equivalent to the specified ValueNode.(package private) boolean
isInListProbeNode()
Returns true if this value node is an operator created for optimized performance of an IN list.(package private) boolean
isParameterNode()
Returns TRUE if this is a parameter node.(package private) boolean
isRelationalOperator()
Returns true if this ValueNode is a relational operator.(package private) boolean
isSameNodeKind(ValueNode other)
Some node classes represent several logical node types (to reduce footprint), which we call kinds.(package private) boolean
optimizableEqualityNode(Optimizable optTable, int columnNumber, boolean isNullOkay)
Return true if the predicate represents an optimizable equality node.(package private) ValueNode
preprocess(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList)
Preprocess an expression tree.(package private) ValueNode
putAndsOnTop()
Do the 1st step in putting an expression into conjunctive normal form.(package private) ValueNode
remapColumnReferencesToExpressions()
Remap all ColumnReferences in this tree to be clones of the underlying expression.(package private) 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(int collationType, int collationDerivation)
Set the collation type and derivation of this node based upon the collation information passed in.void
setCollationInfo(DataTypeDescriptor collationInfoType)
Set the collation type and derivation of this node based upon the collation information in the passed in type.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).(package private) 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(package private) boolean
verifyChangeToCNF()
Verify that changeToCNF() did its job correctly.(package private) boolean
verifyEliminateNots()
Verify that eliminateNots() did its job correctly.(package private) boolean
verifyPutAndsOnTop()
Verify that putAndsOnTop() did its job correctly.-
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, acceptChildren, addTag, addUDTUsagePriv, addUDTUsagePriv, bindOffsetFetch, bindRowMultiSet, bindUserCatalogType, bindUserType, checkReliability, checkReliability, convertDefaultNode, copyTagsFrom, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContext, getContextManager, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getLongProperty, getNullNode, getOffsetOrderedNodes, getOptimizerFactory, getOptimizerTracer, getParameterTypes, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, getUDTDesc, isAtomic, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, optimizerTracingIsOn, orReliability, parseSearchCondition, parseStatement, printLabel, printSubNodes, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setEndOffset, setRefActionInfo, stackPrint, taggedWith, treePrint, treePrint, verifyClassExist
-
-
-
-
Field Detail
-
dataTypeServices
private DataTypeDescriptor dataTypeServices
The data type for this node.
-
transformed
boolean transformed
-
-
Constructor Detail
-
ValueNode
ValueNode(ContextManager cm)
-
-
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
-
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 classQueryTreeNode
- Returns:
- This object as a String
-
getTypeServices
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 typecollationDerivation
- Collation derivation- Throws:
StandardException
- Error setting type
-
getTypeId
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
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
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
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
ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.List<AggregateNode> aggregates) throws StandardException
- Throws:
StandardException
-
bindExpression
ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.List<AggregateNode> aggregates, 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 bindingsubqueryList
- The SubqueryList we are building as we hit SubqueryNodes.aggregates
- The aggregate list being built as we find AggregateNodes- Returns:
- The new top of the expression tree.
- Throws:
StandardException
- Thrown on error
-
genSQLJavaSQLTree
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
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 StatementouterFromList
- FromList from outer query blockouterSubqueryList
- SubqueryList from outer query blockouterPredicateList
- 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
ValueNode genEqualsFalseTree() throws StandardException
Transform this into this = false. Useful for NOT elimination.- Returns:
- The modified expression
- Throws:
StandardException
- Thrown on error
-
genIsNullTree
ValueNode genIsNullTree(boolean notNull) throws StandardException
Transform this into this IS NULL or IS NOT NULL.- Parameters:
notNull
- if true, transform this into IS NOT NULL; otherwise, transform this into IS NULL- 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
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
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
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
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
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 FromTablessimplePredsOnly
- 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
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
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
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
boolean isCloneable()
Return whether or not this expression tree is cloneable.- Returns:
- boolean Whether or not this expression tree is cloneable.
-
getClone
ValueNode getClone() throws StandardException
Return a clone of this node.- Returns:
- ValueNode A clone of this node.
- Throws:
StandardException
- Thrown on error
-
copyFields
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
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
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
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
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 classQueryTreeNode
- Parameters:
acb
- The ActivationClassBuilder for the class being builtmb
- 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
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 builtmb
- 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 tableeqOuterCols
- 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 MapsresultTable
- -1 if this table is not the result table; otherwise the index into tableNumbers for the result tablearg1
- one side of the = predicatearg2
- 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 tableeqOuterCols
- Array of booleans for noting which columns are in = predicates without columns from the subquery block.colReference
- The column to setresultTable
- If -1 set all the bit for all the tables for that column; otherwise set the bit for the specified table
-
isRelationalOperator
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
boolean isBinaryEqualsOperatorNode()
Returns true if this value node is a equals operator.- See Also:
isRelationalOperator()
-
isInListProbeNode
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
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:- the operator is an = or IS NULL operator
- one of the operands is a column specified by optTable/columnNumber
- Both operands are not the same column; i.e tab.col = tab.col
- 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/columnNumberisNullOkay
- if set to true we also consider IS NULL predicates; otherwise consider only = predicates.- Throws:
StandardException
-
requiresTypeFromContext
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
boolean isParameterNode()
Returns TRUE if this is a parameter node. We do lots of special things with Parameter Nodes.
-
isEquivalent
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:
- The two ValueNodes must be of the same node type to be considered equivalent. e.g.: CastNode vs. CastNode - equivalent (if their args also match), ColumnReference vs CastNode - not equivalent.
- If node P contains other ValueNode(s) and so on, those node(s) must also be of the same node type to be considered equivalent.
- If node P takes a parameter list, then the number of arguments and its arguments for the two nodes must also match to be considered equivalent. e.g.: CAST(c1 as INTEGER) vs CAST(c1 as SMALLINT), they are not equivalent.
- When comparing SQL NULLs in this context, they are considered to be equivalent.
- If this does not apply or it is determined that the two nodes are not equivalent then the derived class of this method should return false; otherwise, return true.
- Parameters:
other
- the node to compare this ValueNode against.- Returns:
true
if the two nodes are equivalent,false
otherwise.- Throws:
StandardException
-
isSameNodeKind
boolean isSameNodeKind(ValueNode other)
Some node classes represent several logical node types (to reduce footprint), which we call kinds. This means that implementations ofisEquivalent(org.apache.derby.impl.sql.compile.ValueNode)
cannot always just useinstanceof
to check if the other node represents the same kind. Hence this method needs to be overridden by all node classes that represent several kinds. This default implementation does not look at kinds. It is only called from implementations ofisEquivalent
.- Parameters:
other
- The other value node whose kind we want to compare with.- Returns:
true
ifthis
ando
represent the same logical node type, i.e. kind.
-
-