KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.compile.OptimizablePredicateList
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.sql.dictionary.ConglomerateDescriptor;
25
26 import org.apache.derby.iapi.services.compiler.MethodBuilder;
27
28 import org.apache.derby.iapi.error.StandardException;
29
30 import org.apache.derby.iapi.util.JBitSet;
31
32 /**
33  * OptimizablePredicateList provides services for optimizing a table in a query.
34  * RESOLVE - the methods for this interface need to get defined.
35  */

36
37 public interface OptimizablePredicateList
38 {
39     /**
40      * Return the number of OptimizablePredicates in the list.
41      *
42      * @return integer The number of OptimizablePredicates in the list.
43      */

44     public int size();
45
46     /**
47      * Return the nth OptimizablePredicate in the list.
48      *
49      * @param n "index" (0 based) into the list.
50      *
51      * @return OptimizablePredicate The nth OptimizablePredicate in the list.
52      */

53     public OptimizablePredicate getOptPredicate(int n);
54
55     /**
56      * Remove the OptimizablePredicate at the specified index (0-based) from the list.
57      *
58      * @param predCtr The index.
59      *
60      * @exception StandardException Thrown on error
61      */

62     void removeOptPredicate(int predCtr) throws StandardException;
63
64     /**
65      * Add the given OptimizablePredicate to the end of this list.
66      *
67      * @param optPredicate The predicate to add
68      */

69     void addOptPredicate(OptimizablePredicate optPredicate);
70
71     /**
72      * Return true if this predicate list is useful for limiting the scan on
73      * the given table using the given conglomerate.
74      *
75      * @param optTable An Optimizable for the table in question
76      * @param cd A ConglomerateDescriptor for the conglomerate in question
77      *
78      * @return true if this predicate list can limit the scan
79      * @exception StandardException Thrown on error
80      */

81     boolean useful(Optimizable optTable, ConglomerateDescriptor cd)
82         throws StandardException;
83
84     /**
85      * Determine which predicates in this list are useful for limiting
86      * the scan on the given table using its best conglomerate. Remove
87      * those predicates from this list and push them down to the given
88      * Optimizable table. The predicates are pushed down in the order of
89      * the index columns that they qualify. Also, the predicates are
90      * "marked" as start predicates, stop predicates, or qualifier
91      * predicates. Finally, the start and stop operators are set in
92      * the given Optimizable.
93      *
94      * @param optTable An Optimizable for the table in question
95      *
96      * @exception StandardException Thrown on error
97      */

98     void pushUsefulPredicates(Optimizable optTable)
99                 throws StandardException;
100
101     /**
102      * Classify the predicates in this list according to the given
103      * table and conglomerate. Each predicate can be a start key, stop key,
104      * and/or qualifier, or it can be none of the above. This method
105      * also orders the predicates to match the order of the columns
106      * in a keyed conglomerate. No ordering is done for heaps.
107      *
108      * @param optTable The Optimizable table for which to classify
109      * the predicates in this list.
110      * @param cd The ConglomerateDescriptor for which to classify
111      * the predicates in this list.
112      *
113      * @exception StandardException Thrown on error
114      */

115     void classify(Optimizable optTable, ConglomerateDescriptor cd)
116                 throws StandardException;
117
118     /**
119      * Mark all of the predicates as Qualifiers and set the numberOfQualifiers
120      * to reflect this. This is useful for hash joins where all of the
121      * predicates in the list to be evaluated during the probe into the
122      * hash table on a next are qualifiers.
123      */

124     public void markAllPredicatesQualifiers();
125
126     /**
127      * Is there an optimizable equality predicate on the specified column?
128      *
129      * @param optTable The optimizable the column comes from.
130      * @param columnNumber The column number within the base table.
131      * @param isNullOkay boolean, whether or not the IS NULL operator
132      * satisfies the search
133      *
134      * @return Whether or not there is an optimizable equality predicate on the specified column.
135      *
136      * @exception StandardException Thrown on error
137      */

138     boolean hasOptimizableEqualityPredicate(Optimizable optTable,
139                                             int columnNumber,
140                                             boolean isNullOkay)
141                                 throws StandardException;
142
143     /**
144      * Is there an optimizable equijoin on the specified column?
145      *
146      * @param optTable The optimizable the column comes from.
147      * @param columnNumber The column number within the base table.
148      *
149      * @return Whether or not there is an optimizable equijoin on the specified column.
150      *
151      * @exception StandardException Thrown on error
152      */

153     boolean hasOptimizableEquijoin(Optimizable optTable,
154                                     int columnNumber)
155                             throws StandardException;
156                                     
157
158     /**
159      * Find the optimizable equality predicate on the specified column and make
160      * it the first predicate in this list. This is useful for hash joins where
161      * Qualifier[0] is assumed to be on the hash key.
162      *
163      * @param optTable The optimizable the column comes from.
164      * @param columnNumber The column number within the base table.
165      *
166      * @exception StandardException Thrown on error
167      */

168     void putOptimizableEqualityPredicateFirst(Optimizable optTable,
169                                                 int columnNumber)
170                                 throws StandardException;
171
172     /**
173      * Transfer the predicates whose referenced set is contained by the
174      * specified referencedTableMap from this list to the other list.
175      * This is useful when splitting out a set of predicates from a larger
176      * set, like when generating a HashScanResultSet.
177      *
178      * @param otherList The predicateList to xfer to
179      * @param referencedTableMap The table map to check against
180      * @param table The table to order the new predicates
181      * against
182      *
183      * @exception StandardException Thrown on error
184      */

185     public void transferPredicates(OptimizablePredicateList otherList,
186                                     JBitSet referencedTableMap,
187                                     Optimizable table)
188         throws StandardException;
189
190
191     /**
192      * Transfer all the predicates from this list to the given list.
193      *
194      * @exception StandardException Thrown on error
195      */

196     public void transferAllPredicates(OptimizablePredicateList otherList)
197         throws StandardException;
198
199     /**
200      * Non-destructive copy of all of the predicates from this list to the
201      * other list.
202      *
203      * This is useful when splitting out a set of predicates from a larger
204      * set, like when generating a HashScanResultSet.
205      *
206      * @param otherList The predicateList to xfer to
207      *
208      * @exception StandardException Thrown on error
209      */

210     public void copyPredicatesToOtherList(OptimizablePredicateList otherList)
211         throws StandardException;
212
213     /**
214      * Sets the given list to have the same elements as this one, and
215      * the same properties as this one (number of qualifiers and start
216      * and stop predicates.
217      *
218      * @param otherList The list to set the same as this one.
219      *
220      * @exception StandardException Thrown on error
221      */

222     public void setPredicatesAndProperties(OptimizablePredicateList otherList)
223         throws StandardException;
224
225     /**
226      * Return whether or not the specified entry in the list is a redundant
227      * predicate. This is useful for selectivity calculations because we
228      * do not want redundant predicates included in the selectivity calculation.
229      *
230      * @param predNum The entry in the list
231      *
232      * @return Whether or not the specified entry in the list is a redundant predicate.
233      */

234     public boolean isRedundantPredicate(int predNum);
235
236     /**
237      * Get the start operator for the given Optimizable for a heap or
238      * index scan.
239      */

240     int startOperator(Optimizable optTable);
241
242     /**
243      * Get the stop operator for the given Optimizable for a heap or
244      * index scan.
245      */

246     int stopOperator(Optimizable optTable);
247
248     /**
249      * Generate the qualifiers for a scan. This method generates an array
250      * of Qualifiers, and fills them in with calls to the factory method
251      * for generating Qualifiers in the constructor for the activation.
252      * It stores the array of Qualifiers in a field in the activation, and
253      * returns a reference to that field.
254      *
255      * If there are no qualifiers, it initializes the array of Qualifiers
256      * to null.
257      *
258      * @param acb The ExpressionClassBuilderInterface for the class we are building
259      * @param mb The method the generated code is going into
260      * @param optTable The Optimizable table the Qualifiers are on
261      * @param absolute Generate absolute column positions if true,
262      * else relative column positions (within the underlying
263      * row)
264      *
265      *
266      * @exception StandardException Thrown on error
267      */

268     void generateQualifiers(ExpressionClassBuilderInterface acb,
269                                     MethodBuilder mb,
270                                     Optimizable optTable,
271                                     boolean absolute)
272                             throws StandardException;
273
274     /**
275      * Generate the start key for a heap or index scan.
276      *
277      * @param acb The ExpressionClassBuilderInterface for the class we're building
278      * @param mb The method the generated code is to go into
279      * @param optTable The Optimizable table the start key is for
280      *
281      * @exception StandardException Thrown on error
282      */

283     void generateStartKey(ExpressionClassBuilderInterface acb,
284                                 MethodBuilder mb,
285                                 Optimizable optTable)
286                 throws StandardException;
287
288     /**
289      * Generate the stop key for a heap or index scan.
290      *
291      * @param acb The ExpressionClassBuilderInterface for the class we're building
292      * @param mb the method the generated code is to go into
293      * @param optTable The Optimizable table the stop key is for
294      *
295      * @exception StandardException Thrown on error
296      */

297     void generateStopKey(ExpressionClassBuilderInterface acb,
298                                 MethodBuilder mb,
299                                 Optimizable optTable)
300                 throws StandardException;
301
302     /**
303      * Can we use the same key for both the start and stop key.
304      * This is possible when doing an exact match on an index
305      * where there are no other sargable predicates.
306      *
307      * @return Whether or not we can use the same key for both the start and stop key.
308      *
309      * @exception StandardException Thrown on error
310      */

311     public boolean sameStartStopPosition()
312                 throws StandardException;
313     
314     /**
315      * calculate the selectivity for a set of predicates.
316      * If statistics exist for the predicates this method uses the
317      * statistics. If statistics do not exist, then simply call
318      * selectivity for each of the predicates and return the result.
319      *
320      * @param optTable the Optimizable that the predicate list restricts.
321      */

322     public double selectivity(Optimizable optTable) throws StandardException;
323     
324 }
325
Popular Tags