org.apache.derby.impl.sql.compile
Interface RelationalOperator

All Known Implementing Classes:
BinaryRelationalOperatorNode, IsNullNode

public interface RelationalOperator

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
static int EQUALS_RELOP
           
static int GREATER_EQUALS_RELOP
           
static int GREATER_THAN_RELOP
           
static int IS_NOT_NULL_RELOP
           
static int IS_NULL_RELOP
           
static int LESS_EQUALS_RELOP
           
static int LESS_THAN_RELOP
           
static int NOT_EQUALS_RELOP
           
 
Method Summary
 boolean compareWithKnownConstant(Optimizable optTable, boolean considerParameters)
          Return whether this operator compares the given Optimizable with a constant whose value is known at compile time.
 boolean equalsComparisonWithConstantExpression(Optimizable optTable)
          Return whether this operator is an equality comparison of the given optimizable with a constant expression.
 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.
 void generateExpressionOperand(Optimizable optTable, int columnPosition, ExpressionClassBuilder acb, MethodBuilder mb)
          Check whether this RelationalOperator is a comparison of the given column with an expression.
 void generateNegate(MethodBuilder mb, Optimizable optTable)
          Generate an expression that evaluates to true if the result of the comparison should be negated.
 void generateOperator(MethodBuilder mb, Optimizable optTable)
          Generate the comparison operator for this RelationalOperator.
 void generateOrderedNulls(MethodBuilder mb)
          Generate an expression that evaluates to true if this RelationalOperator uses ordered null semantics, false if it doesn't.
 void generateQualMethod(ExpressionClassBuilder acb, MethodBuilder mb, Optimizable optTable)
          Generate the method to evaluate a Qualifier.
 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.
 ColumnReference getColumnOperand(int tableNumber, int columnPosition)
          Check whether this RelationalOperator is a comparison of the given column with an expression.
 ColumnReference getColumnOperand(Optimizable optTable)
          Get the ColumnReference for the given table on one side of this RelationalOperator.
 ColumnReference getColumnOperand(Optimizable optTable, int columnPosition)
          Check whether this RelationalOperator is a comparison of the given column with an expression.
 DataValueDescriptor getCompareValue(Optimizable optTable)
          Return an Object representing the known value that this relational operator is comparing to a column in the given Optimizable.
 ValueNode getExpressionOperand(int tableNumber, int columnPosition)
          Check whether this RelationalOperator is a comparison of the given column with an expression.
 int getOperator()
          Return the operator (as an int) for this RelationalOperator.
 int getOrderableVariantType(Optimizable optTable)
          Return the variant type for the Qualifier's Orderable.
 int getStartOperator(Optimizable optTable)
          Get the start operator for a scan (at the store level) for this RelationalOperator.
 int getStopOperator(Optimizable optTable)
          Get the stop operator for a scan (at the store level) for this RelationalOperator.
 RelationalOperator getTransitiveSearchClause(ColumnReference otherCR)
          Return a relational operator which matches the current one but with the passed in ColumnReference as the (left) operand.
 boolean isQualifier(Optimizable optTable)
          Return true if this operator can be compiled into a Qualifier for the given Optimizable table.
 boolean orderedNulls()
          Return true if this operator uses ordered null semantics
 boolean selfComparison(ColumnReference cr)
          Check whether this RelationalOperator compares the given ColumnReference to any columns in the same table as the ColumnReference.
 boolean usefulStartKey(Optimizable optTable)
          Tell whether this relop is a useful start key for the given table.
 boolean usefulStopKey(Optimizable optTable)
          Tell whether this relop is a useful stop key for the given table.
 

Field Detail

EQUALS_RELOP

public static final int EQUALS_RELOP
See Also:
Constant Field Values

NOT_EQUALS_RELOP

public static final int NOT_EQUALS_RELOP
See Also:
Constant Field Values

GREATER_THAN_RELOP

public static final int GREATER_THAN_RELOP
See Also:
Constant Field Values

GREATER_EQUALS_RELOP

public static final int GREATER_EQUALS_RELOP
See Also:
Constant Field Values

LESS_THAN_RELOP

public static final int LESS_THAN_RELOP
See Also:
Constant Field Values

LESS_EQUALS_RELOP

public static final int LESS_EQUALS_RELOP
See Also:
Constant Field Values

IS_NULL_RELOP

public static final int IS_NULL_RELOP
See Also:
Constant Field Values

IS_NOT_NULL_RELOP

public static final int IS_NOT_NULL_RELOP
See Also:
Constant Field Values
Method Detail

getColumnOperand

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 - An Optimizable for the base table the column is in
columnPosition - 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.

getColumnOperand

public ColumnReference getColumnOperand(int tableNumber,
                                        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:
tableNumber - The table number of the table in question
columnPosition - 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.

getColumnOperand

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.


getExpressionOperand

public ValueNode getExpressionOperand(int tableNumber,
                                      int columnPosition)
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 - The table number of the base table the column is in
columnPosition - The ordinal position of the column (one-based)
Returns:
The ValueNode for the expression the column is being compared to - null if the column is not being compared to anything.

generateExpressionOperand

public void generateExpressionOperand(Optimizable optTable,
                                      int columnPosition,
                                      ExpressionClassBuilder 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 - An Optimizable for the base table the column is in
columnPosition - The ordinal position of the column (one-based)
acb - The ExpressionClassBuilder for the class we're building
mb - The method the expression will go into
Throws:
StandardException - Thrown on error

selfComparison

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

usefulStartKey

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

usefulStopKey

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

getStartOperator

public int getStartOperator(Optimizable optTable)
Get the start operator for a scan (at the store level) for this RelationalOperator.

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:
TransactionController.openScan(long, boolean, int, int, int, org.apache.derby.iapi.services.io.FormatableBitSet, org.apache.derby.iapi.types.DataValueDescriptor[], int, org.apache.derby.iapi.store.access.Qualifier[][], org.apache.derby.iapi.types.DataValueDescriptor[], int)

getStopOperator

public int getStopOperator(Optimizable optTable)
Get the stop operator for a scan (at the store level) for this RelationalOperator.

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:
TransactionController.openScan(long, boolean, int, int, int, org.apache.derby.iapi.services.io.FormatableBitSet, org.apache.derby.iapi.types.DataValueDescriptor[], int, org.apache.derby.iapi.store.access.Qualifier[][], org.apache.derby.iapi.types.DataValueDescriptor[], int)

generateAbsoluteColumnId

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 - The method the generated code is to go into
optTable - The optimizable table we're doing the scan on.

generateRelativeColumnId

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 - The method the generated code is to go into
optTable - The optimizable table we're doing the scan on.

generateOperator

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 - The method the generated code is to go into
optTable - The optimizable table we're doing the scan on.

generateQualMethod

public void generateQualMethod(ExpressionClassBuilder 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 - The ExpressionClassBuilder for the class we're building
mb - The method the generated code is to go into
optTable - The Optimizable table the Qualifier will qualify
Returns:
An expression that evaluates to the GeneratedMethod that returns the Orderable to be returned by Qualifier.getOrderable()
Throws:
StandardException - Thrown on error.

generateOrderedNulls

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 - The method the generated code is to go into

generateNegate

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

orderedNulls

public boolean orderedNulls()
Return true if this operator uses ordered null semantics


isQualifier

public boolean isQualifier(Optimizable optTable)
                    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.

Parameters:
optTable - The Optimizable table in question.
Returns:
true if this operator can be compiled into a Qualifier for the given Optimizable table.
Throws:
StandardException - Thrown on error

getOperator

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

Returns:
int The operator for this RelationalOperator.

getOrderableVariantType

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 - The Optimizable table the Qualifier will qualify
Returns:
int The variant type for the Qualifier's Orderable.
Throws:
StandardException - thrown on error

compareWithKnownConstant

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.


getCompareValue

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.

Throws:
StandardException - Thrown on error

equalsComparisonWithConstantExpression

public boolean equalsComparisonWithConstantExpression(Optimizable optTable)
Return whether this operator is an equality comparison of the given optimizable with a constant expression.


getTransitiveSearchClause

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

Built on Mon 2007-06-04 09:58:47+0400, from revision ???

Apache Derby V10.1 Engine Documentation - Copyright © 1997,2005 The Apache Software Foundation or its licensors, as applicable.