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

pack-priv Class RowOrderingImpl

extends Object
implements RowOrdering
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.sql.compile.RowOrdering
Imports
java.util.ArrayList, .Iterator, .ListIterator, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.compile.Optimizable, .RowOrdering

Field Summary

Modifier and TypeField and Description
private final ArrayList<Optimizable>
alwaysOrderedOptimizables

List of table numbers for tables that are always ordered.

pack-priv ColumnOrdering
pack-priv ColumnOrdering
private final ArrayList<ColumnOrdering>
ordering

List of ColumnOrderings.

private final ArrayList<Optimizable>
unorderedOptimizables

List of unordered Optimizables.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
addOrderedColumn(int
One of ASCENDING, DESCENDING, or DONTCARE. DONTCARE can be used for things like columns with constant value, and for one-row tables.
direction
,
int
The table the column is in.
tableNumber
,
int
The column number in the table (one-based)
columnNumber
)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.addOrderedColumn.

Add a column to this RowOrdering in the current order position.

public void
addUnorderedOptimizable(Optimizable optimizable)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.addUnorderedOptimizable.

Add an unordered optimizable to this RowOrdering.

public boolean
alwaysOrdered(int tableNumber)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.alwaysOrdered.

Ask whether the given table is always ordered.

public void
columnAlwaysOrdered(Optimizable
The table in question
optimizable
,
int
The number of the column in question.
columnNumber
)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.columnAlwaysOrdered.

Tell this RowOrdering that it is always ordered on the given column of the given optimizable.

public void
copy(RowOrdering copyTo)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.copy.

Copy the contents of this RowOrdering to the given RowOrdering.

public boolean
isColumnAlwaysOrdered(int
The table in question
tableNumber
,
int
The number of the column in question.
columnNumber
)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.isColumnAlwaysOrdered.

Return true if the column is always ordered.

public void
nextOrderPosition(int
One of ASCENDING, DESCENDING, or DONTCARE. DONTCARE can be used for things like columns with constant value, and for one-row tables.
direction
)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.nextOrderPosition.

Move to the next order position for adding ordered columns.

public void
optimizableAlwaysOrdered(Optimizable
The table in question
optimizable
)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.optimizableAlwaysOrdered.

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.

public boolean
orderedOnColumn(int
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.
direction
,
int
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).
orderPosition
,
int
The table number of the Optimizable containing the column in question
tableNumber
,
int
The column number in the table (one-based).
columnNumber
)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.orderedOnColumn.

Tell whether this ordering is ordered on the given column in the given position

public boolean
orderedOnColumn(int
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.
direction
,
int
The table number of the Optimizable containing the column in question
tableNumber
,
int
The column number in the table (one-based).
columnNumber
)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.orderedOnColumn.

Tell whether this ordering is ordered on the given column.

private void
public void
removeOptimizable(int
The number of the table to remove from this RowOrdering.
tableNumber
)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.removeOptimizable.

Tell this row ordering that it is no longer ordered on the given table.

private void
removeOptimizable(int tableNumber, ArrayList<Optimizable> list)

Remove all optimizables with the given table number from the given list of optimizables.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private boolean
unorderedOptimizablesOtherThan(Optimizable optimizable)

Returns true if there are unordered optimizables in the join order other than the given one.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

alwaysOrderedOptimizablesback to summary
private final ArrayList<Optimizable> alwaysOrderedOptimizables

List of table numbers for tables that are always ordered. This happens for one-row tables.

columnsAlwaysOrderedback to summary
pack-priv ColumnOrdering columnsAlwaysOrdered
currentColumnOrderingback to summary
pack-priv ColumnOrdering currentColumnOrdering
orderingback to summary
private final ArrayList<ColumnOrdering> ordering

List of ColumnOrderings.

unorderedOptimizablesback to summary
private final ArrayList<Optimizable> unorderedOptimizables

List of unordered Optimizables.

Constructor Detail

RowOrderingImplback to summary
pack-priv RowOrderingImpl()

Method Detail

addOrderedColumnback to summary
public void addOrderedColumn(int direction, int tableNumber, int columnNumber)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.addOrderedColumn.

Doc from org.apache.derby.iapi.sql.compile.RowOrdering.addOrderedColumn.

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

Parameters
direction:int

One of ASCENDING, DESCENDING, or DONTCARE. DONTCARE can be used for things like columns with constant value, and for one-row tables.

tableNumber:int

The table the column is in.

columnNumber:int

The column number in the table (one-based)

See Also
RowOrdering#addOrderedColumn
addUnorderedOptimizableback to summary
public void addUnorderedOptimizable(Optimizable optimizable)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.addUnorderedOptimizable.

Doc from org.apache.derby.iapi.sql.compile.RowOrdering.addUnorderedOptimizable.

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.

See Also
RowOrdering#addUnorderedOptimizable
alwaysOrderedback to summary
public boolean alwaysOrdered(int tableNumber)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.alwaysOrdered.

Doc from org.apache.derby.iapi.sql.compile.RowOrdering.alwaysOrdered.

Ask whether the given table is always ordered.

See Also
RowOrdering#alwaysOrdered
columnAlwaysOrderedback to summary
public void columnAlwaysOrdered(Optimizable optimizable, int columnNumber)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.columnAlwaysOrdered.

Doc from org.apache.derby.iapi.sql.compile.RowOrdering.columnAlwaysOrdered.

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.

Parameters
optimizable:Optimizable

The table in question

columnNumber:int

The number of the column in question.

See Also
RowOrdering#columnAlwaysOrdered
copyback to summary
public void copy(RowOrdering copyTo)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.copy.

Doc from org.apache.derby.iapi.sql.compile.RowOrdering.copy.

Copy the contents of this RowOrdering to the given RowOrdering.

See Also
RowOrdering#copy
isColumnAlwaysOrderedback to summary
public boolean isColumnAlwaysOrdered(int tableNumber, int columnNumber)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.isColumnAlwaysOrdered.

Doc from org.apache.derby.iapi.sql.compile.RowOrdering.isColumnAlwaysOrdered.

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.

Parameters
tableNumber:int

The table in question

columnNumber:int

The number of the column in question.

Returns:boolean

true means this column is always ordered

See Also
RowOrdering#isColumnAlwaysOrdered
nextOrderPositionback to summary
public void nextOrderPosition(int direction)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.nextOrderPosition.

Doc from org.apache.derby.iapi.sql.compile.RowOrdering.nextOrderPosition.

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

Parameters
direction:int

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
optimizableAlwaysOrderedback to summary
public void optimizableAlwaysOrdered(Optimizable optimizable)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.optimizableAlwaysOrdered.

Doc from org.apache.derby.iapi.sql.compile.RowOrdering.optimizableAlwaysOrdered.

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.

Parameters
optimizable:Optimizable

The table in question

orderedOnColumnback to summary
public boolean orderedOnColumn(int direction, int orderPosition, int tableNumber, int columnNumber) throws StandardException

Implements org.apache.derby.iapi.sql.compile.RowOrdering.orderedOnColumn.

Doc from org.apache.derby.iapi.sql.compile.RowOrdering.orderedOnColumn.

Tell whether this ordering is ordered on the given column in the given position

Parameters
direction:int

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

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

The table number of the Optimizable containing the column in question

columnNumber:int

The column number in the table (one-based).

Returns:boolean

true means this ordering is ordered on the given column in the given position.

Exceptions
StandardException:
Thrown on error
See Also
RowOrdering#orderedOnColumn
orderedOnColumnback to summary
public boolean orderedOnColumn(int direction, int tableNumber, int columnNumber) throws StandardException

Implements org.apache.derby.iapi.sql.compile.RowOrdering.orderedOnColumn.

Doc from org.apache.derby.iapi.sql.compile.RowOrdering.orderedOnColumn.

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.

Parameters
direction:int

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

The table number of the Optimizable containing the column in question

columnNumber:int

The column number in the table (one-based).

Returns:boolean

true means this ordering is ordered on the given column in the given position.

Exceptions
StandardException:
Thrown on error
See Also
RowOrdering#orderedOnColumn
rememberCurrentColumnOrderingback to summary
private void rememberCurrentColumnOrdering(int posn)
removeOptimizableback to summary
public void removeOptimizable(int tableNumber)

Implements org.apache.derby.iapi.sql.compile.RowOrdering.removeOptimizable.

Doc from org.apache.derby.iapi.sql.compile.RowOrdering.removeOptimizable.

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.

Parameters
tableNumber:int

The number of the table to remove from this RowOrdering.

See Also
RowOrdering#removeOptimizable
removeOptimizableback to summary
private void removeOptimizable(int tableNumber, ArrayList<Optimizable> list)

Remove all optimizables with the given table number from the given list of optimizables.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
unorderedOptimizablesOtherThanback to summary
private boolean unorderedOptimizablesOtherThan(Optimizable optimizable)

Returns true if there are unordered optimizables in the join order other than the given one.