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

pack-priv Interface RelationalOperator

Known Direct Implementers
org.apache.derby.impl.sql.compile.BinaryRelationalOperatorNode, org.apache.derby.impl.sql.compile.IsNullNode
Imports
org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.sql.compile.ExpressionClassBuilderInterface, .Optimizable, org.apache.derby.iapi.store.access.TransactionController, org.apache.derby.iapi.types.DataValueDescriptor

This interface is an abstraction of a relational operator. It was created for optimization, to allow binary comparison operators and IS NULL to be treated the same.

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int

Method Summary

Modifier and TypeMethod and Description
public boolean
compareWithKnownConstant(Optimizable optTable, boolean considerParameters)

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

public boolean
equalsComparisonWithConstantExpression(Optimizable optTable)

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

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
)

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
acb
,
MethodBuilder
The method the expression will go into
mb
)

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
)

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
)

Generate the comparison operator for this RelationalOperator.

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

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
acb
,
MethodBuilder
The method the generated code is to go into
mb
,
Optimizable
The Optimizable table the Qualifier will qualify
optTable
)

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
)

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.

public ColumnReference

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.
getColumnOperand
(Optimizable
An Optimizable for the base table the column is in
optTable
,
int
The ordinal position of the column (one-based)
columnPosition
)

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

public ColumnReference
getColumnOperand(Optimizable optTable)

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

public DataValueDescriptor
getCompareValue(Optimizable optTable)

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

public ValueNode

Returns:

The ValueNode for the expression the column is being compared to - null if the column is not being compared to anything.
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
)

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

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
)

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

Returns:

int The operator for this RelationalOperator.
getOperator
()

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

public int

Returns:

int The variant type for the Qualifier's Orderable.
getOrderableVariantType
(Optimizable
The Optimizable table the Qualifier will qualify
optTable
)

Return the variant type for the Qualifier's Orderable.

public int

Returns:

Either ScanController.GT or ScanController.GE
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
)

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

public int

Returns:

Either ScanController.GT or ScanController.GE
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
)

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

public RelationalOperator

Returns:

A relational operator which matches the current one but with the passed in ColumnReference as the (left) operand.
getTransitiveSearchClause
(ColumnReference
The ColumnReference for the new (left) operand.
otherCR
)

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

public boolean

Returns:

true if this operator can be compiled into a Qualifier for the given Optimizable table.
isQualifier
(Optimizable
The Optimizable table in question.
optTable
,
boolean
Are we asking because we're trying to push?
forPush
)

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

public boolean
orderedNulls()

Return true if this operator uses ordered null semantics

public boolean

Returns:

true if the given ColumnReference is being compared to any columns from the same table
selfComparison
(ColumnReference
The ColumnReference that is being compared to some expression.
cr
)

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

public boolean

Returns:

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

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

public boolean

Returns:

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

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

Field Detail

EQUALS_RELOPback to summary
public static final int EQUALS_RELOP
GREATER_EQUALS_RELOPback to summary
public static final int GREATER_EQUALS_RELOP
GREATER_THAN_RELOPback to summary
public static final int GREATER_THAN_RELOP
IS_NOT_NULL_RELOPback to summary
public static final int IS_NOT_NULL_RELOP
IS_NULL_RELOPback to summary
public static final int IS_NULL_RELOP
LESS_EQUALS_RELOPback to summary
public static final int LESS_EQUALS_RELOP
LESS_THAN_RELOPback to summary
public static final int LESS_THAN_RELOP
NOT_EQUALS_RELOPback to summary
public static final int NOT_EQUALS_RELOP

Method Detail

compareWithKnownConstantback to summary
public boolean compareWithKnownConstant(Optimizable optTable, boolean considerParameters)

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

equalsComparisonWithConstantExpressionback to summary
public boolean equalsComparisonWithConstantExpression(Optimizable optTable)

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

generateAbsoluteColumnIdback to summary
public void generateAbsoluteColumnId(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. (Absolute column id means column id within the row stored on disk.)

Parameters
mb:MethodBuilder

The method the generated code is to go into

optTable:Optimizable

The optimizable table we're doing the scan on.

generateExpressionOperandback to summary
public void generateExpressionOperand(Optimizable optTable, int columnPosition, ExpressionClassBuilderInterface acb, MethodBuilder mb) throws StandardException

Check 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.

Parameters
optTable:Optimizable

An Optimizable for the base table the column is in

columnPosition:int

The ordinal position of the column (one-based)

acb:ExpressionClassBuilderInterface

The ExpressionClassBuilder for the class we're building

mb:MethodBuilder

The method the expression will go into

Exceptions
StandardException:
Thrown on error
generateNegateback to summary
public void generateNegate(MethodBuilder mb, Optimizable optTable)

Generate 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.

Parameters
mb:MethodBuilder

The method the generated code is to go into

optTable:Optimizable

The Optimizable table the Qualifier will qualify

generateOperatorback to summary
public void generateOperator(MethodBuilder mb, Optimizable optTable)

Generate the comparison operator for this RelationalOperator. The operator can depend on which side of this operator the optimizable column is.

Parameters
mb:MethodBuilder

The method the generated code is to go into

optTable:Optimizable

The optimizable table we're doing the scan on.

generateOrderedNullsback to summary
public void generateOrderedNulls(MethodBuilder mb)

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

Parameters
mb:MethodBuilder

The method the generated code is to go into

generateQualMethodback to summary
public void generateQualMethod(ExpressionClassBuilderInterface acb, MethodBuilder mb, Optimizable optTable) throws StandardException

Generate the method to evaluate a Qualifier. The factory method for a Qualifier takes a GeneratedMethod that returns the Orderable that Qualifier.getOrderable() returns.

Parameters
acb:ExpressionClassBuilderInterface

The ExpressionClassBuilder for the class we're building

mb:MethodBuilder

The method the generated code is to go into

optTable:Optimizable

The Optimizable table the Qualifier will qualify

Exceptions
StandardException:
Thrown on error.
generateRelativeColumnIdback to summary
public void generateRelativeColumnId(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. (Relative column id means column id within the partial row returned by the store.)

Parameters
mb:MethodBuilder

The method the generated code is to go into

optTable:Optimizable

The optimizable table we're doing the scan on.

getColumnOperandback to summary
public ColumnReference getColumnOperand(Optimizable optTable, int columnPosition)

Check 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.

Parameters
optTable:Optimizable

An Optimizable for the base table the column is in

columnPosition:int

The ordinal position of the column (one-based)

Returns:ColumnReference

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.

getColumnOperandback to summary
public ColumnReference getColumnOperand(Optimizable optTable)

Get 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.

getCompareValueback to summary
public DataValueDescriptor getCompareValue(Optimizable optTable) throws StandardException

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

Exceptions
StandardException:
Thrown on error
getExpressionOperandback to summary
public ValueNode getExpressionOperand(int tableNumber, int columnPosition, Optimizable ft)

Check whether this RelationalOperator is a comparison of the given column with an expression. If so, return the expression the column is being compared to.

Parameters
tableNumber:int

The table number of the base table the column is in

columnPosition:int

The ordinal position of the column (one-based)

ft: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.

Returns:ValueNode

The ValueNode for the expression the column is being compared to - null if the column is not being compared to anything.

getOperandback to summary
public ValueNode getOperand(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. This presumes it will be found only on one side. If not found, it will return null.

Parameters
cRef:ColumnReference

The ColumnReference for which we're searching.

refSetSize: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.

otherSide: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.

getOperatorback to summary
public int getOperator()

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

Returns:int

int The operator for this RelationalOperator.

getOrderableVariantTypeback to summary
public int getOrderableVariantType(Optimizable optTable) throws StandardException

Return the variant type for the Qualifier's Orderable. (Is the Orderable invariant within a scan or within a query?)

Parameters
optTable:Optimizable

The Optimizable table the Qualifier will qualify

Returns:int

int The variant type for the Qualifier's Orderable.

Exceptions
StandardException:
thrown on error
getStartOperatorback to summary
public int getStartOperator(Optimizable optTable)

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

Parameters
optTable: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.

Returns:int

Either ScanController.GT or ScanController.GE

See Also
TransactionController#openScan
getStopOperatorback to summary
public int getStopOperator(Optimizable optTable)

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

Parameters
optTable: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.

Returns:int

Either ScanController.GT or ScanController.GE

See Also
TransactionController#openScan
getTransitiveSearchClauseback to summary
public RelationalOperator getTransitiveSearchClause(ColumnReference otherCR) throws StandardException

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

Parameters
otherCR:ColumnReference

The ColumnReference for the new (left) operand.

Returns:RelationalOperator

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

Exceptions
StandardException:
Thrown on error
isQualifierback to summary
public boolean isQualifier(Optimizable optTable, boolean forPush) throws StandardException

Return 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.

Parameters
optTable:Optimizable

The Optimizable table in question.

forPush:boolean

Are we asking because we're trying to push?

Returns:boolean

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

Exceptions
StandardException:
Thrown on error
orderedNullsback to summary
public boolean orderedNulls()

Return true if this operator uses ordered null semantics

selfComparisonback to summary
public boolean selfComparison(ColumnReference cr) throws StandardException

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

Parameters
cr:ColumnReference

The ColumnReference that is being compared to some expression.

Returns:boolean

true if the given ColumnReference is being compared to any columns from the same table

Exceptions
StandardException:
Thrown on error
usefulStartKeyback to summary
public boolean usefulStartKey(Optimizable optTable)

Tell 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.

Parameters
optTable:Optimizable

The Optimizable table for which we want to know whether this is a useful start key.

Returns:boolean

true if this is a useful start key

usefulStopKeyback to summary
public boolean usefulStopKey(Optimizable optTable)

Tell 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.

Parameters
optTable:Optimizable

The Optimizable table for which we want to know whether this is a useful stop key.

Returns:boolean

true if this is a useful stop key