| | @@ -23,531 +23,10 @@ |
| 23 | 23 | # define SQLITE_PRIVATE static |
| 24 | 24 | #endif |
| 25 | 25 | #ifndef SQLITE_API |
| 26 | 26 | # define SQLITE_API |
| 27 | 27 | #endif |
| 28 | | -/************** Begin file sqliteInt.h ***************************************/ |
| 29 | | -/* |
| 30 | | -** 2001 September 15 |
| 31 | | -** |
| 32 | | -** The author disclaims copyright to this source code. In place of |
| 33 | | -** a legal notice, here is a blessing: |
| 34 | | -** |
| 35 | | -** May you do good and not evil. |
| 36 | | -** May you find forgiveness for yourself and forgive others. |
| 37 | | -** May you share freely, never taking more than you give. |
| 38 | | -** |
| 39 | | -************************************************************************* |
| 40 | | -** Internal interface definitions for SQLite. |
| 41 | | -** |
| 42 | | -*/ |
| 43 | | -#ifndef _SQLITEINT_H_ |
| 44 | | -#define _SQLITEINT_H_ |
| 45 | | - |
| 46 | | -/* |
| 47 | | -** These #defines should enable >2GB file support on POSIX if the |
| 48 | | -** underlying operating system supports it. If the OS lacks |
| 49 | | -** large file support, or if the OS is windows, these should be no-ops. |
| 50 | | -** |
| 51 | | -** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any |
| 52 | | -** system #includes. Hence, this block of code must be the very first |
| 53 | | -** code in all source files. |
| 54 | | -** |
| 55 | | -** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch |
| 56 | | -** on the compiler command line. This is necessary if you are compiling |
| 57 | | -** on a recent machine (ex: Red Hat 7.2) but you want your code to work |
| 58 | | -** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2 |
| 59 | | -** without this option, LFS is enable. But LFS does not exist in the kernel |
| 60 | | -** in Red Hat 6.0, so the code won't work. Hence, for maximum binary |
| 61 | | -** portability you should omit LFS. |
| 62 | | -** |
| 63 | | -** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later. |
| 64 | | -*/ |
| 65 | | -#ifndef SQLITE_DISABLE_LFS |
| 66 | | -# define _LARGE_FILE 1 |
| 67 | | -# ifndef _FILE_OFFSET_BITS |
| 68 | | -# define _FILE_OFFSET_BITS 64 |
| 69 | | -# endif |
| 70 | | -# define _LARGEFILE_SOURCE 1 |
| 71 | | -#endif |
| 72 | | - |
| 73 | | -/* |
| 74 | | -** Include the configuration header output by 'configure' if we're using the |
| 75 | | -** autoconf-based build |
| 76 | | -*/ |
| 77 | | -#ifdef _HAVE_SQLITE_CONFIG_H |
| 78 | | -#include "config.h" |
| 79 | | -#endif |
| 80 | | - |
| 81 | | -/************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/ |
| 82 | | -/************** Begin file sqliteLimit.h *************************************/ |
| 83 | | -/* |
| 84 | | -** 2007 May 7 |
| 85 | | -** |
| 86 | | -** The author disclaims copyright to this source code. In place of |
| 87 | | -** a legal notice, here is a blessing: |
| 88 | | -** |
| 89 | | -** May you do good and not evil. |
| 90 | | -** May you find forgiveness for yourself and forgive others. |
| 91 | | -** May you share freely, never taking more than you give. |
| 92 | | -** |
| 93 | | -************************************************************************* |
| 94 | | -** |
| 95 | | -** This file defines various limits of what SQLite can process. |
| 96 | | -*/ |
| 97 | | - |
| 98 | | -/* |
| 99 | | -** The maximum length of a TEXT or BLOB in bytes. This also |
| 100 | | -** limits the size of a row in a table or index. |
| 101 | | -** |
| 102 | | -** The hard limit is the ability of a 32-bit signed integer |
| 103 | | -** to count the size: 2^31-1 or 2147483647. |
| 104 | | -*/ |
| 105 | | -#ifndef SQLITE_MAX_LENGTH |
| 106 | | -# define SQLITE_MAX_LENGTH 1000000000 |
| 107 | | -#endif |
| 108 | | - |
| 109 | | -/* |
| 110 | | -** This is the maximum number of |
| 111 | | -** |
| 112 | | -** * Columns in a table |
| 113 | | -** * Columns in an index |
| 114 | | -** * Columns in a view |
| 115 | | -** * Terms in the SET clause of an UPDATE statement |
| 116 | | -** * Terms in the result set of a SELECT statement |
| 117 | | -** * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement. |
| 118 | | -** * Terms in the VALUES clause of an INSERT statement |
| 119 | | -** |
| 120 | | -** The hard upper limit here is 32676. Most database people will |
| 121 | | -** tell you that in a well-normalized database, you usually should |
| 122 | | -** not have more than a dozen or so columns in any table. And if |
| 123 | | -** that is the case, there is no point in having more than a few |
| 124 | | -** dozen values in any of the other situations described above. |
| 125 | | -*/ |
| 126 | | -#ifndef SQLITE_MAX_COLUMN |
| 127 | | -# define SQLITE_MAX_COLUMN 2000 |
| 128 | | -#endif |
| 129 | | - |
| 130 | | -/* |
| 131 | | -** The maximum length of a single SQL statement in bytes. |
| 132 | | -** |
| 133 | | -** It used to be the case that setting this value to zero would |
| 134 | | -** turn the limit off. That is no longer true. It is not possible |
| 135 | | -** to turn this limit off. |
| 136 | | -*/ |
| 137 | | -#ifndef SQLITE_MAX_SQL_LENGTH |
| 138 | | -# define SQLITE_MAX_SQL_LENGTH 1000000000 |
| 139 | | -#endif |
| 140 | | - |
| 141 | | -/* |
| 142 | | -** The maximum depth of an expression tree. This is limited to |
| 143 | | -** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might |
| 144 | | -** want to place more severe limits on the complexity of an |
| 145 | | -** expression. |
| 146 | | -** |
| 147 | | -** A value of 0 used to mean that the limit was not enforced. |
| 148 | | -** But that is no longer true. The limit is now strictly enforced |
| 149 | | -** at all times. |
| 150 | | -*/ |
| 151 | | -#ifndef SQLITE_MAX_EXPR_DEPTH |
| 152 | | -# define SQLITE_MAX_EXPR_DEPTH 1000 |
| 153 | | -#endif |
| 154 | | - |
| 155 | | -/* |
| 156 | | -** The maximum number of terms in a compound SELECT statement. |
| 157 | | -** The code generator for compound SELECT statements does one |
| 158 | | -** level of recursion for each term. A stack overflow can result |
| 159 | | -** if the number of terms is too large. In practice, most SQL |
| 160 | | -** never has more than 3 or 4 terms. Use a value of 0 to disable |
| 161 | | -** any limit on the number of terms in a compount SELECT. |
| 162 | | -*/ |
| 163 | | -#ifndef SQLITE_MAX_COMPOUND_SELECT |
| 164 | | -# define SQLITE_MAX_COMPOUND_SELECT 500 |
| 165 | | -#endif |
| 166 | | - |
| 167 | | -/* |
| 168 | | -** The maximum number of opcodes in a VDBE program. |
| 169 | | -** Not currently enforced. |
| 170 | | -*/ |
| 171 | | -#ifndef SQLITE_MAX_VDBE_OP |
| 172 | | -# define SQLITE_MAX_VDBE_OP 25000 |
| 173 | | -#endif |
| 174 | | - |
| 175 | | -/* |
| 176 | | -** The maximum number of arguments to an SQL function. |
| 177 | | -*/ |
| 178 | | -#ifndef SQLITE_MAX_FUNCTION_ARG |
| 179 | | -# define SQLITE_MAX_FUNCTION_ARG 127 |
| 180 | | -#endif |
| 181 | | - |
| 182 | | -/* |
| 183 | | -** The maximum number of in-memory pages to use for the main database |
| 184 | | -** table and for temporary tables. The SQLITE_DEFAULT_CACHE_SIZE |
| 185 | | -*/ |
| 186 | | -#ifndef SQLITE_DEFAULT_CACHE_SIZE |
| 187 | | -# define SQLITE_DEFAULT_CACHE_SIZE 2000 |
| 188 | | -#endif |
| 189 | | -#ifndef SQLITE_DEFAULT_TEMP_CACHE_SIZE |
| 190 | | -# define SQLITE_DEFAULT_TEMP_CACHE_SIZE 500 |
| 191 | | -#endif |
| 192 | | - |
| 193 | | -/* |
| 194 | | -** The default number of frames to accumulate in the log file before |
| 195 | | -** checkpointing the database in WAL mode. |
| 196 | | -*/ |
| 197 | | -#ifndef SQLITE_DEFAULT_WAL_AUTOCHECKPOINT |
| 198 | | -# define SQLITE_DEFAULT_WAL_AUTOCHECKPOINT 1000 |
| 199 | | -#endif |
| 200 | | - |
| 201 | | -/* |
| 202 | | -** The maximum number of attached databases. This must be between 0 |
| 203 | | -** and 62. The upper bound on 62 is because a 64-bit integer bitmap |
| 204 | | -** is used internally to track attached databases. |
| 205 | | -*/ |
| 206 | | -#ifndef SQLITE_MAX_ATTACHED |
| 207 | | -# define SQLITE_MAX_ATTACHED 10 |
| 208 | | -#endif |
| 209 | | - |
| 210 | | - |
| 211 | | -/* |
| 212 | | -** The maximum value of a ?nnn wildcard that the parser will accept. |
| 213 | | -*/ |
| 214 | | -#ifndef SQLITE_MAX_VARIABLE_NUMBER |
| 215 | | -# define SQLITE_MAX_VARIABLE_NUMBER 999 |
| 216 | | -#endif |
| 217 | | - |
| 218 | | -/* Maximum page size. The upper bound on this value is 65536. This a limit |
| 219 | | -** imposed by the use of 16-bit offsets within each page. |
| 220 | | -** |
| 221 | | -** Earlier versions of SQLite allowed the user to change this value at |
| 222 | | -** compile time. This is no longer permitted, on the grounds that it creates |
| 223 | | -** a library that is technically incompatible with an SQLite library |
| 224 | | -** compiled with a different limit. If a process operating on a database |
| 225 | | -** with a page-size of 65536 bytes crashes, then an instance of SQLite |
| 226 | | -** compiled with the default page-size limit will not be able to rollback |
| 227 | | -** the aborted transaction. This could lead to database corruption. |
| 228 | | -*/ |
| 229 | | -#ifdef SQLITE_MAX_PAGE_SIZE |
| 230 | | -# undef SQLITE_MAX_PAGE_SIZE |
| 231 | | -#endif |
| 232 | | -#define SQLITE_MAX_PAGE_SIZE 65536 |
| 233 | | - |
| 234 | | - |
| 235 | | -/* |
| 236 | | -** The default size of a database page. |
| 237 | | -*/ |
| 238 | | -#ifndef SQLITE_DEFAULT_PAGE_SIZE |
| 239 | | -# define SQLITE_DEFAULT_PAGE_SIZE 1024 |
| 240 | | -#endif |
| 241 | | -#if SQLITE_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE |
| 242 | | -# undef SQLITE_DEFAULT_PAGE_SIZE |
| 243 | | -# define SQLITE_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE |
| 244 | | -#endif |
| 245 | | - |
| 246 | | -/* |
| 247 | | -** Ordinarily, if no value is explicitly provided, SQLite creates databases |
| 248 | | -** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain |
| 249 | | -** device characteristics (sector-size and atomic write() support), |
| 250 | | -** SQLite may choose a larger value. This constant is the maximum value |
| 251 | | -** SQLite will choose on its own. |
| 252 | | -*/ |
| 253 | | -#ifndef SQLITE_MAX_DEFAULT_PAGE_SIZE |
| 254 | | -# define SQLITE_MAX_DEFAULT_PAGE_SIZE 8192 |
| 255 | | -#endif |
| 256 | | -#if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE |
| 257 | | -# undef SQLITE_MAX_DEFAULT_PAGE_SIZE |
| 258 | | -# define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE |
| 259 | | -#endif |
| 260 | | - |
| 261 | | - |
| 262 | | -/* |
| 263 | | -** Maximum number of pages in one database file. |
| 264 | | -** |
| 265 | | -** This is really just the default value for the max_page_count pragma. |
| 266 | | -** This value can be lowered (or raised) at run-time using that the |
| 267 | | -** max_page_count macro. |
| 268 | | -*/ |
| 269 | | -#ifndef SQLITE_MAX_PAGE_COUNT |
| 270 | | -# define SQLITE_MAX_PAGE_COUNT 1073741823 |
| 271 | | -#endif |
| 272 | | - |
| 273 | | -/* |
| 274 | | -** Maximum length (in bytes) of the pattern in a LIKE or GLOB |
| 275 | | -** operator. |
| 276 | | -*/ |
| 277 | | -#ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH |
| 278 | | -# define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000 |
| 279 | | -#endif |
| 280 | | - |
| 281 | | -/* |
| 282 | | -** Maximum depth of recursion for triggers. |
| 283 | | -** |
| 284 | | -** A value of 1 means that a trigger program will not be able to itself |
| 285 | | -** fire any triggers. A value of 0 means that no trigger programs at all |
| 286 | | -** may be executed. |
| 287 | | -*/ |
| 288 | | -#ifndef SQLITE_MAX_TRIGGER_DEPTH |
| 289 | | -# define SQLITE_MAX_TRIGGER_DEPTH 1000 |
| 290 | | -#endif |
| 291 | | - |
| 292 | | -/************** End of sqliteLimit.h *****************************************/ |
| 293 | | -/************** Continuing where we left off in sqliteInt.h ******************/ |
| 294 | | - |
| 295 | | -/* Disable nuisance warnings on Borland compilers */ |
| 296 | | -#if defined(__BORLANDC__) |
| 297 | | -#pragma warn -rch /* unreachable code */ |
| 298 | | -#pragma warn -ccc /* Condition is always true or false */ |
| 299 | | -#pragma warn -aus /* Assigned value is never used */ |
| 300 | | -#pragma warn -csu /* Comparing signed and unsigned */ |
| 301 | | -#pragma warn -spa /* Suspicious pointer arithmetic */ |
| 302 | | -#endif |
| 303 | | - |
| 304 | | -/* Needed for various definitions... */ |
| 305 | | -#ifndef _GNU_SOURCE |
| 306 | | -# define _GNU_SOURCE |
| 307 | | -#endif |
| 308 | | - |
| 309 | | -#if defined(__OpenBSD__) && !defined(_BSD_SOURCE) |
| 310 | | -# define _BSD_SOURCE |
| 311 | | -#endif |
| 312 | | - |
| 313 | | -/* |
| 314 | | -** Include standard header files as necessary |
| 315 | | -*/ |
| 316 | | -#ifdef HAVE_STDINT_H |
| 317 | | -#include <stdint.h> |
| 318 | | -#endif |
| 319 | | -#ifdef HAVE_INTTYPES_H |
| 320 | | -#include <inttypes.h> |
| 321 | | -#endif |
| 322 | | - |
| 323 | | -/* |
| 324 | | -** The following macros are used to cast pointers to integers and |
| 325 | | -** integers to pointers. The way you do this varies from one compiler |
| 326 | | -** to the next, so we have developed the following set of #if statements |
| 327 | | -** to generate appropriate macros for a wide range of compilers. |
| 328 | | -** |
| 329 | | -** The correct "ANSI" way to do this is to use the intptr_t type. |
| 330 | | -** Unfortunately, that typedef is not available on all compilers, or |
| 331 | | -** if it is available, it requires an #include of specific headers |
| 332 | | -** that vary from one machine to the next. |
| 333 | | -** |
| 334 | | -** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on |
| 335 | | -** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)). |
| 336 | | -** So we have to define the macros in different ways depending on the |
| 337 | | -** compiler. |
| 338 | | -*/ |
| 339 | | -#if defined(__PTRDIFF_TYPE__) /* This case should work for GCC */ |
| 340 | | -# define SQLITE_INT_TO_PTR(X) ((void*)(__PTRDIFF_TYPE__)(X)) |
| 341 | | -# define SQLITE_PTR_TO_INT(X) ((int)(__PTRDIFF_TYPE__)(X)) |
| 342 | | -#elif !defined(__GNUC__) /* Works for compilers other than LLVM */ |
| 343 | | -# define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X]) |
| 344 | | -# define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0)) |
| 345 | | -#elif defined(HAVE_STDINT_H) /* Use this case if we have ANSI headers */ |
| 346 | | -# define SQLITE_INT_TO_PTR(X) ((void*)(intptr_t)(X)) |
| 347 | | -# define SQLITE_PTR_TO_INT(X) ((int)(intptr_t)(X)) |
| 348 | | -#else /* Generates a warning - but it always works */ |
| 349 | | -# define SQLITE_INT_TO_PTR(X) ((void*)(X)) |
| 350 | | -# define SQLITE_PTR_TO_INT(X) ((int)(X)) |
| 351 | | -#endif |
| 352 | | - |
| 353 | | -/* |
| 354 | | -** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2. |
| 355 | | -** 0 means mutexes are permanently disable and the library is never |
| 356 | | -** threadsafe. 1 means the library is serialized which is the highest |
| 357 | | -** level of threadsafety. 2 means the library is multithreaded - multiple |
| 358 | | -** threads can use SQLite as long as no two threads try to use the same |
| 359 | | -** database connection at the same time. |
| 360 | | -** |
| 361 | | -** Older versions of SQLite used an optional THREADSAFE macro. |
| 362 | | -** We support that for legacy. |
| 363 | | -*/ |
| 364 | | -#if !defined(SQLITE_THREADSAFE) |
| 365 | | -# if defined(THREADSAFE) |
| 366 | | -# define SQLITE_THREADSAFE THREADSAFE |
| 367 | | -# else |
| 368 | | -# define SQLITE_THREADSAFE 1 /* IMP: R-07272-22309 */ |
| 369 | | -# endif |
| 370 | | -#endif |
| 371 | | - |
| 372 | | -/* |
| 373 | | -** Powersafe overwrite is on by default. But can be turned off using |
| 374 | | -** the -DSQLITE_POWERSAFE_OVERWRITE=0 command-line option. |
| 375 | | -*/ |
| 376 | | -#ifndef SQLITE_POWERSAFE_OVERWRITE |
| 377 | | -# define SQLITE_POWERSAFE_OVERWRITE 1 |
| 378 | | -#endif |
| 379 | | - |
| 380 | | -/* |
| 381 | | -** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1. |
| 382 | | -** It determines whether or not the features related to |
| 383 | | -** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can |
| 384 | | -** be overridden at runtime using the sqlite3_config() API. |
| 385 | | -*/ |
| 386 | | -#if !defined(SQLITE_DEFAULT_MEMSTATUS) |
| 387 | | -# define SQLITE_DEFAULT_MEMSTATUS 1 |
| 388 | | -#endif |
| 389 | | - |
| 390 | | -/* |
| 391 | | -** Exactly one of the following macros must be defined in order to |
| 392 | | -** specify which memory allocation subsystem to use. |
| 393 | | -** |
| 394 | | -** SQLITE_SYSTEM_MALLOC // Use normal system malloc() |
| 395 | | -** SQLITE_WIN32_MALLOC // Use Win32 native heap API |
| 396 | | -** SQLITE_ZERO_MALLOC // Use a stub allocator that always fails |
| 397 | | -** SQLITE_MEMDEBUG // Debugging version of system malloc() |
| 398 | | -** |
| 399 | | -** On Windows, if the SQLITE_WIN32_MALLOC_VALIDATE macro is defined and the |
| 400 | | -** assert() macro is enabled, each call into the Win32 native heap subsystem |
| 401 | | -** will cause HeapValidate to be called. If heap validation should fail, an |
| 402 | | -** assertion will be triggered. |
| 403 | | -** |
| 404 | | -** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as |
| 405 | | -** the default. |
| 406 | | -*/ |
| 407 | | -#if defined(SQLITE_SYSTEM_MALLOC) \ |
| 408 | | - + defined(SQLITE_WIN32_MALLOC) \ |
| 409 | | - + defined(SQLITE_ZERO_MALLOC) \ |
| 410 | | - + defined(SQLITE_MEMDEBUG)>1 |
| 411 | | -# error "Two or more of the following compile-time configuration options\ |
| 412 | | - are defined but at most one is allowed:\ |
| 413 | | - SQLITE_SYSTEM_MALLOC, SQLITE_WIN32_MALLOC, SQLITE_MEMDEBUG,\ |
| 414 | | - SQLITE_ZERO_MALLOC" |
| 415 | | -#endif |
| 416 | | -#if defined(SQLITE_SYSTEM_MALLOC) \ |
| 417 | | - + defined(SQLITE_WIN32_MALLOC) \ |
| 418 | | - + defined(SQLITE_ZERO_MALLOC) \ |
| 419 | | - + defined(SQLITE_MEMDEBUG)==0 |
| 420 | | -# define SQLITE_SYSTEM_MALLOC 1 |
| 421 | | -#endif |
| 422 | | - |
| 423 | | -/* |
| 424 | | -** If SQLITE_MALLOC_SOFT_LIMIT is not zero, then try to keep the |
| 425 | | -** sizes of memory allocations below this value where possible. |
| 426 | | -*/ |
| 427 | | -#if !defined(SQLITE_MALLOC_SOFT_LIMIT) |
| 428 | | -# define SQLITE_MALLOC_SOFT_LIMIT 1024 |
| 429 | | -#endif |
| 430 | | - |
| 431 | | -/* |
| 432 | | -** We need to define _XOPEN_SOURCE as follows in order to enable |
| 433 | | -** recursive mutexes on most Unix systems and fchmod() on OpenBSD. |
| 434 | | -** But _XOPEN_SOURCE define causes problems for Mac OS X, so omit |
| 435 | | -** it. |
| 436 | | -*/ |
| 437 | | -#if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__) |
| 438 | | -# define _XOPEN_SOURCE 600 |
| 439 | | -#endif |
| 440 | | - |
| 441 | | -/* |
| 442 | | -** NDEBUG and SQLITE_DEBUG are opposites. It should always be true that |
| 443 | | -** defined(NDEBUG)==!defined(SQLITE_DEBUG). If this is not currently true, |
| 444 | | -** make it true by defining or undefining NDEBUG. |
| 445 | | -** |
| 446 | | -** Setting NDEBUG makes the code smaller and faster by disabling the |
| 447 | | -** assert() statements in the code. So we want the default action |
| 448 | | -** to be for NDEBUG to be set and NDEBUG to be undefined only if SQLITE_DEBUG |
| 449 | | -** is set. Thus NDEBUG becomes an opt-in rather than an opt-out |
| 450 | | -** feature. |
| 451 | | -*/ |
| 452 | | -#if !defined(NDEBUG) && !defined(SQLITE_DEBUG) |
| 453 | | -# define NDEBUG 1 |
| 454 | | -#endif |
| 455 | | -#if defined(NDEBUG) && defined(SQLITE_DEBUG) |
| 456 | | -# undef NDEBUG |
| 457 | | -#endif |
| 458 | | - |
| 459 | | -/* |
| 460 | | -** The testcase() macro is used to aid in coverage testing. When |
| 461 | | -** doing coverage testing, the condition inside the argument to |
| 462 | | -** testcase() must be evaluated both true and false in order to |
| 463 | | -** get full branch coverage. The testcase() macro is inserted |
| 464 | | -** to help ensure adequate test coverage in places where simple |
| 465 | | -** condition/decision coverage is inadequate. For example, testcase() |
| 466 | | -** can be used to make sure boundary values are tested. For |
| 467 | | -** bitmask tests, testcase() can be used to make sure each bit |
| 468 | | -** is significant and used at least once. On switch statements |
| 469 | | -** where multiple cases go to the same block of code, testcase() |
| 470 | | -** can insure that all cases are evaluated. |
| 471 | | -** |
| 472 | | -*/ |
| 473 | | -#ifdef SQLITE_COVERAGE_TEST |
| 474 | | -SQLITE_PRIVATE void sqlite3Coverage(int); |
| 475 | | -# define testcase(X) if( X ){ sqlite3Coverage(__LINE__); } |
| 476 | | -#else |
| 477 | | -# define testcase(X) |
| 478 | | -#endif |
| 479 | | - |
| 480 | | -/* |
| 481 | | -** The TESTONLY macro is used to enclose variable declarations or |
| 482 | | -** other bits of code that are needed to support the arguments |
| 483 | | -** within testcase() and assert() macros. |
| 484 | | -*/ |
| 485 | | -#if !defined(NDEBUG) || defined(SQLITE_COVERAGE_TEST) |
| 486 | | -# define TESTONLY(X) X |
| 487 | | -#else |
| 488 | | -# define TESTONLY(X) |
| 489 | | -#endif |
| 490 | | - |
| 491 | | -/* |
| 492 | | -** Sometimes we need a small amount of code such as a variable initialization |
| 493 | | -** to setup for a later assert() statement. We do not want this code to |
| 494 | | -** appear when assert() is disabled. The following macro is therefore |
| 495 | | -** used to contain that setup code. The "VVA" acronym stands for |
| 496 | | -** "Verification, Validation, and Accreditation". In other words, the |
| 497 | | -** code within VVA_ONLY() will only run during verification processes. |
| 498 | | -*/ |
| 499 | | -#ifndef NDEBUG |
| 500 | | -# define VVA_ONLY(X) X |
| 501 | | -#else |
| 502 | | -# define VVA_ONLY(X) |
| 503 | | -#endif |
| 504 | | - |
| 505 | | -/* |
| 506 | | -** The ALWAYS and NEVER macros surround boolean expressions which |
| 507 | | -** are intended to always be true or false, respectively. Such |
| 508 | | -** expressions could be omitted from the code completely. But they |
| 509 | | -** are included in a few cases in order to enhance the resilience |
| 510 | | -** of SQLite to unexpected behavior - to make the code "self-healing" |
| 511 | | -** or "ductile" rather than being "brittle" and crashing at the first |
| 512 | | -** hint of unplanned behavior. |
| 513 | | -** |
| 514 | | -** In other words, ALWAYS and NEVER are added for defensive code. |
| 515 | | -** |
| 516 | | -** When doing coverage testing ALWAYS and NEVER are hard-coded to |
| 517 | | -** be true and false so that the unreachable code they specify will |
| 518 | | -** not be counted as untested code. |
| 519 | | -*/ |
| 520 | | -#if defined(SQLITE_COVERAGE_TEST) |
| 521 | | -# define ALWAYS(X) (1) |
| 522 | | -# define NEVER(X) (0) |
| 523 | | -#elif !defined(NDEBUG) |
| 524 | | -# define ALWAYS(X) ((X)?1:(assert(0),0)) |
| 525 | | -# define NEVER(X) ((X)?(assert(0),1):0) |
| 526 | | -#else |
| 527 | | -# define ALWAYS(X) (X) |
| 528 | | -# define NEVER(X) (X) |
| 529 | | -#endif |
| 530 | | - |
| 531 | | -/* |
| 532 | | -** Return true (non-zero) if the input is a integer that is too large |
| 533 | | -** to fit in 32-bits. This macro is used inside of various testcase() |
| 534 | | -** macros to verify that we have tested SQLite for large-file support. |
| 535 | | -*/ |
| 536 | | -#define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0) |
| 537 | | - |
| 538 | | -/* |
| 539 | | -** The macro unlikely() is a hint that surrounds a boolean |
| 540 | | -** expression that is usually false. Macro likely() surrounds |
| 541 | | -** a boolean expression that is usually true. These hints could, |
| 542 | | -** in theory, be used by the compiler to generate better code, but |
| 543 | | -** currently they are just comments for human readers. |
| 544 | | -*/ |
| 545 | | -#define likely(X) (X) |
| 546 | | -#define unlikely(X) (X) |
| 547 | | - |
| 548 | | -/************** Include sqlite3.h in the middle of sqliteInt.h ***************/ |
| 549 | 28 | /************** Begin file sqlite3.h *****************************************/ |
| 550 | 29 | /* |
| 551 | 30 | ** 2001 September 15 |
| 552 | 31 | ** |
| 553 | 32 | ** The author disclaims copyright to this source code. In place of |
| | @@ -656,11 +135,11 @@ |
| 656 | 135 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 657 | 136 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 658 | 137 | */ |
| 659 | 138 | #define SQLITE_VERSION "3.8.1" |
| 660 | 139 | #define SQLITE_VERSION_NUMBER 3008001 |
| 661 | | -#define SQLITE_SOURCE_ID "2013-09-16 12:57:19 daf6ba413cb3cb6065774ba07495eab4a28b49b0" |
| 140 | +#define SQLITE_SOURCE_ID "2013-10-11 13:27:26 03593817ab5abdd4bbaa5e47e2e4745eef025af9" |
| 662 | 141 | |
| 663 | 142 | /* |
| 664 | 143 | ** CAPI3REF: Run-Time Library Version Numbers |
| 665 | 144 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 666 | 145 | ** |
| | @@ -7846,11 +7325,530 @@ |
| 7846 | 7325 | |
| 7847 | 7326 | #endif /* ifndef _SQLITE3RTREE_H_ */ |
| 7848 | 7327 | |
| 7849 | 7328 | |
| 7850 | 7329 | /************** End of sqlite3.h *********************************************/ |
| 7330 | +/************** Begin file sqliteInt.h ***************************************/ |
| 7331 | +/* |
| 7332 | +** 2001 September 15 |
| 7333 | +** |
| 7334 | +** The author disclaims copyright to this source code. In place of |
| 7335 | +** a legal notice, here is a blessing: |
| 7336 | +** |
| 7337 | +** May you do good and not evil. |
| 7338 | +** May you find forgiveness for yourself and forgive others. |
| 7339 | +** May you share freely, never taking more than you give. |
| 7340 | +** |
| 7341 | +************************************************************************* |
| 7342 | +** Internal interface definitions for SQLite. |
| 7343 | +** |
| 7344 | +*/ |
| 7345 | +#ifndef _SQLITEINT_H_ |
| 7346 | +#define _SQLITEINT_H_ |
| 7347 | + |
| 7348 | +/* |
| 7349 | +** These #defines should enable >2GB file support on POSIX if the |
| 7350 | +** underlying operating system supports it. If the OS lacks |
| 7351 | +** large file support, or if the OS is windows, these should be no-ops. |
| 7352 | +** |
| 7353 | +** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any |
| 7354 | +** system #includes. Hence, this block of code must be the very first |
| 7355 | +** code in all source files. |
| 7356 | +** |
| 7357 | +** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch |
| 7358 | +** on the compiler command line. This is necessary if you are compiling |
| 7359 | +** on a recent machine (ex: Red Hat 7.2) but you want your code to work |
| 7360 | +** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2 |
| 7361 | +** without this option, LFS is enable. But LFS does not exist in the kernel |
| 7362 | +** in Red Hat 6.0, so the code won't work. Hence, for maximum binary |
| 7363 | +** portability you should omit LFS. |
| 7364 | +** |
| 7365 | +** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later. |
| 7366 | +*/ |
| 7367 | +#ifndef SQLITE_DISABLE_LFS |
| 7368 | +# define _LARGE_FILE 1 |
| 7369 | +# ifndef _FILE_OFFSET_BITS |
| 7370 | +# define _FILE_OFFSET_BITS 64 |
| 7371 | +# endif |
| 7372 | +# define _LARGEFILE_SOURCE 1 |
| 7373 | +#endif |
| 7374 | + |
| 7375 | +/* |
| 7376 | +** Include the configuration header output by 'configure' if we're using the |
| 7377 | +** autoconf-based build |
| 7378 | +*/ |
| 7379 | +#ifdef _HAVE_SQLITE_CONFIG_H |
| 7380 | +#include "config.h" |
| 7381 | +#endif |
| 7382 | + |
| 7383 | +/************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/ |
| 7384 | +/************** Begin file sqliteLimit.h *************************************/ |
| 7385 | +/* |
| 7386 | +** 2007 May 7 |
| 7387 | +** |
| 7388 | +** The author disclaims copyright to this source code. In place of |
| 7389 | +** a legal notice, here is a blessing: |
| 7390 | +** |
| 7391 | +** May you do good and not evil. |
| 7392 | +** May you find forgiveness for yourself and forgive others. |
| 7393 | +** May you share freely, never taking more than you give. |
| 7394 | +** |
| 7395 | +************************************************************************* |
| 7396 | +** |
| 7397 | +** This file defines various limits of what SQLite can process. |
| 7398 | +*/ |
| 7399 | + |
| 7400 | +/* |
| 7401 | +** The maximum length of a TEXT or BLOB in bytes. This also |
| 7402 | +** limits the size of a row in a table or index. |
| 7403 | +** |
| 7404 | +** The hard limit is the ability of a 32-bit signed integer |
| 7405 | +** to count the size: 2^31-1 or 2147483647. |
| 7406 | +*/ |
| 7407 | +#ifndef SQLITE_MAX_LENGTH |
| 7408 | +# define SQLITE_MAX_LENGTH 1000000000 |
| 7409 | +#endif |
| 7410 | + |
| 7411 | +/* |
| 7412 | +** This is the maximum number of |
| 7413 | +** |
| 7414 | +** * Columns in a table |
| 7415 | +** * Columns in an index |
| 7416 | +** * Columns in a view |
| 7417 | +** * Terms in the SET clause of an UPDATE statement |
| 7418 | +** * Terms in the result set of a SELECT statement |
| 7419 | +** * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement. |
| 7420 | +** * Terms in the VALUES clause of an INSERT statement |
| 7421 | +** |
| 7422 | +** The hard upper limit here is 32676. Most database people will |
| 7423 | +** tell you that in a well-normalized database, you usually should |
| 7424 | +** not have more than a dozen or so columns in any table. And if |
| 7425 | +** that is the case, there is no point in having more than a few |
| 7426 | +** dozen values in any of the other situations described above. |
| 7427 | +*/ |
| 7428 | +#ifndef SQLITE_MAX_COLUMN |
| 7429 | +# define SQLITE_MAX_COLUMN 2000 |
| 7430 | +#endif |
| 7431 | + |
| 7432 | +/* |
| 7433 | +** The maximum length of a single SQL statement in bytes. |
| 7434 | +** |
| 7435 | +** It used to be the case that setting this value to zero would |
| 7436 | +** turn the limit off. That is no longer true. It is not possible |
| 7437 | +** to turn this limit off. |
| 7438 | +*/ |
| 7439 | +#ifndef SQLITE_MAX_SQL_LENGTH |
| 7440 | +# define SQLITE_MAX_SQL_LENGTH 1000000000 |
| 7441 | +#endif |
| 7442 | + |
| 7443 | +/* |
| 7444 | +** The maximum depth of an expression tree. This is limited to |
| 7445 | +** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might |
| 7446 | +** want to place more severe limits on the complexity of an |
| 7447 | +** expression. |
| 7448 | +** |
| 7449 | +** A value of 0 used to mean that the limit was not enforced. |
| 7450 | +** But that is no longer true. The limit is now strictly enforced |
| 7451 | +** at all times. |
| 7452 | +*/ |
| 7453 | +#ifndef SQLITE_MAX_EXPR_DEPTH |
| 7454 | +# define SQLITE_MAX_EXPR_DEPTH 1000 |
| 7455 | +#endif |
| 7456 | + |
| 7457 | +/* |
| 7458 | +** The maximum number of terms in a compound SELECT statement. |
| 7459 | +** The code generator for compound SELECT statements does one |
| 7460 | +** level of recursion for each term. A stack overflow can result |
| 7461 | +** if the number of terms is too large. In practice, most SQL |
| 7462 | +** never has more than 3 or 4 terms. Use a value of 0 to disable |
| 7463 | +** any limit on the number of terms in a compount SELECT. |
| 7464 | +*/ |
| 7465 | +#ifndef SQLITE_MAX_COMPOUND_SELECT |
| 7466 | +# define SQLITE_MAX_COMPOUND_SELECT 500 |
| 7467 | +#endif |
| 7468 | + |
| 7469 | +/* |
| 7470 | +** The maximum number of opcodes in a VDBE program. |
| 7471 | +** Not currently enforced. |
| 7472 | +*/ |
| 7473 | +#ifndef SQLITE_MAX_VDBE_OP |
| 7474 | +# define SQLITE_MAX_VDBE_OP 25000 |
| 7475 | +#endif |
| 7476 | + |
| 7477 | +/* |
| 7478 | +** The maximum number of arguments to an SQL function. |
| 7479 | +*/ |
| 7480 | +#ifndef SQLITE_MAX_FUNCTION_ARG |
| 7481 | +# define SQLITE_MAX_FUNCTION_ARG 127 |
| 7482 | +#endif |
| 7483 | + |
| 7484 | +/* |
| 7485 | +** The maximum number of in-memory pages to use for the main database |
| 7486 | +** table and for temporary tables. The SQLITE_DEFAULT_CACHE_SIZE |
| 7487 | +*/ |
| 7488 | +#ifndef SQLITE_DEFAULT_CACHE_SIZE |
| 7489 | +# define SQLITE_DEFAULT_CACHE_SIZE 2000 |
| 7490 | +#endif |
| 7491 | +#ifndef SQLITE_DEFAULT_TEMP_CACHE_SIZE |
| 7492 | +# define SQLITE_DEFAULT_TEMP_CACHE_SIZE 500 |
| 7493 | +#endif |
| 7494 | + |
| 7495 | +/* |
| 7496 | +** The default number of frames to accumulate in the log file before |
| 7497 | +** checkpointing the database in WAL mode. |
| 7498 | +*/ |
| 7499 | +#ifndef SQLITE_DEFAULT_WAL_AUTOCHECKPOINT |
| 7500 | +# define SQLITE_DEFAULT_WAL_AUTOCHECKPOINT 1000 |
| 7501 | +#endif |
| 7502 | + |
| 7503 | +/* |
| 7504 | +** The maximum number of attached databases. This must be between 0 |
| 7505 | +** and 62. The upper bound on 62 is because a 64-bit integer bitmap |
| 7506 | +** is used internally to track attached databases. |
| 7507 | +*/ |
| 7508 | +#ifndef SQLITE_MAX_ATTACHED |
| 7509 | +# define SQLITE_MAX_ATTACHED 10 |
| 7510 | +#endif |
| 7511 | + |
| 7512 | + |
| 7513 | +/* |
| 7514 | +** The maximum value of a ?nnn wildcard that the parser will accept. |
| 7515 | +*/ |
| 7516 | +#ifndef SQLITE_MAX_VARIABLE_NUMBER |
| 7517 | +# define SQLITE_MAX_VARIABLE_NUMBER 999 |
| 7518 | +#endif |
| 7519 | + |
| 7520 | +/* Maximum page size. The upper bound on this value is 65536. This a limit |
| 7521 | +** imposed by the use of 16-bit offsets within each page. |
| 7522 | +** |
| 7523 | +** Earlier versions of SQLite allowed the user to change this value at |
| 7524 | +** compile time. This is no longer permitted, on the grounds that it creates |
| 7525 | +** a library that is technically incompatible with an SQLite library |
| 7526 | +** compiled with a different limit. If a process operating on a database |
| 7527 | +** with a page-size of 65536 bytes crashes, then an instance of SQLite |
| 7528 | +** compiled with the default page-size limit will not be able to rollback |
| 7529 | +** the aborted transaction. This could lead to database corruption. |
| 7530 | +*/ |
| 7531 | +#ifdef SQLITE_MAX_PAGE_SIZE |
| 7532 | +# undef SQLITE_MAX_PAGE_SIZE |
| 7533 | +#endif |
| 7534 | +#define SQLITE_MAX_PAGE_SIZE 65536 |
| 7535 | + |
| 7536 | + |
| 7537 | +/* |
| 7538 | +** The default size of a database page. |
| 7539 | +*/ |
| 7540 | +#ifndef SQLITE_DEFAULT_PAGE_SIZE |
| 7541 | +# define SQLITE_DEFAULT_PAGE_SIZE 1024 |
| 7542 | +#endif |
| 7543 | +#if SQLITE_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE |
| 7544 | +# undef SQLITE_DEFAULT_PAGE_SIZE |
| 7545 | +# define SQLITE_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE |
| 7546 | +#endif |
| 7547 | + |
| 7548 | +/* |
| 7549 | +** Ordinarily, if no value is explicitly provided, SQLite creates databases |
| 7550 | +** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain |
| 7551 | +** device characteristics (sector-size and atomic write() support), |
| 7552 | +** SQLite may choose a larger value. This constant is the maximum value |
| 7553 | +** SQLite will choose on its own. |
| 7554 | +*/ |
| 7555 | +#ifndef SQLITE_MAX_DEFAULT_PAGE_SIZE |
| 7556 | +# define SQLITE_MAX_DEFAULT_PAGE_SIZE 8192 |
| 7557 | +#endif |
| 7558 | +#if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE |
| 7559 | +# undef SQLITE_MAX_DEFAULT_PAGE_SIZE |
| 7560 | +# define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE |
| 7561 | +#endif |
| 7562 | + |
| 7563 | + |
| 7564 | +/* |
| 7565 | +** Maximum number of pages in one database file. |
| 7566 | +** |
| 7567 | +** This is really just the default value for the max_page_count pragma. |
| 7568 | +** This value can be lowered (or raised) at run-time using that the |
| 7569 | +** max_page_count macro. |
| 7570 | +*/ |
| 7571 | +#ifndef SQLITE_MAX_PAGE_COUNT |
| 7572 | +# define SQLITE_MAX_PAGE_COUNT 1073741823 |
| 7573 | +#endif |
| 7574 | + |
| 7575 | +/* |
| 7576 | +** Maximum length (in bytes) of the pattern in a LIKE or GLOB |
| 7577 | +** operator. |
| 7578 | +*/ |
| 7579 | +#ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH |
| 7580 | +# define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000 |
| 7581 | +#endif |
| 7582 | + |
| 7583 | +/* |
| 7584 | +** Maximum depth of recursion for triggers. |
| 7585 | +** |
| 7586 | +** A value of 1 means that a trigger program will not be able to itself |
| 7587 | +** fire any triggers. A value of 0 means that no trigger programs at all |
| 7588 | +** may be executed. |
| 7589 | +*/ |
| 7590 | +#ifndef SQLITE_MAX_TRIGGER_DEPTH |
| 7591 | +# define SQLITE_MAX_TRIGGER_DEPTH 1000 |
| 7592 | +#endif |
| 7593 | + |
| 7594 | +/************** End of sqliteLimit.h *****************************************/ |
| 7851 | 7595 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| 7596 | + |
| 7597 | +/* Disable nuisance warnings on Borland compilers */ |
| 7598 | +#if defined(__BORLANDC__) |
| 7599 | +#pragma warn -rch /* unreachable code */ |
| 7600 | +#pragma warn -ccc /* Condition is always true or false */ |
| 7601 | +#pragma warn -aus /* Assigned value is never used */ |
| 7602 | +#pragma warn -csu /* Comparing signed and unsigned */ |
| 7603 | +#pragma warn -spa /* Suspicious pointer arithmetic */ |
| 7604 | +#endif |
| 7605 | + |
| 7606 | +/* Needed for various definitions... */ |
| 7607 | +#ifndef _GNU_SOURCE |
| 7608 | +# define _GNU_SOURCE |
| 7609 | +#endif |
| 7610 | + |
| 7611 | +#if defined(__OpenBSD__) && !defined(_BSD_SOURCE) |
| 7612 | +# define _BSD_SOURCE |
| 7613 | +#endif |
| 7614 | + |
| 7615 | +/* |
| 7616 | +** Include standard header files as necessary |
| 7617 | +*/ |
| 7618 | +#ifdef HAVE_STDINT_H |
| 7619 | +#include <stdint.h> |
| 7620 | +#endif |
| 7621 | +#ifdef HAVE_INTTYPES_H |
| 7622 | +#include <inttypes.h> |
| 7623 | +#endif |
| 7624 | + |
| 7625 | +/* |
| 7626 | +** The following macros are used to cast pointers to integers and |
| 7627 | +** integers to pointers. The way you do this varies from one compiler |
| 7628 | +** to the next, so we have developed the following set of #if statements |
| 7629 | +** to generate appropriate macros for a wide range of compilers. |
| 7630 | +** |
| 7631 | +** The correct "ANSI" way to do this is to use the intptr_t type. |
| 7632 | +** Unfortunately, that typedef is not available on all compilers, or |
| 7633 | +** if it is available, it requires an #include of specific headers |
| 7634 | +** that vary from one machine to the next. |
| 7635 | +** |
| 7636 | +** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on |
| 7637 | +** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)). |
| 7638 | +** So we have to define the macros in different ways depending on the |
| 7639 | +** compiler. |
| 7640 | +*/ |
| 7641 | +#if defined(__PTRDIFF_TYPE__) /* This case should work for GCC */ |
| 7642 | +# define SQLITE_INT_TO_PTR(X) ((void*)(__PTRDIFF_TYPE__)(X)) |
| 7643 | +# define SQLITE_PTR_TO_INT(X) ((int)(__PTRDIFF_TYPE__)(X)) |
| 7644 | +#elif !defined(__GNUC__) /* Works for compilers other than LLVM */ |
| 7645 | +# define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X]) |
| 7646 | +# define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0)) |
| 7647 | +#elif defined(HAVE_STDINT_H) /* Use this case if we have ANSI headers */ |
| 7648 | +# define SQLITE_INT_TO_PTR(X) ((void*)(intptr_t)(X)) |
| 7649 | +# define SQLITE_PTR_TO_INT(X) ((int)(intptr_t)(X)) |
| 7650 | +#else /* Generates a warning - but it always works */ |
| 7651 | +# define SQLITE_INT_TO_PTR(X) ((void*)(X)) |
| 7652 | +# define SQLITE_PTR_TO_INT(X) ((int)(X)) |
| 7653 | +#endif |
| 7654 | + |
| 7655 | +/* |
| 7656 | +** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2. |
| 7657 | +** 0 means mutexes are permanently disable and the library is never |
| 7658 | +** threadsafe. 1 means the library is serialized which is the highest |
| 7659 | +** level of threadsafety. 2 means the library is multithreaded - multiple |
| 7660 | +** threads can use SQLite as long as no two threads try to use the same |
| 7661 | +** database connection at the same time. |
| 7662 | +** |
| 7663 | +** Older versions of SQLite used an optional THREADSAFE macro. |
| 7664 | +** We support that for legacy. |
| 7665 | +*/ |
| 7666 | +#if !defined(SQLITE_THREADSAFE) |
| 7667 | +# if defined(THREADSAFE) |
| 7668 | +# define SQLITE_THREADSAFE THREADSAFE |
| 7669 | +# else |
| 7670 | +# define SQLITE_THREADSAFE 1 /* IMP: R-07272-22309 */ |
| 7671 | +# endif |
| 7672 | +#endif |
| 7673 | + |
| 7674 | +/* |
| 7675 | +** Powersafe overwrite is on by default. But can be turned off using |
| 7676 | +** the -DSQLITE_POWERSAFE_OVERWRITE=0 command-line option. |
| 7677 | +*/ |
| 7678 | +#ifndef SQLITE_POWERSAFE_OVERWRITE |
| 7679 | +# define SQLITE_POWERSAFE_OVERWRITE 1 |
| 7680 | +#endif |
| 7681 | + |
| 7682 | +/* |
| 7683 | +** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1. |
| 7684 | +** It determines whether or not the features related to |
| 7685 | +** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can |
| 7686 | +** be overridden at runtime using the sqlite3_config() API. |
| 7687 | +*/ |
| 7688 | +#if !defined(SQLITE_DEFAULT_MEMSTATUS) |
| 7689 | +# define SQLITE_DEFAULT_MEMSTATUS 1 |
| 7690 | +#endif |
| 7691 | + |
| 7692 | +/* |
| 7693 | +** Exactly one of the following macros must be defined in order to |
| 7694 | +** specify which memory allocation subsystem to use. |
| 7695 | +** |
| 7696 | +** SQLITE_SYSTEM_MALLOC // Use normal system malloc() |
| 7697 | +** SQLITE_WIN32_MALLOC // Use Win32 native heap API |
| 7698 | +** SQLITE_ZERO_MALLOC // Use a stub allocator that always fails |
| 7699 | +** SQLITE_MEMDEBUG // Debugging version of system malloc() |
| 7700 | +** |
| 7701 | +** On Windows, if the SQLITE_WIN32_MALLOC_VALIDATE macro is defined and the |
| 7702 | +** assert() macro is enabled, each call into the Win32 native heap subsystem |
| 7703 | +** will cause HeapValidate to be called. If heap validation should fail, an |
| 7704 | +** assertion will be triggered. |
| 7705 | +** |
| 7706 | +** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as |
| 7707 | +** the default. |
| 7708 | +*/ |
| 7709 | +#if defined(SQLITE_SYSTEM_MALLOC) \ |
| 7710 | + + defined(SQLITE_WIN32_MALLOC) \ |
| 7711 | + + defined(SQLITE_ZERO_MALLOC) \ |
| 7712 | + + defined(SQLITE_MEMDEBUG)>1 |
| 7713 | +# error "Two or more of the following compile-time configuration options\ |
| 7714 | + are defined but at most one is allowed:\ |
| 7715 | + SQLITE_SYSTEM_MALLOC, SQLITE_WIN32_MALLOC, SQLITE_MEMDEBUG,\ |
| 7716 | + SQLITE_ZERO_MALLOC" |
| 7717 | +#endif |
| 7718 | +#if defined(SQLITE_SYSTEM_MALLOC) \ |
| 7719 | + + defined(SQLITE_WIN32_MALLOC) \ |
| 7720 | + + defined(SQLITE_ZERO_MALLOC) \ |
| 7721 | + + defined(SQLITE_MEMDEBUG)==0 |
| 7722 | +# define SQLITE_SYSTEM_MALLOC 1 |
| 7723 | +#endif |
| 7724 | + |
| 7725 | +/* |
| 7726 | +** If SQLITE_MALLOC_SOFT_LIMIT is not zero, then try to keep the |
| 7727 | +** sizes of memory allocations below this value where possible. |
| 7728 | +*/ |
| 7729 | +#if !defined(SQLITE_MALLOC_SOFT_LIMIT) |
| 7730 | +# define SQLITE_MALLOC_SOFT_LIMIT 1024 |
| 7731 | +#endif |
| 7732 | + |
| 7733 | +/* |
| 7734 | +** We need to define _XOPEN_SOURCE as follows in order to enable |
| 7735 | +** recursive mutexes on most Unix systems and fchmod() on OpenBSD. |
| 7736 | +** But _XOPEN_SOURCE define causes problems for Mac OS X, so omit |
| 7737 | +** it. |
| 7738 | +*/ |
| 7739 | +#if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__) |
| 7740 | +# define _XOPEN_SOURCE 600 |
| 7741 | +#endif |
| 7742 | + |
| 7743 | +/* |
| 7744 | +** NDEBUG and SQLITE_DEBUG are opposites. It should always be true that |
| 7745 | +** defined(NDEBUG)==!defined(SQLITE_DEBUG). If this is not currently true, |
| 7746 | +** make it true by defining or undefining NDEBUG. |
| 7747 | +** |
| 7748 | +** Setting NDEBUG makes the code smaller and faster by disabling the |
| 7749 | +** assert() statements in the code. So we want the default action |
| 7750 | +** to be for NDEBUG to be set and NDEBUG to be undefined only if SQLITE_DEBUG |
| 7751 | +** is set. Thus NDEBUG becomes an opt-in rather than an opt-out |
| 7752 | +** feature. |
| 7753 | +*/ |
| 7754 | +#if !defined(NDEBUG) && !defined(SQLITE_DEBUG) |
| 7755 | +# define NDEBUG 1 |
| 7756 | +#endif |
| 7757 | +#if defined(NDEBUG) && defined(SQLITE_DEBUG) |
| 7758 | +# undef NDEBUG |
| 7759 | +#endif |
| 7760 | + |
| 7761 | +/* |
| 7762 | +** The testcase() macro is used to aid in coverage testing. When |
| 7763 | +** doing coverage testing, the condition inside the argument to |
| 7764 | +** testcase() must be evaluated both true and false in order to |
| 7765 | +** get full branch coverage. The testcase() macro is inserted |
| 7766 | +** to help ensure adequate test coverage in places where simple |
| 7767 | +** condition/decision coverage is inadequate. For example, testcase() |
| 7768 | +** can be used to make sure boundary values are tested. For |
| 7769 | +** bitmask tests, testcase() can be used to make sure each bit |
| 7770 | +** is significant and used at least once. On switch statements |
| 7771 | +** where multiple cases go to the same block of code, testcase() |
| 7772 | +** can insure that all cases are evaluated. |
| 7773 | +** |
| 7774 | +*/ |
| 7775 | +#ifdef SQLITE_COVERAGE_TEST |
| 7776 | +SQLITE_PRIVATE void sqlite3Coverage(int); |
| 7777 | +# define testcase(X) if( X ){ sqlite3Coverage(__LINE__); } |
| 7778 | +#else |
| 7779 | +# define testcase(X) |
| 7780 | +#endif |
| 7781 | + |
| 7782 | +/* |
| 7783 | +** The TESTONLY macro is used to enclose variable declarations or |
| 7784 | +** other bits of code that are needed to support the arguments |
| 7785 | +** within testcase() and assert() macros. |
| 7786 | +*/ |
| 7787 | +#if !defined(NDEBUG) || defined(SQLITE_COVERAGE_TEST) |
| 7788 | +# define TESTONLY(X) X |
| 7789 | +#else |
| 7790 | +# define TESTONLY(X) |
| 7791 | +#endif |
| 7792 | + |
| 7793 | +/* |
| 7794 | +** Sometimes we need a small amount of code such as a variable initialization |
| 7795 | +** to setup for a later assert() statement. We do not want this code to |
| 7796 | +** appear when assert() is disabled. The following macro is therefore |
| 7797 | +** used to contain that setup code. The "VVA" acronym stands for |
| 7798 | +** "Verification, Validation, and Accreditation". In other words, the |
| 7799 | +** code within VVA_ONLY() will only run during verification processes. |
| 7800 | +*/ |
| 7801 | +#ifndef NDEBUG |
| 7802 | +# define VVA_ONLY(X) X |
| 7803 | +#else |
| 7804 | +# define VVA_ONLY(X) |
| 7805 | +#endif |
| 7806 | + |
| 7807 | +/* |
| 7808 | +** The ALWAYS and NEVER macros surround boolean expressions which |
| 7809 | +** are intended to always be true or false, respectively. Such |
| 7810 | +** expressions could be omitted from the code completely. But they |
| 7811 | +** are included in a few cases in order to enhance the resilience |
| 7812 | +** of SQLite to unexpected behavior - to make the code "self-healing" |
| 7813 | +** or "ductile" rather than being "brittle" and crashing at the first |
| 7814 | +** hint of unplanned behavior. |
| 7815 | +** |
| 7816 | +** In other words, ALWAYS and NEVER are added for defensive code. |
| 7817 | +** |
| 7818 | +** When doing coverage testing ALWAYS and NEVER are hard-coded to |
| 7819 | +** be true and false so that the unreachable code they specify will |
| 7820 | +** not be counted as untested code. |
| 7821 | +*/ |
| 7822 | +#if defined(SQLITE_COVERAGE_TEST) |
| 7823 | +# define ALWAYS(X) (1) |
| 7824 | +# define NEVER(X) (0) |
| 7825 | +#elif !defined(NDEBUG) |
| 7826 | +# define ALWAYS(X) ((X)?1:(assert(0),0)) |
| 7827 | +# define NEVER(X) ((X)?(assert(0),1):0) |
| 7828 | +#else |
| 7829 | +# define ALWAYS(X) (X) |
| 7830 | +# define NEVER(X) (X) |
| 7831 | +#endif |
| 7832 | + |
| 7833 | +/* |
| 7834 | +** Return true (non-zero) if the input is a integer that is too large |
| 7835 | +** to fit in 32-bits. This macro is used inside of various testcase() |
| 7836 | +** macros to verify that we have tested SQLite for large-file support. |
| 7837 | +*/ |
| 7838 | +#define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0) |
| 7839 | + |
| 7840 | +/* |
| 7841 | +** The macro unlikely() is a hint that surrounds a boolean |
| 7842 | +** expression that is usually false. Macro likely() surrounds |
| 7843 | +** a boolean expression that is usually true. These hints could, |
| 7844 | +** in theory, be used by the compiler to generate better code, but |
| 7845 | +** currently they are just comments for human readers. |
| 7846 | +*/ |
| 7847 | +#define likely(X) (X) |
| 7848 | +#define unlikely(X) (X) |
| 7849 | + |
| 7852 | 7850 | /************** Include hash.h in the middle of sqliteInt.h ******************/ |
| 7853 | 7851 | /************** Begin file hash.h ********************************************/ |
| 7854 | 7852 | /* |
| 7855 | 7853 | ** 2001 September 22 |
| 7856 | 7854 | ** |
| | @@ -8272,10 +8270,35 @@ |
| 8272 | 8270 | typedef u64 tRowcnt; /* 64-bit only if requested at compile-time */ |
| 8273 | 8271 | #else |
| 8274 | 8272 | typedef u32 tRowcnt; /* 32-bit is the default */ |
| 8275 | 8273 | #endif |
| 8276 | 8274 | |
| 8275 | +/* |
| 8276 | +** Estimated quantities used for query planning are stored as 16-bit |
| 8277 | +** logarithms. For quantity X, the value stored is 10*log2(X). This |
| 8278 | +** gives a possible range of values of approximately 1.0e986 to 1e-986. |
| 8279 | +** But the allowed values are "grainy". Not every value is representable. |
| 8280 | +** For example, quantities 16 and 17 are both represented by a LogEst |
| 8281 | +** of 40. However, since LogEst quantatites are suppose to be estimates, |
| 8282 | +** not exact values, this imprecision is not a problem. |
| 8283 | +** |
| 8284 | +** "LogEst" is short for "Logarithimic Estimate". |
| 8285 | +** |
| 8286 | +** Examples: |
| 8287 | +** 1 -> 0 20 -> 43 10000 -> 132 |
| 8288 | +** 2 -> 10 25 -> 46 25000 -> 146 |
| 8289 | +** 3 -> 16 100 -> 66 1000000 -> 199 |
| 8290 | +** 4 -> 20 1000 -> 99 1048576 -> 200 |
| 8291 | +** 10 -> 33 1024 -> 100 4294967296 -> 320 |
| 8292 | +** |
| 8293 | +** The LogEst can be negative to indicate fractional values. |
| 8294 | +** Examples: |
| 8295 | +** |
| 8296 | +** 0.5 -> -10 0.1 -> -33 0.0625 -> -40 |
| 8297 | +*/ |
| 8298 | +typedef INT16_TYPE LogEst; |
| 8299 | + |
| 8277 | 8300 | /* |
| 8278 | 8301 | ** Macros to determine whether the machine is big or little endian, |
| 8279 | 8302 | ** evaluated at runtime. |
| 8280 | 8303 | */ |
| 8281 | 8304 | #ifdef SQLITE_AMALGAMATION |
| | @@ -10419,11 +10442,12 @@ |
| 10419 | 10442 | char *zDflt; /* Original text of the default value */ |
| 10420 | 10443 | char *zType; /* Data type for this column */ |
| 10421 | 10444 | char *zColl; /* Collating sequence. If NULL, use the default */ |
| 10422 | 10445 | u8 notNull; /* An OE_ code for handling a NOT NULL constraint */ |
| 10423 | 10446 | char affinity; /* One of the SQLITE_AFF_... values */ |
| 10424 | | - u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */ |
| 10447 | + u8 szEst; /* Estimated size of this column. INT==1 */ |
| 10448 | + u8 colFlags; /* Boolean properties. See COLFLAG_ defines below */ |
| 10425 | 10449 | }; |
| 10426 | 10450 | |
| 10427 | 10451 | /* Allowed values for Column.colFlags: |
| 10428 | 10452 | */ |
| 10429 | 10453 | #define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */ |
| | @@ -10583,10 +10607,11 @@ |
| 10583 | 10607 | tRowcnt nRowEst; /* Estimated rows in table - from sqlite_stat1 table */ |
| 10584 | 10608 | int tnum; /* Root BTree node for this table (see note above) */ |
| 10585 | 10609 | i16 iPKey; /* If not negative, use aCol[iPKey] as the primary key */ |
| 10586 | 10610 | i16 nCol; /* Number of columns in this table */ |
| 10587 | 10611 | u16 nRef; /* Number of pointers to this Table */ |
| 10612 | + LogEst szTabRow; /* Estimated size of each table row in bytes */ |
| 10588 | 10613 | u8 tabFlags; /* Mask of TF_* values */ |
| 10589 | 10614 | u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ |
| 10590 | 10615 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 10591 | 10616 | int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */ |
| 10592 | 10617 | #endif |
| | @@ -10694,11 +10719,11 @@ |
| 10694 | 10719 | #define OE_Restrict 6 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */ |
| 10695 | 10720 | #define OE_SetNull 7 /* Set the foreign key value to NULL */ |
| 10696 | 10721 | #define OE_SetDflt 8 /* Set the foreign key value to its default */ |
| 10697 | 10722 | #define OE_Cascade 9 /* Cascade the changes */ |
| 10698 | 10723 | |
| 10699 | | -#define OE_Default 99 /* Do whatever the default action is */ |
| 10724 | +#define OE_Default 10 /* Do whatever the default action is */ |
| 10700 | 10725 | |
| 10701 | 10726 | |
| 10702 | 10727 | /* |
| 10703 | 10728 | ** An instance of the following structure is passed as the first |
| 10704 | 10729 | ** argument to sqlite3VdbeKeyCompare and is used to control the |
| | @@ -10781,10 +10806,11 @@ |
| 10781 | 10806 | Schema *pSchema; /* Schema containing this index */ |
| 10782 | 10807 | u8 *aSortOrder; /* for each column: True==DESC, False==ASC */ |
| 10783 | 10808 | char **azColl; /* Array of collation sequence names for index */ |
| 10784 | 10809 | Expr *pPartIdxWhere; /* WHERE clause for partial indices */ |
| 10785 | 10810 | int tnum; /* DB Page containing root of this index */ |
| 10811 | + LogEst szIdxRow; /* Estimated average row size in bytes */ |
| 10786 | 10812 | u16 nColumn; /* Number of columns in table used by this index */ |
| 10787 | 10813 | u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ |
| 10788 | 10814 | unsigned autoIndex:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */ |
| 10789 | 10815 | unsigned bUnordered:1; /* Use this index for == or IN queries only */ |
| 10790 | 10816 | unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */ |
| | @@ -11636,10 +11662,11 @@ |
| 11636 | 11662 | */ |
| 11637 | 11663 | typedef struct DbFixer DbFixer; |
| 11638 | 11664 | struct DbFixer { |
| 11639 | 11665 | Parse *pParse; /* The parsing context. Error messages written here */ |
| 11640 | 11666 | Schema *pSchema; /* Fix items to this schema */ |
| 11667 | + int bVarOnly; /* Check for variable references only */ |
| 11641 | 11668 | const char *zDb; /* Make sure all objects are contained in this database */ |
| 11642 | 11669 | const char *zType; /* Type of the container - used for error messages */ |
| 11643 | 11670 | const Token *pName; /* Name of the container - used for error messages */ |
| 11644 | 11671 | }; |
| 11645 | 11672 | |
| | @@ -12174,11 +12201,11 @@ |
| 12174 | 12201 | # define sqlite3AuthContextPush(a,b,c) |
| 12175 | 12202 | # define sqlite3AuthContextPop(a) ((void)(a)) |
| 12176 | 12203 | #endif |
| 12177 | 12204 | SQLITE_PRIVATE void sqlite3Attach(Parse*, Expr*, Expr*, Expr*); |
| 12178 | 12205 | SQLITE_PRIVATE void sqlite3Detach(Parse*, Expr*); |
| 12179 | | -SQLITE_PRIVATE int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*); |
| 12206 | +SQLITE_PRIVATE void sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*); |
| 12180 | 12207 | SQLITE_PRIVATE int sqlite3FixSrcList(DbFixer*, SrcList*); |
| 12181 | 12208 | SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*); |
| 12182 | 12209 | SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*); |
| 12183 | 12210 | SQLITE_PRIVATE int sqlite3FixExprList(DbFixer*, ExprList*); |
| 12184 | 12211 | SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*); |
| | @@ -12186,10 +12213,16 @@ |
| 12186 | 12213 | SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*); |
| 12187 | 12214 | SQLITE_PRIVATE int sqlite3Atoi(const char*); |
| 12188 | 12215 | SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar); |
| 12189 | 12216 | SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte); |
| 12190 | 12217 | SQLITE_PRIVATE u32 sqlite3Utf8Read(const u8**); |
| 12218 | +SQLITE_PRIVATE LogEst sqlite3LogEst(u64); |
| 12219 | +SQLITE_PRIVATE LogEst sqlite3LogEstAdd(LogEst,LogEst); |
| 12220 | +#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 12221 | +SQLITE_PRIVATE LogEst sqlite3LogEstFromDouble(double); |
| 12222 | +#endif |
| 12223 | +SQLITE_PRIVATE u64 sqlite3LogEstToInt(LogEst); |
| 12191 | 12224 | |
| 12192 | 12225 | /* |
| 12193 | 12226 | ** Routines to read and write variable-length integers. These used to |
| 12194 | 12227 | ** be defined locally, but now we use the varint routines in the util.c |
| 12195 | 12228 | ** file. Code should use the MACRO forms below, as the Varint32 versions |
| | @@ -12302,11 +12335,11 @@ |
| 12302 | 12335 | SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*); |
| 12303 | 12336 | SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *, Table *, int, int); |
| 12304 | 12337 | SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *, Token *); |
| 12305 | 12338 | SQLITE_PRIVATE void sqlite3AlterBeginAddColumn(Parse *, SrcList *); |
| 12306 | 12339 | SQLITE_PRIVATE CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*); |
| 12307 | | -SQLITE_PRIVATE char sqlite3AffinityType(const char*); |
| 12340 | +SQLITE_PRIVATE char sqlite3AffinityType(const char*, u8*); |
| 12308 | 12341 | SQLITE_PRIVATE void sqlite3Analyze(Parse*, Token*, Token*); |
| 12309 | 12342 | SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler*); |
| 12310 | 12343 | SQLITE_PRIVATE int sqlite3FindDb(sqlite3*, Token*); |
| 12311 | 12344 | SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *, const char *); |
| 12312 | 12345 | SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3*,int iDB); |
| | @@ -22387,10 +22420,87 @@ |
| 22387 | 22420 | for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){} |
| 22388 | 22421 | if( z[i]=='.' && ALWAYS(sz>i+4) ) memmove(&z[i+1], &z[sz-3], 4); |
| 22389 | 22422 | } |
| 22390 | 22423 | } |
| 22391 | 22424 | #endif |
| 22425 | + |
| 22426 | +/* |
| 22427 | +** Find (an approximate) sum of two LogEst values. This computation is |
| 22428 | +** not a simple "+" operator because LogEst is stored as a logarithmic |
| 22429 | +** value. |
| 22430 | +** |
| 22431 | +*/ |
| 22432 | +SQLITE_PRIVATE LogEst sqlite3LogEstAdd(LogEst a, LogEst b){ |
| 22433 | + static const unsigned char x[] = { |
| 22434 | + 10, 10, /* 0,1 */ |
| 22435 | + 9, 9, /* 2,3 */ |
| 22436 | + 8, 8, /* 4,5 */ |
| 22437 | + 7, 7, 7, /* 6,7,8 */ |
| 22438 | + 6, 6, 6, /* 9,10,11 */ |
| 22439 | + 5, 5, 5, /* 12-14 */ |
| 22440 | + 4, 4, 4, 4, /* 15-18 */ |
| 22441 | + 3, 3, 3, 3, 3, 3, /* 19-24 */ |
| 22442 | + 2, 2, 2, 2, 2, 2, 2, /* 25-31 */ |
| 22443 | + }; |
| 22444 | + if( a>=b ){ |
| 22445 | + if( a>b+49 ) return a; |
| 22446 | + if( a>b+31 ) return a+1; |
| 22447 | + return a+x[a-b]; |
| 22448 | + }else{ |
| 22449 | + if( b>a+49 ) return b; |
| 22450 | + if( b>a+31 ) return b+1; |
| 22451 | + return b+x[b-a]; |
| 22452 | + } |
| 22453 | +} |
| 22454 | + |
| 22455 | +/* |
| 22456 | +** Convert an integer into a LogEst. In other words, compute a |
| 22457 | +** good approximatation for 10*log2(x). |
| 22458 | +*/ |
| 22459 | +SQLITE_PRIVATE LogEst sqlite3LogEst(u64 x){ |
| 22460 | + static LogEst a[] = { 0, 2, 3, 5, 6, 7, 8, 9 }; |
| 22461 | + LogEst y = 40; |
| 22462 | + if( x<8 ){ |
| 22463 | + if( x<2 ) return 0; |
| 22464 | + while( x<8 ){ y -= 10; x <<= 1; } |
| 22465 | + }else{ |
| 22466 | + while( x>255 ){ y += 40; x >>= 4; } |
| 22467 | + while( x>15 ){ y += 10; x >>= 1; } |
| 22468 | + } |
| 22469 | + return a[x&7] + y - 10; |
| 22470 | +} |
| 22471 | + |
| 22472 | +#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 22473 | +/* |
| 22474 | +** Convert a double into a LogEst |
| 22475 | +** In other words, compute an approximation for 10*log2(x). |
| 22476 | +*/ |
| 22477 | +SQLITE_PRIVATE LogEst sqlite3LogEstFromDouble(double x){ |
| 22478 | + u64 a; |
| 22479 | + LogEst e; |
| 22480 | + assert( sizeof(x)==8 && sizeof(a)==8 ); |
| 22481 | + if( x<=1 ) return 0; |
| 22482 | + if( x<=2000000000 ) return sqlite3LogEst((u64)x); |
| 22483 | + memcpy(&a, &x, 8); |
| 22484 | + e = (a>>52) - 1022; |
| 22485 | + return e*10; |
| 22486 | +} |
| 22487 | +#endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 22488 | + |
| 22489 | +/* |
| 22490 | +** Convert a LogEst into an integer. |
| 22491 | +*/ |
| 22492 | +SQLITE_PRIVATE u64 sqlite3LogEstToInt(LogEst x){ |
| 22493 | + u64 n; |
| 22494 | + if( x<10 ) return 1; |
| 22495 | + n = x%10; |
| 22496 | + x /= 10; |
| 22497 | + if( n>=5 ) n -= 2; |
| 22498 | + else if( n>=1 ) n -= 1; |
| 22499 | + if( x>=3 ) return (n+8)<<(x-3); |
| 22500 | + return (n+8)>>(3-x); |
| 22501 | +} |
| 22392 | 22502 | |
| 22393 | 22503 | /************** End of util.c ************************************************/ |
| 22394 | 22504 | /************** Begin file hash.c ********************************************/ |
| 22395 | 22505 | /* |
| 22396 | 22506 | ** 2001 September 22 |
| | @@ -31382,11 +31492,11 @@ |
| 31382 | 31492 | #endif |
| 31383 | 31493 | |
| 31384 | 31494 | #define osGetVersionExA ((BOOL(WINAPI*)( \ |
| 31385 | 31495 | LPOSVERSIONINFOA))aSyscall[34].pCurrent) |
| 31386 | 31496 | |
| 31387 | | -#if defined(SQLITE_WIN32_HAS_WIDE) |
| 31497 | +#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) |
| 31388 | 31498 | { "GetVersionExW", (SYSCALL)GetVersionExW, 0 }, |
| 31389 | 31499 | #else |
| 31390 | 31500 | { "GetVersionExW", (SYSCALL)0, 0 }, |
| 31391 | 31501 | #endif |
| 31392 | 31502 | |
| | @@ -48986,17 +49096,17 @@ |
| 48986 | 49096 | ** page contain a special header (the "file header") that describes the file. |
| 48987 | 49097 | ** The format of the file header is as follows: |
| 48988 | 49098 | ** |
| 48989 | 49099 | ** OFFSET SIZE DESCRIPTION |
| 48990 | 49100 | ** 0 16 Header string: "SQLite format 3\000" |
| 48991 | | -** 16 2 Page size in bytes. |
| 49101 | +** 16 2 Page size in bytes. (1 means 65536) |
| 48992 | 49102 | ** 18 1 File format write version |
| 48993 | 49103 | ** 19 1 File format read version |
| 48994 | 49104 | ** 20 1 Bytes of unused space at the end of each page |
| 48995 | | -** 21 1 Max embedded payload fraction |
| 48996 | | -** 22 1 Min embedded payload fraction |
| 48997 | | -** 23 1 Min leaf payload fraction |
| 49105 | +** 21 1 Max embedded payload fraction (must be 64) |
| 49106 | +** 22 1 Min embedded payload fraction (must be 32) |
| 49107 | +** 23 1 Min leaf payload fraction (must be 32) |
| 48998 | 49108 | ** 24 4 File change counter |
| 48999 | 49109 | ** 28 4 Reserved for future use |
| 49000 | 49110 | ** 32 4 First freelist page |
| 49001 | 49111 | ** 36 4 Number of freelist pages in the file |
| 49002 | 49112 | ** 40 60 15 4-byte meta values passed to higher layers |
| | @@ -49006,13 +49116,14 @@ |
| 49006 | 49116 | ** 48 4 Size of page cache |
| 49007 | 49117 | ** 52 4 Largest root-page (auto/incr_vacuum) |
| 49008 | 49118 | ** 56 4 1=UTF-8 2=UTF16le 3=UTF16be |
| 49009 | 49119 | ** 60 4 User version |
| 49010 | 49120 | ** 64 4 Incremental vacuum mode |
| 49011 | | -** 68 4 unused |
| 49012 | | -** 72 4 unused |
| 49013 | | -** 76 4 unused |
| 49121 | +** 68 4 Application-ID |
| 49122 | +** 72 20 unused |
| 49123 | +** 92 4 The version-valid-for number |
| 49124 | +** 96 4 SQLITE_VERSION_NUMBER |
| 49014 | 49125 | ** |
| 49015 | 49126 | ** All of the integer values are big-endian (most significant byte first). |
| 49016 | 49127 | ** |
| 49017 | 49128 | ** The file change counter is incremented when the database is changed |
| 49018 | 49129 | ** This counter allows other processes to know when the file has changed |
| | @@ -52378,11 +52489,10 @@ |
| 52378 | 52489 | pBt->max1bytePayload = (u8)pBt->maxLocal; |
| 52379 | 52490 | } |
| 52380 | 52491 | assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) ); |
| 52381 | 52492 | pBt->pPage1 = pPage1; |
| 52382 | 52493 | pBt->nPage = nPage; |
| 52383 | | -assert( pPage1->leaf==0 || pPage1->leaf==1 ); |
| 52384 | 52494 | return SQLITE_OK; |
| 52385 | 52495 | |
| 52386 | 52496 | page1_init_failed: |
| 52387 | 52497 | releasePage(pPage1); |
| 52388 | 52498 | pBt->pPage1 = 0; |
| | @@ -52538,11 +52648,11 @@ |
| 52538 | 52648 | ** is requested, this is a no-op. |
| 52539 | 52649 | */ |
| 52540 | 52650 | if( p->inTrans==TRANS_WRITE || (p->inTrans==TRANS_READ && !wrflag) ){ |
| 52541 | 52651 | goto trans_begun; |
| 52542 | 52652 | } |
| 52543 | | - assert( IfNotOmitAV(pBt->bDoTruncate)==0 ); |
| 52653 | + assert( pBt->inTransaction==TRANS_WRITE || IfNotOmitAV(pBt->bDoTruncate)==0 ); |
| 52544 | 52654 | |
| 52545 | 52655 | /* Write transactions are not possible on a read-only database */ |
| 52546 | 52656 | if( (pBt->btsFlags & BTS_READ_ONLY)!=0 && wrflag ){ |
| 52547 | 52657 | rc = SQLITE_READONLY; |
| 52548 | 52658 | goto trans_begun; |
| | @@ -62977,10 +63087,11 @@ |
| 62977 | 63087 | } |
| 62978 | 63088 | fclose(out); |
| 62979 | 63089 | } |
| 62980 | 63090 | } |
| 62981 | 63091 | #endif |
| 63092 | + p->iCurrentTime = 0; |
| 62982 | 63093 | p->magic = VDBE_MAGIC_INIT; |
| 62983 | 63094 | return p->rc & db->errMask; |
| 62984 | 63095 | } |
| 62985 | 63096 | |
| 62986 | 63097 | /* |
| | @@ -76082,11 +76193,11 @@ |
| 76082 | 76193 | return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr); |
| 76083 | 76194 | } |
| 76084 | 76195 | #ifndef SQLITE_OMIT_CAST |
| 76085 | 76196 | if( op==TK_CAST ){ |
| 76086 | 76197 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 76087 | | - return sqlite3AffinityType(pExpr->u.zToken); |
| 76198 | + return sqlite3AffinityType(pExpr->u.zToken, 0); |
| 76088 | 76199 | } |
| 76089 | 76200 | #endif |
| 76090 | 76201 | if( (op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_REGISTER) |
| 76091 | 76202 | && pExpr->pTab!=0 |
| 76092 | 76203 | ){ |
| | @@ -78502,11 +78613,11 @@ |
| 78502 | 78613 | case TK_CAST: { |
| 78503 | 78614 | /* Expressions of the form: CAST(pLeft AS token) */ |
| 78504 | 78615 | int aff, to_op; |
| 78505 | 78616 | inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target); |
| 78506 | 78617 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 78507 | | - aff = sqlite3AffinityType(pExpr->u.zToken); |
| 78618 | + aff = sqlite3AffinityType(pExpr->u.zToken, 0); |
| 78508 | 78619 | to_op = aff - SQLITE_AFF_TEXT + OP_ToText; |
| 78509 | 78620 | assert( to_op==OP_ToText || aff!=SQLITE_AFF_TEXT ); |
| 78510 | 78621 | assert( to_op==OP_ToBlob || aff!=SQLITE_AFF_NONE ); |
| 78511 | 78622 | assert( to_op==OP_ToNumeric || aff!=SQLITE_AFF_NUMERIC ); |
| 78512 | 78623 | assert( to_op==OP_ToInt || aff!=SQLITE_AFF_INTEGER ); |
| | @@ -79169,11 +79280,11 @@ |
| 79169 | 79280 | } |
| 79170 | 79281 | #ifndef SQLITE_OMIT_CAST |
| 79171 | 79282 | case TK_CAST: { |
| 79172 | 79283 | /* Expressions of the form: CAST(pLeft AS token) */ |
| 79173 | 79284 | const char *zAff = "unk"; |
| 79174 | | - switch( sqlite3AffinityType(pExpr->u.zToken) ){ |
| 79285 | + switch( sqlite3AffinityType(pExpr->u.zToken, 0) ){ |
| 79175 | 79286 | case SQLITE_AFF_TEXT: zAff = "TEXT"; break; |
| 79176 | 79287 | case SQLITE_AFF_NONE: zAff = "NONE"; break; |
| 79177 | 79288 | case SQLITE_AFF_NUMERIC: zAff = "NUMERIC"; break; |
| 79178 | 79289 | case SQLITE_AFF_INTEGER: zAff = "INTEGER"; break; |
| 79179 | 79290 | case SQLITE_AFF_REAL: zAff = "REAL"; break; |
| | @@ -81884,16 +81995,16 @@ |
| 81884 | 81995 | if( zRet==0 ){ |
| 81885 | 81996 | sqlite3_result_error_nomem(context); |
| 81886 | 81997 | return; |
| 81887 | 81998 | } |
| 81888 | 81999 | |
| 81889 | | - sqlite3_snprintf(24, zRet, "%lld", p->nRow); |
| 82000 | + sqlite3_snprintf(24, zRet, "%llu", (u64)p->nRow); |
| 81890 | 82001 | z = zRet + sqlite3Strlen30(zRet); |
| 81891 | 82002 | for(i=0; i<(p->nCol-1); i++){ |
| 81892 | | - i64 nDistinct = p->current.anDLt[i] + 1; |
| 81893 | | - i64 iVal = (p->nRow + nDistinct - 1) / nDistinct; |
| 81894 | | - sqlite3_snprintf(24, z, " %lld", iVal); |
| 82003 | + u64 nDistinct = p->current.anDLt[i] + 1; |
| 82004 | + u64 iVal = (p->nRow + nDistinct - 1) / nDistinct; |
| 82005 | + sqlite3_snprintf(24, z, " %llu", iVal); |
| 81895 | 82006 | z += sqlite3Strlen30(z); |
| 81896 | 82007 | assert( p->current.anEq[i] ); |
| 81897 | 82008 | } |
| 81898 | 82009 | assert( z[0]=='\0' && z>zRet ); |
| 81899 | 82010 | |
| | @@ -81930,11 +82041,11 @@ |
| 81930 | 82041 | sqlite3_result_error_nomem(context); |
| 81931 | 82042 | }else{ |
| 81932 | 82043 | int i; |
| 81933 | 82044 | char *z = zRet; |
| 81934 | 82045 | for(i=0; i<p->nCol; i++){ |
| 81935 | | - sqlite3_snprintf(24, z, "%lld ", aCnt[i]); |
| 82046 | + sqlite3_snprintf(24, z, "%llu ", (u64)aCnt[i]); |
| 81936 | 82047 | z += sqlite3Strlen30(z); |
| 81937 | 82048 | } |
| 81938 | 82049 | assert( z[0]=='\0' && z>zRet ); |
| 81939 | 82050 | z[-1] = '\0'; |
| 81940 | 82051 | sqlite3_result_text(context, zRet, -1, sqlite3_free); |
| | @@ -82391,22 +82502,20 @@ |
| 82391 | 82502 | ** The first argument points to a nul-terminated string containing a |
| 82392 | 82503 | ** list of space separated integers. Read the first nOut of these into |
| 82393 | 82504 | ** the array aOut[]. |
| 82394 | 82505 | */ |
| 82395 | 82506 | static void decodeIntArray( |
| 82396 | | - char *zIntArray, |
| 82397 | | - int nOut, |
| 82398 | | - tRowcnt *aOut, |
| 82399 | | - int *pbUnordered |
| 82507 | + char *zIntArray, /* String containing int array to decode */ |
| 82508 | + int nOut, /* Number of slots in aOut[] */ |
| 82509 | + tRowcnt *aOut, /* Store integers here */ |
| 82510 | + Index *pIndex /* Handle extra flags for this index, if not NULL */ |
| 82400 | 82511 | ){ |
| 82401 | 82512 | char *z = zIntArray; |
| 82402 | 82513 | int c; |
| 82403 | 82514 | int i; |
| 82404 | 82515 | tRowcnt v; |
| 82405 | 82516 | |
| 82406 | | - assert( pbUnordered==0 || *pbUnordered==0 ); |
| 82407 | | - |
| 82408 | 82517 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 82409 | 82518 | if( z==0 ) z = ""; |
| 82410 | 82519 | #else |
| 82411 | 82520 | if( NEVER(z==0) ) z = ""; |
| 82412 | 82521 | #endif |
| | @@ -82417,12 +82526,23 @@ |
| 82417 | 82526 | z++; |
| 82418 | 82527 | } |
| 82419 | 82528 | aOut[i] = v; |
| 82420 | 82529 | if( *z==' ' ) z++; |
| 82421 | 82530 | } |
| 82422 | | - if( pbUnordered && strcmp(z, "unordered")==0 ){ |
| 82423 | | - *pbUnordered = 1; |
| 82531 | +#ifndef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 82532 | + assert( pIndex!=0 ); |
| 82533 | +#else |
| 82534 | + if( pIndex ) |
| 82535 | +#endif |
| 82536 | + { |
| 82537 | + if( strcmp(z, "unordered")==0 ){ |
| 82538 | + pIndex->bUnordered = 1; |
| 82539 | + }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){ |
| 82540 | + int v32 = 0; |
| 82541 | + sqlite3GetInt32(z+3, &v32); |
| 82542 | + pIndex->szIdxRow = sqlite3LogEst(v32); |
| 82543 | + } |
| 82424 | 82544 | } |
| 82425 | 82545 | } |
| 82426 | 82546 | |
| 82427 | 82547 | /* |
| 82428 | 82548 | ** This callback is invoked once for each index when reading the |
| | @@ -82457,16 +82577,17 @@ |
| 82457 | 82577 | pIndex = 0; |
| 82458 | 82578 | } |
| 82459 | 82579 | z = argv[2]; |
| 82460 | 82580 | |
| 82461 | 82581 | if( pIndex ){ |
| 82462 | | - int bUnordered = 0; |
| 82463 | | - decodeIntArray((char*)z, pIndex->nColumn+1, pIndex->aiRowEst,&bUnordered); |
| 82582 | + decodeIntArray((char*)z, pIndex->nColumn+1, pIndex->aiRowEst, pIndex); |
| 82464 | 82583 | if( pIndex->pPartIdxWhere==0 ) pTable->nRowEst = pIndex->aiRowEst[0]; |
| 82465 | | - pIndex->bUnordered = bUnordered; |
| 82466 | 82584 | }else{ |
| 82467 | | - decodeIntArray((char*)z, 1, &pTable->nRowEst, 0); |
| 82585 | + Index fakeIdx; |
| 82586 | + fakeIdx.szIdxRow = pTable->szTabRow; |
| 82587 | + decodeIntArray((char*)z, 1, &pTable->nRowEst, &fakeIdx); |
| 82588 | + pTable->szTabRow = fakeIdx.szIdxRow; |
| 82468 | 82589 | } |
| 82469 | 82590 | |
| 82470 | 82591 | return 0; |
| 82471 | 82592 | } |
| 82472 | 82593 | |
| | @@ -83185,32 +83306,28 @@ |
| 83185 | 83306 | #endif /* SQLITE_OMIT_ATTACH */ |
| 83186 | 83307 | |
| 83187 | 83308 | /* |
| 83188 | 83309 | ** Initialize a DbFixer structure. This routine must be called prior |
| 83189 | 83310 | ** to passing the structure to one of the sqliteFixAAAA() routines below. |
| 83190 | | -** |
| 83191 | | -** The return value indicates whether or not fixation is required. TRUE |
| 83192 | | -** means we do need to fix the database references, FALSE means we do not. |
| 83193 | 83311 | */ |
| 83194 | | -SQLITE_PRIVATE int sqlite3FixInit( |
| 83312 | +SQLITE_PRIVATE void sqlite3FixInit( |
| 83195 | 83313 | DbFixer *pFix, /* The fixer to be initialized */ |
| 83196 | 83314 | Parse *pParse, /* Error messages will be written here */ |
| 83197 | 83315 | int iDb, /* This is the database that must be used */ |
| 83198 | 83316 | const char *zType, /* "view", "trigger", or "index" */ |
| 83199 | 83317 | const Token *pName /* Name of the view, trigger, or index */ |
| 83200 | 83318 | ){ |
| 83201 | 83319 | sqlite3 *db; |
| 83202 | 83320 | |
| 83203 | | - if( NEVER(iDb<0) || iDb==1 ) return 0; |
| 83204 | 83321 | db = pParse->db; |
| 83205 | 83322 | assert( db->nDb>iDb ); |
| 83206 | 83323 | pFix->pParse = pParse; |
| 83207 | 83324 | pFix->zDb = db->aDb[iDb].zName; |
| 83208 | 83325 | pFix->pSchema = db->aDb[iDb].pSchema; |
| 83209 | 83326 | pFix->zType = zType; |
| 83210 | 83327 | pFix->pName = pName; |
| 83211 | | - return 1; |
| 83328 | + pFix->bVarOnly = (iDb==1); |
| 83212 | 83329 | } |
| 83213 | 83330 | |
| 83214 | 83331 | /* |
| 83215 | 83332 | ** The following set of routines walk through the parse tree and assign |
| 83216 | 83333 | ** a specific database to all table references where the database name |
| | @@ -83234,19 +83351,21 @@ |
| 83234 | 83351 | struct SrcList_item *pItem; |
| 83235 | 83352 | |
| 83236 | 83353 | if( NEVER(pList==0) ) return 0; |
| 83237 | 83354 | zDb = pFix->zDb; |
| 83238 | 83355 | for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){ |
| 83239 | | - if( pItem->zDatabase && sqlite3StrICmp(pItem->zDatabase, zDb) ){ |
| 83240 | | - sqlite3ErrorMsg(pFix->pParse, |
| 83241 | | - "%s %T cannot reference objects in database %s", |
| 83242 | | - pFix->zType, pFix->pName, pItem->zDatabase); |
| 83243 | | - return 1; |
| 83244 | | - } |
| 83245 | | - sqlite3DbFree(pFix->pParse->db, pItem->zDatabase); |
| 83246 | | - pItem->zDatabase = 0; |
| 83247 | | - pItem->pSchema = pFix->pSchema; |
| 83356 | + if( pFix->bVarOnly==0 ){ |
| 83357 | + if( pItem->zDatabase && sqlite3StrICmp(pItem->zDatabase, zDb) ){ |
| 83358 | + sqlite3ErrorMsg(pFix->pParse, |
| 83359 | + "%s %T cannot reference objects in database %s", |
| 83360 | + pFix->zType, pFix->pName, pItem->zDatabase); |
| 83361 | + return 1; |
| 83362 | + } |
| 83363 | + sqlite3DbFree(pFix->pParse->db, pItem->zDatabase); |
| 83364 | + pItem->zDatabase = 0; |
| 83365 | + pItem->pSchema = pFix->pSchema; |
| 83366 | + } |
| 83248 | 83367 | #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER) |
| 83249 | 83368 | if( sqlite3FixSelect(pFix, pItem->pSelect) ) return 1; |
| 83250 | 83369 | if( sqlite3FixExpr(pFix, pItem->pOn) ) return 1; |
| 83251 | 83370 | #endif |
| 83252 | 83371 | } |
| | @@ -83264,13 +83383,25 @@ |
| 83264 | 83383 | if( sqlite3FixSrcList(pFix, pSelect->pSrc) ){ |
| 83265 | 83384 | return 1; |
| 83266 | 83385 | } |
| 83267 | 83386 | if( sqlite3FixExpr(pFix, pSelect->pWhere) ){ |
| 83268 | 83387 | return 1; |
| 83388 | + } |
| 83389 | + if( sqlite3FixExprList(pFix, pSelect->pGroupBy) ){ |
| 83390 | + return 1; |
| 83269 | 83391 | } |
| 83270 | 83392 | if( sqlite3FixExpr(pFix, pSelect->pHaving) ){ |
| 83271 | 83393 | return 1; |
| 83394 | + } |
| 83395 | + if( sqlite3FixExprList(pFix, pSelect->pOrderBy) ){ |
| 83396 | + return 1; |
| 83397 | + } |
| 83398 | + if( sqlite3FixExpr(pFix, pSelect->pLimit) ){ |
| 83399 | + return 1; |
| 83400 | + } |
| 83401 | + if( sqlite3FixExpr(pFix, pSelect->pOffset) ){ |
| 83402 | + return 1; |
| 83272 | 83403 | } |
| 83273 | 83404 | pSelect = pSelect->pPrior; |
| 83274 | 83405 | } |
| 83275 | 83406 | return 0; |
| 83276 | 83407 | } |
| | @@ -83277,10 +83408,18 @@ |
| 83277 | 83408 | SQLITE_PRIVATE int sqlite3FixExpr( |
| 83278 | 83409 | DbFixer *pFix, /* Context of the fixation */ |
| 83279 | 83410 | Expr *pExpr /* The expression to be fixed to one database */ |
| 83280 | 83411 | ){ |
| 83281 | 83412 | while( pExpr ){ |
| 83413 | + if( pExpr->op==TK_VARIABLE ){ |
| 83414 | + if( pFix->pParse->db->init.busy ){ |
| 83415 | + pExpr->op = TK_NULL; |
| 83416 | + }else{ |
| 83417 | + sqlite3ErrorMsg(pFix->pParse, "%s cannot use variables", pFix->zType); |
| 83418 | + return 1; |
| 83419 | + } |
| 83420 | + } |
| 83282 | 83421 | if( ExprHasProperty(pExpr, EP_TokenOnly) ) break; |
| 83283 | 83422 | if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 83284 | 83423 | if( sqlite3FixSelect(pFix, pExpr->x.pSelect) ) return 1; |
| 83285 | 83424 | }else{ |
| 83286 | 83425 | if( sqlite3FixExprList(pFix, pExpr->x.pList) ) return 1; |
| | @@ -84460,11 +84599,11 @@ |
| 84460 | 84599 | } |
| 84461 | 84600 | pTable->zName = zName; |
| 84462 | 84601 | pTable->iPKey = -1; |
| 84463 | 84602 | pTable->pSchema = db->aDb[iDb].pSchema; |
| 84464 | 84603 | pTable->nRef = 1; |
| 84465 | | - pTable->nRowEst = 1000000; |
| 84604 | + pTable->nRowEst = 1048576; |
| 84466 | 84605 | assert( pParse->pNewTable==0 ); |
| 84467 | 84606 | pParse->pNewTable = pTable; |
| 84468 | 84607 | |
| 84469 | 84608 | /* If this is the magic sqlite_sequence table used by autoincrement, |
| 84470 | 84609 | ** then record a pointer to this table in the main database structure |
| | @@ -84607,10 +84746,11 @@ |
| 84607 | 84746 | /* If there is no type specified, columns have the default affinity |
| 84608 | 84747 | ** 'NONE'. If there is a type specified, then sqlite3AddColumnType() will |
| 84609 | 84748 | ** be called next to set pCol->affinity correctly. |
| 84610 | 84749 | */ |
| 84611 | 84750 | pCol->affinity = SQLITE_AFF_NONE; |
| 84751 | + pCol->szEst = 1; |
| 84612 | 84752 | p->nCol++; |
| 84613 | 84753 | } |
| 84614 | 84754 | |
| 84615 | 84755 | /* |
| 84616 | 84756 | ** This routine is called by the parser while in the middle of |
| | @@ -84648,26 +84788,30 @@ |
| 84648 | 84788 | ** 'DOUB' | SQLITE_AFF_REAL |
| 84649 | 84789 | ** |
| 84650 | 84790 | ** If none of the substrings in the above table are found, |
| 84651 | 84791 | ** SQLITE_AFF_NUMERIC is returned. |
| 84652 | 84792 | */ |
| 84653 | | -SQLITE_PRIVATE char sqlite3AffinityType(const char *zIn){ |
| 84793 | +SQLITE_PRIVATE char sqlite3AffinityType(const char *zIn, u8 *pszEst){ |
| 84654 | 84794 | u32 h = 0; |
| 84655 | 84795 | char aff = SQLITE_AFF_NUMERIC; |
| 84796 | + const char *zChar = 0; |
| 84656 | 84797 | |
| 84657 | | - if( zIn ) while( zIn[0] ){ |
| 84798 | + if( zIn==0 ) return aff; |
| 84799 | + while( zIn[0] ){ |
| 84658 | 84800 | h = (h<<8) + sqlite3UpperToLower[(*zIn)&0xff]; |
| 84659 | 84801 | zIn++; |
| 84660 | 84802 | if( h==(('c'<<24)+('h'<<16)+('a'<<8)+'r') ){ /* CHAR */ |
| 84661 | | - aff = SQLITE_AFF_TEXT; |
| 84803 | + aff = SQLITE_AFF_TEXT; |
| 84804 | + zChar = zIn; |
| 84662 | 84805 | }else if( h==(('c'<<24)+('l'<<16)+('o'<<8)+'b') ){ /* CLOB */ |
| 84663 | 84806 | aff = SQLITE_AFF_TEXT; |
| 84664 | 84807 | }else if( h==(('t'<<24)+('e'<<16)+('x'<<8)+'t') ){ /* TEXT */ |
| 84665 | 84808 | aff = SQLITE_AFF_TEXT; |
| 84666 | 84809 | }else if( h==(('b'<<24)+('l'<<16)+('o'<<8)+'b') /* BLOB */ |
| 84667 | 84810 | && (aff==SQLITE_AFF_NUMERIC || aff==SQLITE_AFF_REAL) ){ |
| 84668 | 84811 | aff = SQLITE_AFF_NONE; |
| 84812 | + if( zIn[0]=='(' ) zChar = zIn; |
| 84669 | 84813 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 84670 | 84814 | }else if( h==(('r'<<24)+('e'<<16)+('a'<<8)+'l') /* REAL */ |
| 84671 | 84815 | && aff==SQLITE_AFF_NUMERIC ){ |
| 84672 | 84816 | aff = SQLITE_AFF_REAL; |
| 84673 | 84817 | }else if( h==(('f'<<24)+('l'<<16)+('o'<<8)+'a') /* FLOA */ |
| | @@ -84681,10 +84825,32 @@ |
| 84681 | 84825 | aff = SQLITE_AFF_INTEGER; |
| 84682 | 84826 | break; |
| 84683 | 84827 | } |
| 84684 | 84828 | } |
| 84685 | 84829 | |
| 84830 | + /* If pszEst is not NULL, store an estimate of the field size. The |
| 84831 | + ** estimate is scaled so that the size of an integer is 1. */ |
| 84832 | + if( pszEst ){ |
| 84833 | + *pszEst = 1; /* default size is approx 4 bytes */ |
| 84834 | + if( aff<=SQLITE_AFF_NONE ){ |
| 84835 | + if( zChar ){ |
| 84836 | + while( zChar[0] ){ |
| 84837 | + if( sqlite3Isdigit(zChar[0]) ){ |
| 84838 | + int v; |
| 84839 | + sqlite3GetInt32(zChar, &v); |
| 84840 | + v = v/4 + 1; |
| 84841 | + if( v>255 ) v = 255; |
| 84842 | + *pszEst = v; /* BLOB(k), VARCHAR(k), CHAR(k) -> r=(k/4+1) */ |
| 84843 | + break; |
| 84844 | + } |
| 84845 | + zChar++; |
| 84846 | + } |
| 84847 | + }else{ |
| 84848 | + *pszEst = 5; /* BLOB, TEXT, CLOB -> r=5 (approx 20 bytes)*/ |
| 84849 | + } |
| 84850 | + } |
| 84851 | + } |
| 84686 | 84852 | return aff; |
| 84687 | 84853 | } |
| 84688 | 84854 | |
| 84689 | 84855 | /* |
| 84690 | 84856 | ** This routine is called by the parser while in the middle of |
| | @@ -84702,11 +84868,11 @@ |
| 84702 | 84868 | p = pParse->pNewTable; |
| 84703 | 84869 | if( p==0 || NEVER(p->nCol<1) ) return; |
| 84704 | 84870 | pCol = &p->aCol[p->nCol-1]; |
| 84705 | 84871 | assert( pCol->zType==0 ); |
| 84706 | 84872 | pCol->zType = sqlite3NameFromToken(pParse->db, pType); |
| 84707 | | - pCol->affinity = sqlite3AffinityType(pCol->zType); |
| 84873 | + pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst); |
| 84708 | 84874 | } |
| 84709 | 84875 | |
| 84710 | 84876 | /* |
| 84711 | 84877 | ** The expression is the default value for the most recently added column |
| 84712 | 84878 | ** of the table currently under construction. |
| | @@ -85050,18 +85216,46 @@ |
| 85050 | 85216 | testcase( pCol->affinity==SQLITE_AFF_REAL ); |
| 85051 | 85217 | |
| 85052 | 85218 | zType = azType[pCol->affinity - SQLITE_AFF_TEXT]; |
| 85053 | 85219 | len = sqlite3Strlen30(zType); |
| 85054 | 85220 | assert( pCol->affinity==SQLITE_AFF_NONE |
| 85055 | | - || pCol->affinity==sqlite3AffinityType(zType) ); |
| 85221 | + || pCol->affinity==sqlite3AffinityType(zType, 0) ); |
| 85056 | 85222 | memcpy(&zStmt[k], zType, len); |
| 85057 | 85223 | k += len; |
| 85058 | 85224 | assert( k<=n ); |
| 85059 | 85225 | } |
| 85060 | 85226 | sqlite3_snprintf(n-k, &zStmt[k], "%s", zEnd); |
| 85061 | 85227 | return zStmt; |
| 85062 | 85228 | } |
| 85229 | + |
| 85230 | +/* |
| 85231 | +** Estimate the total row width for a table. |
| 85232 | +*/ |
| 85233 | +static void estimateTableWidth(Table *pTab){ |
| 85234 | + unsigned wTable = 0; |
| 85235 | + const Column *pTabCol; |
| 85236 | + int i; |
| 85237 | + for(i=pTab->nCol, pTabCol=pTab->aCol; i>0; i--, pTabCol++){ |
| 85238 | + wTable += pTabCol->szEst; |
| 85239 | + } |
| 85240 | + if( pTab->iPKey<0 ) wTable++; |
| 85241 | + pTab->szTabRow = sqlite3LogEst(wTable*4); |
| 85242 | +} |
| 85243 | + |
| 85244 | +/* |
| 85245 | +** Estimate the average size of a row for an index. |
| 85246 | +*/ |
| 85247 | +static void estimateIndexWidth(Index *pIdx){ |
| 85248 | + unsigned wIndex = 1; |
| 85249 | + int i; |
| 85250 | + const Column *aCol = pIdx->pTable->aCol; |
| 85251 | + for(i=0; i<pIdx->nColumn; i++){ |
| 85252 | + assert( pIdx->aiColumn[i]>=0 && pIdx->aiColumn[i]<pIdx->pTable->nCol ); |
| 85253 | + wIndex += aCol[pIdx->aiColumn[i]].szEst; |
| 85254 | + } |
| 85255 | + pIdx->szIdxRow = sqlite3LogEst(wIndex*4); |
| 85256 | +} |
| 85063 | 85257 | |
| 85064 | 85258 | /* |
| 85065 | 85259 | ** This routine is called to report the final ")" that terminates |
| 85066 | 85260 | ** a CREATE TABLE statement. |
| 85067 | 85261 | ** |
| | @@ -85085,13 +85279,14 @@ |
| 85085 | 85279 | Parse *pParse, /* Parse context */ |
| 85086 | 85280 | Token *pCons, /* The ',' token after the last column defn. */ |
| 85087 | 85281 | Token *pEnd, /* The final ')' token in the CREATE TABLE */ |
| 85088 | 85282 | Select *pSelect /* Select from a "CREATE ... AS SELECT" */ |
| 85089 | 85283 | ){ |
| 85090 | | - Table *p; |
| 85091 | | - sqlite3 *db = pParse->db; |
| 85092 | | - int iDb; |
| 85284 | + Table *p; /* The new table */ |
| 85285 | + sqlite3 *db = pParse->db; /* The database connection */ |
| 85286 | + int iDb; /* Database in which the table lives */ |
| 85287 | + Index *pIdx; /* An implied index of the table */ |
| 85093 | 85288 | |
| 85094 | 85289 | if( (pEnd==0 && pSelect==0) || db->mallocFailed ){ |
| 85095 | 85290 | return; |
| 85096 | 85291 | } |
| 85097 | 85292 | p = pParse->pNewTable; |
| | @@ -85106,10 +85301,16 @@ |
| 85106 | 85301 | */ |
| 85107 | 85302 | if( p->pCheck ){ |
| 85108 | 85303 | sqlite3ResolveSelfReference(pParse, p, NC_IsCheck, 0, p->pCheck); |
| 85109 | 85304 | } |
| 85110 | 85305 | #endif /* !defined(SQLITE_OMIT_CHECK) */ |
| 85306 | + |
| 85307 | + /* Estimate the average row size for the table and for all implied indices */ |
| 85308 | + estimateTableWidth(p); |
| 85309 | + for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 85310 | + estimateIndexWidth(pIdx); |
| 85311 | + } |
| 85111 | 85312 | |
| 85112 | 85313 | /* If the db->init.busy is 1 it means we are reading the SQL off the |
| 85113 | 85314 | ** "sqlite_master" or "sqlite_temp_master" table on the disk. |
| 85114 | 85315 | ** So do not write to the disk again. Extract the root page number |
| 85115 | 85316 | ** for the table from the db->init.newTnum field. (The page number |
| | @@ -85303,13 +85504,12 @@ |
| 85303 | 85504 | sqlite3SelectDelete(db, pSelect); |
| 85304 | 85505 | return; |
| 85305 | 85506 | } |
| 85306 | 85507 | sqlite3TwoPartName(pParse, pName1, pName2, &pName); |
| 85307 | 85508 | iDb = sqlite3SchemaToIndex(db, p->pSchema); |
| 85308 | | - if( sqlite3FixInit(&sFix, pParse, iDb, "view", pName) |
| 85309 | | - && sqlite3FixSelect(&sFix, pSelect) |
| 85310 | | - ){ |
| 85509 | + sqlite3FixInit(&sFix, pParse, iDb, "view", pName); |
| 85510 | + if( sqlite3FixSelect(&sFix, pSelect) ){ |
| 85311 | 85511 | sqlite3SelectDelete(db, pSelect); |
| 85312 | 85512 | return; |
| 85313 | 85513 | } |
| 85314 | 85514 | |
| 85315 | 85515 | /* Make a copy of the entire SELECT statement that defines the view. |
| | @@ -86066,13 +86266,14 @@ |
| 86066 | 86266 | sqlite3 *db = pParse->db; |
| 86067 | 86267 | Db *pDb; /* The specific table containing the indexed database */ |
| 86068 | 86268 | int iDb; /* Index of the database that is being written */ |
| 86069 | 86269 | Token *pName = 0; /* Unqualified name of the index to create */ |
| 86070 | 86270 | struct ExprList_item *pListItem; /* For looping over pList */ |
| 86071 | | - int nCol; |
| 86072 | | - int nExtra = 0; |
| 86073 | | - char *zExtra; |
| 86271 | + const Column *pTabCol; /* A column in the table */ |
| 86272 | + int nCol; /* Number of columns */ |
| 86273 | + int nExtra = 0; /* Space allocated for zExtra[] */ |
| 86274 | + char *zExtra; /* Extra space after the Index object */ |
| 86074 | 86275 | |
| 86075 | 86276 | assert( pParse->nErr==0 ); /* Never called with prior errors */ |
| 86076 | 86277 | if( db->mallocFailed || IN_DECLARE_VTAB ){ |
| 86077 | 86278 | goto exit_create_index; |
| 86078 | 86279 | } |
| | @@ -86105,13 +86306,12 @@ |
| 86105 | 86306 | iDb = 1; |
| 86106 | 86307 | } |
| 86107 | 86308 | } |
| 86108 | 86309 | #endif |
| 86109 | 86310 | |
| 86110 | | - if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) && |
| 86111 | | - sqlite3FixSrcList(&sFix, pTblName) |
| 86112 | | - ){ |
| 86311 | + sqlite3FixInit(&sFix, pParse, iDb, "index", pName); |
| 86312 | + if( sqlite3FixSrcList(&sFix, pTblName) ){ |
| 86113 | 86313 | /* Because the parser constructs pTblName from a single identifier, |
| 86114 | 86314 | ** sqlite3FixSrcList can never fail. */ |
| 86115 | 86315 | assert(0); |
| 86116 | 86316 | } |
| 86117 | 86317 | pTab = sqlite3LocateTableItem(pParse, 0, &pTblName->a[0]); |
| | @@ -86296,11 +86496,10 @@ |
| 86296 | 86496 | ** same column more than once cannot be an error because that would |
| 86297 | 86497 | ** break backwards compatibility - it needs to be a warning. |
| 86298 | 86498 | */ |
| 86299 | 86499 | for(i=0, pListItem=pList->a; i<pList->nExpr; i++, pListItem++){ |
| 86300 | 86500 | const char *zColName = pListItem->zName; |
| 86301 | | - Column *pTabCol; |
| 86302 | 86501 | int requestedSortOrder; |
| 86303 | 86502 | char *zColl; /* Collation sequence name */ |
| 86304 | 86503 | |
| 86305 | 86504 | for(j=0, pTabCol=pTab->aCol; j<pTab->nCol; j++, pTabCol++){ |
| 86306 | 86505 | if( sqlite3StrICmp(zColName, pTabCol->zName)==0 ) break; |
| | @@ -86333,10 +86532,11 @@ |
| 86333 | 86532 | requestedSortOrder = pListItem->sortOrder & sortOrderMask; |
| 86334 | 86533 | pIndex->aSortOrder[i] = (u8)requestedSortOrder; |
| 86335 | 86534 | if( pTab->aCol[j].notNull==0 ) pIndex->uniqNotNull = 0; |
| 86336 | 86535 | } |
| 86337 | 86536 | sqlite3DefaultRowEst(pIndex); |
| 86537 | + if( pParse->pNewTable==0 ) estimateIndexWidth(pIndex); |
| 86338 | 86538 | |
| 86339 | 86539 | if( pTab==pParse->pNewTable ){ |
| 86340 | 86540 | /* This routine has been called to create an automatic index as a |
| 86341 | 86541 | ** result of a PRIMARY KEY or UNIQUE clause on a column definition, or |
| 86342 | 86542 | ** a PRIMARY KEY or UNIQUE clause following the column definitions. |
| | @@ -88238,10 +88438,11 @@ |
| 88238 | 88438 | ** API function sqlite3_count_changes) to be set incorrectly. */ |
| 88239 | 88439 | if( rcauth==SQLITE_OK && pWhere==0 && !pTrigger && !IsVirtual(pTab) |
| 88240 | 88440 | && 0==sqlite3FkRequired(pParse, pTab, 0, 0) |
| 88241 | 88441 | ){ |
| 88242 | 88442 | assert( !isView ); |
| 88443 | + sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName); |
| 88243 | 88444 | sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt, |
| 88244 | 88445 | pTab->zName, P4_STATIC); |
| 88245 | 88446 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 88246 | 88447 | assert( pIdx->pSchema==pTab->pSchema ); |
| 88247 | 88448 | sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb); |
| | @@ -93487,10 +93688,11 @@ |
| 93487 | 93688 | (char*)pKey, P4_KEYINFO_HANDOFF); |
| 93488 | 93689 | VdbeComment((v, "%s", pSrcIdx->zName)); |
| 93489 | 93690 | pKey = sqlite3IndexKeyinfo(pParse, pDestIdx); |
| 93490 | 93691 | sqlite3VdbeAddOp4(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest, |
| 93491 | 93692 | (char*)pKey, P4_KEYINFO_HANDOFF); |
| 93693 | + sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR); |
| 93492 | 93694 | VdbeComment((v, "%s", pDestIdx->zName)); |
| 93493 | 93695 | addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); |
| 93494 | 93696 | sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData); |
| 93495 | 93697 | sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1); |
| 93496 | 93698 | sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); |
| | @@ -94974,181 +95176,363 @@ |
| 94974 | 95176 | #define PragTyp_HEXKEY 35 |
| 94975 | 95177 | #define PragTyp_KEY 36 |
| 94976 | 95178 | #define PragTyp_REKEY 37 |
| 94977 | 95179 | #define PragTyp_LOCK_STATUS 38 |
| 94978 | 95180 | #define PragTyp_PARSER_TRACE 39 |
| 95181 | +#define PragFlag_NeedSchema 0x01 |
| 94979 | 95182 | static const struct sPragmaNames { |
| 94980 | 95183 | const char *const zName; /* Name of pragma */ |
| 94981 | 95184 | u8 ePragTyp; /* PragTyp_XXX value */ |
| 95185 | + u8 mPragFlag; /* Zero or more PragFlag_XXX values */ |
| 94982 | 95186 | u32 iArg; /* Extra argument */ |
| 94983 | 95187 | } aPragmaNames[] = { |
| 94984 | 95188 | #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD) |
| 94985 | | - { "activate_extensions", PragTyp_ACTIVATE_EXTENSIONS, 0 }, |
| 95189 | + { /* zName: */ "activate_extensions", |
| 95190 | + /* ePragTyp: */ PragTyp_ACTIVATE_EXTENSIONS, |
| 95191 | + /* ePragFlag: */ 0, |
| 95192 | + /* iArg: */ 0 }, |
| 94986 | 95193 | #endif |
| 94987 | 95194 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 94988 | | - { "application_id", PragTyp_HEADER_VALUE, 0 }, |
| 95195 | + { /* zName: */ "application_id", |
| 95196 | + /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 95197 | + /* ePragFlag: */ 0, |
| 95198 | + /* iArg: */ 0 }, |
| 94989 | 95199 | #endif |
| 94990 | 95200 | #if !defined(SQLITE_OMIT_AUTOVACUUM) |
| 94991 | | - { "auto_vacuum", PragTyp_AUTO_VACUUM, 0 }, |
| 95201 | + { /* zName: */ "auto_vacuum", |
| 95202 | + /* ePragTyp: */ PragTyp_AUTO_VACUUM, |
| 95203 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95204 | + /* iArg: */ 0 }, |
| 94992 | 95205 | #endif |
| 94993 | 95206 | #if !defined(SQLITE_OMIT_AUTOMATIC_INDEX) |
| 94994 | | - { "automatic_index", PragTyp_FLAG, |
| 94995 | | - SQLITE_AutoIndex }, |
| 95207 | + { /* zName: */ "automatic_index", |
| 95208 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95209 | + /* ePragFlag: */ 0, |
| 95210 | + /* iArg: */ SQLITE_AutoIndex }, |
| 94996 | 95211 | #endif |
| 94997 | | - { "busy_timeout", PragTyp_BUSY_TIMEOUT, 0 }, |
| 95212 | + { /* zName: */ "busy_timeout", |
| 95213 | + /* ePragTyp: */ PragTyp_BUSY_TIMEOUT, |
| 95214 | + /* ePragFlag: */ 0, |
| 95215 | + /* iArg: */ 0 }, |
| 94998 | 95216 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 94999 | | - { "cache_size", PragTyp_CACHE_SIZE, 0 }, |
| 95217 | + { /* zName: */ "cache_size", |
| 95218 | + /* ePragTyp: */ PragTyp_CACHE_SIZE, |
| 95219 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95220 | + /* iArg: */ 0 }, |
| 95000 | 95221 | #endif |
| 95001 | | - { "cache_spill", PragTyp_FLAG, |
| 95002 | | - SQLITE_CacheSpill }, |
| 95003 | | - { "case_sensitive_like", PragTyp_CASE_SENSITIVE_LIKE, 0 }, |
| 95004 | | - { "checkpoint_fullfsync", PragTyp_FLAG, |
| 95005 | | - SQLITE_CkptFullFSync }, |
| 95222 | + { /* zName: */ "cache_spill", |
| 95223 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95224 | + /* ePragFlag: */ 0, |
| 95225 | + /* iArg: */ SQLITE_CacheSpill }, |
| 95226 | + { /* zName: */ "case_sensitive_like", |
| 95227 | + /* ePragTyp: */ PragTyp_CASE_SENSITIVE_LIKE, |
| 95228 | + /* ePragFlag: */ 0, |
| 95229 | + /* iArg: */ 0 }, |
| 95230 | + { /* zName: */ "checkpoint_fullfsync", |
| 95231 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95232 | + /* ePragFlag: */ 0, |
| 95233 | + /* iArg: */ SQLITE_CkptFullFSync }, |
| 95006 | 95234 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 95007 | | - { "collation_list", PragTyp_COLLATION_LIST, 0 }, |
| 95235 | + { /* zName: */ "collation_list", |
| 95236 | + /* ePragTyp: */ PragTyp_COLLATION_LIST, |
| 95237 | + /* ePragFlag: */ 0, |
| 95238 | + /* iArg: */ 0 }, |
| 95008 | 95239 | #endif |
| 95009 | 95240 | #if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS) |
| 95010 | | - { "compile_options", PragTyp_COMPILE_OPTIONS, 0 }, |
| 95241 | + { /* zName: */ "compile_options", |
| 95242 | + /* ePragTyp: */ PragTyp_COMPILE_OPTIONS, |
| 95243 | + /* ePragFlag: */ 0, |
| 95244 | + /* iArg: */ 0 }, |
| 95011 | 95245 | #endif |
| 95012 | | - { "count_changes", PragTyp_FLAG, |
| 95013 | | - SQLITE_CountRows }, |
| 95246 | + { /* zName: */ "count_changes", |
| 95247 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95248 | + /* ePragFlag: */ 0, |
| 95249 | + /* iArg: */ SQLITE_CountRows }, |
| 95014 | 95250 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN |
| 95015 | | - { "data_store_directory", PragTyp_DATA_STORE_DIRECTORY, 0 }, |
| 95251 | + { /* zName: */ "data_store_directory", |
| 95252 | + /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY, |
| 95253 | + /* ePragFlag: */ 0, |
| 95254 | + /* iArg: */ 0 }, |
| 95016 | 95255 | #endif |
| 95017 | 95256 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 95018 | | - { "database_list", PragTyp_DATABASE_LIST, 0 }, |
| 95257 | + { /* zName: */ "database_list", |
| 95258 | + /* ePragTyp: */ PragTyp_DATABASE_LIST, |
| 95259 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95260 | + /* iArg: */ 0 }, |
| 95019 | 95261 | #endif |
| 95020 | 95262 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) |
| 95021 | | - { "default_cache_size", PragTyp_DEFAULT_CACHE_SIZE, 0 }, |
| 95263 | + { /* zName: */ "default_cache_size", |
| 95264 | + /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE, |
| 95265 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95266 | + /* iArg: */ 0 }, |
| 95022 | 95267 | #endif |
| 95023 | 95268 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
| 95024 | | - { "defer_foreign_keys", PragTyp_FLAG, |
| 95025 | | - SQLITE_DeferFKs }, |
| 95269 | + { /* zName: */ "defer_foreign_keys", |
| 95270 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95271 | + /* ePragFlag: */ 0, |
| 95272 | + /* iArg: */ SQLITE_DeferFKs }, |
| 95026 | 95273 | #endif |
| 95027 | | - { "empty_result_callbacks", PragTyp_FLAG, |
| 95028 | | - SQLITE_NullCallback }, |
| 95274 | + { /* zName: */ "empty_result_callbacks", |
| 95275 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95276 | + /* ePragFlag: */ 0, |
| 95277 | + /* iArg: */ SQLITE_NullCallback }, |
| 95029 | 95278 | #if !defined(SQLITE_OMIT_UTF16) |
| 95030 | | - { "encoding", PragTyp_ENCODING, 0 }, |
| 95279 | + { /* zName: */ "encoding", |
| 95280 | + /* ePragTyp: */ PragTyp_ENCODING, |
| 95281 | + /* ePragFlag: */ 0, |
| 95282 | + /* iArg: */ 0 }, |
| 95031 | 95283 | #endif |
| 95032 | 95284 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
| 95033 | | - { "foreign_key_check", PragTyp_FOREIGN_KEY_CHECK, 0 }, |
| 95285 | + { /* zName: */ "foreign_key_check", |
| 95286 | + /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK, |
| 95287 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95288 | + /* iArg: */ 0 }, |
| 95034 | 95289 | #endif |
| 95035 | 95290 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) |
| 95036 | | - { "foreign_key_list", PragTyp_FOREIGN_KEY_LIST, 0 }, |
| 95291 | + { /* zName: */ "foreign_key_list", |
| 95292 | + /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST, |
| 95293 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95294 | + /* iArg: */ 0 }, |
| 95037 | 95295 | #endif |
| 95038 | 95296 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
| 95039 | | - { "foreign_keys", PragTyp_FLAG, |
| 95040 | | - SQLITE_ForeignKeys }, |
| 95297 | + { /* zName: */ "foreign_keys", |
| 95298 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95299 | + /* ePragFlag: */ 0, |
| 95300 | + /* iArg: */ SQLITE_ForeignKeys }, |
| 95041 | 95301 | #endif |
| 95042 | 95302 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 95043 | | - { "freelist_count", PragTyp_HEADER_VALUE, 0 }, |
| 95303 | + { /* zName: */ "freelist_count", |
| 95304 | + /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 95305 | + /* ePragFlag: */ 0, |
| 95306 | + /* iArg: */ 0 }, |
| 95044 | 95307 | #endif |
| 95045 | | - { "full_column_names", PragTyp_FLAG, |
| 95046 | | - SQLITE_FullColNames }, |
| 95047 | | - { "fullfsync", PragTyp_FLAG, |
| 95048 | | - SQLITE_FullFSync }, |
| 95308 | + { /* zName: */ "full_column_names", |
| 95309 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95310 | + /* ePragFlag: */ 0, |
| 95311 | + /* iArg: */ SQLITE_FullColNames }, |
| 95312 | + { /* zName: */ "fullfsync", |
| 95313 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95314 | + /* ePragFlag: */ 0, |
| 95315 | + /* iArg: */ SQLITE_FullFSync }, |
| 95049 | 95316 | #if defined(SQLITE_HAS_CODEC) |
| 95050 | | - { "hexkey", PragTyp_HEXKEY, 0 }, |
| 95317 | + { /* zName: */ "hexkey", |
| 95318 | + /* ePragTyp: */ PragTyp_HEXKEY, |
| 95319 | + /* ePragFlag: */ 0, |
| 95320 | + /* iArg: */ 0 }, |
| 95321 | + { /* zName: */ "hexrekey", |
| 95322 | + /* ePragTyp: */ PragTyp_HEXKEY, |
| 95323 | + /* ePragFlag: */ 0, |
| 95324 | + /* iArg: */ 0 }, |
| 95051 | 95325 | #endif |
| 95052 | 95326 | #if !defined(SQLITE_OMIT_CHECK) |
| 95053 | | - { "ignore_check_constraints", PragTyp_FLAG, |
| 95054 | | - SQLITE_IgnoreChecks }, |
| 95327 | + { /* zName: */ "ignore_check_constraints", |
| 95328 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95329 | + /* ePragFlag: */ 0, |
| 95330 | + /* iArg: */ SQLITE_IgnoreChecks }, |
| 95055 | 95331 | #endif |
| 95056 | 95332 | #if !defined(SQLITE_OMIT_AUTOVACUUM) |
| 95057 | | - { "incremental_vacuum", PragTyp_INCREMENTAL_VACUUM, 0 }, |
| 95333 | + { /* zName: */ "incremental_vacuum", |
| 95334 | + /* ePragTyp: */ PragTyp_INCREMENTAL_VACUUM, |
| 95335 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95336 | + /* iArg: */ 0 }, |
| 95058 | 95337 | #endif |
| 95059 | 95338 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 95060 | | - { "index_info", PragTyp_INDEX_INFO, 0 }, |
| 95061 | | - { "index_list", PragTyp_INDEX_LIST, 0 }, |
| 95339 | + { /* zName: */ "index_info", |
| 95340 | + /* ePragTyp: */ PragTyp_INDEX_INFO, |
| 95341 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95342 | + /* iArg: */ 0 }, |
| 95343 | + { /* zName: */ "index_list", |
| 95344 | + /* ePragTyp: */ PragTyp_INDEX_LIST, |
| 95345 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95346 | + /* iArg: */ 0 }, |
| 95062 | 95347 | #endif |
| 95063 | 95348 | #if !defined(SQLITE_OMIT_INTEGRITY_CHECK) |
| 95064 | | - { "integrity_check", PragTyp_INTEGRITY_CHECK, 0 }, |
| 95349 | + { /* zName: */ "integrity_check", |
| 95350 | + /* ePragTyp: */ PragTyp_INTEGRITY_CHECK, |
| 95351 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95352 | + /* iArg: */ 0 }, |
| 95065 | 95353 | #endif |
| 95066 | 95354 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 95067 | | - { "journal_mode", PragTyp_JOURNAL_MODE, 0 }, |
| 95068 | | - { "journal_size_limit", PragTyp_JOURNAL_SIZE_LIMIT, 0 }, |
| 95355 | + { /* zName: */ "journal_mode", |
| 95356 | + /* ePragTyp: */ PragTyp_JOURNAL_MODE, |
| 95357 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95358 | + /* iArg: */ 0 }, |
| 95359 | + { /* zName: */ "journal_size_limit", |
| 95360 | + /* ePragTyp: */ PragTyp_JOURNAL_SIZE_LIMIT, |
| 95361 | + /* ePragFlag: */ 0, |
| 95362 | + /* iArg: */ 0 }, |
| 95069 | 95363 | #endif |
| 95070 | 95364 | #if defined(SQLITE_HAS_CODEC) |
| 95071 | | - { "key", PragTyp_KEY, 0 }, |
| 95365 | + { /* zName: */ "key", |
| 95366 | + /* ePragTyp: */ PragTyp_KEY, |
| 95367 | + /* ePragFlag: */ 0, |
| 95368 | + /* iArg: */ 0 }, |
| 95072 | 95369 | #endif |
| 95073 | | - { "legacy_file_format", PragTyp_FLAG, |
| 95074 | | - SQLITE_LegacyFileFmt }, |
| 95370 | + { /* zName: */ "legacy_file_format", |
| 95371 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95372 | + /* ePragFlag: */ 0, |
| 95373 | + /* iArg: */ SQLITE_LegacyFileFmt }, |
| 95075 | 95374 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE |
| 95076 | | - { "lock_proxy_file", PragTyp_LOCK_PROXY_FILE, 0 }, |
| 95375 | + { /* zName: */ "lock_proxy_file", |
| 95376 | + /* ePragTyp: */ PragTyp_LOCK_PROXY_FILE, |
| 95377 | + /* ePragFlag: */ 0, |
| 95378 | + /* iArg: */ 0 }, |
| 95077 | 95379 | #endif |
| 95078 | 95380 | #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
| 95079 | | - { "lock_status", PragTyp_LOCK_STATUS, 0 }, |
| 95080 | | -#endif |
| 95081 | | -#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 95082 | | - { "locking_mode", PragTyp_LOCKING_MODE, 0 }, |
| 95083 | | - { "max_page_count", PragTyp_PAGE_COUNT, 0 }, |
| 95084 | | - { "mmap_size", PragTyp_MMAP_SIZE, 0 }, |
| 95085 | | - { "page_count", PragTyp_PAGE_COUNT, 0 }, |
| 95086 | | - { "page_size", PragTyp_PAGE_SIZE, 0 }, |
| 95087 | | -#endif |
| 95088 | | -#if defined(SQLITE_DEBUG) |
| 95089 | | - { "parser_trace", PragTyp_PARSER_TRACE, 0 }, |
| 95090 | | -#endif |
| 95091 | | - { "query_only", PragTyp_FLAG, |
| 95092 | | - SQLITE_QueryOnly }, |
| 95093 | | -#if !defined(SQLITE_OMIT_INTEGRITY_CHECK) |
| 95094 | | - { "quick_check", PragTyp_INTEGRITY_CHECK, 0 }, |
| 95095 | | -#endif |
| 95096 | | - { "read_uncommitted", PragTyp_FLAG, |
| 95097 | | - SQLITE_ReadUncommitted }, |
| 95098 | | - { "recursive_triggers", PragTyp_FLAG, |
| 95099 | | - SQLITE_RecTriggers }, |
| 95100 | | -#if defined(SQLITE_HAS_CODEC) |
| 95101 | | - { "rekey", PragTyp_REKEY, 0 }, |
| 95102 | | -#endif |
| 95103 | | - { "reverse_unordered_selects", PragTyp_FLAG, |
| 95104 | | - SQLITE_ReverseOrder }, |
| 95105 | | -#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 95106 | | - { "schema_version", PragTyp_HEADER_VALUE, 0 }, |
| 95107 | | -#endif |
| 95108 | | -#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 95109 | | - { "secure_delete", PragTyp_SECURE_DELETE, 0 }, |
| 95110 | | -#endif |
| 95111 | | - { "short_column_names", PragTyp_FLAG, |
| 95112 | | - SQLITE_ShortColNames }, |
| 95113 | | - { "shrink_memory", PragTyp_SHRINK_MEMORY, 0 }, |
| 95114 | | - { "soft_heap_limit", PragTyp_SOFT_HEAP_LIMIT, 0 }, |
| 95115 | | -#if defined(SQLITE_DEBUG) |
| 95116 | | - { "sql_trace", PragTyp_FLAG, |
| 95117 | | - SQLITE_SqlTrace }, |
| 95118 | | -#endif |
| 95119 | | -#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 95120 | | - { "synchronous", PragTyp_SYNCHRONOUS, 0 }, |
| 95381 | + { /* zName: */ "lock_status", |
| 95382 | + /* ePragTyp: */ PragTyp_LOCK_STATUS, |
| 95383 | + /* ePragFlag: */ 0, |
| 95384 | + /* iArg: */ 0 }, |
| 95385 | +#endif |
| 95386 | +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 95387 | + { /* zName: */ "locking_mode", |
| 95388 | + /* ePragTyp: */ PragTyp_LOCKING_MODE, |
| 95389 | + /* ePragFlag: */ 0, |
| 95390 | + /* iArg: */ 0 }, |
| 95391 | + { /* zName: */ "max_page_count", |
| 95392 | + /* ePragTyp: */ PragTyp_PAGE_COUNT, |
| 95393 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95394 | + /* iArg: */ 0 }, |
| 95395 | + { /* zName: */ "mmap_size", |
| 95396 | + /* ePragTyp: */ PragTyp_MMAP_SIZE, |
| 95397 | + /* ePragFlag: */ 0, |
| 95398 | + /* iArg: */ 0 }, |
| 95399 | + { /* zName: */ "page_count", |
| 95400 | + /* ePragTyp: */ PragTyp_PAGE_COUNT, |
| 95401 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95402 | + /* iArg: */ 0 }, |
| 95403 | + { /* zName: */ "page_size", |
| 95404 | + /* ePragTyp: */ PragTyp_PAGE_SIZE, |
| 95405 | + /* ePragFlag: */ 0, |
| 95406 | + /* iArg: */ 0 }, |
| 95407 | +#endif |
| 95408 | +#if defined(SQLITE_DEBUG) |
| 95409 | + { /* zName: */ "parser_trace", |
| 95410 | + /* ePragTyp: */ PragTyp_PARSER_TRACE, |
| 95411 | + /* ePragFlag: */ 0, |
| 95412 | + /* iArg: */ 0 }, |
| 95413 | +#endif |
| 95414 | + { /* zName: */ "query_only", |
| 95415 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95416 | + /* ePragFlag: */ 0, |
| 95417 | + /* iArg: */ SQLITE_QueryOnly }, |
| 95418 | +#if !defined(SQLITE_OMIT_INTEGRITY_CHECK) |
| 95419 | + { /* zName: */ "quick_check", |
| 95420 | + /* ePragTyp: */ PragTyp_INTEGRITY_CHECK, |
| 95421 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95422 | + /* iArg: */ 0 }, |
| 95423 | +#endif |
| 95424 | + { /* zName: */ "read_uncommitted", |
| 95425 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95426 | + /* ePragFlag: */ 0, |
| 95427 | + /* iArg: */ SQLITE_ReadUncommitted }, |
| 95428 | + { /* zName: */ "recursive_triggers", |
| 95429 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95430 | + /* ePragFlag: */ 0, |
| 95431 | + /* iArg: */ SQLITE_RecTriggers }, |
| 95432 | +#if defined(SQLITE_HAS_CODEC) |
| 95433 | + { /* zName: */ "rekey", |
| 95434 | + /* ePragTyp: */ PragTyp_REKEY, |
| 95435 | + /* ePragFlag: */ 0, |
| 95436 | + /* iArg: */ 0 }, |
| 95437 | +#endif |
| 95438 | + { /* zName: */ "reverse_unordered_selects", |
| 95439 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95440 | + /* ePragFlag: */ 0, |
| 95441 | + /* iArg: */ SQLITE_ReverseOrder }, |
| 95442 | +#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 95443 | + { /* zName: */ "schema_version", |
| 95444 | + /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 95445 | + /* ePragFlag: */ 0, |
| 95446 | + /* iArg: */ 0 }, |
| 95447 | +#endif |
| 95448 | +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 95449 | + { /* zName: */ "secure_delete", |
| 95450 | + /* ePragTyp: */ PragTyp_SECURE_DELETE, |
| 95451 | + /* ePragFlag: */ 0, |
| 95452 | + /* iArg: */ 0 }, |
| 95453 | +#endif |
| 95454 | + { /* zName: */ "short_column_names", |
| 95455 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95456 | + /* ePragFlag: */ 0, |
| 95457 | + /* iArg: */ SQLITE_ShortColNames }, |
| 95458 | + { /* zName: */ "shrink_memory", |
| 95459 | + /* ePragTyp: */ PragTyp_SHRINK_MEMORY, |
| 95460 | + /* ePragFlag: */ 0, |
| 95461 | + /* iArg: */ 0 }, |
| 95462 | + { /* zName: */ "soft_heap_limit", |
| 95463 | + /* ePragTyp: */ PragTyp_SOFT_HEAP_LIMIT, |
| 95464 | + /* ePragFlag: */ 0, |
| 95465 | + /* iArg: */ 0 }, |
| 95466 | +#if defined(SQLITE_DEBUG) |
| 95467 | + { /* zName: */ "sql_trace", |
| 95468 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95469 | + /* ePragFlag: */ 0, |
| 95470 | + /* iArg: */ SQLITE_SqlTrace }, |
| 95471 | +#endif |
| 95472 | +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 95473 | + { /* zName: */ "synchronous", |
| 95474 | + /* ePragTyp: */ PragTyp_SYNCHRONOUS, |
| 95475 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95476 | + /* iArg: */ 0 }, |
| 95121 | 95477 | #endif |
| 95122 | 95478 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 95123 | | - { "table_info", PragTyp_TABLE_INFO, 0 }, |
| 95479 | + { /* zName: */ "table_info", |
| 95480 | + /* ePragTyp: */ PragTyp_TABLE_INFO, |
| 95481 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95482 | + /* iArg: */ 0 }, |
| 95124 | 95483 | #endif |
| 95125 | 95484 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 95126 | | - { "temp_store", PragTyp_TEMP_STORE, 0 }, |
| 95127 | | - { "temp_store_directory", PragTyp_TEMP_STORE_DIRECTORY, 0 }, |
| 95485 | + { /* zName: */ "temp_store", |
| 95486 | + /* ePragTyp: */ PragTyp_TEMP_STORE, |
| 95487 | + /* ePragFlag: */ 0, |
| 95488 | + /* iArg: */ 0 }, |
| 95489 | + { /* zName: */ "temp_store_directory", |
| 95490 | + /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY, |
| 95491 | + /* ePragFlag: */ 0, |
| 95492 | + /* iArg: */ 0 }, |
| 95128 | 95493 | #endif |
| 95129 | 95494 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 95130 | | - { "user_version", PragTyp_HEADER_VALUE, 0 }, |
| 95495 | + { /* zName: */ "user_version", |
| 95496 | + /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 95497 | + /* ePragFlag: */ 0, |
| 95498 | + /* iArg: */ 0 }, |
| 95131 | 95499 | #endif |
| 95132 | 95500 | #if defined(SQLITE_DEBUG) |
| 95133 | | - { "vdbe_addoptrace", PragTyp_FLAG, |
| 95134 | | - SQLITE_VdbeAddopTrace }, |
| 95135 | | - { "vdbe_debug", PragTyp_FLAG, |
| 95136 | | - SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace }, |
| 95137 | | - { "vdbe_listing", PragTyp_FLAG, |
| 95138 | | - SQLITE_VdbeListing }, |
| 95139 | | - { "vdbe_trace", PragTyp_FLAG, |
| 95140 | | - SQLITE_VdbeTrace }, |
| 95501 | + { /* zName: */ "vdbe_addoptrace", |
| 95502 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95503 | + /* ePragFlag: */ 0, |
| 95504 | + /* iArg: */ SQLITE_VdbeAddopTrace }, |
| 95505 | + { /* zName: */ "vdbe_debug", |
| 95506 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95507 | + /* ePragFlag: */ 0, |
| 95508 | + /* iArg: */ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace }, |
| 95509 | + { /* zName: */ "vdbe_listing", |
| 95510 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95511 | + /* ePragFlag: */ 0, |
| 95512 | + /* iArg: */ SQLITE_VdbeListing }, |
| 95513 | + { /* zName: */ "vdbe_trace", |
| 95514 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95515 | + /* ePragFlag: */ 0, |
| 95516 | + /* iArg: */ SQLITE_VdbeTrace }, |
| 95141 | 95517 | #endif |
| 95142 | 95518 | #if !defined(SQLITE_OMIT_WAL) |
| 95143 | | - { "wal_autocheckpoint", PragTyp_WAL_AUTOCHECKPOINT, 0 }, |
| 95144 | | - { "wal_checkpoint", PragTyp_WAL_CHECKPOINT, 0 }, |
| 95519 | + { /* zName: */ "wal_autocheckpoint", |
| 95520 | + /* ePragTyp: */ PragTyp_WAL_AUTOCHECKPOINT, |
| 95521 | + /* ePragFlag: */ 0, |
| 95522 | + /* iArg: */ 0 }, |
| 95523 | + { /* zName: */ "wal_checkpoint", |
| 95524 | + /* ePragTyp: */ PragTyp_WAL_CHECKPOINT, |
| 95525 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95526 | + /* iArg: */ 0 }, |
| 95145 | 95527 | #endif |
| 95146 | | - { "writable_schema", PragTyp_FLAG, |
| 95147 | | - SQLITE_WriteSchema|SQLITE_RecoveryMode }, |
| 95528 | + { /* zName: */ "writable_schema", |
| 95529 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95530 | + /* ePragFlag: */ 0, |
| 95531 | + /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode }, |
| 95148 | 95532 | }; |
| 95149 | | -/* Number of pragmas: 55 on by default, 66 total. */ |
| 95533 | +/* Number of pragmas: 55 on by default, 67 total. */ |
| 95150 | 95534 | /* End of the automatically generated pragma table. |
| 95151 | 95535 | ***************************************************************************/ |
| 95152 | 95536 | |
| 95153 | 95537 | /* |
| 95154 | 95538 | ** Interpret the given string as a safety level. Return 0 for OFF, |
| | @@ -95476,10 +95860,15 @@ |
| 95476 | 95860 | }else{ |
| 95477 | 95861 | lwr = mid + 1; |
| 95478 | 95862 | } |
| 95479 | 95863 | } |
| 95480 | 95864 | if( lwr>upr ) goto pragma_out; |
| 95865 | + |
| 95866 | + /* Make sure the database schema is loaded if the pragma requires that */ |
| 95867 | + if( (aPragmaNames[mid].mPragFlag & PragFlag_NeedSchema)!=0 ){ |
| 95868 | + if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 95869 | + } |
| 95481 | 95870 | |
| 95482 | 95871 | /* Jump to the appropriate pragma handler */ |
| 95483 | 95872 | switch( aPragmaNames[mid].ePragTyp ){ |
| 95484 | 95873 | |
| 95485 | 95874 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) |
| | @@ -95510,11 +95899,10 @@ |
| 95510 | 95899 | { OP_Integer, 0, 1, 0}, /* 6 */ |
| 95511 | 95900 | { OP_Noop, 0, 0, 0}, |
| 95512 | 95901 | { OP_ResultRow, 1, 1, 0}, |
| 95513 | 95902 | }; |
| 95514 | 95903 | int addr; |
| 95515 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 95516 | 95904 | sqlite3VdbeUsesBtree(v, iDb); |
| 95517 | 95905 | if( !zRight ){ |
| 95518 | 95906 | sqlite3VdbeSetNumCols(v, 1); |
| 95519 | 95907 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC); |
| 95520 | 95908 | pParse->nMem += 2; |
| | @@ -95606,11 +95994,10 @@ |
| 95606 | 95994 | ** |
| 95607 | 95995 | ** Return the number of pages in the specified database. |
| 95608 | 95996 | */ |
| 95609 | 95997 | case PragTyp_PAGE_COUNT: { |
| 95610 | 95998 | int iReg; |
| 95611 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 95612 | 95999 | sqlite3CodeVerifySchema(pParse, iDb); |
| 95613 | 96000 | iReg = ++pParse->nMem; |
| 95614 | 96001 | if( sqlite3Tolower(zLeft[0])=='p' ){ |
| 95615 | 96002 | sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg); |
| 95616 | 96003 | }else{ |
| | @@ -95679,18 +96066,10 @@ |
| 95679 | 96066 | */ |
| 95680 | 96067 | case PragTyp_JOURNAL_MODE: { |
| 95681 | 96068 | int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */ |
| 95682 | 96069 | int ii; /* Loop counter */ |
| 95683 | 96070 | |
| 95684 | | - /* Force the schema to be loaded on all databases. This causes all |
| 95685 | | - ** database files to be opened and the journal_modes set. This is |
| 95686 | | - ** necessary because subsequent processing must know if the databases |
| 95687 | | - ** are in WAL mode. */ |
| 95688 | | - if( sqlite3ReadSchema(pParse) ){ |
| 95689 | | - goto pragma_out; |
| 95690 | | - } |
| 95691 | | - |
| 95692 | 96071 | sqlite3VdbeSetNumCols(v, 1); |
| 95693 | 96072 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC); |
| 95694 | 96073 | |
| 95695 | 96074 | if( zRight==0 ){ |
| 95696 | 96075 | /* If there is no "=MODE" part of the pragma, do a query for the |
| | @@ -95752,55 +96131,44 @@ |
| 95752 | 96131 | */ |
| 95753 | 96132 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 95754 | 96133 | case PragTyp_AUTO_VACUUM: { |
| 95755 | 96134 | Btree *pBt = pDb->pBt; |
| 95756 | 96135 | assert( pBt!=0 ); |
| 95757 | | - if( sqlite3ReadSchema(pParse) ){ |
| 95758 | | - goto pragma_out; |
| 95759 | | - } |
| 95760 | 96136 | if( !zRight ){ |
| 95761 | | - int auto_vacuum; |
| 95762 | | - if( ALWAYS(pBt) ){ |
| 95763 | | - auto_vacuum = sqlite3BtreeGetAutoVacuum(pBt); |
| 95764 | | - }else{ |
| 95765 | | - auto_vacuum = SQLITE_DEFAULT_AUTOVACUUM; |
| 95766 | | - } |
| 95767 | | - returnSingleInt(pParse, "auto_vacuum", auto_vacuum); |
| 96137 | + returnSingleInt(pParse, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt)); |
| 95768 | 96138 | }else{ |
| 95769 | 96139 | int eAuto = getAutoVacuum(zRight); |
| 95770 | 96140 | assert( eAuto>=0 && eAuto<=2 ); |
| 95771 | 96141 | db->nextAutovac = (u8)eAuto; |
| 95772 | | - if( ALWAYS(eAuto>=0) ){ |
| 95773 | | - /* Call SetAutoVacuum() to set initialize the internal auto and |
| 95774 | | - ** incr-vacuum flags. This is required in case this connection |
| 95775 | | - ** creates the database file. It is important that it is created |
| 95776 | | - ** as an auto-vacuum capable db. |
| 95777 | | - */ |
| 95778 | | - rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto); |
| 95779 | | - if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){ |
| 95780 | | - /* When setting the auto_vacuum mode to either "full" or |
| 95781 | | - ** "incremental", write the value of meta[6] in the database |
| 95782 | | - ** file. Before writing to meta[6], check that meta[3] indicates |
| 95783 | | - ** that this really is an auto-vacuum capable database. |
| 95784 | | - */ |
| 95785 | | - static const VdbeOpList setMeta6[] = { |
| 95786 | | - { OP_Transaction, 0, 1, 0}, /* 0 */ |
| 95787 | | - { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE}, |
| 95788 | | - { OP_If, 1, 0, 0}, /* 2 */ |
| 95789 | | - { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */ |
| 95790 | | - { OP_Integer, 0, 1, 0}, /* 4 */ |
| 95791 | | - { OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */ |
| 95792 | | - }; |
| 95793 | | - int iAddr; |
| 95794 | | - iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6); |
| 95795 | | - sqlite3VdbeChangeP1(v, iAddr, iDb); |
| 95796 | | - sqlite3VdbeChangeP1(v, iAddr+1, iDb); |
| 95797 | | - sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4); |
| 95798 | | - sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1); |
| 95799 | | - sqlite3VdbeChangeP1(v, iAddr+5, iDb); |
| 95800 | | - sqlite3VdbeUsesBtree(v, iDb); |
| 95801 | | - } |
| 96142 | + /* Call SetAutoVacuum() to set initialize the internal auto and |
| 96143 | + ** incr-vacuum flags. This is required in case this connection |
| 96144 | + ** creates the database file. It is important that it is created |
| 96145 | + ** as an auto-vacuum capable db. |
| 96146 | + */ |
| 96147 | + rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto); |
| 96148 | + if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){ |
| 96149 | + /* When setting the auto_vacuum mode to either "full" or |
| 96150 | + ** "incremental", write the value of meta[6] in the database |
| 96151 | + ** file. Before writing to meta[6], check that meta[3] indicates |
| 96152 | + ** that this really is an auto-vacuum capable database. |
| 96153 | + */ |
| 96154 | + static const VdbeOpList setMeta6[] = { |
| 96155 | + { OP_Transaction, 0, 1, 0}, /* 0 */ |
| 96156 | + { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE}, |
| 96157 | + { OP_If, 1, 0, 0}, /* 2 */ |
| 96158 | + { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */ |
| 96159 | + { OP_Integer, 0, 1, 0}, /* 4 */ |
| 96160 | + { OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */ |
| 96161 | + }; |
| 96162 | + int iAddr; |
| 96163 | + iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6); |
| 96164 | + sqlite3VdbeChangeP1(v, iAddr, iDb); |
| 96165 | + sqlite3VdbeChangeP1(v, iAddr+1, iDb); |
| 96166 | + sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4); |
| 96167 | + sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1); |
| 96168 | + sqlite3VdbeChangeP1(v, iAddr+5, iDb); |
| 96169 | + sqlite3VdbeUsesBtree(v, iDb); |
| 95802 | 96170 | } |
| 95803 | 96171 | } |
| 95804 | 96172 | break; |
| 95805 | 96173 | } |
| 95806 | 96174 | #endif |
| | @@ -95811,13 +96179,10 @@ |
| 95811 | 96179 | ** Do N steps of incremental vacuuming on a database. |
| 95812 | 96180 | */ |
| 95813 | 96181 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 95814 | 96182 | case PragTyp_INCREMENTAL_VACUUM: { |
| 95815 | 96183 | int iLimit, addr; |
| 95816 | | - if( sqlite3ReadSchema(pParse) ){ |
| 95817 | | - goto pragma_out; |
| 95818 | | - } |
| 95819 | 96184 | if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){ |
| 95820 | 96185 | iLimit = 0x7fffffff; |
| 95821 | 96186 | } |
| 95822 | 96187 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 95823 | 96188 | sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1); |
| | @@ -95841,11 +96206,10 @@ |
| 95841 | 96206 | ** number of pages in the cache. If N is negative, then the |
| 95842 | 96207 | ** number of pages is adjusted so that the cache uses -N kibibytes |
| 95843 | 96208 | ** of memory. |
| 95844 | 96209 | */ |
| 95845 | 96210 | case PragTyp_CACHE_SIZE: { |
| 95846 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 95847 | 96211 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 95848 | 96212 | if( !zRight ){ |
| 95849 | 96213 | returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size); |
| 95850 | 96214 | }else{ |
| 95851 | 96215 | int size = sqlite3Atoi(zRight); |
| | @@ -96062,11 +96426,10 @@ |
| 96062 | 96426 | ** the local value does not make changes to the disk file and the |
| 96063 | 96427 | ** default value will be restored the next time the database is |
| 96064 | 96428 | ** opened. |
| 96065 | 96429 | */ |
| 96066 | 96430 | case PragTyp_SYNCHRONOUS: { |
| 96067 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96068 | 96431 | if( !zRight ){ |
| 96069 | 96432 | returnSingleInt(pParse, "synchronous", pDb->safety_level-1); |
| 96070 | 96433 | }else{ |
| 96071 | 96434 | if( !db->autoCommit ){ |
| 96072 | 96435 | sqlite3ErrorMsg(pParse, |
| | @@ -96124,11 +96487,10 @@ |
| 96124 | 96487 | ** notnull: True if 'NOT NULL' is part of column declaration |
| 96125 | 96488 | ** dflt_value: The default value for the column, if any. |
| 96126 | 96489 | */ |
| 96127 | 96490 | case PragTyp_TABLE_INFO: if( zRight ){ |
| 96128 | 96491 | Table *pTab; |
| 96129 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96130 | 96492 | pTab = sqlite3FindTable(db, zRight, zDb); |
| 96131 | 96493 | if( pTab ){ |
| 96132 | 96494 | int i, k; |
| 96133 | 96495 | int nHidden = 0; |
| 96134 | 96496 | Column *pCol; |
| | @@ -96174,11 +96536,10 @@ |
| 96174 | 96536 | break; |
| 96175 | 96537 | |
| 96176 | 96538 | case PragTyp_INDEX_INFO: if( zRight ){ |
| 96177 | 96539 | Index *pIdx; |
| 96178 | 96540 | Table *pTab; |
| 96179 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96180 | 96541 | pIdx = sqlite3FindIndex(db, zRight, zDb); |
| 96181 | 96542 | if( pIdx ){ |
| 96182 | 96543 | int i; |
| 96183 | 96544 | pTab = pIdx->pTable; |
| 96184 | 96545 | sqlite3VdbeSetNumCols(v, 3); |
| | @@ -96200,39 +96561,41 @@ |
| 96200 | 96561 | break; |
| 96201 | 96562 | |
| 96202 | 96563 | case PragTyp_INDEX_LIST: if( zRight ){ |
| 96203 | 96564 | Index *pIdx; |
| 96204 | 96565 | Table *pTab; |
| 96205 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96566 | + int i; |
| 96206 | 96567 | pTab = sqlite3FindTable(db, zRight, zDb); |
| 96207 | 96568 | if( pTab ){ |
| 96208 | 96569 | v = sqlite3GetVdbe(pParse); |
| 96209 | | - pIdx = pTab->pIndex; |
| 96210 | | - if( pIdx ){ |
| 96211 | | - int i = 0; |
| 96212 | | - sqlite3VdbeSetNumCols(v, 3); |
| 96213 | | - pParse->nMem = 3; |
| 96214 | | - sqlite3CodeVerifySchema(pParse, iDb); |
| 96215 | | - sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC); |
| 96216 | | - sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC); |
| 96217 | | - sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC); |
| 96218 | | - while(pIdx){ |
| 96219 | | - sqlite3VdbeAddOp2(v, OP_Integer, i, 1); |
| 96220 | | - sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0); |
| 96221 | | - sqlite3VdbeAddOp2(v, OP_Integer, pIdx->onError!=OE_None, 3); |
| 96222 | | - sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); |
| 96223 | | - ++i; |
| 96224 | | - pIdx = pIdx->pNext; |
| 96225 | | - } |
| 96570 | + sqlite3VdbeSetNumCols(v, 4); |
| 96571 | + pParse->nMem = 4; |
| 96572 | + sqlite3CodeVerifySchema(pParse, iDb); |
| 96573 | + sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC); |
| 96574 | + sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC); |
| 96575 | + sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC); |
| 96576 | + sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "avgrowsize", SQLITE_STATIC); |
| 96577 | + sqlite3VdbeAddOp2(v, OP_Integer, 0, 1); |
| 96578 | + sqlite3VdbeAddOp2(v, OP_Null, 0, 2); |
| 96579 | + sqlite3VdbeAddOp2(v, OP_Integer, 1, 3); |
| 96580 | + sqlite3VdbeAddOp2(v, OP_Integer, |
| 96581 | + (int)sqlite3LogEstToInt(pTab->szTabRow), 4); |
| 96582 | + sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4); |
| 96583 | + for(pIdx=pTab->pIndex, i=1; pIdx; pIdx=pIdx->pNext, i++){ |
| 96584 | + sqlite3VdbeAddOp2(v, OP_Integer, i, 1); |
| 96585 | + sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0); |
| 96586 | + sqlite3VdbeAddOp2(v, OP_Integer, pIdx->onError!=OE_None, 3); |
| 96587 | + sqlite3VdbeAddOp2(v, OP_Integer, |
| 96588 | + (int)sqlite3LogEstToInt(pIdx->szIdxRow), 4); |
| 96589 | + sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4); |
| 96226 | 96590 | } |
| 96227 | 96591 | } |
| 96228 | 96592 | } |
| 96229 | 96593 | break; |
| 96230 | 96594 | |
| 96231 | 96595 | case PragTyp_DATABASE_LIST: { |
| 96232 | 96596 | int i; |
| 96233 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96234 | 96597 | sqlite3VdbeSetNumCols(v, 3); |
| 96235 | 96598 | pParse->nMem = 3; |
| 96236 | 96599 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC); |
| 96237 | 96600 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC); |
| 96238 | 96601 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC); |
| | @@ -96267,11 +96630,10 @@ |
| 96267 | 96630 | |
| 96268 | 96631 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 96269 | 96632 | case PragTyp_FOREIGN_KEY_LIST: if( zRight ){ |
| 96270 | 96633 | FKey *pFK; |
| 96271 | 96634 | Table *pTab; |
| 96272 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96273 | 96635 | pTab = sqlite3FindTable(db, zRight, zDb); |
| 96274 | 96636 | if( pTab ){ |
| 96275 | 96637 | v = sqlite3GetVdbe(pParse); |
| 96276 | 96638 | pFK = pTab->pFKey; |
| 96277 | 96639 | if( pFK ){ |
| | @@ -96329,11 +96691,10 @@ |
| 96329 | 96691 | int regRow; /* Registers to hold a row from pTab */ |
| 96330 | 96692 | int addrTop; /* Top of a loop checking foreign keys */ |
| 96331 | 96693 | int addrOk; /* Jump here if the key is OK */ |
| 96332 | 96694 | int *aiCols; /* child to parent column mapping */ |
| 96333 | 96695 | |
| 96334 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96335 | 96696 | regResult = pParse->nMem+1; |
| 96336 | 96697 | pParse->nMem += 4; |
| 96337 | 96698 | regKey = ++pParse->nMem; |
| 96338 | 96699 | regRow = ++pParse->nMem; |
| 96339 | 96700 | v = sqlite3GetVdbe(pParse); |
| | @@ -96490,11 +96851,10 @@ |
| 96490 | 96851 | assert( iDb>=0 ); |
| 96491 | 96852 | assert( iDb==0 || pId2->z ); |
| 96492 | 96853 | if( pId2->z==0 ) iDb = -1; |
| 96493 | 96854 | |
| 96494 | 96855 | /* Initialize the VDBE program */ |
| 96495 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96496 | 96856 | pParse->nMem = 6; |
| 96497 | 96857 | sqlite3VdbeSetNumCols(v, 1); |
| 96498 | 96858 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", SQLITE_STATIC); |
| 96499 | 96859 | |
| 96500 | 96860 | /* Set the maximum error count */ |
| | @@ -96814,11 +97174,10 @@ |
| 96814 | 97174 | eMode = SQLITE_CHECKPOINT_FULL; |
| 96815 | 97175 | }else if( sqlite3StrICmp(zRight, "restart")==0 ){ |
| 96816 | 97176 | eMode = SQLITE_CHECKPOINT_RESTART; |
| 96817 | 97177 | } |
| 96818 | 97178 | } |
| 96819 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96820 | 97179 | sqlite3VdbeSetNumCols(v, 3); |
| 96821 | 97180 | pParse->nMem = 3; |
| 96822 | 97181 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "busy", SQLITE_STATIC); |
| 96823 | 97182 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "log", SQLITE_STATIC); |
| 96824 | 97183 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "checkpointed", SQLITE_STATIC); |
| | @@ -96934,16 +97293,16 @@ |
| 96934 | 97293 | if( zRight ) sqlite3_rekey_v2(db, zDb, zRight, sqlite3Strlen30(zRight)); |
| 96935 | 97294 | break; |
| 96936 | 97295 | } |
| 96937 | 97296 | case PragTyp_HEXKEY: { |
| 96938 | 97297 | if( zRight ){ |
| 96939 | | - int i, h1, h2; |
| 97298 | + u8 iByte; |
| 97299 | + int i; |
| 96940 | 97300 | char zKey[40]; |
| 96941 | | - for(i=0; (h1 = zRight[i])!=0 && (h2 = zRight[i+1])!=0; i+=2){ |
| 96942 | | - h1 += 9*(1&(h1>>6)); |
| 96943 | | - h2 += 9*(1&(h2>>6)); |
| 96944 | | - zKey[i/2] = (h2 & 0x0f) | ((h1 & 0xf)<<4); |
| 97301 | + for(i=0, iByte=0; i<sizeof(zKey)*2 && sqlite3Isxdigit(zRight[i]); i++){ |
| 97302 | + iByte = (iByte<<4) + sqlite3HexToInt(zRight[i]); |
| 97303 | + if( (i&1)!=0 ) zKey[i/2] = iByte; |
| 96945 | 97304 | } |
| 96946 | 97305 | if( (zLeft[3] & 0xf)==0xb ){ |
| 96947 | 97306 | sqlite3_key_v2(db, zDb, zKey, i/2); |
| 96948 | 97307 | }else{ |
| 96949 | 97308 | sqlite3_rekey_v2(db, zDb, zKey, i/2); |
| | @@ -98913,10 +99272,13 @@ |
| 98913 | 99272 | } |
| 98914 | 99273 | |
| 98915 | 99274 | /* |
| 98916 | 99275 | ** Return a pointer to a string containing the 'declaration type' of the |
| 98917 | 99276 | ** expression pExpr. The string may be treated as static by the caller. |
| 99277 | +** |
| 99278 | +** Also try to estimate the size of the returned value and return that |
| 99279 | +** result in *pEstWidth. |
| 98918 | 99280 | ** |
| 98919 | 99281 | ** The declaration type is the exact datatype definition extracted from the |
| 98920 | 99282 | ** original CREATE TABLE statement if the expression is a column. The |
| 98921 | 99283 | ** declaration type for a ROWID field is INTEGER. Exactly when an expression |
| 98922 | 99284 | ** is considered a column can be complex in the presence of subqueries. The |
| | @@ -98927,25 +99289,40 @@ |
| 98927 | 99289 | ** SELECT (SELECT col FROM tbl; |
| 98928 | 99290 | ** SELECT (SELECT col FROM tbl); |
| 98929 | 99291 | ** SELECT abc FROM (SELECT col AS abc FROM tbl); |
| 98930 | 99292 | ** |
| 98931 | 99293 | ** The declaration type for any expression other than a column is NULL. |
| 99294 | +** |
| 99295 | +** This routine has either 3 or 6 parameters depending on whether or not |
| 99296 | +** the SQLITE_ENABLE_COLUMN_METADATA compile-time option is used. |
| 98932 | 99297 | */ |
| 98933 | | -static const char *columnType( |
| 99298 | +#ifdef SQLITE_ENABLE_COLUMN_METADATA |
| 99299 | +# define columnType(A,B,C,D,E,F) columnTypeImpl(A,B,C,D,E,F) |
| 99300 | +static const char *columnTypeImpl( |
| 99301 | + NameContext *pNC, |
| 99302 | + Expr *pExpr, |
| 99303 | + const char **pzOrigDb, |
| 99304 | + const char **pzOrigTab, |
| 99305 | + const char **pzOrigCol, |
| 99306 | + u8 *pEstWidth |
| 99307 | +){ |
| 99308 | + char const *zOrigDb = 0; |
| 99309 | + char const *zOrigTab = 0; |
| 99310 | + char const *zOrigCol = 0; |
| 99311 | +#else /* if !defined(SQLITE_ENABLE_COLUMN_METADATA) */ |
| 99312 | +# define columnType(A,B,C,D,E,F) columnTypeImpl(A,B,F) |
| 99313 | +static const char *columnTypeImpl( |
| 98934 | 99314 | NameContext *pNC, |
| 98935 | 99315 | Expr *pExpr, |
| 98936 | | - const char **pzOriginDb, |
| 98937 | | - const char **pzOriginTab, |
| 98938 | | - const char **pzOriginCol |
| 99316 | + u8 *pEstWidth |
| 98939 | 99317 | ){ |
| 99318 | +#endif /* !defined(SQLITE_ENABLE_COLUMN_METADATA) */ |
| 98940 | 99319 | char const *zType = 0; |
| 98941 | | - char const *zOriginDb = 0; |
| 98942 | | - char const *zOriginTab = 0; |
| 98943 | | - char const *zOriginCol = 0; |
| 98944 | 99320 | int j; |
| 99321 | + u8 estWidth = 1; |
| 99322 | + |
| 98945 | 99323 | if( NEVER(pExpr==0) || pNC->pSrcList==0 ) return 0; |
| 98946 | | - |
| 98947 | 99324 | switch( pExpr->op ){ |
| 98948 | 99325 | case TK_AGG_COLUMN: |
| 98949 | 99326 | case TK_COLUMN: { |
| 98950 | 99327 | /* The expression is a column. Locate the table the column is being |
| 98951 | 99328 | ** extracted from in NameContext.pSrcList. This table may be real |
| | @@ -99002,29 +99379,39 @@ |
| 99002 | 99379 | NameContext sNC; |
| 99003 | 99380 | Expr *p = pS->pEList->a[iCol].pExpr; |
| 99004 | 99381 | sNC.pSrcList = pS->pSrc; |
| 99005 | 99382 | sNC.pNext = pNC; |
| 99006 | 99383 | sNC.pParse = pNC->pParse; |
| 99007 | | - zType = columnType(&sNC, p, &zOriginDb, &zOriginTab, &zOriginCol); |
| 99384 | + zType = columnType(&sNC, p,&zOrigDb,&zOrigTab,&zOrigCol, &estWidth); |
| 99008 | 99385 | } |
| 99009 | 99386 | }else if( ALWAYS(pTab->pSchema) ){ |
| 99010 | 99387 | /* A real table */ |
| 99011 | 99388 | assert( !pS ); |
| 99012 | 99389 | if( iCol<0 ) iCol = pTab->iPKey; |
| 99013 | 99390 | assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) ); |
| 99391 | +#ifdef SQLITE_ENABLE_COLUMN_METADATA |
| 99014 | 99392 | if( iCol<0 ){ |
| 99015 | 99393 | zType = "INTEGER"; |
| 99016 | | - zOriginCol = "rowid"; |
| 99394 | + zOrigCol = "rowid"; |
| 99017 | 99395 | }else{ |
| 99018 | 99396 | zType = pTab->aCol[iCol].zType; |
| 99019 | | - zOriginCol = pTab->aCol[iCol].zName; |
| 99397 | + zOrigCol = pTab->aCol[iCol].zName; |
| 99398 | + estWidth = pTab->aCol[iCol].szEst; |
| 99020 | 99399 | } |
| 99021 | | - zOriginTab = pTab->zName; |
| 99400 | + zOrigTab = pTab->zName; |
| 99022 | 99401 | if( pNC->pParse ){ |
| 99023 | 99402 | int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema); |
| 99024 | | - zOriginDb = pNC->pParse->db->aDb[iDb].zName; |
| 99403 | + zOrigDb = pNC->pParse->db->aDb[iDb].zName; |
| 99025 | 99404 | } |
| 99405 | +#else |
| 99406 | + if( iCol<0 ){ |
| 99407 | + zType = "INTEGER"; |
| 99408 | + }else{ |
| 99409 | + zType = pTab->aCol[iCol].zType; |
| 99410 | + estWidth = pTab->aCol[iCol].szEst; |
| 99411 | + } |
| 99412 | +#endif |
| 99026 | 99413 | } |
| 99027 | 99414 | break; |
| 99028 | 99415 | } |
| 99029 | 99416 | #ifndef SQLITE_OMIT_SUBQUERY |
| 99030 | 99417 | case TK_SELECT: { |
| | @@ -99037,22 +99424,25 @@ |
| 99037 | 99424 | Expr *p = pS->pEList->a[0].pExpr; |
| 99038 | 99425 | assert( ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 99039 | 99426 | sNC.pSrcList = pS->pSrc; |
| 99040 | 99427 | sNC.pNext = pNC; |
| 99041 | 99428 | sNC.pParse = pNC->pParse; |
| 99042 | | - zType = columnType(&sNC, p, &zOriginDb, &zOriginTab, &zOriginCol); |
| 99429 | + zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol, &estWidth); |
| 99043 | 99430 | break; |
| 99044 | 99431 | } |
| 99045 | 99432 | #endif |
| 99046 | 99433 | } |
| 99047 | | - |
| 99048 | | - if( pzOriginDb ){ |
| 99049 | | - assert( pzOriginTab && pzOriginCol ); |
| 99050 | | - *pzOriginDb = zOriginDb; |
| 99051 | | - *pzOriginTab = zOriginTab; |
| 99052 | | - *pzOriginCol = zOriginCol; |
| 99434 | + |
| 99435 | +#ifdef SQLITE_ENABLE_COLUMN_METADATA |
| 99436 | + if( pzOrigDb ){ |
| 99437 | + assert( pzOrigTab && pzOrigCol ); |
| 99438 | + *pzOrigDb = zOrigDb; |
| 99439 | + *pzOrigTab = zOrigTab; |
| 99440 | + *pzOrigCol = zOrigCol; |
| 99053 | 99441 | } |
| 99442 | +#endif |
| 99443 | + if( pEstWidth ) *pEstWidth = estWidth; |
| 99054 | 99444 | return zType; |
| 99055 | 99445 | } |
| 99056 | 99446 | |
| 99057 | 99447 | /* |
| 99058 | 99448 | ** Generate code that will tell the VDBE the declaration types of columns |
| | @@ -99074,25 +99464,25 @@ |
| 99074 | 99464 | const char *zType; |
| 99075 | 99465 | #ifdef SQLITE_ENABLE_COLUMN_METADATA |
| 99076 | 99466 | const char *zOrigDb = 0; |
| 99077 | 99467 | const char *zOrigTab = 0; |
| 99078 | 99468 | const char *zOrigCol = 0; |
| 99079 | | - zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol); |
| 99469 | + zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol, 0); |
| 99080 | 99470 | |
| 99081 | 99471 | /* The vdbe must make its own copy of the column-type and other |
| 99082 | 99472 | ** column specific strings, in case the schema is reset before this |
| 99083 | 99473 | ** virtual machine is deleted. |
| 99084 | 99474 | */ |
| 99085 | 99475 | sqlite3VdbeSetColName(v, i, COLNAME_DATABASE, zOrigDb, SQLITE_TRANSIENT); |
| 99086 | 99476 | sqlite3VdbeSetColName(v, i, COLNAME_TABLE, zOrigTab, SQLITE_TRANSIENT); |
| 99087 | 99477 | sqlite3VdbeSetColName(v, i, COLNAME_COLUMN, zOrigCol, SQLITE_TRANSIENT); |
| 99088 | 99478 | #else |
| 99089 | | - zType = columnType(&sNC, p, 0, 0, 0); |
| 99479 | + zType = columnType(&sNC, p, 0, 0, 0, 0); |
| 99090 | 99480 | #endif |
| 99091 | 99481 | sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT); |
| 99092 | 99482 | } |
| 99093 | | -#endif /* SQLITE_OMIT_DECLTYPE */ |
| 99483 | +#endif /* !defined(SQLITE_OMIT_DECLTYPE) */ |
| 99094 | 99484 | } |
| 99095 | 99485 | |
| 99096 | 99486 | /* |
| 99097 | 99487 | ** Generate code that will tell the VDBE the names of columns |
| 99098 | 99488 | ** in the result set. This information is used to provide the |
| | @@ -99277,39 +99667,41 @@ |
| 99277 | 99667 | ** This routine requires that all identifiers in the SELECT |
| 99278 | 99668 | ** statement be resolved. |
| 99279 | 99669 | */ |
| 99280 | 99670 | static void selectAddColumnTypeAndCollation( |
| 99281 | 99671 | Parse *pParse, /* Parsing contexts */ |
| 99282 | | - int nCol, /* Number of columns */ |
| 99283 | | - Column *aCol, /* List of columns */ |
| 99672 | + Table *pTab, /* Add column type information to this table */ |
| 99284 | 99673 | Select *pSelect /* SELECT used to determine types and collations */ |
| 99285 | 99674 | ){ |
| 99286 | 99675 | sqlite3 *db = pParse->db; |
| 99287 | 99676 | NameContext sNC; |
| 99288 | 99677 | Column *pCol; |
| 99289 | 99678 | CollSeq *pColl; |
| 99290 | 99679 | int i; |
| 99291 | 99680 | Expr *p; |
| 99292 | 99681 | struct ExprList_item *a; |
| 99682 | + u64 szAll = 0; |
| 99293 | 99683 | |
| 99294 | 99684 | assert( pSelect!=0 ); |
| 99295 | 99685 | assert( (pSelect->selFlags & SF_Resolved)!=0 ); |
| 99296 | | - assert( nCol==pSelect->pEList->nExpr || db->mallocFailed ); |
| 99686 | + assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed ); |
| 99297 | 99687 | if( db->mallocFailed ) return; |
| 99298 | 99688 | memset(&sNC, 0, sizeof(sNC)); |
| 99299 | 99689 | sNC.pSrcList = pSelect->pSrc; |
| 99300 | 99690 | a = pSelect->pEList->a; |
| 99301 | | - for(i=0, pCol=aCol; i<nCol; i++, pCol++){ |
| 99691 | + for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ |
| 99302 | 99692 | p = a[i].pExpr; |
| 99303 | | - pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p, 0, 0, 0)); |
| 99693 | + pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst)); |
| 99694 | + szAll += pCol->szEst; |
| 99304 | 99695 | pCol->affinity = sqlite3ExprAffinity(p); |
| 99305 | 99696 | if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE; |
| 99306 | 99697 | pColl = sqlite3ExprCollSeq(pParse, p); |
| 99307 | 99698 | if( pColl ){ |
| 99308 | 99699 | pCol->zColl = sqlite3DbStrDup(db, pColl->zName); |
| 99309 | 99700 | } |
| 99310 | 99701 | } |
| 99702 | + pTab->szTabRow = sqlite3LogEst(szAll*4); |
| 99311 | 99703 | } |
| 99312 | 99704 | |
| 99313 | 99705 | /* |
| 99314 | 99706 | ** Given a SELECT statement, generate a Table structure that describes |
| 99315 | 99707 | ** the result set of that SELECT. |
| | @@ -99333,13 +99725,13 @@ |
| 99333 | 99725 | /* The sqlite3ResultSetOfSelect() is only used n contexts where lookaside |
| 99334 | 99726 | ** is disabled */ |
| 99335 | 99727 | assert( db->lookaside.bEnabled==0 ); |
| 99336 | 99728 | pTab->nRef = 1; |
| 99337 | 99729 | pTab->zName = 0; |
| 99338 | | - pTab->nRowEst = 1000000; |
| 99730 | + pTab->nRowEst = 1048576; |
| 99339 | 99731 | selectColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol); |
| 99340 | | - selectAddColumnTypeAndCollation(pParse, pTab->nCol, pTab->aCol, pSelect); |
| 99732 | + selectAddColumnTypeAndCollation(pParse, pTab, pSelect); |
| 99341 | 99733 | pTab->iPKey = -1; |
| 99342 | 99734 | if( db->mallocFailed ){ |
| 99343 | 99735 | sqlite3DeleteTable(db, pTab); |
| 99344 | 99736 | return 0; |
| 99345 | 99737 | } |
| | @@ -101247,15 +101639,15 @@ |
| 101247 | 101639 | assert( pFrom->pTab==0 ); |
| 101248 | 101640 | sqlite3WalkSelect(pWalker, pSel); |
| 101249 | 101641 | pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table)); |
| 101250 | 101642 | if( pTab==0 ) return WRC_Abort; |
| 101251 | 101643 | pTab->nRef = 1; |
| 101252 | | - pTab->zName = sqlite3MPrintf(db, "sqlite_subquery_%p_", (void*)pTab); |
| 101644 | + pTab->zName = sqlite3MPrintf(db, "sqlite_sq_%p", (void*)pTab); |
| 101253 | 101645 | while( pSel->pPrior ){ pSel = pSel->pPrior; } |
| 101254 | 101646 | selectColumnsFromExprList(pParse, pSel->pEList, &pTab->nCol, &pTab->aCol); |
| 101255 | 101647 | pTab->iPKey = -1; |
| 101256 | | - pTab->nRowEst = 1000000; |
| 101648 | + pTab->nRowEst = 1048576; |
| 101257 | 101649 | pTab->tabFlags |= TF_Ephemeral; |
| 101258 | 101650 | #endif |
| 101259 | 101651 | }else{ |
| 101260 | 101652 | /* An ordinary table or view name in the FROM clause */ |
| 101261 | 101653 | assert( pFrom->pTab==0 ); |
| | @@ -101535,11 +101927,11 @@ |
| 101535 | 101927 | if( ALWAYS(pTab!=0) && (pTab->tabFlags & TF_Ephemeral)!=0 ){ |
| 101536 | 101928 | /* A sub-query in the FROM clause of a SELECT */ |
| 101537 | 101929 | Select *pSel = pFrom->pSelect; |
| 101538 | 101930 | assert( pSel ); |
| 101539 | 101931 | while( pSel->pPrior ) pSel = pSel->pPrior; |
| 101540 | | - selectAddColumnTypeAndCollation(pParse, pTab->nCol, pTab->aCol, pSel); |
| 101932 | + selectAddColumnTypeAndCollation(pParse, pTab, pSel); |
| 101541 | 101933 | } |
| 101542 | 101934 | } |
| 101543 | 101935 | } |
| 101544 | 101936 | return WRC_Continue; |
| 101545 | 101937 | } |
| | @@ -102450,29 +102842,29 @@ |
| 102450 | 102842 | int iRoot = pTab->tnum; /* Root page of scanned b-tree */ |
| 102451 | 102843 | |
| 102452 | 102844 | sqlite3CodeVerifySchema(pParse, iDb); |
| 102453 | 102845 | sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); |
| 102454 | 102846 | |
| 102455 | | - /* Search for the index that has the least amount of columns. If |
| 102456 | | - ** there is such an index, and it has less columns than the table |
| 102457 | | - ** does, then we can assume that it consumes less space on disk and |
| 102458 | | - ** will therefore be cheaper to scan to determine the query result. |
| 102459 | | - ** In this case set iRoot to the root page number of the index b-tree |
| 102460 | | - ** and pKeyInfo to the KeyInfo structure required to navigate the |
| 102461 | | - ** index. |
| 102847 | + /* Search for the index that has the lowest scan cost. |
| 102462 | 102848 | ** |
| 102463 | 102849 | ** (2011-04-15) Do not do a full scan of an unordered index. |
| 102850 | + ** |
| 102851 | + ** (2013-10-03) Do not count the entires in a partial index. |
| 102464 | 102852 | ** |
| 102465 | 102853 | ** In practice the KeyInfo structure will not be used. It is only |
| 102466 | 102854 | ** passed to keep OP_OpenRead happy. |
| 102467 | 102855 | */ |
| 102468 | 102856 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 102469 | | - if( pIdx->bUnordered==0 && (!pBest || pIdx->nColumn<pBest->nColumn) ){ |
| 102857 | + if( pIdx->bUnordered==0 |
| 102858 | + && pIdx->szIdxRow<pTab->szTabRow |
| 102859 | + && pIdx->pPartIdxWhere==0 |
| 102860 | + && (!pBest || pIdx->szIdxRow<pBest->szIdxRow) |
| 102861 | + ){ |
| 102470 | 102862 | pBest = pIdx; |
| 102471 | 102863 | } |
| 102472 | 102864 | } |
| 102473 | | - if( pBest && pBest->nColumn<pTab->nCol ){ |
| 102865 | + if( pBest ){ |
| 102474 | 102866 | iRoot = pBest->tnum; |
| 102475 | 102867 | pKeyInfo = sqlite3IndexKeyinfo(pParse, pBest); |
| 102476 | 102868 | } |
| 102477 | 102869 | |
| 102478 | 102870 | /* Open a read-only cursor, execute the OP_Count, close the cursor. */ |
| | @@ -103046,12 +103438,12 @@ |
| 103046 | 103438 | } |
| 103047 | 103439 | |
| 103048 | 103440 | /* Ensure the table name matches database name and that the table exists */ |
| 103049 | 103441 | if( db->mallocFailed ) goto trigger_cleanup; |
| 103050 | 103442 | assert( pTableName->nSrc==1 ); |
| 103051 | | - if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", pName) && |
| 103052 | | - sqlite3FixSrcList(&sFix, pTableName) ){ |
| 103443 | + sqlite3FixInit(&sFix, pParse, iDb, "trigger", pName); |
| 103444 | + if( sqlite3FixSrcList(&sFix, pTableName) ){ |
| 103053 | 103445 | goto trigger_cleanup; |
| 103054 | 103446 | } |
| 103055 | 103447 | pTab = sqlite3SrcListLookup(pParse, pTableName); |
| 103056 | 103448 | if( !pTab ){ |
| 103057 | 103449 | /* The table does not exist. */ |
| | @@ -103189,12 +103581,14 @@ |
| 103189 | 103581 | pStepList->pTrig = pTrig; |
| 103190 | 103582 | pStepList = pStepList->pNext; |
| 103191 | 103583 | } |
| 103192 | 103584 | nameToken.z = pTrig->zName; |
| 103193 | 103585 | nameToken.n = sqlite3Strlen30(nameToken.z); |
| 103194 | | - if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", &nameToken) |
| 103195 | | - && sqlite3FixTriggerStep(&sFix, pTrig->step_list) ){ |
| 103586 | + sqlite3FixInit(&sFix, pParse, iDb, "trigger", &nameToken); |
| 103587 | + if( sqlite3FixTriggerStep(&sFix, pTrig->step_list) |
| 103588 | + || sqlite3FixExpr(&sFix, pTrig->pWhen) |
| 103589 | + ){ |
| 103196 | 103590 | goto triggerfinish_cleanup; |
| 103197 | 103591 | } |
| 103198 | 103592 | |
| 103199 | 103593 | /* if we are not initializing, |
| 103200 | 103594 | ** build the sqlite_master entry |
| | @@ -104781,18 +105175,38 @@ |
| 104781 | 105175 | |
| 104782 | 105176 | return vacuumFinalize(db, pStmt, pzErrMsg); |
| 104783 | 105177 | } |
| 104784 | 105178 | |
| 104785 | 105179 | /* |
| 104786 | | -** The non-standard VACUUM command is used to clean up the database, |
| 105180 | +** The VACUUM command is used to clean up the database, |
| 104787 | 105181 | ** collapse free space, etc. It is modelled after the VACUUM command |
| 104788 | | -** in PostgreSQL. |
| 105182 | +** in PostgreSQL. The VACUUM command works as follows: |
| 104789 | 105183 | ** |
| 104790 | | -** In version 1.0.x of SQLite, the VACUUM command would call |
| 104791 | | -** gdbm_reorganize() on all the database tables. But beginning |
| 104792 | | -** with 2.0.0, SQLite no longer uses GDBM so this command has |
| 104793 | | -** become a no-op. |
| 105184 | +** (1) Create a new transient database file |
| 105185 | +** (2) Copy all content from the database being vacuumed into |
| 105186 | +** the new transient database file |
| 105187 | +** (3) Copy content from the transient database back into the |
| 105188 | +** original database. |
| 105189 | +** |
| 105190 | +** The transient database requires temporary disk space approximately |
| 105191 | +** equal to the size of the original database. The copy operation of |
| 105192 | +** step (3) requires additional temporary disk space approximately equal |
| 105193 | +** to the size of the original database for the rollback journal. |
| 105194 | +** Hence, temporary disk space that is approximately 2x the size of the |
| 105195 | +** orginal database is required. Every page of the database is written |
| 105196 | +** approximately 3 times: Once for step (2) and twice for step (3). |
| 105197 | +** Two writes per page are required in step (3) because the original |
| 105198 | +** database content must be written into the rollback journal prior to |
| 105199 | +** overwriting the database with the vacuumed content. |
| 105200 | +** |
| 105201 | +** Only 1x temporary space and only 1x writes would be required if |
| 105202 | +** the copy of step (3) were replace by deleting the original database |
| 105203 | +** and renaming the transient database as the original. But that will |
| 105204 | +** not work if other processes are attached to the original database. |
| 105205 | +** And a power loss in between deleting the original and renaming the |
| 105206 | +** transient would cause the database file to appear to be deleted |
| 105207 | +** following reboot. |
| 104794 | 105208 | */ |
| 104795 | 105209 | SQLITE_PRIVATE void sqlite3Vacuum(Parse *pParse){ |
| 104796 | 105210 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 104797 | 105211 | if( v ){ |
| 104798 | 105212 | sqlite3VdbeAddOp2(v, OP_Vacuum, 0, 0); |
| | @@ -106206,30 +106620,10 @@ |
| 106206 | 106620 | typedef struct WhereLoopBuilder WhereLoopBuilder; |
| 106207 | 106621 | typedef struct WhereScan WhereScan; |
| 106208 | 106622 | typedef struct WhereOrCost WhereOrCost; |
| 106209 | 106623 | typedef struct WhereOrSet WhereOrSet; |
| 106210 | 106624 | |
| 106211 | | -/* |
| 106212 | | -** Cost X is tracked as 10*log2(X) stored in a 16-bit integer. The |
| 106213 | | -** maximum cost for ordinary tables is 64*(2**63) which becomes 6900. |
| 106214 | | -** (Virtual tables can return a larger cost, but let's assume they do not.) |
| 106215 | | -** So all costs can be stored in a 16-bit integer without risk |
| 106216 | | -** of overflow. |
| 106217 | | -** |
| 106218 | | -** Costs are estimates, so no effort is made to compute 10*log2(X) exactly. |
| 106219 | | -** Instead, a close estimate is used. Any value of X=1 is stored as 0. |
| 106220 | | -** X=2 is 10. X=3 is 16. X=1000 is 99. etc. Negative values are allowed. |
| 106221 | | -** A WhereCost of -10 means 0.5. WhereCost of -20 means 0.25. And so forth. |
| 106222 | | -** |
| 106223 | | -** The tool/wherecosttest.c source file implements a command-line program |
| 106224 | | -** that will convert WhereCosts to integers, convert integers to WhereCosts |
| 106225 | | -** and do addition and multiplication on WhereCost values. The wherecosttest |
| 106226 | | -** command-line program is a useful utility to have around when working with |
| 106227 | | -** this module. |
| 106228 | | -*/ |
| 106229 | | -typedef short int WhereCost; |
| 106230 | | - |
| 106231 | 106625 | /* |
| 106232 | 106626 | ** This object contains information needed to implement a single nested |
| 106233 | 106627 | ** loop in WHERE clause. |
| 106234 | 106628 | ** |
| 106235 | 106629 | ** Contrast this object with WhereLoop. This object describes the |
| | @@ -106290,13 +106684,13 @@ |
| 106290 | 106684 | #ifdef SQLITE_DEBUG |
| 106291 | 106685 | char cId; /* Symbolic ID of this loop for debugging use */ |
| 106292 | 106686 | #endif |
| 106293 | 106687 | u8 iTab; /* Position in FROM clause of table for this loop */ |
| 106294 | 106688 | u8 iSortIdx; /* Sorting index number. 0==None */ |
| 106295 | | - WhereCost rSetup; /* One-time setup cost (ex: create transient index) */ |
| 106296 | | - WhereCost rRun; /* Cost of running each loop */ |
| 106297 | | - WhereCost nOut; /* Estimated number of output rows */ |
| 106689 | + LogEst rSetup; /* One-time setup cost (ex: create transient index) */ |
| 106690 | + LogEst rRun; /* Cost of running each loop */ |
| 106691 | + LogEst nOut; /* Estimated number of output rows */ |
| 106298 | 106692 | union { |
| 106299 | 106693 | struct { /* Information for internal btree tables */ |
| 106300 | 106694 | int nEq; /* Number of equality constraints */ |
| 106301 | 106695 | Index *pIndex; /* Index used, or NULL */ |
| 106302 | 106696 | } btree; |
| | @@ -106322,12 +106716,12 @@ |
| 106322 | 106716 | ** subquery on one operand of an OR operator in the WHERE clause. |
| 106323 | 106717 | ** See WhereOrSet for additional information |
| 106324 | 106718 | */ |
| 106325 | 106719 | struct WhereOrCost { |
| 106326 | 106720 | Bitmask prereq; /* Prerequisites */ |
| 106327 | | - WhereCost rRun; /* Cost of running this subquery */ |
| 106328 | | - WhereCost nOut; /* Number of outputs for this subquery */ |
| 106721 | + LogEst rRun; /* Cost of running this subquery */ |
| 106722 | + LogEst nOut; /* Number of outputs for this subquery */ |
| 106329 | 106723 | }; |
| 106330 | 106724 | |
| 106331 | 106725 | /* The WhereOrSet object holds a set of possible WhereOrCosts that |
| 106332 | 106726 | ** correspond to the subquery(s) of OR-clause processing. Only the |
| 106333 | 106727 | ** best N_OR_COST elements are retained. |
| | @@ -106361,12 +106755,12 @@ |
| 106361 | 106755 | ** at the end is the choosen query plan. |
| 106362 | 106756 | */ |
| 106363 | 106757 | struct WherePath { |
| 106364 | 106758 | Bitmask maskLoop; /* Bitmask of all WhereLoop objects in this path */ |
| 106365 | 106759 | Bitmask revLoop; /* aLoop[]s that should be reversed for ORDER BY */ |
| 106366 | | - WhereCost nRow; /* Estimated number of rows generated by this path */ |
| 106367 | | - WhereCost rCost; /* Total cost of this path */ |
| 106760 | + LogEst nRow; /* Estimated number of rows generated by this path */ |
| 106761 | + LogEst rCost; /* Total cost of this path */ |
| 106368 | 106762 | u8 isOrdered; /* True if this path satisfies ORDER BY */ |
| 106369 | 106763 | u8 isOrderedValid; /* True if the isOrdered field is valid */ |
| 106370 | 106764 | WhereLoop **aLoop; /* Array of WhereLoop objects implementing this path */ |
| 106371 | 106765 | }; |
| 106372 | 106766 | |
| | @@ -106428,11 +106822,11 @@ |
| 106428 | 106822 | union { |
| 106429 | 106823 | int leftColumn; /* Column number of X in "X <op> <expr>" */ |
| 106430 | 106824 | WhereOrInfo *pOrInfo; /* Extra information if (eOperator & WO_OR)!=0 */ |
| 106431 | 106825 | WhereAndInfo *pAndInfo; /* Extra information if (eOperator& WO_AND)!=0 */ |
| 106432 | 106826 | } u; |
| 106433 | | - WhereCost truthProb; /* Probability of truth for this expression */ |
| 106827 | + LogEst truthProb; /* Probability of truth for this expression */ |
| 106434 | 106828 | u16 eOperator; /* A WO_xx value describing <op> */ |
| 106435 | 106829 | u8 wtFlags; /* TERM_xxx bit flags. See below */ |
| 106436 | 106830 | u8 nChild; /* Number of children that must disable us */ |
| 106437 | 106831 | WhereClause *pWC; /* The clause this term is part of */ |
| 106438 | 106832 | Bitmask prereqRight; /* Bitmask of tables used by pExpr->pRight */ |
| | @@ -106576,11 +106970,11 @@ |
| 106576 | 106970 | SrcList *pTabList; /* List of tables in the join */ |
| 106577 | 106971 | ExprList *pOrderBy; /* The ORDER BY clause or NULL */ |
| 106578 | 106972 | ExprList *pResultSet; /* Result set. DISTINCT operates on these */ |
| 106579 | 106973 | WhereLoop *pLoops; /* List of all WhereLoop objects */ |
| 106580 | 106974 | Bitmask revMask; /* Mask of ORDER BY terms that need reversing */ |
| 106581 | | - WhereCost nRowOut; /* Estimated number of output rows */ |
| 106975 | + LogEst nRowOut; /* Estimated number of output rows */ |
| 106582 | 106976 | u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */ |
| 106583 | 106977 | u8 bOBSat; /* ORDER BY satisfied by indices */ |
| 106584 | 106978 | u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE/DELETE */ |
| 106585 | 106979 | u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */ |
| 106586 | 106980 | u8 eDistinct; /* One of the WHERE_DISTINCT_* values below */ |
| | @@ -106636,30 +107030,15 @@ |
| 106636 | 107030 | #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */ |
| 106637 | 107031 | #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */ |
| 106638 | 107032 | #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */ |
| 106639 | 107033 | #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */ |
| 106640 | 107034 | |
| 106641 | | - |
| 106642 | | -/* Convert a WhereCost value (10 times log2(X)) into its integer value X. |
| 106643 | | -** A rough approximation is used. The value returned is not exact. |
| 106644 | | -*/ |
| 106645 | | -static u64 whereCostToInt(WhereCost x){ |
| 106646 | | - u64 n; |
| 106647 | | - if( x<10 ) return 1; |
| 106648 | | - n = x%10; |
| 106649 | | - x /= 10; |
| 106650 | | - if( n>=5 ) n -= 2; |
| 106651 | | - else if( n>=1 ) n -= 1; |
| 106652 | | - if( x>=3 ) return (n+8)<<(x-3); |
| 106653 | | - return (n+8)>>(3-x); |
| 106654 | | -} |
| 106655 | | - |
| 106656 | 107035 | /* |
| 106657 | 107036 | ** Return the estimated number of output rows from a WHERE clause |
| 106658 | 107037 | */ |
| 106659 | 107038 | SQLITE_PRIVATE u64 sqlite3WhereOutputRowCount(WhereInfo *pWInfo){ |
| 106660 | | - return whereCostToInt(pWInfo->nRowOut); |
| 107039 | + return sqlite3LogEstToInt(pWInfo->nRowOut); |
| 106661 | 107040 | } |
| 106662 | 107041 | |
| 106663 | 107042 | /* |
| 106664 | 107043 | ** Return one of the WHERE_DISTINCT_xxxxx values to indicate how this |
| 106665 | 107044 | ** WHERE clause returns outputs for DISTINCT processing. |
| | @@ -106717,12 +107096,12 @@ |
| 106717 | 107096 | ** so that pSet keeps the N_OR_COST best entries seen so far. |
| 106718 | 107097 | */ |
| 106719 | 107098 | static int whereOrInsert( |
| 106720 | 107099 | WhereOrSet *pSet, /* The WhereOrSet to be updated */ |
| 106721 | 107100 | Bitmask prereq, /* Prerequisites of the new entry */ |
| 106722 | | - WhereCost rRun, /* Run-cost of the new entry */ |
| 106723 | | - WhereCost nOut /* Number of outputs for the new entry */ |
| 107101 | + LogEst rRun, /* Run-cost of the new entry */ |
| 107102 | + LogEst nOut /* Number of outputs for the new entry */ |
| 106724 | 107103 | ){ |
| 106725 | 107104 | u16 i; |
| 106726 | 107105 | WhereOrCost *p; |
| 106727 | 107106 | for(i=pSet->n, p=pSet->a; i>0; i--, p++){ |
| 106728 | 107107 | if( rRun<=p->rRun && (prereq & p->prereq)==prereq ){ |
| | @@ -106803,13 +107182,10 @@ |
| 106803 | 107182 | if( pWC->a!=pWC->aStatic ){ |
| 106804 | 107183 | sqlite3DbFree(db, pWC->a); |
| 106805 | 107184 | } |
| 106806 | 107185 | } |
| 106807 | 107186 | |
| 106808 | | -/* Forward declaration */ |
| 106809 | | -static WhereCost whereCost(tRowcnt x); |
| 106810 | | - |
| 106811 | 107187 | /* |
| 106812 | 107188 | ** Add a single new WhereTerm entry to the WhereClause object pWC. |
| 106813 | 107189 | ** The new WhereTerm object is constructed from Expr p and with wtFlags. |
| 106814 | 107190 | ** The index in pWC->a[] of the new WhereTerm is returned on success. |
| 106815 | 107191 | ** 0 is returned if the new WhereTerm could not be added due to a memory |
| | @@ -106848,11 +107224,11 @@ |
| 106848 | 107224 | } |
| 106849 | 107225 | pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]); |
| 106850 | 107226 | } |
| 106851 | 107227 | pTerm = &pWC->a[idx = pWC->nTerm++]; |
| 106852 | 107228 | if( p && ExprHasProperty(p, EP_Unlikely) ){ |
| 106853 | | - pTerm->truthProb = whereCost(p->iTable) - 99; |
| 107229 | + pTerm->truthProb = sqlite3LogEst(p->iTable) - 99; |
| 106854 | 107230 | }else{ |
| 106855 | 107231 | pTerm->truthProb = -1; |
| 106856 | 107232 | } |
| 106857 | 107233 | pTerm->pExpr = sqlite3ExprSkipCollate(p); |
| 106858 | 107234 | pTerm->wtFlags = wtFlags; |
| | @@ -108112,79 +108488,16 @@ |
| 108112 | 108488 | } |
| 108113 | 108489 | |
| 108114 | 108490 | return 0; |
| 108115 | 108491 | } |
| 108116 | 108492 | |
| 108117 | | -/* |
| 108118 | | -** Find (an approximate) sum of two WhereCosts. This computation is |
| 108119 | | -** not a simple "+" operator because WhereCost is stored as a logarithmic |
| 108120 | | -** value. |
| 108121 | | -** |
| 108122 | | -*/ |
| 108123 | | -static WhereCost whereCostAdd(WhereCost a, WhereCost b){ |
| 108124 | | - static const unsigned char x[] = { |
| 108125 | | - 10, 10, /* 0,1 */ |
| 108126 | | - 9, 9, /* 2,3 */ |
| 108127 | | - 8, 8, /* 4,5 */ |
| 108128 | | - 7, 7, 7, /* 6,7,8 */ |
| 108129 | | - 6, 6, 6, /* 9,10,11 */ |
| 108130 | | - 5, 5, 5, /* 12-14 */ |
| 108131 | | - 4, 4, 4, 4, /* 15-18 */ |
| 108132 | | - 3, 3, 3, 3, 3, 3, /* 19-24 */ |
| 108133 | | - 2, 2, 2, 2, 2, 2, 2, /* 25-31 */ |
| 108134 | | - }; |
| 108135 | | - if( a>=b ){ |
| 108136 | | - if( a>b+49 ) return a; |
| 108137 | | - if( a>b+31 ) return a+1; |
| 108138 | | - return a+x[a-b]; |
| 108139 | | - }else{ |
| 108140 | | - if( b>a+49 ) return b; |
| 108141 | | - if( b>a+31 ) return b+1; |
| 108142 | | - return b+x[b-a]; |
| 108143 | | - } |
| 108144 | | -} |
| 108145 | | - |
| 108146 | | -/* |
| 108147 | | -** Convert an integer into a WhereCost. In other words, compute a |
| 108148 | | -** good approximatation for 10*log2(x). |
| 108149 | | -*/ |
| 108150 | | -static WhereCost whereCost(tRowcnt x){ |
| 108151 | | - static WhereCost a[] = { 0, 2, 3, 5, 6, 7, 8, 9 }; |
| 108152 | | - WhereCost y = 40; |
| 108153 | | - if( x<8 ){ |
| 108154 | | - if( x<2 ) return 0; |
| 108155 | | - while( x<8 ){ y -= 10; x <<= 1; } |
| 108156 | | - }else{ |
| 108157 | | - while( x>255 ){ y += 40; x >>= 4; } |
| 108158 | | - while( x>15 ){ y += 10; x >>= 1; } |
| 108159 | | - } |
| 108160 | | - return a[x&7] + y - 10; |
| 108161 | | -} |
| 108162 | | - |
| 108163 | | -#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 108164 | | -/* |
| 108165 | | -** Convert a double (as received from xBestIndex of a virtual table) |
| 108166 | | -** into a WhereCost. In other words, compute an approximation for |
| 108167 | | -** 10*log2(x). |
| 108168 | | -*/ |
| 108169 | | -static WhereCost whereCostFromDouble(double x){ |
| 108170 | | - u64 a; |
| 108171 | | - WhereCost e; |
| 108172 | | - assert( sizeof(x)==8 && sizeof(a)==8 ); |
| 108173 | | - if( x<=1 ) return 0; |
| 108174 | | - if( x<=2000000000 ) return whereCost((tRowcnt)x); |
| 108175 | | - memcpy(&a, &x, 8); |
| 108176 | | - e = (a>>52) - 1022; |
| 108177 | | - return e*10; |
| 108178 | | -} |
| 108179 | | -#endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 108180 | 108493 | |
| 108181 | 108494 | /* |
| 108182 | 108495 | ** Estimate the logarithm of the input value to base 2. |
| 108183 | 108496 | */ |
| 108184 | | -static WhereCost estLog(WhereCost N){ |
| 108185 | | - WhereCost x = whereCost(N); |
| 108497 | +static LogEst estLog(LogEst N){ |
| 108498 | + LogEst x = sqlite3LogEst(N); |
| 108186 | 108499 | return x>33 ? x - 33 : 0; |
| 108187 | 108500 | } |
| 108188 | 108501 | |
| 108189 | 108502 | /* |
| 108190 | 108503 | ** Two routines for printing the content of an sqlite3_index_info |
| | @@ -108693,11 +109006,11 @@ |
| 108693 | 109006 | ** |
| 108694 | 109007 | ** ... FROM t1 WHERE a > ? AND a < ? ... |
| 108695 | 109008 | ** |
| 108696 | 109009 | ** then nEq is set to 0. |
| 108697 | 109010 | ** |
| 108698 | | -** When this function is called, *pnOut is set to the whereCost() of the |
| 109011 | +** When this function is called, *pnOut is set to the sqlite3LogEst() of the |
| 108699 | 109012 | ** number of rows that the index scan is expected to visit without |
| 108700 | 109013 | ** considering the range constraints. If nEq is 0, this is the number of |
| 108701 | 109014 | ** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced) |
| 108702 | 109015 | ** to account for the range contraints pLower and pUpper. |
| 108703 | 109016 | ** |
| | @@ -108709,19 +109022,19 @@ |
| 108709 | 109022 | static int whereRangeScanEst( |
| 108710 | 109023 | Parse *pParse, /* Parsing & code generating context */ |
| 108711 | 109024 | WhereLoopBuilder *pBuilder, |
| 108712 | 109025 | WhereTerm *pLower, /* Lower bound on the range. ex: "x>123" Might be NULL */ |
| 108713 | 109026 | WhereTerm *pUpper, /* Upper bound on the range. ex: "x<455" Might be NULL */ |
| 108714 | | - WhereCost *pnOut /* IN/OUT: Number of rows visited */ |
| 109027 | + WhereLoop *pLoop /* Modify the .nOut and maybe .rRun fields */ |
| 108715 | 109028 | ){ |
| 108716 | 109029 | int rc = SQLITE_OK; |
| 108717 | | - int nOut = (int)*pnOut; |
| 108718 | | - WhereCost nNew; |
| 109030 | + int nOut = pLoop->nOut; |
| 109031 | + int nEq = pLoop->u.btree.nEq; |
| 109032 | + LogEst nNew; |
| 108719 | 109033 | |
| 108720 | 109034 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 108721 | | - Index *p = pBuilder->pNew->u.btree.pIndex; |
| 108722 | | - int nEq = pBuilder->pNew->u.btree.nEq; |
| 109035 | + Index *p = pLoop->u.btree.pIndex; |
| 108723 | 109036 | |
| 108724 | 109037 | if( p->nSample>0 |
| 108725 | 109038 | && nEq==pBuilder->nRecValid |
| 108726 | 109039 | && nEq<p->nSampleCol |
| 108727 | 109040 | && OptimizationEnabled(pParse->db, SQLITE_Stat3) |
| | @@ -108798,18 +109111,18 @@ |
| 108798 | 109111 | } |
| 108799 | 109112 | |
| 108800 | 109113 | pBuilder->pRec = pRec; |
| 108801 | 109114 | if( rc==SQLITE_OK ){ |
| 108802 | 109115 | if( iUpper>iLower ){ |
| 108803 | | - nNew = whereCost(iUpper - iLower); |
| 109116 | + nNew = sqlite3LogEst(iUpper - iLower); |
| 108804 | 109117 | }else{ |
| 108805 | | - nNew = 10; assert( 10==whereCost(2) ); |
| 109118 | + nNew = 10; assert( 10==sqlite3LogEst(2) ); |
| 108806 | 109119 | } |
| 108807 | 109120 | if( nNew<nOut ){ |
| 108808 | 109121 | nOut = nNew; |
| 108809 | 109122 | } |
| 108810 | | - *pnOut = (WhereCost)nOut; |
| 109123 | + pLoop->nOut = (LogEst)nOut; |
| 108811 | 109124 | WHERETRACE(0x100, ("range scan regions: %u..%u est=%d\n", |
| 108812 | 109125 | (u32)iLower, (u32)iUpper, nOut)); |
| 108813 | 109126 | return SQLITE_OK; |
| 108814 | 109127 | } |
| 108815 | 109128 | } |
| | @@ -108820,20 +109133,20 @@ |
| 108820 | 109133 | assert( pLower || pUpper ); |
| 108821 | 109134 | /* TUNING: Each inequality constraint reduces the search space 4-fold. |
| 108822 | 109135 | ** A BETWEEN operator, therefore, reduces the search space 16-fold */ |
| 108823 | 109136 | nNew = nOut; |
| 108824 | 109137 | if( pLower && (pLower->wtFlags & TERM_VNULL)==0 ){ |
| 108825 | | - nNew -= 20; assert( 20==whereCost(4) ); |
| 109138 | + nNew -= 20; assert( 20==sqlite3LogEst(4) ); |
| 108826 | 109139 | nOut--; |
| 108827 | 109140 | } |
| 108828 | 109141 | if( pUpper ){ |
| 108829 | | - nNew -= 20; assert( 20==whereCost(4) ); |
| 109142 | + nNew -= 20; assert( 20==sqlite3LogEst(4) ); |
| 108830 | 109143 | nOut--; |
| 108831 | 109144 | } |
| 108832 | 109145 | if( nNew<10 ) nNew = 10; |
| 108833 | 109146 | if( nNew<nOut ) nOut = nNew; |
| 108834 | | - *pnOut = (WhereCost)nOut; |
| 109147 | + pLoop->nOut = (LogEst)nOut; |
| 108835 | 109148 | return rc; |
| 108836 | 109149 | } |
| 108837 | 109150 | |
| 108838 | 109151 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 108839 | 109152 | /* |
| | @@ -110473,11 +110786,11 @@ |
| 110473 | 110786 | */ |
| 110474 | 110787 | static int whereLoopAddBtreeIndex( |
| 110475 | 110788 | WhereLoopBuilder *pBuilder, /* The WhereLoop factory */ |
| 110476 | 110789 | struct SrcList_item *pSrc, /* FROM clause term being analyzed */ |
| 110477 | 110790 | Index *pProbe, /* An index on pSrc */ |
| 110478 | | - WhereCost nInMul /* log(Number of iterations due to IN) */ |
| 110791 | + LogEst nInMul /* log(Number of iterations due to IN) */ |
| 110479 | 110792 | ){ |
| 110480 | 110793 | WhereInfo *pWInfo = pBuilder->pWInfo; /* WHERE analyse context */ |
| 110481 | 110794 | Parse *pParse = pWInfo->pParse; /* Parsing context */ |
| 110482 | 110795 | sqlite3 *db = pParse->db; /* Database connection malloc context */ |
| 110483 | 110796 | WhereLoop *pNew; /* Template WhereLoop under construction */ |
| | @@ -110486,15 +110799,15 @@ |
| 110486 | 110799 | WhereScan scan; /* Iterator for WHERE terms */ |
| 110487 | 110800 | Bitmask saved_prereq; /* Original value of pNew->prereq */ |
| 110488 | 110801 | u16 saved_nLTerm; /* Original value of pNew->nLTerm */ |
| 110489 | 110802 | int saved_nEq; /* Original value of pNew->u.btree.nEq */ |
| 110490 | 110803 | u32 saved_wsFlags; /* Original value of pNew->wsFlags */ |
| 110491 | | - WhereCost saved_nOut; /* Original value of pNew->nOut */ |
| 110804 | + LogEst saved_nOut; /* Original value of pNew->nOut */ |
| 110492 | 110805 | int iCol; /* Index of the column in the table */ |
| 110493 | 110806 | int rc = SQLITE_OK; /* Return code */ |
| 110494 | | - WhereCost nRowEst; /* Estimated index selectivity */ |
| 110495 | | - WhereCost rLogSize; /* Logarithm of table size */ |
| 110807 | + LogEst nRowEst; /* Estimated index selectivity */ |
| 110808 | + LogEst rLogSize; /* Logarithm of table size */ |
| 110496 | 110809 | WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */ |
| 110497 | 110810 | |
| 110498 | 110811 | pNew = pBuilder->pNew; |
| 110499 | 110812 | if( db->mallocFailed ) return SQLITE_NOMEM; |
| 110500 | 110813 | |
| | @@ -110510,11 +110823,11 @@ |
| 110510 | 110823 | if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE); |
| 110511 | 110824 | |
| 110512 | 110825 | assert( pNew->u.btree.nEq<=pProbe->nColumn ); |
| 110513 | 110826 | if( pNew->u.btree.nEq < pProbe->nColumn ){ |
| 110514 | 110827 | iCol = pProbe->aiColumn[pNew->u.btree.nEq]; |
| 110515 | | - nRowEst = whereCost(pProbe->aiRowEst[pNew->u.btree.nEq+1]); |
| 110828 | + nRowEst = sqlite3LogEst(pProbe->aiRowEst[pNew->u.btree.nEq+1]); |
| 110516 | 110829 | if( nRowEst==0 && pProbe->onError==OE_None ) nRowEst = 1; |
| 110517 | 110830 | }else{ |
| 110518 | 110831 | iCol = -1; |
| 110519 | 110832 | nRowEst = 0; |
| 110520 | 110833 | } |
| | @@ -110524,11 +110837,11 @@ |
| 110524 | 110837 | saved_nLTerm = pNew->nLTerm; |
| 110525 | 110838 | saved_wsFlags = pNew->wsFlags; |
| 110526 | 110839 | saved_prereq = pNew->prereq; |
| 110527 | 110840 | saved_nOut = pNew->nOut; |
| 110528 | 110841 | pNew->rSetup = 0; |
| 110529 | | - rLogSize = estLog(whereCost(pProbe->aiRowEst[0])); |
| 110842 | + rLogSize = estLog(sqlite3LogEst(pProbe->aiRowEst[0])); |
| 110530 | 110843 | for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){ |
| 110531 | 110844 | int nIn = 0; |
| 110532 | 110845 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 110533 | 110846 | int nRecValid = pBuilder->nRecValid; |
| 110534 | 110847 | #endif |
| | @@ -110551,14 +110864,14 @@ |
| 110551 | 110864 | if( pTerm->eOperator & WO_IN ){ |
| 110552 | 110865 | Expr *pExpr = pTerm->pExpr; |
| 110553 | 110866 | pNew->wsFlags |= WHERE_COLUMN_IN; |
| 110554 | 110867 | if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 110555 | 110868 | /* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */ |
| 110556 | | - nIn = 46; assert( 46==whereCost(25) ); |
| 110869 | + nIn = 46; assert( 46==sqlite3LogEst(25) ); |
| 110557 | 110870 | }else if( ALWAYS(pExpr->x.pList && pExpr->x.pList->nExpr) ){ |
| 110558 | 110871 | /* "x IN (value, value, ...)" */ |
| 110559 | | - nIn = whereCost(pExpr->x.pList->nExpr); |
| 110872 | + nIn = sqlite3LogEst(pExpr->x.pList->nExpr); |
| 110560 | 110873 | } |
| 110561 | 110874 | pNew->rRun += nIn; |
| 110562 | 110875 | pNew->u.btree.nEq++; |
| 110563 | 110876 | pNew->nOut = nRowEst + nInMul + nIn; |
| 110564 | 110877 | }else if( pTerm->eOperator & (WO_EQ) ){ |
| | @@ -110576,11 +110889,11 @@ |
| 110576 | 110889 | pNew->nOut = nRowEst + nInMul; |
| 110577 | 110890 | }else if( pTerm->eOperator & (WO_ISNULL) ){ |
| 110578 | 110891 | pNew->wsFlags |= WHERE_COLUMN_NULL; |
| 110579 | 110892 | pNew->u.btree.nEq++; |
| 110580 | 110893 | /* TUNING: IS NULL selects 2 rows */ |
| 110581 | | - nIn = 10; assert( 10==whereCost(2) ); |
| 110894 | + nIn = 10; assert( 10==sqlite3LogEst(2) ); |
| 110582 | 110895 | pNew->nOut = nRowEst + nInMul + nIn; |
| 110583 | 110896 | }else if( pTerm->eOperator & (WO_GT|WO_GE) ){ |
| 110584 | 110897 | testcase( pTerm->eOperator & WO_GT ); |
| 110585 | 110898 | testcase( pTerm->eOperator & WO_GE ); |
| 110586 | 110899 | pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_BTM_LIMIT; |
| | @@ -110596,11 +110909,11 @@ |
| 110596 | 110909 | pNew->aLTerm[pNew->nLTerm-2] : 0; |
| 110597 | 110910 | } |
| 110598 | 110911 | if( pNew->wsFlags & WHERE_COLUMN_RANGE ){ |
| 110599 | 110912 | /* Adjust nOut and rRun for STAT3 range values */ |
| 110600 | 110913 | assert( pNew->nOut==saved_nOut ); |
| 110601 | | - whereRangeScanEst(pParse, pBuilder, pBtm, pTop, &pNew->nOut); |
| 110914 | + whereRangeScanEst(pParse, pBuilder, pBtm, pTop, pNew); |
| 110602 | 110915 | } |
| 110603 | 110916 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 110604 | 110917 | if( nInMul==0 |
| 110605 | 110918 | && pProbe->nSample |
| 110606 | 110919 | && pNew->u.btree.nEq<=pProbe->nSampleCol |
| | @@ -110616,22 +110929,22 @@ |
| 110616 | 110929 | && !ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 110617 | 110930 | rc = whereInScanEst(pParse, pBuilder, pExpr->x.pList, &nOut); |
| 110618 | 110931 | } |
| 110619 | 110932 | assert( nOut==0 || rc==SQLITE_OK ); |
| 110620 | 110933 | if( nOut ){ |
| 110621 | | - nOut = whereCost(nOut); |
| 110934 | + nOut = sqlite3LogEst(nOut); |
| 110622 | 110935 | pNew->nOut = MIN(nOut, saved_nOut); |
| 110623 | 110936 | } |
| 110624 | 110937 | } |
| 110625 | 110938 | #endif |
| 110626 | 110939 | if( (pNew->wsFlags & (WHERE_IDX_ONLY|WHERE_IPK))==0 ){ |
| 110627 | 110940 | /* Each row involves a step of the index, then a binary search of |
| 110628 | 110941 | ** the main table */ |
| 110629 | | - pNew->rRun = whereCostAdd(pNew->rRun, rLogSize>27 ? rLogSize-17 : 10); |
| 110942 | + pNew->rRun = sqlite3LogEstAdd(pNew->rRun,rLogSize>27 ? rLogSize-17 : 10); |
| 110630 | 110943 | } |
| 110631 | 110944 | /* Step cost for each output row */ |
| 110632 | | - pNew->rRun = whereCostAdd(pNew->rRun, pNew->nOut); |
| 110945 | + pNew->rRun = sqlite3LogEstAdd(pNew->rRun, pNew->nOut); |
| 110633 | 110946 | whereLoopOutputAdjust(pBuilder->pWC, pNew, pSrc->iCursor); |
| 110634 | 110947 | rc = whereLoopInsert(pBuilder, pNew); |
| 110635 | 110948 | if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 |
| 110636 | 110949 | && pNew->u.btree.nEq<(pProbe->nColumn + (pProbe->zName!=0)) |
| 110637 | 110950 | ){ |
| | @@ -110727,18 +111040,20 @@ |
| 110727 | 111040 | struct SrcList_item *pSrc; /* The FROM clause btree term to add */ |
| 110728 | 111041 | WhereLoop *pNew; /* Template WhereLoop object */ |
| 110729 | 111042 | int rc = SQLITE_OK; /* Return code */ |
| 110730 | 111043 | int iSortIdx = 1; /* Index number */ |
| 110731 | 111044 | int b; /* A boolean value */ |
| 110732 | | - WhereCost rSize; /* number of rows in the table */ |
| 110733 | | - WhereCost rLogSize; /* Logarithm of the number of rows in the table */ |
| 111045 | + LogEst rSize; /* number of rows in the table */ |
| 111046 | + LogEst rLogSize; /* Logarithm of the number of rows in the table */ |
| 110734 | 111047 | WhereClause *pWC; /* The parsed WHERE clause */ |
| 111048 | + Table *pTab; /* Table being queried */ |
| 110735 | 111049 | |
| 110736 | 111050 | pNew = pBuilder->pNew; |
| 110737 | 111051 | pWInfo = pBuilder->pWInfo; |
| 110738 | 111052 | pTabList = pWInfo->pTabList; |
| 110739 | 111053 | pSrc = pTabList->a + pNew->iTab; |
| 111054 | + pTab = pSrc->pTab; |
| 110740 | 111055 | pWC = pBuilder->pWC; |
| 110741 | 111056 | assert( !IsVirtual(pSrc->pTab) ); |
| 110742 | 111057 | |
| 110743 | 111058 | if( pSrc->pIndex ){ |
| 110744 | 111059 | /* An INDEXED BY clause specifies a particular index to use */ |
| | @@ -110752,22 +111067,22 @@ |
| 110752 | 111067 | memset(&sPk, 0, sizeof(Index)); |
| 110753 | 111068 | sPk.nColumn = 1; |
| 110754 | 111069 | sPk.aiColumn = &aiColumnPk; |
| 110755 | 111070 | sPk.aiRowEst = aiRowEstPk; |
| 110756 | 111071 | sPk.onError = OE_Replace; |
| 110757 | | - sPk.pTable = pSrc->pTab; |
| 110758 | | - aiRowEstPk[0] = pSrc->pTab->nRowEst; |
| 111072 | + sPk.pTable = pTab; |
| 111073 | + aiRowEstPk[0] = pTab->nRowEst; |
| 110759 | 111074 | aiRowEstPk[1] = 1; |
| 110760 | 111075 | pFirst = pSrc->pTab->pIndex; |
| 110761 | 111076 | if( pSrc->notIndexed==0 ){ |
| 110762 | 111077 | /* The real indices of the table are only considered if the |
| 110763 | 111078 | ** NOT INDEXED qualifier is omitted from the FROM clause */ |
| 110764 | 111079 | sPk.pNext = pFirst; |
| 110765 | 111080 | } |
| 110766 | 111081 | pProbe = &sPk; |
| 110767 | 111082 | } |
| 110768 | | - rSize = whereCost(pSrc->pTab->nRowEst); |
| 111083 | + rSize = sqlite3LogEst(pTab->nRowEst); |
| 110769 | 111084 | rLogSize = estLog(rSize); |
| 110770 | 111085 | |
| 110771 | 111086 | #ifndef SQLITE_OMIT_AUTOMATIC_INDEX |
| 110772 | 111087 | /* Automatic indexes */ |
| 110773 | 111088 | if( !pBuilder->pOrSet |
| | @@ -110788,17 +111103,17 @@ |
| 110788 | 111103 | pNew->nLTerm = 1; |
| 110789 | 111104 | pNew->aLTerm[0] = pTerm; |
| 110790 | 111105 | /* TUNING: One-time cost for computing the automatic index is |
| 110791 | 111106 | ** approximately 7*N*log2(N) where N is the number of rows in |
| 110792 | 111107 | ** the table being indexed. */ |
| 110793 | | - pNew->rSetup = rLogSize + rSize + 28; assert( 28==whereCost(7) ); |
| 111108 | + pNew->rSetup = rLogSize + rSize + 28; assert( 28==sqlite3LogEst(7) ); |
| 110794 | 111109 | /* TUNING: Each index lookup yields 20 rows in the table. This |
| 110795 | 111110 | ** is more than the usual guess of 10 rows, since we have no way |
| 110796 | 111111 | ** of knowning how selective the index will ultimately be. It would |
| 110797 | 111112 | ** not be unreasonable to make this value much larger. */ |
| 110798 | | - pNew->nOut = 43; assert( 43==whereCost(20) ); |
| 110799 | | - pNew->rRun = whereCostAdd(rLogSize,pNew->nOut); |
| 111113 | + pNew->nOut = 43; assert( 43==sqlite3LogEst(20) ); |
| 111114 | + pNew->rRun = sqlite3LogEstAdd(rLogSize,pNew->nOut); |
| 110800 | 111115 | pNew->wsFlags = WHERE_AUTO_INDEX; |
| 110801 | 111116 | pNew->prereq = mExtra | pTerm->prereqRight; |
| 110802 | 111117 | rc = whereLoopInsert(pBuilder, pNew); |
| 110803 | 111118 | } |
| 110804 | 111119 | } |
| | @@ -110828,14 +111143,12 @@ |
| 110828 | 111143 | |
| 110829 | 111144 | /* Full table scan */ |
| 110830 | 111145 | pNew->iSortIdx = b ? iSortIdx : 0; |
| 110831 | 111146 | /* TUNING: Cost of full table scan is 3*(N + log2(N)). |
| 110832 | 111147 | ** + The extra 3 factor is to encourage the use of indexed lookups |
| 110833 | | - ** over full scans. A smaller constant 2 is used for covering |
| 110834 | | - ** index scans so that a covering index scan will be favored over |
| 110835 | | - ** a table scan. */ |
| 110836 | | - pNew->rRun = whereCostAdd(rSize,rLogSize) + 16; |
| 111148 | + ** over full scans. FIXME */ |
| 111149 | + pNew->rRun = sqlite3LogEstAdd(rSize,rLogSize) + 16; |
| 110837 | 111150 | whereLoopOutputAdjust(pWC, pNew, pSrc->iCursor); |
| 110838 | 111151 | rc = whereLoopInsert(pBuilder, pNew); |
| 110839 | 111152 | pNew->nOut = rSize; |
| 110840 | 111153 | if( rc ) break; |
| 110841 | 111154 | }else{ |
| | @@ -110844,26 +111157,25 @@ |
| 110844 | 111157 | |
| 110845 | 111158 | /* Full scan via index */ |
| 110846 | 111159 | if( b |
| 110847 | 111160 | || ( m==0 |
| 110848 | 111161 | && pProbe->bUnordered==0 |
| 111162 | + && pProbe->szIdxRow<pTab->szTabRow |
| 110849 | 111163 | && (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 |
| 110850 | 111164 | && sqlite3GlobalConfig.bUseCis |
| 110851 | 111165 | && OptimizationEnabled(pWInfo->pParse->db, SQLITE_CoverIdxScan) |
| 110852 | 111166 | ) |
| 110853 | 111167 | ){ |
| 110854 | 111168 | pNew->iSortIdx = b ? iSortIdx : 0; |
| 110855 | 111169 | if( m==0 ){ |
| 110856 | | - /* TUNING: Cost of a covering index scan is 2*(N + log2(N)). |
| 110857 | | - ** + The extra 2 factor is to encourage the use of indexed lookups |
| 110858 | | - ** over index scans. A table scan uses a factor of 3 so that |
| 110859 | | - ** index scans are favored over table scans. |
| 110860 | | - ** + If this covering index might also help satisfy the ORDER BY |
| 110861 | | - ** clause, then the cost is fudged down slightly so that this |
| 110862 | | - ** index is favored above other indices that have no hope of |
| 110863 | | - ** helping with the ORDER BY. */ |
| 110864 | | - pNew->rRun = 10 + whereCostAdd(rSize,rLogSize) - b; |
| 111170 | + /* TUNING: Cost of a covering index scan is K*(N + log2(N)). |
| 111171 | + ** + The extra factor K of between 1.1 and 3.0 that depends |
| 111172 | + ** on the relative sizes of the table and the index. K |
| 111173 | + ** is smaller for smaller indices, thus favoring them. |
| 111174 | + */ |
| 111175 | + pNew->rRun = sqlite3LogEstAdd(rSize,rLogSize) + 1 + |
| 111176 | + (15*pProbe->szIdxRow)/pTab->szTabRow; |
| 110865 | 111177 | }else{ |
| 110866 | 111178 | assert( b!=0 ); |
| 110867 | 111179 | /* TUNING: Cost of scanning a non-covering index is (N+1)*log2(N) |
| 110868 | 111180 | ** which we will simplify to just N*log2(N) */ |
| 110869 | 111181 | pNew->rRun = rSize + rLogSize; |
| | @@ -111037,13 +111349,13 @@ |
| 111037 | 111349 | pIdxInfo->needToFreeIdxStr = 0; |
| 111038 | 111350 | pNew->u.vtab.idxStr = pIdxInfo->idxStr; |
| 111039 | 111351 | pNew->u.vtab.isOrdered = (u8)((pIdxInfo->nOrderBy!=0) |
| 111040 | 111352 | && pIdxInfo->orderByConsumed); |
| 111041 | 111353 | pNew->rSetup = 0; |
| 111042 | | - pNew->rRun = whereCostFromDouble(pIdxInfo->estimatedCost); |
| 111354 | + pNew->rRun = sqlite3LogEstFromDouble(pIdxInfo->estimatedCost); |
| 111043 | 111355 | /* TUNING: Every virtual table query returns 25 rows */ |
| 111044 | | - pNew->nOut = 46; assert( 46==whereCost(25) ); |
| 111356 | + pNew->nOut = 46; assert( 46==sqlite3LogEst(25) ); |
| 111045 | 111357 | whereLoopInsert(pBuilder, pNew); |
| 111046 | 111358 | if( pNew->u.vtab.needFree ){ |
| 111047 | 111359 | sqlite3_free(pNew->u.vtab.idxStr); |
| 111048 | 111360 | pNew->u.vtab.needFree = 0; |
| 111049 | 111361 | } |
| | @@ -111076,10 +111388,12 @@ |
| 111076 | 111388 | pWC = pBuilder->pWC; |
| 111077 | 111389 | if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK; |
| 111078 | 111390 | pWCEnd = pWC->a + pWC->nTerm; |
| 111079 | 111391 | pNew = pBuilder->pNew; |
| 111080 | 111392 | memset(&sSum, 0, sizeof(sSum)); |
| 111393 | + pItem = pWInfo->pTabList->a + pNew->iTab; |
| 111394 | + iCur = pItem->iCursor; |
| 111081 | 111395 | |
| 111082 | 111396 | for(pTerm=pWC->a; pTerm<pWCEnd && rc==SQLITE_OK; pTerm++){ |
| 111083 | 111397 | if( (pTerm->eOperator & WO_OR)!=0 |
| 111084 | 111398 | && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0 |
| 111085 | 111399 | ){ |
| | @@ -111087,12 +111401,10 @@ |
| 111087 | 111401 | WhereTerm * const pOrWCEnd = &pOrWC->a[pOrWC->nTerm]; |
| 111088 | 111402 | WhereTerm *pOrTerm; |
| 111089 | 111403 | int once = 1; |
| 111090 | 111404 | int i, j; |
| 111091 | 111405 | |
| 111092 | | - pItem = pWInfo->pTabList->a + pNew->iTab; |
| 111093 | | - iCur = pItem->iCursor; |
| 111094 | 111406 | sSubBuild = *pBuilder; |
| 111095 | 111407 | sSubBuild.pOrderBy = 0; |
| 111096 | 111408 | sSubBuild.pOrSet = &sCur; |
| 111097 | 111409 | |
| 111098 | 111410 | for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){ |
| | @@ -111129,12 +111441,12 @@ |
| 111129 | 111441 | whereOrMove(&sPrev, &sSum); |
| 111130 | 111442 | sSum.n = 0; |
| 111131 | 111443 | for(i=0; i<sPrev.n; i++){ |
| 111132 | 111444 | for(j=0; j<sCur.n; j++){ |
| 111133 | 111445 | whereOrInsert(&sSum, sPrev.a[i].prereq | sCur.a[j].prereq, |
| 111134 | | - whereCostAdd(sPrev.a[i].rRun, sCur.a[j].rRun), |
| 111135 | | - whereCostAdd(sPrev.a[i].nOut, sCur.a[j].nOut)); |
| 111446 | + sqlite3LogEstAdd(sPrev.a[i].rRun, sCur.a[j].rRun), |
| 111447 | + sqlite3LogEstAdd(sPrev.a[i].nOut, sCur.a[j].nOut)); |
| 111136 | 111448 | } |
| 111137 | 111449 | } |
| 111138 | 111450 | } |
| 111139 | 111451 | } |
| 111140 | 111452 | pNew->nLTerm = 1; |
| | @@ -111468,23 +111780,23 @@ |
| 111468 | 111780 | ** costs if nRowEst==0. |
| 111469 | 111781 | ** |
| 111470 | 111782 | ** Return SQLITE_OK on success or SQLITE_NOMEM of a memory allocation |
| 111471 | 111783 | ** error occurs. |
| 111472 | 111784 | */ |
| 111473 | | -static int wherePathSolver(WhereInfo *pWInfo, WhereCost nRowEst){ |
| 111785 | +static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ |
| 111474 | 111786 | int mxChoice; /* Maximum number of simultaneous paths tracked */ |
| 111475 | 111787 | int nLoop; /* Number of terms in the join */ |
| 111476 | 111788 | Parse *pParse; /* Parsing context */ |
| 111477 | 111789 | sqlite3 *db; /* The database connection */ |
| 111478 | 111790 | int iLoop; /* Loop counter over the terms of the join */ |
| 111479 | 111791 | int ii, jj; /* Loop counters */ |
| 111480 | 111792 | int mxI = 0; /* Index of next entry to replace */ |
| 111481 | | - WhereCost rCost; /* Cost of a path */ |
| 111482 | | - WhereCost nOut; /* Number of outputs */ |
| 111483 | | - WhereCost mxCost = 0; /* Maximum cost of a set of paths */ |
| 111484 | | - WhereCost mxOut = 0; /* Maximum nOut value on the set of paths */ |
| 111485 | | - WhereCost rSortCost; /* Cost to do a sort */ |
| 111793 | + LogEst rCost; /* Cost of a path */ |
| 111794 | + LogEst nOut; /* Number of outputs */ |
| 111795 | + LogEst mxCost = 0; /* Maximum cost of a set of paths */ |
| 111796 | + LogEst mxOut = 0; /* Maximum nOut value on the set of paths */ |
| 111797 | + LogEst rSortCost; /* Cost to do a sort */ |
| 111486 | 111798 | int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */ |
| 111487 | 111799 | WherePath *aFrom; /* All nFrom paths at the previous level */ |
| 111488 | 111800 | WherePath *aTo; /* The nTo best paths at the current level */ |
| 111489 | 111801 | WherePath *pFrom; /* An element of aFrom[] that we are working on */ |
| 111490 | 111802 | WherePath *pTo; /* An element of aTo[] that we are working on */ |
| | @@ -111517,21 +111829,23 @@ |
| 111517 | 111829 | /* Seed the search with a single WherePath containing zero WhereLoops. |
| 111518 | 111830 | ** |
| 111519 | 111831 | ** TUNING: Do not let the number of iterations go above 25. If the cost |
| 111520 | 111832 | ** of computing an automatic index is not paid back within the first 25 |
| 111521 | 111833 | ** rows, then do not use the automatic index. */ |
| 111522 | | - aFrom[0].nRow = MIN(pParse->nQueryLoop, 46); assert( 46==whereCost(25) ); |
| 111834 | + aFrom[0].nRow = MIN(pParse->nQueryLoop, 46); assert( 46==sqlite3LogEst(25) ); |
| 111523 | 111835 | nFrom = 1; |
| 111524 | 111836 | |
| 111525 | 111837 | /* Precompute the cost of sorting the final result set, if the caller |
| 111526 | 111838 | ** to sqlite3WhereBegin() was concerned about sorting */ |
| 111527 | 111839 | rSortCost = 0; |
| 111528 | 111840 | if( pWInfo->pOrderBy==0 || nRowEst==0 ){ |
| 111529 | 111841 | aFrom[0].isOrderedValid = 1; |
| 111530 | 111842 | }else{ |
| 111531 | | - /* TUNING: Estimated cost of sorting is N*log2(N) where N is the |
| 111532 | | - ** number of output rows. */ |
| 111843 | + /* TUNING: Estimated cost of sorting is 48*N*log2(N) where N is the |
| 111844 | + ** number of output rows. The 48 is the expected size of a row to sort. |
| 111845 | + ** FIXME: compute a better estimate of the 48 multiplier based on the |
| 111846 | + ** result set expressions. */ |
| 111533 | 111847 | rSortCost = nRowEst + estLog(nRowEst); |
| 111534 | 111848 | WHERETRACE(0x002,("---- sort cost=%-3d\n", rSortCost)); |
| 111535 | 111849 | } |
| 111536 | 111850 | |
| 111537 | 111851 | /* Compute successively longer WherePaths using the previous generation |
| | @@ -111547,12 +111861,12 @@ |
| 111547 | 111861 | u8 isOrdered = pFrom->isOrdered; |
| 111548 | 111862 | if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue; |
| 111549 | 111863 | if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue; |
| 111550 | 111864 | /* At this point, pWLoop is a candidate to be the next loop. |
| 111551 | 111865 | ** Compute its cost */ |
| 111552 | | - rCost = whereCostAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow); |
| 111553 | | - rCost = whereCostAdd(rCost, pFrom->rCost); |
| 111866 | + rCost = sqlite3LogEstAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow); |
| 111867 | + rCost = sqlite3LogEstAdd(rCost, pFrom->rCost); |
| 111554 | 111868 | nOut = pFrom->nRow + pWLoop->nOut; |
| 111555 | 111869 | maskNew = pFrom->maskLoop | pWLoop->maskSelf; |
| 111556 | 111870 | if( !isOrderedValid ){ |
| 111557 | 111871 | switch( wherePathSatisfiesOrderBy(pWInfo, |
| 111558 | 111872 | pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags, |
| | @@ -111562,11 +111876,11 @@ |
| 111562 | 111876 | isOrderedValid = 1; |
| 111563 | 111877 | break; |
| 111564 | 111878 | case 0: /* No. pFrom+pWLoop will require a separate sort */ |
| 111565 | 111879 | isOrdered = 0; |
| 111566 | 111880 | isOrderedValid = 1; |
| 111567 | | - rCost = whereCostAdd(rCost, rSortCost); |
| 111881 | + rCost = sqlite3LogEstAdd(rCost, rSortCost); |
| 111568 | 111882 | break; |
| 111569 | 111883 | default: /* Cannot tell yet. Try again on the next iteration */ |
| 111570 | 111884 | break; |
| 111571 | 111885 | } |
| 111572 | 111886 | }else{ |
| | @@ -111769,11 +112083,11 @@ |
| 111769 | 112083 | pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW; |
| 111770 | 112084 | pLoop->aLTerm[0] = pTerm; |
| 111771 | 112085 | pLoop->nLTerm = 1; |
| 111772 | 112086 | pLoop->u.btree.nEq = 1; |
| 111773 | 112087 | /* TUNING: Cost of a rowid lookup is 10 */ |
| 111774 | | - pLoop->rRun = 33; /* 33==whereCost(10) */ |
| 112088 | + pLoop->rRun = 33; /* 33==sqlite3LogEst(10) */ |
| 111775 | 112089 | }else{ |
| 111776 | 112090 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 111777 | 112091 | assert( pLoop->aLTermSpace==pLoop->aLTerm ); |
| 111778 | 112092 | assert( ArraySize(pLoop->aLTermSpace)==4 ); |
| 111779 | 112093 | if( pIdx->onError==OE_None |
| | @@ -111792,16 +112106,16 @@ |
| 111792 | 112106 | } |
| 111793 | 112107 | pLoop->nLTerm = j; |
| 111794 | 112108 | pLoop->u.btree.nEq = j; |
| 111795 | 112109 | pLoop->u.btree.pIndex = pIdx; |
| 111796 | 112110 | /* TUNING: Cost of a unique index lookup is 15 */ |
| 111797 | | - pLoop->rRun = 39; /* 39==whereCost(15) */ |
| 112111 | + pLoop->rRun = 39; /* 39==sqlite3LogEst(15) */ |
| 111798 | 112112 | break; |
| 111799 | 112113 | } |
| 111800 | 112114 | } |
| 111801 | 112115 | if( pLoop->wsFlags ){ |
| 111802 | | - pLoop->nOut = (WhereCost)1; |
| 112116 | + pLoop->nOut = (LogEst)1; |
| 111803 | 112117 | pWInfo->a[0].pWLoop = pLoop; |
| 111804 | 112118 | pLoop->maskSelf = getMask(&pWInfo->sMaskSet, iCur); |
| 111805 | 112119 | pWInfo->a[0].iTabCur = iCur; |
| 111806 | 112120 | pWInfo->nRowOut = 1; |
| 111807 | 112121 | if( pWInfo->pOrderBy ) pWInfo->bOBSat = 1; |
| | @@ -112165,11 +112479,11 @@ |
| 112165 | 112479 | WHERETRACE(0xffff,("*** Optimizer Finished ***\n")); |
| 112166 | 112480 | pWInfo->pParse->nQueryLoop += pWInfo->nRowOut; |
| 112167 | 112481 | |
| 112168 | 112482 | /* If the caller is an UPDATE or DELETE statement that is requesting |
| 112169 | 112483 | ** to use a one-pass algorithm, determine if this is appropriate. |
| 112170 | | - ** The one-pass algorithm only works if the WHERE clause constraints |
| 112484 | + ** The one-pass algorithm only works if the WHERE clause constrains |
| 112171 | 112485 | ** the statement to update a single row. |
| 112172 | 112486 | */ |
| 112173 | 112487 | assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 ); |
| 112174 | 112488 | if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 |
| 112175 | 112489 | && (pWInfo->a[0].pWLoop->wsFlags & WHERE_ONEROW)!=0 ){ |
| | @@ -121583,10 +121897,16 @@ |
| 121583 | 121897 | ** verifying the operation of the SQLite core. |
| 121584 | 121898 | */ |
| 121585 | 121899 | int inTransaction; /* True after xBegin but before xCommit/xRollback */ |
| 121586 | 121900 | int mxSavepoint; /* Largest valid xSavepoint integer */ |
| 121587 | 121901 | #endif |
| 121902 | + |
| 121903 | +#ifdef SQLITE_TEST |
| 121904 | + /* True to disable the incremental doclist optimization. This is controled |
| 121905 | + ** by special insert command 'test-no-incr-doclist'. */ |
| 121906 | + int bNoIncrDoclist; |
| 121907 | +#endif |
| 121588 | 121908 | }; |
| 121589 | 121909 | |
| 121590 | 121910 | /* |
| 121591 | 121911 | ** When the core wants to read from the virtual table, it creates a |
| 121592 | 121912 | ** virtual table cursor (an instance of the following structure) using |
| | @@ -121608,11 +121928,12 @@ |
| 121608 | 121928 | int nDoclist; /* Size of buffer at aDoclist */ |
| 121609 | 121929 | u8 bDesc; /* True to sort in descending order */ |
| 121610 | 121930 | int eEvalmode; /* An FTS3_EVAL_XX constant */ |
| 121611 | 121931 | int nRowAvg; /* Average size of database rows, in pages */ |
| 121612 | 121932 | sqlite3_int64 nDoc; /* Documents in table */ |
| 121613 | | - |
| 121933 | + i64 iMinDocid; /* Minimum docid to return */ |
| 121934 | + i64 iMaxDocid; /* Maximum docid to return */ |
| 121614 | 121935 | int isMatchinfoNeeded; /* True when aMatchinfo[] needs filling in */ |
| 121615 | 121936 | u32 *aMatchinfo; /* Information about most recent match */ |
| 121616 | 121937 | int nMatchinfo; /* Number of elements in aMatchinfo[] */ |
| 121617 | 121938 | char *zMatchinfo; /* Matchinfo specification */ |
| 121618 | 121939 | }; |
| | @@ -121638,10 +121959,19 @@ |
| 121638 | 121959 | */ |
| 121639 | 121960 | #define FTS3_FULLSCAN_SEARCH 0 /* Linear scan of %_content table */ |
| 121640 | 121961 | #define FTS3_DOCID_SEARCH 1 /* Lookup by rowid on %_content table */ |
| 121641 | 121962 | #define FTS3_FULLTEXT_SEARCH 2 /* Full-text index search */ |
| 121642 | 121963 | |
| 121964 | +/* |
| 121965 | +** The lower 16-bits of the sqlite3_index_info.idxNum value set by |
| 121966 | +** the xBestIndex() method contains the Fts3Cursor.eSearch value described |
| 121967 | +** above. The upper 16-bits contain a combination of the following |
| 121968 | +** bits, used to describe extra constraints on full-text searches. |
| 121969 | +*/ |
| 121970 | +#define FTS3_HAVE_LANGID 0x00010000 /* languageid=? */ |
| 121971 | +#define FTS3_HAVE_DOCID_GE 0x00020000 /* docid>=? */ |
| 121972 | +#define FTS3_HAVE_DOCID_LE 0x00040000 /* docid<=? */ |
| 121643 | 121973 | |
| 121644 | 121974 | struct Fts3Doclist { |
| 121645 | 121975 | char *aAll; /* Array containing doclist (or NULL) */ |
| 121646 | 121976 | int nAll; /* Size of a[] in bytes */ |
| 121647 | 121977 | char *pNextDocid; /* Pointer to next docid */ |
| | @@ -123058,27 +123388,31 @@ |
| 123058 | 123388 | */ |
| 123059 | 123389 | static int fts3BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){ |
| 123060 | 123390 | Fts3Table *p = (Fts3Table *)pVTab; |
| 123061 | 123391 | int i; /* Iterator variable */ |
| 123062 | 123392 | int iCons = -1; /* Index of constraint to use */ |
| 123393 | + |
| 123063 | 123394 | int iLangidCons = -1; /* Index of langid=x constraint, if present */ |
| 123395 | + int iDocidGe = -1; /* Index of docid>=x constraint, if present */ |
| 123396 | + int iDocidLe = -1; /* Index of docid<=x constraint, if present */ |
| 123397 | + int iIdx; |
| 123064 | 123398 | |
| 123065 | 123399 | /* By default use a full table scan. This is an expensive option, |
| 123066 | 123400 | ** so search through the constraints to see if a more efficient |
| 123067 | 123401 | ** strategy is possible. |
| 123068 | 123402 | */ |
| 123069 | 123403 | pInfo->idxNum = FTS3_FULLSCAN_SEARCH; |
| 123070 | 123404 | pInfo->estimatedCost = 5000000; |
| 123071 | 123405 | for(i=0; i<pInfo->nConstraint; i++){ |
| 123406 | + int bDocid; /* True if this constraint is on docid */ |
| 123072 | 123407 | struct sqlite3_index_constraint *pCons = &pInfo->aConstraint[i]; |
| 123073 | 123408 | if( pCons->usable==0 ) continue; |
| 123409 | + |
| 123410 | + bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1); |
| 123074 | 123411 | |
| 123075 | 123412 | /* A direct lookup on the rowid or docid column. Assign a cost of 1.0. */ |
| 123076 | | - if( iCons<0 |
| 123077 | | - && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ |
| 123078 | | - && (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1 ) |
| 123079 | | - ){ |
| 123413 | + if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){ |
| 123080 | 123414 | pInfo->idxNum = FTS3_DOCID_SEARCH; |
| 123081 | 123415 | pInfo->estimatedCost = 1.0; |
| 123082 | 123416 | iCons = i; |
| 123083 | 123417 | } |
| 123084 | 123418 | |
| | @@ -123103,18 +123437,42 @@ |
| 123103 | 123437 | if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ |
| 123104 | 123438 | && pCons->iColumn==p->nColumn + 2 |
| 123105 | 123439 | ){ |
| 123106 | 123440 | iLangidCons = i; |
| 123107 | 123441 | } |
| 123442 | + |
| 123443 | + if( bDocid ){ |
| 123444 | + switch( pCons->op ){ |
| 123445 | + case SQLITE_INDEX_CONSTRAINT_GE: |
| 123446 | + case SQLITE_INDEX_CONSTRAINT_GT: |
| 123447 | + iDocidGe = i; |
| 123448 | + break; |
| 123449 | + |
| 123450 | + case SQLITE_INDEX_CONSTRAINT_LE: |
| 123451 | + case SQLITE_INDEX_CONSTRAINT_LT: |
| 123452 | + iDocidLe = i; |
| 123453 | + break; |
| 123454 | + } |
| 123455 | + } |
| 123108 | 123456 | } |
| 123109 | 123457 | |
| 123458 | + iIdx = 1; |
| 123110 | 123459 | if( iCons>=0 ){ |
| 123111 | | - pInfo->aConstraintUsage[iCons].argvIndex = 1; |
| 123460 | + pInfo->aConstraintUsage[iCons].argvIndex = iIdx++; |
| 123112 | 123461 | pInfo->aConstraintUsage[iCons].omit = 1; |
| 123113 | 123462 | } |
| 123114 | 123463 | if( iLangidCons>=0 ){ |
| 123115 | | - pInfo->aConstraintUsage[iLangidCons].argvIndex = 2; |
| 123464 | + pInfo->idxNum |= FTS3_HAVE_LANGID; |
| 123465 | + pInfo->aConstraintUsage[iLangidCons].argvIndex = iIdx++; |
| 123466 | + } |
| 123467 | + if( iDocidGe>=0 ){ |
| 123468 | + pInfo->idxNum |= FTS3_HAVE_DOCID_GE; |
| 123469 | + pInfo->aConstraintUsage[iDocidGe].argvIndex = iIdx++; |
| 123470 | + } |
| 123471 | + if( iDocidLe>=0 ){ |
| 123472 | + pInfo->idxNum |= FTS3_HAVE_DOCID_LE; |
| 123473 | + pInfo->aConstraintUsage[iDocidLe].argvIndex = iIdx++; |
| 123116 | 123474 | } |
| 123117 | 123475 | |
| 123118 | 123476 | /* Regardless of the strategy selected, FTS can deliver rows in rowid (or |
| 123119 | 123477 | ** docid) order. Both ascending and descending are possible. |
| 123120 | 123478 | */ |
| | @@ -124556,10 +124914,37 @@ |
| 124556 | 124914 | rc = fts3EvalNext((Fts3Cursor *)pCursor); |
| 124557 | 124915 | } |
| 124558 | 124916 | assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 ); |
| 124559 | 124917 | return rc; |
| 124560 | 124918 | } |
| 124919 | + |
| 124920 | +/* |
| 124921 | +** The following are copied from sqliteInt.h. |
| 124922 | +** |
| 124923 | +** Constants for the largest and smallest possible 64-bit signed integers. |
| 124924 | +** These macros are designed to work correctly on both 32-bit and 64-bit |
| 124925 | +** compilers. |
| 124926 | +*/ |
| 124927 | +#ifndef SQLITE_AMALGAMATION |
| 124928 | +# define LARGEST_INT64 (0xffffffff|(((sqlite3_int64)0x7fffffff)<<32)) |
| 124929 | +# define SMALLEST_INT64 (((sqlite3_int64)-1) - LARGEST_INT64) |
| 124930 | +#endif |
| 124931 | + |
| 124932 | +/* |
| 124933 | +** If the numeric type of argument pVal is "integer", then return it |
| 124934 | +** converted to a 64-bit signed integer. Otherwise, return a copy of |
| 124935 | +** the second parameter, iDefault. |
| 124936 | +*/ |
| 124937 | +static sqlite3_int64 fts3DocidRange(sqlite3_value *pVal, i64 iDefault){ |
| 124938 | + if( pVal ){ |
| 124939 | + int eType = sqlite3_value_numeric_type(pVal); |
| 124940 | + if( eType==SQLITE_INTEGER ){ |
| 124941 | + return sqlite3_value_int64(pVal); |
| 124942 | + } |
| 124943 | + } |
| 124944 | + return iDefault; |
| 124945 | +} |
| 124561 | 124946 | |
| 124562 | 124947 | /* |
| 124563 | 124948 | ** This is the xFilter interface for the virtual table. See |
| 124564 | 124949 | ** the virtual table xFilter method documentation for additional |
| 124565 | 124950 | ** information. |
| | @@ -124582,44 +124967,62 @@ |
| 124582 | 124967 | int nVal, /* Number of elements in apVal */ |
| 124583 | 124968 | sqlite3_value **apVal /* Arguments for the indexing scheme */ |
| 124584 | 124969 | ){ |
| 124585 | 124970 | int rc; |
| 124586 | 124971 | char *zSql; /* SQL statement used to access %_content */ |
| 124972 | + int eSearch; |
| 124587 | 124973 | Fts3Table *p = (Fts3Table *)pCursor->pVtab; |
| 124588 | 124974 | Fts3Cursor *pCsr = (Fts3Cursor *)pCursor; |
| 124975 | + |
| 124976 | + sqlite3_value *pCons = 0; /* The MATCH or rowid constraint, if any */ |
| 124977 | + sqlite3_value *pLangid = 0; /* The "langid = ?" constraint, if any */ |
| 124978 | + sqlite3_value *pDocidGe = 0; /* The "docid >= ?" constraint, if any */ |
| 124979 | + sqlite3_value *pDocidLe = 0; /* The "docid <= ?" constraint, if any */ |
| 124980 | + int iIdx; |
| 124589 | 124981 | |
| 124590 | 124982 | UNUSED_PARAMETER(idxStr); |
| 124591 | 124983 | UNUSED_PARAMETER(nVal); |
| 124592 | 124984 | |
| 124593 | | - assert( idxNum>=0 && idxNum<=(FTS3_FULLTEXT_SEARCH+p->nColumn) ); |
| 124594 | | - assert( nVal==0 || nVal==1 || nVal==2 ); |
| 124595 | | - assert( (nVal==0)==(idxNum==FTS3_FULLSCAN_SEARCH) ); |
| 124985 | + eSearch = (idxNum & 0x0000FFFF); |
| 124986 | + assert( eSearch>=0 && eSearch<=(FTS3_FULLTEXT_SEARCH+p->nColumn) ); |
| 124596 | 124987 | assert( p->pSegments==0 ); |
| 124988 | + |
| 124989 | + /* Collect arguments into local variables */ |
| 124990 | + iIdx = 0; |
| 124991 | + if( eSearch!=FTS3_FULLSCAN_SEARCH ) pCons = apVal[iIdx++]; |
| 124992 | + if( idxNum & FTS3_HAVE_LANGID ) pLangid = apVal[iIdx++]; |
| 124993 | + if( idxNum & FTS3_HAVE_DOCID_GE ) pDocidGe = apVal[iIdx++]; |
| 124994 | + if( idxNum & FTS3_HAVE_DOCID_LE ) pDocidLe = apVal[iIdx++]; |
| 124995 | + assert( iIdx==nVal ); |
| 124597 | 124996 | |
| 124598 | 124997 | /* In case the cursor has been used before, clear it now. */ |
| 124599 | 124998 | sqlite3_finalize(pCsr->pStmt); |
| 124600 | 124999 | sqlite3_free(pCsr->aDoclist); |
| 124601 | 125000 | sqlite3Fts3ExprFree(pCsr->pExpr); |
| 124602 | 125001 | memset(&pCursor[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor)); |
| 124603 | 125002 | |
| 125003 | + /* Set the lower and upper bounds on docids to return */ |
| 125004 | + pCsr->iMinDocid = fts3DocidRange(pDocidGe, SMALLEST_INT64); |
| 125005 | + pCsr->iMaxDocid = fts3DocidRange(pDocidLe, LARGEST_INT64); |
| 125006 | + |
| 124604 | 125007 | if( idxStr ){ |
| 124605 | 125008 | pCsr->bDesc = (idxStr[0]=='D'); |
| 124606 | 125009 | }else{ |
| 124607 | 125010 | pCsr->bDesc = p->bDescIdx; |
| 124608 | 125011 | } |
| 124609 | | - pCsr->eSearch = (i16)idxNum; |
| 125012 | + pCsr->eSearch = (i16)eSearch; |
| 124610 | 125013 | |
| 124611 | | - if( idxNum!=FTS3_DOCID_SEARCH && idxNum!=FTS3_FULLSCAN_SEARCH ){ |
| 124612 | | - int iCol = idxNum-FTS3_FULLTEXT_SEARCH; |
| 124613 | | - const char *zQuery = (const char *)sqlite3_value_text(apVal[0]); |
| 125014 | + if( eSearch!=FTS3_DOCID_SEARCH && eSearch!=FTS3_FULLSCAN_SEARCH ){ |
| 125015 | + int iCol = eSearch-FTS3_FULLTEXT_SEARCH; |
| 125016 | + const char *zQuery = (const char *)sqlite3_value_text(pCons); |
| 124614 | 125017 | |
| 124615 | | - if( zQuery==0 && sqlite3_value_type(apVal[0])!=SQLITE_NULL ){ |
| 125018 | + if( zQuery==0 && sqlite3_value_type(pCons)!=SQLITE_NULL ){ |
| 124616 | 125019 | return SQLITE_NOMEM; |
| 124617 | 125020 | } |
| 124618 | 125021 | |
| 124619 | 125022 | pCsr->iLangid = 0; |
| 124620 | | - if( nVal==2 ) pCsr->iLangid = sqlite3_value_int(apVal[1]); |
| 125023 | + if( pLangid ) pCsr->iLangid = sqlite3_value_int(pLangid); |
| 124621 | 125024 | |
| 124622 | 125025 | assert( p->base.zErrMsg==0 ); |
| 124623 | 125026 | rc = sqlite3Fts3ExprParse(p->pTokenizer, pCsr->iLangid, |
| 124624 | 125027 | p->azColumn, p->bFts4, p->nColumn, iCol, zQuery, -1, &pCsr->pExpr, |
| 124625 | 125028 | &p->base.zErrMsg |
| | @@ -124638,11 +125041,11 @@ |
| 124638 | 125041 | /* Compile a SELECT statement for this cursor. For a full-table-scan, the |
| 124639 | 125042 | ** statement loops through all rows of the %_content table. For a |
| 124640 | 125043 | ** full-text query or docid lookup, the statement retrieves a single |
| 124641 | 125044 | ** row by docid. |
| 124642 | 125045 | */ |
| 124643 | | - if( idxNum==FTS3_FULLSCAN_SEARCH ){ |
| 125046 | + if( eSearch==FTS3_FULLSCAN_SEARCH ){ |
| 124644 | 125047 | zSql = sqlite3_mprintf( |
| 124645 | 125048 | "SELECT %s ORDER BY rowid %s", |
| 124646 | 125049 | p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC") |
| 124647 | 125050 | ); |
| 124648 | 125051 | if( zSql ){ |
| | @@ -124649,14 +125052,14 @@ |
| 124649 | 125052 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0); |
| 124650 | 125053 | sqlite3_free(zSql); |
| 124651 | 125054 | }else{ |
| 124652 | 125055 | rc = SQLITE_NOMEM; |
| 124653 | 125056 | } |
| 124654 | | - }else if( idxNum==FTS3_DOCID_SEARCH ){ |
| 125057 | + }else if( eSearch==FTS3_DOCID_SEARCH ){ |
| 124655 | 125058 | rc = fts3CursorSeekStmt(pCsr, &pCsr->pStmt); |
| 124656 | 125059 | if( rc==SQLITE_OK ){ |
| 124657 | | - rc = sqlite3_bind_value(pCsr->pStmt, 1, apVal[0]); |
| 125060 | + rc = sqlite3_bind_value(pCsr->pStmt, 1, pCons); |
| 124658 | 125061 | } |
| 124659 | 125062 | } |
| 124660 | 125063 | if( rc!=SQLITE_OK ) return rc; |
| 124661 | 125064 | |
| 124662 | 125065 | return fts3NextMethod(pCursor); |
| | @@ -125543,10 +125946,16 @@ |
| 125543 | 125946 | } |
| 125544 | 125947 | |
| 125545 | 125948 | return SQLITE_OK; |
| 125546 | 125949 | } |
| 125547 | 125950 | |
| 125951 | +/* |
| 125952 | +** Maximum number of tokens a phrase may have to be considered for the |
| 125953 | +** incremental doclists strategy. |
| 125954 | +*/ |
| 125955 | +#define MAX_INCR_PHRASE_TOKENS 4 |
| 125956 | + |
| 125548 | 125957 | /* |
| 125549 | 125958 | ** This function is called for each Fts3Phrase in a full-text query |
| 125550 | 125959 | ** expression to initialize the mechanism for returning rows. Once this |
| 125551 | 125960 | ** function has been called successfully on an Fts3Phrase, it may be |
| 125552 | 125961 | ** used with fts3EvalPhraseNext() to iterate through the matching docids. |
| | @@ -125556,27 +125965,47 @@ |
| 125556 | 125965 | ** memory within this call. |
| 125557 | 125966 | ** |
| 125558 | 125967 | ** SQLITE_OK is returned if no error occurs, otherwise an SQLite error code. |
| 125559 | 125968 | */ |
| 125560 | 125969 | static int fts3EvalPhraseStart(Fts3Cursor *pCsr, int bOptOk, Fts3Phrase *p){ |
| 125561 | | - int rc; /* Error code */ |
| 125562 | | - Fts3PhraseToken *pFirst = &p->aToken[0]; |
| 125563 | 125970 | Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab; |
| 125564 | | - |
| 125565 | | - if( pCsr->bDesc==pTab->bDescIdx |
| 125566 | | - && bOptOk==1 |
| 125567 | | - && p->nToken==1 |
| 125568 | | - && pFirst->pSegcsr |
| 125569 | | - && pFirst->pSegcsr->bLookup |
| 125570 | | - && pFirst->bFirst==0 |
| 125571 | | - ){ |
| 125971 | + int rc = SQLITE_OK; /* Error code */ |
| 125972 | + int i; |
| 125973 | + |
| 125974 | + /* Determine if doclists may be loaded from disk incrementally. This is |
| 125975 | + ** possible if the bOptOk argument is true, the FTS doclists will be |
| 125976 | + ** scanned in forward order, and the phrase consists of |
| 125977 | + ** MAX_INCR_PHRASE_TOKENS or fewer tokens, none of which are are "^first" |
| 125978 | + ** tokens or prefix tokens that cannot use a prefix-index. */ |
| 125979 | + int bHaveIncr = 0; |
| 125980 | + int bIncrOk = (bOptOk |
| 125981 | + && pCsr->bDesc==pTab->bDescIdx |
| 125982 | + && p->nToken<=MAX_INCR_PHRASE_TOKENS && p->nToken>0 |
| 125983 | + && p->nToken<=MAX_INCR_PHRASE_TOKENS && p->nToken>0 |
| 125984 | +#ifdef SQLITE_TEST |
| 125985 | + && pTab->bNoIncrDoclist==0 |
| 125986 | +#endif |
| 125987 | + ); |
| 125988 | + for(i=0; bIncrOk==1 && i<p->nToken; i++){ |
| 125989 | + Fts3PhraseToken *pToken = &p->aToken[i]; |
| 125990 | + if( pToken->bFirst || (pToken->pSegcsr!=0 && !pToken->pSegcsr->bLookup) ){ |
| 125991 | + bIncrOk = 0; |
| 125992 | + } |
| 125993 | + if( pToken->pSegcsr ) bHaveIncr = 1; |
| 125994 | + } |
| 125995 | + |
| 125996 | + if( bIncrOk && bHaveIncr ){ |
| 125572 | 125997 | /* Use the incremental approach. */ |
| 125573 | 125998 | int iCol = (p->iColumn >= pTab->nColumn ? -1 : p->iColumn); |
| 125574 | | - rc = sqlite3Fts3MsrIncrStart( |
| 125575 | | - pTab, pFirst->pSegcsr, iCol, pFirst->z, pFirst->n); |
| 125999 | + for(i=0; rc==SQLITE_OK && i<p->nToken; i++){ |
| 126000 | + Fts3PhraseToken *pToken = &p->aToken[i]; |
| 126001 | + Fts3MultiSegReader *pSegcsr = pToken->pSegcsr; |
| 126002 | + if( pSegcsr ){ |
| 126003 | + rc = sqlite3Fts3MsrIncrStart(pTab, pSegcsr, iCol, pToken->z, pToken->n); |
| 126004 | + } |
| 126005 | + } |
| 125576 | 126006 | p->bIncr = 1; |
| 125577 | | - |
| 125578 | 126007 | }else{ |
| 125579 | 126008 | /* Load the full doclist for the phrase into memory. */ |
| 125580 | 126009 | rc = fts3EvalPhraseLoad(pCsr, p); |
| 125581 | 126010 | p->bIncr = 0; |
| 125582 | 126011 | } |
| | @@ -125680,10 +126109,220 @@ |
| 125680 | 126109 | } |
| 125681 | 126110 | } |
| 125682 | 126111 | |
| 125683 | 126112 | *ppIter = p; |
| 125684 | 126113 | } |
| 126114 | + |
| 126115 | +/* |
| 126116 | +** Advance the iterator pDL to the next entry in pDL->aAll/nAll. Set *pbEof |
| 126117 | +** to true if EOF is reached. |
| 126118 | +*/ |
| 126119 | +static void fts3EvalDlPhraseNext( |
| 126120 | + Fts3Table *pTab, |
| 126121 | + Fts3Doclist *pDL, |
| 126122 | + u8 *pbEof |
| 126123 | +){ |
| 126124 | + char *pIter; /* Used to iterate through aAll */ |
| 126125 | + char *pEnd = &pDL->aAll[pDL->nAll]; /* 1 byte past end of aAll */ |
| 126126 | + |
| 126127 | + if( pDL->pNextDocid ){ |
| 126128 | + pIter = pDL->pNextDocid; |
| 126129 | + }else{ |
| 126130 | + pIter = pDL->aAll; |
| 126131 | + } |
| 126132 | + |
| 126133 | + if( pIter>=pEnd ){ |
| 126134 | + /* We have already reached the end of this doclist. EOF. */ |
| 126135 | + *pbEof = 1; |
| 126136 | + }else{ |
| 126137 | + sqlite3_int64 iDelta; |
| 126138 | + pIter += sqlite3Fts3GetVarint(pIter, &iDelta); |
| 126139 | + if( pTab->bDescIdx==0 || pDL->pNextDocid==0 ){ |
| 126140 | + pDL->iDocid += iDelta; |
| 126141 | + }else{ |
| 126142 | + pDL->iDocid -= iDelta; |
| 126143 | + } |
| 126144 | + pDL->pList = pIter; |
| 126145 | + fts3PoslistCopy(0, &pIter); |
| 126146 | + pDL->nList = (int)(pIter - pDL->pList); |
| 126147 | + |
| 126148 | + /* pIter now points just past the 0x00 that terminates the position- |
| 126149 | + ** list for document pDL->iDocid. However, if this position-list was |
| 126150 | + ** edited in place by fts3EvalNearTrim(), then pIter may not actually |
| 126151 | + ** point to the start of the next docid value. The following line deals |
| 126152 | + ** with this case by advancing pIter past the zero-padding added by |
| 126153 | + ** fts3EvalNearTrim(). */ |
| 126154 | + while( pIter<pEnd && *pIter==0 ) pIter++; |
| 126155 | + |
| 126156 | + pDL->pNextDocid = pIter; |
| 126157 | + assert( pIter>=&pDL->aAll[pDL->nAll] || *pIter ); |
| 126158 | + *pbEof = 0; |
| 126159 | + } |
| 126160 | +} |
| 126161 | + |
| 126162 | +/* |
| 126163 | +** Helper type used by fts3EvalIncrPhraseNext() and incrPhraseTokenNext(). |
| 126164 | +*/ |
| 126165 | +typedef struct TokenDoclist TokenDoclist; |
| 126166 | +struct TokenDoclist { |
| 126167 | + int bIgnore; |
| 126168 | + sqlite3_int64 iDocid; |
| 126169 | + char *pList; |
| 126170 | + int nList; |
| 126171 | +}; |
| 126172 | + |
| 126173 | +/* |
| 126174 | +** Token pToken is an incrementally loaded token that is part of a |
| 126175 | +** multi-token phrase. Advance it to the next matching document in the |
| 126176 | +** database and populate output variable *p with the details of the new |
| 126177 | +** entry. Or, if the iterator has reached EOF, set *pbEof to true. |
| 126178 | +** |
| 126179 | +** If an error occurs, return an SQLite error code. Otherwise, return |
| 126180 | +** SQLITE_OK. |
| 126181 | +*/ |
| 126182 | +static int incrPhraseTokenNext( |
| 126183 | + Fts3Table *pTab, /* Virtual table handle */ |
| 126184 | + Fts3Phrase *pPhrase, /* Phrase to advance token of */ |
| 126185 | + int iToken, /* Specific token to advance */ |
| 126186 | + TokenDoclist *p, /* OUT: Docid and doclist for new entry */ |
| 126187 | + u8 *pbEof /* OUT: True if iterator is at EOF */ |
| 126188 | +){ |
| 126189 | + int rc = SQLITE_OK; |
| 126190 | + |
| 126191 | + if( pPhrase->iDoclistToken==iToken ){ |
| 126192 | + assert( p->bIgnore==0 ); |
| 126193 | + assert( pPhrase->aToken[iToken].pSegcsr==0 ); |
| 126194 | + fts3EvalDlPhraseNext(pTab, &pPhrase->doclist, pbEof); |
| 126195 | + p->pList = pPhrase->doclist.pList; |
| 126196 | + p->nList = pPhrase->doclist.nList; |
| 126197 | + p->iDocid = pPhrase->doclist.iDocid; |
| 126198 | + }else{ |
| 126199 | + Fts3PhraseToken *pToken = &pPhrase->aToken[iToken]; |
| 126200 | + assert( pToken->pDeferred==0 ); |
| 126201 | + assert( pToken->pSegcsr || pPhrase->iDoclistToken>=0 ); |
| 126202 | + if( pToken->pSegcsr ){ |
| 126203 | + assert( p->bIgnore==0 ); |
| 126204 | + rc = sqlite3Fts3MsrIncrNext( |
| 126205 | + pTab, pToken->pSegcsr, &p->iDocid, &p->pList, &p->nList |
| 126206 | + ); |
| 126207 | + if( p->pList==0 ) *pbEof = 1; |
| 126208 | + }else{ |
| 126209 | + p->bIgnore = 1; |
| 126210 | + } |
| 126211 | + } |
| 126212 | + |
| 126213 | + return rc; |
| 126214 | +} |
| 126215 | + |
| 126216 | + |
| 126217 | +/* |
| 126218 | +** The phrase iterator passed as the second argument: |
| 126219 | +** |
| 126220 | +** * features at least one token that uses an incremental doclist, and |
| 126221 | +** |
| 126222 | +** * does not contain any deferred tokens. |
| 126223 | +** |
| 126224 | +** Advance it to the next matching documnent in the database and populate |
| 126225 | +** the Fts3Doclist.pList and nList fields. |
| 126226 | +** |
| 126227 | +** If there is no "next" entry and no error occurs, then *pbEof is set to |
| 126228 | +** 1 before returning. Otherwise, if no error occurs and the iterator is |
| 126229 | +** successfully advanced, *pbEof is set to 0. |
| 126230 | +** |
| 126231 | +** If an error occurs, return an SQLite error code. Otherwise, return |
| 126232 | +** SQLITE_OK. |
| 126233 | +*/ |
| 126234 | +static int fts3EvalIncrPhraseNext( |
| 126235 | + Fts3Cursor *pCsr, /* FTS Cursor handle */ |
| 126236 | + Fts3Phrase *p, /* Phrase object to advance to next docid */ |
| 126237 | + u8 *pbEof /* OUT: Set to 1 if EOF */ |
| 126238 | +){ |
| 126239 | + int rc = SQLITE_OK; |
| 126240 | + Fts3Doclist *pDL = &p->doclist; |
| 126241 | + Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab; |
| 126242 | + u8 bEof = 0; |
| 126243 | + |
| 126244 | + /* This is only called if it is guaranteed that the phrase has at least |
| 126245 | + ** one incremental token. In which case the bIncr flag is set. */ |
| 126246 | + assert( p->bIncr==1 ); |
| 126247 | + |
| 126248 | + if( p->nToken==1 && p->bIncr ){ |
| 126249 | + rc = sqlite3Fts3MsrIncrNext(pTab, p->aToken[0].pSegcsr, |
| 126250 | + &pDL->iDocid, &pDL->pList, &pDL->nList |
| 126251 | + ); |
| 126252 | + if( pDL->pList==0 ) bEof = 1; |
| 126253 | + }else{ |
| 126254 | + int bDescDoclist = pCsr->bDesc; |
| 126255 | + struct TokenDoclist a[MAX_INCR_PHRASE_TOKENS]; |
| 126256 | + |
| 126257 | + memset(a, 0, sizeof(a)); |
| 126258 | + assert( p->nToken<=MAX_INCR_PHRASE_TOKENS ); |
| 126259 | + assert( p->iDoclistToken<MAX_INCR_PHRASE_TOKENS ); |
| 126260 | + |
| 126261 | + while( bEof==0 ){ |
| 126262 | + int bMaxSet = 0; |
| 126263 | + sqlite3_int64 iMax; /* Largest docid for all iterators */ |
| 126264 | + int i; /* Used to iterate through tokens */ |
| 126265 | + |
| 126266 | + /* Advance the iterator for each token in the phrase once. */ |
| 126267 | + for(i=0; rc==SQLITE_OK && i<p->nToken; i++){ |
| 126268 | + rc = incrPhraseTokenNext(pTab, p, i, &a[i], &bEof); |
| 126269 | + if( a[i].bIgnore==0 && (bMaxSet==0 || DOCID_CMP(iMax, a[i].iDocid)<0) ){ |
| 126270 | + iMax = a[i].iDocid; |
| 126271 | + bMaxSet = 1; |
| 126272 | + } |
| 126273 | + } |
| 126274 | + assert( rc!=SQLITE_OK || a[p->nToken-1].bIgnore==0 ); |
| 126275 | + assert( rc!=SQLITE_OK || bMaxSet ); |
| 126276 | + |
| 126277 | + /* Keep advancing iterators until they all point to the same document */ |
| 126278 | + for(i=0; i<p->nToken; i++){ |
| 126279 | + while( rc==SQLITE_OK && bEof==0 |
| 126280 | + && a[i].bIgnore==0 && DOCID_CMP(a[i].iDocid, iMax)<0 |
| 126281 | + ){ |
| 126282 | + rc = incrPhraseTokenNext(pTab, p, i, &a[i], &bEof); |
| 126283 | + if( DOCID_CMP(a[i].iDocid, iMax)>0 ){ |
| 126284 | + iMax = a[i].iDocid; |
| 126285 | + i = 0; |
| 126286 | + } |
| 126287 | + } |
| 126288 | + } |
| 126289 | + |
| 126290 | + /* Check if the current entries really are a phrase match */ |
| 126291 | + if( bEof==0 ){ |
| 126292 | + int nList = 0; |
| 126293 | + int nByte = a[p->nToken-1].nList; |
| 126294 | + char *aDoclist = sqlite3_malloc(nByte+1); |
| 126295 | + if( !aDoclist ) return SQLITE_NOMEM; |
| 126296 | + memcpy(aDoclist, a[p->nToken-1].pList, nByte+1); |
| 126297 | + |
| 126298 | + for(i=0; i<(p->nToken-1); i++){ |
| 126299 | + if( a[i].bIgnore==0 ){ |
| 126300 | + char *pL = a[i].pList; |
| 126301 | + char *pR = aDoclist; |
| 126302 | + char *pOut = aDoclist; |
| 126303 | + int nDist = p->nToken-1-i; |
| 126304 | + int res = fts3PoslistPhraseMerge(&pOut, nDist, 0, 1, &pL, &pR); |
| 126305 | + if( res==0 ) break; |
| 126306 | + nList = (pOut - aDoclist); |
| 126307 | + } |
| 126308 | + } |
| 126309 | + if( i==(p->nToken-1) ){ |
| 126310 | + pDL->iDocid = iMax; |
| 126311 | + pDL->pList = aDoclist; |
| 126312 | + pDL->nList = nList; |
| 126313 | + pDL->bFreeList = 1; |
| 126314 | + break; |
| 126315 | + } |
| 126316 | + sqlite3_free(aDoclist); |
| 126317 | + } |
| 126318 | + } |
| 126319 | + } |
| 126320 | + |
| 126321 | + *pbEof = bEof; |
| 126322 | + return rc; |
| 126323 | +} |
| 125685 | 126324 | |
| 125686 | 126325 | /* |
| 125687 | 126326 | ** Attempt to move the phrase iterator to point to the next matching docid. |
| 125688 | 126327 | ** If an error occurs, return an SQLite error code. Otherwise, return |
| 125689 | 126328 | ** SQLITE_OK. |
| | @@ -125700,59 +126339,18 @@ |
| 125700 | 126339 | int rc = SQLITE_OK; |
| 125701 | 126340 | Fts3Doclist *pDL = &p->doclist; |
| 125702 | 126341 | Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab; |
| 125703 | 126342 | |
| 125704 | 126343 | if( p->bIncr ){ |
| 125705 | | - assert( p->nToken==1 ); |
| 125706 | | - assert( pDL->pNextDocid==0 ); |
| 125707 | | - rc = sqlite3Fts3MsrIncrNext(pTab, p->aToken[0].pSegcsr, |
| 125708 | | - &pDL->iDocid, &pDL->pList, &pDL->nList |
| 125709 | | - ); |
| 125710 | | - if( rc==SQLITE_OK && !pDL->pList ){ |
| 125711 | | - *pbEof = 1; |
| 125712 | | - } |
| 126344 | + rc = fts3EvalIncrPhraseNext(pCsr, p, pbEof); |
| 125713 | 126345 | }else if( pCsr->bDesc!=pTab->bDescIdx && pDL->nAll ){ |
| 125714 | 126346 | sqlite3Fts3DoclistPrev(pTab->bDescIdx, pDL->aAll, pDL->nAll, |
| 125715 | 126347 | &pDL->pNextDocid, &pDL->iDocid, &pDL->nList, pbEof |
| 125716 | 126348 | ); |
| 125717 | 126349 | pDL->pList = pDL->pNextDocid; |
| 125718 | 126350 | }else{ |
| 125719 | | - char *pIter; /* Used to iterate through aAll */ |
| 125720 | | - char *pEnd = &pDL->aAll[pDL->nAll]; /* 1 byte past end of aAll */ |
| 125721 | | - if( pDL->pNextDocid ){ |
| 125722 | | - pIter = pDL->pNextDocid; |
| 125723 | | - }else{ |
| 125724 | | - pIter = pDL->aAll; |
| 125725 | | - } |
| 125726 | | - |
| 125727 | | - if( pIter>=pEnd ){ |
| 125728 | | - /* We have already reached the end of this doclist. EOF. */ |
| 125729 | | - *pbEof = 1; |
| 125730 | | - }else{ |
| 125731 | | - sqlite3_int64 iDelta; |
| 125732 | | - pIter += sqlite3Fts3GetVarint(pIter, &iDelta); |
| 125733 | | - if( pTab->bDescIdx==0 || pDL->pNextDocid==0 ){ |
| 125734 | | - pDL->iDocid += iDelta; |
| 125735 | | - }else{ |
| 125736 | | - pDL->iDocid -= iDelta; |
| 125737 | | - } |
| 125738 | | - pDL->pList = pIter; |
| 125739 | | - fts3PoslistCopy(0, &pIter); |
| 125740 | | - pDL->nList = (int)(pIter - pDL->pList); |
| 125741 | | - |
| 125742 | | - /* pIter now points just past the 0x00 that terminates the position- |
| 125743 | | - ** list for document pDL->iDocid. However, if this position-list was |
| 125744 | | - ** edited in place by fts3EvalNearTrim(), then pIter may not actually |
| 125745 | | - ** point to the start of the next docid value. The following line deals |
| 125746 | | - ** with this case by advancing pIter past the zero-padding added by |
| 125747 | | - ** fts3EvalNearTrim(). */ |
| 125748 | | - while( pIter<pEnd && *pIter==0 ) pIter++; |
| 125749 | | - |
| 125750 | | - pDL->pNextDocid = pIter; |
| 125751 | | - assert( pIter>=&pDL->aAll[pDL->nAll] || *pIter ); |
| 125752 | | - *pbEof = 0; |
| 125753 | | - } |
| 126351 | + fts3EvalDlPhraseNext(pTab, pDL, pbEof); |
| 125754 | 126352 | } |
| 125755 | 126353 | |
| 125756 | 126354 | return rc; |
| 125757 | 126355 | } |
| 125758 | 126356 | |
| | @@ -125773,11 +126371,10 @@ |
| 125773 | 126371 | ** code before returning. |
| 125774 | 126372 | */ |
| 125775 | 126373 | static void fts3EvalStartReaders( |
| 125776 | 126374 | Fts3Cursor *pCsr, /* FTS Cursor handle */ |
| 125777 | 126375 | Fts3Expr *pExpr, /* Expression to initialize phrases in */ |
| 125778 | | - int bOptOk, /* True to enable incremental loading */ |
| 125779 | 126376 | int *pRc /* IN/OUT: Error code */ |
| 125780 | 126377 | ){ |
| 125781 | 126378 | if( pExpr && SQLITE_OK==*pRc ){ |
| 125782 | 126379 | if( pExpr->eType==FTSQUERY_PHRASE ){ |
| 125783 | 126380 | int i; |
| | @@ -125784,14 +126381,14 @@ |
| 125784 | 126381 | int nToken = pExpr->pPhrase->nToken; |
| 125785 | 126382 | for(i=0; i<nToken; i++){ |
| 125786 | 126383 | if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break; |
| 125787 | 126384 | } |
| 125788 | 126385 | pExpr->bDeferred = (i==nToken); |
| 125789 | | - *pRc = fts3EvalPhraseStart(pCsr, bOptOk, pExpr->pPhrase); |
| 126386 | + *pRc = fts3EvalPhraseStart(pCsr, 1, pExpr->pPhrase); |
| 125790 | 126387 | }else{ |
| 125791 | | - fts3EvalStartReaders(pCsr, pExpr->pLeft, bOptOk, pRc); |
| 125792 | | - fts3EvalStartReaders(pCsr, pExpr->pRight, bOptOk, pRc); |
| 126388 | + fts3EvalStartReaders(pCsr, pExpr->pLeft, pRc); |
| 126389 | + fts3EvalStartReaders(pCsr, pExpr->pRight, pRc); |
| 125793 | 126390 | pExpr->bDeferred = (pExpr->pLeft->bDeferred && pExpr->pRight->bDeferred); |
| 125794 | 126391 | } |
| 125795 | 126392 | } |
| 125796 | 126393 | } |
| 125797 | 126394 | |
| | @@ -126029,11 +126626,11 @@ |
| 126029 | 126626 | /* Set nLoad4 to the value of (4^nOther) for the next iteration of the |
| 126030 | 126627 | ** for-loop. Except, limit the value to 2^24 to prevent it from |
| 126031 | 126628 | ** overflowing the 32-bit integer it is stored in. */ |
| 126032 | 126629 | if( ii<12 ) nLoad4 = nLoad4*4; |
| 126033 | 126630 | |
| 126034 | | - if( ii==0 || pTC->pPhrase->nToken>1 ){ |
| 126631 | + if( ii==0 || (pTC->pPhrase->nToken>1 && ii!=nToken-1) ){ |
| 126035 | 126632 | /* Either this is the cheapest token in the entire query, or it is |
| 126036 | 126633 | ** part of a multi-token phrase. Either way, the entire doclist will |
| 126037 | 126634 | ** (eventually) be loaded into memory. It may as well be now. */ |
| 126038 | 126635 | Fts3PhraseToken *pToken = pTC->pToken; |
| 126039 | 126636 | int nList = 0; |
| | @@ -126109,11 +126706,11 @@ |
| 126109 | 126706 | sqlite3_free(aTC); |
| 126110 | 126707 | } |
| 126111 | 126708 | } |
| 126112 | 126709 | #endif |
| 126113 | 126710 | |
| 126114 | | - fts3EvalStartReaders(pCsr, pCsr->pExpr, 1, &rc); |
| 126711 | + fts3EvalStartReaders(pCsr, pCsr->pExpr, &rc); |
| 126115 | 126712 | return rc; |
| 126116 | 126713 | } |
| 126117 | 126714 | |
| 126118 | 126715 | /* |
| 126119 | 126716 | ** Invalidate the current position list for phrase pPhrase. |
| | @@ -126592,10 +127189,20 @@ |
| 126592 | 127189 | pCsr->isRequireSeek = 1; |
| 126593 | 127190 | pCsr->isMatchinfoNeeded = 1; |
| 126594 | 127191 | pCsr->iPrevId = pExpr->iDocid; |
| 126595 | 127192 | }while( pCsr->isEof==0 && fts3EvalTestDeferredAndNear(pCsr, &rc) ); |
| 126596 | 127193 | } |
| 127194 | + |
| 127195 | + /* Check if the cursor is past the end of the docid range specified |
| 127196 | + ** by Fts3Cursor.iMinDocid/iMaxDocid. If so, set the EOF flag. */ |
| 127197 | + if( rc==SQLITE_OK && ( |
| 127198 | + (pCsr->bDesc==0 && pCsr->iPrevId>pCsr->iMaxDocid) |
| 127199 | + || (pCsr->bDesc!=0 && pCsr->iPrevId<pCsr->iMinDocid) |
| 127200 | + )){ |
| 127201 | + pCsr->isEof = 1; |
| 127202 | + } |
| 127203 | + |
| 126597 | 127204 | return rc; |
| 126598 | 127205 | } |
| 126599 | 127206 | |
| 126600 | 127207 | /* |
| 126601 | 127208 | ** Restart interation for expression pExpr so that the next call to |
| | @@ -126615,16 +127222,20 @@ |
| 126615 | 127222 | Fts3Phrase *pPhrase = pExpr->pPhrase; |
| 126616 | 127223 | |
| 126617 | 127224 | if( pPhrase ){ |
| 126618 | 127225 | fts3EvalInvalidatePoslist(pPhrase); |
| 126619 | 127226 | if( pPhrase->bIncr ){ |
| 126620 | | - assert( pPhrase->nToken==1 ); |
| 126621 | | - assert( pPhrase->aToken[0].pSegcsr ); |
| 126622 | | - sqlite3Fts3MsrIncrRestart(pPhrase->aToken[0].pSegcsr); |
| 127227 | + int i; |
| 127228 | + for(i=0; i<pPhrase->nToken; i++){ |
| 127229 | + Fts3PhraseToken *pToken = &pPhrase->aToken[i]; |
| 127230 | + assert( pToken->pDeferred==0 ); |
| 127231 | + if( pToken->pSegcsr ){ |
| 127232 | + sqlite3Fts3MsrIncrRestart(pToken->pSegcsr); |
| 127233 | + } |
| 127234 | + } |
| 126623 | 127235 | *pRc = fts3EvalPhraseStart(pCsr, 0, pPhrase); |
| 126624 | 127236 | } |
| 126625 | | - |
| 126626 | 127237 | pPhrase->doclist.pNextDocid = 0; |
| 126627 | 127238 | pPhrase->doclist.iDocid = 0; |
| 126628 | 127239 | } |
| 126629 | 127240 | |
| 126630 | 127241 | pExpr->iDocid = 0; |
| | @@ -126869,19 +127480,27 @@ |
| 126869 | 127480 | |
| 126870 | 127481 | iDocid = pExpr->iDocid; |
| 126871 | 127482 | pIter = pPhrase->doclist.pList; |
| 126872 | 127483 | if( iDocid!=pCsr->iPrevId || pExpr->bEof ){ |
| 126873 | 127484 | int bDescDoclist = pTab->bDescIdx; /* For DOCID_CMP macro */ |
| 127485 | + int iMul; /* +1 if csr dir matches index dir, else -1 */ |
| 126874 | 127486 | int bOr = 0; |
| 126875 | 127487 | u8 bEof = 0; |
| 126876 | | - Fts3Expr *p; |
| 127488 | + u8 bTreeEof = 0; |
| 127489 | + Fts3Expr *p; /* Used to iterate from pExpr to root */ |
| 127490 | + Fts3Expr *pNear; /* Most senior NEAR ancestor (or pExpr) */ |
| 126877 | 127491 | |
| 126878 | 127492 | /* Check if this phrase descends from an OR expression node. If not, |
| 126879 | 127493 | ** return NULL. Otherwise, the entry that corresponds to docid |
| 126880 | | - ** pCsr->iPrevId may lie earlier in the doclist buffer. */ |
| 127494 | + ** pCsr->iPrevId may lie earlier in the doclist buffer. Or, if the |
| 127495 | + ** tree that the node is part of has been marked as EOF, but the node |
| 127496 | + ** itself is not EOF, then it may point to an earlier entry. */ |
| 127497 | + pNear = pExpr; |
| 126881 | 127498 | for(p=pExpr->pParent; p; p=p->pParent){ |
| 126882 | 127499 | if( p->eType==FTSQUERY_OR ) bOr = 1; |
| 127500 | + if( p->eType==FTSQUERY_NEAR ) pNear = p; |
| 127501 | + if( p->bEof ) bTreeEof = 1; |
| 126883 | 127502 | } |
| 126884 | 127503 | if( bOr==0 ) return SQLITE_OK; |
| 126885 | 127504 | |
| 126886 | 127505 | /* This is the descendent of an OR node. In this case we cannot use |
| 126887 | 127506 | ** an incremental phrase. Load the entire doclist for the phrase |
| | @@ -126896,33 +127515,63 @@ |
| 126896 | 127515 | } |
| 126897 | 127516 | pIter = pPhrase->doclist.pList; |
| 126898 | 127517 | assert( rc!=SQLITE_OK || pPhrase->bIncr==0 ); |
| 126899 | 127518 | if( rc!=SQLITE_OK ) return rc; |
| 126900 | 127519 | } |
| 127520 | + |
| 127521 | + iMul = ((pCsr->bDesc==bDescDoclist) ? 1 : -1); |
| 127522 | + while( bTreeEof==1 |
| 127523 | + && pNear->bEof==0 |
| 127524 | + && (DOCID_CMP(pNear->iDocid, pCsr->iPrevId) * iMul)<0 |
| 127525 | + ){ |
| 127526 | + int rc = SQLITE_OK; |
| 127527 | + fts3EvalNextRow(pCsr, pExpr, &rc); |
| 127528 | + if( rc!=SQLITE_OK ) return rc; |
| 127529 | + iDocid = pExpr->iDocid; |
| 127530 | + pIter = pPhrase->doclist.pList; |
| 127531 | + } |
| 126901 | 127532 | |
| 126902 | | - if( pExpr->bEof ){ |
| 126903 | | - pIter = 0; |
| 126904 | | - iDocid = 0; |
| 126905 | | - } |
| 126906 | 127533 | bEof = (pPhrase->doclist.nAll==0); |
| 126907 | 127534 | assert( bDescDoclist==0 || bDescDoclist==1 ); |
| 126908 | 127535 | assert( pCsr->bDesc==0 || pCsr->bDesc==1 ); |
| 126909 | 127536 | |
| 126910 | | - if( pCsr->bDesc==bDescDoclist ){ |
| 126911 | | - int dummy; |
| 126912 | | - while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){ |
| 126913 | | - sqlite3Fts3DoclistPrev( |
| 126914 | | - bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, |
| 126915 | | - &pIter, &iDocid, &dummy, &bEof |
| 126916 | | - ); |
| 126917 | | - } |
| 126918 | | - }else{ |
| 126919 | | - while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){ |
| 126920 | | - sqlite3Fts3DoclistNext( |
| 126921 | | - bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, |
| 126922 | | - &pIter, &iDocid, &bEof |
| 126923 | | - ); |
| 127537 | + if( bEof==0 ){ |
| 127538 | + if( pCsr->bDesc==bDescDoclist ){ |
| 127539 | + int dummy; |
| 127540 | + if( pNear->bEof ){ |
| 127541 | + /* This expression is already at EOF. So position it to point to the |
| 127542 | + ** last entry in the doclist at pPhrase->doclist.aAll[]. Variable |
| 127543 | + ** iDocid is already set for this entry, so all that is required is |
| 127544 | + ** to set pIter to point to the first byte of the last position-list |
| 127545 | + ** in the doclist. |
| 127546 | + ** |
| 127547 | + ** It would also be correct to set pIter and iDocid to zero. In |
| 127548 | + ** this case, the first call to sqltie3Fts4DoclistPrev() below |
| 127549 | + ** would also move the iterator to point to the last entry in the |
| 127550 | + ** doclist. However, this is expensive, as to do so it has to |
| 127551 | + ** iterate through the entire doclist from start to finish (since |
| 127552 | + ** it does not know the docid for the last entry). */ |
| 127553 | + pIter = &pPhrase->doclist.aAll[pPhrase->doclist.nAll-1]; |
| 127554 | + fts3ReversePoslist(pPhrase->doclist.aAll, &pIter); |
| 127555 | + } |
| 127556 | + while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){ |
| 127557 | + sqlite3Fts3DoclistPrev( |
| 127558 | + bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, |
| 127559 | + &pIter, &iDocid, &dummy, &bEof |
| 127560 | + ); |
| 127561 | + } |
| 127562 | + }else{ |
| 127563 | + if( pNear->bEof ){ |
| 127564 | + pIter = 0; |
| 127565 | + iDocid = 0; |
| 127566 | + } |
| 127567 | + while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){ |
| 127568 | + sqlite3Fts3DoclistNext( |
| 127569 | + bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, |
| 127570 | + &pIter, &iDocid, &bEof |
| 127571 | + ); |
| 127572 | + } |
| 126924 | 127573 | } |
| 126925 | 127574 | } |
| 126926 | 127575 | |
| 126927 | 127576 | if( bEof || iDocid!=pCsr->iPrevId ) pIter = 0; |
| 126928 | 127577 | } |
| | @@ -135756,11 +136405,11 @@ |
| 135756 | 136405 | assert( p->bFts4==0 ); |
| 135757 | 136406 | sqlite3Fts3CreateStatTable(&rc, p); |
| 135758 | 136407 | if( rc ) return rc; |
| 135759 | 136408 | } |
| 135760 | 136409 | rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pStmt, 0); |
| 135761 | | - if( rc ) return rc;; |
| 136410 | + if( rc ) return rc; |
| 135762 | 136411 | sqlite3_bind_int(pStmt, 1, FTS_STAT_AUTOINCRMERGE); |
| 135763 | 136412 | sqlite3_bind_int(pStmt, 2, p->bAutoincrmerge); |
| 135764 | 136413 | sqlite3_step(pStmt); |
| 135765 | 136414 | rc = sqlite3_reset(pStmt); |
| 135766 | 136415 | return rc; |
| | @@ -136025,10 +136674,13 @@ |
| 136025 | 136674 | }else if( nVal>9 && 0==sqlite3_strnicmp(zVal, "nodesize=", 9) ){ |
| 136026 | 136675 | p->nNodeSize = atoi(&zVal[9]); |
| 136027 | 136676 | rc = SQLITE_OK; |
| 136028 | 136677 | }else if( nVal>11 && 0==sqlite3_strnicmp(zVal, "maxpending=", 9) ){ |
| 136029 | 136678 | p->nMaxPendingData = atoi(&zVal[11]); |
| 136679 | + rc = SQLITE_OK; |
| 136680 | + }else if( nVal>21 && 0==sqlite3_strnicmp(zVal, "test-no-incr-doclist=", 21) ){ |
| 136681 | + p->bNoIncrDoclist = atoi(&zVal[21]); |
| 136030 | 136682 | rc = SQLITE_OK; |
| 136031 | 136683 | #endif |
| 136032 | 136684 | }else{ |
| 136033 | 136685 | rc = SQLITE_ERROR; |
| 136034 | 136686 | } |
| 136035 | 136687 | |