Class BinaryRelationalOperatorNode
- 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
-
- org.apache.derby.impl.sql.compile.BinaryRelationalOperatorNode
-
- All Implemented Interfaces:
Visitable,RelationalOperator
class BinaryRelationalOperatorNode extends BinaryComparisonOperatorNode implements RelationalOperator
This class represents the 6 binary operators: LessThan, LessThanEquals, Equals, NotEquals, GreaterThan and GreaterThanEquals.
-
-
Field Summary
Fields Modifier and Type Field Description private BaseTableNumbersVisitorbtnVisprivate InListOperatorNodeinListProbeSource(package private) static intK_EQUALS(package private) static intK_GREATER_EQUALS(package private) static intK_GREATER_THAN(package private) static intK_LESS_EQUALS(package private) static intK_LESS_THAN(package private) static intK_NOT_EQUALS(package private) intkindThis class is used to hold logically different objects for space efficiency.protected static intLEFTprotected static intNEITHER(package private) JBitSetoptBaseTablesprivate intrelOpTypeprotected static intRIGHT(package private) JBitSetvalNodeBaseTables-
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, 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
-
Fields inherited from interface org.apache.derby.impl.sql.compile.RelationalOperator
EQUALS_RELOP, GREATER_EQUALS_RELOP, GREATER_THAN_RELOP, IS_NOT_NULL_RELOP, IS_NULL_RELOP, LESS_EQUALS_RELOP, LESS_THAN_RELOP, NOT_EQUALS_RELOP
-
-
Constructor Summary
Constructors Constructor Description BinaryRelationalOperatorNode(int kind, ValueNode leftOperand, ValueNode rightOperand, boolean forQueryRewrite, ContextManager cm)Constructor.BinaryRelationalOperatorNode(int kind, ValueNode leftOperand, ValueNode rightOperand, InListOperatorNode inListOp, boolean forQueryRewrite, ContextManager cm)Same as constructor above except takes a third argument that is an InListOperatorNode.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected doublebooleanSelectivity(Optimizable optTable)Return 50% if this is a comparison with a boolean column, a negative selectivity otherwise.private voidbuildTableNumList(Optimizable ft, boolean forPush)Create a set of table numbers to search when trying to find which (if either) of this operator's operands reference the received target table.protected intcolumnOnOneSide(Optimizable optTable)Determine whether there is a column from the given table on one side of this operator, and if so, which side is it on?booleancompareWithKnownConstant(Optimizable optTable, boolean considerParameters)Return whether this operator compares the given Optimizable with a constant whose value is known at compile time.private voidconstructorMinion()booleanequalsComparisonWithConstantExpression(Optimizable optTable)Return whether this operator is an equality comparison of the given optimizable with a constant expression.(package private) ValueNodeevaluateConstantExpressions()See if the node always evaluates to true or false, and return a Boolean constant node if it does.voidgenerateAbsoluteColumnId(MethodBuilder mb, Optimizable optTable)Generate the absolute column id for the ColumnReference that appears on one side of this RelationalOperator or the other, and that refers to the given table.voidgenerateExpressionOperand(Optimizable optTable, int columnPosition, ExpressionClassBuilderInterface acbi, MethodBuilder mb)Check whether this RelationalOperator is a comparison of the given column with an expression.voidgenerateNegate(MethodBuilder mb, Optimizable optTable)Generate an expression that evaluates to true if the result of the comparison should be negated.voidgenerateOperator(MethodBuilder mb, Optimizable optTable)Generate the comparison operator for this RelationalOperator.voidgenerateOrderedNulls(MethodBuilder mb)Generate an expression that evaluates to true if this RelationalOperator uses ordered null semantics, false if it doesn't.voidgenerateQualMethod(ExpressionClassBuilderInterface acbi, MethodBuilder mb, Optimizable optTable)Generate the method to evaluate a Qualifier.voidgenerateRelativeColumnId(MethodBuilder mb, Optimizable optTable)Generate the relative column id for the ColumnReference that appears on one side of this RelationalOperator or the other, and that refers to the given table.(package private) ValueNodegenSQLJavaSQLTree()generate a SQL->Java->SQL conversion tree above the left and right operand of this Binary Operator Node if needed.private intgetAbsoluteColumnPosition(Optimizable optTable)Get the absolute 0-based column position of the ColumnReference from the conglomerate for this Optimizable.ColumnReferencegetColumnOperand(Optimizable optTable)Get the ColumnReference for the given table on one side of this RelationalOperator.ColumnReferencegetColumnOperand(Optimizable optTable, int columnPosition)Check whether this RelationalOperator is a comparison of the given column with an expression.DataValueDescriptorgetCompareValue(Optimizable optTable)Return an Object representing the known value that this relational operator is comparing to a column in the given Optimizable.ValueNodegetExpressionOperand(int tableNumber, int columnPosition, Optimizable ft)Check whether this RelationalOperator is a comparison of the given column with an expression.protected InListOperatorNodegetInListOp()If this rel op was created for an IN-list probe predicate then return the underlying InListOperatorNode.private intgetKindForSwap()Return the node type that must be used in order to construct an equivalent expression if the operands are swapped.private static java.lang.StringgetMethodName(int kind)(package private) BinaryOperatorNodegetNegation(ValueNode leftOperand, ValueNode rightOperand)Returns the negation of this operator; negation of Equals is NotEquals.private intgetNegationNode()ValueNodegetOperand(ColumnReference cRef, int refSetSize, boolean otherSide)Find the operand (left or right) that points to the same table as the received ColumnReference, and then return either that operand or the "other" operand, depending on the value of otherSide.intgetOperator()Return the operator (as an int) for this RelationalOperator.private static java.lang.StringgetOperatorName(int kind)intgetOrderableVariantType(Optimizable optTable)Return the variant type for the Qualifier's Orderable.(package private) java.lang.StringgetReceiverInterfaceName()The methods generated for this node all are on Orderable.private intgetRelOpType(int op)(package private) ValueNodegetScopedOperand(int whichSide, JBitSet parentRSNsTables, ResultSetNode childRSN, int[] whichRC)Take a ResultSetNode and return a column reference that is scoped for for the received ResultSetNode, where "scoped" means that the column reference points to a specific column in the RSN.intgetStartOperator(Optimizable optTable)Get the start operator for a scan (at the store level) for this RelationalOperator.intgetStopOperator(Optimizable optTable)Get the stop operator for a scan (at the store level) for this RelationalOperator.(package private) BinaryOperatorNodegetSwappedEquivalent()Return an equivalent node with the operands swapped, and possibly with the operator type changed in order to preserve the meaning of the expression.RelationalOperatorgetTransitiveSearchClause(ColumnReference otherCR)Return a relational operator which matches the current one but with the passed in ColumnReference as the (left) operand.private booleanimplicitVarcharComparison()Return whether or not this binary relational predicate requires an implicit (var)char conversion.private voidinitBaseTableVisitor(int numTablesInQuery, boolean initOptBaseTables)Initialize the fields used for retrieving base tables in subtrees, which allows us to do a more extensive search for table references.(package private) booleanisBinaryEqualsOperatorNode()Returns true if this value node is a equals operator.(package private) booleanisInListProbeNode()Returns true if this value node is an operator created for optimized performance of an IN list.booleanisQualifier(Optimizable optTable, boolean forPush)Return true if this operator can be compiled into a Qualifier for the given Optimizable table.(package private) booleanisRelationalOperator()Returns true if this ValueNode is a relational operator.(package private) booleanisSameNodeKind(ValueNode o)Some node classes represent several logical node types (to reduce footprint), which we call kinds.protected booleankeyColumnOnLeft(Optimizable optTable)Return true if a key column for the given table is found on the left side of this operator, false if it is found on the right side of this operator.private ValueNodenewBool(boolean b)Create a Boolean constant node with a specified value.(package private) booleanoptimizableEqualityNode(Optimizable optTable, int columnNumber, boolean isNullOkay)Return true if the predicate represents an optimizable equality node.booleanorderedNulls()Return true if this operator uses ordered null semanticsdoubleselectivity(Optimizable optTable)return the selectivity of this predicate.booleanselfComparison(ColumnReference cr)Check whether this RelationalOperator compares the given ColumnReference to any columns in the same table as the ColumnReference.protected booleanusefulStartKey(boolean columnOnLeft)is this is useful start key?booleanusefulStartKey(Optimizable optTable)Tell whether this relop is a useful start key for the given table.protected booleanusefulStopKey(boolean columnOnLeft)booleanusefulStopKey(Optimizable optTable)Tell whether this relop is a useful stop key for the given table.private booleanvalNodeReferencesOptTable(ValueNode valNode, Optimizable optTable, boolean forPush, boolean walkOptTableSubtree)Determine whether or not the received ValueNode (which will usually be a ColumnReference) references either the received optTable or else a base table in the subtree beneath that optTable.-
Methods inherited from class org.apache.derby.impl.sql.compile.BinaryComparisonOperatorNode
bindComparisonOperator, bindExpression, changeToCNF, eliminateNots, getBetweenSelectivity, getForQueryRewrite, preprocess, setBetweenSelectivity, setForQueryRewrite
-
Methods inherited from class org.apache.derby.impl.sql.compile.BinaryOperatorNode
acceptChildren, bindXMLQuery, categorize, constantExpression, generateExpression, getLeftOperand, getOrderableVariantType, getRightOperand, isConstantExpression, isEquivalent, 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, genEqualsFalseTree, generate, genIsNullTree, getClone, getColumnName, getConstantValueAsObject, getDataValueFactory, getSchemaName, getSourceResultColumn, getTableName, getTablesReferenced, getTransformed, getTypeCompiler, getTypeId, getTypeServices, isBooleanFalse, isBooleanTrue, isCloneable, isParameterNode, putAndsOnTop, requiresTypeFromContext, 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 Detail
-
K_EQUALS
static final int K_EQUALS
- See Also:
- Constant Field Values
-
K_GREATER_EQUALS
static final int K_GREATER_EQUALS
- See Also:
- Constant Field Values
-
K_GREATER_THAN
static final int K_GREATER_THAN
- See Also:
- Constant Field Values
-
K_LESS_EQUALS
static final int K_LESS_EQUALS
- See Also:
- Constant Field Values
-
K_LESS_THAN
static final int K_LESS_THAN
- See Also:
- Constant Field Values
-
K_NOT_EQUALS
static final int K_NOT_EQUALS
- See Also:
- Constant Field Values
-
kind
final int kind
This class is used to hold logically different objects for space efficiency.kindrepresents the logical object type. See alsoValueNode.isSameNodeKind(org.apache.derby.impl.sql.compile.ValueNode).
-
relOpType
private int relOpType
-
btnVis
private BaseTableNumbersVisitor btnVis
-
optBaseTables
JBitSet optBaseTables
-
valNodeBaseTables
JBitSet valNodeBaseTables
-
inListProbeSource
private InListOperatorNode inListProbeSource
-
LEFT
protected static final int LEFT
- See Also:
- Constant Field Values
-
NEITHER
protected static final int NEITHER
- See Also:
- Constant Field Values
-
RIGHT
protected static final int RIGHT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BinaryRelationalOperatorNode
BinaryRelationalOperatorNode(int kind, ValueNode leftOperand, ValueNode rightOperand, boolean forQueryRewrite, ContextManager cm) throws StandardExceptionConstructor. DERBY-6185 Query against view with"where name LIKE 'Col1' ESCAPE '\' "failed. ArgumentforQueryRewritecan be true only 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.java- Parameters:
kind- The kind of operatorleftOperand- The left operandrightOperand- The right operandforQueryRewrite- See method descriptioncm- The context manager- Throws:
StandardException
-
BinaryRelationalOperatorNode
BinaryRelationalOperatorNode(int kind, ValueNode leftOperand, ValueNode rightOperand, InListOperatorNode inListOp, boolean forQueryRewrite, ContextManager cm) throws StandardExceptionSame as constructor above except takes a third argument that is an InListOperatorNode. This version is used during IN-list preprocessing to create a "probe predicate" for the IN-list. See InListOperatorNode.preprocess() for more. DERBY-6185 (Query against view with "where name LIKE 'Col1' ESCAPE '\' " failed) 4th argument forQueryRewrite can be true only 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.java- Throws:
StandardException
-
-
Method Detail
-
constructorMinion
private void constructorMinion()
-
getMethodName
private static java.lang.String getMethodName(int kind)
-
getOperatorName
private static java.lang.String getOperatorName(int kind)
-
getRelOpType
private int getRelOpType(int op)
-
getInListOp
protected InListOperatorNode getInListOp()
If this rel op was created for an IN-list probe predicate then return the underlying InListOperatorNode. Will return null if this rel op is a "legitimate" relational operator (as opposed to a disguised IN-list). With the exception of nullability checking via the isInListProbeNode() method, all access to this.inListProbeSource MUST come through this method, as this method ensures that the left operand of the inListProbeSource is set correctly before returning it.
-
getColumnOperand
public ColumnReference getColumnOperand(Optimizable optTable, int columnPosition)
Description copied from interface:RelationalOperatorCheck whether this RelationalOperator is a comparison of the given column with an expression. If so, return the ColumnReference that corresponds to the given column, and that is on one side of this RelationalOperator or the other (this method copes with the column being on either side of the operator). If the given column does not appear by itself on one side of the comparison, the method returns null.- Specified by:
getColumnOperandin interfaceRelationalOperator- Parameters:
optTable- An Optimizable for the base table the column is incolumnPosition- The ordinal position of the column (one-based)- Returns:
- The ColumnReference on one side of this RelationalOperator that represents the given columnPosition. Returns null if no such ColumnReference exists by itself on one side of this RelationalOperator.
- See Also:
RelationalOperator.getColumnOperand(org.apache.derby.iapi.sql.compile.Optimizable, int)
-
getColumnOperand
public ColumnReference getColumnOperand(Optimizable optTable)
Description copied from interface:RelationalOperatorGet the ColumnReference for the given table on one side of this RelationalOperator. This presumes it will be found only on one side. If not found, it will return null.- Specified by:
getColumnOperandin interfaceRelationalOperator- See Also:
RelationalOperator.getColumnOperand(org.apache.derby.iapi.sql.compile.Optimizable, int)
-
getExpressionOperand
public ValueNode getExpressionOperand(int tableNumber, int columnPosition, Optimizable ft)
Description copied from interface:RelationalOperatorCheck whether this RelationalOperator is a comparison of the given column with an expression. If so, return the expression the column is being compared to.- Specified by:
getExpressionOperandin interfaceRelationalOperator- Parameters:
tableNumber- The table number of the base table the column is incolumnPosition- The ordinal position of the column (one-based)ft- We'll look for the column in all tables at and beneath ft. This is useful if ft is, say, a ProjectRestrictNode over a subquery-- then we want to look at all of the FROM tables in the subquery to try to find the right column.- Returns:
- The ValueNode for the expression the column is being compared to - null if the column is not being compared to anything.
- See Also:
RelationalOperator.getExpressionOperand(int, int, org.apache.derby.iapi.sql.compile.Optimizable)
-
getOperand
public ValueNode getOperand(ColumnReference cRef, int refSetSize, boolean otherSide)
Description copied from interface:RelationalOperatorFind the operand (left or right) that points to the same table as the received ColumnReference, and then return either that operand or the "other" operand, depending on the value of otherSide. This presumes it will be found only on one side. If not found, it will return null.- Specified by:
getOperandin interfaceRelationalOperator- Parameters:
cRef- The ColumnReference for which we're searching.refSetSize- Size of the referenced map for the predicate represented by this RelationalOperator node. This is used for storing base table numbers when searching for cRef.otherSide- Assuming we find an operand that points to the same table as cRef, then we will return the *other* operand if otherSide is true; else we'll return the operand that matches cRef.- See Also:
RelationalOperator.getOperand(org.apache.derby.impl.sql.compile.ColumnReference, int, boolean)
-
generateExpressionOperand
public void generateExpressionOperand(Optimizable optTable, int columnPosition, ExpressionClassBuilderInterface acbi, MethodBuilder mb) throws StandardException
Description copied from interface:RelationalOperatorCheck whether this RelationalOperator is a comparison of the given column with an expression. If so, generate the Expression for the ValueNode that the column is being compared to.- Specified by:
generateExpressionOperandin interfaceRelationalOperator- Parameters:
optTable- An Optimizable for the base table the column is incolumnPosition- The ordinal position of the column (one-based)acbi- The ExpressionClassBuilder for the class we're buildingmb- The method the expression will go into- Throws:
StandardException- Thrown on error- See Also:
RelationalOperator.generateExpressionOperand(org.apache.derby.iapi.sql.compile.Optimizable, int, org.apache.derby.iapi.sql.compile.ExpressionClassBuilderInterface, org.apache.derby.iapi.services.compiler.MethodBuilder)
-
selfComparison
public boolean selfComparison(ColumnReference cr) throws StandardException
Description copied from interface:RelationalOperatorCheck whether this RelationalOperator compares the given ColumnReference to any columns in the same table as the ColumnReference.- Specified by:
selfComparisonin interfaceRelationalOperator- Parameters:
cr- The ColumnReference that is being compared to some expression.- Returns:
- true if the given ColumnReference is being compared to any columns from the same table
- Throws:
StandardException- Thrown on error- See Also:
RelationalOperator.selfComparison(org.apache.derby.impl.sql.compile.ColumnReference)
-
usefulStartKey
public boolean usefulStartKey(Optimizable optTable)
Description copied from interface:RelationalOperatorTell whether this relop is a useful start key for the given table. It has already been determined that the relop has a column from the given table on one side or the other.- Specified by:
usefulStartKeyin interfaceRelationalOperator- Parameters:
optTable- The Optimizable table for which we want to know whether this is a useful start key.- Returns:
- true if this is a useful start key
- See Also:
RelationalOperator.usefulStartKey(org.apache.derby.iapi.sql.compile.Optimizable)
-
keyColumnOnLeft
protected boolean keyColumnOnLeft(Optimizable optTable)
Return true if a key column for the given table is found on the left side of this operator, false if it is found on the right side of this operator. NOTE: This method assumes that a key column will be found on one side or the other. If you don't know whether a key column exists, use the columnOnOneSide() method (below).- Parameters:
optTable- The Optimizable table that we're looking for a key column on.- Returns:
- true if a key column for the given table is on the left side of this operator, false if one is found on the right side of this operator.
-
columnOnOneSide
protected int columnOnOneSide(Optimizable optTable)
Determine whether there is a column from the given table on one side of this operator, and if so, which side is it on?- Parameters:
optTable- The Optimizable table that we're looking for a key column on.- Returns:
- LEFT if there is a column on the left, RIGHT if there is a column on the right, NEITHER if no column found on either side.
-
usefulStopKey
public boolean usefulStopKey(Optimizable optTable)
Description copied from interface:RelationalOperatorTell whether this relop is a useful stop key for the given table. It has already been determined that the relop has a column from the given table on one side or the other.- Specified by:
usefulStopKeyin interfaceRelationalOperator- Parameters:
optTable- The Optimizable table for which we want to know whether this is a useful stop key.- Returns:
- true if this is a useful stop key
- See Also:
RelationalOperator.usefulStopKey(org.apache.derby.iapi.sql.compile.Optimizable)
-
generateAbsoluteColumnId
public void generateAbsoluteColumnId(MethodBuilder mb, Optimizable optTable)
Description copied from interface:RelationalOperatorGenerate the absolute column id for the ColumnReference that appears on one side of this RelationalOperator or the other, and that refers to the given table. (Absolute column id means column id within the row stored on disk.)- Specified by:
generateAbsoluteColumnIdin interfaceRelationalOperator- Parameters:
mb- The method the generated code is to go intooptTable- The optimizable table we're doing the scan on.- See Also:
RelationalOperator.generateAbsoluteColumnId(org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.sql.compile.Optimizable)
-
generateRelativeColumnId
public void generateRelativeColumnId(MethodBuilder mb, Optimizable optTable)
Description copied from interface:RelationalOperatorGenerate the relative column id for the ColumnReference that appears on one side of this RelationalOperator or the other, and that refers to the given table. (Relative column id means column id within the partial row returned by the store.)- Specified by:
generateRelativeColumnIdin interfaceRelationalOperator- Parameters:
mb- The method the generated code is to go intooptTable- The optimizable table we're doing the scan on.- See Also:
RelationalOperator.generateRelativeColumnId(org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.sql.compile.Optimizable)
-
getAbsoluteColumnPosition
private int getAbsoluteColumnPosition(Optimizable optTable)
Get the absolute 0-based column position of the ColumnReference from the conglomerate for this Optimizable.- Parameters:
optTable- The Optimizable- Returns:
- The absolute 0-based column position of the ColumnReference
-
generateQualMethod
public void generateQualMethod(ExpressionClassBuilderInterface acbi, MethodBuilder mb, Optimizable optTable) throws StandardException
Description copied from interface:RelationalOperatorGenerate the method to evaluate a Qualifier. The factory method for a Qualifier takes a GeneratedMethod that returns the Orderable that Qualifier.getOrderable() returns.- Specified by:
generateQualMethodin interfaceRelationalOperator- Parameters:
acbi- The ExpressionClassBuilder for the class we're buildingmb- The method the generated code is to go intooptTable- The Optimizable table the Qualifier will qualify- Throws:
StandardException- Thrown on error
-
generateOrderedNulls
public void generateOrderedNulls(MethodBuilder mb)
Description copied from interface:RelationalOperatorGenerate an expression that evaluates to true if this RelationalOperator uses ordered null semantics, false if it doesn't.- Specified by:
generateOrderedNullsin interfaceRelationalOperator- Parameters:
mb- The method the generated code is to go into- See Also:
RelationalOperator.generateOrderedNulls(org.apache.derby.iapi.services.compiler.MethodBuilder)
-
orderedNulls
public boolean orderedNulls()
Description copied from interface:RelationalOperatorReturn true if this operator uses ordered null semantics- Specified by:
orderedNullsin interfaceRelationalOperator- See Also:
RelationalOperator.orderedNulls()
-
isQualifier
public boolean isQualifier(Optimizable optTable, boolean forPush) throws StandardException
Description copied from interface:RelationalOperatorReturn true if this operator can be compiled into a Qualifier for the given Optimizable table. This means that there is a column from that table on one side of this relop, and an expression that does not refer to the table on the other side of the relop. Note that this method has two uses: 1) see if this operator (or more specifically, the predicate to which this operator belongs) can be used as a join predicate (esp. for a hash join), and 2) see if this operator can be pushed to the target optTable. We use the parameter "forPush" to distinguish between the two uses because in some cases (esp. situations where we have subqueries) the answer to "is this a qualifier?" can differ depending on whether or not we're pushing. In particular, for binary ops that are join predicates, if we're just trying to find an equijoin predicate then this op qualifies if it references either the target table OR any of the base tables in the table's subtree. But if we're planning to push the predicate down to the target table, this op only qualifies if it references the target table directly. This difference in behavior is required because in case 1 (searching for join predicates), the operator remains at its current level in the tree even if its operands reference nodes further down; in case 2, though, we'll end up pushing the operator down the tree to child node(s) and that requires additional logic, such as "scoping" consideration. Until that logic is in place, we don't search a subtree if the intent is to push the predicate to which this operator belongs further down that subtree. See BinaryRelationalOperatorNode for an example of where this comes into play.- Specified by:
isQualifierin interfaceRelationalOperator- Parameters:
optTable- The Optimizable table in question.forPush- Are we asking because we're trying to push?- Returns:
- true if this operator can be compiled into a Qualifier for the given Optimizable table.
- Throws:
StandardException- Thrown on error- See Also:
RelationalOperator.isQualifier(org.apache.derby.iapi.sql.compile.Optimizable, boolean)
-
getOrderableVariantType
public int getOrderableVariantType(Optimizable optTable) throws StandardException
Description copied from interface:RelationalOperatorReturn the variant type for the Qualifier's Orderable. (Is the Orderable invariant within a scan or within a query?)- Specified by:
getOrderableVariantTypein interfaceRelationalOperator- Parameters:
optTable- The Optimizable table the Qualifier will qualify- Returns:
- int The variant type for the Qualifier's Orderable.
- Throws:
StandardException- thrown on error- See Also:
RelationalOperator.getOrderableVariantType(org.apache.derby.iapi.sql.compile.Optimizable)
-
compareWithKnownConstant
public boolean compareWithKnownConstant(Optimizable optTable, boolean considerParameters)
Description copied from interface:RelationalOperatorReturn whether this operator compares the given Optimizable with a constant whose value is known at compile time.- Specified by:
compareWithKnownConstantin interfaceRelationalOperator- See Also:
RelationalOperator.compareWithKnownConstant(org.apache.derby.iapi.sql.compile.Optimizable, boolean)
-
getCompareValue
public DataValueDescriptor getCompareValue(Optimizable optTable) throws StandardException
Description copied from interface:RelationalOperatorReturn an Object representing the known value that this relational operator is comparing to a column in the given Optimizable.- Specified by:
getCompareValuein interfaceRelationalOperator- Throws:
StandardException- Thrown on error- See Also:
RelationalOperator.getCompareValue(org.apache.derby.iapi.sql.compile.Optimizable)
-
booleanSelectivity
protected double booleanSelectivity(Optimizable optTable) throws StandardException
Return 50% if this is a comparison with a boolean column, a negative selectivity otherwise.- Throws:
StandardException
-
getReceiverInterfaceName
java.lang.String getReceiverInterfaceName()
The methods generated for this node all are on Orderable. Overrides this method in BooleanOperatorNode for code generation purposes.- Overrides:
getReceiverInterfaceNamein classBinaryOperatorNode
-
evaluateConstantExpressions
ValueNode evaluateConstantExpressions() throws StandardException
See if the node always evaluates to true or false, and return a Boolean constant node if it does.- Overrides:
evaluateConstantExpressionsin classValueNode- Returns:
- a node representing a Boolean constant if the result of the operator is known; otherwise, this operator node
- Throws:
StandardException- if an error occurs during evaluation- See Also:
ConstantExpressionVisitor
-
newBool
private ValueNode newBool(boolean b) throws StandardException
Create a Boolean constant node with a specified value.- Parameters:
b- the value of the constant- Returns:
- a node representing a Boolean constant
- Throws:
StandardException
-
getNegation
BinaryOperatorNode getNegation(ValueNode leftOperand, ValueNode rightOperand) throws StandardException
Returns the negation of this operator; negation of Equals is NotEquals.- Specified by:
getNegationin classBinaryComparisonOperatorNode- 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
-
getNegationNode
private int getNegationNode()
-
getSwappedEquivalent
BinaryOperatorNode getSwappedEquivalent() throws StandardException
Return an equivalent node with the operands swapped, and possibly with the operator type changed in order to preserve the meaning of the expression.- Specified by:
getSwappedEquivalentin classBinaryComparisonOperatorNode- Returns:
- an equivalent expression with the operands swapped
- Throws:
StandardException- if an error occurs
-
getKindForSwap
private int getKindForSwap()
Return the node type that must be used in order to construct an equivalent expression if the operands are swapped. For symmetric operators (=and<>), the same node type is returned. Otherwise, the direction of the operator is switched in order to preserve the meaning (for instance, a node representing less-than will return the node type for greater-than).- Returns:
- a node type that preserves the meaning of the expression if the operands are swapped
-
usefulStartKey
protected boolean usefulStartKey(boolean columnOnLeft)
is this is useful start key? for example a predicate of the from column Lessthan 5 is not a useful start key but is a useful stop key. However 5 Lessthan column is a useful start key.- Parameters:
columnOnLeft- is true if the column is the left hand side of the binary operator.
-
usefulStopKey
protected boolean usefulStopKey(boolean columnOnLeft)
-
getStartOperator
public int getStartOperator(Optimizable optTable)
Description copied from interface:RelationalOperatorGet the start operator for a scan (at the store level) for this RelationalOperator.- Specified by:
getStartOperatorin interfaceRelationalOperator- Parameters:
optTable- The optimizable table we're doing the scan on. This parameter is so we can tell which side of the operator the table's column is on.- Returns:
- Either ScanController.GT or ScanController.GE
- See Also:
RelationalOperator.getStartOperator(org.apache.derby.iapi.sql.compile.Optimizable)
-
getStopOperator
public int getStopOperator(Optimizable optTable)
Description copied from interface:RelationalOperatorGet the stop operator for a scan (at the store level) for this RelationalOperator.- Specified by:
getStopOperatorin interfaceRelationalOperator- Parameters:
optTable- The optimizable table we're doing the scan on. This parameter is so we can tell which side of the operator the table's column is on.- Returns:
- Either ScanController.GT or ScanController.GE
- See Also:
RelationalOperator.getStopOperator(org.apache.derby.iapi.sql.compile.Optimizable)
-
generateOperator
public void generateOperator(MethodBuilder mb, Optimizable optTable)
Description copied from interface:RelationalOperatorGenerate the comparison operator for this RelationalOperator. The operator can depend on which side of this operator the optimizable column is.- Specified by:
generateOperatorin interfaceRelationalOperator- Parameters:
mb- The method the generated code is to go intooptTable- The optimizable table we're doing the scan on.- See Also:
RelationalOperator.generateOperator(org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.sql.compile.Optimizable)
-
generateNegate
public void generateNegate(MethodBuilder mb, Optimizable optTable)
Description copied from interface:RelationalOperatorGenerate an expression that evaluates to true if the result of the comparison should be negated. For example, col > 1 generates a comparison operator of <= and a negation of true, while col < 1 generates a comparison operator of < and a negation of false.- Specified by:
generateNegatein interfaceRelationalOperator- Parameters:
mb- The method the generated code is to go intooptTable- The Optimizable table the Qualifier will qualify- See Also:
RelationalOperator.generateNegate(org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.sql.compile.Optimizable)
-
getOperator
public int getOperator()
Description copied from interface:RelationalOperatorReturn the operator (as an int) for this RelationalOperator.- Specified by:
getOperatorin interfaceRelationalOperator- Returns:
- int The operator for this RelationalOperator.
- See Also:
RelationalOperator.getOperator()
-
selectivity
public double selectivity(Optimizable optTable) throws StandardException
return the selectivity of this predicate.- Overrides:
selectivityin classValueNode- Throws:
StandardException
-
getTransitiveSearchClause
public RelationalOperator getTransitiveSearchClause(ColumnReference otherCR) throws StandardException
Description copied from interface:RelationalOperatorReturn a relational operator which matches the current one but with the passed in ColumnReference as the (left) operand.- Specified by:
getTransitiveSearchClausein interfaceRelationalOperator- Parameters:
otherCR- The ColumnReference for the new (left) operand.- Returns:
- A relational operator which matches the current one but with the passed in ColumnReference as the (left) operand.
- Throws:
StandardException- Thrown on error- See Also:
RelationalOperator.getTransitiveSearchClause(org.apache.derby.impl.sql.compile.ColumnReference)
-
equalsComparisonWithConstantExpression
public boolean equalsComparisonWithConstantExpression(Optimizable optTable)
Description copied from interface:RelationalOperatorReturn whether this operator is an equality comparison of the given optimizable with a constant expression.- Specified by:
equalsComparisonWithConstantExpressionin interfaceRelationalOperator
-
isRelationalOperator
boolean isRelationalOperator()
Description copied from class:ValueNodeReturns 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.- Overrides:
isRelationalOperatorin classValueNode- See Also:
ValueNode.isRelationalOperator()
-
isBinaryEqualsOperatorNode
boolean isBinaryEqualsOperatorNode()
Description copied from class:ValueNodeReturns true if this value node is a equals operator.- Overrides:
isBinaryEqualsOperatorNodein classValueNode- See Also:
ValueNode.isBinaryEqualsOperatorNode()
-
isInListProbeNode
boolean isInListProbeNode()
Description copied from class:ValueNodeReturns 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.- Overrides:
isInListProbeNodein classValueNode- See Also:
It's okay for this method to reference inListProbeSource directly because it does not rely on the contents of inListProbeSource's leftOperand, and a caller of this method cannot gain access to inListProbeSource's leftOperand through this method.
-
optimizableEqualityNode
boolean optimizableEqualityNode(Optimizable optTable, int columnNumber, boolean isNullOkay) throws StandardException
Description copied from class:ValueNodeReturn 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
- Overrides:
optimizableEqualityNodein classValueNode- 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- See Also:
ValueNode.optimizableEqualityNode(org.apache.derby.iapi.sql.compile.Optimizable, int, boolean)
-
implicitVarcharComparison
private boolean implicitVarcharComparison() throws StandardExceptionReturn whether or not this binary relational predicate requires an implicit (var)char conversion. This is important when considering hash join since this type of equality predicate is not currently supported for a hash join.- Returns:
- Whether or not an implicit (var)char conversion is required for this binary relational operator.
- Throws:
StandardException- Thrown on error
-
genSQLJavaSQLTree
ValueNode genSQLJavaSQLTree() throws StandardException
Description copied from class:BinaryOperatorNodegenerate 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:
genSQLJavaSQLTreein classBinaryComparisonOperatorNode- Returns:
- ValueNode The new tree.
- Throws:
StandardException- Thrown on error- See Also:
BinaryOperatorNode.genSQLJavaSQLTree()
-
getScopedOperand
ValueNode getScopedOperand(int whichSide, JBitSet parentRSNsTables, ResultSetNode childRSN, int[] whichRC) throws StandardException
Take a ResultSetNode and return a column reference that is scoped for for the received ResultSetNode, where "scoped" means that the column reference points to a specific column in the RSN. This is used for remapping predicates from an outer query down to a subquery. For example, assume we have the following query: select * from (select i,j from t1 union select i,j from t2) X1, (select a,b from t3 union select a,b from t4) X2 where X1.j = X2.b; Then assume that this BinaryRelationalOperatorNode represents the "X1.j = X2.b" predicate and that the childRSN we received as a parameter represents one of the subqueries to which we want to push the predicate; let's say it's: select i,j from t1 Then what we want to do in this method is map one of the operands X1.j or X2.b (depending on the 'whichSide' parameter) to the childRSN, if possible. Note that in our example, "X2.b" should _NOT_ be mapped because it doesn't apply to the childRSN for the subquery "select i,j from t1"; thus we should leave it as it is. "X1.j", however, _does_ need to be scoped, and so this method will return a ColumnReference pointing to "T1.j" (or whatever the corresponding column in T1 is). ASSUMPTION: We should only get to this method if we know that exactly one operand in the predicate to which this operator belongs can and should be mapped to the received childRSN.- Parameters:
whichSide- The operand are we trying to scope (LEFT or RIGHT)parentRSNsTables- Set of all table numbers referenced by the ResultSetNode that is _parent_ to the received childRSN. We need this to make sure we don't scope the operand to a ResultSetNode to which it doesn't apply.childRSN- The result set node to which we want to create a scoped predicate.whichRC- If not -1 then this tells us which ResultColumn in the received childRSN we need to use for the scoped predicate; if -1 then the column position of the scoped column reference will be stored in this array and passed back to the caller.- Returns:
- A column reference scoped to the received childRSN, if possible. If the operand is a ColumnReference that is not supposed to be scoped, we return a _clone_ of the reference--this is necessary because the reference is going to be pushed to two places (left and right children of the parentRSN) and if both children are referencing the same instance of the column reference, they'll interfere with each other during optimization.
- Throws:
StandardException
-
valNodeReferencesOptTable
private boolean valNodeReferencesOptTable(ValueNode valNode, Optimizable optTable, boolean forPush, boolean walkOptTableSubtree)
Determine whether or not the received ValueNode (which will usually be a ColumnReference) references either the received optTable or else a base table in the subtree beneath that optTable.- Parameters:
valNode- The ValueNode that has the reference(s).optTable- The table/subtree node to which we're trying to find a reference.forPush- Whether or not we are searching with the intent to push this operator to the target table.walkOptTableSubtree- Should we walk the subtree beneath optTable to find base tables, or not? Will be false if we've already done it for the left operand and now we're here for the right operand.- Returns:
- True if valNode contains a reference to optTable or to a base table in the subtree beneath optTable; false otherwise.
-
initBaseTableVisitor
private void initBaseTableVisitor(int numTablesInQuery, boolean initOptBaseTables)Initialize the fields used for retrieving base tables in subtrees, which allows us to do a more extensive search for table references. If the fields have already been created, then just reset their values.- Parameters:
numTablesInQuery- Used for creating JBitSets that can hold table numbers for the query.initOptBaseTables- Whether or not we should clear out or initialize the optBaseTables bit set.
-
buildTableNumList
private void buildTableNumList(Optimizable ft, boolean forPush) throws StandardException
Create a set of table numbers to search when trying to find which (if either) of this operator's operands reference the received target table. At the minimum this set should contain the target table's own table number. After that, if we're _not_ attempting to push this operator (or more specifically, the predicate to which this operator belongs) to the target table, we go on to search the subtree beneath the target table and add any base table numbers to the searchable list.- Parameters:
ft- Target table for which we're building the search list.forPush- Whether or not we are searching with the intent to push this operator to the target table.- Throws:
StandardException
-
isSameNodeKind
boolean isSameNodeKind(ValueNode o)
Description copied from class:ValueNodeSome node classes represent several logical node types (to reduce footprint), which we call kinds. This means that implementations ofValueNode.isEquivalent(org.apache.derby.impl.sql.compile.ValueNode)cannot always just useinstanceofto 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.- Overrides:
isSameNodeKindin classBinaryOperatorNode- Parameters:
o- The other value node whose kind we want to compare with.- Returns:
trueifthisandorepresent the same logical node type, i.e. kind.
-
-