KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.compile.RowOrdering
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 /**
27  * This interface provides a representation of the ordering of rows in a
28  * ResultSet.
29  */

30 public interface RowOrdering
31 {
32     static final int ASCENDING = 1;
33     static final int DESCENDING = 2;
34     static final int DONTCARE = 3;
35
36     /**
37      * Tell whether this ordering is ordered on the given column in
38      * the given position
39      *
40      * @param direction One of ASCENDING, DESCENDING, or DONTCARE
41      * depending on the requirements of the caller.
42      * An ORDER BY clause cares about direction,
43      * while DISTINCT and GROUP BY do not.
44      * @param orderPosition The position in the ordering list. For example,
45      * for ORDER BY A, B, position 0 has column A,
46      * and position 1 has column B. Note that for an
47      * ordering, more than one column can be in a single
48      * ordering position: for example, in the query
49      * SELECT * FROM S, T WHERE S.A = T.B ORDER BY T.B
50      * columns S.A and T.B will be in the same ordering
51      * positions because they are equal. Also, constant
52      * values are considered ordered in all positions
53      * (consider SELECT A FROM T WHERE A = 1 ORDER BY A).
54      * @param tableNumber The table number of the Optimizable containing
55      * the column in question
56      * @param columnNumber The column number in the table (one-based).
57      *
58      * @return true means this ordering is ordered on the given column
59      * in the given position.
60      *
61      * @exception StandardException Thrown on error
62      */

63     boolean orderedOnColumn(int direction,
64                             int orderPosition,
65                             int tableNumber,
66                             int columnNumber)
67             throws StandardException;
68
69     /**
70      * Tell whether this ordering is ordered on the given column.
71      * This is similar to the method above, but it checks whether the
72      * column is ordered in any position, rather than a specified position.
73      * This is useful for operations like DISTINCT and GROUP BY.
74      *
75      * @param direction One of ASCENDING, DESCENDING, or DONTCARE
76      * depending on the requirements of the caller.
77      * An ORDER BY clause cares about direction,
78      * while DISTINCT and GROUP BY do not.
79      * @param tableNumber The table number of the Optimizable containing
80      * the column in question
81      * @param columnNumber The column number in the table (one-based).
82      *
83      * @return true means this ordering is ordered on the given column
84      * in the given position.
85      *
86      * @exception StandardException Thrown on error
87      */

88     boolean orderedOnColumn(int direction,
89                             int tableNumber,
90                             int columnNumber)
91             throws StandardException;
92
93     /**
94      * Add a column to this RowOrdering in the current order position.
95      * This is a no-op if there are any unordered optimizables in the
96      * join order (see below).
97      *
98      * @param direction One of ASCENDING, DESCENDING, or DONTCARE.
99      * DONTCARE can be used for things like columns
100      * with constant value, and for one-row tables.
101      * @param tableNumber The table the column is in.
102      * @param columnNumber The column number in the table (one-based)
103      */

104     void addOrderedColumn(int direction,
105                             int tableNumber,
106                             int columnNumber);
107
108     /**
109      * Move to the next order position for adding ordered columns.
110      * This is a no-op if there are any unordered optimizables in the
111      * join order (see below).
112      *
113      * @param direction One of ASCENDING, DESCENDING, or DONTCARE.
114      * DONTCARE can be used for things like columns
115      * with constant value, and for one-row tables.
116      */

117     void nextOrderPosition(int direction);
118
119     /**
120      * Tell this RowOrdering that it is always ordered on the given optimizable
121      * This is useful when considering a unique index where there is an
122      * equality match on the entire key - in this case, all the columns
123      * are ordered, regardless of the direction or position,
124      * or even whether the columns are in the index.
125      *
126      * @param optimizable The table in question
127      */

128     void optimizableAlwaysOrdered(Optimizable optimizable);
129
130     /**
131      * Tell this RowOrdering that it is always ordered on the given column
132      * of the given optimizable. This is useful when a column in the
133      * optimizable has an equals comparison with a constant expression.
134      * This is reset when the optimizable is removed from this RowOrdering.
135      *
136      * @param optimizable The table in question
137      * @param columnNumber The number of the column in question.
138      */

139     void columnAlwaysOrdered(Optimizable optimizable, int columnNumber);
140
141     /**
142      * Ask whether the given table is always ordered.
143      */

144     boolean alwaysOrdered(int tableNumber);
145
146     /**
147      * Tell this row ordering that it is no longer ordered on the given
148      * table. Also, adjust the current order position, if necessary.
149      * This only works to remove ordered columns from the end of the
150      * ordering.
151      *
152      * @param tableNumber The number of the table to remove from
153      * this RowOrdering.
154      */

155     void removeOptimizable(int tableNumber);
156
157     /**
158      * Add an unordered optimizable to this RowOrdering. This is to
159      * solve the following problem:
160      *
161      * Suppose we have the query:
162      *
163      * select * from r, s, t order by r.a, t.b
164      *
165      * Also suppose there are indexes on r.a and t.b. When the
166      * optimizer considers the join order (r, s, t) using the index
167      * on r.a, the heap on s, and the index on t.b, the rows from the
168      * join order will *NOT* be ordered on t.b, because there is an
169      * unordered result set between r and t. So, when s is added to
170      * the partial join order, and we then add table t to the join order,
171      * we want to ensure that we don't add column t.b to the RowOrdering.
172      */

173     void addUnorderedOptimizable(Optimizable optimizable);
174
175     /**
176      * Copy the contents of this RowOrdering to the given RowOrdering.
177      */

178     void copy(RowOrdering copyTo);
179 }
180
Popular Tags