KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.compile.OptimizablePredicate
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.types.DataValueDescriptor;
27
28 import org.apache.derby.iapi.util.JBitSet;
29
30 /**
31  * OptimizablePredicate provides services for optimizing predicates in a query.
32  */

33
34 public interface OptimizablePredicate
35 {
36     /**
37      * Get the map of referenced tables for this OptimizablePredicate.
38      *
39      * @return JBitSet Referenced table map.
40      */

41     JBitSet getReferencedMap();
42
43     /**
44      * Return whether or not an OptimizablePredicate contains a subquery.
45      *
46      * @return boolean Whether or not an OptimizablePredicate includes a subquery.
47      */

48     boolean hasSubquery();
49
50     /**
51      * Return whether or not an OptimizablePredicate contains a method call.
52      *
53      * @return boolean Whether or not an OptimizablePredicate includes a method call.
54      */

55     boolean hasMethodCall();
56
57     /**
58      * Tell the predicate that it is to be used as a column in the start key
59      * value for an index scan.
60      */

61     void markStartKey();
62
63     /** Is this predicate a start key? */
64     boolean isStartKey();
65
66     /**
67      * Tell the predicate that it is to be used as a column in the stop key
68      * value for an index scan.
69      */

70     void markStopKey();
71
72     /** Is this predicate a stop key? */
73     boolean isStopKey();
74
75     /**
76      * Tell the predicate that it is to be used as a qualifier in an index
77      * scan.
78      */

79     void markQualifier();
80
81     /** Is this predicate a qualifier? */
82     boolean isQualifier();
83
84     /**
85      * Is this predicate a comparison with a known constant value?
86      *
87      * @param optTable The Optimizable that we want to know whether we
88      * are comparing to a known constant.
89      * @param considerParameters Whether or not to consider parameters with defaults
90      * as known constants.
91      */

92     boolean compareWithKnownConstant(Optimizable optTable, boolean considerParameters);
93
94     /**
95      * Get an Object representing the known constant value that the given
96      * Optimizable is being compared to.
97      *
98      * @exception StandardException Thrown on error
99      */

100     DataValueDescriptor getCompareValue(Optimizable optTable)
101         throws StandardException;
102
103     /**
104      * Is this predicate an equality comparison with a constant expression?
105      * (IS NULL is considered to be an = comparison with a constant expression).
106      *
107      * @param optTable The Optimizable for which we want to know whether
108      * it is being equality-compared to a constant expression.
109      */

110     boolean equalsComparisonWithConstantExpression(Optimizable optTable);
111
112     
113     /**
114      * Returns if the predicate involves an equal operator on one of the
115      * columns specified in the baseColumnPositions.
116      *
117      * @param baseColumnPositions the column numbers on which the user wants
118      * to check if the equality condition exists.
119      * @param optTable the table for which baseColumnPositions are given.
120
121         @return returns the index into baseColumnPositions of the column that has the
122         equality operator.
123      */

124     int hasEqualOnColumnList(int[] baseColumnPositions,
125                                  Optimizable optTable)
126         throws StandardException;
127
128     /**
129      * Get a (crude) estimate of the selectivity of this predicate.
130      * This is to be used when no better technique is available for
131      * estimating the selectivity - this method's estimate is a hard-
132      * wired number based on the type of predicate and the datatype
133      * (the selectivity of boolean is always 50%).
134      *
135      * @param optTable The Optimizable that this predicate restricts
136      */

137     double selectivity(Optimizable optTable)
138     throws StandardException;
139
140     /**
141      * Get the position of the index column that this predicate restricts.
142      * NOTE: This assumes that this predicate is part of an
143      * OptimizablePredicateList, and that classify() has been called
144      * on the OptimizablePredicateList.
145      *
146      * @return The index position that this predicate restricts (zero-based)
147      */

148     int getIndexPosition();
149 }
150
Popular Tags