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

public Interface RequiredRowOrdering

Known Direct Implementers
org.apache.derby.impl.sql.compile.OrderByList
Imports
org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.util.JBitSet

This interface provides a representation of the required ordering of rows from a ResultSet. Different operations can require ordering: ORDER BY, DISTINCT, GROUP BY. Some operations, like ORDER BY, require that the columns be ordered a particular way, while others, like DISTINCT and GROUP BY, reuire only that there be no duplicates in the result.

Field Summary

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

Method Summary

Modifier and TypeMethod and Description
public void
estimateCost(double
The estimated number of rows to sort
estimatedInputRows
,
RowOrdering
The ordering of the input rows
rowOrdering
,
CostEstimate
A place to store the resulting cost
resultCost
)

Estimate the cost of doing a sort for this row ordering, given the number of rows to be sorted.

public boolean
public void
sortNeeded()

Indicate that a sort is necessary to fulfill this required ordering.

public void
sortNotNeeded()

Indicate that a sort is *NOT* necessary to fulfill this required ordering.

public int

Returns:

SORT_REQUIRED if sorting is required, ELIMINATE_DUPS if no sorting is required but duplicates must be eliminated (i.e. the rows are in the right order but there may be duplicates), NOTHING_REQUIRED is no operation is required
sortRequired
(RowOrdering
The order of rows in question
rowOrdering
,
OptimizableList
The list of join participants
optimizableList
,
int[]
The current join order being considered by the optimizer. We need to look into this to determine if the outer optimizables are single row result set if the order by column is on an inner optimizable and that inner optimizable is not a one. proposedJoinOrder is a map onto optimizableList: it contains indexes of optimizables in that list in the join order proposed, cf. OptimizerImpl#proposedJoinOrder.
proposedJoinOrder
)

Tell whether sorting is required for this RequiredRowOrdering, given a RowOrdering.

public int

Returns:

SORT_REQUIRED if sorting is required, ELIMINATE_DUPS if no sorting is required by duplicates must be eliminated (i.e. the rows are in the right order but there may be duplicates), NOTHING_REQUIRED is no operation is required
sortRequired
(RowOrdering
The order of rows in the partial join order
rowOrdering
,
JBitSet
A bit map of the tables in the partial join order
tableMap
,
OptimizableList
The list of join participants
optimizableList
,
int[]
The current join order being considered by the optimizer. We need to look into this to determine if the outer optimizables are single row result set if the order by column is on an inner optimizable and that inner optimizable is not a one. proposedJoinOrder is a map onto optimizableList: it contains indexes of optimizables in that list in the join order proposed, cf. OptimizerImpl#proposedJoinOrder. DERBY-3926 and DERBY-6148
proposedJoinOrder
)

Tell whether sorting is required for this RequiredRowOrdering, given a RowOrdering representing a partial join order, and a bit map telling what tables are represented in the join order.

Field Detail

ELIMINATE_DUPSback to summary
public static final int ELIMINATE_DUPS
NOTHING_REQUIREDback to summary
public static final int NOTHING_REQUIRED
SORT_REQUIREDback to summary
public static final int SORT_REQUIRED

Method Detail

estimateCostback to summary
public void estimateCost(double estimatedInputRows, RowOrdering rowOrdering, CostEstimate resultCost) throws StandardException

Estimate the cost of doing a sort for this row ordering, given the number of rows to be sorted. This does not take into account whether the sort is really needed. It also estimates the number of result rows.

Parameters
estimatedInputRows:double

The estimated number of rows to sort

rowOrdering:RowOrdering

The ordering of the input rows

resultCost:CostEstimate

A place to store the resulting cost

Exceptions
StandardException:
Thrown on error
getSortNeededback to summary
public boolean getSortNeeded()
sortNeededback to summary
public void sortNeeded()

Indicate that a sort is necessary to fulfill this required ordering. This method may be called many times during a single optimization.

sortNotNeededback to summary
public void sortNotNeeded()

Indicate that a sort is *NOT* necessary to fulfill this required ordering. This method may be called many times during a single optimization.

sortRequiredback to summary
public int sortRequired(RowOrdering rowOrdering, OptimizableList optimizableList, int[] proposedJoinOrder) throws StandardException

Tell whether sorting is required for this RequiredRowOrdering, given a RowOrdering.

Parameters
rowOrdering:RowOrdering

The order of rows in question

optimizableList:OptimizableList

The list of join participants

proposedJoinOrder:int[]

The current join order being considered by the optimizer. We need to look into this to determine if the outer optimizables are single row result set if the order by column is on an inner optimizable and that inner optimizable is not a one. proposedJoinOrder is a map onto optimizableList: it contains indexes of optimizables in that list in the join order proposed, cf. OptimizerImpl#proposedJoinOrder.

Returns:int

SORT_REQUIRED if sorting is required, ELIMINATE_DUPS if no sorting is required but duplicates must be eliminated (i.e. the rows are in the right order but there may be duplicates), NOTHING_REQUIRED is no operation is required

Exceptions
StandardException:
Thrown on error
sortRequiredback to summary
public int sortRequired(RowOrdering rowOrdering, JBitSet tableMap, OptimizableList optimizableList, int[] proposedJoinOrder) throws StandardException

Tell whether sorting is required for this RequiredRowOrdering, given a RowOrdering representing a partial join order, and a bit map telling what tables are represented in the join order. This is useful for reducing the number of cases the optimizer has to consider.

Parameters
rowOrdering:RowOrdering

The order of rows in the partial join order

tableMap:JBitSet

A bit map of the tables in the partial join order

optimizableList:OptimizableList

The list of join participants

proposedJoinOrder:int[]

The current join order being considered by the optimizer. We need to look into this to determine if the outer optimizables are single row result set if the order by column is on an inner optimizable and that inner optimizable is not a one. proposedJoinOrder is a map onto optimizableList: it contains indexes of optimizables in that list in the join order proposed, cf. OptimizerImpl#proposedJoinOrder. DERBY-3926 and DERBY-6148

Returns:int

SORT_REQUIRED if sorting is required, ELIMINATE_DUPS if no sorting is required by duplicates must be eliminated (i.e. the rows are in the right order but there may be duplicates), NOTHING_REQUIRED is no operation is required

Exceptions
StandardException:
Thrown on error