Class RowOrderingImpl
- java.lang.Object
-
- org.apache.derby.impl.sql.compile.RowOrderingImpl
-
- All Implemented Interfaces:
RowOrdering
class RowOrderingImpl extends java.lang.Object implements RowOrdering
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList<Optimizable>
alwaysOrderedOptimizables
List of table numbers for tables that are always ordered.(package private) ColumnOrdering
columnsAlwaysOrdered
(package private) ColumnOrdering
currentColumnOrdering
private java.util.ArrayList<ColumnOrdering>
ordering
List of ColumnOrderings.private java.util.ArrayList<Optimizable>
unorderedOptimizables
List of unordered Optimizables.-
Fields inherited from interface org.apache.derby.iapi.sql.compile.RowOrdering
ASCENDING, DESCENDING, DONTCARE
-
-
Constructor Summary
Constructors Constructor Description RowOrderingImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addOrderedColumn(int direction, int tableNumber, int columnNumber)
Add a column to this RowOrdering in the current order position.void
addUnorderedOptimizable(Optimizable optimizable)
Add an unordered optimizable to this RowOrdering.boolean
alwaysOrdered(int tableNumber)
Ask whether the given table is always ordered.void
columnAlwaysOrdered(Optimizable optimizable, int columnNumber)
Tell this RowOrdering that it is always ordered on the given column of the given optimizable.void
copy(RowOrdering copyTo)
Copy the contents of this RowOrdering to the given RowOrdering.boolean
isColumnAlwaysOrdered(int tableNumber, int columnNumber)
Return true if the column is always ordered.void
nextOrderPosition(int direction)
Move to the next order position for adding ordered columns.void
optimizableAlwaysOrdered(Optimizable optimizable)
Tell this RowOrdering that it is always ordered on the given optimizable This is useful when considering a unique index where there is an equality match on the entire key - in this case, all the columns are ordered, regardless of the direction or position, or even whether the columns are in the index.boolean
orderedOnColumn(int direction, int tableNumber, int columnNumber)
Tell whether this ordering is ordered on the given column.boolean
orderedOnColumn(int direction, int orderPosition, int tableNumber, int columnNumber)
Tell whether this ordering is ordered on the given column in the given positionprivate void
rememberCurrentColumnOrdering(int posn)
void
removeOptimizable(int tableNumber)
Tell this row ordering that it is no longer ordered on the given table.private void
removeOptimizable(int tableNumber, java.util.ArrayList<Optimizable> list)
Remove all optimizables with the given table number from the given list of optimizables.java.lang.String
toString()
private boolean
unorderedOptimizablesOtherThan(Optimizable optimizable)
Returns true if there are unordered optimizables in the join order other than the given one.
-
-
-
Field Detail
-
ordering
private final java.util.ArrayList<ColumnOrdering> ordering
List of ColumnOrderings.
-
columnsAlwaysOrdered
ColumnOrdering columnsAlwaysOrdered
-
alwaysOrderedOptimizables
private final java.util.ArrayList<Optimizable> alwaysOrderedOptimizables
List of table numbers for tables that are always ordered. This happens for one-row tables.
-
currentColumnOrdering
ColumnOrdering currentColumnOrdering
-
unorderedOptimizables
private final java.util.ArrayList<Optimizable> unorderedOptimizables
List of unordered Optimizables.
-
-
Method Detail
-
isColumnAlwaysOrdered
public boolean isColumnAlwaysOrdered(int tableNumber, int columnNumber)
Description copied from interface:RowOrdering
Return true if the column is always ordered. That will be true if the column has a constant comparison predicate on it or it is involved in a equijoin with an optimizable which is always ordered on the column on which the equijoin is happening.- Specified by:
isColumnAlwaysOrdered
in interfaceRowOrdering
- Parameters:
tableNumber
- The table in questioncolumnNumber
- The number of the column in question.- Returns:
- true means this column is always ordered
- See Also:
RowOrdering.isColumnAlwaysOrdered(int, int)
-
orderedOnColumn
public boolean orderedOnColumn(int direction, int orderPosition, int tableNumber, int columnNumber) throws StandardException
Description copied from interface:RowOrdering
Tell whether this ordering is ordered on the given column in the given position- Specified by:
orderedOnColumn
in interfaceRowOrdering
- Parameters:
direction
- One of ASCENDING, DESCENDING, or DONTCARE depending on the requirements of the caller. An ORDER BY clause cares about direction, while DISTINCT and GROUP BY do not.orderPosition
- The position in the ordering list. For example, for ORDER BY A, B, position 0 has column A, and position 1 has column B. Note that for an ordering, more than one column can be in a single ordering position: for example, in the query SELECT * FROM S, T WHERE S.A = T.B ORDER BY T.B columns S.A and T.B will be in the same ordering positions because they are equal. Also, constant values are considered ordered in all positions (consider SELECT A FROM T WHERE A = 1 ORDER BY A).tableNumber
- The table number of the Optimizable containing the column in questioncolumnNumber
- The column number in the table (one-based).- Returns:
- true means this ordering is ordered on the given column in the given position.
- Throws:
StandardException
- Thrown on error- See Also:
RowOrdering.orderedOnColumn(int, int, int, int)
-
orderedOnColumn
public boolean orderedOnColumn(int direction, int tableNumber, int columnNumber) throws StandardException
Description copied from interface:RowOrdering
Tell whether this ordering is ordered on the given column. This is similar to the method above, but it checks whether the column is ordered in any position, rather than a specified position. This is useful for operations like DISTINCT and GROUP BY.- Specified by:
orderedOnColumn
in interfaceRowOrdering
- Parameters:
direction
- One of ASCENDING, DESCENDING, or DONTCARE depending on the requirements of the caller. An ORDER BY clause cares about direction, while DISTINCT and GROUP BY do not.tableNumber
- The table number of the Optimizable containing the column in questioncolumnNumber
- The column number in the table (one-based).- Returns:
- true means this ordering is ordered on the given column in the given position.
- Throws:
StandardException
- Thrown on error- See Also:
RowOrdering.orderedOnColumn(int, int, int, int)
-
addOrderedColumn
public void addOrderedColumn(int direction, int tableNumber, int columnNumber)
Description copied from interface:RowOrdering
Add a column to this RowOrdering in the current order position. This is a no-op if there are any unordered optimizables in the join order (see below).- Specified by:
addOrderedColumn
in interfaceRowOrdering
- Parameters:
direction
- One of ASCENDING, DESCENDING, or DONTCARE. DONTCARE can be used for things like columns with constant value, and for one-row tables.tableNumber
- The table the column is in.columnNumber
- The column number in the table (one-based)- See Also:
RowOrdering.addOrderedColumn(int, int, int)
-
nextOrderPosition
public void nextOrderPosition(int direction)
Description copied from interface:RowOrdering
Move to the next order position for adding ordered columns. This is a no-op if there are any unordered optimizables in the join order (see below).- Specified by:
nextOrderPosition
in interfaceRowOrdering
- Parameters:
direction
- One of ASCENDING, DESCENDING, or DONTCARE. DONTCARE can be used for things like columns with constant value, and for one-row tables.- See Also:
RowOrdering.nextOrderPosition(int)
-
optimizableAlwaysOrdered
public void optimizableAlwaysOrdered(Optimizable optimizable)
Description copied from interface:RowOrdering
Tell this RowOrdering that it is always ordered on the given optimizable This is useful when considering a unique index where there is an equality match on the entire key - in this case, all the columns are ordered, regardless of the direction or position, or even whether the columns are in the index.- Specified by:
optimizableAlwaysOrdered
in interfaceRowOrdering
- Parameters:
optimizable
- The table in question
-
columnAlwaysOrdered
public void columnAlwaysOrdered(Optimizable optimizable, int columnNumber)
Description copied from interface:RowOrdering
Tell this RowOrdering that it is always ordered on the given column of the given optimizable. This is useful when a column in the optimizable has an equals comparison with a constant expression or it is involved in a equijoin with an optimizable which is always ordered on the column on which the equijoin is happening. This is reset when the optimizable is removed from this RowOrdering.- Specified by:
columnAlwaysOrdered
in interfaceRowOrdering
- Parameters:
optimizable
- The table in questioncolumnNumber
- The number of the column in question.- See Also:
RowOrdering.columnAlwaysOrdered(org.apache.derby.iapi.sql.compile.Optimizable, int)
-
alwaysOrdered
public boolean alwaysOrdered(int tableNumber)
Description copied from interface:RowOrdering
Ask whether the given table is always ordered.- Specified by:
alwaysOrdered
in interfaceRowOrdering
- See Also:
RowOrdering.alwaysOrdered(int)
-
removeOptimizable
public void removeOptimizable(int tableNumber)
Description copied from interface:RowOrdering
Tell this row ordering that it is no longer ordered on the given table. Also, adjust the current order position, if necessary. This only works to remove ordered columns from the end of the ordering.- Specified by:
removeOptimizable
in interfaceRowOrdering
- Parameters:
tableNumber
- The number of the table to remove from this RowOrdering.- See Also:
RowOrdering.removeOptimizable(int)
-
removeOptimizable
private void removeOptimizable(int tableNumber, java.util.ArrayList<Optimizable> list)
Remove all optimizables with the given table number from the given list of optimizables.
-
addUnorderedOptimizable
public void addUnorderedOptimizable(Optimizable optimizable)
Description copied from interface:RowOrdering
Add an unordered optimizable to this RowOrdering. This is to solve the following problem: Suppose we have the query: select * from r, s, t order by r.a, t.b Also suppose there are indexes on r.a and t.b. When the optimizer considers the join order (r, s, t) using the index on r.a, the heap on s, and the index on t.b, the rows from the join order will *NOT* be ordered on t.b, because there is an unordered result set between r and t. So, when s is added to the partial join order, and we then add table t to the join order, we want to ensure that we don't add column t.b to the RowOrdering.- Specified by:
addUnorderedOptimizable
in interfaceRowOrdering
- See Also:
RowOrdering.addUnorderedOptimizable(org.apache.derby.iapi.sql.compile.Optimizable)
-
copy
public void copy(RowOrdering copyTo)
Description copied from interface:RowOrdering
Copy the contents of this RowOrdering to the given RowOrdering.- Specified by:
copy
in interfaceRowOrdering
- See Also:
RowOrdering.copy(org.apache.derby.iapi.sql.compile.RowOrdering)
-
rememberCurrentColumnOrdering
private void rememberCurrentColumnOrdering(int posn)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
unorderedOptimizablesOtherThan
private boolean unorderedOptimizablesOtherThan(Optimizable optimizable)
Returns true if there are unordered optimizables in the join order other than the given one.
-
-