File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\index\Index.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.index;
8
9 import org.h2.engine.Session;
10 import org.h2.result.Row;
11 import org.h2.result.SearchRow;
12 import org.h2.schema.SchemaObject;
13 import org.h2.table.Column;
14 import org.h2.table.IndexColumn;
15 import org.h2.table.Table;
16 import org.h2.table.TableFilter;
17
18 /**
19 * An index. Indexes are used to speed up searching data.
20 */
21 public interface Index extends SchemaObject {
22
23 /**
24 * Get the message to show in a EXPLAIN statement.
25 *
26 * @return the plan
27 */
28 String getPlanSQL();
29
30 /**
31 * Close this index.
32 *
33 * @param session the session used to write data
34 */
35 void close(Session session);
36
37 /**
38 * Add a row to the index.
39 *
40 * @param session the session to use
41 * @param row the row to add
42 */
43 void add(Session session, Row row);
44
45 /**
46 * Remove a row from the index.
47 *
48 * @param session the session
49 * @param row the row
50 */
51 void remove(Session session, Row row);
52
53 /**
54 * Find a row or a list of rows and create a cursor to iterate over the result.
55 *
56 * @param session the session
57 * @param first the first row, or null for no limit
58 * @param last the last row, or null for no limit
59 * @return the cursor to iterate over the results
60 */
61 Cursor find(Session session, SearchRow first, SearchRow last);
62
63 /**
64 * Find a row or a list of rows and create a cursor to iterate over the result.
65 *
66 * @param filter the table filter (which possibly knows
67 * about additional conditions)
68 * @param first the first row, or null for no limit
69 * @param last the last row, or null for no limit
70 * @return the cursor to iterate over the results
71 */
72 Cursor find(TableFilter filter, SearchRow first, SearchRow last);
73
74 /**
75 * Estimate the cost to search for rows given the search mask.
76 * There is one element per column in the search mask.
77 * For possible search masks, see IndexCondition.
78 *
79 * @param session the session
80 * @param masks the search mask
81 * @return the estimated cost
82 */
83 double getCost(Session session, int[] masks);
84
85 /**
86 * Remove the index.
87 *
88 * @param session the session
89 */
90 void remove(Session session);
91
92 /**
93 * Remove all rows from the index.
94 *
95 * @param session the session
96 */
97 void truncate(Session session);
98
99 /**
100 * Check if the index can directly look up the lowest or highest value of a
101 * column.
102 *
103 * @return true if it can
104 */
105 boolean canGetFirstOrLast();
106
107 /**
108 * Check if the index can get the next higher value.
109 *
110 * @return true if it can
111 */
112 boolean canFindNext();
113
114 /**
115 * Find a row or a list of rows that is larger and create a cursor to
116 * iterate over the result.
117 *
118 * @param session the session
119 * @param higherThan the lower limit (excluding)
120 * @param last the last row, or null for no limit
121 * @return the cursor
122 */
123 Cursor findNext(Session session, SearchRow higherThan, SearchRow last);
124
125 /**
126 * Find the first (or last) value of this index. The cursor returned is
127 * positioned on the correct row, or on null if no row has been found.
128 *
129 * @param session the session
130 * @param first true if the first (lowest for ascending indexes) or last
131 * value should be returned
132 * @return a cursor (never null)
133 */
134 Cursor findFirstOrLast(Session session, boolean first);
135
136 /**
137 * Check if the index needs to be rebuilt.
138 * This method is called after opening an index.
139 *
140 * @return true if a rebuild is required.
141 */
142 boolean needRebuild();
143
144 /**
145 * Get the row count of this table, for the given session.
146 *
147 * @param session the session
148 * @return the row count
149 */
150 long getRowCount(Session session);
151
152 /**
153 * Get the approximated row count for this table.
154 *
155 * @return the approximated row count
156 */
157 long getRowCountApproximation();
158
159 /**
160 * Compare two rows.
161 *
162 * @param rowData the first row
163 * @param compare the second row
164 * @return 0 if both rows are equal, -1 if the first row is smaller, otherwise 1
165 */
166 int compareRows(SearchRow rowData, SearchRow compare);
167
168 /**
169 * Get the index of a column in the list of index columns
170 *
171 * @param col the column
172 * @return the index (0 meaning first column)
173 */
174 int getColumnIndex(Column col);
175
176 /**
177 * Get the indexed columns as index columns (with ordering information).
178 *
179 * @return the index columns
180 */
181 IndexColumn[] getIndexColumns();
182
183 /**
184 * Get the indexed columns.
185 *
186 * @return the columns
187 */
188 Column[] getColumns();
189
190 /**
191 * Get the index type.
192 *
193 * @return the index type
194 */
195 IndexType getIndexType();
196
197 /**
198 * Get the table on which this index is based.
199 *
200 * @return the table
201 */
202 Table getTable();
203
204 /**
205 * Commit the operation for a row. This is only important for multi-version
206 * indexes.
207 *
208 * @param operation the operation type
209 * @param row the row
210 */
211 void commit(int operation, Row row);
212
213 /**
214 * Get the row with the given key.
215 *
216 * @param session the session
217 * @param key the unique key
218 * @return the row
219 */
220 Row getRow(Session session, long key);
221
222 /**
223 * Does this index support lookup by row id?
224 *
225 * @return true if it does
226 */
227 boolean isRowIdIndex();
228
229 /**
230 * Can this index iterate over all rows?
231 *
232 * @return true if it can
233 */
234 boolean canScan();
235
236 /**
237 * Enable or disable the 'sorted insert' optimizations (rows are inserted in
238 * ascending or descending order) if applicable for this index
239 * implementation.
240 *
241 * @param sortedInsertMode the new value
242 */
243 void setSortedInsertMode(boolean sortedInsertMode);
244
245 }
246