Top Description Fields Constructors Methods
org.apache.derby.impl.sql.compile

pack-priv Class BinaryRelationalOperatorNode

extends BinaryComparisonOperatorNode
implements RelationalOperator
Class Inheritance
All Implemented Interfaces
org.apache.derby.impl.sql.compile.RelationalOperator
Imports
java.sql.Types, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.ClassName, org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.compile.ExpressionClassBuilderInterface, .Optimizable, org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor, org.apache.derby.iapi.store.access.ScanController, org.apache.derby.iapi.types.DataValueDescriptor, .Orderable, .TypeId, org.apache.derby.iapi.util.JBitSet

This class represents the 6 binary operators: LessThan, LessThanEquals, Equals, NotEquals, GreaterThan and GreaterThanEquals.

Field Summary

Modifier and TypeField and Description
private BaseTableNumbersVisitor
private InListOperatorNode
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv final int
kind

Hides org.apache.derby.impl.sql.compile.BinaryOperatorNode.kind.

This class is used to hold logically different objects for space efficiency.
protected static final int
protected static final int
pack-priv JBitSet
private int
protected static final int
pack-priv JBitSet

Constructor Summary

AccessConstructor and Description
pack-priv
BinaryRelationalOperatorNode(int
The kind of operator
kind
,
ValueNode
The left operand
leftOperand
,
ValueNode
The right operand
rightOperand
,
boolean
See method description
forQueryRewrite
,
ContextManager
The context manager
cm
)

Constructor.

pack-priv
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

Modifier and TypeMethod and Description
protected double
booleanSelectivity(Optimizable optTable)

Return 50% if this is a comparison with a boolean column, a negative selectivity otherwise.

private void
buildTableNumList(Optimizable
Target table for which we're building the search list.
ft
,
boolean
Whether or not we are searching with the intent to push this operator to the target table.
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 int

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.
columnOnOneSide
(Optimizable
The Optimizable table that we're looking for a key column on.
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?

public boolean
compareWithKnownConstant(Optimizable optTable, boolean considerParameters)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.compareWithKnownConstant.

Return whether this operator compares the given Optimizable with a constant whose value is known at compile time.

private void
public boolean
equalsComparisonWithConstantExpression(Optimizable optTable)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.equalsComparisonWithConstantExpression.

Return whether this operator is an equality comparison of the given optimizable with a constant expression.

pack-priv ValueNode

Returns:

a node representing a Boolean constant if the result of the operator is known; otherwise, this operator node
evaluateConstantExpressions
()

Overrides org.apache.derby.impl.sql.compile.ValueNode.evaluateConstantExpressions.

See if the node always evaluates to true or false, and return a Boolean constant node if it does.

public void
generateAbsoluteColumnId(MethodBuilder
The method the generated code is to go into
mb
,
Optimizable
The optimizable table we're doing the scan on.
optTable
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.generateAbsoluteColumnId.

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.

public void
generateExpressionOperand(Optimizable
An Optimizable for the base table the column is in
optTable
,
int
The ordinal position of the column (one-based)
columnPosition
,
ExpressionClassBuilderInterface
The ExpressionClassBuilder for the class we're building
acbi
,
MethodBuilder
The method the expression will go into
mb
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.generateExpressionOperand.

Check whether this RelationalOperator is a comparison of the given column with an expression.

public void
generateNegate(MethodBuilder
The method the generated code is to go into
mb
,
Optimizable
The Optimizable table the Qualifier will qualify
optTable
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.generateNegate.

Generate an expression that evaluates to true if the result of the comparison should be negated.

public void
generateOperator(MethodBuilder
The method the generated code is to go into
mb
,
Optimizable
The optimizable table we're doing the scan on.
optTable
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.generateOperator.

Generate the comparison operator for this RelationalOperator.

public void
generateOrderedNulls(MethodBuilder
The method the generated code is to go into
mb
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.generateOrderedNulls.

Generate an expression that evaluates to true if this RelationalOperator uses ordered null semantics, false if it doesn't.

public void
generateQualMethod(ExpressionClassBuilderInterface
The ExpressionClassBuilder for the class we're building
acbi
,
MethodBuilder
The method the generated code is to go into
mb
,
Optimizable
The Optimizable table the Qualifier will qualify
optTable
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.generateQualMethod.

Generate the method to evaluate a Qualifier.

public void
generateRelativeColumnId(MethodBuilder
The method the generated code is to go into
mb
,
Optimizable
The optimizable table we're doing the scan on.
optTable
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.generateRelativeColumnId.

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.

pack-priv ValueNode
genSQLJavaSQLTree()

Overrides org.apache.derby.impl.sql.compile.BinaryComparisonOperatorNode.genSQLJavaSQLTree.

generate a SQL->Java->SQL conversion tree above the left and right operand of this Binary Operator Node if needed.

private int

Returns:

The absolute 0-based column position of the ColumnReference
getAbsoluteColumnPosition
(Optimizable
The Optimizable
optTable
)

Get the absolute 0-based column position of the ColumnReference from the conglomerate for this Optimizable.

public ColumnReference
getColumnOperand(Optimizable
An Optimizable for the base table the column is in
optTable
,
int
The ordinal position of the column (one-based)
columnPosition
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.getColumnOperand.

Check whether this RelationalOperator is a comparison of the given column with an expression.

public ColumnReference
getColumnOperand(Optimizable optTable)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.getColumnOperand.

Get the ColumnReference for the given table on one side of this RelationalOperator.

public DataValueDescriptor
getCompareValue(Optimizable optTable)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.getCompareValue.

Return an Object representing the known value that this relational operator is comparing to a column in the given Optimizable.

public ValueNode
getExpressionOperand(int
The table number of the base table the column is in
tableNumber
,
int
The ordinal position of the column (one-based)
columnPosition
,
Optimizable
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.
ft
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.getExpressionOperand.

Check whether this RelationalOperator is a comparison of the given column with an expression.

protected InListOperatorNode
getInListOp()

If this rel op was created for an IN-list probe predicate then return the underlying InListOperatorNode.

private int

Returns:

a node type that preserves the meaning of the expression if the operands are swapped
getKindForSwap
()

Return the node type that must be used in order to construct an equivalent expression if the operands are swapped.

private static String
getMethodName(int kind)

pack-priv BinaryOperatorNode
getNegation(ValueNode
The left operand of the comparison operator
leftOperand
,
ValueNode
The right operand of the comparison operator
rightOperand
)

Implements abstract org.apache.derby.impl.sql.compile.BinaryComparisonOperatorNode.getNegation.

Returns the negation of this operator; negation of Equals is NotEquals.

private int
public ValueNode
getOperand(ColumnReference
The ColumnReference for which we're searching.
cRef
,
int
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.
refSetSize
,
boolean
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.
otherSide
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.getOperand.

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.

public int
getOperator()

Implements org.apache.derby.impl.sql.compile.RelationalOperator.getOperator.

Return the operator (as an int) for this RelationalOperator.

private static String
getOperatorName(int kind)

public int
getOrderableVariantType(Optimizable
The Optimizable table the Qualifier will qualify
optTable
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.getOrderableVariantType.

Return the variant type for the Qualifier's Orderable.

pack-priv String
getReceiverInterfaceName()

Overrides org.apache.derby.impl.sql.compile.BinaryOperatorNode.getReceiverInterfaceName.

The methods generated for this node all are on Orderable.

private int
getRelOpType(int op)

pack-priv ValueNode

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.
getScopedOperand
(int
The operand are we trying to scope (LEFT or RIGHT)
whichSide
,
JBitSet
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.
parentRSNsTables
,
ResultSetNode
The result set node to which we want to create a scoped predicate.
childRSN
,
int[]
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.
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.

public int
getStartOperator(Optimizable
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.
optTable
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.getStartOperator.

Get the start operator for a scan (at the store level) for this RelationalOperator.

public int
getStopOperator(Optimizable
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.
optTable
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.getStopOperator.

Get the stop operator for a scan (at the store level) for this RelationalOperator.

pack-priv BinaryOperatorNode
getSwappedEquivalent()

Implements abstract org.apache.derby.impl.sql.compile.BinaryComparisonOperatorNode.getSwappedEquivalent.

Return an equivalent node with the operands swapped, and possibly with the operator type changed in order to preserve the meaning of the expression.

public RelationalOperator
getTransitiveSearchClause(ColumnReference
The ColumnReference for the new (left) operand.
otherCR
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.getTransitiveSearchClause.

Return a relational operator which matches the current one but with the passed in ColumnReference as the (left) operand.

private boolean

Returns:

Whether or not an implicit (var)char conversion is required for this binary relational operator.
implicitVarcharComparison
()

Return whether or not this binary relational predicate requires an implicit (var)char conversion.

private void
initBaseTableVisitor(int
Used for creating JBitSets that can hold table numbers for the query.
numTablesInQuery
,
boolean
Whether or not we should clear out or initialize the optBaseTables bit set.
initOptBaseTables
)

Initialize the fields used for retrieving base tables in subtrees, which allows us to do a more extensive search for table references.

pack-priv boolean
isBinaryEqualsOperatorNode()

Overrides org.apache.derby.impl.sql.compile.ValueNode.isBinaryEqualsOperatorNode.

Returns true if this value node is a equals operator.

pack-priv boolean
isInListProbeNode()

Overrides org.apache.derby.impl.sql.compile.ValueNode.isInListProbeNode.

Returns true if this value node is an operator created for optimized performance of an IN list.

public boolean
isQualifier(Optimizable
The Optimizable table in question.
optTable
,
boolean
Are we asking because we're trying to push?
forPush
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.isQualifier.

Return true if this operator can be compiled into a Qualifier for the given Optimizable table.

pack-priv boolean
isRelationalOperator()

Overrides org.apache.derby.impl.sql.compile.ValueNode.isRelationalOperator.

Returns true if this ValueNode is a relational operator.

pack-priv boolean
isSameNodeKind(ValueNode
The other value node whose kind we want to compare with.
o
)

Overrides org.apache.derby.impl.sql.compile.BinaryOperatorNode.isSameNodeKind.

Some node classes represent several logical node types (to reduce footprint), which we call kinds.

protected boolean

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.
keyColumnOnLeft
(Optimizable
The Optimizable table that we're looking for a key column on.
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 ValueNode

Returns:

a node representing a Boolean constant
newBool
(boolean
the value of the constant
b
)

Create a Boolean constant node with a specified value.

pack-priv boolean
optimizableEqualityNode(Optimizable
the table being optimized. Column reference must be from this table.
optTable
,
int
the column number. One of the operands of this predicate must be the column number specified by optTable/columnNumber
columnNumber
,
boolean
if set to true we also consider IS NULL predicates; otherwise consider only = predicates.
isNullOkay
)

Overrides org.apache.derby.impl.sql.compile.ValueNode.optimizableEqualityNode.

Return true if the predicate represents an optimizable equality node.

public boolean
orderedNulls()

Implements org.apache.derby.impl.sql.compile.RelationalOperator.orderedNulls.

Return true if this operator uses ordered null semantics

public double
selectivity(Optimizable optTable)

Overrides org.apache.derby.impl.sql.compile.ValueNode.selectivity.

return the selectivity of this predicate.

public boolean
selfComparison(ColumnReference
The ColumnReference that is being compared to some expression.
cr
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.selfComparison.

Check whether this RelationalOperator compares the given ColumnReference to any columns in the same table as the ColumnReference.

public boolean
usefulStartKey(Optimizable
The Optimizable table for which we want to know whether this is a useful start key.
optTable
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.usefulStartKey.

Tell whether this relop is a useful start key for the given table.

protected boolean
usefulStartKey(boolean
is true if the column is the left hand side of the binary operator.
columnOnLeft
)

is this is useful start key?

public boolean
usefulStopKey(Optimizable
The Optimizable table for which we want to know whether this is a useful stop key.
optTable
)

Implements org.apache.derby.impl.sql.compile.RelationalOperator.usefulStopKey.

Tell whether this relop is a useful stop key for the given table.

protected boolean
usefulStopKey(boolean columnOnLeft)

private boolean

Returns:

True if valNode contains a reference to optTable or to a base table in the subtree beneath optTable; false otherwise.
valNodeReferencesOptTable
(ValueNode
The ValueNode that has the reference(s).
valNode
,
Optimizable
The table/subtree node to which we're trying to find a reference.
optTable
,
boolean
Whether or not we are searching with the intent to push this operator to the target table.
forPush
,
boolean
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.
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.

Inherited from org.apache.derby.impl.sql.compile.BinaryComparisonOperatorNode:
bindComparisonOperatorbindExpressionchangeToCNFeliminateNotsgetBetweenSelectivitygetForQueryRewritepreprocesssetBetweenSelectivitysetForQueryRewrite