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

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

Issue 901033002: Import SQLite 3.8.7.4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chromium changes to support SQLite 3.8.7.4. Created 5 years, 10 months 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
OLDNEW
1 /* 1 /*
2 ** 2009 Nov 12 2 ** 2009 Nov 12
3 ** 3 **
4 ** The author disclaims copyright to this source code. In place of 4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing: 5 ** a legal notice, here is a blessing:
6 ** 6 **
7 ** May you do good and not evil. 7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others. 8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give. 9 ** May you share freely, never taking more than you give.
10 ** 10 **
11 ****************************************************************************** 11 ******************************************************************************
12 ** 12 **
13 */ 13 */
14
15 #ifndef _FTSINT_H 14 #ifndef _FTSINT_H
16 #define _FTSINT_H 15 #define _FTSINT_H
17 16
18 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG) 17 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
19 # define NDEBUG 1 18 # define NDEBUG 1
20 #endif 19 #endif
21 20
21 /*
22 ** FTS4 is really an extension for FTS3. It is enabled using the
23 ** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also all
24 ** the SQLITE_ENABLE_FTS4 macro to serve as an alisse for SQLITE_ENABLE_FTS3.
25 */
26 #if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3)
27 # define SQLITE_ENABLE_FTS3
28 #endif
29
30 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
31
32 /* If not building as part of the core, include sqlite3ext.h. */
33 #ifndef SQLITE_CORE
34 # include "sqlite3ext.h"
35 SQLITE_EXTENSION_INIT3
36 #endif
37
22 #include "sqlite3.h" 38 #include "sqlite3.h"
23 #include "fts3_tokenizer.h" 39 #include "fts3_tokenizer.h"
24 #include "fts3_hash.h" 40 #include "fts3_hash.h"
25 41
26 /* 42 /*
43 ** This constant determines the maximum depth of an FTS expression tree
44 ** that the library will create and use. FTS uses recursion to perform
45 ** various operations on the query tree, so the disadvantage of a large
46 ** limit is that it may allow very large queries to use large amounts
47 ** of stack space (perhaps causing a stack overflow).
48 */
49 #ifndef SQLITE_FTS3_MAX_EXPR_DEPTH
50 # define SQLITE_FTS3_MAX_EXPR_DEPTH 12
51 #endif
52
53
54 /*
27 ** This constant controls how often segments are merged. Once there are 55 ** 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 56 ** FTS3_MERGE_COUNT segments of level N, they are merged into a single
29 ** segment of level N+1. 57 ** segment of level N+1.
30 */ 58 */
31 #define FTS3_MERGE_COUNT 16 59 #define FTS3_MERGE_COUNT 16
32 60
33 /* 61 /*
34 ** This is the maximum amount of data (in bytes) to store in the 62 ** This is the maximum amount of data (in bytes) to store in the
35 ** Fts3Table.pendingTerms hash table. Normally, the hash table is 63 ** Fts3Table.pendingTerms hash table. Normally, the hash table is
36 ** populated as documents are inserted/updated/deleted in a transaction 64 ** populated as documents are inserted/updated/deleted in a transaction
37 ** and used to create a new segment when the transaction is committed. 65 ** 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 66 ** However if this limit is reached midway through a transaction, a new
39 ** segment is created and the hash table cleared immediately. 67 ** segment is created and the hash table cleared immediately.
40 */ 68 */
41 #define FTS3_MAX_PENDING_DATA (1*1024*1024) 69 #define FTS3_MAX_PENDING_DATA (1*1024*1024)
42 70
43 /* 71 /*
44 ** Macro to return the number of elements in an array. SQLite has a 72 ** Macro to return the number of elements in an array. SQLite has a
45 ** similar macro called ArraySize(). Use a different name to avoid 73 ** similar macro called ArraySize(). Use a different name to avoid
46 ** a collision when building an amalgamation with built-in FTS3. 74 ** a collision when building an amalgamation with built-in FTS3.
47 */ 75 */
48 #define SizeofArray(X) ((int)(sizeof(X)/sizeof(X[0]))) 76 #define SizeofArray(X) ((int)(sizeof(X)/sizeof(X[0])))
49 77
78
79 #ifndef MIN
80 # define MIN(x,y) ((x)<(y)?(x):(y))
81 #endif
82 #ifndef MAX
83 # define MAX(x,y) ((x)>(y)?(x):(y))
84 #endif
85
50 /* 86 /*
51 ** Maximum length of a varint encoded integer. The varint format is different 87 ** 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. 88 ** from that used by SQLite, so the maximum length is 10, not 9.
53 */ 89 */
54 #define FTS3_VARINT_MAX 10 90 #define FTS3_VARINT_MAX 10
55 91
56 /* 92 /*
93 ** FTS4 virtual tables may maintain multiple indexes - one index of all terms
94 ** in the document set and zero or more prefix indexes. All indexes are stored
95 ** as one or more b+-trees in the %_segments and %_segdir tables.
96 **
97 ** It is possible to determine which index a b+-tree belongs to based on the
98 ** value stored in the "%_segdir.level" column. Given this value L, the index
99 ** that the b+-tree belongs to is (L<<10). In other words, all b+-trees with
100 ** level values between 0 and 1023 (inclusive) belong to index 0, all levels
101 ** between 1024 and 2047 to index 1, and so on.
102 **
103 ** It is considered impossible for an index to use more than 1024 levels. In
104 ** theory though this may happen, but only after at least
105 ** (FTS3_MERGE_COUNT^1024) separate flushes of the pending-terms tables.
106 */
107 #define FTS3_SEGDIR_MAXLEVEL 1024
108 #define FTS3_SEGDIR_MAXLEVEL_STR "1024"
109
110 /*
57 ** The testcase() macro is only used by the amalgamation. If undefined, 111 ** The testcase() macro is only used by the amalgamation. If undefined,
58 ** make it a no-op. 112 ** make it a no-op.
59 */ 113 */
60 #ifndef testcase 114 #ifndef testcase
61 # define testcase(X) 115 # define testcase(X)
62 #endif 116 #endif
63 117
64 /* 118 /*
65 ** Terminator values for position-lists and column-lists. 119 ** Terminator values for position-lists and column-lists.
66 */ 120 */
67 #define POS_COLUMN (1) /* Column-list terminator */ 121 #define POS_COLUMN (1) /* Column-list terminator */
68 #define POS_END (0) /* Position-list terminator */ 122 #define POS_END (0) /* Position-list terminator */
69 123
70 /* 124 /*
71 ** This section provides definitions to allow the 125 ** This section provides definitions to allow the
72 ** FTS3 extension to be compiled outside of the 126 ** FTS3 extension to be compiled outside of the
73 ** amalgamation. 127 ** amalgamation.
74 */ 128 */
75 #ifndef SQLITE_AMALGAMATION 129 #ifndef SQLITE_AMALGAMATION
76 /* 130 /*
77 ** Macros indicating that conditional expressions are always true or 131 ** Macros indicating that conditional expressions are always true or
78 ** false. 132 ** false.
79 */ 133 */
80 #ifdef SQLITE_COVERAGE_TEST 134 #ifdef SQLITE_COVERAGE_TEST
81 # define ALWAYS(x) (1) 135 # define ALWAYS(x) (1)
82 # define NEVER(X) (0) 136 # define NEVER(X) (0)
83 #else 137 #else
84 # define ALWAYS(x) (x) 138 # define ALWAYS(x) (x)
85 # define NEVER(X) (x) 139 # define NEVER(x) (x)
86 #endif 140 #endif
87 141
88 /* 142 /*
89 ** Internal types used by SQLite. 143 ** Internal types used by SQLite.
90 */ 144 */
91 typedef unsigned char u8; /* 1-byte (or larger) unsigned integer */ 145 typedef unsigned char u8; /* 1-byte (or larger) unsigned integer */
92 typedef short int i16; /* 2-byte (or larger) signed integer */ 146 typedef short int i16; /* 2-byte (or larger) signed integer */
93 typedef unsigned int u32; /* 4-byte unsigned integer */ 147 typedef unsigned int u32; /* 4-byte unsigned integer */
94 typedef sqlite3_uint64 u64; /* 8-byte unsigned integer */ 148 typedef sqlite3_uint64 u64; /* 8-byte unsigned integer */
149 typedef sqlite3_int64 i64; /* 8-byte signed integer */
150
95 /* 151 /*
96 ** Macro used to suppress compiler warnings for unused parameters. 152 ** Macro used to suppress compiler warnings for unused parameters.
97 */ 153 */
98 #define UNUSED_PARAMETER(x) (void)(x) 154 #define UNUSED_PARAMETER(x) (void)(x)
155
156 /*
157 ** Activate assert() only if SQLITE_TEST is enabled.
158 */
159 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
160 # define NDEBUG 1
161 #endif
162
163 /*
164 ** The TESTONLY macro is used to enclose variable declarations or
165 ** other bits of code that are needed to support the arguments
166 ** within testcase() and assert() macros.
167 */
168 #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
169 # define TESTONLY(X) X
170 #else
171 # define TESTONLY(X)
172 #endif
173
174 #endif /* SQLITE_AMALGAMATION */
175
176 #ifdef SQLITE_DEBUG
177 int sqlite3Fts3Corrupt(void);
178 # define FTS_CORRUPT_VTAB sqlite3Fts3Corrupt()
179 #else
180 # define FTS_CORRUPT_VTAB SQLITE_CORRUPT_VTAB
99 #endif 181 #endif
100 182
101 typedef struct Fts3Table Fts3Table; 183 typedef struct Fts3Table Fts3Table;
102 typedef struct Fts3Cursor Fts3Cursor; 184 typedef struct Fts3Cursor Fts3Cursor;
103 typedef struct Fts3Expr Fts3Expr; 185 typedef struct Fts3Expr Fts3Expr;
104 typedef struct Fts3Phrase Fts3Phrase; 186 typedef struct Fts3Phrase Fts3Phrase;
105 typedef struct Fts3PhraseToken Fts3PhraseToken; 187 typedef struct Fts3PhraseToken Fts3PhraseToken;
106 188
189 typedef struct Fts3Doclist Fts3Doclist;
107 typedef struct Fts3SegFilter Fts3SegFilter; 190 typedef struct Fts3SegFilter Fts3SegFilter;
108 typedef struct Fts3DeferredToken Fts3DeferredToken; 191 typedef struct Fts3DeferredToken Fts3DeferredToken;
109 typedef struct Fts3SegReader Fts3SegReader; 192 typedef struct Fts3SegReader Fts3SegReader;
110 typedef struct Fts3SegReaderCursor Fts3SegReaderCursor; 193 typedef struct Fts3MultiSegReader Fts3MultiSegReader;
111 194
112 /* 195 /*
113 ** A connection to a fulltext index is an instance of the following 196 ** A connection to a fulltext index is an instance of the following
114 ** structure. The xCreate and xConnect methods create an instance 197 ** structure. The xCreate and xConnect methods create an instance
115 ** of this structure and xDestroy and xDisconnect free that instance. 198 ** of this structure and xDestroy and xDisconnect free that instance.
116 ** All other methods receive a pointer to the structure as one of their 199 ** All other methods receive a pointer to the structure as one of their
117 ** arguments. 200 ** arguments.
118 */ 201 */
119 struct Fts3Table { 202 struct Fts3Table {
120 sqlite3_vtab base; /* Base class used by SQLite core */ 203 sqlite3_vtab base; /* Base class used by SQLite core */
121 sqlite3 *db; /* The database connection */ 204 sqlite3 *db; /* The database connection */
122 const char *zDb; /* logical database name */ 205 const char *zDb; /* logical database name */
123 const char *zName; /* virtual table name */ 206 const char *zName; /* virtual table name */
124 int nColumn; /* number of named columns in virtual table */ 207 int nColumn; /* number of named columns in virtual table */
125 char **azColumn; /* column names. malloced */ 208 char **azColumn; /* column names. malloced */
209 u8 *abNotindexed; /* True for 'notindexed' columns */
126 sqlite3_tokenizer *pTokenizer; /* tokenizer for inserts and queries */ 210 sqlite3_tokenizer *pTokenizer; /* tokenizer for inserts and queries */
211 char *zContentTbl; /* content=xxx option, or NULL */
212 char *zLanguageid; /* languageid=xxx option, or NULL */
213 int nAutoincrmerge; /* Value configured by 'automerge' */
214 u32 nLeafAdd; /* Number of leaf blocks added this trans */
127 215
128 /* Precompiled statements used by the implementation. Each of these 216 /* Precompiled statements used by the implementation. Each of these
129 ** statements is run and reset within a single virtual table API call. 217 ** statements is run and reset within a single virtual table API call.
130 */ 218 */
131 sqlite3_stmt *aStmt[24]; 219 sqlite3_stmt *aStmt[40];
132 220
133 char *zReadExprlist; 221 char *zReadExprlist;
134 char *zWriteExprlist; 222 char *zWriteExprlist;
135 223
136 int nNodeSize; /* Soft limit for node size */ 224 int nNodeSize; /* Soft limit for node size */
137 u8 bHasStat; /* True if %_stat table exists */ 225 u8 bFts4; /* True for FTS4, false for FTS3 */
226 u8 bHasStat; /* True if %_stat table exists (2==unknown) */
138 u8 bHasDocsize; /* True if %_docsize table exists */ 227 u8 bHasDocsize; /* True if %_docsize table exists */
228 u8 bDescIdx; /* True if doclists are in reverse order */
229 u8 bIgnoreSavepoint; /* True to ignore xSavepoint invocations */
139 int nPgsz; /* Page size for host database */ 230 int nPgsz; /* Page size for host database */
140 char *zSegmentsTbl; /* Name of %_segments table */ 231 char *zSegmentsTbl; /* Name of %_segments table */
141 sqlite3_blob *pSegments; /* Blob handle open on %_segments table */ 232 sqlite3_blob *pSegments; /* Blob handle open on %_segments table */
142 233
143 /* The following hash table is used to buffer pending index updates during 234 /*
144 ** transactions. Variable nPendingData estimates the memory size of the 235 ** The following array of hash tables is used to buffer pending index
145 ** pending data, including hash table overhead, but not malloc overhead. 236 ** updates during transactions. All pending updates buffered at any one
146 ** When nPendingData exceeds nMaxPendingData, the buffer is flushed 237 ** time must share a common language-id (see the FTS4 langid= feature).
147 ** automatically. Variable iPrevDocid is the docid of the most recently 238 ** The current language id is stored in variable iPrevLangid.
148 ** inserted record. 239 **
240 ** A single FTS4 table may have multiple full-text indexes. For each index
241 ** there is an entry in the aIndex[] array. Index 0 is an index of all the
242 ** terms that appear in the document set. Each subsequent index in aIndex[]
243 ** is an index of prefixes of a specific length.
244 **
245 ** Variable nPendingData contains an estimate the memory consumed by the
246 ** pending data structures, including hash table overhead, but not including
247 ** malloc overhead. When nPendingData exceeds nMaxPendingData, all hash
248 ** tables are flushed to disk. Variable iPrevDocid is the docid of the most
249 ** recently inserted record.
149 */ 250 */
150 int nMaxPendingData; 251 int nIndex; /* Size of aIndex[] */
151 int nPendingData; 252 struct Fts3Index {
152 sqlite_int64 iPrevDocid; 253 int nPrefix; /* Prefix length (0 for main terms index) */
153 Fts3Hash pendingTerms; 254 Fts3Hash hPending; /* Pending terms table for this index */
255 } *aIndex;
256 int nMaxPendingData; /* Max pending data before flush to disk */
257 int nPendingData; /* Current bytes of pending data */
258 sqlite_int64 iPrevDocid; /* Docid of most recently inserted document */
259 int iPrevLangid; /* Langid of recently inserted document */
260
261 #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
262 /* State variables used for validating that the transaction control
263 ** methods of the virtual table are called at appropriate times. These
264 ** values do not contribute to FTS functionality; they are used for
265 ** verifying the operation of the SQLite core.
266 */
267 int inTransaction; /* True after xBegin but before xCommit/xRollback */
268 int mxSavepoint; /* Largest valid xSavepoint integer */
269 #endif
270
271 #ifdef SQLITE_TEST
272 /* True to disable the incremental doclist optimization. This is controled
273 ** by special insert command 'test-no-incr-doclist'. */
274 int bNoIncrDoclist;
275 #endif
154 }; 276 };
155 277
156 /* 278 /*
157 ** When the core wants to read from the virtual table, it creates a 279 ** When the core wants to read from the virtual table, it creates a
158 ** virtual table cursor (an instance of the following structure) using 280 ** virtual table cursor (an instance of the following structure) using
159 ** the xOpen method. Cursors are destroyed using the xClose method. 281 ** the xOpen method. Cursors are destroyed using the xClose method.
160 */ 282 */
161 struct Fts3Cursor { 283 struct Fts3Cursor {
162 sqlite3_vtab_cursor base; /* Base class used by SQLite core */ 284 sqlite3_vtab_cursor base; /* Base class used by SQLite core */
163 i16 eSearch; /* Search strategy (see below) */ 285 i16 eSearch; /* Search strategy (see below) */
164 u8 isEof; /* True if at End Of Results */ 286 u8 isEof; /* True if at End Of Results */
165 u8 isRequireSeek; /* True if must seek pStmt to %_content row */ 287 u8 isRequireSeek; /* True if must seek pStmt to %_content row */
166 sqlite3_stmt *pStmt; /* Prepared statement in use by the cursor */ 288 sqlite3_stmt *pStmt; /* Prepared statement in use by the cursor */
167 Fts3Expr *pExpr; /* Parsed MATCH query string */ 289 Fts3Expr *pExpr; /* Parsed MATCH query string */
290 int iLangid; /* Language being queried for */
168 int nPhrase; /* Number of matchable phrases in query */ 291 int nPhrase; /* Number of matchable phrases in query */
169 Fts3DeferredToken *pDeferred; /* Deferred search tokens, if any */ 292 Fts3DeferredToken *pDeferred; /* Deferred search tokens, if any */
170 sqlite3_int64 iPrevId; /* Previous id read from aDoclist */ 293 sqlite3_int64 iPrevId; /* Previous id read from aDoclist */
171 char *pNextId; /* Pointer into the body of aDoclist */ 294 char *pNextId; /* Pointer into the body of aDoclist */
172 char *aDoclist; /* List of docids for full-text queries */ 295 char *aDoclist; /* List of docids for full-text queries */
173 int nDoclist; /* Size of buffer at aDoclist */ 296 int nDoclist; /* Size of buffer at aDoclist */
297 u8 bDesc; /* True to sort in descending order */
174 int eEvalmode; /* An FTS3_EVAL_XX constant */ 298 int eEvalmode; /* An FTS3_EVAL_XX constant */
175 int nRowAvg; /* Average size of database rows, in pages */ 299 int nRowAvg; /* Average size of database rows, in pages */
176 300 sqlite3_int64 nDoc; /* Documents in table */
301 i64 iMinDocid; /* Minimum docid to return */
302 i64 iMaxDocid; /* Maximum docid to return */
177 int isMatchinfoNeeded; /* True when aMatchinfo[] needs filling in */ 303 int isMatchinfoNeeded; /* True when aMatchinfo[] needs filling in */
178 u32 *aMatchinfo; /* Information about most recent match */ 304 u32 *aMatchinfo; /* Information about most recent match */
179 int nMatchinfo; /* Number of elements in aMatchinfo[] */ 305 int nMatchinfo; /* Number of elements in aMatchinfo[] */
180 char *zMatchinfo; /* Matchinfo specification */ 306 char *zMatchinfo; /* Matchinfo specification */
181 }; 307 };
182 308
183 #define FTS3_EVAL_FILTER 0 309 #define FTS3_EVAL_FILTER 0
184 #define FTS3_EVAL_NEXT 1 310 #define FTS3_EVAL_NEXT 1
185 #define FTS3_EVAL_MATCHINFO 2 311 #define FTS3_EVAL_MATCHINFO 2
186 312
(...skipping 10 matching lines...) Expand all
197 ** Fts3Cursor.eSearch will be set to FTS3_FULLTEXT_SEARCH+1. (+0 for a, 323 ** Fts3Cursor.eSearch will be set to FTS3_FULLTEXT_SEARCH+1. (+0 for a,
198 ** +1 for b, +2 for c, +3 for d.) If the LHS of MATCH were "ex1" 324 ** +1 for b, +2 for c, +3 for d.) If the LHS of MATCH were "ex1"
199 ** indicating that all columns should be searched, 325 ** indicating that all columns should be searched,
200 ** then eSearch would be set to FTS3_FULLTEXT_SEARCH+4. 326 ** then eSearch would be set to FTS3_FULLTEXT_SEARCH+4.
201 */ 327 */
202 #define FTS3_FULLSCAN_SEARCH 0 /* Linear scan of %_content table */ 328 #define FTS3_FULLSCAN_SEARCH 0 /* Linear scan of %_content table */
203 #define FTS3_DOCID_SEARCH 1 /* Lookup by rowid on %_content table */ 329 #define FTS3_DOCID_SEARCH 1 /* Lookup by rowid on %_content table */
204 #define FTS3_FULLTEXT_SEARCH 2 /* Full-text index search */ 330 #define FTS3_FULLTEXT_SEARCH 2 /* Full-text index search */
205 331
206 /* 332 /*
333 ** The lower 16-bits of the sqlite3_index_info.idxNum value set by
334 ** the xBestIndex() method contains the Fts3Cursor.eSearch value described
335 ** above. The upper 16-bits contain a combination of the following
336 ** bits, used to describe extra constraints on full-text searches.
337 */
338 #define FTS3_HAVE_LANGID 0x00010000 /* languageid=? */
339 #define FTS3_HAVE_DOCID_GE 0x00020000 /* docid>=? */
340 #define FTS3_HAVE_DOCID_LE 0x00040000 /* docid<=? */
341
342 struct Fts3Doclist {
343 char *aAll; /* Array containing doclist (or NULL) */
344 int nAll; /* Size of a[] in bytes */
345 char *pNextDocid; /* Pointer to next docid */
346
347 sqlite3_int64 iDocid; /* Current docid (if pList!=0) */
348 int bFreeList; /* True if pList should be sqlite3_free()d */
349 char *pList; /* Pointer to position list following iDocid */
350 int nList; /* Length of position list */
351 };
352
353 /*
207 ** A "phrase" is a sequence of one or more tokens that must match in 354 ** A "phrase" is a sequence of one or more tokens that must match in
208 ** sequence. A single token is the base case and the most common case. 355 ** sequence. A single token is the base case and the most common case.
209 ** For a sequence of tokens contained in double-quotes (i.e. "one two three") 356 ** For a sequence of tokens contained in double-quotes (i.e. "one two three")
210 ** nToken will be the number of tokens in the string. 357 ** nToken will be the number of tokens in the string.
211 **
212 ** The nDocMatch and nMatch variables contain data that may be used by the
213 ** matchinfo() function. They are populated when the full-text index is
214 ** queried for hits on the phrase. If one or more tokens in the phrase
215 ** are deferred, the nDocMatch and nMatch variables are populated based
216 ** on the assumption that the
217 */ 358 */
218 struct Fts3PhraseToken { 359 struct Fts3PhraseToken {
219 char *z; /* Text of the token */ 360 char *z; /* Text of the token */
220 int n; /* Number of bytes in buffer z */ 361 int n; /* Number of bytes in buffer z */
221 int isPrefix; /* True if token ends with a "*" character */ 362 int isPrefix; /* True if token ends with a "*" character */
222 int bFulltext; /* True if full-text index was used */ 363 int bFirst; /* True if token must appear at position 0 */
223 Fts3SegReaderCursor *pSegcsr; /* Segment-reader for this token */ 364
365 /* Variables above this point are populated when the expression is
366 ** parsed (by code in fts3_expr.c). Below this point the variables are
367 ** used when evaluating the expression. */
224 Fts3DeferredToken *pDeferred; /* Deferred token object for this token */ 368 Fts3DeferredToken *pDeferred; /* Deferred token object for this token */
369 Fts3MultiSegReader *pSegcsr; /* Segment-reader for this token */
225 }; 370 };
226 371
227 struct Fts3Phrase { 372 struct Fts3Phrase {
228 /* Variables populated by fts3_expr.c when parsing a MATCH expression */ 373 /* Cache of doclist for this phrase. */
374 Fts3Doclist doclist;
375 int bIncr; /* True if doclist is loaded incrementally */
376 int iDoclistToken;
377
378 /* Variables below this point are populated by fts3_expr.c when parsing
379 ** a MATCH expression. Everything above is part of the evaluation phase.
380 */
229 int nToken; /* Number of tokens in the phrase */ 381 int nToken; /* Number of tokens in the phrase */
230 int iColumn; /* Index of column this phrase must match */ 382 int iColumn; /* Index of column this phrase must match */
231 int isNot; /* Phrase prefixed by unary not (-) operator */
232 Fts3PhraseToken aToken[1]; /* One entry for each token in the phrase */ 383 Fts3PhraseToken aToken[1]; /* One entry for each token in the phrase */
233 }; 384 };
234 385
235 /* 386 /*
236 ** A tree of these objects forms the RHS of a MATCH operator. 387 ** A tree of these objects forms the RHS of a MATCH operator.
237 ** 388 **
238 ** If Fts3Expr.eType is either FTSQUERY_NEAR or FTSQUERY_PHRASE and isLoaded 389 ** If Fts3Expr.eType is FTSQUERY_PHRASE and isLoaded is true, then aDoclist
239 ** is true, then aDoclist points to a malloced buffer, size nDoclist bytes, 390 ** points to a malloced buffer, size nDoclist bytes, containing the results
240 ** containing the results of the NEAR or phrase query in FTS3 doclist 391 ** of this phrase query in FTS3 doclist format. As usual, the initial
241 ** format. As usual, the initial "Length" field found in doclists stored 392 ** "Length" field found in doclists stored on disk is omitted from this
242 ** on disk is omitted from this buffer. 393 ** buffer.
243 ** 394 **
244 ** Variable pCurrent always points to the start of a docid field within 395 ** Variable aMI is used only for FTSQUERY_NEAR nodes to store the global
245 ** aDoclist. Since the doclist is usually scanned in docid order, this can 396 ** matchinfo data. If it is not NULL, it points to an array of size nCol*3,
246 ** be used to accelerate seeking to the required docid within the doclist. 397 ** where nCol is the number of columns in the queried FTS table. The array
398 ** is populated as follows:
399 **
400 ** aMI[iCol*3 + 0] = Undefined
401 ** aMI[iCol*3 + 1] = Number of occurrences
402 ** aMI[iCol*3 + 2] = Number of rows containing at least one instance
403 **
404 ** The aMI array is allocated using sqlite3_malloc(). It should be freed
405 ** when the expression node is.
247 */ 406 */
248 struct Fts3Expr { 407 struct Fts3Expr {
249 int eType; /* One of the FTSQUERY_XXX values defined below */ 408 int eType; /* One of the FTSQUERY_XXX values defined below */
250 int nNear; /* Valid if eType==FTSQUERY_NEAR */ 409 int nNear; /* Valid if eType==FTSQUERY_NEAR */
251 Fts3Expr *pParent; /* pParent->pLeft==this or pParent->pRight==this */ 410 Fts3Expr *pParent; /* pParent->pLeft==this or pParent->pRight==this */
252 Fts3Expr *pLeft; /* Left operand */ 411 Fts3Expr *pLeft; /* Left operand */
253 Fts3Expr *pRight; /* Right operand */ 412 Fts3Expr *pRight; /* Right operand */
254 Fts3Phrase *pPhrase; /* Valid if eType==FTSQUERY_PHRASE */ 413 Fts3Phrase *pPhrase; /* Valid if eType==FTSQUERY_PHRASE */
255 414
256 int isLoaded; /* True if aDoclist/nDoclist are initialized. */ 415 /* The following are used by the fts3_eval.c module. */
257 char *aDoclist; /* Buffer containing doclist */ 416 sqlite3_int64 iDocid; /* Current docid */
258 int nDoclist; /* Size of aDoclist in bytes */ 417 u8 bEof; /* True this expression is at EOF already */
418 u8 bStart; /* True if iDocid is valid */
419 u8 bDeferred; /* True if this expression is entirely deferred */
259 420
260 sqlite3_int64 iCurrent; 421 u32 *aMI;
261 char *pCurrent;
262 }; 422 };
263 423
264 /* 424 /*
265 ** Candidate values for Fts3Query.eType. Note that the order of the first 425 ** Candidate values for Fts3Query.eType. Note that the order of the first
266 ** four values is in order of precedence when parsing expressions. For 426 ** four values is in order of precedence when parsing expressions. For
267 ** example, the following: 427 ** example, the following:
268 ** 428 **
269 ** "a OR b AND c NOT d NEAR e" 429 ** "a OR b AND c NOT d NEAR e"
270 ** 430 **
271 ** is equivalent to: 431 ** is equivalent to:
272 ** 432 **
273 ** "a OR (b AND (c NOT (d NEAR e)))" 433 ** "a OR (b AND (c NOT (d NEAR e)))"
274 */ 434 */
275 #define FTSQUERY_NEAR 1 435 #define FTSQUERY_NEAR 1
276 #define FTSQUERY_NOT 2 436 #define FTSQUERY_NOT 2
277 #define FTSQUERY_AND 3 437 #define FTSQUERY_AND 3
278 #define FTSQUERY_OR 4 438 #define FTSQUERY_OR 4
279 #define FTSQUERY_PHRASE 5 439 #define FTSQUERY_PHRASE 5
280 440
281 441
282 /* fts3_write.c */ 442 /* fts3_write.c */
283 int sqlite3Fts3UpdateMethod(sqlite3_vtab*,int,sqlite3_value**,sqlite3_int64*); 443 int sqlite3Fts3UpdateMethod(sqlite3_vtab*,int,sqlite3_value**,sqlite3_int64*);
284 int sqlite3Fts3PendingTermsFlush(Fts3Table *); 444 int sqlite3Fts3PendingTermsFlush(Fts3Table *);
285 void sqlite3Fts3PendingTermsClear(Fts3Table *); 445 void sqlite3Fts3PendingTermsClear(Fts3Table *);
286 int sqlite3Fts3Optimize(Fts3Table *); 446 int sqlite3Fts3Optimize(Fts3Table *);
287 int sqlite3Fts3SegReaderNew(int, sqlite3_int64, 447 int sqlite3Fts3SegReaderNew(int, int, sqlite3_int64,
288 sqlite3_int64, sqlite3_int64, const char *, int, Fts3SegReader**); 448 sqlite3_int64, sqlite3_int64, const char *, int, Fts3SegReader**);
289 int sqlite3Fts3SegReaderPending(Fts3Table*,const char*,int,int,Fts3SegReader**); 449 int sqlite3Fts3SegReaderPending(
450 Fts3Table*,int,const char*,int,int,Fts3SegReader**);
290 void sqlite3Fts3SegReaderFree(Fts3SegReader *); 451 void sqlite3Fts3SegReaderFree(Fts3SegReader *);
291 int sqlite3Fts3SegReaderCost(Fts3Cursor *, Fts3SegReader *, int *); 452 int sqlite3Fts3AllSegdirs(Fts3Table*, int, int, int, sqlite3_stmt **);
292 int sqlite3Fts3AllSegdirs(Fts3Table*, int, sqlite3_stmt **); 453 int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char **, int*, int*);
293 int sqlite3Fts3ReadLock(Fts3Table *);
294 int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char **, int*);
295 454
296 int sqlite3Fts3SelectDoctotal(Fts3Table *, sqlite3_stmt **); 455 int sqlite3Fts3SelectDoctotal(Fts3Table *, sqlite3_stmt **);
297 int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **); 456 int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **);
298 457
458 #ifndef SQLITE_DISABLE_FTS4_DEFERRED
299 void sqlite3Fts3FreeDeferredTokens(Fts3Cursor *); 459 void sqlite3Fts3FreeDeferredTokens(Fts3Cursor *);
300 int sqlite3Fts3DeferToken(Fts3Cursor *, Fts3PhraseToken *, int); 460 int sqlite3Fts3DeferToken(Fts3Cursor *, Fts3PhraseToken *, int);
301 int sqlite3Fts3CacheDeferredDoclists(Fts3Cursor *); 461 int sqlite3Fts3CacheDeferredDoclists(Fts3Cursor *);
302 void sqlite3Fts3FreeDeferredDoclists(Fts3Cursor *); 462 void sqlite3Fts3FreeDeferredDoclists(Fts3Cursor *);
303 char *sqlite3Fts3DeferredDoclist(Fts3DeferredToken *, int *); 463 int sqlite3Fts3DeferredTokenList(Fts3DeferredToken *, char **, int *);
464 #else
465 # define sqlite3Fts3FreeDeferredTokens(x)
466 # define sqlite3Fts3DeferToken(x,y,z) SQLITE_OK
467 # define sqlite3Fts3CacheDeferredDoclists(x) SQLITE_OK
468 # define sqlite3Fts3FreeDeferredDoclists(x)
469 # define sqlite3Fts3DeferredTokenList(x,y,z) SQLITE_OK
470 #endif
471
304 void sqlite3Fts3SegmentsClose(Fts3Table *); 472 void sqlite3Fts3SegmentsClose(Fts3Table *);
473 int sqlite3Fts3MaxLevel(Fts3Table *, int *);
305 474
306 #define FTS3_SEGCURSOR_PENDING -1 475 /* Special values interpreted by sqlite3SegReaderCursor() */
307 #define FTS3_SEGCURSOR_ALL -2 476 #define FTS3_SEGCURSOR_PENDING -1
477 #define FTS3_SEGCURSOR_ALL -2
308 478
309 int sqlite3Fts3SegReaderStart(Fts3Table*, Fts3SegReaderCursor*, Fts3SegFilter*); 479 int sqlite3Fts3SegReaderStart(Fts3Table*, Fts3MultiSegReader*, Fts3SegFilter*);
310 int sqlite3Fts3SegReaderStep(Fts3Table *, Fts3SegReaderCursor *); 480 int sqlite3Fts3SegReaderStep(Fts3Table *, Fts3MultiSegReader *);
311 void sqlite3Fts3SegReaderFinish(Fts3SegReaderCursor *); 481 void sqlite3Fts3SegReaderFinish(Fts3MultiSegReader *);
312 int sqlite3Fts3SegReaderCursor( 482
313 Fts3Table *, int, const char *, int, int, int, Fts3SegReaderCursor *); 483 int sqlite3Fts3SegReaderCursor(Fts3Table *,
484 int, int, int, const char *, int, int, int, Fts3MultiSegReader *);
314 485
315 /* Flags allowed as part of the 4th argument to SegmentReaderIterate() */ 486 /* Flags allowed as part of the 4th argument to SegmentReaderIterate() */
316 #define FTS3_SEGMENT_REQUIRE_POS 0x00000001 487 #define FTS3_SEGMENT_REQUIRE_POS 0x00000001
317 #define FTS3_SEGMENT_IGNORE_EMPTY 0x00000002 488 #define FTS3_SEGMENT_IGNORE_EMPTY 0x00000002
318 #define FTS3_SEGMENT_COLUMN_FILTER 0x00000004 489 #define FTS3_SEGMENT_COLUMN_FILTER 0x00000004
319 #define FTS3_SEGMENT_PREFIX 0x00000008 490 #define FTS3_SEGMENT_PREFIX 0x00000008
320 #define FTS3_SEGMENT_SCAN 0x00000010 491 #define FTS3_SEGMENT_SCAN 0x00000010
492 #define FTS3_SEGMENT_FIRST 0x00000020
321 493
322 /* Type passed as 4th argument to SegmentReaderIterate() */ 494 /* Type passed as 4th argument to SegmentReaderIterate() */
323 struct Fts3SegFilter { 495 struct Fts3SegFilter {
324 const char *zTerm; 496 const char *zTerm;
325 int nTerm; 497 int nTerm;
326 int iCol; 498 int iCol;
327 int flags; 499 int flags;
328 }; 500 };
329 501
330 struct Fts3SegReaderCursor { 502 struct Fts3MultiSegReader {
331 /* Used internally by sqlite3Fts3SegReaderXXX() calls */ 503 /* Used internally by sqlite3Fts3SegReaderXXX() calls */
332 Fts3SegReader **apSegment; /* Array of Fts3SegReader objects */ 504 Fts3SegReader **apSegment; /* Array of Fts3SegReader objects */
333 int nSegment; /* Size of apSegment array */ 505 int nSegment; /* Size of apSegment array */
334 int nAdvance; /* How many seg-readers to advance */ 506 int nAdvance; /* How many seg-readers to advance */
335 Fts3SegFilter *pFilter; /* Pointer to filter object */ 507 Fts3SegFilter *pFilter; /* Pointer to filter object */
336 char *aBuffer; /* Buffer to merge doclists in */ 508 char *aBuffer; /* Buffer to merge doclists in */
337 int nBuffer; /* Allocated size of aBuffer[] in bytes */ 509 int nBuffer; /* Allocated size of aBuffer[] in bytes */
338 510
339 /* Cost of running this iterator. Used by fts3.c only. */ 511 int iColFilter; /* If >=0, filter for this column */
340 int nCost; 512 int bRestart;
513
514 /* Used by fts3.c only. */
515 int nCost; /* Cost of running iterator */
516 int bLookup; /* True if a lookup of a single entry. */
341 517
342 /* Output values. Valid only after Fts3SegReaderStep() returns SQLITE_ROW. */ 518 /* Output values. Valid only after Fts3SegReaderStep() returns SQLITE_ROW. */
343 char *zTerm; /* Pointer to term buffer */ 519 char *zTerm; /* Pointer to term buffer */
344 int nTerm; /* Size of zTerm in bytes */ 520 int nTerm; /* Size of zTerm in bytes */
345 char *aDoclist; /* Pointer to doclist buffer */ 521 char *aDoclist; /* Pointer to doclist buffer */
346 int nDoclist; /* Size of aDoclist[] in bytes */ 522 int nDoclist; /* Size of aDoclist[] in bytes */
347 }; 523 };
348 524
525 int sqlite3Fts3Incrmerge(Fts3Table*,int,int);
526
527 #define fts3GetVarint32(p, piVal) ( \
528 (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
529 )
530
349 /* fts3.c */ 531 /* fts3.c */
350 int sqlite3Fts3PutVarint(char *, sqlite3_int64); 532 int sqlite3Fts3PutVarint(char *, sqlite3_int64);
351 int sqlite3Fts3GetVarint(const char *, sqlite_int64 *); 533 int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
352 int sqlite3Fts3GetVarint32(const char *, int *); 534 int sqlite3Fts3GetVarint32(const char *, int *);
353 int sqlite3Fts3VarintLen(sqlite3_uint64); 535 int sqlite3Fts3VarintLen(sqlite3_uint64);
354 void sqlite3Fts3Dequote(char *); 536 void sqlite3Fts3Dequote(char *);
355 537 void sqlite3Fts3DoclistPrev(int,char*,int,char**,sqlite3_int64*,int*,u8*);
356 char *sqlite3Fts3FindPositions(Fts3Expr *, sqlite3_int64, int); 538 int sqlite3Fts3EvalPhraseStats(Fts3Cursor *, Fts3Expr *, u32 *);
357 int sqlite3Fts3ExprLoadDoclist(Fts3Cursor *, Fts3Expr *); 539 int sqlite3Fts3FirstFilter(sqlite3_int64, char *, int, char *);
358 int sqlite3Fts3ExprLoadFtDoclist(Fts3Cursor *, Fts3Expr *, char **, int *); 540 void sqlite3Fts3CreateStatTable(int*, Fts3Table*);
359 int sqlite3Fts3ExprNearTrim(Fts3Expr *, Fts3Expr *, int);
360 541
361 /* fts3_tokenizer.c */ 542 /* fts3_tokenizer.c */
362 const char *sqlite3Fts3NextToken(const char *, int *); 543 const char *sqlite3Fts3NextToken(const char *, int *);
363 int sqlite3Fts3InitHashTable(sqlite3 *, Fts3Hash *, const char *); 544 int sqlite3Fts3InitHashTable(sqlite3 *, Fts3Hash *, const char *);
364 int sqlite3Fts3InitTokenizer(Fts3Hash *pHash, const char *, 545 int sqlite3Fts3InitTokenizer(Fts3Hash *pHash, const char *,
365 sqlite3_tokenizer **, char ** 546 sqlite3_tokenizer **, char **
366 ); 547 );
367 int sqlite3Fts3IsIdChar(char); 548 int sqlite3Fts3IsIdChar(char);
368 549
369 /* fts3_snippet.c */ 550 /* fts3_snippet.c */
370 void sqlite3Fts3Offsets(sqlite3_context*, Fts3Cursor*); 551 void sqlite3Fts3Offsets(sqlite3_context*, Fts3Cursor*);
371 void sqlite3Fts3Snippet(sqlite3_context *, Fts3Cursor *, const char *, 552 void sqlite3Fts3Snippet(sqlite3_context *, Fts3Cursor *, const char *,
372 const char *, const char *, int, int 553 const char *, const char *, int, int
373 ); 554 );
374 void sqlite3Fts3Matchinfo(sqlite3_context *, Fts3Cursor *, const char *); 555 void sqlite3Fts3Matchinfo(sqlite3_context *, Fts3Cursor *, const char *);
375 556
376 /* fts3_expr.c */ 557 /* fts3_expr.c */
377 int sqlite3Fts3ExprParse(sqlite3_tokenizer *, 558 int sqlite3Fts3ExprParse(sqlite3_tokenizer *, int,
378 char **, int, int, const char *, int, Fts3Expr ** 559 char **, int, int, int, const char *, int, Fts3Expr **, char **
379 ); 560 );
380 void sqlite3Fts3ExprFree(Fts3Expr *); 561 void sqlite3Fts3ExprFree(Fts3Expr *);
381 #ifdef SQLITE_TEST 562 #ifdef SQLITE_TEST
382 int sqlite3Fts3ExprInitTestInterface(sqlite3 *db); 563 int sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
564 int sqlite3Fts3InitTerm(sqlite3 *db);
383 #endif 565 #endif
384 566
567 int sqlite3Fts3OpenTokenizer(sqlite3_tokenizer *, int, const char *, int,
568 sqlite3_tokenizer_cursor **
569 );
570
385 /* fts3_aux.c */ 571 /* fts3_aux.c */
386 int sqlite3Fts3InitAux(sqlite3 *db); 572 int sqlite3Fts3InitAux(sqlite3 *db);
387 573
574 void sqlite3Fts3EvalPhraseCleanup(Fts3Phrase *);
575
576 int sqlite3Fts3MsrIncrStart(
577 Fts3Table*, Fts3MultiSegReader*, int, const char*, int);
578 int sqlite3Fts3MsrIncrNext(
579 Fts3Table *, Fts3MultiSegReader *, sqlite3_int64 *, char **, int *);
580 int sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iCol, char **);
581 int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *);
582 int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr);
583
584 /* fts3_tokenize_vtab.c */
585 int sqlite3Fts3InitTok(sqlite3*, Fts3Hash *);
586
587 /* fts3_unicode2.c (functions generated by parsing unicode text files) */
588 #ifndef SQLITE_DISABLE_FTS3_UNICODE
589 int sqlite3FtsUnicodeFold(int, int);
590 int sqlite3FtsUnicodeIsalnum(int);
591 int sqlite3FtsUnicodeIsdiacritic(int);
592 #endif
593
594 #endif /* !SQLITE_CORE || SQLITE_ENABLE_FTS3 */
388 #endif /* _FTSINT_H */ 595 #endif /* _FTSINT_H */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698