Visitable
class CachedValueNode extends ValueNode
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 | Description |
---|---|---|
private LocalField |
field |
The field in the
Activation class where the value is cached. |
private ValueNode |
value |
The node representing the expression whose value should be cached.
|
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX
transformed
Constructor | Description |
---|---|
CachedValueNode(ValueNode value) |
Wrap the value in a
CachedValueNode . |
Modifier and Type | Method | Description |
---|---|---|
(package private) void |
acceptChildren(Visitor v) |
Accept a visitor on all child nodes.
|
(package private) ValueNode |
bindExpression(FromList fromList,
SubqueryList subqueryList,
java.util.List<AggregateNode> aggregates) |
|
(package private) boolean |
categorize(JBitSet referencedTabs,
boolean simplePredsOnly) |
Categorize this predicate.
|
(package private) void |
generateClearField(MethodBuilder mb) |
Generate code that clears the field that holds the cached value, so
that it can be garbage collected.
|
(package private) void |
generateExpression(ExpressionClassBuilder acb,
MethodBuilder mb) |
Generate code that returns the value that this expression evaluates
to.
|
(package private) DataTypeDescriptor |
getTypeServices() |
Get the DataTypeServices from this ValueNode.
|
(package private) boolean |
isEquivalent(ValueNode other) |
Tests if this node is equivalent to the specified ValueNode.
|
(package private) ValueNode |
preprocess(int numTables,
FromList outerFromList,
SubqueryList outerSubqueryList,
PredicateList outerPredicateList) |
Preprocess an expression tree.
|
(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.
|
(package private) void |
setType(DataTypeDescriptor dtd) |
Set the DataTypeServices for this ValueNode.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
accept, 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
bindExpression, changeToCNF, checkIsBoolean, checkTopPredicatesForEqualsConditions, constantExpression, copyFields, eliminateNots, evaluateConstantExpressions, genEqualsFalseTree, generate, genIsNullTree, genSQLJavaSQLTree, getClone, getColumnName, getConstantValueAsObject, getDataValueFactory, getOrderableVariantType, getSchemaName, getSourceResultColumn, getTableName, getTablesReferenced, getTransformed, getTypeCompiler, getTypeId, isBinaryEqualsOperatorNode, isBooleanFalse, isBooleanTrue, isCloneable, isConstantExpression, isInListProbeNode, isParameterNode, isRelationalOperator, isSameNodeKind, optimizableEqualityNode, putAndsOnTop, selectivity, setCollationInfo, setCollationInfo, setCollationUsingCompilationSchema, setCollationUsingCompilationSchema, setNullability, setTransformed, setType, setType, toString, updatableByCursor, verifyChangeToCNF, verifyEliminateNots, verifyPutAndsOnTop
private ValueNode value
private LocalField field
Activation
class where the value is cached.CachedValueNode(ValueNode value)
CachedValueNode
.value
- the value to wrapvoid generateExpression(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException
Activation
class. For subsequent occurrences of this node, it will
simply generate code that reads the value of that field, so that
reevaluation is not performed.generateExpression
in class ValueNode
acb
- the class buildermb
- the method builderStandardException
- if an error occursvoid generateClearField(MethodBuilder mb)
mb
- the method builder that should have the codeValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.List<AggregateNode> aggregates) throws StandardException
bindExpression
in class ValueNode
StandardException
ValueNode preprocess(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList) throws StandardException
ValueNode
preprocess
in class ValueNode
numTables
- Number of tables in the DML StatementouterFromList
- FromList from outer query blockouterSubqueryList
- SubqueryList from outer query blockouterPredicateList
- PredicateList from outer query blockStandardException
- Thrown on errorboolean isEquivalent(ValueNode other) throws StandardException
ValueNode
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:
isEquivalent
in class ValueNode
other
- the node to compare this ValueNode against.true
if the two nodes are equivalent,
false
otherwise.StandardException
void acceptChildren(Visitor v) throws StandardException
QueryTreeNode
accept(v)
on all visitable fields, as well as
super.acceptChildren(v)
to make sure all visitable fields
defined by the super-class are accepted too.acceptChildren
in class QueryTreeNode
v
- the visitorStandardException
- on errors raised by the visitorDataTypeDescriptor getTypeServices()
ValueNode
getTypeServices
in class ValueNode
void setType(DataTypeDescriptor dtd) throws StandardException
ValueNode
setType
in class ValueNode
dtd
- The DataTypeServices to set in this
ValueNodeStandardException
boolean requiresTypeFromContext()
ValueNode
requiresTypeFromContext
in class ValueNode
ValueNode remapColumnReferencesToExpressions() throws StandardException
ValueNode
remapColumnReferencesToExpressions
in class ValueNode
StandardException
- Thrown on errorboolean categorize(JBitSet referencedTabs, boolean simplePredsOnly) throws StandardException
ValueNode
categorize
in class ValueNode
referencedTabs
- JBitSet with bit map of referenced FromTablessimplePredsOnly
- Whether or not to consider method
calls, field references and conditional nodes
when building bit mapStandardException
- Thrown on errorApache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.