KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > sql > compile > RequiredRowOrdering


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.compile.RequiredRowOrdering
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.iapi.sql.compile;
23
24 import org.apache.derby.iapi.error.StandardException;
25
26 import org.apache.derby.iapi.util.JBitSet;
27
28 /**
29  * This interface provides a representation of the required ordering of rows
30  * from a ResultSet. Different operations can require ordering: ORDER BY,
31  * DISTINCT, GROUP BY. Some operations, like ORDER BY, require that the
32  * columns be ordered a particular way, while others, like DISTINCT and
33  * GROUP BY, reuire only that there be no duplicates in the result.
34  */

35 public interface RequiredRowOrdering
36 {
37     static final int SORT_REQUIRED = 1;
38     static final int ELIMINATE_DUPS = 2;
39     static final int NOTHING_REQUIRED = 3;
40
41     /**
42      * Tell whether sorting is required for this RequiredRowOrdering,
43      * given a RowOrdering.
44      *
45      * @param rowOrdering The order of rows in question
46      *
47      * @return SORT_REQUIRED if sorting is required,
48      * ELIMINATE_DUPS if no sorting is required but duplicates
49      * must be eliminated (i.e. the rows are in
50      * the right order but there may be duplicates),
51      * NOTHING_REQUIRED is no operation is required
52      *
53      * @exception StandardException Thrown on error
54      */

55     int sortRequired(RowOrdering rowOrdering) throws StandardException;
56
57     /**
58      * Tell whether sorting is required for this RequiredRowOrdering,
59      * given a RowOrdering representing a partial join order, and
60      * a bit map telling what tables are represented in the join order.
61      * This is useful for reducing the number of cases the optimizer
62      * has to consider.
63      *
64      * @param rowOrdering The order of rows in the partial join order
65      * @param tableMap A bit map of the tables in the partial join order
66      *
67      * @return SORT_REQUIRED if sorting is required,
68      * ELIMINATE_DUPS if no sorting is required by duplicates
69      * must be eliminated (i.e. the rows are in
70      * the right order but there may be duplicates),
71      * NOTHING_REQUIRED is no operation is required
72      *
73      * @exception StandardException Thrown on error
74      */

75     int sortRequired(RowOrdering rowOrdering, JBitSet tableMap)
76             throws StandardException;
77
78     /**
79      * Estimate the cost of doing a sort for this row ordering, given
80      * the number of rows to be sorted. This does not take into account
81      * whether the sort is really needed. It also estimates the number of
82      * result rows.
83      *
84      * @param estimatedInputRows The estimated number of rows to sort
85      * @param rowOrdering The ordering of the input rows
86      * @param resultCost A place to store the resulting cost
87      *
88      * @exception StandardException Thrown on error
89      */

90     void estimateCost(double estimatedInputRows,
91                         RowOrdering rowOrdering,
92                         CostEstimate resultCost)
93                     throws StandardException;
94
95     /**
96      * Indicate that a sort is necessary to fulfill this required ordering.
97      * This method may be called many times during a single optimization.
98      */

99     void sortNeeded();
100
101     /**
102      * Indicate that a sort is *NOT* necessary to fulfill this required
103      * ordering. This method may be called many times during a single
104      * optimization.
105      */

106     void sortNotNeeded();
107
108     boolean getSortNeeded();
109 }
110
Popular Tags