A wrapper class for a ValueNode that is referenced multiple
places in the abstract syntax tree, but should only be evaluated once.
This node will cache the return value the first time the expression
is evaluated, and simply return the cached value the next time.
For example, an expression such as
CASE expr1
WHEN expr2 THEN expr3
WHEN expr4 THEN expr5
END
is rewritten by the parser to
CASE
WHEN expr1 = expr2 THEN expr3
WHEN expr1 = expr4 THEN expr5
END
In this case, we want expr1 to be evaluated only once, even
though it's referenced twice in the rewritten tree. By wrapping the
ValueNode for expr1 in a CachedValueNode, we
make sure expr1 is only evaluated once, and the second reference
to it will use the cached return value from the first evaluation.
| Modifier and Type | Field and Description |
|---|---|
| private LocalField | field
The field in the |
| private ValueNode | value
The node representing the expression whose value should be cached. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | acceptChildren(Visitor
the visitor v)Overrides org. Accept a visitor on all child nodes. |
| pack-priv ValueNode | bindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates)
Overrides org.
|
| pack-priv boolean | categorize(JBitSet
JBitSet with bit map of referenced FromTables referencedTabs, boolean Whether or not to consider method
calls, field references and conditional nodes
when building bit map simplePredsOnly)Overrides org. Categorize this predicate. |
| pack-priv void | generateClearField(MethodBuilder
the method builder that should have the code mb)Generate code that clears the field that holds the cached value, so that it can be garbage collected. |
| pack-priv void | generateExpression(ExpressionClassBuilder
the class builder acb, MethodBuilder the method builder mb)Overrides org. Generate code that returns the value that this expression evaluates to. |
| pack-priv DataTypeDescriptor | getTypeServices()
Overrides org. Get the DataTypeServices from this ValueNode. |
| pack-priv boolean | isEquivalent(ValueNode
the node to compare this ValueNode against. other)Implements abstract org. Tests if this node is equivalent to the specified ValueNode. |
| pack-priv ValueNode | preprocess(int
Number of tables in the DML Statement numTables, FromList FromList from outer query block outerFromList, SubqueryList SubqueryList from outer query block outerSubqueryList, PredicateList PredicateList from outer query block outerPredicateList)Overrides org. Preprocess an expression tree. |
| pack-priv ValueNode | remapColumnReferencesToExpressions()
Overrides org. Remap all ColumnReferences in this tree to be clones of the underlying expression. |
| pack-priv boolean | requiresTypeFromContext()
Overrides org. Returns TRUE if the type of this node will be determined from the context in which it is getting used. |
| pack-priv void | setType(DataTypeDescriptor
The DataTypeServices to set in this
ValueNode dtd)Overrides org. Set the DataTypeServices for this ValueNode. |
| field | back to summary |
|---|---|
| private LocalField field The field in the | |
| value | back to summary |
|---|---|
| private ValueNode value The node representing the expression whose value should be cached. | |
| CachedValueNode | back to summary |
|---|---|
| pack-priv CachedValueNode(ValueNode value) Wrap the value in a
| |
| acceptChildren | back to summary |
|---|---|
| pack-priv void acceptChildren(Visitor v) throws StandardException Overrides org. Doc from org. Accept a visitor on all child nodes. All sub-classes that add fields
that should be visited, should override this method and call
| |
| bindExpression | back to summary |
|---|---|
| pack-priv ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates) throws StandardException Overrides org.
| |
| categorize | back to summary |
|---|---|
| pack-priv boolean categorize(JBitSet referencedTabs, boolean simplePredsOnly) throws StandardException Overrides org. Doc from org. 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.
| |
| generateClearField | back to summary |
|---|---|
| pack-priv void generateClearField(MethodBuilder mb) Generate code that clears the field that holds the cached value, so that it can be garbage collected.
| |
| generateExpression | back to summary |
|---|---|
| pack-priv void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException Overrides org. Generate code that returns the value that this expression evaluates
to. For the first occurrence of this node in the abstract syntax
tree, this method generates the code needed to evaluate the expression.
Additionally, it stores the returned value in a field in the
| |
| getTypeServices | back to summary |
|---|---|
| pack-priv DataTypeDescriptor getTypeServices() Overrides org. Doc from org. Get the DataTypeServices from this ValueNode.
| |
| isEquivalent | back to summary |
|---|---|
| pack-priv boolean isEquivalent(ValueNode other) throws StandardException Implements abstract org. Doc from org. 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:
| |
| preprocess | back to summary |
|---|---|
| pack-priv ValueNode preprocess(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList) throws StandardException Overrides org. Doc from org. 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.
| |
| remapColumnReferencesToExpressions | back to summary |
|---|---|
| pack-priv ValueNode remapColumnReferencesToExpressions() throws StandardException Overrides org. Doc from org. Remap all ColumnReferences in this tree to be clones of the underlying expression.
| |
| requiresTypeFromContext | back to summary |
|---|---|
| pack-priv boolean requiresTypeFromContext() Overrides org. Doc from org. 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().
| |
| setType | back to summary |
|---|---|
| pack-priv void setType(DataTypeDescriptor dtd) throws StandardException Overrides org. Doc from org. Set the DataTypeServices for this ValueNode. This method is overridden in ParameterNode.
| |