KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > access > btree > SearchParameters


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.btree.SearchParameters
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.impl.store.access.btree;
23
24 import java.io.PrintStream JavaDoc;
25
26 import org.apache.derby.iapi.services.sanity.SanityManager;
27
28 import org.apache.derby.iapi.error.StandardException;
29
30 import org.apache.derby.iapi.store.access.ScanController;
31 import org.apache.derby.iapi.store.access.RowUtil;
32
33 import org.apache.derby.iapi.types.DataValueDescriptor;
34
35
36 /**
37
38   Parameters that are passed down during a recursive b-tree search.
39   This class is intended to be used as a struct, primarily to make
40   it easier to pass a number of search parameters around, and also
41   to make it easy to re-use objects and not re-allocate.
42
43 **/

44
45 public class SearchParameters
46 {
47
48     /**
49      * Position on key just left of a sequence of partial key matches.
50      * Used by scan which will then start scan on next key.
51      **/

52     public static final int POSITION_LEFT_OF_PARTIAL_KEY_MATCH = 1;
53
54     /**
55      * Position on last key in a sequence of partial key matches.
56      * Used by scan which will then start scan on next key.
57      **/

58     public static final int POSITION_RIGHT_OF_PARTIAL_KEY_MATCH = -1;
59
60     /**
61     The key being searched for. Never intended to be modified
62     for the lifetime of the object.
63     **/

64     public DataValueDescriptor[] searchKey;
65
66     /**
67     Value to return in comparisons where partial key matches exactly
68     the partial key of a row. Use this parameter to control where
69     in a duplicate partial key list to position the search.
70
71     Here are some examples:
72
73     Assume: dataset of {1,0}, {5,1}, {5,2}, {6,4}; and partial key of {5}.
74
75
76     If the scan is GE , then the scan intially wants to position
77     on {1,0} (one before first qualifying row) - In this case when a partial
78     match is found we want to return 1 when we hit {5,1}; but if the
79     searchOperator is GT, then we want to return -1 on {5,1}, {5,2}, and then
80     return 1 on {6,4}.
81
82
83     partial_key_match_op = POSITION_LEFT_OF_PARTIAL_KEY_MATCH:
84     Scan is looking for GE the partial key, so position the scan to the
85     left of any partial key that exactly matches the partial key.
86     If the scan is GE , then the scan intially wants to position
87     on {1,0} (one before first qualifying row) - In this case when a partial
88     match is found we want to return 1 when we hit {5,1}.
89
90     partial_key_match_op = POSITION_RIGHT_OF_PARTIAL_KEY_MATCH:
91     Scan is looking for GT the partial key, so position the scan to the
92     right of any partial key that exactly matches the partial key.
93     If the scan is GT, then the scan intially wants to position
94     on {5,2} (one before first qualifying row) - In this case when a partial
95     match is found we want to return -1 when we hit on {5,1}, {5,2}, and then
96     return 1 on {6,4}.
97
98     partial_key_match_op = 0:
99     Scan does not care where in a set of duplicate partial keys to position
100     to (not used currently).
101     **/

102     int partial_key_match_op;
103
104     /**
105     An index row with the correct types for the index,
106     into which rows are read during the search.
107     Rows are read into the template during a page search, but
108     they will be overwritten; there is only one template per
109     search.
110     **/

111     public DataValueDescriptor[] template;
112
113     /**
114     The b-tree this search is for. Effectively read-only for the
115     lifetime of this object.
116     **/

117     public OpenBTree btree;
118
119     /**
120     The resulting slot from the search. Updated when the search completes.
121     **/

122     public int resultSlot;
123
124     /**
125     Whether the row found exactly matched the searchKey. Updated
126     when the search completes.
127     **/

128     public boolean resultExact;
129
130     /**
131     Whether the search is for the optimizer, to determine range of scan.
132     **/

133     public boolean searchForOptimizer;
134
135     /**
136     If this is an optimizer search, the fraction of rows that are left of
137     the current search. When the search completes this number multiplied by
138     the number of leaf rows in the table is the number of rows left of
139     the result slot in the search.
140     **/

141     public float left_fraction;
142
143     /**
144     If this is an optimizer search, the fraction of rows that are "in" the
145     the current search. This number is used as we descend down the tree to
146     track the percentage of rows that we think are in the current subtree
147     defined by all leaf's that can be reached from the current branch.
148     **/

149     public float current_fraction;
150
151     /**
152     Construct search parameters.
153
154     @exception StandardException Standard exception policy.
155     **/

156     public SearchParameters(
157     DataValueDescriptor[] searchKey,
158     int partial_key_match_op,
159     DataValueDescriptor[] template,
160     OpenBTree btree,
161     boolean searchForOptimizer)
162         throws StandardException
163     {
164         this.searchKey = searchKey;
165         this.partial_key_match_op = partial_key_match_op;
166         this.template = template;
167         this.btree = btree;
168         this.resultSlot = 0;
169         this.resultExact = false;
170         this.searchForOptimizer = searchForOptimizer;
171
172         if (this.searchForOptimizer)
173         {
174             this.left_fraction = 0;
175             this.current_fraction = 1;
176         }
177
178         if (SanityManager.DEBUG)
179         {
180             // RESOLVE - this is ugly but has caught some problems.
181
SanityManager.ASSERT(partial_key_match_op == -1||
182                                  partial_key_match_op == 1);
183         }
184     }
185
186     public String JavaDoc toString()
187     {
188         if (SanityManager.DEBUG)
189         {
190             String JavaDoc string =
191                 "key = " + RowUtil.toString(searchKey) + ";" +
192                 "op = " + (partial_key_match_op == 1 ? "GE" :
193                                   (partial_key_match_op == -1 ? "GT" :
194                                    "BAD OP:" + partial_key_match_op)) + ";" +
195                 "template = " + RowUtil.toString(template) + ";" +
196                 // RESOLVE (mikem) - do we want to print out btree?
197
// "btree = " + btree + ";" +
198
"Slot = " + resultSlot + ";" +
199                 "Exact = " + resultExact + ";";
200
201             return(string);
202         }
203         else
204         {
205             return(null);
206         }
207     }
208 }
209
Popular Tags