| | @@ -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-17 12:57:35 c78be6d786c19073b3a6730dfe3fb1be54f5657a" |
| 662 | 141 | |
| 663 | 142 | /* |
| 664 | 143 | ** CAPI3REF: Run-Time Library Version Numbers |
| 665 | 144 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 666 | 145 | ** |
| | @@ -2164,31 +1643,31 @@ |
| 2164 | 1643 | ** supplied by the application must not invoke any SQLite interface. |
| 2165 | 1644 | ** In a multi-threaded application, the application-defined logger |
| 2166 | 1645 | ** function must be threadsafe. </dd> |
| 2167 | 1646 | ** |
| 2168 | 1647 | ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
| 2169 | | -** <dd> This option takes a single argument of type int. If non-zero, then |
| 1648 | +** <dd>^(This option takes a single argument of type int. If non-zero, then |
| 2170 | 1649 | ** URI handling is globally enabled. If the parameter is zero, then URI handling |
| 2171 | | -** is globally disabled. If URI handling is globally enabled, all filenames |
| 1650 | +** is globally disabled.)^ ^If URI handling is globally enabled, all filenames |
| 2172 | 1651 | ** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or |
| 2173 | 1652 | ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
| 2174 | 1653 | ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
| 2175 | | -** connection is opened. If it is globally disabled, filenames are |
| 1654 | +** connection is opened. ^If it is globally disabled, filenames are |
| 2176 | 1655 | ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
| 2177 | | -** database connection is opened. By default, URI handling is globally |
| 1656 | +** database connection is opened. ^(By default, URI handling is globally |
| 2178 | 1657 | ** disabled. The default value may be changed by compiling with the |
| 2179 | | -** [SQLITE_USE_URI] symbol defined. |
| 1658 | +** [SQLITE_USE_URI] symbol defined.)^ |
| 2180 | 1659 | ** |
| 2181 | 1660 | ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN |
| 2182 | | -** <dd> This option takes a single integer argument which is interpreted as |
| 1661 | +** <dd>^This option takes a single integer argument which is interpreted as |
| 2183 | 1662 | ** a boolean in order to enable or disable the use of covering indices for |
| 2184 | | -** full table scans in the query optimizer. The default setting is determined |
| 1663 | +** full table scans in the query optimizer. ^The default setting is determined |
| 2185 | 1664 | ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on" |
| 2186 | 1665 | ** if that compile-time option is omitted. |
| 2187 | 1666 | ** The ability to disable the use of covering indices for full table scans |
| 2188 | 1667 | ** is because some incorrectly coded legacy applications might malfunction |
| 2189 | | -** malfunction when the optimization is enabled. Providing the ability to |
| 1668 | +** when the optimization is enabled. Providing the ability to |
| 2190 | 1669 | ** disable the optimization allows the older, buggy application code to work |
| 2191 | 1670 | ** without change even with newer versions of SQLite. |
| 2192 | 1671 | ** |
| 2193 | 1672 | ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]] |
| 2194 | 1673 | ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE |
| | @@ -2213,20 +1692,20 @@ |
| 2213 | 1692 | ** configuration option can be seen in the "test_sqllog.c" source file in |
| 2214 | 1693 | ** the canonical SQLite source tree.</dd> |
| 2215 | 1694 | ** |
| 2216 | 1695 | ** [[SQLITE_CONFIG_MMAP_SIZE]] |
| 2217 | 1696 | ** <dt>SQLITE_CONFIG_MMAP_SIZE |
| 2218 | | -** <dd>SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values |
| 1697 | +** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values |
| 2219 | 1698 | ** that are the default mmap size limit (the default setting for |
| 2220 | 1699 | ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit. |
| 2221 | | -** The default setting can be overridden by each database connection using |
| 1700 | +** ^The default setting can be overridden by each database connection using |
| 2222 | 1701 | ** either the [PRAGMA mmap_size] command, or by using the |
| 2223 | | -** [SQLITE_FCNTL_MMAP_SIZE] file control. The maximum allowed mmap size |
| 1702 | +** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size |
| 2224 | 1703 | ** cannot be changed at run-time. Nor may the maximum allowed mmap size |
| 2225 | 1704 | ** exceed the compile-time maximum mmap size set by the |
| 2226 | | -** [SQLITE_MAX_MMAP_SIZE] compile-time option. |
| 2227 | | -** If either argument to this option is negative, then that argument is |
| 1705 | +** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^ |
| 1706 | +** ^If either argument to this option is negative, then that argument is |
| 2228 | 1707 | ** changed to its compile-time default. |
| 2229 | 1708 | ** </dl> |
| 2230 | 1709 | */ |
| 2231 | 1710 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 2232 | 1711 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| | @@ -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); |
| | @@ -12435,14 +12468,14 @@ |
| 12435 | 12468 | SQLITE_PRIVATE int sqlite3FkRequired(Parse*, Table*, int*, int); |
| 12436 | 12469 | SQLITE_PRIVATE u32 sqlite3FkOldmask(Parse*, Table*); |
| 12437 | 12470 | SQLITE_PRIVATE FKey *sqlite3FkReferences(Table *); |
| 12438 | 12471 | #else |
| 12439 | 12472 | #define sqlite3FkActions(a,b,c,d,e,f) |
| 12440 | | - #define sqlite3FkCheck(a,b,c,d) |
| 12473 | + #define sqlite3FkCheck(a,b,c,d,e,f) |
| 12441 | 12474 | #define sqlite3FkDropTable(a,b,c) |
| 12442 | | - #define sqlite3FkOldmask(a,b) 0 |
| 12443 | | - #define sqlite3FkRequired(a,b,c,d,e,f) 0 |
| 12475 | + #define sqlite3FkOldmask(a,b) 0 |
| 12476 | + #define sqlite3FkRequired(a,b,c,d) 0 |
| 12444 | 12477 | #endif |
| 12445 | 12478 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 12446 | 12479 | SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*); |
| 12447 | 12480 | SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**); |
| 12448 | 12481 | #else |
| | @@ -14397,10 +14430,14 @@ |
| 14397 | 14430 | ** is available. This routine returns 0 on success and |
| 14398 | 14431 | ** non-zero on any kind of error. |
| 14399 | 14432 | ** |
| 14400 | 14433 | ** If the sqlite3GlobalConfig.bLocaltimeFault variable is true then this |
| 14401 | 14434 | ** routine will always fail. |
| 14435 | +** |
| 14436 | +** EVIDENCE-OF: R-62172-00036 In this implementation, the standard C |
| 14437 | +** library function localtime_r() is used to assist in the calculation of |
| 14438 | +** local time. |
| 14402 | 14439 | */ |
| 14403 | 14440 | static int osLocaltime(time_t *t, struct tm *pTm){ |
| 14404 | 14441 | int rc; |
| 14405 | 14442 | #if (!defined(HAVE_LOCALTIME_R) || !HAVE_LOCALTIME_R) \ |
| 14406 | 14443 | && (!defined(HAVE_LOCALTIME_S) || !HAVE_LOCALTIME_S) |
| | @@ -14453,10 +14490,15 @@ |
| 14453 | 14490 | memset(&sLocal, 0, sizeof(sLocal)); |
| 14454 | 14491 | |
| 14455 | 14492 | x = *p; |
| 14456 | 14493 | computeYMD_HMS(&x); |
| 14457 | 14494 | if( x.Y<1971 || x.Y>=2038 ){ |
| 14495 | + /* EVIDENCE-OF: R-55269-29598 The localtime_r() C function normally only |
| 14496 | + ** works for years between 1970 and 2037. For dates outside this range, |
| 14497 | + ** SQLite attempts to map the year into an equivalent year within this |
| 14498 | + ** range, do the calculation, then map the year back. |
| 14499 | + */ |
| 14458 | 14500 | x.Y = 2000; |
| 14459 | 14501 | x.M = 1; |
| 14460 | 14502 | x.D = 1; |
| 14461 | 14503 | x.h = 0; |
| 14462 | 14504 | x.m = 0; |
| | @@ -22387,10 +22429,87 @@ |
| 22387 | 22429 | for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){} |
| 22388 | 22430 | if( z[i]=='.' && ALWAYS(sz>i+4) ) memmove(&z[i+1], &z[sz-3], 4); |
| 22389 | 22431 | } |
| 22390 | 22432 | } |
| 22391 | 22433 | #endif |
| 22434 | + |
| 22435 | +/* |
| 22436 | +** Find (an approximate) sum of two LogEst values. This computation is |
| 22437 | +** not a simple "+" operator because LogEst is stored as a logarithmic |
| 22438 | +** value. |
| 22439 | +** |
| 22440 | +*/ |
| 22441 | +SQLITE_PRIVATE LogEst sqlite3LogEstAdd(LogEst a, LogEst b){ |
| 22442 | + static const unsigned char x[] = { |
| 22443 | + 10, 10, /* 0,1 */ |
| 22444 | + 9, 9, /* 2,3 */ |
| 22445 | + 8, 8, /* 4,5 */ |
| 22446 | + 7, 7, 7, /* 6,7,8 */ |
| 22447 | + 6, 6, 6, /* 9,10,11 */ |
| 22448 | + 5, 5, 5, /* 12-14 */ |
| 22449 | + 4, 4, 4, 4, /* 15-18 */ |
| 22450 | + 3, 3, 3, 3, 3, 3, /* 19-24 */ |
| 22451 | + 2, 2, 2, 2, 2, 2, 2, /* 25-31 */ |
| 22452 | + }; |
| 22453 | + if( a>=b ){ |
| 22454 | + if( a>b+49 ) return a; |
| 22455 | + if( a>b+31 ) return a+1; |
| 22456 | + return a+x[a-b]; |
| 22457 | + }else{ |
| 22458 | + if( b>a+49 ) return b; |
| 22459 | + if( b>a+31 ) return b+1; |
| 22460 | + return b+x[b-a]; |
| 22461 | + } |
| 22462 | +} |
| 22463 | + |
| 22464 | +/* |
| 22465 | +** Convert an integer into a LogEst. In other words, compute a |
| 22466 | +** good approximatation for 10*log2(x). |
| 22467 | +*/ |
| 22468 | +SQLITE_PRIVATE LogEst sqlite3LogEst(u64 x){ |
| 22469 | + static LogEst a[] = { 0, 2, 3, 5, 6, 7, 8, 9 }; |
| 22470 | + LogEst y = 40; |
| 22471 | + if( x<8 ){ |
| 22472 | + if( x<2 ) return 0; |
| 22473 | + while( x<8 ){ y -= 10; x <<= 1; } |
| 22474 | + }else{ |
| 22475 | + while( x>255 ){ y += 40; x >>= 4; } |
| 22476 | + while( x>15 ){ y += 10; x >>= 1; } |
| 22477 | + } |
| 22478 | + return a[x&7] + y - 10; |
| 22479 | +} |
| 22480 | + |
| 22481 | +#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 22482 | +/* |
| 22483 | +** Convert a double into a LogEst |
| 22484 | +** In other words, compute an approximation for 10*log2(x). |
| 22485 | +*/ |
| 22486 | +SQLITE_PRIVATE LogEst sqlite3LogEstFromDouble(double x){ |
| 22487 | + u64 a; |
| 22488 | + LogEst e; |
| 22489 | + assert( sizeof(x)==8 && sizeof(a)==8 ); |
| 22490 | + if( x<=1 ) return 0; |
| 22491 | + if( x<=2000000000 ) return sqlite3LogEst((u64)x); |
| 22492 | + memcpy(&a, &x, 8); |
| 22493 | + e = (a>>52) - 1022; |
| 22494 | + return e*10; |
| 22495 | +} |
| 22496 | +#endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 22497 | + |
| 22498 | +/* |
| 22499 | +** Convert a LogEst into an integer. |
| 22500 | +*/ |
| 22501 | +SQLITE_PRIVATE u64 sqlite3LogEstToInt(LogEst x){ |
| 22502 | + u64 n; |
| 22503 | + if( x<10 ) return 1; |
| 22504 | + n = x%10; |
| 22505 | + x /= 10; |
| 22506 | + if( n>=5 ) n -= 2; |
| 22507 | + else if( n>=1 ) n -= 1; |
| 22508 | + if( x>=3 ) return (n+8)<<(x-3); |
| 22509 | + return (n+8)>>(3-x); |
| 22510 | +} |
| 22392 | 22511 | |
| 22393 | 22512 | /************** End of util.c ************************************************/ |
| 22394 | 22513 | /************** Begin file hash.c ********************************************/ |
| 22395 | 22514 | /* |
| 22396 | 22515 | ** 2001 September 22 |
| | @@ -31382,11 +31501,11 @@ |
| 31382 | 31501 | #endif |
| 31383 | 31502 | |
| 31384 | 31503 | #define osGetVersionExA ((BOOL(WINAPI*)( \ |
| 31385 | 31504 | LPOSVERSIONINFOA))aSyscall[34].pCurrent) |
| 31386 | 31505 | |
| 31387 | | -#if defined(SQLITE_WIN32_HAS_WIDE) |
| 31506 | +#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) |
| 31388 | 31507 | { "GetVersionExW", (SYSCALL)GetVersionExW, 0 }, |
| 31389 | 31508 | #else |
| 31390 | 31509 | { "GetVersionExW", (SYSCALL)0, 0 }, |
| 31391 | 31510 | #endif |
| 31392 | 31511 | |
| | @@ -32896,12 +33015,11 @@ |
| 32896 | 33015 | #endif |
| 32897 | 33016 | assert( pFile->h!=NULL && pFile->h!=INVALID_HANDLE_VALUE ); |
| 32898 | 33017 | OSTRACE(("CLOSE file=%p\n", pFile->h)); |
| 32899 | 33018 | |
| 32900 | 33019 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 32901 | | - rc = winUnmapfile(pFile); |
| 32902 | | - if( rc!=SQLITE_OK ) return rc; |
| 33020 | + winUnmapfile(pFile); |
| 32903 | 33021 | #endif |
| 32904 | 33022 | |
| 32905 | 33023 | do{ |
| 32906 | 33024 | rc = osCloseHandle(pFile->h); |
| 32907 | 33025 | /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */ |
| | @@ -33703,11 +33821,11 @@ |
| 33703 | 33821 | } |
| 33704 | 33822 | *(i64*)pArg = pFile->mmapSizeMax; |
| 33705 | 33823 | if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){ |
| 33706 | 33824 | pFile->mmapSizeMax = newLimit; |
| 33707 | 33825 | if( pFile->mmapSize>0 ){ |
| 33708 | | - (void)winUnmapfile(pFile); |
| 33826 | + winUnmapfile(pFile); |
| 33709 | 33827 | rc = winMapfile(pFile, -1); |
| 33710 | 33828 | } |
| 33711 | 33829 | } |
| 33712 | 33830 | OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc))); |
| 33713 | 33831 | return rc; |
| | @@ -33920,11 +34038,11 @@ |
| 33920 | 34038 | osGetCurrentProcessId(), deleteFlag)); |
| 33921 | 34039 | pp = &winShmNodeList; |
| 33922 | 34040 | while( (p = *pp)!=0 ){ |
| 33923 | 34041 | if( p->nRef==0 ){ |
| 33924 | 34042 | int i; |
| 33925 | | - if( p->mutex ) sqlite3_mutex_free(p->mutex); |
| 34043 | + if( p->mutex ){ sqlite3_mutex_free(p->mutex); } |
| 33926 | 34044 | for(i=0; i<p->nRegion; i++){ |
| 33927 | 34045 | BOOL bRc = osUnmapViewOfFile(p->aRegion[i].pMap); |
| 33928 | 34046 | OSTRACE(("SHM-PURGE-UNMAP pid=%lu, region=%d, rc=%s\n", |
| 33929 | 34047 | osGetCurrentProcessId(), i, bRc ? "ok" : "failed")); |
| 33930 | 34048 | UNUSED_VARIABLE_VALUE(bRc); |
| | @@ -34773,10 +34891,11 @@ |
| 34773 | 34891 | ** API prior to using it. |
| 34774 | 34892 | */ |
| 34775 | 34893 | if( winIsDriveLetterAndColon(zDir) ){ |
| 34776 | 34894 | zConverted = winConvertFromUtf8Filename(zDir); |
| 34777 | 34895 | if( !zConverted ){ |
| 34896 | + sqlite3_free(zBuf); |
| 34778 | 34897 | OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
| 34779 | 34898 | return SQLITE_IOERR_NOMEM; |
| 34780 | 34899 | } |
| 34781 | 34900 | if( winIsDir(zConverted) ){ |
| 34782 | 34901 | sqlite3_snprintf(nBuf-30, zBuf, "%s", zDir); |
| | @@ -34785,17 +34904,19 @@ |
| 34785 | 34904 | } |
| 34786 | 34905 | sqlite3_free(zConverted); |
| 34787 | 34906 | }else{ |
| 34788 | 34907 | zConverted = sqlite3MallocZero( nBuf+1 ); |
| 34789 | 34908 | if( !zConverted ){ |
| 34909 | + sqlite3_free(zBuf); |
| 34790 | 34910 | OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
| 34791 | 34911 | return SQLITE_IOERR_NOMEM; |
| 34792 | 34912 | } |
| 34793 | 34913 | if( cygwin_conv_path( |
| 34794 | 34914 | osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A, zDir, |
| 34795 | 34915 | zConverted, nBuf+1)<0 ){ |
| 34796 | 34916 | sqlite3_free(zConverted); |
| 34917 | + sqlite3_free(zBuf); |
| 34797 | 34918 | OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_CONVPATH\n")); |
| 34798 | 34919 | return winLogError(SQLITE_IOERR_CONVPATH, (DWORD)errno, |
| 34799 | 34920 | "winGetTempname1", zDir); |
| 34800 | 34921 | } |
| 34801 | 34922 | if( winIsDir(zConverted) ){ |
| | @@ -34805,10 +34926,11 @@ |
| 34805 | 34926 | */ |
| 34806 | 34927 | if( osIsNT() ){ |
| 34807 | 34928 | char *zUtf8 = winUnicodeToUtf8(zConverted); |
| 34808 | 34929 | if( !zUtf8 ){ |
| 34809 | 34930 | sqlite3_free(zConverted); |
| 34931 | + sqlite3_free(zBuf); |
| 34810 | 34932 | OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
| 34811 | 34933 | return SQLITE_IOERR_NOMEM; |
| 34812 | 34934 | } |
| 34813 | 34935 | sqlite3_snprintf(nBuf-30, zBuf, "%s", zUtf8); |
| 34814 | 34936 | sqlite3_free(zUtf8); |
| | @@ -34820,11 +34942,10 @@ |
| 34820 | 34942 | break; |
| 34821 | 34943 | } |
| 34822 | 34944 | } |
| 34823 | 34945 | sqlite3_free(zConverted); |
| 34824 | 34946 | } |
| 34825 | | - break; |
| 34826 | 34947 | } |
| 34827 | 34948 | } |
| 34828 | 34949 | #elif !SQLITE_OS_WINRT && !defined(__CYGWIN__) |
| 34829 | 34950 | else if( osIsNT() ){ |
| 34830 | 34951 | char *zMulti; |
| | @@ -35190,13 +35311,13 @@ |
| 35190 | 35311 | pFile->zDeleteOnClose = zConverted; |
| 35191 | 35312 | }else |
| 35192 | 35313 | #endif |
| 35193 | 35314 | { |
| 35194 | 35315 | sqlite3_free(zConverted); |
| 35195 | | - sqlite3_free(zTmpname); |
| 35196 | 35316 | } |
| 35197 | 35317 | |
| 35318 | + sqlite3_free(zTmpname); |
| 35198 | 35319 | pFile->pMethod = &winIoMethod; |
| 35199 | 35320 | pFile->pVfs = pVfs; |
| 35200 | 35321 | pFile->h = h; |
| 35201 | 35322 | if( isReadonly ){ |
| 35202 | 35323 | pFile->ctrlFlags |= WINFILE_RDONLY; |
| | @@ -48986,17 +49107,17 @@ |
| 48986 | 49107 | ** page contain a special header (the "file header") that describes the file. |
| 48987 | 49108 | ** The format of the file header is as follows: |
| 48988 | 49109 | ** |
| 48989 | 49110 | ** OFFSET SIZE DESCRIPTION |
| 48990 | 49111 | ** 0 16 Header string: "SQLite format 3\000" |
| 48991 | | -** 16 2 Page size in bytes. |
| 49112 | +** 16 2 Page size in bytes. (1 means 65536) |
| 48992 | 49113 | ** 18 1 File format write version |
| 48993 | 49114 | ** 19 1 File format read version |
| 48994 | 49115 | ** 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 |
| 49116 | +** 21 1 Max embedded payload fraction (must be 64) |
| 49117 | +** 22 1 Min embedded payload fraction (must be 32) |
| 49118 | +** 23 1 Min leaf payload fraction (must be 32) |
| 48998 | 49119 | ** 24 4 File change counter |
| 48999 | 49120 | ** 28 4 Reserved for future use |
| 49000 | 49121 | ** 32 4 First freelist page |
| 49001 | 49122 | ** 36 4 Number of freelist pages in the file |
| 49002 | 49123 | ** 40 60 15 4-byte meta values passed to higher layers |
| | @@ -49006,13 +49127,14 @@ |
| 49006 | 49127 | ** 48 4 Size of page cache |
| 49007 | 49128 | ** 52 4 Largest root-page (auto/incr_vacuum) |
| 49008 | 49129 | ** 56 4 1=UTF-8 2=UTF16le 3=UTF16be |
| 49009 | 49130 | ** 60 4 User version |
| 49010 | 49131 | ** 64 4 Incremental vacuum mode |
| 49011 | | -** 68 4 unused |
| 49012 | | -** 72 4 unused |
| 49013 | | -** 76 4 unused |
| 49132 | +** 68 4 Application-ID |
| 49133 | +** 72 20 unused |
| 49134 | +** 92 4 The version-valid-for number |
| 49135 | +** 96 4 SQLITE_VERSION_NUMBER |
| 49014 | 49136 | ** |
| 49015 | 49137 | ** All of the integer values are big-endian (most significant byte first). |
| 49016 | 49138 | ** |
| 49017 | 49139 | ** The file change counter is incremented when the database is changed |
| 49018 | 49140 | ** This counter allows other processes to know when the file has changed |
| | @@ -51922,10 +52044,22 @@ |
| 51922 | 52044 | ** MX_CELL_SIZE(pBt) bytes. |
| 51923 | 52045 | */ |
| 51924 | 52046 | static void allocateTempSpace(BtShared *pBt){ |
| 51925 | 52047 | if( !pBt->pTmpSpace ){ |
| 51926 | 52048 | pBt->pTmpSpace = sqlite3PageMalloc( pBt->pageSize ); |
| 52049 | + |
| 52050 | + /* One of the uses of pBt->pTmpSpace is to format cells before |
| 52051 | + ** inserting them into a leaf page (function fillInCell()). If |
| 52052 | + ** a cell is less than 4 bytes in size, it is rounded up to 4 bytes |
| 52053 | + ** by the various routines that manipulate binary cells. Which |
| 52054 | + ** can mean that fillInCell() only initializes the first 2 or 3 |
| 52055 | + ** bytes of pTmpSpace, but that the first 4 bytes are copied from |
| 52056 | + ** it into a database page. This is not actually a problem, but it |
| 52057 | + ** does cause a valgrind error when the 1 or 2 bytes of unitialized |
| 52058 | + ** data is passed to system call write(). So to avoid this error, |
| 52059 | + ** zero the first 4 bytes of temp space here. */ |
| 52060 | + if( pBt->pTmpSpace ) memset(pBt->pTmpSpace, 0, 4); |
| 51927 | 52061 | } |
| 51928 | 52062 | } |
| 51929 | 52063 | |
| 51930 | 52064 | /* |
| 51931 | 52065 | ** Free the pBt->pTmpSpace allocation |
| | @@ -52378,11 +52512,10 @@ |
| 52378 | 52512 | pBt->max1bytePayload = (u8)pBt->maxLocal; |
| 52379 | 52513 | } |
| 52380 | 52514 | assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) ); |
| 52381 | 52515 | pBt->pPage1 = pPage1; |
| 52382 | 52516 | pBt->nPage = nPage; |
| 52383 | | -assert( pPage1->leaf==0 || pPage1->leaf==1 ); |
| 52384 | 52517 | return SQLITE_OK; |
| 52385 | 52518 | |
| 52386 | 52519 | page1_init_failed: |
| 52387 | 52520 | releasePage(pPage1); |
| 52388 | 52521 | pBt->pPage1 = 0; |
| | @@ -52538,11 +52671,11 @@ |
| 52538 | 52671 | ** is requested, this is a no-op. |
| 52539 | 52672 | */ |
| 52540 | 52673 | if( p->inTrans==TRANS_WRITE || (p->inTrans==TRANS_READ && !wrflag) ){ |
| 52541 | 52674 | goto trans_begun; |
| 52542 | 52675 | } |
| 52543 | | - assert( IfNotOmitAV(pBt->bDoTruncate)==0 ); |
| 52676 | + assert( pBt->inTransaction==TRANS_WRITE || IfNotOmitAV(pBt->bDoTruncate)==0 ); |
| 52544 | 52677 | |
| 52545 | 52678 | /* Write transactions are not possible on a read-only database */ |
| 52546 | 52679 | if( (pBt->btsFlags & BTS_READ_ONLY)!=0 && wrflag ){ |
| 52547 | 52680 | rc = SQLITE_READONLY; |
| 52548 | 52681 | goto trans_begun; |
| | @@ -60189,11 +60322,13 @@ |
| 60189 | 60322 | } |
| 60190 | 60323 | |
| 60191 | 60324 | pRec->nField = p->iVal+1; |
| 60192 | 60325 | return &pRec->aMem[p->iVal]; |
| 60193 | 60326 | } |
| 60194 | | -#endif |
| 60327 | +#else |
| 60328 | + UNUSED_PARAMETER(p); |
| 60329 | +#endif /* defined(SQLITE_ENABLE_STAT3_OR_STAT4) */ |
| 60195 | 60330 | return sqlite3ValueNew(db); |
| 60196 | 60331 | } |
| 60197 | 60332 | |
| 60198 | 60333 | /* |
| 60199 | 60334 | ** Extract a value from the supplied expression in the manner described |
| | @@ -60203,11 +60338,11 @@ |
| 60203 | 60338 | ** If pCtx is NULL and an error occurs after the sqlite3_value object |
| 60204 | 60339 | ** has been allocated, it is freed before returning. Or, if pCtx is not |
| 60205 | 60340 | ** NULL, it is assumed that the caller will free any allocated object |
| 60206 | 60341 | ** in all cases. |
| 60207 | 60342 | */ |
| 60208 | | -int valueFromExpr( |
| 60343 | +static int valueFromExpr( |
| 60209 | 60344 | sqlite3 *db, /* The database connection */ |
| 60210 | 60345 | Expr *pExpr, /* The expression to evaluate */ |
| 60211 | 60346 | u8 enc, /* Encoding to use */ |
| 60212 | 60347 | u8 affinity, /* Affinity to use */ |
| 60213 | 60348 | sqlite3_value **ppVal, /* Write the new value here */ |
| | @@ -60360,10 +60495,11 @@ |
| 60360 | 60495 | int nVal; /* Bytes of space required for argv[0] */ |
| 60361 | 60496 | int nRet; |
| 60362 | 60497 | sqlite3 *db; |
| 60363 | 60498 | u8 *aRet; |
| 60364 | 60499 | |
| 60500 | + UNUSED_PARAMETER( argc ); |
| 60365 | 60501 | iSerial = sqlite3VdbeSerialType(argv[0], file_format); |
| 60366 | 60502 | nSerial = sqlite3VarintLen(iSerial); |
| 60367 | 60503 | nVal = sqlite3VdbeSerialTypeLen(iSerial); |
| 60368 | 60504 | db = sqlite3_context_db_handle(context); |
| 60369 | 60505 | |
| | @@ -62977,10 +63113,11 @@ |
| 62977 | 63113 | } |
| 62978 | 63114 | fclose(out); |
| 62979 | 63115 | } |
| 62980 | 63116 | } |
| 62981 | 63117 | #endif |
| 63118 | + p->iCurrentTime = 0; |
| 62982 | 63119 | p->magic = VDBE_MAGIC_INIT; |
| 62983 | 63120 | return p->rc & db->errMask; |
| 62984 | 63121 | } |
| 62985 | 63122 | |
| 62986 | 63123 | /* |
| | @@ -75299,10 +75436,14 @@ |
| 75299 | 75436 | sqlite3ErrorMsg(pParse, "second argument to likelihood() must be a " |
| 75300 | 75437 | "constant between 0.0 and 1.0"); |
| 75301 | 75438 | pNC->nErr++; |
| 75302 | 75439 | } |
| 75303 | 75440 | }else{ |
| 75441 | + /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is equivalent to |
| 75442 | + ** likelihood(X, 0.0625). |
| 75443 | + ** EVIDENCE-OF: R-01283-11636 The unlikely(X) function is short-hand for |
| 75444 | + ** likelihood(X,0.0625). */ |
| 75304 | 75445 | pExpr->iTable = 62; /* TUNING: Default 2nd arg to unlikely() is 0.0625 */ |
| 75305 | 75446 | } |
| 75306 | 75447 | } |
| 75307 | 75448 | } |
| 75308 | 75449 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| | @@ -76082,11 +76223,11 @@ |
| 76082 | 76223 | return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr); |
| 76083 | 76224 | } |
| 76084 | 76225 | #ifndef SQLITE_OMIT_CAST |
| 76085 | 76226 | if( op==TK_CAST ){ |
| 76086 | 76227 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 76087 | | - return sqlite3AffinityType(pExpr->u.zToken); |
| 76228 | + return sqlite3AffinityType(pExpr->u.zToken, 0); |
| 76088 | 76229 | } |
| 76089 | 76230 | #endif |
| 76090 | 76231 | if( (op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_REGISTER) |
| 76091 | 76232 | && pExpr->pTab!=0 |
| 76092 | 76233 | ){ |
| | @@ -78502,11 +78643,11 @@ |
| 78502 | 78643 | case TK_CAST: { |
| 78503 | 78644 | /* Expressions of the form: CAST(pLeft AS token) */ |
| 78504 | 78645 | int aff, to_op; |
| 78505 | 78646 | inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target); |
| 78506 | 78647 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 78507 | | - aff = sqlite3AffinityType(pExpr->u.zToken); |
| 78648 | + aff = sqlite3AffinityType(pExpr->u.zToken, 0); |
| 78508 | 78649 | to_op = aff - SQLITE_AFF_TEXT + OP_ToText; |
| 78509 | 78650 | assert( to_op==OP_ToText || aff!=SQLITE_AFF_TEXT ); |
| 78510 | 78651 | assert( to_op==OP_ToBlob || aff!=SQLITE_AFF_NONE ); |
| 78511 | 78652 | assert( to_op==OP_ToNumeric || aff!=SQLITE_AFF_NUMERIC ); |
| 78512 | 78653 | assert( to_op==OP_ToInt || aff!=SQLITE_AFF_INTEGER ); |
| | @@ -79169,11 +79310,11 @@ |
| 79169 | 79310 | } |
| 79170 | 79311 | #ifndef SQLITE_OMIT_CAST |
| 79171 | 79312 | case TK_CAST: { |
| 79172 | 79313 | /* Expressions of the form: CAST(pLeft AS token) */ |
| 79173 | 79314 | const char *zAff = "unk"; |
| 79174 | | - switch( sqlite3AffinityType(pExpr->u.zToken) ){ |
| 79315 | + switch( sqlite3AffinityType(pExpr->u.zToken, 0) ){ |
| 79175 | 79316 | case SQLITE_AFF_TEXT: zAff = "TEXT"; break; |
| 79176 | 79317 | case SQLITE_AFF_NONE: zAff = "NONE"; break; |
| 79177 | 79318 | case SQLITE_AFF_NUMERIC: zAff = "NUMERIC"; break; |
| 79178 | 79319 | case SQLITE_AFF_INTEGER: zAff = "INTEGER"; break; |
| 79179 | 79320 | case SQLITE_AFF_REAL: zAff = "REAL"; break; |
| | @@ -81173,11 +81314,11 @@ |
| 81173 | 81314 | ** The sqlite_stat2 table is superseded by sqlite_stat3, which is only |
| 81174 | 81315 | ** created and used by SQLite versions 3.7.9 and later and with |
| 81175 | 81316 | ** SQLITE_ENABLE_STAT3 defined. The functionality of sqlite_stat3 |
| 81176 | 81317 | ** is a superset of sqlite_stat2. The sqlite_stat4 is an enhanced |
| 81177 | 81318 | ** version of sqlite_stat3 and is only available when compiled with |
| 81178 | | -** SQLITE_ENABLE_STAT4 and in SQLite versions 3.8.0 and later. It is |
| 81319 | +** SQLITE_ENABLE_STAT4 and in SQLite versions 3.8.1 and later. It is |
| 81179 | 81320 | ** not possible to enable both STAT3 and STAT4 at the same time. If they |
| 81180 | 81321 | ** are both enabled, then STAT4 takes precedence. |
| 81181 | 81322 | ** |
| 81182 | 81323 | ** For most applications, sqlite_stat1 provides all the statisics required |
| 81183 | 81324 | ** for the query planner to make good choices. |
| | @@ -81249,16 +81390,16 @@ |
| 81249 | 81390 | ** |
| 81250 | 81391 | ** The sqlite_stat4 table contains multiple entries for each index. |
| 81251 | 81392 | ** The idx column names the index and the tbl column is the table of the |
| 81252 | 81393 | ** index. If the idx and tbl columns are the same, then the sample is |
| 81253 | 81394 | ** of the INTEGER PRIMARY KEY. The sample column is a blob which is the |
| 81254 | | -** binary encoding of a key from the index, with the trailing rowid |
| 81255 | | -** omitted. The nEq column is a list of integers. The first integer |
| 81256 | | -** is the approximate number of entries in the index whose left-most |
| 81257 | | -** column exactly matches the left-most column of the sample. The second |
| 81258 | | -** integer in nEq is the approximate number of entries in the index where |
| 81259 | | -** the first two columns match the first two columns of the sample. |
| 81395 | +** binary encoding of a key from the index. The nEq column is a |
| 81396 | +** list of integers. The first integer is the approximate number |
| 81397 | +** of entries in the index whose left-most column exactly matches |
| 81398 | +** the left-most column of the sample. The second integer in nEq |
| 81399 | +** is the approximate number of entries in the index where the |
| 81400 | +** first two columns match the first two columns of the sample. |
| 81260 | 81401 | ** And so forth. nLt is another list of integers that show the approximate |
| 81261 | 81402 | ** number of entries that are strictly less than the sample. The first |
| 81262 | 81403 | ** integer in nLt contains the number of entries in the index where the |
| 81263 | 81404 | ** left-most column is less than the left-most column of the sample. |
| 81264 | 81405 | ** The K-th integer in the nLt entry is the number of index entries |
| | @@ -81585,11 +81726,11 @@ |
| 81585 | 81726 | } |
| 81586 | 81727 | |
| 81587 | 81728 | /* |
| 81588 | 81729 | ** Copy the contents of object (*pFrom) into (*pTo). |
| 81589 | 81730 | */ |
| 81590 | | -void sampleCopy(Stat4Accum *p, Stat4Sample *pTo, Stat4Sample *pFrom){ |
| 81731 | +static void sampleCopy(Stat4Accum *p, Stat4Sample *pTo, Stat4Sample *pFrom){ |
| 81591 | 81732 | pTo->iRowid = pFrom->iRowid; |
| 81592 | 81733 | pTo->isPSample = pFrom->isPSample; |
| 81593 | 81734 | pTo->iCol = pFrom->iCol; |
| 81594 | 81735 | pTo->iHash = pFrom->iHash; |
| 81595 | 81736 | memcpy(pTo->anEq, pFrom->anEq, sizeof(tRowcnt)*p->nCol); |
| | @@ -81730,10 +81871,15 @@ |
| 81730 | 81871 | ){ |
| 81731 | 81872 | sampleInsert(p, &p->current, 0); |
| 81732 | 81873 | } |
| 81733 | 81874 | } |
| 81734 | 81875 | #endif |
| 81876 | + |
| 81877 | +#ifndef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 81878 | + UNUSED_PARAMETER( p ); |
| 81879 | + UNUSED_PARAMETER( iChng ); |
| 81880 | +#endif |
| 81735 | 81881 | } |
| 81736 | 81882 | |
| 81737 | 81883 | /* |
| 81738 | 81884 | ** Implementation of the stat_push SQL function: stat_push(P,R,C) |
| 81739 | 81885 | ** Arguments: |
| | @@ -81755,10 +81901,12 @@ |
| 81755 | 81901 | |
| 81756 | 81902 | /* The three function arguments */ |
| 81757 | 81903 | Stat4Accum *p = (Stat4Accum*)sqlite3_value_blob(argv[0]); |
| 81758 | 81904 | int iChng = sqlite3_value_int(argv[1]); |
| 81759 | 81905 | |
| 81906 | + UNUSED_PARAMETER( argc ); |
| 81907 | + UNUSED_PARAMETER( context ); |
| 81760 | 81908 | assert( p->nCol>1 ); /* Includes rowid field */ |
| 81761 | 81909 | assert( iChng<p->nCol ); |
| 81762 | 81910 | |
| 81763 | 81911 | if( p->nRow==0 ){ |
| 81764 | 81912 | /* This is the first call to this function. Do initialization. */ |
| | @@ -81884,16 +82032,16 @@ |
| 81884 | 82032 | if( zRet==0 ){ |
| 81885 | 82033 | sqlite3_result_error_nomem(context); |
| 81886 | 82034 | return; |
| 81887 | 82035 | } |
| 81888 | 82036 | |
| 81889 | | - sqlite3_snprintf(24, zRet, "%lld", p->nRow); |
| 82037 | + sqlite3_snprintf(24, zRet, "%llu", (u64)p->nRow); |
| 81890 | 82038 | z = zRet + sqlite3Strlen30(zRet); |
| 81891 | 82039 | 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); |
| 82040 | + u64 nDistinct = p->current.anDLt[i] + 1; |
| 82041 | + u64 iVal = (p->nRow + nDistinct - 1) / nDistinct; |
| 82042 | + sqlite3_snprintf(24, z, " %llu", iVal); |
| 81895 | 82043 | z += sqlite3Strlen30(z); |
| 81896 | 82044 | assert( p->current.anEq[i] ); |
| 81897 | 82045 | } |
| 81898 | 82046 | assert( z[0]=='\0' && z>zRet ); |
| 81899 | 82047 | |
| | @@ -81930,20 +82078,23 @@ |
| 81930 | 82078 | sqlite3_result_error_nomem(context); |
| 81931 | 82079 | }else{ |
| 81932 | 82080 | int i; |
| 81933 | 82081 | char *z = zRet; |
| 81934 | 82082 | for(i=0; i<p->nCol; i++){ |
| 81935 | | - sqlite3_snprintf(24, z, "%lld ", aCnt[i]); |
| 82083 | + sqlite3_snprintf(24, z, "%llu ", (u64)aCnt[i]); |
| 81936 | 82084 | z += sqlite3Strlen30(z); |
| 81937 | 82085 | } |
| 81938 | 82086 | assert( z[0]=='\0' && z>zRet ); |
| 81939 | 82087 | z[-1] = '\0'; |
| 81940 | 82088 | sqlite3_result_text(context, zRet, -1, sqlite3_free); |
| 81941 | 82089 | } |
| 81942 | 82090 | } |
| 81943 | 82091 | } |
| 81944 | 82092 | #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */ |
| 82093 | +#ifndef SQLITE_DEBUG |
| 82094 | + UNUSED_PARAMETER( argc ); |
| 82095 | +#endif |
| 81945 | 82096 | } |
| 81946 | 82097 | static const FuncDef statGetFuncdef = { |
| 81947 | 82098 | 1+IsStat34, /* nArg */ |
| 81948 | 82099 | SQLITE_UTF8, /* funcFlags */ |
| 81949 | 82100 | 0, /* pUserData */ |
| | @@ -81958,12 +82109,14 @@ |
| 81958 | 82109 | |
| 81959 | 82110 | static void callStatGet(Vdbe *v, int regStat4, int iParam, int regOut){ |
| 81960 | 82111 | assert( regOut!=regStat4 && regOut!=regStat4+1 ); |
| 81961 | 82112 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 81962 | 82113 | sqlite3VdbeAddOp2(v, OP_Integer, iParam, regStat4+1); |
| 81963 | | -#else |
| 82114 | +#elif SQLITE_DEBUG |
| 81964 | 82115 | assert( iParam==STAT_GET_STAT1 ); |
| 82116 | +#else |
| 82117 | + UNUSED_PARAMETER( iParam ); |
| 81965 | 82118 | #endif |
| 81966 | 82119 | sqlite3VdbeAddOp3(v, OP_Function, 0, regStat4, regOut); |
| 81967 | 82120 | sqlite3VdbeChangeP4(v, -1, (char*)&statGetFuncdef, P4_FUNCDEF); |
| 81968 | 82121 | sqlite3VdbeChangeP5(v, 1 + IsStat34); |
| 81969 | 82122 | } |
| | @@ -82391,22 +82544,20 @@ |
| 82391 | 82544 | ** The first argument points to a nul-terminated string containing a |
| 82392 | 82545 | ** list of space separated integers. Read the first nOut of these into |
| 82393 | 82546 | ** the array aOut[]. |
| 82394 | 82547 | */ |
| 82395 | 82548 | static void decodeIntArray( |
| 82396 | | - char *zIntArray, |
| 82397 | | - int nOut, |
| 82398 | | - tRowcnt *aOut, |
| 82399 | | - int *pbUnordered |
| 82549 | + char *zIntArray, /* String containing int array to decode */ |
| 82550 | + int nOut, /* Number of slots in aOut[] */ |
| 82551 | + tRowcnt *aOut, /* Store integers here */ |
| 82552 | + Index *pIndex /* Handle extra flags for this index, if not NULL */ |
| 82400 | 82553 | ){ |
| 82401 | 82554 | char *z = zIntArray; |
| 82402 | 82555 | int c; |
| 82403 | 82556 | int i; |
| 82404 | 82557 | tRowcnt v; |
| 82405 | 82558 | |
| 82406 | | - assert( pbUnordered==0 || *pbUnordered==0 ); |
| 82407 | | - |
| 82408 | 82559 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 82409 | 82560 | if( z==0 ) z = ""; |
| 82410 | 82561 | #else |
| 82411 | 82562 | if( NEVER(z==0) ) z = ""; |
| 82412 | 82563 | #endif |
| | @@ -82417,12 +82568,23 @@ |
| 82417 | 82568 | z++; |
| 82418 | 82569 | } |
| 82419 | 82570 | aOut[i] = v; |
| 82420 | 82571 | if( *z==' ' ) z++; |
| 82421 | 82572 | } |
| 82422 | | - if( pbUnordered && strcmp(z, "unordered")==0 ){ |
| 82423 | | - *pbUnordered = 1; |
| 82573 | +#ifndef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 82574 | + assert( pIndex!=0 ); |
| 82575 | +#else |
| 82576 | + if( pIndex ) |
| 82577 | +#endif |
| 82578 | + { |
| 82579 | + if( strcmp(z, "unordered")==0 ){ |
| 82580 | + pIndex->bUnordered = 1; |
| 82581 | + }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){ |
| 82582 | + int v32 = 0; |
| 82583 | + sqlite3GetInt32(z+3, &v32); |
| 82584 | + pIndex->szIdxRow = sqlite3LogEst(v32); |
| 82585 | + } |
| 82424 | 82586 | } |
| 82425 | 82587 | } |
| 82426 | 82588 | |
| 82427 | 82589 | /* |
| 82428 | 82590 | ** This callback is invoked once for each index when reading the |
| | @@ -82457,16 +82619,17 @@ |
| 82457 | 82619 | pIndex = 0; |
| 82458 | 82620 | } |
| 82459 | 82621 | z = argv[2]; |
| 82460 | 82622 | |
| 82461 | 82623 | if( pIndex ){ |
| 82462 | | - int bUnordered = 0; |
| 82463 | | - decodeIntArray((char*)z, pIndex->nColumn+1, pIndex->aiRowEst,&bUnordered); |
| 82624 | + decodeIntArray((char*)z, pIndex->nColumn+1, pIndex->aiRowEst, pIndex); |
| 82464 | 82625 | if( pIndex->pPartIdxWhere==0 ) pTable->nRowEst = pIndex->aiRowEst[0]; |
| 82465 | | - pIndex->bUnordered = bUnordered; |
| 82466 | 82626 | }else{ |
| 82467 | | - decodeIntArray((char*)z, 1, &pTable->nRowEst, 0); |
| 82627 | + Index fakeIdx; |
| 82628 | + fakeIdx.szIdxRow = pTable->szTabRow; |
| 82629 | + decodeIntArray((char*)z, 1, &pTable->nRowEst, &fakeIdx); |
| 82630 | + pTable->szTabRow = fakeIdx.szIdxRow; |
| 82468 | 82631 | } |
| 82469 | 82632 | |
| 82470 | 82633 | return 0; |
| 82471 | 82634 | } |
| 82472 | 82635 | |
| | @@ -83185,32 +83348,28 @@ |
| 83185 | 83348 | #endif /* SQLITE_OMIT_ATTACH */ |
| 83186 | 83349 | |
| 83187 | 83350 | /* |
| 83188 | 83351 | ** Initialize a DbFixer structure. This routine must be called prior |
| 83189 | 83352 | ** 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 | 83353 | */ |
| 83194 | | -SQLITE_PRIVATE int sqlite3FixInit( |
| 83354 | +SQLITE_PRIVATE void sqlite3FixInit( |
| 83195 | 83355 | DbFixer *pFix, /* The fixer to be initialized */ |
| 83196 | 83356 | Parse *pParse, /* Error messages will be written here */ |
| 83197 | 83357 | int iDb, /* This is the database that must be used */ |
| 83198 | 83358 | const char *zType, /* "view", "trigger", or "index" */ |
| 83199 | 83359 | const Token *pName /* Name of the view, trigger, or index */ |
| 83200 | 83360 | ){ |
| 83201 | 83361 | sqlite3 *db; |
| 83202 | 83362 | |
| 83203 | | - if( NEVER(iDb<0) || iDb==1 ) return 0; |
| 83204 | 83363 | db = pParse->db; |
| 83205 | 83364 | assert( db->nDb>iDb ); |
| 83206 | 83365 | pFix->pParse = pParse; |
| 83207 | 83366 | pFix->zDb = db->aDb[iDb].zName; |
| 83208 | 83367 | pFix->pSchema = db->aDb[iDb].pSchema; |
| 83209 | 83368 | pFix->zType = zType; |
| 83210 | 83369 | pFix->pName = pName; |
| 83211 | | - return 1; |
| 83370 | + pFix->bVarOnly = (iDb==1); |
| 83212 | 83371 | } |
| 83213 | 83372 | |
| 83214 | 83373 | /* |
| 83215 | 83374 | ** The following set of routines walk through the parse tree and assign |
| 83216 | 83375 | ** a specific database to all table references where the database name |
| | @@ -83234,19 +83393,21 @@ |
| 83234 | 83393 | struct SrcList_item *pItem; |
| 83235 | 83394 | |
| 83236 | 83395 | if( NEVER(pList==0) ) return 0; |
| 83237 | 83396 | zDb = pFix->zDb; |
| 83238 | 83397 | 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; |
| 83398 | + if( pFix->bVarOnly==0 ){ |
| 83399 | + if( pItem->zDatabase && sqlite3StrICmp(pItem->zDatabase, zDb) ){ |
| 83400 | + sqlite3ErrorMsg(pFix->pParse, |
| 83401 | + "%s %T cannot reference objects in database %s", |
| 83402 | + pFix->zType, pFix->pName, pItem->zDatabase); |
| 83403 | + return 1; |
| 83404 | + } |
| 83405 | + sqlite3DbFree(pFix->pParse->db, pItem->zDatabase); |
| 83406 | + pItem->zDatabase = 0; |
| 83407 | + pItem->pSchema = pFix->pSchema; |
| 83408 | + } |
| 83248 | 83409 | #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER) |
| 83249 | 83410 | if( sqlite3FixSelect(pFix, pItem->pSelect) ) return 1; |
| 83250 | 83411 | if( sqlite3FixExpr(pFix, pItem->pOn) ) return 1; |
| 83251 | 83412 | #endif |
| 83252 | 83413 | } |
| | @@ -83264,13 +83425,25 @@ |
| 83264 | 83425 | if( sqlite3FixSrcList(pFix, pSelect->pSrc) ){ |
| 83265 | 83426 | return 1; |
| 83266 | 83427 | } |
| 83267 | 83428 | if( sqlite3FixExpr(pFix, pSelect->pWhere) ){ |
| 83268 | 83429 | return 1; |
| 83430 | + } |
| 83431 | + if( sqlite3FixExprList(pFix, pSelect->pGroupBy) ){ |
| 83432 | + return 1; |
| 83269 | 83433 | } |
| 83270 | 83434 | if( sqlite3FixExpr(pFix, pSelect->pHaving) ){ |
| 83271 | 83435 | return 1; |
| 83436 | + } |
| 83437 | + if( sqlite3FixExprList(pFix, pSelect->pOrderBy) ){ |
| 83438 | + return 1; |
| 83439 | + } |
| 83440 | + if( sqlite3FixExpr(pFix, pSelect->pLimit) ){ |
| 83441 | + return 1; |
| 83442 | + } |
| 83443 | + if( sqlite3FixExpr(pFix, pSelect->pOffset) ){ |
| 83444 | + return 1; |
| 83272 | 83445 | } |
| 83273 | 83446 | pSelect = pSelect->pPrior; |
| 83274 | 83447 | } |
| 83275 | 83448 | return 0; |
| 83276 | 83449 | } |
| | @@ -83277,10 +83450,18 @@ |
| 83277 | 83450 | SQLITE_PRIVATE int sqlite3FixExpr( |
| 83278 | 83451 | DbFixer *pFix, /* Context of the fixation */ |
| 83279 | 83452 | Expr *pExpr /* The expression to be fixed to one database */ |
| 83280 | 83453 | ){ |
| 83281 | 83454 | while( pExpr ){ |
| 83455 | + if( pExpr->op==TK_VARIABLE ){ |
| 83456 | + if( pFix->pParse->db->init.busy ){ |
| 83457 | + pExpr->op = TK_NULL; |
| 83458 | + }else{ |
| 83459 | + sqlite3ErrorMsg(pFix->pParse, "%s cannot use variables", pFix->zType); |
| 83460 | + return 1; |
| 83461 | + } |
| 83462 | + } |
| 83282 | 83463 | if( ExprHasProperty(pExpr, EP_TokenOnly) ) break; |
| 83283 | 83464 | if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 83284 | 83465 | if( sqlite3FixSelect(pFix, pExpr->x.pSelect) ) return 1; |
| 83285 | 83466 | }else{ |
| 83286 | 83467 | if( sqlite3FixExprList(pFix, pExpr->x.pList) ) return 1; |
| | @@ -84460,11 +84641,11 @@ |
| 84460 | 84641 | } |
| 84461 | 84642 | pTable->zName = zName; |
| 84462 | 84643 | pTable->iPKey = -1; |
| 84463 | 84644 | pTable->pSchema = db->aDb[iDb].pSchema; |
| 84464 | 84645 | pTable->nRef = 1; |
| 84465 | | - pTable->nRowEst = 1000000; |
| 84646 | + pTable->nRowEst = 1048576; |
| 84466 | 84647 | assert( pParse->pNewTable==0 ); |
| 84467 | 84648 | pParse->pNewTable = pTable; |
| 84468 | 84649 | |
| 84469 | 84650 | /* If this is the magic sqlite_sequence table used by autoincrement, |
| 84470 | 84651 | ** then record a pointer to this table in the main database structure |
| | @@ -84607,10 +84788,11 @@ |
| 84607 | 84788 | /* If there is no type specified, columns have the default affinity |
| 84608 | 84789 | ** 'NONE'. If there is a type specified, then sqlite3AddColumnType() will |
| 84609 | 84790 | ** be called next to set pCol->affinity correctly. |
| 84610 | 84791 | */ |
| 84611 | 84792 | pCol->affinity = SQLITE_AFF_NONE; |
| 84793 | + pCol->szEst = 1; |
| 84612 | 84794 | p->nCol++; |
| 84613 | 84795 | } |
| 84614 | 84796 | |
| 84615 | 84797 | /* |
| 84616 | 84798 | ** This routine is called by the parser while in the middle of |
| | @@ -84648,26 +84830,30 @@ |
| 84648 | 84830 | ** 'DOUB' | SQLITE_AFF_REAL |
| 84649 | 84831 | ** |
| 84650 | 84832 | ** If none of the substrings in the above table are found, |
| 84651 | 84833 | ** SQLITE_AFF_NUMERIC is returned. |
| 84652 | 84834 | */ |
| 84653 | | -SQLITE_PRIVATE char sqlite3AffinityType(const char *zIn){ |
| 84835 | +SQLITE_PRIVATE char sqlite3AffinityType(const char *zIn, u8 *pszEst){ |
| 84654 | 84836 | u32 h = 0; |
| 84655 | 84837 | char aff = SQLITE_AFF_NUMERIC; |
| 84838 | + const char *zChar = 0; |
| 84656 | 84839 | |
| 84657 | | - if( zIn ) while( zIn[0] ){ |
| 84840 | + if( zIn==0 ) return aff; |
| 84841 | + while( zIn[0] ){ |
| 84658 | 84842 | h = (h<<8) + sqlite3UpperToLower[(*zIn)&0xff]; |
| 84659 | 84843 | zIn++; |
| 84660 | 84844 | if( h==(('c'<<24)+('h'<<16)+('a'<<8)+'r') ){ /* CHAR */ |
| 84661 | | - aff = SQLITE_AFF_TEXT; |
| 84845 | + aff = SQLITE_AFF_TEXT; |
| 84846 | + zChar = zIn; |
| 84662 | 84847 | }else if( h==(('c'<<24)+('l'<<16)+('o'<<8)+'b') ){ /* CLOB */ |
| 84663 | 84848 | aff = SQLITE_AFF_TEXT; |
| 84664 | 84849 | }else if( h==(('t'<<24)+('e'<<16)+('x'<<8)+'t') ){ /* TEXT */ |
| 84665 | 84850 | aff = SQLITE_AFF_TEXT; |
| 84666 | 84851 | }else if( h==(('b'<<24)+('l'<<16)+('o'<<8)+'b') /* BLOB */ |
| 84667 | 84852 | && (aff==SQLITE_AFF_NUMERIC || aff==SQLITE_AFF_REAL) ){ |
| 84668 | 84853 | aff = SQLITE_AFF_NONE; |
| 84854 | + if( zIn[0]=='(' ) zChar = zIn; |
| 84669 | 84855 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 84670 | 84856 | }else if( h==(('r'<<24)+('e'<<16)+('a'<<8)+'l') /* REAL */ |
| 84671 | 84857 | && aff==SQLITE_AFF_NUMERIC ){ |
| 84672 | 84858 | aff = SQLITE_AFF_REAL; |
| 84673 | 84859 | }else if( h==(('f'<<24)+('l'<<16)+('o'<<8)+'a') /* FLOA */ |
| | @@ -84681,10 +84867,32 @@ |
| 84681 | 84867 | aff = SQLITE_AFF_INTEGER; |
| 84682 | 84868 | break; |
| 84683 | 84869 | } |
| 84684 | 84870 | } |
| 84685 | 84871 | |
| 84872 | + /* If pszEst is not NULL, store an estimate of the field size. The |
| 84873 | + ** estimate is scaled so that the size of an integer is 1. */ |
| 84874 | + if( pszEst ){ |
| 84875 | + *pszEst = 1; /* default size is approx 4 bytes */ |
| 84876 | + if( aff<=SQLITE_AFF_NONE ){ |
| 84877 | + if( zChar ){ |
| 84878 | + while( zChar[0] ){ |
| 84879 | + if( sqlite3Isdigit(zChar[0]) ){ |
| 84880 | + int v = 0; |
| 84881 | + sqlite3GetInt32(zChar, &v); |
| 84882 | + v = v/4 + 1; |
| 84883 | + if( v>255 ) v = 255; |
| 84884 | + *pszEst = v; /* BLOB(k), VARCHAR(k), CHAR(k) -> r=(k/4+1) */ |
| 84885 | + break; |
| 84886 | + } |
| 84887 | + zChar++; |
| 84888 | + } |
| 84889 | + }else{ |
| 84890 | + *pszEst = 5; /* BLOB, TEXT, CLOB -> r=5 (approx 20 bytes)*/ |
| 84891 | + } |
| 84892 | + } |
| 84893 | + } |
| 84686 | 84894 | return aff; |
| 84687 | 84895 | } |
| 84688 | 84896 | |
| 84689 | 84897 | /* |
| 84690 | 84898 | ** This routine is called by the parser while in the middle of |
| | @@ -84702,11 +84910,11 @@ |
| 84702 | 84910 | p = pParse->pNewTable; |
| 84703 | 84911 | if( p==0 || NEVER(p->nCol<1) ) return; |
| 84704 | 84912 | pCol = &p->aCol[p->nCol-1]; |
| 84705 | 84913 | assert( pCol->zType==0 ); |
| 84706 | 84914 | pCol->zType = sqlite3NameFromToken(pParse->db, pType); |
| 84707 | | - pCol->affinity = sqlite3AffinityType(pCol->zType); |
| 84915 | + pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst); |
| 84708 | 84916 | } |
| 84709 | 84917 | |
| 84710 | 84918 | /* |
| 84711 | 84919 | ** The expression is the default value for the most recently added column |
| 84712 | 84920 | ** of the table currently under construction. |
| | @@ -85050,18 +85258,46 @@ |
| 85050 | 85258 | testcase( pCol->affinity==SQLITE_AFF_REAL ); |
| 85051 | 85259 | |
| 85052 | 85260 | zType = azType[pCol->affinity - SQLITE_AFF_TEXT]; |
| 85053 | 85261 | len = sqlite3Strlen30(zType); |
| 85054 | 85262 | assert( pCol->affinity==SQLITE_AFF_NONE |
| 85055 | | - || pCol->affinity==sqlite3AffinityType(zType) ); |
| 85263 | + || pCol->affinity==sqlite3AffinityType(zType, 0) ); |
| 85056 | 85264 | memcpy(&zStmt[k], zType, len); |
| 85057 | 85265 | k += len; |
| 85058 | 85266 | assert( k<=n ); |
| 85059 | 85267 | } |
| 85060 | 85268 | sqlite3_snprintf(n-k, &zStmt[k], "%s", zEnd); |
| 85061 | 85269 | return zStmt; |
| 85062 | 85270 | } |
| 85271 | + |
| 85272 | +/* |
| 85273 | +** Estimate the total row width for a table. |
| 85274 | +*/ |
| 85275 | +static void estimateTableWidth(Table *pTab){ |
| 85276 | + unsigned wTable = 0; |
| 85277 | + const Column *pTabCol; |
| 85278 | + int i; |
| 85279 | + for(i=pTab->nCol, pTabCol=pTab->aCol; i>0; i--, pTabCol++){ |
| 85280 | + wTable += pTabCol->szEst; |
| 85281 | + } |
| 85282 | + if( pTab->iPKey<0 ) wTable++; |
| 85283 | + pTab->szTabRow = sqlite3LogEst(wTable*4); |
| 85284 | +} |
| 85285 | + |
| 85286 | +/* |
| 85287 | +** Estimate the average size of a row for an index. |
| 85288 | +*/ |
| 85289 | +static void estimateIndexWidth(Index *pIdx){ |
| 85290 | + unsigned wIndex = 1; |
| 85291 | + int i; |
| 85292 | + const Column *aCol = pIdx->pTable->aCol; |
| 85293 | + for(i=0; i<pIdx->nColumn; i++){ |
| 85294 | + assert( pIdx->aiColumn[i]>=0 && pIdx->aiColumn[i]<pIdx->pTable->nCol ); |
| 85295 | + wIndex += aCol[pIdx->aiColumn[i]].szEst; |
| 85296 | + } |
| 85297 | + pIdx->szIdxRow = sqlite3LogEst(wIndex*4); |
| 85298 | +} |
| 85063 | 85299 | |
| 85064 | 85300 | /* |
| 85065 | 85301 | ** This routine is called to report the final ")" that terminates |
| 85066 | 85302 | ** a CREATE TABLE statement. |
| 85067 | 85303 | ** |
| | @@ -85085,13 +85321,14 @@ |
| 85085 | 85321 | Parse *pParse, /* Parse context */ |
| 85086 | 85322 | Token *pCons, /* The ',' token after the last column defn. */ |
| 85087 | 85323 | Token *pEnd, /* The final ')' token in the CREATE TABLE */ |
| 85088 | 85324 | Select *pSelect /* Select from a "CREATE ... AS SELECT" */ |
| 85089 | 85325 | ){ |
| 85090 | | - Table *p; |
| 85091 | | - sqlite3 *db = pParse->db; |
| 85092 | | - int iDb; |
| 85326 | + Table *p; /* The new table */ |
| 85327 | + sqlite3 *db = pParse->db; /* The database connection */ |
| 85328 | + int iDb; /* Database in which the table lives */ |
| 85329 | + Index *pIdx; /* An implied index of the table */ |
| 85093 | 85330 | |
| 85094 | 85331 | if( (pEnd==0 && pSelect==0) || db->mallocFailed ){ |
| 85095 | 85332 | return; |
| 85096 | 85333 | } |
| 85097 | 85334 | p = pParse->pNewTable; |
| | @@ -85106,10 +85343,16 @@ |
| 85106 | 85343 | */ |
| 85107 | 85344 | if( p->pCheck ){ |
| 85108 | 85345 | sqlite3ResolveSelfReference(pParse, p, NC_IsCheck, 0, p->pCheck); |
| 85109 | 85346 | } |
| 85110 | 85347 | #endif /* !defined(SQLITE_OMIT_CHECK) */ |
| 85348 | + |
| 85349 | + /* Estimate the average row size for the table and for all implied indices */ |
| 85350 | + estimateTableWidth(p); |
| 85351 | + for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 85352 | + estimateIndexWidth(pIdx); |
| 85353 | + } |
| 85111 | 85354 | |
| 85112 | 85355 | /* If the db->init.busy is 1 it means we are reading the SQL off the |
| 85113 | 85356 | ** "sqlite_master" or "sqlite_temp_master" table on the disk. |
| 85114 | 85357 | ** So do not write to the disk again. Extract the root page number |
| 85115 | 85358 | ** for the table from the db->init.newTnum field. (The page number |
| | @@ -85303,13 +85546,12 @@ |
| 85303 | 85546 | sqlite3SelectDelete(db, pSelect); |
| 85304 | 85547 | return; |
| 85305 | 85548 | } |
| 85306 | 85549 | sqlite3TwoPartName(pParse, pName1, pName2, &pName); |
| 85307 | 85550 | iDb = sqlite3SchemaToIndex(db, p->pSchema); |
| 85308 | | - if( sqlite3FixInit(&sFix, pParse, iDb, "view", pName) |
| 85309 | | - && sqlite3FixSelect(&sFix, pSelect) |
| 85310 | | - ){ |
| 85551 | + sqlite3FixInit(&sFix, pParse, iDb, "view", pName); |
| 85552 | + if( sqlite3FixSelect(&sFix, pSelect) ){ |
| 85311 | 85553 | sqlite3SelectDelete(db, pSelect); |
| 85312 | 85554 | return; |
| 85313 | 85555 | } |
| 85314 | 85556 | |
| 85315 | 85557 | /* Make a copy of the entire SELECT statement that defines the view. |
| | @@ -86066,13 +86308,14 @@ |
| 86066 | 86308 | sqlite3 *db = pParse->db; |
| 86067 | 86309 | Db *pDb; /* The specific table containing the indexed database */ |
| 86068 | 86310 | int iDb; /* Index of the database that is being written */ |
| 86069 | 86311 | Token *pName = 0; /* Unqualified name of the index to create */ |
| 86070 | 86312 | struct ExprList_item *pListItem; /* For looping over pList */ |
| 86071 | | - int nCol; |
| 86072 | | - int nExtra = 0; |
| 86073 | | - char *zExtra; |
| 86313 | + const Column *pTabCol; /* A column in the table */ |
| 86314 | + int nCol; /* Number of columns */ |
| 86315 | + int nExtra = 0; /* Space allocated for zExtra[] */ |
| 86316 | + char *zExtra; /* Extra space after the Index object */ |
| 86074 | 86317 | |
| 86075 | 86318 | assert( pParse->nErr==0 ); /* Never called with prior errors */ |
| 86076 | 86319 | if( db->mallocFailed || IN_DECLARE_VTAB ){ |
| 86077 | 86320 | goto exit_create_index; |
| 86078 | 86321 | } |
| | @@ -86105,13 +86348,12 @@ |
| 86105 | 86348 | iDb = 1; |
| 86106 | 86349 | } |
| 86107 | 86350 | } |
| 86108 | 86351 | #endif |
| 86109 | 86352 | |
| 86110 | | - if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) && |
| 86111 | | - sqlite3FixSrcList(&sFix, pTblName) |
| 86112 | | - ){ |
| 86353 | + sqlite3FixInit(&sFix, pParse, iDb, "index", pName); |
| 86354 | + if( sqlite3FixSrcList(&sFix, pTblName) ){ |
| 86113 | 86355 | /* Because the parser constructs pTblName from a single identifier, |
| 86114 | 86356 | ** sqlite3FixSrcList can never fail. */ |
| 86115 | 86357 | assert(0); |
| 86116 | 86358 | } |
| 86117 | 86359 | pTab = sqlite3LocateTableItem(pParse, 0, &pTblName->a[0]); |
| | @@ -86296,11 +86538,10 @@ |
| 86296 | 86538 | ** same column more than once cannot be an error because that would |
| 86297 | 86539 | ** break backwards compatibility - it needs to be a warning. |
| 86298 | 86540 | */ |
| 86299 | 86541 | for(i=0, pListItem=pList->a; i<pList->nExpr; i++, pListItem++){ |
| 86300 | 86542 | const char *zColName = pListItem->zName; |
| 86301 | | - Column *pTabCol; |
| 86302 | 86543 | int requestedSortOrder; |
| 86303 | 86544 | char *zColl; /* Collation sequence name */ |
| 86304 | 86545 | |
| 86305 | 86546 | for(j=0, pTabCol=pTab->aCol; j<pTab->nCol; j++, pTabCol++){ |
| 86306 | 86547 | if( sqlite3StrICmp(zColName, pTabCol->zName)==0 ) break; |
| | @@ -86333,10 +86574,11 @@ |
| 86333 | 86574 | requestedSortOrder = pListItem->sortOrder & sortOrderMask; |
| 86334 | 86575 | pIndex->aSortOrder[i] = (u8)requestedSortOrder; |
| 86335 | 86576 | if( pTab->aCol[j].notNull==0 ) pIndex->uniqNotNull = 0; |
| 86336 | 86577 | } |
| 86337 | 86578 | sqlite3DefaultRowEst(pIndex); |
| 86579 | + if( pParse->pNewTable==0 ) estimateIndexWidth(pIndex); |
| 86338 | 86580 | |
| 86339 | 86581 | if( pTab==pParse->pNewTable ){ |
| 86340 | 86582 | /* This routine has been called to create an automatic index as a |
| 86341 | 86583 | ** result of a PRIMARY KEY or UNIQUE clause on a column definition, or |
| 86342 | 86584 | ** a PRIMARY KEY or UNIQUE clause following the column definitions. |
| | @@ -88238,10 +88480,11 @@ |
| 88238 | 88480 | ** API function sqlite3_count_changes) to be set incorrectly. */ |
| 88239 | 88481 | if( rcauth==SQLITE_OK && pWhere==0 && !pTrigger && !IsVirtual(pTab) |
| 88240 | 88482 | && 0==sqlite3FkRequired(pParse, pTab, 0, 0) |
| 88241 | 88483 | ){ |
| 88242 | 88484 | assert( !isView ); |
| 88485 | + sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName); |
| 88243 | 88486 | sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt, |
| 88244 | 88487 | pTab->zName, P4_STATIC); |
| 88245 | 88488 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 88246 | 88489 | assert( pIdx->pSchema==pTab->pSchema ); |
| 88247 | 88490 | sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb); |
| | @@ -90943,11 +91186,11 @@ |
| 90943 | 91186 | ** generating any VDBE code. If one can be found, then jump over |
| 90944 | 91187 | ** the entire DELETE if there are no outstanding deferred constraints |
| 90945 | 91188 | ** when this statement is run. */ |
| 90946 | 91189 | FKey *p; |
| 90947 | 91190 | for(p=pTab->pFKey; p; p=p->pNextFrom){ |
| 90948 | | - if( p->isDeferred ) break; |
| 91191 | + if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break; |
| 90949 | 91192 | } |
| 90950 | 91193 | if( !p ) return; |
| 90951 | 91194 | iSkip = sqlite3VdbeMakeLabel(v); |
| 90952 | 91195 | sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); |
| 90953 | 91196 | } |
| | @@ -90957,15 +91200,22 @@ |
| 90957 | 91200 | pParse->disableTriggers = 0; |
| 90958 | 91201 | |
| 90959 | 91202 | /* If the DELETE has generated immediate foreign key constraint |
| 90960 | 91203 | ** violations, halt the VDBE and return an error at this point, before |
| 90961 | 91204 | ** any modifications to the schema are made. This is because statement |
| 90962 | | - ** transactions are not able to rollback schema changes. */ |
| 90963 | | - sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2); |
| 90964 | | - sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY, |
| 90965 | | - OE_Abort, "foreign key constraint failed", P4_STATIC |
| 90966 | | - ); |
| 91205 | + ** transactions are not able to rollback schema changes. |
| 91206 | + ** |
| 91207 | + ** If the SQLITE_DeferFKs flag is set, then this is not required, as |
| 91208 | + ** the statement transaction will not be rolled back even if FK |
| 91209 | + ** constraints are violated. |
| 91210 | + */ |
| 91211 | + if( (db->flags & SQLITE_DeferFKs)==0 ){ |
| 91212 | + sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2); |
| 91213 | + sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY, |
| 91214 | + OE_Abort, "foreign key constraint failed", P4_STATIC |
| 91215 | + ); |
| 91216 | + } |
| 90967 | 91217 | |
| 90968 | 91218 | if( iSkip ){ |
| 90969 | 91219 | sqlite3VdbeResolveLabel(v, iSkip); |
| 90970 | 91220 | } |
| 90971 | 91221 | } |
| | @@ -93487,10 +93737,11 @@ |
| 93487 | 93737 | (char*)pKey, P4_KEYINFO_HANDOFF); |
| 93488 | 93738 | VdbeComment((v, "%s", pSrcIdx->zName)); |
| 93489 | 93739 | pKey = sqlite3IndexKeyinfo(pParse, pDestIdx); |
| 93490 | 93740 | sqlite3VdbeAddOp4(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest, |
| 93491 | 93741 | (char*)pKey, P4_KEYINFO_HANDOFF); |
| 93742 | + sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR); |
| 93492 | 93743 | VdbeComment((v, "%s", pDestIdx->zName)); |
| 93493 | 93744 | addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); |
| 93494 | 93745 | sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData); |
| 93495 | 93746 | sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1); |
| 93496 | 93747 | sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); |
| | @@ -94962,193 +95213,382 @@ |
| 94962 | 95213 | #define PragTyp_MMAP_SIZE 23 |
| 94963 | 95214 | #define PragTyp_PAGE_SIZE 24 |
| 94964 | 95215 | #define PragTyp_SECURE_DELETE 25 |
| 94965 | 95216 | #define PragTyp_SHRINK_MEMORY 26 |
| 94966 | 95217 | #define PragTyp_SOFT_HEAP_LIMIT 27 |
| 94967 | | -#define PragTyp_SYNCHRONOUS 28 |
| 94968 | | -#define PragTyp_TABLE_INFO 29 |
| 94969 | | -#define PragTyp_TEMP_STORE 30 |
| 94970 | | -#define PragTyp_TEMP_STORE_DIRECTORY 31 |
| 94971 | | -#define PragTyp_WAL_AUTOCHECKPOINT 32 |
| 94972 | | -#define PragTyp_WAL_CHECKPOINT 33 |
| 94973 | | -#define PragTyp_ACTIVATE_EXTENSIONS 34 |
| 94974 | | -#define PragTyp_HEXKEY 35 |
| 94975 | | -#define PragTyp_KEY 36 |
| 94976 | | -#define PragTyp_REKEY 37 |
| 94977 | | -#define PragTyp_LOCK_STATUS 38 |
| 94978 | | -#define PragTyp_PARSER_TRACE 39 |
| 95218 | +#define PragTyp_STATS 28 |
| 95219 | +#define PragTyp_SYNCHRONOUS 29 |
| 95220 | +#define PragTyp_TABLE_INFO 30 |
| 95221 | +#define PragTyp_TEMP_STORE 31 |
| 95222 | +#define PragTyp_TEMP_STORE_DIRECTORY 32 |
| 95223 | +#define PragTyp_WAL_AUTOCHECKPOINT 33 |
| 95224 | +#define PragTyp_WAL_CHECKPOINT 34 |
| 95225 | +#define PragTyp_ACTIVATE_EXTENSIONS 35 |
| 95226 | +#define PragTyp_HEXKEY 36 |
| 95227 | +#define PragTyp_KEY 37 |
| 95228 | +#define PragTyp_REKEY 38 |
| 95229 | +#define PragTyp_LOCK_STATUS 39 |
| 95230 | +#define PragTyp_PARSER_TRACE 40 |
| 95231 | +#define PragFlag_NeedSchema 0x01 |
| 94979 | 95232 | static const struct sPragmaNames { |
| 94980 | 95233 | const char *const zName; /* Name of pragma */ |
| 94981 | 95234 | u8 ePragTyp; /* PragTyp_XXX value */ |
| 95235 | + u8 mPragFlag; /* Zero or more PragFlag_XXX values */ |
| 94982 | 95236 | u32 iArg; /* Extra argument */ |
| 94983 | 95237 | } aPragmaNames[] = { |
| 94984 | 95238 | #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD) |
| 94985 | | - { "activate_extensions", PragTyp_ACTIVATE_EXTENSIONS, 0 }, |
| 95239 | + { /* zName: */ "activate_extensions", |
| 95240 | + /* ePragTyp: */ PragTyp_ACTIVATE_EXTENSIONS, |
| 95241 | + /* ePragFlag: */ 0, |
| 95242 | + /* iArg: */ 0 }, |
| 94986 | 95243 | #endif |
| 94987 | 95244 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 94988 | | - { "application_id", PragTyp_HEADER_VALUE, 0 }, |
| 95245 | + { /* zName: */ "application_id", |
| 95246 | + /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 95247 | + /* ePragFlag: */ 0, |
| 95248 | + /* iArg: */ 0 }, |
| 94989 | 95249 | #endif |
| 94990 | 95250 | #if !defined(SQLITE_OMIT_AUTOVACUUM) |
| 94991 | | - { "auto_vacuum", PragTyp_AUTO_VACUUM, 0 }, |
| 95251 | + { /* zName: */ "auto_vacuum", |
| 95252 | + /* ePragTyp: */ PragTyp_AUTO_VACUUM, |
| 95253 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95254 | + /* iArg: */ 0 }, |
| 94992 | 95255 | #endif |
| 94993 | 95256 | #if !defined(SQLITE_OMIT_AUTOMATIC_INDEX) |
| 94994 | | - { "automatic_index", PragTyp_FLAG, |
| 94995 | | - SQLITE_AutoIndex }, |
| 95257 | + { /* zName: */ "automatic_index", |
| 95258 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95259 | + /* ePragFlag: */ 0, |
| 95260 | + /* iArg: */ SQLITE_AutoIndex }, |
| 94996 | 95261 | #endif |
| 94997 | | - { "busy_timeout", PragTyp_BUSY_TIMEOUT, 0 }, |
| 95262 | + { /* zName: */ "busy_timeout", |
| 95263 | + /* ePragTyp: */ PragTyp_BUSY_TIMEOUT, |
| 95264 | + /* ePragFlag: */ 0, |
| 95265 | + /* iArg: */ 0 }, |
| 94998 | 95266 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 94999 | | - { "cache_size", PragTyp_CACHE_SIZE, 0 }, |
| 95267 | + { /* zName: */ "cache_size", |
| 95268 | + /* ePragTyp: */ PragTyp_CACHE_SIZE, |
| 95269 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95270 | + /* iArg: */ 0 }, |
| 95000 | 95271 | #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 }, |
| 95272 | + { /* zName: */ "cache_spill", |
| 95273 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95274 | + /* ePragFlag: */ 0, |
| 95275 | + /* iArg: */ SQLITE_CacheSpill }, |
| 95276 | + { /* zName: */ "case_sensitive_like", |
| 95277 | + /* ePragTyp: */ PragTyp_CASE_SENSITIVE_LIKE, |
| 95278 | + /* ePragFlag: */ 0, |
| 95279 | + /* iArg: */ 0 }, |
| 95280 | + { /* zName: */ "checkpoint_fullfsync", |
| 95281 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95282 | + /* ePragFlag: */ 0, |
| 95283 | + /* iArg: */ SQLITE_CkptFullFSync }, |
| 95006 | 95284 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 95007 | | - { "collation_list", PragTyp_COLLATION_LIST, 0 }, |
| 95285 | + { /* zName: */ "collation_list", |
| 95286 | + /* ePragTyp: */ PragTyp_COLLATION_LIST, |
| 95287 | + /* ePragFlag: */ 0, |
| 95288 | + /* iArg: */ 0 }, |
| 95008 | 95289 | #endif |
| 95009 | 95290 | #if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS) |
| 95010 | | - { "compile_options", PragTyp_COMPILE_OPTIONS, 0 }, |
| 95291 | + { /* zName: */ "compile_options", |
| 95292 | + /* ePragTyp: */ PragTyp_COMPILE_OPTIONS, |
| 95293 | + /* ePragFlag: */ 0, |
| 95294 | + /* iArg: */ 0 }, |
| 95011 | 95295 | #endif |
| 95012 | | - { "count_changes", PragTyp_FLAG, |
| 95013 | | - SQLITE_CountRows }, |
| 95296 | + { /* zName: */ "count_changes", |
| 95297 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95298 | + /* ePragFlag: */ 0, |
| 95299 | + /* iArg: */ SQLITE_CountRows }, |
| 95014 | 95300 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN |
| 95015 | | - { "data_store_directory", PragTyp_DATA_STORE_DIRECTORY, 0 }, |
| 95301 | + { /* zName: */ "data_store_directory", |
| 95302 | + /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY, |
| 95303 | + /* ePragFlag: */ 0, |
| 95304 | + /* iArg: */ 0 }, |
| 95016 | 95305 | #endif |
| 95017 | 95306 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 95018 | | - { "database_list", PragTyp_DATABASE_LIST, 0 }, |
| 95307 | + { /* zName: */ "database_list", |
| 95308 | + /* ePragTyp: */ PragTyp_DATABASE_LIST, |
| 95309 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95310 | + /* iArg: */ 0 }, |
| 95019 | 95311 | #endif |
| 95020 | 95312 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) |
| 95021 | | - { "default_cache_size", PragTyp_DEFAULT_CACHE_SIZE, 0 }, |
| 95313 | + { /* zName: */ "default_cache_size", |
| 95314 | + /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE, |
| 95315 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95316 | + /* iArg: */ 0 }, |
| 95022 | 95317 | #endif |
| 95023 | 95318 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
| 95024 | | - { "defer_foreign_keys", PragTyp_FLAG, |
| 95025 | | - SQLITE_DeferFKs }, |
| 95319 | + { /* zName: */ "defer_foreign_keys", |
| 95320 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95321 | + /* ePragFlag: */ 0, |
| 95322 | + /* iArg: */ SQLITE_DeferFKs }, |
| 95026 | 95323 | #endif |
| 95027 | | - { "empty_result_callbacks", PragTyp_FLAG, |
| 95028 | | - SQLITE_NullCallback }, |
| 95324 | + { /* zName: */ "empty_result_callbacks", |
| 95325 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95326 | + /* ePragFlag: */ 0, |
| 95327 | + /* iArg: */ SQLITE_NullCallback }, |
| 95029 | 95328 | #if !defined(SQLITE_OMIT_UTF16) |
| 95030 | | - { "encoding", PragTyp_ENCODING, 0 }, |
| 95329 | + { /* zName: */ "encoding", |
| 95330 | + /* ePragTyp: */ PragTyp_ENCODING, |
| 95331 | + /* ePragFlag: */ 0, |
| 95332 | + /* iArg: */ 0 }, |
| 95031 | 95333 | #endif |
| 95032 | 95334 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
| 95033 | | - { "foreign_key_check", PragTyp_FOREIGN_KEY_CHECK, 0 }, |
| 95335 | + { /* zName: */ "foreign_key_check", |
| 95336 | + /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK, |
| 95337 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95338 | + /* iArg: */ 0 }, |
| 95034 | 95339 | #endif |
| 95035 | 95340 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) |
| 95036 | | - { "foreign_key_list", PragTyp_FOREIGN_KEY_LIST, 0 }, |
| 95341 | + { /* zName: */ "foreign_key_list", |
| 95342 | + /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST, |
| 95343 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95344 | + /* iArg: */ 0 }, |
| 95037 | 95345 | #endif |
| 95038 | 95346 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
| 95039 | | - { "foreign_keys", PragTyp_FLAG, |
| 95040 | | - SQLITE_ForeignKeys }, |
| 95347 | + { /* zName: */ "foreign_keys", |
| 95348 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95349 | + /* ePragFlag: */ 0, |
| 95350 | + /* iArg: */ SQLITE_ForeignKeys }, |
| 95041 | 95351 | #endif |
| 95042 | 95352 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 95043 | | - { "freelist_count", PragTyp_HEADER_VALUE, 0 }, |
| 95353 | + { /* zName: */ "freelist_count", |
| 95354 | + /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 95355 | + /* ePragFlag: */ 0, |
| 95356 | + /* iArg: */ 0 }, |
| 95044 | 95357 | #endif |
| 95045 | | - { "full_column_names", PragTyp_FLAG, |
| 95046 | | - SQLITE_FullColNames }, |
| 95047 | | - { "fullfsync", PragTyp_FLAG, |
| 95048 | | - SQLITE_FullFSync }, |
| 95358 | + { /* zName: */ "full_column_names", |
| 95359 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95360 | + /* ePragFlag: */ 0, |
| 95361 | + /* iArg: */ SQLITE_FullColNames }, |
| 95362 | + { /* zName: */ "fullfsync", |
| 95363 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95364 | + /* ePragFlag: */ 0, |
| 95365 | + /* iArg: */ SQLITE_FullFSync }, |
| 95049 | 95366 | #if defined(SQLITE_HAS_CODEC) |
| 95050 | | - { "hexkey", PragTyp_HEXKEY, 0 }, |
| 95367 | + { /* zName: */ "hexkey", |
| 95368 | + /* ePragTyp: */ PragTyp_HEXKEY, |
| 95369 | + /* ePragFlag: */ 0, |
| 95370 | + /* iArg: */ 0 }, |
| 95371 | + { /* zName: */ "hexrekey", |
| 95372 | + /* ePragTyp: */ PragTyp_HEXKEY, |
| 95373 | + /* ePragFlag: */ 0, |
| 95374 | + /* iArg: */ 0 }, |
| 95051 | 95375 | #endif |
| 95052 | 95376 | #if !defined(SQLITE_OMIT_CHECK) |
| 95053 | | - { "ignore_check_constraints", PragTyp_FLAG, |
| 95054 | | - SQLITE_IgnoreChecks }, |
| 95377 | + { /* zName: */ "ignore_check_constraints", |
| 95378 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95379 | + /* ePragFlag: */ 0, |
| 95380 | + /* iArg: */ SQLITE_IgnoreChecks }, |
| 95055 | 95381 | #endif |
| 95056 | 95382 | #if !defined(SQLITE_OMIT_AUTOVACUUM) |
| 95057 | | - { "incremental_vacuum", PragTyp_INCREMENTAL_VACUUM, 0 }, |
| 95383 | + { /* zName: */ "incremental_vacuum", |
| 95384 | + /* ePragTyp: */ PragTyp_INCREMENTAL_VACUUM, |
| 95385 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95386 | + /* iArg: */ 0 }, |
| 95058 | 95387 | #endif |
| 95059 | 95388 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 95060 | | - { "index_info", PragTyp_INDEX_INFO, 0 }, |
| 95061 | | - { "index_list", PragTyp_INDEX_LIST, 0 }, |
| 95389 | + { /* zName: */ "index_info", |
| 95390 | + /* ePragTyp: */ PragTyp_INDEX_INFO, |
| 95391 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95392 | + /* iArg: */ 0 }, |
| 95393 | + { /* zName: */ "index_list", |
| 95394 | + /* ePragTyp: */ PragTyp_INDEX_LIST, |
| 95395 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95396 | + /* iArg: */ 0 }, |
| 95062 | 95397 | #endif |
| 95063 | 95398 | #if !defined(SQLITE_OMIT_INTEGRITY_CHECK) |
| 95064 | | - { "integrity_check", PragTyp_INTEGRITY_CHECK, 0 }, |
| 95399 | + { /* zName: */ "integrity_check", |
| 95400 | + /* ePragTyp: */ PragTyp_INTEGRITY_CHECK, |
| 95401 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95402 | + /* iArg: */ 0 }, |
| 95065 | 95403 | #endif |
| 95066 | 95404 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 95067 | | - { "journal_mode", PragTyp_JOURNAL_MODE, 0 }, |
| 95068 | | - { "journal_size_limit", PragTyp_JOURNAL_SIZE_LIMIT, 0 }, |
| 95405 | + { /* zName: */ "journal_mode", |
| 95406 | + /* ePragTyp: */ PragTyp_JOURNAL_MODE, |
| 95407 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95408 | + /* iArg: */ 0 }, |
| 95409 | + { /* zName: */ "journal_size_limit", |
| 95410 | + /* ePragTyp: */ PragTyp_JOURNAL_SIZE_LIMIT, |
| 95411 | + /* ePragFlag: */ 0, |
| 95412 | + /* iArg: */ 0 }, |
| 95069 | 95413 | #endif |
| 95070 | 95414 | #if defined(SQLITE_HAS_CODEC) |
| 95071 | | - { "key", PragTyp_KEY, 0 }, |
| 95415 | + { /* zName: */ "key", |
| 95416 | + /* ePragTyp: */ PragTyp_KEY, |
| 95417 | + /* ePragFlag: */ 0, |
| 95418 | + /* iArg: */ 0 }, |
| 95072 | 95419 | #endif |
| 95073 | | - { "legacy_file_format", PragTyp_FLAG, |
| 95074 | | - SQLITE_LegacyFileFmt }, |
| 95420 | + { /* zName: */ "legacy_file_format", |
| 95421 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95422 | + /* ePragFlag: */ 0, |
| 95423 | + /* iArg: */ SQLITE_LegacyFileFmt }, |
| 95075 | 95424 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE |
| 95076 | | - { "lock_proxy_file", PragTyp_LOCK_PROXY_FILE, 0 }, |
| 95425 | + { /* zName: */ "lock_proxy_file", |
| 95426 | + /* ePragTyp: */ PragTyp_LOCK_PROXY_FILE, |
| 95427 | + /* ePragFlag: */ 0, |
| 95428 | + /* iArg: */ 0 }, |
| 95077 | 95429 | #endif |
| 95078 | 95430 | #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 }, |
| 95431 | + { /* zName: */ "lock_status", |
| 95432 | + /* ePragTyp: */ PragTyp_LOCK_STATUS, |
| 95433 | + /* ePragFlag: */ 0, |
| 95434 | + /* iArg: */ 0 }, |
| 95435 | +#endif |
| 95436 | +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 95437 | + { /* zName: */ "locking_mode", |
| 95438 | + /* ePragTyp: */ PragTyp_LOCKING_MODE, |
| 95439 | + /* ePragFlag: */ 0, |
| 95440 | + /* iArg: */ 0 }, |
| 95441 | + { /* zName: */ "max_page_count", |
| 95442 | + /* ePragTyp: */ PragTyp_PAGE_COUNT, |
| 95443 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95444 | + /* iArg: */ 0 }, |
| 95445 | + { /* zName: */ "mmap_size", |
| 95446 | + /* ePragTyp: */ PragTyp_MMAP_SIZE, |
| 95447 | + /* ePragFlag: */ 0, |
| 95448 | + /* iArg: */ 0 }, |
| 95449 | + { /* zName: */ "page_count", |
| 95450 | + /* ePragTyp: */ PragTyp_PAGE_COUNT, |
| 95451 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95452 | + /* iArg: */ 0 }, |
| 95453 | + { /* zName: */ "page_size", |
| 95454 | + /* ePragTyp: */ PragTyp_PAGE_SIZE, |
| 95455 | + /* ePragFlag: */ 0, |
| 95456 | + /* iArg: */ 0 }, |
| 95457 | +#endif |
| 95458 | +#if defined(SQLITE_DEBUG) |
| 95459 | + { /* zName: */ "parser_trace", |
| 95460 | + /* ePragTyp: */ PragTyp_PARSER_TRACE, |
| 95461 | + /* ePragFlag: */ 0, |
| 95462 | + /* iArg: */ 0 }, |
| 95463 | +#endif |
| 95464 | + { /* zName: */ "query_only", |
| 95465 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95466 | + /* ePragFlag: */ 0, |
| 95467 | + /* iArg: */ SQLITE_QueryOnly }, |
| 95468 | +#if !defined(SQLITE_OMIT_INTEGRITY_CHECK) |
| 95469 | + { /* zName: */ "quick_check", |
| 95470 | + /* ePragTyp: */ PragTyp_INTEGRITY_CHECK, |
| 95471 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95472 | + /* iArg: */ 0 }, |
| 95473 | +#endif |
| 95474 | + { /* zName: */ "read_uncommitted", |
| 95475 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95476 | + /* ePragFlag: */ 0, |
| 95477 | + /* iArg: */ SQLITE_ReadUncommitted }, |
| 95478 | + { /* zName: */ "recursive_triggers", |
| 95479 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95480 | + /* ePragFlag: */ 0, |
| 95481 | + /* iArg: */ SQLITE_RecTriggers }, |
| 95482 | +#if defined(SQLITE_HAS_CODEC) |
| 95483 | + { /* zName: */ "rekey", |
| 95484 | + /* ePragTyp: */ PragTyp_REKEY, |
| 95485 | + /* ePragFlag: */ 0, |
| 95486 | + /* iArg: */ 0 }, |
| 95487 | +#endif |
| 95488 | + { /* zName: */ "reverse_unordered_selects", |
| 95489 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95490 | + /* ePragFlag: */ 0, |
| 95491 | + /* iArg: */ SQLITE_ReverseOrder }, |
| 95492 | +#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 95493 | + { /* zName: */ "schema_version", |
| 95494 | + /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 95495 | + /* ePragFlag: */ 0, |
| 95496 | + /* iArg: */ 0 }, |
| 95497 | +#endif |
| 95498 | +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 95499 | + { /* zName: */ "secure_delete", |
| 95500 | + /* ePragTyp: */ PragTyp_SECURE_DELETE, |
| 95501 | + /* ePragFlag: */ 0, |
| 95502 | + /* iArg: */ 0 }, |
| 95503 | +#endif |
| 95504 | + { /* zName: */ "short_column_names", |
| 95505 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95506 | + /* ePragFlag: */ 0, |
| 95507 | + /* iArg: */ SQLITE_ShortColNames }, |
| 95508 | + { /* zName: */ "shrink_memory", |
| 95509 | + /* ePragTyp: */ PragTyp_SHRINK_MEMORY, |
| 95510 | + /* ePragFlag: */ 0, |
| 95511 | + /* iArg: */ 0 }, |
| 95512 | + { /* zName: */ "soft_heap_limit", |
| 95513 | + /* ePragTyp: */ PragTyp_SOFT_HEAP_LIMIT, |
| 95514 | + /* ePragFlag: */ 0, |
| 95515 | + /* iArg: */ 0 }, |
| 95516 | +#if defined(SQLITE_DEBUG) |
| 95517 | + { /* zName: */ "sql_trace", |
| 95518 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95519 | + /* ePragFlag: */ 0, |
| 95520 | + /* iArg: */ SQLITE_SqlTrace }, |
| 95521 | +#endif |
| 95522 | +#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 95523 | + { /* zName: */ "stats", |
| 95524 | + /* ePragTyp: */ PragTyp_STATS, |
| 95525 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95526 | + /* iArg: */ 0 }, |
| 95527 | +#endif |
| 95528 | +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 95529 | + { /* zName: */ "synchronous", |
| 95530 | + /* ePragTyp: */ PragTyp_SYNCHRONOUS, |
| 95531 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95532 | + /* iArg: */ 0 }, |
| 95121 | 95533 | #endif |
| 95122 | 95534 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 95123 | | - { "table_info", PragTyp_TABLE_INFO, 0 }, |
| 95535 | + { /* zName: */ "table_info", |
| 95536 | + /* ePragTyp: */ PragTyp_TABLE_INFO, |
| 95537 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95538 | + /* iArg: */ 0 }, |
| 95124 | 95539 | #endif |
| 95125 | 95540 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 95126 | | - { "temp_store", PragTyp_TEMP_STORE, 0 }, |
| 95127 | | - { "temp_store_directory", PragTyp_TEMP_STORE_DIRECTORY, 0 }, |
| 95541 | + { /* zName: */ "temp_store", |
| 95542 | + /* ePragTyp: */ PragTyp_TEMP_STORE, |
| 95543 | + /* ePragFlag: */ 0, |
| 95544 | + /* iArg: */ 0 }, |
| 95545 | + { /* zName: */ "temp_store_directory", |
| 95546 | + /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY, |
| 95547 | + /* ePragFlag: */ 0, |
| 95548 | + /* iArg: */ 0 }, |
| 95128 | 95549 | #endif |
| 95129 | 95550 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 95130 | | - { "user_version", PragTyp_HEADER_VALUE, 0 }, |
| 95551 | + { /* zName: */ "user_version", |
| 95552 | + /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 95553 | + /* ePragFlag: */ 0, |
| 95554 | + /* iArg: */ 0 }, |
| 95131 | 95555 | #endif |
| 95132 | 95556 | #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 }, |
| 95557 | + { /* zName: */ "vdbe_addoptrace", |
| 95558 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95559 | + /* ePragFlag: */ 0, |
| 95560 | + /* iArg: */ SQLITE_VdbeAddopTrace }, |
| 95561 | + { /* zName: */ "vdbe_debug", |
| 95562 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95563 | + /* ePragFlag: */ 0, |
| 95564 | + /* iArg: */ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace }, |
| 95565 | + { /* zName: */ "vdbe_listing", |
| 95566 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95567 | + /* ePragFlag: */ 0, |
| 95568 | + /* iArg: */ SQLITE_VdbeListing }, |
| 95569 | + { /* zName: */ "vdbe_trace", |
| 95570 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95571 | + /* ePragFlag: */ 0, |
| 95572 | + /* iArg: */ SQLITE_VdbeTrace }, |
| 95141 | 95573 | #endif |
| 95142 | 95574 | #if !defined(SQLITE_OMIT_WAL) |
| 95143 | | - { "wal_autocheckpoint", PragTyp_WAL_AUTOCHECKPOINT, 0 }, |
| 95144 | | - { "wal_checkpoint", PragTyp_WAL_CHECKPOINT, 0 }, |
| 95575 | + { /* zName: */ "wal_autocheckpoint", |
| 95576 | + /* ePragTyp: */ PragTyp_WAL_AUTOCHECKPOINT, |
| 95577 | + /* ePragFlag: */ 0, |
| 95578 | + /* iArg: */ 0 }, |
| 95579 | + { /* zName: */ "wal_checkpoint", |
| 95580 | + /* ePragTyp: */ PragTyp_WAL_CHECKPOINT, |
| 95581 | + /* ePragFlag: */ PragFlag_NeedSchema, |
| 95582 | + /* iArg: */ 0 }, |
| 95145 | 95583 | #endif |
| 95146 | | - { "writable_schema", PragTyp_FLAG, |
| 95147 | | - SQLITE_WriteSchema|SQLITE_RecoveryMode }, |
| 95584 | + { /* zName: */ "writable_schema", |
| 95585 | + /* ePragTyp: */ PragTyp_FLAG, |
| 95586 | + /* ePragFlag: */ 0, |
| 95587 | + /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode }, |
| 95148 | 95588 | }; |
| 95149 | | -/* Number of pragmas: 55 on by default, 66 total. */ |
| 95589 | +/* Number of pragmas: 56 on by default, 68 total. */ |
| 95150 | 95590 | /* End of the automatically generated pragma table. |
| 95151 | 95591 | ***************************************************************************/ |
| 95152 | 95592 | |
| 95153 | 95593 | /* |
| 95154 | 95594 | ** Interpret the given string as a safety level. Return 0 for OFF, |
| | @@ -95476,10 +95916,15 @@ |
| 95476 | 95916 | }else{ |
| 95477 | 95917 | lwr = mid + 1; |
| 95478 | 95918 | } |
| 95479 | 95919 | } |
| 95480 | 95920 | if( lwr>upr ) goto pragma_out; |
| 95921 | + |
| 95922 | + /* Make sure the database schema is loaded if the pragma requires that */ |
| 95923 | + if( (aPragmaNames[mid].mPragFlag & PragFlag_NeedSchema)!=0 ){ |
| 95924 | + if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 95925 | + } |
| 95481 | 95926 | |
| 95482 | 95927 | /* Jump to the appropriate pragma handler */ |
| 95483 | 95928 | switch( aPragmaNames[mid].ePragTyp ){ |
| 95484 | 95929 | |
| 95485 | 95930 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) |
| | @@ -95510,11 +95955,10 @@ |
| 95510 | 95955 | { OP_Integer, 0, 1, 0}, /* 6 */ |
| 95511 | 95956 | { OP_Noop, 0, 0, 0}, |
| 95512 | 95957 | { OP_ResultRow, 1, 1, 0}, |
| 95513 | 95958 | }; |
| 95514 | 95959 | int addr; |
| 95515 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 95516 | 95960 | sqlite3VdbeUsesBtree(v, iDb); |
| 95517 | 95961 | if( !zRight ){ |
| 95518 | 95962 | sqlite3VdbeSetNumCols(v, 1); |
| 95519 | 95963 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC); |
| 95520 | 95964 | pParse->nMem += 2; |
| | @@ -95606,11 +96050,10 @@ |
| 95606 | 96050 | ** |
| 95607 | 96051 | ** Return the number of pages in the specified database. |
| 95608 | 96052 | */ |
| 95609 | 96053 | case PragTyp_PAGE_COUNT: { |
| 95610 | 96054 | int iReg; |
| 95611 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 95612 | 96055 | sqlite3CodeVerifySchema(pParse, iDb); |
| 95613 | 96056 | iReg = ++pParse->nMem; |
| 95614 | 96057 | if( sqlite3Tolower(zLeft[0])=='p' ){ |
| 95615 | 96058 | sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg); |
| 95616 | 96059 | }else{ |
| | @@ -95679,18 +96122,10 @@ |
| 95679 | 96122 | */ |
| 95680 | 96123 | case PragTyp_JOURNAL_MODE: { |
| 95681 | 96124 | int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */ |
| 95682 | 96125 | int ii; /* Loop counter */ |
| 95683 | 96126 | |
| 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 | 96127 | sqlite3VdbeSetNumCols(v, 1); |
| 95693 | 96128 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC); |
| 95694 | 96129 | |
| 95695 | 96130 | if( zRight==0 ){ |
| 95696 | 96131 | /* If there is no "=MODE" part of the pragma, do a query for the |
| | @@ -95752,55 +96187,44 @@ |
| 95752 | 96187 | */ |
| 95753 | 96188 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 95754 | 96189 | case PragTyp_AUTO_VACUUM: { |
| 95755 | 96190 | Btree *pBt = pDb->pBt; |
| 95756 | 96191 | assert( pBt!=0 ); |
| 95757 | | - if( sqlite3ReadSchema(pParse) ){ |
| 95758 | | - goto pragma_out; |
| 95759 | | - } |
| 95760 | 96192 | 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); |
| 96193 | + returnSingleInt(pParse, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt)); |
| 95768 | 96194 | }else{ |
| 95769 | 96195 | int eAuto = getAutoVacuum(zRight); |
| 95770 | 96196 | assert( eAuto>=0 && eAuto<=2 ); |
| 95771 | 96197 | 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 | | - } |
| 96198 | + /* Call SetAutoVacuum() to set initialize the internal auto and |
| 96199 | + ** incr-vacuum flags. This is required in case this connection |
| 96200 | + ** creates the database file. It is important that it is created |
| 96201 | + ** as an auto-vacuum capable db. |
| 96202 | + */ |
| 96203 | + rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto); |
| 96204 | + if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){ |
| 96205 | + /* When setting the auto_vacuum mode to either "full" or |
| 96206 | + ** "incremental", write the value of meta[6] in the database |
| 96207 | + ** file. Before writing to meta[6], check that meta[3] indicates |
| 96208 | + ** that this really is an auto-vacuum capable database. |
| 96209 | + */ |
| 96210 | + static const VdbeOpList setMeta6[] = { |
| 96211 | + { OP_Transaction, 0, 1, 0}, /* 0 */ |
| 96212 | + { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE}, |
| 96213 | + { OP_If, 1, 0, 0}, /* 2 */ |
| 96214 | + { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */ |
| 96215 | + { OP_Integer, 0, 1, 0}, /* 4 */ |
| 96216 | + { OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */ |
| 96217 | + }; |
| 96218 | + int iAddr; |
| 96219 | + iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6); |
| 96220 | + sqlite3VdbeChangeP1(v, iAddr, iDb); |
| 96221 | + sqlite3VdbeChangeP1(v, iAddr+1, iDb); |
| 96222 | + sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4); |
| 96223 | + sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1); |
| 96224 | + sqlite3VdbeChangeP1(v, iAddr+5, iDb); |
| 96225 | + sqlite3VdbeUsesBtree(v, iDb); |
| 95802 | 96226 | } |
| 95803 | 96227 | } |
| 95804 | 96228 | break; |
| 95805 | 96229 | } |
| 95806 | 96230 | #endif |
| | @@ -95811,13 +96235,10 @@ |
| 95811 | 96235 | ** Do N steps of incremental vacuuming on a database. |
| 95812 | 96236 | */ |
| 95813 | 96237 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 95814 | 96238 | case PragTyp_INCREMENTAL_VACUUM: { |
| 95815 | 96239 | int iLimit, addr; |
| 95816 | | - if( sqlite3ReadSchema(pParse) ){ |
| 95817 | | - goto pragma_out; |
| 95818 | | - } |
| 95819 | 96240 | if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){ |
| 95820 | 96241 | iLimit = 0x7fffffff; |
| 95821 | 96242 | } |
| 95822 | 96243 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 95823 | 96244 | sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1); |
| | @@ -95841,11 +96262,10 @@ |
| 95841 | 96262 | ** number of pages in the cache. If N is negative, then the |
| 95842 | 96263 | ** number of pages is adjusted so that the cache uses -N kibibytes |
| 95843 | 96264 | ** of memory. |
| 95844 | 96265 | */ |
| 95845 | 96266 | case PragTyp_CACHE_SIZE: { |
| 95846 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 95847 | 96267 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 95848 | 96268 | if( !zRight ){ |
| 95849 | 96269 | returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size); |
| 95850 | 96270 | }else{ |
| 95851 | 96271 | int size = sqlite3Atoi(zRight); |
| | @@ -96062,11 +96482,10 @@ |
| 96062 | 96482 | ** the local value does not make changes to the disk file and the |
| 96063 | 96483 | ** default value will be restored the next time the database is |
| 96064 | 96484 | ** opened. |
| 96065 | 96485 | */ |
| 96066 | 96486 | case PragTyp_SYNCHRONOUS: { |
| 96067 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96068 | 96487 | if( !zRight ){ |
| 96069 | 96488 | returnSingleInt(pParse, "synchronous", pDb->safety_level-1); |
| 96070 | 96489 | }else{ |
| 96071 | 96490 | if( !db->autoCommit ){ |
| 96072 | 96491 | sqlite3ErrorMsg(pParse, |
| | @@ -96124,11 +96543,10 @@ |
| 96124 | 96543 | ** notnull: True if 'NOT NULL' is part of column declaration |
| 96125 | 96544 | ** dflt_value: The default value for the column, if any. |
| 96126 | 96545 | */ |
| 96127 | 96546 | case PragTyp_TABLE_INFO: if( zRight ){ |
| 96128 | 96547 | Table *pTab; |
| 96129 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96130 | 96548 | pTab = sqlite3FindTable(db, zRight, zDb); |
| 96131 | 96549 | if( pTab ){ |
| 96132 | 96550 | int i, k; |
| 96133 | 96551 | int nHidden = 0; |
| 96134 | 96552 | Column *pCol; |
| | @@ -96170,15 +96588,44 @@ |
| 96170 | 96588 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6); |
| 96171 | 96589 | } |
| 96172 | 96590 | } |
| 96173 | 96591 | } |
| 96174 | 96592 | break; |
| 96593 | + |
| 96594 | + case PragTyp_STATS: { |
| 96595 | + Index *pIdx; |
| 96596 | + HashElem *i; |
| 96597 | + v = sqlite3GetVdbe(pParse); |
| 96598 | + sqlite3VdbeSetNumCols(v, 4); |
| 96599 | + pParse->nMem = 4; |
| 96600 | + sqlite3CodeVerifySchema(pParse, iDb); |
| 96601 | + sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC); |
| 96602 | + sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "index", SQLITE_STATIC); |
| 96603 | + sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "width", SQLITE_STATIC); |
| 96604 | + sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "height", SQLITE_STATIC); |
| 96605 | + for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){ |
| 96606 | + Table *pTab = sqliteHashData(i); |
| 96607 | + sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, pTab->zName, 0); |
| 96608 | + sqlite3VdbeAddOp2(v, OP_Null, 0, 2); |
| 96609 | + sqlite3VdbeAddOp2(v, OP_Integer, |
| 96610 | + (int)sqlite3LogEstToInt(pTab->szTabRow), 3); |
| 96611 | + sqlite3VdbeAddOp2(v, OP_Integer, (int)pTab->nRowEst, 4); |
| 96612 | + sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4); |
| 96613 | + for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 96614 | + sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0); |
| 96615 | + sqlite3VdbeAddOp2(v, OP_Integer, |
| 96616 | + (int)sqlite3LogEstToInt(pIdx->szIdxRow), 3); |
| 96617 | + sqlite3VdbeAddOp2(v, OP_Integer, (int)pIdx->aiRowEst[0], 4); |
| 96618 | + sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4); |
| 96619 | + } |
| 96620 | + } |
| 96621 | + } |
| 96622 | + break; |
| 96175 | 96623 | |
| 96176 | 96624 | case PragTyp_INDEX_INFO: if( zRight ){ |
| 96177 | 96625 | Index *pIdx; |
| 96178 | 96626 | Table *pTab; |
| 96179 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96180 | 96627 | pIdx = sqlite3FindIndex(db, zRight, zDb); |
| 96181 | 96628 | if( pIdx ){ |
| 96182 | 96629 | int i; |
| 96183 | 96630 | pTab = pIdx->pTable; |
| 96184 | 96631 | sqlite3VdbeSetNumCols(v, 3); |
| | @@ -96200,39 +96647,32 @@ |
| 96200 | 96647 | break; |
| 96201 | 96648 | |
| 96202 | 96649 | case PragTyp_INDEX_LIST: if( zRight ){ |
| 96203 | 96650 | Index *pIdx; |
| 96204 | 96651 | Table *pTab; |
| 96205 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96652 | + int i; |
| 96206 | 96653 | pTab = sqlite3FindTable(db, zRight, zDb); |
| 96207 | 96654 | if( pTab ){ |
| 96208 | 96655 | 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 | | - } |
| 96656 | + sqlite3VdbeSetNumCols(v, 3); |
| 96657 | + pParse->nMem = 3; |
| 96658 | + sqlite3CodeVerifySchema(pParse, iDb); |
| 96659 | + sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC); |
| 96660 | + sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC); |
| 96661 | + sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC); |
| 96662 | + for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){ |
| 96663 | + sqlite3VdbeAddOp2(v, OP_Integer, i, 1); |
| 96664 | + sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0); |
| 96665 | + sqlite3VdbeAddOp2(v, OP_Integer, pIdx->onError!=OE_None, 3); |
| 96666 | + sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); |
| 96226 | 96667 | } |
| 96227 | 96668 | } |
| 96228 | 96669 | } |
| 96229 | 96670 | break; |
| 96230 | 96671 | |
| 96231 | 96672 | case PragTyp_DATABASE_LIST: { |
| 96232 | 96673 | int i; |
| 96233 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96234 | 96674 | sqlite3VdbeSetNumCols(v, 3); |
| 96235 | 96675 | pParse->nMem = 3; |
| 96236 | 96676 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC); |
| 96237 | 96677 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC); |
| 96238 | 96678 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC); |
| | @@ -96267,11 +96707,10 @@ |
| 96267 | 96707 | |
| 96268 | 96708 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 96269 | 96709 | case PragTyp_FOREIGN_KEY_LIST: if( zRight ){ |
| 96270 | 96710 | FKey *pFK; |
| 96271 | 96711 | Table *pTab; |
| 96272 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96273 | 96712 | pTab = sqlite3FindTable(db, zRight, zDb); |
| 96274 | 96713 | if( pTab ){ |
| 96275 | 96714 | v = sqlite3GetVdbe(pParse); |
| 96276 | 96715 | pFK = pTab->pFKey; |
| 96277 | 96716 | if( pFK ){ |
| | @@ -96329,11 +96768,10 @@ |
| 96329 | 96768 | int regRow; /* Registers to hold a row from pTab */ |
| 96330 | 96769 | int addrTop; /* Top of a loop checking foreign keys */ |
| 96331 | 96770 | int addrOk; /* Jump here if the key is OK */ |
| 96332 | 96771 | int *aiCols; /* child to parent column mapping */ |
| 96333 | 96772 | |
| 96334 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96335 | 96773 | regResult = pParse->nMem+1; |
| 96336 | 96774 | pParse->nMem += 4; |
| 96337 | 96775 | regKey = ++pParse->nMem; |
| 96338 | 96776 | regRow = ++pParse->nMem; |
| 96339 | 96777 | v = sqlite3GetVdbe(pParse); |
| | @@ -96357,12 +96795,12 @@ |
| 96357 | 96795 | if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow; |
| 96358 | 96796 | sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead); |
| 96359 | 96797 | sqlite3VdbeAddOp4(v, OP_String8, 0, regResult, 0, pTab->zName, |
| 96360 | 96798 | P4_TRANSIENT); |
| 96361 | 96799 | for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
| 96362 | | - pParent = sqlite3LocateTable(pParse, 0, pFK->zTo, zDb); |
| 96363 | | - if( pParent==0 ) break; |
| 96800 | + pParent = sqlite3FindTable(db, pFK->zTo, zDb); |
| 96801 | + if( pParent==0 ) continue; |
| 96364 | 96802 | pIdx = 0; |
| 96365 | 96803 | sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName); |
| 96366 | 96804 | x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0); |
| 96367 | 96805 | if( x==0 ){ |
| 96368 | 96806 | if( pIdx==0 ){ |
| | @@ -96375,22 +96813,24 @@ |
| 96375 | 96813 | }else{ |
| 96376 | 96814 | k = 0; |
| 96377 | 96815 | break; |
| 96378 | 96816 | } |
| 96379 | 96817 | } |
| 96818 | + assert( pParse->nErr>0 || pFK==0 ); |
| 96380 | 96819 | if( pFK ) break; |
| 96381 | 96820 | if( pParse->nTab<i ) pParse->nTab = i; |
| 96382 | 96821 | addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); |
| 96383 | 96822 | for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
| 96384 | | - pParent = sqlite3LocateTable(pParse, 0, pFK->zTo, zDb); |
| 96385 | | - assert( pParent!=0 ); |
| 96823 | + pParent = sqlite3FindTable(db, pFK->zTo, zDb); |
| 96386 | 96824 | pIdx = 0; |
| 96387 | 96825 | aiCols = 0; |
| 96388 | | - x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols); |
| 96389 | | - assert( x==0 ); |
| 96826 | + if( pParent ){ |
| 96827 | + x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols); |
| 96828 | + assert( x==0 ); |
| 96829 | + } |
| 96390 | 96830 | addrOk = sqlite3VdbeMakeLabel(v); |
| 96391 | | - if( pIdx==0 ){ |
| 96831 | + if( pParent && pIdx==0 ){ |
| 96392 | 96832 | int iKey = pFK->aCol[0].iFrom; |
| 96393 | 96833 | assert( iKey>=0 && iKey<pTab->nCol ); |
| 96394 | 96834 | if( iKey!=pTab->iPKey ){ |
| 96395 | 96835 | sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow); |
| 96396 | 96836 | sqlite3ColumnDefault(v, pTab, iKey, regRow); |
| | @@ -96404,17 +96844,19 @@ |
| 96404 | 96844 | sqlite3VdbeAddOp2(v, OP_Goto, 0, addrOk); |
| 96405 | 96845 | sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2); |
| 96406 | 96846 | }else{ |
| 96407 | 96847 | for(j=0; j<pFK->nCol; j++){ |
| 96408 | 96848 | sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, |
| 96409 | | - aiCols ? aiCols[j] : pFK->aCol[0].iFrom, regRow+j); |
| 96849 | + aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j); |
| 96410 | 96850 | sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); |
| 96411 | 96851 | } |
| 96412 | | - sqlite3VdbeAddOp3(v, OP_MakeRecord, regRow, pFK->nCol, regKey); |
| 96413 | | - sqlite3VdbeChangeP4(v, -1, |
| 96414 | | - sqlite3IndexAffinityStr(v,pIdx), P4_TRANSIENT); |
| 96415 | | - sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0); |
| 96852 | + if( pParent ){ |
| 96853 | + sqlite3VdbeAddOp3(v, OP_MakeRecord, regRow, pFK->nCol, regKey); |
| 96854 | + sqlite3VdbeChangeP4(v, -1, |
| 96855 | + sqlite3IndexAffinityStr(v,pIdx), P4_TRANSIENT); |
| 96856 | + sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0); |
| 96857 | + } |
| 96416 | 96858 | } |
| 96417 | 96859 | sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1); |
| 96418 | 96860 | sqlite3VdbeAddOp4(v, OP_String8, 0, regResult+2, 0, |
| 96419 | 96861 | pFK->zTo, P4_TRANSIENT); |
| 96420 | 96862 | sqlite3VdbeAddOp2(v, OP_Integer, i-1, regResult+3); |
| | @@ -96490,11 +96932,10 @@ |
| 96490 | 96932 | assert( iDb>=0 ); |
| 96491 | 96933 | assert( iDb==0 || pId2->z ); |
| 96492 | 96934 | if( pId2->z==0 ) iDb = -1; |
| 96493 | 96935 | |
| 96494 | 96936 | /* Initialize the VDBE program */ |
| 96495 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96496 | 96937 | pParse->nMem = 6; |
| 96497 | 96938 | sqlite3VdbeSetNumCols(v, 1); |
| 96498 | 96939 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", SQLITE_STATIC); |
| 96499 | 96940 | |
| 96500 | 96941 | /* Set the maximum error count */ |
| | @@ -96814,11 +97255,10 @@ |
| 96814 | 97255 | eMode = SQLITE_CHECKPOINT_FULL; |
| 96815 | 97256 | }else if( sqlite3StrICmp(zRight, "restart")==0 ){ |
| 96816 | 97257 | eMode = SQLITE_CHECKPOINT_RESTART; |
| 96817 | 97258 | } |
| 96818 | 97259 | } |
| 96819 | | - if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 96820 | 97260 | sqlite3VdbeSetNumCols(v, 3); |
| 96821 | 97261 | pParse->nMem = 3; |
| 96822 | 97262 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "busy", SQLITE_STATIC); |
| 96823 | 97263 | sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "log", SQLITE_STATIC); |
| 96824 | 97264 | sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "checkpointed", SQLITE_STATIC); |
| | @@ -96934,16 +97374,16 @@ |
| 96934 | 97374 | if( zRight ) sqlite3_rekey_v2(db, zDb, zRight, sqlite3Strlen30(zRight)); |
| 96935 | 97375 | break; |
| 96936 | 97376 | } |
| 96937 | 97377 | case PragTyp_HEXKEY: { |
| 96938 | 97378 | if( zRight ){ |
| 96939 | | - int i, h1, h2; |
| 97379 | + u8 iByte; |
| 97380 | + int i; |
| 96940 | 97381 | 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); |
| 97382 | + for(i=0, iByte=0; i<sizeof(zKey)*2 && sqlite3Isxdigit(zRight[i]); i++){ |
| 97383 | + iByte = (iByte<<4) + sqlite3HexToInt(zRight[i]); |
| 97384 | + if( (i&1)!=0 ) zKey[i/2] = iByte; |
| 96945 | 97385 | } |
| 96946 | 97386 | if( (zLeft[3] & 0xf)==0xb ){ |
| 96947 | 97387 | sqlite3_key_v2(db, zDb, zKey, i/2); |
| 96948 | 97388 | }else{ |
| 96949 | 97389 | sqlite3_rekey_v2(db, zDb, zKey, i/2); |
| | @@ -98913,10 +99353,13 @@ |
| 98913 | 99353 | } |
| 98914 | 99354 | |
| 98915 | 99355 | /* |
| 98916 | 99356 | ** Return a pointer to a string containing the 'declaration type' of the |
| 98917 | 99357 | ** expression pExpr. The string may be treated as static by the caller. |
| 99358 | +** |
| 99359 | +** Also try to estimate the size of the returned value and return that |
| 99360 | +** result in *pEstWidth. |
| 98918 | 99361 | ** |
| 98919 | 99362 | ** The declaration type is the exact datatype definition extracted from the |
| 98920 | 99363 | ** original CREATE TABLE statement if the expression is a column. The |
| 98921 | 99364 | ** declaration type for a ROWID field is INTEGER. Exactly when an expression |
| 98922 | 99365 | ** is considered a column can be complex in the presence of subqueries. The |
| | @@ -98927,25 +99370,40 @@ |
| 98927 | 99370 | ** SELECT (SELECT col FROM tbl; |
| 98928 | 99371 | ** SELECT (SELECT col FROM tbl); |
| 98929 | 99372 | ** SELECT abc FROM (SELECT col AS abc FROM tbl); |
| 98930 | 99373 | ** |
| 98931 | 99374 | ** The declaration type for any expression other than a column is NULL. |
| 99375 | +** |
| 99376 | +** This routine has either 3 or 6 parameters depending on whether or not |
| 99377 | +** the SQLITE_ENABLE_COLUMN_METADATA compile-time option is used. |
| 98932 | 99378 | */ |
| 98933 | | -static const char *columnType( |
| 99379 | +#ifdef SQLITE_ENABLE_COLUMN_METADATA |
| 99380 | +# define columnType(A,B,C,D,E,F) columnTypeImpl(A,B,C,D,E,F) |
| 99381 | +static const char *columnTypeImpl( |
| 99382 | + NameContext *pNC, |
| 99383 | + Expr *pExpr, |
| 99384 | + const char **pzOrigDb, |
| 99385 | + const char **pzOrigTab, |
| 99386 | + const char **pzOrigCol, |
| 99387 | + u8 *pEstWidth |
| 99388 | +){ |
| 99389 | + char const *zOrigDb = 0; |
| 99390 | + char const *zOrigTab = 0; |
| 99391 | + char const *zOrigCol = 0; |
| 99392 | +#else /* if !defined(SQLITE_ENABLE_COLUMN_METADATA) */ |
| 99393 | +# define columnType(A,B,C,D,E,F) columnTypeImpl(A,B,F) |
| 99394 | +static const char *columnTypeImpl( |
| 98934 | 99395 | NameContext *pNC, |
| 98935 | 99396 | Expr *pExpr, |
| 98936 | | - const char **pzOriginDb, |
| 98937 | | - const char **pzOriginTab, |
| 98938 | | - const char **pzOriginCol |
| 99397 | + u8 *pEstWidth |
| 98939 | 99398 | ){ |
| 99399 | +#endif /* !defined(SQLITE_ENABLE_COLUMN_METADATA) */ |
| 98940 | 99400 | char const *zType = 0; |
| 98941 | | - char const *zOriginDb = 0; |
| 98942 | | - char const *zOriginTab = 0; |
| 98943 | | - char const *zOriginCol = 0; |
| 98944 | 99401 | int j; |
| 99402 | + u8 estWidth = 1; |
| 99403 | + |
| 98945 | 99404 | if( NEVER(pExpr==0) || pNC->pSrcList==0 ) return 0; |
| 98946 | | - |
| 98947 | 99405 | switch( pExpr->op ){ |
| 98948 | 99406 | case TK_AGG_COLUMN: |
| 98949 | 99407 | case TK_COLUMN: { |
| 98950 | 99408 | /* The expression is a column. Locate the table the column is being |
| 98951 | 99409 | ** extracted from in NameContext.pSrcList. This table may be real |
| | @@ -99002,29 +99460,39 @@ |
| 99002 | 99460 | NameContext sNC; |
| 99003 | 99461 | Expr *p = pS->pEList->a[iCol].pExpr; |
| 99004 | 99462 | sNC.pSrcList = pS->pSrc; |
| 99005 | 99463 | sNC.pNext = pNC; |
| 99006 | 99464 | sNC.pParse = pNC->pParse; |
| 99007 | | - zType = columnType(&sNC, p, &zOriginDb, &zOriginTab, &zOriginCol); |
| 99465 | + zType = columnType(&sNC, p,&zOrigDb,&zOrigTab,&zOrigCol, &estWidth); |
| 99008 | 99466 | } |
| 99009 | 99467 | }else if( ALWAYS(pTab->pSchema) ){ |
| 99010 | 99468 | /* A real table */ |
| 99011 | 99469 | assert( !pS ); |
| 99012 | 99470 | if( iCol<0 ) iCol = pTab->iPKey; |
| 99013 | 99471 | assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) ); |
| 99472 | +#ifdef SQLITE_ENABLE_COLUMN_METADATA |
| 99014 | 99473 | if( iCol<0 ){ |
| 99015 | 99474 | zType = "INTEGER"; |
| 99016 | | - zOriginCol = "rowid"; |
| 99475 | + zOrigCol = "rowid"; |
| 99017 | 99476 | }else{ |
| 99018 | 99477 | zType = pTab->aCol[iCol].zType; |
| 99019 | | - zOriginCol = pTab->aCol[iCol].zName; |
| 99478 | + zOrigCol = pTab->aCol[iCol].zName; |
| 99479 | + estWidth = pTab->aCol[iCol].szEst; |
| 99020 | 99480 | } |
| 99021 | | - zOriginTab = pTab->zName; |
| 99481 | + zOrigTab = pTab->zName; |
| 99022 | 99482 | if( pNC->pParse ){ |
| 99023 | 99483 | int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema); |
| 99024 | | - zOriginDb = pNC->pParse->db->aDb[iDb].zName; |
| 99484 | + zOrigDb = pNC->pParse->db->aDb[iDb].zName; |
| 99025 | 99485 | } |
| 99486 | +#else |
| 99487 | + if( iCol<0 ){ |
| 99488 | + zType = "INTEGER"; |
| 99489 | + }else{ |
| 99490 | + zType = pTab->aCol[iCol].zType; |
| 99491 | + estWidth = pTab->aCol[iCol].szEst; |
| 99492 | + } |
| 99493 | +#endif |
| 99026 | 99494 | } |
| 99027 | 99495 | break; |
| 99028 | 99496 | } |
| 99029 | 99497 | #ifndef SQLITE_OMIT_SUBQUERY |
| 99030 | 99498 | case TK_SELECT: { |
| | @@ -99037,22 +99505,25 @@ |
| 99037 | 99505 | Expr *p = pS->pEList->a[0].pExpr; |
| 99038 | 99506 | assert( ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 99039 | 99507 | sNC.pSrcList = pS->pSrc; |
| 99040 | 99508 | sNC.pNext = pNC; |
| 99041 | 99509 | sNC.pParse = pNC->pParse; |
| 99042 | | - zType = columnType(&sNC, p, &zOriginDb, &zOriginTab, &zOriginCol); |
| 99510 | + zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol, &estWidth); |
| 99043 | 99511 | break; |
| 99044 | 99512 | } |
| 99045 | 99513 | #endif |
| 99046 | 99514 | } |
| 99047 | | - |
| 99048 | | - if( pzOriginDb ){ |
| 99049 | | - assert( pzOriginTab && pzOriginCol ); |
| 99050 | | - *pzOriginDb = zOriginDb; |
| 99051 | | - *pzOriginTab = zOriginTab; |
| 99052 | | - *pzOriginCol = zOriginCol; |
| 99515 | + |
| 99516 | +#ifdef SQLITE_ENABLE_COLUMN_METADATA |
| 99517 | + if( pzOrigDb ){ |
| 99518 | + assert( pzOrigTab && pzOrigCol ); |
| 99519 | + *pzOrigDb = zOrigDb; |
| 99520 | + *pzOrigTab = zOrigTab; |
| 99521 | + *pzOrigCol = zOrigCol; |
| 99053 | 99522 | } |
| 99523 | +#endif |
| 99524 | + if( pEstWidth ) *pEstWidth = estWidth; |
| 99054 | 99525 | return zType; |
| 99055 | 99526 | } |
| 99056 | 99527 | |
| 99057 | 99528 | /* |
| 99058 | 99529 | ** Generate code that will tell the VDBE the declaration types of columns |
| | @@ -99074,25 +99545,25 @@ |
| 99074 | 99545 | const char *zType; |
| 99075 | 99546 | #ifdef SQLITE_ENABLE_COLUMN_METADATA |
| 99076 | 99547 | const char *zOrigDb = 0; |
| 99077 | 99548 | const char *zOrigTab = 0; |
| 99078 | 99549 | const char *zOrigCol = 0; |
| 99079 | | - zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol); |
| 99550 | + zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol, 0); |
| 99080 | 99551 | |
| 99081 | 99552 | /* The vdbe must make its own copy of the column-type and other |
| 99082 | 99553 | ** column specific strings, in case the schema is reset before this |
| 99083 | 99554 | ** virtual machine is deleted. |
| 99084 | 99555 | */ |
| 99085 | 99556 | sqlite3VdbeSetColName(v, i, COLNAME_DATABASE, zOrigDb, SQLITE_TRANSIENT); |
| 99086 | 99557 | sqlite3VdbeSetColName(v, i, COLNAME_TABLE, zOrigTab, SQLITE_TRANSIENT); |
| 99087 | 99558 | sqlite3VdbeSetColName(v, i, COLNAME_COLUMN, zOrigCol, SQLITE_TRANSIENT); |
| 99088 | 99559 | #else |
| 99089 | | - zType = columnType(&sNC, p, 0, 0, 0); |
| 99560 | + zType = columnType(&sNC, p, 0, 0, 0, 0); |
| 99090 | 99561 | #endif |
| 99091 | 99562 | sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT); |
| 99092 | 99563 | } |
| 99093 | | -#endif /* SQLITE_OMIT_DECLTYPE */ |
| 99564 | +#endif /* !defined(SQLITE_OMIT_DECLTYPE) */ |
| 99094 | 99565 | } |
| 99095 | 99566 | |
| 99096 | 99567 | /* |
| 99097 | 99568 | ** Generate code that will tell the VDBE the names of columns |
| 99098 | 99569 | ** in the result set. This information is used to provide the |
| | @@ -99277,39 +99748,41 @@ |
| 99277 | 99748 | ** This routine requires that all identifiers in the SELECT |
| 99278 | 99749 | ** statement be resolved. |
| 99279 | 99750 | */ |
| 99280 | 99751 | static void selectAddColumnTypeAndCollation( |
| 99281 | 99752 | Parse *pParse, /* Parsing contexts */ |
| 99282 | | - int nCol, /* Number of columns */ |
| 99283 | | - Column *aCol, /* List of columns */ |
| 99753 | + Table *pTab, /* Add column type information to this table */ |
| 99284 | 99754 | Select *pSelect /* SELECT used to determine types and collations */ |
| 99285 | 99755 | ){ |
| 99286 | 99756 | sqlite3 *db = pParse->db; |
| 99287 | 99757 | NameContext sNC; |
| 99288 | 99758 | Column *pCol; |
| 99289 | 99759 | CollSeq *pColl; |
| 99290 | 99760 | int i; |
| 99291 | 99761 | Expr *p; |
| 99292 | 99762 | struct ExprList_item *a; |
| 99763 | + u64 szAll = 0; |
| 99293 | 99764 | |
| 99294 | 99765 | assert( pSelect!=0 ); |
| 99295 | 99766 | assert( (pSelect->selFlags & SF_Resolved)!=0 ); |
| 99296 | | - assert( nCol==pSelect->pEList->nExpr || db->mallocFailed ); |
| 99767 | + assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed ); |
| 99297 | 99768 | if( db->mallocFailed ) return; |
| 99298 | 99769 | memset(&sNC, 0, sizeof(sNC)); |
| 99299 | 99770 | sNC.pSrcList = pSelect->pSrc; |
| 99300 | 99771 | a = pSelect->pEList->a; |
| 99301 | | - for(i=0, pCol=aCol; i<nCol; i++, pCol++){ |
| 99772 | + for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ |
| 99302 | 99773 | p = a[i].pExpr; |
| 99303 | | - pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p, 0, 0, 0)); |
| 99774 | + pCol->zType = sqlite3DbStrDup(db, columnType(&sNC, p,0,0,0, &pCol->szEst)); |
| 99775 | + szAll += pCol->szEst; |
| 99304 | 99776 | pCol->affinity = sqlite3ExprAffinity(p); |
| 99305 | 99777 | if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE; |
| 99306 | 99778 | pColl = sqlite3ExprCollSeq(pParse, p); |
| 99307 | 99779 | if( pColl ){ |
| 99308 | 99780 | pCol->zColl = sqlite3DbStrDup(db, pColl->zName); |
| 99309 | 99781 | } |
| 99310 | 99782 | } |
| 99783 | + pTab->szTabRow = sqlite3LogEst(szAll*4); |
| 99311 | 99784 | } |
| 99312 | 99785 | |
| 99313 | 99786 | /* |
| 99314 | 99787 | ** Given a SELECT statement, generate a Table structure that describes |
| 99315 | 99788 | ** the result set of that SELECT. |
| | @@ -99333,13 +99806,13 @@ |
| 99333 | 99806 | /* The sqlite3ResultSetOfSelect() is only used n contexts where lookaside |
| 99334 | 99807 | ** is disabled */ |
| 99335 | 99808 | assert( db->lookaside.bEnabled==0 ); |
| 99336 | 99809 | pTab->nRef = 1; |
| 99337 | 99810 | pTab->zName = 0; |
| 99338 | | - pTab->nRowEst = 1000000; |
| 99811 | + pTab->nRowEst = 1048576; |
| 99339 | 99812 | selectColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol); |
| 99340 | | - selectAddColumnTypeAndCollation(pParse, pTab->nCol, pTab->aCol, pSelect); |
| 99813 | + selectAddColumnTypeAndCollation(pParse, pTab, pSelect); |
| 99341 | 99814 | pTab->iPKey = -1; |
| 99342 | 99815 | if( db->mallocFailed ){ |
| 99343 | 99816 | sqlite3DeleteTable(db, pTab); |
| 99344 | 99817 | return 0; |
| 99345 | 99818 | } |
| | @@ -101247,15 +101720,15 @@ |
| 101247 | 101720 | assert( pFrom->pTab==0 ); |
| 101248 | 101721 | sqlite3WalkSelect(pWalker, pSel); |
| 101249 | 101722 | pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table)); |
| 101250 | 101723 | if( pTab==0 ) return WRC_Abort; |
| 101251 | 101724 | pTab->nRef = 1; |
| 101252 | | - pTab->zName = sqlite3MPrintf(db, "sqlite_subquery_%p_", (void*)pTab); |
| 101725 | + pTab->zName = sqlite3MPrintf(db, "sqlite_sq_%p", (void*)pTab); |
| 101253 | 101726 | while( pSel->pPrior ){ pSel = pSel->pPrior; } |
| 101254 | 101727 | selectColumnsFromExprList(pParse, pSel->pEList, &pTab->nCol, &pTab->aCol); |
| 101255 | 101728 | pTab->iPKey = -1; |
| 101256 | | - pTab->nRowEst = 1000000; |
| 101729 | + pTab->nRowEst = 1048576; |
| 101257 | 101730 | pTab->tabFlags |= TF_Ephemeral; |
| 101258 | 101731 | #endif |
| 101259 | 101732 | }else{ |
| 101260 | 101733 | /* An ordinary table or view name in the FROM clause */ |
| 101261 | 101734 | assert( pFrom->pTab==0 ); |
| | @@ -101535,11 +102008,11 @@ |
| 101535 | 102008 | if( ALWAYS(pTab!=0) && (pTab->tabFlags & TF_Ephemeral)!=0 ){ |
| 101536 | 102009 | /* A sub-query in the FROM clause of a SELECT */ |
| 101537 | 102010 | Select *pSel = pFrom->pSelect; |
| 101538 | 102011 | assert( pSel ); |
| 101539 | 102012 | while( pSel->pPrior ) pSel = pSel->pPrior; |
| 101540 | | - selectAddColumnTypeAndCollation(pParse, pTab->nCol, pTab->aCol, pSel); |
| 102013 | + selectAddColumnTypeAndCollation(pParse, pTab, pSel); |
| 101541 | 102014 | } |
| 101542 | 102015 | } |
| 101543 | 102016 | } |
| 101544 | 102017 | return WRC_Continue; |
| 101545 | 102018 | } |
| | @@ -102450,29 +102923,29 @@ |
| 102450 | 102923 | int iRoot = pTab->tnum; /* Root page of scanned b-tree */ |
| 102451 | 102924 | |
| 102452 | 102925 | sqlite3CodeVerifySchema(pParse, iDb); |
| 102453 | 102926 | sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); |
| 102454 | 102927 | |
| 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. |
| 102928 | + /* Search for the index that has the lowest scan cost. |
| 102462 | 102929 | ** |
| 102463 | 102930 | ** (2011-04-15) Do not do a full scan of an unordered index. |
| 102931 | + ** |
| 102932 | + ** (2013-10-03) Do not count the entires in a partial index. |
| 102464 | 102933 | ** |
| 102465 | 102934 | ** In practice the KeyInfo structure will not be used. It is only |
| 102466 | 102935 | ** passed to keep OP_OpenRead happy. |
| 102467 | 102936 | */ |
| 102468 | 102937 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 102469 | | - if( pIdx->bUnordered==0 && (!pBest || pIdx->nColumn<pBest->nColumn) ){ |
| 102938 | + if( pIdx->bUnordered==0 |
| 102939 | + && pIdx->szIdxRow<pTab->szTabRow |
| 102940 | + && pIdx->pPartIdxWhere==0 |
| 102941 | + && (!pBest || pIdx->szIdxRow<pBest->szIdxRow) |
| 102942 | + ){ |
| 102470 | 102943 | pBest = pIdx; |
| 102471 | 102944 | } |
| 102472 | 102945 | } |
| 102473 | | - if( pBest && pBest->nColumn<pTab->nCol ){ |
| 102946 | + if( pBest ){ |
| 102474 | 102947 | iRoot = pBest->tnum; |
| 102475 | 102948 | pKeyInfo = sqlite3IndexKeyinfo(pParse, pBest); |
| 102476 | 102949 | } |
| 102477 | 102950 | |
| 102478 | 102951 | /* Open a read-only cursor, execute the OP_Count, close the cursor. */ |
| | @@ -103046,12 +103519,12 @@ |
| 103046 | 103519 | } |
| 103047 | 103520 | |
| 103048 | 103521 | /* Ensure the table name matches database name and that the table exists */ |
| 103049 | 103522 | if( db->mallocFailed ) goto trigger_cleanup; |
| 103050 | 103523 | assert( pTableName->nSrc==1 ); |
| 103051 | | - if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", pName) && |
| 103052 | | - sqlite3FixSrcList(&sFix, pTableName) ){ |
| 103524 | + sqlite3FixInit(&sFix, pParse, iDb, "trigger", pName); |
| 103525 | + if( sqlite3FixSrcList(&sFix, pTableName) ){ |
| 103053 | 103526 | goto trigger_cleanup; |
| 103054 | 103527 | } |
| 103055 | 103528 | pTab = sqlite3SrcListLookup(pParse, pTableName); |
| 103056 | 103529 | if( !pTab ){ |
| 103057 | 103530 | /* The table does not exist. */ |
| | @@ -103189,12 +103662,14 @@ |
| 103189 | 103662 | pStepList->pTrig = pTrig; |
| 103190 | 103663 | pStepList = pStepList->pNext; |
| 103191 | 103664 | } |
| 103192 | 103665 | nameToken.z = pTrig->zName; |
| 103193 | 103666 | nameToken.n = sqlite3Strlen30(nameToken.z); |
| 103194 | | - if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", &nameToken) |
| 103195 | | - && sqlite3FixTriggerStep(&sFix, pTrig->step_list) ){ |
| 103667 | + sqlite3FixInit(&sFix, pParse, iDb, "trigger", &nameToken); |
| 103668 | + if( sqlite3FixTriggerStep(&sFix, pTrig->step_list) |
| 103669 | + || sqlite3FixExpr(&sFix, pTrig->pWhen) |
| 103670 | + ){ |
| 103196 | 103671 | goto triggerfinish_cleanup; |
| 103197 | 103672 | } |
| 103198 | 103673 | |
| 103199 | 103674 | /* if we are not initializing, |
| 103200 | 103675 | ** build the sqlite_master entry |
| | @@ -104781,18 +105256,38 @@ |
| 104781 | 105256 | |
| 104782 | 105257 | return vacuumFinalize(db, pStmt, pzErrMsg); |
| 104783 | 105258 | } |
| 104784 | 105259 | |
| 104785 | 105260 | /* |
| 104786 | | -** The non-standard VACUUM command is used to clean up the database, |
| 105261 | +** The VACUUM command is used to clean up the database, |
| 104787 | 105262 | ** collapse free space, etc. It is modelled after the VACUUM command |
| 104788 | | -** in PostgreSQL. |
| 105263 | +** in PostgreSQL. The VACUUM command works as follows: |
| 104789 | 105264 | ** |
| 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. |
| 105265 | +** (1) Create a new transient database file |
| 105266 | +** (2) Copy all content from the database being vacuumed into |
| 105267 | +** the new transient database file |
| 105268 | +** (3) Copy content from the transient database back into the |
| 105269 | +** original database. |
| 105270 | +** |
| 105271 | +** The transient database requires temporary disk space approximately |
| 105272 | +** equal to the size of the original database. The copy operation of |
| 105273 | +** step (3) requires additional temporary disk space approximately equal |
| 105274 | +** to the size of the original database for the rollback journal. |
| 105275 | +** Hence, temporary disk space that is approximately 2x the size of the |
| 105276 | +** orginal database is required. Every page of the database is written |
| 105277 | +** approximately 3 times: Once for step (2) and twice for step (3). |
| 105278 | +** Two writes per page are required in step (3) because the original |
| 105279 | +** database content must be written into the rollback journal prior to |
| 105280 | +** overwriting the database with the vacuumed content. |
| 105281 | +** |
| 105282 | +** Only 1x temporary space and only 1x writes would be required if |
| 105283 | +** the copy of step (3) were replace by deleting the original database |
| 105284 | +** and renaming the transient database as the original. But that will |
| 105285 | +** not work if other processes are attached to the original database. |
| 105286 | +** And a power loss in between deleting the original and renaming the |
| 105287 | +** transient would cause the database file to appear to be deleted |
| 105288 | +** following reboot. |
| 104794 | 105289 | */ |
| 104795 | 105290 | SQLITE_PRIVATE void sqlite3Vacuum(Parse *pParse){ |
| 104796 | 105291 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 104797 | 105292 | if( v ){ |
| 104798 | 105293 | sqlite3VdbeAddOp2(v, OP_Vacuum, 0, 0); |
| | @@ -106206,30 +106701,10 @@ |
| 106206 | 106701 | typedef struct WhereLoopBuilder WhereLoopBuilder; |
| 106207 | 106702 | typedef struct WhereScan WhereScan; |
| 106208 | 106703 | typedef struct WhereOrCost WhereOrCost; |
| 106209 | 106704 | typedef struct WhereOrSet WhereOrSet; |
| 106210 | 106705 | |
| 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 | 106706 | /* |
| 106232 | 106707 | ** This object contains information needed to implement a single nested |
| 106233 | 106708 | ** loop in WHERE clause. |
| 106234 | 106709 | ** |
| 106235 | 106710 | ** Contrast this object with WhereLoop. This object describes the |
| | @@ -106290,13 +106765,13 @@ |
| 106290 | 106765 | #ifdef SQLITE_DEBUG |
| 106291 | 106766 | char cId; /* Symbolic ID of this loop for debugging use */ |
| 106292 | 106767 | #endif |
| 106293 | 106768 | u8 iTab; /* Position in FROM clause of table for this loop */ |
| 106294 | 106769 | 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 */ |
| 106770 | + LogEst rSetup; /* One-time setup cost (ex: create transient index) */ |
| 106771 | + LogEst rRun; /* Cost of running each loop */ |
| 106772 | + LogEst nOut; /* Estimated number of output rows */ |
| 106298 | 106773 | union { |
| 106299 | 106774 | struct { /* Information for internal btree tables */ |
| 106300 | 106775 | int nEq; /* Number of equality constraints */ |
| 106301 | 106776 | Index *pIndex; /* Index used, or NULL */ |
| 106302 | 106777 | } btree; |
| | @@ -106322,12 +106797,12 @@ |
| 106322 | 106797 | ** subquery on one operand of an OR operator in the WHERE clause. |
| 106323 | 106798 | ** See WhereOrSet for additional information |
| 106324 | 106799 | */ |
| 106325 | 106800 | struct WhereOrCost { |
| 106326 | 106801 | Bitmask prereq; /* Prerequisites */ |
| 106327 | | - WhereCost rRun; /* Cost of running this subquery */ |
| 106328 | | - WhereCost nOut; /* Number of outputs for this subquery */ |
| 106802 | + LogEst rRun; /* Cost of running this subquery */ |
| 106803 | + LogEst nOut; /* Number of outputs for this subquery */ |
| 106329 | 106804 | }; |
| 106330 | 106805 | |
| 106331 | 106806 | /* The WhereOrSet object holds a set of possible WhereOrCosts that |
| 106332 | 106807 | ** correspond to the subquery(s) of OR-clause processing. Only the |
| 106333 | 106808 | ** best N_OR_COST elements are retained. |
| | @@ -106361,12 +106836,12 @@ |
| 106361 | 106836 | ** at the end is the choosen query plan. |
| 106362 | 106837 | */ |
| 106363 | 106838 | struct WherePath { |
| 106364 | 106839 | Bitmask maskLoop; /* Bitmask of all WhereLoop objects in this path */ |
| 106365 | 106840 | 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 */ |
| 106841 | + LogEst nRow; /* Estimated number of rows generated by this path */ |
| 106842 | + LogEst rCost; /* Total cost of this path */ |
| 106368 | 106843 | u8 isOrdered; /* True if this path satisfies ORDER BY */ |
| 106369 | 106844 | u8 isOrderedValid; /* True if the isOrdered field is valid */ |
| 106370 | 106845 | WhereLoop **aLoop; /* Array of WhereLoop objects implementing this path */ |
| 106371 | 106846 | }; |
| 106372 | 106847 | |
| | @@ -106428,11 +106903,11 @@ |
| 106428 | 106903 | union { |
| 106429 | 106904 | int leftColumn; /* Column number of X in "X <op> <expr>" */ |
| 106430 | 106905 | WhereOrInfo *pOrInfo; /* Extra information if (eOperator & WO_OR)!=0 */ |
| 106431 | 106906 | WhereAndInfo *pAndInfo; /* Extra information if (eOperator& WO_AND)!=0 */ |
| 106432 | 106907 | } u; |
| 106433 | | - WhereCost truthProb; /* Probability of truth for this expression */ |
| 106908 | + LogEst truthProb; /* Probability of truth for this expression */ |
| 106434 | 106909 | u16 eOperator; /* A WO_xx value describing <op> */ |
| 106435 | 106910 | u8 wtFlags; /* TERM_xxx bit flags. See below */ |
| 106436 | 106911 | u8 nChild; /* Number of children that must disable us */ |
| 106437 | 106912 | WhereClause *pWC; /* The clause this term is part of */ |
| 106438 | 106913 | Bitmask prereqRight; /* Bitmask of tables used by pExpr->pRight */ |
| | @@ -106576,11 +107051,11 @@ |
| 106576 | 107051 | SrcList *pTabList; /* List of tables in the join */ |
| 106577 | 107052 | ExprList *pOrderBy; /* The ORDER BY clause or NULL */ |
| 106578 | 107053 | ExprList *pResultSet; /* Result set. DISTINCT operates on these */ |
| 106579 | 107054 | WhereLoop *pLoops; /* List of all WhereLoop objects */ |
| 106580 | 107055 | Bitmask revMask; /* Mask of ORDER BY terms that need reversing */ |
| 106581 | | - WhereCost nRowOut; /* Estimated number of output rows */ |
| 107056 | + LogEst nRowOut; /* Estimated number of output rows */ |
| 106582 | 107057 | u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */ |
| 106583 | 107058 | u8 bOBSat; /* ORDER BY satisfied by indices */ |
| 106584 | 107059 | u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE/DELETE */ |
| 106585 | 107060 | u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */ |
| 106586 | 107061 | u8 eDistinct; /* One of the WHERE_DISTINCT_* values below */ |
| | @@ -106636,30 +107111,15 @@ |
| 106636 | 107111 | #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */ |
| 106637 | 107112 | #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */ |
| 106638 | 107113 | #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */ |
| 106639 | 107114 | #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */ |
| 106640 | 107115 | |
| 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 | 107116 | /* |
| 106657 | 107117 | ** Return the estimated number of output rows from a WHERE clause |
| 106658 | 107118 | */ |
| 106659 | 107119 | SQLITE_PRIVATE u64 sqlite3WhereOutputRowCount(WhereInfo *pWInfo){ |
| 106660 | | - return whereCostToInt(pWInfo->nRowOut); |
| 107120 | + return sqlite3LogEstToInt(pWInfo->nRowOut); |
| 106661 | 107121 | } |
| 106662 | 107122 | |
| 106663 | 107123 | /* |
| 106664 | 107124 | ** Return one of the WHERE_DISTINCT_xxxxx values to indicate how this |
| 106665 | 107125 | ** WHERE clause returns outputs for DISTINCT processing. |
| | @@ -106717,12 +107177,12 @@ |
| 106717 | 107177 | ** so that pSet keeps the N_OR_COST best entries seen so far. |
| 106718 | 107178 | */ |
| 106719 | 107179 | static int whereOrInsert( |
| 106720 | 107180 | WhereOrSet *pSet, /* The WhereOrSet to be updated */ |
| 106721 | 107181 | 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 */ |
| 107182 | + LogEst rRun, /* Run-cost of the new entry */ |
| 107183 | + LogEst nOut /* Number of outputs for the new entry */ |
| 106724 | 107184 | ){ |
| 106725 | 107185 | u16 i; |
| 106726 | 107186 | WhereOrCost *p; |
| 106727 | 107187 | for(i=pSet->n, p=pSet->a; i>0; i--, p++){ |
| 106728 | 107188 | if( rRun<=p->rRun && (prereq & p->prereq)==prereq ){ |
| | @@ -106803,13 +107263,10 @@ |
| 106803 | 107263 | if( pWC->a!=pWC->aStatic ){ |
| 106804 | 107264 | sqlite3DbFree(db, pWC->a); |
| 106805 | 107265 | } |
| 106806 | 107266 | } |
| 106807 | 107267 | |
| 106808 | | -/* Forward declaration */ |
| 106809 | | -static WhereCost whereCost(tRowcnt x); |
| 106810 | | - |
| 106811 | 107268 | /* |
| 106812 | 107269 | ** Add a single new WhereTerm entry to the WhereClause object pWC. |
| 106813 | 107270 | ** The new WhereTerm object is constructed from Expr p and with wtFlags. |
| 106814 | 107271 | ** The index in pWC->a[] of the new WhereTerm is returned on success. |
| 106815 | 107272 | ** 0 is returned if the new WhereTerm could not be added due to a memory |
| | @@ -106848,11 +107305,11 @@ |
| 106848 | 107305 | } |
| 106849 | 107306 | pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]); |
| 106850 | 107307 | } |
| 106851 | 107308 | pTerm = &pWC->a[idx = pWC->nTerm++]; |
| 106852 | 107309 | if( p && ExprHasProperty(p, EP_Unlikely) ){ |
| 106853 | | - pTerm->truthProb = whereCost(p->iTable) - 99; |
| 107310 | + pTerm->truthProb = sqlite3LogEst(p->iTable) - 99; |
| 106854 | 107311 | }else{ |
| 106855 | 107312 | pTerm->truthProb = -1; |
| 106856 | 107313 | } |
| 106857 | 107314 | pTerm->pExpr = sqlite3ExprSkipCollate(p); |
| 106858 | 107315 | pTerm->wtFlags = wtFlags; |
| | @@ -108112,79 +108569,16 @@ |
| 108112 | 108569 | } |
| 108113 | 108570 | |
| 108114 | 108571 | return 0; |
| 108115 | 108572 | } |
| 108116 | 108573 | |
| 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 | 108574 | |
| 108181 | 108575 | /* |
| 108182 | 108576 | ** Estimate the logarithm of the input value to base 2. |
| 108183 | 108577 | */ |
| 108184 | | -static WhereCost estLog(WhereCost N){ |
| 108185 | | - WhereCost x = whereCost(N); |
| 108578 | +static LogEst estLog(LogEst N){ |
| 108579 | + LogEst x = sqlite3LogEst(N); |
| 108186 | 108580 | return x>33 ? x - 33 : 0; |
| 108187 | 108581 | } |
| 108188 | 108582 | |
| 108189 | 108583 | /* |
| 108190 | 108584 | ** Two routines for printing the content of an sqlite3_index_info |
| | @@ -108596,10 +108990,13 @@ |
| 108596 | 108990 | int iMin = 0; /* Smallest sample not yet tested */ |
| 108597 | 108991 | int i = pIdx->nSample; /* Smallest sample larger than or equal to pRec */ |
| 108598 | 108992 | int iTest; /* Next sample to test */ |
| 108599 | 108993 | int res; /* Result of comparison operation */ |
| 108600 | 108994 | |
| 108995 | +#ifndef SQLITE_DEBUG |
| 108996 | + UNUSED_PARAMETER( pParse ); |
| 108997 | +#endif |
| 108601 | 108998 | assert( pRec!=0 || pParse->db->mallocFailed ); |
| 108602 | 108999 | if( pRec==0 ) return; |
| 108603 | 109000 | iCol = pRec->nField - 1; |
| 108604 | 109001 | assert( pIdx->nSample>0 ); |
| 108605 | 109002 | assert( pRec->nField>0 && iCol<pIdx->nSampleCol ); |
| | @@ -108693,11 +109090,11 @@ |
| 108693 | 109090 | ** |
| 108694 | 109091 | ** ... FROM t1 WHERE a > ? AND a < ? ... |
| 108695 | 109092 | ** |
| 108696 | 109093 | ** then nEq is set to 0. |
| 108697 | 109094 | ** |
| 108698 | | -** When this function is called, *pnOut is set to the whereCost() of the |
| 109095 | +** When this function is called, *pnOut is set to the sqlite3LogEst() of the |
| 108699 | 109096 | ** number of rows that the index scan is expected to visit without |
| 108700 | 109097 | ** considering the range constraints. If nEq is 0, this is the number of |
| 108701 | 109098 | ** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced) |
| 108702 | 109099 | ** to account for the range contraints pLower and pUpper. |
| 108703 | 109100 | ** |
| | @@ -108709,19 +109106,19 @@ |
| 108709 | 109106 | static int whereRangeScanEst( |
| 108710 | 109107 | Parse *pParse, /* Parsing & code generating context */ |
| 108711 | 109108 | WhereLoopBuilder *pBuilder, |
| 108712 | 109109 | WhereTerm *pLower, /* Lower bound on the range. ex: "x>123" Might be NULL */ |
| 108713 | 109110 | WhereTerm *pUpper, /* Upper bound on the range. ex: "x<455" Might be NULL */ |
| 108714 | | - WhereCost *pnOut /* IN/OUT: Number of rows visited */ |
| 109111 | + WhereLoop *pLoop /* Modify the .nOut and maybe .rRun fields */ |
| 108715 | 109112 | ){ |
| 108716 | 109113 | int rc = SQLITE_OK; |
| 108717 | | - int nOut = (int)*pnOut; |
| 108718 | | - WhereCost nNew; |
| 109114 | + int nOut = pLoop->nOut; |
| 109115 | + LogEst nNew; |
| 108719 | 109116 | |
| 108720 | 109117 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 108721 | | - Index *p = pBuilder->pNew->u.btree.pIndex; |
| 108722 | | - int nEq = pBuilder->pNew->u.btree.nEq; |
| 109118 | + Index *p = pLoop->u.btree.pIndex; |
| 109119 | + int nEq = pLoop->u.btree.nEq; |
| 108723 | 109120 | |
| 108724 | 109121 | if( p->nSample>0 |
| 108725 | 109122 | && nEq==pBuilder->nRecValid |
| 108726 | 109123 | && nEq<p->nSampleCol |
| 108727 | 109124 | && OptimizationEnabled(pParse->db, SQLITE_Stat3) |
| | @@ -108798,18 +109195,18 @@ |
| 108798 | 109195 | } |
| 108799 | 109196 | |
| 108800 | 109197 | pBuilder->pRec = pRec; |
| 108801 | 109198 | if( rc==SQLITE_OK ){ |
| 108802 | 109199 | if( iUpper>iLower ){ |
| 108803 | | - nNew = whereCost(iUpper - iLower); |
| 109200 | + nNew = sqlite3LogEst(iUpper - iLower); |
| 108804 | 109201 | }else{ |
| 108805 | | - nNew = 10; assert( 10==whereCost(2) ); |
| 109202 | + nNew = 10; assert( 10==sqlite3LogEst(2) ); |
| 108806 | 109203 | } |
| 108807 | 109204 | if( nNew<nOut ){ |
| 108808 | 109205 | nOut = nNew; |
| 108809 | 109206 | } |
| 108810 | | - *pnOut = (WhereCost)nOut; |
| 109207 | + pLoop->nOut = (LogEst)nOut; |
| 108811 | 109208 | WHERETRACE(0x100, ("range scan regions: %u..%u est=%d\n", |
| 108812 | 109209 | (u32)iLower, (u32)iUpper, nOut)); |
| 108813 | 109210 | return SQLITE_OK; |
| 108814 | 109211 | } |
| 108815 | 109212 | } |
| | @@ -108820,20 +109217,20 @@ |
| 108820 | 109217 | assert( pLower || pUpper ); |
| 108821 | 109218 | /* TUNING: Each inequality constraint reduces the search space 4-fold. |
| 108822 | 109219 | ** A BETWEEN operator, therefore, reduces the search space 16-fold */ |
| 108823 | 109220 | nNew = nOut; |
| 108824 | 109221 | if( pLower && (pLower->wtFlags & TERM_VNULL)==0 ){ |
| 108825 | | - nNew -= 20; assert( 20==whereCost(4) ); |
| 109222 | + nNew -= 20; assert( 20==sqlite3LogEst(4) ); |
| 108826 | 109223 | nOut--; |
| 108827 | 109224 | } |
| 108828 | 109225 | if( pUpper ){ |
| 108829 | | - nNew -= 20; assert( 20==whereCost(4) ); |
| 109226 | + nNew -= 20; assert( 20==sqlite3LogEst(4) ); |
| 108830 | 109227 | nOut--; |
| 108831 | 109228 | } |
| 108832 | 109229 | if( nNew<10 ) nNew = 10; |
| 108833 | 109230 | if( nNew<nOut ) nOut = nNew; |
| 108834 | | - *pnOut = (WhereCost)nOut; |
| 109231 | + pLoop->nOut = (LogEst)nOut; |
| 108835 | 109232 | return rc; |
| 108836 | 109233 | } |
| 108837 | 109234 | |
| 108838 | 109235 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 108839 | 109236 | /* |
| | @@ -110441,11 +110838,11 @@ |
| 110441 | 110838 | ** |
| 110442 | 110839 | ** In the current implementation, the first extra WHERE clause term reduces |
| 110443 | 110840 | ** the number of output rows by a factor of 10 and each additional term |
| 110444 | 110841 | ** reduces the number of output rows by sqrt(2). |
| 110445 | 110842 | */ |
| 110446 | | -static void whereLoopOutputAdjust(WhereClause *pWC, WhereLoop *pLoop, int iCur){ |
| 110843 | +static void whereLoopOutputAdjust(WhereClause *pWC, WhereLoop *pLoop){ |
| 110447 | 110844 | WhereTerm *pTerm, *pX; |
| 110448 | 110845 | Bitmask notAllowed = ~(pLoop->prereq|pLoop->maskSelf); |
| 110449 | 110846 | int i, j; |
| 110450 | 110847 | |
| 110451 | 110848 | if( !OptimizationEnabled(pWC->pWInfo->pParse->db, SQLITE_AdjustOutEst) ){ |
| | @@ -110473,11 +110870,11 @@ |
| 110473 | 110870 | */ |
| 110474 | 110871 | static int whereLoopAddBtreeIndex( |
| 110475 | 110872 | WhereLoopBuilder *pBuilder, /* The WhereLoop factory */ |
| 110476 | 110873 | struct SrcList_item *pSrc, /* FROM clause term being analyzed */ |
| 110477 | 110874 | Index *pProbe, /* An index on pSrc */ |
| 110478 | | - WhereCost nInMul /* log(Number of iterations due to IN) */ |
| 110875 | + LogEst nInMul /* log(Number of iterations due to IN) */ |
| 110479 | 110876 | ){ |
| 110480 | 110877 | WhereInfo *pWInfo = pBuilder->pWInfo; /* WHERE analyse context */ |
| 110481 | 110878 | Parse *pParse = pWInfo->pParse; /* Parsing context */ |
| 110482 | 110879 | sqlite3 *db = pParse->db; /* Database connection malloc context */ |
| 110483 | 110880 | WhereLoop *pNew; /* Template WhereLoop under construction */ |
| | @@ -110486,15 +110883,15 @@ |
| 110486 | 110883 | WhereScan scan; /* Iterator for WHERE terms */ |
| 110487 | 110884 | Bitmask saved_prereq; /* Original value of pNew->prereq */ |
| 110488 | 110885 | u16 saved_nLTerm; /* Original value of pNew->nLTerm */ |
| 110489 | 110886 | int saved_nEq; /* Original value of pNew->u.btree.nEq */ |
| 110490 | 110887 | u32 saved_wsFlags; /* Original value of pNew->wsFlags */ |
| 110491 | | - WhereCost saved_nOut; /* Original value of pNew->nOut */ |
| 110888 | + LogEst saved_nOut; /* Original value of pNew->nOut */ |
| 110492 | 110889 | int iCol; /* Index of the column in the table */ |
| 110493 | 110890 | int rc = SQLITE_OK; /* Return code */ |
| 110494 | | - WhereCost nRowEst; /* Estimated index selectivity */ |
| 110495 | | - WhereCost rLogSize; /* Logarithm of table size */ |
| 110891 | + LogEst nRowEst; /* Estimated index selectivity */ |
| 110892 | + LogEst rLogSize; /* Logarithm of table size */ |
| 110496 | 110893 | WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */ |
| 110497 | 110894 | |
| 110498 | 110895 | pNew = pBuilder->pNew; |
| 110499 | 110896 | if( db->mallocFailed ) return SQLITE_NOMEM; |
| 110500 | 110897 | |
| | @@ -110510,11 +110907,11 @@ |
| 110510 | 110907 | if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE); |
| 110511 | 110908 | |
| 110512 | 110909 | assert( pNew->u.btree.nEq<=pProbe->nColumn ); |
| 110513 | 110910 | if( pNew->u.btree.nEq < pProbe->nColumn ){ |
| 110514 | 110911 | iCol = pProbe->aiColumn[pNew->u.btree.nEq]; |
| 110515 | | - nRowEst = whereCost(pProbe->aiRowEst[pNew->u.btree.nEq+1]); |
| 110912 | + nRowEst = sqlite3LogEst(pProbe->aiRowEst[pNew->u.btree.nEq+1]); |
| 110516 | 110913 | if( nRowEst==0 && pProbe->onError==OE_None ) nRowEst = 1; |
| 110517 | 110914 | }else{ |
| 110518 | 110915 | iCol = -1; |
| 110519 | 110916 | nRowEst = 0; |
| 110520 | 110917 | } |
| | @@ -110524,11 +110921,11 @@ |
| 110524 | 110921 | saved_nLTerm = pNew->nLTerm; |
| 110525 | 110922 | saved_wsFlags = pNew->wsFlags; |
| 110526 | 110923 | saved_prereq = pNew->prereq; |
| 110527 | 110924 | saved_nOut = pNew->nOut; |
| 110528 | 110925 | pNew->rSetup = 0; |
| 110529 | | - rLogSize = estLog(whereCost(pProbe->aiRowEst[0])); |
| 110926 | + rLogSize = estLog(sqlite3LogEst(pProbe->aiRowEst[0])); |
| 110530 | 110927 | for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){ |
| 110531 | 110928 | int nIn = 0; |
| 110532 | 110929 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 110533 | 110930 | int nRecValid = pBuilder->nRecValid; |
| 110534 | 110931 | #endif |
| | @@ -110551,14 +110948,14 @@ |
| 110551 | 110948 | if( pTerm->eOperator & WO_IN ){ |
| 110552 | 110949 | Expr *pExpr = pTerm->pExpr; |
| 110553 | 110950 | pNew->wsFlags |= WHERE_COLUMN_IN; |
| 110554 | 110951 | if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 110555 | 110952 | /* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */ |
| 110556 | | - nIn = 46; assert( 46==whereCost(25) ); |
| 110953 | + nIn = 46; assert( 46==sqlite3LogEst(25) ); |
| 110557 | 110954 | }else if( ALWAYS(pExpr->x.pList && pExpr->x.pList->nExpr) ){ |
| 110558 | 110955 | /* "x IN (value, value, ...)" */ |
| 110559 | | - nIn = whereCost(pExpr->x.pList->nExpr); |
| 110956 | + nIn = sqlite3LogEst(pExpr->x.pList->nExpr); |
| 110560 | 110957 | } |
| 110561 | 110958 | pNew->rRun += nIn; |
| 110562 | 110959 | pNew->u.btree.nEq++; |
| 110563 | 110960 | pNew->nOut = nRowEst + nInMul + nIn; |
| 110564 | 110961 | }else if( pTerm->eOperator & (WO_EQ) ){ |
| | @@ -110576,11 +110973,11 @@ |
| 110576 | 110973 | pNew->nOut = nRowEst + nInMul; |
| 110577 | 110974 | }else if( pTerm->eOperator & (WO_ISNULL) ){ |
| 110578 | 110975 | pNew->wsFlags |= WHERE_COLUMN_NULL; |
| 110579 | 110976 | pNew->u.btree.nEq++; |
| 110580 | 110977 | /* TUNING: IS NULL selects 2 rows */ |
| 110581 | | - nIn = 10; assert( 10==whereCost(2) ); |
| 110978 | + nIn = 10; assert( 10==sqlite3LogEst(2) ); |
| 110582 | 110979 | pNew->nOut = nRowEst + nInMul + nIn; |
| 110583 | 110980 | }else if( pTerm->eOperator & (WO_GT|WO_GE) ){ |
| 110584 | 110981 | testcase( pTerm->eOperator & WO_GT ); |
| 110585 | 110982 | testcase( pTerm->eOperator & WO_GE ); |
| 110586 | 110983 | pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_BTM_LIMIT; |
| | @@ -110596,11 +110993,11 @@ |
| 110596 | 110993 | pNew->aLTerm[pNew->nLTerm-2] : 0; |
| 110597 | 110994 | } |
| 110598 | 110995 | if( pNew->wsFlags & WHERE_COLUMN_RANGE ){ |
| 110599 | 110996 | /* Adjust nOut and rRun for STAT3 range values */ |
| 110600 | 110997 | assert( pNew->nOut==saved_nOut ); |
| 110601 | | - whereRangeScanEst(pParse, pBuilder, pBtm, pTop, &pNew->nOut); |
| 110998 | + whereRangeScanEst(pParse, pBuilder, pBtm, pTop, pNew); |
| 110602 | 110999 | } |
| 110603 | 111000 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 110604 | 111001 | if( nInMul==0 |
| 110605 | 111002 | && pProbe->nSample |
| 110606 | 111003 | && pNew->u.btree.nEq<=pProbe->nSampleCol |
| | @@ -110616,23 +111013,23 @@ |
| 110616 | 111013 | && !ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 110617 | 111014 | rc = whereInScanEst(pParse, pBuilder, pExpr->x.pList, &nOut); |
| 110618 | 111015 | } |
| 110619 | 111016 | assert( nOut==0 || rc==SQLITE_OK ); |
| 110620 | 111017 | if( nOut ){ |
| 110621 | | - nOut = whereCost(nOut); |
| 110622 | | - pNew->nOut = MIN(nOut, saved_nOut); |
| 111018 | + pNew->nOut = sqlite3LogEst(nOut); |
| 111019 | + if( pNew->nOut>saved_nOut ) pNew->nOut = saved_nOut; |
| 110623 | 111020 | } |
| 110624 | 111021 | } |
| 110625 | 111022 | #endif |
| 110626 | 111023 | if( (pNew->wsFlags & (WHERE_IDX_ONLY|WHERE_IPK))==0 ){ |
| 110627 | 111024 | /* Each row involves a step of the index, then a binary search of |
| 110628 | 111025 | ** the main table */ |
| 110629 | | - pNew->rRun = whereCostAdd(pNew->rRun, rLogSize>27 ? rLogSize-17 : 10); |
| 111026 | + pNew->rRun = sqlite3LogEstAdd(pNew->rRun,rLogSize>27 ? rLogSize-17 : 10); |
| 110630 | 111027 | } |
| 110631 | 111028 | /* Step cost for each output row */ |
| 110632 | | - pNew->rRun = whereCostAdd(pNew->rRun, pNew->nOut); |
| 110633 | | - whereLoopOutputAdjust(pBuilder->pWC, pNew, pSrc->iCursor); |
| 111029 | + pNew->rRun = sqlite3LogEstAdd(pNew->rRun, pNew->nOut); |
| 111030 | + whereLoopOutputAdjust(pBuilder->pWC, pNew); |
| 110634 | 111031 | rc = whereLoopInsert(pBuilder, pNew); |
| 110635 | 111032 | if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 |
| 110636 | 111033 | && pNew->u.btree.nEq<(pProbe->nColumn + (pProbe->zName!=0)) |
| 110637 | 111034 | ){ |
| 110638 | 111035 | whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn); |
| | @@ -110727,18 +111124,20 @@ |
| 110727 | 111124 | struct SrcList_item *pSrc; /* The FROM clause btree term to add */ |
| 110728 | 111125 | WhereLoop *pNew; /* Template WhereLoop object */ |
| 110729 | 111126 | int rc = SQLITE_OK; /* Return code */ |
| 110730 | 111127 | int iSortIdx = 1; /* Index number */ |
| 110731 | 111128 | 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 */ |
| 111129 | + LogEst rSize; /* number of rows in the table */ |
| 111130 | + LogEst rLogSize; /* Logarithm of the number of rows in the table */ |
| 110734 | 111131 | WhereClause *pWC; /* The parsed WHERE clause */ |
| 111132 | + Table *pTab; /* Table being queried */ |
| 110735 | 111133 | |
| 110736 | 111134 | pNew = pBuilder->pNew; |
| 110737 | 111135 | pWInfo = pBuilder->pWInfo; |
| 110738 | 111136 | pTabList = pWInfo->pTabList; |
| 110739 | 111137 | pSrc = pTabList->a + pNew->iTab; |
| 111138 | + pTab = pSrc->pTab; |
| 110740 | 111139 | pWC = pBuilder->pWC; |
| 110741 | 111140 | assert( !IsVirtual(pSrc->pTab) ); |
| 110742 | 111141 | |
| 110743 | 111142 | if( pSrc->pIndex ){ |
| 110744 | 111143 | /* An INDEXED BY clause specifies a particular index to use */ |
| | @@ -110752,22 +111151,22 @@ |
| 110752 | 111151 | memset(&sPk, 0, sizeof(Index)); |
| 110753 | 111152 | sPk.nColumn = 1; |
| 110754 | 111153 | sPk.aiColumn = &aiColumnPk; |
| 110755 | 111154 | sPk.aiRowEst = aiRowEstPk; |
| 110756 | 111155 | sPk.onError = OE_Replace; |
| 110757 | | - sPk.pTable = pSrc->pTab; |
| 110758 | | - aiRowEstPk[0] = pSrc->pTab->nRowEst; |
| 111156 | + sPk.pTable = pTab; |
| 111157 | + aiRowEstPk[0] = pTab->nRowEst; |
| 110759 | 111158 | aiRowEstPk[1] = 1; |
| 110760 | 111159 | pFirst = pSrc->pTab->pIndex; |
| 110761 | 111160 | if( pSrc->notIndexed==0 ){ |
| 110762 | 111161 | /* The real indices of the table are only considered if the |
| 110763 | 111162 | ** NOT INDEXED qualifier is omitted from the FROM clause */ |
| 110764 | 111163 | sPk.pNext = pFirst; |
| 110765 | 111164 | } |
| 110766 | 111165 | pProbe = &sPk; |
| 110767 | 111166 | } |
| 110768 | | - rSize = whereCost(pSrc->pTab->nRowEst); |
| 111167 | + rSize = sqlite3LogEst(pTab->nRowEst); |
| 110769 | 111168 | rLogSize = estLog(rSize); |
| 110770 | 111169 | |
| 110771 | 111170 | #ifndef SQLITE_OMIT_AUTOMATIC_INDEX |
| 110772 | 111171 | /* Automatic indexes */ |
| 110773 | 111172 | if( !pBuilder->pOrSet |
| | @@ -110788,17 +111187,17 @@ |
| 110788 | 111187 | pNew->nLTerm = 1; |
| 110789 | 111188 | pNew->aLTerm[0] = pTerm; |
| 110790 | 111189 | /* TUNING: One-time cost for computing the automatic index is |
| 110791 | 111190 | ** approximately 7*N*log2(N) where N is the number of rows in |
| 110792 | 111191 | ** the table being indexed. */ |
| 110793 | | - pNew->rSetup = rLogSize + rSize + 28; assert( 28==whereCost(7) ); |
| 111192 | + pNew->rSetup = rLogSize + rSize + 28; assert( 28==sqlite3LogEst(7) ); |
| 110794 | 111193 | /* TUNING: Each index lookup yields 20 rows in the table. This |
| 110795 | 111194 | ** is more than the usual guess of 10 rows, since we have no way |
| 110796 | 111195 | ** of knowning how selective the index will ultimately be. It would |
| 110797 | 111196 | ** not be unreasonable to make this value much larger. */ |
| 110798 | | - pNew->nOut = 43; assert( 43==whereCost(20) ); |
| 110799 | | - pNew->rRun = whereCostAdd(rLogSize,pNew->nOut); |
| 111197 | + pNew->nOut = 43; assert( 43==sqlite3LogEst(20) ); |
| 111198 | + pNew->rRun = sqlite3LogEstAdd(rLogSize,pNew->nOut); |
| 110800 | 111199 | pNew->wsFlags = WHERE_AUTO_INDEX; |
| 110801 | 111200 | pNew->prereq = mExtra | pTerm->prereqRight; |
| 110802 | 111201 | rc = whereLoopInsert(pBuilder, pNew); |
| 110803 | 111202 | } |
| 110804 | 111203 | } |
| | @@ -110828,15 +111227,13 @@ |
| 110828 | 111227 | |
| 110829 | 111228 | /* Full table scan */ |
| 110830 | 111229 | pNew->iSortIdx = b ? iSortIdx : 0; |
| 110831 | 111230 | /* TUNING: Cost of full table scan is 3*(N + log2(N)). |
| 110832 | 111231 | ** + 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; |
| 110837 | | - whereLoopOutputAdjust(pWC, pNew, pSrc->iCursor); |
| 111232 | + ** over full scans. FIXME */ |
| 111233 | + pNew->rRun = sqlite3LogEstAdd(rSize,rLogSize) + 16; |
| 111234 | + whereLoopOutputAdjust(pWC, pNew); |
| 110838 | 111235 | rc = whereLoopInsert(pBuilder, pNew); |
| 110839 | 111236 | pNew->nOut = rSize; |
| 110840 | 111237 | if( rc ) break; |
| 110841 | 111238 | }else{ |
| 110842 | 111239 | Bitmask m = pSrc->colUsed & ~columnsInIndex(pProbe); |
| | @@ -110844,33 +111241,32 @@ |
| 110844 | 111241 | |
| 110845 | 111242 | /* Full scan via index */ |
| 110846 | 111243 | if( b |
| 110847 | 111244 | || ( m==0 |
| 110848 | 111245 | && pProbe->bUnordered==0 |
| 111246 | + && pProbe->szIdxRow<pTab->szTabRow |
| 110849 | 111247 | && (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 |
| 110850 | 111248 | && sqlite3GlobalConfig.bUseCis |
| 110851 | 111249 | && OptimizationEnabled(pWInfo->pParse->db, SQLITE_CoverIdxScan) |
| 110852 | 111250 | ) |
| 110853 | 111251 | ){ |
| 110854 | 111252 | pNew->iSortIdx = b ? iSortIdx : 0; |
| 110855 | 111253 | 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; |
| 111254 | + /* TUNING: Cost of a covering index scan is K*(N + log2(N)). |
| 111255 | + ** + The extra factor K of between 1.1 and 3.0 that depends |
| 111256 | + ** on the relative sizes of the table and the index. K |
| 111257 | + ** is smaller for smaller indices, thus favoring them. |
| 111258 | + */ |
| 111259 | + pNew->rRun = sqlite3LogEstAdd(rSize,rLogSize) + 1 + |
| 111260 | + (15*pProbe->szIdxRow)/pTab->szTabRow; |
| 110865 | 111261 | }else{ |
| 110866 | 111262 | assert( b!=0 ); |
| 110867 | 111263 | /* TUNING: Cost of scanning a non-covering index is (N+1)*log2(N) |
| 110868 | 111264 | ** which we will simplify to just N*log2(N) */ |
| 110869 | 111265 | pNew->rRun = rSize + rLogSize; |
| 110870 | 111266 | } |
| 110871 | | - whereLoopOutputAdjust(pWC, pNew, pSrc->iCursor); |
| 111267 | + whereLoopOutputAdjust(pWC, pNew); |
| 110872 | 111268 | rc = whereLoopInsert(pBuilder, pNew); |
| 110873 | 111269 | pNew->nOut = rSize; |
| 110874 | 111270 | if( rc ) break; |
| 110875 | 111271 | } |
| 110876 | 111272 | } |
| | @@ -111037,13 +111433,13 @@ |
| 111037 | 111433 | pIdxInfo->needToFreeIdxStr = 0; |
| 111038 | 111434 | pNew->u.vtab.idxStr = pIdxInfo->idxStr; |
| 111039 | 111435 | pNew->u.vtab.isOrdered = (u8)((pIdxInfo->nOrderBy!=0) |
| 111040 | 111436 | && pIdxInfo->orderByConsumed); |
| 111041 | 111437 | pNew->rSetup = 0; |
| 111042 | | - pNew->rRun = whereCostFromDouble(pIdxInfo->estimatedCost); |
| 111438 | + pNew->rRun = sqlite3LogEstFromDouble(pIdxInfo->estimatedCost); |
| 111043 | 111439 | /* TUNING: Every virtual table query returns 25 rows */ |
| 111044 | | - pNew->nOut = 46; assert( 46==whereCost(25) ); |
| 111440 | + pNew->nOut = 46; assert( 46==sqlite3LogEst(25) ); |
| 111045 | 111441 | whereLoopInsert(pBuilder, pNew); |
| 111046 | 111442 | if( pNew->u.vtab.needFree ){ |
| 111047 | 111443 | sqlite3_free(pNew->u.vtab.idxStr); |
| 111048 | 111444 | pNew->u.vtab.needFree = 0; |
| 111049 | 111445 | } |
| | @@ -111076,10 +111472,12 @@ |
| 111076 | 111472 | pWC = pBuilder->pWC; |
| 111077 | 111473 | if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK; |
| 111078 | 111474 | pWCEnd = pWC->a + pWC->nTerm; |
| 111079 | 111475 | pNew = pBuilder->pNew; |
| 111080 | 111476 | memset(&sSum, 0, sizeof(sSum)); |
| 111477 | + pItem = pWInfo->pTabList->a + pNew->iTab; |
| 111478 | + iCur = pItem->iCursor; |
| 111081 | 111479 | |
| 111082 | 111480 | for(pTerm=pWC->a; pTerm<pWCEnd && rc==SQLITE_OK; pTerm++){ |
| 111083 | 111481 | if( (pTerm->eOperator & WO_OR)!=0 |
| 111084 | 111482 | && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0 |
| 111085 | 111483 | ){ |
| | @@ -111087,12 +111485,10 @@ |
| 111087 | 111485 | WhereTerm * const pOrWCEnd = &pOrWC->a[pOrWC->nTerm]; |
| 111088 | 111486 | WhereTerm *pOrTerm; |
| 111089 | 111487 | int once = 1; |
| 111090 | 111488 | int i, j; |
| 111091 | 111489 | |
| 111092 | | - pItem = pWInfo->pTabList->a + pNew->iTab; |
| 111093 | | - iCur = pItem->iCursor; |
| 111094 | 111490 | sSubBuild = *pBuilder; |
| 111095 | 111491 | sSubBuild.pOrderBy = 0; |
| 111096 | 111492 | sSubBuild.pOrSet = &sCur; |
| 111097 | 111493 | |
| 111098 | 111494 | for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){ |
| | @@ -111129,12 +111525,12 @@ |
| 111129 | 111525 | whereOrMove(&sPrev, &sSum); |
| 111130 | 111526 | sSum.n = 0; |
| 111131 | 111527 | for(i=0; i<sPrev.n; i++){ |
| 111132 | 111528 | for(j=0; j<sCur.n; j++){ |
| 111133 | 111529 | 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)); |
| 111530 | + sqlite3LogEstAdd(sPrev.a[i].rRun, sCur.a[j].rRun), |
| 111531 | + sqlite3LogEstAdd(sPrev.a[i].nOut, sCur.a[j].nOut)); |
| 111136 | 111532 | } |
| 111137 | 111533 | } |
| 111138 | 111534 | } |
| 111139 | 111535 | } |
| 111140 | 111536 | pNew->nLTerm = 1; |
| | @@ -111468,23 +111864,23 @@ |
| 111468 | 111864 | ** costs if nRowEst==0. |
| 111469 | 111865 | ** |
| 111470 | 111866 | ** Return SQLITE_OK on success or SQLITE_NOMEM of a memory allocation |
| 111471 | 111867 | ** error occurs. |
| 111472 | 111868 | */ |
| 111473 | | -static int wherePathSolver(WhereInfo *pWInfo, WhereCost nRowEst){ |
| 111869 | +static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ |
| 111474 | 111870 | int mxChoice; /* Maximum number of simultaneous paths tracked */ |
| 111475 | 111871 | int nLoop; /* Number of terms in the join */ |
| 111476 | 111872 | Parse *pParse; /* Parsing context */ |
| 111477 | 111873 | sqlite3 *db; /* The database connection */ |
| 111478 | 111874 | int iLoop; /* Loop counter over the terms of the join */ |
| 111479 | 111875 | int ii, jj; /* Loop counters */ |
| 111480 | 111876 | 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 */ |
| 111877 | + LogEst rCost; /* Cost of a path */ |
| 111878 | + LogEst nOut; /* Number of outputs */ |
| 111879 | + LogEst mxCost = 0; /* Maximum cost of a set of paths */ |
| 111880 | + LogEst mxOut = 0; /* Maximum nOut value on the set of paths */ |
| 111881 | + LogEst rSortCost; /* Cost to do a sort */ |
| 111486 | 111882 | int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */ |
| 111487 | 111883 | WherePath *aFrom; /* All nFrom paths at the previous level */ |
| 111488 | 111884 | WherePath *aTo; /* The nTo best paths at the current level */ |
| 111489 | 111885 | WherePath *pFrom; /* An element of aFrom[] that we are working on */ |
| 111490 | 111886 | WherePath *pTo; /* An element of aTo[] that we are working on */ |
| | @@ -111517,21 +111913,23 @@ |
| 111517 | 111913 | /* Seed the search with a single WherePath containing zero WhereLoops. |
| 111518 | 111914 | ** |
| 111519 | 111915 | ** TUNING: Do not let the number of iterations go above 25. If the cost |
| 111520 | 111916 | ** of computing an automatic index is not paid back within the first 25 |
| 111521 | 111917 | ** rows, then do not use the automatic index. */ |
| 111522 | | - aFrom[0].nRow = MIN(pParse->nQueryLoop, 46); assert( 46==whereCost(25) ); |
| 111918 | + aFrom[0].nRow = MIN(pParse->nQueryLoop, 46); assert( 46==sqlite3LogEst(25) ); |
| 111523 | 111919 | nFrom = 1; |
| 111524 | 111920 | |
| 111525 | 111921 | /* Precompute the cost of sorting the final result set, if the caller |
| 111526 | 111922 | ** to sqlite3WhereBegin() was concerned about sorting */ |
| 111527 | 111923 | rSortCost = 0; |
| 111528 | 111924 | if( pWInfo->pOrderBy==0 || nRowEst==0 ){ |
| 111529 | 111925 | aFrom[0].isOrderedValid = 1; |
| 111530 | 111926 | }else{ |
| 111531 | | - /* TUNING: Estimated cost of sorting is N*log2(N) where N is the |
| 111532 | | - ** number of output rows. */ |
| 111927 | + /* TUNING: Estimated cost of sorting is 48*N*log2(N) where N is the |
| 111928 | + ** number of output rows. The 48 is the expected size of a row to sort. |
| 111929 | + ** FIXME: compute a better estimate of the 48 multiplier based on the |
| 111930 | + ** result set expressions. */ |
| 111533 | 111931 | rSortCost = nRowEst + estLog(nRowEst); |
| 111534 | 111932 | WHERETRACE(0x002,("---- sort cost=%-3d\n", rSortCost)); |
| 111535 | 111933 | } |
| 111536 | 111934 | |
| 111537 | 111935 | /* Compute successively longer WherePaths using the previous generation |
| | @@ -111547,12 +111945,12 @@ |
| 111547 | 111945 | u8 isOrdered = pFrom->isOrdered; |
| 111548 | 111946 | if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue; |
| 111549 | 111947 | if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue; |
| 111550 | 111948 | /* At this point, pWLoop is a candidate to be the next loop. |
| 111551 | 111949 | ** Compute its cost */ |
| 111552 | | - rCost = whereCostAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow); |
| 111553 | | - rCost = whereCostAdd(rCost, pFrom->rCost); |
| 111950 | + rCost = sqlite3LogEstAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow); |
| 111951 | + rCost = sqlite3LogEstAdd(rCost, pFrom->rCost); |
| 111554 | 111952 | nOut = pFrom->nRow + pWLoop->nOut; |
| 111555 | 111953 | maskNew = pFrom->maskLoop | pWLoop->maskSelf; |
| 111556 | 111954 | if( !isOrderedValid ){ |
| 111557 | 111955 | switch( wherePathSatisfiesOrderBy(pWInfo, |
| 111558 | 111956 | pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags, |
| | @@ -111562,11 +111960,11 @@ |
| 111562 | 111960 | isOrderedValid = 1; |
| 111563 | 111961 | break; |
| 111564 | 111962 | case 0: /* No. pFrom+pWLoop will require a separate sort */ |
| 111565 | 111963 | isOrdered = 0; |
| 111566 | 111964 | isOrderedValid = 1; |
| 111567 | | - rCost = whereCostAdd(rCost, rSortCost); |
| 111965 | + rCost = sqlite3LogEstAdd(rCost, rSortCost); |
| 111568 | 111966 | break; |
| 111569 | 111967 | default: /* Cannot tell yet. Try again on the next iteration */ |
| 111570 | 111968 | break; |
| 111571 | 111969 | } |
| 111572 | 111970 | }else{ |
| | @@ -111769,11 +112167,11 @@ |
| 111769 | 112167 | pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW; |
| 111770 | 112168 | pLoop->aLTerm[0] = pTerm; |
| 111771 | 112169 | pLoop->nLTerm = 1; |
| 111772 | 112170 | pLoop->u.btree.nEq = 1; |
| 111773 | 112171 | /* TUNING: Cost of a rowid lookup is 10 */ |
| 111774 | | - pLoop->rRun = 33; /* 33==whereCost(10) */ |
| 112172 | + pLoop->rRun = 33; /* 33==sqlite3LogEst(10) */ |
| 111775 | 112173 | }else{ |
| 111776 | 112174 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 111777 | 112175 | assert( pLoop->aLTermSpace==pLoop->aLTerm ); |
| 111778 | 112176 | assert( ArraySize(pLoop->aLTermSpace)==4 ); |
| 111779 | 112177 | if( pIdx->onError==OE_None |
| | @@ -111792,16 +112190,16 @@ |
| 111792 | 112190 | } |
| 111793 | 112191 | pLoop->nLTerm = j; |
| 111794 | 112192 | pLoop->u.btree.nEq = j; |
| 111795 | 112193 | pLoop->u.btree.pIndex = pIdx; |
| 111796 | 112194 | /* TUNING: Cost of a unique index lookup is 15 */ |
| 111797 | | - pLoop->rRun = 39; /* 39==whereCost(15) */ |
| 112195 | + pLoop->rRun = 39; /* 39==sqlite3LogEst(15) */ |
| 111798 | 112196 | break; |
| 111799 | 112197 | } |
| 111800 | 112198 | } |
| 111801 | 112199 | if( pLoop->wsFlags ){ |
| 111802 | | - pLoop->nOut = (WhereCost)1; |
| 112200 | + pLoop->nOut = (LogEst)1; |
| 111803 | 112201 | pWInfo->a[0].pWLoop = pLoop; |
| 111804 | 112202 | pLoop->maskSelf = getMask(&pWInfo->sMaskSet, iCur); |
| 111805 | 112203 | pWInfo->a[0].iTabCur = iCur; |
| 111806 | 112204 | pWInfo->nRowOut = 1; |
| 111807 | 112205 | if( pWInfo->pOrderBy ) pWInfo->bOBSat = 1; |
| | @@ -112165,11 +112563,11 @@ |
| 112165 | 112563 | WHERETRACE(0xffff,("*** Optimizer Finished ***\n")); |
| 112166 | 112564 | pWInfo->pParse->nQueryLoop += pWInfo->nRowOut; |
| 112167 | 112565 | |
| 112168 | 112566 | /* If the caller is an UPDATE or DELETE statement that is requesting |
| 112169 | 112567 | ** to use a one-pass algorithm, determine if this is appropriate. |
| 112170 | | - ** The one-pass algorithm only works if the WHERE clause constraints |
| 112568 | + ** The one-pass algorithm only works if the WHERE clause constrains |
| 112171 | 112569 | ** the statement to update a single row. |
| 112172 | 112570 | */ |
| 112173 | 112571 | assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 ); |
| 112174 | 112572 | if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 |
| 112175 | 112573 | && (pWInfo->a[0].pWLoop->wsFlags & WHERE_ONEROW)!=0 ){ |
| | @@ -121583,10 +121981,16 @@ |
| 121583 | 121981 | ** verifying the operation of the SQLite core. |
| 121584 | 121982 | */ |
| 121585 | 121983 | int inTransaction; /* True after xBegin but before xCommit/xRollback */ |
| 121586 | 121984 | int mxSavepoint; /* Largest valid xSavepoint integer */ |
| 121587 | 121985 | #endif |
| 121986 | + |
| 121987 | +#ifdef SQLITE_TEST |
| 121988 | + /* True to disable the incremental doclist optimization. This is controled |
| 121989 | + ** by special insert command 'test-no-incr-doclist'. */ |
| 121990 | + int bNoIncrDoclist; |
| 121991 | +#endif |
| 121588 | 121992 | }; |
| 121589 | 121993 | |
| 121590 | 121994 | /* |
| 121591 | 121995 | ** When the core wants to read from the virtual table, it creates a |
| 121592 | 121996 | ** virtual table cursor (an instance of the following structure) using |
| | @@ -121608,11 +122012,12 @@ |
| 121608 | 122012 | int nDoclist; /* Size of buffer at aDoclist */ |
| 121609 | 122013 | u8 bDesc; /* True to sort in descending order */ |
| 121610 | 122014 | int eEvalmode; /* An FTS3_EVAL_XX constant */ |
| 121611 | 122015 | int nRowAvg; /* Average size of database rows, in pages */ |
| 121612 | 122016 | sqlite3_int64 nDoc; /* Documents in table */ |
| 121613 | | - |
| 122017 | + i64 iMinDocid; /* Minimum docid to return */ |
| 122018 | + i64 iMaxDocid; /* Maximum docid to return */ |
| 121614 | 122019 | int isMatchinfoNeeded; /* True when aMatchinfo[] needs filling in */ |
| 121615 | 122020 | u32 *aMatchinfo; /* Information about most recent match */ |
| 121616 | 122021 | int nMatchinfo; /* Number of elements in aMatchinfo[] */ |
| 121617 | 122022 | char *zMatchinfo; /* Matchinfo specification */ |
| 121618 | 122023 | }; |
| | @@ -121638,10 +122043,19 @@ |
| 121638 | 122043 | */ |
| 121639 | 122044 | #define FTS3_FULLSCAN_SEARCH 0 /* Linear scan of %_content table */ |
| 121640 | 122045 | #define FTS3_DOCID_SEARCH 1 /* Lookup by rowid on %_content table */ |
| 121641 | 122046 | #define FTS3_FULLTEXT_SEARCH 2 /* Full-text index search */ |
| 121642 | 122047 | |
| 122048 | +/* |
| 122049 | +** The lower 16-bits of the sqlite3_index_info.idxNum value set by |
| 122050 | +** the xBestIndex() method contains the Fts3Cursor.eSearch value described |
| 122051 | +** above. The upper 16-bits contain a combination of the following |
| 122052 | +** bits, used to describe extra constraints on full-text searches. |
| 122053 | +*/ |
| 122054 | +#define FTS3_HAVE_LANGID 0x00010000 /* languageid=? */ |
| 122055 | +#define FTS3_HAVE_DOCID_GE 0x00020000 /* docid>=? */ |
| 122056 | +#define FTS3_HAVE_DOCID_LE 0x00040000 /* docid<=? */ |
| 121643 | 122057 | |
| 121644 | 122058 | struct Fts3Doclist { |
| 121645 | 122059 | char *aAll; /* Array containing doclist (or NULL) */ |
| 121646 | 122060 | int nAll; /* Size of a[] in bytes */ |
| 121647 | 122061 | char *pNextDocid; /* Pointer to next docid */ |
| | @@ -123058,27 +123472,31 @@ |
| 123058 | 123472 | */ |
| 123059 | 123473 | static int fts3BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){ |
| 123060 | 123474 | Fts3Table *p = (Fts3Table *)pVTab; |
| 123061 | 123475 | int i; /* Iterator variable */ |
| 123062 | 123476 | int iCons = -1; /* Index of constraint to use */ |
| 123477 | + |
| 123063 | 123478 | int iLangidCons = -1; /* Index of langid=x constraint, if present */ |
| 123479 | + int iDocidGe = -1; /* Index of docid>=x constraint, if present */ |
| 123480 | + int iDocidLe = -1; /* Index of docid<=x constraint, if present */ |
| 123481 | + int iIdx; |
| 123064 | 123482 | |
| 123065 | 123483 | /* By default use a full table scan. This is an expensive option, |
| 123066 | 123484 | ** so search through the constraints to see if a more efficient |
| 123067 | 123485 | ** strategy is possible. |
| 123068 | 123486 | */ |
| 123069 | 123487 | pInfo->idxNum = FTS3_FULLSCAN_SEARCH; |
| 123070 | 123488 | pInfo->estimatedCost = 5000000; |
| 123071 | 123489 | for(i=0; i<pInfo->nConstraint; i++){ |
| 123490 | + int bDocid; /* True if this constraint is on docid */ |
| 123072 | 123491 | struct sqlite3_index_constraint *pCons = &pInfo->aConstraint[i]; |
| 123073 | 123492 | if( pCons->usable==0 ) continue; |
| 123493 | + |
| 123494 | + bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1); |
| 123074 | 123495 | |
| 123075 | 123496 | /* 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 | | - ){ |
| 123497 | + if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){ |
| 123080 | 123498 | pInfo->idxNum = FTS3_DOCID_SEARCH; |
| 123081 | 123499 | pInfo->estimatedCost = 1.0; |
| 123082 | 123500 | iCons = i; |
| 123083 | 123501 | } |
| 123084 | 123502 | |
| | @@ -123103,18 +123521,42 @@ |
| 123103 | 123521 | if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ |
| 123104 | 123522 | && pCons->iColumn==p->nColumn + 2 |
| 123105 | 123523 | ){ |
| 123106 | 123524 | iLangidCons = i; |
| 123107 | 123525 | } |
| 123526 | + |
| 123527 | + if( bDocid ){ |
| 123528 | + switch( pCons->op ){ |
| 123529 | + case SQLITE_INDEX_CONSTRAINT_GE: |
| 123530 | + case SQLITE_INDEX_CONSTRAINT_GT: |
| 123531 | + iDocidGe = i; |
| 123532 | + break; |
| 123533 | + |
| 123534 | + case SQLITE_INDEX_CONSTRAINT_LE: |
| 123535 | + case SQLITE_INDEX_CONSTRAINT_LT: |
| 123536 | + iDocidLe = i; |
| 123537 | + break; |
| 123538 | + } |
| 123539 | + } |
| 123108 | 123540 | } |
| 123109 | 123541 | |
| 123542 | + iIdx = 1; |
| 123110 | 123543 | if( iCons>=0 ){ |
| 123111 | | - pInfo->aConstraintUsage[iCons].argvIndex = 1; |
| 123544 | + pInfo->aConstraintUsage[iCons].argvIndex = iIdx++; |
| 123112 | 123545 | pInfo->aConstraintUsage[iCons].omit = 1; |
| 123113 | 123546 | } |
| 123114 | 123547 | if( iLangidCons>=0 ){ |
| 123115 | | - pInfo->aConstraintUsage[iLangidCons].argvIndex = 2; |
| 123548 | + pInfo->idxNum |= FTS3_HAVE_LANGID; |
| 123549 | + pInfo->aConstraintUsage[iLangidCons].argvIndex = iIdx++; |
| 123550 | + } |
| 123551 | + if( iDocidGe>=0 ){ |
| 123552 | + pInfo->idxNum |= FTS3_HAVE_DOCID_GE; |
| 123553 | + pInfo->aConstraintUsage[iDocidGe].argvIndex = iIdx++; |
| 123554 | + } |
| 123555 | + if( iDocidLe>=0 ){ |
| 123556 | + pInfo->idxNum |= FTS3_HAVE_DOCID_LE; |
| 123557 | + pInfo->aConstraintUsage[iDocidLe].argvIndex = iIdx++; |
| 123116 | 123558 | } |
| 123117 | 123559 | |
| 123118 | 123560 | /* Regardless of the strategy selected, FTS can deliver rows in rowid (or |
| 123119 | 123561 | ** docid) order. Both ascending and descending are possible. |
| 123120 | 123562 | */ |
| | @@ -124556,10 +124998,37 @@ |
| 124556 | 124998 | rc = fts3EvalNext((Fts3Cursor *)pCursor); |
| 124557 | 124999 | } |
| 124558 | 125000 | assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 ); |
| 124559 | 125001 | return rc; |
| 124560 | 125002 | } |
| 125003 | + |
| 125004 | +/* |
| 125005 | +** The following are copied from sqliteInt.h. |
| 125006 | +** |
| 125007 | +** Constants for the largest and smallest possible 64-bit signed integers. |
| 125008 | +** These macros are designed to work correctly on both 32-bit and 64-bit |
| 125009 | +** compilers. |
| 125010 | +*/ |
| 125011 | +#ifndef SQLITE_AMALGAMATION |
| 125012 | +# define LARGEST_INT64 (0xffffffff|(((sqlite3_int64)0x7fffffff)<<32)) |
| 125013 | +# define SMALLEST_INT64 (((sqlite3_int64)-1) - LARGEST_INT64) |
| 125014 | +#endif |
| 125015 | + |
| 125016 | +/* |
| 125017 | +** If the numeric type of argument pVal is "integer", then return it |
| 125018 | +** converted to a 64-bit signed integer. Otherwise, return a copy of |
| 125019 | +** the second parameter, iDefault. |
| 125020 | +*/ |
| 125021 | +static sqlite3_int64 fts3DocidRange(sqlite3_value *pVal, i64 iDefault){ |
| 125022 | + if( pVal ){ |
| 125023 | + int eType = sqlite3_value_numeric_type(pVal); |
| 125024 | + if( eType==SQLITE_INTEGER ){ |
| 125025 | + return sqlite3_value_int64(pVal); |
| 125026 | + } |
| 125027 | + } |
| 125028 | + return iDefault; |
| 125029 | +} |
| 124561 | 125030 | |
| 124562 | 125031 | /* |
| 124563 | 125032 | ** This is the xFilter interface for the virtual table. See |
| 124564 | 125033 | ** the virtual table xFilter method documentation for additional |
| 124565 | 125034 | ** information. |
| | @@ -124582,44 +125051,62 @@ |
| 124582 | 125051 | int nVal, /* Number of elements in apVal */ |
| 124583 | 125052 | sqlite3_value **apVal /* Arguments for the indexing scheme */ |
| 124584 | 125053 | ){ |
| 124585 | 125054 | int rc; |
| 124586 | 125055 | char *zSql; /* SQL statement used to access %_content */ |
| 125056 | + int eSearch; |
| 124587 | 125057 | Fts3Table *p = (Fts3Table *)pCursor->pVtab; |
| 124588 | 125058 | Fts3Cursor *pCsr = (Fts3Cursor *)pCursor; |
| 125059 | + |
| 125060 | + sqlite3_value *pCons = 0; /* The MATCH or rowid constraint, if any */ |
| 125061 | + sqlite3_value *pLangid = 0; /* The "langid = ?" constraint, if any */ |
| 125062 | + sqlite3_value *pDocidGe = 0; /* The "docid >= ?" constraint, if any */ |
| 125063 | + sqlite3_value *pDocidLe = 0; /* The "docid <= ?" constraint, if any */ |
| 125064 | + int iIdx; |
| 124589 | 125065 | |
| 124590 | 125066 | UNUSED_PARAMETER(idxStr); |
| 124591 | 125067 | UNUSED_PARAMETER(nVal); |
| 124592 | 125068 | |
| 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) ); |
| 125069 | + eSearch = (idxNum & 0x0000FFFF); |
| 125070 | + assert( eSearch>=0 && eSearch<=(FTS3_FULLTEXT_SEARCH+p->nColumn) ); |
| 124596 | 125071 | assert( p->pSegments==0 ); |
| 125072 | + |
| 125073 | + /* Collect arguments into local variables */ |
| 125074 | + iIdx = 0; |
| 125075 | + if( eSearch!=FTS3_FULLSCAN_SEARCH ) pCons = apVal[iIdx++]; |
| 125076 | + if( idxNum & FTS3_HAVE_LANGID ) pLangid = apVal[iIdx++]; |
| 125077 | + if( idxNum & FTS3_HAVE_DOCID_GE ) pDocidGe = apVal[iIdx++]; |
| 125078 | + if( idxNum & FTS3_HAVE_DOCID_LE ) pDocidLe = apVal[iIdx++]; |
| 125079 | + assert( iIdx==nVal ); |
| 124597 | 125080 | |
| 124598 | 125081 | /* In case the cursor has been used before, clear it now. */ |
| 124599 | 125082 | sqlite3_finalize(pCsr->pStmt); |
| 124600 | 125083 | sqlite3_free(pCsr->aDoclist); |
| 124601 | 125084 | sqlite3Fts3ExprFree(pCsr->pExpr); |
| 124602 | 125085 | memset(&pCursor[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor)); |
| 124603 | 125086 | |
| 125087 | + /* Set the lower and upper bounds on docids to return */ |
| 125088 | + pCsr->iMinDocid = fts3DocidRange(pDocidGe, SMALLEST_INT64); |
| 125089 | + pCsr->iMaxDocid = fts3DocidRange(pDocidLe, LARGEST_INT64); |
| 125090 | + |
| 124604 | 125091 | if( idxStr ){ |
| 124605 | 125092 | pCsr->bDesc = (idxStr[0]=='D'); |
| 124606 | 125093 | }else{ |
| 124607 | 125094 | pCsr->bDesc = p->bDescIdx; |
| 124608 | 125095 | } |
| 124609 | | - pCsr->eSearch = (i16)idxNum; |
| 125096 | + pCsr->eSearch = (i16)eSearch; |
| 124610 | 125097 | |
| 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]); |
| 125098 | + if( eSearch!=FTS3_DOCID_SEARCH && eSearch!=FTS3_FULLSCAN_SEARCH ){ |
| 125099 | + int iCol = eSearch-FTS3_FULLTEXT_SEARCH; |
| 125100 | + const char *zQuery = (const char *)sqlite3_value_text(pCons); |
| 124614 | 125101 | |
| 124615 | | - if( zQuery==0 && sqlite3_value_type(apVal[0])!=SQLITE_NULL ){ |
| 125102 | + if( zQuery==0 && sqlite3_value_type(pCons)!=SQLITE_NULL ){ |
| 124616 | 125103 | return SQLITE_NOMEM; |
| 124617 | 125104 | } |
| 124618 | 125105 | |
| 124619 | 125106 | pCsr->iLangid = 0; |
| 124620 | | - if( nVal==2 ) pCsr->iLangid = sqlite3_value_int(apVal[1]); |
| 125107 | + if( pLangid ) pCsr->iLangid = sqlite3_value_int(pLangid); |
| 124621 | 125108 | |
| 124622 | 125109 | assert( p->base.zErrMsg==0 ); |
| 124623 | 125110 | rc = sqlite3Fts3ExprParse(p->pTokenizer, pCsr->iLangid, |
| 124624 | 125111 | p->azColumn, p->bFts4, p->nColumn, iCol, zQuery, -1, &pCsr->pExpr, |
| 124625 | 125112 | &p->base.zErrMsg |
| | @@ -124638,11 +125125,11 @@ |
| 124638 | 125125 | /* Compile a SELECT statement for this cursor. For a full-table-scan, the |
| 124639 | 125126 | ** statement loops through all rows of the %_content table. For a |
| 124640 | 125127 | ** full-text query or docid lookup, the statement retrieves a single |
| 124641 | 125128 | ** row by docid. |
| 124642 | 125129 | */ |
| 124643 | | - if( idxNum==FTS3_FULLSCAN_SEARCH ){ |
| 125130 | + if( eSearch==FTS3_FULLSCAN_SEARCH ){ |
| 124644 | 125131 | zSql = sqlite3_mprintf( |
| 124645 | 125132 | "SELECT %s ORDER BY rowid %s", |
| 124646 | 125133 | p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC") |
| 124647 | 125134 | ); |
| 124648 | 125135 | if( zSql ){ |
| | @@ -124649,14 +125136,14 @@ |
| 124649 | 125136 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0); |
| 124650 | 125137 | sqlite3_free(zSql); |
| 124651 | 125138 | }else{ |
| 124652 | 125139 | rc = SQLITE_NOMEM; |
| 124653 | 125140 | } |
| 124654 | | - }else if( idxNum==FTS3_DOCID_SEARCH ){ |
| 125141 | + }else if( eSearch==FTS3_DOCID_SEARCH ){ |
| 124655 | 125142 | rc = fts3CursorSeekStmt(pCsr, &pCsr->pStmt); |
| 124656 | 125143 | if( rc==SQLITE_OK ){ |
| 124657 | | - rc = sqlite3_bind_value(pCsr->pStmt, 1, apVal[0]); |
| 125144 | + rc = sqlite3_bind_value(pCsr->pStmt, 1, pCons); |
| 124658 | 125145 | } |
| 124659 | 125146 | } |
| 124660 | 125147 | if( rc!=SQLITE_OK ) return rc; |
| 124661 | 125148 | |
| 124662 | 125149 | return fts3NextMethod(pCursor); |
| | @@ -125543,10 +126030,16 @@ |
| 125543 | 126030 | } |
| 125544 | 126031 | |
| 125545 | 126032 | return SQLITE_OK; |
| 125546 | 126033 | } |
| 125547 | 126034 | |
| 126035 | +/* |
| 126036 | +** Maximum number of tokens a phrase may have to be considered for the |
| 126037 | +** incremental doclists strategy. |
| 126038 | +*/ |
| 126039 | +#define MAX_INCR_PHRASE_TOKENS 4 |
| 126040 | + |
| 125548 | 126041 | /* |
| 125549 | 126042 | ** This function is called for each Fts3Phrase in a full-text query |
| 125550 | 126043 | ** expression to initialize the mechanism for returning rows. Once this |
| 125551 | 126044 | ** function has been called successfully on an Fts3Phrase, it may be |
| 125552 | 126045 | ** used with fts3EvalPhraseNext() to iterate through the matching docids. |
| | @@ -125556,27 +126049,47 @@ |
| 125556 | 126049 | ** memory within this call. |
| 125557 | 126050 | ** |
| 125558 | 126051 | ** SQLITE_OK is returned if no error occurs, otherwise an SQLite error code. |
| 125559 | 126052 | */ |
| 125560 | 126053 | static int fts3EvalPhraseStart(Fts3Cursor *pCsr, int bOptOk, Fts3Phrase *p){ |
| 125561 | | - int rc; /* Error code */ |
| 125562 | | - Fts3PhraseToken *pFirst = &p->aToken[0]; |
| 125563 | 126054 | 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 | | - ){ |
| 126055 | + int rc = SQLITE_OK; /* Error code */ |
| 126056 | + int i; |
| 126057 | + |
| 126058 | + /* Determine if doclists may be loaded from disk incrementally. This is |
| 126059 | + ** possible if the bOptOk argument is true, the FTS doclists will be |
| 126060 | + ** scanned in forward order, and the phrase consists of |
| 126061 | + ** MAX_INCR_PHRASE_TOKENS or fewer tokens, none of which are are "^first" |
| 126062 | + ** tokens or prefix tokens that cannot use a prefix-index. */ |
| 126063 | + int bHaveIncr = 0; |
| 126064 | + int bIncrOk = (bOptOk |
| 126065 | + && pCsr->bDesc==pTab->bDescIdx |
| 126066 | + && p->nToken<=MAX_INCR_PHRASE_TOKENS && p->nToken>0 |
| 126067 | + && p->nToken<=MAX_INCR_PHRASE_TOKENS && p->nToken>0 |
| 126068 | +#ifdef SQLITE_TEST |
| 126069 | + && pTab->bNoIncrDoclist==0 |
| 126070 | +#endif |
| 126071 | + ); |
| 126072 | + for(i=0; bIncrOk==1 && i<p->nToken; i++){ |
| 126073 | + Fts3PhraseToken *pToken = &p->aToken[i]; |
| 126074 | + if( pToken->bFirst || (pToken->pSegcsr!=0 && !pToken->pSegcsr->bLookup) ){ |
| 126075 | + bIncrOk = 0; |
| 126076 | + } |
| 126077 | + if( pToken->pSegcsr ) bHaveIncr = 1; |
| 126078 | + } |
| 126079 | + |
| 126080 | + if( bIncrOk && bHaveIncr ){ |
| 125572 | 126081 | /* Use the incremental approach. */ |
| 125573 | 126082 | int iCol = (p->iColumn >= pTab->nColumn ? -1 : p->iColumn); |
| 125574 | | - rc = sqlite3Fts3MsrIncrStart( |
| 125575 | | - pTab, pFirst->pSegcsr, iCol, pFirst->z, pFirst->n); |
| 126083 | + for(i=0; rc==SQLITE_OK && i<p->nToken; i++){ |
| 126084 | + Fts3PhraseToken *pToken = &p->aToken[i]; |
| 126085 | + Fts3MultiSegReader *pSegcsr = pToken->pSegcsr; |
| 126086 | + if( pSegcsr ){ |
| 126087 | + rc = sqlite3Fts3MsrIncrStart(pTab, pSegcsr, iCol, pToken->z, pToken->n); |
| 126088 | + } |
| 126089 | + } |
| 125576 | 126090 | p->bIncr = 1; |
| 125577 | | - |
| 125578 | 126091 | }else{ |
| 125579 | 126092 | /* Load the full doclist for the phrase into memory. */ |
| 125580 | 126093 | rc = fts3EvalPhraseLoad(pCsr, p); |
| 125581 | 126094 | p->bIncr = 0; |
| 125582 | 126095 | } |
| | @@ -125680,10 +126193,220 @@ |
| 125680 | 126193 | } |
| 125681 | 126194 | } |
| 125682 | 126195 | |
| 125683 | 126196 | *ppIter = p; |
| 125684 | 126197 | } |
| 126198 | + |
| 126199 | +/* |
| 126200 | +** Advance the iterator pDL to the next entry in pDL->aAll/nAll. Set *pbEof |
| 126201 | +** to true if EOF is reached. |
| 126202 | +*/ |
| 126203 | +static void fts3EvalDlPhraseNext( |
| 126204 | + Fts3Table *pTab, |
| 126205 | + Fts3Doclist *pDL, |
| 126206 | + u8 *pbEof |
| 126207 | +){ |
| 126208 | + char *pIter; /* Used to iterate through aAll */ |
| 126209 | + char *pEnd = &pDL->aAll[pDL->nAll]; /* 1 byte past end of aAll */ |
| 126210 | + |
| 126211 | + if( pDL->pNextDocid ){ |
| 126212 | + pIter = pDL->pNextDocid; |
| 126213 | + }else{ |
| 126214 | + pIter = pDL->aAll; |
| 126215 | + } |
| 126216 | + |
| 126217 | + if( pIter>=pEnd ){ |
| 126218 | + /* We have already reached the end of this doclist. EOF. */ |
| 126219 | + *pbEof = 1; |
| 126220 | + }else{ |
| 126221 | + sqlite3_int64 iDelta; |
| 126222 | + pIter += sqlite3Fts3GetVarint(pIter, &iDelta); |
| 126223 | + if( pTab->bDescIdx==0 || pDL->pNextDocid==0 ){ |
| 126224 | + pDL->iDocid += iDelta; |
| 126225 | + }else{ |
| 126226 | + pDL->iDocid -= iDelta; |
| 126227 | + } |
| 126228 | + pDL->pList = pIter; |
| 126229 | + fts3PoslistCopy(0, &pIter); |
| 126230 | + pDL->nList = (int)(pIter - pDL->pList); |
| 126231 | + |
| 126232 | + /* pIter now points just past the 0x00 that terminates the position- |
| 126233 | + ** list for document pDL->iDocid. However, if this position-list was |
| 126234 | + ** edited in place by fts3EvalNearTrim(), then pIter may not actually |
| 126235 | + ** point to the start of the next docid value. The following line deals |
| 126236 | + ** with this case by advancing pIter past the zero-padding added by |
| 126237 | + ** fts3EvalNearTrim(). */ |
| 126238 | + while( pIter<pEnd && *pIter==0 ) pIter++; |
| 126239 | + |
| 126240 | + pDL->pNextDocid = pIter; |
| 126241 | + assert( pIter>=&pDL->aAll[pDL->nAll] || *pIter ); |
| 126242 | + *pbEof = 0; |
| 126243 | + } |
| 126244 | +} |
| 126245 | + |
| 126246 | +/* |
| 126247 | +** Helper type used by fts3EvalIncrPhraseNext() and incrPhraseTokenNext(). |
| 126248 | +*/ |
| 126249 | +typedef struct TokenDoclist TokenDoclist; |
| 126250 | +struct TokenDoclist { |
| 126251 | + int bIgnore; |
| 126252 | + sqlite3_int64 iDocid; |
| 126253 | + char *pList; |
| 126254 | + int nList; |
| 126255 | +}; |
| 126256 | + |
| 126257 | +/* |
| 126258 | +** Token pToken is an incrementally loaded token that is part of a |
| 126259 | +** multi-token phrase. Advance it to the next matching document in the |
| 126260 | +** database and populate output variable *p with the details of the new |
| 126261 | +** entry. Or, if the iterator has reached EOF, set *pbEof to true. |
| 126262 | +** |
| 126263 | +** If an error occurs, return an SQLite error code. Otherwise, return |
| 126264 | +** SQLITE_OK. |
| 126265 | +*/ |
| 126266 | +static int incrPhraseTokenNext( |
| 126267 | + Fts3Table *pTab, /* Virtual table handle */ |
| 126268 | + Fts3Phrase *pPhrase, /* Phrase to advance token of */ |
| 126269 | + int iToken, /* Specific token to advance */ |
| 126270 | + TokenDoclist *p, /* OUT: Docid and doclist for new entry */ |
| 126271 | + u8 *pbEof /* OUT: True if iterator is at EOF */ |
| 126272 | +){ |
| 126273 | + int rc = SQLITE_OK; |
| 126274 | + |
| 126275 | + if( pPhrase->iDoclistToken==iToken ){ |
| 126276 | + assert( p->bIgnore==0 ); |
| 126277 | + assert( pPhrase->aToken[iToken].pSegcsr==0 ); |
| 126278 | + fts3EvalDlPhraseNext(pTab, &pPhrase->doclist, pbEof); |
| 126279 | + p->pList = pPhrase->doclist.pList; |
| 126280 | + p->nList = pPhrase->doclist.nList; |
| 126281 | + p->iDocid = pPhrase->doclist.iDocid; |
| 126282 | + }else{ |
| 126283 | + Fts3PhraseToken *pToken = &pPhrase->aToken[iToken]; |
| 126284 | + assert( pToken->pDeferred==0 ); |
| 126285 | + assert( pToken->pSegcsr || pPhrase->iDoclistToken>=0 ); |
| 126286 | + if( pToken->pSegcsr ){ |
| 126287 | + assert( p->bIgnore==0 ); |
| 126288 | + rc = sqlite3Fts3MsrIncrNext( |
| 126289 | + pTab, pToken->pSegcsr, &p->iDocid, &p->pList, &p->nList |
| 126290 | + ); |
| 126291 | + if( p->pList==0 ) *pbEof = 1; |
| 126292 | + }else{ |
| 126293 | + p->bIgnore = 1; |
| 126294 | + } |
| 126295 | + } |
| 126296 | + |
| 126297 | + return rc; |
| 126298 | +} |
| 126299 | + |
| 126300 | + |
| 126301 | +/* |
| 126302 | +** The phrase iterator passed as the second argument: |
| 126303 | +** |
| 126304 | +** * features at least one token that uses an incremental doclist, and |
| 126305 | +** |
| 126306 | +** * does not contain any deferred tokens. |
| 126307 | +** |
| 126308 | +** Advance it to the next matching documnent in the database and populate |
| 126309 | +** the Fts3Doclist.pList and nList fields. |
| 126310 | +** |
| 126311 | +** If there is no "next" entry and no error occurs, then *pbEof is set to |
| 126312 | +** 1 before returning. Otherwise, if no error occurs and the iterator is |
| 126313 | +** successfully advanced, *pbEof is set to 0. |
| 126314 | +** |
| 126315 | +** If an error occurs, return an SQLite error code. Otherwise, return |
| 126316 | +** SQLITE_OK. |
| 126317 | +*/ |
| 126318 | +static int fts3EvalIncrPhraseNext( |
| 126319 | + Fts3Cursor *pCsr, /* FTS Cursor handle */ |
| 126320 | + Fts3Phrase *p, /* Phrase object to advance to next docid */ |
| 126321 | + u8 *pbEof /* OUT: Set to 1 if EOF */ |
| 126322 | +){ |
| 126323 | + int rc = SQLITE_OK; |
| 126324 | + Fts3Doclist *pDL = &p->doclist; |
| 126325 | + Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab; |
| 126326 | + u8 bEof = 0; |
| 126327 | + |
| 126328 | + /* This is only called if it is guaranteed that the phrase has at least |
| 126329 | + ** one incremental token. In which case the bIncr flag is set. */ |
| 126330 | + assert( p->bIncr==1 ); |
| 126331 | + |
| 126332 | + if( p->nToken==1 && p->bIncr ){ |
| 126333 | + rc = sqlite3Fts3MsrIncrNext(pTab, p->aToken[0].pSegcsr, |
| 126334 | + &pDL->iDocid, &pDL->pList, &pDL->nList |
| 126335 | + ); |
| 126336 | + if( pDL->pList==0 ) bEof = 1; |
| 126337 | + }else{ |
| 126338 | + int bDescDoclist = pCsr->bDesc; |
| 126339 | + struct TokenDoclist a[MAX_INCR_PHRASE_TOKENS]; |
| 126340 | + |
| 126341 | + memset(a, 0, sizeof(a)); |
| 126342 | + assert( p->nToken<=MAX_INCR_PHRASE_TOKENS ); |
| 126343 | + assert( p->iDoclistToken<MAX_INCR_PHRASE_TOKENS ); |
| 126344 | + |
| 126345 | + while( bEof==0 ){ |
| 126346 | + int bMaxSet = 0; |
| 126347 | + sqlite3_int64 iMax = 0; /* Largest docid for all iterators */ |
| 126348 | + int i; /* Used to iterate through tokens */ |
| 126349 | + |
| 126350 | + /* Advance the iterator for each token in the phrase once. */ |
| 126351 | + for(i=0; rc==SQLITE_OK && i<p->nToken && bEof==0; i++){ |
| 126352 | + rc = incrPhraseTokenNext(pTab, p, i, &a[i], &bEof); |
| 126353 | + if( a[i].bIgnore==0 && (bMaxSet==0 || DOCID_CMP(iMax, a[i].iDocid)<0) ){ |
| 126354 | + iMax = a[i].iDocid; |
| 126355 | + bMaxSet = 1; |
| 126356 | + } |
| 126357 | + } |
| 126358 | + assert( rc!=SQLITE_OK || a[p->nToken-1].bIgnore==0 ); |
| 126359 | + assert( rc!=SQLITE_OK || bMaxSet ); |
| 126360 | + |
| 126361 | + /* Keep advancing iterators until they all point to the same document */ |
| 126362 | + for(i=0; i<p->nToken; i++){ |
| 126363 | + while( rc==SQLITE_OK && bEof==0 |
| 126364 | + && a[i].bIgnore==0 && DOCID_CMP(a[i].iDocid, iMax)<0 |
| 126365 | + ){ |
| 126366 | + rc = incrPhraseTokenNext(pTab, p, i, &a[i], &bEof); |
| 126367 | + if( DOCID_CMP(a[i].iDocid, iMax)>0 ){ |
| 126368 | + iMax = a[i].iDocid; |
| 126369 | + i = 0; |
| 126370 | + } |
| 126371 | + } |
| 126372 | + } |
| 126373 | + |
| 126374 | + /* Check if the current entries really are a phrase match */ |
| 126375 | + if( bEof==0 ){ |
| 126376 | + int nList = 0; |
| 126377 | + int nByte = a[p->nToken-1].nList; |
| 126378 | + char *aDoclist = sqlite3_malloc(nByte+1); |
| 126379 | + if( !aDoclist ) return SQLITE_NOMEM; |
| 126380 | + memcpy(aDoclist, a[p->nToken-1].pList, nByte+1); |
| 126381 | + |
| 126382 | + for(i=0; i<(p->nToken-1); i++){ |
| 126383 | + if( a[i].bIgnore==0 ){ |
| 126384 | + char *pL = a[i].pList; |
| 126385 | + char *pR = aDoclist; |
| 126386 | + char *pOut = aDoclist; |
| 126387 | + int nDist = p->nToken-1-i; |
| 126388 | + int res = fts3PoslistPhraseMerge(&pOut, nDist, 0, 1, &pL, &pR); |
| 126389 | + if( res==0 ) break; |
| 126390 | + nList = (int)(pOut - aDoclist); |
| 126391 | + } |
| 126392 | + } |
| 126393 | + if( i==(p->nToken-1) ){ |
| 126394 | + pDL->iDocid = iMax; |
| 126395 | + pDL->pList = aDoclist; |
| 126396 | + pDL->nList = nList; |
| 126397 | + pDL->bFreeList = 1; |
| 126398 | + break; |
| 126399 | + } |
| 126400 | + sqlite3_free(aDoclist); |
| 126401 | + } |
| 126402 | + } |
| 126403 | + } |
| 126404 | + |
| 126405 | + *pbEof = bEof; |
| 126406 | + return rc; |
| 126407 | +} |
| 125685 | 126408 | |
| 125686 | 126409 | /* |
| 125687 | 126410 | ** Attempt to move the phrase iterator to point to the next matching docid. |
| 125688 | 126411 | ** If an error occurs, return an SQLite error code. Otherwise, return |
| 125689 | 126412 | ** SQLITE_OK. |
| | @@ -125700,59 +126423,18 @@ |
| 125700 | 126423 | int rc = SQLITE_OK; |
| 125701 | 126424 | Fts3Doclist *pDL = &p->doclist; |
| 125702 | 126425 | Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab; |
| 125703 | 126426 | |
| 125704 | 126427 | 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 | | - } |
| 126428 | + rc = fts3EvalIncrPhraseNext(pCsr, p, pbEof); |
| 125713 | 126429 | }else if( pCsr->bDesc!=pTab->bDescIdx && pDL->nAll ){ |
| 125714 | 126430 | sqlite3Fts3DoclistPrev(pTab->bDescIdx, pDL->aAll, pDL->nAll, |
| 125715 | 126431 | &pDL->pNextDocid, &pDL->iDocid, &pDL->nList, pbEof |
| 125716 | 126432 | ); |
| 125717 | 126433 | pDL->pList = pDL->pNextDocid; |
| 125718 | 126434 | }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 | | - } |
| 126435 | + fts3EvalDlPhraseNext(pTab, pDL, pbEof); |
| 125754 | 126436 | } |
| 125755 | 126437 | |
| 125756 | 126438 | return rc; |
| 125757 | 126439 | } |
| 125758 | 126440 | |
| | @@ -125773,11 +126455,10 @@ |
| 125773 | 126455 | ** code before returning. |
| 125774 | 126456 | */ |
| 125775 | 126457 | static void fts3EvalStartReaders( |
| 125776 | 126458 | Fts3Cursor *pCsr, /* FTS Cursor handle */ |
| 125777 | 126459 | Fts3Expr *pExpr, /* Expression to initialize phrases in */ |
| 125778 | | - int bOptOk, /* True to enable incremental loading */ |
| 125779 | 126460 | int *pRc /* IN/OUT: Error code */ |
| 125780 | 126461 | ){ |
| 125781 | 126462 | if( pExpr && SQLITE_OK==*pRc ){ |
| 125782 | 126463 | if( pExpr->eType==FTSQUERY_PHRASE ){ |
| 125783 | 126464 | int i; |
| | @@ -125784,14 +126465,14 @@ |
| 125784 | 126465 | int nToken = pExpr->pPhrase->nToken; |
| 125785 | 126466 | for(i=0; i<nToken; i++){ |
| 125786 | 126467 | if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break; |
| 125787 | 126468 | } |
| 125788 | 126469 | pExpr->bDeferred = (i==nToken); |
| 125789 | | - *pRc = fts3EvalPhraseStart(pCsr, bOptOk, pExpr->pPhrase); |
| 126470 | + *pRc = fts3EvalPhraseStart(pCsr, 1, pExpr->pPhrase); |
| 125790 | 126471 | }else{ |
| 125791 | | - fts3EvalStartReaders(pCsr, pExpr->pLeft, bOptOk, pRc); |
| 125792 | | - fts3EvalStartReaders(pCsr, pExpr->pRight, bOptOk, pRc); |
| 126472 | + fts3EvalStartReaders(pCsr, pExpr->pLeft, pRc); |
| 126473 | + fts3EvalStartReaders(pCsr, pExpr->pRight, pRc); |
| 125793 | 126474 | pExpr->bDeferred = (pExpr->pLeft->bDeferred && pExpr->pRight->bDeferred); |
| 125794 | 126475 | } |
| 125795 | 126476 | } |
| 125796 | 126477 | } |
| 125797 | 126478 | |
| | @@ -126029,11 +126710,11 @@ |
| 126029 | 126710 | /* Set nLoad4 to the value of (4^nOther) for the next iteration of the |
| 126030 | 126711 | ** for-loop. Except, limit the value to 2^24 to prevent it from |
| 126031 | 126712 | ** overflowing the 32-bit integer it is stored in. */ |
| 126032 | 126713 | if( ii<12 ) nLoad4 = nLoad4*4; |
| 126033 | 126714 | |
| 126034 | | - if( ii==0 || pTC->pPhrase->nToken>1 ){ |
| 126715 | + if( ii==0 || (pTC->pPhrase->nToken>1 && ii!=nToken-1) ){ |
| 126035 | 126716 | /* Either this is the cheapest token in the entire query, or it is |
| 126036 | 126717 | ** part of a multi-token phrase. Either way, the entire doclist will |
| 126037 | 126718 | ** (eventually) be loaded into memory. It may as well be now. */ |
| 126038 | 126719 | Fts3PhraseToken *pToken = pTC->pToken; |
| 126039 | 126720 | int nList = 0; |
| | @@ -126109,11 +126790,11 @@ |
| 126109 | 126790 | sqlite3_free(aTC); |
| 126110 | 126791 | } |
| 126111 | 126792 | } |
| 126112 | 126793 | #endif |
| 126113 | 126794 | |
| 126114 | | - fts3EvalStartReaders(pCsr, pCsr->pExpr, 1, &rc); |
| 126795 | + fts3EvalStartReaders(pCsr, pCsr->pExpr, &rc); |
| 126115 | 126796 | return rc; |
| 126116 | 126797 | } |
| 126117 | 126798 | |
| 126118 | 126799 | /* |
| 126119 | 126800 | ** Invalidate the current position list for phrase pPhrase. |
| | @@ -126592,10 +127273,20 @@ |
| 126592 | 127273 | pCsr->isRequireSeek = 1; |
| 126593 | 127274 | pCsr->isMatchinfoNeeded = 1; |
| 126594 | 127275 | pCsr->iPrevId = pExpr->iDocid; |
| 126595 | 127276 | }while( pCsr->isEof==0 && fts3EvalTestDeferredAndNear(pCsr, &rc) ); |
| 126596 | 127277 | } |
| 127278 | + |
| 127279 | + /* Check if the cursor is past the end of the docid range specified |
| 127280 | + ** by Fts3Cursor.iMinDocid/iMaxDocid. If so, set the EOF flag. */ |
| 127281 | + if( rc==SQLITE_OK && ( |
| 127282 | + (pCsr->bDesc==0 && pCsr->iPrevId>pCsr->iMaxDocid) |
| 127283 | + || (pCsr->bDesc!=0 && pCsr->iPrevId<pCsr->iMinDocid) |
| 127284 | + )){ |
| 127285 | + pCsr->isEof = 1; |
| 127286 | + } |
| 127287 | + |
| 126597 | 127288 | return rc; |
| 126598 | 127289 | } |
| 126599 | 127290 | |
| 126600 | 127291 | /* |
| 126601 | 127292 | ** Restart interation for expression pExpr so that the next call to |
| | @@ -126615,16 +127306,20 @@ |
| 126615 | 127306 | Fts3Phrase *pPhrase = pExpr->pPhrase; |
| 126616 | 127307 | |
| 126617 | 127308 | if( pPhrase ){ |
| 126618 | 127309 | fts3EvalInvalidatePoslist(pPhrase); |
| 126619 | 127310 | if( pPhrase->bIncr ){ |
| 126620 | | - assert( pPhrase->nToken==1 ); |
| 126621 | | - assert( pPhrase->aToken[0].pSegcsr ); |
| 126622 | | - sqlite3Fts3MsrIncrRestart(pPhrase->aToken[0].pSegcsr); |
| 127311 | + int i; |
| 127312 | + for(i=0; i<pPhrase->nToken; i++){ |
| 127313 | + Fts3PhraseToken *pToken = &pPhrase->aToken[i]; |
| 127314 | + assert( pToken->pDeferred==0 ); |
| 127315 | + if( pToken->pSegcsr ){ |
| 127316 | + sqlite3Fts3MsrIncrRestart(pToken->pSegcsr); |
| 127317 | + } |
| 127318 | + } |
| 126623 | 127319 | *pRc = fts3EvalPhraseStart(pCsr, 0, pPhrase); |
| 126624 | 127320 | } |
| 126625 | | - |
| 126626 | 127321 | pPhrase->doclist.pNextDocid = 0; |
| 126627 | 127322 | pPhrase->doclist.iDocid = 0; |
| 126628 | 127323 | } |
| 126629 | 127324 | |
| 126630 | 127325 | pExpr->iDocid = 0; |
| | @@ -126869,19 +127564,27 @@ |
| 126869 | 127564 | |
| 126870 | 127565 | iDocid = pExpr->iDocid; |
| 126871 | 127566 | pIter = pPhrase->doclist.pList; |
| 126872 | 127567 | if( iDocid!=pCsr->iPrevId || pExpr->bEof ){ |
| 126873 | 127568 | int bDescDoclist = pTab->bDescIdx; /* For DOCID_CMP macro */ |
| 127569 | + int iMul; /* +1 if csr dir matches index dir, else -1 */ |
| 126874 | 127570 | int bOr = 0; |
| 126875 | 127571 | u8 bEof = 0; |
| 126876 | | - Fts3Expr *p; |
| 127572 | + u8 bTreeEof = 0; |
| 127573 | + Fts3Expr *p; /* Used to iterate from pExpr to root */ |
| 127574 | + Fts3Expr *pNear; /* Most senior NEAR ancestor (or pExpr) */ |
| 126877 | 127575 | |
| 126878 | 127576 | /* Check if this phrase descends from an OR expression node. If not, |
| 126879 | 127577 | ** return NULL. Otherwise, the entry that corresponds to docid |
| 126880 | | - ** pCsr->iPrevId may lie earlier in the doclist buffer. */ |
| 127578 | + ** pCsr->iPrevId may lie earlier in the doclist buffer. Or, if the |
| 127579 | + ** tree that the node is part of has been marked as EOF, but the node |
| 127580 | + ** itself is not EOF, then it may point to an earlier entry. */ |
| 127581 | + pNear = pExpr; |
| 126881 | 127582 | for(p=pExpr->pParent; p; p=p->pParent){ |
| 126882 | 127583 | if( p->eType==FTSQUERY_OR ) bOr = 1; |
| 127584 | + if( p->eType==FTSQUERY_NEAR ) pNear = p; |
| 127585 | + if( p->bEof ) bTreeEof = 1; |
| 126883 | 127586 | } |
| 126884 | 127587 | if( bOr==0 ) return SQLITE_OK; |
| 126885 | 127588 | |
| 126886 | 127589 | /* This is the descendent of an OR node. In this case we cannot use |
| 126887 | 127590 | ** an incremental phrase. Load the entire doclist for the phrase |
| | @@ -126896,33 +127599,63 @@ |
| 126896 | 127599 | } |
| 126897 | 127600 | pIter = pPhrase->doclist.pList; |
| 126898 | 127601 | assert( rc!=SQLITE_OK || pPhrase->bIncr==0 ); |
| 126899 | 127602 | if( rc!=SQLITE_OK ) return rc; |
| 126900 | 127603 | } |
| 127604 | + |
| 127605 | + iMul = ((pCsr->bDesc==bDescDoclist) ? 1 : -1); |
| 127606 | + while( bTreeEof==1 |
| 127607 | + && pNear->bEof==0 |
| 127608 | + && (DOCID_CMP(pNear->iDocid, pCsr->iPrevId) * iMul)<0 |
| 127609 | + ){ |
| 127610 | + int rc = SQLITE_OK; |
| 127611 | + fts3EvalNextRow(pCsr, pExpr, &rc); |
| 127612 | + if( rc!=SQLITE_OK ) return rc; |
| 127613 | + iDocid = pExpr->iDocid; |
| 127614 | + pIter = pPhrase->doclist.pList; |
| 127615 | + } |
| 126901 | 127616 | |
| 126902 | | - if( pExpr->bEof ){ |
| 126903 | | - pIter = 0; |
| 126904 | | - iDocid = 0; |
| 126905 | | - } |
| 126906 | 127617 | bEof = (pPhrase->doclist.nAll==0); |
| 126907 | 127618 | assert( bDescDoclist==0 || bDescDoclist==1 ); |
| 126908 | 127619 | assert( pCsr->bDesc==0 || pCsr->bDesc==1 ); |
| 126909 | 127620 | |
| 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 | | - ); |
| 127621 | + if( bEof==0 ){ |
| 127622 | + if( pCsr->bDesc==bDescDoclist ){ |
| 127623 | + int dummy; |
| 127624 | + if( pNear->bEof ){ |
| 127625 | + /* This expression is already at EOF. So position it to point to the |
| 127626 | + ** last entry in the doclist at pPhrase->doclist.aAll[]. Variable |
| 127627 | + ** iDocid is already set for this entry, so all that is required is |
| 127628 | + ** to set pIter to point to the first byte of the last position-list |
| 127629 | + ** in the doclist. |
| 127630 | + ** |
| 127631 | + ** It would also be correct to set pIter and iDocid to zero. In |
| 127632 | + ** this case, the first call to sqltie3Fts4DoclistPrev() below |
| 127633 | + ** would also move the iterator to point to the last entry in the |
| 127634 | + ** doclist. However, this is expensive, as to do so it has to |
| 127635 | + ** iterate through the entire doclist from start to finish (since |
| 127636 | + ** it does not know the docid for the last entry). */ |
| 127637 | + pIter = &pPhrase->doclist.aAll[pPhrase->doclist.nAll-1]; |
| 127638 | + fts3ReversePoslist(pPhrase->doclist.aAll, &pIter); |
| 127639 | + } |
| 127640 | + while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){ |
| 127641 | + sqlite3Fts3DoclistPrev( |
| 127642 | + bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, |
| 127643 | + &pIter, &iDocid, &dummy, &bEof |
| 127644 | + ); |
| 127645 | + } |
| 127646 | + }else{ |
| 127647 | + if( pNear->bEof ){ |
| 127648 | + pIter = 0; |
| 127649 | + iDocid = 0; |
| 127650 | + } |
| 127651 | + while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){ |
| 127652 | + sqlite3Fts3DoclistNext( |
| 127653 | + bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll, |
| 127654 | + &pIter, &iDocid, &bEof |
| 127655 | + ); |
| 127656 | + } |
| 126924 | 127657 | } |
| 126925 | 127658 | } |
| 126926 | 127659 | |
| 126927 | 127660 | if( bEof || iDocid!=pCsr->iPrevId ) pIter = 0; |
| 126928 | 127661 | } |
| | @@ -127026,10 +127759,11 @@ |
| 127026 | 127759 | sqlite3_vtab_cursor base; /* Base class used by SQLite core */ |
| 127027 | 127760 | Fts3MultiSegReader csr; /* Must be right after "base" */ |
| 127028 | 127761 | Fts3SegFilter filter; |
| 127029 | 127762 | char *zStop; |
| 127030 | 127763 | int nStop; /* Byte-length of string zStop */ |
| 127764 | + int iLangid; /* Language id to query */ |
| 127031 | 127765 | int isEof; /* True if cursor is at EOF */ |
| 127032 | 127766 | sqlite3_int64 iRowid; /* Current rowid */ |
| 127033 | 127767 | |
| 127034 | 127768 | int iCol; /* Current value of 'col' column */ |
| 127035 | 127769 | int nStat; /* Size of aStat[] array */ |
| | @@ -127040,11 +127774,12 @@ |
| 127040 | 127774 | }; |
| 127041 | 127775 | |
| 127042 | 127776 | /* |
| 127043 | 127777 | ** Schema of the terms table. |
| 127044 | 127778 | */ |
| 127045 | | -#define FTS3_TERMS_SCHEMA "CREATE TABLE x(term, col, documents, occurrences)" |
| 127779 | +#define FTS3_AUX_SCHEMA \ |
| 127780 | + "CREATE TABLE x(term, col, documents, occurrences, languageid HIDDEN)" |
| 127046 | 127781 | |
| 127047 | 127782 | /* |
| 127048 | 127783 | ** This function does all the work for both the xConnect and xCreate methods. |
| 127049 | 127784 | ** These tables have no persistent representation of their own, so xConnect |
| 127050 | 127785 | ** and xCreate are identical operations. |
| | @@ -127087,11 +127822,11 @@ |
| 127087 | 127822 | }else{ |
| 127088 | 127823 | zFts3 = argv[3]; |
| 127089 | 127824 | } |
| 127090 | 127825 | nFts3 = (int)strlen(zFts3); |
| 127091 | 127826 | |
| 127092 | | - rc = sqlite3_declare_vtab(db, FTS3_TERMS_SCHEMA); |
| 127827 | + rc = sqlite3_declare_vtab(db, FTS3_AUX_SCHEMA); |
| 127093 | 127828 | if( rc!=SQLITE_OK ) return rc; |
| 127094 | 127829 | |
| 127095 | 127830 | nByte = sizeof(Fts3auxTable) + sizeof(Fts3Table) + nDb + nFts3 + 2; |
| 127096 | 127831 | p = (Fts3auxTable *)sqlite3_malloc(nByte); |
| 127097 | 127832 | if( !p ) return SQLITE_NOMEM; |
| | @@ -127147,10 +127882,12 @@ |
| 127147 | 127882 | ){ |
| 127148 | 127883 | int i; |
| 127149 | 127884 | int iEq = -1; |
| 127150 | 127885 | int iGe = -1; |
| 127151 | 127886 | int iLe = -1; |
| 127887 | + int iLangid = -1; |
| 127888 | + int iNext = 1; /* Next free argvIndex value */ |
| 127152 | 127889 | |
| 127153 | 127890 | UNUSED_PARAMETER(pVTab); |
| 127154 | 127891 | |
| 127155 | 127892 | /* This vtab delivers always results in "ORDER BY term ASC" order. */ |
| 127156 | 127893 | if( pInfo->nOrderBy==1 |
| | @@ -127158,40 +127895,52 @@ |
| 127158 | 127895 | && pInfo->aOrderBy[0].desc==0 |
| 127159 | 127896 | ){ |
| 127160 | 127897 | pInfo->orderByConsumed = 1; |
| 127161 | 127898 | } |
| 127162 | 127899 | |
| 127163 | | - /* Search for equality and range constraints on the "term" column. */ |
| 127900 | + /* Search for equality and range constraints on the "term" column. |
| 127901 | + ** And equality constraints on the hidden "languageid" column. */ |
| 127164 | 127902 | for(i=0; i<pInfo->nConstraint; i++){ |
| 127165 | | - if( pInfo->aConstraint[i].usable && pInfo->aConstraint[i].iColumn==0 ){ |
| 127903 | + if( pInfo->aConstraint[i].usable ){ |
| 127166 | 127904 | int op = pInfo->aConstraint[i].op; |
| 127167 | | - if( op==SQLITE_INDEX_CONSTRAINT_EQ ) iEq = i; |
| 127168 | | - if( op==SQLITE_INDEX_CONSTRAINT_LT ) iLe = i; |
| 127169 | | - if( op==SQLITE_INDEX_CONSTRAINT_LE ) iLe = i; |
| 127170 | | - if( op==SQLITE_INDEX_CONSTRAINT_GT ) iGe = i; |
| 127171 | | - if( op==SQLITE_INDEX_CONSTRAINT_GE ) iGe = i; |
| 127905 | + int iCol = pInfo->aConstraint[i].iColumn; |
| 127906 | + |
| 127907 | + if( iCol==0 ){ |
| 127908 | + if( op==SQLITE_INDEX_CONSTRAINT_EQ ) iEq = i; |
| 127909 | + if( op==SQLITE_INDEX_CONSTRAINT_LT ) iLe = i; |
| 127910 | + if( op==SQLITE_INDEX_CONSTRAINT_LE ) iLe = i; |
| 127911 | + if( op==SQLITE_INDEX_CONSTRAINT_GT ) iGe = i; |
| 127912 | + if( op==SQLITE_INDEX_CONSTRAINT_GE ) iGe = i; |
| 127913 | + } |
| 127914 | + if( iCol==4 ){ |
| 127915 | + if( op==SQLITE_INDEX_CONSTRAINT_EQ ) iLangid = i; |
| 127916 | + } |
| 127172 | 127917 | } |
| 127173 | 127918 | } |
| 127174 | 127919 | |
| 127175 | 127920 | if( iEq>=0 ){ |
| 127176 | 127921 | pInfo->idxNum = FTS4AUX_EQ_CONSTRAINT; |
| 127177 | | - pInfo->aConstraintUsage[iEq].argvIndex = 1; |
| 127922 | + pInfo->aConstraintUsage[iEq].argvIndex = iNext++; |
| 127178 | 127923 | pInfo->estimatedCost = 5; |
| 127179 | 127924 | }else{ |
| 127180 | 127925 | pInfo->idxNum = 0; |
| 127181 | 127926 | pInfo->estimatedCost = 20000; |
| 127182 | 127927 | if( iGe>=0 ){ |
| 127183 | 127928 | pInfo->idxNum += FTS4AUX_GE_CONSTRAINT; |
| 127184 | | - pInfo->aConstraintUsage[iGe].argvIndex = 1; |
| 127929 | + pInfo->aConstraintUsage[iGe].argvIndex = iNext++; |
| 127185 | 127930 | pInfo->estimatedCost /= 2; |
| 127186 | 127931 | } |
| 127187 | 127932 | if( iLe>=0 ){ |
| 127188 | 127933 | pInfo->idxNum += FTS4AUX_LE_CONSTRAINT; |
| 127189 | | - pInfo->aConstraintUsage[iLe].argvIndex = 1 + (iGe>=0); |
| 127934 | + pInfo->aConstraintUsage[iLe].argvIndex = iNext++; |
| 127190 | 127935 | pInfo->estimatedCost /= 2; |
| 127191 | 127936 | } |
| 127192 | 127937 | } |
| 127938 | + if( iLangid>=0 ){ |
| 127939 | + pInfo->aConstraintUsage[iLangid].argvIndex = iNext++; |
| 127940 | + pInfo->estimatedCost--; |
| 127941 | + } |
| 127193 | 127942 | |
| 127194 | 127943 | return SQLITE_OK; |
| 127195 | 127944 | } |
| 127196 | 127945 | |
| 127197 | 127946 | /* |
| | @@ -127347,21 +128096,42 @@ |
| 127347 | 128096 | sqlite3_value **apVal /* Arguments for the indexing scheme */ |
| 127348 | 128097 | ){ |
| 127349 | 128098 | Fts3auxCursor *pCsr = (Fts3auxCursor *)pCursor; |
| 127350 | 128099 | Fts3Table *pFts3 = ((Fts3auxTable *)pCursor->pVtab)->pFts3Tab; |
| 127351 | 128100 | int rc; |
| 127352 | | - int isScan; |
| 128101 | + int isScan = 0; |
| 128102 | + int iLangVal = 0; /* Language id to query */ |
| 128103 | + |
| 128104 | + int iEq = -1; /* Index of term=? value in apVal */ |
| 128105 | + int iGe = -1; /* Index of term>=? value in apVal */ |
| 128106 | + int iLe = -1; /* Index of term<=? value in apVal */ |
| 128107 | + int iLangid = -1; /* Index of languageid=? value in apVal */ |
| 128108 | + int iNext = 0; |
| 127353 | 128109 | |
| 127354 | 128110 | UNUSED_PARAMETER(nVal); |
| 127355 | 128111 | UNUSED_PARAMETER(idxStr); |
| 127356 | 128112 | |
| 127357 | 128113 | assert( idxStr==0 ); |
| 127358 | 128114 | assert( idxNum==FTS4AUX_EQ_CONSTRAINT || idxNum==0 |
| 127359 | 128115 | || idxNum==FTS4AUX_LE_CONSTRAINT || idxNum==FTS4AUX_GE_CONSTRAINT |
| 127360 | 128116 | || idxNum==(FTS4AUX_LE_CONSTRAINT|FTS4AUX_GE_CONSTRAINT) |
| 127361 | 128117 | ); |
| 127362 | | - isScan = (idxNum!=FTS4AUX_EQ_CONSTRAINT); |
| 128118 | + |
| 128119 | + if( idxNum==FTS4AUX_EQ_CONSTRAINT ){ |
| 128120 | + iEq = iNext++; |
| 128121 | + }else{ |
| 128122 | + isScan = 1; |
| 128123 | + if( idxNum & FTS4AUX_GE_CONSTRAINT ){ |
| 128124 | + iGe = iNext++; |
| 128125 | + } |
| 128126 | + if( idxNum & FTS4AUX_LE_CONSTRAINT ){ |
| 128127 | + iLe = iNext++; |
| 128128 | + } |
| 128129 | + } |
| 128130 | + if( iNext<nVal ){ |
| 128131 | + iLangid = iNext++; |
| 128132 | + } |
| 127363 | 128133 | |
| 127364 | 128134 | /* In case this cursor is being reused, close and zero it. */ |
| 127365 | 128135 | testcase(pCsr->filter.zTerm); |
| 127366 | 128136 | sqlite3Fts3SegReaderFinish(&pCsr->csr); |
| 127367 | 128137 | sqlite3_free((void *)pCsr->filter.zTerm); |
| | @@ -127369,26 +128139,39 @@ |
| 127369 | 128139 | memset(&pCsr->csr, 0, ((u8*)&pCsr[1]) - (u8*)&pCsr->csr); |
| 127370 | 128140 | |
| 127371 | 128141 | pCsr->filter.flags = FTS3_SEGMENT_REQUIRE_POS|FTS3_SEGMENT_IGNORE_EMPTY; |
| 127372 | 128142 | if( isScan ) pCsr->filter.flags |= FTS3_SEGMENT_SCAN; |
| 127373 | 128143 | |
| 127374 | | - if( idxNum&(FTS4AUX_EQ_CONSTRAINT|FTS4AUX_GE_CONSTRAINT) ){ |
| 128144 | + if( iEq>=0 || iGe>=0 ){ |
| 127375 | 128145 | const unsigned char *zStr = sqlite3_value_text(apVal[0]); |
| 128146 | + assert( (iEq==0 && iGe==-1) || (iEq==-1 && iGe==0) ); |
| 127376 | 128147 | if( zStr ){ |
| 127377 | 128148 | pCsr->filter.zTerm = sqlite3_mprintf("%s", zStr); |
| 127378 | 128149 | pCsr->filter.nTerm = sqlite3_value_bytes(apVal[0]); |
| 127379 | 128150 | if( pCsr->filter.zTerm==0 ) return SQLITE_NOMEM; |
| 127380 | 128151 | } |
| 127381 | 128152 | } |
| 127382 | | - if( idxNum&FTS4AUX_LE_CONSTRAINT ){ |
| 127383 | | - int iIdx = (idxNum&FTS4AUX_GE_CONSTRAINT) ? 1 : 0; |
| 127384 | | - pCsr->zStop = sqlite3_mprintf("%s", sqlite3_value_text(apVal[iIdx])); |
| 127385 | | - pCsr->nStop = sqlite3_value_bytes(apVal[iIdx]); |
| 128153 | + |
| 128154 | + if( iLe>=0 ){ |
| 128155 | + pCsr->zStop = sqlite3_mprintf("%s", sqlite3_value_text(apVal[iLe])); |
| 128156 | + pCsr->nStop = sqlite3_value_bytes(apVal[iLe]); |
| 127386 | 128157 | if( pCsr->zStop==0 ) return SQLITE_NOMEM; |
| 127387 | 128158 | } |
| 128159 | + |
| 128160 | + if( iLangid>=0 ){ |
| 128161 | + iLangVal = sqlite3_value_int(apVal[iLangid]); |
| 127388 | 128162 | |
| 127389 | | - rc = sqlite3Fts3SegReaderCursor(pFts3, 0, 0, FTS3_SEGCURSOR_ALL, |
| 128163 | + /* If the user specified a negative value for the languageid, use zero |
| 128164 | + ** instead. This works, as the "languageid=?" constraint will also |
| 128165 | + ** be tested by the VDBE layer. The test will always be false (since |
| 128166 | + ** this module will not return a row with a negative languageid), and |
| 128167 | + ** so the overall query will return zero rows. */ |
| 128168 | + if( iLangVal<0 ) iLangVal = 0; |
| 128169 | + } |
| 128170 | + pCsr->iLangid = iLangVal; |
| 128171 | + |
| 128172 | + rc = sqlite3Fts3SegReaderCursor(pFts3, iLangVal, 0, FTS3_SEGCURSOR_ALL, |
| 127390 | 128173 | pCsr->filter.zTerm, pCsr->filter.nTerm, 0, isScan, &pCsr->csr |
| 127391 | 128174 | ); |
| 127392 | 128175 | if( rc==SQLITE_OK ){ |
| 127393 | 128176 | rc = sqlite3Fts3SegReaderStart(pFts3, &pCsr->csr, &pCsr->filter); |
| 127394 | 128177 | } |
| | @@ -127408,28 +128191,41 @@ |
| 127408 | 128191 | /* |
| 127409 | 128192 | ** xColumn - Return a column value. |
| 127410 | 128193 | */ |
| 127411 | 128194 | static int fts3auxColumnMethod( |
| 127412 | 128195 | sqlite3_vtab_cursor *pCursor, /* Cursor to retrieve value from */ |
| 127413 | | - sqlite3_context *pContext, /* Context for sqlite3_result_xxx() calls */ |
| 128196 | + sqlite3_context *pCtx, /* Context for sqlite3_result_xxx() calls */ |
| 127414 | 128197 | int iCol /* Index of column to read value from */ |
| 127415 | 128198 | ){ |
| 127416 | 128199 | Fts3auxCursor *p = (Fts3auxCursor *)pCursor; |
| 127417 | 128200 | |
| 127418 | 128201 | assert( p->isEof==0 ); |
| 127419 | | - if( iCol==0 ){ /* Column "term" */ |
| 127420 | | - sqlite3_result_text(pContext, p->csr.zTerm, p->csr.nTerm, SQLITE_TRANSIENT); |
| 127421 | | - }else if( iCol==1 ){ /* Column "col" */ |
| 127422 | | - if( p->iCol ){ |
| 127423 | | - sqlite3_result_int(pContext, p->iCol-1); |
| 127424 | | - }else{ |
| 127425 | | - sqlite3_result_text(pContext, "*", -1, SQLITE_STATIC); |
| 127426 | | - } |
| 127427 | | - }else if( iCol==2 ){ /* Column "documents" */ |
| 127428 | | - sqlite3_result_int64(pContext, p->aStat[p->iCol].nDoc); |
| 127429 | | - }else{ /* Column "occurrences" */ |
| 127430 | | - sqlite3_result_int64(pContext, p->aStat[p->iCol].nOcc); |
| 128202 | + switch( iCol ){ |
| 128203 | + case 0: /* term */ |
| 128204 | + sqlite3_result_text(pCtx, p->csr.zTerm, p->csr.nTerm, SQLITE_TRANSIENT); |
| 128205 | + break; |
| 128206 | + |
| 128207 | + case 1: /* col */ |
| 128208 | + if( p->iCol ){ |
| 128209 | + sqlite3_result_int(pCtx, p->iCol-1); |
| 128210 | + }else{ |
| 128211 | + sqlite3_result_text(pCtx, "*", -1, SQLITE_STATIC); |
| 128212 | + } |
| 128213 | + break; |
| 128214 | + |
| 128215 | + case 2: /* documents */ |
| 128216 | + sqlite3_result_int64(pCtx, p->aStat[p->iCol].nDoc); |
| 128217 | + break; |
| 128218 | + |
| 128219 | + case 3: /* occurrences */ |
| 128220 | + sqlite3_result_int64(pCtx, p->aStat[p->iCol].nOcc); |
| 128221 | + break; |
| 128222 | + |
| 128223 | + default: /* languageid */ |
| 128224 | + assert( iCol==4 ); |
| 128225 | + sqlite3_result_int(pCtx, p->iLangid); |
| 128226 | + break; |
| 127431 | 128227 | } |
| 127432 | 128228 | |
| 127433 | 128229 | return SQLITE_OK; |
| 127434 | 128230 | } |
| 127435 | 128231 | |
| | @@ -135756,11 +136552,11 @@ |
| 135756 | 136552 | assert( p->bFts4==0 ); |
| 135757 | 136553 | sqlite3Fts3CreateStatTable(&rc, p); |
| 135758 | 136554 | if( rc ) return rc; |
| 135759 | 136555 | } |
| 135760 | 136556 | rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pStmt, 0); |
| 135761 | | - if( rc ) return rc;; |
| 136557 | + if( rc ) return rc; |
| 135762 | 136558 | sqlite3_bind_int(pStmt, 1, FTS_STAT_AUTOINCRMERGE); |
| 135763 | 136559 | sqlite3_bind_int(pStmt, 2, p->bAutoincrmerge); |
| 135764 | 136560 | sqlite3_step(pStmt); |
| 135765 | 136561 | rc = sqlite3_reset(pStmt); |
| 135766 | 136562 | return rc; |
| | @@ -136025,10 +136821,13 @@ |
| 136025 | 136821 | }else if( nVal>9 && 0==sqlite3_strnicmp(zVal, "nodesize=", 9) ){ |
| 136026 | 136822 | p->nNodeSize = atoi(&zVal[9]); |
| 136027 | 136823 | rc = SQLITE_OK; |
| 136028 | 136824 | }else if( nVal>11 && 0==sqlite3_strnicmp(zVal, "maxpending=", 9) ){ |
| 136029 | 136825 | p->nMaxPendingData = atoi(&zVal[11]); |
| 136826 | + rc = SQLITE_OK; |
| 136827 | + }else if( nVal>21 && 0==sqlite3_strnicmp(zVal, "test-no-incr-doclist=", 21) ){ |
| 136828 | + p->bNoIncrDoclist = atoi(&zVal[21]); |
| 136030 | 136829 | rc = SQLITE_OK; |
| 136031 | 136830 | #endif |
| 136032 | 136831 | }else{ |
| 136033 | 136832 | rc = SQLITE_ERROR; |
| 136034 | 136833 | } |
| 136035 | 136834 | |