001: /*
002:
003: Derby - Class org.apache.derby.iapi.sql.compile.RequiredRowOrdering
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.iapi.sql.compile;
023:
024: import org.apache.derby.iapi.error.StandardException;
025:
026: import org.apache.derby.iapi.util.JBitSet;
027:
028: /**
029: * This interface provides a representation of the required ordering of rows
030: * from a ResultSet. Different operations can require ordering: ORDER BY,
031: * DISTINCT, GROUP BY. Some operations, like ORDER BY, require that the
032: * columns be ordered a particular way, while others, like DISTINCT and
033: * GROUP BY, reuire only that there be no duplicates in the result.
034: */
035: public interface RequiredRowOrdering {
036: static final int SORT_REQUIRED = 1;
037: static final int ELIMINATE_DUPS = 2;
038: static final int NOTHING_REQUIRED = 3;
039:
040: /**
041: * Tell whether sorting is required for this RequiredRowOrdering,
042: * given a RowOrdering.
043: *
044: * @param rowOrdering The order of rows in question
045: *
046: * @return SORT_REQUIRED if sorting is required,
047: * ELIMINATE_DUPS if no sorting is required but duplicates
048: * must be eliminated (i.e. the rows are in
049: * the right order but there may be duplicates),
050: * NOTHING_REQUIRED is no operation is required
051: *
052: * @exception StandardException Thrown on error
053: */
054: int sortRequired(RowOrdering rowOrdering) throws StandardException;
055:
056: /**
057: * Tell whether sorting is required for this RequiredRowOrdering,
058: * given a RowOrdering representing a partial join order, and
059: * a bit map telling what tables are represented in the join order.
060: * This is useful for reducing the number of cases the optimizer
061: * has to consider.
062: *
063: * @param rowOrdering The order of rows in the partial join order
064: * @param tableMap A bit map of the tables in the partial join order
065: *
066: * @return SORT_REQUIRED if sorting is required,
067: * ELIMINATE_DUPS if no sorting is required by duplicates
068: * must be eliminated (i.e. the rows are in
069: * the right order but there may be duplicates),
070: * NOTHING_REQUIRED is no operation is required
071: *
072: * @exception StandardException Thrown on error
073: */
074: int sortRequired(RowOrdering rowOrdering, JBitSet tableMap)
075: throws StandardException;
076:
077: /**
078: * Estimate the cost of doing a sort for this row ordering, given
079: * the number of rows to be sorted. This does not take into account
080: * whether the sort is really needed. It also estimates the number of
081: * result rows.
082: *
083: * @param estimatedInputRows The estimated number of rows to sort
084: * @param rowOrdering The ordering of the input rows
085: * @param resultCost A place to store the resulting cost
086: *
087: * @exception StandardException Thrown on error
088: */
089: void estimateCost(double estimatedInputRows,
090: RowOrdering rowOrdering, CostEstimate resultCost)
091: throws StandardException;
092:
093: /**
094: * Indicate that a sort is necessary to fulfill this required ordering.
095: * This method may be called many times during a single optimization.
096: */
097: void sortNeeded();
098:
099: /**
100: * Indicate that a sort is *NOT* necessary to fulfill this required
101: * ordering. This method may be called many times during a single
102: * optimization.
103: */
104: void sortNotNeeded();
105:
106: boolean getSortNeeded();
107: }
|