Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: third_party/sqlite/src/ext/fts3/fts3Int.h

Issue 5626002: Update sqlite to 3.7.3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/third_party/sqlite/src
Patch Set: Remove misc change. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/sqlite/src/ext/fts3/fts3.c ('k') | third_party/sqlite/src/ext/fts3/fts3_expr.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 ** 2009 Nov 12
3 **
4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
6 **
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
10 **
11 ******************************************************************************
12 **
13 */
14
15 #ifndef _FTSINT_H
16 #define _FTSINT_H
17
18 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
19 # define NDEBUG 1
20 #endif
21
22 #include "sqlite3.h"
23 #include "fts3_tokenizer.h"
24 #include "fts3_hash.h"
25
26 /*
27 ** This constant controls how often segments are merged. Once there are
28 ** FTS3_MERGE_COUNT segments of level N, they are merged into a single
29 ** segment of level N+1.
30 */
31 #define FTS3_MERGE_COUNT 16
32
33 /*
34 ** This is the maximum amount of data (in bytes) to store in the
35 ** Fts3Table.pendingTerms hash table. Normally, the hash table is
36 ** populated as documents are inserted/updated/deleted in a transaction
37 ** and used to create a new segment when the transaction is committed.
38 ** However if this limit is reached midway through a transaction, a new
39 ** segment is created and the hash table cleared immediately.
40 */
41 #define FTS3_MAX_PENDING_DATA (1*1024*1024)
42
43 /*
44 ** Macro to return the number of elements in an array. SQLite has a
45 ** similar macro called ArraySize(). Use a different name to avoid
46 ** a collision when building an amalgamation with built-in FTS3.
47 */
48 #define SizeofArray(X) ((int)(sizeof(X)/sizeof(X[0])))
49
50 /*
51 ** Maximum length of a varint encoded integer. The varint format is different
52 ** from that used by SQLite, so the maximum length is 10, not 9.
53 */
54 #define FTS3_VARINT_MAX 10
55
56 /*
57 ** The testcase() macro is only used by the amalgamation. If undefined,
58 ** make it a no-op.
59 */
60 #ifndef testcase
61 # define testcase(X)
62 #endif
63
64 /*
65 ** Terminator values for position-lists and column-lists.
66 */
67 #define POS_COLUMN (1) /* Column-list terminator */
68 #define POS_END (0) /* Position-list terminator */
69
70 /*
71 ** This section provides definitions to allow the
72 ** FTS3 extension to be compiled outside of the
73 ** amalgamation.
74 */
75 #ifndef SQLITE_AMALGAMATION
76 /*
77 ** Macros indicating that conditional expressions are always true or
78 ** false.
79 */
80 # define ALWAYS(x) (x)
81 # define NEVER(X) (x)
82 /*
83 ** Internal types used by SQLite.
84 */
85 typedef unsigned char u8; /* 1-byte (or larger) unsigned integer */
86 typedef short int i16; /* 2-byte (or larger) signed integer */
87 typedef unsigned int u32; /* 4-byte unsigned integer */
88 typedef sqlite3_uint64 u64; /* 8-byte unsigned integer */
89 /*
90 ** Macro used to suppress compiler warnings for unused parameters.
91 */
92 #define UNUSED_PARAMETER(x) (void)(x)
93 #endif
94
95 typedef struct Fts3Table Fts3Table;
96 typedef struct Fts3Cursor Fts3Cursor;
97 typedef struct Fts3Expr Fts3Expr;
98 typedef struct Fts3Phrase Fts3Phrase;
99 typedef struct Fts3SegReader Fts3SegReader;
100 typedef struct Fts3SegFilter Fts3SegFilter;
101
102 /*
103 ** A connection to a fulltext index is an instance of the following
104 ** structure. The xCreate and xConnect methods create an instance
105 ** of this structure and xDestroy and xDisconnect free that instance.
106 ** All other methods receive a pointer to the structure as one of their
107 ** arguments.
108 */
109 struct Fts3Table {
110 sqlite3_vtab base; /* Base class used by SQLite core */
111 sqlite3 *db; /* The database connection */
112 const char *zDb; /* logical database name */
113 const char *zName; /* virtual table name */
114 int nColumn; /* number of named columns in virtual table */
115 char **azColumn; /* column names. malloced */
116 sqlite3_tokenizer *pTokenizer; /* tokenizer for inserts and queries */
117
118 /* Precompiled statements used by the implementation. Each of these
119 ** statements is run and reset within a single virtual table API call.
120 */
121 sqlite3_stmt *aStmt[25];
122
123 /* Pointer to string containing the SQL:
124 **
125 ** "SELECT block FROM %_segments WHERE blockid BETWEEN ? AND ?
126 ** ORDER BY blockid"
127 */
128 char *zSelectLeaves;
129 int nLeavesStmt; /* Valid statements in aLeavesStmt */
130 int nLeavesTotal; /* Total number of prepared leaves stmts */
131 int nLeavesAlloc; /* Allocated size of aLeavesStmt */
132 sqlite3_stmt **aLeavesStmt; /* Array of prepared zSelectLeaves stmts */
133
134 int nNodeSize; /* Soft limit for node size */
135 u8 bHasContent; /* True if %_content table exists */
136 u8 bHasDocsize; /* True if %_docsize table exists */
137
138 /* The following hash table is used to buffer pending index updates during
139 ** transactions. Variable nPendingData estimates the memory size of the
140 ** pending data, including hash table overhead, but not malloc overhead.
141 ** When nPendingData exceeds nMaxPendingData, the buffer is flushed
142 ** automatically. Variable iPrevDocid is the docid of the most recently
143 ** inserted record.
144 */
145 int nMaxPendingData;
146 int nPendingData;
147 sqlite_int64 iPrevDocid;
148 Fts3Hash pendingTerms;
149 };
150
151 /*
152 ** When the core wants to read from the virtual table, it creates a
153 ** virtual table cursor (an instance of the following structure) using
154 ** the xOpen method. Cursors are destroyed using the xClose method.
155 */
156 struct Fts3Cursor {
157 sqlite3_vtab_cursor base; /* Base class used by SQLite core */
158 i16 eSearch; /* Search strategy (see below) */
159 u8 isEof; /* True if at End Of Results */
160 u8 isRequireSeek; /* True if must seek pStmt to %_content row */
161 sqlite3_stmt *pStmt; /* Prepared statement in use by the cursor */
162 Fts3Expr *pExpr; /* Parsed MATCH query string */
163 sqlite3_int64 iPrevId; /* Previous id read from aDoclist */
164 char *pNextId; /* Pointer into the body of aDoclist */
165 char *aDoclist; /* List of docids for full-text queries */
166 int nDoclist; /* Size of buffer at aDoclist */
167 int isMatchinfoNeeded; /* True when aMatchinfo[] needs filling in */
168 u32 *aMatchinfo; /* Information about most recent match */
169 };
170
171 /*
172 ** The Fts3Cursor.eSearch member is always set to one of the following.
173 ** Actualy, Fts3Cursor.eSearch can be greater than or equal to
174 ** FTS3_FULLTEXT_SEARCH. If so, then Fts3Cursor.eSearch - 2 is the index
175 ** of the column to be searched. For example, in
176 **
177 ** CREATE VIRTUAL TABLE ex1 USING fts3(a,b,c,d);
178 ** SELECT docid FROM ex1 WHERE b MATCH 'one two three';
179 **
180 ** Because the LHS of the MATCH operator is 2nd column "b",
181 ** Fts3Cursor.eSearch will be set to FTS3_FULLTEXT_SEARCH+1. (+0 for a,
182 ** +1 for b, +2 for c, +3 for d.) If the LHS of MATCH were "ex1"
183 ** indicating that all columns should be searched,
184 ** then eSearch would be set to FTS3_FULLTEXT_SEARCH+4.
185 */
186 #define FTS3_FULLSCAN_SEARCH 0 /* Linear scan of %_content table */
187 #define FTS3_DOCID_SEARCH 1 /* Lookup by rowid on %_content table */
188 #define FTS3_FULLTEXT_SEARCH 2 /* Full-text index search */
189
190 /*
191 ** A "phrase" is a sequence of one or more tokens that must match in
192 ** sequence. A single token is the base case and the most common case.
193 ** For a sequence of tokens contained in "...", nToken will be the number
194 ** of tokens in the string.
195 */
196 struct Fts3Phrase {
197 int nToken; /* Number of tokens in the phrase */
198 int iColumn; /* Index of column this phrase must match */
199 int isNot; /* Phrase prefixed by unary not (-) operator */
200 struct PhraseToken {
201 char *z; /* Text of the token */
202 int n; /* Number of bytes in buffer pointed to by z */
203 int isPrefix; /* True if token ends in with a "*" character */
204 } aToken[1]; /* One entry for each token in the phrase */
205 };
206
207 /*
208 ** A tree of these objects forms the RHS of a MATCH operator.
209 **
210 ** If Fts3Expr.eType is either FTSQUERY_NEAR or FTSQUERY_PHRASE and isLoaded
211 ** is true, then aDoclist points to a malloced buffer, size nDoclist bytes,
212 ** containing the results of the NEAR or phrase query in FTS3 doclist
213 ** format. As usual, the initial "Length" field found in doclists stored
214 ** on disk is omitted from this buffer.
215 **
216 ** Variable pCurrent always points to the start of a docid field within
217 ** aDoclist. Since the doclist is usually scanned in docid order, this can
218 ** be used to accelerate seeking to the required docid within the doclist.
219 */
220 struct Fts3Expr {
221 int eType; /* One of the FTSQUERY_XXX values defined below */
222 int nNear; /* Valid if eType==FTSQUERY_NEAR */
223 Fts3Expr *pParent; /* pParent->pLeft==this or pParent->pRight==this */
224 Fts3Expr *pLeft; /* Left operand */
225 Fts3Expr *pRight; /* Right operand */
226 Fts3Phrase *pPhrase; /* Valid if eType==FTSQUERY_PHRASE */
227
228 int isLoaded; /* True if aDoclist/nDoclist are initialized. */
229 char *aDoclist; /* Buffer containing doclist */
230 int nDoclist; /* Size of aDoclist in bytes */
231
232 sqlite3_int64 iCurrent;
233 char *pCurrent;
234 };
235
236 /*
237 ** Candidate values for Fts3Query.eType. Note that the order of the first
238 ** four values is in order of precedence when parsing expressions. For
239 ** example, the following:
240 **
241 ** "a OR b AND c NOT d NEAR e"
242 **
243 ** is equivalent to:
244 **
245 ** "a OR (b AND (c NOT (d NEAR e)))"
246 */
247 #define FTSQUERY_NEAR 1
248 #define FTSQUERY_NOT 2
249 #define FTSQUERY_AND 3
250 #define FTSQUERY_OR 4
251 #define FTSQUERY_PHRASE 5
252
253
254 /* fts3_init.c */
255 int sqlite3Fts3DeleteVtab(int, sqlite3_vtab *);
256 int sqlite3Fts3InitVtab(int, sqlite3*, void*, int, const char*const*,
257 sqlite3_vtab **, char **);
258
259 /* fts3_write.c */
260 int sqlite3Fts3UpdateMethod(sqlite3_vtab*,int,sqlite3_value**,sqlite3_int64*);
261 int sqlite3Fts3PendingTermsFlush(Fts3Table *);
262 void sqlite3Fts3PendingTermsClear(Fts3Table *);
263 int sqlite3Fts3Optimize(Fts3Table *);
264 int sqlite3Fts3SegReaderNew(Fts3Table *,int, sqlite3_int64,
265 sqlite3_int64, sqlite3_int64, const char *, int, Fts3SegReader**);
266 int sqlite3Fts3SegReaderPending(Fts3Table*,const char*,int,int,Fts3SegReader**);
267 void sqlite3Fts3SegReaderFree(Fts3Table *, Fts3SegReader *);
268 int sqlite3Fts3SegReaderIterate(
269 Fts3Table *, Fts3SegReader **, int, Fts3SegFilter *,
270 int (*)(Fts3Table *, void *, char *, int, char *, int), void *
271 );
272 int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char const**, int*);
273 int sqlite3Fts3AllSegdirs(Fts3Table*, sqlite3_stmt **);
274 int sqlite3Fts3MatchinfoDocsizeLocal(Fts3Cursor*, u32*);
275 int sqlite3Fts3MatchinfoDocsizeGlobal(Fts3Cursor*, u32*);
276 int sqlite3Fts3ReadLock(Fts3Table *);
277
278 /* Flags allowed as part of the 4th argument to SegmentReaderIterate() */
279 #define FTS3_SEGMENT_REQUIRE_POS 0x00000001
280 #define FTS3_SEGMENT_IGNORE_EMPTY 0x00000002
281 #define FTS3_SEGMENT_COLUMN_FILTER 0x00000004
282 #define FTS3_SEGMENT_PREFIX 0x00000008
283
284 /* Type passed as 4th argument to SegmentReaderIterate() */
285 struct Fts3SegFilter {
286 const char *zTerm;
287 int nTerm;
288 int iCol;
289 int flags;
290 };
291
292 /* fts3.c */
293 int sqlite3Fts3PutVarint(char *, sqlite3_int64);
294 int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
295 int sqlite3Fts3GetVarint32(const char *, int *);
296 int sqlite3Fts3VarintLen(sqlite3_uint64);
297 void sqlite3Fts3Dequote(char *);
298
299 char *sqlite3Fts3FindPositions(Fts3Expr *, sqlite3_int64, int);
300 int sqlite3Fts3ExprLoadDoclist(Fts3Table *, Fts3Expr *);
301 int sqlite3Fts3ExprNearTrim(Fts3Expr *, Fts3Expr *, int);
302
303 /* fts3_tokenizer.c */
304 const char *sqlite3Fts3NextToken(const char *, int *);
305 int sqlite3Fts3InitHashTable(sqlite3 *, Fts3Hash *, const char *);
306 int sqlite3Fts3InitTokenizer(Fts3Hash *pHash,
307 const char *, sqlite3_tokenizer **, const char **, char **
308 );
309
310 /* fts3_snippet.c */
311 void sqlite3Fts3Offsets(sqlite3_context*, Fts3Cursor*);
312 void sqlite3Fts3Snippet(sqlite3_context *, Fts3Cursor *, const char *,
313 const char *, const char *, int, int
314 );
315 void sqlite3Fts3Matchinfo(sqlite3_context *, Fts3Cursor *);
316
317 /* fts3_expr.c */
318 int sqlite3Fts3ExprParse(sqlite3_tokenizer *,
319 char **, int, int, const char *, int, Fts3Expr **
320 );
321 void sqlite3Fts3ExprFree(Fts3Expr *);
322 #ifdef SQLITE_TEST
323 int sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
324 #endif
325
326 #endif /* _FTSINT_H */
OLDNEW
« no previous file with comments | « third_party/sqlite/src/ext/fts3/fts3.c ('k') | third_party/sqlite/src/ext/fts3/fts3_expr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698