Class BinaryComparisonOperatorNode
java.lang.Object
org.apache.derby.impl.sql.compile.QueryTreeNode
org.apache.derby.impl.sql.compile.ValueNode
org.apache.derby.impl.sql.compile.OperatorNode
org.apache.derby.impl.sql.compile.BinaryOperatorNode
org.apache.derby.impl.sql.compile.BinaryComparisonOperatorNode
- All Implemented Interfaces:
Visitable
- Direct Known Subclasses:
BinaryRelationalOperatorNode
This node is the superclass for all binary comparison operators, such as =,
<>, <, etc.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private boolean
Fields inherited from class org.apache.derby.impl.sql.compile.BinaryOperatorNode
AND, BinaryArgTypes, BinaryMethodNames, BinaryOperators, BinaryResultTypes, CONCATENATE, DIVIDE, EQ, GE, GT, K_BASE, K_XMLEXISTS, K_XMLQUERY, kind, LE, leftInterfaceType, leftOperand, LIKE, LT, methodName, MINUS, NE, operator, OR, PLUS, receiver, resultInterfaceType, rightInterfaceType, rightOperand, TIMES
Fields inherited from class org.apache.derby.impl.sql.compile.ValueNode
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
ConstructorsConstructorDescriptionBinaryComparisonOperatorNode
(ValueNode leftOperand, ValueNode rightOperand, String operator, String methodName, boolean forQueryRewrite, ContextManager cm) Constructor for a BinaryComparisonOperatorNode -
Method Summary
Modifier and TypeMethodDescription(package private) void
Test the type compatability of the operands and set the type info for this node.(package private) ValueNode
bindExpression
(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates) Bind this comparison operator.(package private) ValueNode
changeToCNF
(boolean underTopAndNode) Finish putting an expression into conjunctive normal form.(package private) ValueNode
eliminateNots
(boolean underNotNode) Eliminate NotNodes in the current query block.(package private) ValueNode
generate a SQL->Java->SQL conversion tree above the left and right operand of this Binary Operator Node if needed.(package private) boolean
Return whether or not to use the between selectivity for this node.(package private) boolean
Was this node generated in a query rewrite?(package private) abstract BinaryOperatorNode
getNegation
(ValueNode leftOperand, ValueNode rightOperand) Negate the comparison.(package private) abstract BinaryOperatorNode
Return a node equivalent to this node, but with the left and right operands swapped.(package private) ValueNode
preprocess
(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList) Preprocess an expression tree.(package private) void
Use between selectivity when calculating the selectivity.(package private) void
setForQueryRewrite
(boolean val) This node was generated as part of a query rewrite.Methods inherited from class org.apache.derby.impl.sql.compile.BinaryOperatorNode
acceptChildren, bindXMLQuery, categorize, constantExpression, generateExpression, getLeftOperand, getOrderableVariantType, getReceiverInterfaceName, getRightOperand, isConstantExpression, isEquivalent, isSameNodeKind, printSubNodes, remapColumnReferencesToExpressions, setLeftOperand, setLeftRightInterfaceType, setMethodName, setOperator, setRightOperand, toString
Methods inherited from class org.apache.derby.impl.sql.compile.OperatorNode
pushSqlXmlUtil
Methods inherited from class org.apache.derby.impl.sql.compile.ValueNode
bindExpression, checkIsBoolean, checkTopPredicatesForEqualsConditions, copyFields, evaluateConstantExpressions, genEqualsFalseTree, generate, genIsNullTree, getClone, getColumnName, getConstantValueAsObject, getDataValueFactory, getSchemaName, getSourceResultColumn, getTableName, getTablesReferenced, getTransformed, getTypeCompiler, getTypeId, getTypeServices, isBinaryEqualsOperatorNode, isBooleanFalse, isBooleanTrue, isCloneable, isInListProbeNode, isParameterNode, isRelationalOperator, optimizableEqualityNode, putAndsOnTop, requiresTypeFromContext, selectivity, setCollationInfo, setCollationInfo, setCollationUsingCompilationSchema, setCollationUsingCompilationSchema, setNullability, setTransformed, setType, setType, setType, updatableByCursor, verifyChangeToCNF, verifyEliminateNots, verifyPutAndsOnTop
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
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, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setEndOffset, setRefActionInfo, stackPrint, taggedWith, treePrint, treePrint, verifyClassExist
-
Field Details
-
forQueryRewrite
private boolean forQueryRewrite -
betweenSelectivity
private boolean betweenSelectivity
-
-
Constructor Details
-
BinaryComparisonOperatorNode
BinaryComparisonOperatorNode(ValueNode leftOperand, ValueNode rightOperand, String operator, String methodName, boolean forQueryRewrite, ContextManager cm) throws StandardException Constructor for a BinaryComparisonOperatorNode- Parameters:
leftOperand
- The left operand of the comparisonrightOperand
- The right operand of the comparisonoperator
- The name of the operatormethodName
- The name of the method to call in the generated classforQueryRewrite
- Can be true only if if this node has been added by an internal rewrite of the query. This allows binding to be more liberal when checking it against allowed syntax. This parameter will be passed FALSE when a new instance of the node is being created(which is the majority of the cases). But when an existing node is getting cloned, the value of this parameter should be passed as the originalNode.getForQueryRewrite(). Examples of this can be found in Predicate.Java and PredicateList.javacm
- The context manager- Throws:
StandardException
-
-
Method Details
-
setForQueryRewrite
void setForQueryRewrite(boolean val) This node was generated as part of a query rewrite. Bypass the normal comparability checks.- Parameters:
val
- true if this was for a query rewrite
-
getForQueryRewrite
boolean getForQueryRewrite()Was this node generated in a query rewrite?- Returns:
- true if it was generated in a query rewrite.
-
setBetweenSelectivity
void setBetweenSelectivity()Use between selectivity when calculating the selectivity. -
getBetweenSelectivity
boolean getBetweenSelectivity()Return whether or not to use the between selectivity for this node.- Returns:
- Whether or not to use the between selectivity for this node.
-
bindExpression
ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates) throws StandardException Bind this comparison operator. All that has to be done for binding a comparison operator is to bind the operands, check the compatibility of the types, and set the result type to SQLBoolean.- Overrides:
bindExpression
in classBinaryOperatorNode
- Parameters:
fromList
- The query's FROM listsubqueryList
- The subquery list being built as we find SubqueryNodesaggregates
- The aggregate list being built as we find AggregateNodes- Returns:
- The new top of the expression tree.
- Throws:
StandardException
- Thrown on error
-
bindComparisonOperator
Test the type compatability of the operands and set the type info for this node. This method is useful both during binding and when we generate nodes within the language module outside of the parser.- 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.- Overrides:
preprocess
in classBinaryOperatorNode
- 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
-
eliminateNots
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.- Overrides:
eliminateNots
in classValueNode
- Parameters:
underNotNode
- Whether or not we are under a NotNode.- Returns:
- The modified expression
- Throws:
StandardException
- Thrown on error
-
getNegation
abstract BinaryOperatorNode getNegation(ValueNode leftOperand, ValueNode rightOperand) throws StandardException Negate the comparison.- Parameters:
leftOperand
- The left operand of the comparison operatorrightOperand
- The right operand of the comparison operator- Returns:
- BinaryOperatorNode The negated expression
- Throws:
StandardException
- Thrown on error
-
getSwappedEquivalent
Return a node equivalent to this node, but with the left and right operands swapped. The node type may also be changed if the operator is not symmetric.
This method may for instance be used to normalize a predicate by moving constants to the right-hand side of the comparison. Example:
1 = A
will be transformed toA = 1
, and10 < B
will be transformed toB > 10
.- Returns:
- an equivalent expression with the operands swapped
- Throws:
StandardException
- if an error occurs
-
changeToCNF
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.- Overrides:
changeToCNF
in classValueNode
- Parameters:
underTopAndNode
- Whether or not we are under a top level AndNode.- Returns:
- The modified expression
- Throws:
StandardException
- Thrown on error
-
genSQLJavaSQLTree
Description copied from class:BinaryOperatorNode
generate a SQL->Java->SQL conversion tree above the left and right operand of this Binary Operator Node if needed. Subclasses can override the default behavior.- Overrides:
genSQLJavaSQLTree
in classBinaryOperatorNode
- Returns:
- ValueNode The new tree.
- Throws:
StandardException
- Thrown on error- See Also:
-