| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | | -** version 3.37.0. By combining all the individual C code files into this |
| 3 | +** version 3.38.0. By combining all the individual C code files into this |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| | @@ -450,13 +450,13 @@ |
| 450 | 450 | ** |
| 451 | 451 | ** See also: [sqlite3_libversion()], |
| 452 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | 454 | */ |
| 455 | | -#define SQLITE_VERSION "3.37.0" |
| 456 | | -#define SQLITE_VERSION_NUMBER 3037000 |
| 457 | | -#define SQLITE_SOURCE_ID "2021-10-04 11:10:15 8b24c177061c38361588f419eda9b7943b72a0c6b2855b6f39272451b8a1b813" |
| 455 | +#define SQLITE_VERSION "3.38.0" |
| 456 | +#define SQLITE_VERSION_NUMBER 3038000 |
| 457 | +#define SQLITE_SOURCE_ID "2021-12-09 20:06:18 633bfeeea2bccdd44126acf3f61ecca163c9d933bdc787a2c18a697dc9406882" |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| | @@ -843,11 +843,10 @@ |
| 843 | 843 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 844 | 844 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 845 | 845 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
| 846 | 846 | #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */ |
| 847 | 847 | #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8)) |
| 848 | | -#define SQLITE_CANTOPEN_EXISTS (SQLITE_CANTOPEN | (7<<8)) |
| 849 | 848 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 850 | 849 | #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8)) |
| 851 | 850 | #define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8)) |
| 852 | 851 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 853 | 852 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| | @@ -879,10 +878,23 @@ |
| 879 | 878 | ** CAPI3REF: Flags For File Open Operations |
| 880 | 879 | ** |
| 881 | 880 | ** These bit values are intended for use in the |
| 882 | 881 | ** 3rd parameter to the [sqlite3_open_v2()] interface and |
| 883 | 882 | ** in the 4th parameter to the [sqlite3_vfs.xOpen] method. |
| 883 | +** |
| 884 | +** Only those flags marked as "Ok for sqlite3_open_v2()" may be |
| 885 | +** used as the third argument to the [sqlite3_open_v2()] interface. |
| 886 | +** The other flags have historically been ignored by sqlite3_open_v2(), |
| 887 | +** though future versions of SQLite might change so that an error is |
| 888 | +** raised if any of the disallowed bits are passed into sqlite3_open_v2(). |
| 889 | +** Applications should not depend on the historical behavior. |
| 890 | +** |
| 891 | +** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into |
| 892 | +** [sqlite3_open_v2()] does *not* cause the underlying database file |
| 893 | +** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into |
| 894 | +** [sqlite3_open_v2()] has historically be a no-op and might become an |
| 895 | +** error in future versions of SQLite. |
| 884 | 896 | */ |
| 885 | 897 | #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ |
| 886 | 898 | #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ |
| 887 | 899 | #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ |
| 888 | 900 | #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ |
| | @@ -901,10 +913,11 @@ |
| 901 | 913 | #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ |
| 902 | 914 | #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ |
| 903 | 915 | #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ |
| 904 | 916 | #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ |
| 905 | 917 | #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */ |
| 918 | +#define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */ |
| 906 | 919 | |
| 907 | 920 | /* Reserved: 0x00F00000 */ |
| 908 | 921 | /* Legacy compatibility: */ |
| 909 | 922 | #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ |
| 910 | 923 | |
| | @@ -3720,25 +3733,35 @@ |
| 3720 | 3733 | ** |
| 3721 | 3734 | ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt> |
| 3722 | 3735 | ** <dd>The database is opened [shared cache] disabled, overriding |
| 3723 | 3736 | ** the default shared cache setting provided by |
| 3724 | 3737 | ** [sqlite3_enable_shared_cache()].)^ |
| 3738 | +** |
| 3739 | +** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt> |
| 3740 | +** <dd>The database connection comes up in "extended result code mode". |
| 3741 | +** In other words, the database behaves has if |
| 3742 | +** [sqlite3_extended_result_codes(db,1)] where called on the database |
| 3743 | +** connection as soon as the connection is created. In addition to setting |
| 3744 | +** the extended result code mode, this flag also causes [sqlite3_open_v2()] |
| 3745 | +** to return an extended result code.</dd> |
| 3725 | 3746 | ** |
| 3726 | 3747 | ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt> |
| 3727 | 3748 | ** <dd>The database filename is not allowed to be a symbolic link</dd> |
| 3728 | | -** |
| 3729 | | -** [[OPEN_EXCLUSIVE]] ^(<dt>[SQLITE_OPEN_EXCLUSIVE]</dt> |
| 3730 | | -** <dd>This flag causes the open to fail if the database file already |
| 3731 | | -** exists. The open will only be success if this flag is used in combination |
| 3732 | | -** with the SQLITE_OPEN_CREATE and SQLITE_OPEN_READWRITE flags and if |
| 3733 | | -** the file does not previously exist.</dd> |
| 3734 | 3749 | ** </dl>)^ |
| 3735 | 3750 | ** |
| 3736 | 3751 | ** If the 3rd parameter to sqlite3_open_v2() is not one of the |
| 3737 | 3752 | ** required combinations shown above optionally combined with other |
| 3738 | 3753 | ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits] |
| 3739 | | -** then the behavior is undefined. |
| 3754 | +** then the behavior is undefined. Historic versions of SQLite |
| 3755 | +** have silently ignored surplus bits in the flags parameter to |
| 3756 | +** sqlite3_open_v2(), however that behavior might not be carried through |
| 3757 | +** into future versions of SQLite and so applications should not rely |
| 3758 | +** upon it. Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op |
| 3759 | +** for sqlite3_open_v2(). The SQLITE_OPEN_EXCLUSIVE does *not* cause |
| 3760 | +** the open to fail if the database already exists. The SQLITE_OPEN_EXCLUSIVE |
| 3761 | +** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not |
| 3762 | +** by sqlite3_open_v2(). |
| 3740 | 3763 | ** |
| 3741 | 3764 | ** ^The fourth parameter to sqlite3_open_v2() is the name of the |
| 3742 | 3765 | ** [sqlite3_vfs] object that defines the operating system interface that |
| 3743 | 3766 | ** the new database connection should use. ^If the fourth parameter is |
| 3744 | 3767 | ** a NULL pointer then the default [sqlite3_vfs] object is used. |
| | @@ -6695,10 +6718,76 @@ |
| 6695 | 6718 | ** |
| 6696 | 6719 | ** See also the [sqlite3_update_hook()] interface. |
| 6697 | 6720 | */ |
| 6698 | 6721 | SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); |
| 6699 | 6722 | SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); |
| 6723 | + |
| 6724 | +/* |
| 6725 | +** CAPI3REF: Autovacuum Compaction Amount Callback |
| 6726 | +** METHOD: sqlite3 |
| 6727 | +** |
| 6728 | +** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback |
| 6729 | +** function C that is invoked prior to each autovacuum of the database |
| 6730 | +** file. ^The callback is passed a copy of the generic data pointer (P), |
| 6731 | +** the schema-name of the attached database that is being autovacuumed, |
| 6732 | +** the the size of the database file in pages, the number of free pages, |
| 6733 | +** and the number of bytes per page, respectively. The callback should |
| 6734 | +** return the number of free pages that should be removed by the |
| 6735 | +** autovacuum. ^If the callback returns zero, then no autovacuum happens. |
| 6736 | +** ^If the value returned is greater than or equal to the number of |
| 6737 | +** free pages, then a complete autovacuum happens. |
| 6738 | +** |
| 6739 | +** <p>^If there are multiple ATTACH-ed database files that are being |
| 6740 | +** modified as part of a transaction commit, then the autovacuum pages |
| 6741 | +** callback is invoked separately for each file. |
| 6742 | +** |
| 6743 | +** <p><b>The callback is not reentrant.</b> The callback function should |
| 6744 | +** not attempt to invoke any other SQLite interface. If it does, bad |
| 6745 | +** things may happen, including segmentation faults and corrupt database |
| 6746 | +** files. The callback function should be a simple function that |
| 6747 | +** does some arithmetic on its input parameters and returns a result. |
| 6748 | +** |
| 6749 | +** ^The X parameter to sqlite3_autovacuum_pages(D,C,P,X) is an optional |
| 6750 | +** destructor for the P parameter. ^If X is not NULL, then X(P) is |
| 6751 | +** invoked whenever the database connection closes or when the callback |
| 6752 | +** is overwritten by another invocation of sqlite3_autovacuum_pages(). |
| 6753 | +** |
| 6754 | +** <p>^There is only one autovacuum pages callback per database connection. |
| 6755 | +** ^Each call to the sqlite3_autovacuum_pages() interface overrides all |
| 6756 | +** previous invocations for that database connection. ^If the callback |
| 6757 | +** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer, |
| 6758 | +** then the autovacuum steps callback is cancelled. The return value |
| 6759 | +** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might |
| 6760 | +** be some other error code if something goes wrong. The current |
| 6761 | +** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other |
| 6762 | +** return codes might be added in future releases. |
| 6763 | +** |
| 6764 | +** <p>If no autovacuum pages callback is specified (the usual case) or |
| 6765 | +** a NULL pointer is provided for the callback, |
| 6766 | +** then the default behavior is to vacuum all free pages. So, in other |
| 6767 | +** words, the default behavior is the same as if the callback function |
| 6768 | +** were something like this: |
| 6769 | +** |
| 6770 | +** <blockquote><pre> |
| 6771 | +** unsigned int demonstration_autovac_pages_callback( |
| 6772 | +** void *pClientData, |
| 6773 | +** const char *zSchema, |
| 6774 | +** unsigned int nDbPage, |
| 6775 | +** unsigned int nFreePage, |
| 6776 | +** unsigned int nBytePerPage |
| 6777 | +** ){ |
| 6778 | +** return nFreePage; |
| 6779 | +** } |
| 6780 | +** </pre></blockquote> |
| 6781 | +*/ |
| 6782 | +SQLITE_API int sqlite3_autovacuum_pages( |
| 6783 | + sqlite3 *db, |
| 6784 | + unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int), |
| 6785 | + void*, |
| 6786 | + void(*)(void*) |
| 6787 | +); |
| 6788 | + |
| 6700 | 6789 | |
| 6701 | 6790 | /* |
| 6702 | 6791 | ** CAPI3REF: Data Change Notification Callbacks |
| 6703 | 6792 | ** METHOD: sqlite3 |
| 6704 | 6793 | ** |
| | @@ -8159,11 +8248,12 @@ |
| 8159 | 8248 | #define SQLITE_TESTCTRL_PRNG_SEED 28 |
| 8160 | 8249 | #define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS 29 |
| 8161 | 8250 | #define SQLITE_TESTCTRL_SEEK_COUNT 30 |
| 8162 | 8251 | #define SQLITE_TESTCTRL_TRACEFLAGS 31 |
| 8163 | 8252 | #define SQLITE_TESTCTRL_TUNE 32 |
| 8164 | | -#define SQLITE_TESTCTRL_LAST 32 /* Largest TESTCTRL */ |
| 8253 | +#define SQLITE_TESTCTRL_LOGEST 33 |
| 8254 | +#define SQLITE_TESTCTRL_LAST 33 /* Largest TESTCTRL */ |
| 8165 | 8255 | |
| 8166 | 8256 | /* |
| 8167 | 8257 | ** CAPI3REF: SQL Keyword Checking |
| 8168 | 8258 | ** |
| 8169 | 8259 | ** These routines provide access to the set of SQL language keywords |
| | @@ -8681,10 +8771,20 @@ |
| 8681 | 8771 | ** <dd>^This is the number of times that the prepared statement has |
| 8682 | 8772 | ** been run. A single "run" for the purposes of this counter is one |
| 8683 | 8773 | ** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()]. |
| 8684 | 8774 | ** The counter is incremented on the first [sqlite3_step()] call of each |
| 8685 | 8775 | ** cycle. |
| 8776 | +** |
| 8777 | +** [[SQLITE_STMTSTATUS_FILTER_MISS]] |
| 8778 | +** [[SQLITE_STMTSTATUS_FILTER HIT]] |
| 8779 | +** <dt>SQLITE_STMTSTATUS_FILTER_HIT<br> |
| 8780 | +** SQLITE_STMTSTATUS_FILTER_MISS</dt> |
| 8781 | +** <dd>^SQLITE_STMTSTATUS_FILTER_HIT is the number of times that a join |
| 8782 | +** step was bypassed because a Bloom filter returned not-found. The |
| 8783 | +** corresponding SQLITE_STMTSTATUS_FILTER_MISS value is the number of |
| 8784 | +** times that the Bloom filter returned a find, and thus the join step |
| 8785 | +** had to be processed as normal. |
| 8686 | 8786 | ** |
| 8687 | 8787 | ** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt> |
| 8688 | 8788 | ** <dd>^This is the approximate number of bytes of heap memory |
| 8689 | 8789 | ** used to store the prepared statement. ^This value is not actually |
| 8690 | 8790 | ** a counter, and so the resetFlg parameter to sqlite3_stmt_status() |
| | @@ -8696,10 +8796,12 @@ |
| 8696 | 8796 | #define SQLITE_STMTSTATUS_SORT 2 |
| 8697 | 8797 | #define SQLITE_STMTSTATUS_AUTOINDEX 3 |
| 8698 | 8798 | #define SQLITE_STMTSTATUS_VM_STEP 4 |
| 8699 | 8799 | #define SQLITE_STMTSTATUS_REPREPARE 5 |
| 8700 | 8800 | #define SQLITE_STMTSTATUS_RUN 6 |
| 8801 | +#define SQLITE_STMTSTATUS_FILTER_MISS 7 |
| 8802 | +#define SQLITE_STMTSTATUS_FILTER_HIT 8 |
| 8701 | 8803 | #define SQLITE_STMTSTATUS_MEMUSED 99 |
| 8702 | 8804 | |
| 8703 | 8805 | /* |
| 8704 | 8806 | ** CAPI3REF: Custom Page Cache Object |
| 8705 | 8807 | ** |
| | @@ -13160,15 +13262,16 @@ |
| 13160 | 13262 | ** can be used to make sure boundary values are tested. For |
| 13161 | 13263 | ** bitmask tests, testcase() can be used to make sure each bit |
| 13162 | 13264 | ** is significant and used at least once. On switch statements |
| 13163 | 13265 | ** where multiple cases go to the same block of code, testcase() |
| 13164 | 13266 | ** can insure that all cases are evaluated. |
| 13165 | | -** |
| 13166 | 13267 | */ |
| 13167 | | -#ifdef SQLITE_COVERAGE_TEST |
| 13168 | | -SQLITE_PRIVATE void sqlite3Coverage(int); |
| 13169 | | -# define testcase(X) if( X ){ sqlite3Coverage(__LINE__); } |
| 13268 | +#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG) |
| 13269 | +# ifndef SQLITE_AMALGAMATION |
| 13270 | + extern unsigned int sqlite3CoverageCounter; |
| 13271 | +# endif |
| 13272 | +# define testcase(X) if( X ){ sqlite3CoverageCounter += (unsigned)__LINE__; } |
| 13170 | 13273 | #else |
| 13171 | 13274 | # define testcase(X) |
| 13172 | 13275 | #endif |
| 13173 | 13276 | |
| 13174 | 13277 | /* |
| | @@ -13194,10 +13297,18 @@ |
| 13194 | 13297 | # define VVA_ONLY(X) X |
| 13195 | 13298 | #else |
| 13196 | 13299 | # define VVA_ONLY(X) |
| 13197 | 13300 | #endif |
| 13198 | 13301 | |
| 13302 | +/* |
| 13303 | +** Disable ALWAYS() and NEVER() (make them pass-throughs) for coverage |
| 13304 | +** and mutation testing |
| 13305 | +*/ |
| 13306 | +#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST) |
| 13307 | +# define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1 |
| 13308 | +#endif |
| 13309 | + |
| 13199 | 13310 | /* |
| 13200 | 13311 | ** The ALWAYS and NEVER macros surround boolean expressions which |
| 13201 | 13312 | ** are intended to always be true or false, respectively. Such |
| 13202 | 13313 | ** expressions could be omitted from the code completely. But they |
| 13203 | 13314 | ** are included in a few cases in order to enhance the resilience |
| | @@ -13209,11 +13320,11 @@ |
| 13209 | 13320 | ** |
| 13210 | 13321 | ** When doing coverage testing ALWAYS and NEVER are hard-coded to |
| 13211 | 13322 | ** be true and false so that the unreachable code they specify will |
| 13212 | 13323 | ** not be counted as untested code. |
| 13213 | 13324 | */ |
| 13214 | | -#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST) |
| 13325 | +#if defined(SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS) |
| 13215 | 13326 | # define ALWAYS(X) (1) |
| 13216 | 13327 | # define NEVER(X) (0) |
| 13217 | 13328 | #elif !defined(NDEBUG) |
| 13218 | 13329 | # define ALWAYS(X) ((X)?1:(assert(0),0)) |
| 13219 | 13330 | # define NEVER(X) ((X)?(assert(0),1):0) |
| | @@ -13220,30 +13331,10 @@ |
| 13220 | 13331 | #else |
| 13221 | 13332 | # define ALWAYS(X) (X) |
| 13222 | 13333 | # define NEVER(X) (X) |
| 13223 | 13334 | #endif |
| 13224 | 13335 | |
| 13225 | | -/* |
| 13226 | | -** The harmless(X) macro indicates that expression X is usually false |
| 13227 | | -** but can be true without causing any problems, but we don't know of |
| 13228 | | -** any way to cause X to be true. |
| 13229 | | -** |
| 13230 | | -** In debugging and testing builds, this macro will abort if X is ever |
| 13231 | | -** true. In this way, developers are alerted to a possible test case |
| 13232 | | -** that causes X to be true. If a harmless macro ever fails, that is |
| 13233 | | -** an opportunity to change the macro into a testcase() and add a new |
| 13234 | | -** test case to the test suite. |
| 13235 | | -** |
| 13236 | | -** For normal production builds, harmless(X) is a no-op, since it does |
| 13237 | | -** not matter whether expression X is true or false. |
| 13238 | | -*/ |
| 13239 | | -#ifdef SQLITE_DEBUG |
| 13240 | | -# define harmless(X) assert(!(X)); |
| 13241 | | -#else |
| 13242 | | -# define harmless(X) |
| 13243 | | -#endif |
| 13244 | | - |
| 13245 | 13336 | /* |
| 13246 | 13337 | ** Some conditionals are optimizations only. In other words, if the |
| 13247 | 13338 | ** conditionals are replaced with a constant 1 (true) or 0 (false) then |
| 13248 | 13339 | ** the correct answer is still obtained, though perhaps not as quickly. |
| 13249 | 13340 | ** |
| | @@ -13422,11 +13513,11 @@ |
| 13422 | 13513 | /* #define sqliteHashKeysize(E) ((E)->nKey) // NOT USED */ |
| 13423 | 13514 | |
| 13424 | 13515 | /* |
| 13425 | 13516 | ** Number of entries in a hash table |
| 13426 | 13517 | */ |
| 13427 | | -/* #define sqliteHashCount(H) ((H)->count) // NOT USED */ |
| 13518 | +#define sqliteHashCount(H) ((H)->count) |
| 13428 | 13519 | |
| 13429 | 13520 | #endif /* SQLITE_HASH_H */ |
| 13430 | 13521 | |
| 13431 | 13522 | /************** End of hash.h ************************************************/ |
| 13432 | 13523 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| | @@ -13474,14 +13565,14 @@ |
| 13474 | 13565 | #define TK_DETACH 40 |
| 13475 | 13566 | #define TK_EACH 41 |
| 13476 | 13567 | #define TK_FAIL 42 |
| 13477 | 13568 | #define TK_OR 43 |
| 13478 | 13569 | #define TK_AND 44 |
| 13479 | | -#define TK_IS 45 |
| 13480 | | -#define TK_MATCH 46 |
| 13481 | | -#define TK_LIKE_KW 47 |
| 13482 | | -#define TK_BETWEEN 48 |
| 13570 | +#define TK_MATCH 45 |
| 13571 | +#define TK_LIKE_KW 46 |
| 13572 | +#define TK_BETWEEN 47 |
| 13573 | +#define TK_IS 48 |
| 13483 | 13574 | #define TK_IN 49 |
| 13484 | 13575 | #define TK_ISNULL 50 |
| 13485 | 13576 | #define TK_NOTNULL 51 |
| 13486 | 13577 | #define TK_NE 52 |
| 13487 | 13578 | #define TK_EQ 53 |
| | @@ -13718,11 +13809,11 @@ |
| 13718 | 13809 | ** The default initial allocation for the pagecache when using separate |
| 13719 | 13810 | ** pagecaches for each database connection. A positive number is the |
| 13720 | 13811 | ** number of pages. A negative number N translations means that a buffer |
| 13721 | 13812 | ** of -1024*N bytes is allocated and used for as many pages as it will hold. |
| 13722 | 13813 | ** |
| 13723 | | -** The default value of "20" was choosen to minimize the run-time of the |
| 13814 | +** The default value of "20" was chosen to minimize the run-time of the |
| 13724 | 13815 | ** speedtest1 test program with options: --shrink-memory --reprepare |
| 13725 | 13816 | */ |
| 13726 | 13817 | #ifndef SQLITE_DEFAULT_PCACHE_INITSZ |
| 13727 | 13818 | # define SQLITE_DEFAULT_PCACHE_INITSZ 20 |
| 13728 | 13819 | #endif |
| | @@ -14075,15 +14166,29 @@ |
| 14075 | 14166 | int nBusy; /* Incremented with each busy call */ |
| 14076 | 14167 | }; |
| 14077 | 14168 | |
| 14078 | 14169 | /* |
| 14079 | 14170 | ** Name of table that holds the database schema. |
| 14171 | +** |
| 14172 | +** The PREFERRED names are used whereever possible. But LEGACY is also |
| 14173 | +** used for backwards compatibility. |
| 14174 | +** |
| 14175 | +** 1. Queries can use either the PREFERRED or the LEGACY names |
| 14176 | +** 2. The sqlite3_set_authorizer() callback uses the LEGACY name |
| 14177 | +** 3. The PRAGMA table_list statement uses the PREFERRED name |
| 14178 | +** |
| 14179 | +** The LEGACY names are stored in the internal symbol hash table |
| 14180 | +** in support of (2). Names are translated using sqlite3PreferredTableName() |
| 14181 | +** for (3). The sqlite3FindTable() function takes care of translating |
| 14182 | +** names for (1). |
| 14183 | +** |
| 14184 | +** Note that "sqlite_temp_schema" can also be called "temp.sqlite_schema". |
| 14080 | 14185 | */ |
| 14081 | | -#define DFLT_SCHEMA_TABLE "sqlite_master" |
| 14082 | | -#define DFLT_TEMP_SCHEMA_TABLE "sqlite_temp_master" |
| 14083 | | -#define ALT_SCHEMA_TABLE "sqlite_schema" |
| 14084 | | -#define ALT_TEMP_SCHEMA_TABLE "sqlite_temp_schema" |
| 14186 | +#define LEGACY_SCHEMA_TABLE "sqlite_master" |
| 14187 | +#define LEGACY_TEMP_SCHEMA_TABLE "sqlite_temp_master" |
| 14188 | +#define PREFERRED_SCHEMA_TABLE "sqlite_schema" |
| 14189 | +#define PREFERRED_TEMP_SCHEMA_TABLE "sqlite_temp_schema" |
| 14085 | 14190 | |
| 14086 | 14191 | |
| 14087 | 14192 | /* |
| 14088 | 14193 | ** The root-page of the schema table. |
| 14089 | 14194 | */ |
| | @@ -14091,11 +14196,11 @@ |
| 14091 | 14196 | |
| 14092 | 14197 | /* |
| 14093 | 14198 | ** The name of the schema table. The name is different for TEMP. |
| 14094 | 14199 | */ |
| 14095 | 14200 | #define SCHEMA_TABLE(x) \ |
| 14096 | | - ((!OMIT_TEMPDB)&&(x==1)?DFLT_TEMP_SCHEMA_TABLE:DFLT_SCHEMA_TABLE) |
| 14201 | + ((!OMIT_TEMPDB)&&(x==1)?LEGACY_TEMP_SCHEMA_TABLE:LEGACY_SCHEMA_TABLE) |
| 14097 | 14202 | |
| 14098 | 14203 | /* |
| 14099 | 14204 | ** A convenience macro that returns the number of elements in |
| 14100 | 14205 | ** an array. |
| 14101 | 14206 | */ |
| | @@ -15159,49 +15264,49 @@ |
| 15159 | 15264 | #define OP_ElseEq 58 /* jump, same as TK_ESCAPE */ |
| 15160 | 15265 | #define OP_IfNotZero 59 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */ |
| 15161 | 15266 | #define OP_DecrJumpZero 60 /* jump, synopsis: if (--r[P1])==0 goto P2 */ |
| 15162 | 15267 | #define OP_IncrVacuum 61 /* jump */ |
| 15163 | 15268 | #define OP_VNext 62 /* jump */ |
| 15164 | | -#define OP_Init 63 /* jump, synopsis: Start at P2 */ |
| 15165 | | -#define OP_PureFunc 64 /* synopsis: r[P3]=func(r[P2@NP]) */ |
| 15166 | | -#define OP_Function 65 /* synopsis: r[P3]=func(r[P2@NP]) */ |
| 15167 | | -#define OP_Return 66 |
| 15168 | | -#define OP_EndCoroutine 67 |
| 15169 | | -#define OP_HaltIfNull 68 /* synopsis: if r[P3]=null halt */ |
| 15170 | | -#define OP_Halt 69 |
| 15171 | | -#define OP_Integer 70 /* synopsis: r[P2]=P1 */ |
| 15172 | | -#define OP_Int64 71 /* synopsis: r[P2]=P4 */ |
| 15173 | | -#define OP_String 72 /* synopsis: r[P2]='P4' (len=P1) */ |
| 15174 | | -#define OP_Null 73 /* synopsis: r[P2..P3]=NULL */ |
| 15175 | | -#define OP_SoftNull 74 /* synopsis: r[P1]=NULL */ |
| 15176 | | -#define OP_Blob 75 /* synopsis: r[P2]=P4 (len=P1) */ |
| 15177 | | -#define OP_Variable 76 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 15178 | | -#define OP_Move 77 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 15179 | | -#define OP_Copy 78 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ |
| 15180 | | -#define OP_SCopy 79 /* synopsis: r[P2]=r[P1] */ |
| 15181 | | -#define OP_IntCopy 80 /* synopsis: r[P2]=r[P1] */ |
| 15182 | | -#define OP_ChngCntRow 81 /* synopsis: output=r[P1] */ |
| 15183 | | -#define OP_ResultRow 82 /* synopsis: output=r[P1@P2] */ |
| 15184 | | -#define OP_CollSeq 83 |
| 15185 | | -#define OP_AddImm 84 /* synopsis: r[P1]=r[P1]+P2 */ |
| 15186 | | -#define OP_RealAffinity 85 |
| 15187 | | -#define OP_Cast 86 /* synopsis: affinity(r[P1]) */ |
| 15188 | | -#define OP_Permutation 87 |
| 15189 | | -#define OP_Compare 88 /* synopsis: r[P1@P3] <-> r[P2@P3] */ |
| 15190 | | -#define OP_IsTrue 89 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */ |
| 15191 | | -#define OP_ZeroOrNull 90 /* synopsis: r[P2] = 0 OR NULL */ |
| 15192 | | -#define OP_Offset 91 /* synopsis: r[P3] = sqlite_offset(P1) */ |
| 15193 | | -#define OP_Column 92 /* synopsis: r[P3]=PX */ |
| 15194 | | -#define OP_TypeCheck 93 /* synopsis: typecheck(r[P1@P2]) */ |
| 15195 | | -#define OP_Affinity 94 /* synopsis: affinity(r[P1@P2]) */ |
| 15196 | | -#define OP_MakeRecord 95 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 15197 | | -#define OP_Count 96 /* synopsis: r[P2]=count() */ |
| 15198 | | -#define OP_ReadCookie 97 |
| 15199 | | -#define OP_SetCookie 98 |
| 15200 | | -#define OP_ReopenIdx 99 /* synopsis: root=P2 iDb=P3 */ |
| 15201 | | -#define OP_OpenRead 100 /* synopsis: root=P2 iDb=P3 */ |
| 15202 | | -#define OP_OpenWrite 101 /* synopsis: root=P2 iDb=P3 */ |
| 15269 | +#define OP_Filter 63 /* jump, synopsis: if key(P3@P4) not in filter(P1) goto P2 */ |
| 15270 | +#define OP_Init 64 /* jump, synopsis: Start at P2 */ |
| 15271 | +#define OP_PureFunc 65 /* synopsis: r[P3]=func(r[P2@NP]) */ |
| 15272 | +#define OP_Function 66 /* synopsis: r[P3]=func(r[P2@NP]) */ |
| 15273 | +#define OP_Return 67 |
| 15274 | +#define OP_EndCoroutine 68 |
| 15275 | +#define OP_HaltIfNull 69 /* synopsis: if r[P3]=null halt */ |
| 15276 | +#define OP_Halt 70 |
| 15277 | +#define OP_Integer 71 /* synopsis: r[P2]=P1 */ |
| 15278 | +#define OP_Int64 72 /* synopsis: r[P2]=P4 */ |
| 15279 | +#define OP_String 73 /* synopsis: r[P2]='P4' (len=P1) */ |
| 15280 | +#define OP_Null 74 /* synopsis: r[P2..P3]=NULL */ |
| 15281 | +#define OP_SoftNull 75 /* synopsis: r[P1]=NULL */ |
| 15282 | +#define OP_Blob 76 /* synopsis: r[P2]=P4 (len=P1) */ |
| 15283 | +#define OP_Variable 77 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 15284 | +#define OP_Move 78 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 15285 | +#define OP_Copy 79 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ |
| 15286 | +#define OP_SCopy 80 /* synopsis: r[P2]=r[P1] */ |
| 15287 | +#define OP_IntCopy 81 /* synopsis: r[P2]=r[P1] */ |
| 15288 | +#define OP_FkCheck 82 |
| 15289 | +#define OP_ResultRow 83 /* synopsis: output=r[P1@P2] */ |
| 15290 | +#define OP_CollSeq 84 |
| 15291 | +#define OP_AddImm 85 /* synopsis: r[P1]=r[P1]+P2 */ |
| 15292 | +#define OP_RealAffinity 86 |
| 15293 | +#define OP_Cast 87 /* synopsis: affinity(r[P1]) */ |
| 15294 | +#define OP_Permutation 88 |
| 15295 | +#define OP_Compare 89 /* synopsis: r[P1@P3] <-> r[P2@P3] */ |
| 15296 | +#define OP_IsTrue 90 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */ |
| 15297 | +#define OP_ZeroOrNull 91 /* synopsis: r[P2] = 0 OR NULL */ |
| 15298 | +#define OP_Offset 92 /* synopsis: r[P3] = sqlite_offset(P1) */ |
| 15299 | +#define OP_Column 93 /* synopsis: r[P3]=PX */ |
| 15300 | +#define OP_TypeCheck 94 /* synopsis: typecheck(r[P1@P2]) */ |
| 15301 | +#define OP_Affinity 95 /* synopsis: affinity(r[P1@P2]) */ |
| 15302 | +#define OP_MakeRecord 96 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 15303 | +#define OP_Count 97 /* synopsis: r[P2]=count() */ |
| 15304 | +#define OP_ReadCookie 98 |
| 15305 | +#define OP_SetCookie 99 |
| 15306 | +#define OP_ReopenIdx 100 /* synopsis: root=P2 iDb=P3 */ |
| 15307 | +#define OP_OpenRead 101 /* synopsis: root=P2 iDb=P3 */ |
| 15203 | 15308 | #define OP_BitAnd 102 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */ |
| 15204 | 15309 | #define OP_BitOr 103 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */ |
| 15205 | 15310 | #define OP_ShiftLeft 104 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */ |
| 15206 | 15311 | #define OP_ShiftRight 105 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */ |
| 15207 | 15312 | #define OP_Add 106 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */ |
| | @@ -15208,80 +15313,82 @@ |
| 15208 | 15313 | #define OP_Subtract 107 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */ |
| 15209 | 15314 | #define OP_Multiply 108 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */ |
| 15210 | 15315 | #define OP_Divide 109 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */ |
| 15211 | 15316 | #define OP_Remainder 110 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */ |
| 15212 | 15317 | #define OP_Concat 111 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */ |
| 15213 | | -#define OP_OpenDup 112 |
| 15318 | +#define OP_OpenWrite 112 /* synopsis: root=P2 iDb=P3 */ |
| 15214 | 15319 | #define OP_BitNot 113 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */ |
| 15215 | | -#define OP_OpenAutoindex 114 /* synopsis: nColumn=P2 */ |
| 15216 | | -#define OP_OpenEphemeral 115 /* synopsis: nColumn=P2 */ |
| 15320 | +#define OP_OpenDup 114 |
| 15321 | +#define OP_OpenAutoindex 115 /* synopsis: nColumn=P2 */ |
| 15217 | 15322 | #define OP_String8 116 /* same as TK_STRING, synopsis: r[P2]='P4' */ |
| 15218 | | -#define OP_SorterOpen 117 |
| 15219 | | -#define OP_SequenceTest 118 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ |
| 15220 | | -#define OP_OpenPseudo 119 /* synopsis: P3 columns in r[P2] */ |
| 15221 | | -#define OP_Close 120 |
| 15222 | | -#define OP_ColumnsUsed 121 |
| 15223 | | -#define OP_SeekScan 122 /* synopsis: Scan-ahead up to P1 rows */ |
| 15224 | | -#define OP_SeekHit 123 /* synopsis: set P2<=seekHit<=P3 */ |
| 15225 | | -#define OP_Sequence 124 /* synopsis: r[P2]=cursor[P1].ctr++ */ |
| 15226 | | -#define OP_NewRowid 125 /* synopsis: r[P2]=rowid */ |
| 15227 | | -#define OP_Insert 126 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 15228 | | -#define OP_RowCell 127 |
| 15229 | | -#define OP_Delete 128 |
| 15230 | | -#define OP_ResetCount 129 |
| 15231 | | -#define OP_SorterCompare 130 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ |
| 15232 | | -#define OP_SorterData 131 /* synopsis: r[P2]=data */ |
| 15233 | | -#define OP_RowData 132 /* synopsis: r[P2]=data */ |
| 15234 | | -#define OP_Rowid 133 /* synopsis: r[P2]=rowid */ |
| 15235 | | -#define OP_NullRow 134 |
| 15236 | | -#define OP_SeekEnd 135 |
| 15237 | | -#define OP_IdxInsert 136 /* synopsis: key=r[P2] */ |
| 15238 | | -#define OP_SorterInsert 137 /* synopsis: key=r[P2] */ |
| 15239 | | -#define OP_IdxDelete 138 /* synopsis: key=r[P2@P3] */ |
| 15240 | | -#define OP_DeferredSeek 139 /* synopsis: Move P3 to P1.rowid if needed */ |
| 15241 | | -#define OP_IdxRowid 140 /* synopsis: r[P2]=rowid */ |
| 15242 | | -#define OP_FinishSeek 141 |
| 15243 | | -#define OP_Destroy 142 |
| 15244 | | -#define OP_Clear 143 |
| 15245 | | -#define OP_ResetSorter 144 |
| 15246 | | -#define OP_CreateBtree 145 /* synopsis: r[P2]=root iDb=P1 flags=P3 */ |
| 15247 | | -#define OP_SqlExec 146 |
| 15248 | | -#define OP_ParseSchema 147 |
| 15249 | | -#define OP_LoadAnalysis 148 |
| 15250 | | -#define OP_DropTable 149 |
| 15251 | | -#define OP_DropIndex 150 |
| 15252 | | -#define OP_DropTrigger 151 |
| 15323 | +#define OP_OpenEphemeral 117 /* synopsis: nColumn=P2 */ |
| 15324 | +#define OP_SorterOpen 118 |
| 15325 | +#define OP_SequenceTest 119 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ |
| 15326 | +#define OP_OpenPseudo 120 /* synopsis: P3 columns in r[P2] */ |
| 15327 | +#define OP_Close 121 |
| 15328 | +#define OP_ColumnsUsed 122 |
| 15329 | +#define OP_SeekScan 123 /* synopsis: Scan-ahead up to P1 rows */ |
| 15330 | +#define OP_SeekHit 124 /* synopsis: set P2<=seekHit<=P3 */ |
| 15331 | +#define OP_Sequence 125 /* synopsis: r[P2]=cursor[P1].ctr++ */ |
| 15332 | +#define OP_NewRowid 126 /* synopsis: r[P2]=rowid */ |
| 15333 | +#define OP_Insert 127 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 15334 | +#define OP_RowCell 128 |
| 15335 | +#define OP_Delete 129 |
| 15336 | +#define OP_ResetCount 130 |
| 15337 | +#define OP_SorterCompare 131 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ |
| 15338 | +#define OP_SorterData 132 /* synopsis: r[P2]=data */ |
| 15339 | +#define OP_RowData 133 /* synopsis: r[P2]=data */ |
| 15340 | +#define OP_Rowid 134 /* synopsis: r[P2]=rowid */ |
| 15341 | +#define OP_NullRow 135 |
| 15342 | +#define OP_SeekEnd 136 |
| 15343 | +#define OP_IdxInsert 137 /* synopsis: key=r[P2] */ |
| 15344 | +#define OP_SorterInsert 138 /* synopsis: key=r[P2] */ |
| 15345 | +#define OP_IdxDelete 139 /* synopsis: key=r[P2@P3] */ |
| 15346 | +#define OP_DeferredSeek 140 /* synopsis: Move P3 to P1.rowid if needed */ |
| 15347 | +#define OP_IdxRowid 141 /* synopsis: r[P2]=rowid */ |
| 15348 | +#define OP_FinishSeek 142 |
| 15349 | +#define OP_Destroy 143 |
| 15350 | +#define OP_Clear 144 |
| 15351 | +#define OP_ResetSorter 145 |
| 15352 | +#define OP_CreateBtree 146 /* synopsis: r[P2]=root iDb=P1 flags=P3 */ |
| 15353 | +#define OP_SqlExec 147 |
| 15354 | +#define OP_ParseSchema 148 |
| 15355 | +#define OP_LoadAnalysis 149 |
| 15356 | +#define OP_DropTable 150 |
| 15357 | +#define OP_DropIndex 151 |
| 15253 | 15358 | #define OP_Real 152 /* same as TK_FLOAT, synopsis: r[P2]=P4 */ |
| 15254 | | -#define OP_IntegrityCk 153 |
| 15255 | | -#define OP_RowSetAdd 154 /* synopsis: rowset(P1)=r[P2] */ |
| 15256 | | -#define OP_Param 155 |
| 15257 | | -#define OP_FkCounter 156 /* synopsis: fkctr[P1]+=P2 */ |
| 15258 | | -#define OP_MemMax 157 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 15259 | | -#define OP_OffsetLimit 158 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ |
| 15260 | | -#define OP_AggInverse 159 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */ |
| 15261 | | -#define OP_AggStep 160 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 15262 | | -#define OP_AggStep1 161 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 15263 | | -#define OP_AggValue 162 /* synopsis: r[P3]=value N=P2 */ |
| 15264 | | -#define OP_AggFinal 163 /* synopsis: accum=r[P1] N=P2 */ |
| 15265 | | -#define OP_Expire 164 |
| 15266 | | -#define OP_CursorLock 165 |
| 15267 | | -#define OP_CursorUnlock 166 |
| 15268 | | -#define OP_TableLock 167 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 15269 | | -#define OP_VBegin 168 |
| 15270 | | -#define OP_VCreate 169 |
| 15271 | | -#define OP_VDestroy 170 |
| 15272 | | -#define OP_VOpen 171 |
| 15273 | | -#define OP_VColumn 172 /* synopsis: r[P3]=vcolumn(P2) */ |
| 15274 | | -#define OP_VRename 173 |
| 15275 | | -#define OP_Pagecount 174 |
| 15276 | | -#define OP_MaxPgcnt 175 |
| 15277 | | -#define OP_Trace 176 |
| 15278 | | -#define OP_CursorHint 177 |
| 15279 | | -#define OP_ReleaseReg 178 /* synopsis: release r[P1@P2] mask P3 */ |
| 15280 | | -#define OP_Noop 179 |
| 15281 | | -#define OP_Explain 180 |
| 15282 | | -#define OP_Abortable 181 |
| 15359 | +#define OP_DropTrigger 153 |
| 15360 | +#define OP_IntegrityCk 154 |
| 15361 | +#define OP_RowSetAdd 155 /* synopsis: rowset(P1)=r[P2] */ |
| 15362 | +#define OP_Param 156 |
| 15363 | +#define OP_FkCounter 157 /* synopsis: fkctr[P1]+=P2 */ |
| 15364 | +#define OP_MemMax 158 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 15365 | +#define OP_OffsetLimit 159 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ |
| 15366 | +#define OP_AggInverse 160 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */ |
| 15367 | +#define OP_AggStep 161 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 15368 | +#define OP_AggStep1 162 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 15369 | +#define OP_AggValue 163 /* synopsis: r[P3]=value N=P2 */ |
| 15370 | +#define OP_AggFinal 164 /* synopsis: accum=r[P1] N=P2 */ |
| 15371 | +#define OP_Expire 165 |
| 15372 | +#define OP_CursorLock 166 |
| 15373 | +#define OP_CursorUnlock 167 |
| 15374 | +#define OP_TableLock 168 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 15375 | +#define OP_VBegin 169 |
| 15376 | +#define OP_VCreate 170 |
| 15377 | +#define OP_VDestroy 171 |
| 15378 | +#define OP_VOpen 172 |
| 15379 | +#define OP_VColumn 173 /* synopsis: r[P3]=vcolumn(P2) */ |
| 15380 | +#define OP_VRename 174 |
| 15381 | +#define OP_Pagecount 175 |
| 15382 | +#define OP_MaxPgcnt 176 |
| 15383 | +#define OP_FilterAdd 177 /* synopsis: filter(P1) += key(P3@P4) */ |
| 15384 | +#define OP_Trace 178 |
| 15385 | +#define OP_CursorHint 179 |
| 15386 | +#define OP_ReleaseReg 180 /* synopsis: release r[P1@P2] mask P3 */ |
| 15387 | +#define OP_Noop 181 |
| 15388 | +#define OP_Explain 182 |
| 15389 | +#define OP_Abortable 183 |
| 15283 | 15390 | |
| 15284 | 15391 | /* Properties such as "out2" or "jump" that are specified in |
| 15285 | 15392 | ** comments following the "case" for each opcode in the vdbe.c |
| 15286 | 15393 | ** are encoded into bitvectors as follows: |
| 15287 | 15394 | */ |
| | @@ -15298,33 +15405,34 @@ |
| 15298 | 15405 | /* 24 */ 0x09, 0x09, 0x09, 0x01, 0x09, 0x09, 0x09, 0x09,\ |
| 15299 | 15406 | /* 32 */ 0x09, 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\ |
| 15300 | 15407 | /* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x23, 0x0b, 0x01,\ |
| 15301 | 15408 | /* 48 */ 0x01, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\ |
| 15302 | 15409 | /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x01, 0x01, 0x01,\ |
| 15303 | | -/* 64 */ 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10,\ |
| 15304 | | -/* 72 */ 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10,\ |
| 15305 | | -/* 80 */ 0x10, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00,\ |
| 15306 | | -/* 88 */ 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00, 0x00, 0x00,\ |
| 15307 | | -/* 96 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x26, 0x26,\ |
| 15410 | +/* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\ |
| 15411 | +/* 72 */ 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00,\ |
| 15412 | +/* 80 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02,\ |
| 15413 | +/* 88 */ 0x00, 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00, 0x00,\ |
| 15414 | +/* 96 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x26, 0x26,\ |
| 15308 | 15415 | /* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\ |
| 15309 | 15416 | /* 112 */ 0x00, 0x12, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,\ |
| 15310 | | -/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\ |
| 15311 | | -/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,\ |
| 15312 | | -/* 136 */ 0x04, 0x04, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00,\ |
| 15313 | | -/* 144 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 15314 | | -/* 152 */ 0x10, 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00,\ |
| 15417 | +/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\ |
| 15418 | +/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\ |
| 15419 | +/* 136 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00, 0x10,\ |
| 15420 | +/* 144 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 15421 | +/* 152 */ 0x10, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a,\ |
| 15315 | 15422 | /* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 15316 | | -/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\ |
| 15317 | | -/* 176 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,} |
| 15423 | +/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\ |
| 15424 | +/* 176 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 15425 | +} |
| 15318 | 15426 | |
| 15319 | 15427 | /* The resolve3P2Values() routine is able to run faster if it knows |
| 15320 | 15428 | ** the value of the largest JUMP opcode. The smaller the maximum |
| 15321 | 15429 | ** JUMP opcode the better, so the mkopcodeh.tcl script that |
| 15322 | 15430 | ** generated this include file strives to group all JUMP opcodes |
| 15323 | 15431 | ** together near the beginning of the list. |
| 15324 | 15432 | */ |
| 15325 | | -#define SQLITE_MX_JUMP_OPCODE 63 /* Maximum JUMP opcode */ |
| 15433 | +#define SQLITE_MX_JUMP_OPCODE 64 /* Maximum JUMP opcode */ |
| 15326 | 15434 | |
| 15327 | 15435 | /************** End of opcodes.h *********************************************/ |
| 15328 | 15436 | /************** Continuing where we left off in vdbe.h ***********************/ |
| 15329 | 15437 | |
| 15330 | 15438 | /* |
| | @@ -16420,14 +16528,14 @@ |
| 16420 | 16528 | int nVdbeExec; /* Number of nested calls to VdbeExec() */ |
| 16421 | 16529 | int nVDestroy; /* Number of active OP_VDestroy operations */ |
| 16422 | 16530 | int nExtension; /* Number of loaded extensions */ |
| 16423 | 16531 | void **aExtension; /* Array of shared library handles */ |
| 16424 | 16532 | union { |
| 16425 | | - void (*xLegacy)(void*,const char*); /* Legacy trace function */ |
| 16426 | | - int (*xV2)(u32,void*,void*,void*); /* V2 Trace function */ |
| 16533 | + void (*xLegacy)(void*,const char*); /* mTrace==SQLITE_TRACE_LEGACY */ |
| 16534 | + int (*xV2)(u32,void*,void*,void*); /* All other mTrace values */ |
| 16427 | 16535 | } trace; |
| 16428 | | - void *pTraceArg; /* Argument to the trace function */ |
| 16536 | + void *pTraceArg; /* Argument to the trace function */ |
| 16429 | 16537 | #ifndef SQLITE_OMIT_DEPRECATED |
| 16430 | 16538 | void (*xProfile)(void*,const char*,u64); /* Profiling function */ |
| 16431 | 16539 | void *pProfileArg; /* Argument to profile function */ |
| 16432 | 16540 | #endif |
| 16433 | 16541 | void *pCommitArg; /* Argument to xCommitCallback() */ |
| | @@ -16434,10 +16542,13 @@ |
| 16434 | 16542 | int (*xCommitCallback)(void*); /* Invoked at every commit. */ |
| 16435 | 16543 | void *pRollbackArg; /* Argument to xRollbackCallback() */ |
| 16436 | 16544 | void (*xRollbackCallback)(void*); /* Invoked at every commit. */ |
| 16437 | 16545 | void *pUpdateArg; |
| 16438 | 16546 | void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64); |
| 16547 | + void *pAutovacPagesArg; /* Client argument to autovac_pages */ |
| 16548 | + void (*xAutovacDestr)(void*); /* Destructor for pAutovacPAgesArg */ |
| 16549 | + unsigned int (*xAutovacPages)(void*,const char*,u32,u32,u32); |
| 16439 | 16550 | Parse *pParse; /* Current parse */ |
| 16440 | 16551 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 16441 | 16552 | void *pPreUpdateArg; /* First argument to xPreUpdateCallback */ |
| 16442 | 16553 | void (*xPreUpdateCallback)( /* Registered using sqlite3_preupdate_hook() */ |
| 16443 | 16554 | void*,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64 |
| | @@ -16563,10 +16674,11 @@ |
| 16563 | 16674 | #define SQLITE_DqsDML 0x40000000 /* dbl-quoted strings allowed in DML*/ |
| 16564 | 16675 | #define SQLITE_EnableView 0x80000000 /* Enable the use of views */ |
| 16565 | 16676 | #define SQLITE_CountRows HI(0x00001) /* Count rows changed by INSERT, */ |
| 16566 | 16677 | /* DELETE, or UPDATE and return */ |
| 16567 | 16678 | /* the count using a callback. */ |
| 16679 | +#define SQLITE_CorruptRdOnly HI(0x00002) /* Prohibit writes due to error */ |
| 16568 | 16680 | |
| 16569 | 16681 | /* Flags used only if debugging */ |
| 16570 | 16682 | #ifdef SQLITE_DEBUG |
| 16571 | 16683 | #define SQLITE_SqlTrace HI(0x0100000) /* Debug print SQL as it executes */ |
| 16572 | 16684 | #define SQLITE_VdbeListing HI(0x0200000) /* Debug listings of VDBE progs */ |
| | @@ -16611,10 +16723,12 @@ |
| 16611 | 16723 | #define SQLITE_PropagateConst 0x00008000 /* The constant propagation opt */ |
| 16612 | 16724 | #define SQLITE_MinMaxOpt 0x00010000 /* The min/max optimization */ |
| 16613 | 16725 | #define SQLITE_SeekScan 0x00020000 /* The OP_SeekScan optimization */ |
| 16614 | 16726 | #define SQLITE_OmitOrderBy 0x00040000 /* Omit pointless ORDER BY */ |
| 16615 | 16727 | /* TH3 expects this value ^^^^^^^^^^ to be 0x40000. Coordinate any change */ |
| 16728 | +#define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */ |
| 16729 | +#define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */ |
| 16616 | 16730 | #define SQLITE_AllOpts 0xffffffff /* All optimizations */ |
| 16617 | 16731 | |
| 16618 | 16732 | /* |
| 16619 | 16733 | ** Macros for testing whether or not optimizations are enabled or disabled. |
| 16620 | 16734 | */ |
| | @@ -16659,11 +16773,11 @@ |
| 16659 | 16773 | void (*xInverse)(sqlite3_context*,int,sqlite3_value**); /* inverse agg-step */ |
| 16660 | 16774 | const char *zName; /* SQL name of the function. */ |
| 16661 | 16775 | union { |
| 16662 | 16776 | FuncDef *pHash; /* Next with a different name but the same hash */ |
| 16663 | 16777 | FuncDestructor *pDestructor; /* Reference counted destructor function */ |
| 16664 | | - } u; |
| 16778 | + } u; /* pHash if SQLITE_FUNC_BUILTIN, pDestructor otherwise */ |
| 16665 | 16779 | }; |
| 16666 | 16780 | |
| 16667 | 16781 | /* |
| 16668 | 16782 | ** This structure encapsulates a user-function destructor callback (as |
| 16669 | 16783 | ** configured using create_function_v2()) and a reference counter. When |
| | @@ -16720,10 +16834,11 @@ |
| 16720 | 16834 | #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */ |
| 16721 | 16835 | #define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */ |
| 16722 | 16836 | #define SQLITE_FUNC_SUBTYPE 0x00100000 /* Result likely to have sub-type */ |
| 16723 | 16837 | #define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */ |
| 16724 | 16838 | #define SQLITE_FUNC_INLINE 0x00400000 /* Functions implemented in-line */ |
| 16839 | +#define SQLITE_FUNC_BUILTIN 0x00800000 /* This is a built-in function */ |
| 16725 | 16840 | #define SQLITE_FUNC_ANYORDER 0x08000000 /* count/min/max aggregate */ |
| 16726 | 16841 | |
| 16727 | 16842 | /* Identifier numbers for each in-line function */ |
| 16728 | 16843 | #define INLINEFUNC_coalesce 0 |
| 16729 | 16844 | #define INLINEFUNC_implies_nonnull_row 1 |
| | @@ -16798,48 +16913,55 @@ |
| 16798 | 16913 | ** available as the function user-data (sqlite3_user_data()). The |
| 16799 | 16914 | ** FuncDef.flags variable is set to the value passed as the flags |
| 16800 | 16915 | ** parameter. |
| 16801 | 16916 | */ |
| 16802 | 16917 | #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 16803 | | - {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 16918 | + {nArg, SQLITE_FUNC_BUILTIN|\ |
| 16919 | + SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 16804 | 16920 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16805 | 16921 | #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 16806 | | - {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 16922 | + {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 16807 | 16923 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16808 | 16924 | #define SFUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 16809 | | - {nArg, SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \ |
| 16925 | + {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \ |
| 16810 | 16926 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16811 | 16927 | #define MFUNCTION(zName, nArg, xPtr, xFunc) \ |
| 16812 | | - {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \ |
| 16928 | + {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \ |
| 16813 | 16929 | xPtr, 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16814 | 16930 | #define INLINE_FUNC(zName, nArg, iArg, mFlags) \ |
| 16815 | | - {nArg, SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \ |
| 16931 | + {nArg, SQLITE_FUNC_BUILTIN|\ |
| 16932 | + SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \ |
| 16816 | 16933 | SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} } |
| 16817 | 16934 | #define TEST_FUNC(zName, nArg, iArg, mFlags) \ |
| 16818 | | - {nArg, SQLITE_UTF8|SQLITE_FUNC_INTERNAL|SQLITE_FUNC_TEST| \ |
| 16935 | + {nArg, SQLITE_FUNC_BUILTIN|\ |
| 16936 | + SQLITE_UTF8|SQLITE_FUNC_INTERNAL|SQLITE_FUNC_TEST| \ |
| 16819 | 16937 | SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \ |
| 16820 | 16938 | SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} } |
| 16821 | 16939 | #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 16822 | | - {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \ |
| 16940 | + {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \ |
| 16823 | 16941 | 0, 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16824 | 16942 | #define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \ |
| 16825 | | - {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \ |
| 16943 | + {nArg, SQLITE_FUNC_BUILTIN|\ |
| 16944 | + SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \ |
| 16826 | 16945 | (void*)&sqlite3Config, 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16827 | 16946 | #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \ |
| 16828 | | - {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\ |
| 16947 | + {nArg, SQLITE_FUNC_BUILTIN|\ |
| 16948 | + SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\ |
| 16829 | 16949 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16830 | 16950 | #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \ |
| 16831 | | - {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 16951 | + {nArg, SQLITE_FUNC_BUILTIN|\ |
| 16952 | + SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 16832 | 16953 | pArg, 0, xFunc, 0, 0, 0, #zName, } |
| 16833 | 16954 | #define LIKEFUNC(zName, nArg, arg, flags) \ |
| 16834 | | - {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \ |
| 16955 | + {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \ |
| 16835 | 16956 | (void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} } |
| 16836 | 16957 | #define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \ |
| 16837 | | - {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \ |
| 16958 | + {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \ |
| 16838 | 16959 | SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}} |
| 16839 | 16960 | #define INTERNAL_FUNCTION(zName, nArg, xFunc) \ |
| 16840 | | - {nArg, SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \ |
| 16961 | + {nArg, SQLITE_FUNC_BUILTIN|\ |
| 16962 | + SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \ |
| 16841 | 16963 | 0, 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16842 | 16964 | |
| 16843 | 16965 | |
| 16844 | 16966 | /* |
| 16845 | 16967 | ** All current savepoints are stored in a linked list starting at |
| | @@ -17558,14 +17680,14 @@ |
| 17558 | 17680 | ** code representing the ">=" operator. This same integer code is reused |
| 17559 | 17681 | ** to represent the greater-than-or-equal-to operator in the expression |
| 17560 | 17682 | ** tree. |
| 17561 | 17683 | ** |
| 17562 | 17684 | ** If the expression is an SQL literal (TK_INTEGER, TK_FLOAT, TK_BLOB, |
| 17563 | | -** or TK_STRING), then Expr.token contains the text of the SQL literal. If |
| 17564 | | -** the expression is a variable (TK_VARIABLE), then Expr.token contains the |
| 17685 | +** or TK_STRING), then Expr.u.zToken contains the text of the SQL literal. If |
| 17686 | +** the expression is a variable (TK_VARIABLE), then Expr.u.zToken contains the |
| 17565 | 17687 | ** variable name. Finally, if the expression is an SQL function (TK_FUNCTION), |
| 17566 | | -** then Expr.token contains the name of the function. |
| 17688 | +** then Expr.u.zToken contains the name of the function. |
| 17567 | 17689 | ** |
| 17568 | 17690 | ** Expr.pRight and Expr.pLeft are the left and right subexpressions of a |
| 17569 | 17691 | ** binary operator. Either or both may be NULL. |
| 17570 | 17692 | ** |
| 17571 | 17693 | ** Expr.x.pList is a list of arguments if the expression is an SQL function, |
| | @@ -17601,11 +17723,11 @@ |
| 17601 | 17723 | ** |
| 17602 | 17724 | ** Expr objects can use a lot of memory space in database schema. To |
| 17603 | 17725 | ** help reduce memory requirements, sometimes an Expr object will be |
| 17604 | 17726 | ** truncated. And to reduce the number of memory allocations, sometimes |
| 17605 | 17727 | ** two or more Expr objects will be stored in a single memory allocation, |
| 17606 | | -** together with Expr.zToken strings. |
| 17728 | +** together with Expr.u.zToken strings. |
| 17607 | 17729 | ** |
| 17608 | 17730 | ** If the EP_Reduced and EP_TokenOnly flags are set when |
| 17609 | 17731 | ** an Expr object is truncated. When EP_Reduced is set, then all |
| 17610 | 17732 | ** the child Expr objects in the Expr.pLeft and Expr.pRight subtrees |
| 17611 | 17733 | ** are contained within the same memory allocation. Note, however, that |
| | @@ -17670,12 +17792,11 @@ |
| 17670 | 17792 | int regReturn; /* Register used to hold return address */ |
| 17671 | 17793 | } sub; |
| 17672 | 17794 | } y; |
| 17673 | 17795 | }; |
| 17674 | 17796 | |
| 17675 | | -/* |
| 17676 | | -** The following are the meanings of bits in the Expr.flags field. |
| 17797 | +/* The following are the meanings of bits in the Expr.flags field. |
| 17677 | 17798 | ** Value restrictions: |
| 17678 | 17799 | ** |
| 17679 | 17800 | ** EP_Agg == NC_HasAgg == SF_HasAgg |
| 17680 | 17801 | ** EP_Win == NC_HasWin |
| 17681 | 17802 | */ |
| | @@ -17710,27 +17831,35 @@ |
| 17710 | 17831 | #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */ |
| 17711 | 17832 | #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */ |
| 17712 | 17833 | #define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */ |
| 17713 | 17834 | /* 0x80000000 // Available */ |
| 17714 | 17835 | |
| 17715 | | -/* |
| 17716 | | -** The EP_Propagate mask is a set of properties that automatically propagate |
| 17836 | +/* The EP_Propagate mask is a set of properties that automatically propagate |
| 17717 | 17837 | ** upwards into parent nodes. |
| 17718 | 17838 | */ |
| 17719 | 17839 | #define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc) |
| 17720 | 17840 | |
| 17721 | | -/* |
| 17722 | | -** These macros can be used to test, set, or clear bits in the |
| 17841 | +/* Macros can be used to test, set, or clear bits in the |
| 17723 | 17842 | ** Expr.flags field. |
| 17724 | 17843 | */ |
| 17725 | 17844 | #define ExprHasProperty(E,P) (((E)->flags&(P))!=0) |
| 17726 | 17845 | #define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P)) |
| 17727 | 17846 | #define ExprSetProperty(E,P) (E)->flags|=(P) |
| 17728 | 17847 | #define ExprClearProperty(E,P) (E)->flags&=~(P) |
| 17729 | 17848 | #define ExprAlwaysTrue(E) (((E)->flags&(EP_FromJoin|EP_IsTrue))==EP_IsTrue) |
| 17730 | 17849 | #define ExprAlwaysFalse(E) (((E)->flags&(EP_FromJoin|EP_IsFalse))==EP_IsFalse) |
| 17731 | 17850 | |
| 17851 | +/* Macros used to ensure that the correct members of unions are accessed |
| 17852 | +** in Expr. |
| 17853 | +*/ |
| 17854 | +#define ExprUseUToken(E) (((E)->flags&EP_IntValue)==0) |
| 17855 | +#define ExprUseUValue(E) (((E)->flags&EP_IntValue)!=0) |
| 17856 | +#define ExprUseXList(E) (((E)->flags&EP_xIsSelect)==0) |
| 17857 | +#define ExprUseXSelect(E) (((E)->flags&EP_xIsSelect)!=0) |
| 17858 | +#define ExprUseYTab(E) (((E)->flags&(EP_WinFunc|EP_Subrtn))==0) |
| 17859 | +#define ExprUseYWin(E) (((E)->flags&EP_WinFunc)!=0) |
| 17860 | +#define ExprUseYSub(E) (((E)->flags&EP_Subrtn)!=0) |
| 17732 | 17861 | |
| 17733 | 17862 | /* Flags for use with Expr.vvaFlags |
| 17734 | 17863 | */ |
| 17735 | 17864 | #define EP_NoReduce 0x01 /* Cannot EXPRDUP_REDUCE this Expr */ |
| 17736 | 17865 | #define EP_Immutable 0x02 /* Do not change this Expr node */ |
| | @@ -17809,15 +17938,16 @@ |
| 17809 | 17938 | unsigned done :1; /* A flag to indicate when processing is finished */ |
| 17810 | 17939 | unsigned reusable :1; /* Constant expression is reusable */ |
| 17811 | 17940 | unsigned bSorterRef :1; /* Defer evaluation until after sorting */ |
| 17812 | 17941 | unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */ |
| 17813 | 17942 | union { |
| 17814 | | - struct { |
| 17943 | + struct { /* Used by any ExprList other than Parse.pConsExpr */ |
| 17815 | 17944 | u16 iOrderByCol; /* For ORDER BY, column number in result set */ |
| 17816 | 17945 | u16 iAlias; /* Index into Parse.aAlias[] for zName */ |
| 17817 | 17946 | } x; |
| 17818 | | - int iConstExprReg; /* Register in which Expr value is cached */ |
| 17947 | + int iConstExprReg; /* Register in which Expr value is cached. Used only |
| 17948 | + ** by Parse.pConstExpr */ |
| 17819 | 17949 | } u; |
| 17820 | 17950 | } a[1]; /* One slot for each expression in the list */ |
| 17821 | 17951 | }; |
| 17822 | 17952 | |
| 17823 | 17953 | /* |
| | @@ -17851,10 +17981,17 @@ |
| 17851 | 17981 | }; |
| 17852 | 17982 | |
| 17853 | 17983 | /* |
| 17854 | 17984 | ** The SrcItem object represents a single term in the FROM clause of a query. |
| 17855 | 17985 | ** The SrcList object is mostly an array of SrcItems. |
| 17986 | +** |
| 17987 | +** Union member validity: |
| 17988 | +** |
| 17989 | +** u1.zIndexedBy fg.isIndexedBy && !fg.isTabFunc |
| 17990 | +** u1.pFuncArg fg.isTabFunc && !fg.isIndexedBy |
| 17991 | +** u2.pIBIndex fg.isIndexedBy && !fg.isCte |
| 17992 | +** u2.pCteUse fg.isCte && !fg.isIndexedBy |
| 17856 | 17993 | */ |
| 17857 | 17994 | struct SrcItem { |
| 17858 | 17995 | Schema *pSchema; /* Schema to which this item is fixed */ |
| 17859 | 17996 | char *zDatabase; /* Name of database holding this table */ |
| 17860 | 17997 | char *zName; /* Name of the table */ |
| | @@ -18382,11 +18519,10 @@ |
| 18382 | 18519 | TableLock *aTableLock; /* Required table locks for shared-cache mode */ |
| 18383 | 18520 | #endif |
| 18384 | 18521 | AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */ |
| 18385 | 18522 | Parse *pToplevel; /* Parse structure for main program (or NULL) */ |
| 18386 | 18523 | Table *pTriggerTab; /* Table triggers are being coded for */ |
| 18387 | | - Parse *pParentParse; /* Parent parser if this parser is nested */ |
| 18388 | 18524 | union { |
| 18389 | 18525 | int addrCrTab; /* Address of OP_CreateBtree on CREATE TABLE */ |
| 18390 | 18526 | Returning *pReturning; /* The RETURNING clause */ |
| 18391 | 18527 | } u1; |
| 18392 | 18528 | u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */ |
| | @@ -18445,10 +18581,12 @@ |
| 18445 | 18581 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 18446 | 18582 | RenameToken *pRename; /* Tokens subject to renaming by ALTER TABLE */ |
| 18447 | 18583 | #endif |
| 18448 | 18584 | }; |
| 18449 | 18585 | |
| 18586 | +/* Allowed values for Parse.eParseMode |
| 18587 | +*/ |
| 18450 | 18588 | #define PARSE_MODE_NORMAL 0 |
| 18451 | 18589 | #define PARSE_MODE_DECLARE_VTAB 1 |
| 18452 | 18590 | #define PARSE_MODE_RENAME 2 |
| 18453 | 18591 | #define PARSE_MODE_UNMAP 3 |
| 18454 | 18592 | |
| | @@ -18666,12 +18804,14 @@ |
| 18666 | 18804 | } InitData; |
| 18667 | 18805 | |
| 18668 | 18806 | /* |
| 18669 | 18807 | ** Allowed values for mInitFlags |
| 18670 | 18808 | */ |
| 18809 | +#define INITFLAG_AlterMask 0x0003 /* Types of ALTER */ |
| 18671 | 18810 | #define INITFLAG_AlterRename 0x0001 /* Reparse after a RENAME */ |
| 18672 | 18811 | #define INITFLAG_AlterDrop 0x0002 /* Reparse after a DROP COLUMN */ |
| 18812 | +#define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */ |
| 18673 | 18813 | |
| 18674 | 18814 | /* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled |
| 18675 | 18815 | ** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning |
| 18676 | 18816 | ** parameters are for temporary use during development, to help find |
| 18677 | 18817 | ** optimial values for parameters in the query planner. The should not |
| | @@ -18788,12 +18928,12 @@ |
| 18788 | 18928 | union { /* Extra data for callback */ |
| 18789 | 18929 | NameContext *pNC; /* Naming context */ |
| 18790 | 18930 | int n; /* A counter */ |
| 18791 | 18931 | int iCur; /* A cursor number */ |
| 18792 | 18932 | SrcList *pSrcList; /* FROM clause */ |
| 18793 | | - struct SrcCount *pSrcCount; /* Counting column references */ |
| 18794 | 18933 | struct CCurHint *pCCurHint; /* Used by codeCursorHint() */ |
| 18934 | + struct RefSrcList *pRefSrcList; /* sqlite3ReferencesSrcList() */ |
| 18795 | 18935 | int *aiCol; /* array of column indexes */ |
| 18796 | 18936 | struct IdxCover *pIdxCover; /* Check for index coverage */ |
| 18797 | 18937 | struct IdxExprTrans *pIdxTrans; /* Convert idxed expr to column */ |
| 18798 | 18938 | ExprList *pGroupBy; /* GROUP BY clause */ |
| 18799 | 18939 | Select *pSelect; /* HAVING to WHERE clause ctx */ |
| | @@ -19387,10 +19527,11 @@ |
| 19387 | 19527 | SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int); |
| 19388 | 19528 | SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int); |
| 19389 | 19529 | #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) |
| 19390 | 19530 | SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,char*); |
| 19391 | 19531 | #endif |
| 19532 | +SQLITE_PRIVATE void sqlite3CodeChangeCount(Vdbe*,int,const char*); |
| 19392 | 19533 | SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*, ExprList*, Expr*); |
| 19393 | 19534 | SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*,Expr*,int,ExprList*,Expr*, |
| 19394 | 19535 | Upsert*); |
| 19395 | 19536 | SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int); |
| 19396 | 19537 | SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*); |
| | @@ -19430,10 +19571,11 @@ |
| 19430 | 19571 | SQLITE_PRIVATE void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int); |
| 19431 | 19572 | SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*); |
| 19432 | 19573 | #define LOCATE_VIEW 0x01 |
| 19433 | 19574 | #define LOCATE_NOERR 0x02 |
| 19434 | 19575 | SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,u32 flags,const char*, const char*); |
| 19576 | +SQLITE_PRIVATE const char *sqlite3PreferredTableName(const char*); |
| 19435 | 19577 | SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,u32 flags,SrcItem *); |
| 19436 | 19578 | SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*); |
| 19437 | 19579 | SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*); |
| 19438 | 19580 | SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*); |
| 19439 | 19581 | SQLITE_PRIVATE void sqlite3Vacuum(Parse*,Token*,Expr*); |
| | @@ -19446,11 +19588,11 @@ |
| 19446 | 19588 | SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int); |
| 19447 | 19589 | SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit(Walker*,Parse*); |
| 19448 | 19590 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); |
| 19449 | 19591 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 19450 | 19592 | SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx); |
| 19451 | | -SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); |
| 19593 | +SQLITE_PRIVATE int sqlite3ReferencesSrcList(Parse*, Expr*, SrcList*); |
| 19452 | 19594 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*); |
| 19453 | 19595 | #ifndef SQLITE_UNTESTABLE |
| 19454 | 19596 | SQLITE_PRIVATE void sqlite3PrngSaveState(void); |
| 19455 | 19597 | SQLITE_PRIVATE void sqlite3PrngRestoreState(void); |
| 19456 | 19598 | #endif |
| | @@ -19596,18 +19738,12 @@ |
| 19596 | 19738 | #endif |
| 19597 | 19739 | SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte); |
| 19598 | 19740 | SQLITE_PRIVATE u32 sqlite3Utf8Read(const u8**); |
| 19599 | 19741 | SQLITE_PRIVATE LogEst sqlite3LogEst(u64); |
| 19600 | 19742 | SQLITE_PRIVATE LogEst sqlite3LogEstAdd(LogEst,LogEst); |
| 19601 | | -#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 19602 | 19743 | SQLITE_PRIVATE LogEst sqlite3LogEstFromDouble(double); |
| 19603 | | -#endif |
| 19604 | | -#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || \ |
| 19605 | | - defined(SQLITE_ENABLE_STAT4) || \ |
| 19606 | | - defined(SQLITE_EXPLAIN_ESTIMATED_ROWS) |
| 19607 | 19744 | SQLITE_PRIVATE u64 sqlite3LogEstToInt(LogEst); |
| 19608 | | -#endif |
| 19609 | 19745 | SQLITE_PRIVATE VList *sqlite3VListAdd(sqlite3*,VList*,const char*,int,int); |
| 19610 | 19746 | SQLITE_PRIVATE const char *sqlite3VListNumToName(VList*,int); |
| 19611 | 19747 | SQLITE_PRIVATE int sqlite3VListNameToNum(VList*,const char*,int); |
| 19612 | 19748 | |
| 19613 | 19749 | /* |
| | @@ -19888,13 +20024,15 @@ |
| 19888 | 20024 | #endif |
| 19889 | 20025 | SQLITE_PRIVATE int sqlite3ReadOnlyShadowTables(sqlite3 *db); |
| 19890 | 20026 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 19891 | 20027 | SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName); |
| 19892 | 20028 | SQLITE_PRIVATE int sqlite3IsShadowTableOf(sqlite3*,Table*,const char*); |
| 20029 | +SQLITE_PRIVATE void sqlite3MarkAllShadowTablesOf(sqlite3*, Table*); |
| 19893 | 20030 | #else |
| 19894 | 20031 | # define sqlite3ShadowTableName(A,B) 0 |
| 19895 | 20032 | # define sqlite3IsShadowTableOf(A,B,C) 0 |
| 20033 | +# define sqlite3MarkAllShadowTablesOf(A,B) |
| 19896 | 20034 | #endif |
| 19897 | 20035 | SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*); |
| 19898 | 20036 | SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*); |
| 19899 | 20037 | SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*); |
| 19900 | 20038 | SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int); |
| | @@ -19933,11 +20071,11 @@ |
| 19933 | 20071 | #else |
| 19934 | 20072 | # define sqlite3CteNew(P,T,E,S) ((void*)0) |
| 19935 | 20073 | # define sqlite3CteDelete(D,C) |
| 19936 | 20074 | # define sqlite3CteWithAdd(P,W,C) ((void*)0) |
| 19937 | 20075 | # define sqlite3WithDelete(x,y) |
| 19938 | | -# define sqlite3WithPush(x,y,z) |
| 20076 | +# define sqlite3WithPush(x,y,z) ((void*)0) |
| 19939 | 20077 | #endif |
| 19940 | 20078 | #ifndef SQLITE_OMIT_UPSERT |
| 19941 | 20079 | SQLITE_PRIVATE Upsert *sqlite3UpsertNew(sqlite3*,ExprList*,Expr*,ExprList*,Expr*,Upsert*); |
| 19942 | 20080 | SQLITE_PRIVATE void sqlite3UpsertDelete(sqlite3*,Upsert*); |
| 19943 | 20081 | SQLITE_PRIVATE Upsert *sqlite3UpsertDup(sqlite3*,Upsert*); |
| | @@ -20101,12 +20239,12 @@ |
| 20101 | 20239 | ** All of this is no-op for a production build. It only comes into |
| 20102 | 20240 | ** play when the SQLITE_MEMDEBUG compile-time option is used. |
| 20103 | 20241 | */ |
| 20104 | 20242 | #ifdef SQLITE_MEMDEBUG |
| 20105 | 20243 | SQLITE_PRIVATE void sqlite3MemdebugSetType(void*,u8); |
| 20106 | | -SQLITE_PRIVATE int sqlite3MemdebugHasType(void*,u8); |
| 20107 | | -SQLITE_PRIVATE int sqlite3MemdebugNoType(void*,u8); |
| 20244 | +SQLITE_PRIVATE int sqlite3MemdebugHasType(const void*,u8); |
| 20245 | +SQLITE_PRIVATE int sqlite3MemdebugNoType(const void*,u8); |
| 20108 | 20246 | #else |
| 20109 | 20247 | # define sqlite3MemdebugSetType(X,Y) /* no-op */ |
| 20110 | 20248 | # define sqlite3MemdebugHasType(X,Y) 1 |
| 20111 | 20249 | # define sqlite3MemdebugNoType(X,Y) 1 |
| 20112 | 20250 | #endif |
| | @@ -21425,10 +21563,22 @@ |
| 21425 | 21563 | ** database connections. After initialization, this table is |
| 21426 | 21564 | ** read-only. |
| 21427 | 21565 | */ |
| 21428 | 21566 | SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions; |
| 21429 | 21567 | |
| 21568 | +#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG) |
| 21569 | +/* |
| 21570 | +** Counter used for coverage testing. Does not come into play for |
| 21571 | +** release builds. |
| 21572 | +** |
| 21573 | +** Access to this global variable is not mutex protected. This might |
| 21574 | +** result in TSAN warnings. But as the variable does not exist in |
| 21575 | +** release builds, that should not be a concern. |
| 21576 | +*/ |
| 21577 | +SQLITE_PRIVATE unsigned int sqlite3CoverageCounter; |
| 21578 | +#endif /* SQLITE_COVERAGE_TEST || SQLITE_DEBUG */ |
| 21579 | + |
| 21430 | 21580 | #ifdef VDBE_PROFILE |
| 21431 | 21581 | /* |
| 21432 | 21582 | ** The following performance counter can be used in place of |
| 21433 | 21583 | ** sqlite3Hwtime() for profiling. This is a no-op on standard builds. |
| 21434 | 21584 | */ |
| | @@ -21969,11 +22119,11 @@ |
| 21969 | 22119 | bft usesStmtJournal:1; /* True if uses a statement journal */ |
| 21970 | 22120 | bft readOnly:1; /* True for statements that do not write */ |
| 21971 | 22121 | bft bIsReader:1; /* True for statements that read */ |
| 21972 | 22122 | yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ |
| 21973 | 22123 | yDbMask lockMask; /* Subset of btreeMask that requires a lock */ |
| 21974 | | - u32 aCounter[7]; /* Counters used by sqlite3_stmt_status() */ |
| 22124 | + u32 aCounter[9]; /* Counters used by sqlite3_stmt_status() */ |
| 21975 | 22125 | char *zSql; /* Text of the SQL statement that generated this */ |
| 21976 | 22126 | #ifdef SQLITE_ENABLE_NORMALIZE |
| 21977 | 22127 | char *zNormSql; /* Normalization of the associated SQL statement */ |
| 21978 | 22128 | DblquoteStr *pDblStr; /* List of double-quoted string literals */ |
| 21979 | 22129 | #endif |
| | @@ -22065,19 +22215,23 @@ |
| 22065 | 22215 | SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem*, double); |
| 22066 | 22216 | #endif |
| 22067 | 22217 | SQLITE_PRIVATE void sqlite3VdbeMemSetPointer(Mem*, void*, const char*, void(*)(void*)); |
| 22068 | 22218 | SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem*,sqlite3*,u16); |
| 22069 | 22219 | SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem*); |
| 22220 | +#ifndef SQLITE_OMIT_INCRBLOB |
| 22070 | 22221 | SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem*,int); |
| 22222 | +#else |
| 22223 | +SQLITE_PRIVATE int sqlite3VdbeMemSetZeroBlob(Mem*,int); |
| 22224 | +#endif |
| 22071 | 22225 | #ifdef SQLITE_DEBUG |
| 22072 | 22226 | SQLITE_PRIVATE int sqlite3VdbeMemIsRowSet(const Mem*); |
| 22073 | 22227 | #endif |
| 22074 | 22228 | SQLITE_PRIVATE int sqlite3VdbeMemSetRowSet(Mem*); |
| 22075 | 22229 | SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*); |
| 22076 | 22230 | SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, u8, u8); |
| 22077 | 22231 | SQLITE_PRIVATE int sqlite3IntFloatCompare(i64,double); |
| 22078 | | -SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem*); |
| 22232 | +SQLITE_PRIVATE i64 sqlite3VdbeIntValue(const Mem*); |
| 22079 | 22233 | SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*); |
| 22080 | 22234 | SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*); |
| 22081 | 22235 | SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem*, int ifNull); |
| 22082 | 22236 | SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*); |
| 22083 | 22237 | SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*); |
| | @@ -23071,11 +23225,13 @@ |
| 23071 | 23225 | pX = localtime(t); |
| 23072 | 23226 | #ifndef SQLITE_UNTESTABLE |
| 23073 | 23227 | if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0; |
| 23074 | 23228 | #endif |
| 23075 | 23229 | if( pX ) *pTm = *pX; |
| 23230 | +#if SQLITE_THREADSAFE>0 |
| 23076 | 23231 | sqlite3_mutex_leave(mutex); |
| 23232 | +#endif |
| 23077 | 23233 | rc = pX==0; |
| 23078 | 23234 | #else |
| 23079 | 23235 | #ifndef SQLITE_UNTESTABLE |
| 23080 | 23236 | if( sqlite3GlobalConfig.bLocaltimeFault ) return 1; |
| 23081 | 23237 | #endif |
| | @@ -23210,10 +23366,49 @@ |
| 23210 | 23366 | DateTime *p /* The date/time value to be modified */ |
| 23211 | 23367 | ){ |
| 23212 | 23368 | int rc = 1; |
| 23213 | 23369 | double r; |
| 23214 | 23370 | switch(sqlite3UpperToLower[(u8)z[0]] ){ |
| 23371 | + case 'a': { |
| 23372 | + /* |
| 23373 | + ** auto |
| 23374 | + ** |
| 23375 | + ** If rawS is available, then interpret as a julian day number, or |
| 23376 | + ** a unix timestamp, depending on its magnitude. |
| 23377 | + */ |
| 23378 | + if( sqlite3_stricmp(z, "auto")==0 ){ |
| 23379 | + if( !p->rawS || p->validJD ){ |
| 23380 | + rc = 0; |
| 23381 | + p->rawS = 0; |
| 23382 | + }else if( p->s>=-210866760000 && p->s<=253402300799 ){ |
| 23383 | + r = p->s*1000.0 + 210866760000000.0; |
| 23384 | + clearYMD_HMS_TZ(p); |
| 23385 | + p->iJD = (sqlite3_int64)(r + 0.5); |
| 23386 | + p->validJD = 1; |
| 23387 | + p->rawS = 0; |
| 23388 | + rc = 0; |
| 23389 | + } |
| 23390 | + } |
| 23391 | + break; |
| 23392 | + } |
| 23393 | + case 'j': { |
| 23394 | + /* |
| 23395 | + ** julianday |
| 23396 | + ** |
| 23397 | + ** Always interpret the prior number as a julian-day value. If this |
| 23398 | + ** is not the first modifier, or if the prior argument is not a numeric |
| 23399 | + ** value in the allowed range of julian day numbers understood by |
| 23400 | + ** SQLite (0..5373484.5) then the result will be NULL. |
| 23401 | + */ |
| 23402 | + if( sqlite3_stricmp(z, "julianday")==0 ){ |
| 23403 | + if( p->validJD && p->rawS ){ |
| 23404 | + rc = 0; |
| 23405 | + p->rawS = 0; |
| 23406 | + } |
| 23407 | + } |
| 23408 | + break; |
| 23409 | + } |
| 23215 | 23410 | #ifndef SQLITE_OMIT_LOCALTIME |
| 23216 | 23411 | case 'l': { |
| 23217 | 23412 | /* localtime |
| 23218 | 23413 | ** |
| 23219 | 23414 | ** Assuming the current time value is UTC (a.k.a. GMT), shift it to |
| | @@ -23473,10 +23668,28 @@ |
| 23473 | 23668 | if( isDate(context, argc, argv, &x)==0 ){ |
| 23474 | 23669 | computeJD(&x); |
| 23475 | 23670 | sqlite3_result_double(context, x.iJD/86400000.0); |
| 23476 | 23671 | } |
| 23477 | 23672 | } |
| 23673 | + |
| 23674 | +/* |
| 23675 | +** unixepoch( TIMESTRING, MOD, MOD, ...) |
| 23676 | +** |
| 23677 | +** Return the number of seconds (including fractional seconds) since |
| 23678 | +** the unix epoch of 1970-01-01 00:00:00 GMT. |
| 23679 | +*/ |
| 23680 | +static void unixepochFunc( |
| 23681 | + sqlite3_context *context, |
| 23682 | + int argc, |
| 23683 | + sqlite3_value **argv |
| 23684 | +){ |
| 23685 | + DateTime x; |
| 23686 | + if( isDate(context, argc, argv, &x)==0 ){ |
| 23687 | + computeJD(&x); |
| 23688 | + sqlite3_result_int64(context, x.iJD/1000 - 21086676*(i64)10000); |
| 23689 | + } |
| 23690 | +} |
| 23478 | 23691 | |
| 23479 | 23692 | /* |
| 23480 | 23693 | ** datetime( TIMESTRING, MOD, MOD, ...) |
| 23481 | 23694 | ** |
| 23482 | 23695 | ** Return YYYY-MM-DD HH:MM:SS |
| | @@ -23573,11 +23786,11 @@ |
| 23573 | 23786 | |
| 23574 | 23787 | computeJD(&x); |
| 23575 | 23788 | computeYMD_HMS(&x); |
| 23576 | 23789 | for(i=j=0; zFmt[i]; i++){ |
| 23577 | 23790 | if( zFmt[i]!='%' ) continue; |
| 23578 | | - if( j<i ) sqlite3_str_append(&sRes, zFmt+j, i-j); |
| 23791 | + if( j<i ) sqlite3_str_append(&sRes, zFmt+j, (int)(i-j)); |
| 23579 | 23792 | i++; |
| 23580 | 23793 | j = i + 1; |
| 23581 | 23794 | switch( zFmt[i] ){ |
| 23582 | 23795 | case 'd': { |
| 23583 | 23796 | sqlite3_str_appendf(&sRes, "%02d", x.D); |
| | @@ -23649,11 +23862,11 @@ |
| 23649 | 23862 | sqlite3_str_reset(&sRes); |
| 23650 | 23863 | return; |
| 23651 | 23864 | } |
| 23652 | 23865 | } |
| 23653 | 23866 | } |
| 23654 | | - if( j<i ) sqlite3_str_append(&sRes, zFmt+j, i-j); |
| 23867 | + if( j<i ) sqlite3_str_append(&sRes, zFmt+j, (int)(i-j)); |
| 23655 | 23868 | sqlite3ResultStrAccum(context, &sRes); |
| 23656 | 23869 | } |
| 23657 | 23870 | |
| 23658 | 23871 | /* |
| 23659 | 23872 | ** current_time() |
| | @@ -23750,10 +23963,11 @@ |
| 23750 | 23963 | */ |
| 23751 | 23964 | SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void){ |
| 23752 | 23965 | static FuncDef aDateTimeFuncs[] = { |
| 23753 | 23966 | #ifndef SQLITE_OMIT_DATETIME_FUNCS |
| 23754 | 23967 | PURE_DATE(julianday, -1, 0, 0, juliandayFunc ), |
| 23968 | + PURE_DATE(unixepoch, -1, 0, 0, unixepochFunc ), |
| 23755 | 23969 | PURE_DATE(date, -1, 0, 0, dateFunc ), |
| 23756 | 23970 | PURE_DATE(time, -1, 0, 0, timeFunc ), |
| 23757 | 23971 | PURE_DATE(datetime, -1, 0, 0, datetimeFunc ), |
| 23758 | 23972 | PURE_DATE(strftime, -1, 0, 0, strftimeFunc ), |
| 23759 | 23973 | DFUNCTION(current_time, 0, 0, 0, ctimeFunc ), |
| | @@ -24086,16 +24300,19 @@ |
| 24086 | 24300 | pFile = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile); |
| 24087 | 24301 | if( pFile ){ |
| 24088 | 24302 | rc = sqlite3OsOpen(pVfs, zFile, pFile, flags, pOutFlags); |
| 24089 | 24303 | if( rc!=SQLITE_OK ){ |
| 24090 | 24304 | sqlite3_free(pFile); |
| 24305 | + *ppFile = 0; |
| 24091 | 24306 | }else{ |
| 24092 | 24307 | *ppFile = pFile; |
| 24093 | 24308 | } |
| 24094 | 24309 | }else{ |
| 24310 | + *ppFile = 0; |
| 24095 | 24311 | rc = SQLITE_NOMEM_BKPT; |
| 24096 | 24312 | } |
| 24313 | + assert( *ppFile!=0 || rc!=SQLITE_OK ); |
| 24097 | 24314 | return rc; |
| 24098 | 24315 | } |
| 24099 | 24316 | SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *pFile){ |
| 24100 | 24317 | assert( pFile ); |
| 24101 | 24318 | sqlite3OsClose(pFile); |
| | @@ -24809,11 +25026,11 @@ |
| 24809 | 25026 | ** Given an allocation, find the MemBlockHdr for that allocation. |
| 24810 | 25027 | ** |
| 24811 | 25028 | ** This routine checks the guards at either end of the allocation and |
| 24812 | 25029 | ** if they are incorrect it asserts. |
| 24813 | 25030 | */ |
| 24814 | | -static struct MemBlockHdr *sqlite3MemsysGetHeader(void *pAllocation){ |
| 25031 | +static struct MemBlockHdr *sqlite3MemsysGetHeader(const void *pAllocation){ |
| 24815 | 25032 | struct MemBlockHdr *p; |
| 24816 | 25033 | int *pInt; |
| 24817 | 25034 | u8 *pU8; |
| 24818 | 25035 | int nReserve; |
| 24819 | 25036 | |
| | @@ -25056,11 +25273,11 @@ |
| 25056 | 25273 | ** This routine is designed for use within an assert() statement, to |
| 25057 | 25274 | ** verify the type of an allocation. For example: |
| 25058 | 25275 | ** |
| 25059 | 25276 | ** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); |
| 25060 | 25277 | */ |
| 25061 | | -SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){ |
| 25278 | +SQLITE_PRIVATE int sqlite3MemdebugHasType(const void *p, u8 eType){ |
| 25062 | 25279 | int rc = 1; |
| 25063 | 25280 | if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){ |
| 25064 | 25281 | struct MemBlockHdr *pHdr; |
| 25065 | 25282 | pHdr = sqlite3MemsysGetHeader(p); |
| 25066 | 25283 | assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */ |
| | @@ -25078,11 +25295,11 @@ |
| 25078 | 25295 | ** This routine is designed for use within an assert() statement, to |
| 25079 | 25296 | ** verify the type of an allocation. For example: |
| 25080 | 25297 | ** |
| 25081 | 25298 | ** assert( sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) ); |
| 25082 | 25299 | */ |
| 25083 | | -SQLITE_PRIVATE int sqlite3MemdebugNoType(void *p, u8 eType){ |
| 25300 | +SQLITE_PRIVATE int sqlite3MemdebugNoType(const void *p, u8 eType){ |
| 25084 | 25301 | int rc = 1; |
| 25085 | 25302 | if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){ |
| 25086 | 25303 | struct MemBlockHdr *pHdr; |
| 25087 | 25304 | pHdr = sqlite3MemsysGetHeader(p); |
| 25088 | 25305 | assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */ |
| | @@ -30543,10 +30760,11 @@ |
| 30543 | 30760 | zOp2[0] = 0; |
| 30544 | 30761 | } |
| 30545 | 30762 | sqlite3TreeViewLine(pView, "COLUMN(%d)%s%s", |
| 30546 | 30763 | pExpr->iColumn, zFlgs, zOp2); |
| 30547 | 30764 | }else{ |
| 30765 | + assert( ExprUseYTab(pExpr) ); |
| 30548 | 30766 | sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s", |
| 30549 | 30767 | pExpr->iTable, pExpr->iColumn, |
| 30550 | 30768 | pExpr->y.pTab, zFlgs); |
| 30551 | 30769 | } |
| 30552 | 30770 | if( ExprHasProperty(pExpr, EP_FixedCol) ){ |
| | @@ -30562,15 +30780,17 @@ |
| 30562 | 30780 | } |
| 30563 | 30781 | break; |
| 30564 | 30782 | } |
| 30565 | 30783 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 30566 | 30784 | case TK_FLOAT: { |
| 30785 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30567 | 30786 | sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); |
| 30568 | 30787 | break; |
| 30569 | 30788 | } |
| 30570 | 30789 | #endif |
| 30571 | 30790 | case TK_STRING: { |
| 30791 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30572 | 30792 | sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken); |
| 30573 | 30793 | break; |
| 30574 | 30794 | } |
| 30575 | 30795 | case TK_NULL: { |
| 30576 | 30796 | sqlite3TreeViewLine(pView,"NULL"); |
| | @@ -30581,30 +30801,34 @@ |
| 30581 | 30801 | sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs); |
| 30582 | 30802 | break; |
| 30583 | 30803 | } |
| 30584 | 30804 | #ifndef SQLITE_OMIT_BLOB_LITERAL |
| 30585 | 30805 | case TK_BLOB: { |
| 30806 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30586 | 30807 | sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); |
| 30587 | 30808 | break; |
| 30588 | 30809 | } |
| 30589 | 30810 | #endif |
| 30590 | 30811 | case TK_VARIABLE: { |
| 30812 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30591 | 30813 | sqlite3TreeViewLine(pView,"VARIABLE(%s,%d)", |
| 30592 | 30814 | pExpr->u.zToken, pExpr->iColumn); |
| 30593 | 30815 | break; |
| 30594 | 30816 | } |
| 30595 | 30817 | case TK_REGISTER: { |
| 30596 | 30818 | sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable); |
| 30597 | 30819 | break; |
| 30598 | 30820 | } |
| 30599 | 30821 | case TK_ID: { |
| 30822 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30600 | 30823 | sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken); |
| 30601 | 30824 | break; |
| 30602 | 30825 | } |
| 30603 | 30826 | #ifndef SQLITE_OMIT_CAST |
| 30604 | 30827 | case TK_CAST: { |
| 30605 | 30828 | /* Expressions of the form: CAST(pLeft AS token) */ |
| 30829 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30606 | 30830 | sqlite3TreeViewLine(pView,"CAST %Q", pExpr->u.zToken); |
| 30607 | 30831 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 30608 | 30832 | break; |
| 30609 | 30833 | } |
| 30610 | 30834 | #endif /* SQLITE_OMIT_CAST */ |
| | @@ -30650,10 +30874,11 @@ |
| 30650 | 30874 | zUniOp = azOp[x]; |
| 30651 | 30875 | break; |
| 30652 | 30876 | } |
| 30653 | 30877 | |
| 30654 | 30878 | case TK_SPAN: { |
| 30879 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30655 | 30880 | sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken); |
| 30656 | 30881 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 30657 | 30882 | break; |
| 30658 | 30883 | } |
| 30659 | 30884 | |
| | @@ -30661,10 +30886,11 @@ |
| 30661 | 30886 | /* COLLATE operators without the EP_Collate flag are intended to |
| 30662 | 30887 | ** emulate collation associated with a table column. These show |
| 30663 | 30888 | ** up in the treeview output as "SOFT-COLLATE". Explicit COLLATE |
| 30664 | 30889 | ** operators that appear in the original SQL always have the |
| 30665 | 30890 | ** EP_Collate bit set and appear in treeview output as just "COLLATE" */ |
| 30891 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30666 | 30892 | sqlite3TreeViewLine(pView, "%sCOLLATE %Q%s", |
| 30667 | 30893 | !ExprHasProperty(pExpr, EP_Collate) ? "SOFT-" : "", |
| 30668 | 30894 | pExpr->u.zToken, zFlgs); |
| 30669 | 30895 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 30670 | 30896 | break; |
| | @@ -30676,17 +30902,19 @@ |
| 30676 | 30902 | Window *pWin; |
| 30677 | 30903 | if( ExprHasProperty(pExpr, EP_TokenOnly) ){ |
| 30678 | 30904 | pFarg = 0; |
| 30679 | 30905 | pWin = 0; |
| 30680 | 30906 | }else{ |
| 30907 | + assert( ExprUseXList(pExpr) ); |
| 30681 | 30908 | pFarg = pExpr->x.pList; |
| 30682 | 30909 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 30683 | 30910 | pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0; |
| 30684 | 30911 | #else |
| 30685 | 30912 | pWin = 0; |
| 30686 | 30913 | #endif |
| 30687 | 30914 | } |
| 30915 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30688 | 30916 | if( pExpr->op==TK_AGG_FUNCTION ){ |
| 30689 | 30917 | sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p", |
| 30690 | 30918 | pExpr->op2, pExpr->u.zToken, zFlgs, |
| 30691 | 30919 | pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0, |
| 30692 | 30920 | pExpr->iAgg, pExpr->pAggInfo); |
| | @@ -30714,23 +30942,25 @@ |
| 30714 | 30942 | #endif |
| 30715 | 30943 | break; |
| 30716 | 30944 | } |
| 30717 | 30945 | #ifndef SQLITE_OMIT_SUBQUERY |
| 30718 | 30946 | case TK_EXISTS: { |
| 30947 | + assert( ExprUseXSelect(pExpr) ); |
| 30719 | 30948 | sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags); |
| 30720 | 30949 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 30721 | 30950 | break; |
| 30722 | 30951 | } |
| 30723 | 30952 | case TK_SELECT: { |
| 30953 | + assert( ExprUseXSelect(pExpr) ); |
| 30724 | 30954 | sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags); |
| 30725 | 30955 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 30726 | 30956 | break; |
| 30727 | 30957 | } |
| 30728 | 30958 | case TK_IN: { |
| 30729 | 30959 | sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags); |
| 30730 | 30960 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); |
| 30731 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 30961 | + if( ExprUseXSelect(pExpr) ){ |
| 30732 | 30962 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 30733 | 30963 | }else{ |
| 30734 | 30964 | sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); |
| 30735 | 30965 | } |
| 30736 | 30966 | break; |
| | @@ -30747,13 +30977,16 @@ |
| 30747 | 30977 | ** X is stored in pExpr->pLeft. |
| 30748 | 30978 | ** Y is stored in pExpr->pList->a[0].pExpr. |
| 30749 | 30979 | ** Z is stored in pExpr->pList->a[1].pExpr. |
| 30750 | 30980 | */ |
| 30751 | 30981 | case TK_BETWEEN: { |
| 30752 | | - Expr *pX = pExpr->pLeft; |
| 30753 | | - Expr *pY = pExpr->x.pList->a[0].pExpr; |
| 30754 | | - Expr *pZ = pExpr->x.pList->a[1].pExpr; |
| 30982 | + const Expr *pX, *pY, *pZ; |
| 30983 | + pX = pExpr->pLeft; |
| 30984 | + assert( ExprUseXList(pExpr) ); |
| 30985 | + assert( pExpr->x.pList->nExpr==2 ); |
| 30986 | + pY = pExpr->x.pList->a[0].pExpr; |
| 30987 | + pZ = pExpr->x.pList->a[1].pExpr; |
| 30755 | 30988 | sqlite3TreeViewLine(pView, "BETWEEN"); |
| 30756 | 30989 | sqlite3TreeViewExpr(pView, pX, 1); |
| 30757 | 30990 | sqlite3TreeViewExpr(pView, pY, 1); |
| 30758 | 30991 | sqlite3TreeViewExpr(pView, pZ, 0); |
| 30759 | 30992 | break; |
| | @@ -30771,10 +31004,11 @@ |
| 30771 | 31004 | break; |
| 30772 | 31005 | } |
| 30773 | 31006 | case TK_CASE: { |
| 30774 | 31007 | sqlite3TreeViewLine(pView, "CASE"); |
| 30775 | 31008 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); |
| 31009 | + assert( ExprUseXList(pExpr) ); |
| 30776 | 31010 | sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); |
| 30777 | 31011 | break; |
| 30778 | 31012 | } |
| 30779 | 31013 | #ifndef SQLITE_OMIT_TRIGGER |
| 30780 | 31014 | case TK_RAISE: { |
| | @@ -30783,10 +31017,11 @@ |
| 30783 | 31017 | case OE_Rollback: zType = "rollback"; break; |
| 30784 | 31018 | case OE_Abort: zType = "abort"; break; |
| 30785 | 31019 | case OE_Fail: zType = "fail"; break; |
| 30786 | 31020 | case OE_Ignore: zType = "ignore"; break; |
| 30787 | 31021 | } |
| 31022 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30788 | 31023 | sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken); |
| 30789 | 31024 | break; |
| 30790 | 31025 | } |
| 30791 | 31026 | #endif |
| 30792 | 31027 | case TK_MATCH: { |
| | @@ -30795,18 +31030,20 @@ |
| 30795 | 31030 | sqlite3TreeViewExpr(pView, pExpr->pRight, 0); |
| 30796 | 31031 | break; |
| 30797 | 31032 | } |
| 30798 | 31033 | case TK_VECTOR: { |
| 30799 | 31034 | char *z = sqlite3_mprintf("VECTOR%s",zFlgs); |
| 31035 | + assert( ExprUseXList(pExpr) ); |
| 30800 | 31036 | sqlite3TreeViewBareExprList(pView, pExpr->x.pList, z); |
| 30801 | 31037 | sqlite3_free(z); |
| 30802 | 31038 | break; |
| 30803 | 31039 | } |
| 30804 | 31040 | case TK_SELECT_COLUMN: { |
| 30805 | 31041 | sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s", |
| 30806 | 31042 | pExpr->iColumn, pExpr->iTable-1, |
| 30807 | 31043 | pExpr->pRight==pExpr->pLeft ? " (SELECT-owner)" : ""); |
| 31044 | + assert( ExprUseXSelect(pExpr->pLeft) ); |
| 30808 | 31045 | sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0); |
| 30809 | 31046 | break; |
| 30810 | 31047 | } |
| 30811 | 31048 | case TK_IF_NULL_ROW: { |
| 30812 | 31049 | sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable); |
| | @@ -31879,20 +32116,10 @@ |
| 31879 | 32116 | /* #include <stdarg.h> */ |
| 31880 | 32117 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 31881 | 32118 | #include <math.h> |
| 31882 | 32119 | #endif |
| 31883 | 32120 | |
| 31884 | | -/* |
| 31885 | | -** Routine needed to support the testcase() macro. |
| 31886 | | -*/ |
| 31887 | | -#ifdef SQLITE_COVERAGE_TEST |
| 31888 | | -SQLITE_PRIVATE void sqlite3Coverage(int x){ |
| 31889 | | - static unsigned dummy = 0; |
| 31890 | | - dummy += (unsigned)x; |
| 31891 | | -} |
| 31892 | | -#endif |
| 31893 | | - |
| 31894 | 32121 | /* |
| 31895 | 32122 | ** Calls to sqlite3FaultSim() are used to simulate a failure during testing, |
| 31896 | 32123 | ** or to bypass normal error detection during testing in order to let |
| 31897 | 32124 | ** execute proceed futher downstream. |
| 31898 | 32125 | ** |
| | @@ -32135,10 +32362,11 @@ |
| 32135 | 32362 | } |
| 32136 | 32363 | } |
| 32137 | 32364 | z[j] = 0; |
| 32138 | 32365 | } |
| 32139 | 32366 | SQLITE_PRIVATE void sqlite3DequoteExpr(Expr *p){ |
| 32367 | + assert( !ExprHasProperty(p, EP_IntValue) ); |
| 32140 | 32368 | assert( sqlite3Isquote(p->u.zToken[0]) ); |
| 32141 | 32369 | p->flags |= p->u.zToken[0]=='"' ? EP_Quoted|EP_DblQuoted : EP_Quoted; |
| 32142 | 32370 | sqlite3Dequote(p->u.zToken); |
| 32143 | 32371 | } |
| 32144 | 32372 | |
| | @@ -33453,11 +33681,10 @@ |
| 33453 | 33681 | #endif |
| 33454 | 33682 | } |
| 33455 | 33683 | return a[x&7] + y - 10; |
| 33456 | 33684 | } |
| 33457 | 33685 | |
| 33458 | | -#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 33459 | 33686 | /* |
| 33460 | 33687 | ** Convert a double into a LogEst |
| 33461 | 33688 | ** In other words, compute an approximation for 10*log2(x). |
| 33462 | 33689 | */ |
| 33463 | 33690 | SQLITE_PRIVATE LogEst sqlite3LogEstFromDouble(double x){ |
| | @@ -33468,38 +33695,23 @@ |
| 33468 | 33695 | if( x<=2000000000 ) return sqlite3LogEst((u64)x); |
| 33469 | 33696 | memcpy(&a, &x, 8); |
| 33470 | 33697 | e = (a>>52) - 1022; |
| 33471 | 33698 | return e*10; |
| 33472 | 33699 | } |
| 33473 | | -#endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 33474 | 33700 | |
| 33475 | | -#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || \ |
| 33476 | | - defined(SQLITE_ENABLE_STAT4) || \ |
| 33477 | | - defined(SQLITE_EXPLAIN_ESTIMATED_ROWS) |
| 33478 | 33701 | /* |
| 33479 | 33702 | ** Convert a LogEst into an integer. |
| 33480 | | -** |
| 33481 | | -** Note that this routine is only used when one or more of various |
| 33482 | | -** non-standard compile-time options is enabled. |
| 33483 | 33703 | */ |
| 33484 | 33704 | SQLITE_PRIVATE u64 sqlite3LogEstToInt(LogEst x){ |
| 33485 | 33705 | u64 n; |
| 33486 | 33706 | n = x%10; |
| 33487 | 33707 | x /= 10; |
| 33488 | 33708 | if( n>=5 ) n -= 2; |
| 33489 | 33709 | else if( n>=1 ) n -= 1; |
| 33490 | | -#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || \ |
| 33491 | | - defined(SQLITE_EXPLAIN_ESTIMATED_ROWS) |
| 33492 | 33710 | if( x>60 ) return (u64)LARGEST_INT64; |
| 33493 | | -#else |
| 33494 | | - /* If only SQLITE_ENABLE_STAT4 is on, then the largest input |
| 33495 | | - ** possible to this routine is 310, resulting in a maximum x of 31 */ |
| 33496 | | - assert( x<=60 ); |
| 33497 | | -#endif |
| 33498 | 33711 | return x>=3 ? (n+8)<<(x-3) : (n+8)>>(3-x); |
| 33499 | 33712 | } |
| 33500 | | -#endif /* defined SCANSTAT or STAT4 or ESTIMATED_ROWS */ |
| 33501 | 33713 | |
| 33502 | 33714 | /* |
| 33503 | 33715 | ** Add a new name/number pair to a VList. This might require that the |
| 33504 | 33716 | ** VList object be reallocated, so return the new VList. If an OOM |
| 33505 | 33717 | ** error occurs, the original VList returned and the |
| | @@ -33949,49 +34161,49 @@ |
| 33949 | 34161 | /* 58 */ "ElseEq" OpHelp(""), |
| 33950 | 34162 | /* 59 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"), |
| 33951 | 34163 | /* 60 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), |
| 33952 | 34164 | /* 61 */ "IncrVacuum" OpHelp(""), |
| 33953 | 34165 | /* 62 */ "VNext" OpHelp(""), |
| 33954 | | - /* 63 */ "Init" OpHelp("Start at P2"), |
| 33955 | | - /* 64 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"), |
| 33956 | | - /* 65 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"), |
| 33957 | | - /* 66 */ "Return" OpHelp(""), |
| 33958 | | - /* 67 */ "EndCoroutine" OpHelp(""), |
| 33959 | | - /* 68 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), |
| 33960 | | - /* 69 */ "Halt" OpHelp(""), |
| 33961 | | - /* 70 */ "Integer" OpHelp("r[P2]=P1"), |
| 33962 | | - /* 71 */ "Int64" OpHelp("r[P2]=P4"), |
| 33963 | | - /* 72 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 33964 | | - /* 73 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 33965 | | - /* 74 */ "SoftNull" OpHelp("r[P1]=NULL"), |
| 33966 | | - /* 75 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 33967 | | - /* 76 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 33968 | | - /* 77 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 33969 | | - /* 78 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), |
| 33970 | | - /* 79 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 33971 | | - /* 80 */ "IntCopy" OpHelp("r[P2]=r[P1]"), |
| 33972 | | - /* 81 */ "ChngCntRow" OpHelp("output=r[P1]"), |
| 33973 | | - /* 82 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 33974 | | - /* 83 */ "CollSeq" OpHelp(""), |
| 33975 | | - /* 84 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 33976 | | - /* 85 */ "RealAffinity" OpHelp(""), |
| 33977 | | - /* 86 */ "Cast" OpHelp("affinity(r[P1])"), |
| 33978 | | - /* 87 */ "Permutation" OpHelp(""), |
| 33979 | | - /* 88 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), |
| 33980 | | - /* 89 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"), |
| 33981 | | - /* 90 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"), |
| 33982 | | - /* 91 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"), |
| 33983 | | - /* 92 */ "Column" OpHelp("r[P3]=PX"), |
| 33984 | | - /* 93 */ "TypeCheck" OpHelp("typecheck(r[P1@P2])"), |
| 33985 | | - /* 94 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 33986 | | - /* 95 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 33987 | | - /* 96 */ "Count" OpHelp("r[P2]=count()"), |
| 33988 | | - /* 97 */ "ReadCookie" OpHelp(""), |
| 33989 | | - /* 98 */ "SetCookie" OpHelp(""), |
| 33990 | | - /* 99 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), |
| 33991 | | - /* 100 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 33992 | | - /* 101 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 34166 | + /* 63 */ "Filter" OpHelp("if key(P3@P4) not in filter(P1) goto P2"), |
| 34167 | + /* 64 */ "Init" OpHelp("Start at P2"), |
| 34168 | + /* 65 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"), |
| 34169 | + /* 66 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"), |
| 34170 | + /* 67 */ "Return" OpHelp(""), |
| 34171 | + /* 68 */ "EndCoroutine" OpHelp(""), |
| 34172 | + /* 69 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), |
| 34173 | + /* 70 */ "Halt" OpHelp(""), |
| 34174 | + /* 71 */ "Integer" OpHelp("r[P2]=P1"), |
| 34175 | + /* 72 */ "Int64" OpHelp("r[P2]=P4"), |
| 34176 | + /* 73 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 34177 | + /* 74 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 34178 | + /* 75 */ "SoftNull" OpHelp("r[P1]=NULL"), |
| 34179 | + /* 76 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 34180 | + /* 77 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 34181 | + /* 78 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 34182 | + /* 79 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), |
| 34183 | + /* 80 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 34184 | + /* 81 */ "IntCopy" OpHelp("r[P2]=r[P1]"), |
| 34185 | + /* 82 */ "FkCheck" OpHelp(""), |
| 34186 | + /* 83 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 34187 | + /* 84 */ "CollSeq" OpHelp(""), |
| 34188 | + /* 85 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 34189 | + /* 86 */ "RealAffinity" OpHelp(""), |
| 34190 | + /* 87 */ "Cast" OpHelp("affinity(r[P1])"), |
| 34191 | + /* 88 */ "Permutation" OpHelp(""), |
| 34192 | + /* 89 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), |
| 34193 | + /* 90 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"), |
| 34194 | + /* 91 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"), |
| 34195 | + /* 92 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"), |
| 34196 | + /* 93 */ "Column" OpHelp("r[P3]=PX"), |
| 34197 | + /* 94 */ "TypeCheck" OpHelp("typecheck(r[P1@P2])"), |
| 34198 | + /* 95 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 34199 | + /* 96 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 34200 | + /* 97 */ "Count" OpHelp("r[P2]=count()"), |
| 34201 | + /* 98 */ "ReadCookie" OpHelp(""), |
| 34202 | + /* 99 */ "SetCookie" OpHelp(""), |
| 34203 | + /* 100 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), |
| 34204 | + /* 101 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 33993 | 34205 | /* 102 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"), |
| 33994 | 34206 | /* 103 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"), |
| 33995 | 34207 | /* 104 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"), |
| 33996 | 34208 | /* 105 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"), |
| 33997 | 34209 | /* 106 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"), |
| | @@ -33998,80 +34210,82 @@ |
| 33998 | 34210 | /* 107 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"), |
| 33999 | 34211 | /* 108 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"), |
| 34000 | 34212 | /* 109 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"), |
| 34001 | 34213 | /* 110 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"), |
| 34002 | 34214 | /* 111 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"), |
| 34003 | | - /* 112 */ "OpenDup" OpHelp(""), |
| 34215 | + /* 112 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 34004 | 34216 | /* 113 */ "BitNot" OpHelp("r[P2]= ~r[P1]"), |
| 34005 | | - /* 114 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 34006 | | - /* 115 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 34217 | + /* 114 */ "OpenDup" OpHelp(""), |
| 34218 | + /* 115 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 34007 | 34219 | /* 116 */ "String8" OpHelp("r[P2]='P4'"), |
| 34008 | | - /* 117 */ "SorterOpen" OpHelp(""), |
| 34009 | | - /* 118 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), |
| 34010 | | - /* 119 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), |
| 34011 | | - /* 120 */ "Close" OpHelp(""), |
| 34012 | | - /* 121 */ "ColumnsUsed" OpHelp(""), |
| 34013 | | - /* 122 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"), |
| 34014 | | - /* 123 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"), |
| 34015 | | - /* 124 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), |
| 34016 | | - /* 125 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 34017 | | - /* 126 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 34018 | | - /* 127 */ "RowCell" OpHelp(""), |
| 34019 | | - /* 128 */ "Delete" OpHelp(""), |
| 34020 | | - /* 129 */ "ResetCount" OpHelp(""), |
| 34021 | | - /* 130 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), |
| 34022 | | - /* 131 */ "SorterData" OpHelp("r[P2]=data"), |
| 34023 | | - /* 132 */ "RowData" OpHelp("r[P2]=data"), |
| 34024 | | - /* 133 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 34025 | | - /* 134 */ "NullRow" OpHelp(""), |
| 34026 | | - /* 135 */ "SeekEnd" OpHelp(""), |
| 34027 | | - /* 136 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 34028 | | - /* 137 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 34029 | | - /* 138 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 34030 | | - /* 139 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), |
| 34031 | | - /* 140 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 34032 | | - /* 141 */ "FinishSeek" OpHelp(""), |
| 34033 | | - /* 142 */ "Destroy" OpHelp(""), |
| 34034 | | - /* 143 */ "Clear" OpHelp(""), |
| 34035 | | - /* 144 */ "ResetSorter" OpHelp(""), |
| 34036 | | - /* 145 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"), |
| 34037 | | - /* 146 */ "SqlExec" OpHelp(""), |
| 34038 | | - /* 147 */ "ParseSchema" OpHelp(""), |
| 34039 | | - /* 148 */ "LoadAnalysis" OpHelp(""), |
| 34040 | | - /* 149 */ "DropTable" OpHelp(""), |
| 34041 | | - /* 150 */ "DropIndex" OpHelp(""), |
| 34042 | | - /* 151 */ "DropTrigger" OpHelp(""), |
| 34220 | + /* 117 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 34221 | + /* 118 */ "SorterOpen" OpHelp(""), |
| 34222 | + /* 119 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), |
| 34223 | + /* 120 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), |
| 34224 | + /* 121 */ "Close" OpHelp(""), |
| 34225 | + /* 122 */ "ColumnsUsed" OpHelp(""), |
| 34226 | + /* 123 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"), |
| 34227 | + /* 124 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"), |
| 34228 | + /* 125 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), |
| 34229 | + /* 126 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 34230 | + /* 127 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 34231 | + /* 128 */ "RowCell" OpHelp(""), |
| 34232 | + /* 129 */ "Delete" OpHelp(""), |
| 34233 | + /* 130 */ "ResetCount" OpHelp(""), |
| 34234 | + /* 131 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), |
| 34235 | + /* 132 */ "SorterData" OpHelp("r[P2]=data"), |
| 34236 | + /* 133 */ "RowData" OpHelp("r[P2]=data"), |
| 34237 | + /* 134 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 34238 | + /* 135 */ "NullRow" OpHelp(""), |
| 34239 | + /* 136 */ "SeekEnd" OpHelp(""), |
| 34240 | + /* 137 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 34241 | + /* 138 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 34242 | + /* 139 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 34243 | + /* 140 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), |
| 34244 | + /* 141 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 34245 | + /* 142 */ "FinishSeek" OpHelp(""), |
| 34246 | + /* 143 */ "Destroy" OpHelp(""), |
| 34247 | + /* 144 */ "Clear" OpHelp(""), |
| 34248 | + /* 145 */ "ResetSorter" OpHelp(""), |
| 34249 | + /* 146 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"), |
| 34250 | + /* 147 */ "SqlExec" OpHelp(""), |
| 34251 | + /* 148 */ "ParseSchema" OpHelp(""), |
| 34252 | + /* 149 */ "LoadAnalysis" OpHelp(""), |
| 34253 | + /* 150 */ "DropTable" OpHelp(""), |
| 34254 | + /* 151 */ "DropIndex" OpHelp(""), |
| 34043 | 34255 | /* 152 */ "Real" OpHelp("r[P2]=P4"), |
| 34044 | | - /* 153 */ "IntegrityCk" OpHelp(""), |
| 34045 | | - /* 154 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 34046 | | - /* 155 */ "Param" OpHelp(""), |
| 34047 | | - /* 156 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 34048 | | - /* 157 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 34049 | | - /* 158 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), |
| 34050 | | - /* 159 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"), |
| 34051 | | - /* 160 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 34052 | | - /* 161 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 34053 | | - /* 162 */ "AggValue" OpHelp("r[P3]=value N=P2"), |
| 34054 | | - /* 163 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 34055 | | - /* 164 */ "Expire" OpHelp(""), |
| 34056 | | - /* 165 */ "CursorLock" OpHelp(""), |
| 34057 | | - /* 166 */ "CursorUnlock" OpHelp(""), |
| 34058 | | - /* 167 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 34059 | | - /* 168 */ "VBegin" OpHelp(""), |
| 34060 | | - /* 169 */ "VCreate" OpHelp(""), |
| 34061 | | - /* 170 */ "VDestroy" OpHelp(""), |
| 34062 | | - /* 171 */ "VOpen" OpHelp(""), |
| 34063 | | - /* 172 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 34064 | | - /* 173 */ "VRename" OpHelp(""), |
| 34065 | | - /* 174 */ "Pagecount" OpHelp(""), |
| 34066 | | - /* 175 */ "MaxPgcnt" OpHelp(""), |
| 34067 | | - /* 176 */ "Trace" OpHelp(""), |
| 34068 | | - /* 177 */ "CursorHint" OpHelp(""), |
| 34069 | | - /* 178 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"), |
| 34070 | | - /* 179 */ "Noop" OpHelp(""), |
| 34071 | | - /* 180 */ "Explain" OpHelp(""), |
| 34072 | | - /* 181 */ "Abortable" OpHelp(""), |
| 34256 | + /* 153 */ "DropTrigger" OpHelp(""), |
| 34257 | + /* 154 */ "IntegrityCk" OpHelp(""), |
| 34258 | + /* 155 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 34259 | + /* 156 */ "Param" OpHelp(""), |
| 34260 | + /* 157 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 34261 | + /* 158 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 34262 | + /* 159 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), |
| 34263 | + /* 160 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"), |
| 34264 | + /* 161 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 34265 | + /* 162 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 34266 | + /* 163 */ "AggValue" OpHelp("r[P3]=value N=P2"), |
| 34267 | + /* 164 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 34268 | + /* 165 */ "Expire" OpHelp(""), |
| 34269 | + /* 166 */ "CursorLock" OpHelp(""), |
| 34270 | + /* 167 */ "CursorUnlock" OpHelp(""), |
| 34271 | + /* 168 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 34272 | + /* 169 */ "VBegin" OpHelp(""), |
| 34273 | + /* 170 */ "VCreate" OpHelp(""), |
| 34274 | + /* 171 */ "VDestroy" OpHelp(""), |
| 34275 | + /* 172 */ "VOpen" OpHelp(""), |
| 34276 | + /* 173 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 34277 | + /* 174 */ "VRename" OpHelp(""), |
| 34278 | + /* 175 */ "Pagecount" OpHelp(""), |
| 34279 | + /* 176 */ "MaxPgcnt" OpHelp(""), |
| 34280 | + /* 177 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"), |
| 34281 | + /* 178 */ "Trace" OpHelp(""), |
| 34282 | + /* 179 */ "CursorHint" OpHelp(""), |
| 34283 | + /* 180 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"), |
| 34284 | + /* 181 */ "Noop" OpHelp(""), |
| 34285 | + /* 182 */ "Explain" OpHelp(""), |
| 34286 | + /* 183 */ "Abortable" OpHelp(""), |
| 34073 | 34287 | }; |
| 34074 | 34288 | return azName[i]; |
| 34075 | 34289 | } |
| 34076 | 34290 | #endif |
| 34077 | 34291 | |
| | @@ -38028,11 +38242,13 @@ |
| 38028 | 38242 | } |
| 38029 | 38243 | } |
| 38030 | 38244 | |
| 38031 | 38245 | /* Forward declaration */ |
| 38032 | 38246 | static int unixGetTempname(int nBuf, char *zBuf); |
| 38033 | | -static int unixFcntlExternalReader(unixFile*, int*); |
| 38247 | +#ifndef SQLITE_OMIT_WAL |
| 38248 | + static int unixFcntlExternalReader(unixFile*, int*); |
| 38249 | +#endif |
| 38034 | 38250 | |
| 38035 | 38251 | /* |
| 38036 | 38252 | ** Information and control of an open file handle. |
| 38037 | 38253 | */ |
| 38038 | 38254 | static int unixFileControl(sqlite3_file *id, int op, void *pArg){ |
| | @@ -38147,11 +38363,16 @@ |
| 38147 | 38363 | return proxyFileControl(id,op,pArg); |
| 38148 | 38364 | } |
| 38149 | 38365 | #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */ |
| 38150 | 38366 | |
| 38151 | 38367 | case SQLITE_FCNTL_EXTERNAL_READER: { |
| 38368 | +#ifndef SQLITE_OMIT_WAL |
| 38152 | 38369 | return unixFcntlExternalReader((unixFile*)id, (int*)pArg); |
| 38370 | +#else |
| 38371 | + *(int*)pArg = 0; |
| 38372 | + return SQLITE_OK; |
| 38373 | +#endif |
| 38153 | 38374 | } |
| 38154 | 38375 | } |
| 38155 | 38376 | return SQLITE_NOTFOUND; |
| 38156 | 38377 | } |
| 38157 | 38378 | |
| | @@ -39867,40 +40088,50 @@ |
| 39867 | 40088 | OpenCounter(+1); |
| 39868 | 40089 | verifyDbFile(pNew); |
| 39869 | 40090 | } |
| 39870 | 40091 | return rc; |
| 39871 | 40092 | } |
| 40093 | + |
| 40094 | +/* |
| 40095 | +** Directories to consider for temp files. |
| 40096 | +*/ |
| 40097 | +static const char *azTempDirs[] = { |
| 40098 | + 0, |
| 40099 | + 0, |
| 40100 | + "/var/tmp", |
| 40101 | + "/usr/tmp", |
| 40102 | + "/tmp", |
| 40103 | + "." |
| 40104 | +}; |
| 40105 | + |
| 40106 | +/* |
| 40107 | +** Initialize first two members of azTempDirs[] array. |
| 40108 | +*/ |
| 40109 | +static void unixTempFileInit(void){ |
| 40110 | + azTempDirs[0] = getenv("SQLITE_TMPDIR"); |
| 40111 | + azTempDirs[1] = getenv("TMPDIR"); |
| 40112 | +} |
| 39872 | 40113 | |
| 39873 | 40114 | /* |
| 39874 | 40115 | ** Return the name of a directory in which to put temporary files. |
| 39875 | 40116 | ** If no suitable temporary file directory can be found, return NULL. |
| 39876 | 40117 | */ |
| 39877 | 40118 | static const char *unixTempFileDir(void){ |
| 39878 | | - static const char *azDirs[] = { |
| 39879 | | - 0, |
| 39880 | | - 0, |
| 39881 | | - "/var/tmp", |
| 39882 | | - "/usr/tmp", |
| 39883 | | - "/tmp", |
| 39884 | | - "." |
| 39885 | | - }; |
| 39886 | 40119 | unsigned int i = 0; |
| 39887 | 40120 | struct stat buf; |
| 39888 | 40121 | const char *zDir = sqlite3_temp_directory; |
| 39889 | 40122 | |
| 39890 | | - if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR"); |
| 39891 | | - if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR"); |
| 39892 | 40123 | while(1){ |
| 39893 | 40124 | if( zDir!=0 |
| 39894 | 40125 | && osStat(zDir, &buf)==0 |
| 39895 | 40126 | && S_ISDIR(buf.st_mode) |
| 39896 | 40127 | && osAccess(zDir, 03)==0 |
| 39897 | 40128 | ){ |
| 39898 | 40129 | return zDir; |
| 39899 | 40130 | } |
| 39900 | | - if( i>=sizeof(azDirs)/sizeof(azDirs[0]) ) break; |
| 39901 | | - zDir = azDirs[i++]; |
| 40131 | + if( i>=sizeof(azTempDirs)/sizeof(azTempDirs[0]) ) break; |
| 40132 | + zDir = azTempDirs[i++]; |
| 39902 | 40133 | } |
| 39903 | 40134 | return 0; |
| 39904 | 40135 | } |
| 39905 | 40136 | |
| 39906 | 40137 | /* |
| | @@ -40201,10 +40432,15 @@ |
| 40201 | 40432 | if( randomnessPid!=osGetpid(0) ){ |
| 40202 | 40433 | randomnessPid = osGetpid(0); |
| 40203 | 40434 | sqlite3_randomness(0,0); |
| 40204 | 40435 | } |
| 40205 | 40436 | memset(p, 0, sizeof(unixFile)); |
| 40437 | + |
| 40438 | +#ifdef SQLITE_ASSERT_NO_FILES |
| 40439 | + /* Applications that never read or write a persistent disk files */ |
| 40440 | + assert( zName==0 ); |
| 40441 | +#endif |
| 40206 | 40442 | |
| 40207 | 40443 | if( eType==SQLITE_OPEN_MAIN_DB ){ |
| 40208 | 40444 | UnixUnusedFd *pUnused; |
| 40209 | 40445 | pUnused = findReusableFd(zName, flags); |
| 40210 | 40446 | if( pUnused ){ |
| | @@ -40262,12 +40498,10 @@ |
| 40262 | 40498 | if( fd<0 ){ |
| 40263 | 40499 | if( isNewJrnl && errno==EACCES && osAccess(zName, F_OK) ){ |
| 40264 | 40500 | /* If unable to create a journal because the directory is not |
| 40265 | 40501 | ** writable, change the error code to indicate that. */ |
| 40266 | 40502 | rc = SQLITE_READONLY_DIRECTORY; |
| 40267 | | - }else if( errno==EEXIST ){ |
| 40268 | | - rc = SQLITE_CANTOPEN_EXISTS; |
| 40269 | 40503 | }else if( errno!=EISDIR && isReadWrite ){ |
| 40270 | 40504 | /* Failed to open the file for read/write access. Try read-only. */ |
| 40271 | 40505 | flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE); |
| 40272 | 40506 | openFlags &= ~(O_RDWR|O_CREAT); |
| 40273 | 40507 | flags |= SQLITE_OPEN_READONLY; |
| | @@ -42164,10 +42398,13 @@ |
| 42164 | 42398 | ** READ-4 UNIX_SHM_BASE+7 127 |
| 42165 | 42399 | ** DMS UNIX_SHM_BASE+8 128 |
| 42166 | 42400 | */ |
| 42167 | 42401 | assert( UNIX_SHM_DMS==128 ); /* Byte offset of the deadman-switch */ |
| 42168 | 42402 | #endif |
| 42403 | + |
| 42404 | + /* Initialize temp file dir array. */ |
| 42405 | + unixTempFileInit(); |
| 42169 | 42406 | |
| 42170 | 42407 | return SQLITE_OK; |
| 42171 | 42408 | } |
| 42172 | 42409 | |
| 42173 | 42410 | /* |
| | @@ -48615,11 +48852,11 @@ |
| 48615 | 48852 | /* |
| 48616 | 48853 | ** Try to enlarge the memory allocation to hold at least sz bytes |
| 48617 | 48854 | */ |
| 48618 | 48855 | static int memdbEnlarge(MemStore *p, sqlite3_int64 newSz){ |
| 48619 | 48856 | unsigned char *pNew; |
| 48620 | | - if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){ |
| 48857 | + if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || NEVER(p->nMmap>0) ){ |
| 48621 | 48858 | return SQLITE_FULL; |
| 48622 | 48859 | } |
| 48623 | 48860 | if( newSz>p->szMax ){ |
| 48624 | 48861 | return SQLITE_FULL; |
| 48625 | 48862 | } |
| | @@ -48674,12 +48911,13 @@ |
| 48674 | 48911 | */ |
| 48675 | 48912 | static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){ |
| 48676 | 48913 | MemStore *p = ((MemFile*)pFile)->pStore; |
| 48677 | 48914 | int rc = SQLITE_OK; |
| 48678 | 48915 | memdbEnter(p); |
| 48679 | | - if( NEVER(size>p->sz) ){ |
| 48680 | | - rc = SQLITE_FULL; |
| 48916 | + if( size>p->sz ){ |
| 48917 | + /* This can only happen with a corrupt wal mode db */ |
| 48918 | + rc = SQLITE_CORRUPT; |
| 48681 | 48919 | }else{ |
| 48682 | 48920 | p->sz = size; |
| 48683 | 48921 | } |
| 48684 | 48922 | memdbLeave(p); |
| 48685 | 48923 | return rc; |
| | @@ -48814,11 +49052,11 @@ |
| 48814 | 49052 | int iAmt, |
| 48815 | 49053 | void **pp |
| 48816 | 49054 | ){ |
| 48817 | 49055 | MemStore *p = ((MemFile*)pFile)->pStore; |
| 48818 | 49056 | memdbEnter(p); |
| 48819 | | - if( iOfst+iAmt>p->sz ){ |
| 49057 | + if( iOfst+iAmt>p->sz || (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)!=0 ){ |
| 48820 | 49058 | *pp = 0; |
| 48821 | 49059 | }else{ |
| 48822 | 49060 | p->nMmap++; |
| 48823 | 49061 | *pp = (void*)(p->aData + iOfst); |
| 48824 | 49062 | } |
| | @@ -48848,13 +49086,12 @@ |
| 48848 | 49086 | int *pOutFlags |
| 48849 | 49087 | ){ |
| 48850 | 49088 | MemFile *pFile = (MemFile*)pFd; |
| 48851 | 49089 | MemStore *p = 0; |
| 48852 | 49090 | int szName; |
| 48853 | | - if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){ |
| 48854 | | - return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFd, flags, pOutFlags); |
| 48855 | | - } |
| 49091 | + UNUSED_PARAMETER(pVfs); |
| 49092 | + |
| 48856 | 49093 | memset(pFile, 0, sizeof(*pFile)); |
| 48857 | 49094 | szName = sqlite3Strlen30(zName); |
| 48858 | 49095 | if( szName>1 && zName[0]=='/' ){ |
| 48859 | 49096 | int i; |
| 48860 | 49097 | #ifndef SQLITE_MUTEX_OMIT |
| | @@ -48910,12 +49147,13 @@ |
| 48910 | 49147 | memset(p, 0, sizeof(*p)); |
| 48911 | 49148 | p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE; |
| 48912 | 49149 | p->szMax = sqlite3GlobalConfig.mxMemdbSize; |
| 48913 | 49150 | } |
| 48914 | 49151 | pFile->pStore = p; |
| 48915 | | - assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */ |
| 48916 | | - *pOutFlags = flags | SQLITE_OPEN_MEMORY; |
| 49152 | + if( pOutFlags!=0 ){ |
| 49153 | + *pOutFlags = flags | SQLITE_OPEN_MEMORY; |
| 49154 | + } |
| 48917 | 49155 | pFd->pMethods = &memdb_io_methods; |
| 48918 | 49156 | memdbLeave(p); |
| 48919 | 49157 | return SQLITE_OK; |
| 48920 | 49158 | } |
| 48921 | 49159 | |
| | @@ -49576,11 +49814,11 @@ |
| 49576 | 49814 | /* NULL pBitvec tests */ |
| 49577 | 49815 | sqlite3BitvecSet(0, 1); |
| 49578 | 49816 | sqlite3BitvecClear(0, 1, pTmpSpace); |
| 49579 | 49817 | |
| 49580 | 49818 | /* Run the program */ |
| 49581 | | - pc = 0; |
| 49819 | + pc = i = 0; |
| 49582 | 49820 | while( (op = aOp[pc])!=0 ){ |
| 49583 | 49821 | switch( op ){ |
| 49584 | 49822 | case 1: |
| 49585 | 49823 | case 2: |
| 49586 | 49824 | case 5: { |
| | @@ -53106,10 +53344,11 @@ |
| 53106 | 53344 | u8 walSyncFlags; /* See description above */ |
| 53107 | 53345 | u8 tempFile; /* zFilename is a temporary or immutable file */ |
| 53108 | 53346 | u8 noLock; /* Do not lock (except in WAL mode) */ |
| 53109 | 53347 | u8 readOnly; /* True for a read-only database */ |
| 53110 | 53348 | u8 memDb; /* True to inhibit all file I/O */ |
| 53349 | + u8 memVfs; /* VFS-implemented memory database */ |
| 53111 | 53350 | |
| 53112 | 53351 | /************************************************************************** |
| 53113 | 53352 | ** The following block contains those class members that change during |
| 53114 | 53353 | ** routine operation. Class members not in this block are either fixed |
| 53115 | 53354 | ** when the pager is first created or else only change when there is a |
| | @@ -55500,10 +55739,11 @@ |
| 55500 | 55739 | ** routine which only updates the change-counter if the update is actually |
| 55501 | 55740 | ** needed, as determined by the pPager->changeCountDone state variable. |
| 55502 | 55741 | */ |
| 55503 | 55742 | static void pager_write_changecounter(PgHdr *pPg){ |
| 55504 | 55743 | u32 change_counter; |
| 55744 | + if( NEVER(pPg==0) ) return; |
| 55505 | 55745 | |
| 55506 | 55746 | /* Increment the value just read and write it back to byte 24. */ |
| 55507 | 55747 | change_counter = sqlite3Get4byte((u8*)pPg->pPager->dbFileVers)+1; |
| 55508 | 55748 | put32bits(((char*)pPg->pData)+24, change_counter); |
| 55509 | 55749 | |
| | @@ -57347,11 +57587,11 @@ |
| 57347 | 57587 | if( zFilename && zFilename[0] ){ |
| 57348 | 57588 | int fout = 0; /* VFS flags returned by xOpen() */ |
| 57349 | 57589 | rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout); |
| 57350 | 57590 | assert( !memDb ); |
| 57351 | 57591 | #ifndef SQLITE_OMIT_DESERIALIZE |
| 57352 | | - memJM = (fout&SQLITE_OPEN_MEMORY)!=0; |
| 57592 | + pPager->memVfs = memJM = (fout&SQLITE_OPEN_MEMORY)!=0; |
| 57353 | 57593 | #endif |
| 57354 | 57594 | readOnly = (fout&SQLITE_OPEN_READONLY)!=0; |
| 57355 | 57595 | |
| 57356 | 57596 | /* If the file was successfully opened for read/write access, |
| 57357 | 57597 | ** choose a default page size in case we have to create the |
| | @@ -59284,11 +59524,11 @@ |
| 59284 | 59524 | |
| 59285 | 59525 | /* |
| 59286 | 59526 | ** Return true if this is an in-memory or temp-file backed pager. |
| 59287 | 59527 | */ |
| 59288 | 59528 | SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){ |
| 59289 | | - return pPager->tempFile; |
| 59529 | + return pPager->tempFile || pPager->memVfs; |
| 59290 | 59530 | } |
| 59291 | 59531 | |
| 59292 | 59532 | /* |
| 59293 | 59533 | ** Check that there are at least nSavepoint savepoints open. If there are |
| 59294 | 59534 | ** currently less than nSavepoints open, then open one or more savepoints |
| | @@ -59604,11 +59844,11 @@ |
| 59604 | 59844 | */ |
| 59605 | 59845 | pPg->flags &= ~PGHDR_NEED_SYNC; |
| 59606 | 59846 | pPgOld = sqlite3PagerLookup(pPager, pgno); |
| 59607 | 59847 | assert( !pPgOld || pPgOld->nRef==1 || CORRUPT_DB ); |
| 59608 | 59848 | if( pPgOld ){ |
| 59609 | | - if( pPgOld->nRef>1 ){ |
| 59849 | + if( NEVER(pPgOld->nRef>1) ){ |
| 59610 | 59850 | sqlite3PagerUnrefNotNull(pPgOld); |
| 59611 | 59851 | return SQLITE_CORRUPT_BKPT; |
| 59612 | 59852 | } |
| 59613 | 59853 | pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC); |
| 59614 | 59854 | if( pPager->tempFile ){ |
| | @@ -60809,13 +61049,17 @@ |
| 60809 | 61049 | ** If the wal-index is currently smaller the iPage pages then the size |
| 60810 | 61050 | ** of the wal-index might be increased, but only if it is safe to do |
| 60811 | 61051 | ** so. It is safe to enlarge the wal-index if pWal->writeLock is true |
| 60812 | 61052 | ** or pWal->exclusiveMode==WAL_HEAPMEMORY_MODE. |
| 60813 | 61053 | ** |
| 60814 | | -** If this call is successful, *ppPage is set to point to the wal-index |
| 60815 | | -** page and SQLITE_OK is returned. If an error (an OOM or VFS error) occurs, |
| 60816 | | -** then an SQLite error code is returned and *ppPage is set to 0. |
| 61054 | +** Three possible result scenarios: |
| 61055 | +** |
| 61056 | +** (1) rc==SQLITE_OK and *ppPage==Requested-Wal-Index-Page |
| 61057 | +** (2) rc>=SQLITE_ERROR and *ppPage==NULL |
| 61058 | +** (3) rc==SQLITE_OK and *ppPage==NULL // only if iPage==0 |
| 61059 | +** |
| 61060 | +** Scenario (3) can only occur when pWal->writeLock is false and iPage==0 |
| 60817 | 61061 | */ |
| 60818 | 61062 | static SQLITE_NOINLINE int walIndexPageRealloc( |
| 60819 | 61063 | Wal *pWal, /* The WAL context */ |
| 60820 | 61064 | int iPage, /* The page we seek */ |
| 60821 | 61065 | volatile u32 **ppPage /* Write the page pointer here */ |
| | @@ -60844,11 +61088,13 @@ |
| 60844 | 61088 | if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM_BKPT; |
| 60845 | 61089 | }else{ |
| 60846 | 61090 | rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ, |
| 60847 | 61091 | pWal->writeLock, (void volatile **)&pWal->apWiData[iPage] |
| 60848 | 61092 | ); |
| 60849 | | - assert( pWal->apWiData[iPage]!=0 || rc!=SQLITE_OK || pWal->writeLock==0 ); |
| 61093 | + assert( pWal->apWiData[iPage]!=0 |
| 61094 | + || rc!=SQLITE_OK |
| 61095 | + || (pWal->writeLock==0 && iPage==0) ); |
| 60850 | 61096 | testcase( pWal->apWiData[iPage]==0 && rc==SQLITE_OK ); |
| 60851 | 61097 | if( rc==SQLITE_OK ){ |
| 60852 | 61098 | if( iPage>0 && sqlite3FaultSim(600) ) rc = SQLITE_NOMEM; |
| 60853 | 61099 | }else if( (rc&0xff)==SQLITE_READONLY ){ |
| 60854 | 61100 | pWal->readOnly |= WAL_SHM_RDONLY; |
| | @@ -61183,12 +61429,12 @@ |
| 61183 | 61429 | ** in the wal-index file. Set pLoc->iZero to one less than the frame |
| 61184 | 61430 | ** number of the first frame indexed by this hash table. If a |
| 61185 | 61431 | ** slot in the hash table is set to N, it refers to frame number |
| 61186 | 61432 | ** (pLoc->iZero+N) in the log. |
| 61187 | 61433 | ** |
| 61188 | | -** Finally, set pLoc->aPgno so that pLoc->aPgno[1] is the page number of the |
| 61189 | | -** first frame indexed by the hash table, frame (pLoc->iZero+1). |
| 61434 | +** Finally, set pLoc->aPgno so that pLoc->aPgno[0] is the page number of the |
| 61435 | +** first frame indexed by the hash table, frame (pLoc->iZero). |
| 61190 | 61436 | */ |
| 61191 | 61437 | static int walHashGet( |
| 61192 | 61438 | Wal *pWal, /* WAL handle */ |
| 61193 | 61439 | int iHash, /* Find the iHash'th table */ |
| 61194 | 61440 | WalHashLoc *pLoc /* OUT: Hash table location */ |
| | @@ -61196,19 +61442,20 @@ |
| 61196 | 61442 | int rc; /* Return code */ |
| 61197 | 61443 | |
| 61198 | 61444 | rc = walIndexPage(pWal, iHash, &pLoc->aPgno); |
| 61199 | 61445 | assert( rc==SQLITE_OK || iHash>0 ); |
| 61200 | 61446 | |
| 61201 | | - if( rc==SQLITE_OK ){ |
| 61447 | + if( pLoc->aPgno ){ |
| 61202 | 61448 | pLoc->aHash = (volatile ht_slot *)&pLoc->aPgno[HASHTABLE_NPAGE]; |
| 61203 | 61449 | if( iHash==0 ){ |
| 61204 | 61450 | pLoc->aPgno = &pLoc->aPgno[WALINDEX_HDR_SIZE/sizeof(u32)]; |
| 61205 | 61451 | pLoc->iZero = 0; |
| 61206 | 61452 | }else{ |
| 61207 | 61453 | pLoc->iZero = HASHTABLE_NPAGE_ONE + (iHash-1)*HASHTABLE_NPAGE; |
| 61208 | 61454 | } |
| 61209 | | - pLoc->aPgno = &pLoc->aPgno[-1]; |
| 61455 | + }else if( NEVER(rc==SQLITE_OK) ){ |
| 61456 | + rc = SQLITE_ERROR; |
| 61210 | 61457 | } |
| 61211 | 61458 | return rc; |
| 61212 | 61459 | } |
| 61213 | 61460 | |
| 61214 | 61461 | /* |
| | @@ -61286,25 +61533,26 @@ |
| 61286 | 61533 | } |
| 61287 | 61534 | |
| 61288 | 61535 | /* Zero the entries in the aPgno array that correspond to frames with |
| 61289 | 61536 | ** frame numbers greater than pWal->hdr.mxFrame. |
| 61290 | 61537 | */ |
| 61291 | | - nByte = (int)((char *)sLoc.aHash - (char *)&sLoc.aPgno[iLimit+1]); |
| 61292 | | - memset((void *)&sLoc.aPgno[iLimit+1], 0, nByte); |
| 61538 | + nByte = (int)((char *)sLoc.aHash - (char *)&sLoc.aPgno[iLimit]); |
| 61539 | + assert( nByte>=0 ); |
| 61540 | + memset((void *)&sLoc.aPgno[iLimit], 0, nByte); |
| 61293 | 61541 | |
| 61294 | 61542 | #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT |
| 61295 | 61543 | /* Verify that the every entry in the mapping region is still reachable |
| 61296 | 61544 | ** via the hash table even after the cleanup. |
| 61297 | 61545 | */ |
| 61298 | 61546 | if( iLimit ){ |
| 61299 | 61547 | int j; /* Loop counter */ |
| 61300 | 61548 | int iKey; /* Hash key */ |
| 61301 | | - for(j=1; j<=iLimit; j++){ |
| 61549 | + for(j=0; j<iLimit; j++){ |
| 61302 | 61550 | for(iKey=walHash(sLoc.aPgno[j]);sLoc.aHash[iKey];iKey=walNextHash(iKey)){ |
| 61303 | | - if( sLoc.aHash[iKey]==j ) break; |
| 61551 | + if( sLoc.aHash[iKey]==j+1 ) break; |
| 61304 | 61552 | } |
| 61305 | | - assert( sLoc.aHash[iKey]==j ); |
| 61553 | + assert( sLoc.aHash[iKey]==j+1 ); |
| 61306 | 61554 | } |
| 61307 | 61555 | } |
| 61308 | 61556 | #endif /* SQLITE_ENABLE_EXPENSIVE_ASSERT */ |
| 61309 | 61557 | } |
| 61310 | 61558 | |
| | @@ -61332,32 +61580,32 @@ |
| 61332 | 61580 | |
| 61333 | 61581 | /* If this is the first entry to be added to this hash-table, zero the |
| 61334 | 61582 | ** entire hash table and aPgno[] array before proceeding. |
| 61335 | 61583 | */ |
| 61336 | 61584 | if( idx==1 ){ |
| 61337 | | - int nByte = (int)((u8 *)&sLoc.aHash[HASHTABLE_NSLOT] |
| 61338 | | - - (u8 *)&sLoc.aPgno[1]); |
| 61339 | | - memset((void*)&sLoc.aPgno[1], 0, nByte); |
| 61585 | + int nByte = (int)((u8*)&sLoc.aHash[HASHTABLE_NSLOT] - (u8*)sLoc.aPgno); |
| 61586 | + assert( nByte>=0 ); |
| 61587 | + memset((void*)sLoc.aPgno, 0, nByte); |
| 61340 | 61588 | } |
| 61341 | 61589 | |
| 61342 | 61590 | /* If the entry in aPgno[] is already set, then the previous writer |
| 61343 | 61591 | ** must have exited unexpectedly in the middle of a transaction (after |
| 61344 | 61592 | ** writing one or more dirty pages to the WAL to free up memory). |
| 61345 | 61593 | ** Remove the remnants of that writers uncommitted transaction from |
| 61346 | 61594 | ** the hash-table before writing any new entries. |
| 61347 | 61595 | */ |
| 61348 | | - if( sLoc.aPgno[idx] ){ |
| 61596 | + if( sLoc.aPgno[idx-1] ){ |
| 61349 | 61597 | walCleanupHash(pWal); |
| 61350 | | - assert( !sLoc.aPgno[idx] ); |
| 61598 | + assert( !sLoc.aPgno[idx-1] ); |
| 61351 | 61599 | } |
| 61352 | 61600 | |
| 61353 | 61601 | /* Write the aPgno[] array entry and the hash-table slot. */ |
| 61354 | 61602 | nCollide = idx; |
| 61355 | 61603 | for(iKey=walHash(iPage); sLoc.aHash[iKey]; iKey=walNextHash(iKey)){ |
| 61356 | 61604 | if( (nCollide--)==0 ) return SQLITE_CORRUPT_BKPT; |
| 61357 | 61605 | } |
| 61358 | | - sLoc.aPgno[idx] = iPage; |
| 61606 | + sLoc.aPgno[idx-1] = iPage; |
| 61359 | 61607 | AtomicStore(&sLoc.aHash[iKey], (ht_slot)idx); |
| 61360 | 61608 | |
| 61361 | 61609 | #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT |
| 61362 | 61610 | /* Verify that the number of entries in the hash table exactly equals |
| 61363 | 61611 | ** the number of entries in the mapping region. |
| | @@ -61374,22 +61622,21 @@ |
| 61374 | 61622 | ** thing to check, so only do this occasionally - not on every |
| 61375 | 61623 | ** iteration. |
| 61376 | 61624 | */ |
| 61377 | 61625 | if( (idx&0x3ff)==0 ){ |
| 61378 | 61626 | int i; /* Loop counter */ |
| 61379 | | - for(i=1; i<=idx; i++){ |
| 61627 | + for(i=0; i<idx; i++){ |
| 61380 | 61628 | for(iKey=walHash(sLoc.aPgno[i]); |
| 61381 | 61629 | sLoc.aHash[iKey]; |
| 61382 | 61630 | iKey=walNextHash(iKey)){ |
| 61383 | | - if( sLoc.aHash[iKey]==i ) break; |
| 61631 | + if( sLoc.aHash[iKey]==i+1 ) break; |
| 61384 | 61632 | } |
| 61385 | | - assert( sLoc.aHash[iKey]==i ); |
| 61633 | + assert( sLoc.aHash[iKey]==i+1 ); |
| 61386 | 61634 | } |
| 61387 | 61635 | } |
| 61388 | 61636 | #endif /* SQLITE_ENABLE_EXPENSIVE_ASSERT */ |
| 61389 | 61637 | } |
| 61390 | | - |
| 61391 | 61638 | |
| 61392 | 61639 | return rc; |
| 61393 | 61640 | } |
| 61394 | 61641 | |
| 61395 | 61642 | |
| | @@ -61507,11 +61754,12 @@ |
| 61507 | 61754 | u32 iFrame; /* Index of last frame read */ |
| 61508 | 61755 | u32 iLast = MIN(iLastFrame, HASHTABLE_NPAGE_ONE+iPg*HASHTABLE_NPAGE); |
| 61509 | 61756 | u32 iFirst = 1 + (iPg==0?0:HASHTABLE_NPAGE_ONE+(iPg-1)*HASHTABLE_NPAGE); |
| 61510 | 61757 | u32 nHdr, nHdr32; |
| 61511 | 61758 | rc = walIndexPage(pWal, iPg, (volatile u32**)&aShare); |
| 61512 | | - if( rc ) break; |
| 61759 | + assert( aShare!=0 || rc!=SQLITE_OK ); |
| 61760 | + if( aShare==0 ) break; |
| 61513 | 61761 | pWal->apWiData[iPg] = aPrivate; |
| 61514 | 61762 | |
| 61515 | 61763 | for(iFrame=iFirst; iFrame<=iLast; iFrame++){ |
| 61516 | 61764 | i64 iOffset = walFrameOffset(iFrame, szPage); |
| 61517 | 61765 | u32 pgno; /* Database page number for frame */ |
| | @@ -62004,11 +62252,10 @@ |
| 62004 | 62252 | if( rc==SQLITE_OK ){ |
| 62005 | 62253 | int j; /* Counter variable */ |
| 62006 | 62254 | int nEntry; /* Number of entries in this segment */ |
| 62007 | 62255 | ht_slot *aIndex; /* Sorted index for this segment */ |
| 62008 | 62256 | |
| 62009 | | - sLoc.aPgno++; |
| 62010 | 62257 | if( (i+1)==nSegment ){ |
| 62011 | 62258 | nEntry = (int)(iLast - sLoc.iZero); |
| 62012 | 62259 | }else{ |
| 62013 | 62260 | nEntry = (int)((u32*)sLoc.aHash - (u32*)sLoc.aPgno); |
| 62014 | 62261 | } |
| | @@ -63143,11 +63390,12 @@ |
| 63143 | 63390 | i64 iDbOff; /* Offset of db file entry */ |
| 63144 | 63391 | i64 iWalOff; /* Offset of wal file entry */ |
| 63145 | 63392 | |
| 63146 | 63393 | rc = walHashGet(pWal, walFramePage(i), &sLoc); |
| 63147 | 63394 | if( rc!=SQLITE_OK ) break; |
| 63148 | | - pgno = sLoc.aPgno[i-sLoc.iZero]; |
| 63395 | + assert( i - sLoc.iZero - 1 >=0 ); |
| 63396 | + pgno = sLoc.aPgno[i-sLoc.iZero-1]; |
| 63149 | 63397 | iDbOff = (i64)(pgno-1) * szPage; |
| 63150 | 63398 | |
| 63151 | 63399 | if( iDbOff+szPage<=szDb ){ |
| 63152 | 63400 | iWalOff = walFrameOffset(i, szPage) + WAL_FRAME_HDRSIZE; |
| 63153 | 63401 | rc = sqlite3OsRead(pWal->pWalFd, pBuf1, szPage, iWalOff); |
| | @@ -63376,11 +63624,11 @@ |
| 63376 | 63624 | } |
| 63377 | 63625 | nCollide = HASHTABLE_NSLOT; |
| 63378 | 63626 | iKey = walHash(pgno); |
| 63379 | 63627 | while( (iH = AtomicLoad(&sLoc.aHash[iKey]))!=0 ){ |
| 63380 | 63628 | u32 iFrame = iH + sLoc.iZero; |
| 63381 | | - if( iFrame<=iLast && iFrame>=pWal->minFrame && sLoc.aPgno[iH]==pgno ){ |
| 63629 | + if( iFrame<=iLast && iFrame>=pWal->minFrame && sLoc.aPgno[iH-1]==pgno ){ |
| 63382 | 63630 | assert( iFrame>iRead || CORRUPT_DB ); |
| 63383 | 63631 | iRead = iFrame; |
| 63384 | 63632 | } |
| 63385 | 63633 | if( (nCollide--)==0 ){ |
| 63386 | 63634 | return SQLITE_CORRUPT_BKPT; |
| | @@ -64628,11 +64876,10 @@ |
| 64628 | 64876 | ** Access to all fields of this structure is controlled by the mutex |
| 64629 | 64877 | ** stored in MemPage.pBt->mutex. |
| 64630 | 64878 | */ |
| 64631 | 64879 | struct MemPage { |
| 64632 | 64880 | u8 isInit; /* True if previously initialized. MUST BE FIRST! */ |
| 64633 | | - u8 bBusy; /* Prevent endless loops on corrupt database files */ |
| 64634 | 64881 | u8 intKey; /* True if table b-trees. False for index b-trees */ |
| 64635 | 64882 | u8 intKeyLeaf; /* True if the leaf of an intKey table */ |
| 64636 | 64883 | Pgno pgno; /* Page number for this page */ |
| 64637 | 64884 | /* Only the first 8 bytes (above) are zeroed by pager.c when a new page |
| 64638 | 64885 | ** is allocated. All fields that follow must be initialized before use */ |
| | @@ -66870,11 +67117,11 @@ |
| 66870 | 67117 | if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage); |
| 66871 | 67118 | sz2 = get2byte(&data[iFree2+2]); |
| 66872 | 67119 | if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage); |
| 66873 | 67120 | memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz)); |
| 66874 | 67121 | sz += sz2; |
| 66875 | | - }else if( iFree+sz>usableSize ){ |
| 67122 | + }else if( NEVER(iFree+sz>usableSize) ){ |
| 66876 | 67123 | return SQLITE_CORRUPT_PAGE(pPage); |
| 66877 | 67124 | } |
| 66878 | 67125 | |
| 66879 | 67126 | cbrk = top+sz; |
| 66880 | 67127 | assert( cbrk+(iFree-top) <= usableSize ); |
| | @@ -68075,34 +68322,42 @@ |
| 68075 | 68322 | /* |
| 68076 | 68323 | ** Make sure pBt->pTmpSpace points to an allocation of |
| 68077 | 68324 | ** MX_CELL_SIZE(pBt) bytes with a 4-byte prefix for a left-child |
| 68078 | 68325 | ** pointer. |
| 68079 | 68326 | */ |
| 68080 | | -static void allocateTempSpace(BtShared *pBt){ |
| 68081 | | - if( !pBt->pTmpSpace ){ |
| 68082 | | - pBt->pTmpSpace = sqlite3PageMalloc( pBt->pageSize ); |
| 68083 | | - |
| 68084 | | - /* One of the uses of pBt->pTmpSpace is to format cells before |
| 68085 | | - ** inserting them into a leaf page (function fillInCell()). If |
| 68086 | | - ** a cell is less than 4 bytes in size, it is rounded up to 4 bytes |
| 68087 | | - ** by the various routines that manipulate binary cells. Which |
| 68088 | | - ** can mean that fillInCell() only initializes the first 2 or 3 |
| 68089 | | - ** bytes of pTmpSpace, but that the first 4 bytes are copied from |
| 68090 | | - ** it into a database page. This is not actually a problem, but it |
| 68091 | | - ** does cause a valgrind error when the 1 or 2 bytes of unitialized |
| 68092 | | - ** data is passed to system call write(). So to avoid this error, |
| 68093 | | - ** zero the first 4 bytes of temp space here. |
| 68094 | | - ** |
| 68095 | | - ** Also: Provide four bytes of initialized space before the |
| 68096 | | - ** beginning of pTmpSpace as an area available to prepend the |
| 68097 | | - ** left-child pointer to the beginning of a cell. |
| 68098 | | - */ |
| 68099 | | - if( pBt->pTmpSpace ){ |
| 68100 | | - memset(pBt->pTmpSpace, 0, 8); |
| 68101 | | - pBt->pTmpSpace += 4; |
| 68102 | | - } |
| 68103 | | - } |
| 68327 | +static SQLITE_NOINLINE int allocateTempSpace(BtShared *pBt){ |
| 68328 | + assert( pBt!=0 ); |
| 68329 | + assert( pBt->pTmpSpace==0 ); |
| 68330 | + /* This routine is called only by btreeCursor() when allocating the |
| 68331 | + ** first write cursor for the BtShared object */ |
| 68332 | + assert( pBt->pCursor!=0 && (pBt->pCursor->curFlags & BTCF_WriteFlag)!=0 ); |
| 68333 | + pBt->pTmpSpace = sqlite3PageMalloc( pBt->pageSize ); |
| 68334 | + if( pBt->pTmpSpace==0 ){ |
| 68335 | + BtCursor *pCur = pBt->pCursor; |
| 68336 | + pBt->pCursor = pCur->pNext; /* Unlink the cursor */ |
| 68337 | + memset(pCur, 0, sizeof(*pCur)); |
| 68338 | + return SQLITE_NOMEM_BKPT; |
| 68339 | + } |
| 68340 | + |
| 68341 | + /* One of the uses of pBt->pTmpSpace is to format cells before |
| 68342 | + ** inserting them into a leaf page (function fillInCell()). If |
| 68343 | + ** a cell is less than 4 bytes in size, it is rounded up to 4 bytes |
| 68344 | + ** by the various routines that manipulate binary cells. Which |
| 68345 | + ** can mean that fillInCell() only initializes the first 2 or 3 |
| 68346 | + ** bytes of pTmpSpace, but that the first 4 bytes are copied from |
| 68347 | + ** it into a database page. This is not actually a problem, but it |
| 68348 | + ** does cause a valgrind error when the 1 or 2 bytes of unitialized |
| 68349 | + ** data is passed to system call write(). So to avoid this error, |
| 68350 | + ** zero the first 4 bytes of temp space here. |
| 68351 | + ** |
| 68352 | + ** Also: Provide four bytes of initialized space before the |
| 68353 | + ** beginning of pTmpSpace as an area available to prepend the |
| 68354 | + ** left-child pointer to the beginning of a cell. |
| 68355 | + */ |
| 68356 | + memset(pBt->pTmpSpace, 0, 8); |
| 68357 | + pBt->pTmpSpace += 4; |
| 68358 | + return SQLITE_OK; |
| 68104 | 68359 | } |
| 68105 | 68360 | |
| 68106 | 68361 | /* |
| 68107 | 68362 | ** Free the pBt->pTmpSpace allocation |
| 68108 | 68363 | */ |
| | @@ -68477,11 +68732,10 @@ |
| 68477 | 68732 | static int lockBtree(BtShared *pBt){ |
| 68478 | 68733 | int rc; /* Result code from subfunctions */ |
| 68479 | 68734 | MemPage *pPage1; /* Page 1 of the database file */ |
| 68480 | 68735 | u32 nPage; /* Number of pages in the database */ |
| 68481 | 68736 | u32 nPageFile = 0; /* Number of pages in the database file */ |
| 68482 | | - u32 nPageHeader; /* Number of pages in the database according to hdr */ |
| 68483 | 68737 | |
| 68484 | 68738 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 68485 | 68739 | assert( pBt->pPage1==0 ); |
| 68486 | 68740 | rc = sqlite3PagerSharedLock(pBt->pPager); |
| 68487 | 68741 | if( rc!=SQLITE_OK ) return rc; |
| | @@ -68489,11 +68743,11 @@ |
| 68489 | 68743 | if( rc!=SQLITE_OK ) return rc; |
| 68490 | 68744 | |
| 68491 | 68745 | /* Do some checking to help insure the file we opened really is |
| 68492 | 68746 | ** a valid database file. |
| 68493 | 68747 | */ |
| 68494 | | - nPage = nPageHeader = get4byte(28+(u8*)pPage1->aData); |
| 68748 | + nPage = get4byte(28+(u8*)pPage1->aData); |
| 68495 | 68749 | sqlite3PagerPagecount(pBt->pPager, (int*)&nPageFile); |
| 68496 | 68750 | if( nPage==0 || memcmp(24+(u8*)pPage1->aData, 92+(u8*)pPage1->aData,4)!=0 ){ |
| 68497 | 68751 | nPage = nPageFile; |
| 68498 | 68752 | } |
| 68499 | 68753 | if( (pBt->db->flags & SQLITE_ResetDatabase)!=0 ){ |
| | @@ -69322,27 +69576,30 @@ |
| 69322 | 69576 | } |
| 69323 | 69577 | |
| 69324 | 69578 | /* |
| 69325 | 69579 | ** This routine is called prior to sqlite3PagerCommit when a transaction |
| 69326 | 69580 | ** is committed for an auto-vacuum database. |
| 69327 | | -** |
| 69328 | | -** If SQLITE_OK is returned, then *pnTrunc is set to the number of pages |
| 69329 | | -** the database file should be truncated to during the commit process. |
| 69330 | | -** i.e. the database has been reorganized so that only the first *pnTrunc |
| 69331 | | -** pages are in use. |
| 69332 | 69581 | */ |
| 69333 | | -static int autoVacuumCommit(BtShared *pBt){ |
| 69582 | +static int autoVacuumCommit(Btree *p){ |
| 69334 | 69583 | int rc = SQLITE_OK; |
| 69335 | | - Pager *pPager = pBt->pPager; |
| 69336 | | - VVA_ONLY( int nRef = sqlite3PagerRefcount(pPager); ) |
| 69584 | + Pager *pPager; |
| 69585 | + BtShared *pBt; |
| 69586 | + sqlite3 *db; |
| 69587 | + VVA_ONLY( int nRef ); |
| 69588 | + |
| 69589 | + assert( p!=0 ); |
| 69590 | + pBt = p->pBt; |
| 69591 | + pPager = pBt->pPager; |
| 69592 | + VVA_ONLY( nRef = sqlite3PagerRefcount(pPager); ) |
| 69337 | 69593 | |
| 69338 | 69594 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 69339 | 69595 | invalidateAllOverflowCache(pBt); |
| 69340 | 69596 | assert(pBt->autoVacuum); |
| 69341 | 69597 | if( !pBt->incrVacuum ){ |
| 69342 | 69598 | Pgno nFin; /* Number of pages in database after autovacuuming */ |
| 69343 | 69599 | Pgno nFree; /* Number of pages on the freelist initially */ |
| 69600 | + Pgno nVac; /* Number of pages to vacuum */ |
| 69344 | 69601 | Pgno iFree; /* The next page to be freed */ |
| 69345 | 69602 | Pgno nOrig; /* Database size before freeing */ |
| 69346 | 69603 | |
| 69347 | 69604 | nOrig = btreePagecount(pBt); |
| 69348 | 69605 | if( PTRMAP_ISPAGE(pBt, nOrig) || nOrig==PENDING_BYTE_PAGE(pBt) ){ |
| | @@ -69352,22 +69609,46 @@ |
| 69352 | 69609 | */ |
| 69353 | 69610 | return SQLITE_CORRUPT_BKPT; |
| 69354 | 69611 | } |
| 69355 | 69612 | |
| 69356 | 69613 | nFree = get4byte(&pBt->pPage1->aData[36]); |
| 69357 | | - nFin = finalDbSize(pBt, nOrig, nFree); |
| 69614 | + db = p->db; |
| 69615 | + if( db->xAutovacPages ){ |
| 69616 | + int iDb; |
| 69617 | + for(iDb=0; ALWAYS(iDb<db->nDb); iDb++){ |
| 69618 | + if( db->aDb[iDb].pBt==p ) break; |
| 69619 | + } |
| 69620 | + nVac = db->xAutovacPages( |
| 69621 | + db->pAutovacPagesArg, |
| 69622 | + db->aDb[iDb].zDbSName, |
| 69623 | + nOrig, |
| 69624 | + nFree, |
| 69625 | + pBt->pageSize |
| 69626 | + ); |
| 69627 | + if( nVac>nFree ){ |
| 69628 | + nVac = nFree; |
| 69629 | + } |
| 69630 | + if( nVac==0 ){ |
| 69631 | + return SQLITE_OK; |
| 69632 | + } |
| 69633 | + }else{ |
| 69634 | + nVac = nFree; |
| 69635 | + } |
| 69636 | + nFin = finalDbSize(pBt, nOrig, nVac); |
| 69358 | 69637 | if( nFin>nOrig ) return SQLITE_CORRUPT_BKPT; |
| 69359 | 69638 | if( nFin<nOrig ){ |
| 69360 | 69639 | rc = saveAllCursors(pBt, 0, 0); |
| 69361 | 69640 | } |
| 69362 | 69641 | for(iFree=nOrig; iFree>nFin && rc==SQLITE_OK; iFree--){ |
| 69363 | | - rc = incrVacuumStep(pBt, nFin, iFree, 1); |
| 69642 | + rc = incrVacuumStep(pBt, nFin, iFree, nVac==nFree); |
| 69364 | 69643 | } |
| 69365 | 69644 | if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){ |
| 69366 | 69645 | rc = sqlite3PagerWrite(pBt->pPage1->pDbPage); |
| 69367 | | - put4byte(&pBt->pPage1->aData[32], 0); |
| 69368 | | - put4byte(&pBt->pPage1->aData[36], 0); |
| 69646 | + if( nVac==nFree ){ |
| 69647 | + put4byte(&pBt->pPage1->aData[32], 0); |
| 69648 | + put4byte(&pBt->pPage1->aData[36], 0); |
| 69649 | + } |
| 69369 | 69650 | put4byte(&pBt->pPage1->aData[28], nFin); |
| 69370 | 69651 | pBt->bDoTruncate = 1; |
| 69371 | 69652 | pBt->nPage = nFin; |
| 69372 | 69653 | } |
| 69373 | 69654 | if( rc!=SQLITE_OK ){ |
| | @@ -69414,11 +69695,11 @@ |
| 69414 | 69695 | if( p->inTrans==TRANS_WRITE ){ |
| 69415 | 69696 | BtShared *pBt = p->pBt; |
| 69416 | 69697 | sqlite3BtreeEnter(p); |
| 69417 | 69698 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 69418 | 69699 | if( pBt->autoVacuum ){ |
| 69419 | | - rc = autoVacuumCommit(pBt); |
| 69700 | + rc = autoVacuumCommit(p); |
| 69420 | 69701 | if( rc!=SQLITE_OK ){ |
| 69421 | 69702 | sqlite3BtreeLeave(p); |
| 69422 | 69703 | return rc; |
| 69423 | 69704 | } |
| 69424 | 69705 | } |
| | @@ -69813,14 +70094,10 @@ |
| 69813 | 70094 | assert( p->inTrans>TRANS_NONE ); |
| 69814 | 70095 | assert( wrFlag==0 || p->inTrans==TRANS_WRITE ); |
| 69815 | 70096 | assert( pBt->pPage1 && pBt->pPage1->aData ); |
| 69816 | 70097 | assert( wrFlag==0 || (pBt->btsFlags & BTS_READ_ONLY)==0 ); |
| 69817 | 70098 | |
| 69818 | | - if( wrFlag ){ |
| 69819 | | - allocateTempSpace(pBt); |
| 69820 | | - if( pBt->pTmpSpace==0 ) return SQLITE_NOMEM_BKPT; |
| 69821 | | - } |
| 69822 | 70099 | if( iTable<=1 ){ |
| 69823 | 70100 | if( iTable<1 ){ |
| 69824 | 70101 | return SQLITE_CORRUPT_BKPT; |
| 69825 | 70102 | }else if( btreePagecount(pBt)==0 ){ |
| 69826 | 70103 | assert( wrFlag==0 ); |
| | @@ -69833,23 +70110,29 @@ |
| 69833 | 70110 | pCur->pgnoRoot = iTable; |
| 69834 | 70111 | pCur->iPage = -1; |
| 69835 | 70112 | pCur->pKeyInfo = pKeyInfo; |
| 69836 | 70113 | pCur->pBtree = p; |
| 69837 | 70114 | pCur->pBt = pBt; |
| 69838 | | - pCur->curFlags = wrFlag ? BTCF_WriteFlag : 0; |
| 69839 | | - pCur->curPagerFlags = wrFlag ? 0 : PAGER_GET_READONLY; |
| 70115 | + pCur->curFlags = 0; |
| 69840 | 70116 | /* If there are two or more cursors on the same btree, then all such |
| 69841 | 70117 | ** cursors *must* have the BTCF_Multiple flag set. */ |
| 69842 | 70118 | for(pX=pBt->pCursor; pX; pX=pX->pNext){ |
| 69843 | 70119 | if( pX->pgnoRoot==iTable ){ |
| 69844 | 70120 | pX->curFlags |= BTCF_Multiple; |
| 69845 | | - pCur->curFlags |= BTCF_Multiple; |
| 70121 | + pCur->curFlags = BTCF_Multiple; |
| 69846 | 70122 | } |
| 69847 | 70123 | } |
| 70124 | + pCur->eState = CURSOR_INVALID; |
| 69848 | 70125 | pCur->pNext = pBt->pCursor; |
| 69849 | 70126 | pBt->pCursor = pCur; |
| 69850 | | - pCur->eState = CURSOR_INVALID; |
| 70127 | + if( wrFlag ){ |
| 70128 | + pCur->curFlags |= BTCF_WriteFlag; |
| 70129 | + pCur->curPagerFlags = 0; |
| 70130 | + if( pBt->pTmpSpace==0 ) return allocateTempSpace(pBt); |
| 70131 | + }else{ |
| 70132 | + pCur->curPagerFlags = PAGER_GET_READONLY; |
| 70133 | + } |
| 69851 | 70134 | return SQLITE_OK; |
| 69852 | 70135 | } |
| 69853 | 70136 | static int btreeCursorWithLock( |
| 69854 | 70137 | Btree *p, /* The btree */ |
| 69855 | 70138 | Pgno iTable, /* Root page of table to open */ |
| | @@ -70219,11 +70502,13 @@ |
| 70219 | 70502 | #endif |
| 70220 | 70503 | |
| 70221 | 70504 | assert( pPage ); |
| 70222 | 70505 | assert( eOp==0 || eOp==1 ); |
| 70223 | 70506 | assert( pCur->eState==CURSOR_VALID ); |
| 70224 | | - assert( pCur->ix<pPage->nCell ); |
| 70507 | + if( pCur->ix>=pPage->nCell ){ |
| 70508 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 70509 | + } |
| 70225 | 70510 | assert( cursorHoldsMutex(pCur) ); |
| 70226 | 70511 | |
| 70227 | 70512 | getCellInfo(pCur); |
| 70228 | 70513 | aPayload = pCur->info.pPayload; |
| 70229 | 70514 | assert( offset+amt <= pCur->info.nPayload ); |
| | @@ -70406,11 +70691,10 @@ |
| 70406 | 70691 | */ |
| 70407 | 70692 | SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ |
| 70408 | 70693 | assert( cursorHoldsMutex(pCur) ); |
| 70409 | 70694 | assert( pCur->eState==CURSOR_VALID ); |
| 70410 | 70695 | assert( pCur->iPage>=0 && pCur->pPage ); |
| 70411 | | - assert( pCur->ix<pCur->pPage->nCell ); |
| 70412 | 70696 | return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0); |
| 70413 | 70697 | } |
| 70414 | 70698 | |
| 70415 | 70699 | /* |
| 70416 | 70700 | ** This variant of sqlite3BtreePayload() works even if the cursor has not |
| | @@ -70468,11 +70752,11 @@ |
| 70468 | 70752 | int amt; |
| 70469 | 70753 | assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage); |
| 70470 | 70754 | assert( pCur->eState==CURSOR_VALID ); |
| 70471 | 70755 | assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 70472 | 70756 | assert( cursorOwnsBtShared(pCur) ); |
| 70473 | | - assert( pCur->ix<pCur->pPage->nCell ); |
| 70757 | + assert( pCur->ix<pCur->pPage->nCell || CORRUPT_DB ); |
| 70474 | 70758 | assert( pCur->info.nSize>0 ); |
| 70475 | 70759 | assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB ); |
| 70476 | 70760 | assert( pCur->info.pPayload<pCur->pPage->aDataEnd ||CORRUPT_DB); |
| 70477 | 70761 | amt = pCur->info.nLocal; |
| 70478 | 70762 | if( amt>(int)(pCur->pPage->aDataEnd - pCur->info.pPayload) ){ |
| | @@ -71254,20 +71538,10 @@ |
| 71254 | 71538 | ** module cov1/btree78.test testcase 220 (2018-06-08) for an |
| 71255 | 71539 | ** example. */ |
| 71256 | 71540 | return SQLITE_CORRUPT_BKPT; |
| 71257 | 71541 | } |
| 71258 | 71542 | |
| 71259 | | - /* If the database file is corrupt, it is possible for the value of idx |
| 71260 | | - ** to be invalid here. This can only occur if a second cursor modifies |
| 71261 | | - ** the page while cursor pCur is holding a reference to it. Which can |
| 71262 | | - ** only happen if the database is corrupt in such a way as to link the |
| 71263 | | - ** page into more than one b-tree structure. |
| 71264 | | - ** |
| 71265 | | - ** Update 2019-12-23: appears to long longer be possible after the |
| 71266 | | - ** addition of anotherValidCursor() condition on balance_deeper(). */ |
| 71267 | | - harmless( idx>pPage->nCell ); |
| 71268 | | - |
| 71269 | 71543 | if( idx>=pPage->nCell ){ |
| 71270 | 71544 | if( !pPage->leaf ){ |
| 71271 | 71545 | rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8])); |
| 71272 | 71546 | if( rc ) return rc; |
| 71273 | 71547 | return moveToLeftmost(pCur); |
| | @@ -71751,11 +72025,11 @@ |
| 71751 | 72025 | |
| 71752 | 72026 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 71753 | 72027 | assert( CORRUPT_DB || iPage>1 ); |
| 71754 | 72028 | assert( !pMemPage || pMemPage->pgno==iPage ); |
| 71755 | 72029 | |
| 71756 | | - if( iPage<2 || iPage>pBt->nPage ){ |
| 72030 | + if( NEVER(iPage<2) || iPage>pBt->nPage ){ |
| 71757 | 72031 | return SQLITE_CORRUPT_BKPT; |
| 71758 | 72032 | } |
| 71759 | 72033 | if( pMemPage ){ |
| 71760 | 72034 | pPage = pMemPage; |
| 71761 | 72035 | sqlite3PagerRef(pPage->pDbPage); |
| | @@ -73069,15 +73343,14 @@ |
| 73069 | 73343 | Pgno pgno; /* Temp var to store a page number in */ |
| 73070 | 73344 | u8 abDone[NB+2]; /* True after i'th new page is populated */ |
| 73071 | 73345 | Pgno aPgno[NB+2]; /* Page numbers of new pages before shuffling */ |
| 73072 | 73346 | Pgno aPgOrder[NB+2]; /* Copy of aPgno[] used for sorting pages */ |
| 73073 | 73347 | u16 aPgFlags[NB+2]; /* flags field of new pages before shuffling */ |
| 73074 | | - CellArray b; /* Parsed information on cells being balanced */ |
| 73348 | + CellArray b; /* Parsed information on cells being balanced */ |
| 73075 | 73349 | |
| 73076 | 73350 | memset(abDone, 0, sizeof(abDone)); |
| 73077 | | - b.nCell = 0; |
| 73078 | | - b.apCell = 0; |
| 73351 | + memset(&b, 0, sizeof(b)); |
| 73079 | 73352 | pBt = pParent->pBt; |
| 73080 | 73353 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 73081 | 73354 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 73082 | 73355 | |
| 73083 | 73356 | /* At this point pParent may have at most one overflow cell. And if |
| | @@ -73884,11 +74157,11 @@ |
| 73884 | 74157 | |
| 73885 | 74158 | /* |
| 73886 | 74159 | ** Return SQLITE_CORRUPT if any cursor other than pCur is currently valid |
| 73887 | 74160 | ** on the same B-tree as pCur. |
| 73888 | 74161 | ** |
| 73889 | | -** This can if a database is corrupt with two or more SQL tables |
| 74162 | +** This can occur if a database is corrupt with two or more SQL tables |
| 73890 | 74163 | ** pointing to the same b-tree. If an insert occurs on one SQL table |
| 73891 | 74164 | ** and causes a BEFORE TRIGGER to do a secondary insert on the other SQL |
| 73892 | 74165 | ** table linked to the same b-tree. If the secondary insert causes a |
| 73893 | 74166 | ** rebalance, that can change content out from under the cursor on the |
| 73894 | 74167 | ** first SQL table, violating invariants on the first insert. |
| | @@ -74353,11 +74626,14 @@ |
| 74353 | 74626 | assert( szNew==pPage->xCellSize(pPage, newCell) ); |
| 74354 | 74627 | assert( szNew <= MX_CELL_SIZE(pBt) ); |
| 74355 | 74628 | idx = pCur->ix; |
| 74356 | 74629 | if( loc==0 ){ |
| 74357 | 74630 | CellInfo info; |
| 74358 | | - assert( idx<pPage->nCell ); |
| 74631 | + assert( idx>=0 ); |
| 74632 | + if( idx>=pPage->nCell ){ |
| 74633 | + return SQLITE_CORRUPT_BKPT; |
| 74634 | + } |
| 74359 | 74635 | rc = sqlite3PagerWrite(pPage->pDbPage); |
| 74360 | 74636 | if( rc ){ |
| 74361 | 74637 | goto end_insert; |
| 74362 | 74638 | } |
| 74363 | 74639 | oldCell = findCell(pPage, idx); |
| | @@ -74939,15 +75215,16 @@ |
| 74939 | 75215 | if( pgno>btreePagecount(pBt) ){ |
| 74940 | 75216 | return SQLITE_CORRUPT_BKPT; |
| 74941 | 75217 | } |
| 74942 | 75218 | rc = getAndInitPage(pBt, pgno, &pPage, 0, 0); |
| 74943 | 75219 | if( rc ) return rc; |
| 74944 | | - if( pPage->bBusy ){ |
| 75220 | + if( (pBt->openFlags & BTREE_SINGLE)==0 |
| 75221 | + && sqlite3PagerPageRefcount(pPage->pDbPage)!=1 |
| 75222 | + ){ |
| 74945 | 75223 | rc = SQLITE_CORRUPT_BKPT; |
| 74946 | 75224 | goto cleardatabasepage_out; |
| 74947 | 75225 | } |
| 74948 | | - pPage->bBusy = 1; |
| 74949 | 75226 | hdr = pPage->hdrOffset; |
| 74950 | 75227 | for(i=0; i<pPage->nCell; i++){ |
| 74951 | 75228 | pCell = findCell(pPage, i); |
| 74952 | 75229 | if( !pPage->leaf ){ |
| 74953 | 75230 | rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange); |
| | @@ -74970,11 +75247,10 @@ |
| 74970 | 75247 | }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){ |
| 74971 | 75248 | zeroPage(pPage, pPage->aData[hdr] | PTF_LEAF); |
| 74972 | 75249 | } |
| 74973 | 75250 | |
| 74974 | 75251 | cleardatabasepage_out: |
| 74975 | | - pPage->bBusy = 0; |
| 74976 | 75252 | releasePage(pPage); |
| 74977 | 75253 | return rc; |
| 74978 | 75254 | } |
| 74979 | 75255 | |
| 74980 | 75256 | /* |
| | @@ -75049,14 +75325,14 @@ |
| 75049 | 75325 | assert( iTable>=2 ); |
| 75050 | 75326 | if( iTable>btreePagecount(pBt) ){ |
| 75051 | 75327 | return SQLITE_CORRUPT_BKPT; |
| 75052 | 75328 | } |
| 75053 | 75329 | |
| 75054 | | - rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0); |
| 75055 | | - if( rc ) return rc; |
| 75056 | 75330 | rc = sqlite3BtreeClearTable(p, iTable, 0); |
| 75057 | | - if( rc ){ |
| 75331 | + if( rc ) return rc; |
| 75332 | + rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0); |
| 75333 | + if( NEVER(rc) ){ |
| 75058 | 75334 | releasePage(pPage); |
| 75059 | 75335 | return rc; |
| 75060 | 75336 | } |
| 75061 | 75337 | |
| 75062 | 75338 | *piMoved = 0; |
| | @@ -77209,10 +77485,11 @@ |
| 77209 | 77485 | */ |
| 77210 | 77486 | SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){ |
| 77211 | 77487 | #ifndef SQLITE_OMIT_UTF16 |
| 77212 | 77488 | int rc; |
| 77213 | 77489 | #endif |
| 77490 | + assert( pMem!=0 ); |
| 77214 | 77491 | assert( !sqlite3VdbeMemIsRowSet(pMem) ); |
| 77215 | 77492 | assert( desiredEnc==SQLITE_UTF8 || desiredEnc==SQLITE_UTF16LE |
| 77216 | 77493 | || desiredEnc==SQLITE_UTF16BE ); |
| 77217 | 77494 | if( !(pMem->flags&MEM_Str) || pMem->enc==desiredEnc ){ |
| 77218 | 77495 | return SQLITE_OK; |
| | @@ -77341,10 +77618,11 @@ |
| 77341 | 77618 | ** MEM.zMalloc, where it can be safely written. |
| 77342 | 77619 | ** |
| 77343 | 77620 | ** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails. |
| 77344 | 77621 | */ |
| 77345 | 77622 | SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem *pMem){ |
| 77623 | + assert( pMem!=0 ); |
| 77346 | 77624 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 77347 | 77625 | assert( !sqlite3VdbeMemIsRowSet(pMem) ); |
| 77348 | 77626 | if( (pMem->flags & (MEM_Str|MEM_Blob))!=0 ){ |
| 77349 | 77627 | if( ExpandBlob(pMem) ) return SQLITE_NOMEM; |
| 77350 | 77628 | if( pMem->szMalloc==0 || pMem->z!=pMem->zMalloc ){ |
| | @@ -77365,10 +77643,11 @@ |
| 77365 | 77643 | ** blob stored in dynamically allocated space. |
| 77366 | 77644 | */ |
| 77367 | 77645 | #ifndef SQLITE_OMIT_INCRBLOB |
| 77368 | 77646 | SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *pMem){ |
| 77369 | 77647 | int nByte; |
| 77648 | + assert( pMem!=0 ); |
| 77370 | 77649 | assert( pMem->flags & MEM_Zero ); |
| 77371 | 77650 | assert( (pMem->flags&MEM_Blob)!=0 || MemNullNochng(pMem) ); |
| 77372 | 77651 | testcase( sqlite3_value_nochange(pMem) ); |
| 77373 | 77652 | assert( !sqlite3VdbeMemIsRowSet(pMem) ); |
| 77374 | 77653 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| | @@ -77380,10 +77659,12 @@ |
| 77380 | 77659 | nByte = 1; |
| 77381 | 77660 | } |
| 77382 | 77661 | if( sqlite3VdbeMemGrow(pMem, nByte, 1) ){ |
| 77383 | 77662 | return SQLITE_NOMEM_BKPT; |
| 77384 | 77663 | } |
| 77664 | + assert( pMem->z!=0 ); |
| 77665 | + assert( sqlite3DbMallocSize(pMem->db,pMem->z) >= nByte ); |
| 77385 | 77666 | |
| 77386 | 77667 | memset(&pMem->z[pMem->n], 0, pMem->u.nZero); |
| 77387 | 77668 | pMem->n += pMem->u.nZero; |
| 77388 | 77669 | pMem->flags &= ~(MEM_Zero|MEM_Term); |
| 77389 | 77670 | return SQLITE_OK; |
| | @@ -77392,10 +77673,11 @@ |
| 77392 | 77673 | |
| 77393 | 77674 | /* |
| 77394 | 77675 | ** Make sure the given Mem is \u0000 terminated. |
| 77395 | 77676 | */ |
| 77396 | 77677 | SQLITE_PRIVATE int sqlite3VdbeMemNulTerminate(Mem *pMem){ |
| 77678 | + assert( pMem!=0 ); |
| 77397 | 77679 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 77398 | 77680 | testcase( (pMem->flags & (MEM_Term|MEM_Str))==(MEM_Term|MEM_Str) ); |
| 77399 | 77681 | testcase( (pMem->flags & (MEM_Term|MEM_Str))==0 ); |
| 77400 | 77682 | if( (pMem->flags & (MEM_Term|MEM_Str))!=MEM_Str ){ |
| 77401 | 77683 | return SQLITE_OK; /* Nothing to do */ |
| | @@ -77419,10 +77701,11 @@ |
| 77419 | 77701 | ** user and the latter is an internal programming error. |
| 77420 | 77702 | */ |
| 77421 | 77703 | SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem *pMem, u8 enc, u8 bForce){ |
| 77422 | 77704 | const int nByte = 32; |
| 77423 | 77705 | |
| 77706 | + assert( pMem!=0 ); |
| 77424 | 77707 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 77425 | 77708 | assert( !(pMem->flags&MEM_Zero) ); |
| 77426 | 77709 | assert( !(pMem->flags&(MEM_Str|MEM_Blob)) ); |
| 77427 | 77710 | assert( pMem->flags&(MEM_Int|MEM_Real|MEM_IntReal) ); |
| 77428 | 77711 | assert( !sqlite3VdbeMemIsRowSet(pMem) ); |
| | @@ -77454,10 +77737,11 @@ |
| 77454 | 77737 | */ |
| 77455 | 77738 | SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem *pMem, FuncDef *pFunc){ |
| 77456 | 77739 | sqlite3_context ctx; |
| 77457 | 77740 | Mem t; |
| 77458 | 77741 | assert( pFunc!=0 ); |
| 77742 | + assert( pMem!=0 ); |
| 77459 | 77743 | assert( pFunc->xFinalize!=0 ); |
| 77460 | 77744 | assert( (pMem->flags & MEM_Null)!=0 || pFunc==pMem->u.pDef ); |
| 77461 | 77745 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 77462 | 77746 | memset(&ctx, 0, sizeof(ctx)); |
| 77463 | 77747 | memset(&t, 0, sizeof(t)); |
| | @@ -77597,17 +77881,18 @@ |
| 77597 | 77881 | ** it into an integer and return that. If pMem represents an |
| 77598 | 77882 | ** an SQL-NULL value, return 0. |
| 77599 | 77883 | ** |
| 77600 | 77884 | ** If pMem represents a string value, its encoding might be changed. |
| 77601 | 77885 | */ |
| 77602 | | -static SQLITE_NOINLINE i64 memIntValue(Mem *pMem){ |
| 77886 | +static SQLITE_NOINLINE i64 memIntValue(const Mem *pMem){ |
| 77603 | 77887 | i64 value = 0; |
| 77604 | 77888 | sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc); |
| 77605 | 77889 | return value; |
| 77606 | 77890 | } |
| 77607 | | -SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem *pMem){ |
| 77891 | +SQLITE_PRIVATE i64 sqlite3VdbeIntValue(const Mem *pMem){ |
| 77608 | 77892 | int flags; |
| 77893 | + assert( pMem!=0 ); |
| 77609 | 77894 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 77610 | 77895 | assert( EIGHT_BYTE_ALIGNMENT(pMem) ); |
| 77611 | 77896 | flags = pMem->flags; |
| 77612 | 77897 | if( flags & (MEM_Int|MEM_IntReal) ){ |
| 77613 | 77898 | testcase( flags & MEM_IntReal ); |
| | @@ -77632,10 +77917,11 @@ |
| 77632 | 77917 | double val = (double)0; |
| 77633 | 77918 | sqlite3AtoF(pMem->z, &val, pMem->n, pMem->enc); |
| 77634 | 77919 | return val; |
| 77635 | 77920 | } |
| 77636 | 77921 | SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){ |
| 77922 | + assert( pMem!=0 ); |
| 77637 | 77923 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 77638 | 77924 | assert( EIGHT_BYTE_ALIGNMENT(pMem) ); |
| 77639 | 77925 | if( pMem->flags & MEM_Real ){ |
| 77640 | 77926 | return pMem->u.r; |
| 77641 | 77927 | }else if( pMem->flags & (MEM_Int|MEM_IntReal) ){ |
| | @@ -77664,10 +77950,11 @@ |
| 77664 | 77950 | ** The MEM structure is already a MEM_Real. Try to also make it a |
| 77665 | 77951 | ** MEM_Int if we can. |
| 77666 | 77952 | */ |
| 77667 | 77953 | SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem *pMem){ |
| 77668 | 77954 | i64 ix; |
| 77955 | + assert( pMem!=0 ); |
| 77669 | 77956 | assert( pMem->flags & MEM_Real ); |
| 77670 | 77957 | assert( !sqlite3VdbeMemIsRowSet(pMem) ); |
| 77671 | 77958 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 77672 | 77959 | assert( EIGHT_BYTE_ALIGNMENT(pMem) ); |
| 77673 | 77960 | |
| | @@ -77691,10 +77978,11 @@ |
| 77691 | 77978 | |
| 77692 | 77979 | /* |
| 77693 | 77980 | ** Convert pMem to type integer. Invalidate any prior representations. |
| 77694 | 77981 | */ |
| 77695 | 77982 | SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem *pMem){ |
| 77983 | + assert( pMem!=0 ); |
| 77696 | 77984 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 77697 | 77985 | assert( !sqlite3VdbeMemIsRowSet(pMem) ); |
| 77698 | 77986 | assert( EIGHT_BYTE_ALIGNMENT(pMem) ); |
| 77699 | 77987 | |
| 77700 | 77988 | pMem->u.i = sqlite3VdbeIntValue(pMem); |
| | @@ -77705,10 +77993,11 @@ |
| 77705 | 77993 | /* |
| 77706 | 77994 | ** Convert pMem so that it is of type MEM_Real. |
| 77707 | 77995 | ** Invalidate any prior representations. |
| 77708 | 77996 | */ |
| 77709 | 77997 | SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem *pMem){ |
| 77998 | + assert( pMem!=0 ); |
| 77710 | 77999 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 77711 | 78000 | assert( EIGHT_BYTE_ALIGNMENT(pMem) ); |
| 77712 | 78001 | |
| 77713 | 78002 | pMem->u.r = sqlite3VdbeRealValue(pMem); |
| 77714 | 78003 | MemSetTypeFlag(pMem, MEM_Real); |
| | @@ -77738,10 +78027,11 @@ |
| 77738 | 78027 | ** Every effort is made to force the conversion, even if the input |
| 77739 | 78028 | ** is a string that does not look completely like a number. Convert |
| 77740 | 78029 | ** as much of the string as we can and ignore the rest. |
| 77741 | 78030 | */ |
| 77742 | 78031 | SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem *pMem){ |
| 78032 | + assert( pMem!=0 ); |
| 77743 | 78033 | testcase( pMem->flags & MEM_Int ); |
| 77744 | 78034 | testcase( pMem->flags & MEM_Real ); |
| 77745 | 78035 | testcase( pMem->flags & MEM_IntReal ); |
| 77746 | 78036 | testcase( pMem->flags & MEM_Null ); |
| 77747 | 78037 | if( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null))==0 ){ |
| | @@ -77847,19 +78137,35 @@ |
| 77847 | 78137 | |
| 77848 | 78138 | /* |
| 77849 | 78139 | ** Delete any previous value and set the value to be a BLOB of length |
| 77850 | 78140 | ** n containing all zeros. |
| 77851 | 78141 | */ |
| 78142 | +#ifndef SQLITE_OMIT_INCRBLOB |
| 77852 | 78143 | SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){ |
| 77853 | 78144 | sqlite3VdbeMemRelease(pMem); |
| 77854 | 78145 | pMem->flags = MEM_Blob|MEM_Zero; |
| 77855 | 78146 | pMem->n = 0; |
| 77856 | 78147 | if( n<0 ) n = 0; |
| 77857 | 78148 | pMem->u.nZero = n; |
| 77858 | 78149 | pMem->enc = SQLITE_UTF8; |
| 77859 | 78150 | pMem->z = 0; |
| 77860 | 78151 | } |
| 78152 | +#else |
| 78153 | +SQLITE_PRIVATE int sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){ |
| 78154 | + int nByte = n>0?n:1; |
| 78155 | + if( sqlite3VdbeMemGrow(pMem, nByte, 0) ){ |
| 78156 | + return SQLITE_NOMEM_BKPT; |
| 78157 | + } |
| 78158 | + assert( pMem->z!=0 ); |
| 78159 | + assert( sqlite3DbMallocSize(pMem->db, pMem->z)>=nByte ); |
| 78160 | + memset(pMem->z, 0, nByte); |
| 78161 | + pMem->n = n>0?n:0; |
| 78162 | + pMem->flags = MEM_Blob; |
| 78163 | + pMem->enc = SQLITE_UTF8; |
| 78164 | + return SQLITE_OK; |
| 78165 | +} |
| 78166 | +#endif |
| 77861 | 78167 | |
| 77862 | 78168 | /* |
| 77863 | 78169 | ** The pMem is known to contain content that needs to be destroyed prior |
| 77864 | 78170 | ** to a value change. So invoke the destructor, then set the value to |
| 77865 | 78171 | ** a 64-bit integer. |
| | @@ -78089,10 +78395,11 @@ |
| 78089 | 78395 | ){ |
| 78090 | 78396 | i64 nByte = n; /* New value for pMem->n */ |
| 78091 | 78397 | int iLimit; /* Maximum allowed string or blob size */ |
| 78092 | 78398 | u16 flags = 0; /* New value for pMem->flags */ |
| 78093 | 78399 | |
| 78400 | + assert( pMem!=0 ); |
| 78094 | 78401 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 78095 | 78402 | assert( !sqlite3VdbeMemIsRowSet(pMem) ); |
| 78096 | 78403 | |
| 78097 | 78404 | /* If z is a NULL pointer, set pMem to contain an SQL NULL. */ |
| 78098 | 78405 | if( !z ){ |
| | @@ -78414,12 +78721,14 @@ |
| 78414 | 78721 | ExprList *pList = 0; /* Function arguments */ |
| 78415 | 78722 | int i; /* Iterator variable */ |
| 78416 | 78723 | |
| 78417 | 78724 | assert( pCtx!=0 ); |
| 78418 | 78725 | assert( (p->flags & EP_TokenOnly)==0 ); |
| 78726 | + assert( ExprUseXList(p) ); |
| 78419 | 78727 | pList = p->x.pList; |
| 78420 | 78728 | if( pList ) nVal = pList->nExpr; |
| 78729 | + assert( !ExprHasProperty(p, EP_IntValue) ); |
| 78421 | 78730 | pFunc = sqlite3FindFunction(db, p->u.zToken, nVal, enc, 0); |
| 78422 | 78731 | assert( pFunc ); |
| 78423 | 78732 | if( (pFunc->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0 |
| 78424 | 78733 | || (pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL) |
| 78425 | 78734 | ){ |
| | @@ -78519,11 +78828,13 @@ |
| 78519 | 78828 | ** check ensures that an EP_TokenOnly expression is never passed down |
| 78520 | 78829 | ** into valueFromFunction(). */ |
| 78521 | 78830 | assert( (pExpr->flags & EP_TokenOnly)==0 || pCtx==0 ); |
| 78522 | 78831 | |
| 78523 | 78832 | if( op==TK_CAST ){ |
| 78524 | | - u8 aff = sqlite3AffinityType(pExpr->u.zToken,0); |
| 78833 | + u8 aff; |
| 78834 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 78835 | + aff = sqlite3AffinityType(pExpr->u.zToken,0); |
| 78525 | 78836 | rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx); |
| 78526 | 78837 | testcase( rc!=SQLITE_OK ); |
| 78527 | 78838 | if( *ppVal ){ |
| 78528 | 78839 | sqlite3VdbeMemCast(*ppVal, aff, SQLITE_UTF8); |
| 78529 | 78840 | sqlite3ValueApplyAffinity(*ppVal, affinity, SQLITE_UTF8); |
| | @@ -78592,10 +78903,11 @@ |
| 78592 | 78903 | sqlite3VdbeMemSetNull(pVal); |
| 78593 | 78904 | } |
| 78594 | 78905 | #ifndef SQLITE_OMIT_BLOB_LITERAL |
| 78595 | 78906 | else if( op==TK_BLOB ){ |
| 78596 | 78907 | int nVal; |
| 78908 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 78597 | 78909 | assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' ); |
| 78598 | 78910 | assert( pExpr->u.zToken[1]=='\'' ); |
| 78599 | 78911 | pVal = valueNew(db, pCtx); |
| 78600 | 78912 | if( !pVal ) goto no_mem; |
| 78601 | 78913 | zVal = &pExpr->u.zToken[2]; |
| | @@ -78609,10 +78921,11 @@ |
| 78609 | 78921 | else if( op==TK_FUNCTION && pCtx!=0 ){ |
| 78610 | 78922 | rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx); |
| 78611 | 78923 | } |
| 78612 | 78924 | #endif |
| 78613 | 78925 | else if( op==TK_TRUEFALSE ){ |
| 78926 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 78614 | 78927 | pVal = valueNew(db, pCtx); |
| 78615 | 78928 | if( pVal ){ |
| 78616 | 78929 | pVal->flags = MEM_Int; |
| 78617 | 78930 | pVal->u.i = pExpr->u.zToken[4]==0; |
| 78618 | 78931 | } |
| | @@ -79162,12 +79475,14 @@ |
| 79162 | 79475 | assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); |
| 79163 | 79476 | assert( op>=0 && op<0xff ); |
| 79164 | 79477 | if( p->nOpAlloc<=i ){ |
| 79165 | 79478 | return growOp3(p, op, p1, p2, p3); |
| 79166 | 79479 | } |
| 79480 | + assert( p->aOp!=0 ); |
| 79167 | 79481 | p->nOp++; |
| 79168 | 79482 | pOp = &p->aOp[i]; |
| 79483 | + assert( pOp!=0 ); |
| 79169 | 79484 | pOp->opcode = (u8)op; |
| 79170 | 79485 | pOp->p5 = 0; |
| 79171 | 79486 | pOp->p1 = p1; |
| 79172 | 79487 | pOp->p2 = p2; |
| 79173 | 79488 | pOp->p3 = p3; |
| | @@ -80406,11 +80721,11 @@ |
| 80406 | 80721 | zOpName = sqlite3OpcodeName(pOp->opcode); |
| 80407 | 80722 | nOpName = sqlite3Strlen30(zOpName); |
| 80408 | 80723 | if( zOpName[nOpName+1] ){ |
| 80409 | 80724 | int seenCom = 0; |
| 80410 | 80725 | char c; |
| 80411 | | - zSynopsis = zOpName += nOpName + 1; |
| 80726 | + zSynopsis = zOpName + nOpName + 1; |
| 80412 | 80727 | if( strncmp(zSynopsis,"IF ",3)==0 ){ |
| 80413 | 80728 | sqlite3_snprintf(sizeof(zAlt), zAlt, "if %s goto P2", zSynopsis+3); |
| 80414 | 80729 | zSynopsis = zAlt; |
| 80415 | 80730 | } |
| 80416 | 80731 | for(ii=0; (c = zSynopsis[ii])!=0; ii++){ |
| | @@ -80479,10 +80794,11 @@ |
| 80479 | 80794 | */ |
| 80480 | 80795 | static void displayP4Expr(StrAccum *p, Expr *pExpr){ |
| 80481 | 80796 | const char *zOp = 0; |
| 80482 | 80797 | switch( pExpr->op ){ |
| 80483 | 80798 | case TK_STRING: |
| 80799 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 80484 | 80800 | sqlite3_str_appendf(p, "%Q", pExpr->u.zToken); |
| 80485 | 80801 | break; |
| 80486 | 80802 | case TK_INTEGER: |
| 80487 | 80803 | sqlite3_str_appendf(p, "%d", pExpr->u.iValue); |
| 80488 | 80804 | break; |
| | @@ -80825,12 +81141,12 @@ |
| 80825 | 81141 | ** with no indexes using a single prepared INSERT statement, bind() |
| 80826 | 81142 | ** and reset(). Inserts are grouped into a transaction. |
| 80827 | 81143 | */ |
| 80828 | 81144 | testcase( p->flags & MEM_Agg ); |
| 80829 | 81145 | testcase( p->flags & MEM_Dyn ); |
| 80830 | | - testcase( p->xDel==sqlite3VdbeFrameMemDel ); |
| 80831 | 81146 | if( p->flags&(MEM_Agg|MEM_Dyn) ){ |
| 81147 | + testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel ); |
| 80832 | 81148 | sqlite3VdbeMemRelease(p); |
| 80833 | 81149 | }else if( p->szMalloc ){ |
| 80834 | 81150 | sqlite3DbFreeNN(db, p->zMalloc); |
| 80835 | 81151 | p->szMalloc = 0; |
| 80836 | 81152 | } |
| | @@ -81974,13 +82290,19 @@ |
| 81974 | 82290 | |
| 81975 | 82291 | /* Lock all btrees used by the statement */ |
| 81976 | 82292 | sqlite3VdbeEnter(p); |
| 81977 | 82293 | |
| 81978 | 82294 | /* Check for one of the special errors */ |
| 81979 | | - mrc = p->rc & 0xff; |
| 81980 | | - isSpecialError = mrc==SQLITE_NOMEM || mrc==SQLITE_IOERR |
| 81981 | | - || mrc==SQLITE_INTERRUPT || mrc==SQLITE_FULL; |
| 82295 | + if( p->rc ){ |
| 82296 | + mrc = p->rc & 0xff; |
| 82297 | + isSpecialError = mrc==SQLITE_NOMEM |
| 82298 | + || mrc==SQLITE_IOERR |
| 82299 | + || mrc==SQLITE_INTERRUPT |
| 82300 | + || mrc==SQLITE_FULL; |
| 82301 | + }else{ |
| 82302 | + mrc = isSpecialError = 0; |
| 82303 | + } |
| 81982 | 82304 | if( isSpecialError ){ |
| 81983 | 82305 | /* If the query was read-only and the error code is SQLITE_INTERRUPT, |
| 81984 | 82306 | ** no rollback is necessary. Otherwise, at least a savepoint |
| 81985 | 82307 | ** transaction must be rolled back to restore the database to a |
| 81986 | 82308 | ** consistent state. |
| | @@ -82028,10 +82350,13 @@ |
| 82028 | 82350 | if( NEVER(p->readOnly) ){ |
| 82029 | 82351 | sqlite3VdbeLeave(p); |
| 82030 | 82352 | return SQLITE_ERROR; |
| 82031 | 82353 | } |
| 82032 | 82354 | rc = SQLITE_CONSTRAINT_FOREIGNKEY; |
| 82355 | + }else if( db->flags & SQLITE_CorruptRdOnly ){ |
| 82356 | + rc = SQLITE_CORRUPT; |
| 82357 | + db->flags &= ~SQLITE_CorruptRdOnly; |
| 82033 | 82358 | }else{ |
| 82034 | 82359 | /* The auto-commit flag is true, the vdbe program was successful |
| 82035 | 82360 | ** or hit an 'OR FAIL' constraint and there are no deferred foreign |
| 82036 | 82361 | ** key constraints to hold up the transaction. This means a commit |
| 82037 | 82362 | ** is required. */ |
| | @@ -84132,10 +84457,12 @@ |
| 84132 | 84457 | }else{ |
| 84133 | 84458 | iKey2 = iKey1; |
| 84134 | 84459 | } |
| 84135 | 84460 | } |
| 84136 | 84461 | |
| 84462 | + assert( pCsr!=0 ); |
| 84463 | + assert( pCsr->eCurType==CURTYPE_BTREE ); |
| 84137 | 84464 | assert( pCsr->nField==pTab->nCol |
| 84138 | 84465 | || (pCsr->nField==pTab->nCol+1 && op==SQLITE_DELETE && iReg==-1) |
| 84139 | 84466 | ); |
| 84140 | 84467 | |
| 84141 | 84468 | preupdate.v = v; |
| | @@ -84531,12 +84858,12 @@ |
| 84531 | 84858 | /**************************** sqlite3_result_ ******************************* |
| 84532 | 84859 | ** The following routines are used by user-defined functions to specify |
| 84533 | 84860 | ** the function result. |
| 84534 | 84861 | ** |
| 84535 | 84862 | ** The setStrOrError() function calls sqlite3VdbeMemSetStr() to store the |
| 84536 | | -** result as a string or blob but if the string or blob is too large, it |
| 84537 | | -** then sets the error code to SQLITE_TOOBIG |
| 84863 | +** result as a string or blob. Appropriate errors are set if the string/blob |
| 84864 | +** is too big or if an OOM occurs. |
| 84538 | 84865 | ** |
| 84539 | 84866 | ** The invokeValueDestructor(P,X) routine invokes destructor function X() |
| 84540 | 84867 | ** on value P is not going to be used and need to be destroyed. |
| 84541 | 84868 | */ |
| 84542 | 84869 | static void setResultStrOrError( |
| | @@ -84544,12 +84871,20 @@ |
| 84544 | 84871 | const char *z, /* String pointer */ |
| 84545 | 84872 | int n, /* Bytes in string, or negative */ |
| 84546 | 84873 | u8 enc, /* Encoding of z. 0 for BLOBs */ |
| 84547 | 84874 | void (*xDel)(void*) /* Destructor function */ |
| 84548 | 84875 | ){ |
| 84549 | | - if( sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel)==SQLITE_TOOBIG ){ |
| 84550 | | - sqlite3_result_error_toobig(pCtx); |
| 84876 | + int rc = sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel); |
| 84877 | + if( rc ){ |
| 84878 | + if( rc==SQLITE_TOOBIG ){ |
| 84879 | + sqlite3_result_error_toobig(pCtx); |
| 84880 | + }else{ |
| 84881 | + /* The only errors possible from sqlite3VdbeMemSetStr are |
| 84882 | + ** SQLITE_TOOBIG and SQLITE_NOMEM */ |
| 84883 | + assert( rc==SQLITE_NOMEM ); |
| 84884 | + sqlite3_result_error_nomem(pCtx); |
| 84885 | + } |
| 84551 | 84886 | } |
| 84552 | 84887 | } |
| 84553 | 84888 | static int invokeValueDestructor( |
| 84554 | 84889 | const void *p, /* Value to destroy */ |
| 84555 | 84890 | void (*xDel)(void*), /* The destructor */ |
| | @@ -84702,12 +85037,16 @@ |
| 84702 | 85037 | Mem *pOut = pCtx->pOut; |
| 84703 | 85038 | assert( sqlite3_mutex_held(pOut->db->mutex) ); |
| 84704 | 85039 | if( n>(u64)pOut->db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 84705 | 85040 | return SQLITE_TOOBIG; |
| 84706 | 85041 | } |
| 85042 | +#ifndef SQLITE_OMIT_INCRBLOB |
| 84707 | 85043 | sqlite3VdbeMemSetZeroBlob(pCtx->pOut, (int)n); |
| 84708 | 85044 | return SQLITE_OK; |
| 85045 | +#else |
| 85046 | + return sqlite3VdbeMemSetZeroBlob(pCtx->pOut, (int)n); |
| 85047 | +#endif |
| 84709 | 85048 | } |
| 84710 | 85049 | SQLITE_API void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){ |
| 84711 | 85050 | pCtx->isError = errCode ? errCode : -1; |
| 84712 | 85051 | #ifdef SQLITE_DEBUG |
| 84713 | 85052 | if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode; |
| | @@ -85715,11 +86054,15 @@ |
| 85715 | 86054 | SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){ |
| 85716 | 86055 | int rc; |
| 85717 | 86056 | Vdbe *p = (Vdbe *)pStmt; |
| 85718 | 86057 | rc = vdbeUnbind(p, i); |
| 85719 | 86058 | if( rc==SQLITE_OK ){ |
| 86059 | +#ifndef SQLITE_OMIT_INCRBLOB |
| 85720 | 86060 | sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n); |
| 86061 | +#else |
| 86062 | + rc = sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n); |
| 86063 | +#endif |
| 85721 | 86064 | sqlite3_mutex_leave(p->db->mutex); |
| 85722 | 86065 | } |
| 85723 | 86066 | return rc; |
| 85724 | 86067 | } |
| 85725 | 86068 | SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt *pStmt, int i, sqlite3_uint64 n){ |
| | @@ -86003,10 +86346,11 @@ |
| 86003 | 86346 | /* If the old.* record has not yet been loaded into memory, do so now. */ |
| 86004 | 86347 | if( p->pUnpacked==0 ){ |
| 86005 | 86348 | u32 nRec; |
| 86006 | 86349 | u8 *aRec; |
| 86007 | 86350 | |
| 86351 | + assert( p->pCsr->eCurType==CURTYPE_BTREE ); |
| 86008 | 86352 | nRec = sqlite3BtreePayloadSize(p->pCsr->uc.pCursor); |
| 86009 | 86353 | aRec = sqlite3DbMallocRaw(db, nRec); |
| 86010 | 86354 | if( !aRec ) goto preupdate_old_out; |
| 86011 | 86355 | rc = sqlite3BtreePayload(p->pCsr->uc.pCursor, 0, nRec, aRec); |
| 86012 | 86356 | if( rc==SQLITE_OK ){ |
| | @@ -87091,10 +87435,35 @@ |
| 87091 | 87435 | }else{ |
| 87092 | 87436 | pOut->flags = MEM_Int; |
| 87093 | 87437 | return pOut; |
| 87094 | 87438 | } |
| 87095 | 87439 | } |
| 87440 | + |
| 87441 | +/* |
| 87442 | +** Compute a bloom filter hash using pOp->p4.i registers from aMem[] beginning |
| 87443 | +** with pOp->p3. Return the hash. |
| 87444 | +*/ |
| 87445 | +static u64 filterHash(const Mem *aMem, const Op *pOp){ |
| 87446 | + int i, mx; |
| 87447 | + u64 h = 0; |
| 87448 | + |
| 87449 | + i = pOp->p3; |
| 87450 | + assert( pOp->p4type==P4_INT32 ); |
| 87451 | + mx = i + pOp->p4.i; |
| 87452 | + for(i=pOp->p3, mx=i+pOp->p4.i; i<mx; i++){ |
| 87453 | + const Mem *p = &aMem[i]; |
| 87454 | + if( p->flags & (MEM_Int|MEM_IntReal) ){ |
| 87455 | + h += p->u.i; |
| 87456 | + }else if( p->flags & MEM_Real ){ |
| 87457 | + h += sqlite3VdbeIntValue(p); |
| 87458 | + }else if( p->flags & (MEM_Str|MEM_Blob) ){ |
| 87459 | + h += p->n; |
| 87460 | + if( p->flags & MEM_Zero ) h += p->u.nZero; |
| 87461 | + } |
| 87462 | + } |
| 87463 | + return h; |
| 87464 | +} |
| 87096 | 87465 | |
| 87097 | 87466 | /* |
| 87098 | 87467 | ** Return the symbolic name for the data type of a pMem |
| 87099 | 87468 | */ |
| 87100 | 87469 | static const char *vdbeMemTypeName(Mem *pMem){ |
| | @@ -87746,16 +88115,22 @@ |
| 87746 | 88115 | |
| 87747 | 88116 | /* Opcode: Blob P1 P2 * P4 * |
| 87748 | 88117 | ** Synopsis: r[P2]=P4 (len=P1) |
| 87749 | 88118 | ** |
| 87750 | 88119 | ** P4 points to a blob of data P1 bytes long. Store this |
| 87751 | | -** blob in register P2. |
| 88120 | +** blob in register P2. If P4 is a NULL pointer, then construct |
| 88121 | +** a zero-filled blob that is P1 bytes long in P2. |
| 87752 | 88122 | */ |
| 87753 | 88123 | case OP_Blob: { /* out2 */ |
| 87754 | 88124 | assert( pOp->p1 <= SQLITE_MAX_LENGTH ); |
| 87755 | 88125 | pOut = out2Prerelease(p, pOp); |
| 87756 | | - sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0); |
| 88126 | + if( pOp->p4.z==0 ){ |
| 88127 | + sqlite3VdbeMemSetZeroBlob(pOut, pOp->p1); |
| 88128 | + if( sqlite3VdbeMemExpandBlob(pOut) ) goto no_mem; |
| 88129 | + }else{ |
| 88130 | + sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0); |
| 88131 | + } |
| 87757 | 88132 | pOut->enc = encoding; |
| 87758 | 88133 | UPDATE_MAX_BLOBSIZE(pOut); |
| 87759 | 88134 | break; |
| 87760 | 88135 | } |
| 87761 | 88136 | |
| | @@ -87900,28 +88275,26 @@ |
| 87900 | 88275 | pOut = &aMem[pOp->p2]; |
| 87901 | 88276 | sqlite3VdbeMemSetInt64(pOut, pIn1->u.i); |
| 87902 | 88277 | break; |
| 87903 | 88278 | } |
| 87904 | 88279 | |
| 87905 | | -/* Opcode: ChngCntRow P1 P2 * * * |
| 87906 | | -** Synopsis: output=r[P1] |
| 87907 | | -** |
| 87908 | | -** Output value in register P1 as the chance count for a DML statement, |
| 87909 | | -** due to the "PRAGMA count_changes=ON" setting. Or, if there was a |
| 87910 | | -** foreign key error in the statement, trigger the error now. |
| 87911 | | -** |
| 87912 | | -** This opcode is a variant of OP_ResultRow that checks the foreign key |
| 87913 | | -** immediate constraint count and throws an error if the count is |
| 87914 | | -** non-zero. The P2 opcode must be 1. |
| 87915 | | -*/ |
| 87916 | | -case OP_ChngCntRow: { |
| 87917 | | - assert( pOp->p2==1 ); |
| 88280 | +/* Opcode: FkCheck * * * * * |
| 88281 | +** |
| 88282 | +** Halt with an SQLITE_CONSTRAINT error if there are any unresolved |
| 88283 | +** foreign key constraint violations. If there are no foreign key |
| 88284 | +** constraint violations, this is a no-op. |
| 88285 | +** |
| 88286 | +** FK constraint violations are also checked when the prepared statement |
| 88287 | +** exits. This opcode is used to raise foreign key constraint errors prior |
| 88288 | +** to returning results such as a row change count or the result of a |
| 88289 | +** RETURNING clause. |
| 88290 | +*/ |
| 88291 | +case OP_FkCheck: { |
| 87918 | 88292 | if( (rc = sqlite3VdbeCheckFk(p,0))!=SQLITE_OK ){ |
| 87919 | 88293 | goto abort_due_to_error; |
| 87920 | 88294 | } |
| 87921 | | - /* Fall through to the next case, OP_ResultRow */ |
| 87922 | | - /* no break */ deliberate_fall_through |
| 88295 | + break; |
| 87923 | 88296 | } |
| 87924 | 88297 | |
| 87925 | 88298 | /* Opcode: ResultRow P1 P2 * * * |
| 87926 | 88299 | ** Synopsis: output=r[P1@P2] |
| 87927 | 88300 | ** |
| | @@ -89320,20 +89693,25 @@ |
| 89320 | 89693 | rc = SQLITE_CORRUPT_BKPT; |
| 89321 | 89694 | goto abort_due_to_error; |
| 89322 | 89695 | } |
| 89323 | 89696 | } |
| 89324 | 89697 | |
| 89325 | | -/* Opcode: TypeCheck P1 P2 * P4 * |
| 89698 | +/* Opcode: TypeCheck P1 P2 P3 P4 * |
| 89326 | 89699 | ** Synopsis: typecheck(r[P1@P2]) |
| 89327 | 89700 | ** |
| 89328 | 89701 | ** Apply affinities to the range of P2 registers beginning with P1. |
| 89329 | 89702 | ** Take the affinities from the Table object in P4. If any value |
| 89330 | 89703 | ** cannot be coerced into the correct type, then raise an error. |
| 89331 | 89704 | ** |
| 89332 | 89705 | ** This opcode is similar to OP_Affinity except that this opcode |
| 89333 | 89706 | ** forces the register type to the Table column type. This is used |
| 89334 | 89707 | ** to implement "strict affinity". |
| 89708 | +** |
| 89709 | +** GENERATED ALWAYS AS ... STATIC columns are only checked if P3 |
| 89710 | +** is zero. When P3 is non-zero, no type checking occurs for |
| 89711 | +** static generated columns. Virtual columns are computed at query time |
| 89712 | +** and so they are never checked. |
| 89335 | 89713 | ** |
| 89336 | 89714 | ** Preconditions: |
| 89337 | 89715 | ** |
| 89338 | 89716 | ** <ul> |
| 89339 | 89717 | ** <li> P2 should be the number of non-virtual columns in the |
| | @@ -89353,11 +89731,14 @@ |
| 89353 | 89731 | assert( pTab->tabFlags & TF_Strict ); |
| 89354 | 89732 | assert( pTab->nNVCol==pOp->p2 ); |
| 89355 | 89733 | aCol = pTab->aCol; |
| 89356 | 89734 | pIn1 = &aMem[pOp->p1]; |
| 89357 | 89735 | for(i=0; i<pTab->nCol; i++){ |
| 89358 | | - if( aCol[i].colFlags & COLFLAG_VIRTUAL ) continue; |
| 89736 | + if( aCol[i].colFlags & COLFLAG_GENERATED ){ |
| 89737 | + if( aCol[i].colFlags & COLFLAG_VIRTUAL ) continue; |
| 89738 | + if( pOp->p3 ){ pIn1++; continue; } |
| 89739 | + } |
| 89359 | 89740 | assert( pIn1 < &aMem[pOp->p1+pOp->p2] ); |
| 89360 | 89741 | applyAffinity(pIn1, aCol[i].affinity, encoding); |
| 89361 | 89742 | if( (pIn1->flags & MEM_Null)==0 ){ |
| 89362 | 89743 | switch( aCol[i].eCType ){ |
| 89363 | 89744 | case COLTYPE_BLOB: { |
| | @@ -89756,11 +90137,11 @@ |
| 89756 | 90137 | assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); |
| 89757 | 90138 | REGISTER_TRACE(pOp->p3, pOut); |
| 89758 | 90139 | break; |
| 89759 | 90140 | } |
| 89760 | 90141 | |
| 89761 | | -/* Opcode: Count P1 P2 p3 * * |
| 90142 | +/* Opcode: Count P1 P2 P3 * * |
| 89762 | 90143 | ** Synopsis: r[P2]=count() |
| 89763 | 90144 | ** |
| 89764 | 90145 | ** Store the number of entries (an integer value) in the table or index |
| 89765 | 90146 | ** opened by cursor P1 in register P2. |
| 89766 | 90147 | ** |
| | @@ -90077,12 +90458,20 @@ |
| 90077 | 90458 | assert( p->bIsReader ); |
| 90078 | 90459 | assert( p->readOnly==0 || pOp->p2==0 ); |
| 90079 | 90460 | assert( pOp->p2>=0 && pOp->p2<=2 ); |
| 90080 | 90461 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 90081 | 90462 | assert( DbMaskTest(p->btreeMask, pOp->p1) ); |
| 90082 | | - if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){ |
| 90083 | | - rc = SQLITE_READONLY; |
| 90463 | + assert( rc==SQLITE_OK ); |
| 90464 | + if( pOp->p2 && (db->flags & (SQLITE_QueryOnly|SQLITE_CorruptRdOnly))!=0 ){ |
| 90465 | + if( db->flags & SQLITE_QueryOnly ){ |
| 90466 | + /* Writes prohibited by the "PRAGMA query_only=TRUE" statement */ |
| 90467 | + rc = SQLITE_READONLY; |
| 90468 | + }else{ |
| 90469 | + /* Writes prohibited due to a prior SQLITE_CORRUPT in the current |
| 90470 | + ** transaction */ |
| 90471 | + rc = SQLITE_CORRUPT; |
| 90472 | + } |
| 90084 | 90473 | goto abort_due_to_error; |
| 90085 | 90474 | } |
| 90086 | 90475 | pBt = db->aDb[pOp->p1].pBt; |
| 90087 | 90476 | |
| 90088 | 90477 | if( pBt ){ |
| | @@ -90120,11 +90509,12 @@ |
| 90120 | 90509 | p->nStmtDefCons = db->nDeferredCons; |
| 90121 | 90510 | p->nStmtDefImmCons = db->nDeferredImmCons; |
| 90122 | 90511 | } |
| 90123 | 90512 | } |
| 90124 | 90513 | assert( pOp->p5==0 || pOp->p4type==P4_INT32 ); |
| 90125 | | - if( pOp->p5 |
| 90514 | + if( rc==SQLITE_OK |
| 90515 | + && pOp->p5 |
| 90126 | 90516 | && (iMeta!=pOp->p3 |
| 90127 | 90517 | || db->aDb[pOp->p1].pSchema->iGeneration!=pOp->p4.i) |
| 90128 | 90518 | ){ |
| 90129 | 90519 | /* |
| 90130 | 90520 | ** IMPLEMENTATION-OF: R-03189-51135 As each SQL statement runs, the schema |
| | @@ -90514,11 +90904,11 @@ |
| 90514 | 90904 | assert( aMem[pOp->p3].flags & MEM_Null ); |
| 90515 | 90905 | aMem[pOp->p3].n = 0; |
| 90516 | 90906 | aMem[pOp->p3].z = ""; |
| 90517 | 90907 | } |
| 90518 | 90908 | pCx = p->apCsr[pOp->p1]; |
| 90519 | | - if( pCx && !pCx->hasBeenDuped ){ |
| 90909 | + if( pCx && !pCx->hasBeenDuped && ALWAYS(pOp->p2<=pCx->nField) ){ |
| 90520 | 90910 | /* If the ephermeral table is already open and has no duplicates from |
| 90521 | 90911 | ** OP_OpenDup, then erase all existing content so that the table is |
| 90522 | 90912 | ** empty again, rather than creating a new table. */ |
| 90523 | 90913 | assert( pCx->isEphemeral ); |
| 90524 | 90914 | pCx->seqCount = 0; |
| | @@ -91677,11 +92067,11 @@ |
| 91677 | 92067 | zDb = db->aDb[pC->iDb].zDbSName; |
| 91678 | 92068 | pTab = pOp->p4.pTab; |
| 91679 | 92069 | assert( (pOp->p5 & OPFLAG_ISNOOP) || HasRowid(pTab) ); |
| 91680 | 92070 | }else{ |
| 91681 | 92071 | pTab = 0; |
| 91682 | | - zDb = 0; /* Not needed. Silence a compiler warning. */ |
| 92072 | + zDb = 0; |
| 91683 | 92073 | } |
| 91684 | 92074 | |
| 91685 | 92075 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 91686 | 92076 | /* Invoke the pre-update hook, if any */ |
| 91687 | 92077 | if( pTab ){ |
| | @@ -91830,17 +92220,18 @@ |
| 91830 | 92220 | pTab = pOp->p4.pTab; |
| 91831 | 92221 | if( (pOp->p5 & OPFLAG_SAVEPOSITION)!=0 && pC->isTable ){ |
| 91832 | 92222 | pC->movetoTarget = sqlite3BtreeIntegerKey(pC->uc.pCursor); |
| 91833 | 92223 | } |
| 91834 | 92224 | }else{ |
| 91835 | | - zDb = 0; /* Not needed. Silence a compiler warning. */ |
| 91836 | | - pTab = 0; /* Not needed. Silence a compiler warning. */ |
| 92225 | + zDb = 0; |
| 92226 | + pTab = 0; |
| 91837 | 92227 | } |
| 91838 | 92228 | |
| 91839 | 92229 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 91840 | 92230 | /* Invoke the pre-update-hook if required. */ |
| 91841 | | - if( db->xPreUpdateCallback && pOp->p4.pTab ){ |
| 92231 | + assert( db->xPreUpdateCallback==0 || pTab==pOp->p4.pTab ); |
| 92232 | + if( db->xPreUpdateCallback && pTab ){ |
| 91842 | 92233 | assert( !(opflags & OPFLAG_ISUPDATE) |
| 91843 | 92234 | || HasRowid(pTab)==0 |
| 91844 | 92235 | || (aMem[pOp->p3].flags & MEM_Int) |
| 91845 | 92236 | ); |
| 91846 | 92237 | sqlite3VdbePreUpdateHook(p, pC, |
| | @@ -91877,11 +92268,11 @@ |
| 91877 | 92268 | if( rc ) goto abort_due_to_error; |
| 91878 | 92269 | |
| 91879 | 92270 | /* Invoke the update-hook if required. */ |
| 91880 | 92271 | if( opflags & OPFLAG_NCHANGE ){ |
| 91881 | 92272 | p->nChange++; |
| 91882 | | - if( db->xUpdateCallback && HasRowid(pTab) ){ |
| 92273 | + if( db->xUpdateCallback && ALWAYS(pTab!=0) && HasRowid(pTab) ){ |
| 91883 | 92274 | db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, zDb, pTab->zName, |
| 91884 | 92275 | pC->movetoTarget); |
| 91885 | 92276 | assert( pC->iDb>=0 ); |
| 91886 | 92277 | } |
| 91887 | 92278 | } |
| | @@ -92925,11 +93316,11 @@ |
| 92925 | 93316 | db->mDbFlags |= DBFLAG_SchemaChange; |
| 92926 | 93317 | p->expired = 0; |
| 92927 | 93318 | }else |
| 92928 | 93319 | #endif |
| 92929 | 93320 | { |
| 92930 | | - zSchema = DFLT_SCHEMA_TABLE; |
| 93321 | + zSchema = LEGACY_SCHEMA_TABLE; |
| 92931 | 93322 | initData.db = db; |
| 92932 | 93323 | initData.iDb = iDb; |
| 92933 | 93324 | initData.pzErrMsg = &p->zErrMsg; |
| 92934 | 93325 | initData.mInitFlags = 0; |
| 92935 | 93326 | initData.mxPage = sqlite3BtreeLastPage(db->aDb[iDb].pBt); |
| | @@ -94145,10 +94536,11 @@ |
| 94145 | 94536 | pQuery = &aMem[pOp->p3]; |
| 94146 | 94537 | pArgc = &pQuery[1]; |
| 94147 | 94538 | pCur = p->apCsr[pOp->p1]; |
| 94148 | 94539 | assert( memIsValid(pQuery) ); |
| 94149 | 94540 | REGISTER_TRACE(pOp->p3, pQuery); |
| 94541 | + assert( pCur!=0 ); |
| 94150 | 94542 | assert( pCur->eCurType==CURTYPE_VTAB ); |
| 94151 | 94543 | pVCur = pCur->uc.pVCur; |
| 94152 | 94544 | pVtab = pVCur->pVtab; |
| 94153 | 94545 | pModule = pVtab->pModule; |
| 94154 | 94546 | |
| | @@ -94193,10 +94585,11 @@ |
| 94193 | 94585 | const sqlite3_module *pModule; |
| 94194 | 94586 | Mem *pDest; |
| 94195 | 94587 | sqlite3_context sContext; |
| 94196 | 94588 | |
| 94197 | 94589 | VdbeCursor *pCur = p->apCsr[pOp->p1]; |
| 94590 | + assert( pCur!=0 ); |
| 94198 | 94591 | assert( pCur->eCurType==CURTYPE_VTAB ); |
| 94199 | 94592 | assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); |
| 94200 | 94593 | pDest = &aMem[pOp->p3]; |
| 94201 | 94594 | memAboutToChange(p, pDest); |
| 94202 | 94595 | if( pCur->nullRow ){ |
| | @@ -94246,10 +94639,11 @@ |
| 94246 | 94639 | const sqlite3_module *pModule; |
| 94247 | 94640 | int res; |
| 94248 | 94641 | VdbeCursor *pCur; |
| 94249 | 94642 | |
| 94250 | 94643 | pCur = p->apCsr[pOp->p1]; |
| 94644 | + assert( pCur!=0 ); |
| 94251 | 94645 | assert( pCur->eCurType==CURTYPE_VTAB ); |
| 94252 | 94646 | if( pCur->nullRow ){ |
| 94253 | 94647 | break; |
| 94254 | 94648 | } |
| 94255 | 94649 | pVtab = pCur->uc.pVCur->pVtab; |
| | @@ -94341,11 +94735,11 @@ |
| 94341 | 94735 | case OP_VUpdate: { |
| 94342 | 94736 | sqlite3_vtab *pVtab; |
| 94343 | 94737 | const sqlite3_module *pModule; |
| 94344 | 94738 | int nArg; |
| 94345 | 94739 | int i; |
| 94346 | | - sqlite_int64 rowid; |
| 94740 | + sqlite_int64 rowid = 0; |
| 94347 | 94741 | Mem **apArg; |
| 94348 | 94742 | Mem *pX; |
| 94349 | 94743 | |
| 94350 | 94744 | assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback |
| 94351 | 94745 | || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace |
| | @@ -94528,10 +94922,81 @@ |
| 94528 | 94922 | |
| 94529 | 94923 | REGISTER_TRACE(pOp->p3, pOut); |
| 94530 | 94924 | UPDATE_MAX_BLOBSIZE(pOut); |
| 94531 | 94925 | break; |
| 94532 | 94926 | } |
| 94927 | + |
| 94928 | +/* Opcode: FilterAdd P1 * P3 P4 * |
| 94929 | +** Synopsis: filter(P1) += key(P3@P4) |
| 94930 | +** |
| 94931 | +** Compute a hash on the P4 registers starting with r[P3] and |
| 94932 | +** add that hash to the bloom filter contained in r[P1]. |
| 94933 | +*/ |
| 94934 | +case OP_FilterAdd: { |
| 94935 | + u64 h; |
| 94936 | + |
| 94937 | + assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) ); |
| 94938 | + pIn1 = &aMem[pOp->p1]; |
| 94939 | + assert( pIn1->flags & MEM_Blob ); |
| 94940 | + assert( pIn1->n>0 ); |
| 94941 | + h = filterHash(aMem, pOp); |
| 94942 | +#ifdef SQLITE_DEBUG |
| 94943 | + if( db->flags&SQLITE_VdbeTrace ){ |
| 94944 | + int ii; |
| 94945 | + for(ii=pOp->p3; ii<pOp->p3+pOp->p4.i; ii++){ |
| 94946 | + registerTrace(ii, &aMem[ii]); |
| 94947 | + } |
| 94948 | + printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n)); |
| 94949 | + } |
| 94950 | +#endif |
| 94951 | + h %= pIn1->n; |
| 94952 | + pIn1->z[h/8] |= 1<<(h&7); |
| 94953 | + break; |
| 94954 | +} |
| 94955 | + |
| 94956 | +/* Opcode: Filter P1 P2 P3 P4 * |
| 94957 | +** Synopsis: if key(P3@P4) not in filter(P1) goto P2 |
| 94958 | +** |
| 94959 | +** Compute a hash on the key contained in the P4 registers starting |
| 94960 | +** with r[P3]. Check to see if that hash is found in the |
| 94961 | +** bloom filter hosted by register P1. If it is not present then |
| 94962 | +** maybe jump to P2. Otherwise fall through. |
| 94963 | +** |
| 94964 | +** False negatives are harmless. It is always safe to fall through, |
| 94965 | +** even if the value is in the bloom filter. A false negative causes |
| 94966 | +** more CPU cycles to be used, but it should still yield the correct |
| 94967 | +** answer. However, an incorrect answer may well arise from a |
| 94968 | +** false positive - if the jump is taken when it should fall through. |
| 94969 | +*/ |
| 94970 | +case OP_Filter: { /* jump */ |
| 94971 | + u64 h; |
| 94972 | + |
| 94973 | + assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) ); |
| 94974 | + pIn1 = &aMem[pOp->p1]; |
| 94975 | + assert( (pIn1->flags & MEM_Blob)!=0 ); |
| 94976 | + assert( pIn1->n >= 1 ); |
| 94977 | + h = filterHash(aMem, pOp); |
| 94978 | +#ifdef SQLITE_DEBUG |
| 94979 | + if( db->flags&SQLITE_VdbeTrace ){ |
| 94980 | + int ii; |
| 94981 | + for(ii=pOp->p3; ii<pOp->p3+pOp->p4.i; ii++){ |
| 94982 | + registerTrace(ii, &aMem[ii]); |
| 94983 | + } |
| 94984 | + printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n)); |
| 94985 | + } |
| 94986 | +#endif |
| 94987 | + h %= pIn1->n; |
| 94988 | + if( (pIn1->z[h/8] & (1<<(h&7)))==0 ){ |
| 94989 | + VdbeBranchTaken(1, 2); |
| 94990 | + p->aCounter[SQLITE_STMTSTATUS_FILTER_HIT]++; |
| 94991 | + goto jump_to_p2; |
| 94992 | + }else{ |
| 94993 | + p->aCounter[SQLITE_STMTSTATUS_FILTER_MISS]++; |
| 94994 | + VdbeBranchTaken(0, 2); |
| 94995 | + } |
| 94996 | + break; |
| 94997 | +} |
| 94533 | 94998 | |
| 94534 | 94999 | /* Opcode: Trace P1 P2 * P4 * |
| 94535 | 95000 | ** |
| 94536 | 95001 | ** Write P4 on the statement trace output if statement tracing is |
| 94537 | 95002 | ** enabled. |
| | @@ -94788,11 +95253,18 @@ |
| 94788 | 95253 | rc = SQLITE_CORRUPT_BKPT; |
| 94789 | 95254 | } |
| 94790 | 95255 | assert( rc ); |
| 94791 | 95256 | #ifdef SQLITE_DEBUG |
| 94792 | 95257 | if( db->flags & SQLITE_VdbeTrace ){ |
| 94793 | | - printf("ABORT-due-to-error. rc=%d\n", rc); |
| 95258 | + const char *zTrace = p->zSql; |
| 95259 | + if( zTrace==0 ){ |
| 95260 | + if( aOp[0].opcode==OP_Trace ){ |
| 95261 | + zTrace = aOp[0].p4.z; |
| 95262 | + } |
| 95263 | + if( zTrace==0 ) zTrace = "???"; |
| 95264 | + } |
| 95265 | + printf("ABORT-due-to-error (rc=%d): %s\n", rc, zTrace); |
| 94794 | 95266 | } |
| 94795 | 95267 | #endif |
| 94796 | 95268 | if( p->zErrMsg==0 && rc!=SQLITE_IOERR_NOMEM ){ |
| 94797 | 95269 | sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc)); |
| 94798 | 95270 | } |
| | @@ -94801,10 +95273,13 @@ |
| 94801 | 95273 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 94802 | 95274 | sqlite3_log(rc, "statement aborts at %d: [%s] %s", |
| 94803 | 95275 | (int)(pOp - aOp), p->zSql, p->zErrMsg); |
| 94804 | 95276 | sqlite3VdbeHalt(p); |
| 94805 | 95277 | if( rc==SQLITE_IOERR_NOMEM ) sqlite3OomFault(db); |
| 95278 | + if( rc==SQLITE_CORRUPT && db->autoCommit==0 ){ |
| 95279 | + db->flags |= SQLITE_CorruptRdOnly; |
| 95280 | + } |
| 94806 | 95281 | rc = SQLITE_ERROR; |
| 94807 | 95282 | if( resetSchemaOnFault>0 ){ |
| 94808 | 95283 | sqlite3ResetOneSchema(db, resetSchemaOnFault-1); |
| 94809 | 95284 | } |
| 94810 | 95285 | |
| | @@ -94932,11 +95407,14 @@ |
| 94932 | 95407 | }else{ |
| 94933 | 95408 | rc = sqlite3_step(p->pStmt); |
| 94934 | 95409 | } |
| 94935 | 95410 | if( rc==SQLITE_ROW ){ |
| 94936 | 95411 | VdbeCursor *pC = v->apCsr[0]; |
| 94937 | | - u32 type = pC->nHdrParsed>p->iCol ? pC->aType[p->iCol] : 0; |
| 95412 | + u32 type; |
| 95413 | + assert( pC!=0 ); |
| 95414 | + assert( pC->eCurType==CURTYPE_BTREE ); |
| 95415 | + type = pC->nHdrParsed>p->iCol ? pC->aType[p->iCol] : 0; |
| 94938 | 95416 | testcase( pC->nHdrParsed==p->iCol ); |
| 94939 | 95417 | testcase( pC->nHdrParsed==p->iCol+1 ); |
| 94940 | 95418 | if( type<12 ){ |
| 94941 | 95419 | zErr = sqlite3MPrintf(p->db, "cannot open value of type %s", |
| 94942 | 95420 | type==0?"null": type==7?"real": "integer" |
| | @@ -95069,11 +95547,11 @@ |
| 95069 | 95547 | /* Check that the column is not part of an FK child key definition. It |
| 95070 | 95548 | ** is not necessary to check if it is part of a parent key, as parent |
| 95071 | 95549 | ** key columns must be indexed. The check below will pick up this |
| 95072 | 95550 | ** case. */ |
| 95073 | 95551 | FKey *pFKey; |
| 95074 | | - assert( !IsVirtual(pTab) ); |
| 95552 | + assert( IsOrdinaryTable(pTab) ); |
| 95075 | 95553 | for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 95076 | 95554 | int j; |
| 95077 | 95555 | for(j=0; j<pFKey->nCol; j++){ |
| 95078 | 95556 | if( pFKey->aCol[j].iFrom==iCol ){ |
| 95079 | 95557 | zFault = "foreign key"; |
| | @@ -95277,10 +95755,12 @@ |
| 95277 | 95755 | ** using the incremental-blob API, this works. For the sessions module |
| 95278 | 95756 | ** anyhow. |
| 95279 | 95757 | */ |
| 95280 | 95758 | sqlite3_int64 iKey; |
| 95281 | 95759 | iKey = sqlite3BtreeIntegerKey(p->pCsr); |
| 95760 | + assert( v->apCsr[0]!=0 ); |
| 95761 | + assert( v->apCsr[0]->eCurType==CURTYPE_BTREE ); |
| 95282 | 95762 | sqlite3VdbePreUpdateHook( |
| 95283 | 95763 | v, v->apCsr[0], SQLITE_DELETE, p->zDb, p->pTab, iKey, -1, p->iCol |
| 95284 | 95764 | ); |
| 95285 | 95765 | } |
| 95286 | 95766 | #endif |
| | @@ -96659,11 +97139,11 @@ |
| 96659 | 97139 | void *p = 0; |
| 96660 | 97140 | int chunksize = 4*1024; |
| 96661 | 97141 | sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_CHUNK_SIZE, &chunksize); |
| 96662 | 97142 | sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_SIZE_HINT, &nByte); |
| 96663 | 97143 | sqlite3OsFetch(pFd, 0, (int)nByte, &p); |
| 96664 | | - sqlite3OsUnfetch(pFd, 0, p); |
| 97144 | + if( p ) sqlite3OsUnfetch(pFd, 0, p); |
| 96665 | 97145 | } |
| 96666 | 97146 | } |
| 96667 | 97147 | #else |
| 96668 | 97148 | # define vdbeSorterExtendFile(x,y,z) |
| 96669 | 97149 | #endif |
| | @@ -97377,10 +97857,11 @@ |
| 97377 | 97857 | pTask->file2.iEof += pIncr->mxSz; |
| 97378 | 97858 | }else{ |
| 97379 | 97859 | vdbeMergeEngineFree(pMerger); |
| 97380 | 97860 | rc = SQLITE_NOMEM_BKPT; |
| 97381 | 97861 | } |
| 97862 | + assert( *ppOut!=0 || rc!=SQLITE_OK ); |
| 97382 | 97863 | return rc; |
| 97383 | 97864 | } |
| 97384 | 97865 | |
| 97385 | 97866 | #if SQLITE_MAX_WORKER_THREADS>0 |
| 97386 | 97867 | /* |
| | @@ -99078,11 +99559,11 @@ |
| 99078 | 99559 | if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort; |
| 99079 | 99560 | if( pExpr->pRight ){ |
| 99080 | 99561 | assert( !ExprHasProperty(pExpr, EP_WinFunc) ); |
| 99081 | 99562 | pExpr = pExpr->pRight; |
| 99082 | 99563 | continue; |
| 99083 | | - }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 99564 | + }else if( ExprUseXSelect(pExpr) ){ |
| 99084 | 99565 | assert( !ExprHasProperty(pExpr, EP_WinFunc) ); |
| 99085 | 99566 | if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort; |
| 99086 | 99567 | }else{ |
| 99087 | 99568 | if( pExpr->x.pList ){ |
| 99088 | 99569 | if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort; |
| | @@ -99350,10 +99831,11 @@ |
| 99350 | 99831 | sqlite3ExprDelete(db, pDup); |
| 99351 | 99832 | pDup = 0; |
| 99352 | 99833 | }else{ |
| 99353 | 99834 | incrAggFunctionDepth(pDup, nSubquery); |
| 99354 | 99835 | if( pExpr->op==TK_COLLATE ){ |
| 99836 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 99355 | 99837 | pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken); |
| 99356 | 99838 | } |
| 99357 | 99839 | |
| 99358 | 99840 | /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This |
| 99359 | 99841 | ** prevents ExprDelete() from deleting the Expr structure itself, |
| | @@ -99453,10 +99935,11 @@ |
| 99453 | 99935 | SQLITE_PRIVATE Bitmask sqlite3ExprColUsed(Expr *pExpr){ |
| 99454 | 99936 | int n; |
| 99455 | 99937 | Table *pExTab; |
| 99456 | 99938 | |
| 99457 | 99939 | n = pExpr->iColumn; |
| 99940 | + assert( ExprUseYTab(pExpr) ); |
| 99458 | 99941 | pExTab = pExpr->y.pTab; |
| 99459 | 99942 | assert( pExTab!=0 ); |
| 99460 | 99943 | if( (pExTab->tabFlags & TF_HasGenerated)!=0 |
| 99461 | 99944 | && (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0 |
| 99462 | 99945 | ){ |
| | @@ -99590,10 +100073,11 @@ |
| 99590 | 100073 | const char *zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName; |
| 99591 | 100074 | assert( zTabName!=0 ); |
| 99592 | 100075 | if( sqlite3StrICmp(zTabName, zTab)!=0 ){ |
| 99593 | 100076 | continue; |
| 99594 | 100077 | } |
| 100078 | + assert( ExprUseYTab(pExpr) ); |
| 99595 | 100079 | if( IN_RENAME_OBJECT && pItem->zAlias ){ |
| 99596 | 100080 | sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab); |
| 99597 | 100081 | } |
| 99598 | 100082 | } |
| 99599 | 100083 | hCol = sqlite3StrIHash(zCol); |
| | @@ -99621,10 +100105,11 @@ |
| 99621 | 100105 | pMatch = pItem; |
| 99622 | 100106 | } |
| 99623 | 100107 | } |
| 99624 | 100108 | if( pMatch ){ |
| 99625 | 100109 | pExpr->iTable = pMatch->iCursor; |
| 100110 | + assert( ExprUseYTab(pExpr) ); |
| 99626 | 100111 | pExpr->y.pTab = pMatch->pTab; |
| 99627 | 100112 | /* RIGHT JOIN not (yet) supported */ |
| 99628 | 100113 | assert( (pMatch->fg.jointype & JT_RIGHT)==0 ); |
| 99629 | 100114 | if( (pMatch->fg.jointype & JT_LEFT)!=0 ){ |
| 99630 | 100115 | ExprSetProperty(pExpr, EP_CanBeNull); |
| | @@ -99694,10 +100179,11 @@ |
| 99694 | 100179 | cnt++; |
| 99695 | 100180 | pMatch = 0; |
| 99696 | 100181 | #ifndef SQLITE_OMIT_UPSERT |
| 99697 | 100182 | if( pExpr->iTable==EXCLUDED_TABLE_NUMBER ){ |
| 99698 | 100183 | testcase( iCol==(-1) ); |
| 100184 | + assert( ExprUseYTab(pExpr) ); |
| 99699 | 100185 | if( IN_RENAME_OBJECT ){ |
| 99700 | 100186 | pExpr->iColumn = iCol; |
| 99701 | 100187 | pExpr->y.pTab = pTab; |
| 99702 | 100188 | eNewExprOp = TK_COLUMN; |
| 99703 | 100189 | }else{ |
| | @@ -99706,10 +100192,11 @@ |
| 99706 | 100192 | eNewExprOp = TK_REGISTER; |
| 99707 | 100193 | } |
| 99708 | 100194 | }else |
| 99709 | 100195 | #endif /* SQLITE_OMIT_UPSERT */ |
| 99710 | 100196 | { |
| 100197 | + assert( ExprUseYTab(pExpr) ); |
| 99711 | 100198 | pExpr->y.pTab = pTab; |
| 99712 | 100199 | if( pParse->bReturning ){ |
| 99713 | 100200 | eNewExprOp = TK_REGISTER; |
| 99714 | 100201 | pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable + |
| 99715 | 100202 | sqlite3TableColumnToStorage(pTab, iCol) + 1; |
| | @@ -99780,12 +100267,12 @@ |
| 99780 | 100267 | if( pEList->a[j].eEName==ENAME_NAME |
| 99781 | 100268 | && sqlite3_stricmp(zAs, zCol)==0 |
| 99782 | 100269 | ){ |
| 99783 | 100270 | Expr *pOrig; |
| 99784 | 100271 | assert( pExpr->pLeft==0 && pExpr->pRight==0 ); |
| 99785 | | - assert( pExpr->x.pList==0 ); |
| 99786 | | - assert( pExpr->x.pSelect==0 ); |
| 100272 | + assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 ); |
| 100273 | + assert( ExprUseXSelect(pExpr)==0 || pExpr->x.pSelect==0 ); |
| 99787 | 100274 | pOrig = pEList->a[j].pExpr; |
| 99788 | 100275 | if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){ |
| 99789 | 100276 | sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs); |
| 99790 | 100277 | return WRC_Abort; |
| 99791 | 100278 | } |
| | @@ -99853,11 +100340,11 @@ |
| 99853 | 100340 | "double-quoted string literal: \"%w\"", zCol); |
| 99854 | 100341 | #ifdef SQLITE_ENABLE_NORMALIZE |
| 99855 | 100342 | sqlite3VdbeAddDblquoteStr(db, pParse->pVdbe, zCol); |
| 99856 | 100343 | #endif |
| 99857 | 100344 | pExpr->op = TK_STRING; |
| 99858 | | - pExpr->y.pTab = 0; |
| 100345 | + memset(&pExpr->y, 0, sizeof(pExpr->y)); |
| 99859 | 100346 | return WRC_Prune; |
| 99860 | 100347 | } |
| 99861 | 100348 | if( sqlite3ExprIdToTrueFalse(pExpr) ){ |
| 99862 | 100349 | return WRC_Prune; |
| 99863 | 100350 | } |
| | @@ -99939,11 +100426,13 @@ |
| 99939 | 100426 | */ |
| 99940 | 100427 | SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){ |
| 99941 | 100428 | Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0); |
| 99942 | 100429 | if( p ){ |
| 99943 | 100430 | SrcItem *pItem = &pSrc->a[iSrc]; |
| 99944 | | - Table *pTab = p->y.pTab = pItem->pTab; |
| 100431 | + Table *pTab; |
| 100432 | + assert( ExprUseYTab(p) ); |
| 100433 | + pTab = p->y.pTab = pItem->pTab; |
| 99945 | 100434 | p->iTable = pItem->iCursor; |
| 99946 | 100435 | if( p->y.pTab->iPKey==iCol ){ |
| 99947 | 100436 | p->iColumn = -1; |
| 99948 | 100437 | }else{ |
| 99949 | 100438 | p->iColumn = (ynVar)iCol; |
| | @@ -100006,10 +100495,11 @@ |
| 100006 | 100495 | ** value between 1.0 and 0.0. |
| 100007 | 100496 | */ |
| 100008 | 100497 | static int exprProbability(Expr *p){ |
| 100009 | 100498 | double r = -1.0; |
| 100010 | 100499 | if( p->op!=TK_FLOAT ) return -1; |
| 100500 | + assert( !ExprHasProperty(p, EP_IntValue) ); |
| 100011 | 100501 | sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8); |
| 100012 | 100502 | assert( r>=0.0 ); |
| 100013 | 100503 | if( r>1.0 ) return -1; |
| 100014 | 100504 | return (int)(r*134217728.0); |
| 100015 | 100505 | } |
| | @@ -100054,10 +100544,11 @@ |
| 100054 | 100544 | SrcList *pSrcList = pNC->pSrcList; |
| 100055 | 100545 | SrcItem *pItem; |
| 100056 | 100546 | assert( pSrcList && pSrcList->nSrc>=1 ); |
| 100057 | 100547 | pItem = pSrcList->a; |
| 100058 | 100548 | pExpr->op = TK_COLUMN; |
| 100549 | + assert( ExprUseYTab(pExpr) ); |
| 100059 | 100550 | pExpr->y.pTab = pItem->pTab; |
| 100060 | 100551 | pExpr->iTable = pItem->iCursor; |
| 100061 | 100552 | pExpr->iColumn--; |
| 100062 | 100553 | pExpr->affExpr = SQLITE_AFF_INTEGER; |
| 100063 | 100554 | break; |
| | @@ -100086,10 +100577,11 @@ |
| 100086 | 100577 | anRef[i] = p->nRef; |
| 100087 | 100578 | } |
| 100088 | 100579 | sqlite3WalkExpr(pWalker, pExpr->pLeft); |
| 100089 | 100580 | if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){ |
| 100090 | 100581 | testcase( ExprHasProperty(pExpr, EP_FromJoin) ); |
| 100582 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 100091 | 100583 | if( pExpr->op==TK_NOTNULL ){ |
| 100092 | 100584 | pExpr->u.zToken = "true"; |
| 100093 | 100585 | ExprSetProperty(pExpr, EP_IsTrue); |
| 100094 | 100586 | }else{ |
| 100095 | 100587 | pExpr->u.zToken = "false"; |
| | @@ -100121,10 +100613,11 @@ |
| 100121 | 100613 | Expr *pRight; |
| 100122 | 100614 | |
| 100123 | 100615 | if( pExpr->op==TK_ID ){ |
| 100124 | 100616 | zDb = 0; |
| 100125 | 100617 | zTable = 0; |
| 100618 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 100126 | 100619 | zColumn = pExpr->u.zToken; |
| 100127 | 100620 | }else{ |
| 100128 | 100621 | Expr *pLeft = pExpr->pLeft; |
| 100129 | 100622 | testcase( pNC->ncFlags & NC_IdxExpr ); |
| 100130 | 100623 | testcase( pNC->ncFlags & NC_GenCol ); |
| | @@ -100133,16 +100626,19 @@ |
| 100133 | 100626 | pRight = pExpr->pRight; |
| 100134 | 100627 | if( pRight->op==TK_ID ){ |
| 100135 | 100628 | zDb = 0; |
| 100136 | 100629 | }else{ |
| 100137 | 100630 | assert( pRight->op==TK_DOT ); |
| 100631 | + assert( !ExprHasProperty(pRight, EP_IntValue) ); |
| 100138 | 100632 | zDb = pLeft->u.zToken; |
| 100139 | 100633 | pLeft = pRight->pLeft; |
| 100140 | 100634 | pRight = pRight->pRight; |
| 100141 | 100635 | } |
| 100636 | + assert( ExprUseUToken(pLeft) && ExprUseUToken(pRight) ); |
| 100142 | 100637 | zTable = pLeft->u.zToken; |
| 100143 | 100638 | zColumn = pRight->u.zToken; |
| 100639 | + assert( ExprUseYTab(pExpr) ); |
| 100144 | 100640 | if( IN_RENAME_OBJECT ){ |
| 100145 | 100641 | sqlite3RenameTokenRemap(pParse, (void*)pExpr, (void*)pRight); |
| 100146 | 100642 | sqlite3RenameTokenRemap(pParse, (void*)&pExpr->y.pTab, (void*)pLeft); |
| 100147 | 100643 | } |
| 100148 | 100644 | } |
| | @@ -100163,11 +100659,11 @@ |
| 100163 | 100659 | u8 enc = ENC(pParse->db); /* The database encoding */ |
| 100164 | 100660 | int savedAllowFlags = (pNC->ncFlags & (NC_AllowAgg | NC_AllowWin)); |
| 100165 | 100661 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 100166 | 100662 | Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0); |
| 100167 | 100663 | #endif |
| 100168 | | - assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 100664 | + assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) ); |
| 100169 | 100665 | zId = pExpr->u.zToken; |
| 100170 | 100666 | nId = sqlite3Strlen30(zId); |
| 100171 | 100667 | pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0); |
| 100172 | 100668 | if( pDef==0 ){ |
| 100173 | 100669 | pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0); |
| | @@ -100327,11 +100823,11 @@ |
| 100327 | 100823 | sqlite3WalkExprList(pWalker, pList); |
| 100328 | 100824 | if( is_agg ){ |
| 100329 | 100825 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 100330 | 100826 | if( pWin ){ |
| 100331 | 100827 | Select *pSel = pNC->pWinSelect; |
| 100332 | | - assert( pWin==pExpr->y.pWin ); |
| 100828 | + assert( pWin==0 || (ExprUseYWin(pExpr) && pWin==pExpr->y.pWin) ); |
| 100333 | 100829 | if( IN_RENAME_OBJECT==0 ){ |
| 100334 | 100830 | sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef); |
| 100335 | 100831 | if( pParse->db->mallocFailed ) break; |
| 100336 | 100832 | } |
| 100337 | 100833 | sqlite3WalkExprList(pWalker, pWin->pPartition); |
| | @@ -100340,19 +100836,22 @@ |
| 100340 | 100836 | sqlite3WindowLink(pSel, pWin); |
| 100341 | 100837 | pNC->ncFlags |= NC_HasWin; |
| 100342 | 100838 | }else |
| 100343 | 100839 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 100344 | 100840 | { |
| 100345 | | - NameContext *pNC2 = pNC; |
| 100841 | + NameContext *pNC2; /* For looping up thru outer contexts */ |
| 100346 | 100842 | pExpr->op = TK_AGG_FUNCTION; |
| 100347 | 100843 | pExpr->op2 = 0; |
| 100348 | 100844 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 100349 | 100845 | if( ExprHasProperty(pExpr, EP_WinFunc) ){ |
| 100350 | 100846 | sqlite3WalkExpr(pWalker, pExpr->y.pWin->pFilter); |
| 100351 | 100847 | } |
| 100352 | 100848 | #endif |
| 100353 | | - while( pNC2 && !sqlite3FunctionUsesThisSrc(pExpr, pNC2->pSrcList) ){ |
| 100849 | + pNC2 = pNC; |
| 100850 | + while( pNC2 |
| 100851 | + && sqlite3ReferencesSrcList(pParse, pExpr, pNC2->pSrcList)==0 |
| 100852 | + ){ |
| 100354 | 100853 | pExpr->op2++; |
| 100355 | 100854 | pNC2 = pNC2->pNext; |
| 100356 | 100855 | } |
| 100357 | 100856 | assert( pDef!=0 || IN_RENAME_OBJECT ); |
| 100358 | 100857 | if( pNC2 && pDef ){ |
| | @@ -100376,11 +100875,11 @@ |
| 100376 | 100875 | case TK_SELECT: |
| 100377 | 100876 | case TK_EXISTS: testcase( pExpr->op==TK_EXISTS ); |
| 100378 | 100877 | #endif |
| 100379 | 100878 | case TK_IN: { |
| 100380 | 100879 | testcase( pExpr->op==TK_IN ); |
| 100381 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 100880 | + if( ExprUseXSelect(pExpr) ){ |
| 100382 | 100881 | int nRef = pNC->nRef; |
| 100383 | 100882 | testcase( pNC->ncFlags & NC_IsCheck ); |
| 100384 | 100883 | testcase( pNC->ncFlags & NC_PartIdx ); |
| 100385 | 100884 | testcase( pNC->ncFlags & NC_IdxExpr ); |
| 100386 | 100885 | testcase( pNC->ncFlags & NC_GenCol ); |
| | @@ -100433,10 +100932,11 @@ |
| 100433 | 100932 | int nLeft, nRight; |
| 100434 | 100933 | if( pParse->db->mallocFailed ) break; |
| 100435 | 100934 | assert( pExpr->pLeft!=0 ); |
| 100436 | 100935 | nLeft = sqlite3ExprVectorSize(pExpr->pLeft); |
| 100437 | 100936 | if( pExpr->op==TK_BETWEEN ){ |
| 100937 | + assert( ExprUseXList(pExpr) ); |
| 100438 | 100938 | nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[0].pExpr); |
| 100439 | 100939 | if( nRight==nLeft ){ |
| 100440 | 100940 | nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[1].pExpr); |
| 100441 | 100941 | } |
| 100442 | 100942 | }else{ |
| | @@ -100481,11 +100981,13 @@ |
| 100481 | 100981 | int i; /* Loop counter */ |
| 100482 | 100982 | |
| 100483 | 100983 | UNUSED_PARAMETER(pParse); |
| 100484 | 100984 | |
| 100485 | 100985 | if( pE->op==TK_ID ){ |
| 100486 | | - char *zCol = pE->u.zToken; |
| 100986 | + const char *zCol; |
| 100987 | + assert( !ExprHasProperty(pE, EP_IntValue) ); |
| 100988 | + zCol = pE->u.zToken; |
| 100487 | 100989 | for(i=0; i<pEList->nExpr; i++){ |
| 100488 | 100990 | if( pEList->a[i].eEName==ENAME_NAME |
| 100489 | 100991 | && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0 |
| 100490 | 100992 | ){ |
| 100491 | 100993 | return i+1; |
| | @@ -101315,12 +101817,12 @@ |
| 101315 | 101817 | |
| 101316 | 101818 | /* |
| 101317 | 101819 | ** Return the affinity character for a single column of a table. |
| 101318 | 101820 | */ |
| 101319 | 101821 | SQLITE_PRIVATE char sqlite3TableColumnAffinity(const Table *pTab, int iCol){ |
| 101320 | | - assert( iCol<pTab->nCol ); |
| 101321 | | - return iCol>=0 ? pTab->aCol[iCol].affinity : SQLITE_AFF_INTEGER; |
| 101822 | + if( iCol<0 || NEVER(iCol>=pTab->nCol) ) return SQLITE_AFF_INTEGER; |
| 101823 | + return pTab->aCol[iCol].affinity; |
| 101322 | 101824 | } |
| 101323 | 101825 | |
| 101324 | 101826 | /* |
| 101325 | 101827 | ** Return the 'affinity' of the expression pExpr if any. |
| 101326 | 101828 | ** |
| | @@ -101346,15 +101848,18 @@ |
| 101346 | 101848 | pExpr = pExpr->pLeft; |
| 101347 | 101849 | assert( pExpr!=0 ); |
| 101348 | 101850 | } |
| 101349 | 101851 | op = pExpr->op; |
| 101350 | 101852 | if( op==TK_REGISTER ) op = pExpr->op2; |
| 101351 | | - if( (op==TK_COLUMN || op==TK_AGG_COLUMN) && pExpr->y.pTab ){ |
| 101352 | | - return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn); |
| 101853 | + if( op==TK_COLUMN || op==TK_AGG_COLUMN ){ |
| 101854 | + assert( ExprUseYTab(pExpr) ); |
| 101855 | + if( pExpr->y.pTab ){ |
| 101856 | + return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn); |
| 101857 | + } |
| 101353 | 101858 | } |
| 101354 | 101859 | if( op==TK_SELECT ){ |
| 101355 | | - assert( pExpr->flags&EP_xIsSelect ); |
| 101860 | + assert( ExprUseXSelect(pExpr) ); |
| 101356 | 101861 | assert( pExpr->x.pSelect!=0 ); |
| 101357 | 101862 | assert( pExpr->x.pSelect->pEList!=0 ); |
| 101358 | 101863 | assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 ); |
| 101359 | 101864 | return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr); |
| 101360 | 101865 | } |
| | @@ -101363,18 +101868,19 @@ |
| 101363 | 101868 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 101364 | 101869 | return sqlite3AffinityType(pExpr->u.zToken, 0); |
| 101365 | 101870 | } |
| 101366 | 101871 | #endif |
| 101367 | 101872 | if( op==TK_SELECT_COLUMN ){ |
| 101368 | | - assert( pExpr->pLeft->flags&EP_xIsSelect ); |
| 101873 | + assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) ); |
| 101369 | 101874 | assert( pExpr->iColumn < pExpr->iTable ); |
| 101370 | 101875 | assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr ); |
| 101371 | 101876 | return sqlite3ExprAffinity( |
| 101372 | 101877 | pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr |
| 101373 | 101878 | ); |
| 101374 | 101879 | } |
| 101375 | 101880 | if( op==TK_VECTOR ){ |
| 101881 | + assert( ExprUseXList(pExpr) ); |
| 101376 | 101882 | return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr); |
| 101377 | 101883 | } |
| 101378 | 101884 | return pExpr->affExpr; |
| 101379 | 101885 | } |
| 101380 | 101886 | |
| | @@ -101430,11 +101936,11 @@ |
| 101430 | 101936 | ** expression. |
| 101431 | 101937 | */ |
| 101432 | 101938 | SQLITE_PRIVATE Expr *sqlite3ExprSkipCollateAndLikely(Expr *pExpr){ |
| 101433 | 101939 | while( pExpr && ExprHasProperty(pExpr, EP_Skip|EP_Unlikely) ){ |
| 101434 | 101940 | if( ExprHasProperty(pExpr, EP_Unlikely) ){ |
| 101435 | | - assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 101941 | + assert( ExprUseXList(pExpr) ); |
| 101436 | 101942 | assert( pExpr->x.pList->nExpr>0 ); |
| 101437 | 101943 | assert( pExpr->op==TK_FUNCTION ); |
| 101438 | 101944 | pExpr = pExpr->x.pList->a[0].pExpr; |
| 101439 | 101945 | }else{ |
| 101440 | 101946 | assert( pExpr->op==TK_COLLATE ); |
| | @@ -101463,45 +101969,46 @@ |
| 101463 | 101969 | CollSeq *pColl = 0; |
| 101464 | 101970 | const Expr *p = pExpr; |
| 101465 | 101971 | while( p ){ |
| 101466 | 101972 | int op = p->op; |
| 101467 | 101973 | if( op==TK_REGISTER ) op = p->op2; |
| 101468 | | - if( (op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_TRIGGER) |
| 101469 | | - && p->y.pTab!=0 |
| 101470 | | - ){ |
| 101471 | | - /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally |
| 101472 | | - ** a TK_COLUMN but was previously evaluated and cached in a register */ |
| 101473 | | - int j = p->iColumn; |
| 101474 | | - if( j>=0 ){ |
| 101475 | | - const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]); |
| 101476 | | - pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0); |
| 101477 | | - } |
| 101478 | | - break; |
| 101974 | + if( op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_TRIGGER ){ |
| 101975 | + assert( ExprUseYTab(p) ); |
| 101976 | + if( p->y.pTab!=0 ){ |
| 101977 | + /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally |
| 101978 | + ** a TK_COLUMN but was previously evaluated and cached in a register */ |
| 101979 | + int j = p->iColumn; |
| 101980 | + if( j>=0 ){ |
| 101981 | + const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]); |
| 101982 | + pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0); |
| 101983 | + } |
| 101984 | + break; |
| 101985 | + } |
| 101479 | 101986 | } |
| 101480 | 101987 | if( op==TK_CAST || op==TK_UPLUS ){ |
| 101481 | 101988 | p = p->pLeft; |
| 101482 | 101989 | continue; |
| 101483 | 101990 | } |
| 101484 | 101991 | if( op==TK_VECTOR ){ |
| 101992 | + assert( ExprUseXList(p) ); |
| 101485 | 101993 | p = p->x.pList->a[0].pExpr; |
| 101486 | 101994 | continue; |
| 101487 | 101995 | } |
| 101488 | 101996 | if( op==TK_COLLATE ){ |
| 101997 | + assert( !ExprHasProperty(p, EP_IntValue) ); |
| 101489 | 101998 | pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken); |
| 101490 | 101999 | break; |
| 101491 | 102000 | } |
| 101492 | 102001 | if( p->flags & EP_Collate ){ |
| 101493 | 102002 | if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){ |
| 101494 | 102003 | p = p->pLeft; |
| 101495 | 102004 | }else{ |
| 101496 | 102005 | Expr *pNext = p->pRight; |
| 101497 | 102006 | /* The Expr.x union is never used at the same time as Expr.pRight */ |
| 102007 | + assert( ExprUseXList(p) ); |
| 101498 | 102008 | assert( p->x.pList==0 || p->pRight==0 ); |
| 101499 | | - if( p->x.pList!=0 |
| 101500 | | - && !db->mallocFailed |
| 101501 | | - && ALWAYS(!ExprHasProperty(p, EP_xIsSelect)) |
| 101502 | | - ){ |
| 102009 | + if( p->x.pList!=0 && !db->mallocFailed ){ |
| 101503 | 102010 | int i; |
| 101504 | 102011 | for(i=0; ALWAYS(i<p->x.pList->nExpr); i++){ |
| 101505 | 102012 | if( ExprHasProperty(p->x.pList->a[i].pExpr, EP_Collate) ){ |
| 101506 | 102013 | pNext = p->x.pList->a[i].pExpr; |
| 101507 | 102014 | break; |
| | @@ -101580,11 +102087,11 @@ |
| 101580 | 102087 | pExpr->op==TK_NE || pExpr->op==TK_IS || pExpr->op==TK_ISNOT ); |
| 101581 | 102088 | assert( pExpr->pLeft ); |
| 101582 | 102089 | aff = sqlite3ExprAffinity(pExpr->pLeft); |
| 101583 | 102090 | if( pExpr->pRight ){ |
| 101584 | 102091 | aff = sqlite3CompareAffinity(pExpr->pRight, aff); |
| 101585 | | - }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 102092 | + }else if( ExprUseXSelect(pExpr) ){ |
| 101586 | 102093 | aff = sqlite3CompareAffinity(pExpr->x.pSelect->pEList->a[0].pExpr, aff); |
| 101587 | 102094 | }else if( aff==0 ){ |
| 101588 | 102095 | aff = SQLITE_AFF_BLOB; |
| 101589 | 102096 | } |
| 101590 | 102097 | return aff; |
| | @@ -101720,12 +102227,14 @@ |
| 101720 | 102227 | */ |
| 101721 | 102228 | SQLITE_PRIVATE int sqlite3ExprVectorSize(const Expr *pExpr){ |
| 101722 | 102229 | u8 op = pExpr->op; |
| 101723 | 102230 | if( op==TK_REGISTER ) op = pExpr->op2; |
| 101724 | 102231 | if( op==TK_VECTOR ){ |
| 102232 | + assert( ExprUseXList(pExpr) ); |
| 101725 | 102233 | return pExpr->x.pList->nExpr; |
| 101726 | 102234 | }else if( op==TK_SELECT ){ |
| 102235 | + assert( ExprUseXSelect(pExpr) ); |
| 101727 | 102236 | return pExpr->x.pSelect->pEList->nExpr; |
| 101728 | 102237 | }else{ |
| 101729 | 102238 | return 1; |
| 101730 | 102239 | } |
| 101731 | 102240 | } |
| | @@ -101748,12 +102257,14 @@ |
| 101748 | 102257 | SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr *pVector, int i){ |
| 101749 | 102258 | assert( i<sqlite3ExprVectorSize(pVector) || pVector->op==TK_ERROR ); |
| 101750 | 102259 | if( sqlite3ExprIsVector(pVector) ){ |
| 101751 | 102260 | assert( pVector->op2==0 || pVector->op==TK_REGISTER ); |
| 101752 | 102261 | if( pVector->op==TK_SELECT || pVector->op2==TK_SELECT ){ |
| 102262 | + assert( ExprUseXSelect(pVector) ); |
| 101753 | 102263 | return pVector->x.pSelect->pEList->a[i].pExpr; |
| 101754 | 102264 | }else{ |
| 102265 | + assert( ExprUseXList(pVector) ); |
| 101755 | 102266 | return pVector->x.pList->a[i].pExpr; |
| 101756 | 102267 | } |
| 101757 | 102268 | } |
| 101758 | 102269 | return pVector; |
| 101759 | 102270 | } |
| | @@ -101785,11 +102296,11 @@ |
| 101785 | 102296 | int iField, /* Which column of the vector to return */ |
| 101786 | 102297 | int nField /* Total number of columns in the vector */ |
| 101787 | 102298 | ){ |
| 101788 | 102299 | Expr *pRet; |
| 101789 | 102300 | if( pVector->op==TK_SELECT ){ |
| 101790 | | - assert( pVector->flags & EP_xIsSelect ); |
| 102301 | + assert( ExprUseXSelect(pVector) ); |
| 101791 | 102302 | /* The TK_SELECT_COLUMN Expr node: |
| 101792 | 102303 | ** |
| 101793 | 102304 | ** pLeft: pVector containing TK_SELECT. Not deleted. |
| 101794 | 102305 | ** pRight: not used. But recursively deleted. |
| 101795 | 102306 | ** iColumn: Index of a column in pVector |
| | @@ -101810,11 +102321,13 @@ |
| 101810 | 102321 | pRet->iColumn = iField; |
| 101811 | 102322 | pRet->pLeft = pVector; |
| 101812 | 102323 | } |
| 101813 | 102324 | }else{ |
| 101814 | 102325 | if( pVector->op==TK_VECTOR ){ |
| 101815 | | - Expr **ppVector = &pVector->x.pList->a[iField].pExpr; |
| 102326 | + Expr **ppVector; |
| 102327 | + assert( ExprUseXList(pVector) ); |
| 102328 | + ppVector = &pVector->x.pList->a[iField].pExpr; |
| 101816 | 102329 | pVector = *ppVector; |
| 101817 | 102330 | if( IN_RENAME_OBJECT ){ |
| 101818 | 102331 | /* This must be a vector UPDATE inside a trigger */ |
| 101819 | 102332 | *ppVector = 0; |
| 101820 | 102333 | return pVector; |
| | @@ -101874,14 +102387,16 @@ |
| 101874 | 102387 | if( op==TK_REGISTER ){ |
| 101875 | 102388 | *ppExpr = sqlite3VectorFieldSubexpr(pVector, iField); |
| 101876 | 102389 | return pVector->iTable+iField; |
| 101877 | 102390 | } |
| 101878 | 102391 | if( op==TK_SELECT ){ |
| 102392 | + assert( ExprUseXSelect(pVector) ); |
| 101879 | 102393 | *ppExpr = pVector->x.pSelect->pEList->a[iField].pExpr; |
| 101880 | 102394 | return regSelect+iField; |
| 101881 | 102395 | } |
| 101882 | 102396 | if( op==TK_VECTOR ){ |
| 102397 | + assert( ExprUseXList(pVector) ); |
| 101883 | 102398 | *ppExpr = pVector->x.pList->a[iField].pExpr; |
| 101884 | 102399 | return sqlite3ExprCodeTemp(pParse, *ppExpr, pRegFree); |
| 101885 | 102400 | } |
| 101886 | 102401 | return 0; |
| 101887 | 102402 | } |
| | @@ -102052,11 +102567,11 @@ |
| 102052 | 102567 | */ |
| 102053 | 102568 | static void exprSetHeight(Expr *p){ |
| 102054 | 102569 | int nHeight = 0; |
| 102055 | 102570 | heightOfExpr(p->pLeft, &nHeight); |
| 102056 | 102571 | heightOfExpr(p->pRight, &nHeight); |
| 102057 | | - if( ExprHasProperty(p, EP_xIsSelect) ){ |
| 102572 | + if( ExprUseXSelect(p) ){ |
| 102058 | 102573 | heightOfSelect(p->x.pSelect, &nHeight); |
| 102059 | 102574 | }else if( p->x.pList ){ |
| 102060 | 102575 | heightOfExprList(p->x.pList, &nHeight); |
| 102061 | 102576 | p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList); |
| 102062 | 102577 | } |
| | @@ -102091,11 +102606,11 @@ |
| 102091 | 102606 | ** Propagate all EP_Propagate flags from the Expr.x.pList into |
| 102092 | 102607 | ** Expr.flags. |
| 102093 | 102608 | */ |
| 102094 | 102609 | SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){ |
| 102095 | 102610 | if( pParse->nErr ) return; |
| 102096 | | - if( p && p->x.pList && !ExprHasProperty(p, EP_xIsSelect) ){ |
| 102611 | + if( p && ExprUseXList(p) && p->x.pList ){ |
| 102097 | 102612 | p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList); |
| 102098 | 102613 | } |
| 102099 | 102614 | } |
| 102100 | 102615 | #define exprSetHeight(y) |
| 102101 | 102616 | #endif /* SQLITE_MAX_EXPR_DEPTH>0 */ |
| | @@ -102275,17 +102790,24 @@ |
| 102275 | 102790 | Select *pRet = 0; |
| 102276 | 102791 | assert( nElem>1 ); |
| 102277 | 102792 | for(ii=0; ii<pEList->nExpr; ii++){ |
| 102278 | 102793 | Select *pSel; |
| 102279 | 102794 | Expr *pExpr = pEList->a[ii].pExpr; |
| 102280 | | - int nExprElem = (pExpr->op==TK_VECTOR ? pExpr->x.pList->nExpr : 1); |
| 102795 | + int nExprElem; |
| 102796 | + if( pExpr->op==TK_VECTOR ){ |
| 102797 | + assert( ExprUseXList(pExpr) ); |
| 102798 | + nExprElem = pExpr->x.pList->nExpr; |
| 102799 | + }else{ |
| 102800 | + nExprElem = 1; |
| 102801 | + } |
| 102281 | 102802 | if( nExprElem!=nElem ){ |
| 102282 | 102803 | sqlite3ErrorMsg(pParse, "IN(...) element has %d term%s - expected %d", |
| 102283 | 102804 | nExprElem, nExprElem>1?"s":"", nElem |
| 102284 | 102805 | ); |
| 102285 | 102806 | break; |
| 102286 | 102807 | } |
| 102808 | + assert( ExprUseXList(pExpr) ); |
| 102287 | 102809 | pSel = sqlite3SelectNew(pParse, pExpr->x.pList, 0, 0, 0, 0, 0, SF_Values,0); |
| 102288 | 102810 | pExpr->x.pList = 0; |
| 102289 | 102811 | if( pSel ){ |
| 102290 | 102812 | if( pRet ){ |
| 102291 | 102813 | pSel->op = TK_ALL; |
| | @@ -102351,11 +102873,11 @@ |
| 102351 | 102873 | ){ |
| 102352 | 102874 | sqlite3ErrorMsg(pParse, "too many arguments on function %T", pToken); |
| 102353 | 102875 | } |
| 102354 | 102876 | pNew->x.pList = pList; |
| 102355 | 102877 | ExprSetProperty(pNew, EP_HasFunc); |
| 102356 | | - assert( !ExprHasProperty(pNew, EP_xIsSelect) ); |
| 102878 | + assert( ExprUseXList(pNew) ); |
| 102357 | 102879 | sqlite3ExprSetHeightAndFlags(pParse, pNew); |
| 102358 | 102880 | if( eDistinct==SF_Distinct ) ExprSetProperty(pNew, EP_Distinct); |
| 102359 | 102881 | return pNew; |
| 102360 | 102882 | } |
| 102361 | 102883 | |
| | @@ -102477,31 +102999,30 @@ |
| 102477 | 102999 | /* |
| 102478 | 103000 | ** Recursively delete an expression tree. |
| 102479 | 103001 | */ |
| 102480 | 103002 | static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){ |
| 102481 | 103003 | assert( p!=0 ); |
| 102482 | | - /* Sanity check: Assert that the IntValue is non-negative if it exists */ |
| 102483 | | - assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 ); |
| 102484 | | - |
| 102485 | | - assert( !ExprHasProperty(p, EP_WinFunc) || p->y.pWin!=0 || db->mallocFailed ); |
| 102486 | | - assert( p->op!=TK_FUNCTION || ExprHasProperty(p, EP_TokenOnly|EP_Reduced) |
| 102487 | | - || p->y.pWin==0 || ExprHasProperty(p, EP_WinFunc) ); |
| 103004 | + assert( !ExprUseUValue(p) || p->u.iValue>=0 ); |
| 103005 | + assert( !ExprUseYWin(p) || !ExprUseYSub(p) ); |
| 103006 | + assert( !ExprUseYWin(p) || p->y.pWin!=0 || db->mallocFailed ); |
| 103007 | + assert( p->op!=TK_FUNCTION || !ExprUseYSub(p) ); |
| 102488 | 103008 | #ifdef SQLITE_DEBUG |
| 102489 | 103009 | if( ExprHasProperty(p, EP_Leaf) && !ExprHasProperty(p, EP_TokenOnly) ){ |
| 102490 | 103010 | assert( p->pLeft==0 ); |
| 102491 | 103011 | assert( p->pRight==0 ); |
| 102492 | | - assert( p->x.pSelect==0 ); |
| 103012 | + assert( !ExprUseXSelect(p) || p->x.pSelect==0 ); |
| 103013 | + assert( !ExprUseXList(p) || p->x.pList==0 ); |
| 102493 | 103014 | } |
| 102494 | 103015 | #endif |
| 102495 | 103016 | if( !ExprHasProperty(p, (EP_TokenOnly|EP_Leaf)) ){ |
| 102496 | 103017 | /* The Expr.x union is never used at the same time as Expr.pRight */ |
| 102497 | | - assert( p->x.pList==0 || p->pRight==0 ); |
| 103018 | + assert( (ExprUseXList(p) && p->x.pList==0) || p->pRight==0 ); |
| 102498 | 103019 | if( p->pLeft && p->op!=TK_SELECT_COLUMN ) sqlite3ExprDeleteNN(db, p->pLeft); |
| 102499 | 103020 | if( p->pRight ){ |
| 102500 | 103021 | assert( !ExprHasProperty(p, EP_WinFunc) ); |
| 102501 | 103022 | sqlite3ExprDeleteNN(db, p->pRight); |
| 102502 | | - }else if( ExprHasProperty(p, EP_xIsSelect) ){ |
| 103023 | + }else if( ExprUseXSelect(p) ){ |
| 102503 | 103024 | assert( !ExprHasProperty(p, EP_WinFunc) ); |
| 102504 | 103025 | sqlite3SelectDelete(db, p->x.pSelect); |
| 102505 | 103026 | }else{ |
| 102506 | 103027 | sqlite3ExprListDelete(db, p->x.pList); |
| 102507 | 103028 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| | @@ -102509,11 +103030,14 @@ |
| 102509 | 103030 | sqlite3WindowDelete(db, p->y.pWin); |
| 102510 | 103031 | } |
| 102511 | 103032 | #endif |
| 102512 | 103033 | } |
| 102513 | 103034 | } |
| 102514 | | - if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken); |
| 103035 | + if( ExprHasProperty(p, EP_MemToken) ){ |
| 103036 | + assert( !ExprHasProperty(p, EP_IntValue) ); |
| 103037 | + sqlite3DbFree(db, p->u.zToken); |
| 103038 | + } |
| 102515 | 103039 | if( !ExprHasProperty(p, EP_Static) ){ |
| 102516 | 103040 | sqlite3DbFreeNN(db, p); |
| 102517 | 103041 | } |
| 102518 | 103042 | } |
| 102519 | 103043 | SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){ |
| | @@ -102725,11 +103249,11 @@ |
| 102725 | 103249 | memcpy(zToken, p->u.zToken, nToken); |
| 102726 | 103250 | } |
| 102727 | 103251 | |
| 102728 | 103252 | if( 0==((p->flags|pNew->flags) & (EP_TokenOnly|EP_Leaf)) ){ |
| 102729 | 103253 | /* Fill in the pNew->x.pSelect or pNew->x.pList member. */ |
| 102730 | | - if( ExprHasProperty(p, EP_xIsSelect) ){ |
| 103254 | + if( ExprUseXSelect(p) ){ |
| 102731 | 103255 | pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, dupFlags); |
| 102732 | 103256 | }else{ |
| 102733 | 103257 | pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, dupFlags); |
| 102734 | 103258 | } |
| 102735 | 103259 | } |
| | @@ -103019,11 +103543,11 @@ |
| 103019 | 103543 | } |
| 103020 | 103544 | |
| 103021 | 103545 | return pRet; |
| 103022 | 103546 | } |
| 103023 | 103547 | #else |
| 103024 | | -SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){ |
| 103548 | +SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, const Select *p, int flags){ |
| 103025 | 103549 | assert( p==0 ); |
| 103026 | 103550 | return 0; |
| 103027 | 103551 | } |
| 103028 | 103552 | #endif |
| 103029 | 103553 | |
| | @@ -103352,11 +103876,11 @@ |
| 103352 | 103876 | ** the conversion happened, and zero if the expression is unaltered. |
| 103353 | 103877 | */ |
| 103354 | 103878 | SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr *pExpr){ |
| 103355 | 103879 | u32 v; |
| 103356 | 103880 | assert( pExpr->op==TK_ID || pExpr->op==TK_STRING ); |
| 103357 | | - if( !ExprHasProperty(pExpr, EP_Quoted) |
| 103881 | + if( !ExprHasProperty(pExpr, EP_Quoted|EP_IntValue) |
| 103358 | 103882 | && (v = sqlite3IsTrueOrFalse(pExpr->u.zToken))!=0 |
| 103359 | 103883 | ){ |
| 103360 | 103884 | pExpr->op = TK_TRUEFALSE; |
| 103361 | 103885 | ExprSetProperty(pExpr, v); |
| 103362 | 103886 | return 1; |
| | @@ -103369,10 +103893,11 @@ |
| 103369 | 103893 | ** and 0 if it is FALSE. |
| 103370 | 103894 | */ |
| 103371 | 103895 | SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr *pExpr){ |
| 103372 | 103896 | pExpr = sqlite3ExprSkipCollate((Expr*)pExpr); |
| 103373 | 103897 | assert( pExpr->op==TK_TRUEFALSE ); |
| 103898 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 103374 | 103899 | assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0 |
| 103375 | 103900 | || sqlite3StrICmp(pExpr->u.zToken,"false")==0 ); |
| 103376 | 103901 | return pExpr->u.zToken[4]==0; |
| 103377 | 103902 | } |
| 103378 | 103903 | |
| | @@ -103573,11 +104098,11 @@ |
| 103573 | 104098 | } |
| 103574 | 104099 | } |
| 103575 | 104100 | } |
| 103576 | 104101 | |
| 103577 | 104102 | /* Check if pExpr is a sub-select. If so, consider it variable. */ |
| 103578 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 104103 | + if( ExprUseXSelect(pExpr) ){ |
| 103579 | 104104 | pWalker->eCode = 0; |
| 103580 | 104105 | return WRC_Abort; |
| 103581 | 104106 | } |
| 103582 | 104107 | |
| 103583 | 104108 | return exprNodeIsConstant(pWalker, pExpr); |
| | @@ -103680,13 +104205,13 @@ |
| 103680 | 104205 | case TK_UPLUS: { |
| 103681 | 104206 | rc = sqlite3ExprIsInteger(p->pLeft, pValue); |
| 103682 | 104207 | break; |
| 103683 | 104208 | } |
| 103684 | 104209 | case TK_UMINUS: { |
| 103685 | | - int v; |
| 104210 | + int v = 0; |
| 103686 | 104211 | if( sqlite3ExprIsInteger(p->pLeft, &v) ){ |
| 103687 | | - assert( v!=(-2147483647-1) ); |
| 104212 | + assert( ((unsigned int)v)!=0x80000000 ); |
| 103688 | 104213 | *pValue = -v; |
| 103689 | 104214 | rc = 1; |
| 103690 | 104215 | } |
| 103691 | 104216 | break; |
| 103692 | 104217 | } |
| | @@ -103723,14 +104248,15 @@ |
| 103723 | 104248 | case TK_STRING: |
| 103724 | 104249 | case TK_FLOAT: |
| 103725 | 104250 | case TK_BLOB: |
| 103726 | 104251 | return 0; |
| 103727 | 104252 | case TK_COLUMN: |
| 104253 | + assert( ExprUseYTab(p) ); |
| 103728 | 104254 | return ExprHasProperty(p, EP_CanBeNull) || |
| 103729 | 104255 | p->y.pTab==0 || /* Reference to column of index on expression */ |
| 103730 | 104256 | (p->iColumn>=0 |
| 103731 | | - && ALWAYS(p->y.pTab->aCol!=0) /* Defense against OOM problems */ |
| 104257 | + && p->y.pTab->aCol!=0 /* Possible due to prior error */ |
| 103732 | 104258 | && p->y.pTab->aCol[p->iColumn].notNull==0); |
| 103733 | 104259 | default: |
| 103734 | 104260 | return 1; |
| 103735 | 104261 | } |
| 103736 | 104262 | } |
| | @@ -103800,11 +104326,11 @@ |
| 103800 | 104326 | Select *p; |
| 103801 | 104327 | SrcList *pSrc; |
| 103802 | 104328 | ExprList *pEList; |
| 103803 | 104329 | Table *pTab; |
| 103804 | 104330 | int i; |
| 103805 | | - if( !ExprHasProperty(pX, EP_xIsSelect) ) return 0; /* Not a subquery */ |
| 104331 | + if( !ExprUseXSelect(pX) ) return 0; /* Not a subquery */ |
| 103806 | 104332 | if( ExprHasProperty(pX, EP_VarSelect) ) return 0; /* Correlated subq */ |
| 103807 | 104333 | p = pX->x.pSelect; |
| 103808 | 104334 | if( p->pPrior ) return 0; /* Not a compound SELECT */ |
| 103809 | 104335 | if( p->selFlags & (SF_Distinct|SF_Aggregate) ){ |
| 103810 | 104336 | testcase( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct ); |
| | @@ -103971,11 +104497,11 @@ |
| 103971 | 104497 | /* If the RHS of this IN(...) operator is a SELECT, and if it matters |
| 103972 | 104498 | ** whether or not the SELECT result contains NULL values, check whether |
| 103973 | 104499 | ** or not NULL is actually possible (it may not be, for example, due |
| 103974 | 104500 | ** to NOT NULL constraints in the schema). If no NULL values are possible, |
| 103975 | 104501 | ** set prRhsHasNull to 0 before continuing. */ |
| 103976 | | - if( prRhsHasNull && (pX->flags & EP_xIsSelect) ){ |
| 104502 | + if( prRhsHasNull && ExprUseXSelect(pX) ){ |
| 103977 | 104503 | int i; |
| 103978 | 104504 | ExprList *pEList = pX->x.pSelect->pEList; |
| 103979 | 104505 | for(i=0; i<pEList->nExpr; i++){ |
| 103980 | 104506 | if( sqlite3ExprCanBeNull(pEList->a[i].pExpr) ) break; |
| 103981 | 104507 | } |
| | @@ -104072,11 +104598,12 @@ |
| 104072 | 104598 | Expr *pLhs = sqlite3VectorFieldSubexpr(pX->pLeft, i); |
| 104073 | 104599 | Expr *pRhs = pEList->a[i].pExpr; |
| 104074 | 104600 | CollSeq *pReq = sqlite3BinaryCompareCollSeq(pParse, pLhs, pRhs); |
| 104075 | 104601 | int j; |
| 104076 | 104602 | |
| 104077 | | - assert( pReq!=0 || pRhs->iColumn==XN_ROWID || pParse->nErr ); |
| 104603 | + assert( pReq!=0 || pRhs->iColumn==XN_ROWID |
| 104604 | + || pParse->nErr || db->mallocFailed ); |
| 104078 | 104605 | for(j=0; j<nExpr; j++){ |
| 104079 | 104606 | if( pIdx->aiColumn[j]!=pRhs->iColumn ) continue; |
| 104080 | 104607 | assert( pIdx->azColl[j] ); |
| 104081 | 104608 | if( pReq!=0 && sqlite3StrICmp(pReq->zName, pIdx->azColl[j])!=0 ){ |
| 104082 | 104609 | continue; |
| | @@ -104127,11 +104654,11 @@ |
| 104127 | 104654 | ** then it is not worth creating an ephemeral table to evaluate |
| 104128 | 104655 | ** the IN operator so return IN_INDEX_NOOP. |
| 104129 | 104656 | */ |
| 104130 | 104657 | if( eType==0 |
| 104131 | 104658 | && (inFlags & IN_INDEX_NOOP_OK) |
| 104132 | | - && !ExprHasProperty(pX, EP_xIsSelect) |
| 104659 | + && ExprUseXList(pX) |
| 104133 | 104660 | && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2) |
| 104134 | 104661 | ){ |
| 104135 | 104662 | eType = IN_INDEX_NOOP; |
| 104136 | 104663 | } |
| 104137 | 104664 | |
| | @@ -104175,11 +104702,11 @@ |
| 104175 | 104702 | ** string is eventually freed using sqlite3DbFree(). |
| 104176 | 104703 | */ |
| 104177 | 104704 | static char *exprINAffinity(Parse *pParse, const Expr *pExpr){ |
| 104178 | 104705 | Expr *pLeft = pExpr->pLeft; |
| 104179 | 104706 | int nVal = sqlite3ExprVectorSize(pLeft); |
| 104180 | | - Select *pSelect = (pExpr->flags & EP_xIsSelect) ? pExpr->x.pSelect : 0; |
| 104707 | + Select *pSelect = ExprUseXSelect(pExpr) ? pExpr->x.pSelect : 0; |
| 104181 | 104708 | char *zRet; |
| 104182 | 104709 | |
| 104183 | 104710 | assert( pExpr->op==TK_IN ); |
| 104184 | 104711 | zRet = sqlite3DbMallocRaw(pParse->db, nVal+1); |
| 104185 | 104712 | if( zRet ){ |
| | @@ -104225,11 +104752,11 @@ |
| 104225 | 104752 | ** |
| 104226 | 104753 | ** "row value misused" |
| 104227 | 104754 | */ |
| 104228 | 104755 | SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse *pParse, Expr *pExpr){ |
| 104229 | 104756 | #ifndef SQLITE_OMIT_SUBQUERY |
| 104230 | | - if( pExpr->flags & EP_xIsSelect ){ |
| 104757 | + if( ExprUseXSelect(pExpr) ){ |
| 104231 | 104758 | sqlite3SubselectError(pParse, pExpr->x.pSelect->pEList->nExpr, 1); |
| 104232 | 104759 | }else |
| 104233 | 104760 | #endif |
| 104234 | 104761 | { |
| 104235 | 104762 | sqlite3ErrorMsg(pParse, "row value misused"); |
| | @@ -104289,22 +104816,24 @@ |
| 104289 | 104816 | /* If this routine has already been coded, but the previous code |
| 104290 | 104817 | ** might not have been invoked yet, so invoke it now as a subroutine. |
| 104291 | 104818 | */ |
| 104292 | 104819 | if( ExprHasProperty(pExpr, EP_Subrtn) ){ |
| 104293 | 104820 | addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v); |
| 104294 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 104821 | + if( ExprUseXSelect(pExpr) ){ |
| 104295 | 104822 | ExplainQueryPlan((pParse, 0, "REUSE LIST SUBQUERY %d", |
| 104296 | 104823 | pExpr->x.pSelect->selId)); |
| 104297 | 104824 | } |
| 104825 | + assert( ExprUseYSub(pExpr) ); |
| 104298 | 104826 | sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn, |
| 104299 | 104827 | pExpr->y.sub.iAddr); |
| 104300 | 104828 | sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable); |
| 104301 | 104829 | sqlite3VdbeJumpHere(v, addrOnce); |
| 104302 | 104830 | return; |
| 104303 | 104831 | } |
| 104304 | 104832 | |
| 104305 | 104833 | /* Begin coding the subroutine */ |
| 104834 | + assert( !ExprUseYWin(pExpr) ); |
| 104306 | 104835 | ExprSetProperty(pExpr, EP_Subrtn); |
| 104307 | 104836 | assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) ); |
| 104308 | 104837 | pExpr->y.sub.regReturn = ++pParse->nMem; |
| 104309 | 104838 | pExpr->y.sub.iAddr = |
| 104310 | 104839 | sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1; |
| | @@ -104321,19 +104850,19 @@ |
| 104321 | 104850 | ** RHS of the IN operator. |
| 104322 | 104851 | */ |
| 104323 | 104852 | pExpr->iTable = iTab; |
| 104324 | 104853 | addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, nVal); |
| 104325 | 104854 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 104326 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 104855 | + if( ExprUseXSelect(pExpr) ){ |
| 104327 | 104856 | VdbeComment((v, "Result of SELECT %u", pExpr->x.pSelect->selId)); |
| 104328 | 104857 | }else{ |
| 104329 | 104858 | VdbeComment((v, "RHS of IN operator")); |
| 104330 | 104859 | } |
| 104331 | 104860 | #endif |
| 104332 | 104861 | pKeyInfo = sqlite3KeyInfoAlloc(pParse->db, nVal, 1); |
| 104333 | 104862 | |
| 104334 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 104863 | + if( ExprUseXSelect(pExpr) ){ |
| 104335 | 104864 | /* Case 1: expr IN (SELECT ...) |
| 104336 | 104865 | ** |
| 104337 | 104866 | ** Generate code to write the results of the select into the temporary |
| 104338 | 104867 | ** table allocated and opened above. |
| 104339 | 104868 | */ |
| | @@ -104427,10 +104956,11 @@ |
| 104427 | 104956 | sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO); |
| 104428 | 104957 | } |
| 104429 | 104958 | if( addrOnce ){ |
| 104430 | 104959 | sqlite3VdbeJumpHere(v, addrOnce); |
| 104431 | 104960 | /* Subroutine return */ |
| 104961 | + assert( ExprUseYSub(pExpr) ); |
| 104432 | 104962 | sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn); |
| 104433 | 104963 | sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1); |
| 104434 | 104964 | sqlite3ClearTempRegCache(pParse); |
| 104435 | 104965 | } |
| 104436 | 104966 | } |
| | @@ -104463,23 +104993,26 @@ |
| 104463 | 104993 | assert( v!=0 ); |
| 104464 | 104994 | if( pParse->nErr ) return 0; |
| 104465 | 104995 | testcase( pExpr->op==TK_EXISTS ); |
| 104466 | 104996 | testcase( pExpr->op==TK_SELECT ); |
| 104467 | 104997 | assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT ); |
| 104468 | | - assert( ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 104998 | + assert( ExprUseXSelect(pExpr) ); |
| 104469 | 104999 | pSel = pExpr->x.pSelect; |
| 104470 | 105000 | |
| 104471 | 105001 | /* If this routine has already been coded, then invoke it as a |
| 104472 | 105002 | ** subroutine. */ |
| 104473 | 105003 | if( ExprHasProperty(pExpr, EP_Subrtn) ){ |
| 104474 | 105004 | ExplainQueryPlan((pParse, 0, "REUSE SUBQUERY %d", pSel->selId)); |
| 105005 | + assert( ExprUseYSub(pExpr) ); |
| 104475 | 105006 | sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn, |
| 104476 | 105007 | pExpr->y.sub.iAddr); |
| 104477 | 105008 | return pExpr->iTable; |
| 104478 | 105009 | } |
| 104479 | 105010 | |
| 104480 | 105011 | /* Begin coding the subroutine */ |
| 105012 | + assert( !ExprUseYWin(pExpr) ); |
| 105013 | + assert( !ExprHasProperty(pExpr, EP_Reduced|EP_TokenOnly) ); |
| 104481 | 105014 | ExprSetProperty(pExpr, EP_Subrtn); |
| 104482 | 105015 | pExpr->y.sub.regReturn = ++pParse->nMem; |
| 104483 | 105016 | pExpr->y.sub.iAddr = |
| 104484 | 105017 | sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1; |
| 104485 | 105018 | VdbeComment((v, "return address")); |
| | @@ -104555,10 +105088,11 @@ |
| 104555 | 105088 | if( addrOnce ){ |
| 104556 | 105089 | sqlite3VdbeJumpHere(v, addrOnce); |
| 104557 | 105090 | } |
| 104558 | 105091 | |
| 104559 | 105092 | /* Subroutine return */ |
| 105093 | + assert( ExprUseYSub(pExpr) ); |
| 104560 | 105094 | sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn); |
| 104561 | 105095 | sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1); |
| 104562 | 105096 | sqlite3ClearTempRegCache(pParse); |
| 104563 | 105097 | return rReg; |
| 104564 | 105098 | } |
| | @@ -104571,11 +105105,11 @@ |
| 104571 | 105105 | ** columns as the vector on the LHS. Or, if the RHS of the IN() is not |
| 104572 | 105106 | ** a sub-query, that the LHS is a vector of size 1. |
| 104573 | 105107 | */ |
| 104574 | 105108 | SQLITE_PRIVATE int sqlite3ExprCheckIN(Parse *pParse, Expr *pIn){ |
| 104575 | 105109 | int nVector = sqlite3ExprVectorSize(pIn->pLeft); |
| 104576 | | - if( (pIn->flags & EP_xIsSelect)!=0 && !pParse->db->mallocFailed ){ |
| 105110 | + if( ExprUseXSelect(pIn) && !pParse->db->mallocFailed ){ |
| 104577 | 105111 | if( nVector!=pIn->x.pSelect->pEList->nExpr ){ |
| 104578 | 105112 | sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector); |
| 104579 | 105113 | return 1; |
| 104580 | 105114 | } |
| 104581 | 105115 | }else if( nVector!=1 ){ |
| | @@ -104705,17 +105239,19 @@ |
| 104705 | 105239 | ** sequence of comparisons. |
| 104706 | 105240 | ** |
| 104707 | 105241 | ** This is step (1) in the in-operator.md optimized algorithm. |
| 104708 | 105242 | */ |
| 104709 | 105243 | if( eType==IN_INDEX_NOOP ){ |
| 104710 | | - ExprList *pList = pExpr->x.pList; |
| 104711 | | - CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft); |
| 105244 | + ExprList *pList; |
| 105245 | + CollSeq *pColl; |
| 104712 | 105246 | int labelOk = sqlite3VdbeMakeLabel(pParse); |
| 104713 | 105247 | int r2, regToFree; |
| 104714 | 105248 | int regCkNull = 0; |
| 104715 | 105249 | int ii; |
| 104716 | | - assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 105250 | + assert( ExprUseXList(pExpr) ); |
| 105251 | + pList = pExpr->x.pList; |
| 105252 | + pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft); |
| 104717 | 105253 | if( destIfNull!=destIfFalse ){ |
| 104718 | 105254 | regCkNull = sqlite3GetTempReg(pParse); |
| 104719 | 105255 | sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull); |
| 104720 | 105256 | } |
| 104721 | 105257 | for(ii=0; ii<pList->nExpr; ii++){ |
| | @@ -105097,10 +105633,11 @@ |
| 105097 | 105633 | #endif |
| 105098 | 105634 | }else{ |
| 105099 | 105635 | int i; |
| 105100 | 105636 | iResult = pParse->nMem+1; |
| 105101 | 105637 | pParse->nMem += nResult; |
| 105638 | + assert( ExprUseXList(p) ); |
| 105102 | 105639 | for(i=0; i<nResult; i++){ |
| 105103 | 105640 | sqlite3ExprCodeFactorable(pParse, p->x.pList->a[i].pExpr, i+iResult); |
| 105104 | 105641 | } |
| 105105 | 105642 | } |
| 105106 | 105643 | } |
| | @@ -105295,10 +105832,11 @@ |
| 105295 | 105832 | ** datatype by applying the Affinity of the table column to the |
| 105296 | 105833 | ** constant. |
| 105297 | 105834 | */ |
| 105298 | 105835 | int aff; |
| 105299 | 105836 | iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target); |
| 105837 | + assert( ExprUseYTab(pExpr) ); |
| 105300 | 105838 | if( pExpr->y.pTab ){ |
| 105301 | 105839 | aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn); |
| 105302 | 105840 | }else{ |
| 105303 | 105841 | aff = pExpr->affExpr; |
| 105304 | 105842 | } |
| | @@ -105318,13 +105856,15 @@ |
| 105318 | 105856 | ** The row is unpacked into registers beginning at |
| 105319 | 105857 | ** 0-(pParse->iSelfTab). The rowid (if any) is in a register |
| 105320 | 105858 | ** immediately prior to the first column. |
| 105321 | 105859 | */ |
| 105322 | 105860 | Column *pCol; |
| 105323 | | - Table *pTab = pExpr->y.pTab; |
| 105861 | + Table *pTab; |
| 105324 | 105862 | int iSrc; |
| 105325 | 105863 | int iCol = pExpr->iColumn; |
| 105864 | + assert( ExprUseYTab(pExpr) ); |
| 105865 | + pTab = pExpr->y.pTab; |
| 105326 | 105866 | assert( pTab!=0 ); |
| 105327 | 105867 | assert( iCol>=XN_ROWID ); |
| 105328 | 105868 | assert( iCol<pTab->nCol ); |
| 105329 | 105869 | if( iCol<0 ){ |
| 105330 | 105870 | return -1-pParse->iSelfTab; |
| | @@ -105358,10 +105898,11 @@ |
| 105358 | 105898 | /* Coding an expression that is part of an index where column names |
| 105359 | 105899 | ** in the index refer to the table to which the index belongs */ |
| 105360 | 105900 | iTab = pParse->iSelfTab - 1; |
| 105361 | 105901 | } |
| 105362 | 105902 | } |
| 105903 | + assert( ExprUseYTab(pExpr) ); |
| 105363 | 105904 | iReg = sqlite3ExprCodeGetColumn(pParse, pExpr->y.pTab, |
| 105364 | 105905 | pExpr->iColumn, iTab, target, |
| 105365 | 105906 | pExpr->op2); |
| 105366 | 105907 | if( pExpr->y.pTab==0 && pExpr->affExpr==SQLITE_AFF_REAL ){ |
| 105367 | 105908 | sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg); |
| | @@ -105435,10 +105976,11 @@ |
| 105435 | 105976 | inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target); |
| 105436 | 105977 | if( inReg!=target ){ |
| 105437 | 105978 | sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target); |
| 105438 | 105979 | inReg = target; |
| 105439 | 105980 | } |
| 105981 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 105440 | 105982 | sqlite3VdbeAddOp2(v, OP_Cast, target, |
| 105441 | 105983 | sqlite3AffinityType(pExpr->u.zToken, 0)); |
| 105442 | 105984 | return inReg; |
| 105443 | 105985 | } |
| 105444 | 105986 | #endif /* SQLITE_OMIT_CAST */ |
| | @@ -105602,12 +106144,12 @@ |
| 105602 | 106144 | if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){ |
| 105603 | 106145 | /* SQL functions can be expensive. So try to avoid running them |
| 105604 | 106146 | ** multiple times if we know they always give the same result */ |
| 105605 | 106147 | return sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1); |
| 105606 | 106148 | } |
| 105607 | | - assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 105608 | 106149 | assert( !ExprHasProperty(pExpr, EP_TokenOnly) ); |
| 106150 | + assert( ExprUseXList(pExpr) ); |
| 105609 | 106151 | pFarg = pExpr->x.pList; |
| 105610 | 106152 | nFarg = pFarg ? pFarg->nExpr : 0; |
| 105611 | 106153 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 105612 | 106154 | zId = pExpr->u.zToken; |
| 105613 | 106155 | pDef = sqlite3FindFunction(db, zId, nFarg, enc, 0); |
| | @@ -105692,11 +106234,11 @@ |
| 105692 | 106234 | if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 105693 | 106235 | if( !pColl ) pColl = db->pDfltColl; |
| 105694 | 106236 | sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ); |
| 105695 | 106237 | } |
| 105696 | 106238 | #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC |
| 105697 | | - if( pDef->funcFlags & SQLITE_FUNC_OFFSET ){ |
| 106239 | + if( (pDef->funcFlags & SQLITE_FUNC_OFFSET)!=0 && ALWAYS(pFarg!=0) ){ |
| 105698 | 106240 | Expr *pArg = pFarg->a[0].pExpr; |
| 105699 | 106241 | if( pArg->op==TK_COLUMN ){ |
| 105700 | 106242 | sqlite3VdbeAddOp3(v, OP_Offset, pArg->iTable, pArg->iColumn, target); |
| 105701 | 106243 | }else{ |
| 105702 | 106244 | sqlite3VdbeAddOp2(v, OP_Null, 0, target); |
| | @@ -105722,11 +106264,14 @@ |
| 105722 | 106264 | int nCol; |
| 105723 | 106265 | testcase( op==TK_EXISTS ); |
| 105724 | 106266 | testcase( op==TK_SELECT ); |
| 105725 | 106267 | if( pParse->db->mallocFailed ){ |
| 105726 | 106268 | return 0; |
| 105727 | | - }else if( op==TK_SELECT && (nCol = pExpr->x.pSelect->pEList->nExpr)!=1 ){ |
| 106269 | + }else if( op==TK_SELECT |
| 106270 | + && ALWAYS( ExprUseXSelect(pExpr) ) |
| 106271 | + && (nCol = pExpr->x.pSelect->pEList->nExpr)!=1 |
| 106272 | + ){ |
| 105728 | 106273 | sqlite3SubselectError(pParse, nCol, 1); |
| 105729 | 106274 | }else{ |
| 105730 | 106275 | return sqlite3CodeSubselect(pParse, pExpr); |
| 105731 | 106276 | } |
| 105732 | 106277 | break; |
| | @@ -105804,13 +106349,18 @@ |
| 105804 | 106349 | ** |
| 105805 | 106350 | ** p1==0 -> old.rowid p1==3 -> new.rowid |
| 105806 | 106351 | ** p1==1 -> old.a p1==4 -> new.a |
| 105807 | 106352 | ** p1==2 -> old.b p1==5 -> new.b |
| 105808 | 106353 | */ |
| 105809 | | - Table *pTab = pExpr->y.pTab; |
| 105810 | | - int iCol = pExpr->iColumn; |
| 105811 | | - int p1 = pExpr->iTable * (pTab->nCol+1) + 1 |
| 106354 | + Table *pTab; |
| 106355 | + int iCol; |
| 106356 | + int p1; |
| 106357 | + |
| 106358 | + assert( ExprUseYTab(pExpr) ); |
| 106359 | + pTab = pExpr->y.pTab; |
| 106360 | + iCol = pExpr->iColumn; |
| 106361 | + p1 = pExpr->iTable * (pTab->nCol+1) + 1 |
| 105812 | 106362 | + sqlite3TableColumnToStorage(pTab, iCol); |
| 105813 | 106363 | |
| 105814 | 106364 | assert( pExpr->iTable==0 || pExpr->iTable==1 ); |
| 105815 | 106365 | assert( iCol>=-1 && iCol<pTab->nCol ); |
| 105816 | 106366 | assert( pTab->iPKey<0 || iCol!=pTab->iPKey ); |
| | @@ -105894,11 +106444,11 @@ |
| 105894 | 106444 | Expr *pX; /* The X expression */ |
| 105895 | 106445 | Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */ |
| 105896 | 106446 | Expr *pDel = 0; |
| 105897 | 106447 | sqlite3 *db = pParse->db; |
| 105898 | 106448 | |
| 105899 | | - assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList ); |
| 106449 | + assert( ExprUseXList(pExpr) && pExpr->x.pList!=0 ); |
| 105900 | 106450 | assert(pExpr->x.pList->nExpr > 0); |
| 105901 | 106451 | pEList = pExpr->x.pList; |
| 105902 | 106452 | aListelem = pEList->a; |
| 105903 | 106453 | nExpr = pEList->nExpr; |
| 105904 | 106454 | endLabel = sqlite3VdbeMakeLabel(pParse); |
| | @@ -106239,11 +106789,11 @@ |
| 106239 | 106789 | |
| 106240 | 106790 | memset(&compLeft, 0, sizeof(Expr)); |
| 106241 | 106791 | memset(&compRight, 0, sizeof(Expr)); |
| 106242 | 106792 | memset(&exprAnd, 0, sizeof(Expr)); |
| 106243 | 106793 | |
| 106244 | | - assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 106794 | + assert( ExprUseXList(pExpr) ); |
| 106245 | 106795 | pDel = sqlite3ExprDup(db, pExpr->pLeft, 0); |
| 106246 | 106796 | if( db->mallocFailed==0 ){ |
| 106247 | 106797 | exprAnd.op = TK_AND; |
| 106248 | 106798 | exprAnd.pLeft = &compLeft; |
| 106249 | 106799 | exprAnd.pRight = &compRight; |
| | @@ -106714,11 +107264,13 @@ |
| 106714 | 107264 | if( pB->op==TK_COLLATE && sqlite3ExprCompare(pParse, pA,pB->pLeft,iTab)<2 ){ |
| 106715 | 107265 | return 1; |
| 106716 | 107266 | } |
| 106717 | 107267 | return 2; |
| 106718 | 107268 | } |
| 106719 | | - if( pA->op!=TK_COLUMN && pA->op!=TK_AGG_COLUMN && pA->u.zToken ){ |
| 107269 | + assert( !ExprHasProperty(pA, EP_IntValue) ); |
| 107270 | + assert( !ExprHasProperty(pB, EP_IntValue) ); |
| 107271 | + if( pA->u.zToken ){ |
| 106720 | 107272 | if( pA->op==TK_FUNCTION || pA->op==TK_AGG_FUNCTION ){ |
| 106721 | 107273 | if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2; |
| 106722 | 107274 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 106723 | 107275 | assert( pA->op==pB->op ); |
| 106724 | 107276 | if( ExprHasProperty(pA,EP_WinFunc)!=ExprHasProperty(pB,EP_WinFunc) ){ |
| | @@ -106732,11 +107284,16 @@ |
| 106732 | 107284 | #endif |
| 106733 | 107285 | }else if( pA->op==TK_NULL ){ |
| 106734 | 107286 | return 0; |
| 106735 | 107287 | }else if( pA->op==TK_COLLATE ){ |
| 106736 | 107288 | if( sqlite3_stricmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2; |
| 106737 | | - }else if( ALWAYS(pB->u.zToken!=0) && strcmp(pA->u.zToken,pB->u.zToken)!=0 ){ |
| 107289 | + }else |
| 107290 | + if( pB->u.zToken!=0 |
| 107291 | + && pA->op!=TK_COLUMN |
| 107292 | + && pA->op!=TK_AGG_COLUMN |
| 107293 | + && strcmp(pA->u.zToken,pB->u.zToken)!=0 |
| 107294 | + ){ |
| 106738 | 107295 | return 2; |
| 106739 | 107296 | } |
| 106740 | 107297 | } |
| 106741 | 107298 | if( (pA->flags & (EP_Distinct|EP_Commuted)) |
| 106742 | 107299 | != (pB->flags & (EP_Distinct|EP_Commuted)) ) return 2; |
| | @@ -106821,16 +107378,17 @@ |
| 106821 | 107378 | return pNN->op!=TK_NULL; |
| 106822 | 107379 | } |
| 106823 | 107380 | switch( p->op ){ |
| 106824 | 107381 | case TK_IN: { |
| 106825 | 107382 | if( seenNot && ExprHasProperty(p, EP_xIsSelect) ) return 0; |
| 106826 | | - assert( ExprHasProperty(p,EP_xIsSelect) |
| 106827 | | - || (p->x.pList!=0 && p->x.pList->nExpr>0) ); |
| 107383 | + assert( ExprUseXSelect(p) || (p->x.pList!=0 && p->x.pList->nExpr>0) ); |
| 106828 | 107384 | return exprImpliesNotNull(pParse, p->pLeft, pNN, iTab, 1); |
| 106829 | 107385 | } |
| 106830 | 107386 | case TK_BETWEEN: { |
| 106831 | | - ExprList *pList = p->x.pList; |
| 107387 | + ExprList *pList; |
| 107388 | + assert( ExprUseXList(p) ); |
| 107389 | + pList = p->x.pList; |
| 106832 | 107390 | assert( pList!=0 ); |
| 106833 | 107391 | assert( pList->nExpr==2 ); |
| 106834 | 107392 | if( seenNot ) return 0; |
| 106835 | 107393 | if( exprImpliesNotNull(pParse, pList->a[0].pExpr, pNN, iTab, 1) |
| 106836 | 107394 | || exprImpliesNotNull(pParse, pList->a[1].pExpr, pNN, iTab, 1) |
| | @@ -107003,14 +107561,18 @@ |
| 107003 | 107561 | testcase( pExpr->op==TK_LE ); |
| 107004 | 107562 | testcase( pExpr->op==TK_GT ); |
| 107005 | 107563 | testcase( pExpr->op==TK_GE ); |
| 107006 | 107564 | /* The y.pTab=0 assignment in wherecode.c always happens after the |
| 107007 | 107565 | ** impliesNotNullRow() test */ |
| 107008 | | - if( (pLeft->op==TK_COLUMN && pLeft->y.pTab!=0 |
| 107009 | | - && IsVirtual(pLeft->y.pTab)) |
| 107010 | | - || (pRight->op==TK_COLUMN && pRight->y.pTab!=0 |
| 107011 | | - && IsVirtual(pRight->y.pTab)) |
| 107566 | + assert( pLeft->op!=TK_COLUMN || ExprUseYTab(pLeft) ); |
| 107567 | + assert( pRight->op!=TK_COLUMN || ExprUseYTab(pRight) ); |
| 107568 | + if( (pLeft->op==TK_COLUMN |
| 107569 | + && pLeft->y.pTab!=0 |
| 107570 | + && IsVirtual(pLeft->y.pTab)) |
| 107571 | + || (pRight->op==TK_COLUMN |
| 107572 | + && pRight->y.pTab!=0 |
| 107573 | + && IsVirtual(pRight->y.pTab)) |
| 107012 | 107574 | ){ |
| 107013 | 107575 | return WRC_Prune; |
| 107014 | 107576 | } |
| 107015 | 107577 | /* no break */ deliberate_fall_through |
| 107016 | 107578 | } |
| | @@ -107115,92 +107677,129 @@ |
| 107115 | 107677 | sqlite3WalkExpr(&w, pExpr); |
| 107116 | 107678 | return !w.eCode; |
| 107117 | 107679 | } |
| 107118 | 107680 | |
| 107119 | 107681 | |
| 107120 | | -/* |
| 107121 | | -** An instance of the following structure is used by the tree walker |
| 107122 | | -** to count references to table columns in the arguments of an |
| 107123 | | -** aggregate function, in order to implement the |
| 107124 | | -** sqlite3FunctionThisSrc() routine. |
| 107682 | +/* Structure used to pass information throught the Walker in order to |
| 107683 | +** implement sqlite3ReferencesSrcList(). |
| 107125 | 107684 | */ |
| 107126 | | -struct SrcCount { |
| 107127 | | - SrcList *pSrc; /* One particular FROM clause in a nested query */ |
| 107128 | | - int iSrcInner; /* Smallest cursor number in this context */ |
| 107129 | | - int nThis; /* Number of references to columns in pSrcList */ |
| 107130 | | - int nOther; /* Number of references to columns in other FROM clauses */ |
| 107685 | +struct RefSrcList { |
| 107686 | + sqlite3 *db; /* Database connection used for sqlite3DbRealloc() */ |
| 107687 | + SrcList *pRef; /* Looking for references to these tables */ |
| 107688 | + i64 nExclude; /* Number of tables to exclude from the search */ |
| 107689 | + int *aiExclude; /* Cursor IDs for tables to exclude from the search */ |
| 107131 | 107690 | }; |
| 107132 | 107691 | |
| 107133 | 107692 | /* |
| 107134 | | -** xSelect callback for sqlite3FunctionUsesThisSrc(). If this is the first |
| 107135 | | -** SELECT with a FROM clause encountered during this iteration, set |
| 107136 | | -** SrcCount.iSrcInner to the cursor number of the leftmost object in |
| 107137 | | -** the FROM cause. |
| 107693 | +** Walker SELECT callbacks for sqlite3ReferencesSrcList(). |
| 107694 | +** |
| 107695 | +** When entering a new subquery on the pExpr argument, add all FROM clause |
| 107696 | +** entries for that subquery to the exclude list. |
| 107697 | +** |
| 107698 | +** When leaving the subquery, remove those entries from the exclude list. |
| 107138 | 107699 | */ |
| 107139 | | -static int selectSrcCount(Walker *pWalker, Select *pSel){ |
| 107140 | | - struct SrcCount *p = pWalker->u.pSrcCount; |
| 107141 | | - if( p->iSrcInner==0x7FFFFFFF && ALWAYS(pSel->pSrc) && pSel->pSrc->nSrc ){ |
| 107142 | | - pWalker->u.pSrcCount->iSrcInner = pSel->pSrc->a[0].iCursor; |
| 107700 | +static int selectRefEnter(Walker *pWalker, Select *pSelect){ |
| 107701 | + struct RefSrcList *p = pWalker->u.pRefSrcList; |
| 107702 | + SrcList *pSrc = pSelect->pSrc; |
| 107703 | + i64 i, j; |
| 107704 | + int *piNew; |
| 107705 | + if( pSrc->nSrc==0 ) return WRC_Continue; |
| 107706 | + j = p->nExclude; |
| 107707 | + p->nExclude += pSrc->nSrc; |
| 107708 | + piNew = sqlite3DbRealloc(p->db, p->aiExclude, p->nExclude*sizeof(int)); |
| 107709 | + if( piNew==0 ){ |
| 107710 | + p->nExclude = 0; |
| 107711 | + return WRC_Abort; |
| 107712 | + }else{ |
| 107713 | + p->aiExclude = piNew; |
| 107714 | + } |
| 107715 | + for(i=0; i<pSrc->nSrc; i++, j++){ |
| 107716 | + p->aiExclude[j] = pSrc->a[i].iCursor; |
| 107143 | 107717 | } |
| 107144 | 107718 | return WRC_Continue; |
| 107145 | 107719 | } |
| 107146 | | - |
| 107147 | | -/* |
| 107148 | | -** Count the number of references to columns. |
| 107149 | | -*/ |
| 107150 | | -static int exprSrcCount(Walker *pWalker, Expr *pExpr){ |
| 107151 | | - /* There was once a NEVER() on the second term on the grounds that |
| 107152 | | - ** sqlite3FunctionUsesThisSrc() was always called before |
| 107153 | | - ** sqlite3ExprAnalyzeAggregates() and so the TK_COLUMNs have not yet |
| 107154 | | - ** been converted into TK_AGG_COLUMN. But this is no longer true due |
| 107155 | | - ** to window functions - sqlite3WindowRewrite() may now indirectly call |
| 107156 | | - ** FunctionUsesThisSrc() when creating a new sub-select. */ |
| 107157 | | - if( pExpr->op==TK_COLUMN || pExpr->op==TK_AGG_COLUMN ){ |
| 107158 | | - int i; |
| 107159 | | - struct SrcCount *p = pWalker->u.pSrcCount; |
| 107160 | | - SrcList *pSrc = p->pSrc; |
| 107720 | +static void selectRefLeave(Walker *pWalker, Select *pSelect){ |
| 107721 | + struct RefSrcList *p = pWalker->u.pRefSrcList; |
| 107722 | + SrcList *pSrc = pSelect->pSrc; |
| 107723 | + if( p->nExclude ){ |
| 107724 | + assert( p->nExclude>=pSrc->nSrc ); |
| 107725 | + p->nExclude -= pSrc->nSrc; |
| 107726 | + } |
| 107727 | +} |
| 107728 | + |
| 107729 | +/* This is the Walker EXPR callback for sqlite3ReferencesSrcList(). |
| 107730 | +** |
| 107731 | +** Set the 0x01 bit of pWalker->eCode if there is a reference to any |
| 107732 | +** of the tables shown in RefSrcList.pRef. |
| 107733 | +** |
| 107734 | +** Set the 0x02 bit of pWalker->eCode if there is a reference to a |
| 107735 | +** table is in neither RefSrcList.pRef nor RefSrcList.aiExclude. |
| 107736 | +*/ |
| 107737 | +static int exprRefToSrcList(Walker *pWalker, Expr *pExpr){ |
| 107738 | + if( pExpr->op==TK_COLUMN |
| 107739 | + || pExpr->op==TK_AGG_COLUMN |
| 107740 | + ){ |
| 107741 | + int i; |
| 107742 | + struct RefSrcList *p = pWalker->u.pRefSrcList; |
| 107743 | + SrcList *pSrc = p->pRef; |
| 107161 | 107744 | int nSrc = pSrc ? pSrc->nSrc : 0; |
| 107162 | 107745 | for(i=0; i<nSrc; i++){ |
| 107163 | | - if( pExpr->iTable==pSrc->a[i].iCursor ) break; |
| 107164 | | - } |
| 107165 | | - if( i<nSrc ){ |
| 107166 | | - p->nThis++; |
| 107167 | | - }else if( pExpr->iTable<p->iSrcInner ){ |
| 107168 | | - /* In a well-formed parse tree (no name resolution errors), |
| 107169 | | - ** TK_COLUMN nodes with smaller Expr.iTable values are in an |
| 107170 | | - ** outer context. Those are the only ones to count as "other" */ |
| 107171 | | - p->nOther++; |
| 107746 | + if( pExpr->iTable==pSrc->a[i].iCursor ){ |
| 107747 | + pWalker->eCode |= 1; |
| 107748 | + return WRC_Continue; |
| 107749 | + } |
| 107750 | + } |
| 107751 | + for(i=0; i<p->nExclude && p->aiExclude[i]!=pExpr->iTable; i++){} |
| 107752 | + if( i>=p->nExclude ){ |
| 107753 | + pWalker->eCode |= 2; |
| 107172 | 107754 | } |
| 107173 | 107755 | } |
| 107174 | 107756 | return WRC_Continue; |
| 107175 | 107757 | } |
| 107176 | 107758 | |
| 107177 | 107759 | /* |
| 107178 | | -** Determine if any of the arguments to the pExpr Function reference |
| 107179 | | -** pSrcList. Return true if they do. Also return true if the function |
| 107180 | | -** has no arguments or has only constant arguments. Return false if pExpr |
| 107181 | | -** references columns but not columns of tables found in pSrcList. |
| 107760 | +** Check to see if pExpr references any tables in pSrcList. |
| 107761 | +** Possible return values: |
| 107762 | +** |
| 107763 | +** 1 pExpr does references a table in pSrcList. |
| 107764 | +** |
| 107765 | +** 0 pExpr references some table that is not defined in either |
| 107766 | +** pSrcList or in subqueries of pExpr itself. |
| 107767 | +** |
| 107768 | +** -1 pExpr only references no tables at all, or it only |
| 107769 | +** references tables defined in subqueries of pExpr itself. |
| 107770 | +** |
| 107771 | +** As currently used, pExpr is always an aggregate function call. That |
| 107772 | +** fact is exploited for efficiency. |
| 107182 | 107773 | */ |
| 107183 | | -SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr *pExpr, SrcList *pSrcList){ |
| 107774 | +SQLITE_PRIVATE int sqlite3ReferencesSrcList(Parse *pParse, Expr *pExpr, SrcList *pSrcList){ |
| 107184 | 107775 | Walker w; |
| 107185 | | - struct SrcCount cnt; |
| 107776 | + struct RefSrcList x; |
| 107777 | + memset(&w, 0, sizeof(w)); |
| 107778 | + memset(&x, 0, sizeof(x)); |
| 107779 | + w.xExprCallback = exprRefToSrcList; |
| 107780 | + w.xSelectCallback = selectRefEnter; |
| 107781 | + w.xSelectCallback2 = selectRefLeave; |
| 107782 | + w.u.pRefSrcList = &x; |
| 107783 | + x.db = pParse->db; |
| 107784 | + x.pRef = pSrcList; |
| 107186 | 107785 | assert( pExpr->op==TK_AGG_FUNCTION ); |
| 107187 | | - memset(&w, 0, sizeof(w)); |
| 107188 | | - w.xExprCallback = exprSrcCount; |
| 107189 | | - w.xSelectCallback = selectSrcCount; |
| 107190 | | - w.u.pSrcCount = &cnt; |
| 107191 | | - cnt.pSrc = pSrcList; |
| 107192 | | - cnt.iSrcInner = (pSrcList&&pSrcList->nSrc)?pSrcList->a[0].iCursor:0x7FFFFFFF; |
| 107193 | | - cnt.nThis = 0; |
| 107194 | | - cnt.nOther = 0; |
| 107786 | + assert( ExprUseXList(pExpr) ); |
| 107195 | 107787 | sqlite3WalkExprList(&w, pExpr->x.pList); |
| 107196 | 107788 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 107197 | 107789 | if( ExprHasProperty(pExpr, EP_WinFunc) ){ |
| 107198 | 107790 | sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter); |
| 107199 | 107791 | } |
| 107200 | 107792 | #endif |
| 107201 | | - return cnt.nThis>0 || cnt.nOther==0; |
| 107793 | + sqlite3DbFree(pParse->db, x.aiExclude); |
| 107794 | + if( w.eCode & 0x01 ){ |
| 107795 | + return 1; |
| 107796 | + }else if( w.eCode ){ |
| 107797 | + return 0; |
| 107798 | + }else{ |
| 107799 | + return -1; |
| 107800 | + } |
| 107202 | 107801 | } |
| 107203 | 107802 | |
| 107204 | 107803 | /* |
| 107205 | 107804 | ** This is a Walker expression node callback. |
| 107206 | 107805 | ** |
| | @@ -107331,10 +107930,11 @@ |
| 107331 | 107930 | } |
| 107332 | 107931 | if( (k>=pAggInfo->nColumn) |
| 107333 | 107932 | && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0 |
| 107334 | 107933 | ){ |
| 107335 | 107934 | pCol = &pAggInfo->aCol[k]; |
| 107935 | + assert( ExprUseYTab(pExpr) ); |
| 107336 | 107936 | pCol->pTab = pExpr->y.pTab; |
| 107337 | 107937 | pCol->iTable = pExpr->iTable; |
| 107338 | 107938 | pCol->iColumn = pExpr->iColumn; |
| 107339 | 107939 | pCol->iMem = ++pParse->nMem; |
| 107340 | 107940 | pCol->iSorterColumn = -1; |
| | @@ -107394,11 +107994,11 @@ |
| 107394 | 107994 | if( i>=0 ){ |
| 107395 | 107995 | assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 107396 | 107996 | pItem = &pAggInfo->aFunc[i]; |
| 107397 | 107997 | pItem->pFExpr = pExpr; |
| 107398 | 107998 | pItem->iMem = ++pParse->nMem; |
| 107399 | | - assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 107999 | + assert( ExprUseUToken(pExpr) ); |
| 107400 | 108000 | pItem->pFunc = sqlite3FindFunction(pParse->db, |
| 107401 | 108001 | pExpr->u.zToken, |
| 107402 | 108002 | pExpr->x.pList ? pExpr->x.pList->nExpr : 0, enc, 0); |
| 107403 | 108003 | if( pExpr->flags & EP_Distinct ){ |
| 107404 | 108004 | pItem->iDistinct = pParse->nTab++; |
| | @@ -107609,11 +108209,11 @@ |
| 107609 | 108209 | int bNoDQS /* Do not allow DQS in the schema */ |
| 107610 | 108210 | ){ |
| 107611 | 108211 | pParse->colNamesSet = 1; |
| 107612 | 108212 | sqlite3NestedParse(pParse, |
| 107613 | 108213 | "SELECT 1 " |
| 107614 | | - "FROM \"%w\"." DFLT_SCHEMA_TABLE " " |
| 108214 | + "FROM \"%w\"." LEGACY_SCHEMA_TABLE " " |
| 107615 | 108215 | "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" |
| 107616 | 108216 | " AND sql NOT LIKE 'create virtual%%'" |
| 107617 | 108217 | " AND sqlite_rename_test(%Q, sql, type, name, %d, %Q, %d)=NULL ", |
| 107618 | 108218 | zDb, |
| 107619 | 108219 | zDb, bTemp, zWhen, bNoDQS |
| | @@ -107620,11 +108220,11 @@ |
| 107620 | 108220 | ); |
| 107621 | 108221 | |
| 107622 | 108222 | if( bTemp==0 ){ |
| 107623 | 108223 | sqlite3NestedParse(pParse, |
| 107624 | 108224 | "SELECT 1 " |
| 107625 | | - "FROM temp." DFLT_SCHEMA_TABLE " " |
| 108225 | + "FROM temp." LEGACY_SCHEMA_TABLE " " |
| 107626 | 108226 | "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" |
| 107627 | 108227 | " AND sql NOT LIKE 'create virtual%%'" |
| 107628 | 108228 | " AND sqlite_rename_test(%Q, sql, type, name, 1, %Q, %d)=NULL ", |
| 107629 | 108229 | zDb, zWhen, bNoDQS |
| 107630 | 108230 | ); |
| | @@ -107638,18 +108238,18 @@ |
| 107638 | 108238 | ** not true, similarly update all SQL statements in the sqlite_schema table |
| 107639 | 108239 | ** of the temp db. |
| 107640 | 108240 | */ |
| 107641 | 108241 | static void renameFixQuotes(Parse *pParse, const char *zDb, int bTemp){ |
| 107642 | 108242 | sqlite3NestedParse(pParse, |
| 107643 | | - "UPDATE \"%w\"." DFLT_SCHEMA_TABLE |
| 108243 | + "UPDATE \"%w\"." LEGACY_SCHEMA_TABLE |
| 107644 | 108244 | " SET sql = sqlite_rename_quotefix(%Q, sql)" |
| 107645 | 108245 | "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" |
| 107646 | 108246 | " AND sql NOT LIKE 'create virtual%%'" , zDb, zDb |
| 107647 | 108247 | ); |
| 107648 | 108248 | if( bTemp==0 ){ |
| 107649 | 108249 | sqlite3NestedParse(pParse, |
| 107650 | | - "UPDATE temp." DFLT_SCHEMA_TABLE |
| 108250 | + "UPDATE temp." LEGACY_SCHEMA_TABLE |
| 107651 | 108251 | " SET sql = sqlite_rename_quotefix('temp', sql)" |
| 107652 | 108252 | "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" |
| 107653 | 108253 | " AND sql NOT LIKE 'create virtual%%'" |
| 107654 | 108254 | ); |
| 107655 | 108255 | } |
| | @@ -107763,21 +108363,21 @@ |
| 107763 | 108363 | nTabName = sqlite3Utf8CharLen(zTabName, -1); |
| 107764 | 108364 | |
| 107765 | 108365 | /* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in |
| 107766 | 108366 | ** the schema to use the new table name. */ |
| 107767 | 108367 | sqlite3NestedParse(pParse, |
| 107768 | | - "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " |
| 108368 | + "UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET " |
| 107769 | 108369 | "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, %d) " |
| 107770 | 108370 | "WHERE (type!='index' OR tbl_name=%Q COLLATE nocase)" |
| 107771 | 108371 | "AND name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" |
| 107772 | 108372 | , zDb, zDb, zTabName, zName, (iDb==1), zTabName |
| 107773 | 108373 | ); |
| 107774 | 108374 | |
| 107775 | 108375 | /* Update the tbl_name and name columns of the sqlite_schema table |
| 107776 | 108376 | ** as required. */ |
| 107777 | 108377 | sqlite3NestedParse(pParse, |
| 107778 | | - "UPDATE %Q." DFLT_SCHEMA_TABLE " SET " |
| 108378 | + "UPDATE %Q." LEGACY_SCHEMA_TABLE " SET " |
| 107779 | 108379 | "tbl_name = %Q, " |
| 107780 | 108380 | "name = CASE " |
| 107781 | 108381 | "WHEN type='table' THEN %Q " |
| 107782 | 108382 | "WHEN name LIKE 'sqliteX_autoindex%%' ESCAPE 'X' " |
| 107783 | 108383 | " AND type='index' THEN " |
| | @@ -107916,10 +108516,11 @@ |
| 107916 | 108516 | */ |
| 107917 | 108517 | assert( pDflt==0 || pDflt->op==TK_SPAN ); |
| 107918 | 108518 | if( pDflt && pDflt->pLeft->op==TK_NULL ){ |
| 107919 | 108519 | pDflt = 0; |
| 107920 | 108520 | } |
| 108521 | + assert( IsOrdinaryTable(pNew) ); |
| 107921 | 108522 | if( (db->flags&SQLITE_ForeignKeys) && pNew->u.tab.pFKey && pDflt ){ |
| 107922 | 108523 | sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, |
| 107923 | 108524 | "Cannot add a REFERENCES column with non-NULL default value"); |
| 107924 | 108525 | } |
| 107925 | 108526 | if( pCol->notNull && !pDflt ){ |
| | @@ -107958,13 +108559,14 @@ |
| 107958 | 108559 | while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){ |
| 107959 | 108560 | *zEnd-- = '\0'; |
| 107960 | 108561 | } |
| 107961 | 108562 | /* substr() operations on characters, but addColOffset is in bytes. So we |
| 107962 | 108563 | ** have to use printf() to translate between these units: */ |
| 107963 | | - assert( !IsVirtual(pTab) ); |
| 108564 | + assert( IsOrdinaryTable(pTab) ); |
| 108565 | + assert( IsOrdinaryTable(pNew) ); |
| 107964 | 108566 | sqlite3NestedParse(pParse, |
| 107965 | | - "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " |
| 108567 | + "UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET " |
| 107966 | 108568 | "sql = printf('%%.%ds, ',sql) || %Q" |
| 107967 | 108569 | " || substr(sql,1+length(printf('%%.%ds',sql))) " |
| 107968 | 108570 | "WHERE type = 'table' AND name = %Q", |
| 107969 | 108571 | zDb, pNew->u.tab.addColOffset, zCol, pNew->u.tab.addColOffset, |
| 107970 | 108572 | zTab |
| | @@ -107986,11 +108588,11 @@ |
| 107986 | 108588 | VdbeCoverage(v); |
| 107987 | 108589 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, 3); |
| 107988 | 108590 | sqlite3ReleaseTempReg(pParse, r1); |
| 107989 | 108591 | |
| 107990 | 108592 | /* Reload the table definition */ |
| 107991 | | - renameReloadSchema(pParse, iDb, INITFLAG_AlterRename); |
| 108593 | + renameReloadSchema(pParse, iDb, INITFLAG_AlterAdd); |
| 107992 | 108594 | |
| 107993 | 108595 | /* Verify that constraints are still satisfied */ |
| 107994 | 108596 | if( pNew->pCheck!=0 |
| 107995 | 108597 | || (pCol->notNull && (pCol->colFlags & COLFLAG_GENERATED)!=0) |
| 107996 | 108598 | ){ |
| | @@ -108052,10 +108654,11 @@ |
| 108052 | 108654 | if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){ |
| 108053 | 108655 | goto exit_begin_add_column; |
| 108054 | 108656 | } |
| 108055 | 108657 | |
| 108056 | 108658 | sqlite3MayAbort(pParse); |
| 108659 | + assert( IsOrdinaryTable(pTab) ); |
| 108057 | 108660 | assert( pTab->u.tab.addColOffset>0 ); |
| 108058 | 108661 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 108059 | 108662 | |
| 108060 | 108663 | /* Put a copy of the Table struct in Parse.pNewTable for the |
| 108061 | 108664 | ** sqlite3AddColumn() function and friends to modify. But modify |
| | @@ -108082,11 +108685,11 @@ |
| 108082 | 108685 | for(i=0; i<pNew->nCol; i++){ |
| 108083 | 108686 | Column *pCol = &pNew->aCol[i]; |
| 108084 | 108687 | pCol->zCnName = sqlite3DbStrDup(db, pCol->zCnName); |
| 108085 | 108688 | pCol->hName = sqlite3StrIHash(pCol->zCnName); |
| 108086 | 108689 | } |
| 108087 | | - assert( !IsVirtual(pNew) ); |
| 108690 | + assert( IsOrdinaryTable(pNew) ); |
| 108088 | 108691 | pNew->u.tab.pDfltList = sqlite3ExprListDup(db, pTab->u.tab.pDfltList, 0); |
| 108089 | 108692 | pNew->pSchema = db->aDb[iDb].pSchema; |
| 108090 | 108693 | pNew->u.tab.addColOffset = pTab->u.tab.addColOffset; |
| 108091 | 108694 | pNew->nTabRef = 1; |
| 108092 | 108695 | |
| | @@ -108193,21 +108796,21 @@ |
| 108193 | 108796 | zNew = sqlite3NameFromToken(db, pNew); |
| 108194 | 108797 | if( !zNew ) goto exit_rename_column; |
| 108195 | 108798 | assert( pNew->n>0 ); |
| 108196 | 108799 | bQuote = sqlite3Isquote(pNew->z[0]); |
| 108197 | 108800 | sqlite3NestedParse(pParse, |
| 108198 | | - "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " |
| 108801 | + "UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET " |
| 108199 | 108802 | "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) " |
| 108200 | 108803 | "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' " |
| 108201 | 108804 | " AND (type != 'index' OR tbl_name = %Q)", |
| 108202 | 108805 | zDb, |
| 108203 | 108806 | zDb, pTab->zName, iCol, zNew, bQuote, iSchema==1, |
| 108204 | 108807 | pTab->zName |
| 108205 | 108808 | ); |
| 108206 | 108809 | |
| 108207 | 108810 | sqlite3NestedParse(pParse, |
| 108208 | | - "UPDATE temp." DFLT_SCHEMA_TABLE " SET " |
| 108811 | + "UPDATE temp." LEGACY_SCHEMA_TABLE " SET " |
| 108209 | 108812 | "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, 1) " |
| 108210 | 108813 | "WHERE type IN ('trigger', 'view')", |
| 108211 | 108814 | zDb, pTab->zName, iCol, zNew, bQuote |
| 108212 | 108815 | ); |
| 108213 | 108816 | |
| | @@ -108351,11 +108954,13 @@ |
| 108351 | 108954 | ** Walker callback used by sqlite3RenameExprUnmap(). |
| 108352 | 108955 | */ |
| 108353 | 108956 | static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr){ |
| 108354 | 108957 | Parse *pParse = pWalker->pParse; |
| 108355 | 108958 | sqlite3RenameTokenRemap(pParse, 0, (const void*)pExpr); |
| 108356 | | - sqlite3RenameTokenRemap(pParse, 0, (const void*)&pExpr->y.pTab); |
| 108959 | + if( ExprUseYTab(pExpr) ){ |
| 108960 | + sqlite3RenameTokenRemap(pParse, 0, (const void*)&pExpr->y.pTab); |
| 108961 | + } |
| 108357 | 108962 | return WRC_Continue; |
| 108358 | 108963 | } |
| 108359 | 108964 | |
| 108360 | 108965 | /* |
| 108361 | 108966 | ** Iterate through the Select objects that are part of WITH clauses attached |
| | @@ -108413,11 +109018,13 @@ |
| 108413 | 109018 | */ |
| 108414 | 109019 | static int renameUnmapSelectCb(Walker *pWalker, Select *p){ |
| 108415 | 109020 | Parse *pParse = pWalker->pParse; |
| 108416 | 109021 | int i; |
| 108417 | 109022 | if( pParse->nErr ) return WRC_Abort; |
| 108418 | | - if( NEVER(p->selFlags & (SF_View|SF_CopyCte)) ){ |
| 109023 | + testcase( p->selFlags & SF_View ); |
| 109024 | + testcase( p->selFlags & SF_CopyCte ); |
| 109025 | + if( p->selFlags & (SF_View|SF_CopyCte) ){ |
| 108419 | 109026 | return WRC_Prune; |
| 108420 | 109027 | } |
| 108421 | 109028 | if( ALWAYS(p->pEList) ){ |
| 108422 | 109029 | ExprList *pList = p->pEList; |
| 108423 | 109030 | for(i=0; i<pList->nExpr; i++){ |
| | @@ -108550,10 +109157,11 @@ |
| 108550 | 109157 | && pWalker->pParse->pTriggerTab==p->pTab |
| 108551 | 109158 | ){ |
| 108552 | 109159 | renameTokenFind(pWalker->pParse, p, (void*)pExpr); |
| 108553 | 109160 | }else if( pExpr->op==TK_COLUMN |
| 108554 | 109161 | && pExpr->iColumn==p->iCol |
| 109162 | + && ALWAYS(ExprUseYTab(pExpr)) |
| 108555 | 109163 | && p->pTab==pExpr->y.pTab |
| 108556 | 109164 | ){ |
| 108557 | 109165 | renameTokenFind(pWalker->pParse, p, (void*)pExpr); |
| 108558 | 109166 | } |
| 108559 | 109167 | return WRC_Continue; |
| | @@ -108874,10 +109482,13 @@ |
| 108874 | 109482 | p->pTab->nTabRef++; |
| 108875 | 109483 | rc = sqlite3ViewGetColumnNames(pParse, p->pTab); |
| 108876 | 109484 | } |
| 108877 | 109485 | } |
| 108878 | 109486 | } |
| 109487 | + if( rc==SQLITE_OK && db->mallocFailed ){ |
| 109488 | + rc = SQLITE_NOMEM; |
| 109489 | + } |
| 108879 | 109490 | sNC.pSrcList = pSrc; |
| 108880 | 109491 | if( rc==SQLITE_OK && pStep->pWhere ){ |
| 108881 | 109492 | rc = sqlite3ResolveExprNames(&sNC, pStep->pWhere); |
| 108882 | 109493 | } |
| 108883 | 109494 | if( rc==SQLITE_OK ){ |
| | @@ -109080,11 +109691,11 @@ |
| 109080 | 109691 | sqlite3WalkExpr(&sWalker, pExpr); |
| 109081 | 109692 | } |
| 109082 | 109693 | #endif |
| 109083 | 109694 | } |
| 109084 | 109695 | |
| 109085 | | - assert( !IsVirtual(sParse.pNewTable) ); |
| 109696 | + assert( IsOrdinaryTable(sParse.pNewTable) ); |
| 109086 | 109697 | for(pFKey=sParse.pNewTable->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 109087 | 109698 | for(i=0; i<pFKey->nCol; i++){ |
| 109088 | 109699 | if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){ |
| 109089 | 109700 | renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]); |
| 109090 | 109701 | } |
| | @@ -109152,11 +109763,14 @@ |
| 109152 | 109763 | /* |
| 109153 | 109764 | ** Walker expression callback used by "RENAME TABLE". |
| 109154 | 109765 | */ |
| 109155 | 109766 | static int renameTableExprCb(Walker *pWalker, Expr *pExpr){ |
| 109156 | 109767 | RenameCtx *p = pWalker->u.pRename; |
| 109157 | | - if( pExpr->op==TK_COLUMN && p->pTab==pExpr->y.pTab ){ |
| 109768 | + if( pExpr->op==TK_COLUMN |
| 109769 | + && ALWAYS(ExprUseYTab(pExpr)) |
| 109770 | + && p->pTab==pExpr->y.pTab |
| 109771 | + ){ |
| 109158 | 109772 | renameTokenFind(pWalker->pParse, p, (void*)&pExpr->y.pTab); |
| 109159 | 109773 | } |
| 109160 | 109774 | return WRC_Continue; |
| 109161 | 109775 | } |
| 109162 | 109776 | |
| | @@ -109270,11 +109884,11 @@ |
| 109270 | 109884 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 109271 | 109885 | if( (isLegacy==0 || (db->flags & SQLITE_ForeignKeys)) |
| 109272 | 109886 | && !IsVirtual(pTab) |
| 109273 | 109887 | ){ |
| 109274 | 109888 | FKey *pFKey; |
| 109275 | | - assert( !IsVirtual(pTab) ); |
| 109889 | + assert( IsOrdinaryTable(pTab) ); |
| 109276 | 109890 | for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 109277 | 109891 | if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){ |
| 109278 | 109892 | renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo); |
| 109279 | 109893 | } |
| 109280 | 109894 | } |
| | @@ -109591,11 +110205,11 @@ |
| 109591 | 110205 | if( iCol<pTab->nCol-1 ){ |
| 109592 | 110206 | RenameToken *pEnd; |
| 109593 | 110207 | pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zCnName); |
| 109594 | 110208 | zEnd = (const char*)pEnd->t.z; |
| 109595 | 110209 | }else{ |
| 109596 | | - assert( !IsVirtual(pTab) ); |
| 110210 | + assert( IsOrdinaryTable(pTab) ); |
| 109597 | 110211 | zEnd = (const char*)&zSql[pTab->u.tab.addColOffset]; |
| 109598 | 110212 | while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--; |
| 109599 | 110213 | } |
| 109600 | 110214 | |
| 109601 | 110215 | zNew = sqlite3MPrintf(db, "%.*s%s", pCol->t.z-zSql, zSql, zEnd); |
| | @@ -109673,11 +110287,11 @@ |
| 109673 | 110287 | assert( iDb>=0 ); |
| 109674 | 110288 | zDb = db->aDb[iDb].zDbSName; |
| 109675 | 110289 | renameTestSchema(pParse, zDb, iDb==1, "", 0); |
| 109676 | 110290 | renameFixQuotes(pParse, zDb, iDb==1); |
| 109677 | 110291 | sqlite3NestedParse(pParse, |
| 109678 | | - "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " |
| 110292 | + "UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET " |
| 109679 | 110293 | "sql = sqlite_drop_column(%d, sql, %d) " |
| 109680 | 110294 | "WHERE (type=='table' AND tbl_name=%Q COLLATE nocase)" |
| 109681 | 110295 | , zDb, iDb, iCol, pTab->zName |
| 109682 | 110296 | ); |
| 109683 | 110297 | |
| | @@ -110766,11 +111380,11 @@ |
| 110766 | 111380 | pParse->nMem = MAX(pParse->nMem, iMem); |
| 110767 | 111381 | v = sqlite3GetVdbe(pParse); |
| 110768 | 111382 | if( v==0 || NEVER(pTab==0) ){ |
| 110769 | 111383 | return; |
| 110770 | 111384 | } |
| 110771 | | - if( pTab->tnum==0 ){ |
| 111385 | + if( !IsOrdinaryTable(pTab) ){ |
| 110772 | 111386 | /* Do not gather statistics on views or virtual tables */ |
| 110773 | 111387 | return; |
| 110774 | 111388 | } |
| 110775 | 111389 | if( sqlite3_strlike("sqlite\\_%", pTab->zName, '\\')==0 ){ |
| 110776 | 111390 | /* Do not gather statistics on system tables */ |
| | @@ -112049,21 +112663,22 @@ |
| 112049 | 112663 | if( pParse->nErr ) goto attach_end; |
| 112050 | 112664 | memset(&sName, 0, sizeof(NameContext)); |
| 112051 | 112665 | sName.pParse = pParse; |
| 112052 | 112666 | |
| 112053 | 112667 | if( |
| 112054 | | - SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) || |
| 112055 | | - SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) || |
| 112056 | | - SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey)) |
| 112668 | + SQLITE_OK!=resolveAttachExpr(&sName, pFilename) || |
| 112669 | + SQLITE_OK!=resolveAttachExpr(&sName, pDbname) || |
| 112670 | + SQLITE_OK!=resolveAttachExpr(&sName, pKey) |
| 112057 | 112671 | ){ |
| 112058 | 112672 | goto attach_end; |
| 112059 | 112673 | } |
| 112060 | 112674 | |
| 112061 | 112675 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 112062 | 112676 | if( pAuthArg ){ |
| 112063 | 112677 | char *zAuthArg; |
| 112064 | 112678 | if( pAuthArg->op==TK_STRING ){ |
| 112679 | + assert( !ExprHasProperty(pAuthArg, EP_IntValue) ); |
| 112065 | 112680 | zAuthArg = pAuthArg->u.zToken; |
| 112066 | 112681 | }else{ |
| 112067 | 112682 | zAuthArg = 0; |
| 112068 | 112683 | } |
| 112069 | 112684 | rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0); |
| | @@ -112744,21 +113359,26 @@ |
| 112744 | 113359 | Returning *pReturning = pParse->u1.pReturning; |
| 112745 | 113360 | int addrRewind; |
| 112746 | 113361 | int i; |
| 112747 | 113362 | int reg; |
| 112748 | 113363 | |
| 112749 | | - addrRewind = |
| 112750 | | - sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur); |
| 112751 | | - VdbeCoverage(v); |
| 112752 | | - reg = pReturning->iRetReg; |
| 112753 | | - for(i=0; i<pReturning->nRetCol; i++){ |
| 112754 | | - sqlite3VdbeAddOp3(v, OP_Column, pReturning->iRetCur, i, reg+i); |
| 112755 | | - } |
| 112756 | | - sqlite3VdbeAddOp2(v, OP_ResultRow, reg, i); |
| 112757 | | - sqlite3VdbeAddOp2(v, OP_Next, pReturning->iRetCur, addrRewind+1); |
| 112758 | | - VdbeCoverage(v); |
| 112759 | | - sqlite3VdbeJumpHere(v, addrRewind); |
| 113364 | + if( pReturning->nRetCol==0 ){ |
| 113365 | + assert( CORRUPT_DB ); |
| 113366 | + }else{ |
| 113367 | + sqlite3VdbeAddOp0(v, OP_FkCheck); |
| 113368 | + addrRewind = |
| 113369 | + sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur); |
| 113370 | + VdbeCoverage(v); |
| 113371 | + reg = pReturning->iRetReg; |
| 113372 | + for(i=0; i<pReturning->nRetCol; i++){ |
| 113373 | + sqlite3VdbeAddOp3(v, OP_Column, pReturning->iRetCur, i, reg+i); |
| 113374 | + } |
| 113375 | + sqlite3VdbeAddOp2(v, OP_ResultRow, reg, i); |
| 113376 | + sqlite3VdbeAddOp2(v, OP_Next, pReturning->iRetCur, addrRewind+1); |
| 113377 | + VdbeCoverage(v); |
| 113378 | + sqlite3VdbeJumpHere(v, addrRewind); |
| 113379 | + } |
| 112760 | 113380 | } |
| 112761 | 113381 | sqlite3VdbeAddOp0(v, OP_Halt); |
| 112762 | 113382 | |
| 112763 | 113383 | #if SQLITE_USER_AUTHENTICATION |
| 112764 | 113384 | if( pParse->nTableLock>0 && db->init.busy==0 ){ |
| | @@ -112835,11 +113455,15 @@ |
| 112835 | 113455 | } |
| 112836 | 113456 | } |
| 112837 | 113457 | |
| 112838 | 113458 | if( pParse->bReturning ){ |
| 112839 | 113459 | Returning *pRet = pParse->u1.pReturning; |
| 112840 | | - sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol); |
| 113460 | + if( pRet->nRetCol==0 ){ |
| 113461 | + assert( CORRUPT_DB ); |
| 113462 | + }else{ |
| 113463 | + sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol); |
| 113464 | + } |
| 112841 | 113465 | } |
| 112842 | 113466 | |
| 112843 | 113467 | /* Finally, jump back to the beginning of the executable code. */ |
| 112844 | 113468 | sqlite3VdbeGoto(v, 1); |
| 112845 | 113469 | } |
| | @@ -112953,21 +113577,21 @@ |
| 112953 | 113577 | } |
| 112954 | 113578 | } |
| 112955 | 113579 | p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName); |
| 112956 | 113580 | if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){ |
| 112957 | 113581 | if( i==1 ){ |
| 112958 | | - if( sqlite3StrICmp(zName+7, &ALT_TEMP_SCHEMA_TABLE[7])==0 |
| 112959 | | - || sqlite3StrICmp(zName+7, &ALT_SCHEMA_TABLE[7])==0 |
| 112960 | | - || sqlite3StrICmp(zName+7, &DFLT_SCHEMA_TABLE[7])==0 |
| 113582 | + if( sqlite3StrICmp(zName+7, &PREFERRED_TEMP_SCHEMA_TABLE[7])==0 |
| 113583 | + || sqlite3StrICmp(zName+7, &PREFERRED_SCHEMA_TABLE[7])==0 |
| 113584 | + || sqlite3StrICmp(zName+7, &LEGACY_SCHEMA_TABLE[7])==0 |
| 112961 | 113585 | ){ |
| 112962 | 113586 | p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, |
| 112963 | | - DFLT_TEMP_SCHEMA_TABLE); |
| 113587 | + LEGACY_TEMP_SCHEMA_TABLE); |
| 112964 | 113588 | } |
| 112965 | 113589 | }else{ |
| 112966 | | - if( sqlite3StrICmp(zName+7, &ALT_SCHEMA_TABLE[7])==0 ){ |
| 113590 | + if( sqlite3StrICmp(zName+7, &PREFERRED_SCHEMA_TABLE[7])==0 ){ |
| 112967 | 113591 | p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, |
| 112968 | | - DFLT_SCHEMA_TABLE); |
| 113592 | + LEGACY_SCHEMA_TABLE); |
| 112969 | 113593 | } |
| 112970 | 113594 | } |
| 112971 | 113595 | } |
| 112972 | 113596 | }else{ |
| 112973 | 113597 | /* Match against TEMP first */ |
| | @@ -112981,15 +113605,15 @@ |
| 112981 | 113605 | assert( sqlite3SchemaMutexHeld(db, i, 0) ); |
| 112982 | 113606 | p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName); |
| 112983 | 113607 | if( p ) break; |
| 112984 | 113608 | } |
| 112985 | 113609 | if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){ |
| 112986 | | - if( sqlite3StrICmp(zName+7, &ALT_SCHEMA_TABLE[7])==0 ){ |
| 112987 | | - p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, DFLT_SCHEMA_TABLE); |
| 112988 | | - }else if( sqlite3StrICmp(zName+7, &ALT_TEMP_SCHEMA_TABLE[7])==0 ){ |
| 113610 | + if( sqlite3StrICmp(zName+7, &PREFERRED_SCHEMA_TABLE[7])==0 ){ |
| 113611 | + p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, LEGACY_SCHEMA_TABLE); |
| 113612 | + }else if( sqlite3StrICmp(zName+7, &PREFERRED_TEMP_SCHEMA_TABLE[7])==0 ){ |
| 112989 | 113613 | p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, |
| 112990 | | - DFLT_TEMP_SCHEMA_TABLE); |
| 113614 | + LEGACY_TEMP_SCHEMA_TABLE); |
| 112991 | 113615 | } |
| 112992 | 113616 | } |
| 112993 | 113617 | } |
| 112994 | 113618 | return p; |
| 112995 | 113619 | } |
| | @@ -113080,10 +113704,26 @@ |
| 113080 | 113704 | }else{ |
| 113081 | 113705 | zDb = p->zDatabase; |
| 113082 | 113706 | } |
| 113083 | 113707 | return sqlite3LocateTable(pParse, flags, p->zName, zDb); |
| 113084 | 113708 | } |
| 113709 | + |
| 113710 | +/* |
| 113711 | +** Return the preferred table name for system tables. Translate legacy |
| 113712 | +** names into the new preferred names, as appropriate. |
| 113713 | +*/ |
| 113714 | +SQLITE_PRIVATE const char *sqlite3PreferredTableName(const char *zName){ |
| 113715 | + if( sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){ |
| 113716 | + if( sqlite3StrICmp(zName+7, &LEGACY_SCHEMA_TABLE[7])==0 ){ |
| 113717 | + return PREFERRED_SCHEMA_TABLE; |
| 113718 | + } |
| 113719 | + if( sqlite3StrICmp(zName+7, &LEGACY_TEMP_SCHEMA_TABLE[7])==0 ){ |
| 113720 | + return PREFERRED_TEMP_SCHEMA_TABLE; |
| 113721 | + } |
| 113722 | + } |
| 113723 | + return zName; |
| 113724 | +} |
| 113085 | 113725 | |
| 113086 | 113726 | /* |
| 113087 | 113727 | ** Locate the in-memory structure that describes |
| 113088 | 113728 | ** a particular index given the name of that index |
| 113089 | 113729 | ** and the name of the database that contains the index. |
| | @@ -113257,11 +113897,11 @@ |
| 113257 | 113897 | Table *pTab, /* The table containing the column */ |
| 113258 | 113898 | Column *pCol, /* The column to receive the new DEFAULT expression */ |
| 113259 | 113899 | Expr *pExpr /* The new default expression */ |
| 113260 | 113900 | ){ |
| 113261 | 113901 | ExprList *pList; |
| 113262 | | - assert( !IsVirtual(pTab) ); |
| 113902 | + assert( IsOrdinaryTable(pTab) ); |
| 113263 | 113903 | pList = pTab->u.tab.pDfltList; |
| 113264 | 113904 | if( pCol->iDflt==0 |
| 113265 | 113905 | || NEVER(pList==0) |
| 113266 | 113906 | || NEVER(pList->nExpr<pCol->iDflt) |
| 113267 | 113907 | ){ |
| | @@ -113278,11 +113918,11 @@ |
| 113278 | 113918 | ** the DEFAULT clause or the AS clause of a generated column. |
| 113279 | 113919 | ** Return NULL if the column has no associated expression. |
| 113280 | 113920 | */ |
| 113281 | 113921 | SQLITE_PRIVATE Expr *sqlite3ColumnExpr(Table *pTab, Column *pCol){ |
| 113282 | 113922 | if( pCol->iDflt==0 ) return 0; |
| 113283 | | - if( NEVER(IsVirtual(pTab)) ) return 0; |
| 113923 | + if( NEVER(!IsOrdinaryTable(pTab)) ) return 0; |
| 113284 | 113924 | if( NEVER(pTab->u.tab.pDfltList==0) ) return 0; |
| 113285 | 113925 | if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0; |
| 113286 | 113926 | return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr; |
| 113287 | 113927 | } |
| 113288 | 113928 | |
| | @@ -113292,12 +113932,12 @@ |
| 113292 | 113932 | SQLITE_PRIVATE void sqlite3ColumnSetColl( |
| 113293 | 113933 | sqlite3 *db, |
| 113294 | 113934 | Column *pCol, |
| 113295 | 113935 | const char *zColl |
| 113296 | 113936 | ){ |
| 113297 | | - int nColl; |
| 113298 | | - int n; |
| 113937 | + i64 nColl; |
| 113938 | + i64 n; |
| 113299 | 113939 | char *zNew; |
| 113300 | 113940 | assert( zColl!=0 ); |
| 113301 | 113941 | n = sqlite3Strlen30(pCol->zCnName) + 1; |
| 113302 | 113942 | if( pCol->colFlags & COLFLAG_HASTYPE ){ |
| 113303 | 113943 | n += sqlite3Strlen30(pCol->zCnName+n) + 1; |
| | @@ -113337,17 +113977,17 @@ |
| 113337 | 113977 | for(i=0; i<pTable->nCol; i++, pCol++){ |
| 113338 | 113978 | assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) ); |
| 113339 | 113979 | sqlite3DbFree(db, pCol->zCnName); |
| 113340 | 113980 | } |
| 113341 | 113981 | sqlite3DbFree(db, pTable->aCol); |
| 113342 | | - if( !IsVirtual(pTable) ){ |
| 113982 | + if( IsOrdinaryTable(pTable) ){ |
| 113343 | 113983 | sqlite3ExprListDelete(db, pTable->u.tab.pDfltList); |
| 113344 | 113984 | } |
| 113345 | 113985 | if( db==0 || db->pnBytesFreed==0 ){ |
| 113346 | 113986 | pTable->aCol = 0; |
| 113347 | 113987 | pTable->nCol = 0; |
| 113348 | | - if( !IsVirtual(pTable) ){ |
| 113988 | + if( IsOrdinaryTable(pTable) ){ |
| 113349 | 113989 | pTable->u.tab.pDfltList = 0; |
| 113350 | 113990 | } |
| 113351 | 113991 | } |
| 113352 | 113992 | } |
| 113353 | 113993 | } |
| | @@ -113479,11 +114119,11 @@ |
| 113479 | 114119 | ** Open the sqlite_schema table stored in database number iDb for |
| 113480 | 114120 | ** writing. The table is opened using cursor 0. |
| 113481 | 114121 | */ |
| 113482 | 114122 | SQLITE_PRIVATE void sqlite3OpenSchemaTable(Parse *p, int iDb){ |
| 113483 | 114123 | Vdbe *v = sqlite3GetVdbe(p); |
| 113484 | | - sqlite3TableLock(p, iDb, SCHEMA_ROOT, 1, DFLT_SCHEMA_TABLE); |
| 114124 | + sqlite3TableLock(p, iDb, SCHEMA_ROOT, 1, LEGACY_SCHEMA_TABLE); |
| 113485 | 114125 | sqlite3VdbeAddOp4Int(v, OP_OpenWrite, 0, SCHEMA_ROOT, iDb, 5); |
| 113486 | 114126 | if( p->nTab==0 ){ |
| 113487 | 114127 | p->nTab = 1; |
| 113488 | 114128 | } |
| 113489 | 114129 | } |
| | @@ -114098,11 +114738,11 @@ |
| 114098 | 114738 | break; |
| 114099 | 114739 | } |
| 114100 | 114740 | } |
| 114101 | 114741 | } |
| 114102 | 114742 | |
| 114103 | | - z = sqlite3DbMallocRaw(db, sName.n + 1 + sType.n + (sType.n>0) ); |
| 114743 | + z = sqlite3DbMallocRaw(db, (i64)sName.n + 1 + (i64)sType.n + (sType.n>0) ); |
| 114104 | 114744 | if( z==0 ) return; |
| 114105 | 114745 | if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, &sName); |
| 114106 | 114746 | memcpy(z, sName.z, sName.n); |
| 114107 | 114747 | z[sName.n] = 0; |
| 114108 | 114748 | sqlite3Dequote(z); |
| | @@ -114112,11 +114752,11 @@ |
| 114112 | 114752 | sqlite3ErrorMsg(pParse, "duplicate column name: %s", z); |
| 114113 | 114753 | sqlite3DbFree(db, z); |
| 114114 | 114754 | return; |
| 114115 | 114755 | } |
| 114116 | 114756 | } |
| 114117 | | - aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+1)*sizeof(p->aCol[0])); |
| 114757 | + aNew = sqlite3DbRealloc(db,p->aCol,((i64)p->nCol+1)*sizeof(p->aCol[0])); |
| 114118 | 114758 | if( aNew==0 ){ |
| 114119 | 114759 | sqlite3DbFree(db, z); |
| 114120 | 114760 | return; |
| 114121 | 114761 | } |
| 114122 | 114762 | p->aCol = aNew; |
| | @@ -114410,11 +115050,13 @@ |
| 114410 | 115050 | for(i=0; i<nTerm; i++){ |
| 114411 | 115051 | Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr); |
| 114412 | 115052 | assert( pCExpr!=0 ); |
| 114413 | 115053 | sqlite3StringToId(pCExpr); |
| 114414 | 115054 | if( pCExpr->op==TK_ID ){ |
| 114415 | | - const char *zCName = pCExpr->u.zToken; |
| 115055 | + const char *zCName; |
| 115056 | + assert( !ExprHasProperty(pCExpr, EP_IntValue) ); |
| 115057 | + zCName = pCExpr->u.zToken; |
| 114416 | 115058 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 114417 | 115059 | if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zCnName)==0 ){ |
| 114418 | 115060 | pCol = &pTab->aCol[iCol]; |
| 114419 | 115061 | makeColumnPartOfPrimaryKey(pParse, pCol); |
| 114420 | 115062 | break; |
| | @@ -114782,11 +115424,10 @@ |
| 114782 | 115424 | ** This is used to determine if the column number x appears in any of the |
| 114783 | 115425 | ** first nCol entries of an index. |
| 114784 | 115426 | */ |
| 114785 | 115427 | static int hasColumn(const i16 *aiCol, int nCol, int x){ |
| 114786 | 115428 | while( nCol-- > 0 ){ |
| 114787 | | - assert( aiCol[0]>=0 ); |
| 114788 | 115429 | if( x==*(aiCol++) ){ |
| 114789 | 115430 | return 1; |
| 114790 | 115431 | } |
| 114791 | 115432 | } |
| 114792 | 115433 | return 0; |
| | @@ -115057,10 +115698,45 @@ |
| 115057 | 115698 | if( pMod->pModule->xShadowName==0 ) return 0; |
| 115058 | 115699 | return pMod->pModule->xShadowName(zName+nName+1); |
| 115059 | 115700 | } |
| 115060 | 115701 | #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */ |
| 115061 | 115702 | |
| 115703 | +#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 115704 | +/* |
| 115705 | +** Table pTab is a virtual table. If it the virtual table implementation |
| 115706 | +** exists and has an xShadowName method, then loop over all other ordinary |
| 115707 | +** tables within the same schema looking for shadow tables of pTab, and mark |
| 115708 | +** any shadow tables seen using the TF_Shadow flag. |
| 115709 | +*/ |
| 115710 | +SQLITE_PRIVATE void sqlite3MarkAllShadowTablesOf(sqlite3 *db, Table *pTab){ |
| 115711 | + int nName; /* Length of pTab->zName */ |
| 115712 | + Module *pMod; /* Module for the virtual table */ |
| 115713 | + HashElem *k; /* For looping through the symbol table */ |
| 115714 | + |
| 115715 | + assert( IsVirtual(pTab) ); |
| 115716 | + pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->u.vtab.azArg[0]); |
| 115717 | + if( pMod==0 ) return; |
| 115718 | + if( NEVER(pMod->pModule==0) ) return; |
| 115719 | + if( pMod->pModule->iVersion<3 ) return; |
| 115720 | + if( pMod->pModule->xShadowName==0 ) return; |
| 115721 | + assert( pTab->zName!=0 ); |
| 115722 | + nName = sqlite3Strlen30(pTab->zName); |
| 115723 | + for(k=sqliteHashFirst(&pTab->pSchema->tblHash); k; k=sqliteHashNext(k)){ |
| 115724 | + Table *pOther = sqliteHashData(k); |
| 115725 | + assert( pOther->zName!=0 ); |
| 115726 | + if( !IsOrdinaryTable(pOther) ) continue; |
| 115727 | + if( pOther->tabFlags & TF_Shadow ) continue; |
| 115728 | + if( sqlite3StrNICmp(pOther->zName, pTab->zName, nName)==0 |
| 115729 | + && pOther->zName[nName]=='_' |
| 115730 | + && pMod->pModule->xShadowName(pOther->zName+nName+1) |
| 115731 | + ){ |
| 115732 | + pOther->tabFlags |= TF_Shadow; |
| 115733 | + } |
| 115734 | + } |
| 115735 | +} |
| 115736 | +#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */ |
| 115737 | + |
| 115062 | 115738 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 115063 | 115739 | /* |
| 115064 | 115740 | ** Return true if zName is a shadow table name in the current database |
| 115065 | 115741 | ** connection. |
| 115066 | 115742 | ** |
| | @@ -115158,11 +115834,11 @@ |
| 115158 | 115834 | ** |
| 115159 | 115835 | ** If the root page number is 1, that means this is the sqlite_schema |
| 115160 | 115836 | ** table itself. So mark it read-only. |
| 115161 | 115837 | */ |
| 115162 | 115838 | if( db->init.busy ){ |
| 115163 | | - if( pSelect ){ |
| 115839 | + if( pSelect || (!IsOrdinaryTable(p) && db->init.newTnum) ){ |
| 115164 | 115840 | sqlite3ErrorMsg(pParse, ""); |
| 115165 | 115841 | return; |
| 115166 | 115842 | } |
| 115167 | 115843 | p->tnum = db->init.newTnum; |
| 115168 | 115844 | if( p->tnum==1 ) p->tabFlags |= TF_Readonly; |
| | @@ -115385,11 +116061,11 @@ |
| 115385 | 116061 | /* A slot for the record has already been allocated in the |
| 115386 | 116062 | ** schema table. We just need to update that slot with all |
| 115387 | 116063 | ** the information we've collected. |
| 115388 | 116064 | */ |
| 115389 | 116065 | sqlite3NestedParse(pParse, |
| 115390 | | - "UPDATE %Q." DFLT_SCHEMA_TABLE |
| 116066 | + "UPDATE %Q." LEGACY_SCHEMA_TABLE |
| 115391 | 116067 | " SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q" |
| 115392 | 116068 | " WHERE rowid=#%d", |
| 115393 | 116069 | db->aDb[iDb].zDbSName, |
| 115394 | 116070 | zType, |
| 115395 | 116071 | p->zName, |
| | @@ -115571,17 +116247,16 @@ |
| 115571 | 116247 | #endif |
| 115572 | 116248 | |
| 115573 | 116249 | assert( pTable ); |
| 115574 | 116250 | |
| 115575 | 116251 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 115576 | | - db->nSchemaLock++; |
| 115577 | | - rc = sqlite3VtabCallConnect(pParse, pTable); |
| 115578 | | - db->nSchemaLock--; |
| 115579 | | - if( rc ){ |
| 115580 | | - return 1; |
| 116252 | + if( IsVirtual(pTable) ){ |
| 116253 | + db->nSchemaLock++; |
| 116254 | + rc = sqlite3VtabCallConnect(pParse, pTable); |
| 116255 | + db->nSchemaLock--; |
| 116256 | + return rc; |
| 115581 | 116257 | } |
| 115582 | | - if( IsVirtual(pTable) ) return 0; |
| 115583 | 116258 | #endif |
| 115584 | 116259 | |
| 115585 | 116260 | #ifndef SQLITE_OMIT_VIEW |
| 115586 | 116261 | /* A positive nCol means the columns names for this view are |
| 115587 | 116262 | ** already known. |
| | @@ -115765,11 +116440,11 @@ |
| 115765 | 116440 | ** The "#NNN" in the SQL is a special constant that means whatever value |
| 115766 | 116441 | ** is in register NNN. See grammar rules associated with the TK_REGISTER |
| 115767 | 116442 | ** token for additional information. |
| 115768 | 116443 | */ |
| 115769 | 116444 | sqlite3NestedParse(pParse, |
| 115770 | | - "UPDATE %Q." DFLT_SCHEMA_TABLE |
| 116445 | + "UPDATE %Q." LEGACY_SCHEMA_TABLE |
| 115771 | 116446 | " SET rootpage=%d WHERE #%d AND rootpage=#%d", |
| 115772 | 116447 | pParse->db->aDb[iDb].zDbSName, iTable, r1, r1); |
| 115773 | 116448 | #endif |
| 115774 | 116449 | sqlite3ReleaseTempReg(pParse, r1); |
| 115775 | 116450 | } |
| | @@ -115900,11 +116575,11 @@ |
| 115900 | 116575 | ** dropped. Triggers are handled separately because a trigger can be |
| 115901 | 116576 | ** created in the temp database that refers to a table in another |
| 115902 | 116577 | ** database. |
| 115903 | 116578 | */ |
| 115904 | 116579 | sqlite3NestedParse(pParse, |
| 115905 | | - "DELETE FROM %Q." DFLT_SCHEMA_TABLE |
| 116580 | + "DELETE FROM %Q." LEGACY_SCHEMA_TABLE |
| 115906 | 116581 | " WHERE tbl_name=%Q and type!='trigger'", |
| 115907 | 116582 | pDb->zDbSName, pTab->zName); |
| 115908 | 116583 | if( !isView && !IsVirtual(pTab) ){ |
| 115909 | 116584 | destroyTable(pParse, pTab); |
| 115910 | 116585 | } |
| | @@ -115947,10 +116622,13 @@ |
| 115947 | 116622 | if( sqlite3StrNICmp(pTab->zName+7, "parameters", 10)==0 ) return 0; |
| 115948 | 116623 | return 1; |
| 115949 | 116624 | } |
| 115950 | 116625 | if( (pTab->tabFlags & TF_Shadow)!=0 && sqlite3ReadOnlyShadowTables(db) ){ |
| 115951 | 116626 | return 1; |
| 116627 | + } |
| 116628 | + if( pTab->tabFlags & TF_Eponymous ){ |
| 116629 | + return 1; |
| 115952 | 116630 | } |
| 115953 | 116631 | return 0; |
| 115954 | 116632 | } |
| 115955 | 116633 | |
| 115956 | 116634 | /* |
| | @@ -116087,11 +116765,11 @@ |
| 116087 | 116765 | sqlite3 *db = pParse->db; |
| 116088 | 116766 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 116089 | 116767 | FKey *pFKey = 0; |
| 116090 | 116768 | FKey *pNextTo; |
| 116091 | 116769 | Table *p = pParse->pNewTable; |
| 116092 | | - int nByte; |
| 116770 | + i64 nByte; |
| 116093 | 116771 | int i; |
| 116094 | 116772 | int nCol; |
| 116095 | 116773 | char *z; |
| 116096 | 116774 | |
| 116097 | 116775 | assert( pTo!=0 ); |
| | @@ -116123,10 +116801,11 @@ |
| 116123 | 116801 | pFKey = sqlite3DbMallocZero(db, nByte ); |
| 116124 | 116802 | if( pFKey==0 ){ |
| 116125 | 116803 | goto fk_end; |
| 116126 | 116804 | } |
| 116127 | 116805 | pFKey->pFrom = p; |
| 116806 | + assert( IsOrdinaryTable(p) ); |
| 116128 | 116807 | pFKey->pNextFrom = p->u.tab.pFKey; |
| 116129 | 116808 | z = (char*)&pFKey->aCol[nCol]; |
| 116130 | 116809 | pFKey->zTo = z; |
| 116131 | 116810 | if( IN_RENAME_OBJECT ){ |
| 116132 | 116811 | sqlite3RenameTokenMap(pParse, (void*)z, pTo); |
| | @@ -116188,11 +116867,11 @@ |
| 116188 | 116867 | pNextTo->pPrevTo = pFKey; |
| 116189 | 116868 | } |
| 116190 | 116869 | |
| 116191 | 116870 | /* Link the foreign key to the table as the last step. |
| 116192 | 116871 | */ |
| 116193 | | - assert( !IsVirtual(p) ); |
| 116872 | + assert( IsOrdinaryTable(p) ); |
| 116194 | 116873 | p->u.tab.pFKey = pFKey; |
| 116195 | 116874 | pFKey = 0; |
| 116196 | 116875 | |
| 116197 | 116876 | fk_end: |
| 116198 | 116877 | sqlite3DbFree(db, pFKey); |
| | @@ -116211,11 +116890,11 @@ |
| 116211 | 116890 | SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse *pParse, int isDeferred){ |
| 116212 | 116891 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 116213 | 116892 | Table *pTab; |
| 116214 | 116893 | FKey *pFKey; |
| 116215 | 116894 | if( (pTab = pParse->pNewTable)==0 ) return; |
| 116216 | | - if( NEVER(IsVirtual(pTab)) ) return; |
| 116895 | + if( NEVER(!IsOrdinaryTable(pTab)) ) return; |
| 116217 | 116896 | if( (pFKey = pTab->u.tab.pFKey)==0 ) return; |
| 116218 | 116897 | assert( isDeferred==0 || isDeferred==1 ); /* EV: R-30323-21917 */ |
| 116219 | 116898 | pFKey->isDeferred = (u8)isDeferred; |
| 116220 | 116899 | #endif |
| 116221 | 116900 | } |
| | @@ -116613,10 +117292,11 @@ |
| 116613 | 117292 | */ |
| 116614 | 117293 | for(i=0; i<pList->nExpr; i++){ |
| 116615 | 117294 | Expr *pExpr = pList->a[i].pExpr; |
| 116616 | 117295 | assert( pExpr!=0 ); |
| 116617 | 117296 | if( pExpr->op==TK_COLLATE ){ |
| 117297 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 116618 | 117298 | nExtra += (1 + sqlite3Strlen30(pExpr->u.zToken)); |
| 116619 | 117299 | } |
| 116620 | 117300 | } |
| 116621 | 117301 | |
| 116622 | 117302 | /* |
| | @@ -116708,10 +117388,11 @@ |
| 116708 | 117388 | pIndex->aiColumn[i] = (i16)j; |
| 116709 | 117389 | } |
| 116710 | 117390 | zColl = 0; |
| 116711 | 117391 | if( pListItem->pExpr->op==TK_COLLATE ){ |
| 116712 | 117392 | int nColl; |
| 117393 | + assert( !ExprHasProperty(pListItem->pExpr, EP_IntValue) ); |
| 116713 | 117394 | zColl = pListItem->pExpr->u.zToken; |
| 116714 | 117395 | nColl = sqlite3Strlen30(zColl) + 1; |
| 116715 | 117396 | assert( nExtra>=nColl ); |
| 116716 | 117397 | memcpy(zExtra, zColl, nColl); |
| 116717 | 117398 | zColl = zExtra; |
| | @@ -116914,17 +117595,17 @@ |
| 116914 | 117595 | } |
| 116915 | 117596 | |
| 116916 | 117597 | /* Add an entry in sqlite_schema for this index |
| 116917 | 117598 | */ |
| 116918 | 117599 | sqlite3NestedParse(pParse, |
| 116919 | | - "INSERT INTO %Q." DFLT_SCHEMA_TABLE " VALUES('index',%Q,%Q,#%d,%Q);", |
| 116920 | | - db->aDb[iDb].zDbSName, |
| 116921 | | - pIndex->zName, |
| 116922 | | - pTab->zName, |
| 116923 | | - iMem, |
| 116924 | | - zStmt |
| 116925 | | - ); |
| 117600 | + "INSERT INTO %Q." LEGACY_SCHEMA_TABLE " VALUES('index',%Q,%Q,#%d,%Q);", |
| 117601 | + db->aDb[iDb].zDbSName, |
| 117602 | + pIndex->zName, |
| 117603 | + pTab->zName, |
| 117604 | + iMem, |
| 117605 | + zStmt |
| 117606 | + ); |
| 116926 | 117607 | sqlite3DbFree(db, zStmt); |
| 116927 | 117608 | |
| 116928 | 117609 | /* Fill the index with data and reparse the schema. Code an OP_Expire |
| 116929 | 117610 | ** to invalidate all pre-compiled statements. |
| 116930 | 117611 | */ |
| | @@ -117100,11 +117781,11 @@ |
| 117100 | 117781 | /* Generate code to remove the index and from the schema table */ |
| 117101 | 117782 | v = sqlite3GetVdbe(pParse); |
| 117102 | 117783 | if( v ){ |
| 117103 | 117784 | sqlite3BeginWriteOperation(pParse, 1, iDb); |
| 117104 | 117785 | sqlite3NestedParse(pParse, |
| 117105 | | - "DELETE FROM %Q." DFLT_SCHEMA_TABLE " WHERE name=%Q AND type='index'", |
| 117786 | + "DELETE FROM %Q." LEGACY_SCHEMA_TABLE " WHERE name=%Q AND type='index'", |
| 117106 | 117787 | db->aDb[iDb].zDbSName, pIndex->zName |
| 117107 | 117788 | ); |
| 117108 | 117789 | sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName); |
| 117109 | 117790 | sqlite3ChangeCookie(pParse, iDb); |
| 117110 | 117791 | destroyRootPage(pParse, pIndex->tnum, iDb); |
| | @@ -117468,11 +118149,11 @@ |
| 117468 | 118149 | pItem->pSelect = pSubquery; |
| 117469 | 118150 | pItem->pOn = pOn; |
| 117470 | 118151 | pItem->pUsing = pUsing; |
| 117471 | 118152 | return p; |
| 117472 | 118153 | |
| 117473 | | - append_from_error: |
| 118154 | +append_from_error: |
| 117474 | 118155 | assert( p==0 ); |
| 117475 | 118156 | sqlite3ExprDelete(db, pOn); |
| 117476 | 118157 | sqlite3IdListDelete(db, pUsing); |
| 117477 | 118158 | sqlite3SelectDelete(db, pSubquery); |
| 117478 | 118159 | return 0; |
| | @@ -117496,10 +118177,11 @@ |
| 117496 | 118177 | ** construct "indexed_opt" for details. */ |
| 117497 | 118178 | pItem->fg.notIndexed = 1; |
| 117498 | 118179 | }else{ |
| 117499 | 118180 | pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy); |
| 117500 | 118181 | pItem->fg.isIndexedBy = 1; |
| 118182 | + assert( pItem->fg.isCte==0 ); /* No collision on union u2 */ |
| 117501 | 118183 | } |
| 117502 | 118184 | } |
| 117503 | 118185 | } |
| 117504 | 118186 | |
| 117505 | 118187 | /* |
| | @@ -118476,10 +119158,11 @@ |
| 118476 | 119158 | int h, /* Hash of the name */ |
| 118477 | 119159 | const char *zFunc /* Name of function */ |
| 118478 | 119160 | ){ |
| 118479 | 119161 | FuncDef *p; |
| 118480 | 119162 | for(p=sqlite3BuiltinFunctions.a[h]; p; p=p->u.pHash){ |
| 119163 | + assert( p->funcFlags & SQLITE_FUNC_BUILTIN ); |
| 118481 | 119164 | if( sqlite3StrICmp(p->zName, zFunc)==0 ){ |
| 118482 | 119165 | return p; |
| 118483 | 119166 | } |
| 118484 | 119167 | } |
| 118485 | 119168 | return 0; |
| | @@ -118497,10 +119180,11 @@ |
| 118497 | 119180 | FuncDef *pOther; |
| 118498 | 119181 | const char *zName = aDef[i].zName; |
| 118499 | 119182 | int nName = sqlite3Strlen30(zName); |
| 118500 | 119183 | int h = SQLITE_FUNC_HASH(zName[0], nName); |
| 118501 | 119184 | assert( zName[0]>='a' && zName[0]<='z' ); |
| 119185 | + assert( aDef[i].funcFlags & SQLITE_FUNC_BUILTIN ); |
| 118502 | 119186 | pOther = sqlite3FunctionSearch(h, zName); |
| 118503 | 119187 | if( pOther ){ |
| 118504 | 119188 | assert( pOther!=&aDef[i] && pOther->pNext!=&aDef[i] ); |
| 118505 | 119189 | aDef[i].pNext = pOther->pNext; |
| 118506 | 119190 | pOther->pNext = &aDef[i]; |
| | @@ -118721,10 +119405,20 @@ |
| 118721 | 119405 | pTab = 0; |
| 118722 | 119406 | } |
| 118723 | 119407 | } |
| 118724 | 119408 | return pTab; |
| 118725 | 119409 | } |
| 119410 | + |
| 119411 | +/* Generate byte-code that will report the number of rows modified |
| 119412 | +** by a DELETE, INSERT, or UPDATE statement. |
| 119413 | +*/ |
| 119414 | +SQLITE_PRIVATE void sqlite3CodeChangeCount(Vdbe *v, int regCounter, const char *zColName){ |
| 119415 | + sqlite3VdbeAddOp0(v, OP_FkCheck); |
| 119416 | + sqlite3VdbeAddOp2(v, OP_ResultRow, regCounter, 1); |
| 119417 | + sqlite3VdbeSetNumCols(v, 1); |
| 119418 | + sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zColName, SQLITE_STATIC); |
| 119419 | +} |
| 118726 | 119420 | |
| 118727 | 119421 | /* Return true if table pTab is read-only. |
| 118728 | 119422 | ** |
| 118729 | 119423 | ** A table is read-only if any of the following are true: |
| 118730 | 119424 | ** |
| | @@ -118888,10 +119582,11 @@ |
| 118888 | 119582 | ** and the SELECT subtree. */ |
| 118889 | 119583 | pSrc->a[0].pTab = 0; |
| 118890 | 119584 | pSelectSrc = sqlite3SrcListDup(db, pSrc, 0); |
| 118891 | 119585 | pSrc->a[0].pTab = pTab; |
| 118892 | 119586 | if( pSrc->a[0].fg.isIndexedBy ){ |
| 119587 | + assert( pSrc->a[0].fg.isCte==0 ); |
| 118893 | 119588 | pSrc->a[0].u2.pIBIndex = 0; |
| 118894 | 119589 | pSrc->a[0].fg.isIndexedBy = 0; |
| 118895 | 119590 | sqlite3DbFree(db, pSrc->a[0].u1.zIndexedBy); |
| 118896 | 119591 | }else if( pSrc->a[0].fg.isCte ){ |
| 118897 | 119592 | pSrc->a[0].u2.pCteUse->nUse++; |
| | @@ -119296,13 +119991,11 @@ |
| 119296 | 119991 | /* Return the number of rows that were deleted. If this routine is |
| 119297 | 119992 | ** generating code because of a call to sqlite3NestedParse(), do not |
| 119298 | 119993 | ** invoke the callback function. |
| 119299 | 119994 | */ |
| 119300 | 119995 | if( memCnt ){ |
| 119301 | | - sqlite3VdbeAddOp2(v, OP_ChngCntRow, memCnt, 1); |
| 119302 | | - sqlite3VdbeSetNumCols(v, 1); |
| 119303 | | - sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows deleted", SQLITE_STATIC); |
| 119996 | + sqlite3CodeChangeCount(v, memCnt, "rows deleted"); |
| 119304 | 119997 | } |
| 119305 | 119998 | |
| 119306 | 119999 | delete_from_cleanup: |
| 119307 | 120000 | sqlite3AuthContextPop(&sContext); |
| 119308 | 120001 | sqlite3SrcListDelete(db, pTabList); |
| | @@ -121472,11 +122165,15 @@ |
| 121472 | 122165 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; |
| 121473 | 122166 | pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC)); |
| 121474 | 122167 | /* pGCC is always non-NULL since groupConcatStep() will have always |
| 121475 | 122168 | ** run frist to initialize it */ |
| 121476 | 122169 | if( ALWAYS(pGCC) ){ |
| 121477 | | - int nVS = sqlite3_value_bytes(argv[0]); |
| 122170 | + int nVS; |
| 122171 | + /* Must call sqlite3_value_text() to convert the argument into text prior |
| 122172 | + ** to invoking sqlite3_value_bytes(), in case the text encoding is UTF16 */ |
| 122173 | + (void)sqlite3_value_text(argv[0]); |
| 122174 | + nVS = sqlite3_value_bytes(argv[0]); |
| 121478 | 122175 | pGCC->nAccum -= 1; |
| 121479 | 122176 | if( pGCC->pnSepLengths!=0 ){ |
| 121480 | 122177 | assert(pGCC->nAccum >= 0); |
| 121481 | 122178 | if( pGCC->nAccum>0 ){ |
| 121482 | 122179 | nVS += *pGCC->pnSepLengths; |
| | @@ -121587,15 +122284,16 @@ |
| 121587 | 122284 | SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){ |
| 121588 | 122285 | FuncDef *pDef; |
| 121589 | 122286 | int nExpr; |
| 121590 | 122287 | assert( pExpr!=0 ); |
| 121591 | 122288 | assert( pExpr->op==TK_FUNCTION ); |
| 122289 | + assert( ExprUseXList(pExpr) ); |
| 121592 | 122290 | if( !pExpr->x.pList ){ |
| 121593 | 122291 | return 0; |
| 121594 | 122292 | } |
| 121595 | | - assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 121596 | 122293 | nExpr = pExpr->x.pList->nExpr; |
| 122294 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 121597 | 122295 | pDef = sqlite3FindFunction(db, pExpr->u.zToken, nExpr, SQLITE_UTF8, 0); |
| 121598 | 122296 | #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| 121599 | 122297 | if( pDef==0 ) return 0; |
| 121600 | 122298 | #endif |
| 121601 | 122299 | if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){ |
| | @@ -121615,10 +122313,11 @@ |
| 121615 | 122313 | aWc[3] = 0; |
| 121616 | 122314 | }else{ |
| 121617 | 122315 | Expr *pEscape = pExpr->x.pList->a[2].pExpr; |
| 121618 | 122316 | char *zEscape; |
| 121619 | 122317 | if( pEscape->op!=TK_STRING ) return 0; |
| 122318 | + assert( !ExprHasProperty(pEscape, EP_IntValue) ); |
| 121620 | 122319 | zEscape = pEscape->u.zToken; |
| 121621 | 122320 | if( zEscape[0]==0 || zEscape[1]!=0 ) return 0; |
| 121622 | 122321 | if( zEscape[0]==aWc[0] ) return 0; |
| 121623 | 122322 | if( zEscape[0]==aWc[1] ) return 0; |
| 121624 | 122323 | aWc[3] = zEscape[0]; |
| | @@ -121996,10 +122695,11 @@ |
| 121996 | 122695 | for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){ |
| 121997 | 122696 | printf("FUNC-HASH %02d:", i); |
| 121998 | 122697 | for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash){ |
| 121999 | 122698 | int n = sqlite3Strlen30(p->zName); |
| 122000 | 122699 | int h = p->zName[0] + n; |
| 122700 | + assert( p->funcFlags & SQLITE_FUNC_BUILTIN ); |
| 122001 | 122701 | printf(" %s(%d)", p->zName, h); |
| 122002 | 122702 | } |
| 122003 | 122703 | printf("\n"); |
| 122004 | 122704 | } |
| 122005 | 122705 | } |
| | @@ -122518,10 +123218,11 @@ |
| 122518 | 123218 | int iCursor, /* The open cursor on the table */ |
| 122519 | 123219 | i16 iCol /* The column that is wanted */ |
| 122520 | 123220 | ){ |
| 122521 | 123221 | Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0); |
| 122522 | 123222 | if( pExpr ){ |
| 123223 | + assert( ExprUseYTab(pExpr) ); |
| 122523 | 123224 | pExpr->y.pTab = pTab; |
| 122524 | 123225 | pExpr->iTable = iCursor; |
| 122525 | 123226 | pExpr->iColumn = iCol; |
| 122526 | 123227 | } |
| 122527 | 123228 | return pExpr; |
| | @@ -122728,17 +123429,16 @@ |
| 122728 | 123429 | ** the table from the database. Triggers are disabled while running this |
| 122729 | 123430 | ** DELETE, but foreign key actions are not. |
| 122730 | 123431 | */ |
| 122731 | 123432 | SQLITE_PRIVATE void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){ |
| 122732 | 123433 | sqlite3 *db = pParse->db; |
| 122733 | | - if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) ){ |
| 123434 | + if( (db->flags&SQLITE_ForeignKeys) && IsOrdinaryTable(pTab) ){ |
| 122734 | 123435 | int iSkip = 0; |
| 122735 | 123436 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 122736 | 123437 | |
| 122737 | 123438 | assert( v ); /* VDBE has already been allocated */ |
| 122738 | | - assert( !IsView(pTab) ); /* Not a view */ |
| 122739 | | - assert( !IsVirtual(pTab) ); |
| 123439 | + assert( IsOrdinaryTable(pTab) ); |
| 122740 | 123440 | if( sqlite3FkReferences(pTab)==0 ){ |
| 122741 | 123441 | /* Search for a deferred foreign key constraint for which this table |
| 122742 | 123442 | ** is the child table. If one cannot be found, return without |
| 122743 | 123443 | ** generating any VDBE code. If one can be found, then jump over |
| 122744 | 123444 | ** the entire DELETE if there are no outstanding deferred constraints |
| | @@ -122898,17 +123598,17 @@ |
| 122898 | 123598 | /* Exactly one of regOld and regNew should be non-zero. */ |
| 122899 | 123599 | assert( (regOld==0)!=(regNew==0) ); |
| 122900 | 123600 | |
| 122901 | 123601 | /* If foreign-keys are disabled, this function is a no-op. */ |
| 122902 | 123602 | if( (db->flags&SQLITE_ForeignKeys)==0 ) return; |
| 123603 | + if( !IsOrdinaryTable(pTab) ) return; |
| 122903 | 123604 | |
| 122904 | 123605 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 122905 | 123606 | zDb = db->aDb[iDb].zDbSName; |
| 122906 | 123607 | |
| 122907 | 123608 | /* Loop through all the foreign key constraints for which pTab is the |
| 122908 | 123609 | ** child table (the table that the foreign key definition is part of). */ |
| 122909 | | - assert( !IsVirtual(pTab) ); |
| 122910 | 123610 | for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 122911 | 123611 | Table *pTo; /* Parent table of foreign key pFKey */ |
| 122912 | 123612 | Index *pIdx = 0; /* Index on key columns in pTo */ |
| 122913 | 123613 | int *aiFree = 0; |
| 122914 | 123614 | int *aiCol; |
| | @@ -123087,14 +123787,13 @@ |
| 123087 | 123787 | SQLITE_PRIVATE u32 sqlite3FkOldmask( |
| 123088 | 123788 | Parse *pParse, /* Parse context */ |
| 123089 | 123789 | Table *pTab /* Table being modified */ |
| 123090 | 123790 | ){ |
| 123091 | 123791 | u32 mask = 0; |
| 123092 | | - if( pParse->db->flags&SQLITE_ForeignKeys ){ |
| 123792 | + if( pParse->db->flags&SQLITE_ForeignKeys && IsOrdinaryTable(pTab) ){ |
| 123093 | 123793 | FKey *p; |
| 123094 | 123794 | int i; |
| 123095 | | - assert( !IsVirtual(pTab) ); |
| 123096 | 123795 | for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){ |
| 123097 | 123796 | for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom); |
| 123098 | 123797 | } |
| 123099 | 123798 | for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){ |
| 123100 | 123799 | Index *pIdx = 0; |
| | @@ -123141,11 +123840,11 @@ |
| 123141 | 123840 | int *aChange, /* Non-NULL for UPDATE operations */ |
| 123142 | 123841 | int chngRowid /* True for UPDATE that affects rowid */ |
| 123143 | 123842 | ){ |
| 123144 | 123843 | int eRet = 1; /* Value to return if bHaveFK is true */ |
| 123145 | 123844 | int bHaveFK = 0; /* If FK processing is required */ |
| 123146 | | - if( pParse->db->flags&SQLITE_ForeignKeys && !IsVirtual(pTab) ){ |
| 123845 | + if( pParse->db->flags&SQLITE_ForeignKeys && IsOrdinaryTable(pTab) ){ |
| 123147 | 123846 | if( !aChange ){ |
| 123148 | 123847 | /* A DELETE operation. Foreign key processing is required if the |
| 123149 | 123848 | ** table in question is either the child or parent table for any |
| 123150 | 123849 | ** foreign key constraint. */ |
| 123151 | 123850 | bHaveFK = (sqlite3FkReferences(pTab) || pTab->u.tab.pFKey); |
| | @@ -123429,11 +124128,11 @@ |
| 123429 | 124128 | */ |
| 123430 | 124129 | SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){ |
| 123431 | 124130 | FKey *pFKey; /* Iterator variable */ |
| 123432 | 124131 | FKey *pNext; /* Copy of pFKey->pNextFrom */ |
| 123433 | 124132 | |
| 123434 | | - assert( !IsVirtual(pTab) ); |
| 124133 | + assert( IsOrdinaryTable(pTab) ); |
| 123435 | 124134 | for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pNext){ |
| 123436 | 124135 | assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) ); |
| 123437 | 124136 | |
| 123438 | 124137 | /* Remove the FK from the fkeyHash hash table. */ |
| 123439 | 124138 | if( !db || db->pnBytesFreed==0 ){ |
| | @@ -123750,28 +124449,34 @@ |
| 123750 | 124449 | |
| 123751 | 124450 | /* Before computing generated columns, first go through and make sure |
| 123752 | 124451 | ** that appropriate affinity has been applied to the regular columns |
| 123753 | 124452 | */ |
| 123754 | 124453 | sqlite3TableAffinity(pParse->pVdbe, pTab, iRegStore); |
| 123755 | | - if( (pTab->tabFlags & TF_HasStored)!=0 |
| 123756 | | - && (pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1))->opcode==OP_Affinity |
| 123757 | | - ){ |
| 123758 | | - /* Change the OP_Affinity argument to '@' (NONE) for all stored |
| 123759 | | - ** columns. '@' is the no-op affinity and those columns have not |
| 123760 | | - ** yet been computed. */ |
| 123761 | | - int ii, jj; |
| 123762 | | - char *zP4 = pOp->p4.z; |
| 123763 | | - assert( zP4!=0 ); |
| 123764 | | - assert( pOp->p4type==P4_DYNAMIC ); |
| 123765 | | - for(ii=jj=0; zP4[jj]; ii++){ |
| 123766 | | - if( pTab->aCol[ii].colFlags & COLFLAG_VIRTUAL ){ |
| 123767 | | - continue; |
| 123768 | | - } |
| 123769 | | - if( pTab->aCol[ii].colFlags & COLFLAG_STORED ){ |
| 123770 | | - zP4[jj] = SQLITE_AFF_NONE; |
| 123771 | | - } |
| 123772 | | - jj++; |
| 124454 | + if( (pTab->tabFlags & TF_HasStored)!=0 ){ |
| 124455 | + pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1); |
| 124456 | + if( pOp->opcode==OP_Affinity ){ |
| 124457 | + /* Change the OP_Affinity argument to '@' (NONE) for all stored |
| 124458 | + ** columns. '@' is the no-op affinity and those columns have not |
| 124459 | + ** yet been computed. */ |
| 124460 | + int ii, jj; |
| 124461 | + char *zP4 = pOp->p4.z; |
| 124462 | + assert( zP4!=0 ); |
| 124463 | + assert( pOp->p4type==P4_DYNAMIC ); |
| 124464 | + for(ii=jj=0; zP4[jj]; ii++){ |
| 124465 | + if( pTab->aCol[ii].colFlags & COLFLAG_VIRTUAL ){ |
| 124466 | + continue; |
| 124467 | + } |
| 124468 | + if( pTab->aCol[ii].colFlags & COLFLAG_STORED ){ |
| 124469 | + zP4[jj] = SQLITE_AFF_NONE; |
| 124470 | + } |
| 124471 | + jj++; |
| 124472 | + } |
| 124473 | + }else if( pOp->opcode==OP_TypeCheck ){ |
| 124474 | + /* If an OP_TypeCheck was generated because the table is STRICT, |
| 124475 | + ** then set the P3 operand to indicate that generated columns should |
| 124476 | + ** not be checked */ |
| 124477 | + pOp->p3 = 1; |
| 123773 | 124478 | } |
| 123774 | 124479 | } |
| 123775 | 124480 | |
| 123776 | 124481 | /* Because there can be multiple generated columns that refer to one another, |
| 123777 | 124482 | ** this is a two-pass algorithm. On the first pass, mark all generated |
| | @@ -124844,13 +125549,11 @@ |
| 124844 | 125549 | ** Return the number of rows inserted. If this routine is |
| 124845 | 125550 | ** generating code because of a call to sqlite3NestedParse(), do not |
| 124846 | 125551 | ** invoke the callback function. |
| 124847 | 125552 | */ |
| 124848 | 125553 | if( regRowCount ){ |
| 124849 | | - sqlite3VdbeAddOp2(v, OP_ChngCntRow, regRowCount, 1); |
| 124850 | | - sqlite3VdbeSetNumCols(v, 1); |
| 124851 | | - sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows inserted", SQLITE_STATIC); |
| 125554 | + sqlite3CodeChangeCount(v, regRowCount, "rows inserted"); |
| 124852 | 125555 | } |
| 124853 | 125556 | |
| 124854 | 125557 | insert_cleanup: |
| 124855 | 125558 | sqlite3SrcListDelete(db, pTabList); |
| 124856 | 125559 | sqlite3ExprListDelete(db, pList); |
| | @@ -125688,10 +126391,11 @@ |
| 125688 | 126391 | ** (5) No FK constraint counters need to be updated if a conflict occurs. |
| 125689 | 126392 | ** |
| 125690 | 126393 | ** This is not possible for ENABLE_PREUPDATE_HOOK builds, as the row |
| 125691 | 126394 | ** must be explicitly deleted in order to ensure any pre-update hook |
| 125692 | 126395 | ** is invoked. */ |
| 126396 | + assert( IsOrdinaryTable(pTab) ); |
| 125693 | 126397 | #ifndef SQLITE_ENABLE_PREUPDATE_HOOK |
| 125694 | 126398 | if( (ix==0 && pIdx->pNext==0) /* Condition 3 */ |
| 125695 | 126399 | && pPk==pIdx /* Condition 2 */ |
| 125696 | 126400 | && onError==OE_Replace /* Condition 1 */ |
| 125697 | 126401 | && ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */ |
| | @@ -125794,11 +126498,12 @@ |
| 125794 | 126498 | default: { |
| 125795 | 126499 | int nConflictCk; /* Number of opcodes in conflict check logic */ |
| 125796 | 126500 | |
| 125797 | 126501 | assert( onError==OE_Replace ); |
| 125798 | 126502 | nConflictCk = sqlite3VdbeCurrentAddr(v) - addrConflictCk; |
| 125799 | | - assert( nConflictCk>0 ); |
| 126503 | + assert( nConflictCk>0 || db->mallocFailed ); |
| 126504 | + testcase( nConflictCk<=0 ); |
| 125800 | 126505 | testcase( nConflictCk>1 ); |
| 125801 | 126506 | if( regTrigCnt ){ |
| 125802 | 126507 | sqlite3MultiWrite(pParse); |
| 125803 | 126508 | nReplaceTrig++; |
| 125804 | 126509 | } |
| | @@ -126080,12 +126785,13 @@ |
| 126080 | 126785 | |
| 126081 | 126786 | assert( op==OP_OpenRead || op==OP_OpenWrite ); |
| 126082 | 126787 | assert( op==OP_OpenWrite || p5==0 ); |
| 126083 | 126788 | if( IsVirtual(pTab) ){ |
| 126084 | 126789 | /* This routine is a no-op for virtual tables. Leave the output |
| 126085 | | - ** variables *piDataCur and *piIdxCur uninitialized so that valgrind |
| 126086 | | - ** can detect if they are used by mistake in the caller. */ |
| 126790 | + ** variables *piDataCur and *piIdxCur set to illegal cursor numbers |
| 126791 | + ** for improved error detection. */ |
| 126792 | + *piDataCur = *piIdxCur = -999; |
| 126087 | 126793 | return 0; |
| 126088 | 126794 | } |
| 126089 | 126795 | iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema); |
| 126090 | 126796 | v = pParse->pVdbe; |
| 126091 | 126797 | assert( v!=0 ); |
| | @@ -126368,11 +127074,13 @@ |
| 126368 | 127074 | /* Default values for second and subsequent columns need to match. */ |
| 126369 | 127075 | if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){ |
| 126370 | 127076 | Expr *pDestExpr = sqlite3ColumnExpr(pDest, pDestCol); |
| 126371 | 127077 | Expr *pSrcExpr = sqlite3ColumnExpr(pSrc, pSrcCol); |
| 126372 | 127078 | assert( pDestExpr==0 || pDestExpr->op==TK_SPAN ); |
| 127079 | + assert( pDestExpr==0 || !ExprHasProperty(pDestExpr, EP_IntValue) ); |
| 126373 | 127080 | assert( pSrcExpr==0 || pSrcExpr->op==TK_SPAN ); |
| 127081 | + assert( pSrcExpr==0 || !ExprHasProperty(pSrcExpr, EP_IntValue) ); |
| 126374 | 127082 | if( (pDestExpr==0)!=(pSrcExpr==0) |
| 126375 | 127083 | || (pDestExpr!=0 && strcmp(pDestExpr->u.zToken, |
| 126376 | 127084 | pSrcExpr->u.zToken)!=0) |
| 126377 | 127085 | ){ |
| 126378 | 127086 | return 0; /* Default values must be the same for all columns */ |
| | @@ -126408,10 +127116,11 @@ |
| 126408 | 127116 | ** But the main beneficiary of the transfer optimization is the VACUUM |
| 126409 | 127117 | ** command, and the VACUUM command disables foreign key constraints. So |
| 126410 | 127118 | ** the extra complication to make this rule less restrictive is probably |
| 126411 | 127119 | ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e] |
| 126412 | 127120 | */ |
| 127121 | + assert( IsOrdinaryTable(pDest) ); |
| 126413 | 127122 | if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->u.tab.pFKey!=0 ){ |
| 126414 | 127123 | return 0; |
| 126415 | 127124 | } |
| 126416 | 127125 | #endif |
| 126417 | 127126 | if( (db->flags & SQLITE_CountRows)!=0 ){ |
| | @@ -127089,10 +127798,14 @@ |
| 127089 | 127798 | /* Version 3.34.0 and later */ |
| 127090 | 127799 | int (*txn_state)(sqlite3*,const char*); |
| 127091 | 127800 | /* Version 3.36.1 and later */ |
| 127092 | 127801 | sqlite3_int64 (*changes64)(sqlite3*); |
| 127093 | 127802 | sqlite3_int64 (*total_changes64)(sqlite3*); |
| 127803 | + /* Version 3.37.0 and later */ |
| 127804 | + int (*autovacuum_pages)(sqlite3*, |
| 127805 | + unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int), |
| 127806 | + void*, void(*)(void*)); |
| 127094 | 127807 | }; |
| 127095 | 127808 | |
| 127096 | 127809 | /* |
| 127097 | 127810 | ** This is the function signature used for all extension entry points. It |
| 127098 | 127811 | ** is also defined in the file "loadext.c". |
| | @@ -127395,10 +128108,15 @@ |
| 127395 | 128108 | #define sqlite3_create_filename sqlite3_api->create_filename |
| 127396 | 128109 | #define sqlite3_free_filename sqlite3_api->free_filename |
| 127397 | 128110 | #define sqlite3_database_file_object sqlite3_api->database_file_object |
| 127398 | 128111 | /* Version 3.34.0 and later */ |
| 127399 | 128112 | #define sqlite3_txn_state sqlite3_api->txn_state |
| 128113 | +/* Version 3.36.1 and later */ |
| 128114 | +#define sqlite3_changes64 sqlite3_api->changes64 |
| 128115 | +#define sqlite3_total_changes64 sqlite3_api->total_changes64 |
| 128116 | +/* Version 3.37.0 and later */ |
| 128117 | +#define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages |
| 127400 | 128118 | #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ |
| 127401 | 128119 | |
| 127402 | 128120 | #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 127403 | 128121 | /* This case when the file really is being compiled as a loadable |
| 127404 | 128122 | ** extension */ |
| | @@ -127882,10 +128600,12 @@ |
| 127882 | 128600 | /* Version 3.34.0 and later */ |
| 127883 | 128601 | sqlite3_txn_state, |
| 127884 | 128602 | /* Version 3.36.1 and later */ |
| 127885 | 128603 | sqlite3_changes64, |
| 127886 | 128604 | sqlite3_total_changes64, |
| 128605 | + /* Version 3.37.0 and later */ |
| 128606 | + sqlite3_autovacuum_pages, |
| 127887 | 128607 | }; |
| 127888 | 128608 | |
| 127889 | 128609 | /* True if x is the directory separator character |
| 127890 | 128610 | */ |
| 127891 | 128611 | #if SQLITE_OS_WIN |
| | @@ -128871,11 +129591,11 @@ |
| 128871 | 129591 | /* iArg: */ 0 }, |
| 128872 | 129592 | {/* zName: */ "table_list", |
| 128873 | 129593 | /* ePragTyp: */ PragTyp_TABLE_LIST, |
| 128874 | 129594 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1, |
| 128875 | 129595 | /* ColNames: */ 15, 6, |
| 128876 | | - /* iArg: */ 1 }, |
| 129596 | + /* iArg: */ 0 }, |
| 128877 | 129597 | {/* zName: */ "table_xinfo", |
| 128878 | 129598 | /* ePragTyp: */ PragTyp_TABLE_INFO, |
| 128879 | 129599 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt, |
| 128880 | 129600 | /* ColNames: */ 8, 7, |
| 128881 | 129601 | /* iArg: */ 1 }, |
| | @@ -129400,11 +130120,15 @@ |
| 129400 | 130120 | goto pragma_out; |
| 129401 | 130121 | } |
| 129402 | 130122 | |
| 129403 | 130123 | /* Locate the pragma in the lookup table */ |
| 129404 | 130124 | pPragma = pragmaLocate(zLeft); |
| 129405 | | - if( pPragma==0 ) goto pragma_out; |
| 130125 | + if( pPragma==0 ){ |
| 130126 | + /* IMP: R-43042-22504 No error messages are generated if an |
| 130127 | + ** unknown pragma is issued. */ |
| 130128 | + goto pragma_out; |
| 130129 | + } |
| 129406 | 130130 | |
| 129407 | 130131 | /* Make sure the database schema is loaded if the pragma requires that */ |
| 129408 | 130132 | if( (pPragma->mPragFlg & PragFlg_NeedSchema)!=0 ){ |
| 129409 | 130133 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 129410 | 130134 | } |
| | @@ -130050,10 +130774,18 @@ |
| 130050 | 130774 | if( sqlite3GetBoolean(zRight, 0) ){ |
| 130051 | 130775 | db->flags |= mask; |
| 130052 | 130776 | }else{ |
| 130053 | 130777 | db->flags &= ~mask; |
| 130054 | 130778 | if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0; |
| 130779 | + if( (mask & SQLITE_WriteSchema)!=0 |
| 130780 | + && sqlite3_stricmp(zRight, "reset")==0 |
| 130781 | + ){ |
| 130782 | + /* IMP: R-60817-01178 If the argument is "RESET" then schema |
| 130783 | + ** writing is disabled (as with "PRAGMA writable_schema=OFF") and, |
| 130784 | + ** in addition, the schema is reloaded. */ |
| 130785 | + sqlite3ResetAllSchemasOfConnection(db); |
| 130786 | + } |
| 130055 | 130787 | } |
| 130056 | 130788 | |
| 130057 | 130789 | /* Many of the flag-pragmas modify the code generated by the SQL |
| 130058 | 130790 | ** compiler (eg. count_changes). So add an opcode to expire all |
| 130059 | 130791 | ** compiled SQL statements after modifying a pragma value. |
| | @@ -130090,10 +130822,11 @@ |
| 130090 | 130822 | Index *pPk = sqlite3PrimaryKeyIndex(pTab); |
| 130091 | 130823 | pParse->nMem = 7; |
| 130092 | 130824 | sqlite3ViewGetColumnNames(pParse, pTab); |
| 130093 | 130825 | for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ |
| 130094 | 130826 | int isHidden = 0; |
| 130827 | + const Expr *pColExpr; |
| 130095 | 130828 | if( pCol->colFlags & COLFLAG_NOINSERT ){ |
| 130096 | 130829 | if( pPragma->iArg==0 ){ |
| 130097 | 130830 | nHidden++; |
| 130098 | 130831 | continue; |
| 130099 | 130832 | } |
| | @@ -130110,20 +130843,20 @@ |
| 130110 | 130843 | }else if( pPk==0 ){ |
| 130111 | 130844 | k = 1; |
| 130112 | 130845 | }else{ |
| 130113 | 130846 | for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){} |
| 130114 | 130847 | } |
| 130115 | | - assert( sqlite3ColumnExpr(pTab,pCol)==0 |
| 130116 | | - || sqlite3ColumnExpr(pTab,pCol)->op==TK_SPAN |
| 130117 | | - || isHidden>=2 ); |
| 130848 | + pColExpr = sqlite3ColumnExpr(pTab,pCol); |
| 130849 | + assert( pColExpr==0 || pColExpr->op==TK_SPAN || isHidden>=2 ); |
| 130850 | + assert( pColExpr==0 || !ExprHasProperty(pColExpr, EP_IntValue) |
| 130851 | + || isHidden>=2 ); |
| 130118 | 130852 | sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi", |
| 130119 | 130853 | i-nHidden, |
| 130120 | 130854 | pCol->zCnName, |
| 130121 | 130855 | sqlite3ColumnType(pCol,""), |
| 130122 | 130856 | pCol->notNull ? 1 : 0, |
| 130123 | | - isHidden>=2 || sqlite3ColumnExpr(pTab,pCol)==0 ? 0 : |
| 130124 | | - sqlite3ColumnExpr(pTab,pCol)->u.zToken, |
| 130857 | + (isHidden>=2 || pColExpr==0) ? 0 : pColExpr->u.zToken, |
| 130125 | 130858 | k, |
| 130126 | 130859 | isHidden); |
| 130127 | 130860 | } |
| 130128 | 130861 | } |
| 130129 | 130862 | } |
| | @@ -130147,12 +130880,39 @@ |
| 130147 | 130880 | pParse->nMem = 6; |
| 130148 | 130881 | sqlite3CodeVerifyNamedSchema(pParse, zDb); |
| 130149 | 130882 | for(ii=0; ii<db->nDb; ii++){ |
| 130150 | 130883 | HashElem *k; |
| 130151 | 130884 | Hash *pHash; |
| 130885 | + int initNCol; |
| 130152 | 130886 | if( zDb && sqlite3_stricmp(zDb, db->aDb[ii].zDbSName)!=0 ) continue; |
| 130887 | + |
| 130888 | + /* Ensure that the Table.nCol field is initialized for all views |
| 130889 | + ** and virtual tables. Each time we initialize a Table.nCol value |
| 130890 | + ** for a table, that can potentially disrupt the hash table, so restart |
| 130891 | + ** the initialization scan. |
| 130892 | + */ |
| 130153 | 130893 | pHash = &db->aDb[ii].pSchema->tblHash; |
| 130894 | + initNCol = sqliteHashCount(pHash); |
| 130895 | + while( initNCol-- ){ |
| 130896 | + for(k=sqliteHashFirst(pHash); 1; k=sqliteHashNext(k) ){ |
| 130897 | + Table *pTab; |
| 130898 | + if( k==0 ){ initNCol = 0; break; } |
| 130899 | + pTab = sqliteHashData(k); |
| 130900 | + if( pTab->nCol==0 ){ |
| 130901 | + char *zSql = sqlite3MPrintf(db, "SELECT*FROM\"%w\"", pTab->zName); |
| 130902 | + if( zSql ){ |
| 130903 | + sqlite3_stmt *pDummy = 0; |
| 130904 | + (void)sqlite3_prepare(db, zSql, -1, &pDummy, 0); |
| 130905 | + (void)sqlite3_finalize(pDummy); |
| 130906 | + sqlite3DbFree(db, zSql); |
| 130907 | + } |
| 130908 | + pHash = &db->aDb[ii].pSchema->tblHash; |
| 130909 | + break; |
| 130910 | + } |
| 130911 | + } |
| 130912 | + } |
| 130913 | + |
| 130154 | 130914 | for(k=sqliteHashFirst(pHash); k; k=sqliteHashNext(k) ){ |
| 130155 | 130915 | Table *pTab = sqliteHashData(k); |
| 130156 | 130916 | const char *zType; |
| 130157 | 130917 | if( zRight && sqlite3_stricmp(zRight, pTab->zName)!=0 ) continue; |
| 130158 | 130918 | if( IsView(pTab) ){ |
| | @@ -130164,11 +130924,11 @@ |
| 130164 | 130924 | }else{ |
| 130165 | 130925 | zType = "table"; |
| 130166 | 130926 | } |
| 130167 | 130927 | sqlite3VdbeMultiLoad(v, 1, "sssiii", |
| 130168 | 130928 | db->aDb[ii].zDbSName, |
| 130169 | | - pTab->zName, |
| 130929 | + sqlite3PreferredTableName(pTab->zName), |
| 130170 | 130930 | zType, |
| 130171 | 130931 | pTab->nCol, |
| 130172 | 130932 | (pTab->tabFlags & TF_WithoutRowid)!=0, |
| 130173 | 130933 | (pTab->tabFlags & TF_Strict)!=0 |
| 130174 | 130934 | ); |
| | @@ -130184,11 +130944,11 @@ |
| 130184 | 130944 | pParse->nMem = 5; |
| 130185 | 130945 | sqlite3CodeVerifySchema(pParse, iDb); |
| 130186 | 130946 | for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){ |
| 130187 | 130947 | Table *pTab = sqliteHashData(i); |
| 130188 | 130948 | sqlite3VdbeMultiLoad(v, 1, "ssiii", |
| 130189 | | - pTab->zName, |
| 130949 | + sqlite3PreferredTableName(pTab->zName), |
| 130190 | 130950 | 0, |
| 130191 | 130951 | pTab->szTabRow, |
| 130192 | 130952 | pTab->nRowLogEst, |
| 130193 | 130953 | pTab->tabFlags); |
| 130194 | 130954 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| | @@ -130303,15 +131063,17 @@ |
| 130303 | 131063 | FuncDef *p; |
| 130304 | 131064 | int showInternFunc = (db->mDbFlags & DBFLAG_InternalFunc)!=0; |
| 130305 | 131065 | pParse->nMem = 6; |
| 130306 | 131066 | for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){ |
| 130307 | 131067 | for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){ |
| 131068 | + assert( p->funcFlags & SQLITE_FUNC_BUILTIN ); |
| 130308 | 131069 | pragmaFunclistLine(v, p, 1, showInternFunc); |
| 130309 | 131070 | } |
| 130310 | 131071 | } |
| 130311 | 131072 | for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){ |
| 130312 | 131073 | p = (FuncDef*)sqliteHashData(j); |
| 131074 | + assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 ); |
| 130313 | 131075 | pragmaFunclistLine(v, p, 0, showInternFunc); |
| 130314 | 131076 | } |
| 130315 | 131077 | } |
| 130316 | 131078 | break; |
| 130317 | 131079 | |
| | @@ -130341,11 +131103,11 @@ |
| 130341 | 131103 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 130342 | 131104 | case PragTyp_FOREIGN_KEY_LIST: if( zRight ){ |
| 130343 | 131105 | FKey *pFK; |
| 130344 | 131106 | Table *pTab; |
| 130345 | 131107 | pTab = sqlite3FindTable(db, zRight, zDb); |
| 130346 | | - if( pTab && !IsVirtual(pTab) ){ |
| 131108 | + if( pTab && IsOrdinaryTable(pTab) ){ |
| 130347 | 131109 | pFK = pTab->u.tab.pFKey; |
| 130348 | 131110 | if( pFK ){ |
| 130349 | 131111 | int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 130350 | 131112 | int i = 0; |
| 130351 | 131113 | pParse->nMem = 8; |
| | @@ -130401,19 +131163,19 @@ |
| 130401 | 131163 | k = 0; |
| 130402 | 131164 | }else{ |
| 130403 | 131165 | pTab = (Table*)sqliteHashData(k); |
| 130404 | 131166 | k = sqliteHashNext(k); |
| 130405 | 131167 | } |
| 130406 | | - if( pTab==0 || IsVirtual(pTab) || pTab->u.tab.pFKey==0 ) continue; |
| 131168 | + if( pTab==0 || !IsOrdinaryTable(pTab) || pTab->u.tab.pFKey==0 ) continue; |
| 130407 | 131169 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 130408 | 131170 | zDb = db->aDb[iDb].zDbSName; |
| 130409 | 131171 | sqlite3CodeVerifySchema(pParse, iDb); |
| 130410 | 131172 | sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); |
| 130411 | 131173 | if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow; |
| 130412 | 131174 | sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead); |
| 130413 | 131175 | sqlite3VdbeLoadString(v, regResult, pTab->zName); |
| 130414 | | - assert( !IsVirtual(pTab) ); |
| 131176 | + assert( IsOrdinaryTable(pTab) ); |
| 130415 | 131177 | for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
| 130416 | 131178 | pParent = sqlite3FindTable(db, pFK->zTo, zDb); |
| 130417 | 131179 | if( pParent==0 ) continue; |
| 130418 | 131180 | pIdx = 0; |
| 130419 | 131181 | sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName); |
| | @@ -130432,11 +131194,11 @@ |
| 130432 | 131194 | } |
| 130433 | 131195 | assert( pParse->nErr>0 || pFK==0 ); |
| 130434 | 131196 | if( pFK ) break; |
| 130435 | 131197 | if( pParse->nTab<i ) pParse->nTab = i; |
| 130436 | 131198 | addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v); |
| 130437 | | - assert( !IsVirtual(pTab) ); |
| 131199 | + assert( IsOrdinaryTable(pTab) ); |
| 130438 | 131200 | for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
| 130439 | 131201 | pParent = sqlite3FindTable(db, pFK->zTo, zDb); |
| 130440 | 131202 | pIdx = 0; |
| 130441 | 131203 | aiCols = 0; |
| 130442 | 131204 | if( pParent ){ |
| | @@ -130636,11 +131398,11 @@ |
| 130636 | 131398 | int loopTop; |
| 130637 | 131399 | int iDataCur, iIdxCur; |
| 130638 | 131400 | int r1 = -1; |
| 130639 | 131401 | int bStrict; |
| 130640 | 131402 | |
| 130641 | | - if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */ |
| 131403 | + if( !IsOrdinaryTable(pTab) ) continue; |
| 130642 | 131404 | if( pObjTab && pObjTab!=pTab ) continue; |
| 130643 | 131405 | pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab); |
| 130644 | 131406 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0, |
| 130645 | 131407 | 1, 0, &iDataCur, &iIdxCur); |
| 130646 | 131408 | /* reg[7] counts the number of entries in the table. |
| | @@ -130677,11 +131439,11 @@ |
| 130677 | 131439 | if( pCol->notNull ){ |
| 130678 | 131440 | jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v); |
| 130679 | 131441 | zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName, |
| 130680 | 131442 | pCol->zCnName); |
| 130681 | 131443 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
| 130682 | | - if( bStrict ){ |
| 131444 | + if( bStrict && pCol->eCType!=COLTYPE_ANY ){ |
| 130683 | 131445 | sqlite3VdbeGoto(v, doError); |
| 130684 | 131446 | }else{ |
| 130685 | 131447 | integrityCheckResultRow(v); |
| 130686 | 131448 | } |
| 130687 | 131449 | sqlite3VdbeJumpHere(v, jmp2); |
| | @@ -131231,16 +131993,16 @@ |
| 131231 | 131993 | ** in each index that it looks at. Return the new limit. |
| 131232 | 131994 | */ |
| 131233 | 131995 | case PragTyp_ANALYSIS_LIMIT: { |
| 131234 | 131996 | sqlite3_int64 N; |
| 131235 | 131997 | if( zRight |
| 131236 | | - && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK |
| 131998 | + && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK /* IMP: R-40975-20399 */ |
| 131237 | 131999 | && N>=0 |
| 131238 | 132000 | ){ |
| 131239 | 132001 | db->nAnalysisLimit = (int)(N&0x7fffffff); |
| 131240 | 132002 | } |
| 131241 | | - returnSingleInt(v, db->nAnalysisLimit); |
| 132003 | + returnSingleInt(v, db->nAnalysisLimit); /* IMP: R-57594-65522 */ |
| 131242 | 132004 | break; |
| 131243 | 132005 | } |
| 131244 | 132006 | |
| 131245 | 132007 | #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
| 131246 | 132008 | /* |
| | @@ -131638,14 +132400,19 @@ |
| 131638 | 132400 | sqlite3 *db = pData->db; |
| 131639 | 132401 | if( db->mallocFailed ){ |
| 131640 | 132402 | pData->rc = SQLITE_NOMEM_BKPT; |
| 131641 | 132403 | }else if( pData->pzErrMsg[0]!=0 ){ |
| 131642 | 132404 | /* A error message has already been generated. Do not overwrite it */ |
| 131643 | | - }else if( pData->mInitFlags & (INITFLAG_AlterRename|INITFLAG_AlterDrop) ){ |
| 132405 | + }else if( pData->mInitFlags & (INITFLAG_AlterMask) ){ |
| 132406 | + static const char *azAlterType[] = { |
| 132407 | + "rename", |
| 132408 | + "drop column", |
| 132409 | + "add column" |
| 132410 | + }; |
| 131644 | 132411 | *pData->pzErrMsg = sqlite3MPrintf(db, |
| 131645 | 132412 | "error in %s %s after %s: %s", azObj[0], azObj[1], |
| 131646 | | - (pData->mInitFlags & INITFLAG_AlterRename) ? "rename" : "drop column", |
| 132413 | + azAlterType[(pData->mInitFlags&INITFLAG_AlterMask)-1], |
| 131647 | 132414 | zExtra |
| 131648 | 132415 | ); |
| 131649 | 132416 | pData->rc = SQLITE_ERROR; |
| 131650 | 132417 | }else if( db->flags & SQLITE_WriteSchema ){ |
| 131651 | 132418 | pData->rc = SQLITE_CORRUPT_BKPT; |
| | @@ -132412,10 +133179,11 @@ |
| 132412 | 133179 | /* Make multiple attempts to compile the SQL, until it either succeeds |
| 132413 | 133180 | ** or encounters a permanent error. A schema problem after one schema |
| 132414 | 133181 | ** reset is considered a permanent error. */ |
| 132415 | 133182 | rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail); |
| 132416 | 133183 | assert( rc==SQLITE_OK || *ppStmt==0 ); |
| 133184 | + if( rc==SQLITE_OK || db->mallocFailed ) break; |
| 132417 | 133185 | }while( rc==SQLITE_ERROR_RETRY |
| 132418 | 133186 | || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) ); |
| 132419 | 133187 | sqlite3BtreeLeaveAll(db); |
| 132420 | 133188 | rc = sqlite3ApiExit(db, rc); |
| 132421 | 133189 | assert( (rc&db->errMask)==rc ); |
| | @@ -133023,14 +133791,17 @@ |
| 133023 | 133791 | while( p ){ |
| 133024 | 133792 | ExprSetProperty(p, EP_FromJoin); |
| 133025 | 133793 | assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) ); |
| 133026 | 133794 | ExprSetVVAProperty(p, EP_NoReduce); |
| 133027 | 133795 | p->iRightJoinTable = iTable; |
| 133028 | | - if( p->op==TK_FUNCTION && p->x.pList ){ |
| 133029 | | - int i; |
| 133030 | | - for(i=0; i<p->x.pList->nExpr; i++){ |
| 133031 | | - sqlite3SetJoinExpr(p->x.pList->a[i].pExpr, iTable); |
| 133796 | + if( p->op==TK_FUNCTION ){ |
| 133797 | + assert( ExprUseXList(p) ); |
| 133798 | + if( p->x.pList ){ |
| 133799 | + int i; |
| 133800 | + for(i=0; i<p->x.pList->nExpr; i++){ |
| 133801 | + sqlite3SetJoinExpr(p->x.pList->a[i].pExpr, iTable); |
| 133802 | + } |
| 133032 | 133803 | } |
| 133033 | 133804 | } |
| 133034 | 133805 | sqlite3SetJoinExpr(p->pLeft, iTable); |
| 133035 | 133806 | p = p->pRight; |
| 133036 | 133807 | } |
| | @@ -133049,14 +133820,17 @@ |
| 133049 | 133820 | ExprClearProperty(p, EP_FromJoin); |
| 133050 | 133821 | } |
| 133051 | 133822 | if( p->op==TK_COLUMN && p->iTable==iTable ){ |
| 133052 | 133823 | ExprClearProperty(p, EP_CanBeNull); |
| 133053 | 133824 | } |
| 133054 | | - if( p->op==TK_FUNCTION && p->x.pList ){ |
| 133055 | | - int i; |
| 133056 | | - for(i=0; i<p->x.pList->nExpr; i++){ |
| 133057 | | - unsetJoinExpr(p->x.pList->a[i].pExpr, iTable); |
| 133825 | + if( p->op==TK_FUNCTION ){ |
| 133826 | + assert( ExprUseXList(p) ); |
| 133827 | + if( p->x.pList ){ |
| 133828 | + int i; |
| 133829 | + for(i=0; i<p->x.pList->nExpr; i++){ |
| 133830 | + unsetJoinExpr(p->x.pList->a[i].pExpr, iTable); |
| 133831 | + } |
| 133058 | 133832 | } |
| 133059 | 133833 | } |
| 133060 | 133834 | unsetJoinExpr(p->pLeft, iTable); |
| 133061 | 133835 | p = p->pRight; |
| 133062 | 133836 | } |
| | @@ -133567,13 +134341,17 @@ |
| 133567 | 134341 | ExprList *pExtra = 0; |
| 133568 | 134342 | for(i=0; i<pEList->nExpr; i++){ |
| 133569 | 134343 | struct ExprList_item *pItem = &pEList->a[i]; |
| 133570 | 134344 | if( pItem->u.x.iOrderByCol==0 ){ |
| 133571 | 134345 | Expr *pExpr = pItem->pExpr; |
| 133572 | | - Table *pTab = pExpr->y.pTab; |
| 133573 | | - if( pExpr->op==TK_COLUMN && pExpr->iColumn>=0 && pTab && !IsVirtual(pTab) |
| 133574 | | - && (pTab->aCol[pExpr->iColumn].colFlags & COLFLAG_SORTERREF) |
| 134346 | + Table *pTab; |
| 134347 | + if( pExpr->op==TK_COLUMN |
| 134348 | + && pExpr->iColumn>=0 |
| 134349 | + && ALWAYS( ExprUseYTab(pExpr) ) |
| 134350 | + && (pTab = pExpr->y.pTab)!=0 |
| 134351 | + && IsOrdinaryTable(pTab) |
| 134352 | + && (pTab->aCol[pExpr->iColumn].colFlags & COLFLAG_SORTERREF)!=0 |
| 133575 | 134353 | ){ |
| 133576 | 134354 | int j; |
| 133577 | 134355 | for(j=0; j<nDefer; j++){ |
| 133578 | 134356 | if( pSort->aDefer[j].iCsr==pExpr->iTable ) break; |
| 133579 | 134357 | } |
| | @@ -133590,10 +134368,11 @@ |
| 133590 | 134368 | } |
| 133591 | 134369 | for(k=0; k<nKey; k++){ |
| 133592 | 134370 | Expr *pNew = sqlite3PExpr(pParse, TK_COLUMN, 0, 0); |
| 133593 | 134371 | if( pNew ){ |
| 133594 | 134372 | pNew->iTable = pExpr->iTable; |
| 134373 | + assert( ExprUseYTab(pNew) ); |
| 133595 | 134374 | pNew->y.pTab = pExpr->y.pTab; |
| 133596 | 134375 | pNew->iColumn = pPk ? pPk->aiColumn[k] : -1; |
| 133597 | 134376 | pExtra = sqlite3ExprListAppend(pParse, pExtra, pNew); |
| 133598 | 134377 | } |
| 133599 | 134378 | } |
| | @@ -134438,11 +135217,11 @@ |
| 134438 | 135217 | ** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT |
| 134439 | 135218 | ** branch below. */ |
| 134440 | 135219 | break; |
| 134441 | 135220 | } |
| 134442 | 135221 | |
| 134443 | | - assert( pTab && pExpr->y.pTab==pTab ); |
| 135222 | + assert( pTab && ExprUseYTab(pExpr) && pExpr->y.pTab==pTab ); |
| 134444 | 135223 | if( pS ){ |
| 134445 | 135224 | /* The "table" is actually a sub-select or a view in the FROM clause |
| 134446 | 135225 | ** of the SELECT statement. Return the declaration type and origin |
| 134447 | 135226 | ** data for the result-set column of the sub-select. |
| 134448 | 135227 | */ |
| | @@ -134498,13 +135277,15 @@ |
| 134498 | 135277 | /* The expression is a sub-select. Return the declaration type and |
| 134499 | 135278 | ** origin info for the single column in the result set of the SELECT |
| 134500 | 135279 | ** statement. |
| 134501 | 135280 | */ |
| 134502 | 135281 | NameContext sNC; |
| 134503 | | - Select *pS = pExpr->x.pSelect; |
| 134504 | | - Expr *p = pS->pEList->a[0].pExpr; |
| 134505 | | - assert( ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 135282 | + Select *pS; |
| 135283 | + Expr *p; |
| 135284 | + assert( ExprUseXSelect(pExpr) ); |
| 135285 | + pS = pExpr->x.pSelect; |
| 135286 | + p = pS->pEList->a[0].pExpr; |
| 134506 | 135287 | sNC.pSrcList = pS->pSrc; |
| 134507 | 135288 | sNC.pNext = pNC; |
| 134508 | 135289 | sNC.pParse = pNC->pParse; |
| 134509 | 135290 | zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol); |
| 134510 | 135291 | break; |
| | @@ -134629,11 +135410,12 @@ |
| 134629 | 135410 | for(i=0; i<pEList->nExpr; i++){ |
| 134630 | 135411 | Expr *p = pEList->a[i].pExpr; |
| 134631 | 135412 | |
| 134632 | 135413 | assert( p!=0 ); |
| 134633 | 135414 | assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */ |
| 134634 | | - assert( p->op!=TK_COLUMN || p->y.pTab!=0 ); /* Covering idx not yet coded */ |
| 135415 | + assert( p->op!=TK_COLUMN |
| 135416 | + || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */ |
| 134635 | 135417 | if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){ |
| 134636 | 135418 | /* An AS clause always takes first priority */ |
| 134637 | 135419 | char *zName = pEList->a[i].zEName; |
| 134638 | 135420 | sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT); |
| 134639 | 135421 | }else if( srcName && p->op==TK_COLUMN ){ |
| | @@ -134725,11 +135507,14 @@ |
| 134725 | 135507 | Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr); |
| 134726 | 135508 | while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){ |
| 134727 | 135509 | pColExpr = pColExpr->pRight; |
| 134728 | 135510 | assert( pColExpr!=0 ); |
| 134729 | 135511 | } |
| 134730 | | - if( pColExpr->op==TK_COLUMN && (pTab = pColExpr->y.pTab)!=0 ){ |
| 135512 | + if( pColExpr->op==TK_COLUMN |
| 135513 | + && ALWAYS( ExprUseYTab(pColExpr) ) |
| 135514 | + && (pTab = pColExpr->y.pTab)!=0 |
| 135515 | + ){ |
| 134731 | 135516 | /* For columns use the column name name */ |
| 134732 | 135517 | int iCol = pColExpr->iColumn; |
| 134733 | 135518 | if( iCol<0 ) iCol = pTab->iPKey; |
| 134734 | 135519 | zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid"; |
| 134735 | 135520 | }else if( pColExpr->op==TK_ID ){ |
| | @@ -134811,11 +135596,11 @@ |
| 134811 | 135596 | memset(&sNC, 0, sizeof(sNC)); |
| 134812 | 135597 | sNC.pSrcList = pSelect->pSrc; |
| 134813 | 135598 | a = pSelect->pEList->a; |
| 134814 | 135599 | for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ |
| 134815 | 135600 | const char *zType; |
| 134816 | | - int n, m; |
| 135601 | + i64 n, m; |
| 134817 | 135602 | pTab->tabFlags |= (pCol->colFlags & COLFLAG_NOINSERT); |
| 134818 | 135603 | p = a[i].pExpr; |
| 134819 | 135604 | zType = columnType(&sNC, p, 0, 0, 0); |
| 134820 | 135605 | /* pCol->szEst = ... // Column size est for SELECT tables never used */ |
| 134821 | 135606 | pCol->affinity = sqlite3ExprAffinity(p); |
| | @@ -134824,10 +135609,13 @@ |
| 134824 | 135609 | n = sqlite3Strlen30(pCol->zCnName); |
| 134825 | 135610 | pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2); |
| 134826 | 135611 | if( pCol->zCnName ){ |
| 134827 | 135612 | memcpy(&pCol->zCnName[n+1], zType, m+1); |
| 134828 | 135613 | pCol->colFlags |= COLFLAG_HASTYPE; |
| 135614 | + }else{ |
| 135615 | + testcase( pCol->colFlags & COLFLAG_HASTYPE ); |
| 135616 | + pCol->colFlags &= ~(COLFLAG_HASTYPE|COLFLAG_HASCOLL); |
| 134829 | 135617 | } |
| 134830 | 135618 | } |
| 134831 | 135619 | if( pCol->affinity<=SQLITE_AFF_NONE ) pCol->affinity = aff; |
| 134832 | 135620 | pColl = sqlite3ExprCollSeq(pParse, p); |
| 134833 | 135621 | if( pColl ){ |
| | @@ -134994,11 +135782,11 @@ |
| 134994 | 135782 | ** function is responsible for ensuring that this structure is eventually |
| 134995 | 135783 | ** freed. |
| 134996 | 135784 | */ |
| 134997 | 135785 | static KeyInfo *multiSelectOrderByKeyInfo(Parse *pParse, Select *p, int nExtra){ |
| 134998 | 135786 | ExprList *pOrderBy = p->pOrderBy; |
| 134999 | | - int nOrderBy = p->pOrderBy->nExpr; |
| 135787 | + int nOrderBy = ALWAYS(pOrderBy!=0) ? pOrderBy->nExpr : 0; |
| 135000 | 135788 | sqlite3 *db = pParse->db; |
| 135001 | 135789 | KeyInfo *pRet = sqlite3KeyInfoAlloc(db, nOrderBy+nExtra, 1); |
| 135002 | 135790 | if( pRet ){ |
| 135003 | 135791 | int i; |
| 135004 | 135792 | for(i=0; i<nOrderBy; i++){ |
| | @@ -135615,10 +136403,11 @@ |
| 135615 | 136403 | Select *pLoop; /* For looping through SELECT statements */ |
| 135616 | 136404 | CollSeq **apColl; /* For looping through pKeyInfo->aColl[] */ |
| 135617 | 136405 | int nCol; /* Number of columns in result set */ |
| 135618 | 136406 | |
| 135619 | 136407 | assert( p->pNext==0 ); |
| 136408 | + assert( p->pEList!=0 ); |
| 135620 | 136409 | nCol = p->pEList->nExpr; |
| 135621 | 136410 | pKeyInfo = sqlite3KeyInfoAlloc(db, nCol, 1); |
| 135622 | 136411 | if( !pKeyInfo ){ |
| 135623 | 136412 | rc = SQLITE_NOMEM_BKPT; |
| 135624 | 136413 | goto multi_select_end; |
| | @@ -135966,10 +136755,11 @@ |
| 135966 | 136755 | */ |
| 135967 | 136756 | if( op!=TK_ALL ){ |
| 135968 | 136757 | for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){ |
| 135969 | 136758 | struct ExprList_item *pItem; |
| 135970 | 136759 | for(j=0, pItem=pOrderBy->a; j<nOrderBy; j++, pItem++){ |
| 136760 | + assert( pItem!=0 ); |
| 135971 | 136761 | assert( pItem->u.x.iOrderByCol>0 ); |
| 135972 | 136762 | if( pItem->u.x.iOrderByCol==i ) break; |
| 135973 | 136763 | } |
| 135974 | 136764 | if( j==nOrderBy ){ |
| 135975 | 136765 | Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0); |
| | @@ -135992,10 +136782,11 @@ |
| 135992 | 136782 | aPermute = sqlite3DbMallocRawNN(db, sizeof(u32)*(nOrderBy + 1)); |
| 135993 | 136783 | if( aPermute ){ |
| 135994 | 136784 | struct ExprList_item *pItem; |
| 135995 | 136785 | aPermute[0] = nOrderBy; |
| 135996 | 136786 | for(i=1, pItem=pOrderBy->a; i<=nOrderBy; i++, pItem++){ |
| 136787 | + assert( pItem!=0 ); |
| 135997 | 136788 | assert( pItem->u.x.iOrderByCol>0 ); |
| 135998 | 136789 | assert( pItem->u.x.iOrderByCol<=p->pEList->nExpr ); |
| 135999 | 136790 | aPermute[i] = pItem->u.x.iOrderByCol - 1; |
| 136000 | 136791 | } |
| 136001 | 136792 | pKeyMerge = multiSelectOrderByKeyInfo(pParse, p, 1); |
| | @@ -136304,11 +137095,11 @@ |
| 136304 | 137095 | if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){ |
| 136305 | 137096 | pExpr->iTable = pSubst->iNewTable; |
| 136306 | 137097 | } |
| 136307 | 137098 | pExpr->pLeft = substExpr(pSubst, pExpr->pLeft); |
| 136308 | 137099 | pExpr->pRight = substExpr(pSubst, pExpr->pRight); |
| 136309 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 137100 | + if( ExprUseXSelect(pExpr) ){ |
| 136310 | 137101 | substSelect(pSubst, pExpr->x.pSelect, 1); |
| 136311 | 137102 | }else{ |
| 136312 | 137103 | substExprList(pSubst, pExpr->x.pList); |
| 136313 | 137104 | } |
| 136314 | 137105 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| | @@ -136791,11 +137582,11 @@ |
| 136791 | 137582 | /* Restriction (23) */ |
| 136792 | 137583 | if( (p->selFlags & SF_Recursive) ) return 0; |
| 136793 | 137584 | |
| 136794 | 137585 | if( pSrc->nSrc>1 ){ |
| 136795 | 137586 | if( pParse->nSelect>500 ) return 0; |
| 136796 | | - aCsrMap = sqlite3DbMallocZero(db, (pParse->nTab+1)*sizeof(int)); |
| 137587 | + aCsrMap = sqlite3DbMallocZero(db, ((i64)pParse->nTab+1)*sizeof(int)); |
| 136797 | 137588 | if( aCsrMap ) aCsrMap[0] = pParse->nTab; |
| 136798 | 137589 | } |
| 136799 | 137590 | } |
| 136800 | 137591 | |
| 136801 | 137592 | /***** If we reach this point, flattening is permitted. *****/ |
| | @@ -137515,25 +138306,28 @@ |
| 137515 | 138306 | ** located but before their arguments have been subjected to aggregate |
| 137516 | 138307 | ** analysis. |
| 137517 | 138308 | */ |
| 137518 | 138309 | static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){ |
| 137519 | 138310 | int eRet = WHERE_ORDERBY_NORMAL; /* Return value */ |
| 137520 | | - ExprList *pEList = pFunc->x.pList; /* Arguments to agg function */ |
| 138311 | + ExprList *pEList; /* Arguments to agg function */ |
| 137521 | 138312 | const char *zFunc; /* Name of aggregate function pFunc */ |
| 137522 | 138313 | ExprList *pOrderBy; |
| 137523 | 138314 | u8 sortFlags = 0; |
| 137524 | 138315 | |
| 137525 | 138316 | assert( *ppMinMax==0 ); |
| 137526 | 138317 | assert( pFunc->op==TK_AGG_FUNCTION ); |
| 137527 | 138318 | assert( !IsWindowFunc(pFunc) ); |
| 138319 | + assert( ExprUseXList(pFunc) ); |
| 138320 | + pEList = pFunc->x.pList; |
| 137528 | 138321 | if( pEList==0 |
| 137529 | 138322 | || pEList->nExpr!=1 |
| 137530 | 138323 | || ExprHasProperty(pFunc, EP_WinFunc) |
| 137531 | 138324 | || OptimizationDisabled(db, SQLITE_MinMaxOpt) |
| 137532 | 138325 | ){ |
| 137533 | 138326 | return eRet; |
| 137534 | 138327 | } |
| 138328 | + assert( !ExprHasProperty(pFunc, EP_IntValue) ); |
| 137535 | 138329 | zFunc = pFunc->u.zToken; |
| 137536 | 138330 | if( sqlite3StrICmp(zFunc, "min")==0 ){ |
| 137537 | 138331 | eRet = WHERE_ORDERBY_MIN; |
| 137538 | 138332 | if( sqlite3ExprCanBeNull(pEList->a[0].pExpr) ){ |
| 137539 | 138333 | sortFlags = KEYINFO_ORDER_BIGNULL; |
| | @@ -137557,31 +138351,44 @@ |
| 137557 | 138351 | ** |
| 137558 | 138352 | ** SELECT count(*) FROM <tbl> |
| 137559 | 138353 | ** |
| 137560 | 138354 | ** where table is a database table, not a sub-select or view. If the query |
| 137561 | 138355 | ** does match this pattern, then a pointer to the Table object representing |
| 137562 | | -** <tbl> is returned. Otherwise, 0 is returned. |
| 138356 | +** <tbl> is returned. Otherwise, NULL is returned. |
| 138357 | +** |
| 138358 | +** This routine checks to see if it is safe to use the count optimization. |
| 138359 | +** A correct answer is still obtained (though perhaps more slowly) if |
| 138360 | +** this routine returns NULL when it could have returned a table pointer. |
| 138361 | +** But returning the pointer when NULL should have been returned can |
| 138362 | +** result in incorrect answers and/or crashes. So, when in doubt, return NULL. |
| 137563 | 138363 | */ |
| 137564 | 138364 | static Table *isSimpleCount(Select *p, AggInfo *pAggInfo){ |
| 137565 | 138365 | Table *pTab; |
| 137566 | 138366 | Expr *pExpr; |
| 137567 | 138367 | |
| 137568 | 138368 | assert( !p->pGroupBy ); |
| 137569 | 138369 | |
| 137570 | | - if( p->pWhere || p->pEList->nExpr!=1 |
| 137571 | | - || p->pSrc->nSrc!=1 || p->pSrc->a[0].pSelect |
| 138370 | + if( p->pWhere |
| 138371 | + || p->pEList->nExpr!=1 |
| 138372 | + || p->pSrc->nSrc!=1 |
| 138373 | + || p->pSrc->a[0].pSelect |
| 138374 | + || pAggInfo->nFunc!=1 |
| 137572 | 138375 | ){ |
| 137573 | 138376 | return 0; |
| 137574 | 138377 | } |
| 137575 | 138378 | pTab = p->pSrc->a[0].pTab; |
| 138379 | + assert( pTab!=0 ); |
| 138380 | + assert( !IsView(pTab) ); |
| 138381 | + if( !IsOrdinaryTable(pTab) ) return 0; |
| 137576 | 138382 | pExpr = p->pEList->a[0].pExpr; |
| 137577 | | - assert( pTab && !IsView(pTab) && pExpr ); |
| 137578 | | - |
| 137579 | | - if( IsVirtual(pTab) ) return 0; |
| 138383 | + assert( pExpr!=0 ); |
| 137580 | 138384 | if( pExpr->op!=TK_AGG_FUNCTION ) return 0; |
| 137581 | | - if( NEVER(pAggInfo->nFunc==0) ) return 0; |
| 138385 | + if( pExpr->pAggInfo!=pAggInfo ) return 0; |
| 137582 | 138386 | if( (pAggInfo->aFunc[0].pFunc->funcFlags&SQLITE_FUNC_COUNT)==0 ) return 0; |
| 138387 | + assert( pAggInfo->aFunc[0].pFExpr==pExpr ); |
| 138388 | + testcase( ExprHasProperty(pExpr, EP_Distinct) ); |
| 138389 | + testcase( ExprHasProperty(pExpr, EP_WinFunc) ); |
| 137583 | 138390 | if( ExprHasProperty(pExpr, EP_Distinct|EP_WinFunc) ) return 0; |
| 137584 | 138391 | |
| 137585 | 138392 | return pTab; |
| 137586 | 138393 | } |
| 137587 | 138394 | |
| | @@ -137606,10 +138413,11 @@ |
| 137606 | 138413 | if( !pIdx ){ |
| 137607 | 138414 | sqlite3ErrorMsg(pParse, "no such index: %s", zIndexedBy, 0); |
| 137608 | 138415 | pParse->checkSchema = 1; |
| 137609 | 138416 | return SQLITE_ERROR; |
| 137610 | 138417 | } |
| 138418 | + assert( pFrom->fg.isCte==0 ); |
| 137611 | 138419 | pFrom->u2.pIBIndex = pIdx; |
| 137612 | 138420 | return SQLITE_OK; |
| 137613 | 138421 | } |
| 137614 | 138422 | |
| 137615 | 138423 | /* |
| | @@ -137863,10 +138671,14 @@ |
| 137863 | 138671 | pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid; |
| 137864 | 138672 | pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0); |
| 137865 | 138673 | if( db->mallocFailed ) return 2; |
| 137866 | 138674 | pFrom->pSelect->selFlags |= SF_CopyCte; |
| 137867 | 138675 | assert( pFrom->pSelect ); |
| 138676 | + if( pFrom->fg.isIndexedBy ){ |
| 138677 | + sqlite3ErrorMsg(pParse, "no such index: \"%s\"", pFrom->u1.zIndexedBy); |
| 138678 | + return 2; |
| 138679 | + } |
| 137868 | 138680 | pFrom->fg.isCte = 1; |
| 137869 | 138681 | pFrom->u2.pCteUse = pCteUse; |
| 137870 | 138682 | pCteUse->nUse++; |
| 137871 | 138683 | if( pCteUse->nUse>=2 && pCteUse->eM10d==M10d_Any ){ |
| 137872 | 138684 | pCteUse->eM10d = M10d_Yes; |
| | @@ -138498,11 +139310,11 @@ |
| 138498 | 139310 | #endif |
| 138499 | 139311 | sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg); |
| 138500 | 139312 | for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){ |
| 138501 | 139313 | if( pFunc->iDistinct>=0 ){ |
| 138502 | 139314 | Expr *pE = pFunc->pFExpr; |
| 138503 | | - assert( !ExprHasProperty(pE, EP_xIsSelect) ); |
| 139315 | + assert( ExprUseXList(pE) ); |
| 138504 | 139316 | if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){ |
| 138505 | 139317 | sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one " |
| 138506 | 139318 | "argument"); |
| 138507 | 139319 | pFunc->iDistinct = -1; |
| 138508 | 139320 | }else{ |
| | @@ -138523,12 +139335,13 @@ |
| 138523 | 139335 | static void finalizeAggFunctions(Parse *pParse, AggInfo *pAggInfo){ |
| 138524 | 139336 | Vdbe *v = pParse->pVdbe; |
| 138525 | 139337 | int i; |
| 138526 | 139338 | struct AggInfo_func *pF; |
| 138527 | 139339 | for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){ |
| 138528 | | - ExprList *pList = pF->pFExpr->x.pList; |
| 138529 | | - assert( !ExprHasProperty(pF->pFExpr, EP_xIsSelect) ); |
| 139340 | + ExprList *pList; |
| 139341 | + assert( ExprUseXList(pF->pFExpr) ); |
| 139342 | + pList = pF->pFExpr->x.pList; |
| 138530 | 139343 | sqlite3VdbeAddOp2(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0); |
| 138531 | 139344 | sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF); |
| 138532 | 139345 | } |
| 138533 | 139346 | } |
| 138534 | 139347 | |
| | @@ -138558,13 +139371,14 @@ |
| 138558 | 139371 | pAggInfo->directMode = 1; |
| 138559 | 139372 | for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){ |
| 138560 | 139373 | int nArg; |
| 138561 | 139374 | int addrNext = 0; |
| 138562 | 139375 | int regAgg; |
| 138563 | | - ExprList *pList = pF->pFExpr->x.pList; |
| 138564 | | - assert( !ExprHasProperty(pF->pFExpr, EP_xIsSelect) ); |
| 139376 | + ExprList *pList; |
| 139377 | + assert( ExprUseXList(pF->pFExpr) ); |
| 138565 | 139378 | assert( !IsWindowFunc(pF->pFExpr) ); |
| 139379 | + pList = pF->pFExpr->x.pList; |
| 138566 | 139380 | if( ExprHasProperty(pF->pFExpr, EP_WinFunc) ){ |
| 138567 | 139381 | Expr *pFilter = pF->pFExpr->y.pWin->pFilter; |
| 138568 | 139382 | if( pAggInfo->nAccumulator |
| 138569 | 139383 | && (pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL) |
| 138570 | 139384 | && regAcc |
| | @@ -138806,11 +139620,13 @@ |
| 138806 | 139620 | if( p->pEList->nExpr!=1 ) return 0; /* Single result column */ |
| 138807 | 139621 | if( p->pWhere ) return 0; |
| 138808 | 139622 | if( p->pGroupBy ) return 0; |
| 138809 | 139623 | pExpr = p->pEList->a[0].pExpr; |
| 138810 | 139624 | if( pExpr->op!=TK_AGG_FUNCTION ) return 0; /* Result is an aggregate */ |
| 139625 | + assert( ExprUseUToken(pExpr) ); |
| 138811 | 139626 | if( sqlite3_stricmp(pExpr->u.zToken,"count") ) return 0; /* Is count() */ |
| 139627 | + assert( ExprUseXList(pExpr) ); |
| 138812 | 139628 | if( pExpr->x.pList!=0 ) return 0; /* Must be count(*) */ |
| 138813 | 139629 | if( p->pSrc->nSrc!=1 ) return 0; /* One table in FROM */ |
| 138814 | 139630 | pSub = p->pSrc->a[0].pSelect; |
| 138815 | 139631 | if( pSub==0 ) return 0; /* The FROM is a subquery */ |
| 138816 | 139632 | if( pSub->pPrior==0 ) return 0; /* Must be a compound ry */ |
| | @@ -139621,11 +140437,11 @@ |
| 139621 | 140437 | }else{ |
| 139622 | 140438 | minMaxFlag = WHERE_ORDERBY_NORMAL; |
| 139623 | 140439 | } |
| 139624 | 140440 | for(i=0; i<pAggInfo->nFunc; i++){ |
| 139625 | 140441 | Expr *pExpr = pAggInfo->aFunc[i].pFExpr; |
| 139626 | | - assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 140442 | + assert( ExprUseXList(pExpr) ); |
| 139627 | 140443 | sNC.ncFlags |= NC_InAggFunc; |
| 139628 | 140444 | sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList); |
| 139629 | 140445 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 139630 | 140446 | assert( !IsWindowFunc(pExpr) ); |
| 139631 | 140447 | if( ExprHasProperty(pExpr, EP_WinFunc) ){ |
| | @@ -139676,11 +140492,13 @@ |
| 139676 | 140492 | u16 distFlag = 0; |
| 139677 | 140493 | int eDist = WHERE_DISTINCT_NOOP; |
| 139678 | 140494 | |
| 139679 | 140495 | if( pAggInfo->nFunc==1 |
| 139680 | 140496 | && pAggInfo->aFunc[0].iDistinct>=0 |
| 139681 | | - && pAggInfo->aFunc[0].pFExpr->x.pList |
| 140497 | + && ALWAYS(pAggInfo->aFunc[0].pFExpr!=0) |
| 140498 | + && ALWAYS(ExprUseXList(pAggInfo->aFunc[0].pFExpr)) |
| 140499 | + && pAggInfo->aFunc[0].pFExpr->x.pList!=0 |
| 139682 | 140500 | ){ |
| 139683 | 140501 | Expr *pExpr = pAggInfo->aFunc[0].pFExpr->x.pList->a[0].pExpr; |
| 139684 | 140502 | pExpr = sqlite3ExprDup(db, pExpr, 0); |
| 139685 | 140503 | pDistinct = sqlite3ExprListDup(db, pGroupBy, 0); |
| 139686 | 140504 | pDistinct = sqlite3ExprListAppend(pParse, pDistinct, pExpr); |
| | @@ -139997,10 +140815,11 @@ |
| 139997 | 140815 | if( i==pAggInfo->nFunc ){ |
| 139998 | 140816 | regAcc = ++pParse->nMem; |
| 139999 | 140817 | sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc); |
| 140000 | 140818 | } |
| 140001 | 140819 | }else if( pAggInfo->nFunc==1 && pAggInfo->aFunc[0].iDistinct>=0 ){ |
| 140820 | + assert( ExprUseXList(pAggInfo->aFunc[0].pFExpr) ); |
| 140002 | 140821 | pDistinct = pAggInfo->aFunc[0].pFExpr->x.pList; |
| 140003 | 140822 | distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0; |
| 140004 | 140823 | } |
| 140005 | 140824 | |
| 140006 | 140825 | /* This case runs if the aggregate has no GROUP BY clause. The |
| | @@ -140670,11 +141489,11 @@ |
| 140670 | 141489 | if( v==0 ) goto triggerfinish_cleanup; |
| 140671 | 141490 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 140672 | 141491 | z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n); |
| 140673 | 141492 | testcase( z==0 ); |
| 140674 | 141493 | sqlite3NestedParse(pParse, |
| 140675 | | - "INSERT INTO %Q." DFLT_SCHEMA_TABLE |
| 141494 | + "INSERT INTO %Q." LEGACY_SCHEMA_TABLE |
| 140676 | 141495 | " VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')", |
| 140677 | 141496 | db->aDb[iDb].zDbSName, zName, |
| 140678 | 141497 | pTrig->table, z); |
| 140679 | 141498 | sqlite3DbFree(db, z); |
| 140680 | 141499 | sqlite3ChangeCookie(pParse, iDb); |
| | @@ -140984,11 +141803,11 @@ |
| 140984 | 141803 | |
| 140985 | 141804 | /* Generate code to destroy the database record of the trigger. |
| 140986 | 141805 | */ |
| 140987 | 141806 | if( (v = sqlite3GetVdbe(pParse))!=0 ){ |
| 140988 | 141807 | sqlite3NestedParse(pParse, |
| 140989 | | - "DELETE FROM %Q." DFLT_SCHEMA_TABLE " WHERE name=%Q AND type='trigger'", |
| 141808 | + "DELETE FROM %Q." LEGACY_SCHEMA_TABLE " WHERE name=%Q AND type='trigger'", |
| 140990 | 141809 | db->aDb[iDb].zDbSName, pTrigger->zName |
| 140991 | 141810 | ); |
| 140992 | 141811 | sqlite3ChangeCookie(pParse, iDb); |
| 140993 | 141812 | sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0); |
| 140994 | 141813 | } |
| | @@ -142852,13 +143671,11 @@ |
| 142852 | 143671 | /* |
| 142853 | 143672 | ** Return the number of rows that were changed, if we are tracking |
| 142854 | 143673 | ** that information. |
| 142855 | 143674 | */ |
| 142856 | 143675 | if( regRowCount ){ |
| 142857 | | - sqlite3VdbeAddOp2(v, OP_ChngCntRow, regRowCount, 1); |
| 142858 | | - sqlite3VdbeSetNumCols(v, 1); |
| 142859 | | - sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", SQLITE_STATIC); |
| 143676 | + sqlite3CodeChangeCount(v, regRowCount, "rows updated"); |
| 142860 | 143677 | } |
| 142861 | 143678 | |
| 142862 | 143679 | update_cleanup: |
| 142863 | 143680 | sqlite3AuthContextPop(&sContext); |
| 142864 | 143681 | sqlite3DbFree(db, aXRef); /* Also frees aRegIdx[] and aToOpen[] */ |
| | @@ -143637,11 +144454,13 @@ |
| 143637 | 144454 | rc = sqlite3BtreeBeginTrans(pMain, pOut==0 ? 2 : 0, 0); |
| 143638 | 144455 | if( rc!=SQLITE_OK ) goto end_of_vacuum; |
| 143639 | 144456 | |
| 143640 | 144457 | /* Do not attempt to change the page size for a WAL database */ |
| 143641 | 144458 | if( sqlite3PagerGetJournalMode(sqlite3BtreePager(pMain)) |
| 143642 | | - ==PAGER_JOURNALMODE_WAL ){ |
| 144459 | + ==PAGER_JOURNALMODE_WAL |
| 144460 | + && pOut==0 |
| 144461 | + ){ |
| 143643 | 144462 | db->nextPagesize = 0; |
| 143644 | 144463 | } |
| 143645 | 144464 | |
| 143646 | 144465 | if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes, 0) |
| 143647 | 144466 | || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0)) |
| | @@ -144022,11 +144841,14 @@ |
| 144022 | 144841 | ** Except, if argument db is not NULL, then the entry associated with |
| 144023 | 144842 | ** connection db is left in the p->u.vtab.p list. |
| 144024 | 144843 | */ |
| 144025 | 144844 | static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){ |
| 144026 | 144845 | VTable *pRet = 0; |
| 144027 | | - VTable *pVTable = p->u.vtab.p; |
| 144846 | + VTable *pVTable; |
| 144847 | + |
| 144848 | + assert( IsVirtual(p) ); |
| 144849 | + pVTable = p->u.vtab.p; |
| 144028 | 144850 | p->u.vtab.p = 0; |
| 144029 | 144851 | |
| 144030 | 144852 | /* Assert that the mutex (if any) associated with the BtShared database |
| 144031 | 144853 | ** that contains table p is held by the caller. See header comments |
| 144032 | 144854 | ** above function sqlite3VtabUnlockList() for an explanation of why |
| | @@ -144130,10 +144952,11 @@ |
| 144130 | 144952 | ** structure being xDisconnected and free). Any other VTable structures |
| 144131 | 144953 | ** in the list are moved to the sqlite3.pDisconnect list of the associated |
| 144132 | 144954 | ** database connection. |
| 144133 | 144955 | */ |
| 144134 | 144956 | SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){ |
| 144957 | + assert( IsVirtual(p) ); |
| 144135 | 144958 | if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p); |
| 144136 | 144959 | if( p->u.vtab.azArg ){ |
| 144137 | 144960 | int i; |
| 144138 | 144961 | for(i=0; i<p->u.vtab.nArg; i++){ |
| 144139 | 144962 | if( i!=1 ) sqlite3DbFree(db, p->u.vtab.azArg[i]); |
| | @@ -144147,13 +144970,16 @@ |
| 144147 | 144970 | ** The string is not copied - the pointer is stored. The |
| 144148 | 144971 | ** string will be freed automatically when the table is |
| 144149 | 144972 | ** deleted. |
| 144150 | 144973 | */ |
| 144151 | 144974 | static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){ |
| 144152 | | - sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->u.vtab.nArg); |
| 144975 | + sqlite3_int64 nBytes; |
| 144153 | 144976 | char **azModuleArg; |
| 144154 | 144977 | sqlite3 *db = pParse->db; |
| 144978 | + |
| 144979 | + assert( IsVirtual(pTable) ); |
| 144980 | + nBytes = sizeof(char *)*(2+pTable->u.vtab.nArg); |
| 144155 | 144981 | if( pTable->u.vtab.nArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){ |
| 144156 | 144982 | sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName); |
| 144157 | 144983 | } |
| 144158 | 144984 | azModuleArg = sqlite3DbRealloc(db, pTable->u.vtab.azArg, nBytes); |
| 144159 | 144985 | if( azModuleArg==0 ){ |
| | @@ -144236,10 +145062,11 @@ |
| 144236 | 145062 | SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){ |
| 144237 | 145063 | Table *pTab = pParse->pNewTable; /* The table being constructed */ |
| 144238 | 145064 | sqlite3 *db = pParse->db; /* The database connection */ |
| 144239 | 145065 | |
| 144240 | 145066 | if( pTab==0 ) return; |
| 145067 | + assert( IsVirtual(pTab) ); |
| 144241 | 145068 | addArgumentToVtab(pParse); |
| 144242 | 145069 | pParse->sArg.z = 0; |
| 144243 | 145070 | if( pTab->u.vtab.nArg<1 ) return; |
| 144244 | 145071 | |
| 144245 | 145072 | /* If the CREATE VIRTUAL TABLE statement is being entered for the |
| | @@ -144271,11 +145098,11 @@ |
| 144271 | 145098 | ** entry in the sqlite_schema table tht was created for this vtab |
| 144272 | 145099 | ** by sqlite3StartTable(). |
| 144273 | 145100 | */ |
| 144274 | 145101 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 144275 | 145102 | sqlite3NestedParse(pParse, |
| 144276 | | - "UPDATE %Q." DFLT_SCHEMA_TABLE " " |
| 145103 | + "UPDATE %Q." LEGACY_SCHEMA_TABLE " " |
| 144277 | 145104 | "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q " |
| 144278 | 145105 | "WHERE rowid=#%d", |
| 144279 | 145106 | db->aDb[iDb].zDbSName, |
| 144280 | 145107 | pTab->zName, |
| 144281 | 145108 | pTab->zName, |
| | @@ -144291,22 +145118,18 @@ |
| 144291 | 145118 | sqlite3DbFree(db, zStmt); |
| 144292 | 145119 | |
| 144293 | 145120 | iReg = ++pParse->nMem; |
| 144294 | 145121 | sqlite3VdbeLoadString(v, iReg, pTab->zName); |
| 144295 | 145122 | sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg); |
| 144296 | | - } |
| 144297 | | - |
| 144298 | | - /* If we are rereading the sqlite_schema table create the in-memory |
| 144299 | | - ** record of the table. The xConnect() method is not called until |
| 144300 | | - ** the first time the virtual table is used in an SQL statement. This |
| 144301 | | - ** allows a schema that contains virtual tables to be loaded before |
| 144302 | | - ** the required virtual table implementations are registered. */ |
| 144303 | | - else { |
| 145123 | + }else{ |
| 145124 | + /* If we are rereading the sqlite_schema table create the in-memory |
| 145125 | + ** record of the table. */ |
| 144304 | 145126 | Table *pOld; |
| 144305 | 145127 | Schema *pSchema = pTab->pSchema; |
| 144306 | 145128 | const char *zName = pTab->zName; |
| 144307 | | - assert( sqlite3SchemaMutexHeld(db, 0, pSchema) ); |
| 145129 | + assert( zName!=0 ); |
| 145130 | + sqlite3MarkAllShadowTablesOf(db, pTab); |
| 144308 | 145131 | pOld = sqlite3HashInsert(&pSchema->tblHash, zName, pTab); |
| 144309 | 145132 | if( pOld ){ |
| 144310 | 145133 | sqlite3OomFault(db); |
| 144311 | 145134 | assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */ |
| 144312 | 145135 | return; |
| | @@ -144353,17 +145176,20 @@ |
| 144353 | 145176 | char **pzErr |
| 144354 | 145177 | ){ |
| 144355 | 145178 | VtabCtx sCtx; |
| 144356 | 145179 | VTable *pVTable; |
| 144357 | 145180 | int rc; |
| 144358 | | - const char *const*azArg = (const char *const*)pTab->u.vtab.azArg; |
| 145181 | + const char *const*azArg; |
| 144359 | 145182 | int nArg = pTab->u.vtab.nArg; |
| 144360 | 145183 | char *zErr = 0; |
| 144361 | 145184 | char *zModuleName; |
| 144362 | 145185 | int iDb; |
| 144363 | 145186 | VtabCtx *pCtx; |
| 144364 | 145187 | |
| 145188 | + assert( IsVirtual(pTab) ); |
| 145189 | + azArg = (const char *const*)pTab->u.vtab.azArg; |
| 145190 | + |
| 144365 | 145191 | /* Check that the virtual-table is not already being initialized */ |
| 144366 | 145192 | for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){ |
| 144367 | 145193 | if( pCtx->pTab==pTab ){ |
| 144368 | 145194 | *pzErr = sqlite3MPrintf(db, |
| 144369 | 145195 | "vtable constructor called recursively: %s", pTab->zName |
| | @@ -144483,11 +145309,12 @@ |
| 144483 | 145309 | const char *zMod; |
| 144484 | 145310 | Module *pMod; |
| 144485 | 145311 | int rc; |
| 144486 | 145312 | |
| 144487 | 145313 | assert( pTab ); |
| 144488 | | - if( !IsVirtual(pTab) || sqlite3GetVTable(db, pTab) ){ |
| 145314 | + assert( IsVirtual(pTab) ); |
| 145315 | + if( sqlite3GetVTable(db, pTab) ){ |
| 144489 | 145316 | return SQLITE_OK; |
| 144490 | 145317 | } |
| 144491 | 145318 | |
| 144492 | 145319 | /* Locate the required virtual table module */ |
| 144493 | 145320 | zMod = pTab->u.vtab.azArg[0]; |
| | @@ -144687,11 +145514,14 @@ |
| 144687 | 145514 | SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){ |
| 144688 | 145515 | int rc = SQLITE_OK; |
| 144689 | 145516 | Table *pTab; |
| 144690 | 145517 | |
| 144691 | 145518 | pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName); |
| 144692 | | - if( pTab!=0 && ALWAYS(pTab->u.vtab.p!=0) ){ |
| 145519 | + if( ALWAYS(pTab!=0) |
| 145520 | + && ALWAYS(IsVirtual(pTab)) |
| 145521 | + && ALWAYS(pTab->u.vtab.p!=0) |
| 145522 | + ){ |
| 144693 | 145523 | VTable *p; |
| 144694 | 145524 | int (*xDestroy)(sqlite3_vtab *); |
| 144695 | 145525 | for(p=pTab->u.vtab.p; p; p=p->pNext){ |
| 144696 | 145526 | assert( p->pVtab ); |
| 144697 | 145527 | if( p->pVtab->nRef>0 ){ |
| | @@ -144920,10 +145750,11 @@ |
| 144920 | 145750 | int rc = 0; |
| 144921 | 145751 | |
| 144922 | 145752 | /* Check to see the left operand is a column in a virtual table */ |
| 144923 | 145753 | if( NEVER(pExpr==0) ) return pDef; |
| 144924 | 145754 | if( pExpr->op!=TK_COLUMN ) return pDef; |
| 145755 | + assert( ExprUseYTab(pExpr) ); |
| 144925 | 145756 | pTab = pExpr->y.pTab; |
| 144926 | 145757 | if( pTab==0 ) return pDef; |
| 144927 | 145758 | if( !IsVirtual(pTab) ) return pDef; |
| 144928 | 145759 | pVtab = sqlite3GetVTable(db, pTab)->pVtab; |
| 144929 | 145760 | assert( pVtab!=0 ); |
| | @@ -145214,10 +146045,11 @@ |
| 145214 | 146045 | int addrBignull; /* Jump here for next part of big-null scan */ |
| 145215 | 146046 | #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS |
| 145216 | 146047 | u32 iLikeRepCntr; /* LIKE range processing counter register (times 2) */ |
| 145217 | 146048 | int addrLikeRep; /* LIKE range processing address */ |
| 145218 | 146049 | #endif |
| 146050 | + int regFilter; /* Bloom filter */ |
| 145219 | 146051 | u8 iFrom; /* Which entry in the FROM clause */ |
| 145220 | 146052 | u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */ |
| 145221 | 146053 | int p1, p2; /* Operands of the opcode used to end the loop */ |
| 145222 | 146054 | union { /* Information that depends on pWLoop->wsFlags */ |
| 145223 | 146055 | struct { |
| | @@ -145228,11 +146060,11 @@ |
| 145228 | 146060 | int iBase; /* Base register of multi-key index record */ |
| 145229 | 146061 | int nPrefix; /* Number of prior entires in the key */ |
| 145230 | 146062 | u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */ |
| 145231 | 146063 | } *aInLoop; /* Information about each nested IN operator */ |
| 145232 | 146064 | } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */ |
| 145233 | | - Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */ |
| 146065 | + Index *pCoveringIdx; /* Possible covering index for WHERE_MULTI_OR */ |
| 145234 | 146066 | } u; |
| 145235 | 146067 | struct WhereLoop *pWLoop; /* The selected WhereLoop object */ |
| 145236 | 146068 | Bitmask notReady; /* FROM entries not usable at this level */ |
| 145237 | 146069 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 145238 | 146070 | int addrVisit; /* Address at which row is visited */ |
| | @@ -145442,15 +146274,15 @@ |
| 145442 | 146274 | struct WhereScan { |
| 145443 | 146275 | WhereClause *pOrigWC; /* Original, innermost WhereClause */ |
| 145444 | 146276 | WhereClause *pWC; /* WhereClause currently being scanned */ |
| 145445 | 146277 | const char *zCollName; /* Required collating sequence, if not NULL */ |
| 145446 | 146278 | Expr *pIdxExpr; /* Search for this index expression */ |
| 145447 | | - char idxaff; /* Must match this affinity, if zCollName!=NULL */ |
| 145448 | | - unsigned char nEquiv; /* Number of entries in aiCur[] and aiColumn[] */ |
| 145449 | | - unsigned char iEquiv; /* Next unused slot in aiCur[] and aiColumn[] */ |
| 146279 | + int k; /* Resume scanning at this->pWC->a[this->k] */ |
| 145450 | 146280 | u32 opMask; /* Acceptable operators */ |
| 145451 | | - int k; /* Resume scanning at this->pWC->a[this->k] */ |
| 146281 | + char idxaff; /* Must match this affinity, if zCollName!=NULL */ |
| 146282 | + unsigned char iEquiv; /* Current slot in aiCur[] and aiColumn[] */ |
| 146283 | + unsigned char nEquiv; /* Number of entries in aiCur[] and aiColumn[] */ |
| 145452 | 146284 | int aiCur[11]; /* Cursors in the equivalence class */ |
| 145453 | 146285 | i16 aiColumn[11]; /* Corresponding column number in the eq-class */ |
| 145454 | 146286 | }; |
| 145455 | 146287 | |
| 145456 | 146288 | /* |
| | @@ -145470,10 +146302,11 @@ |
| 145470 | 146302 | WhereClause *pOuter; /* Outer conjunction */ |
| 145471 | 146303 | u8 op; /* Split operator. TK_AND or TK_OR */ |
| 145472 | 146304 | u8 hasOr; /* True if any a[].eOperator is WO_OR */ |
| 145473 | 146305 | int nTerm; /* Number of terms */ |
| 145474 | 146306 | int nSlot; /* Number of entries in a[] */ |
| 146307 | + int nBase; /* Number of terms through the last non-Virtual */ |
| 145475 | 146308 | WhereTerm *a; /* Each a[] describes a term of the WHERE cluase */ |
| 145476 | 146309 | #if defined(SQLITE_SMALL_STACK) |
| 145477 | 146310 | WhereTerm aStatic[1]; /* Initial static space for a[] */ |
| 145478 | 146311 | #else |
| 145479 | 146312 | WhereTerm aStatic[8]; /* Initial static space for a[] */ |
| | @@ -145527,15 +146360,10 @@ |
| 145527 | 146360 | int bVarSelect; /* Used by sqlite3WhereExprUsage() */ |
| 145528 | 146361 | int n; /* Number of assigned cursor values */ |
| 145529 | 146362 | int ix[BMS]; /* Cursor assigned to each bit */ |
| 145530 | 146363 | }; |
| 145531 | 146364 | |
| 145532 | | -/* |
| 145533 | | -** Initialize a WhereMaskSet object |
| 145534 | | -*/ |
| 145535 | | -#define initMaskSet(P) (P)->n=0 |
| 145536 | | - |
| 145537 | 146365 | /* |
| 145538 | 146366 | ** This object is a convenience wrapper holding all information needed |
| 145539 | 146367 | ** to construct WhereLoop objects for a particular query. |
| 145540 | 146368 | */ |
| 145541 | 146369 | struct WhereLoopBuilder { |
| | @@ -145660,12 +146488,18 @@ |
| 145660 | 146488 | Parse *pParse, /* Parse context */ |
| 145661 | 146489 | SrcList *pTabList, /* Table list this loop refers to */ |
| 145662 | 146490 | WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */ |
| 145663 | 146491 | u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */ |
| 145664 | 146492 | ); |
| 146493 | +SQLITE_PRIVATE int sqlite3WhereExplainBloomFilter( |
| 146494 | + const Parse *pParse, /* Parse context */ |
| 146495 | + const WhereInfo *pWInfo, /* WHERE clause */ |
| 146496 | + const WhereLevel *pLevel /* Bloom filter on this level */ |
| 146497 | +); |
| 145665 | 146498 | #else |
| 145666 | 146499 | # define sqlite3WhereExplainOneScan(u,v,w,x) 0 |
| 146500 | +# define sqlite3WhereExplainBloomFilter(u,v,w) 0 |
| 145667 | 146501 | #endif /* SQLITE_OMIT_EXPLAIN */ |
| 145668 | 146502 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 145669 | 146503 | SQLITE_PRIVATE void sqlite3WhereAddScanStatus( |
| 145670 | 146504 | Vdbe *v, /* Vdbe to add scanstatus entry to */ |
| 145671 | 146505 | SrcList *pSrclist, /* FROM clause pLvl reads data from */ |
| | @@ -145754,10 +146588,12 @@ |
| 145754 | 146588 | #define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */ |
| 145755 | 146589 | #define WHERE_IN_EARLYOUT 0x00040000 /* Perhaps quit IN loops early */ |
| 145756 | 146590 | #define WHERE_BIGNULL_SORT 0x00080000 /* Column nEq of index is BIGNULL */ |
| 145757 | 146591 | #define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */ |
| 145758 | 146592 | #define WHERE_TRANSCONS 0x00200000 /* Uses a transitive constraint */ |
| 146593 | +#define WHERE_BLOOMFILTER 0x00400000 /* Consider using a Bloom-filter */ |
| 146594 | +#define WHERE_SELFCULL 0x00800000 /* nOut reduced by extra WHERE terms */ |
| 145759 | 146595 | |
| 145760 | 146596 | #endif /* !defined(SQLITE_WHEREINT_H) */ |
| 145761 | 146597 | |
| 145762 | 146598 | /************** End of whereInt.h ********************************************/ |
| 145763 | 146599 | /************** Continuing where we left off in wherecode.c ******************/ |
| | @@ -145916,23 +146752,31 @@ |
| 145916 | 146752 | sqlite3_str_append(&str, " USING ", 7); |
| 145917 | 146753 | sqlite3_str_appendf(&str, zFmt, pIdx->zName); |
| 145918 | 146754 | explainIndexRange(&str, pLoop); |
| 145919 | 146755 | } |
| 145920 | 146756 | }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){ |
| 145921 | | - const char *zRangeOp; |
| 146757 | + char cRangeOp; |
| 146758 | +#if 0 /* Better output, but breaks many tests */ |
| 146759 | + const Table *pTab = pItem->pTab; |
| 146760 | + const char *zRowid = pTab->iPKey>=0 ? pTab->aCol[pTab->iPKey].zCnName: |
| 146761 | + "rowid"; |
| 146762 | +#else |
| 146763 | + const char *zRowid = "rowid"; |
| 146764 | +#endif |
| 146765 | + sqlite3_str_appendf(&str, " USING INTEGER PRIMARY KEY (%s", zRowid); |
| 145922 | 146766 | if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){ |
| 145923 | | - zRangeOp = "="; |
| 146767 | + cRangeOp = '='; |
| 145924 | 146768 | }else if( (flags&WHERE_BOTH_LIMIT)==WHERE_BOTH_LIMIT ){ |
| 145925 | | - zRangeOp = ">? AND rowid<"; |
| 146769 | + sqlite3_str_appendf(&str, ">? AND %s", zRowid); |
| 146770 | + cRangeOp = '<'; |
| 145926 | 146771 | }else if( flags&WHERE_BTM_LIMIT ){ |
| 145927 | | - zRangeOp = ">"; |
| 146772 | + cRangeOp = '>'; |
| 145928 | 146773 | }else{ |
| 145929 | 146774 | assert( flags&WHERE_TOP_LIMIT); |
| 145930 | | - zRangeOp = "<"; |
| 146775 | + cRangeOp = '<'; |
| 145931 | 146776 | } |
| 145932 | | - sqlite3_str_appendf(&str, |
| 145933 | | - " USING INTEGER PRIMARY KEY (rowid%s?)",zRangeOp); |
| 146777 | + sqlite3_str_appendf(&str, "%c?)", cRangeOp); |
| 145934 | 146778 | } |
| 145935 | 146779 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 145936 | 146780 | else if( (flags & WHERE_VIRTUALTABLE)!=0 ){ |
| 145937 | 146781 | sqlite3_str_appendf(&str, " VIRTUAL TABLE INDEX %d:%s", |
| 145938 | 146782 | pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr); |
| | @@ -145951,10 +146795,60 @@ |
| 145951 | 146795 | ret = sqlite3VdbeAddOp4(v, OP_Explain, sqlite3VdbeCurrentAddr(v), |
| 145952 | 146796 | pParse->addrExplain, 0, zMsg,P4_DYNAMIC); |
| 145953 | 146797 | } |
| 145954 | 146798 | return ret; |
| 145955 | 146799 | } |
| 146800 | + |
| 146801 | +/* |
| 146802 | +** Add a single OP_Explain opcode that describes a Bloom filter. |
| 146803 | +** |
| 146804 | +** Or if not processing EXPLAIN QUERY PLAN and not in a SQLITE_DEBUG and/or |
| 146805 | +** SQLITE_ENABLE_STMT_SCANSTATUS build, then OP_Explain opcodes are not |
| 146806 | +** required and this routine is a no-op. |
| 146807 | +** |
| 146808 | +** If an OP_Explain opcode is added to the VM, its address is returned. |
| 146809 | +** Otherwise, if no OP_Explain is coded, zero is returned. |
| 146810 | +*/ |
| 146811 | +SQLITE_PRIVATE int sqlite3WhereExplainBloomFilter( |
| 146812 | + const Parse *pParse, /* Parse context */ |
| 146813 | + const WhereInfo *pWInfo, /* WHERE clause */ |
| 146814 | + const WhereLevel *pLevel /* Bloom filter on this level */ |
| 146815 | +){ |
| 146816 | + int ret = 0; |
| 146817 | + SrcItem *pItem = &pWInfo->pTabList->a[pLevel->iFrom]; |
| 146818 | + Vdbe *v = pParse->pVdbe; /* VM being constructed */ |
| 146819 | + sqlite3 *db = pParse->db; /* Database handle */ |
| 146820 | + char *zMsg; /* Text to add to EQP output */ |
| 146821 | + int i; /* Loop counter */ |
| 146822 | + WhereLoop *pLoop; /* The where loop */ |
| 146823 | + StrAccum str; /* EQP output string */ |
| 146824 | + char zBuf[100]; /* Initial space for EQP output string */ |
| 146825 | + |
| 146826 | + sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH); |
| 146827 | + str.printfFlags = SQLITE_PRINTF_INTERNAL; |
| 146828 | + sqlite3_str_appendf(&str, "BLOOM FILTER ON %S (", pItem); |
| 146829 | + pLoop = pLevel->pWLoop; |
| 146830 | + if( pLoop->wsFlags & WHERE_IPK ){ |
| 146831 | + const Table *pTab = pItem->pTab; |
| 146832 | + if( pTab->iPKey>=0 ){ |
| 146833 | + sqlite3_str_appendf(&str, "%s=?", pTab->aCol[pTab->iPKey].zCnName); |
| 146834 | + }else{ |
| 146835 | + sqlite3_str_appendf(&str, "rowid=?"); |
| 146836 | + } |
| 146837 | + }else{ |
| 146838 | + for(i=pLoop->nSkip; i<pLoop->u.btree.nEq; i++){ |
| 146839 | + const char *z = explainIndexColumnName(pLoop->u.btree.pIndex, i); |
| 146840 | + if( i>pLoop->nSkip ) sqlite3_str_append(&str, " AND ", 5); |
| 146841 | + sqlite3_str_appendf(&str, "%s=?", z); |
| 146842 | + } |
| 146843 | + } |
| 146844 | + sqlite3_str_append(&str, ")", 1); |
| 146845 | + zMsg = sqlite3StrAccumFinish(&str); |
| 146846 | + ret = sqlite3VdbeAddOp4(v, OP_Explain, sqlite3VdbeCurrentAddr(v), |
| 146847 | + pParse->addrExplain, 0, zMsg,P4_DYNAMIC); |
| 146848 | + return ret; |
| 146849 | +} |
| 145956 | 146850 | #endif /* SQLITE_OMIT_EXPLAIN */ |
| 145957 | 146851 | |
| 145958 | 146852 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 145959 | 146853 | /* |
| 145960 | 146854 | ** Configure the VM passed as the first argument with an |
| | @@ -146156,20 +147050,27 @@ |
| 146156 | 147050 | ){ |
| 146157 | 147051 | sqlite3 *db = pParse->db; |
| 146158 | 147052 | Expr *pNew; |
| 146159 | 147053 | pNew = sqlite3ExprDup(db, pX, 0); |
| 146160 | 147054 | if( db->mallocFailed==0 ){ |
| 146161 | | - ExprList *pOrigRhs = pNew->x.pSelect->pEList; /* Original unmodified RHS */ |
| 146162 | | - ExprList *pOrigLhs = pNew->pLeft->x.pList; /* Original unmodified LHS */ |
| 147055 | + ExprList *pOrigRhs; /* Original unmodified RHS */ |
| 147056 | + ExprList *pOrigLhs; /* Original unmodified LHS */ |
| 146163 | 147057 | ExprList *pRhs = 0; /* New RHS after modifications */ |
| 146164 | 147058 | ExprList *pLhs = 0; /* New LHS after mods */ |
| 146165 | 147059 | int i; /* Loop counter */ |
| 146166 | 147060 | Select *pSelect; /* Pointer to the SELECT on the RHS */ |
| 146167 | 147061 | |
| 147062 | + assert( ExprUseXSelect(pNew) ); |
| 147063 | + pOrigRhs = pNew->x.pSelect->pEList; |
| 147064 | + assert( pNew->pLeft!=0 ); |
| 147065 | + assert( ExprUseXList(pNew->pLeft) ); |
| 147066 | + pOrigLhs = pNew->pLeft->x.pList; |
| 146168 | 147067 | for(i=iEq; i<pLoop->nLTerm; i++){ |
| 146169 | 147068 | if( pLoop->aLTerm[i]->pExpr==pX ){ |
| 146170 | | - int iField = pLoop->aLTerm[i]->u.x.iField - 1; |
| 147069 | + int iField; |
| 147070 | + assert( (pLoop->aLTerm[i]->eOperator & (WO_OR|WO_AND))==0 ); |
| 147071 | + iField = pLoop->aLTerm[i]->u.x.iField - 1; |
| 146171 | 147072 | if( pOrigRhs->a[iField].pExpr==0 ) continue; /* Duplicate PK column */ |
| 146172 | 147073 | pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr); |
| 146173 | 147074 | pOrigRhs->a[iField].pExpr = 0; |
| 146174 | 147075 | assert( pOrigLhs->a[iField].pExpr!=0 ); |
| 146175 | 147076 | pLhs = sqlite3ExprListAppend(pParse, pLhs, pOrigLhs->a[iField].pExpr); |
| | @@ -146280,11 +147181,11 @@ |
| 146280 | 147181 | assert( pLoop->aLTerm[i]!=0 ); |
| 146281 | 147182 | if( pLoop->aLTerm[i]->pExpr==pX ) nEq++; |
| 146282 | 147183 | } |
| 146283 | 147184 | |
| 146284 | 147185 | iTab = 0; |
| 146285 | | - if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){ |
| 147186 | + if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){ |
| 146286 | 147187 | eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab); |
| 146287 | 147188 | }else{ |
| 146288 | 147189 | sqlite3 *db = pParse->db; |
| 146289 | 147190 | pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX); |
| 146290 | 147191 | |
| | @@ -146302,12 +147203,12 @@ |
| 146302 | 147203 | bRev = !bRev; |
| 146303 | 147204 | } |
| 146304 | 147205 | sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0); |
| 146305 | 147206 | VdbeCoverageIf(v, bRev); |
| 146306 | 147207 | VdbeCoverageIf(v, !bRev); |
| 147208 | + |
| 146307 | 147209 | assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 ); |
| 146308 | | - |
| 146309 | 147210 | pLoop->wsFlags |= WHERE_IN_ABLE; |
| 146310 | 147211 | if( pLevel->u.in.nIn==0 ){ |
| 146311 | 147212 | pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse); |
| 146312 | 147213 | } |
| 146313 | 147214 | if( iEq>0 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0 ){ |
| | @@ -146703,11 +147604,11 @@ |
| 146703 | 147604 | sHint.pIdx = pLoop->u.btree.pIndex; |
| 146704 | 147605 | memset(&sWalker, 0, sizeof(sWalker)); |
| 146705 | 147606 | sWalker.pParse = pParse; |
| 146706 | 147607 | sWalker.u.pCCurHint = &sHint; |
| 146707 | 147608 | pWC = &pWInfo->sWC; |
| 146708 | | - for(i=0; i<pWC->nTerm; i++){ |
| 147609 | + for(i=0; i<pWC->nBase; i++){ |
| 146709 | 147610 | pTerm = &pWC->a[i]; |
| 146710 | 147611 | if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue; |
| 146711 | 147612 | if( pTerm->prereqAll & pLevel->notReady ) continue; |
| 146712 | 147613 | |
| 146713 | 147614 | /* Any terms specified as part of the ON(...) clause for any LEFT |
| | @@ -146845,21 +147746,23 @@ |
| 146845 | 147746 | */ |
| 146846 | 147747 | static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg){ |
| 146847 | 147748 | assert( nReg>0 ); |
| 146848 | 147749 | if( p && sqlite3ExprIsVector(p) ){ |
| 146849 | 147750 | #ifndef SQLITE_OMIT_SUBQUERY |
| 146850 | | - if( (p->flags & EP_xIsSelect) ){ |
| 147751 | + if( ExprUseXSelect(p) ){ |
| 146851 | 147752 | Vdbe *v = pParse->pVdbe; |
| 146852 | 147753 | int iSelect; |
| 146853 | 147754 | assert( p->op==TK_SELECT ); |
| 146854 | 147755 | iSelect = sqlite3CodeSubselect(pParse, p); |
| 146855 | 147756 | sqlite3VdbeAddOp3(v, OP_Copy, iSelect, iReg, nReg-1); |
| 146856 | 147757 | }else |
| 146857 | 147758 | #endif |
| 146858 | 147759 | { |
| 146859 | 147760 | int i; |
| 146860 | | - ExprList *pList = p->x.pList; |
| 147761 | + const ExprList *pList; |
| 147762 | + assert( ExprUseXList(p) ); |
| 147763 | + pList = p->x.pList; |
| 146861 | 147764 | assert( nReg<=pList->nExpr ); |
| 146862 | 147765 | for(i=0; i<nReg; i++){ |
| 146863 | 147766 | sqlite3ExprCode(pParse, pList->a[i].pExpr, iReg+i); |
| 146864 | 147767 | } |
| 146865 | 147768 | } |
| | @@ -146908,14 +147811,14 @@ |
| 146908 | 147811 | preserveExpr(pX, pExpr); |
| 146909 | 147812 | pExpr->affExpr = sqlite3ExprAffinity(pExpr); |
| 146910 | 147813 | pExpr->op = TK_COLUMN; |
| 146911 | 147814 | pExpr->iTable = pX->iIdxCur; |
| 146912 | 147815 | pExpr->iColumn = pX->iIdxCol; |
| 146913 | | - pExpr->y.pTab = 0; |
| 146914 | 147816 | testcase( ExprHasProperty(pExpr, EP_Skip) ); |
| 146915 | 147817 | testcase( ExprHasProperty(pExpr, EP_Unlikely) ); |
| 146916 | | - ExprClearProperty(pExpr, EP_Skip|EP_Unlikely); |
| 147818 | + ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn); |
| 147819 | + pExpr->y.pTab = 0; |
| 146917 | 147820 | return WRC_Prune; |
| 146918 | 147821 | }else{ |
| 146919 | 147822 | return WRC_Continue; |
| 146920 | 147823 | } |
| 146921 | 147824 | } |
| | @@ -146926,11 +147829,11 @@ |
| 146926 | 147829 | */ |
| 146927 | 147830 | static int whereIndexExprTransColumn(Walker *p, Expr *pExpr){ |
| 146928 | 147831 | if( pExpr->op==TK_COLUMN ){ |
| 146929 | 147832 | IdxExprTrans *pX = p->u.pIdxTrans; |
| 146930 | 147833 | if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){ |
| 146931 | | - assert( pExpr->y.pTab!=0 ); |
| 147834 | + assert( ExprUseYTab(pExpr) && pExpr->y.pTab!=0 ); |
| 146932 | 147835 | preserveExpr(pX, pExpr); |
| 146933 | 147836 | pExpr->affExpr = sqlite3TableColumnAffinity(pExpr->y.pTab,pExpr->iColumn); |
| 146934 | 147837 | pExpr->iTable = pX->iIdxCur; |
| 146935 | 147838 | pExpr->iColumn = pX->iIdxCol; |
| 146936 | 147839 | pExpr->y.pTab = 0; |
| | @@ -146974,11 +147877,11 @@ |
| 146974 | 147877 | x.pWInfo = pWInfo; |
| 146975 | 147878 | x.db = pWInfo->pParse->db; |
| 146976 | 147879 | for(iIdxCol=0; iIdxCol<pIdx->nColumn; iIdxCol++){ |
| 146977 | 147880 | i16 iRef = pIdx->aiColumn[iIdxCol]; |
| 146978 | 147881 | if( iRef==XN_EXPR ){ |
| 146979 | | - assert( aColExpr->a[iIdxCol].pExpr!=0 ); |
| 147882 | + assert( aColExpr!=0 && aColExpr->a[iIdxCol].pExpr!=0 ); |
| 146980 | 147883 | x.pIdxExpr = aColExpr->a[iIdxCol].pExpr; |
| 146981 | 147884 | if( sqlite3ExprIsConstant(x.pIdxExpr) ) continue; |
| 146982 | 147885 | w.xExprCallback = whereIndexExprTransNode; |
| 146983 | 147886 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 146984 | 147887 | }else if( iRef>=0 |
| | @@ -147031,10 +147934,67 @@ |
| 147031 | 147934 | if( sqlite3ExprCompare(0, pExpr, pTruth, iTabCur)==0 ){ |
| 147032 | 147935 | pTerm->wtFlags |= TERM_CODED; |
| 147033 | 147936 | } |
| 147034 | 147937 | } |
| 147035 | 147938 | } |
| 147939 | + |
| 147940 | +/* |
| 147941 | +** This routine is called right after An OP_Filter has been generated and |
| 147942 | +** before the corresponding index search has been performed. This routine |
| 147943 | +** checks to see if there are additional Bloom filters in inner loops that |
| 147944 | +** can be checked prior to doing the index lookup. If there are available |
| 147945 | +** inner-loop Bloom filters, then evaluate those filters now, before the |
| 147946 | +** index lookup. The idea is that a Bloom filter check is way faster than |
| 147947 | +** an index lookup, and the Bloom filter might return false, meaning that |
| 147948 | +** the index lookup can be skipped. |
| 147949 | +** |
| 147950 | +** We know that an inner loop uses a Bloom filter because it has the |
| 147951 | +** WhereLevel.regFilter set. If an inner-loop Bloom filter is checked, |
| 147952 | +** then clear the WhereLevel.regFilter value to prevent the Bloom filter |
| 147953 | +** from being checked a second time when the inner loop is evaluated. |
| 147954 | +*/ |
| 147955 | +static SQLITE_NOINLINE void filterPullDown( |
| 147956 | + Parse *pParse, /* Parsing context */ |
| 147957 | + WhereInfo *pWInfo, /* Complete information about the WHERE clause */ |
| 147958 | + int iLevel, /* Which level of pWInfo->a[] should be coded */ |
| 147959 | + int addrNxt, /* Jump here to bypass inner loops */ |
| 147960 | + Bitmask notReady /* Loops that are not ready */ |
| 147961 | +){ |
| 147962 | + while( ++iLevel < pWInfo->nLevel ){ |
| 147963 | + WhereLevel *pLevel = &pWInfo->a[iLevel]; |
| 147964 | + WhereLoop *pLoop = pLevel->pWLoop; |
| 147965 | + if( pLevel->regFilter==0 ) continue; |
| 147966 | + /* ,--- Because constructBloomFilter() has will not have set |
| 147967 | + ** vvvvv--' pLevel->regFilter if this were true. */ |
| 147968 | + if( NEVER(pLoop->prereq & notReady) ) continue; |
| 147969 | + if( pLoop->wsFlags & WHERE_IPK ){ |
| 147970 | + WhereTerm *pTerm = pLoop->aLTerm[0]; |
| 147971 | + int regRowid; |
| 147972 | + assert( pTerm!=0 ); |
| 147973 | + assert( pTerm->pExpr!=0 ); |
| 147974 | + testcase( pTerm->wtFlags & TERM_VIRTUAL ); |
| 147975 | + regRowid = sqlite3GetTempReg(pParse); |
| 147976 | + regRowid = codeEqualityTerm(pParse, pTerm, pLevel, 0, 0, regRowid); |
| 147977 | + sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter, |
| 147978 | + addrNxt, regRowid, 1); |
| 147979 | + VdbeCoverage(pParse->pVdbe); |
| 147980 | + }else{ |
| 147981 | + u16 nEq = pLoop->u.btree.nEq; |
| 147982 | + int r1; |
| 147983 | + char *zStartAff; |
| 147984 | + |
| 147985 | + assert( pLoop->wsFlags & WHERE_INDEXED ); |
| 147986 | + r1 = codeAllEqualityTerms(pParse,pLevel,0,0,&zStartAff); |
| 147987 | + codeApplyAffinity(pParse, r1, nEq, zStartAff); |
| 147988 | + sqlite3DbFree(pParse->db, zStartAff); |
| 147989 | + sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter, |
| 147990 | + addrNxt, r1, nEq); |
| 147991 | + VdbeCoverage(pParse->pVdbe); |
| 147992 | + } |
| 147993 | + pLevel->regFilter = 0; |
| 147994 | + } |
| 147995 | +} |
| 147036 | 147996 | |
| 147037 | 147997 | /* |
| 147038 | 147998 | ** Generate code for the start of the iLevel-th loop in the WHERE clause |
| 147039 | 147999 | ** implementation described by pWInfo. |
| 147040 | 148000 | */ |
| | @@ -147163,11 +148123,16 @@ |
| 147163 | 148123 | ** the u.vtab.idxStr. NULL it out to prevent a use-after-free */ |
| 147164 | 148124 | if( db->mallocFailed ) pLoop->u.vtab.idxStr = 0; |
| 147165 | 148125 | pLevel->p1 = iCur; |
| 147166 | 148126 | pLevel->op = pWInfo->eOnePass ? OP_Noop : OP_VNext; |
| 147167 | 148127 | pLevel->p2 = sqlite3VdbeCurrentAddr(v); |
| 147168 | | - iIn = pLevel->u.in.nIn; |
| 148128 | + assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 ); |
| 148129 | + if( pLoop->wsFlags & WHERE_IN_ABLE ){ |
| 148130 | + iIn = pLevel->u.in.nIn; |
| 148131 | + }else{ |
| 148132 | + iIn = 0; |
| 148133 | + } |
| 147169 | 148134 | for(j=nConstraint-1; j>=0; j--){ |
| 147170 | 148135 | pTerm = pLoop->aLTerm[j]; |
| 147171 | 148136 | if( (pTerm->eOperator & WO_IN)!=0 ) iIn--; |
| 147172 | 148137 | if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){ |
| 147173 | 148138 | disableTerm(pLevel, pTerm); |
| | @@ -147237,10 +148202,16 @@ |
| 147237 | 148202 | testcase( pTerm->wtFlags & TERM_VIRTUAL ); |
| 147238 | 148203 | iReleaseReg = ++pParse->nMem; |
| 147239 | 148204 | iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg); |
| 147240 | 148205 | if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg); |
| 147241 | 148206 | addrNxt = pLevel->addrNxt; |
| 148207 | + if( pLevel->regFilter ){ |
| 148208 | + sqlite3VdbeAddOp4Int(v, OP_Filter, pLevel->regFilter, addrNxt, |
| 148209 | + iRowidReg, 1); |
| 148210 | + VdbeCoverage(v); |
| 148211 | + filterPullDown(pParse, pWInfo, iLevel, addrNxt, notReady); |
| 148212 | + } |
| 147242 | 148213 | sqlite3VdbeAddOp3(v, OP_SeekRowid, iCur, addrNxt, iRowidReg); |
| 147243 | 148214 | VdbeCoverage(v); |
| 147244 | 148215 | pLevel->op = OP_Noop; |
| 147245 | 148216 | }else if( (pLoop->wsFlags & WHERE_IPK)!=0 |
| 147246 | 148217 | && (pLoop->wsFlags & WHERE_COLUMN_RANGE)!=0 |
| | @@ -147562,10 +148533,16 @@ |
| 147562 | 148533 | }else{ |
| 147563 | 148534 | if( regBignull ){ |
| 147564 | 148535 | sqlite3VdbeAddOp2(v, OP_Integer, 1, regBignull); |
| 147565 | 148536 | VdbeComment((v, "NULL-scan pass ctr")); |
| 147566 | 148537 | } |
| 148538 | + if( pLevel->regFilter ){ |
| 148539 | + sqlite3VdbeAddOp4Int(v, OP_Filter, pLevel->regFilter, addrNxt, |
| 148540 | + regBase, nEq); |
| 148541 | + VdbeCoverage(v); |
| 148542 | + filterPullDown(pParse, pWInfo, iLevel, addrNxt, notReady); |
| 148543 | + } |
| 147567 | 148544 | |
| 147568 | 148545 | op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev]; |
| 147569 | 148546 | assert( op!=0 ); |
| 147570 | 148547 | if( (pLoop->wsFlags & WHERE_IN_SEEKSCAN)!=0 && op==OP_SeekGE ){ |
| 147571 | 148548 | assert( regBignull==0 ); |
| | @@ -147610,12 +148587,23 @@ |
| 147610 | 148587 | |
| 147611 | 148588 | /* Load the value for the inequality constraint at the end of the |
| 147612 | 148589 | ** range (if any). |
| 147613 | 148590 | */ |
| 147614 | 148591 | nConstraint = nEq; |
| 148592 | + assert( pLevel->p2==0 ); |
| 147615 | 148593 | if( pRangeEnd ){ |
| 147616 | 148594 | Expr *pRight = pRangeEnd->pExpr->pRight; |
| 148595 | + if( addrSeekScan ){ |
| 148596 | + /* For a seek-scan that has a range on the lowest term of the index, |
| 148597 | + ** we have to make the top of the loop be code that sets the end |
| 148598 | + ** condition of the range. Otherwise, the OP_SeekScan might jump |
| 148599 | + ** over that initialization, leaving the range-end value set to the |
| 148600 | + ** range-start value, resulting in a wrong answer. |
| 148601 | + ** See ticket 5981a8c041a3c2f3 (2021-11-02). |
| 148602 | + */ |
| 148603 | + pLevel->p2 = sqlite3VdbeCurrentAddr(v); |
| 148604 | + } |
| 147617 | 148605 | codeExprOrVector(pParse, pRight, regBase+nEq, nTop); |
| 147618 | 148606 | whereLikeOptimizationStringFixup(v, pLevel, pRangeEnd); |
| 147619 | 148607 | if( (pRangeEnd->wtFlags & TERM_VNULL)==0 |
| 147620 | 148608 | && sqlite3ExprCanBeNull(pRight) |
| 147621 | 148609 | ){ |
| | @@ -147645,11 +148633,11 @@ |
| 147645 | 148633 | } |
| 147646 | 148634 | sqlite3DbFree(db, zStartAff); |
| 147647 | 148635 | sqlite3DbFree(db, zEndAff); |
| 147648 | 148636 | |
| 147649 | 148637 | /* Top of the loop body */ |
| 147650 | | - pLevel->p2 = sqlite3VdbeCurrentAddr(v); |
| 148638 | + if( pLevel->p2==0 ) pLevel->p2 = sqlite3VdbeCurrentAddr(v); |
| 147651 | 148639 | |
| 147652 | 148640 | /* Check if the index cursor is past the end of the range. */ |
| 147653 | 148641 | if( nConstraint ){ |
| 147654 | 148642 | if( regBignull ){ |
| 147655 | 148643 | /* Except, skip the end-of-range check while doing the NULL-scan */ |
| | @@ -148052,11 +149040,14 @@ |
| 148052 | 149040 | } |
| 148053 | 149041 | sqlite3ExprDelete(db, pDelete); |
| 148054 | 149042 | } |
| 148055 | 149043 | } |
| 148056 | 149044 | ExplainQueryPlanPop(pParse); |
| 148057 | | - pLevel->u.pCovidx = pCov; |
| 149045 | + assert( pLevel->pWLoop==pLoop ); |
| 149046 | + assert( (pLoop->wsFlags & WHERE_MULTI_OR)!=0 ); |
| 149047 | + assert( (pLoop->wsFlags & WHERE_IN_ABLE)==0 ); |
| 149048 | + pLevel->u.pCoveringIdx = pCov; |
| 148058 | 149049 | if( pCov ) pLevel->iIdxCur = iCovCur; |
| 148059 | 149050 | if( pAndExpr ){ |
| 148060 | 149051 | pAndExpr->pLeft = 0; |
| 148061 | 149052 | sqlite3ExprDelete(db, pAndExpr); |
| 148062 | 149053 | } |
| | @@ -148179,11 +149170,11 @@ |
| 148179 | 149170 | ** Example: If the WHERE clause contains "t1.a=t2.b" and "t2.b=123" |
| 148180 | 149171 | ** and we are coding the t1 loop and the t2 loop has not yet coded, |
| 148181 | 149172 | ** then we cannot use the "t1.a=t2.b" constraint, but we can code |
| 148182 | 149173 | ** the implied "t1.a=123" constraint. |
| 148183 | 149174 | */ |
| 148184 | | - for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){ |
| 149175 | + for(pTerm=pWC->a, j=pWC->nBase; j>0; j--, pTerm++){ |
| 148185 | 149176 | Expr *pE, sEAlt; |
| 148186 | 149177 | WhereTerm *pAlt; |
| 148187 | 149178 | if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue; |
| 148188 | 149179 | if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) continue; |
| 148189 | 149180 | if( (pTerm->eOperator & WO_EQUIV)==0 ) continue; |
| | @@ -148196,16 +149187,17 @@ |
| 148196 | 149187 | sqlite3WhereTermPrint(pTerm, pWC->nTerm-j); |
| 148197 | 149188 | } |
| 148198 | 149189 | #endif |
| 148199 | 149190 | assert( !ExprHasProperty(pE, EP_FromJoin) ); |
| 148200 | 149191 | assert( (pTerm->prereqRight & pLevel->notReady)!=0 ); |
| 149192 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 148201 | 149193 | pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.x.leftColumn, notReady, |
| 148202 | 149194 | WO_EQ|WO_IN|WO_IS, 0); |
| 148203 | 149195 | if( pAlt==0 ) continue; |
| 148204 | 149196 | if( pAlt->wtFlags & (TERM_CODED) ) continue; |
| 148205 | 149197 | if( (pAlt->eOperator & WO_IN) |
| 148206 | | - && (pAlt->pExpr->flags & EP_xIsSelect) |
| 149198 | + && ExprUseXSelect(pAlt->pExpr) |
| 148207 | 149199 | && (pAlt->pExpr->x.pSelect->pEList->nExpr>1) |
| 148208 | 149200 | ){ |
| 148209 | 149201 | continue; |
| 148210 | 149202 | } |
| 148211 | 149203 | testcase( pAlt->eOperator & WO_EQ ); |
| | @@ -148223,11 +149215,11 @@ |
| 148223 | 149215 | */ |
| 148224 | 149216 | if( pLevel->iLeftJoin ){ |
| 148225 | 149217 | pLevel->addrFirst = sqlite3VdbeCurrentAddr(v); |
| 148226 | 149218 | sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin); |
| 148227 | 149219 | VdbeComment((v, "record LEFT JOIN hit")); |
| 148228 | | - for(pTerm=pWC->a, j=0; j<pWC->nTerm; j++, pTerm++){ |
| 149220 | + for(pTerm=pWC->a, j=0; j<pWC->nBase; j++, pTerm++){ |
| 148229 | 149221 | testcase( pTerm->wtFlags & TERM_VIRTUAL ); |
| 148230 | 149222 | testcase( pTerm->wtFlags & TERM_CODED ); |
| 148231 | 149223 | if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue; |
| 148232 | 149224 | if( (pTerm->prereqAll & pLevel->notReady)!=0 ){ |
| 148233 | 149225 | assert( pWInfo->untestedTerms ); |
| | @@ -148334,10 +149326,11 @@ |
| 148334 | 149326 | sqlite3DbFree(db, pOld); |
| 148335 | 149327 | } |
| 148336 | 149328 | pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]); |
| 148337 | 149329 | } |
| 148338 | 149330 | pTerm = &pWC->a[idx = pWC->nTerm++]; |
| 149331 | + if( (wtFlags & TERM_VIRTUAL)==0 ) pWC->nBase = pWC->nTerm; |
| 148339 | 149332 | if( p && ExprHasProperty(p, EP_Unlikely) ){ |
| 148340 | 149333 | pTerm->truthProb = sqlite3LogEst(p->iTable) - 270; |
| 148341 | 149334 | }else{ |
| 148342 | 149335 | pTerm->truthProb = 1; |
| 148343 | 149336 | } |
| | @@ -148450,10 +149443,11 @@ |
| 148450 | 149443 | return 0; |
| 148451 | 149444 | } |
| 148452 | 149445 | #ifdef SQLITE_EBCDIC |
| 148453 | 149446 | if( *pnoCase ) return 0; |
| 148454 | 149447 | #endif |
| 149448 | + assert( ExprUseXList(pExpr) ); |
| 148455 | 149449 | pList = pExpr->x.pList; |
| 148456 | 149450 | pLeft = pList->a[1].pExpr; |
| 148457 | 149451 | |
| 148458 | 149452 | pRight = sqlite3ExprSkipCollate(pList->a[0].pExpr); |
| 148459 | 149453 | op = pRight->op; |
| | @@ -148465,11 +149459,12 @@ |
| 148465 | 149459 | z = sqlite3_value_text(pVal); |
| 148466 | 149460 | } |
| 148467 | 149461 | sqlite3VdbeSetVarmask(pParse->pVdbe, iCol); |
| 148468 | 149462 | assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER ); |
| 148469 | 149463 | }else if( op==TK_STRING ){ |
| 148470 | | - z = (u8*)pRight->u.zToken; |
| 149464 | + assert( !ExprHasProperty(pRight, EP_IntValue) ); |
| 149465 | + z = (u8*)pRight->u.zToken; |
| 148471 | 149466 | } |
| 148472 | 149467 | if( z ){ |
| 148473 | 149468 | |
| 148474 | 149469 | /* Count the number of prefix characters prior to the first wildcard */ |
| 148475 | 149470 | cnt = 0; |
| | @@ -148494,11 +149489,13 @@ |
| 148494 | 149489 | |
| 148495 | 149490 | /* Get the pattern prefix. Remove all escapes from the prefix. */ |
| 148496 | 149491 | pPrefix = sqlite3Expr(db, TK_STRING, (char*)z); |
| 148497 | 149492 | if( pPrefix ){ |
| 148498 | 149493 | int iFrom, iTo; |
| 148499 | | - char *zNew = pPrefix->u.zToken; |
| 149494 | + char *zNew; |
| 149495 | + assert( !ExprHasProperty(pPrefix, EP_IntValue) ); |
| 149496 | + zNew = pPrefix->u.zToken; |
| 148500 | 149497 | zNew[cnt] = 0; |
| 148501 | 149498 | for(iFrom=iTo=0; iFrom<cnt; iFrom++){ |
| 148502 | 149499 | if( zNew[iFrom]==wc[3] ) iFrom++; |
| 148503 | 149500 | zNew[iTo++] = zNew[iFrom]; |
| 148504 | 149501 | } |
| | @@ -148518,11 +149515,13 @@ |
| 148518 | 149515 | ** 2019-06-14 https://sqlite.org/src/info/ce8717f0885af975 |
| 148519 | 149516 | ** 2019-09-03 https://sqlite.org/src/info/0f0428096f17252a |
| 148520 | 149517 | */ |
| 148521 | 149518 | if( pLeft->op!=TK_COLUMN |
| 148522 | 149519 | || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT |
| 148523 | | - || (pLeft->y.pTab && IsVirtual(pLeft->y.pTab)) /* Might be numeric */ |
| 149520 | + || (ALWAYS( ExprUseYTab(pLeft) ) |
| 149521 | + && pLeft->y.pTab |
| 149522 | + && IsVirtual(pLeft->y.pTab)) /* Might be numeric */ |
| 148524 | 149523 | ){ |
| 148525 | 149524 | int isNum; |
| 148526 | 149525 | double rDummy; |
| 148527 | 149526 | isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8); |
| 148528 | 149527 | if( isNum<=0 ){ |
| | @@ -148546,10 +149545,11 @@ |
| 148546 | 149545 | /* If the RHS pattern is a bound parameter, make arrangements to |
| 148547 | 149546 | ** reprepare the statement when that parameter is rebound */ |
| 148548 | 149547 | if( op==TK_VARIABLE ){ |
| 148549 | 149548 | Vdbe *v = pParse->pVdbe; |
| 148550 | 149549 | sqlite3VdbeSetVarmask(v, pRight->iColumn); |
| 149550 | + assert( !ExprHasProperty(pRight, EP_IntValue) ); |
| 148551 | 149551 | if( *pisComplete && pRight->u.zToken[1] ){ |
| 148552 | 149552 | /* If the rhs of the LIKE expression is a variable, and the current |
| 148553 | 149553 | ** value of the variable means there is no need to invoke the LIKE |
| 148554 | 149554 | ** function, then no OP_Variable will be added to the program. |
| 148555 | 149555 | ** This causes problems for the sqlite3_bind_parameter_name() |
| | @@ -148619,10 +149619,11 @@ |
| 148619 | 149619 | }; |
| 148620 | 149620 | ExprList *pList; |
| 148621 | 149621 | Expr *pCol; /* Column reference */ |
| 148622 | 149622 | int i; |
| 148623 | 149623 | |
| 149624 | + assert( ExprUseXList(pExpr) ); |
| 148624 | 149625 | pList = pExpr->x.pList; |
| 148625 | 149626 | if( pList==0 || pList->nExpr!=2 ){ |
| 148626 | 149627 | return 0; |
| 148627 | 149628 | } |
| 148628 | 149629 | |
| | @@ -148632,13 +149633,15 @@ |
| 148632 | 149633 | ** |
| 148633 | 149634 | ** vtab_column MATCH expression |
| 148634 | 149635 | ** MATCH(expression,vtab_column) |
| 148635 | 149636 | */ |
| 148636 | 149637 | pCol = pList->a[1].pExpr; |
| 149638 | + assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) ); |
| 148637 | 149639 | testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 ); |
| 148638 | 149640 | if( ExprIsVtab(pCol) ){ |
| 148639 | 149641 | for(i=0; i<ArraySize(aOp); i++){ |
| 149642 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 148640 | 149643 | if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){ |
| 148641 | 149644 | *peOp2 = aOp[i].eOp2; |
| 148642 | 149645 | *ppRight = pList->a[0].pExpr; |
| 148643 | 149646 | *ppLeft = pCol; |
| 148644 | 149647 | return 1; |
| | @@ -148655,20 +149658,22 @@ |
| 148655 | 149658 | ** Historically, xFindFunction expected to see lower-case function |
| 148656 | 149659 | ** names. But for this use case, xFindFunction is expected to deal |
| 148657 | 149660 | ** with function names in an arbitrary case. |
| 148658 | 149661 | */ |
| 148659 | 149662 | pCol = pList->a[0].pExpr; |
| 149663 | + assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) ); |
| 148660 | 149664 | testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 ); |
| 148661 | 149665 | if( ExprIsVtab(pCol) ){ |
| 148662 | 149666 | sqlite3_vtab *pVtab; |
| 148663 | 149667 | sqlite3_module *pMod; |
| 148664 | 149668 | void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**); |
| 148665 | 149669 | void *pNotUsed; |
| 148666 | 149670 | pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab; |
| 148667 | 149671 | assert( pVtab!=0 ); |
| 148668 | 149672 | assert( pVtab->pModule!=0 ); |
| 148669 | | - pMod = (sqlite3_module *)pVtab->pModule; |
| 149673 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 149674 | + pMod = (sqlite3_module *)pVtab->pModule; |
| 148670 | 149675 | if( pMod->xFindFunction!=0 ){ |
| 148671 | 149676 | i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed); |
| 148672 | 149677 | if( i>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){ |
| 148673 | 149678 | *peOp2 = i; |
| 148674 | 149679 | *ppRight = pList->a[1].pExpr; |
| | @@ -148679,14 +149684,16 @@ |
| 148679 | 149684 | } |
| 148680 | 149685 | }else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){ |
| 148681 | 149686 | int res = 0; |
| 148682 | 149687 | Expr *pLeft = pExpr->pLeft; |
| 148683 | 149688 | Expr *pRight = pExpr->pRight; |
| 149689 | + assert( pLeft->op!=TK_COLUMN || ExprUseYTab(pLeft) ); |
| 148684 | 149690 | testcase( pLeft->op==TK_COLUMN && pLeft->y.pTab==0 ); |
| 148685 | 149691 | if( ExprIsVtab(pLeft) ){ |
| 148686 | 149692 | res++; |
| 148687 | 149693 | } |
| 149694 | + assert( pRight==0 || pRight->op!=TK_COLUMN || ExprUseYTab(pRight) ); |
| 148688 | 149695 | testcase( pRight && pRight->op==TK_COLUMN && pRight->y.pTab==0 ); |
| 148689 | 149696 | if( pRight && ExprIsVtab(pRight) ){ |
| 148690 | 149697 | res++; |
| 148691 | 149698 | SWAP(Expr*, pLeft, pRight); |
| 148692 | 149699 | } |
| | @@ -148935,10 +149942,11 @@ |
| 148935 | 149942 | int j; |
| 148936 | 149943 | Bitmask b = 0; |
| 148937 | 149944 | pOrTerm->u.pAndInfo = pAndInfo; |
| 148938 | 149945 | pOrTerm->wtFlags |= TERM_ANDINFO; |
| 148939 | 149946 | pOrTerm->eOperator = WO_AND; |
| 149947 | + pOrTerm->leftCursor = -1; |
| 148940 | 149948 | pAndWC = &pAndInfo->wc; |
| 148941 | 149949 | memset(pAndWC->aStatic, 0, sizeof(pAndWC->aStatic)); |
| 148942 | 149950 | sqlite3WhereClauseInit(pAndWC, pWC->pWInfo); |
| 148943 | 149951 | sqlite3WhereSplit(pAndWC, pOrTerm->pExpr, TK_AND); |
| 148944 | 149952 | sqlite3WhereExprAnalyze(pSrc, pAndWC); |
| | @@ -148977,15 +149985,14 @@ |
| 148977 | 149985 | /* |
| 148978 | 149986 | ** Record the set of tables that satisfy case 3. The set might be |
| 148979 | 149987 | ** empty. |
| 148980 | 149988 | */ |
| 148981 | 149989 | pOrInfo->indexable = indexable; |
| 149990 | + pTerm->eOperator = WO_OR; |
| 149991 | + pTerm->leftCursor = -1; |
| 148982 | 149992 | if( indexable ){ |
| 148983 | | - pTerm->eOperator = WO_OR; |
| 148984 | 149993 | pWC->hasOr = 1; |
| 148985 | | - }else{ |
| 148986 | | - pTerm->eOperator = WO_OR; |
| 148987 | 149994 | } |
| 148988 | 149995 | |
| 148989 | 149996 | /* For a two-way OR, attempt to implementation case 2. |
| 148990 | 149997 | */ |
| 148991 | 149998 | if( indexable && pOrWc->nTerm==2 ){ |
| | @@ -149054,10 +150061,11 @@ |
| 149054 | 150061 | testcase( pOrTerm->wtFlags & TERM_COPIED ); |
| 149055 | 150062 | testcase( pOrTerm->wtFlags & TERM_VIRTUAL ); |
| 149056 | 150063 | assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) ); |
| 149057 | 150064 | continue; |
| 149058 | 150065 | } |
| 150066 | + assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 149059 | 150067 | iColumn = pOrTerm->u.x.leftColumn; |
| 149060 | 150068 | iCursor = pOrTerm->leftCursor; |
| 149061 | 150069 | pLeft = pOrTerm->pExpr->pLeft; |
| 149062 | 150070 | break; |
| 149063 | 150071 | } |
| | @@ -149074,10 +150082,11 @@ |
| 149074 | 150082 | /* We have found a candidate table and column. Check to see if that |
| 149075 | 150083 | ** table and column is common to every term in the OR clause */ |
| 149076 | 150084 | okToChngToIN = 1; |
| 149077 | 150085 | for(; i>=0 && okToChngToIN; i--, pOrTerm++){ |
| 149078 | 150086 | assert( pOrTerm->eOperator & WO_EQ ); |
| 150087 | + assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 149079 | 150088 | if( pOrTerm->leftCursor!=iCursor ){ |
| 149080 | 150089 | pOrTerm->wtFlags &= ~TERM_OR_OK; |
| 149081 | 150090 | }else if( pOrTerm->u.x.leftColumn!=iColumn || (iColumn==XN_EXPR |
| 149082 | 150091 | && sqlite3ExprCompare(pParse, pOrTerm->pExpr->pLeft, pLeft, -1) |
| 149083 | 150092 | )){ |
| | @@ -149110,10 +150119,11 @@ |
| 149110 | 150119 | Expr *pNew; /* The complete IN operator */ |
| 149111 | 150120 | |
| 149112 | 150121 | for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0; i--, pOrTerm++){ |
| 149113 | 150122 | if( (pOrTerm->wtFlags & TERM_OR_OK)==0 ) continue; |
| 149114 | 150123 | assert( pOrTerm->eOperator & WO_EQ ); |
| 150124 | + assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 149115 | 150125 | assert( pOrTerm->leftCursor==iCursor ); |
| 149116 | 150126 | assert( pOrTerm->u.x.leftColumn==iColumn ); |
| 149117 | 150127 | pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0); |
| 149118 | 150128 | pList = sqlite3ExprListAppend(pWInfo->pParse, pList, pDup); |
| 149119 | 150129 | pLeft = pOrTerm->pExpr->pLeft; |
| | @@ -149122,11 +150132,11 @@ |
| 149122 | 150132 | pDup = sqlite3ExprDup(db, pLeft, 0); |
| 149123 | 150133 | pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0); |
| 149124 | 150134 | if( pNew ){ |
| 149125 | 150135 | int idxNew; |
| 149126 | 150136 | transferJoinMarkings(pNew, pExpr); |
| 149127 | | - assert( !ExprHasProperty(pNew, EP_xIsSelect) ); |
| 150137 | + assert( ExprUseXList(pNew) ); |
| 149128 | 150138 | pNew->x.pList = pList; |
| 149129 | 150139 | idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC); |
| 149130 | 150140 | testcase( idxNew==0 ); |
| 149131 | 150141 | exprAnalyze(pSrc, pWC, idxNew); |
| 149132 | 150142 | /* pTerm = &pWC->a[idxTerm]; // would be needed if pTerm where reused */ |
| | @@ -149250,10 +150260,11 @@ |
| 149250 | 150260 | ** on the first element of the vector. */ |
| 149251 | 150261 | assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE ); |
| 149252 | 150262 | assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE ); |
| 149253 | 150263 | assert( op<=TK_GE ); |
| 149254 | 150264 | if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){ |
| 150265 | + assert( ExprUseXList(pExpr) ); |
| 149255 | 150266 | pExpr = pExpr->x.pList->a[0].pExpr; |
| 149256 | 150267 | |
| 149257 | 150268 | } |
| 149258 | 150269 | |
| 149259 | 150270 | if( pExpr->op==TK_COLUMN ){ |
| | @@ -149307,32 +150318,49 @@ |
| 149307 | 150318 | int nLeft; /* Number of elements on left side vector */ |
| 149308 | 150319 | |
| 149309 | 150320 | if( db->mallocFailed ){ |
| 149310 | 150321 | return; |
| 149311 | 150322 | } |
| 150323 | + assert( pWC->nTerm > idxTerm ); |
| 149312 | 150324 | pTerm = &pWC->a[idxTerm]; |
| 149313 | 150325 | pMaskSet = &pWInfo->sMaskSet; |
| 149314 | 150326 | pExpr = pTerm->pExpr; |
| 150327 | + assert( pExpr!=0 ); /* Because malloc() has not failed */ |
| 149315 | 150328 | assert( pExpr->op!=TK_AS && pExpr->op!=TK_COLLATE ); |
| 150329 | + pMaskSet->bVarSelect = 0; |
| 149316 | 150330 | prereqLeft = sqlite3WhereExprUsage(pMaskSet, pExpr->pLeft); |
| 149317 | 150331 | op = pExpr->op; |
| 149318 | 150332 | if( op==TK_IN ){ |
| 149319 | 150333 | assert( pExpr->pRight==0 ); |
| 149320 | 150334 | if( sqlite3ExprCheckIN(pParse, pExpr) ) return; |
| 149321 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 150335 | + if( ExprUseXSelect(pExpr) ){ |
| 149322 | 150336 | pTerm->prereqRight = exprSelectUsage(pMaskSet, pExpr->x.pSelect); |
| 149323 | 150337 | }else{ |
| 149324 | 150338 | pTerm->prereqRight = sqlite3WhereExprListUsage(pMaskSet, pExpr->x.pList); |
| 149325 | 150339 | } |
| 149326 | | - }else if( op==TK_ISNULL ){ |
| 149327 | | - pTerm->prereqRight = 0; |
| 150340 | + prereqAll = prereqLeft | pTerm->prereqRight; |
| 149328 | 150341 | }else{ |
| 149329 | 150342 | pTerm->prereqRight = sqlite3WhereExprUsage(pMaskSet, pExpr->pRight); |
| 150343 | + if( pExpr->pLeft==0 |
| 150344 | + || ExprHasProperty(pExpr, EP_xIsSelect|EP_IfNullRow) |
| 150345 | + || pExpr->x.pList!=0 |
| 150346 | + ){ |
| 150347 | + prereqAll = sqlite3WhereExprUsageNN(pMaskSet, pExpr); |
| 150348 | + }else{ |
| 150349 | + prereqAll = prereqLeft | pTerm->prereqRight; |
| 150350 | + } |
| 149330 | 150351 | } |
| 149331 | | - pMaskSet->bVarSelect = 0; |
| 149332 | | - prereqAll = sqlite3WhereExprUsageNN(pMaskSet, pExpr); |
| 149333 | 150352 | if( pMaskSet->bVarSelect ) pTerm->wtFlags |= TERM_VARSELECT; |
| 150353 | + |
| 150354 | +#ifdef SQLITE_DEBUG |
| 150355 | + if( prereqAll!=sqlite3WhereExprUsageNN(pMaskSet, pExpr) ){ |
| 150356 | + printf("\n*** Incorrect prereqAll computed for:\n"); |
| 150357 | + sqlite3TreeViewExpr(0,pExpr,0); |
| 150358 | + abort(); |
| 150359 | + } |
| 150360 | +#endif |
| 150361 | + |
| 149334 | 150362 | if( ExprHasProperty(pExpr, EP_FromJoin) ){ |
| 149335 | 150363 | Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->iRightJoinTable); |
| 149336 | 150364 | prereqAll |= x; |
| 149337 | 150365 | extraRight = x-1; /* ON clause terms may not be used with an index |
| 149338 | 150366 | ** on left table of a LEFT JOIN. Ticket #3015 */ |
| | @@ -149352,15 +150380,17 @@ |
| 149352 | 150380 | u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV; |
| 149353 | 150381 | |
| 149354 | 150382 | if( pTerm->u.x.iField>0 ){ |
| 149355 | 150383 | assert( op==TK_IN ); |
| 149356 | 150384 | assert( pLeft->op==TK_VECTOR ); |
| 150385 | + assert( ExprUseXList(pLeft) ); |
| 149357 | 150386 | pLeft = pLeft->x.pList->a[pTerm->u.x.iField-1].pExpr; |
| 149358 | 150387 | } |
| 149359 | 150388 | |
| 149360 | 150389 | if( exprMightBeIndexed(pSrc, prereqLeft, aiCurCol, pLeft, op) ){ |
| 149361 | 150390 | pTerm->leftCursor = aiCurCol[0]; |
| 150391 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 149362 | 150392 | pTerm->u.x.leftColumn = aiCurCol[1]; |
| 149363 | 150393 | pTerm->eOperator = operatorMask(op) & opMask; |
| 149364 | 150394 | } |
| 149365 | 150395 | if( op==TK_IS ) pTerm->wtFlags |= TERM_IS; |
| 149366 | 150396 | if( pRight |
| | @@ -149394,10 +150424,11 @@ |
| 149394 | 150424 | pDup = pExpr; |
| 149395 | 150425 | pNew = pTerm; |
| 149396 | 150426 | } |
| 149397 | 150427 | pNew->wtFlags |= exprCommute(pParse, pDup); |
| 149398 | 150428 | pNew->leftCursor = aiCurCol[0]; |
| 150429 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 149399 | 150430 | pNew->u.x.leftColumn = aiCurCol[1]; |
| 149400 | 150431 | testcase( (prereqLeft | extraRight) != prereqLeft ); |
| 149401 | 150432 | pNew->prereqRight = prereqLeft | extraRight; |
| 149402 | 150433 | pNew->prereqAll = prereqAll; |
| 149403 | 150434 | pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask; |
| | @@ -149404,10 +150435,11 @@ |
| 149404 | 150435 | }else |
| 149405 | 150436 | if( op==TK_ISNULL |
| 149406 | 150437 | && !ExprHasProperty(pExpr,EP_FromJoin) |
| 149407 | 150438 | && 0==sqlite3ExprCanBeNull(pLeft) |
| 149408 | 150439 | ){ |
| 150440 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 149409 | 150441 | pExpr->op = TK_TRUEFALSE; |
| 149410 | 150442 | pExpr->u.zToken = "false"; |
| 149411 | 150443 | ExprSetProperty(pExpr, EP_IsFalse); |
| 149412 | 150444 | pTerm->prereqAll = 0; |
| 149413 | 150445 | pTerm->eOperator = 0; |
| | @@ -149429,13 +150461,15 @@ |
| 149429 | 150461 | ** term. That means that if the BETWEEN term is coded, the children are |
| 149430 | 150462 | ** skipped. Or, if the children are satisfied by an index, the original |
| 149431 | 150463 | ** BETWEEN term is skipped. |
| 149432 | 150464 | */ |
| 149433 | 150465 | else if( pExpr->op==TK_BETWEEN && pWC->op==TK_AND ){ |
| 149434 | | - ExprList *pList = pExpr->x.pList; |
| 150466 | + ExprList *pList; |
| 149435 | 150467 | int i; |
| 149436 | 150468 | static const u8 ops[] = {TK_GE, TK_LE}; |
| 150469 | + assert( ExprUseXList(pExpr) ); |
| 150470 | + pList = pExpr->x.pList; |
| 149437 | 150471 | assert( pList!=0 ); |
| 149438 | 150472 | assert( pList->nExpr==2 ); |
| 149439 | 150473 | for(i=0; i<2; i++){ |
| 149440 | 150474 | Expr *pNewExpr; |
| 149441 | 150475 | int idxNew; |
| | @@ -149524,12 +150558,16 @@ |
| 149524 | 150558 | int idxNew1; |
| 149525 | 150559 | int idxNew2; |
| 149526 | 150560 | const char *zCollSeqName; /* Name of collating sequence */ |
| 149527 | 150561 | const u16 wtFlags = TERM_LIKEOPT | TERM_VIRTUAL | TERM_DYNAMIC; |
| 149528 | 150562 | |
| 150563 | + assert( ExprUseXList(pExpr) ); |
| 149529 | 150564 | pLeft = pExpr->x.pList->a[1].pExpr; |
| 149530 | 150565 | pStr2 = sqlite3ExprDup(db, pStr1, 0); |
| 150566 | + assert( pStr1==0 || !ExprHasProperty(pStr1, EP_IntValue) ); |
| 150567 | + assert( pStr2==0 || !ExprHasProperty(pStr2, EP_IntValue) ); |
| 150568 | + |
| 149531 | 150569 | |
| 149532 | 150570 | /* Convert the lower bound to upper-case and the upper bound to |
| 149533 | 150571 | ** lower-case (upper-case is less than lower-case in ASCII) so that |
| 149534 | 150572 | ** the range constraints also work for BLOBs |
| 149535 | 150573 | */ |
| | @@ -149625,10 +150663,11 @@ |
| 149625 | 150663 | ** not use window functions. |
| 149626 | 150664 | */ |
| 149627 | 150665 | else if( pExpr->op==TK_IN |
| 149628 | 150666 | && pTerm->u.x.iField==0 |
| 149629 | 150667 | && pExpr->pLeft->op==TK_VECTOR |
| 150668 | + && ALWAYS( ExprUseXSelect(pExpr) ) |
| 149630 | 150669 | && pExpr->x.pSelect->pPrior==0 |
| 149631 | 150670 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 149632 | 150671 | && pExpr->x.pSelect->pWin==0 |
| 149633 | 150672 | #endif |
| 149634 | 150673 | && pWC->op==TK_AND |
| | @@ -149741,10 +150780,11 @@ |
| 149741 | 150780 | ){ |
| 149742 | 150781 | pWC->pWInfo = pWInfo; |
| 149743 | 150782 | pWC->hasOr = 0; |
| 149744 | 150783 | pWC->pOuter = 0; |
| 149745 | 150784 | pWC->nTerm = 0; |
| 150785 | + pWC->nBase = 0; |
| 149746 | 150786 | pWC->nSlot = ArraySize(pWC->aStatic); |
| 149747 | 150787 | pWC->a = pWC->aStatic; |
| 149748 | 150788 | } |
| 149749 | 150789 | |
| 149750 | 150790 | /* |
| | @@ -149751,21 +150791,37 @@ |
| 149751 | 150791 | ** Deallocate a WhereClause structure. The WhereClause structure |
| 149752 | 150792 | ** itself is not freed. This routine is the inverse of |
| 149753 | 150793 | ** sqlite3WhereClauseInit(). |
| 149754 | 150794 | */ |
| 149755 | 150795 | SQLITE_PRIVATE void sqlite3WhereClauseClear(WhereClause *pWC){ |
| 149756 | | - int i; |
| 149757 | | - WhereTerm *a; |
| 149758 | 150796 | sqlite3 *db = pWC->pWInfo->pParse->db; |
| 149759 | | - for(i=pWC->nTerm-1, a=pWC->a; i>=0; i--, a++){ |
| 149760 | | - if( a->wtFlags & TERM_DYNAMIC ){ |
| 149761 | | - sqlite3ExprDelete(db, a->pExpr); |
| 149762 | | - } |
| 149763 | | - if( a->wtFlags & TERM_ORINFO ){ |
| 149764 | | - whereOrInfoDelete(db, a->u.pOrInfo); |
| 149765 | | - }else if( a->wtFlags & TERM_ANDINFO ){ |
| 149766 | | - whereAndInfoDelete(db, a->u.pAndInfo); |
| 150797 | + assert( pWC->nTerm>=pWC->nBase ); |
| 150798 | + if( pWC->nTerm>0 ){ |
| 150799 | + WhereTerm *a = pWC->a; |
| 150800 | + WhereTerm *aLast = &pWC->a[pWC->nTerm-1]; |
| 150801 | +#ifdef SQLITE_DEBUG |
| 150802 | + int i; |
| 150803 | + /* Verify that every term past pWC->nBase is virtual */ |
| 150804 | + for(i=pWC->nBase; i<pWC->nTerm; i++){ |
| 150805 | + assert( (pWC->a[i].wtFlags & TERM_VIRTUAL)!=0 ); |
| 150806 | + } |
| 150807 | +#endif |
| 150808 | + while(1){ |
| 150809 | + if( a->wtFlags & TERM_DYNAMIC ){ |
| 150810 | + sqlite3ExprDelete(db, a->pExpr); |
| 150811 | + } |
| 150812 | + if( a->wtFlags & (TERM_ORINFO|TERM_ANDINFO) ){ |
| 150813 | + if( a->wtFlags & TERM_ORINFO ){ |
| 150814 | + assert( (a->wtFlags & TERM_ANDINFO)==0 ); |
| 150815 | + whereOrInfoDelete(db, a->u.pOrInfo); |
| 150816 | + }else{ |
| 150817 | + assert( (a->wtFlags & TERM_ANDINFO)!=0 ); |
| 150818 | + whereAndInfoDelete(db, a->u.pAndInfo); |
| 150819 | + } |
| 150820 | + } |
| 150821 | + if( a==aLast ) break; |
| 150822 | + a++; |
| 149767 | 150823 | } |
| 149768 | 150824 | } |
| 149769 | 150825 | if( pWC->a!=pWC->aStatic ){ |
| 149770 | 150826 | sqlite3DbFree(db, pWC->a); |
| 149771 | 150827 | } |
| | @@ -149774,38 +150830,71 @@ |
| 149774 | 150830 | |
| 149775 | 150831 | /* |
| 149776 | 150832 | ** These routines walk (recursively) an expression tree and generate |
| 149777 | 150833 | ** a bitmask indicating which tables are used in that expression |
| 149778 | 150834 | ** tree. |
| 150835 | +** |
| 150836 | +** sqlite3WhereExprUsage(MaskSet, Expr) -> |
| 150837 | +** |
| 150838 | +** Return a Bitmask of all tables referenced by Expr. Expr can be |
| 150839 | +** be NULL, in which case 0 is returned. |
| 150840 | +** |
| 150841 | +** sqlite3WhereExprUsageNN(MaskSet, Expr) -> |
| 150842 | +** |
| 150843 | +** Same as sqlite3WhereExprUsage() except that Expr must not be |
| 150844 | +** NULL. The "NN" suffix on the name stands for "Not Null". |
| 150845 | +** |
| 150846 | +** sqlite3WhereExprListUsage(MaskSet, ExprList) -> |
| 150847 | +** |
| 150848 | +** Return a Bitmask of all tables referenced by every expression |
| 150849 | +** in the expression list ExprList. ExprList can be NULL, in which |
| 150850 | +** case 0 is returned. |
| 150851 | +** |
| 150852 | +** sqlite3WhereExprUsageFull(MaskSet, ExprList) -> |
| 150853 | +** |
| 150854 | +** Internal use only. Called only by sqlite3WhereExprUsageNN() for |
| 150855 | +** complex expressions that require pushing register values onto |
| 150856 | +** the stack. Many calls to sqlite3WhereExprUsageNN() do not need |
| 150857 | +** the more complex analysis done by this routine. Hence, the |
| 150858 | +** computations done by this routine are broken out into a separate |
| 150859 | +** "no-inline" function to avoid the stack push overhead in the |
| 150860 | +** common case where it is not needed. |
| 149779 | 150861 | */ |
| 149780 | | -SQLITE_PRIVATE Bitmask sqlite3WhereExprUsageNN(WhereMaskSet *pMaskSet, Expr *p){ |
| 150862 | +static SQLITE_NOINLINE Bitmask sqlite3WhereExprUsageFull( |
| 150863 | + WhereMaskSet *pMaskSet, |
| 150864 | + Expr *p |
| 150865 | +){ |
| 149781 | 150866 | Bitmask mask; |
| 149782 | | - if( p->op==TK_COLUMN && !ExprHasProperty(p, EP_FixedCol) ){ |
| 149783 | | - return sqlite3WhereGetMask(pMaskSet, p->iTable); |
| 149784 | | - }else if( ExprHasProperty(p, EP_TokenOnly|EP_Leaf) ){ |
| 149785 | | - assert( p->op!=TK_IF_NULL_ROW ); |
| 149786 | | - return 0; |
| 149787 | | - } |
| 149788 | 150867 | mask = (p->op==TK_IF_NULL_ROW) ? sqlite3WhereGetMask(pMaskSet, p->iTable) : 0; |
| 149789 | 150868 | if( p->pLeft ) mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pLeft); |
| 149790 | 150869 | if( p->pRight ){ |
| 149791 | 150870 | mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pRight); |
| 149792 | 150871 | assert( p->x.pList==0 ); |
| 149793 | | - }else if( ExprHasProperty(p, EP_xIsSelect) ){ |
| 150872 | + }else if( ExprUseXSelect(p) ){ |
| 149794 | 150873 | if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1; |
| 149795 | 150874 | mask |= exprSelectUsage(pMaskSet, p->x.pSelect); |
| 149796 | 150875 | }else if( p->x.pList ){ |
| 149797 | 150876 | mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList); |
| 149798 | 150877 | } |
| 149799 | 150878 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 149800 | | - if( (p->op==TK_FUNCTION || p->op==TK_AGG_FUNCTION) && p->y.pWin ){ |
| 150879 | + if( (p->op==TK_FUNCTION || p->op==TK_AGG_FUNCTION) && ExprUseYWin(p) ){ |
| 150880 | + assert( p->y.pWin!=0 ); |
| 149801 | 150881 | mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition); |
| 149802 | 150882 | mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy); |
| 149803 | 150883 | mask |= sqlite3WhereExprUsage(pMaskSet, p->y.pWin->pFilter); |
| 149804 | 150884 | } |
| 149805 | 150885 | #endif |
| 149806 | 150886 | return mask; |
| 150887 | +} |
| 150888 | +SQLITE_PRIVATE Bitmask sqlite3WhereExprUsageNN(WhereMaskSet *pMaskSet, Expr *p){ |
| 150889 | + if( p->op==TK_COLUMN && !ExprHasProperty(p, EP_FixedCol) ){ |
| 150890 | + return sqlite3WhereGetMask(pMaskSet, p->iTable); |
| 150891 | + }else if( ExprHasProperty(p, EP_TokenOnly|EP_Leaf) ){ |
| 150892 | + assert( p->op!=TK_IF_NULL_ROW ); |
| 150893 | + return 0; |
| 150894 | + } |
| 150895 | + return sqlite3WhereExprUsageFull(pMaskSet, p); |
| 149807 | 150896 | } |
| 149808 | 150897 | SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){ |
| 149809 | 150898 | return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0; |
| 149810 | 150899 | } |
| 149811 | 150900 | SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet *pMaskSet, ExprList *pList){ |
| | @@ -149870,10 +150959,11 @@ |
| 149870 | 150959 | } |
| 149871 | 150960 | pColRef = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0); |
| 149872 | 150961 | if( pColRef==0 ) return; |
| 149873 | 150962 | pColRef->iTable = pItem->iCursor; |
| 149874 | 150963 | pColRef->iColumn = k++; |
| 150964 | + assert( ExprUseYTab(pColRef) ); |
| 149875 | 150965 | pColRef->y.pTab = pTab; |
| 149876 | 150966 | pRhs = sqlite3PExpr(pParse, TK_UPLUS, |
| 149877 | 150967 | sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0); |
| 149878 | 150968 | pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs); |
| 149879 | 150969 | if( pItem->fg.jointype & JT_LEFT ){ |
| | @@ -150119,11 +151209,16 @@ |
| 150119 | 151209 | ** iCursor is not in the set. |
| 150120 | 151210 | */ |
| 150121 | 151211 | SQLITE_PRIVATE Bitmask sqlite3WhereGetMask(WhereMaskSet *pMaskSet, int iCursor){ |
| 150122 | 151212 | int i; |
| 150123 | 151213 | assert( pMaskSet->n<=(int)sizeof(Bitmask)*8 ); |
| 150124 | | - for(i=0; i<pMaskSet->n; i++){ |
| 151214 | + assert( pMaskSet->n>0 || pMaskSet->ix[0]<0 ); |
| 151215 | + assert( iCursor>=-1 ); |
| 151216 | + if( pMaskSet->ix[0]==iCursor ){ |
| 151217 | + return 1; |
| 151218 | + } |
| 151219 | + for(i=1; i<pMaskSet->n; i++){ |
| 150125 | 151220 | if( pMaskSet->ix[i]==iCursor ){ |
| 150126 | 151221 | return MASKBIT(i); |
| 150127 | 151222 | } |
| 150128 | 151223 | } |
| 150129 | 151224 | return 0; |
| | @@ -150171,12 +151266,14 @@ |
| 150171 | 151266 | pWC = pScan->pWC; |
| 150172 | 151267 | while(1){ |
| 150173 | 151268 | iColumn = pScan->aiColumn[pScan->iEquiv-1]; |
| 150174 | 151269 | iCur = pScan->aiCur[pScan->iEquiv-1]; |
| 150175 | 151270 | assert( pWC!=0 ); |
| 151271 | + assert( iCur>=0 ); |
| 150176 | 151272 | do{ |
| 150177 | 151273 | for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){ |
| 151274 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 || pTerm->leftCursor<0 ); |
| 150178 | 151275 | if( pTerm->leftCursor==iCur |
| 150179 | 151276 | && pTerm->u.x.leftColumn==iColumn |
| 150180 | 151277 | && (iColumn!=XN_EXPR |
| 150181 | 151278 | || sqlite3ExprCompareSkip(pTerm->pExpr->pLeft, |
| 150182 | 151279 | pScan->pIdxExpr,iCur)==0) |
| | @@ -150214,11 +151311,12 @@ |
| 150214 | 151311 | if( sqlite3StrICmp(pColl->zName, pScan->zCollName) ){ |
| 150215 | 151312 | continue; |
| 150216 | 151313 | } |
| 150217 | 151314 | } |
| 150218 | 151315 | if( (pTerm->eOperator & (WO_EQ|WO_IS))!=0 |
| 150219 | | - && (pX = pTerm->pExpr->pRight)->op==TK_COLUMN |
| 151316 | + && (pX = pTerm->pExpr->pRight, ALWAYS(pX!=0)) |
| 151317 | + && pX->op==TK_COLUMN |
| 150220 | 151318 | && pX->iTable==pScan->aiCur[0] |
| 150221 | 151319 | && pX->iColumn==pScan->aiColumn[0] |
| 150222 | 151320 | ){ |
| 150223 | 151321 | testcase( pTerm->eOperator & WO_IS ); |
| 150224 | 151322 | continue; |
| | @@ -150301,20 +151399,20 @@ |
| 150301 | 151399 | pScan->nEquiv = 1; |
| 150302 | 151400 | pScan->iEquiv = 1; |
| 150303 | 151401 | if( pIdx ){ |
| 150304 | 151402 | int j = iColumn; |
| 150305 | 151403 | iColumn = pIdx->aiColumn[j]; |
| 150306 | | - if( iColumn==XN_EXPR ){ |
| 151404 | + if( iColumn==pIdx->pTable->iPKey ){ |
| 151405 | + iColumn = XN_ROWID; |
| 151406 | + }else if( iColumn>=0 ){ |
| 151407 | + pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity; |
| 151408 | + pScan->zCollName = pIdx->azColl[j]; |
| 151409 | + }else if( iColumn==XN_EXPR ){ |
| 150307 | 151410 | pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr; |
| 150308 | 151411 | pScan->zCollName = pIdx->azColl[j]; |
| 150309 | 151412 | pScan->aiColumn[0] = XN_EXPR; |
| 150310 | 151413 | return whereScanInitIndexExpr(pScan); |
| 150311 | | - }else if( iColumn==pIdx->pTable->iPKey ){ |
| 150312 | | - iColumn = XN_ROWID; |
| 150313 | | - }else if( iColumn>=0 ){ |
| 150314 | | - pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity; |
| 150315 | | - pScan->zCollName = pIdx->azColl[j]; |
| 150316 | 151414 | } |
| 150317 | 151415 | }else if( iColumn==XN_EXPR ){ |
| 150318 | 151416 | return 0; |
| 150319 | 151417 | } |
| 150320 | 151418 | pScan->aiColumn[0] = iColumn; |
| | @@ -150594,13 +151692,13 @@ |
| 150594 | 151692 | ** Return TRUE if the WHERE clause term pTerm is of a form where it |
| 150595 | 151693 | ** could be used with an index to access pSrc, assuming an appropriate |
| 150596 | 151694 | ** index existed. |
| 150597 | 151695 | */ |
| 150598 | 151696 | static int termCanDriveIndex( |
| 150599 | | - WhereTerm *pTerm, /* WHERE clause term to check */ |
| 150600 | | - SrcItem *pSrc, /* Table we are trying to access */ |
| 150601 | | - Bitmask notReady /* Tables in outer loops of the join */ |
| 151697 | + const WhereTerm *pTerm, /* WHERE clause term to check */ |
| 151698 | + const SrcItem *pSrc, /* Table we are trying to access */ |
| 151699 | + const Bitmask notReady /* Tables in outer loops of the join */ |
| 150602 | 151700 | ){ |
| 150603 | 151701 | char aff; |
| 150604 | 151702 | if( pTerm->leftCursor!=pSrc->iCursor ) return 0; |
| 150605 | 151703 | if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0; |
| 150606 | 151704 | if( (pSrc->fg.jointype & JT_LEFT) |
| | @@ -150611,10 +151709,11 @@ |
| 150611 | 151709 | ** the RHS of a LEFT JOIN. Such a term can only be used if it is from |
| 150612 | 151710 | ** the ON clause. */ |
| 150613 | 151711 | return 0; |
| 150614 | 151712 | } |
| 150615 | 151713 | if( (pTerm->prereqRight & notReady)!=0 ) return 0; |
| 151714 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 150616 | 151715 | if( pTerm->u.x.leftColumn<0 ) return 0; |
| 150617 | 151716 | aff = pSrc->pTab->aCol[pTerm->u.x.leftColumn].affinity; |
| 150618 | 151717 | if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0; |
| 150619 | 151718 | testcase( pTerm->pExpr->op==TK_IS ); |
| 150620 | 151719 | return 1; |
| | @@ -150626,15 +151725,15 @@ |
| 150626 | 151725 | /* |
| 150627 | 151726 | ** Generate code to construct the Index object for an automatic index |
| 150628 | 151727 | ** and to set up the WhereLevel object pLevel so that the code generator |
| 150629 | 151728 | ** makes use of the automatic index. |
| 150630 | 151729 | */ |
| 150631 | | -static void constructAutomaticIndex( |
| 151730 | +static SQLITE_NOINLINE void constructAutomaticIndex( |
| 150632 | 151731 | Parse *pParse, /* The parsing context */ |
| 150633 | | - WhereClause *pWC, /* The WHERE clause */ |
| 150634 | | - SrcItem *pSrc, /* The FROM clause term to get the next index */ |
| 150635 | | - Bitmask notReady, /* Mask of cursors that are not available */ |
| 151732 | + const WhereClause *pWC, /* The WHERE clause */ |
| 151733 | + const SrcItem *pSrc, /* The FROM clause term to get the next index */ |
| 151734 | + const Bitmask notReady, /* Mask of cursors that are not available */ |
| 150636 | 151735 | WhereLevel *pLevel /* Write new index here */ |
| 150637 | 151736 | ){ |
| 150638 | 151737 | int nKeyCol; /* Number of columns in the constructed index */ |
| 150639 | 151738 | WhereTerm *pTerm; /* A single term of the WHERE clause */ |
| 150640 | 151739 | WhereTerm *pWCEnd; /* End of pWC->a[] */ |
| | @@ -150672,23 +151771,26 @@ |
| 150672 | 151771 | pWCEnd = &pWC->a[pWC->nTerm]; |
| 150673 | 151772 | pLoop = pLevel->pWLoop; |
| 150674 | 151773 | idxCols = 0; |
| 150675 | 151774 | for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){ |
| 150676 | 151775 | Expr *pExpr = pTerm->pExpr; |
| 150677 | | - assert( !ExprHasProperty(pExpr, EP_FromJoin) /* prereq always non-zero */ |
| 150678 | | - || pExpr->iRightJoinTable!=pSrc->iCursor /* for the right-hand */ |
| 150679 | | - || pLoop->prereq!=0 ); /* table of a LEFT JOIN */ |
| 150680 | | - if( pLoop->prereq==0 |
| 150681 | | - && (pTerm->wtFlags & TERM_VIRTUAL)==0 |
| 150682 | | - && !ExprHasProperty(pExpr, EP_FromJoin) |
| 150683 | | - && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) ){ |
| 151776 | + /* Make the automatic index a partial index if there are terms in the |
| 151777 | + ** WHERE clause (or the ON clause of a LEFT join) that constrain which |
| 151778 | + ** rows of the target table (pSrc) that can be used. */ |
| 151779 | + if( (pTerm->wtFlags & TERM_VIRTUAL)==0 |
| 151780 | + && ((pSrc->fg.jointype&JT_LEFT)==0 || ExprHasProperty(pExpr,EP_FromJoin)) |
| 151781 | + && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) |
| 151782 | + ){ |
| 150684 | 151783 | pPartial = sqlite3ExprAnd(pParse, pPartial, |
| 150685 | 151784 | sqlite3ExprDup(pParse->db, pExpr, 0)); |
| 150686 | 151785 | } |
| 150687 | 151786 | if( termCanDriveIndex(pTerm, pSrc, notReady) ){ |
| 150688 | | - int iCol = pTerm->u.x.leftColumn; |
| 150689 | | - Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol); |
| 151787 | + int iCol; |
| 151788 | + Bitmask cMask; |
| 151789 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 151790 | + iCol = pTerm->u.x.leftColumn; |
| 151791 | + cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol); |
| 150690 | 151792 | testcase( iCol==BMS ); |
| 150691 | 151793 | testcase( iCol==BMS-1 ); |
| 150692 | 151794 | if( !sentWarning ){ |
| 150693 | 151795 | sqlite3_log(SQLITE_WARNING_AUTOINDEX, |
| 150694 | 151796 | "automatic index on %s(%s)", pTable->zName, |
| | @@ -150736,12 +151838,15 @@ |
| 150736 | 151838 | pIdx->pTable = pTable; |
| 150737 | 151839 | n = 0; |
| 150738 | 151840 | idxCols = 0; |
| 150739 | 151841 | for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){ |
| 150740 | 151842 | if( termCanDriveIndex(pTerm, pSrc, notReady) ){ |
| 150741 | | - int iCol = pTerm->u.x.leftColumn; |
| 150742 | | - Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol); |
| 151843 | + int iCol; |
| 151844 | + Bitmask cMask; |
| 151845 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 151846 | + iCol = pTerm->u.x.leftColumn; |
| 151847 | + cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol); |
| 150743 | 151848 | testcase( iCol==BMS-1 ); |
| 150744 | 151849 | testcase( iCol==BMS ); |
| 150745 | 151850 | if( (idxCols & cMask)==0 ){ |
| 150746 | 151851 | Expr *pX = pTerm->pExpr; |
| 150747 | 151852 | idxCols |= cMask; |
| | @@ -150779,10 +151884,14 @@ |
| 150779 | 151884 | assert( pLevel->iIdxCur>=0 ); |
| 150780 | 151885 | pLevel->iIdxCur = pParse->nTab++; |
| 150781 | 151886 | sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1); |
| 150782 | 151887 | sqlite3VdbeSetP4KeyInfo(pParse, pIdx); |
| 150783 | 151888 | VdbeComment((v, "for %s", pTable->zName)); |
| 151889 | + if( OptimizationEnabled(pParse->db, SQLITE_BloomFilter) ){ |
| 151890 | + pLevel->regFilter = ++pParse->nMem; |
| 151891 | + sqlite3VdbeAddOp2(v, OP_Blob, 10000, pLevel->regFilter); |
| 151892 | + } |
| 150784 | 151893 | |
| 150785 | 151894 | /* Fill the automatic index with content */ |
| 150786 | 151895 | pTabItem = &pWC->pWInfo->pTabList->a[pLevel->iFrom]; |
| 150787 | 151896 | if( pTabItem->fg.viaCoroutine ){ |
| 150788 | 151897 | int regYield = pTabItem->regReturn; |
| | @@ -150801,10 +151910,14 @@ |
| 150801 | 151910 | } |
| 150802 | 151911 | regRecord = sqlite3GetTempReg(pParse); |
| 150803 | 151912 | regBase = sqlite3GenerateIndexKey( |
| 150804 | 151913 | pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0 |
| 150805 | 151914 | ); |
| 151915 | + if( pLevel->regFilter ){ |
| 151916 | + sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, |
| 151917 | + regBase, pLoop->u.btree.nEq); |
| 151918 | + } |
| 150806 | 151919 | sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord); |
| 150807 | 151920 | sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 150808 | 151921 | if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue); |
| 150809 | 151922 | if( pTabItem->fg.viaCoroutine ){ |
| 150810 | 151923 | sqlite3VdbeChangeP2(v, addrCounter, regBase+n); |
| | @@ -150826,10 +151939,127 @@ |
| 150826 | 151939 | |
| 150827 | 151940 | end_auto_index_create: |
| 150828 | 151941 | sqlite3ExprDelete(pParse->db, pPartial); |
| 150829 | 151942 | } |
| 150830 | 151943 | #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */ |
| 151944 | + |
| 151945 | +/* |
| 151946 | +** Generate bytecode that will initialize a Bloom filter that is appropriate |
| 151947 | +** for pLevel. |
| 151948 | +** |
| 151949 | +** If there are inner loops within pLevel that have the WHERE_BLOOMFILTER |
| 151950 | +** flag set, initialize a Bloomfilter for them as well. Except don't do |
| 151951 | +** this recursive initialization if the SQLITE_BloomPulldown optimization has |
| 151952 | +** been turned off. |
| 151953 | +** |
| 151954 | +** When the Bloom filter is initialized, the WHERE_BLOOMFILTER flag is cleared |
| 151955 | +** from the loop, but the regFilter value is set to a register that implements |
| 151956 | +** the Bloom filter. When regFilter is positive, the |
| 151957 | +** sqlite3WhereCodeOneLoopStart() will generate code to test the Bloom filter |
| 151958 | +** and skip the subsequence B-Tree seek if the Bloom filter indicates that |
| 151959 | +** no matching rows exist. |
| 151960 | +** |
| 151961 | +** This routine may only be called if it has previously been determined that |
| 151962 | +** the loop would benefit from a Bloom filter, and the WHERE_BLOOMFILTER bit |
| 151963 | +** is set. |
| 151964 | +*/ |
| 151965 | +static SQLITE_NOINLINE void constructBloomFilter( |
| 151966 | + WhereInfo *pWInfo, /* The WHERE clause */ |
| 151967 | + int iLevel, /* Index in pWInfo->a[] that is pLevel */ |
| 151968 | + WhereLevel *pLevel, /* Make a Bloom filter for this FROM term */ |
| 151969 | + Bitmask notReady /* Loops that are not ready */ |
| 151970 | +){ |
| 151971 | + int addrOnce; /* Address of opening OP_Once */ |
| 151972 | + int addrTop; /* Address of OP_Rewind */ |
| 151973 | + int addrCont; /* Jump here to skip a row */ |
| 151974 | + const WhereTerm *pTerm; /* For looping over WHERE clause terms */ |
| 151975 | + const WhereTerm *pWCEnd; /* Last WHERE clause term */ |
| 151976 | + Parse *pParse = pWInfo->pParse; /* Parsing context */ |
| 151977 | + Vdbe *v = pParse->pVdbe; /* VDBE under construction */ |
| 151978 | + WhereLoop *pLoop = pLevel->pWLoop; /* The loop being coded */ |
| 151979 | + int iCur; /* Cursor for table getting the filter */ |
| 151980 | + |
| 151981 | + assert( pLoop!=0 ); |
| 151982 | + assert( v!=0 ); |
| 151983 | + assert( pLoop->wsFlags & WHERE_BLOOMFILTER ); |
| 151984 | + |
| 151985 | + addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v); |
| 151986 | + do{ |
| 151987 | + const SrcItem *pItem; |
| 151988 | + const Table *pTab; |
| 151989 | + u64 sz; |
| 151990 | + sqlite3WhereExplainBloomFilter(pParse, pWInfo, pLevel); |
| 151991 | + addrCont = sqlite3VdbeMakeLabel(pParse); |
| 151992 | + iCur = pLevel->iTabCur; |
| 151993 | + pLevel->regFilter = ++pParse->nMem; |
| 151994 | + |
| 151995 | + /* The Bloom filter is a Blob held in a register. Initialize it |
| 151996 | + ** to zero-filled blob of at least 80K bits, but maybe more if the |
| 151997 | + ** estimated size of the table is larger. We could actually |
| 151998 | + ** measure the size of the table at run-time using OP_Count with |
| 151999 | + ** P3==1 and use that value to initialize the blob. But that makes |
| 152000 | + ** testing complicated. By basing the blob size on the value in the |
| 152001 | + ** sqlite_stat1 table, testing is much easier. |
| 152002 | + */ |
| 152003 | + pItem = &pWInfo->pTabList->a[pLevel->iFrom]; |
| 152004 | + assert( pItem!=0 ); |
| 152005 | + pTab = pItem->pTab; |
| 152006 | + assert( pTab!=0 ); |
| 152007 | + sz = sqlite3LogEstToInt(pTab->nRowLogEst); |
| 152008 | + if( sz<10000 ){ |
| 152009 | + sz = 10000; |
| 152010 | + }else if( sz>10000000 ){ |
| 152011 | + sz = 10000000; |
| 152012 | + } |
| 152013 | + sqlite3VdbeAddOp2(v, OP_Blob, (int)sz, pLevel->regFilter); |
| 152014 | + |
| 152015 | + addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v); |
| 152016 | + pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm]; |
| 152017 | + for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){ |
| 152018 | + Expr *pExpr = pTerm->pExpr; |
| 152019 | + if( (pTerm->wtFlags & TERM_VIRTUAL)==0 |
| 152020 | + && sqlite3ExprIsTableConstant(pExpr, iCur) |
| 152021 | + ){ |
| 152022 | + sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL); |
| 152023 | + } |
| 152024 | + } |
| 152025 | + if( pLoop->wsFlags & WHERE_IPK ){ |
| 152026 | + int r1 = sqlite3GetTempReg(pParse); |
| 152027 | + sqlite3VdbeAddOp2(v, OP_Rowid, iCur, r1); |
| 152028 | + sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, r1, 1); |
| 152029 | + sqlite3ReleaseTempReg(pParse, r1); |
| 152030 | + }else{ |
| 152031 | + Index *pIdx = pLoop->u.btree.pIndex; |
| 152032 | + int n = pLoop->u.btree.nEq; |
| 152033 | + int r1 = sqlite3GetTempRange(pParse, n); |
| 152034 | + int jj; |
| 152035 | + for(jj=0; jj<n; jj++){ |
| 152036 | + int iCol = pIdx->aiColumn[jj]; |
| 152037 | + assert( pIdx->pTable==pItem->pTab ); |
| 152038 | + sqlite3ExprCodeGetColumnOfTable(v, pIdx->pTable, iCur, iCol,r1+jj); |
| 152039 | + } |
| 152040 | + sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, r1, n); |
| 152041 | + sqlite3ReleaseTempRange(pParse, r1, n); |
| 152042 | + } |
| 152043 | + sqlite3VdbeResolveLabel(v, addrCont); |
| 152044 | + sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); |
| 152045 | + VdbeCoverage(v); |
| 152046 | + sqlite3VdbeJumpHere(v, addrTop); |
| 152047 | + pLoop->wsFlags &= ~WHERE_BLOOMFILTER; |
| 152048 | + if( OptimizationDisabled(pParse->db, SQLITE_BloomPulldown) ) break; |
| 152049 | + while( iLevel < pWInfo->nLevel ){ |
| 152050 | + iLevel++; |
| 152051 | + pLevel = &pWInfo->a[iLevel]; |
| 152052 | + pLoop = pLevel->pWLoop; |
| 152053 | + if( pLoop==0 ) continue; |
| 152054 | + if( pLoop->prereq & notReady ) continue; |
| 152055 | + if( pLoop->wsFlags & WHERE_BLOOMFILTER ) break; |
| 152056 | + } |
| 152057 | + }while( iLevel < pWInfo->nLevel ); |
| 152058 | + sqlite3VdbeJumpHere(v, addrOnce); |
| 152059 | +} |
| 152060 | + |
| 150831 | 152061 | |
| 150832 | 152062 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 150833 | 152063 | /* |
| 150834 | 152064 | ** Allocate and populate an sqlite3_index_info structure. It is the |
| 150835 | 152065 | ** responsibility of the caller to eventually release the structure |
| | @@ -150864,10 +152094,11 @@ |
| 150864 | 152094 | testcase( pTerm->eOperator & WO_ISNULL ); |
| 150865 | 152095 | testcase( pTerm->eOperator & WO_IS ); |
| 150866 | 152096 | testcase( pTerm->eOperator & WO_ALL ); |
| 150867 | 152097 | if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue; |
| 150868 | 152098 | if( pTerm->wtFlags & TERM_VNULL ) continue; |
| 152099 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 150869 | 152100 | assert( pTerm->u.x.leftColumn>=(-1) ); |
| 150870 | 152101 | nTerm++; |
| 150871 | 152102 | } |
| 150872 | 152103 | |
| 150873 | 152104 | /* If the ORDER BY clause contains only columns in the current |
| | @@ -150924,10 +152155,11 @@ |
| 150924 | 152155 | if( (pSrc->fg.jointype & JT_LEFT)!=0 |
| 150925 | 152156 | && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) |
| 150926 | 152157 | ){ |
| 150927 | 152158 | continue; |
| 150928 | 152159 | } |
| 152160 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 150929 | 152161 | assert( pTerm->u.x.leftColumn>=(-1) ); |
| 150930 | 152162 | pIdxCons[j].iColumn = pTerm->u.x.leftColumn; |
| 150931 | 152163 | pIdxCons[j].iTermOffset = i; |
| 150932 | 152164 | op = pTerm->eOperator & WO_ALL; |
| 150933 | 152165 | if( op==WO_IN ) op = WO_EQ; |
| | @@ -151687,10 +152919,11 @@ |
| 151687 | 152919 | if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V'; |
| 151688 | 152920 | if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E'; |
| 151689 | 152921 | if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L'; |
| 151690 | 152922 | if( pTerm->wtFlags & TERM_CODED ) zType[3] = 'C'; |
| 151691 | 152923 | if( pTerm->eOperator & WO_SINGLE ){ |
| 152924 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 151692 | 152925 | sqlite3_snprintf(sizeof(zLeft),zLeft,"left={%d:%d}", |
| 151693 | 152926 | pTerm->leftCursor, pTerm->u.x.leftColumn); |
| 151694 | 152927 | }else if( (pTerm->eOperator & WO_OR)!=0 && pTerm->u.pOrInfo!=0 ){ |
| 151695 | 152928 | sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx", |
| 151696 | 152929 | pTerm->u.pOrInfo->indexable); |
| | @@ -151704,11 +152937,11 @@ |
| 151704 | 152937 | ** shown about each Term */ |
| 151705 | 152938 | if( sqlite3WhereTrace & 0x10000 ){ |
| 151706 | 152939 | sqlite3DebugPrintf(" prob=%-3d prereq=%llx,%llx", |
| 151707 | 152940 | pTerm->truthProb, (u64)pTerm->prereqAll, (u64)pTerm->prereqRight); |
| 151708 | 152941 | } |
| 151709 | | - if( pTerm->u.x.iField ){ |
| 152942 | + if( (pTerm->eOperator & (WO_OR|WO_AND))==0 && pTerm->u.x.iField ){ |
| 151710 | 152943 | sqlite3DebugPrintf(" iField=%d", pTerm->u.x.iField); |
| 151711 | 152944 | } |
| 151712 | 152945 | if( pTerm->iParent>=0 ){ |
| 151713 | 152946 | sqlite3DebugPrintf(" iParent=%d", pTerm->iParent); |
| 151714 | 152947 | } |
| | @@ -151766,13 +152999,13 @@ |
| 151766 | 152999 | } |
| 151767 | 153000 | sqlite3DebugPrintf(" %-19s", z); |
| 151768 | 153001 | sqlite3_free(z); |
| 151769 | 153002 | } |
| 151770 | 153003 | if( p->wsFlags & WHERE_SKIPSCAN ){ |
| 151771 | | - sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->nSkip); |
| 153004 | + sqlite3DebugPrintf(" f %06x %d-%d", p->wsFlags, p->nLTerm,p->nSkip); |
| 151772 | 153005 | }else{ |
| 151773 | | - sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm); |
| 153006 | + sqlite3DebugPrintf(" f %06x N %d", p->wsFlags, p->nLTerm); |
| 151774 | 153007 | } |
| 151775 | 153008 | sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut); |
| 151776 | 153009 | if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){ |
| 151777 | 153010 | int i; |
| 151778 | 153011 | for(i=0; i<p->nLTerm; i++){ |
| | @@ -151868,11 +153101,12 @@ |
| 151868 | 153101 | static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){ |
| 151869 | 153102 | int i; |
| 151870 | 153103 | assert( pWInfo!=0 ); |
| 151871 | 153104 | for(i=0; i<pWInfo->nLevel; i++){ |
| 151872 | 153105 | WhereLevel *pLevel = &pWInfo->a[i]; |
| 151873 | | - if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){ |
| 153106 | + if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE)!=0 ){ |
| 153107 | + assert( (pLevel->pWLoop->wsFlags & WHERE_MULTI_OR)==0 ); |
| 151874 | 153108 | sqlite3DbFree(db, pLevel->u.in.aInLoop); |
| 151875 | 153109 | } |
| 151876 | 153110 | } |
| 151877 | 153111 | sqlite3WhereClauseClear(&pWInfo->sWC); |
| 151878 | 153112 | while( pWInfo->pLoops ){ |
| | @@ -152227,22 +153461,29 @@ |
| 152227 | 153461 | Bitmask notAllowed = ~(pLoop->prereq|pLoop->maskSelf); |
| 152228 | 153462 | int i, j; |
| 152229 | 153463 | LogEst iReduce = 0; /* pLoop->nOut should not exceed nRow-iReduce */ |
| 152230 | 153464 | |
| 152231 | 153465 | assert( (pLoop->wsFlags & WHERE_AUTO_INDEX)==0 ); |
| 152232 | | - for(i=pWC->nTerm, pTerm=pWC->a; i>0; i--, pTerm++){ |
| 153466 | + for(i=pWC->nBase, pTerm=pWC->a; i>0; i--, pTerm++){ |
| 152233 | 153467 | assert( pTerm!=0 ); |
| 152234 | | - if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break; |
| 153468 | + if( (pTerm->prereqAll & notAllowed)!=0 ) continue; |
| 152235 | 153469 | if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue; |
| 152236 | | - if( (pTerm->prereqAll & notAllowed)!=0 ) continue; |
| 153470 | + if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) continue; |
| 152237 | 153471 | for(j=pLoop->nLTerm-1; j>=0; j--){ |
| 152238 | 153472 | pX = pLoop->aLTerm[j]; |
| 152239 | 153473 | if( pX==0 ) continue; |
| 152240 | 153474 | if( pX==pTerm ) break; |
| 152241 | 153475 | if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break; |
| 152242 | 153476 | } |
| 152243 | 153477 | if( j<0 ){ |
| 153478 | + if( pLoop->maskSelf==pTerm->prereqAll ){ |
| 153479 | + /* If there are extra terms in the WHERE clause not used by an index |
| 153480 | + ** that depend only on the table being scanned, and that will tend to |
| 153481 | + ** cause many rows to be omitted, then mark that table as |
| 153482 | + ** "self-culling". */ |
| 153483 | + pLoop->wsFlags |= WHERE_SELFCULL; |
| 153484 | + } |
| 152244 | 153485 | if( pTerm->truthProb<=0 ){ |
| 152245 | 153486 | /* If a truth probability is specified using the likelihood() hints, |
| 152246 | 153487 | ** then use the probability provided by the application. */ |
| 152247 | 153488 | pLoop->nOut += pTerm->truthProb; |
| 152248 | 153489 | }else{ |
| | @@ -152266,11 +153507,13 @@ |
| 152266 | 153507 | } |
| 152267 | 153508 | } |
| 152268 | 153509 | } |
| 152269 | 153510 | } |
| 152270 | 153511 | } |
| 152271 | | - if( pLoop->nOut > nRow-iReduce ) pLoop->nOut = nRow - iReduce; |
| 153512 | + if( pLoop->nOut > nRow-iReduce ){ |
| 153513 | + pLoop->nOut = nRow - iReduce; |
| 153514 | + } |
| 152272 | 153515 | } |
| 152273 | 153516 | |
| 152274 | 153517 | /* |
| 152275 | 153518 | ** Term pTerm is a vector range comparison operation. The first comparison |
| 152276 | 153519 | ** in the vector can be optimized using column nEq of the index. This |
| | @@ -152303,13 +153546,16 @@ |
| 152303 | 153546 | /* Test if comparison i of pTerm is compatible with column (i+nEq) |
| 152304 | 153547 | ** of the index. If not, exit the loop. */ |
| 152305 | 153548 | char aff; /* Comparison affinity */ |
| 152306 | 153549 | char idxaff = 0; /* Indexed columns affinity */ |
| 152307 | 153550 | CollSeq *pColl; /* Comparison collation sequence */ |
| 152308 | | - Expr *pLhs = pTerm->pExpr->pLeft->x.pList->a[i].pExpr; |
| 152309 | | - Expr *pRhs = pTerm->pExpr->pRight; |
| 152310 | | - if( pRhs->flags & EP_xIsSelect ){ |
| 153551 | + Expr *pLhs, *pRhs; |
| 153552 | + |
| 153553 | + assert( ExprUseXList(pTerm->pExpr->pLeft) ); |
| 153554 | + pLhs = pTerm->pExpr->pLeft->x.pList->a[i].pExpr; |
| 153555 | + pRhs = pTerm->pExpr->pRight; |
| 153556 | + if( ExprUseXSelect(pRhs) ){ |
| 152311 | 153557 | pRhs = pRhs->x.pSelect->pEList->a[i].pExpr; |
| 152312 | 153558 | }else{ |
| 152313 | 153559 | pRhs = pRhs->x.pList->a[i].pExpr; |
| 152314 | 153560 | } |
| 152315 | 153561 | |
| | @@ -152466,11 +153712,11 @@ |
| 152466 | 153712 | || (pNew->wsFlags & WHERE_SKIPSCAN)!=0 |
| 152467 | 153713 | ); |
| 152468 | 153714 | |
| 152469 | 153715 | if( eOp & WO_IN ){ |
| 152470 | 153716 | Expr *pExpr = pTerm->pExpr; |
| 152471 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 153717 | + if( ExprUseXSelect(pExpr) ){ |
| 152472 | 153718 | /* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */ |
| 152473 | 153719 | int i; |
| 152474 | 153720 | nIn = 46; assert( 46==sqlite3LogEst(25) ); |
| 152475 | 153721 | |
| 152476 | 153722 | /* The expression may actually be of the form (x, y) IN (SELECT...). |
| | @@ -152607,11 +153853,11 @@ |
| 152607 | 153853 | #ifdef SQLITE_ENABLE_STAT4 |
| 152608 | 153854 | tRowcnt nOut = 0; |
| 152609 | 153855 | if( nInMul==0 |
| 152610 | 153856 | && pProbe->nSample |
| 152611 | 153857 | && ALWAYS(pNew->u.btree.nEq<=pProbe->nSampleCol) |
| 152612 | | - && ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect)) |
| 153858 | + && ((eOp & WO_IN)==0 || ExprUseXList(pTerm->pExpr)) |
| 152613 | 153859 | && OptimizationEnabled(db, SQLITE_Stat4) |
| 152614 | 153860 | ){ |
| 152615 | 153861 | Expr *pExpr = pTerm->pExpr; |
| 152616 | 153862 | if( (eOp & (WO_EQ|WO_ISNULL|WO_IS))!=0 ){ |
| 152617 | 153863 | testcase( eOp & WO_EQ ); |
| | @@ -152883,10 +154129,11 @@ |
| 152883 | 154129 | pTab = pSrc->pTab; |
| 152884 | 154130 | pWC = pBuilder->pWC; |
| 152885 | 154131 | assert( !IsVirtual(pSrc->pTab) ); |
| 152886 | 154132 | |
| 152887 | 154133 | if( pSrc->fg.isIndexedBy ){ |
| 154134 | + assert( pSrc->fg.isCte==0 ); |
| 152888 | 154135 | /* An INDEXED BY clause specifies a particular index to use */ |
| 152889 | 154136 | pProbe = pSrc->u2.pIBIndex; |
| 152890 | 154137 | }else if( !HasRowid(pTab) ){ |
| 152891 | 154138 | pProbe = pTab->pIndex; |
| 152892 | 154139 | }else{ |
| | @@ -153498,10 +154745,11 @@ |
| 153498 | 154745 | }else if( pOrTerm->leftCursor==iCur ){ |
| 153499 | 154746 | tempWC.pWInfo = pWC->pWInfo; |
| 153500 | 154747 | tempWC.pOuter = pWC; |
| 153501 | 154748 | tempWC.op = TK_AND; |
| 153502 | 154749 | tempWC.nTerm = 1; |
| 154750 | + tempWC.nBase = 1; |
| 153503 | 154751 | tempWC.a = pOrTerm; |
| 153504 | 154752 | sSubBuild.pWC = &tempWC; |
| 153505 | 154753 | }else{ |
| 153506 | 154754 | continue; |
| 153507 | 154755 | } |
| | @@ -153969,11 +155217,11 @@ |
| 153969 | 155217 | } |
| 153970 | 155218 | } /* End the loop over all WhereLoops from outer-most down to inner-most */ |
| 153971 | 155219 | if( obSat==obDone ) return (i8)nOrderBy; |
| 153972 | 155220 | if( !isOrderDistinct ){ |
| 153973 | 155221 | for(i=nOrderBy-1; i>0; i--){ |
| 153974 | | - Bitmask m = MASKBIT(i) - 1; |
| 155222 | + Bitmask m = ALWAYS(i<BMS) ? MASKBIT(i) - 1 : 0; |
| 153975 | 155223 | if( (obSat&m)==m ) return i; |
| 153976 | 155224 | } |
| 153977 | 155225 | return 0; |
| 153978 | 155226 | } |
| 153979 | 155227 | return -1; |
| | @@ -154494,13 +155742,13 @@ |
| 154494 | 155742 | pWC = &pWInfo->sWC; |
| 154495 | 155743 | pLoop = pBuilder->pNew; |
| 154496 | 155744 | pLoop->wsFlags = 0; |
| 154497 | 155745 | pLoop->nSkip = 0; |
| 154498 | 155746 | pTerm = whereScanInit(&scan, pWC, iCur, -1, WO_EQ|WO_IS, 0); |
| 155747 | + while( pTerm && pTerm->prereqRight ) pTerm = whereScanNext(&scan); |
| 154499 | 155748 | if( pTerm ){ |
| 154500 | 155749 | testcase( pTerm->eOperator & WO_IS ); |
| 154501 | | - assert( pTerm->prereqRight==0 ); |
| 154502 | 155750 | pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW; |
| 154503 | 155751 | pLoop->aLTerm[0] = pTerm; |
| 154504 | 155752 | pLoop->nLTerm = 1; |
| 154505 | 155753 | pLoop->u.btree.nEq = 1; |
| 154506 | 155754 | /* TUNING: Cost of a rowid lookup is 10 */ |
| | @@ -154604,10 +155852,154 @@ |
| 154604 | 155852 | } |
| 154605 | 155853 | # define WHERETRACE_ALL_LOOPS(W,C) showAllWhereLoops(W,C) |
| 154606 | 155854 | #else |
| 154607 | 155855 | # define WHERETRACE_ALL_LOOPS(W,C) |
| 154608 | 155856 | #endif |
| 155857 | + |
| 155858 | +/* Attempt to omit tables from a join that do not affect the result. |
| 155859 | +** For a table to not affect the result, the following must be true: |
| 155860 | +** |
| 155861 | +** 1) The query must not be an aggregate. |
| 155862 | +** 2) The table must be the RHS of a LEFT JOIN. |
| 155863 | +** 3) Either the query must be DISTINCT, or else the ON or USING clause |
| 155864 | +** must contain a constraint that limits the scan of the table to |
| 155865 | +** at most a single row. |
| 155866 | +** 4) The table must not be referenced by any part of the query apart |
| 155867 | +** from its own USING or ON clause. |
| 155868 | +** |
| 155869 | +** For example, given: |
| 155870 | +** |
| 155871 | +** CREATE TABLE t1(ipk INTEGER PRIMARY KEY, v1); |
| 155872 | +** CREATE TABLE t2(ipk INTEGER PRIMARY KEY, v2); |
| 155873 | +** CREATE TABLE t3(ipk INTEGER PRIMARY KEY, v3); |
| 155874 | +** |
| 155875 | +** then table t2 can be omitted from the following: |
| 155876 | +** |
| 155877 | +** SELECT v1, v3 FROM t1 |
| 155878 | +** LEFT JOIN t2 ON (t1.ipk=t2.ipk) |
| 155879 | +** LEFT JOIN t3 ON (t1.ipk=t3.ipk) |
| 155880 | +** |
| 155881 | +** or from: |
| 155882 | +** |
| 155883 | +** SELECT DISTINCT v1, v3 FROM t1 |
| 155884 | +** LEFT JOIN t2 |
| 155885 | +** LEFT JOIN t3 ON (t1.ipk=t3.ipk) |
| 155886 | +*/ |
| 155887 | +static SQLITE_NOINLINE Bitmask whereOmitNoopJoin( |
| 155888 | + WhereInfo *pWInfo, |
| 155889 | + Bitmask notReady |
| 155890 | +){ |
| 155891 | + int i; |
| 155892 | + Bitmask tabUsed; |
| 155893 | + |
| 155894 | + /* Preconditions checked by the caller */ |
| 155895 | + assert( pWInfo->nLevel>=2 ); |
| 155896 | + assert( OptimizationEnabled(pWInfo->pParse->db, SQLITE_OmitNoopJoin) ); |
| 155897 | + |
| 155898 | + /* These two preconditions checked by the caller combine to guarantee |
| 155899 | + ** condition (1) of the header comment */ |
| 155900 | + assert( pWInfo->pResultSet!=0 ); |
| 155901 | + assert( 0==(pWInfo->wctrlFlags & WHERE_AGG_DISTINCT) ); |
| 155902 | + |
| 155903 | + tabUsed = sqlite3WhereExprListUsage(&pWInfo->sMaskSet, pWInfo->pResultSet); |
| 155904 | + if( pWInfo->pOrderBy ){ |
| 155905 | + tabUsed |= sqlite3WhereExprListUsage(&pWInfo->sMaskSet, pWInfo->pOrderBy); |
| 155906 | + } |
| 155907 | + for(i=pWInfo->nLevel-1; i>=1; i--){ |
| 155908 | + WhereTerm *pTerm, *pEnd; |
| 155909 | + SrcItem *pItem; |
| 155910 | + WhereLoop *pLoop; |
| 155911 | + pLoop = pWInfo->a[i].pWLoop; |
| 155912 | + pItem = &pWInfo->pTabList->a[pLoop->iTab]; |
| 155913 | + if( (pItem->fg.jointype & JT_LEFT)==0 ) continue; |
| 155914 | + if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)==0 |
| 155915 | + && (pLoop->wsFlags & WHERE_ONEROW)==0 |
| 155916 | + ){ |
| 155917 | + continue; |
| 155918 | + } |
| 155919 | + if( (tabUsed & pLoop->maskSelf)!=0 ) continue; |
| 155920 | + pEnd = pWInfo->sWC.a + pWInfo->sWC.nTerm; |
| 155921 | + for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){ |
| 155922 | + if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){ |
| 155923 | + if( !ExprHasProperty(pTerm->pExpr, EP_FromJoin) |
| 155924 | + || pTerm->pExpr->iRightJoinTable!=pItem->iCursor |
| 155925 | + ){ |
| 155926 | + break; |
| 155927 | + } |
| 155928 | + } |
| 155929 | + } |
| 155930 | + if( pTerm<pEnd ) continue; |
| 155931 | + WHERETRACE(0xffff, ("-> drop loop %c not used\n", pLoop->cId)); |
| 155932 | + notReady &= ~pLoop->maskSelf; |
| 155933 | + for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){ |
| 155934 | + if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){ |
| 155935 | + pTerm->wtFlags |= TERM_CODED; |
| 155936 | + } |
| 155937 | + } |
| 155938 | + if( i!=pWInfo->nLevel-1 ){ |
| 155939 | + int nByte = (pWInfo->nLevel-1-i) * sizeof(WhereLevel); |
| 155940 | + memmove(&pWInfo->a[i], &pWInfo->a[i+1], nByte); |
| 155941 | + } |
| 155942 | + pWInfo->nLevel--; |
| 155943 | + assert( pWInfo->nLevel>0 ); |
| 155944 | + } |
| 155945 | + return notReady; |
| 155946 | +} |
| 155947 | + |
| 155948 | +/* |
| 155949 | +** Check to see if there are any SEARCH loops that might benefit from |
| 155950 | +** using a Bloom filter. Consider a Bloom filter if: |
| 155951 | +** |
| 155952 | +** (1) The SEARCH happens more than N times where N is the number |
| 155953 | +** of rows in the table that is being considered for the Bloom |
| 155954 | +** filter. |
| 155955 | +** (2) Some searches are expected to find zero rows. (This is determined |
| 155956 | +** by the WHERE_SELFCULL flag on the term.) |
| 155957 | +** (3) Bloom-filter processing is not disabled. (Checked by the |
| 155958 | +** caller.) |
| 155959 | +** (4) The size of the table being searched is known by ANALYZE. |
| 155960 | +** |
| 155961 | +** This block of code merely checks to see if a Bloom filter would be |
| 155962 | +** appropriate, and if so sets the WHERE_BLOOMFILTER flag on the |
| 155963 | +** WhereLoop. The implementation of the Bloom filter comes further |
| 155964 | +** down where the code for each WhereLoop is generated. |
| 155965 | +*/ |
| 155966 | +static SQLITE_NOINLINE void whereCheckIfBloomFilterIsUseful( |
| 155967 | + const WhereInfo *pWInfo |
| 155968 | +){ |
| 155969 | + int i; |
| 155970 | + LogEst nSearch; |
| 155971 | + |
| 155972 | + assert( pWInfo->nLevel>=2 ); |
| 155973 | + assert( OptimizationEnabled(pWInfo->pParse->db, SQLITE_BloomFilter) ); |
| 155974 | + nSearch = pWInfo->a[0].pWLoop->nOut; |
| 155975 | + for(i=1; i<pWInfo->nLevel; i++){ |
| 155976 | + WhereLoop *pLoop = pWInfo->a[i].pWLoop; |
| 155977 | + const int reqFlags = (WHERE_SELFCULL|WHERE_COLUMN_EQ); |
| 155978 | + if( (pLoop->wsFlags & reqFlags)==reqFlags |
| 155979 | + /* vvvvvv--- Always the case if WHERE_COLUMN_EQ is defined */ |
| 155980 | + && ALWAYS((pLoop->wsFlags & (WHERE_IPK|WHERE_INDEXED))!=0) |
| 155981 | + ){ |
| 155982 | + SrcItem *pItem = &pWInfo->pTabList->a[pLoop->iTab]; |
| 155983 | + Table *pTab = pItem->pTab; |
| 155984 | + pTab->tabFlags |= TF_StatsUsed; |
| 155985 | + if( nSearch > pTab->nRowLogEst |
| 155986 | + && (pTab->tabFlags & TF_HasStat1)!=0 |
| 155987 | + ){ |
| 155988 | + testcase( pItem->fg.jointype & JT_LEFT ); |
| 155989 | + pLoop->wsFlags |= WHERE_BLOOMFILTER; |
| 155990 | + pLoop->wsFlags &= ~WHERE_IDX_ONLY; |
| 155991 | + WHERETRACE(0xffff, ( |
| 155992 | + "-> use Bloom-filter on loop %c because there are ~%.1e " |
| 155993 | + "lookups into %s which has only ~%.1e rows\n", |
| 155994 | + pLoop->cId, (double)sqlite3LogEstToInt(nSearch), pTab->zName, |
| 155995 | + (double)sqlite3LogEstToInt(pTab->nRowLogEst))); |
| 155996 | + } |
| 155997 | + } |
| 155998 | + nSearch += pLoop->nOut; |
| 155999 | + } |
| 156000 | +} |
| 154609 | 156001 | |
| 154610 | 156002 | /* |
| 154611 | 156003 | ** Generate the beginning of the loop used for WHERE clause processing. |
| 154612 | 156004 | ** The return value is a pointer to an opaque structure that contains |
| 154613 | 156005 | ** information needed to terminate the loop. Later, the calling routine |
| | @@ -154735,16 +156127,10 @@ |
| 154735 | 156127 | /* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */ |
| 154736 | 156128 | testcase( pOrderBy && pOrderBy->nExpr==BMS-1 ); |
| 154737 | 156129 | if( pOrderBy && pOrderBy->nExpr>=BMS ) pOrderBy = 0; |
| 154738 | 156130 | sWLB.pOrderBy = pOrderBy; |
| 154739 | 156131 | |
| 154740 | | - /* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via |
| 154741 | | - ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */ |
| 154742 | | - if( OptimizationDisabled(db, SQLITE_DistinctOpt) ){ |
| 154743 | | - wctrlFlags &= ~WHERE_WANT_DISTINCT; |
| 154744 | | - } |
| 154745 | | - |
| 154746 | 156132 | /* The number of tables in the FROM clause is limited by the number of |
| 154747 | 156133 | ** bits in a Bitmask |
| 154748 | 156134 | */ |
| 154749 | 156135 | testcase( pTabList->nSrc==BMS ); |
| 154750 | 156136 | if( pTabList->nSrc>BMS ){ |
| | @@ -154787,10 +156173,14 @@ |
| 154787 | 156173 | memset(&pWInfo->nOBSat, 0, |
| 154788 | 156174 | offsetof(WhereInfo,sWC) - offsetof(WhereInfo,nOBSat)); |
| 154789 | 156175 | memset(&pWInfo->a[0], 0, sizeof(WhereLoop)+nTabList*sizeof(WhereLevel)); |
| 154790 | 156176 | assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */ |
| 154791 | 156177 | pMaskSet = &pWInfo->sMaskSet; |
| 156178 | + pMaskSet->n = 0; |
| 156179 | + pMaskSet->ix[0] = -99; /* Initialize ix[0] to a value that can never be |
| 156180 | + ** a valid cursor number, to avoid an initial |
| 156181 | + ** test for pMaskSet->n==0 in sqlite3WhereGetMask() */ |
| 154792 | 156182 | sWLB.pWInfo = pWInfo; |
| 154793 | 156183 | sWLB.pWC = &pWInfo->sWC; |
| 154794 | 156184 | sWLB.pNew = (WhereLoop*)(((char*)pWInfo)+nByteWInfo); |
| 154795 | 156185 | assert( EIGHT_BYTE_ALIGNMENT(sWLB.pNew) ); |
| 154796 | 156186 | whereLoopInit(sWLB.pNew); |
| | @@ -154799,19 +156189,20 @@ |
| 154799 | 156189 | #endif |
| 154800 | 156190 | |
| 154801 | 156191 | /* Split the WHERE clause into separate subexpressions where each |
| 154802 | 156192 | ** subexpression is separated by an AND operator. |
| 154803 | 156193 | */ |
| 154804 | | - initMaskSet(pMaskSet); |
| 154805 | 156194 | sqlite3WhereClauseInit(&pWInfo->sWC, pWInfo); |
| 154806 | 156195 | sqlite3WhereSplit(&pWInfo->sWC, pWhere, TK_AND); |
| 154807 | 156196 | |
| 154808 | 156197 | /* Special case: No FROM clause |
| 154809 | 156198 | */ |
| 154810 | 156199 | if( nTabList==0 ){ |
| 154811 | 156200 | if( pOrderBy ) pWInfo->nOBSat = pOrderBy->nExpr; |
| 154812 | | - if( wctrlFlags & WHERE_WANT_DISTINCT ){ |
| 156201 | + if( (wctrlFlags & WHERE_WANT_DISTINCT)!=0 |
| 156202 | + && OptimizationEnabled(db, SQLITE_DistinctOpt) |
| 156203 | + ){ |
| 154813 | 156204 | pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE; |
| 154814 | 156205 | } |
| 154815 | 156206 | ExplainQueryPlan((pParse, 0, "SCAN CONSTANT ROW")); |
| 154816 | 156207 | }else{ |
| 154817 | 156208 | /* Assign a bit from the bitmask to every term in the FROM clause. |
| | @@ -154858,21 +156249,26 @@ |
| 154858 | 156249 | ** preserves SQLite's legacy behaviour in the following two cases: |
| 154859 | 156250 | ** |
| 154860 | 156251 | ** FROM ... WHERE random()>0; -- eval random() once per row |
| 154861 | 156252 | ** FROM ... WHERE (SELECT random())>0; -- eval random() once overall |
| 154862 | 156253 | */ |
| 154863 | | - for(ii=0; ii<sWLB.pWC->nTerm; ii++){ |
| 156254 | + for(ii=0; ii<sWLB.pWC->nBase; ii++){ |
| 154864 | 156255 | WhereTerm *pT = &sWLB.pWC->a[ii]; |
| 154865 | 156256 | if( pT->wtFlags & TERM_VIRTUAL ) continue; |
| 154866 | 156257 | if( pT->prereqAll==0 && (nTabList==0 || exprIsDeterministic(pT->pExpr)) ){ |
| 154867 | 156258 | sqlite3ExprIfFalse(pParse, pT->pExpr, pWInfo->iBreak, SQLITE_JUMPIFNULL); |
| 154868 | 156259 | pT->wtFlags |= TERM_CODED; |
| 154869 | 156260 | } |
| 154870 | 156261 | } |
| 154871 | 156262 | |
| 154872 | 156263 | if( wctrlFlags & WHERE_WANT_DISTINCT ){ |
| 154873 | | - if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){ |
| 156264 | + if( OptimizationDisabled(db, SQLITE_DistinctOpt) ){ |
| 156265 | + /* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via |
| 156266 | + ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */ |
| 156267 | + wctrlFlags &= ~WHERE_WANT_DISTINCT; |
| 156268 | + pWInfo->wctrlFlags &= ~WHERE_WANT_DISTINCT; |
| 156269 | + }else if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){ |
| 154874 | 156270 | /* The DISTINCT marking is pointless. Ignore it. */ |
| 154875 | 156271 | pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE; |
| 154876 | 156272 | }else if( pOrderBy==0 ){ |
| 154877 | 156273 | /* Try to ORDER BY the result set to make distinct processing easier */ |
| 154878 | 156274 | pWInfo->wctrlFlags |= WHERE_DISTINCTBY; |
| | @@ -154969,88 +156365,40 @@ |
| 154969 | 156365 | sqlite3WhereLoopPrint(pWInfo->a[ii].pWLoop, sWLB.pWC); |
| 154970 | 156366 | } |
| 154971 | 156367 | } |
| 154972 | 156368 | #endif |
| 154973 | 156369 | |
| 154974 | | - /* Attempt to omit tables from the join that do not affect the result. |
| 154975 | | - ** For a table to not affect the result, the following must be true: |
| 154976 | | - ** |
| 154977 | | - ** 1) The query must not be an aggregate. |
| 154978 | | - ** 2) The table must be the RHS of a LEFT JOIN. |
| 154979 | | - ** 3) Either the query must be DISTINCT, or else the ON or USING clause |
| 154980 | | - ** must contain a constraint that limits the scan of the table to |
| 154981 | | - ** at most a single row. |
| 154982 | | - ** 4) The table must not be referenced by any part of the query apart |
| 154983 | | - ** from its own USING or ON clause. |
| 154984 | | - ** |
| 154985 | | - ** For example, given: |
| 154986 | | - ** |
| 154987 | | - ** CREATE TABLE t1(ipk INTEGER PRIMARY KEY, v1); |
| 154988 | | - ** CREATE TABLE t2(ipk INTEGER PRIMARY KEY, v2); |
| 154989 | | - ** CREATE TABLE t3(ipk INTEGER PRIMARY KEY, v3); |
| 154990 | | - ** |
| 154991 | | - ** then table t2 can be omitted from the following: |
| 154992 | | - ** |
| 154993 | | - ** SELECT v1, v3 FROM t1 |
| 154994 | | - ** LEFT JOIN t2 ON (t1.ipk=t2.ipk) |
| 154995 | | - ** LEFT JOIN t3 ON (t1.ipk=t3.ipk) |
| 154996 | | - ** |
| 154997 | | - ** or from: |
| 154998 | | - ** |
| 154999 | | - ** SELECT DISTINCT v1, v3 FROM t1 |
| 155000 | | - ** LEFT JOIN t2 |
| 155001 | | - ** LEFT JOIN t3 ON (t1.ipk=t3.ipk) |
| 156370 | + /* Attempt to omit tables from a join that do not affect the result. |
| 156371 | + ** See the comment on whereOmitNoopJoin() for further information. |
| 156372 | + ** |
| 156373 | + ** This query optimization is factored out into a separate "no-inline" |
| 156374 | + ** procedure to keep the sqlite3WhereBegin() procedure from becoming |
| 156375 | + ** too large. If sqlite3WhereBegin() becomes too large, that prevents |
| 156376 | + ** some C-compiler optimizers from in-lining the |
| 156377 | + ** sqlite3WhereCodeOneLoopStart() procedure, and it is important to |
| 156378 | + ** in-line sqlite3WhereCodeOneLoopStart() for performance reasons. |
| 155002 | 156379 | */ |
| 155003 | 156380 | notReady = ~(Bitmask)0; |
| 155004 | 156381 | if( pWInfo->nLevel>=2 |
| 155005 | 156382 | && pResultSet!=0 /* these two combine to guarantee */ |
| 155006 | 156383 | && 0==(wctrlFlags & WHERE_AGG_DISTINCT) /* condition (1) above */ |
| 155007 | 156384 | && OptimizationEnabled(db, SQLITE_OmitNoopJoin) |
| 155008 | 156385 | ){ |
| 155009 | | - int i; |
| 155010 | | - Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet); |
| 155011 | | - if( sWLB.pOrderBy ){ |
| 155012 | | - tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy); |
| 155013 | | - } |
| 155014 | | - for(i=pWInfo->nLevel-1; i>=1; i--){ |
| 155015 | | - WhereTerm *pTerm, *pEnd; |
| 155016 | | - SrcItem *pItem; |
| 155017 | | - pLoop = pWInfo->a[i].pWLoop; |
| 155018 | | - pItem = &pWInfo->pTabList->a[pLoop->iTab]; |
| 155019 | | - if( (pItem->fg.jointype & JT_LEFT)==0 ) continue; |
| 155020 | | - if( (wctrlFlags & WHERE_WANT_DISTINCT)==0 |
| 155021 | | - && (pLoop->wsFlags & WHERE_ONEROW)==0 |
| 155022 | | - ){ |
| 155023 | | - continue; |
| 155024 | | - } |
| 155025 | | - if( (tabUsed & pLoop->maskSelf)!=0 ) continue; |
| 155026 | | - pEnd = sWLB.pWC->a + sWLB.pWC->nTerm; |
| 155027 | | - for(pTerm=sWLB.pWC->a; pTerm<pEnd; pTerm++){ |
| 155028 | | - if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){ |
| 155029 | | - if( !ExprHasProperty(pTerm->pExpr, EP_FromJoin) |
| 155030 | | - || pTerm->pExpr->iRightJoinTable!=pItem->iCursor |
| 155031 | | - ){ |
| 155032 | | - break; |
| 155033 | | - } |
| 155034 | | - } |
| 155035 | | - } |
| 155036 | | - if( pTerm<pEnd ) continue; |
| 155037 | | - WHERETRACE(0xffff, ("-> drop loop %c not used\n", pLoop->cId)); |
| 155038 | | - notReady &= ~pLoop->maskSelf; |
| 155039 | | - for(pTerm=sWLB.pWC->a; pTerm<pEnd; pTerm++){ |
| 155040 | | - if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){ |
| 155041 | | - pTerm->wtFlags |= TERM_CODED; |
| 155042 | | - } |
| 155043 | | - } |
| 155044 | | - if( i!=pWInfo->nLevel-1 ){ |
| 155045 | | - int nByte = (pWInfo->nLevel-1-i) * sizeof(WhereLevel); |
| 155046 | | - memmove(&pWInfo->a[i], &pWInfo->a[i+1], nByte); |
| 155047 | | - } |
| 155048 | | - pWInfo->nLevel--; |
| 155049 | | - nTabList--; |
| 155050 | | - } |
| 155051 | | - } |
| 156386 | + notReady = whereOmitNoopJoin(pWInfo, notReady); |
| 156387 | + nTabList = pWInfo->nLevel; |
| 156388 | + assert( nTabList>0 ); |
| 156389 | + } |
| 156390 | + |
| 156391 | + /* Check to see if there are any SEARCH loops that might benefit from |
| 156392 | + ** using a Bloom filter. |
| 156393 | + */ |
| 156394 | + if( pWInfo->nLevel>=2 |
| 156395 | + && OptimizationEnabled(db, SQLITE_BloomFilter) |
| 156396 | + ){ |
| 156397 | + whereCheckIfBloomFilterIsUseful(pWInfo); |
| 156398 | + } |
| 156399 | + |
| 155052 | 156400 | #if defined(WHERETRACE_ENABLED) |
| 155053 | 156401 | if( sqlite3WhereTrace & 0x100 ){ /* Display all terms of the WHERE clause */ |
| 155054 | 156402 | sqlite3DebugPrintf("---- WHERE clause at end of analysis:\n"); |
| 155055 | 156403 | sqlite3WhereClausePrint(sWLB.pWC); |
| 155056 | 156404 | } |
| | @@ -155232,19 +156580,24 @@ |
| 155232 | 156580 | ** program. |
| 155233 | 156581 | */ |
| 155234 | 156582 | for(ii=0; ii<nTabList; ii++){ |
| 155235 | 156583 | int addrExplain; |
| 155236 | 156584 | int wsFlags; |
| 156585 | + if( pParse->nErr ) goto whereBeginError; |
| 155237 | 156586 | pLevel = &pWInfo->a[ii]; |
| 155238 | 156587 | wsFlags = pLevel->pWLoop->wsFlags; |
| 156588 | + if( (wsFlags & (WHERE_AUTO_INDEX|WHERE_BLOOMFILTER))!=0 ){ |
| 156589 | + if( (wsFlags & WHERE_AUTO_INDEX)!=0 ){ |
| 155239 | 156590 | #ifndef SQLITE_OMIT_AUTOMATIC_INDEX |
| 155240 | | - if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){ |
| 155241 | | - constructAutomaticIndex(pParse, &pWInfo->sWC, |
| 155242 | | - &pTabList->a[pLevel->iFrom], notReady, pLevel); |
| 156591 | + constructAutomaticIndex(pParse, &pWInfo->sWC, |
| 156592 | + &pTabList->a[pLevel->iFrom], notReady, pLevel); |
| 156593 | +#endif |
| 156594 | + }else{ |
| 156595 | + constructBloomFilter(pWInfo, ii, pLevel, notReady); |
| 156596 | + } |
| 155243 | 156597 | if( db->mallocFailed ) goto whereBeginError; |
| 155244 | 156598 | } |
| 155245 | | -#endif |
| 155246 | 156599 | addrExplain = sqlite3WhereExplainOneScan( |
| 155247 | 156600 | pParse, pTabList, pLevel, wctrlFlags |
| 155248 | 156601 | ); |
| 155249 | 156602 | pLevel->addrBody = sqlite3VdbeCurrentAddr(v); |
| 155250 | 156603 | notReady = sqlite3WhereCodeOneLoopStart(pParse,v,pWInfo,ii,pLevel,notReady); |
| | @@ -155353,11 +156706,11 @@ |
| 155353 | 156706 | if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek); |
| 155354 | 156707 | #endif |
| 155355 | 156708 | }else{ |
| 155356 | 156709 | sqlite3VdbeResolveLabel(v, pLevel->addrCont); |
| 155357 | 156710 | } |
| 155358 | | - if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){ |
| 156711 | + if( (pLoop->wsFlags & WHERE_IN_ABLE)!=0 && pLevel->u.in.nIn>0 ){ |
| 155359 | 156712 | struct InLoop *pIn; |
| 155360 | 156713 | int j; |
| 155361 | 156714 | sqlite3VdbeResolveLabel(v, pLevel->addrNxt); |
| 155362 | 156715 | for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){ |
| 155363 | 156716 | assert( sqlite3VdbeGetOp(v, pIn->addrInTop+1)->opcode==OP_IsNull |
| | @@ -155422,14 +156775,14 @@ |
| 155422 | 156775 | if( (ws & WHERE_IDX_ONLY)==0 ){ |
| 155423 | 156776 | assert( pLevel->iTabCur==pTabList->a[pLevel->iFrom].iCursor ); |
| 155424 | 156777 | sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur); |
| 155425 | 156778 | } |
| 155426 | 156779 | if( (ws & WHERE_INDEXED) |
| 155427 | | - || ((ws & WHERE_MULTI_OR) && pLevel->u.pCovidx) |
| 156780 | + || ((ws & WHERE_MULTI_OR) && pLevel->u.pCoveringIdx) |
| 155428 | 156781 | ){ |
| 155429 | 156782 | if( ws & WHERE_MULTI_OR ){ |
| 155430 | | - Index *pIx = pLevel->u.pCovidx; |
| 156783 | + Index *pIx = pLevel->u.pCoveringIdx; |
| 155431 | 156784 | int iDb = sqlite3SchemaToIndex(db, pIx->pSchema); |
| 155432 | 156785 | sqlite3VdbeAddOp3(v, OP_ReopenIdx, pLevel->iIdxCur, pIx->tnum, iDb); |
| 155433 | 156786 | sqlite3VdbeSetP4KeyInfo(pParse, pIx); |
| 155434 | 156787 | } |
| 155435 | 156788 | sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur); |
| | @@ -155506,11 +156859,11 @@ |
| 155506 | 156859 | ** reference the index. |
| 155507 | 156860 | */ |
| 155508 | 156861 | if( pLoop->wsFlags & (WHERE_INDEXED|WHERE_IDX_ONLY) ){ |
| 155509 | 156862 | pIdx = pLoop->u.btree.pIndex; |
| 155510 | 156863 | }else if( pLoop->wsFlags & WHERE_MULTI_OR ){ |
| 155511 | | - pIdx = pLevel->u.pCovidx; |
| 156864 | + pIdx = pLevel->u.pCoveringIdx; |
| 155512 | 156865 | } |
| 155513 | 156866 | if( pIdx |
| 155514 | 156867 | && !db->mallocFailed |
| 155515 | 156868 | ){ |
| 155516 | 156869 | if( pWInfo->eOnePass==ONEPASS_OFF || !HasRowid(pIdx->pTable) ){ |
| | @@ -156167,28 +157520,28 @@ |
| 156167 | 157520 | static void noopValueFunc(sqlite3_context *p){ UNUSED_PARAMETER(p); /*no-op*/ } |
| 156168 | 157521 | |
| 156169 | 157522 | /* Window functions that use all window interfaces: xStep, xFinal, |
| 156170 | 157523 | ** xValue, and xInverse */ |
| 156171 | 157524 | #define WINDOWFUNCALL(name,nArg,extra) { \ |
| 156172 | | - nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \ |
| 157525 | + nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \ |
| 156173 | 157526 | name ## StepFunc, name ## FinalizeFunc, name ## ValueFunc, \ |
| 156174 | 157527 | name ## InvFunc, name ## Name, {0} \ |
| 156175 | 157528 | } |
| 156176 | 157529 | |
| 156177 | 157530 | /* Window functions that are implemented using bytecode and thus have |
| 156178 | 157531 | ** no-op routines for their methods */ |
| 156179 | 157532 | #define WINDOWFUNCNOOP(name,nArg,extra) { \ |
| 156180 | | - nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \ |
| 157533 | + nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \ |
| 156181 | 157534 | noopStepFunc, noopValueFunc, noopValueFunc, \ |
| 156182 | 157535 | noopStepFunc, name ## Name, {0} \ |
| 156183 | 157536 | } |
| 156184 | 157537 | |
| 156185 | 157538 | /* Window functions that use all window interfaces: xStep, the |
| 156186 | 157539 | ** same routine for xFinalize and xValue and which never call |
| 156187 | 157540 | ** xInverse. */ |
| 156188 | 157541 | #define WINDOWFUNCX(name,nArg,extra) { \ |
| 156189 | | - nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \ |
| 157542 | + nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \ |
| 156190 | 157543 | name ## StepFunc, name ## ValueFunc, name ## ValueFunc, \ |
| 156191 | 157544 | noopStepFunc, name ## Name, {0} \ |
| 156192 | 157545 | } |
| 156193 | 157546 | |
| 156194 | 157547 | |
| | @@ -156527,11 +157880,12 @@ |
| 156527 | 157880 | return WRC_Continue; |
| 156528 | 157881 | } |
| 156529 | 157882 | |
| 156530 | 157883 | static int disallowAggregatesInOrderByCb(Walker *pWalker, Expr *pExpr){ |
| 156531 | 157884 | if( pExpr->op==TK_AGG_FUNCTION && pExpr->pAggInfo==0 ){ |
| 156532 | | - sqlite3ErrorMsg(pWalker->pParse, |
| 157885 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 157886 | + sqlite3ErrorMsg(pWalker->pParse, |
| 156533 | 157887 | "misuse of aggregate: %s()", pExpr->u.zToken); |
| 156534 | 157888 | } |
| 156535 | 157889 | return WRC_Continue; |
| 156536 | 157890 | } |
| 156537 | 157891 | |
| | @@ -156615,11 +157969,13 @@ |
| 156615 | 157969 | /* Append the arguments passed to each window function to the |
| 156616 | 157970 | ** sub-select expression list. Also allocate two registers for each |
| 156617 | 157971 | ** window function - one for the accumulator, another for interim |
| 156618 | 157972 | ** results. */ |
| 156619 | 157973 | for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ |
| 156620 | | - ExprList *pArgs = pWin->pOwner->x.pList; |
| 157974 | + ExprList *pArgs; |
| 157975 | + assert( ExprUseXList(pWin->pOwner) ); |
| 157976 | + pArgs = pWin->pOwner->x.pList; |
| 156621 | 157977 | if( pWin->pFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){ |
| 156622 | 157978 | selectWindowRewriteEList(pParse, pMWin, pSrc, pArgs, pTab, &pSublist); |
| 156623 | 157979 | pWin->iArgCol = (pSublist ? pSublist->nExpr : 0); |
| 156624 | 157980 | pWin->bExprArgs = 1; |
| 156625 | 157981 | }else{ |
| | @@ -156682,11 +158038,15 @@ |
| 156682 | 158038 | } |
| 156683 | 158039 | }else{ |
| 156684 | 158040 | sqlite3SelectDelete(db, pSub); |
| 156685 | 158041 | } |
| 156686 | 158042 | if( db->mallocFailed ) rc = SQLITE_NOMEM; |
| 156687 | | - sqlite3DbFree(db, pTab); |
| 158043 | + |
| 158044 | + /* Defer deleting the temporary table pTab because if an error occurred, |
| 158045 | + ** there could still be references to that table embedded in the |
| 158046 | + ** result-set or ORDER BY clause of the SELECT statement p. */ |
| 158047 | + sqlite3ParserAddCleanup(pParse, sqlite3DbFree, pTab); |
| 156688 | 158048 | } |
| 156689 | 158049 | |
| 156690 | 158050 | if( rc ){ |
| 156691 | 158051 | if( pParse->nErr==0 ){ |
| 156692 | 158052 | assert( pParse->db->mallocFailed ); |
| | @@ -157008,12 +158368,15 @@ |
| 157008 | 158368 | ** |
| 157009 | 158369 | ** regApp+0: slot to copy min()/max() argument to for MakeRecord |
| 157010 | 158370 | ** regApp+1: integer value used to ensure keys are unique |
| 157011 | 158371 | ** regApp+2: output of MakeRecord |
| 157012 | 158372 | */ |
| 157013 | | - ExprList *pList = pWin->pOwner->x.pList; |
| 157014 | | - KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0); |
| 158373 | + ExprList *pList; |
| 158374 | + KeyInfo *pKeyInfo; |
| 158375 | + assert( ExprUseXList(pWin->pOwner) ); |
| 158376 | + pList = pWin->pOwner->x.pList; |
| 158377 | + pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0); |
| 157015 | 158378 | pWin->csrApp = pParse->nTab++; |
| 157016 | 158379 | pWin->regApp = pParse->nMem+1; |
| 157017 | 158380 | pParse->nMem += 3; |
| 157018 | 158381 | if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){ |
| 157019 | 158382 | assert( pKeyInfo->aSortFlags[0]==0 ); |
| | @@ -157097,11 +158460,13 @@ |
| 157097 | 158460 | /* |
| 157098 | 158461 | ** Return the number of arguments passed to the window-function associated |
| 157099 | 158462 | ** with the object passed as the only argument to this function. |
| 157100 | 158463 | */ |
| 157101 | 158464 | static int windowArgCount(Window *pWin){ |
| 157102 | | - ExprList *pList = pWin->pOwner->x.pList; |
| 158465 | + const ExprList *pList; |
| 158466 | + assert( ExprUseXList(pWin->pOwner) ); |
| 158467 | + pList = pWin->pOwner->x.pList; |
| 157103 | 158468 | return (pList ? pList->nExpr : 0); |
| 157104 | 158469 | } |
| 157105 | 158470 | |
| 157106 | 158471 | typedef struct WindowCodeArg WindowCodeArg; |
| 157107 | 158472 | typedef struct WindowCsrAndReg WindowCsrAndReg; |
| | @@ -157282,10 +158647,11 @@ |
| 157282 | 158647 | sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1); |
| 157283 | 158648 | }else if( pFunc->xSFunc!=noopStepFunc ){ |
| 157284 | 158649 | int addrIf = 0; |
| 157285 | 158650 | if( pWin->pFilter ){ |
| 157286 | 158651 | int regTmp; |
| 158652 | + assert( ExprUseXList(pWin->pOwner) ); |
| 157287 | 158653 | assert( pWin->bExprArgs || !nArg ||nArg==pWin->pOwner->x.pList->nExpr ); |
| 157288 | 158654 | assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 ); |
| 157289 | 158655 | regTmp = sqlite3GetTempReg(pParse); |
| 157290 | 158656 | sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp); |
| 157291 | 158657 | addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1); |
| | @@ -157295,10 +158661,11 @@ |
| 157295 | 158661 | |
| 157296 | 158662 | if( pWin->bExprArgs ){ |
| 157297 | 158663 | int iOp = sqlite3VdbeCurrentAddr(v); |
| 157298 | 158664 | int iEnd; |
| 157299 | 158665 | |
| 158666 | + assert( ExprUseXList(pWin->pOwner) ); |
| 157300 | 158667 | nArg = pWin->pOwner->x.pList->nExpr; |
| 157301 | 158668 | regArg = sqlite3GetTempRange(pParse, nArg); |
| 157302 | 158669 | sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0); |
| 157303 | 158670 | |
| 157304 | 158671 | for(iEnd=sqlite3VdbeCurrentAddr(v); iOp<iEnd; iOp++){ |
| | @@ -157309,10 +158676,11 @@ |
| 157309 | 158676 | } |
| 157310 | 158677 | } |
| 157311 | 158678 | if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 157312 | 158679 | CollSeq *pColl; |
| 157313 | 158680 | assert( nArg>0 ); |
| 158681 | + assert( ExprUseXList(pWin->pOwner) ); |
| 157314 | 158682 | pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr); |
| 157315 | 158683 | sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ); |
| 157316 | 158684 | } |
| 157317 | 158685 | sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep, |
| 157318 | 158686 | bInverse, regArg, pWin->regAccum); |
| | @@ -157494,10 +158862,11 @@ |
| 157494 | 158862 | Parse *pParse = p->pParse; |
| 157495 | 158863 | Window *pWin; |
| 157496 | 158864 | |
| 157497 | 158865 | for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ |
| 157498 | 158866 | FuncDef *pFunc = pWin->pFunc; |
| 158867 | + assert( ExprUseXList(pWin->pOwner) ); |
| 157499 | 158868 | if( pFunc->zName==nth_valueName |
| 157500 | 158869 | || pFunc->zName==first_valueName |
| 157501 | 158870 | ){ |
| 157502 | 158871 | int csr = pWin->csrApp; |
| 157503 | 158872 | int lbl = sqlite3VdbeMakeLabel(pParse); |
| | @@ -158843,13 +160212,13 @@ |
| 158843 | 160212 | p->affExpr = 0; |
| 158844 | 160213 | p->flags = EP_Leaf; |
| 158845 | 160214 | ExprClearVVAProperties(p); |
| 158846 | 160215 | p->iAgg = -1; |
| 158847 | 160216 | p->pLeft = p->pRight = 0; |
| 158848 | | - p->x.pList = 0; |
| 158849 | 160217 | p->pAggInfo = 0; |
| 158850 | | - p->y.pTab = 0; |
| 160218 | + memset(&p->x, 0, sizeof(p->x)); |
| 160219 | + memset(&p->y, 0, sizeof(p->y)); |
| 158851 | 160220 | p->op2 = 0; |
| 158852 | 160221 | p->iTable = 0; |
| 158853 | 160222 | p->iColumn = 0; |
| 158854 | 160223 | p->u.zToken = (char*)&p[1]; |
| 158855 | 160224 | memcpy(p->u.zToken, t.z, t.n); |
| | @@ -158951,14 +160320,14 @@ |
| 158951 | 160320 | #define TK_DETACH 40 |
| 158952 | 160321 | #define TK_EACH 41 |
| 158953 | 160322 | #define TK_FAIL 42 |
| 158954 | 160323 | #define TK_OR 43 |
| 158955 | 160324 | #define TK_AND 44 |
| 158956 | | -#define TK_IS 45 |
| 158957 | | -#define TK_MATCH 46 |
| 158958 | | -#define TK_LIKE_KW 47 |
| 158959 | | -#define TK_BETWEEN 48 |
| 160325 | +#define TK_MATCH 45 |
| 160326 | +#define TK_LIKE_KW 46 |
| 160327 | +#define TK_BETWEEN 47 |
| 160328 | +#define TK_IS 48 |
| 158960 | 160329 | #define TK_IN 49 |
| 158961 | 160330 | #define TK_ISNULL 50 |
| 158962 | 160331 | #define TK_NOTNULL 51 |
| 158963 | 160332 | #define TK_NE 52 |
| 158964 | 160333 | #define TK_EQ 53 |
| | @@ -159266,216 +160635,215 @@ |
| 159266 | 160635 | ** yy_reduce_ofst[] For each state, the offset into yy_action for |
| 159267 | 160636 | ** shifting non-terminals after a reduce. |
| 159268 | 160637 | ** yy_default[] Default action for each state. |
| 159269 | 160638 | ** |
| 159270 | 160639 | *********** Begin parsing tables **********************************************/ |
| 159271 | | -#define YY_ACTTAB_COUNT (2037) |
| 160640 | +#define YY_ACTTAB_COUNT (2022) |
| 159272 | 160641 | static const YYACTIONTYPE yy_action[] = { |
| 159273 | 160642 | /* 0 */ 564, 115, 112, 220, 169, 199, 115, 112, 220, 564, |
| 159274 | 160643 | /* 10 */ 375, 1266, 564, 376, 564, 270, 1309, 1309, 406, 407, |
| 159275 | 160644 | /* 20 */ 1084, 199, 1513, 41, 41, 515, 489, 521, 558, 558, |
| 159276 | 160645 | /* 30 */ 558, 965, 41, 41, 395, 41, 41, 51, 51, 966, |
| 159277 | | - /* 40 */ 296, 1269, 296, 122, 123, 113, 1207, 1207, 1041, 1044, |
| 160646 | + /* 40 */ 296, 1269, 296, 122, 123, 1207, 1207, 1041, 113, 1044, |
| 159278 | 160647 | /* 50 */ 1034, 1034, 120, 120, 121, 121, 121, 121, 564, 407, |
| 159279 | 160648 | /* 60 */ 275, 275, 275, 275, 1268, 115, 112, 220, 115, 112, |
| 159280 | 160649 | /* 70 */ 220, 1512, 846, 561, 516, 561, 115, 112, 220, 250, |
| 159281 | | - /* 80 */ 217, 71, 71, 122, 123, 113, 1207, 1207, 1041, 1044, |
| 160650 | + /* 80 */ 217, 71, 71, 122, 123, 1207, 1207, 1041, 113, 1044, |
| 159282 | 160651 | /* 90 */ 1034, 1034, 120, 120, 121, 121, 121, 121, 440, 440, |
| 159283 | 160652 | /* 100 */ 440, 1149, 119, 119, 119, 119, 118, 118, 117, 117, |
| 159284 | 160653 | /* 110 */ 117, 116, 442, 1183, 1149, 116, 442, 1149, 546, 513, |
| 159285 | | - /* 120 */ 1548, 1554, 374, 442, 6, 1183, 1154, 522, 1154, 407, |
| 160654 | + /* 120 */ 1548, 1554, 374, 213, 6, 169, 1154, 522, 1154, 407, |
| 159286 | 160655 | /* 130 */ 1556, 461, 373, 1554, 535, 99, 463, 332, 121, 121, |
| 159287 | 160656 | /* 140 */ 121, 121, 119, 119, 119, 119, 118, 118, 117, 117, |
| 159288 | | - /* 150 */ 117, 116, 442, 122, 123, 113, 1207, 1207, 1041, 1044, |
| 160657 | + /* 150 */ 117, 116, 442, 122, 123, 1207, 1207, 1041, 113, 1044, |
| 159289 | 160658 | /* 160 */ 1034, 1034, 120, 120, 121, 121, 121, 121, 1257, 1183, |
| 159290 | 160659 | /* 170 */ 1184, 1185, 243, 1064, 564, 502, 499, 498, 567, 124, |
| 159291 | | - /* 180 */ 567, 1183, 1184, 1185, 474, 497, 119, 119, 119, 119, |
| 160660 | + /* 180 */ 567, 1128, 1627, 344, 1627, 497, 119, 119, 119, 119, |
| 159292 | 160661 | /* 190 */ 118, 118, 117, 117, 117, 116, 442, 70, 70, 407, |
| 159293 | 160662 | /* 200 */ 121, 121, 121, 121, 114, 117, 117, 117, 116, 442, |
| 159294 | | - /* 210 */ 1409, 1469, 119, 119, 119, 119, 118, 118, 117, 117, |
| 159295 | | - /* 220 */ 117, 116, 442, 122, 123, 113, 1207, 1207, 1041, 1044, |
| 159296 | | - /* 230 */ 1034, 1034, 120, 120, 121, 121, 121, 121, 407, 1031, |
| 159297 | | - /* 240 */ 1031, 1042, 1045, 81, 382, 541, 378, 80, 119, 119, |
| 160663 | + /* 210 */ 474, 1469, 119, 119, 119, 119, 118, 118, 117, 117, |
| 160664 | + /* 220 */ 117, 116, 442, 122, 123, 1207, 1207, 1041, 113, 1044, |
| 160665 | + /* 230 */ 1034, 1034, 120, 120, 121, 121, 121, 121, 407, 208, |
| 160666 | + /* 240 */ 539, 1548, 1424, 81, 339, 6, 342, 80, 119, 119, |
| 159298 | 160667 | /* 250 */ 119, 119, 118, 118, 117, 117, 117, 116, 442, 381, |
| 159299 | | - /* 260 */ 463, 332, 122, 123, 113, 1207, 1207, 1041, 1044, 1034, |
| 159300 | | - /* 270 */ 1034, 120, 120, 121, 121, 121, 121, 262, 215, 512, |
| 159301 | | - /* 280 */ 1424, 422, 119, 119, 119, 119, 118, 118, 117, 117, |
| 160668 | + /* 260 */ 1126, 442, 122, 123, 1207, 1207, 1041, 113, 1044, 1034, |
| 160669 | + /* 270 */ 1034, 120, 120, 121, 121, 121, 121, 262, 463, 332, |
| 160670 | + /* 280 */ 359, 1567, 119, 119, 119, 119, 118, 118, 117, 117, |
| 159302 | 160671 | /* 290 */ 117, 116, 442, 1231, 1, 1, 571, 2, 1235, 1573, |
| 159303 | | - /* 300 */ 571, 2, 1235, 307, 1149, 141, 1600, 307, 407, 141, |
| 159304 | | - /* 310 */ 1183, 361, 1317, 1035, 866, 531, 1317, 1149, 359, 1567, |
| 160672 | + /* 300 */ 571, 2, 1235, 307, 1149, 141, 417, 307, 407, 141, |
| 160673 | + /* 310 */ 1183, 98, 1317, 489, 866, 531, 1317, 1149, 215, 512, |
| 159305 | 160674 | /* 320 */ 1149, 119, 119, 119, 119, 118, 118, 117, 117, 117, |
| 159306 | | - /* 330 */ 116, 442, 122, 123, 113, 1207, 1207, 1041, 1044, 1034, |
| 160675 | + /* 330 */ 116, 442, 122, 123, 1207, 1207, 1041, 113, 1044, 1034, |
| 159307 | 160676 | /* 340 */ 1034, 120, 120, 121, 121, 121, 121, 275, 275, 1001, |
| 159308 | | - /* 350 */ 426, 275, 275, 1128, 1627, 1021, 1627, 137, 542, 1541, |
| 159309 | | - /* 360 */ 561, 272, 950, 950, 561, 1423, 1183, 1184, 1185, 1594, |
| 159310 | | - /* 370 */ 866, 1012, 530, 315, 231, 1011, 468, 1276, 231, 119, |
| 160677 | + /* 350 */ 1257, 275, 275, 1128, 1628, 1021, 1628, 137, 415, 1600, |
| 160678 | + /* 360 */ 561, 272, 1255, 950, 561, 1423, 1183, 1184, 1185, 1594, |
| 160679 | + /* 370 */ 866, 1012, 530, 315, 231, 1011, 317, 1276, 231, 119, |
| 159311 | 160680 | /* 380 */ 119, 119, 119, 118, 118, 117, 117, 117, 116, 442, |
| 159312 | 160681 | /* 390 */ 1570, 119, 119, 119, 119, 118, 118, 117, 117, 117, |
| 159313 | 160682 | /* 400 */ 116, 442, 330, 359, 1567, 564, 446, 1011, 1011, 1013, |
| 159314 | | - /* 410 */ 446, 207, 564, 306, 555, 407, 363, 1021, 363, 346, |
| 160683 | + /* 410 */ 446, 877, 564, 306, 555, 407, 447, 1021, 563, 346, |
| 159315 | 160684 | /* 420 */ 184, 118, 118, 117, 117, 117, 116, 442, 71, 71, |
| 159316 | 160685 | /* 430 */ 439, 438, 1126, 1012, 472, 71, 71, 1011, 205, 122, |
| 159317 | | - /* 440 */ 123, 113, 1207, 1207, 1041, 1044, 1034, 1034, 120, 120, |
| 159318 | | - /* 450 */ 121, 121, 121, 121, 219, 219, 472, 1183, 407, 570, |
| 159319 | | - /* 460 */ 1183, 1235, 503, 1477, 149, 546, 307, 489, 141, 1011, |
| 159320 | | - /* 470 */ 1011, 1013, 546, 140, 545, 1317, 1214, 191, 1214, 950, |
| 159321 | | - /* 480 */ 950, 514, 122, 123, 113, 1207, 1207, 1041, 1044, 1034, |
| 159322 | | - /* 490 */ 1034, 120, 120, 121, 121, 121, 121, 563, 119, 119, |
| 160686 | + /* 440 */ 123, 1207, 1207, 1041, 113, 1044, 1034, 1034, 120, 120, |
| 160687 | + /* 450 */ 121, 121, 121, 121, 1304, 219, 1283, 1183, 407, 570, |
| 160688 | + /* 460 */ 1183, 1235, 503, 1477, 1304, 546, 307, 489, 141, 1011, |
| 160689 | + /* 470 */ 1011, 1013, 546, 140, 545, 1317, 1214, 382, 1214, 378, |
| 160690 | + /* 480 */ 950, 514, 122, 123, 1207, 1207, 1041, 113, 1044, 1034, |
| 160691 | + /* 490 */ 1034, 120, 120, 121, 121, 121, 121, 472, 119, 119, |
| 159323 | 160692 | /* 500 */ 119, 119, 118, 118, 117, 117, 117, 116, 442, 283, |
| 159324 | | - /* 510 */ 275, 275, 415, 1183, 1184, 1185, 1183, 1184, 1185, 372, |
| 159325 | | - /* 520 */ 1183, 243, 344, 561, 502, 499, 498, 1539, 407, 1540, |
| 159326 | | - /* 530 */ 1183, 288, 870, 143, 497, 1549, 185, 231, 9, 6, |
| 160693 | + /* 510 */ 275, 275, 1476, 1183, 1184, 1185, 1183, 1184, 1185, 417, |
| 160694 | + /* 520 */ 1183, 243, 541, 561, 502, 499, 498, 1001, 407, 478, |
| 160695 | + /* 530 */ 1183, 472, 870, 143, 497, 1549, 185, 231, 9, 6, |
| 159327 | 160696 | /* 540 */ 253, 119, 119, 119, 119, 118, 118, 117, 117, 117, |
| 159328 | | - /* 550 */ 116, 442, 122, 123, 113, 1207, 1207, 1041, 1044, 1034, |
| 159329 | | - /* 560 */ 1034, 120, 120, 121, 121, 121, 121, 407, 137, 446, |
| 159330 | | - /* 570 */ 447, 863, 169, 1183, 397, 1204, 1183, 1184, 1185, 931, |
| 159331 | | - /* 580 */ 526, 1001, 98, 339, 564, 342, 1183, 1184, 1185, 306, |
| 159332 | | - /* 590 */ 555, 122, 123, 113, 1207, 1207, 1041, 1044, 1034, 1034, |
| 159333 | | - /* 600 */ 120, 120, 121, 121, 121, 121, 452, 71, 71, 275, |
| 160697 | + /* 550 */ 116, 442, 122, 123, 1207, 1207, 1041, 113, 1044, 1034, |
| 160698 | + /* 560 */ 1034, 120, 120, 121, 121, 121, 121, 407, 372, 446, |
| 160699 | + /* 570 */ 363, 863, 288, 1183, 397, 1204, 1183, 1184, 1185, 931, |
| 160700 | + /* 580 */ 330, 458, 318, 526, 564, 541, 1183, 1184, 1185, 284, |
| 160701 | + /* 590 */ 1183, 122, 123, 1207, 1207, 1041, 113, 1044, 1034, 1034, |
| 160702 | + /* 600 */ 120, 120, 121, 121, 121, 121, 291, 71, 71, 275, |
| 159334 | 160703 | /* 610 */ 275, 119, 119, 119, 119, 118, 118, 117, 117, 117, |
| 159335 | | - /* 620 */ 116, 442, 561, 417, 306, 555, 1183, 1307, 1307, 1183, |
| 159336 | | - /* 630 */ 1184, 1185, 1204, 1149, 330, 458, 318, 407, 363, 470, |
| 159337 | | - /* 640 */ 431, 1167, 32, 541, 527, 350, 1149, 1629, 393, 1149, |
| 160704 | + /* 620 */ 116, 442, 561, 1031, 1031, 1042, 1183, 1045, 287, 1183, |
| 160705 | + /* 630 */ 1184, 1185, 1204, 137, 218, 542, 1541, 407, 363, 470, |
| 160706 | + /* 640 */ 431, 1167, 32, 363, 527, 350, 1183, 1184, 1185, 380, |
| 159338 | 160707 | /* 650 */ 119, 119, 119, 119, 118, 118, 117, 117, 117, 116, |
| 159339 | | - /* 660 */ 442, 122, 123, 113, 1207, 1207, 1041, 1044, 1034, 1034, |
| 159340 | | - /* 670 */ 120, 120, 121, 121, 121, 121, 407, 199, 472, 1183, |
| 159341 | | - /* 680 */ 1022, 472, 1183, 1184, 1185, 386, 151, 539, 1548, 277, |
| 159342 | | - /* 690 */ 400, 137, 6, 317, 5, 564, 562, 3, 920, 920, |
| 159343 | | - /* 700 */ 122, 123, 113, 1207, 1207, 1041, 1044, 1034, 1034, 120, |
| 160708 | + /* 660 */ 442, 122, 123, 1207, 1207, 1041, 113, 1044, 1034, 1034, |
| 160709 | + /* 670 */ 120, 120, 121, 121, 121, 121, 407, 392, 1227, 1183, |
| 160710 | + /* 680 */ 1022, 1540, 1183, 1184, 1185, 1523, 149, 1307, 1307, 306, |
| 160711 | + /* 690 */ 555, 151, 1546, 361, 5, 564, 6, 3, 1035, 1542, |
| 160712 | + /* 700 */ 122, 123, 1207, 1207, 1041, 113, 1044, 1034, 1034, 120, |
| 159344 | 160713 | /* 710 */ 120, 121, 121, 121, 121, 411, 505, 83, 71, 71, |
| 159345 | 160714 | /* 720 */ 119, 119, 119, 119, 118, 118, 117, 117, 117, 116, |
| 159346 | | - /* 730 */ 442, 1183, 218, 428, 1183, 1183, 1184, 1185, 363, 261, |
| 159347 | | - /* 740 */ 278, 358, 508, 353, 507, 248, 407, 306, 555, 1539, |
| 159348 | | - /* 750 */ 1006, 349, 363, 291, 489, 302, 293, 1542, 281, 119, |
| 160715 | + /* 730 */ 442, 1183, 426, 428, 1183, 1183, 1184, 1185, 191, 261, |
| 160716 | + /* 740 */ 278, 358, 508, 353, 507, 248, 407, 455, 137, 1539, |
| 160717 | + /* 750 */ 1006, 349, 363, 472, 1539, 302, 1228, 405, 281, 119, |
| 159349 | 160718 | /* 760 */ 119, 119, 119, 118, 118, 117, 117, 117, 116, 442, |
| 159350 | | - /* 770 */ 122, 123, 113, 1207, 1207, 1041, 1044, 1034, 1034, 120, |
| 159351 | | - /* 780 */ 120, 121, 121, 121, 121, 407, 148, 1183, 1184, 1185, |
| 159352 | | - /* 790 */ 1183, 1184, 1185, 275, 275, 1304, 1257, 1283, 483, 1476, |
| 159353 | | - /* 800 */ 150, 489, 480, 564, 1187, 1304, 561, 1587, 1255, 122, |
| 159354 | | - /* 810 */ 123, 113, 1207, 1207, 1041, 1044, 1034, 1034, 120, 120, |
| 159355 | | - /* 820 */ 121, 121, 121, 121, 564, 886, 13, 13, 520, 119, |
| 160719 | + /* 770 */ 122, 123, 1207, 1207, 1041, 113, 1044, 1034, 1034, 120, |
| 160720 | + /* 780 */ 120, 121, 121, 121, 121, 407, 452, 1183, 1184, 1185, |
| 160721 | + /* 790 */ 1183, 1184, 1185, 275, 275, 269, 269, 489, 483, 1525, |
| 160722 | + /* 800 */ 148, 363, 480, 564, 306, 555, 561, 489, 561, 122, |
| 160723 | + /* 810 */ 123, 1207, 1207, 1041, 113, 1044, 1034, 1034, 120, 120, |
| 160724 | + /* 820 */ 121, 121, 121, 121, 564, 886, 13, 13, 293, 119, |
| 159356 | 160725 | /* 830 */ 119, 119, 119, 118, 118, 117, 117, 117, 116, 442, |
| 159357 | | - /* 840 */ 1183, 420, 417, 564, 269, 269, 1316, 13, 13, 1539, |
| 159358 | | - /* 850 */ 1546, 16, 16, 322, 6, 407, 506, 561, 1089, 1089, |
| 159359 | | - /* 860 */ 486, 1187, 425, 1539, 887, 292, 71, 71, 119, 119, |
| 160726 | + /* 840 */ 1183, 420, 1316, 564, 98, 417, 199, 13, 13, 150, |
| 160727 | + /* 850 */ 306, 555, 1312, 322, 386, 407, 506, 478, 562, 400, |
| 160728 | + /* 860 */ 920, 920, 425, 1539, 887, 292, 71, 71, 119, 119, |
| 159360 | 160729 | /* 870 */ 119, 119, 118, 118, 117, 117, 117, 116, 442, 122, |
| 159361 | | - /* 880 */ 123, 113, 1207, 1207, 1041, 1044, 1034, 1034, 120, 120, |
| 159362 | | - /* 890 */ 121, 121, 121, 121, 564, 12, 1183, 1184, 1185, 407, |
| 159363 | | - /* 900 */ 275, 275, 451, 303, 834, 835, 836, 417, 489, 276, |
| 159364 | | - /* 910 */ 276, 1547, 284, 561, 319, 6, 321, 71, 71, 429, |
| 159365 | | - /* 920 */ 451, 450, 561, 952, 101, 113, 1207, 1207, 1041, 1044, |
| 160730 | + /* 880 */ 123, 1207, 1207, 1041, 113, 1044, 1034, 1034, 120, 120, |
| 160731 | + /* 890 */ 121, 121, 121, 121, 564, 1149, 1183, 1184, 1185, 407, |
| 160732 | + /* 900 */ 275, 275, 451, 303, 1089, 1089, 486, 448, 1149, 276, |
| 160733 | + /* 910 */ 276, 1149, 1539, 561, 319, 286, 321, 71, 71, 429, |
| 160734 | + /* 920 */ 451, 450, 561, 952, 101, 1207, 1207, 1041, 113, 1044, |
| 159366 | 160735 | /* 930 */ 1034, 1034, 120, 120, 121, 121, 121, 121, 119, 119, |
| 159367 | 160736 | /* 940 */ 119, 119, 118, 118, 117, 117, 117, 116, 442, 1105, |
| 159368 | | - /* 950 */ 1183, 489, 564, 1312, 437, 455, 478, 564, 246, 245, |
| 159369 | | - /* 960 */ 244, 1409, 1545, 547, 1106, 405, 6, 1544, 196, 1258, |
| 159370 | | - /* 970 */ 413, 6, 105, 462, 103, 71, 71, 286, 564, 1107, |
| 160737 | + /* 950 */ 1183, 1547, 564, 12, 437, 6, 329, 564, 834, 835, |
| 160738 | + /* 960 */ 836, 1629, 393, 547, 1106, 246, 245, 244, 1545, 1258, |
| 160739 | + /* 970 */ 413, 1521, 6, 1086, 310, 71, 71, 1086, 564, 1107, |
| 159371 | 160740 | /* 980 */ 13, 13, 119, 119, 119, 119, 118, 118, 117, 117, |
| 159372 | | - /* 990 */ 117, 116, 442, 451, 104, 427, 337, 320, 275, 275, |
| 159373 | | - /* 1000 */ 906, 13, 13, 564, 1482, 1105, 1183, 1184, 1185, 126, |
| 159374 | | - /* 1010 */ 907, 561, 546, 564, 407, 478, 295, 1321, 253, 200, |
| 159375 | | - /* 1020 */ 1106, 548, 1482, 1484, 280, 1409, 55, 55, 1287, 561, |
| 159376 | | - /* 1030 */ 478, 380, 423, 951, 407, 1107, 71, 71, 122, 123, |
| 159377 | | - /* 1040 */ 113, 1207, 1207, 1041, 1044, 1034, 1034, 120, 120, 121, |
| 159378 | | - /* 1050 */ 121, 121, 121, 1204, 407, 287, 552, 309, 122, 123, |
| 159379 | | - /* 1060 */ 113, 1207, 1207, 1041, 1044, 1034, 1034, 120, 120, 121, |
| 159380 | | - /* 1070 */ 121, 121, 121, 441, 1128, 1628, 146, 1628, 122, 111, |
| 159381 | | - /* 1080 */ 113, 1207, 1207, 1041, 1044, 1034, 1034, 120, 120, 121, |
| 159382 | | - /* 1090 */ 121, 121, 121, 404, 403, 1482, 424, 119, 119, 119, |
| 160741 | + /* 990 */ 117, 116, 442, 451, 104, 427, 537, 320, 275, 275, |
| 160742 | + /* 1000 */ 906, 13, 13, 520, 1482, 1105, 1183, 1184, 1185, 484, |
| 160743 | + /* 1010 */ 907, 561, 546, 564, 407, 536, 295, 478, 253, 200, |
| 160744 | + /* 1020 */ 1106, 548, 1482, 1484, 1160, 1409, 16, 16, 126, 557, |
| 160745 | + /* 1030 */ 413, 479, 311, 951, 407, 1107, 71, 71, 122, 123, |
| 160746 | + /* 1040 */ 1207, 1207, 1041, 113, 1044, 1034, 1034, 120, 120, 121, |
| 160747 | + /* 1050 */ 121, 121, 121, 1204, 407, 544, 552, 314, 122, 123, |
| 160748 | + /* 1060 */ 1207, 1207, 1041, 113, 1044, 1034, 1034, 120, 120, 121, |
| 160749 | + /* 1070 */ 121, 121, 121, 441, 144, 1160, 468, 146, 122, 111, |
| 160750 | + /* 1080 */ 1207, 1207, 1041, 113, 1044, 1034, 1034, 120, 120, 121, |
| 160751 | + /* 1090 */ 121, 121, 121, 247, 12, 1482, 422, 119, 119, 119, |
| 159383 | 160752 | /* 1100 */ 119, 118, 118, 117, 117, 117, 116, 442, 1183, 564, |
| 159384 | | - /* 1110 */ 1204, 544, 1086, 858, 329, 361, 1086, 119, 119, 119, |
| 159385 | | - /* 1120 */ 119, 118, 118, 117, 117, 117, 116, 442, 564, 294, |
| 159386 | | - /* 1130 */ 144, 523, 56, 56, 224, 564, 510, 119, 119, 119, |
| 159387 | | - /* 1140 */ 119, 118, 118, 117, 117, 117, 116, 442, 484, 1409, |
| 159388 | | - /* 1150 */ 537, 15, 15, 1126, 434, 439, 438, 407, 13, 13, |
| 159389 | | - /* 1160 */ 1523, 12, 926, 1211, 1183, 1184, 1185, 925, 1213, 536, |
| 159390 | | - /* 1170 */ 858, 557, 413, 193, 1525, 494, 1212, 448, 1160, 1222, |
| 159391 | | - /* 1180 */ 1183, 564, 123, 113, 1207, 1207, 1041, 1044, 1034, 1034, |
| 159392 | | - /* 1190 */ 120, 120, 121, 121, 121, 121, 1521, 1149, 564, 965, |
| 159393 | | - /* 1200 */ 564, 1214, 247, 1214, 13, 13, 1409, 966, 538, 564, |
| 159394 | | - /* 1210 */ 1149, 108, 556, 1149, 4, 310, 392, 1227, 17, 194, |
| 159395 | | - /* 1220 */ 485, 43, 43, 57, 57, 306, 555, 524, 559, 1160, |
| 159396 | | - /* 1230 */ 464, 564, 44, 44, 392, 1127, 1183, 1184, 1185, 479, |
| 160753 | + /* 1110 */ 1204, 207, 404, 403, 858, 950, 294, 119, 119, 119, |
| 160754 | + /* 1120 */ 119, 118, 118, 117, 117, 117, 116, 442, 564, 30, |
| 160755 | + /* 1130 */ 564, 1409, 55, 55, 1599, 564, 895, 119, 119, 119, |
| 160756 | + /* 1140 */ 119, 118, 118, 117, 117, 117, 116, 442, 510, 1409, |
| 160757 | + /* 1150 */ 1409, 56, 56, 15, 15, 439, 438, 407, 13, 13, |
| 160758 | + /* 1160 */ 31, 1187, 412, 1211, 1183, 1184, 1185, 196, 1213, 306, |
| 160759 | + /* 1170 */ 555, 858, 462, 193, 926, 564, 1212, 489, 361, 925, |
| 160760 | + /* 1180 */ 1183, 564, 123, 1207, 1207, 1041, 113, 1044, 1034, 1034, |
| 160761 | + /* 1190 */ 120, 120, 121, 121, 121, 121, 1544, 1149, 43, 43, |
| 160762 | + /* 1200 */ 6, 1214, 423, 1214, 13, 13, 564, 219, 538, 494, |
| 160763 | + /* 1210 */ 1149, 108, 556, 1149, 4, 392, 1127, 434, 1187, 194, |
| 160764 | + /* 1220 */ 424, 485, 337, 1315, 414, 171, 1253, 1321, 559, 57, |
| 160765 | + /* 1230 */ 57, 564, 950, 564, 224, 247, 1183, 1184, 1185, 561, |
| 159397 | 160766 | /* 1240 */ 119, 119, 119, 119, 118, 118, 117, 117, 117, 116, |
| 159398 | | - /* 1250 */ 442, 443, 564, 327, 13, 13, 564, 418, 1315, 414, |
| 159399 | | - /* 1260 */ 171, 564, 311, 553, 213, 529, 1253, 564, 517, 543, |
| 159400 | | - /* 1270 */ 412, 108, 556, 137, 4, 58, 58, 435, 314, 59, |
| 159401 | | - /* 1280 */ 59, 274, 217, 549, 60, 60, 349, 476, 559, 1353, |
| 159402 | | - /* 1290 */ 61, 61, 1021, 275, 275, 1228, 213, 564, 106, 106, |
| 159403 | | - /* 1300 */ 8, 275, 275, 275, 275, 107, 561, 443, 566, 565, |
| 159404 | | - /* 1310 */ 564, 443, 1011, 1228, 561, 564, 561, 564, 275, 275, |
| 159405 | | - /* 1320 */ 62, 62, 1352, 553, 247, 456, 564, 98, 110, 306, |
| 159406 | | - /* 1330 */ 555, 561, 564, 45, 45, 405, 1203, 533, 46, 46, |
| 159407 | | - /* 1340 */ 47, 47, 532, 465, 1011, 1011, 1013, 1014, 27, 49, |
| 159408 | | - /* 1350 */ 49, 564, 1021, 405, 469, 50, 50, 564, 106, 106, |
| 159409 | | - /* 1360 */ 305, 564, 84, 204, 405, 107, 564, 443, 566, 565, |
| 159410 | | - /* 1370 */ 405, 564, 1011, 564, 63, 63, 564, 1599, 564, 895, |
| 159411 | | - /* 1380 */ 64, 64, 457, 477, 65, 65, 147, 96, 38, 14, |
| 159412 | | - /* 1390 */ 14, 1528, 412, 564, 66, 66, 128, 128, 926, 67, |
| 159413 | | - /* 1400 */ 67, 52, 52, 925, 1011, 1011, 1013, 1014, 27, 1572, |
| 159414 | | - /* 1410 */ 1171, 445, 208, 1123, 279, 394, 68, 68, 228, 390, |
| 159415 | | - /* 1420 */ 390, 389, 264, 387, 1171, 445, 843, 877, 279, 108, |
| 159416 | | - /* 1430 */ 556, 453, 4, 390, 390, 389, 264, 387, 564, 225, |
| 159417 | | - /* 1440 */ 843, 313, 328, 1003, 98, 252, 559, 544, 471, 312, |
| 159418 | | - /* 1450 */ 252, 564, 208, 225, 564, 313, 473, 30, 252, 279, |
| 159419 | | - /* 1460 */ 466, 69, 69, 312, 390, 390, 389, 264, 387, 443, |
| 159420 | | - /* 1470 */ 333, 843, 98, 564, 53, 53, 323, 157, 157, 227, |
| 159421 | | - /* 1480 */ 495, 553, 249, 289, 225, 564, 313, 162, 31, 1501, |
| 159422 | | - /* 1490 */ 135, 564, 1500, 227, 312, 533, 158, 158, 885, 884, |
| 159423 | | - /* 1500 */ 534, 162, 873, 301, 135, 564, 481, 226, 76, 76, |
| 159424 | | - /* 1510 */ 1021, 347, 1071, 98, 54, 54, 106, 106, 1067, 564, |
| 159425 | | - /* 1520 */ 249, 226, 519, 107, 227, 443, 566, 565, 72, 72, |
| 159426 | | - /* 1530 */ 1011, 334, 162, 564, 230, 135, 108, 556, 959, 4, |
| 159427 | | - /* 1540 */ 252, 408, 129, 129, 564, 1349, 306, 555, 564, 923, |
| 159428 | | - /* 1550 */ 564, 110, 226, 559, 564, 408, 73, 73, 564, 873, |
| 159429 | | - /* 1560 */ 306, 555, 1011, 1011, 1013, 1014, 27, 130, 130, 1071, |
| 159430 | | - /* 1570 */ 449, 131, 131, 127, 127, 357, 443, 156, 156, 892, |
| 159431 | | - /* 1580 */ 893, 155, 155, 338, 449, 356, 408, 564, 553, 968, |
| 159432 | | - /* 1590 */ 969, 306, 555, 1015, 341, 564, 108, 556, 564, 4, |
| 159433 | | - /* 1600 */ 1132, 1286, 533, 564, 856, 343, 145, 532, 345, 1300, |
| 159434 | | - /* 1610 */ 136, 136, 1083, 559, 1083, 449, 564, 1021, 134, 134, |
| 159435 | | - /* 1620 */ 1284, 132, 132, 106, 106, 1285, 133, 133, 564, 352, |
| 159436 | | - /* 1630 */ 107, 564, 443, 566, 565, 1340, 443, 1011, 362, 75, |
| 159437 | | - /* 1640 */ 75, 1082, 564, 1082, 564, 924, 1561, 110, 553, 551, |
| 159438 | | - /* 1650 */ 1015, 77, 77, 1361, 74, 74, 1408, 1336, 1347, 550, |
| 159439 | | - /* 1660 */ 1414, 1265, 1256, 1244, 1243, 42, 42, 48, 48, 1011, |
| 159440 | | - /* 1670 */ 1011, 1013, 1014, 27, 1245, 1580, 490, 1021, 267, 202, |
| 159441 | | - /* 1680 */ 1333, 365, 11, 106, 106, 930, 367, 210, 369, 391, |
| 159442 | | - /* 1690 */ 107, 1395, 443, 566, 565, 223, 1390, 1011, 500, 454, |
| 159443 | | - /* 1700 */ 282, 1400, 285, 108, 556, 214, 4, 325, 1383, 1283, |
| 159444 | | - /* 1710 */ 475, 355, 1473, 1583, 1472, 1399, 371, 1222, 326, 398, |
| 159445 | | - /* 1720 */ 559, 290, 331, 197, 100, 556, 209, 4, 198, 1011, |
| 159446 | | - /* 1730 */ 1011, 1013, 1014, 27, 385, 256, 1520, 1518, 554, 1219, |
| 159447 | | - /* 1740 */ 416, 559, 83, 443, 173, 206, 182, 221, 459, 167, |
| 159448 | | - /* 1750 */ 177, 460, 175, 493, 233, 553, 79, 178, 1396, 179, |
| 159449 | | - /* 1760 */ 35, 180, 96, 1402, 443, 396, 36, 467, 1478, 1401, |
| 159450 | | - /* 1770 */ 482, 237, 1404, 399, 82, 186, 553, 1467, 89, 488, |
| 159451 | | - /* 1780 */ 190, 268, 239, 491, 1021, 340, 240, 401, 1246, 1489, |
| 159452 | | - /* 1790 */ 106, 106, 336, 509, 1294, 241, 1303, 107, 430, 443, |
| 159453 | | - /* 1800 */ 566, 565, 1302, 91, 1011, 1021, 1598, 1301, 1273, 215, |
| 159454 | | - /* 1810 */ 1597, 106, 106, 402, 877, 432, 354, 1272, 107, 1271, |
| 159455 | | - /* 1820 */ 443, 566, 565, 1596, 1566, 1011, 1293, 433, 518, 299, |
| 159456 | | - /* 1830 */ 300, 360, 95, 525, 1344, 364, 1011, 1011, 1013, 1014, |
| 159457 | | - /* 1840 */ 27, 254, 255, 1552, 436, 1551, 125, 544, 10, 379, |
| 159458 | | - /* 1850 */ 1326, 1453, 102, 97, 1345, 528, 304, 1011, 1011, 1013, |
| 159459 | | - /* 1860 */ 1014, 27, 366, 377, 1343, 1342, 368, 370, 1325, 384, |
| 159460 | | - /* 1870 */ 201, 383, 34, 1368, 1367, 568, 1177, 266, 263, 265, |
| 159461 | | - /* 1880 */ 1505, 159, 569, 1241, 1236, 1506, 160, 142, 1504, 1503, |
| 159462 | | - /* 1890 */ 297, 211, 830, 161, 212, 78, 444, 203, 308, 222, |
| 159463 | | - /* 1900 */ 1081, 139, 1079, 316, 174, 163, 1203, 229, 176, 909, |
| 159464 | | - /* 1910 */ 324, 232, 1095, 181, 409, 410, 172, 164, 165, 419, |
| 159465 | | - /* 1920 */ 183, 85, 86, 421, 166, 87, 88, 1098, 1094, 234, |
| 159466 | | - /* 1930 */ 235, 152, 18, 236, 335, 1087, 1216, 252, 187, 487, |
| 159467 | | - /* 1940 */ 238, 188, 37, 845, 492, 356, 242, 496, 351, 501, |
| 159468 | | - /* 1950 */ 189, 90, 19, 504, 348, 20, 875, 92, 298, 168, |
| 159469 | | - /* 1960 */ 888, 153, 93, 511, 94, 1165, 154, 1047, 1134, 39, |
| 159470 | | - /* 1970 */ 216, 1133, 271, 273, 958, 192, 953, 110, 1151, 1155, |
| 159471 | | - /* 1980 */ 251, 7, 21, 1159, 1139, 22, 1153, 33, 23, 24, |
| 159472 | | - /* 1990 */ 25, 540, 1158, 195, 98, 1062, 26, 1048, 1046, 1050, |
| 159473 | | - /* 2000 */ 1104, 1051, 1103, 257, 258, 28, 40, 1173, 1016, 857, |
| 159474 | | - /* 2010 */ 109, 29, 560, 388, 138, 1172, 259, 170, 260, 1232, |
| 159475 | | - /* 2020 */ 1232, 919, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, |
| 159476 | | - /* 2030 */ 1232, 1232, 1589, 1232, 1232, 1232, 1588, |
| 160767 | + /* 1250 */ 442, 443, 564, 517, 13, 13, 44, 44, 275, 275, |
| 160768 | + /* 1260 */ 1409, 275, 275, 553, 1353, 529, 213, 549, 456, 543, |
| 160769 | + /* 1270 */ 465, 561, 564, 137, 561, 58, 58, 469, 405, 1222, |
| 160770 | + /* 1280 */ 405, 274, 217, 108, 556, 110, 4, 405, 275, 275, |
| 160771 | + /* 1290 */ 564, 1352, 1021, 564, 1228, 59, 59, 523, 106, 106, |
| 160772 | + /* 1300 */ 559, 561, 275, 275, 412, 107, 457, 443, 566, 565, |
| 160773 | + /* 1310 */ 564, 8, 1011, 60, 60, 561, 61, 61, 564, 965, |
| 160774 | + /* 1320 */ 349, 926, 305, 443, 84, 204, 925, 966, 564, 306, |
| 160775 | + /* 1330 */ 555, 435, 405, 62, 62, 553, 476, 105, 564, 103, |
| 160776 | + /* 1340 */ 464, 45, 45, 1203, 1011, 1011, 1013, 1014, 27, 533, |
| 160777 | + /* 1350 */ 564, 46, 46, 453, 532, 1572, 1171, 445, 1528, 564, |
| 160778 | + /* 1360 */ 279, 47, 47, 327, 1021, 390, 390, 389, 264, 387, |
| 160779 | + /* 1370 */ 106, 106, 843, 49, 49, 108, 556, 107, 4, 443, |
| 160780 | + /* 1380 */ 566, 565, 50, 50, 1011, 225, 564, 313, 564, 96, |
| 160781 | + /* 1390 */ 564, 228, 559, 524, 147, 312, 38, 1123, 564, 394, |
| 160782 | + /* 1400 */ 466, 328, 280, 98, 544, 564, 17, 564, 323, 63, |
| 160783 | + /* 1410 */ 63, 64, 64, 65, 65, 443, 1011, 1011, 1013, 1014, |
| 160784 | + /* 1420 */ 27, 14, 14, 289, 564, 227, 564, 553, 66, 66, |
| 160785 | + /* 1430 */ 128, 128, 477, 162, 564, 309, 135, 564, 1003, 277, |
| 160786 | + /* 1440 */ 252, 533, 564, 1501, 564, 418, 534, 67, 67, 52, |
| 160787 | + /* 1450 */ 52, 564, 1287, 226, 564, 1500, 1021, 68, 68, 208, |
| 160788 | + /* 1460 */ 69, 69, 106, 106, 1286, 53, 53, 157, 157, 107, |
| 160789 | + /* 1470 */ 873, 443, 566, 565, 158, 158, 1011, 76, 76, 564, |
| 160790 | + /* 1480 */ 357, 564, 108, 556, 471, 4, 252, 408, 885, 884, |
| 160791 | + /* 1490 */ 356, 564, 306, 555, 564, 473, 564, 252, 481, 559, |
| 160792 | + /* 1500 */ 564, 334, 54, 54, 72, 72, 564, 230, 1011, 1011, |
| 160793 | + /* 1510 */ 1013, 1014, 27, 564, 129, 129, 449, 73, 73, 130, |
| 160794 | + /* 1520 */ 130, 564, 443, 131, 131, 519, 564, 873, 564, 127, |
| 160795 | + /* 1530 */ 127, 333, 1071, 98, 553, 1349, 156, 156, 564, 495, |
| 160796 | + /* 1540 */ 347, 249, 98, 338, 155, 155, 892, 893, 533, 136, |
| 160797 | + /* 1550 */ 136, 134, 134, 532, 341, 1171, 445, 1587, 564, 279, |
| 160798 | + /* 1560 */ 343, 132, 132, 1021, 390, 390, 389, 264, 387, 106, |
| 160799 | + /* 1570 */ 106, 843, 564, 1067, 564, 249, 107, 564, 443, 566, |
| 160800 | + /* 1580 */ 565, 133, 133, 1011, 225, 1015, 313, 108, 556, 1071, |
| 160801 | + /* 1590 */ 4, 345, 968, 969, 312, 75, 75, 77, 77, 1300, |
| 160802 | + /* 1600 */ 74, 74, 564, 1132, 559, 564, 108, 556, 959, 4, |
| 160803 | + /* 1610 */ 252, 923, 1083, 110, 1083, 1011, 1011, 1013, 1014, 27, |
| 160804 | + /* 1620 */ 1082, 1285, 1082, 559, 227, 42, 42, 443, 48, 48, |
| 160805 | + /* 1630 */ 1284, 856, 162, 145, 924, 135, 110, 352, 362, 553, |
| 160806 | + /* 1640 */ 1340, 1361, 1015, 1408, 1336, 301, 443, 1561, 1347, 550, |
| 160807 | + /* 1650 */ 1414, 551, 226, 202, 1265, 1333, 1256, 1244, 553, 1243, |
| 160808 | + /* 1660 */ 490, 1245, 1580, 267, 11, 391, 210, 223, 1021, 1390, |
| 160809 | + /* 1670 */ 1395, 282, 365, 367, 106, 106, 930, 369, 454, 285, |
| 160810 | + /* 1680 */ 1383, 107, 325, 443, 566, 565, 408, 1021, 1011, 326, |
| 160811 | + /* 1690 */ 475, 306, 555, 106, 106, 100, 556, 500, 4, 1400, |
| 160812 | + /* 1700 */ 107, 1399, 443, 566, 565, 398, 1283, 1011, 214, 355, |
| 160813 | + /* 1710 */ 1473, 290, 559, 1472, 1583, 449, 554, 371, 331, 197, |
| 160814 | + /* 1720 */ 1011, 1011, 1013, 1014, 27, 198, 209, 385, 1222, 173, |
| 160815 | + /* 1730 */ 221, 256, 1520, 1518, 1219, 443, 79, 416, 206, 1011, |
| 160816 | + /* 1740 */ 1011, 1013, 1014, 27, 83, 279, 182, 553, 82, 167, |
| 160817 | + /* 1750 */ 390, 390, 389, 264, 387, 35, 1396, 843, 1478, 459, |
| 160818 | + /* 1760 */ 175, 177, 460, 493, 178, 179, 180, 233, 96, 396, |
| 160819 | + /* 1770 */ 225, 1402, 313, 1401, 36, 1404, 1021, 467, 186, 482, |
| 160820 | + /* 1780 */ 312, 399, 106, 106, 237, 1467, 89, 1489, 488, 107, |
| 160821 | + /* 1790 */ 239, 443, 566, 565, 268, 336, 1011, 190, 491, 340, |
| 160822 | + /* 1800 */ 240, 401, 1246, 241, 509, 1294, 430, 1303, 91, 877, |
| 160823 | + /* 1810 */ 227, 215, 1566, 1302, 1301, 1273, 1598, 432, 162, 518, |
| 160824 | + /* 1820 */ 1272, 135, 1597, 354, 402, 433, 1271, 1596, 1011, 1011, |
| 160825 | + /* 1830 */ 1013, 1014, 27, 1293, 299, 360, 300, 525, 226, 95, |
| 160826 | + /* 1840 */ 254, 255, 1344, 364, 436, 125, 544, 1552, 10, 1453, |
| 160827 | + /* 1850 */ 379, 1551, 102, 304, 97, 528, 34, 568, 1177, 263, |
| 160828 | + /* 1860 */ 265, 266, 569, 1241, 1236, 172, 409, 410, 159, 383, |
| 160829 | + /* 1870 */ 377, 366, 408, 1345, 1343, 368, 370, 306, 555, 1342, |
| 160830 | + /* 1880 */ 1326, 1325, 1368, 201, 384, 1367, 1505, 1506, 160, 1504, |
| 160831 | + /* 1890 */ 1503, 142, 161, 211, 212, 78, 830, 444, 203, 308, |
| 160832 | + /* 1900 */ 297, 449, 222, 1081, 139, 1079, 316, 174, 163, 1203, |
| 160833 | + /* 1910 */ 229, 176, 232, 909, 324, 1095, 164, 181, 165, 419, |
| 160834 | + /* 1920 */ 421, 183, 85, 86, 87, 88, 166, 1098, 235, 234, |
| 160835 | + /* 1930 */ 1094, 152, 18, 236, 335, 1087, 252, 1216, 487, 238, |
| 160836 | + /* 1940 */ 37, 187, 188, 845, 492, 356, 242, 348, 496, 189, |
| 160837 | + /* 1950 */ 90, 93, 19, 20, 168, 875, 501, 351, 92, 504, |
| 160838 | + /* 1960 */ 888, 153, 511, 1133, 1165, 154, 298, 1047, 94, 1134, |
| 160839 | + /* 1970 */ 39, 958, 216, 271, 273, 192, 953, 110, 1151, 251, |
| 160840 | + /* 1980 */ 1155, 21, 1159, 22, 1158, 1139, 1153, 33, 23, 24, |
| 160841 | + /* 1990 */ 540, 25, 195, 98, 26, 1062, 1048, 1046, 1050, 1104, |
| 160842 | + /* 2000 */ 7, 1103, 257, 258, 1051, 28, 40, 560, 1016, 857, |
| 160843 | + /* 2010 */ 109, 29, 919, 138, 259, 260, 170, 1589, 388, 1588, |
| 160844 | + /* 2020 */ 1173, 1172, |
| 159477 | 160845 | }; |
| 159478 | 160846 | static const YYCODETYPE yy_lookahead[] = { |
| 159479 | 160847 | /* 0 */ 192, 273, 274, 275, 192, 192, 273, 274, 275, 192, |
| 159480 | 160848 | /* 10 */ 218, 215, 192, 218, 192, 212, 234, 235, 205, 19, |
| 159481 | 160849 | /* 20 */ 11, 192, 294, 215, 216, 203, 192, 203, 209, 210, |
| | @@ -159486,202 +160854,202 @@ |
| 159486 | 160854 | /* 70 */ 275, 237, 21, 251, 252, 251, 273, 274, 275, 255, |
| 159487 | 160855 | /* 80 */ 256, 215, 216, 43, 44, 45, 46, 47, 48, 49, |
| 159488 | 160856 | /* 90 */ 50, 51, 52, 53, 54, 55, 56, 57, 209, 210, |
| 159489 | 160857 | /* 100 */ 211, 76, 102, 103, 104, 105, 106, 107, 108, 109, |
| 159490 | 160858 | /* 110 */ 110, 111, 112, 59, 89, 111, 112, 92, 252, 307, |
| 159491 | | - /* 120 */ 308, 313, 314, 112, 312, 59, 86, 261, 88, 19, |
| 160859 | + /* 120 */ 308, 313, 314, 25, 312, 192, 86, 261, 88, 19, |
| 159492 | 160860 | /* 130 */ 313, 80, 315, 313, 314, 25, 127, 128, 54, 55, |
| 159493 | 160861 | /* 140 */ 56, 57, 102, 103, 104, 105, 106, 107, 108, 109, |
| 159494 | 160862 | /* 150 */ 110, 111, 112, 43, 44, 45, 46, 47, 48, 49, |
| 159495 | 160863 | /* 160 */ 50, 51, 52, 53, 54, 55, 56, 57, 192, 115, |
| 159496 | 160864 | /* 170 */ 116, 117, 118, 122, 192, 121, 122, 123, 202, 69, |
| 159497 | | - /* 180 */ 204, 115, 116, 117, 192, 131, 102, 103, 104, 105, |
| 160865 | + /* 180 */ 204, 22, 23, 16, 25, 131, 102, 103, 104, 105, |
| 159498 | 160866 | /* 190 */ 106, 107, 108, 109, 110, 111, 112, 215, 216, 19, |
| 159499 | 160867 | /* 200 */ 54, 55, 56, 57, 58, 108, 109, 110, 111, 112, |
| 159500 | 160868 | /* 210 */ 192, 160, 102, 103, 104, 105, 106, 107, 108, 109, |
| 159501 | 160869 | /* 220 */ 110, 111, 112, 43, 44, 45, 46, 47, 48, 49, |
| 159502 | | - /* 230 */ 50, 51, 52, 53, 54, 55, 56, 57, 19, 46, |
| 159503 | | - /* 240 */ 47, 48, 49, 24, 248, 192, 250, 67, 102, 103, |
| 160870 | + /* 230 */ 50, 51, 52, 53, 54, 55, 56, 57, 19, 141, |
| 160871 | + /* 240 */ 307, 308, 272, 24, 77, 312, 79, 67, 102, 103, |
| 159504 | 160872 | /* 250 */ 104, 105, 106, 107, 108, 109, 110, 111, 112, 277, |
| 159505 | | - /* 260 */ 127, 128, 43, 44, 45, 46, 47, 48, 49, 50, |
| 159506 | | - /* 270 */ 51, 52, 53, 54, 55, 56, 57, 26, 164, 165, |
| 159507 | | - /* 280 */ 272, 263, 102, 103, 104, 105, 106, 107, 108, 109, |
| 160873 | + /* 260 */ 101, 112, 43, 44, 45, 46, 47, 48, 49, 50, |
| 160874 | + /* 270 */ 51, 52, 53, 54, 55, 56, 57, 26, 127, 128, |
| 160875 | + /* 280 */ 310, 311, 102, 103, 104, 105, 106, 107, 108, 109, |
| 159508 | 160876 | /* 290 */ 110, 111, 112, 184, 185, 186, 187, 188, 189, 186, |
| 159509 | | - /* 300 */ 187, 188, 189, 194, 76, 196, 229, 194, 19, 196, |
| 159510 | | - /* 310 */ 59, 192, 203, 120, 59, 87, 203, 89, 310, 311, |
| 160877 | + /* 300 */ 187, 188, 189, 194, 76, 196, 192, 194, 19, 196, |
| 160878 | + /* 310 */ 59, 25, 203, 192, 59, 87, 203, 89, 164, 165, |
| 159511 | 160879 | /* 320 */ 92, 102, 103, 104, 105, 106, 107, 108, 109, 110, |
| 159512 | 160880 | /* 330 */ 111, 112, 43, 44, 45, 46, 47, 48, 49, 50, |
| 159513 | 160881 | /* 340 */ 51, 52, 53, 54, 55, 56, 57, 238, 239, 73, |
| 159514 | | - /* 350 */ 231, 238, 239, 22, 23, 100, 25, 81, 305, 306, |
| 159515 | | - /* 360 */ 251, 23, 25, 25, 251, 272, 115, 116, 117, 214, |
| 159516 | | - /* 370 */ 115, 116, 144, 192, 265, 120, 114, 222, 265, 102, |
| 160882 | + /* 350 */ 192, 238, 239, 22, 23, 100, 25, 81, 237, 229, |
| 160883 | + /* 360 */ 251, 23, 204, 25, 251, 272, 115, 116, 117, 214, |
| 160884 | + /* 370 */ 115, 116, 144, 192, 265, 120, 262, 222, 265, 102, |
| 159517 | 160885 | /* 380 */ 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, |
| 159518 | 160886 | /* 390 */ 192, 102, 103, 104, 105, 106, 107, 108, 109, 110, |
| 159519 | 160887 | /* 400 */ 111, 112, 126, 310, 311, 192, 297, 152, 153, 154, |
| 159520 | | - /* 410 */ 297, 149, 192, 137, 138, 19, 192, 100, 192, 23, |
| 160888 | + /* 410 */ 297, 125, 192, 137, 138, 19, 295, 100, 192, 23, |
| 159521 | 160889 | /* 420 */ 22, 106, 107, 108, 109, 110, 111, 112, 215, 216, |
| 159522 | 160890 | /* 430 */ 106, 107, 101, 116, 192, 215, 216, 120, 149, 43, |
| 159523 | 160891 | /* 440 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, |
| 159524 | | - /* 450 */ 54, 55, 56, 57, 117, 117, 192, 59, 19, 187, |
| 159525 | | - /* 460 */ 59, 189, 23, 282, 240, 252, 194, 192, 196, 152, |
| 159526 | | - /* 470 */ 153, 154, 252, 72, 261, 203, 152, 25, 154, 142, |
| 160892 | + /* 450 */ 54, 55, 56, 57, 222, 117, 224, 59, 19, 187, |
| 160893 | + /* 460 */ 59, 189, 23, 282, 232, 252, 194, 192, 196, 152, |
| 160894 | + /* 470 */ 153, 154, 252, 72, 261, 203, 152, 248, 154, 250, |
| 159527 | 160895 | /* 480 */ 142, 261, 43, 44, 45, 46, 47, 48, 49, 50, |
| 159528 | 160896 | /* 490 */ 51, 52, 53, 54, 55, 56, 57, 192, 102, 103, |
| 159529 | 160897 | /* 500 */ 104, 105, 106, 107, 108, 109, 110, 111, 112, 267, |
| 159530 | 160898 | /* 510 */ 238, 239, 237, 115, 116, 117, 115, 116, 117, 192, |
| 159531 | | - /* 520 */ 59, 118, 16, 251, 121, 122, 123, 303, 19, 303, |
| 159532 | | - /* 530 */ 59, 267, 23, 72, 131, 308, 22, 265, 22, 312, |
| 160899 | + /* 520 */ 59, 118, 192, 251, 121, 122, 123, 73, 19, 192, |
| 160900 | + /* 530 */ 59, 192, 23, 72, 131, 308, 22, 265, 22, 312, |
| 159533 | 160901 | /* 540 */ 24, 102, 103, 104, 105, 106, 107, 108, 109, 110, |
| 159534 | 160902 | /* 550 */ 111, 112, 43, 44, 45, 46, 47, 48, 49, 50, |
| 159535 | | - /* 560 */ 51, 52, 53, 54, 55, 56, 57, 19, 81, 297, |
| 159536 | | - /* 570 */ 295, 23, 192, 59, 203, 59, 115, 116, 117, 108, |
| 159537 | | - /* 580 */ 192, 73, 25, 77, 192, 79, 115, 116, 117, 137, |
| 159538 | | - /* 590 */ 138, 43, 44, 45, 46, 47, 48, 49, 50, 51, |
| 159539 | | - /* 600 */ 52, 53, 54, 55, 56, 57, 119, 215, 216, 238, |
| 160903 | + /* 560 */ 51, 52, 53, 54, 55, 56, 57, 19, 192, 297, |
| 160904 | + /* 570 */ 192, 23, 267, 59, 203, 59, 115, 116, 117, 108, |
| 160905 | + /* 580 */ 126, 127, 128, 192, 192, 192, 115, 116, 117, 262, |
| 160906 | + /* 590 */ 59, 43, 44, 45, 46, 47, 48, 49, 50, 51, |
| 160907 | + /* 600 */ 52, 53, 54, 55, 56, 57, 267, 215, 216, 238, |
| 159540 | 160908 | /* 610 */ 239, 102, 103, 104, 105, 106, 107, 108, 109, 110, |
| 159541 | | - /* 620 */ 111, 112, 251, 192, 137, 138, 59, 234, 235, 115, |
| 159542 | | - /* 630 */ 116, 117, 116, 76, 126, 127, 128, 19, 192, 268, |
| 159543 | | - /* 640 */ 19, 23, 22, 192, 252, 24, 89, 300, 301, 92, |
| 160909 | + /* 620 */ 111, 112, 251, 45, 46, 47, 59, 49, 291, 115, |
| 160910 | + /* 630 */ 116, 117, 116, 81, 192, 305, 306, 19, 192, 268, |
| 160911 | + /* 640 */ 19, 23, 22, 192, 252, 24, 115, 116, 117, 192, |
| 159544 | 160912 | /* 650 */ 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, |
| 159545 | 160913 | /* 660 */ 112, 43, 44, 45, 46, 47, 48, 49, 50, 51, |
| 159546 | | - /* 670 */ 52, 53, 54, 55, 56, 57, 19, 192, 192, 59, |
| 159547 | | - /* 680 */ 23, 192, 115, 116, 117, 200, 240, 307, 308, 22, |
| 159548 | | - /* 690 */ 205, 81, 312, 262, 22, 192, 133, 22, 135, 136, |
| 160914 | + /* 670 */ 52, 53, 54, 55, 56, 57, 19, 22, 23, 59, |
| 160915 | + /* 680 */ 23, 303, 115, 116, 117, 192, 240, 234, 235, 137, |
| 160916 | + /* 690 */ 138, 240, 308, 192, 22, 192, 312, 22, 120, 306, |
| 159549 | 160917 | /* 700 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, |
| 159550 | 160918 | /* 710 */ 53, 54, 55, 56, 57, 197, 95, 150, 215, 216, |
| 159551 | 160919 | /* 720 */ 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, |
| 159552 | | - /* 730 */ 112, 59, 192, 112, 59, 115, 116, 117, 192, 118, |
| 159553 | | - /* 740 */ 119, 120, 121, 122, 123, 124, 19, 137, 138, 303, |
| 159554 | | - /* 750 */ 23, 130, 192, 267, 192, 252, 267, 306, 203, 102, |
| 160920 | + /* 730 */ 112, 59, 231, 112, 59, 115, 116, 117, 25, 118, |
| 160921 | + /* 740 */ 119, 120, 121, 122, 123, 124, 19, 243, 81, 303, |
| 160922 | + /* 750 */ 23, 130, 192, 192, 303, 252, 101, 253, 203, 102, |
| 159555 | 160923 | /* 760 */ 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, |
| 159556 | 160924 | /* 770 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, |
| 159557 | | - /* 780 */ 53, 54, 55, 56, 57, 19, 240, 115, 116, 117, |
| 159558 | | - /* 790 */ 115, 116, 117, 238, 239, 222, 192, 224, 280, 237, |
| 159559 | | - /* 800 */ 240, 192, 284, 192, 59, 232, 251, 140, 204, 43, |
| 160925 | + /* 780 */ 53, 54, 55, 56, 57, 19, 119, 115, 116, 117, |
| 160926 | + /* 790 */ 115, 116, 117, 238, 239, 238, 239, 192, 280, 192, |
| 160927 | + /* 800 */ 240, 192, 284, 192, 137, 138, 251, 192, 251, 43, |
| 159560 | 160928 | /* 810 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, |
| 159561 | | - /* 820 */ 54, 55, 56, 57, 192, 35, 215, 216, 192, 102, |
| 160929 | + /* 820 */ 54, 55, 56, 57, 192, 35, 215, 216, 267, 102, |
| 159562 | 160930 | /* 830 */ 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, |
| 159563 | | - /* 840 */ 59, 230, 192, 192, 238, 239, 237, 215, 216, 303, |
| 159564 | | - /* 850 */ 308, 215, 216, 16, 312, 19, 66, 251, 126, 127, |
| 159565 | | - /* 860 */ 128, 116, 230, 303, 74, 203, 215, 216, 102, 103, |
| 160931 | + /* 840 */ 59, 230, 237, 192, 25, 192, 192, 215, 216, 240, |
| 160932 | + /* 850 */ 137, 138, 237, 16, 200, 19, 66, 192, 133, 205, |
| 160933 | + /* 860 */ 135, 136, 230, 303, 74, 203, 215, 216, 102, 103, |
| 159566 | 160934 | /* 870 */ 104, 105, 106, 107, 108, 109, 110, 111, 112, 43, |
| 159567 | 160935 | /* 880 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, |
| 159568 | | - /* 890 */ 54, 55, 56, 57, 192, 212, 115, 116, 117, 19, |
| 159569 | | - /* 900 */ 238, 239, 192, 252, 7, 8, 9, 192, 192, 238, |
| 159570 | | - /* 910 */ 239, 308, 262, 251, 77, 312, 79, 215, 216, 129, |
| 160936 | + /* 890 */ 54, 55, 56, 57, 192, 76, 115, 116, 117, 19, |
| 160937 | + /* 900 */ 238, 239, 192, 252, 126, 127, 128, 192, 89, 238, |
| 160938 | + /* 910 */ 239, 92, 303, 251, 77, 262, 79, 215, 216, 129, |
| 159571 | 160939 | /* 920 */ 210, 211, 251, 142, 158, 45, 46, 47, 48, 49, |
| 159572 | 160940 | /* 930 */ 50, 51, 52, 53, 54, 55, 56, 57, 102, 103, |
| 159573 | 160941 | /* 940 */ 104, 105, 106, 107, 108, 109, 110, 111, 112, 12, |
| 159574 | | - /* 950 */ 59, 192, 192, 237, 252, 243, 192, 192, 126, 127, |
| 159575 | | - /* 960 */ 128, 192, 308, 203, 27, 253, 312, 308, 285, 207, |
| 159576 | | - /* 970 */ 208, 312, 157, 290, 159, 215, 216, 262, 192, 42, |
| 160942 | + /* 950 */ 59, 308, 192, 212, 252, 312, 291, 192, 7, 8, |
| 160943 | + /* 960 */ 9, 300, 301, 203, 27, 126, 127, 128, 308, 207, |
| 160944 | + /* 970 */ 208, 192, 312, 29, 192, 215, 216, 33, 192, 42, |
| 159577 | 160945 | /* 980 */ 215, 216, 102, 103, 104, 105, 106, 107, 108, 109, |
| 159578 | | - /* 990 */ 110, 111, 112, 283, 158, 230, 237, 160, 238, 239, |
| 159579 | | - /* 1000 */ 63, 215, 216, 192, 192, 12, 115, 116, 117, 22, |
| 159580 | | - /* 1010 */ 73, 251, 252, 192, 19, 192, 230, 239, 24, 24, |
| 159581 | | - /* 1020 */ 27, 261, 210, 211, 99, 192, 215, 216, 225, 251, |
| 159582 | | - /* 1030 */ 192, 192, 263, 142, 19, 42, 215, 216, 43, 44, |
| 160946 | + /* 990 */ 110, 111, 112, 283, 158, 230, 66, 160, 238, 239, |
| 160947 | + /* 1000 */ 63, 215, 216, 192, 192, 12, 115, 116, 117, 65, |
| 160948 | + /* 1010 */ 73, 251, 252, 192, 19, 85, 230, 192, 24, 24, |
| 160949 | + /* 1020 */ 27, 261, 210, 211, 94, 192, 215, 216, 22, 207, |
| 160950 | + /* 1030 */ 208, 290, 192, 142, 19, 42, 215, 216, 43, 44, |
| 159583 | 160951 | /* 1040 */ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, |
| 159584 | | - /* 1050 */ 55, 56, 57, 59, 19, 291, 63, 132, 43, 44, |
| 160952 | + /* 1050 */ 55, 56, 57, 59, 19, 144, 63, 192, 43, 44, |
| 159585 | 160953 | /* 1060 */ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, |
| 159586 | | - /* 1070 */ 55, 56, 57, 252, 22, 23, 22, 25, 43, 44, |
| 160954 | + /* 1070 */ 55, 56, 57, 252, 163, 145, 114, 22, 43, 44, |
| 159587 | 160955 | /* 1080 */ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, |
| 159588 | | - /* 1090 */ 55, 56, 57, 106, 107, 283, 263, 102, 103, 104, |
| 160956 | + /* 1090 */ 55, 56, 57, 45, 212, 283, 263, 102, 103, 104, |
| 159589 | 160957 | /* 1100 */ 105, 106, 107, 108, 109, 110, 111, 112, 59, 192, |
| 159590 | | - /* 1110 */ 116, 144, 29, 59, 291, 192, 33, 102, 103, 104, |
| 159591 | | - /* 1120 */ 105, 106, 107, 108, 109, 110, 111, 112, 192, 291, |
| 159592 | | - /* 1130 */ 163, 19, 215, 216, 15, 192, 108, 102, 103, 104, |
| 159593 | | - /* 1140 */ 105, 106, 107, 108, 109, 110, 111, 112, 65, 192, |
| 159594 | | - /* 1150 */ 66, 215, 216, 101, 231, 106, 107, 19, 215, 216, |
| 159595 | | - /* 1160 */ 192, 212, 134, 114, 115, 116, 117, 139, 119, 85, |
| 159596 | | - /* 1170 */ 116, 207, 208, 230, 192, 19, 127, 192, 94, 60, |
| 160958 | + /* 1110 */ 116, 149, 106, 107, 59, 25, 291, 102, 103, 104, |
| 160959 | + /* 1120 */ 105, 106, 107, 108, 109, 110, 111, 112, 192, 22, |
| 160960 | + /* 1130 */ 192, 192, 215, 216, 23, 192, 25, 102, 103, 104, |
| 160961 | + /* 1140 */ 105, 106, 107, 108, 109, 110, 111, 112, 108, 192, |
| 160962 | + /* 1150 */ 192, 215, 216, 215, 216, 106, 107, 19, 215, 216, |
| 160963 | + /* 1160 */ 53, 59, 114, 114, 115, 116, 117, 285, 119, 137, |
| 160964 | + /* 1170 */ 138, 116, 290, 230, 134, 192, 127, 192, 192, 139, |
| 159597 | 160965 | /* 1180 */ 59, 192, 44, 45, 46, 47, 48, 49, 50, 51, |
| 159598 | | - /* 1190 */ 52, 53, 54, 55, 56, 57, 192, 76, 192, 31, |
| 159599 | | - /* 1200 */ 192, 152, 46, 154, 215, 216, 192, 39, 87, 192, |
| 159600 | | - /* 1210 */ 89, 19, 20, 92, 22, 192, 22, 23, 22, 230, |
| 159601 | | - /* 1220 */ 263, 215, 216, 215, 216, 137, 138, 115, 36, 145, |
| 159602 | | - /* 1230 */ 128, 192, 215, 216, 22, 23, 115, 116, 117, 290, |
| 160966 | + /* 1190 */ 52, 53, 54, 55, 56, 57, 308, 76, 215, 216, |
| 160967 | + /* 1200 */ 312, 152, 263, 154, 215, 216, 192, 117, 87, 19, |
| 160968 | + /* 1210 */ 89, 19, 20, 92, 22, 22, 23, 231, 116, 230, |
| 160969 | + /* 1220 */ 263, 263, 237, 203, 298, 299, 203, 239, 36, 215, |
| 160970 | + /* 1230 */ 216, 192, 142, 192, 15, 45, 115, 116, 117, 251, |
| 159603 | 160971 | /* 1240 */ 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, |
| 159604 | | - /* 1250 */ 112, 59, 192, 151, 215, 216, 192, 61, 203, 298, |
| 159605 | | - /* 1260 */ 299, 192, 192, 71, 25, 144, 203, 192, 203, 230, |
| 159606 | | - /* 1270 */ 114, 19, 20, 81, 22, 215, 216, 263, 192, 215, |
| 159607 | | - /* 1280 */ 216, 255, 256, 203, 215, 216, 130, 19, 36, 192, |
| 159608 | | - /* 1290 */ 215, 216, 100, 238, 239, 101, 25, 192, 106, 107, |
| 159609 | | - /* 1300 */ 48, 238, 239, 238, 239, 113, 251, 115, 116, 117, |
| 159610 | | - /* 1310 */ 192, 59, 120, 101, 251, 192, 251, 192, 238, 239, |
| 159611 | | - /* 1320 */ 215, 216, 192, 71, 46, 243, 192, 25, 25, 137, |
| 159612 | | - /* 1330 */ 138, 251, 192, 215, 216, 253, 25, 85, 215, 216, |
| 159613 | | - /* 1340 */ 215, 216, 90, 243, 152, 153, 154, 155, 156, 215, |
| 159614 | | - /* 1350 */ 216, 192, 100, 253, 243, 215, 216, 192, 106, 107, |
| 159615 | | - /* 1360 */ 243, 192, 148, 149, 253, 113, 192, 115, 116, 117, |
| 159616 | | - /* 1370 */ 253, 192, 120, 192, 215, 216, 192, 23, 192, 25, |
| 159617 | | - /* 1380 */ 215, 216, 192, 115, 215, 216, 22, 148, 24, 215, |
| 159618 | | - /* 1390 */ 216, 192, 114, 192, 215, 216, 215, 216, 134, 215, |
| 159619 | | - /* 1400 */ 216, 215, 216, 139, 152, 153, 154, 155, 156, 0, |
| 159620 | | - /* 1410 */ 1, 2, 141, 23, 5, 25, 215, 216, 24, 10, |
| 159621 | | - /* 1420 */ 11, 12, 13, 14, 1, 2, 17, 125, 5, 19, |
| 159622 | | - /* 1430 */ 20, 268, 22, 10, 11, 12, 13, 14, 192, 30, |
| 159623 | | - /* 1440 */ 17, 32, 23, 23, 25, 25, 36, 144, 23, 40, |
| 159624 | | - /* 1450 */ 25, 192, 141, 30, 192, 32, 23, 22, 25, 5, |
| 159625 | | - /* 1460 */ 128, 215, 216, 40, 10, 11, 12, 13, 14, 59, |
| 159626 | | - /* 1470 */ 23, 17, 25, 192, 215, 216, 192, 215, 216, 70, |
| 159627 | | - /* 1480 */ 23, 71, 25, 151, 30, 192, 32, 78, 53, 192, |
| 159628 | | - /* 1490 */ 81, 192, 192, 70, 40, 85, 215, 216, 119, 120, |
| 159629 | | - /* 1500 */ 90, 78, 59, 254, 81, 192, 192, 98, 215, 216, |
| 159630 | | - /* 1510 */ 100, 23, 59, 25, 215, 216, 106, 107, 23, 192, |
| 159631 | | - /* 1520 */ 25, 98, 19, 113, 70, 115, 116, 117, 215, 216, |
| 159632 | | - /* 1530 */ 120, 192, 78, 192, 140, 81, 19, 20, 23, 22, |
| 159633 | | - /* 1540 */ 25, 132, 215, 216, 192, 192, 137, 138, 192, 23, |
| 159634 | | - /* 1550 */ 192, 25, 98, 36, 192, 132, 215, 216, 192, 116, |
| 159635 | | - /* 1560 */ 137, 138, 152, 153, 154, 155, 156, 215, 216, 116, |
| 159636 | | - /* 1570 */ 161, 215, 216, 215, 216, 120, 59, 215, 216, 7, |
| 159637 | | - /* 1580 */ 8, 215, 216, 192, 161, 130, 132, 192, 71, 83, |
| 159638 | | - /* 1590 */ 84, 137, 138, 59, 192, 192, 19, 20, 192, 22, |
| 159639 | | - /* 1600 */ 97, 225, 85, 192, 23, 192, 25, 90, 192, 192, |
| 159640 | | - /* 1610 */ 215, 216, 152, 36, 154, 161, 192, 100, 215, 216, |
| 159641 | | - /* 1620 */ 192, 215, 216, 106, 107, 225, 215, 216, 192, 192, |
| 159642 | | - /* 1630 */ 113, 192, 115, 116, 117, 257, 59, 120, 192, 215, |
| 159643 | | - /* 1640 */ 216, 152, 192, 154, 192, 23, 317, 25, 71, 235, |
| 159644 | | - /* 1650 */ 116, 215, 216, 192, 215, 216, 192, 192, 192, 192, |
| 159645 | | - /* 1660 */ 192, 192, 192, 192, 192, 215, 216, 215, 216, 152, |
| 159646 | | - /* 1670 */ 153, 154, 155, 156, 192, 192, 287, 100, 286, 241, |
| 159647 | | - /* 1680 */ 254, 254, 242, 106, 107, 108, 254, 213, 254, 190, |
| 159648 | | - /* 1690 */ 113, 270, 115, 116, 117, 296, 266, 120, 219, 258, |
| 159649 | | - /* 1700 */ 244, 270, 258, 19, 20, 228, 22, 292, 266, 224, |
| 159650 | | - /* 1710 */ 292, 218, 218, 195, 218, 270, 258, 60, 245, 270, |
| 159651 | | - /* 1720 */ 36, 245, 244, 248, 19, 20, 242, 22, 248, 152, |
| 159652 | | - /* 1730 */ 153, 154, 155, 156, 244, 140, 199, 199, 279, 38, |
| 159653 | | - /* 1740 */ 199, 36, 150, 59, 296, 149, 22, 296, 18, 43, |
| 159654 | | - /* 1750 */ 236, 199, 233, 18, 198, 71, 293, 236, 271, 236, |
| 159655 | | - /* 1760 */ 269, 236, 148, 271, 59, 245, 269, 245, 282, 271, |
| 159656 | | - /* 1770 */ 199, 198, 233, 245, 293, 233, 71, 245, 157, 62, |
| 159657 | | - /* 1780 */ 22, 199, 198, 220, 100, 199, 198, 220, 199, 289, |
| 159658 | | - /* 1790 */ 106, 107, 288, 114, 226, 198, 217, 113, 64, 115, |
| 159659 | | - /* 1800 */ 116, 117, 217, 22, 120, 100, 223, 217, 217, 164, |
| 159660 | | - /* 1810 */ 223, 106, 107, 220, 125, 24, 217, 219, 113, 217, |
| 159661 | | - /* 1820 */ 115, 116, 117, 217, 311, 120, 226, 112, 304, 281, |
| 159662 | | - /* 1830 */ 281, 220, 114, 143, 260, 259, 152, 153, 154, 155, |
| 159663 | | - /* 1840 */ 156, 199, 91, 316, 82, 316, 147, 144, 22, 199, |
| 159664 | | - /* 1850 */ 249, 276, 157, 146, 260, 145, 278, 152, 153, 154, |
| 159665 | | - /* 1860 */ 155, 156, 259, 248, 260, 260, 259, 259, 249, 245, |
| 159666 | | - /* 1870 */ 247, 246, 25, 264, 264, 201, 13, 6, 193, 193, |
| 159667 | | - /* 1880 */ 212, 206, 191, 191, 191, 212, 206, 221, 212, 212, |
| 159668 | | - /* 1890 */ 221, 213, 4, 206, 213, 212, 3, 22, 162, 15, |
| 159669 | | - /* 1900 */ 23, 16, 23, 138, 150, 129, 25, 24, 141, 20, |
| 159670 | | - /* 1910 */ 16, 143, 1, 141, 302, 302, 299, 129, 129, 61, |
| 159671 | | - /* 1920 */ 150, 53, 53, 37, 129, 53, 53, 115, 1, 34, |
| 159672 | | - /* 1930 */ 140, 5, 22, 114, 160, 68, 75, 25, 68, 41, |
| 159673 | | - /* 1940 */ 140, 114, 24, 20, 19, 130, 124, 67, 24, 67, |
| 159674 | | - /* 1950 */ 22, 22, 22, 96, 23, 22, 59, 22, 67, 37, |
| 159675 | | - /* 1960 */ 28, 23, 148, 22, 25, 23, 23, 23, 23, 22, |
| 159676 | | - /* 1970 */ 140, 97, 23, 23, 115, 22, 142, 25, 88, 75, |
| 159677 | | - /* 1980 */ 34, 44, 34, 75, 23, 34, 86, 22, 34, 34, |
| 159678 | | - /* 1990 */ 34, 24, 93, 25, 25, 23, 34, 23, 23, 23, |
| 159679 | | - /* 2000 */ 23, 11, 23, 25, 22, 22, 22, 1, 23, 23, |
| 159680 | | - /* 2010 */ 22, 22, 25, 15, 23, 1, 140, 25, 140, 318, |
| 159681 | | - /* 2020 */ 318, 134, 318, 318, 318, 318, 318, 318, 318, 318, |
| 159682 | | - /* 2030 */ 318, 318, 140, 318, 318, 318, 140, 318, 318, 318, |
| 160972 | + /* 1250 */ 112, 59, 192, 203, 215, 216, 215, 216, 238, 239, |
| 160973 | + /* 1260 */ 192, 238, 239, 71, 192, 144, 25, 203, 243, 230, |
| 160974 | + /* 1270 */ 243, 251, 192, 81, 251, 215, 216, 243, 253, 60, |
| 160975 | + /* 1280 */ 253, 255, 256, 19, 20, 25, 22, 253, 238, 239, |
| 160976 | + /* 1290 */ 192, 192, 100, 192, 101, 215, 216, 19, 106, 107, |
| 160977 | + /* 1300 */ 36, 251, 238, 239, 114, 113, 192, 115, 116, 117, |
| 160978 | + /* 1310 */ 192, 47, 120, 215, 216, 251, 215, 216, 192, 31, |
| 160979 | + /* 1320 */ 130, 134, 243, 59, 148, 149, 139, 39, 192, 137, |
| 160980 | + /* 1330 */ 138, 263, 253, 215, 216, 71, 19, 157, 192, 159, |
| 160981 | + /* 1340 */ 128, 215, 216, 25, 152, 153, 154, 155, 156, 85, |
| 160982 | + /* 1350 */ 192, 215, 216, 268, 90, 0, 1, 2, 192, 192, |
| 160983 | + /* 1360 */ 5, 215, 216, 151, 100, 10, 11, 12, 13, 14, |
| 160984 | + /* 1370 */ 106, 107, 17, 215, 216, 19, 20, 113, 22, 115, |
| 160985 | + /* 1380 */ 116, 117, 215, 216, 120, 30, 192, 32, 192, 148, |
| 160986 | + /* 1390 */ 192, 24, 36, 115, 22, 40, 24, 23, 192, 25, |
| 160987 | + /* 1400 */ 128, 23, 99, 25, 144, 192, 22, 192, 192, 215, |
| 160988 | + /* 1410 */ 216, 215, 216, 215, 216, 59, 152, 153, 154, 155, |
| 160989 | + /* 1420 */ 156, 215, 216, 151, 192, 70, 192, 71, 215, 216, |
| 160990 | + /* 1430 */ 215, 216, 115, 78, 192, 132, 81, 192, 23, 22, |
| 160991 | + /* 1440 */ 25, 85, 192, 192, 192, 61, 90, 215, 216, 215, |
| 160992 | + /* 1450 */ 216, 192, 225, 98, 192, 192, 100, 215, 216, 141, |
| 160993 | + /* 1460 */ 215, 216, 106, 107, 225, 215, 216, 215, 216, 113, |
| 160994 | + /* 1470 */ 59, 115, 116, 117, 215, 216, 120, 215, 216, 192, |
| 160995 | + /* 1480 */ 120, 192, 19, 20, 23, 22, 25, 132, 119, 120, |
| 160996 | + /* 1490 */ 130, 192, 137, 138, 192, 23, 192, 25, 192, 36, |
| 160997 | + /* 1500 */ 192, 192, 215, 216, 215, 216, 192, 140, 152, 153, |
| 160998 | + /* 1510 */ 154, 155, 156, 192, 215, 216, 161, 215, 216, 215, |
| 160999 | + /* 1520 */ 216, 192, 59, 215, 216, 19, 192, 116, 192, 215, |
| 161000 | + /* 1530 */ 216, 23, 59, 25, 71, 192, 215, 216, 192, 23, |
| 161001 | + /* 1540 */ 23, 25, 25, 192, 215, 216, 7, 8, 85, 215, |
| 161002 | + /* 1550 */ 216, 215, 216, 90, 192, 1, 2, 140, 192, 5, |
| 161003 | + /* 1560 */ 192, 215, 216, 100, 10, 11, 12, 13, 14, 106, |
| 161004 | + /* 1570 */ 107, 17, 192, 23, 192, 25, 113, 192, 115, 116, |
| 161005 | + /* 1580 */ 117, 215, 216, 120, 30, 59, 32, 19, 20, 116, |
| 161006 | + /* 1590 */ 22, 192, 83, 84, 40, 215, 216, 215, 216, 192, |
| 161007 | + /* 1600 */ 215, 216, 192, 97, 36, 192, 19, 20, 23, 22, |
| 161008 | + /* 1610 */ 25, 23, 152, 25, 154, 152, 153, 154, 155, 156, |
| 161009 | + /* 1620 */ 152, 225, 154, 36, 70, 215, 216, 59, 215, 216, |
| 161010 | + /* 1630 */ 192, 23, 78, 25, 23, 81, 25, 192, 192, 71, |
| 161011 | + /* 1640 */ 257, 192, 116, 192, 192, 254, 59, 317, 192, 192, |
| 161012 | + /* 1650 */ 192, 235, 98, 241, 192, 254, 192, 192, 71, 192, |
| 161013 | + /* 1660 */ 287, 192, 192, 286, 242, 190, 213, 296, 100, 266, |
| 161014 | + /* 1670 */ 270, 244, 254, 254, 106, 107, 108, 254, 258, 258, |
| 161015 | + /* 1680 */ 266, 113, 292, 115, 116, 117, 132, 100, 120, 245, |
| 161016 | + /* 1690 */ 292, 137, 138, 106, 107, 19, 20, 219, 22, 270, |
| 161017 | + /* 1700 */ 113, 270, 115, 116, 117, 270, 224, 120, 228, 218, |
| 161018 | + /* 1710 */ 218, 245, 36, 218, 195, 161, 279, 258, 244, 248, |
| 161019 | + /* 1720 */ 152, 153, 154, 155, 156, 248, 242, 244, 60, 296, |
| 161020 | + /* 1730 */ 296, 140, 199, 199, 38, 59, 293, 199, 149, 152, |
| 161021 | + /* 1740 */ 153, 154, 155, 156, 150, 5, 22, 71, 293, 43, |
| 161022 | + /* 1750 */ 10, 11, 12, 13, 14, 269, 271, 17, 282, 18, |
| 161023 | + /* 1760 */ 233, 236, 199, 18, 236, 236, 236, 198, 148, 245, |
| 161024 | + /* 1770 */ 30, 271, 32, 271, 269, 233, 100, 245, 233, 199, |
| 161025 | + /* 1780 */ 40, 245, 106, 107, 198, 245, 157, 289, 62, 113, |
| 161026 | + /* 1790 */ 198, 115, 116, 117, 199, 288, 120, 22, 220, 199, |
| 161027 | + /* 1800 */ 198, 220, 199, 198, 114, 226, 64, 217, 22, 125, |
| 161028 | + /* 1810 */ 70, 164, 311, 217, 217, 217, 223, 24, 78, 304, |
| 161029 | + /* 1820 */ 219, 81, 223, 217, 220, 112, 217, 217, 152, 153, |
| 161030 | + /* 1830 */ 154, 155, 156, 226, 281, 220, 281, 143, 98, 114, |
| 161031 | + /* 1840 */ 199, 91, 260, 259, 82, 147, 144, 316, 22, 276, |
| 161032 | + /* 1850 */ 199, 316, 157, 278, 146, 145, 25, 201, 13, 193, |
| 161033 | + /* 1860 */ 193, 6, 191, 191, 191, 299, 302, 302, 206, 246, |
| 161034 | + /* 1870 */ 248, 259, 132, 260, 260, 259, 259, 137, 138, 260, |
| 161035 | + /* 1880 */ 249, 249, 264, 247, 245, 264, 212, 212, 206, 212, |
| 161036 | + /* 1890 */ 212, 221, 206, 213, 213, 212, 4, 3, 22, 162, |
| 161037 | + /* 1900 */ 221, 161, 15, 23, 16, 23, 138, 150, 129, 25, |
| 161038 | + /* 1910 */ 24, 141, 143, 20, 16, 1, 129, 141, 129, 61, |
| 161039 | + /* 1920 */ 37, 150, 53, 53, 53, 53, 129, 115, 140, 34, |
| 161040 | + /* 1930 */ 1, 5, 22, 114, 160, 68, 25, 75, 41, 140, |
| 161041 | + /* 1940 */ 24, 68, 114, 20, 19, 130, 124, 23, 67, 22, |
| 161042 | + /* 1950 */ 22, 148, 22, 22, 37, 59, 67, 24, 22, 96, |
| 161043 | + /* 1960 */ 28, 23, 22, 97, 23, 23, 67, 23, 25, 23, |
| 161044 | + /* 1970 */ 22, 115, 140, 23, 23, 22, 142, 25, 88, 34, |
| 161045 | + /* 1980 */ 75, 34, 75, 34, 93, 23, 86, 22, 34, 34, |
| 161046 | + /* 1990 */ 24, 34, 25, 25, 34, 23, 23, 23, 23, 23, |
| 161047 | + /* 2000 */ 44, 23, 25, 22, 11, 22, 22, 25, 23, 23, |
| 161048 | + /* 2010 */ 22, 22, 134, 23, 140, 140, 25, 140, 15, 140, |
| 161049 | + /* 2020 */ 1, 1, 318, 318, 318, 318, 318, 318, 318, 318, |
| 161050 | + /* 2030 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, |
| 159683 | 161051 | /* 2040 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, |
| 159684 | 161052 | /* 2050 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, |
| 159685 | 161053 | /* 2060 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, |
| 159686 | 161054 | /* 2070 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, |
| 159687 | 161055 | /* 2080 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, |
| | @@ -159694,122 +161062,120 @@ |
| 159694 | 161062 | /* 2150 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, |
| 159695 | 161063 | /* 2160 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, |
| 159696 | 161064 | /* 2170 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, |
| 159697 | 161065 | /* 2180 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, |
| 159698 | 161066 | /* 2190 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, |
| 159699 | | - /* 2200 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, |
| 159700 | | - /* 2210 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, |
| 159701 | | - /* 2220 */ 318, |
| 161067 | + /* 2200 */ 318, 318, 318, 318, 318, 318, |
| 159702 | 161068 | }; |
| 159703 | 161069 | #define YY_SHIFT_COUNT (571) |
| 159704 | 161070 | #define YY_SHIFT_MIN (0) |
| 159705 | | -#define YY_SHIFT_MAX (2014) |
| 161071 | +#define YY_SHIFT_MAX (2020) |
| 159706 | 161072 | static const unsigned short int yy_shift_ofst[] = { |
| 159707 | | - /* 0 */ 1423, 1409, 1454, 1192, 1192, 610, 1252, 1410, 1517, 1684, |
| 159708 | | - /* 10 */ 1684, 1684, 276, 0, 0, 180, 1015, 1684, 1684, 1684, |
| 159709 | | - /* 20 */ 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, |
| 159710 | | - /* 30 */ 1049, 1049, 1121, 1121, 54, 487, 610, 610, 610, 610, |
| 159711 | | - /* 40 */ 610, 40, 110, 219, 289, 396, 439, 509, 548, 618, |
| 161073 | + /* 0 */ 1554, 1355, 1740, 1192, 1192, 552, 1264, 1356, 1463, 1587, |
| 161074 | + /* 10 */ 1587, 1587, 276, 0, 0, 180, 1015, 1587, 1587, 1587, |
| 161075 | + /* 20 */ 1587, 1587, 1587, 1587, 1587, 1587, 1587, 1587, 1587, 1587, |
| 161076 | + /* 30 */ 1049, 1049, 1121, 1121, 54, 667, 552, 552, 552, 552, |
| 161077 | + /* 40 */ 552, 40, 110, 219, 289, 396, 439, 509, 548, 618, |
| 159712 | 161078 | /* 50 */ 657, 727, 766, 836, 995, 1015, 1015, 1015, 1015, 1015, |
| 159713 | 161079 | /* 60 */ 1015, 1015, 1015, 1015, 1015, 1015, 1015, 1015, 1015, 1015, |
| 159714 | | - /* 70 */ 1015, 1015, 1015, 1035, 1015, 1138, 880, 880, 1577, 1684, |
| 159715 | | - /* 80 */ 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, |
| 159716 | | - /* 90 */ 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, |
| 159717 | | - /* 100 */ 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, |
| 159718 | | - /* 110 */ 1684, 1684, 1684, 1705, 1684, 1684, 1684, 1684, 1684, 1684, |
| 159719 | | - /* 120 */ 1684, 1684, 1684, 1684, 1684, 1684, 1684, 146, 84, 84, |
| 159720 | | - /* 130 */ 84, 84, 84, 277, 315, 401, 97, 461, 251, 66, |
| 159721 | | - /* 140 */ 66, 51, 1156, 66, 66, 324, 324, 66, 452, 452, |
| 159722 | | - /* 150 */ 452, 452, 133, 114, 114, 4, 11, 2037, 2037, 621, |
| 161080 | + /* 70 */ 1015, 1015, 1015, 1035, 1015, 1138, 880, 880, 1568, 1587, |
| 161081 | + /* 80 */ 1587, 1587, 1587, 1587, 1587, 1587, 1587, 1587, 1587, 1587, |
| 161082 | + /* 90 */ 1587, 1587, 1587, 1587, 1587, 1587, 1587, 1587, 1587, 1587, |
| 161083 | + /* 100 */ 1587, 1587, 1587, 1587, 1587, 1587, 1587, 1587, 1587, 1587, |
| 161084 | + /* 110 */ 1587, 1587, 1587, 1676, 1587, 1587, 1587, 1587, 1587, 1587, |
| 161085 | + /* 120 */ 1587, 1587, 1587, 1587, 1587, 1587, 1587, 146, 84, 84, |
| 161086 | + /* 130 */ 84, 84, 84, 277, 315, 401, 97, 461, 251, 531, |
| 161087 | + /* 140 */ 531, 51, 1190, 531, 531, 324, 324, 531, 713, 713, |
| 161088 | + /* 150 */ 713, 713, 151, 154, 154, 4, 149, 2022, 2022, 621, |
| 159723 | 161089 | /* 160 */ 621, 621, 567, 398, 398, 398, 398, 937, 937, 228, |
| 159724 | | - /* 170 */ 251, 331, 1052, 66, 66, 66, 66, 66, 66, 66, |
| 159725 | | - /* 180 */ 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, |
| 159726 | | - /* 190 */ 66, 66, 66, 557, 557, 66, 9, 25, 25, 745, |
| 159727 | | - /* 200 */ 745, 967, 1088, 2037, 2037, 2037, 2037, 2037, 2037, 2037, |
| 161090 | + /* 170 */ 251, 159, 331, 531, 531, 531, 531, 531, 531, 531, |
| 161091 | + /* 180 */ 531, 531, 531, 531, 531, 531, 531, 531, 531, 531, |
| 161092 | + /* 190 */ 531, 531, 531, 819, 819, 531, 9, 25, 25, 1102, |
| 161093 | + /* 200 */ 1102, 911, 1032, 2022, 2022, 2022, 2022, 2022, 2022, 2022, |
| 159728 | 161094 | /* 210 */ 255, 317, 317, 514, 403, 620, 471, 672, 781, 891, |
| 159729 | | - /* 220 */ 675, 66, 66, 66, 66, 66, 66, 66, 66, 66, |
| 159730 | | - /* 230 */ 66, 508, 66, 66, 66, 66, 66, 66, 66, 66, |
| 159731 | | - /* 240 */ 66, 66, 66, 66, 790, 790, 790, 66, 66, 66, |
| 159732 | | - /* 250 */ 338, 66, 66, 66, 516, 1084, 66, 66, 993, 66, |
| 159733 | | - /* 260 */ 66, 66, 66, 66, 66, 66, 66, 732, 1083, 563, |
| 159734 | | - /* 270 */ 994, 994, 994, 994, 337, 563, 563, 1028, 987, 897, |
| 159735 | | - /* 280 */ 1119, 262, 1214, 1271, 1112, 1214, 1112, 1268, 1239, 262, |
| 159736 | | - /* 290 */ 262, 1239, 262, 1271, 1268, 1302, 1354, 1278, 1168, 1168, |
| 159737 | | - /* 300 */ 1168, 1112, 1303, 1303, 815, 1311, 1264, 1364, 1657, 1657, |
| 159738 | | - /* 310 */ 1595, 1595, 1701, 1701, 1595, 1592, 1596, 1724, 1706, 1730, |
| 159739 | | - /* 320 */ 1730, 1730, 1730, 1595, 1735, 1614, 1596, 1596, 1614, 1724, |
| 159740 | | - /* 330 */ 1706, 1614, 1706, 1614, 1595, 1735, 1621, 1717, 1595, 1735, |
| 159741 | | - /* 340 */ 1758, 1595, 1735, 1595, 1735, 1758, 1679, 1679, 1679, 1734, |
| 159742 | | - /* 350 */ 1781, 1781, 1758, 1679, 1689, 1679, 1734, 1679, 1679, 1645, |
| 159743 | | - /* 360 */ 1791, 1715, 1715, 1758, 1690, 1718, 1690, 1718, 1690, 1718, |
| 159744 | | - /* 370 */ 1690, 1718, 1595, 1751, 1751, 1762, 1762, 1699, 1703, 1826, |
| 159745 | | - /* 380 */ 1595, 1695, 1699, 1707, 1710, 1614, 1847, 1863, 1863, 1871, |
| 159746 | | - /* 390 */ 1871, 1871, 2037, 2037, 2037, 2037, 2037, 2037, 2037, 2037, |
| 159747 | | - /* 400 */ 2037, 2037, 2037, 2037, 2037, 2037, 2037, 193, 837, 1194, |
| 159748 | | - /* 410 */ 1212, 506, 832, 1054, 1390, 925, 1435, 1394, 1102, 1332, |
| 159749 | | - /* 420 */ 1419, 1196, 1420, 1425, 1433, 1447, 1457, 1488, 1443, 1379, |
| 159750 | | - /* 430 */ 1572, 1455, 1503, 1453, 1495, 1515, 1506, 1526, 1460, 1489, |
| 159751 | | - /* 440 */ 1581, 1622, 1534, 667, 1888, 1893, 1875, 1736, 1884, 1885, |
| 159752 | | - /* 450 */ 1877, 1879, 1765, 1754, 1776, 1881, 1881, 1883, 1767, 1889, |
| 159753 | | - /* 460 */ 1768, 1894, 1911, 1772, 1788, 1881, 1789, 1858, 1886, 1881, |
| 159754 | | - /* 470 */ 1770, 1868, 1869, 1872, 1873, 1795, 1812, 1895, 1790, 1927, |
| 159755 | | - /* 480 */ 1926, 1910, 1819, 1774, 1867, 1912, 1870, 1861, 1898, 1800, |
| 159756 | | - /* 490 */ 1827, 1918, 1923, 1925, 1815, 1822, 1928, 1880, 1929, 1930, |
| 159757 | | - /* 500 */ 1931, 1933, 1882, 1897, 1924, 1857, 1932, 1935, 1891, 1922, |
| 159758 | | - /* 510 */ 1938, 1814, 1941, 1942, 1943, 1944, 1939, 1945, 1947, 1874, |
| 159759 | | - /* 520 */ 1830, 1949, 1950, 1859, 1946, 1953, 1834, 1952, 1948, 1951, |
| 159760 | | - /* 530 */ 1954, 1955, 1890, 1904, 1900, 1937, 1908, 1899, 1956, 1961, |
| 159761 | | - /* 540 */ 1965, 1967, 1968, 1969, 1962, 1972, 1952, 1974, 1975, 1976, |
| 159762 | | - /* 550 */ 1977, 1978, 1979, 1982, 1990, 1983, 1984, 1985, 1986, 1988, |
| 159763 | | - /* 560 */ 1989, 1987, 1887, 1876, 1878, 1892, 1896, 1992, 1991, 1998, |
| 159764 | | - /* 570 */ 2006, 2014, |
| 161095 | + /* 220 */ 675, 531, 531, 531, 531, 531, 531, 531, 531, 531, |
| 161096 | + /* 230 */ 531, 454, 531, 531, 531, 531, 531, 531, 531, 531, |
| 161097 | + /* 240 */ 531, 531, 531, 531, 790, 790, 790, 531, 531, 531, |
| 161098 | + /* 250 */ 338, 531, 531, 531, 516, 930, 531, 531, 993, 531, |
| 161099 | + /* 260 */ 531, 531, 531, 531, 531, 531, 531, 778, 944, 725, |
| 161100 | + /* 270 */ 994, 994, 994, 994, 1090, 725, 725, 1040, 1006, 951, |
| 161101 | + /* 280 */ 1219, 962, 1176, 98, 1278, 1176, 1278, 1317, 1241, 962, |
| 161102 | + /* 290 */ 962, 1241, 962, 98, 1317, 286, 1111, 1048, 1288, 1288, |
| 161103 | + /* 300 */ 1288, 1278, 1260, 1260, 1180, 1318, 1187, 1372, 1668, 1668, |
| 161104 | + /* 310 */ 1591, 1591, 1696, 1696, 1591, 1594, 1589, 1724, 1706, 1741, |
| 161105 | + /* 320 */ 1741, 1741, 1741, 1591, 1745, 1620, 1589, 1589, 1620, 1724, |
| 161106 | + /* 330 */ 1706, 1620, 1706, 1620, 1591, 1745, 1629, 1726, 1591, 1745, |
| 161107 | + /* 340 */ 1775, 1591, 1745, 1591, 1745, 1775, 1690, 1690, 1690, 1742, |
| 161108 | + /* 350 */ 1786, 1786, 1775, 1690, 1684, 1690, 1742, 1690, 1690, 1647, |
| 161109 | + /* 360 */ 1793, 1713, 1713, 1775, 1694, 1725, 1694, 1725, 1694, 1725, |
| 161110 | + /* 370 */ 1694, 1725, 1591, 1750, 1750, 1762, 1762, 1698, 1702, 1826, |
| 161111 | + /* 380 */ 1591, 1695, 1698, 1708, 1710, 1620, 1831, 1845, 1845, 1855, |
| 161112 | + /* 390 */ 1855, 1855, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, |
| 161113 | + /* 400 */ 2022, 2022, 2022, 2022, 2022, 2022, 2022, 578, 837, 655, |
| 161114 | + /* 410 */ 1193, 167, 839, 1055, 1374, 1303, 1107, 1367, 1212, 1272, |
| 161115 | + /* 420 */ 1378, 1384, 1415, 1461, 1472, 1508, 1516, 1517, 1411, 1369, |
| 161116 | + /* 430 */ 1539, 1360, 1506, 1473, 1550, 1585, 1509, 1588, 1460, 1468, |
| 161117 | + /* 440 */ 1608, 1611, 1526, 1417, 1892, 1894, 1876, 1737, 1887, 1888, |
| 161118 | + /* 450 */ 1880, 1882, 1768, 1757, 1779, 1884, 1884, 1886, 1770, 1893, |
| 161119 | + /* 460 */ 1769, 1898, 1914, 1776, 1787, 1884, 1789, 1858, 1883, 1884, |
| 161120 | + /* 470 */ 1771, 1869, 1870, 1871, 1872, 1797, 1812, 1895, 1788, 1929, |
| 161121 | + /* 480 */ 1926, 1910, 1819, 1774, 1867, 1911, 1873, 1862, 1897, 1799, |
| 161122 | + /* 490 */ 1828, 1916, 1923, 1925, 1815, 1822, 1927, 1881, 1928, 1930, |
| 161123 | + /* 500 */ 1924, 1931, 1889, 1896, 1933, 1863, 1932, 1936, 1899, 1917, |
| 161124 | + /* 510 */ 1938, 1803, 1940, 1941, 1942, 1944, 1943, 1946, 1948, 1866, |
| 161125 | + /* 520 */ 1832, 1950, 1951, 1856, 1945, 1953, 1834, 1952, 1947, 1949, |
| 161126 | + /* 530 */ 1954, 1955, 1890, 1905, 1900, 1956, 1907, 1891, 1957, 1962, |
| 161127 | + /* 540 */ 1965, 1966, 1967, 1968, 1960, 1972, 1952, 1973, 1974, 1975, |
| 161128 | + /* 550 */ 1976, 1977, 1978, 1981, 1993, 1983, 1984, 1985, 1986, 1988, |
| 161129 | + /* 560 */ 1989, 1982, 1878, 1874, 1875, 1877, 1879, 1991, 1990, 2003, |
| 161130 | + /* 570 */ 2019, 2020, |
| 159765 | 161131 | }; |
| 159766 | 161132 | #define YY_REDUCE_COUNT (406) |
| 159767 | 161133 | #define YY_REDUCE_MIN (-272) |
| 159768 | | -#define YY_REDUCE_MAX (1693) |
| 161134 | +#define YY_REDUCE_MAX (1686) |
| 159769 | 161135 | static const short yy_reduce_ofst[] = { |
| 159770 | 161136 | /* 0 */ 109, 113, 272, 760, -178, -176, -192, -183, -180, -134, |
| 159771 | 161137 | /* 10 */ 213, 220, 371, -208, -205, -272, -197, 611, 632, 765, |
| 159772 | 161138 | /* 20 */ 786, 392, 943, 989, 503, 651, 1039, -18, 702, 821, |
| 159773 | | - /* 30 */ 710, 812, -188, 380, -187, 555, 662, 1055, 1063, 1065, |
| 159774 | | - /* 40 */ 1080, -267, -267, -267, -267, -267, -267, -267, -267, -267, |
| 161139 | + /* 30 */ 710, 812, -188, -67, -187, 555, 662, 1020, 1023, 1050, |
| 161140 | + /* 40 */ 1064, -267, -267, -267, -267, -267, -267, -267, -267, -267, |
| 159775 | 161141 | /* 50 */ -267, -267, -267, -267, -267, -267, -267, -267, -267, -267, |
| 159776 | 161142 | /* 60 */ -267, -267, -267, -267, -267, -267, -267, -267, -267, -267, |
| 159777 | | - /* 70 */ -267, -267, -267, -267, -267, -267, -267, -267, 636, 811, |
| 159778 | | - /* 80 */ 917, 936, 1006, 1008, 1017, 1060, 1064, 1069, 1075, 1105, |
| 159779 | | - /* 90 */ 1118, 1123, 1125, 1134, 1140, 1159, 1165, 1169, 1174, 1179, |
| 159780 | | - /* 100 */ 1181, 1184, 1186, 1201, 1246, 1259, 1262, 1281, 1293, 1299, |
| 159781 | | - /* 110 */ 1313, 1327, 1341, 1352, 1356, 1358, 1362, 1366, 1395, 1403, |
| 159782 | | - /* 120 */ 1406, 1411, 1424, 1436, 1439, 1450, 1452, -267, -267, -267, |
| 159783 | | - /* 130 */ -267, -267, -267, -267, -267, 224, -267, 446, -24, 275, |
| 159784 | | - /* 140 */ 546, 518, 573, 560, 53, -181, -111, 485, 606, 671, |
| 159785 | | - /* 150 */ 606, 671, 683, 8, 93, -267, -267, -267, -267, 155, |
| 159786 | | - /* 160 */ 155, 155, 181, 242, 264, 486, 489, -218, 393, 227, |
| 159787 | | - /* 170 */ 604, 347, 347, -171, 431, 650, 715, -166, 562, 609, |
| 159788 | | - /* 180 */ 716, 764, 18, 823, 769, 833, 838, 957, 759, 119, |
| 159789 | | - /* 190 */ 923, 226, 1014, 542, 603, 451, 949, 654, 659, 762, |
| 159790 | | - /* 200 */ 964, -4, 778, 961, 712, 1082, 1100, 1111, 1026, 1117, |
| 159791 | | - /* 210 */ -204, -174, -151, -8, 77, 198, 305, 327, 388, 540, |
| 159792 | | - /* 220 */ 839, 968, 982, 985, 1004, 1023, 1070, 1086, 1097, 1130, |
| 159793 | | - /* 230 */ 1190, 1163, 1199, 1284, 1297, 1300, 1314, 1339, 1353, 1391, |
| 159794 | | - /* 240 */ 1402, 1413, 1416, 1417, 803, 1376, 1400, 1428, 1437, 1446, |
| 159795 | | - /* 250 */ 1378, 1461, 1464, 1465, 1249, 1329, 1466, 1467, 1414, 1468, |
| 159796 | | - /* 260 */ 305, 1469, 1470, 1471, 1472, 1482, 1483, 1389, 1392, 1438, |
| 159797 | | - /* 270 */ 1426, 1427, 1432, 1434, 1378, 1438, 1438, 1440, 1474, 1499, |
| 159798 | | - /* 280 */ 1399, 1421, 1430, 1456, 1441, 1442, 1444, 1415, 1473, 1431, |
| 159799 | | - /* 290 */ 1445, 1476, 1449, 1478, 1418, 1479, 1477, 1485, 1493, 1494, |
| 159800 | | - /* 300 */ 1496, 1458, 1475, 1480, 1459, 1490, 1484, 1518, 1448, 1451, |
| 159801 | | - /* 310 */ 1537, 1538, 1463, 1481, 1541, 1486, 1487, 1491, 1519, 1514, |
| 159802 | | - /* 320 */ 1521, 1523, 1525, 1552, 1556, 1520, 1492, 1498, 1522, 1497, |
| 159803 | | - /* 330 */ 1539, 1528, 1542, 1532, 1571, 1573, 1500, 1504, 1582, 1584, |
| 159804 | | - /* 340 */ 1563, 1586, 1588, 1589, 1597, 1567, 1579, 1585, 1590, 1568, |
| 159805 | | - /* 350 */ 1583, 1587, 1593, 1591, 1598, 1599, 1600, 1602, 1606, 1513, |
| 159806 | | - /* 360 */ 1524, 1548, 1549, 1611, 1574, 1576, 1594, 1603, 1604, 1607, |
| 159807 | | - /* 370 */ 1605, 1608, 1642, 1527, 1529, 1609, 1610, 1601, 1615, 1575, |
| 159808 | | - /* 380 */ 1650, 1578, 1619, 1623, 1625, 1624, 1674, 1685, 1686, 1691, |
| 159809 | | - /* 390 */ 1692, 1693, 1612, 1613, 1617, 1675, 1668, 1673, 1676, 1677, |
| 159810 | | - /* 400 */ 1680, 1666, 1669, 1678, 1681, 1683, 1687, |
| 161143 | + /* 70 */ -267, -267, -267, -267, -267, -267, -267, -267, 811, 917, |
| 161144 | + /* 80 */ 936, 938, 983, 1014, 1041, 1060, 1080, 1098, 1101, 1118, |
| 161145 | + /* 90 */ 1126, 1136, 1146, 1158, 1167, 1194, 1196, 1198, 1206, 1213, |
| 161146 | + /* 100 */ 1215, 1232, 1234, 1242, 1245, 1250, 1252, 1259, 1262, 1287, |
| 161147 | + /* 110 */ 1289, 1299, 1302, 1304, 1308, 1314, 1321, 1329, 1334, 1336, |
| 161148 | + /* 120 */ 1346, 1366, 1380, 1382, 1385, 1410, 1413, -267, -267, -267, |
| 161149 | + /* 130 */ -267, -267, -267, -267, -267, 446, -267, 451, -24, 121, |
| 161150 | + /* 140 */ 560, 518, 232, 609, 330, -181, -111, 654, 557, 671, |
| 161151 | + /* 150 */ 557, 671, 882, -30, 93, -267, -267, -267, -267, 155, |
| 161152 | + /* 160 */ 155, 155, 181, 242, 305, 339, 561, -218, 453, 227, |
| 161153 | + /* 170 */ 158, 661, 661, -171, 114, 327, 653, -166, 275, 605, |
| 161154 | + /* 180 */ 615, 337, 833, 665, 939, 957, 825, 958, 985, 501, |
| 161155 | + /* 190 */ 986, 378, 1068, 384, 643, 393, 741, 660, 888, 762, |
| 161156 | + /* 200 */ 822, 229, 988, 926, 504, 1025, 1027, 1034, 1026, 1079, |
| 161157 | + /* 210 */ -204, -174, -151, 18, 130, 198, 226, 376, 391, 442, |
| 161158 | + /* 220 */ 457, 493, 607, 715, 779, 782, 840, 865, 1072, 1099, |
| 161159 | + /* 230 */ 1114, 1085, 1166, 1216, 1251, 1263, 1306, 1309, 1343, 1351, |
| 161160 | + /* 240 */ 1362, 1368, 1399, 1407, 1227, 1239, 1396, 1438, 1445, 1446, |
| 161161 | + /* 250 */ 1383, 1449, 1451, 1452, 1391, 1330, 1456, 1457, 1416, 1458, |
| 161162 | + /* 260 */ 226, 1462, 1464, 1465, 1467, 1469, 1470, 1373, 1377, 1412, |
| 161163 | + /* 270 */ 1401, 1418, 1419, 1423, 1383, 1412, 1412, 1422, 1453, 1475, |
| 161164 | + /* 280 */ 1371, 1400, 1403, 1427, 1420, 1414, 1421, 1390, 1444, 1429, |
| 161165 | + /* 290 */ 1431, 1466, 1435, 1474, 1398, 1478, 1480, 1482, 1491, 1492, |
| 161166 | + /* 300 */ 1495, 1459, 1471, 1477, 1437, 1483, 1484, 1519, 1433, 1434, |
| 161167 | + /* 310 */ 1533, 1534, 1443, 1455, 1538, 1476, 1485, 1486, 1527, 1525, |
| 161168 | + /* 320 */ 1528, 1529, 1530, 1563, 1569, 1524, 1500, 1502, 1532, 1505, |
| 161169 | + /* 330 */ 1542, 1536, 1545, 1540, 1580, 1586, 1498, 1507, 1595, 1592, |
| 161170 | + /* 340 */ 1578, 1600, 1602, 1603, 1605, 1581, 1590, 1596, 1597, 1579, |
| 161171 | + /* 350 */ 1593, 1599, 1604, 1598, 1601, 1606, 1607, 1609, 1610, 1501, |
| 161172 | + /* 360 */ 1515, 1553, 1555, 1615, 1582, 1584, 1613, 1612, 1614, 1616, |
| 161173 | + /* 370 */ 1619, 1617, 1641, 1531, 1535, 1618, 1621, 1631, 1622, 1573, |
| 161174 | + /* 380 */ 1651, 1575, 1632, 1636, 1623, 1639, 1656, 1666, 1667, 1671, |
| 161175 | + /* 390 */ 1672, 1673, 1564, 1565, 1566, 1662, 1674, 1675, 1677, 1678, |
| 161176 | + /* 400 */ 1682, 1670, 1679, 1680, 1681, 1683, 1686, |
| 159811 | 161177 | }; |
| 159812 | 161178 | static const YYACTIONTYPE yy_default[] = { |
| 159813 | 161179 | /* 0 */ 1633, 1633, 1633, 1462, 1230, 1341, 1230, 1230, 1230, 1462, |
| 159814 | 161180 | /* 10 */ 1462, 1462, 1230, 1371, 1371, 1515, 1263, 1230, 1230, 1230, |
| 159815 | 161181 | /* 20 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1461, 1230, 1230, |
| | @@ -159930,14 +161296,14 @@ |
| 159930 | 161296 | 59, /* DETACH => ID */ |
| 159931 | 161297 | 59, /* EACH => ID */ |
| 159932 | 161298 | 59, /* FAIL => ID */ |
| 159933 | 161299 | 0, /* OR => nothing */ |
| 159934 | 161300 | 0, /* AND => nothing */ |
| 159935 | | - 0, /* IS => nothing */ |
| 159936 | 161301 | 59, /* MATCH => ID */ |
| 159937 | 161302 | 59, /* LIKE_KW => ID */ |
| 159938 | 161303 | 0, /* BETWEEN => nothing */ |
| 161304 | + 0, /* IS => nothing */ |
| 159939 | 161305 | 0, /* IN => nothing */ |
| 159940 | 161306 | 0, /* ISNULL => nothing */ |
| 159941 | 161307 | 0, /* NOTNULL => nothing */ |
| 159942 | 161308 | 0, /* NE => nothing */ |
| 159943 | 161309 | 0, /* EQ => nothing */ |
| | @@ -160120,13 +161486,13 @@ |
| 160120 | 161486 | yyStackEntry *yystackEnd; /* Last entry in the stack */ |
| 160121 | 161487 | #endif |
| 160122 | 161488 | }; |
| 160123 | 161489 | typedef struct yyParser yyParser; |
| 160124 | 161490 | |
| 161491 | +/* #include <assert.h> */ |
| 160125 | 161492 | #ifndef NDEBUG |
| 160126 | 161493 | /* #include <stdio.h> */ |
| 160127 | | -/* #include <assert.h> */ |
| 160128 | 161494 | static FILE *yyTraceFILE = 0; |
| 160129 | 161495 | static char *yyTracePrompt = 0; |
| 160130 | 161496 | #endif /* NDEBUG */ |
| 160131 | 161497 | |
| 160132 | 161498 | #ifndef NDEBUG |
| | @@ -160202,14 +161568,14 @@ |
| 160202 | 161568 | /* 40 */ "DETACH", |
| 160203 | 161569 | /* 41 */ "EACH", |
| 160204 | 161570 | /* 42 */ "FAIL", |
| 160205 | 161571 | /* 43 */ "OR", |
| 160206 | 161572 | /* 44 */ "AND", |
| 160207 | | - /* 45 */ "IS", |
| 160208 | | - /* 46 */ "MATCH", |
| 160209 | | - /* 47 */ "LIKE_KW", |
| 160210 | | - /* 48 */ "BETWEEN", |
| 161573 | + /* 45 */ "MATCH", |
| 161574 | + /* 46 */ "LIKE_KW", |
| 161575 | + /* 47 */ "BETWEEN", |
| 161576 | + /* 48 */ "IS", |
| 160211 | 161577 | /* 49 */ "IN", |
| 160212 | 161578 | /* 50 */ "ISNULL", |
| 160213 | 161579 | /* 51 */ "NOTNULL", |
| 160214 | 161580 | /* 52 */ "NE", |
| 160215 | 161581 | /* 53 */ "EQ", |
| | @@ -163871,12 +165237,12 @@ |
| 163871 | 165237 | assert( yypParser->yytos>=yypParser->yystack ); |
| 163872 | 165238 | assert( yyact==yypParser->yytos->stateno ); |
| 163873 | 165239 | yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact); |
| 163874 | 165240 | if( yyact >= YY_MIN_REDUCE ){ |
| 163875 | 165241 | unsigned int yyruleno = yyact - YY_MIN_REDUCE; /* Reduce by this rule */ |
| 163876 | | - assert( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ); |
| 163877 | 165242 | #ifndef NDEBUG |
| 165243 | + assert( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ); |
| 163878 | 165244 | if( yyTraceFILE ){ |
| 163879 | 165245 | int yysize = yyRuleInfoNRhs[yyruleno]; |
| 163880 | 165246 | if( yysize ){ |
| 163881 | 165247 | fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", |
| 163882 | 165248 | yyTracePrompt, |
| | @@ -165119,10 +166485,11 @@ |
| 165119 | 166485 | int n = 0; /* Length of the next token token */ |
| 165120 | 166486 | int tokenType; /* type of the next token */ |
| 165121 | 166487 | int lastTokenParsed = -1; /* type of the previous token */ |
| 165122 | 166488 | sqlite3 *db = pParse->db; /* The database connection */ |
| 165123 | 166489 | int mxSqlLen; /* Max length of an SQL string */ |
| 166490 | + Parse *pParentParse = 0; /* Outer parse context, if any */ |
| 165124 | 166491 | #ifdef sqlite3Parser_ENGINEALWAYSONSTACK |
| 165125 | 166492 | yyParser sEngine; /* Space to hold the Lemon-generated Parser object */ |
| 165126 | 166493 | #endif |
| 165127 | 166494 | VVA_ONLY( u8 startedWithOom = db->mallocFailed ); |
| 165128 | 166495 | |
| | @@ -165154,11 +166521,11 @@ |
| 165154 | 166521 | #endif |
| 165155 | 166522 | assert( pParse->pNewTable==0 ); |
| 165156 | 166523 | assert( pParse->pNewTrigger==0 ); |
| 165157 | 166524 | assert( pParse->nVar==0 ); |
| 165158 | 166525 | assert( pParse->pVList==0 ); |
| 165159 | | - pParse->pParentParse = db->pParse; |
| 166526 | + pParentParse = db->pParse; |
| 165160 | 166527 | db->pParse = pParse; |
| 165161 | 166528 | while( 1 ){ |
| 165162 | 166529 | n = sqlite3GetToken((u8*)zSql, &tokenType); |
| 165163 | 166530 | mxSqlLen -= n; |
| 165164 | 166531 | if( mxSqlLen<0 ){ |
| | @@ -165269,12 +166636,11 @@ |
| 165269 | 166636 | } |
| 165270 | 166637 | if( !IN_RENAME_OBJECT ){ |
| 165271 | 166638 | sqlite3DeleteTrigger(db, pParse->pNewTrigger); |
| 165272 | 166639 | } |
| 165273 | 166640 | sqlite3DbFree(db, pParse->pVList); |
| 165274 | | - db->pParse = pParse->pParentParse; |
| 165275 | | - pParse->pParentParse = 0; |
| 166641 | + db->pParse = pParentParse; |
| 165276 | 166642 | assert( nErr==0 || pParse->rc!=SQLITE_OK ); |
| 165277 | 166643 | return nErr; |
| 165278 | 166644 | } |
| 165279 | 166645 | |
| 165280 | 166646 | |
| | @@ -166939,11 +168305,13 @@ |
| 166939 | 168305 | ** if this is not the last copy of the function, do not invoke it. Multiple |
| 166940 | 168306 | ** copies of a single function are created when create_function() is called |
| 166941 | 168307 | ** with SQLITE_ANY as the encoding. |
| 166942 | 168308 | */ |
| 166943 | 168309 | static void functionDestroy(sqlite3 *db, FuncDef *p){ |
| 166944 | | - FuncDestructor *pDestructor = p->u.pDestructor; |
| 168310 | + FuncDestructor *pDestructor; |
| 168311 | + assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 ); |
| 168312 | + pDestructor = p->u.pDestructor; |
| 166945 | 168313 | if( pDestructor ){ |
| 166946 | 168314 | pDestructor->nRef--; |
| 166947 | 168315 | if( pDestructor->nRef==0 ){ |
| 166948 | 168316 | pDestructor->xDestroy(pDestructor->pUserData); |
| 166949 | 168317 | sqlite3DbFree(db, pDestructor); |
| | @@ -167202,10 +168570,13 @@ |
| 167202 | 168570 | ** So it needs to be freed here. Todo: Why not roll the temp schema into |
| 167203 | 168571 | ** the same sqliteMalloc() as the one that allocates the database |
| 167204 | 168572 | ** structure? |
| 167205 | 168573 | */ |
| 167206 | 168574 | sqlite3DbFree(db, db->aDb[1].pSchema); |
| 168575 | + if( db->xAutovacDestr ){ |
| 168576 | + db->xAutovacDestr(db->pAutovacPagesArg); |
| 168577 | + } |
| 167207 | 168578 | sqlite3_mutex_leave(db->mutex); |
| 167208 | 168579 | db->eOpenState = SQLITE_STATE_CLOSED; |
| 167209 | 168580 | sqlite3_mutex_free(db->mutex); |
| 167210 | 168581 | assert( sqlite3LookasideUsed(db,0)==0 ); |
| 167211 | 168582 | if( db->lookaside.bMalloced ){ |
| | @@ -167256,11 +168627,11 @@ |
| 167256 | 168627 | sqlite3BtreeLeaveAll(db); |
| 167257 | 168628 | |
| 167258 | 168629 | /* Any deferred constraint violations have now been resolved. */ |
| 167259 | 168630 | db->nDeferredCons = 0; |
| 167260 | 168631 | db->nDeferredImmCons = 0; |
| 167261 | | - db->flags &= ~(u64)SQLITE_DeferFKs; |
| 168632 | + db->flags &= ~(u64)(SQLITE_DeferFKs|SQLITE_CorruptRdOnly); |
| 167262 | 168633 | |
| 167263 | 168634 | /* If one has been configured, invoke the rollback-hook callback */ |
| 167264 | 168635 | if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){ |
| 167265 | 168636 | db->xRollbackCallback(db->pRollbackArg); |
| 167266 | 168637 | } |
| | @@ -167620,21 +168991,20 @@ |
| 167620 | 168991 | void (*xValue)(sqlite3_context*), |
| 167621 | 168992 | void (*xInverse)(sqlite3_context*,int,sqlite3_value **), |
| 167622 | 168993 | FuncDestructor *pDestructor |
| 167623 | 168994 | ){ |
| 167624 | 168995 | FuncDef *p; |
| 167625 | | - int nName; |
| 167626 | 168996 | int extraFlags; |
| 167627 | 168997 | |
| 167628 | 168998 | assert( sqlite3_mutex_held(db->mutex) ); |
| 167629 | 168999 | assert( xValue==0 || xSFunc==0 ); |
| 167630 | 169000 | if( zFunctionName==0 /* Must have a valid name */ |
| 167631 | 169001 | || (xSFunc!=0 && xFinal!=0) /* Not both xSFunc and xFinal */ |
| 167632 | 169002 | || ((xFinal==0)!=(xStep==0)) /* Both or neither of xFinal and xStep */ |
| 167633 | 169003 | || ((xValue==0)!=(xInverse==0)) /* Both or neither of xValue, xInverse */ |
| 167634 | 169004 | || (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) |
| 167635 | | - || (255<(nName = sqlite3Strlen30( zFunctionName))) |
| 169005 | + || (255<sqlite3Strlen30(zFunctionName)) |
| 167636 | 169006 | ){ |
| 167637 | 169007 | return SQLITE_MISUSE_BKPT; |
| 167638 | 169008 | } |
| 167639 | 169009 | |
| 167640 | 169010 | assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC ); |
| | @@ -168103,10 +169473,38 @@ |
| 168103 | 169473 | db->pPreUpdateArg = pArg; |
| 168104 | 169474 | sqlite3_mutex_leave(db->mutex); |
| 168105 | 169475 | return pRet; |
| 168106 | 169476 | } |
| 168107 | 169477 | #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */ |
| 169478 | + |
| 169479 | +/* |
| 169480 | +** Register a function to be invoked prior to each autovacuum that |
| 169481 | +** determines the number of pages to vacuum. |
| 169482 | +*/ |
| 169483 | +SQLITE_API int sqlite3_autovacuum_pages( |
| 169484 | + sqlite3 *db, /* Attach the hook to this database */ |
| 169485 | + unsigned int (*xCallback)(void*,const char*,u32,u32,u32), |
| 169486 | + void *pArg, /* Argument to the function */ |
| 169487 | + void (*xDestructor)(void*) /* Destructor for pArg */ |
| 169488 | +){ |
| 169489 | +#ifdef SQLITE_ENABLE_API_ARMOR |
| 169490 | + if( !sqlite3SafetyCheckOk(db) ){ |
| 169491 | + if( xDestructor ) xDestructor(pArg); |
| 169492 | + return SQLITE_MISUSE_BKPT; |
| 169493 | + } |
| 169494 | +#endif |
| 169495 | + sqlite3_mutex_enter(db->mutex); |
| 169496 | + if( db->xAutovacDestr ){ |
| 169497 | + db->xAutovacDestr(db->pAutovacPagesArg); |
| 169498 | + } |
| 169499 | + db->xAutovacPages = xCallback; |
| 169500 | + db->pAutovacPagesArg = pArg; |
| 169501 | + db->xAutovacDestr = xDestructor; |
| 169502 | + sqlite3_mutex_leave(db->mutex); |
| 169503 | + return SQLITE_OK; |
| 169504 | +} |
| 169505 | + |
| 168108 | 169506 | |
| 168109 | 169507 | #ifndef SQLITE_OMIT_WAL |
| 168110 | 169508 | /* |
| 168111 | 169509 | ** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint(). |
| 168112 | 169510 | ** Invoke sqlite3_wal_checkpoint if the number of frames in the log file |
| | @@ -168626,10 +170024,12 @@ |
| 168626 | 170024 | } |
| 168627 | 170025 | oldLimit = db->aLimit[limitId]; |
| 168628 | 170026 | if( newLimit>=0 ){ /* IMP: R-52476-28732 */ |
| 168629 | 170027 | if( newLimit>aHardLimit[limitId] ){ |
| 168630 | 170028 | newLimit = aHardLimit[limitId]; /* IMP: R-51463-25634 */ |
| 170029 | + }else if( newLimit<1 && limitId==SQLITE_LIMIT_LENGTH ){ |
| 170030 | + newLimit = 1; |
| 168631 | 170031 | } |
| 168632 | 170032 | db->aLimit[limitId] = newLimit; |
| 168633 | 170033 | } |
| 168634 | 170034 | return oldLimit; /* IMP: R-53341-35419 */ |
| 168635 | 170035 | } |
| | @@ -168897,11 +170297,11 @@ |
| 168897 | 170297 | ** This routine does the core work of extracting URI parameters from a |
| 168898 | 170298 | ** database filename for the sqlite3_uri_parameter() interface. |
| 168899 | 170299 | */ |
| 168900 | 170300 | static const char *uriParameter(const char *zFilename, const char *zParam){ |
| 168901 | 170301 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 168902 | | - while( zFilename[0] ){ |
| 170302 | + while( ALWAYS(zFilename!=0) && zFilename[0] ){ |
| 168903 | 170303 | int x = strcmp(zFilename, zParam); |
| 168904 | 170304 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 168905 | 170305 | if( x==0 ) return zFilename; |
| 168906 | 170306 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 168907 | 170307 | } |
| | @@ -168957,14 +170357,15 @@ |
| 168957 | 170357 | ** |
| 168958 | 170358 | ** The SQLITE_OPEN_NOMUTEX and SQLITE_OPEN_FULLMUTEX flags were |
| 168959 | 170359 | ** dealt with in the previous code block. Besides these, the only |
| 168960 | 170360 | ** valid input flags for sqlite3_open_v2() are SQLITE_OPEN_READONLY, |
| 168961 | 170361 | ** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE, |
| 168962 | | - ** SQLITE_OPEN_PRIVATECACHE, and some reserved bits. Silently mask |
| 168963 | | - ** off all other flags. |
| 170362 | + ** SQLITE_OPEN_PRIVATECACHE, SQLITE_OPEN_EXRESCODE, and some reserved |
| 170363 | + ** bits. Silently mask off all other flags. |
| 168964 | 170364 | */ |
| 168965 | 170365 | flags &= ~( SQLITE_OPEN_DELETEONCLOSE | |
| 170366 | + SQLITE_OPEN_EXCLUSIVE | |
| 168966 | 170367 | SQLITE_OPEN_MAIN_DB | |
| 168967 | 170368 | SQLITE_OPEN_TEMP_DB | |
| 168968 | 170369 | SQLITE_OPEN_TRANSIENT_DB | |
| 168969 | 170370 | SQLITE_OPEN_MAIN_JOURNAL | |
| 168970 | 170371 | SQLITE_OPEN_TEMP_JOURNAL | |
| | @@ -168992,11 +170393,11 @@ |
| 168992 | 170393 | if( isThreadsafe==0 ){ |
| 168993 | 170394 | sqlite3MutexWarnOnContention(db->mutex); |
| 168994 | 170395 | } |
| 168995 | 170396 | } |
| 168996 | 170397 | sqlite3_mutex_enter(db->mutex); |
| 168997 | | - db->errMask = 0xff; |
| 170398 | + db->errMask = (flags & SQLITE_OPEN_EXRESCODE)!=0 ? 0xffffffff : 0xff; |
| 168998 | 170399 | db->nDb = 2; |
| 168999 | 170400 | db->eOpenState = SQLITE_STATE_BUSY; |
| 169000 | 170401 | db->aDb = db->aDbStatic; |
| 169001 | 170402 | db->lookaside.bDisable = 1; |
| 169002 | 170403 | db->lookaside.sz = 0; |
| | @@ -169224,12 +170625,12 @@ |
| 169224 | 170625 | assert( db->mutex!=0 || isThreadsafe==0 |
| 169225 | 170626 | || sqlite3GlobalConfig.bFullMutex==0 ); |
| 169226 | 170627 | sqlite3_mutex_leave(db->mutex); |
| 169227 | 170628 | } |
| 169228 | 170629 | rc = sqlite3_errcode(db); |
| 169229 | | - assert( db!=0 || rc==SQLITE_NOMEM ); |
| 169230 | | - if( rc==SQLITE_NOMEM ){ |
| 170630 | + assert( db!=0 || (rc&0xff)==SQLITE_NOMEM ); |
| 170631 | + if( (rc&0xff)==SQLITE_NOMEM ){ |
| 169231 | 170632 | sqlite3_close(db); |
| 169232 | 170633 | db = 0; |
| 169233 | 170634 | }else if( rc!=SQLITE_OK ){ |
| 169234 | 170635 | db->eOpenState = SQLITE_STATE_SICK; |
| 169235 | 170636 | } |
| | @@ -169240,11 +170641,11 @@ |
| 169240 | 170641 | void *pArg = sqlite3GlobalConfig.pSqllogArg; |
| 169241 | 170642 | sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0); |
| 169242 | 170643 | } |
| 169243 | 170644 | #endif |
| 169244 | 170645 | sqlite3_free_filename(zOpen); |
| 169245 | | - return rc & 0xff; |
| 170646 | + return rc; |
| 169246 | 170647 | } |
| 169247 | 170648 | |
| 169248 | 170649 | |
| 169249 | 170650 | /* |
| 169250 | 170651 | ** Open a new database handle. |
| | @@ -170028,16 +171429,20 @@ |
| 170028 | 171429 | ** the schema to be reparsed the next time it is needed. This has the |
| 170029 | 171430 | ** effect of erasing all imposter tables. |
| 170030 | 171431 | */ |
| 170031 | 171432 | case SQLITE_TESTCTRL_IMPOSTER: { |
| 170032 | 171433 | sqlite3 *db = va_arg(ap, sqlite3*); |
| 171434 | + int iDb; |
| 170033 | 171435 | sqlite3_mutex_enter(db->mutex); |
| 170034 | | - db->init.iDb = sqlite3FindDbName(db, va_arg(ap,const char*)); |
| 170035 | | - db->init.busy = db->init.imposterTable = va_arg(ap,int); |
| 170036 | | - db->init.newTnum = va_arg(ap,int); |
| 170037 | | - if( db->init.busy==0 && db->init.newTnum>0 ){ |
| 170038 | | - sqlite3ResetAllSchemasOfConnection(db); |
| 171436 | + iDb = sqlite3FindDbName(db, va_arg(ap,const char*)); |
| 171437 | + if( iDb>=0 ){ |
| 171438 | + db->init.iDb = iDb; |
| 171439 | + db->init.busy = db->init.imposterTable = va_arg(ap,int); |
| 171440 | + db->init.newTnum = va_arg(ap,int); |
| 171441 | + if( db->init.busy==0 && db->init.newTnum>0 ){ |
| 171442 | + sqlite3ResetAllSchemasOfConnection(db); |
| 171443 | + } |
| 170039 | 171444 | } |
| 170040 | 171445 | sqlite3_mutex_leave(db->mutex); |
| 170041 | 171446 | break; |
| 170042 | 171447 | } |
| 170043 | 171448 | |
| | @@ -170108,10 +171513,30 @@ |
| 170108 | 171513 | case 2: *ptr = sqlite3WhereTrace; break; |
| 170109 | 171514 | case 3: sqlite3WhereTrace = *ptr; break; |
| 170110 | 171515 | } |
| 170111 | 171516 | break; |
| 170112 | 171517 | } |
| 171518 | + |
| 171519 | + /* sqlite3_test_control(SQLITE_TESTCTRL_LOGEST, |
| 171520 | + ** double fIn, // Input value |
| 171521 | + ** int *pLogEst, // sqlite3LogEstFromDouble(fIn) |
| 171522 | + ** u64 *pInt, // sqlite3LogEstToInt(*pLogEst) |
| 171523 | + ** int *pLogEst2 // sqlite3LogEst(*pInt) |
| 171524 | + ** ); |
| 171525 | + ** |
| 171526 | + ** Test access for the LogEst conversion routines. |
| 171527 | + */ |
| 171528 | + case SQLITE_TESTCTRL_LOGEST: { |
| 171529 | + double rIn = va_arg(ap, double); |
| 171530 | + LogEst rLogEst = sqlite3LogEstFromDouble(rIn); |
| 171531 | + u64 iInt = sqlite3LogEstToInt(rLogEst); |
| 171532 | + va_arg(ap, int*)[0] = rLogEst; |
| 171533 | + va_arg(ap, u64*)[0] = iInt; |
| 171534 | + va_arg(ap, int*)[0] = sqlite3LogEst(iInt); |
| 171535 | + break; |
| 171536 | + } |
| 171537 | + |
| 170113 | 171538 | |
| 170114 | 171539 | #if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_WSD) |
| 170115 | 171540 | /* sqlite3_test_control(SQLITE_TESTCTRL_TUNE, id, *piValue) |
| 170116 | 171541 | ** |
| 170117 | 171542 | ** If "id" is an integer between 1 and SQLITE_NTUNE then set the value |
| | @@ -170245,11 +171670,11 @@ |
| 170245 | 171670 | */ |
| 170246 | 171671 | SQLITE_API const char *sqlite3_uri_key(const char *zFilename, int N){ |
| 170247 | 171672 | if( zFilename==0 || N<0 ) return 0; |
| 170248 | 171673 | zFilename = databaseName(zFilename); |
| 170249 | 171674 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 170250 | | - while( zFilename[0] && (N--)>0 ){ |
| 171675 | + while( ALWAYS(zFilename) && zFilename[0] && (N--)>0 ){ |
| 170251 | 171676 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 170252 | 171677 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 170253 | 171678 | } |
| 170254 | 171679 | return zFilename[0] ? zFilename : 0; |
| 170255 | 171680 | } |
| | @@ -170295,11 +171720,11 @@ |
| 170295 | 171720 | } |
| 170296 | 171721 | SQLITE_API const char *sqlite3_filename_journal(const char *zFilename){ |
| 170297 | 171722 | if( zFilename==0 ) return 0; |
| 170298 | 171723 | zFilename = databaseName(zFilename); |
| 170299 | 171724 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 170300 | | - while( zFilename[0] ){ |
| 171725 | + while( ALWAYS(zFilename) && zFilename[0] ){ |
| 170301 | 171726 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 170302 | 171727 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 170303 | 171728 | } |
| 170304 | 171729 | return zFilename + 1; |
| 170305 | 171730 | } |
| | @@ -171599,21 +173024,22 @@ |
| 171599 | 173024 | #ifndef SQLITE_AMALGAMATION |
| 171600 | 173025 | /* |
| 171601 | 173026 | ** Macros indicating that conditional expressions are always true or |
| 171602 | 173027 | ** false. |
| 171603 | 173028 | */ |
| 171604 | | -#ifdef SQLITE_COVERAGE_TEST |
| 171605 | | -# define ALWAYS(x) (1) |
| 171606 | | -# define NEVER(X) (0) |
| 171607 | | -#elif defined(SQLITE_DEBUG) |
| 171608 | | -# define ALWAYS(x) sqlite3Fts3Always((x)!=0) |
| 171609 | | -# define NEVER(x) sqlite3Fts3Never((x)!=0) |
| 171610 | | -SQLITE_PRIVATE int sqlite3Fts3Always(int b); |
| 171611 | | -SQLITE_PRIVATE int sqlite3Fts3Never(int b); |
| 173029 | +#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST) |
| 173030 | +# define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1 |
| 173031 | +#endif |
| 173032 | +#if defined(SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS) |
| 173033 | +# define ALWAYS(X) (1) |
| 173034 | +# define NEVER(X) (0) |
| 173035 | +#elif !defined(NDEBUG) |
| 173036 | +# define ALWAYS(X) ((X)?1:(assert(0),0)) |
| 173037 | +# define NEVER(X) ((X)?(assert(0),1):0) |
| 171612 | 173038 | #else |
| 171613 | | -# define ALWAYS(x) (x) |
| 171614 | | -# define NEVER(x) (x) |
| 173039 | +# define ALWAYS(X) (X) |
| 173040 | +# define NEVER(X) (X) |
| 171615 | 173041 | #endif |
| 171616 | 173042 | |
| 171617 | 173043 | /* |
| 171618 | 173044 | ** Internal types used by SQLite. |
| 171619 | 173045 | */ |
| | @@ -172068,10 +173494,11 @@ |
| 172068 | 173494 | SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *); |
| 172069 | 173495 | #ifdef SQLITE_TEST |
| 172070 | 173496 | SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db, Fts3Hash*); |
| 172071 | 173497 | SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db); |
| 172072 | 173498 | #endif |
| 173499 | +SQLITE_PRIVATE void *sqlite3Fts3MallocZero(i64 nByte); |
| 172073 | 173500 | |
| 172074 | 173501 | SQLITE_PRIVATE int sqlite3Fts3OpenTokenizer(sqlite3_tokenizer *, int, const char *, int, |
| 172075 | 173502 | sqlite3_tokenizer_cursor ** |
| 172076 | 173503 | ); |
| 172077 | 173504 | |
| | @@ -172125,17 +173552,10 @@ |
| 172125 | 173552 | static int fts3EvalNext(Fts3Cursor *pCsr); |
| 172126 | 173553 | static int fts3EvalStart(Fts3Cursor *pCsr); |
| 172127 | 173554 | static int fts3TermSegReaderCursor( |
| 172128 | 173555 | Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **); |
| 172129 | 173556 | |
| 172130 | | -#ifndef SQLITE_AMALGAMATION |
| 172131 | | -# if defined(SQLITE_DEBUG) |
| 172132 | | -SQLITE_PRIVATE int sqlite3Fts3Always(int b) { assert( b ); return b; } |
| 172133 | | -SQLITE_PRIVATE int sqlite3Fts3Never(int b) { assert( !b ); return b; } |
| 172134 | | -# endif |
| 172135 | | -#endif |
| 172136 | | - |
| 172137 | 173557 | /* |
| 172138 | 173558 | ** This variable is set to false when running tests for which the on disk |
| 172139 | 173559 | ** structures should not be corrupt. Otherwise, true. If it is false, extra |
| 172140 | 173560 | ** assert() conditions in the fts3 code are activated - conditions that are |
| 172141 | 173561 | ** only true if it is guaranteed that the fts3 database is not corrupt. |
| | @@ -177156,12 +178576,12 @@ |
| 177156 | 178576 | case FTSQUERY_OR: { |
| 177157 | 178577 | Fts3Expr *pLeft = pExpr->pLeft; |
| 177158 | 178578 | Fts3Expr *pRight = pExpr->pRight; |
| 177159 | 178579 | sqlite3_int64 iCmp = DOCID_CMP(pLeft->iDocid, pRight->iDocid); |
| 177160 | 178580 | |
| 177161 | | - assert( pLeft->bStart || pLeft->iDocid==pRight->iDocid ); |
| 177162 | | - assert( pRight->bStart || pLeft->iDocid==pRight->iDocid ); |
| 178581 | + assert_fts3_nc( pLeft->bStart || pLeft->iDocid==pRight->iDocid ); |
| 178582 | + assert_fts3_nc( pRight->bStart || pLeft->iDocid==pRight->iDocid ); |
| 177163 | 178583 | |
| 177164 | 178584 | if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){ |
| 177165 | 178585 | fts3EvalNextRow(pCsr, pLeft, pRc); |
| 177166 | 178586 | }else if( pLeft->bEof || iCmp>0 ){ |
| 177167 | 178587 | fts3EvalNextRow(pCsr, pRight, pRc); |
| | @@ -177795,10 +179215,13 @@ |
| 177795 | 179215 | while( rc==SQLITE_OK && !pNear->bEof ){ |
| 177796 | 179216 | fts3EvalNextRow(pCsr, pNear, &rc); |
| 177797 | 179217 | if( bEofSave==0 && pNear->iDocid==iDocid ) break; |
| 177798 | 179218 | } |
| 177799 | 179219 | assert( rc!=SQLITE_OK || pPhrase->bIncr==0 ); |
| 179220 | + if( rc==SQLITE_OK && pNear->bEof!=bEofSave ){ |
| 179221 | + rc = FTS_CORRUPT_VTAB; |
| 179222 | + } |
| 177800 | 179223 | } |
| 177801 | 179224 | if( bTreeEof ){ |
| 177802 | 179225 | while( rc==SQLITE_OK && !pNear->bEof ){ |
| 177803 | 179226 | fts3EvalNextRow(pCsr, pNear, &rc); |
| 177804 | 179227 | } |
| | @@ -178217,10 +179640,11 @@ |
| 178217 | 179640 | } |
| 178218 | 179641 | |
| 178219 | 179642 | if( fts3auxGrowStatArray(pCsr, 2) ) return SQLITE_NOMEM; |
| 178220 | 179643 | memset(pCsr->aStat, 0, sizeof(struct Fts3auxColstats) * pCsr->nStat); |
| 178221 | 179644 | iCol = 0; |
| 179645 | + rc = SQLITE_OK; |
| 178222 | 179646 | |
| 178223 | 179647 | while( i<nDoclist ){ |
| 178224 | 179648 | sqlite3_int64 v = 0; |
| 178225 | 179649 | |
| 178226 | 179650 | i += sqlite3Fts3GetVarint(&aDoclist[i], &v); |
| | @@ -178260,19 +179684,22 @@ |
| 178260 | 179684 | break; |
| 178261 | 179685 | |
| 178262 | 179686 | /* State 3. The integer just read is a column number. */ |
| 178263 | 179687 | default: assert( eState==3 ); |
| 178264 | 179688 | iCol = (int)v; |
| 179689 | + if( iCol<1 ){ |
| 179690 | + rc = SQLITE_CORRUPT_VTAB; |
| 179691 | + break; |
| 179692 | + } |
| 178265 | 179693 | if( fts3auxGrowStatArray(pCsr, iCol+2) ) return SQLITE_NOMEM; |
| 178266 | 179694 | pCsr->aStat[iCol+1].nDoc++; |
| 178267 | 179695 | eState = 2; |
| 178268 | 179696 | break; |
| 178269 | 179697 | } |
| 178270 | 179698 | } |
| 178271 | 179699 | |
| 178272 | 179700 | pCsr->iCol = 0; |
| 178273 | | - rc = SQLITE_OK; |
| 178274 | 179701 | }else{ |
| 178275 | 179702 | pCsr->isEof = 1; |
| 178276 | 179703 | } |
| 178277 | 179704 | return rc; |
| 178278 | 179705 | } |
| | @@ -178597,11 +180024,11 @@ |
| 178597 | 180024 | /* |
| 178598 | 180025 | ** Allocate nByte bytes of memory using sqlite3_malloc(). If successful, |
| 178599 | 180026 | ** zero the memory before returning a pointer to it. If unsuccessful, |
| 178600 | 180027 | ** return NULL. |
| 178601 | 180028 | */ |
| 178602 | | -static void *fts3MallocZero(sqlite3_int64 nByte){ |
| 180029 | +SQLITE_PRIVATE void *sqlite3Fts3MallocZero(sqlite3_int64 nByte){ |
| 178603 | 180030 | void *pRet = sqlite3_malloc64(nByte); |
| 178604 | 180031 | if( pRet ) memset(pRet, 0, nByte); |
| 178605 | 180032 | return pRet; |
| 178606 | 180033 | } |
| 178607 | 180034 | |
| | @@ -178678,11 +180105,11 @@ |
| 178678 | 180105 | sqlite3_int64 nByte; /* total space to allocate */ |
| 178679 | 180106 | |
| 178680 | 180107 | rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition); |
| 178681 | 180108 | if( rc==SQLITE_OK ){ |
| 178682 | 180109 | nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken; |
| 178683 | | - pRet = (Fts3Expr *)fts3MallocZero(nByte); |
| 180110 | + pRet = (Fts3Expr *)sqlite3Fts3MallocZero(nByte); |
| 178684 | 180111 | if( !pRet ){ |
| 178685 | 180112 | rc = SQLITE_NOMEM; |
| 178686 | 180113 | }else{ |
| 178687 | 180114 | pRet->eType = FTSQUERY_PHRASE; |
| 178688 | 180115 | pRet->pPhrase = (Fts3Phrase *)&pRet[1]; |
| | @@ -178933,11 +180360,11 @@ |
| 178933 | 180360 | */ |
| 178934 | 180361 | cNext = zInput[nKey]; |
| 178935 | 180362 | if( fts3isspace(cNext) |
| 178936 | 180363 | || cNext=='"' || cNext=='(' || cNext==')' || cNext==0 |
| 178937 | 180364 | ){ |
| 178938 | | - pRet = (Fts3Expr *)fts3MallocZero(sizeof(Fts3Expr)); |
| 180365 | + pRet = (Fts3Expr *)sqlite3Fts3MallocZero(sizeof(Fts3Expr)); |
| 178939 | 180366 | if( !pRet ){ |
| 178940 | 180367 | return SQLITE_NOMEM; |
| 178941 | 180368 | } |
| 178942 | 180369 | pRet->eType = pKey->eType; |
| 178943 | 180370 | pRet->nNear = nNear; |
| | @@ -179112,11 +180539,11 @@ |
| 179112 | 180539 | |
| 179113 | 180540 | if( !sqlite3_fts3_enable_parentheses |
| 179114 | 180541 | && p->eType==FTSQUERY_PHRASE && pParse->isNot |
| 179115 | 180542 | ){ |
| 179116 | 180543 | /* Create an implicit NOT operator. */ |
| 179117 | | - Fts3Expr *pNot = fts3MallocZero(sizeof(Fts3Expr)); |
| 180544 | + Fts3Expr *pNot = sqlite3Fts3MallocZero(sizeof(Fts3Expr)); |
| 179118 | 180545 | if( !pNot ){ |
| 179119 | 180546 | sqlite3Fts3ExprFree(p); |
| 179120 | 180547 | rc = SQLITE_NOMEM; |
| 179121 | 180548 | goto exprparse_out; |
| 179122 | 180549 | } |
| | @@ -179146,11 +180573,11 @@ |
| 179146 | 180573 | |
| 179147 | 180574 | if( isPhrase && !isRequirePhrase ){ |
| 179148 | 180575 | /* Insert an implicit AND operator. */ |
| 179149 | 180576 | Fts3Expr *pAnd; |
| 179150 | 180577 | assert( pRet && pPrev ); |
| 179151 | | - pAnd = fts3MallocZero(sizeof(Fts3Expr)); |
| 180578 | + pAnd = sqlite3Fts3MallocZero(sizeof(Fts3Expr)); |
| 179152 | 180579 | if( !pAnd ){ |
| 179153 | 180580 | sqlite3Fts3ExprFree(p); |
| 179154 | 180581 | rc = SQLITE_NOMEM; |
| 179155 | 180582 | goto exprparse_out; |
| 179156 | 180583 | } |
| | @@ -183376,12 +184803,22 @@ |
| 183376 | 184803 | pReader->aNode = 0; |
| 183377 | 184804 | if( pElem ){ |
| 183378 | 184805 | char *aCopy; |
| 183379 | 184806 | PendingList *pList = (PendingList *)fts3HashData(pElem); |
| 183380 | 184807 | int nCopy = pList->nData+1; |
| 183381 | | - pReader->zTerm = (char *)fts3HashKey(pElem); |
| 183382 | | - pReader->nTerm = fts3HashKeysize(pElem); |
| 184808 | + |
| 184809 | + int nTerm = fts3HashKeysize(pElem); |
| 184810 | + if( (nTerm+1)>pReader->nTermAlloc ){ |
| 184811 | + sqlite3_free(pReader->zTerm); |
| 184812 | + pReader->zTerm = (char*)sqlite3_malloc((nTerm+1)*2); |
| 184813 | + if( !pReader->zTerm ) return SQLITE_NOMEM; |
| 184814 | + pReader->nTermAlloc = (nTerm+1)*2; |
| 184815 | + } |
| 184816 | + memcpy(pReader->zTerm, fts3HashKey(pElem), nTerm); |
| 184817 | + pReader->zTerm[nTerm] = '\0'; |
| 184818 | + pReader->nTerm = nTerm; |
| 184819 | + |
| 183383 | 184820 | aCopy = (char*)sqlite3_malloc(nCopy); |
| 183384 | 184821 | if( !aCopy ) return SQLITE_NOMEM; |
| 183385 | 184822 | memcpy(aCopy, pList->aData, nCopy); |
| 183386 | 184823 | pReader->nNode = pReader->nDoclist = nCopy; |
| 183387 | 184824 | pReader->aNode = pReader->aDoclist = aCopy; |
| | @@ -183630,13 +185067,11 @@ |
| 183630 | 185067 | ** Free all allocations associated with the iterator passed as the |
| 183631 | 185068 | ** second argument. |
| 183632 | 185069 | */ |
| 183633 | 185070 | SQLITE_PRIVATE void sqlite3Fts3SegReaderFree(Fts3SegReader *pReader){ |
| 183634 | 185071 | if( pReader ){ |
| 183635 | | - if( !fts3SegReaderIsPending(pReader) ){ |
| 183636 | | - sqlite3_free(pReader->zTerm); |
| 183637 | | - } |
| 185072 | + sqlite3_free(pReader->zTerm); |
| 183638 | 185073 | if( !fts3SegReaderIsRootOnly(pReader) ){ |
| 183639 | 185074 | sqlite3_free(pReader->aNode); |
| 183640 | 185075 | } |
| 183641 | 185076 | sqlite3_blob_close(pReader->pBlob); |
| 183642 | 185077 | } |
| | @@ -185824,11 +187259,11 @@ |
| 185824 | 187259 | |
| 185825 | 187260 | if( nPrefix>p->term.n || nSuffix>p->nNode-p->iOff || nSuffix==0 ){ |
| 185826 | 187261 | return FTS_CORRUPT_VTAB; |
| 185827 | 187262 | } |
| 185828 | 187263 | blobGrowBuffer(&p->term, nPrefix+nSuffix, &rc); |
| 185829 | | - if( rc==SQLITE_OK ){ |
| 187264 | + if( rc==SQLITE_OK && ALWAYS(p->term.a!=0) ){ |
| 185830 | 187265 | memcpy(&p->term.a[nPrefix], &p->aNode[p->iOff], nSuffix); |
| 185831 | 187266 | p->term.n = nPrefix+nSuffix; |
| 185832 | 187267 | p->iOff += nSuffix; |
| 185833 | 187268 | if( p->iChild==0 ){ |
| 185834 | 187269 | p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &p->nDoclist); |
| | @@ -186218,11 +187653,15 @@ |
| 186218 | 187653 | const char *zRhs, int nRhs /* RHS of comparison */ |
| 186219 | 187654 | ){ |
| 186220 | 187655 | int nCmp = MIN(nLhs, nRhs); |
| 186221 | 187656 | int res; |
| 186222 | 187657 | |
| 186223 | | - res = (nCmp ? memcmp(zLhs, zRhs, nCmp) : 0); |
| 187658 | + if( nCmp && ALWAYS(zLhs) && ALWAYS(zRhs) ){ |
| 187659 | + res = memcmp(zLhs, zRhs, nCmp); |
| 187660 | + }else{ |
| 187661 | + res = 0; |
| 187662 | + } |
| 186224 | 187663 | if( res==0 ) res = nLhs - nRhs; |
| 186225 | 187664 | |
| 186226 | 187665 | return res; |
| 186227 | 187666 | } |
| 186228 | 187667 | |
| | @@ -186862,11 +188301,11 @@ |
| 186862 | 188301 | const char *aHint = sqlite3_column_blob(pSelect, 0); |
| 186863 | 188302 | int nHint = sqlite3_column_bytes(pSelect, 0); |
| 186864 | 188303 | if( aHint ){ |
| 186865 | 188304 | blobGrowBuffer(pHint, nHint, &rc); |
| 186866 | 188305 | if( rc==SQLITE_OK ){ |
| 186867 | | - memcpy(pHint->a, aHint, nHint); |
| 188306 | + if( ALWAYS(pHint->a!=0) ) memcpy(pHint->a, aHint, nHint); |
| 186868 | 188307 | pHint->n = nHint; |
| 186869 | 188308 | } |
| 186870 | 188309 | } |
| 186871 | 188310 | } |
| 186872 | 188311 | rc2 = sqlite3_reset(pSelect); |
| | @@ -187979,13 +189418,12 @@ |
| 187979 | 189418 | MatchinfoBuffer *pRet; |
| 187980 | 189419 | sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1) |
| 187981 | 189420 | + sizeof(MatchinfoBuffer); |
| 187982 | 189421 | sqlite3_int64 nStr = strlen(zMatchinfo); |
| 187983 | 189422 | |
| 187984 | | - pRet = sqlite3_malloc64(nByte + nStr+1); |
| 189423 | + pRet = sqlite3Fts3MallocZero(nByte + nStr+1); |
| 187985 | 189424 | if( pRet ){ |
| 187986 | | - memset(pRet, 0, nByte); |
| 187987 | 189425 | pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet; |
| 187988 | 189426 | pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0] |
| 187989 | 189427 | + sizeof(u32)*((int)nElem+1); |
| 187990 | 189428 | pRet->nElem = (int)nElem; |
| 187991 | 189429 | pRet->zMatchinfo = ((char*)pRet) + nByte; |
| | @@ -188385,15 +189823,14 @@ |
| 188385 | 189823 | |
| 188386 | 189824 | /* Now that it is known how many phrases there are, allocate and zero |
| 188387 | 189825 | ** the required space using malloc(). |
| 188388 | 189826 | */ |
| 188389 | 189827 | nByte = sizeof(SnippetPhrase) * nList; |
| 188390 | | - sIter.aPhrase = (SnippetPhrase *)sqlite3_malloc64(nByte); |
| 189828 | + sIter.aPhrase = (SnippetPhrase *)sqlite3Fts3MallocZero(nByte); |
| 188391 | 189829 | if( !sIter.aPhrase ){ |
| 188392 | 189830 | return SQLITE_NOMEM; |
| 188393 | 189831 | } |
| 188394 | | - memset(sIter.aPhrase, 0, nByte); |
| 188395 | 189832 | |
| 188396 | 189833 | /* Initialize the contents of the SnippetIter object. Then iterate through |
| 188397 | 189834 | ** the set of phrases in the expression to populate the aPhrase[] array. |
| 188398 | 189835 | */ |
| 188399 | 189836 | sIter.pCsr = pCsr; |
| | @@ -188953,14 +190390,16 @@ |
| 188953 | 190390 | ** Advance the iterator passed as an argument to the next position. Return |
| 188954 | 190391 | ** 1 if the iterator is at EOF or if it now points to the start of the |
| 188955 | 190392 | ** position list for the next column. |
| 188956 | 190393 | */ |
| 188957 | 190394 | static int fts3LcsIteratorAdvance(LcsIterator *pIter){ |
| 188958 | | - char *pRead = pIter->pRead; |
| 190395 | + char *pRead; |
| 188959 | 190396 | sqlite3_int64 iRead; |
| 188960 | 190397 | int rc = 0; |
| 188961 | 190398 | |
| 190399 | + if( NEVER(pIter==0) ) return 1; |
| 190400 | + pRead = pIter->pRead; |
| 188962 | 190401 | pRead += sqlite3Fts3GetVarint(pRead, &iRead); |
| 188963 | 190402 | if( iRead==0 || iRead==1 ){ |
| 188964 | 190403 | pRead = 0; |
| 188965 | 190404 | rc = 1; |
| 188966 | 190405 | }else{ |
| | @@ -188990,13 +190429,12 @@ |
| 188990 | 190429 | int rc = SQLITE_OK; |
| 188991 | 190430 | |
| 188992 | 190431 | /* Allocate and populate the array of LcsIterator objects. The array |
| 188993 | 190432 | ** contains one element for each matchable phrase in the query. |
| 188994 | 190433 | **/ |
| 188995 | | - aIter = sqlite3_malloc64(sizeof(LcsIterator) * pCsr->nPhrase); |
| 190434 | + aIter = sqlite3Fts3MallocZero(sizeof(LcsIterator) * pCsr->nPhrase); |
| 188996 | 190435 | if( !aIter ) return SQLITE_NOMEM; |
| 188997 | | - memset(aIter, 0, sizeof(LcsIterator) * pCsr->nPhrase); |
| 188998 | 190436 | (void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter); |
| 188999 | 190437 | |
| 189000 | 190438 | for(i=0; i<pInfo->nPhrase; i++){ |
| 189001 | 190439 | LcsIterator *pIter = &aIter[i]; |
| 189002 | 190440 | nToken -= pIter->pExpr->pPhrase->nToken; |
| | @@ -189453,11 +190891,11 @@ |
| 189453 | 190891 | /* Count the number of terms in the query */ |
| 189454 | 190892 | rc = fts3ExprLoadDoclists(pCsr, 0, &nToken); |
| 189455 | 190893 | if( rc!=SQLITE_OK ) goto offsets_out; |
| 189456 | 190894 | |
| 189457 | 190895 | /* Allocate the array of TermOffset iterators. */ |
| 189458 | | - sCtx.aTerm = (TermOffset *)sqlite3_malloc64(sizeof(TermOffset)*nToken); |
| 190896 | + sCtx.aTerm = (TermOffset *)sqlite3Fts3MallocZero(sizeof(TermOffset)*nToken); |
| 189459 | 190897 | if( 0==sCtx.aTerm ){ |
| 189460 | 190898 | rc = SQLITE_NOMEM; |
| 189461 | 190899 | goto offsets_out; |
| 189462 | 190900 | } |
| 189463 | 190901 | sCtx.iDocid = pCsr->iPrevId; |
| | @@ -189474,17 +190912,17 @@ |
| 189474 | 190912 | int iEnd = 0; |
| 189475 | 190913 | int iCurrent = 0; |
| 189476 | 190914 | const char *zDoc; |
| 189477 | 190915 | int nDoc; |
| 189478 | 190916 | |
| 189479 | | - /* Initialize the contents of sCtx.aTerm[] for column iCol. There is |
| 189480 | | - ** no way that this operation can fail, so the return code from |
| 189481 | | - ** fts3ExprIterate() can be discarded. |
| 190917 | + /* Initialize the contents of sCtx.aTerm[] for column iCol. This |
| 190918 | + ** operation may fail if the database contains corrupt records. |
| 189482 | 190919 | */ |
| 189483 | 190920 | sCtx.iCol = iCol; |
| 189484 | 190921 | sCtx.iTerm = 0; |
| 189485 | | - (void)fts3ExprIterate(pCsr->pExpr, fts3ExprTermOffsetInit, (void*)&sCtx); |
| 190922 | + rc = fts3ExprIterate(pCsr->pExpr, fts3ExprTermOffsetInit, (void*)&sCtx); |
| 190923 | + if( rc!=SQLITE_OK ) goto offsets_out; |
| 189486 | 190924 | |
| 189487 | 190925 | /* Retreive the text stored in column iCol. If an SQL NULL is stored |
| 189488 | 190926 | ** in column iCol, jump immediately to the next iteration of the loop. |
| 189489 | 190927 | ** If an OOM occurs while retrieving the data (this can happen if SQLite |
| 189490 | 190928 | ** needs to transform the data from utf-16 to utf-8), return SQLITE_NOMEM |
| | @@ -190478,11 +191916,38 @@ |
| 190478 | 191916 | ** but the definitions need to be repeated for separate compilation. */ |
| 190479 | 191917 | typedef sqlite3_uint64 u64; |
| 190480 | 191918 | typedef unsigned int u32; |
| 190481 | 191919 | typedef unsigned short int u16; |
| 190482 | 191920 | typedef unsigned char u8; |
| 191921 | +# if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST) |
| 191922 | +# define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1 |
| 191923 | +# endif |
| 191924 | +# if defined(SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS) |
| 191925 | +# define ALWAYS(X) (1) |
| 191926 | +# define NEVER(X) (0) |
| 191927 | +# elif !defined(NDEBUG) |
| 191928 | +# define ALWAYS(X) ((X)?1:(assert(0),0)) |
| 191929 | +# define NEVER(X) ((X)?(assert(0),1):0) |
| 191930 | +# else |
| 191931 | +# define ALWAYS(X) (X) |
| 191932 | +# define NEVER(X) (X) |
| 191933 | +# endif |
| 191934 | +# define testcase(X) |
| 190483 | 191935 | #endif |
| 191936 | +#if !defined(SQLITE_DEBUG) && !defined(SQLITE_COVERAGE_TEST) |
| 191937 | +# define VVA(X) |
| 191938 | +#else |
| 191939 | +# define VVA(X) X |
| 191940 | +#endif |
| 191941 | + |
| 191942 | +/* |
| 191943 | +** Some of the testcase() macros in this file are problematic for gcov |
| 191944 | +** in that they generate false-miss errors randomly. This is a gcov problem, |
| 191945 | +** not a problem in this case. But to work around it, we disable the |
| 191946 | +** problematic test cases for production builds. |
| 191947 | +*/ |
| 191948 | +#define json_testcase(X) |
| 190484 | 191949 | |
| 190485 | 191950 | /* Objects */ |
| 190486 | 191951 | typedef struct JsonString JsonString; |
| 190487 | 191952 | typedef struct JsonNode JsonNode; |
| 190488 | 191953 | typedef struct JsonParse JsonParse; |
| | @@ -190536,17 +192001,18 @@ |
| 190536 | 192001 | /* A single node of parsed JSON |
| 190537 | 192002 | */ |
| 190538 | 192003 | struct JsonNode { |
| 190539 | 192004 | u8 eType; /* One of the JSON_ type values */ |
| 190540 | 192005 | u8 jnFlags; /* JNODE flags */ |
| 192006 | + u8 eU; /* Which union element to use */ |
| 190541 | 192007 | u32 n; /* Bytes of content, or number of sub-nodes */ |
| 190542 | 192008 | union { |
| 190543 | | - const char *zJContent; /* Content for INT, REAL, and STRING */ |
| 190544 | | - u32 iAppend; /* More terms for ARRAY and OBJECT */ |
| 190545 | | - u32 iKey; /* Key for ARRAY objects in json_tree() */ |
| 190546 | | - u32 iReplace; /* Replacement content for JNODE_REPLACE */ |
| 190547 | | - JsonNode *pPatch; /* Node chain of patch for JNODE_PATCH */ |
| 192009 | + const char *zJContent; /* 1: Content for INT, REAL, and STRING */ |
| 192010 | + u32 iAppend; /* 2: More terms for ARRAY and OBJECT */ |
| 192011 | + u32 iKey; /* 3: Key for ARRAY objects in json_tree() */ |
| 192012 | + u32 iReplace; /* 4: Replacement content for JNODE_REPLACE */ |
| 192013 | + JsonNode *pPatch; /* 5: Node chain of patch for JNODE_PATCH */ |
| 190548 | 192014 | } u; |
| 190549 | 192015 | }; |
| 190550 | 192016 | |
| 190551 | 192017 | /* A completely parsed JSON string |
| 190552 | 192018 | */ |
| | @@ -190820,15 +192286,18 @@ |
| 190820 | 192286 | static void jsonRenderNode( |
| 190821 | 192287 | JsonNode *pNode, /* The node to render */ |
| 190822 | 192288 | JsonString *pOut, /* Write JSON here */ |
| 190823 | 192289 | sqlite3_value **aReplace /* Replacement values */ |
| 190824 | 192290 | ){ |
| 192291 | + assert( pNode!=0 ); |
| 190825 | 192292 | if( pNode->jnFlags & (JNODE_REPLACE|JNODE_PATCH) ){ |
| 190826 | | - if( pNode->jnFlags & JNODE_REPLACE ){ |
| 192293 | + if( (pNode->jnFlags & JNODE_REPLACE)!=0 && ALWAYS(aReplace!=0) ){ |
| 192294 | + assert( pNode->eU==4 ); |
| 190827 | 192295 | jsonAppendValue(pOut, aReplace[pNode->u.iReplace]); |
| 190828 | 192296 | return; |
| 190829 | 192297 | } |
| 192298 | + assert( pNode->eU==5 ); |
| 190830 | 192299 | pNode = pNode->u.pPatch; |
| 190831 | 192300 | } |
| 190832 | 192301 | switch( pNode->eType ){ |
| 190833 | 192302 | default: { |
| 190834 | 192303 | assert( pNode->eType==JSON_NULL ); |
| | @@ -190843,17 +192312,19 @@ |
| 190843 | 192312 | jsonAppendRaw(pOut, "false", 5); |
| 190844 | 192313 | break; |
| 190845 | 192314 | } |
| 190846 | 192315 | case JSON_STRING: { |
| 190847 | 192316 | if( pNode->jnFlags & JNODE_RAW ){ |
| 192317 | + assert( pNode->eU==1 ); |
| 190848 | 192318 | jsonAppendString(pOut, pNode->u.zJContent, pNode->n); |
| 190849 | 192319 | break; |
| 190850 | 192320 | } |
| 190851 | 192321 | /* no break */ deliberate_fall_through |
| 190852 | 192322 | } |
| 190853 | 192323 | case JSON_REAL: |
| 190854 | 192324 | case JSON_INT: { |
| 192325 | + assert( pNode->eU==1 ); |
| 190855 | 192326 | jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n); |
| 190856 | 192327 | break; |
| 190857 | 192328 | } |
| 190858 | 192329 | case JSON_ARRAY: { |
| 190859 | 192330 | u32 j = 1; |
| | @@ -190865,10 +192336,11 @@ |
| 190865 | 192336 | jsonRenderNode(&pNode[j], pOut, aReplace); |
| 190866 | 192337 | } |
| 190867 | 192338 | j += jsonNodeSize(&pNode[j]); |
| 190868 | 192339 | } |
| 190869 | 192340 | if( (pNode->jnFlags & JNODE_APPEND)==0 ) break; |
| 192341 | + assert( pNode->eU==2 ); |
| 190870 | 192342 | pNode = &pNode[pNode->u.iAppend]; |
| 190871 | 192343 | j = 1; |
| 190872 | 192344 | } |
| 190873 | 192345 | jsonAppendChar(pOut, ']'); |
| 190874 | 192346 | break; |
| | @@ -190885,10 +192357,11 @@ |
| 190885 | 192357 | jsonRenderNode(&pNode[j+1], pOut, aReplace); |
| 190886 | 192358 | } |
| 190887 | 192359 | j += 1 + jsonNodeSize(&pNode[j+1]); |
| 190888 | 192360 | } |
| 190889 | 192361 | if( (pNode->jnFlags & JNODE_APPEND)==0 ) break; |
| 192362 | + assert( pNode->eU==2 ); |
| 190890 | 192363 | pNode = &pNode[pNode->u.iAppend]; |
| 190891 | 192364 | j = 1; |
| 190892 | 192365 | } |
| 190893 | 192366 | jsonAppendChar(pOut, '}'); |
| 190894 | 192367 | break; |
| | @@ -190964,11 +192437,13 @@ |
| 190964 | 192437 | sqlite3_result_int(pCtx, 0); |
| 190965 | 192438 | break; |
| 190966 | 192439 | } |
| 190967 | 192440 | case JSON_INT: { |
| 190968 | 192441 | sqlite3_int64 i = 0; |
| 190969 | | - const char *z = pNode->u.zJContent; |
| 192442 | + const char *z; |
| 192443 | + assert( pNode->eU==1 ); |
| 192444 | + z = pNode->u.zJContent; |
| 190970 | 192445 | if( z[0]=='-' ){ z++; } |
| 190971 | 192446 | while( z[0]>='0' && z[0]<='9' ){ |
| 190972 | 192447 | unsigned v = *(z++) - '0'; |
| 190973 | 192448 | if( i>=LARGEST_INT64/10 ){ |
| 190974 | 192449 | if( i>LARGEST_INT64/10 ) goto int_as_real; |
| | @@ -190992,13 +192467,16 @@ |
| 190992 | 192467 | int_as_real: ; /* no break */ deliberate_fall_through |
| 190993 | 192468 | } |
| 190994 | 192469 | case JSON_REAL: { |
| 190995 | 192470 | double r; |
| 190996 | 192471 | #ifdef SQLITE_AMALGAMATION |
| 190997 | | - const char *z = pNode->u.zJContent; |
| 192472 | + const char *z; |
| 192473 | + assert( pNode->eU==1 ); |
| 192474 | + z = pNode->u.zJContent; |
| 190998 | 192475 | sqlite3AtoF(z, &r, sqlite3Strlen30(z), SQLITE_UTF8); |
| 190999 | 192476 | #else |
| 192477 | + assert( pNode->eU==1 ); |
| 191000 | 192478 | r = strtod(pNode->u.zJContent, 0); |
| 191001 | 192479 | #endif |
| 191002 | 192480 | sqlite3_result_double(pCtx, r); |
| 191003 | 192481 | break; |
| 191004 | 192482 | } |
| | @@ -191005,26 +192483,30 @@ |
| 191005 | 192483 | case JSON_STRING: { |
| 191006 | 192484 | #if 0 /* Never happens because JNODE_RAW is only set by json_set(), |
| 191007 | 192485 | ** json_insert() and json_replace() and those routines do not |
| 191008 | 192486 | ** call jsonReturn() */ |
| 191009 | 192487 | if( pNode->jnFlags & JNODE_RAW ){ |
| 192488 | + assert( pNode->eU==1 ); |
| 191010 | 192489 | sqlite3_result_text(pCtx, pNode->u.zJContent, pNode->n, |
| 191011 | 192490 | SQLITE_TRANSIENT); |
| 191012 | 192491 | }else |
| 191013 | 192492 | #endif |
| 191014 | 192493 | assert( (pNode->jnFlags & JNODE_RAW)==0 ); |
| 191015 | 192494 | if( (pNode->jnFlags & JNODE_ESCAPE)==0 ){ |
| 191016 | 192495 | /* JSON formatted without any backslash-escapes */ |
| 192496 | + assert( pNode->eU==1 ); |
| 191017 | 192497 | sqlite3_result_text(pCtx, pNode->u.zJContent+1, pNode->n-2, |
| 191018 | 192498 | SQLITE_TRANSIENT); |
| 191019 | 192499 | }else{ |
| 191020 | 192500 | /* Translate JSON formatted string into raw text */ |
| 191021 | 192501 | u32 i; |
| 191022 | 192502 | u32 n = pNode->n; |
| 191023 | | - const char *z = pNode->u.zJContent; |
| 192503 | + const char *z; |
| 191024 | 192504 | char *zOut; |
| 191025 | 192505 | u32 j; |
| 192506 | + assert( pNode->eU==1 ); |
| 192507 | + z = pNode->u.zJContent; |
| 191026 | 192508 | zOut = sqlite3_malloc( n+1 ); |
| 191027 | 192509 | if( zOut==0 ){ |
| 191028 | 192510 | sqlite3_result_error_nomem(pCtx); |
| 191029 | 192511 | break; |
| 191030 | 192512 | } |
| | @@ -191141,16 +192623,17 @@ |
| 191141 | 192623 | u32 eType, /* Node type */ |
| 191142 | 192624 | u32 n, /* Content size or sub-node count */ |
| 191143 | 192625 | const char *zContent /* Content */ |
| 191144 | 192626 | ){ |
| 191145 | 192627 | JsonNode *p; |
| 191146 | | - if( pParse->nNode>=pParse->nAlloc ){ |
| 192628 | + if( pParse->aNode==0 || pParse->nNode>=pParse->nAlloc ){ |
| 191147 | 192629 | return jsonParseAddNodeExpand(pParse, eType, n, zContent); |
| 191148 | 192630 | } |
| 191149 | 192631 | p = &pParse->aNode[pParse->nNode]; |
| 191150 | 192632 | p->eType = (u8)eType; |
| 191151 | 192633 | p->jnFlags = 0; |
| 192634 | + VVA( p->eU = zContent ? 1 : 0 ); |
| 191152 | 192635 | p->n = n; |
| 191153 | 192636 | p->u.zJContent = zContent; |
| 191154 | 192637 | return pParse->nNode++; |
| 191155 | 192638 | } |
| 191156 | 192639 | |
| | @@ -191214,10 +192697,11 @@ |
| 191214 | 192697 | return j+1; |
| 191215 | 192698 | }else if( c=='[' ){ |
| 191216 | 192699 | /* Parse array */ |
| 191217 | 192700 | iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0); |
| 191218 | 192701 | if( iThis<0 ) return -1; |
| 192702 | + memset(&pParse->aNode[iThis].u, 0, sizeof(pParse->aNode[iThis].u)); |
| 191219 | 192703 | for(j=i+1;;j++){ |
| 191220 | 192704 | while( safe_isspace(z[j]) ){ j++; } |
| 191221 | 192705 | if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1; |
| 191222 | 192706 | x = jsonParseValue(pParse, j); |
| 191223 | 192707 | pParse->iDepth--; |
| | @@ -191478,10 +192962,11 @@ |
| 191478 | 192962 | /* |
| 191479 | 192963 | ** Compare the OBJECT label at pNode against zKey,nKey. Return true on |
| 191480 | 192964 | ** a match. |
| 191481 | 192965 | */ |
| 191482 | 192966 | static int jsonLabelCompare(JsonNode *pNode, const char *zKey, u32 nKey){ |
| 192967 | + assert( pNode->eU==1 ); |
| 191483 | 192968 | if( pNode->jnFlags & JNODE_RAW ){ |
| 191484 | 192969 | if( pNode->n!=nKey ) return 0; |
| 191485 | 192970 | return strncmp(pNode->u.zJContent, zKey, nKey)==0; |
| 191486 | 192971 | }else{ |
| 191487 | 192972 | if( pNode->n!=nKey+2 ) return 0; |
| | @@ -191543,10 +193028,11 @@ |
| 191543 | 193028 | } |
| 191544 | 193029 | j++; |
| 191545 | 193030 | j += jsonNodeSize(&pRoot[j]); |
| 191546 | 193031 | } |
| 191547 | 193032 | if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break; |
| 193033 | + assert( pRoot->eU==2 ); |
| 191548 | 193034 | iRoot += pRoot->u.iAppend; |
| 191549 | 193035 | pRoot = &pParse->aNode[iRoot]; |
| 191550 | 193036 | j = 1; |
| 191551 | 193037 | } |
| 191552 | 193038 | if( pApnd ){ |
| | @@ -191557,12 +193043,14 @@ |
| 191557 | 193043 | zPath += i; |
| 191558 | 193044 | pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr); |
| 191559 | 193045 | if( pParse->oom ) return 0; |
| 191560 | 193046 | if( pNode ){ |
| 191561 | 193047 | pRoot = &pParse->aNode[iRoot]; |
| 193048 | + assert( pRoot->eU==0 ); |
| 191562 | 193049 | pRoot->u.iAppend = iStart - iRoot; |
| 191563 | 193050 | pRoot->jnFlags |= JNODE_APPEND; |
| 193051 | + VVA( pRoot->eU = 2 ); |
| 191564 | 193052 | pParse->aNode[iLabel].jnFlags |= JNODE_RAW; |
| 191565 | 193053 | } |
| 191566 | 193054 | return pNode; |
| 191567 | 193055 | } |
| 191568 | 193056 | }else if( zPath[0]=='[' ){ |
| | @@ -191581,10 +193069,11 @@ |
| 191581 | 193069 | while( j<=pBase->n ){ |
| 191582 | 193070 | if( (pBase[j].jnFlags & JNODE_REMOVE)==0 ) i++; |
| 191583 | 193071 | j += jsonNodeSize(&pBase[j]); |
| 191584 | 193072 | } |
| 191585 | 193073 | if( (pBase->jnFlags & JNODE_APPEND)==0 ) break; |
| 193074 | + assert( pBase->eU==2 ); |
| 191586 | 193075 | iBase += pBase->u.iAppend; |
| 191587 | 193076 | pBase = &pParse->aNode[iBase]; |
| 191588 | 193077 | j = 1; |
| 191589 | 193078 | } |
| 191590 | 193079 | j = 2; |
| | @@ -191614,10 +193103,11 @@ |
| 191614 | 193103 | while( j<=pRoot->n && (i>0 || (pRoot[j].jnFlags & JNODE_REMOVE)!=0) ){ |
| 191615 | 193104 | if( (pRoot[j].jnFlags & JNODE_REMOVE)==0 ) i--; |
| 191616 | 193105 | j += jsonNodeSize(&pRoot[j]); |
| 191617 | 193106 | } |
| 191618 | 193107 | if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break; |
| 193108 | + assert( pRoot->eU==2 ); |
| 191619 | 193109 | iRoot += pRoot->u.iAppend; |
| 191620 | 193110 | pRoot = &pParse->aNode[iRoot]; |
| 191621 | 193111 | j = 1; |
| 191622 | 193112 | } |
| 191623 | 193113 | if( j<=pRoot->n ){ |
| | @@ -191629,12 +193119,14 @@ |
| 191629 | 193119 | iStart = jsonParseAddNode(pParse, JSON_ARRAY, 1, 0); |
| 191630 | 193120 | pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr); |
| 191631 | 193121 | if( pParse->oom ) return 0; |
| 191632 | 193122 | if( pNode ){ |
| 191633 | 193123 | pRoot = &pParse->aNode[iRoot]; |
| 193124 | + assert( pRoot->eU==0 ); |
| 191634 | 193125 | pRoot->u.iAppend = iStart - iRoot; |
| 191635 | 193126 | pRoot->jnFlags |= JNODE_APPEND; |
| 193127 | + VVA( pRoot->eU = 2 ); |
| 191636 | 193128 | } |
| 191637 | 193129 | return pNode; |
| 191638 | 193130 | } |
| 191639 | 193131 | }else{ |
| 191640 | 193132 | *pzErr = zPath; |
| | @@ -191784,13 +193276,17 @@ |
| 191784 | 193276 | }else{ |
| 191785 | 193277 | zType = jsonType[x.aNode[i].eType]; |
| 191786 | 193278 | } |
| 191787 | 193279 | jsonPrintf(100, &s,"node %3u: %7s n=%-4d up=%-4d", |
| 191788 | 193280 | i, zType, x.aNode[i].n, x.aUp[i]); |
| 193281 | + assert( x.aNode[i].eU==0 || x.aNode[i].eU==1 ); |
| 191789 | 193282 | if( x.aNode[i].u.zJContent!=0 ){ |
| 193283 | + assert( x.aNode[i].eU==1 ); |
| 191790 | 193284 | jsonAppendRaw(&s, " ", 1); |
| 191791 | 193285 | jsonAppendRaw(&s, x.aNode[i].u.zJContent, x.aNode[i].n); |
| 193286 | + }else{ |
| 193287 | + assert( x.aNode[i].eU==0 ); |
| 191792 | 193288 | } |
| 191793 | 193289 | jsonAppendRaw(&s, "\n", 1); |
| 191794 | 193290 | } |
| 191795 | 193291 | jsonParseReset(&x); |
| 191796 | 193292 | jsonResult(&s); |
| | @@ -191969,10 +193465,11 @@ |
| 191969 | 193465 | for(i=1; i<pPatch->n; i += jsonNodeSize(&pPatch[i+1])+1){ |
| 191970 | 193466 | u32 nKey; |
| 191971 | 193467 | const char *zKey; |
| 191972 | 193468 | assert( pPatch[i].eType==JSON_STRING ); |
| 191973 | 193469 | assert( pPatch[i].jnFlags & JNODE_LABEL ); |
| 193470 | + assert( pPatch[i].eU==1 ); |
| 191974 | 193471 | nKey = pPatch[i].n; |
| 191975 | 193472 | zKey = pPatch[i].u.zJContent; |
| 191976 | 193473 | assert( (pPatch[i].jnFlags & JNODE_RAW)==0 ); |
| 191977 | 193474 | for(j=1; j<pTarget->n; j += jsonNodeSize(&pTarget[j+1])+1 ){ |
| 191978 | 193475 | assert( pTarget[j].eType==JSON_STRING ); |
| | @@ -191985,10 +193482,16 @@ |
| 191985 | 193482 | }else{ |
| 191986 | 193483 | JsonNode *pNew = jsonMergePatch(pParse, iTarget+j+1, &pPatch[i+1]); |
| 191987 | 193484 | if( pNew==0 ) return 0; |
| 191988 | 193485 | pTarget = &pParse->aNode[iTarget]; |
| 191989 | 193486 | if( pNew!=&pTarget[j+1] ){ |
| 193487 | + assert( pTarget[j+1].eU==0 |
| 193488 | + || pTarget[j+1].eU==1 |
| 193489 | + || pTarget[j+1].eU==2 ); |
| 193490 | + testcase( pTarget[j+1].eU==1 ); |
| 193491 | + testcase( pTarget[j+1].eU==2 ); |
| 193492 | + VVA( pTarget[j+1].eU = 5 ); |
| 191990 | 193493 | pTarget[j+1].u.pPatch = pNew; |
| 191991 | 193494 | pTarget[j+1].jnFlags |= JNODE_PATCH; |
| 191992 | 193495 | } |
| 191993 | 193496 | } |
| 191994 | 193497 | break; |
| | @@ -192000,13 +193503,18 @@ |
| 192000 | 193503 | jsonParseAddNode(pParse, JSON_STRING, nKey, zKey); |
| 192001 | 193504 | iPatch = jsonParseAddNode(pParse, JSON_TRUE, 0, 0); |
| 192002 | 193505 | if( pParse->oom ) return 0; |
| 192003 | 193506 | jsonRemoveAllNulls(pPatch); |
| 192004 | 193507 | pTarget = &pParse->aNode[iTarget]; |
| 193508 | + assert( pParse->aNode[iRoot].eU==0 || pParse->aNode[iRoot].eU==2 ); |
| 193509 | + testcase( pParse->aNode[iRoot].eU==2 ); |
| 192005 | 193510 | pParse->aNode[iRoot].jnFlags |= JNODE_APPEND; |
| 193511 | + VVA( pParse->aNode[iRoot].eU = 2 ); |
| 192006 | 193512 | pParse->aNode[iRoot].u.iAppend = iStart - iRoot; |
| 192007 | 193513 | iRoot = iStart; |
| 193514 | + assert( pParse->aNode[iPatch].eU==0 ); |
| 193515 | + VVA( pParse->aNode[iPatch].eU = 5 ); |
| 192008 | 193516 | pParse->aNode[iPatch].jnFlags |= JNODE_PATCH; |
| 192009 | 193517 | pParse->aNode[iPatch].u.pPatch = &pPatch[i+1]; |
| 192010 | 193518 | } |
| 192011 | 193519 | } |
| 192012 | 193520 | return pTarget; |
| | @@ -192144,15 +193652,19 @@ |
| 192144 | 193652 | for(i=1; i<(u32)argc; i+=2){ |
| 192145 | 193653 | zPath = (const char*)sqlite3_value_text(argv[i]); |
| 192146 | 193654 | pNode = jsonLookup(&x, zPath, 0, ctx); |
| 192147 | 193655 | if( x.nErr ) goto replace_err; |
| 192148 | 193656 | if( pNode ){ |
| 193657 | + assert( pNode->eU==0 || pNode->eU==1 || pNode->eU==4 ); |
| 193658 | + json_testcase( pNode->eU!=0 && pNode->eU!=1 ); |
| 192149 | 193659 | pNode->jnFlags |= (u8)JNODE_REPLACE; |
| 193660 | + VVA( pNode->eU = 4 ); |
| 192150 | 193661 | pNode->u.iReplace = i + 1; |
| 192151 | 193662 | } |
| 192152 | 193663 | } |
| 192153 | 193664 | if( x.aNode[0].jnFlags & JNODE_REPLACE ){ |
| 193665 | + assert( x.aNode[0].eU==4 ); |
| 192154 | 193666 | sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]); |
| 192155 | 193667 | }else{ |
| 192156 | 193668 | jsonReturnJson(x.aNode, ctx, argv); |
| 192157 | 193669 | } |
| 192158 | 193670 | replace_err: |
| | @@ -192198,15 +193710,19 @@ |
| 192198 | 193710 | sqlite3_result_error_nomem(ctx); |
| 192199 | 193711 | goto jsonSetDone; |
| 192200 | 193712 | }else if( x.nErr ){ |
| 192201 | 193713 | goto jsonSetDone; |
| 192202 | 193714 | }else if( pNode && (bApnd || bIsSet) ){ |
| 193715 | + json_testcase( pNode->eU!=0 && pNode->eU!=1 && pNode->eU!=4 ); |
| 193716 | + assert( pNode->eU!=3 || pNode->eU!=5 ); |
| 193717 | + VVA( pNode->eU = 4 ); |
| 192203 | 193718 | pNode->jnFlags |= (u8)JNODE_REPLACE; |
| 192204 | 193719 | pNode->u.iReplace = i + 1; |
| 192205 | 193720 | } |
| 192206 | 193721 | } |
| 192207 | 193722 | if( x.aNode[0].jnFlags & JNODE_REPLACE ){ |
| 193723 | + assert( x.aNode[0].eU==4 ); |
| 192208 | 193724 | sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]); |
| 192209 | 193725 | }else{ |
| 192210 | 193726 | jsonReturnJson(x.aNode, ctx, argv); |
| 192211 | 193727 | } |
| 192212 | 193728 | jsonSetDone: |
| | @@ -192553,10 +194069,13 @@ |
| 192553 | 194069 | if( p->i<p->iEnd ){ |
| 192554 | 194070 | u32 iUp = p->sParse.aUp[p->i]; |
| 192555 | 194071 | JsonNode *pUp = &p->sParse.aNode[iUp]; |
| 192556 | 194072 | p->eType = pUp->eType; |
| 192557 | 194073 | if( pUp->eType==JSON_ARRAY ){ |
| 194074 | + assert( pUp->eU==0 || pUp->eU==3 ); |
| 194075 | + json_testcase( pUp->eU==3 ); |
| 194076 | + VVA( pUp->eU = 3 ); |
| 192558 | 194077 | if( iUp==p->i-1 ){ |
| 192559 | 194078 | pUp->u.iKey = 0; |
| 192560 | 194079 | }else{ |
| 192561 | 194080 | pUp->u.iKey++; |
| 192562 | 194081 | } |
| | @@ -192599,16 +194118,19 @@ |
| 192599 | 194118 | iUp = p->sParse.aUp[i]; |
| 192600 | 194119 | jsonEachComputePath(p, pStr, iUp); |
| 192601 | 194120 | pNode = &p->sParse.aNode[i]; |
| 192602 | 194121 | pUp = &p->sParse.aNode[iUp]; |
| 192603 | 194122 | if( pUp->eType==JSON_ARRAY ){ |
| 194123 | + assert( pUp->eU==3 || (pUp->eU==0 && pUp->u.iKey==0) ); |
| 194124 | + testcase( pUp->eU==0 ); |
| 192604 | 194125 | jsonPrintf(30, pStr, "[%d]", pUp->u.iKey); |
| 192605 | 194126 | }else{ |
| 192606 | 194127 | assert( pUp->eType==JSON_OBJECT ); |
| 192607 | 194128 | if( (pNode->jnFlags & JNODE_LABEL)==0 ) pNode--; |
| 192608 | 194129 | assert( pNode->eType==JSON_STRING ); |
| 192609 | 194130 | assert( pNode->jnFlags & JNODE_LABEL ); |
| 194131 | + assert( pNode->eU==1 ); |
| 192610 | 194132 | jsonPrintf(pNode->n+1, pStr, ".%.*s", pNode->n-2, pNode->u.zJContent+1); |
| 192611 | 194133 | } |
| 192612 | 194134 | } |
| 192613 | 194135 | |
| 192614 | 194136 | /* Return the value of a column */ |
| | @@ -192626,10 +194148,11 @@ |
| 192626 | 194148 | jsonReturn(pThis, ctx, 0); |
| 192627 | 194149 | }else if( p->eType==JSON_ARRAY ){ |
| 192628 | 194150 | u32 iKey; |
| 192629 | 194151 | if( p->bRecursive ){ |
| 192630 | 194152 | if( p->iRowid==0 ) break; |
| 194153 | + assert( p->sParse.aNode[p->sParse.aUp[p->i]].eU==3 ); |
| 192631 | 194154 | iKey = p->sParse.aNode[p->sParse.aUp[p->i]].u.iKey; |
| 192632 | 194155 | }else{ |
| 192633 | 194156 | iKey = p->iRowid; |
| 192634 | 194157 | } |
| 192635 | 194158 | sqlite3_result_int64(ctx, (sqlite3_int64)iKey); |
| | @@ -192675,10 +194198,11 @@ |
| 192675 | 194198 | jsonAppendChar(&x, '$'); |
| 192676 | 194199 | } |
| 192677 | 194200 | if( p->eType==JSON_ARRAY ){ |
| 192678 | 194201 | jsonPrintf(30, &x, "[%d]", p->iRowid); |
| 192679 | 194202 | }else if( p->eType==JSON_OBJECT ){ |
| 194203 | + assert( pThis->eU==1 ); |
| 192680 | 194204 | jsonPrintf(pThis->n, &x, ".%.*s", pThis->n-2, pThis->u.zJContent+1); |
| 192681 | 194205 | } |
| 192682 | 194206 | } |
| 192683 | 194207 | jsonResult(&x); |
| 192684 | 194208 | break; |
| | @@ -192742,10 +194266,11 @@ |
| 192742 | 194266 | int iCol; |
| 192743 | 194267 | int iMask; |
| 192744 | 194268 | if( pConstraint->iColumn < JEACH_JSON ) continue; |
| 192745 | 194269 | iCol = pConstraint->iColumn - JEACH_JSON; |
| 192746 | 194270 | assert( iCol==0 || iCol==1 ); |
| 194271 | + testcase( iCol==0 ); |
| 192747 | 194272 | iMask = 1 << iCol; |
| 192748 | 194273 | if( pConstraint->usable==0 ){ |
| 192749 | 194274 | unusableMask |= iMask; |
| 192750 | 194275 | }else if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ ){ |
| 192751 | 194276 | aIdx[iCol] = i; |
| | @@ -192839,10 +194364,12 @@ |
| 192839 | 194364 | pNode = p->sParse.aNode; |
| 192840 | 194365 | } |
| 192841 | 194366 | p->iBegin = p->i = (int)(pNode - p->sParse.aNode); |
| 192842 | 194367 | p->eType = pNode->eType; |
| 192843 | 194368 | if( p->eType>=JSON_ARRAY ){ |
| 194369 | + assert( pNode->eU==0 ); |
| 194370 | + VVA( pNode->eU = 3 ); |
| 192844 | 194371 | pNode->u.iKey = 0; |
| 192845 | 194372 | p->iEnd = p->i + pNode->n + 1; |
| 192846 | 194373 | if( p->bRecursive ){ |
| 192847 | 194374 | p->eType = p->sParse.aNode[p->sParse.aUp[p->i]].eType; |
| 192848 | 194375 | if( p->i>0 && (p->sParse.aNode[p->i-1].jnFlags & JNODE_LABEL)!=0 ){ |
| | @@ -193099,10 +194626,13 @@ |
| 193099 | 194626 | #endif |
| 193100 | 194627 | #if defined(NDEBUG) && defined(SQLITE_DEBUG) |
| 193101 | 194628 | # undef NDEBUG |
| 193102 | 194629 | #endif |
| 193103 | 194630 | #if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST) |
| 194631 | +# define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1 |
| 194632 | +#endif |
| 194633 | +#if defined(SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS) |
| 193104 | 194634 | # define ALWAYS(X) (1) |
| 193105 | 194635 | # define NEVER(X) (0) |
| 193106 | 194636 | #elif !defined(NDEBUG) |
| 193107 | 194637 | # define ALWAYS(X) ((X)?1:(assert(0),0)) |
| 193108 | 194638 | # define NEVER(X) ((X)?(assert(0),1):0) |
| | @@ -193450,11 +194980,16 @@ |
| 193450 | 194980 | |
| 193451 | 194981 | /* The testcase() macro should already be defined in the amalgamation. If |
| 193452 | 194982 | ** it is not, make it a no-op. |
| 193453 | 194983 | */ |
| 193454 | 194984 | #ifndef SQLITE_AMALGAMATION |
| 193455 | | -# define testcase(X) |
| 194985 | +# if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG) |
| 194986 | + unsigned int sqlite3RtreeTestcase = 0; |
| 194987 | +# define testcase(X) if( X ){ sqlite3RtreeTestcase += __LINE__; } |
| 194988 | +# else |
| 194989 | +# define testcase(X) |
| 194990 | +# endif |
| 193456 | 194991 | #endif |
| 193457 | 194992 | |
| 193458 | 194993 | /* |
| 193459 | 194994 | ** Make sure that the compiler intrinsics we desire are enabled when |
| 193460 | 194995 | ** compiling with an appropriate version of MSVC unless prevented by |
| | @@ -194296,24 +195831,33 @@ |
| 194296 | 195831 | || p->op==RTREE_FALSE ); |
| 194297 | 195832 | assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */ |
| 194298 | 195833 | switch( p->op ){ |
| 194299 | 195834 | case RTREE_TRUE: return; /* Always satisfied */ |
| 194300 | 195835 | case RTREE_FALSE: break; /* Never satisfied */ |
| 194301 | | - case RTREE_LE: |
| 194302 | | - case RTREE_LT: |
| 194303 | 195836 | case RTREE_EQ: |
| 194304 | 195837 | RTREE_DECODE_COORD(eInt, pCellData, val); |
| 194305 | 195838 | /* val now holds the lower bound of the coordinate pair */ |
| 195839 | + if( p->u.rValue>=val ){ |
| 195840 | + pCellData += 4; |
| 195841 | + RTREE_DECODE_COORD(eInt, pCellData, val); |
| 195842 | + /* val now holds the upper bound of the coordinate pair */ |
| 195843 | + if( p->u.rValue<=val ) return; |
| 195844 | + } |
| 195845 | + break; |
| 195846 | + case RTREE_LE: |
| 195847 | + case RTREE_LT: |
| 195848 | + RTREE_DECODE_COORD(eInt, pCellData, val); |
| 195849 | + /* val now holds the lower bound of the coordinate pair */ |
| 194306 | 195850 | if( p->u.rValue>=val ) return; |
| 194307 | | - if( p->op!=RTREE_EQ ) break; /* RTREE_LE and RTREE_LT end here */ |
| 194308 | | - /* Fall through for the RTREE_EQ case */ |
| 195851 | + break; |
| 194309 | 195852 | |
| 194310 | | - default: /* RTREE_GT or RTREE_GE, or fallthrough of RTREE_EQ */ |
| 195853 | + default: |
| 194311 | 195854 | pCellData += 4; |
| 194312 | 195855 | RTREE_DECODE_COORD(eInt, pCellData, val); |
| 194313 | 195856 | /* val now holds the upper bound of the coordinate pair */ |
| 194314 | 195857 | if( p->u.rValue<=val ) return; |
| 195858 | + break; |
| 194315 | 195859 | } |
| 194316 | 195860 | *peWithin = NOT_WITHIN; |
| 194317 | 195861 | } |
| 194318 | 195862 | |
| 194319 | 195863 | /* |
| | @@ -195214,11 +196758,11 @@ |
| 195214 | 196758 | RtreeDValue fMinGrowth = RTREE_ZERO; |
| 195215 | 196759 | RtreeDValue fMinArea = RTREE_ZERO; |
| 195216 | 196760 | |
| 195217 | 196761 | int nCell = NCELL(pNode); |
| 195218 | 196762 | RtreeCell cell; |
| 195219 | | - RtreeNode *pChild; |
| 196763 | + RtreeNode *pChild = 0; |
| 195220 | 196764 | |
| 195221 | 196765 | RtreeCell *aCell = 0; |
| 195222 | 196766 | |
| 195223 | 196767 | /* Select the child node which will be enlarged the least if pCell |
| 195224 | 196768 | ** is inserted into it. Resolve ties by choosing the entry with |
| | @@ -195572,10 +197116,11 @@ |
| 195572 | 197116 | nodeRelease(pRtree, pChild->pParent); |
| 195573 | 197117 | nodeReference(pNode); |
| 195574 | 197118 | pChild->pParent = pNode; |
| 195575 | 197119 | } |
| 195576 | 197120 | } |
| 197121 | + if( NEVER(pNode==0) ) return SQLITE_ERROR; |
| 195577 | 197122 | return xSetMapping(pRtree, iRowid, pNode->iNode); |
| 195578 | 197123 | } |
| 195579 | 197124 | |
| 195580 | 197125 | static int SplitNode( |
| 195581 | 197126 | Rtree *pRtree, |
| | @@ -196876,10 +198421,11 @@ |
| 196876 | 198421 | tree.nDim = (u8)sqlite3_value_int(apArg[0]); |
| 196877 | 198422 | if( tree.nDim<1 || tree.nDim>5 ) return; |
| 196878 | 198423 | tree.nDim2 = tree.nDim*2; |
| 196879 | 198424 | tree.nBytesPerCell = 8 + 8 * tree.nDim; |
| 196880 | 198425 | node.zData = (u8 *)sqlite3_value_blob(apArg[1]); |
| 198426 | + if( node.zData==0 ) return; |
| 196881 | 198427 | nData = sqlite3_value_bytes(apArg[1]); |
| 196882 | 198428 | if( nData<4 ) return; |
| 196883 | 198429 | if( nData<NCELL(&node)*tree.nBytesPerCell ) return; |
| 196884 | 198430 | |
| 196885 | 198431 | pOut = sqlite3_str_new(0); |
| | @@ -197707,17 +199253,18 @@ |
| 197707 | 199253 | sqlite3_value *pVal, /* The value to decode */ |
| 197708 | 199254 | int *pRc /* Write error here */ |
| 197709 | 199255 | ){ |
| 197710 | 199256 | GeoPoly *p = 0; |
| 197711 | 199257 | int nByte; |
| 199258 | + testcase( pCtx==0 ); |
| 197712 | 199259 | if( sqlite3_value_type(pVal)==SQLITE_BLOB |
| 197713 | 199260 | && (nByte = sqlite3_value_bytes(pVal))>=(4+6*sizeof(GeoCoord)) |
| 197714 | 199261 | ){ |
| 197715 | 199262 | const unsigned char *a = sqlite3_value_blob(pVal); |
| 197716 | 199263 | int nVertex; |
| 197717 | 199264 | if( a==0 ){ |
| 197718 | | - sqlite3_result_error_nomem(pCtx); |
| 199265 | + if( pCtx ) sqlite3_result_error_nomem(pCtx); |
| 197719 | 199266 | return 0; |
| 197720 | 199267 | } |
| 197721 | 199268 | nVertex = (a[1]<<16) + (a[2]<<8) + a[3]; |
| 197722 | 199269 | if( (a[0]==0 || a[0]==1) |
| 197723 | 199270 | && (nVertex*2*sizeof(GeoCoord) + 4)==(unsigned int)nByte |
| | @@ -198540,15 +200087,15 @@ |
| 198540 | 200087 | pActive = pSeg; |
| 198541 | 200088 | needSort = 1; |
| 198542 | 200089 | }else{ |
| 198543 | 200090 | /* Remove a segment */ |
| 198544 | 200091 | if( pActive==pThisEvent->pSeg ){ |
| 198545 | | - pActive = pActive->pNext; |
| 200092 | + pActive = ALWAYS(pActive) ? pActive->pNext : 0; |
| 198546 | 200093 | }else{ |
| 198547 | 200094 | for(pSeg=pActive; pSeg; pSeg=pSeg->pNext){ |
| 198548 | 200095 | if( pSeg->pNext==pThisEvent->pSeg ){ |
| 198549 | | - pSeg->pNext = pSeg->pNext->pNext; |
| 200096 | + pSeg->pNext = ALWAYS(pSeg->pNext) ? pSeg->pNext->pNext : 0; |
| 198550 | 200097 | break; |
| 198551 | 200098 | } |
| 198552 | 200099 | } |
| 198553 | 200100 | } |
| 198554 | 200101 | } |
| | @@ -198788,10 +200335,11 @@ |
| 198788 | 200335 | rc = nodeAcquire(pRtree, 1, 0, &pRoot); |
| 198789 | 200336 | if( rc==SQLITE_OK && idxNum<=3 ){ |
| 198790 | 200337 | RtreeCoord bbox[4]; |
| 198791 | 200338 | RtreeConstraint *p; |
| 198792 | 200339 | assert( argc==1 ); |
| 200340 | + assert( argv[0]!=0 ); |
| 198793 | 200341 | geopolyBBox(0, argv[0], bbox, &rc); |
| 198794 | 200342 | if( rc ){ |
| 198795 | 200343 | goto geopoly_filter_end; |
| 198796 | 200344 | } |
| 198797 | 200345 | pCsr->aConstraint = p = sqlite3_malloc(sizeof(RtreeConstraint)*4); |
| | @@ -199015,10 +200563,11 @@ |
| 199015 | 200563 | if( nData>1 /* not a DELETE */ |
| 199016 | 200564 | && (!oldRowidValid /* INSERT */ |
| 199017 | 200565 | || !sqlite3_value_nochange(aData[2]) /* UPDATE _shape */ |
| 199018 | 200566 | || oldRowid!=newRowid) /* Rowid change */ |
| 199019 | 200567 | ){ |
| 200568 | + assert( aData[2]!=0 ); |
| 199020 | 200569 | geopolyBBox(0, aData[2], cell.aCoord, &rc); |
| 199021 | 200570 | if( rc ){ |
| 199022 | 200571 | if( rc==SQLITE_ERROR ){ |
| 199023 | 200572 | pVtab->zErrMsg = |
| 199024 | 200573 | sqlite3_mprintf("_shape does not contain a valid polygon"); |
| | @@ -200941,10 +202490,17 @@ |
| 200941 | 202490 | ** Swap two objects of type TYPE. |
| 200942 | 202491 | */ |
| 200943 | 202492 | #if !defined(SQLITE_AMALGAMATION) |
| 200944 | 202493 | # define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;} |
| 200945 | 202494 | #endif |
| 202495 | + |
| 202496 | +/* |
| 202497 | +** Name of the URI option that causes RBU to take an exclusive lock as |
| 202498 | +** part of the incremental checkpoint operation. |
| 202499 | +*/ |
| 202500 | +#define RBU_EXCLUSIVE_CHECKPOINT "rbu_exclusive_checkpoint" |
| 202501 | + |
| 200946 | 202502 | |
| 200947 | 202503 | /* |
| 200948 | 202504 | ** The rbu_state table is used to save the state of a partially applied |
| 200949 | 202505 | ** update so that it can be resumed later. The table consists of integer |
| 200950 | 202506 | ** keys mapped to values as follows: |
| | @@ -202388,11 +203944,11 @@ |
| 202388 | 203944 | ** |
| 202389 | 203945 | ** If the expression cannot be created, NULL is returned. In this case, |
| 202390 | 203946 | ** the caller has to use an OFFSET clause to extract only the required |
| 202391 | 203947 | ** rows from the sourct table, just as it does for an RBU update operation. |
| 202392 | 203948 | */ |
| 202393 | | -char *rbuVacuumIndexStart( |
| 203949 | +static char *rbuVacuumIndexStart( |
| 202394 | 203950 | sqlite3rbu *p, /* RBU handle */ |
| 202395 | 203951 | RbuObjIter *pIter /* RBU iterator object */ |
| 202396 | 203952 | ){ |
| 202397 | 203953 | char *zOrder = 0; |
| 202398 | 203954 | char *zLhs = 0; |
| | @@ -203588,17 +205144,23 @@ |
| 203588 | 205144 | |
| 203589 | 205145 | |
| 203590 | 205146 | /* |
| 203591 | 205147 | ** Open the database handle and attach the RBU database as "rbu". If an |
| 203592 | 205148 | ** error occurs, leave an error code and message in the RBU handle. |
| 205149 | +** |
| 205150 | +** If argument dbMain is not NULL, then it is a database handle already |
| 205151 | +** open on the target database. Use this handle instead of opening a new |
| 205152 | +** one. |
| 203593 | 205153 | */ |
| 203594 | | -static void rbuOpenDatabase(sqlite3rbu *p, int *pbRetry){ |
| 205154 | +static void rbuOpenDatabase(sqlite3rbu *p, sqlite3 *dbMain, int *pbRetry){ |
| 203595 | 205155 | assert( p->rc || (p->dbMain==0 && p->dbRbu==0) ); |
| 203596 | 205156 | assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 ); |
| 205157 | + assert( dbMain==0 || rbuIsVacuum(p)==0 ); |
| 203597 | 205158 | |
| 203598 | 205159 | /* Open the RBU database */ |
| 203599 | 205160 | p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1); |
| 205161 | + p->dbMain = dbMain; |
| 203600 | 205162 | |
| 203601 | 205163 | if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){ |
| 203602 | 205164 | sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p); |
| 203603 | 205165 | if( p->zState==0 ){ |
| 203604 | 205166 | const char *zFile = sqlite3_db_filename(p->dbRbu, "main"); |
| | @@ -203960,19 +205522,35 @@ |
| 203960 | 205522 | p->rc = pDb->pMethods->xWrite(pDb, p->aBuf, p->pgsz, iOff); |
| 203961 | 205523 | } |
| 203962 | 205524 | |
| 203963 | 205525 | |
| 203964 | 205526 | /* |
| 203965 | | -** Take an EXCLUSIVE lock on the database file. |
| 205527 | +** Take an EXCLUSIVE lock on the database file. Return SQLITE_OK if |
| 205528 | +** successful, or an SQLite error code otherwise. |
| 203966 | 205529 | */ |
| 203967 | | -static void rbuLockDatabase(sqlite3rbu *p){ |
| 203968 | | - sqlite3_file *pReal = p->pTargetFd->pReal; |
| 203969 | | - assert( p->rc==SQLITE_OK ); |
| 203970 | | - p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_SHARED); |
| 203971 | | - if( p->rc==SQLITE_OK ){ |
| 203972 | | - p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_EXCLUSIVE); |
| 205530 | +static int rbuLockDatabase(sqlite3 *db){ |
| 205531 | + int rc = SQLITE_OK; |
| 205532 | + sqlite3_file *fd = 0; |
| 205533 | + sqlite3_file_control(db, "main", SQLITE_FCNTL_FILE_POINTER, &fd); |
| 205534 | + |
| 205535 | + if( fd->pMethods ){ |
| 205536 | + rc = fd->pMethods->xLock(fd, SQLITE_LOCK_SHARED); |
| 205537 | + if( rc==SQLITE_OK ){ |
| 205538 | + rc = fd->pMethods->xLock(fd, SQLITE_LOCK_EXCLUSIVE); |
| 205539 | + } |
| 203973 | 205540 | } |
| 205541 | + return rc; |
| 205542 | +} |
| 205543 | + |
| 205544 | +/* |
| 205545 | +** Return true if the database handle passed as the only argument |
| 205546 | +** was opened with the rbu_exclusive_checkpoint=1 URI parameter |
| 205547 | +** specified. Or false otherwise. |
| 205548 | +*/ |
| 205549 | +static int rbuExclusiveCheckpoint(sqlite3 *db){ |
| 205550 | + const char *zUri = sqlite3_db_filename(db, 0); |
| 205551 | + return sqlite3_uri_boolean(zUri, RBU_EXCLUSIVE_CHECKPOINT, 0); |
| 203974 | 205552 | } |
| 203975 | 205553 | |
| 203976 | 205554 | #if defined(_WIN32_WCE) |
| 203977 | 205555 | static LPWSTR rbuWinUtf8ToUnicode(const char *zFilename){ |
| 203978 | 205556 | int nChar; |
| | @@ -204026,22 +205604,28 @@ |
| 204026 | 205604 | ** in WAL mode). So no other connection may be writing the db. |
| 204027 | 205605 | ** |
| 204028 | 205606 | ** In order to ensure that there are no database readers, an EXCLUSIVE |
| 204029 | 205607 | ** lock is obtained here before the *-oal is moved to *-wal. |
| 204030 | 205608 | */ |
| 204031 | | - rbuLockDatabase(p); |
| 205609 | + sqlite3 *dbMain = 0; |
| 205610 | + rbuFileSuffix3(zBase, zWal); |
| 205611 | + rbuFileSuffix3(zBase, zOal); |
| 205612 | + |
| 205613 | + /* Re-open the databases. */ |
| 205614 | + rbuObjIterFinalize(&p->objiter); |
| 205615 | + sqlite3_close(p->dbRbu); |
| 205616 | + sqlite3_close(p->dbMain); |
| 205617 | + p->dbMain = 0; |
| 205618 | + p->dbRbu = 0; |
| 205619 | + |
| 205620 | + dbMain = rbuOpenDbhandle(p, p->zTarget, 1); |
| 205621 | + if( dbMain ){ |
| 205622 | + assert( p->rc==SQLITE_OK ); |
| 205623 | + p->rc = rbuLockDatabase(dbMain); |
| 205624 | + } |
| 205625 | + |
| 204032 | 205626 | if( p->rc==SQLITE_OK ){ |
| 204033 | | - rbuFileSuffix3(zBase, zWal); |
| 204034 | | - rbuFileSuffix3(zBase, zOal); |
| 204035 | | - |
| 204036 | | - /* Re-open the databases. */ |
| 204037 | | - rbuObjIterFinalize(&p->objiter); |
| 204038 | | - sqlite3_close(p->dbRbu); |
| 204039 | | - sqlite3_close(p->dbMain); |
| 204040 | | - p->dbMain = 0; |
| 204041 | | - p->dbRbu = 0; |
| 204042 | | - |
| 204043 | 205627 | #if defined(_WIN32_WCE) |
| 204044 | 205628 | { |
| 204045 | 205629 | LPWSTR zWideOal; |
| 204046 | 205630 | LPWSTR zWideWal; |
| 204047 | 205631 | |
| | @@ -204064,15 +205648,23 @@ |
| 204064 | 205648 | } |
| 204065 | 205649 | } |
| 204066 | 205650 | #else |
| 204067 | 205651 | p->rc = rename(zOal, zWal) ? SQLITE_IOERR : SQLITE_OK; |
| 204068 | 205652 | #endif |
| 205653 | + } |
| 204069 | 205654 | |
| 204070 | | - if( p->rc==SQLITE_OK ){ |
| 204071 | | - rbuOpenDatabase(p, 0); |
| 204072 | | - rbuSetupCheckpoint(p, 0); |
| 204073 | | - } |
| 205655 | + if( p->rc!=SQLITE_OK |
| 205656 | + || rbuIsVacuum(p) |
| 205657 | + || rbuExclusiveCheckpoint(dbMain)==0 |
| 205658 | + ){ |
| 205659 | + sqlite3_close(dbMain); |
| 205660 | + dbMain = 0; |
| 205661 | + } |
| 205662 | + |
| 205663 | + if( p->rc==SQLITE_OK ){ |
| 205664 | + rbuOpenDatabase(p, dbMain, 0); |
| 205665 | + rbuSetupCheckpoint(p, 0); |
| 204074 | 205666 | } |
| 204075 | 205667 | } |
| 204076 | 205668 | |
| 204077 | 205669 | sqlite3_free(zWal); |
| 204078 | 205670 | sqlite3_free(zOal); |
| | @@ -204819,13 +206411,13 @@ |
| 204819 | 206411 | ** to be a wal-mode db. But, this may have happened due to an earlier |
| 204820 | 206412 | ** RBU vacuum operation leaving an old wal file in the directory. |
| 204821 | 206413 | ** If this is the case, it will have been checkpointed and deleted |
| 204822 | 206414 | ** when the handle was closed and a second attempt to open the |
| 204823 | 206415 | ** database may succeed. */ |
| 204824 | | - rbuOpenDatabase(p, &bRetry); |
| 206416 | + rbuOpenDatabase(p, 0, &bRetry); |
| 204825 | 206417 | if( bRetry ){ |
| 204826 | | - rbuOpenDatabase(p, 0); |
| 206418 | + rbuOpenDatabase(p, 0, 0); |
| 204827 | 206419 | } |
| 204828 | 206420 | } |
| 204829 | 206421 | |
| 204830 | 206422 | if( p->rc==SQLITE_OK ){ |
| 204831 | 206423 | pState = rbuLoadState(p); |
| | @@ -204916,10 +206508,18 @@ |
| 204916 | 206508 | } |
| 204917 | 206509 | } |
| 204918 | 206510 | }else if( p->eStage==RBU_STAGE_MOVE ){ |
| 204919 | 206511 | /* no-op */ |
| 204920 | 206512 | }else if( p->eStage==RBU_STAGE_CKPT ){ |
| 206513 | + if( !rbuIsVacuum(p) && rbuExclusiveCheckpoint(p->dbMain) ){ |
| 206514 | + /* If the rbu_exclusive_checkpoint=1 URI parameter was specified |
| 206515 | + ** and an incremental checkpoint is being resumed, attempt an |
| 206516 | + ** exclusive lock on the db file. If this fails, so be it. */ |
| 206517 | + p->eStage = RBU_STAGE_DONE; |
| 206518 | + rbuLockDatabase(p->dbMain); |
| 206519 | + p->eStage = RBU_STAGE_CKPT; |
| 206520 | + } |
| 204921 | 206521 | rbuSetupCheckpoint(p, pState); |
| 204922 | 206522 | }else if( p->eStage==RBU_STAGE_DONE ){ |
| 204923 | 206523 | p->rc = SQLITE_DONE; |
| 204924 | 206524 | }else{ |
| 204925 | 206525 | p->rc = SQLITE_CORRUPT; |
| | @@ -204953,11 +206553,10 @@ |
| 204953 | 206553 | const char *zTarget, |
| 204954 | 206554 | const char *zRbu, |
| 204955 | 206555 | const char *zState |
| 204956 | 206556 | ){ |
| 204957 | 206557 | if( zTarget==0 || zRbu==0 ){ return rbuMisuseError(); } |
| 204958 | | - /* TODO: Check that zTarget and zRbu are non-NULL */ |
| 204959 | 206558 | return openRbuHandle(zTarget, zRbu, zState); |
| 204960 | 206559 | } |
| 204961 | 206560 | |
| 204962 | 206561 | /* |
| 204963 | 206562 | ** Open a handle to begin or resume an RBU VACUUM operation. |
| | @@ -207873,11 +209472,11 @@ |
| 207873 | 209472 | if( z==0 && (eType!=SQLITE_BLOB || n>0) ) return SQLITE_NOMEM; |
| 207874 | 209473 | nVarint = sessionVarintLen(n); |
| 207875 | 209474 | |
| 207876 | 209475 | if( aBuf ){ |
| 207877 | 209476 | sessionVarintPut(&aBuf[1], n); |
| 207878 | | - if( n ) memcpy(&aBuf[nVarint + 1], z, n); |
| 209477 | + if( n>0 ) memcpy(&aBuf[nVarint + 1], z, n); |
| 207879 | 209478 | } |
| 207880 | 209479 | |
| 207881 | 209480 | nByte = 1 + nVarint + n; |
| 207882 | 209481 | break; |
| 207883 | 209482 | } |
| | @@ -208478,20 +210077,36 @@ |
| 208478 | 210077 | "SELECT 2, 'stat', '', 0, '', 0" |
| 208479 | 210078 | ); |
| 208480 | 210079 | }else if( rc==SQLITE_ERROR ){ |
| 208481 | 210080 | zPragma = sqlite3_mprintf(""); |
| 208482 | 210081 | }else{ |
| 210082 | + *pazCol = 0; |
| 210083 | + *pabPK = 0; |
| 210084 | + *pnCol = 0; |
| 210085 | + if( pzTab ) *pzTab = 0; |
| 208483 | 210086 | return rc; |
| 208484 | 210087 | } |
| 208485 | 210088 | }else{ |
| 208486 | 210089 | zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis); |
| 208487 | 210090 | } |
| 208488 | | - if( !zPragma ) return SQLITE_NOMEM; |
| 210091 | + if( !zPragma ){ |
| 210092 | + *pazCol = 0; |
| 210093 | + *pabPK = 0; |
| 210094 | + *pnCol = 0; |
| 210095 | + if( pzTab ) *pzTab = 0; |
| 210096 | + return SQLITE_NOMEM; |
| 210097 | + } |
| 208489 | 210098 | |
| 208490 | 210099 | rc = sqlite3_prepare_v2(db, zPragma, -1, &pStmt, 0); |
| 208491 | 210100 | sqlite3_free(zPragma); |
| 208492 | | - if( rc!=SQLITE_OK ) return rc; |
| 210101 | + if( rc!=SQLITE_OK ){ |
| 210102 | + *pazCol = 0; |
| 210103 | + *pabPK = 0; |
| 210104 | + *pnCol = 0; |
| 210105 | + if( pzTab ) *pzTab = 0; |
| 210106 | + return rc; |
| 210107 | + } |
| 208493 | 210108 | |
| 208494 | 210109 | nByte = nThis + 1; |
| 208495 | 210110 | while( SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 208496 | 210111 | nByte += sqlite3_column_bytes(pStmt, 1); |
| 208497 | 210112 | nDbCol++; |
| | @@ -208905,11 +210520,15 @@ |
| 208905 | 210520 | if( pSession->xTableFilter==0 |
| 208906 | 210521 | || pSession->xTableFilter(pSession->pFilterCtx, zName) |
| 208907 | 210522 | ){ |
| 208908 | 210523 | rc = sqlite3session_attach(pSession, zName); |
| 208909 | 210524 | if( rc==SQLITE_OK ){ |
| 208910 | | - for(pRet=pSession->pTable; pRet->pNext; pRet=pRet->pNext); |
| 210525 | + pRet = pSession->pTable; |
| 210526 | + while( ALWAYS(pRet) && pRet->pNext ){ |
| 210527 | + pRet = pRet->pNext; |
| 210528 | + } |
| 210529 | + assert( pRet!=0 ); |
| 208911 | 210530 | assert( 0==sqlite3_strnicmp(pRet->zName, zName, nName+1) ); |
| 208912 | 210531 | } |
| 208913 | 210532 | } |
| 208914 | 210533 | } |
| 208915 | 210534 | |
| | @@ -209678,10 +211297,11 @@ |
| 209678 | 211297 | int bNoop = 1; /* Set to zero if any values are modified */ |
| 209679 | 211298 | int nRewind = pBuf->nBuf; /* Set to zero if any values are modified */ |
| 209680 | 211299 | int i; /* Used to iterate through columns */ |
| 209681 | 211300 | u8 *pCsr = p->aRecord; /* Used to iterate through old.* values */ |
| 209682 | 211301 | |
| 211302 | + assert( abPK!=0 ); |
| 209683 | 211303 | sessionAppendByte(pBuf, SQLITE_UPDATE, &rc); |
| 209684 | 211304 | sessionAppendByte(pBuf, p->bIndirect, &rc); |
| 209685 | 211305 | for(i=0; i<sqlite3_column_count(pStmt); i++){ |
| 209686 | 211306 | int bChanged = 0; |
| 209687 | 211307 | int nAdvance; |
| | @@ -209982,16 +211602,18 @@ |
| 209982 | 211602 | sqlite3 *db = pSession->db; /* Source database handle */ |
| 209983 | 211603 | SessionTable *pTab; /* Used to iterate through attached tables */ |
| 209984 | 211604 | SessionBuffer buf = {0,0,0}; /* Buffer in which to accumlate changeset */ |
| 209985 | 211605 | int rc; /* Return code */ |
| 209986 | 211606 | |
| 209987 | | - assert( xOutput==0 || (pnChangeset==0 && ppChangeset==0 ) ); |
| 211607 | + assert( xOutput==0 || (pnChangeset==0 && ppChangeset==0) ); |
| 211608 | + assert( xOutput!=0 || (pnChangeset!=0 && ppChangeset!=0) ); |
| 209988 | 211609 | |
| 209989 | 211610 | /* Zero the output variables in case an error occurs. If this session |
| 209990 | 211611 | ** object is already in the error state (sqlite3_session.rc != SQLITE_OK), |
| 209991 | 211612 | ** this call will be a no-op. */ |
| 209992 | 211613 | if( xOutput==0 ){ |
| 211614 | + assert( pnChangeset!=0 && ppChangeset!=0 ); |
| 209993 | 211615 | *pnChangeset = 0; |
| 209994 | 211616 | *ppChangeset = 0; |
| 209995 | 211617 | } |
| 209996 | 211618 | |
| 209997 | 211619 | if( pSession->rc ) return pSession->rc; |
| | @@ -210001,12 +211623,12 @@ |
| 210001 | 211623 | sqlite3_mutex_enter(sqlite3_db_mutex(db)); |
| 210002 | 211624 | |
| 210003 | 211625 | for(pTab=pSession->pTable; rc==SQLITE_OK && pTab; pTab=pTab->pNext){ |
| 210004 | 211626 | if( pTab->nEntry ){ |
| 210005 | 211627 | const char *zName = pTab->zName; |
| 210006 | | - int nCol; /* Number of columns in table */ |
| 210007 | | - u8 *abPK; /* Primary key array */ |
| 211628 | + int nCol = 0; /* Number of columns in table */ |
| 211629 | + u8 *abPK = 0; /* Primary key array */ |
| 210008 | 211630 | const char **azCol = 0; /* Table columns */ |
| 210009 | 211631 | int i; /* Used to iterate through hash buckets */ |
| 210010 | 211632 | sqlite3_stmt *pSel = 0; /* SELECT statement to query table pTab */ |
| 210011 | 211633 | int nRewind = buf.nBuf; /* Initial size of write buffer */ |
| 210012 | 211634 | int nNoop; /* Size of buffer after writing tbl header */ |
| | @@ -210040,10 +211662,11 @@ |
| 210040 | 211662 | sessionAppendByte(&buf, p->bIndirect, &rc); |
| 210041 | 211663 | for(iCol=0; iCol<nCol; iCol++){ |
| 210042 | 211664 | sessionAppendCol(&buf, pSel, iCol, &rc); |
| 210043 | 211665 | } |
| 210044 | 211666 | }else{ |
| 211667 | + assert( abPK!=0 ); /* Because sessionSelectStmt() returned ok */ |
| 210045 | 211668 | rc = sessionAppendUpdate(&buf, bPatchset, pSel, p, abPK); |
| 210046 | 211669 | } |
| 210047 | 211670 | }else if( p->op!=SQLITE_INSERT ){ |
| 210048 | 211671 | rc = sessionAppendDelete(&buf, bPatchset, p, nCol, abPK); |
| 210049 | 211672 | } |
| | @@ -210100,11 +211723,14 @@ |
| 210100 | 211723 | SQLITE_API int sqlite3session_changeset( |
| 210101 | 211724 | sqlite3_session *pSession, /* Session object */ |
| 210102 | 211725 | int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */ |
| 210103 | 211726 | void **ppChangeset /* OUT: Buffer containing changeset */ |
| 210104 | 211727 | ){ |
| 210105 | | - int rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset,ppChangeset); |
| 211728 | + int rc; |
| 211729 | + |
| 211730 | + if( pnChangeset==0 || ppChangeset==0 ) return SQLITE_MISUSE; |
| 211731 | + rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset,ppChangeset); |
| 210106 | 211732 | assert( rc || pnChangeset==0 |
| 210107 | 211733 | || pSession->bEnableSize==0 || *pnChangeset<=pSession->nMaxChangesetSize |
| 210108 | 211734 | ); |
| 210109 | 211735 | return rc; |
| 210110 | 211736 | } |
| | @@ -210115,10 +211741,11 @@ |
| 210115 | 211741 | SQLITE_API int sqlite3session_changeset_strm( |
| 210116 | 211742 | sqlite3_session *pSession, |
| 210117 | 211743 | int (*xOutput)(void *pOut, const void *pData, int nData), |
| 210118 | 211744 | void *pOut |
| 210119 | 211745 | ){ |
| 211746 | + if( xOutput==0 ) return SQLITE_MISUSE; |
| 210120 | 211747 | return sessionGenerateChangeset(pSession, 0, xOutput, pOut, 0, 0); |
| 210121 | 211748 | } |
| 210122 | 211749 | |
| 210123 | 211750 | /* |
| 210124 | 211751 | ** Streaming version of sqlite3session_patchset(). |
| | @@ -210126,10 +211753,11 @@ |
| 210126 | 211753 | SQLITE_API int sqlite3session_patchset_strm( |
| 210127 | 211754 | sqlite3_session *pSession, |
| 210128 | 211755 | int (*xOutput)(void *pOut, const void *pData, int nData), |
| 210129 | 211756 | void *pOut |
| 210130 | 211757 | ){ |
| 211758 | + if( xOutput==0 ) return SQLITE_MISUSE; |
| 210131 | 211759 | return sessionGenerateChangeset(pSession, 1, xOutput, pOut, 0, 0); |
| 210132 | 211760 | } |
| 210133 | 211761 | |
| 210134 | 211762 | /* |
| 210135 | 211763 | ** Obtain a patchset object containing all changes recorded by the |
| | @@ -210141,10 +211769,11 @@ |
| 210141 | 211769 | SQLITE_API int sqlite3session_patchset( |
| 210142 | 211770 | sqlite3_session *pSession, /* Session object */ |
| 210143 | 211771 | int *pnPatchset, /* OUT: Size of buffer at *ppChangeset */ |
| 210144 | 211772 | void **ppPatchset /* OUT: Buffer containing changeset */ |
| 210145 | 211773 | ){ |
| 211774 | + if( pnPatchset==0 || ppPatchset==0 ) return SQLITE_MISUSE; |
| 210146 | 211775 | return sessionGenerateChangeset(pSession, 1, 0, 0, pnPatchset, ppPatchset); |
| 210147 | 211776 | } |
| 210148 | 211777 | |
| 210149 | 211778 | /* |
| 210150 | 211779 | ** Enable or disable the session object passed as the first argument. |
| | @@ -211104,15 +212733,15 @@ |
| 211104 | 212733 | if( rc!=SQLITE_OK ) goto finished_invert; |
| 211105 | 212734 | } |
| 211106 | 212735 | } |
| 211107 | 212736 | |
| 211108 | 212737 | assert( rc==SQLITE_OK ); |
| 211109 | | - if( pnInverted ){ |
| 212738 | + if( pnInverted && ALWAYS(ppInverted) ){ |
| 211110 | 212739 | *pnInverted = sOut.nBuf; |
| 211111 | 212740 | *ppInverted = sOut.aBuf; |
| 211112 | 212741 | sOut.aBuf = 0; |
| 211113 | | - }else if( sOut.nBuf>0 ){ |
| 212742 | + }else if( sOut.nBuf>0 && ALWAYS(xOutput!=0) ){ |
| 211114 | 212743 | rc = xOutput(pOut, sOut.aBuf, sOut.nBuf); |
| 211115 | 212744 | } |
| 211116 | 212745 | |
| 211117 | 212746 | finished_invert: |
| 211118 | 212747 | sqlite3_free(sOut.aBuf); |
| | @@ -211564,11 +213193,11 @@ |
| 211564 | 213193 | ** in the code below. */ |
| 211565 | 213194 | assert( xValue==sqlite3changeset_old || xValue==sqlite3changeset_new ); |
| 211566 | 213195 | |
| 211567 | 213196 | for(i=0; rc==SQLITE_OK && i<nCol; i++){ |
| 211568 | 213197 | if( !abPK || abPK[i] ){ |
| 211569 | | - sqlite3_value *pVal; |
| 213198 | + sqlite3_value *pVal = 0; |
| 211570 | 213199 | (void)xValue(pIter, i, &pVal); |
| 211571 | 213200 | if( pVal==0 ){ |
| 211572 | 213201 | /* The value in the changeset was "undefined". This indicates a |
| 211573 | 213202 | ** corrupt changeset blob. */ |
| 211574 | 213203 | rc = SQLITE_CORRUPT_BKPT; |
| | @@ -212707,13 +214336,13 @@ |
| 212707 | 214336 | } |
| 212708 | 214337 | |
| 212709 | 214338 | if( rc==SQLITE_OK ){ |
| 212710 | 214339 | if( xOutput ){ |
| 212711 | 214340 | if( buf.nBuf>0 ) rc = xOutput(pOut, buf.aBuf, buf.nBuf); |
| 212712 | | - }else{ |
| 214341 | + }else if( ppOut ){ |
| 212713 | 214342 | *ppOut = buf.aBuf; |
| 212714 | | - *pnOut = buf.nBuf; |
| 214343 | + if( pnOut ) *pnOut = buf.nBuf; |
| 212715 | 214344 | buf.aBuf = 0; |
| 212716 | 214345 | } |
| 212717 | 214346 | } |
| 212718 | 214347 | sqlite3_free(buf.aBuf); |
| 212719 | 214348 | |
| | @@ -213109,11 +214738,11 @@ |
| 213109 | 214738 | if( rc==SQLITE_OK ){ |
| 213110 | 214739 | if( xOutput ){ |
| 213111 | 214740 | if( sOut.nBuf>0 ){ |
| 213112 | 214741 | rc = xOutput(pOut, sOut.aBuf, sOut.nBuf); |
| 213113 | 214742 | } |
| 213114 | | - }else{ |
| 214743 | + }else if( ppOut ){ |
| 213115 | 214744 | *ppOut = (void*)sOut.aBuf; |
| 213116 | 214745 | *pnOut = sOut.nBuf; |
| 213117 | 214746 | sOut.aBuf = 0; |
| 213118 | 214747 | } |
| 213119 | 214748 | } |
| | @@ -213852,12 +215481,24 @@ |
| 213852 | 215481 | #ifndef ArraySize |
| 213853 | 215482 | # define ArraySize(x) ((int)(sizeof(x) / sizeof(x[0]))) |
| 213854 | 215483 | #endif |
| 213855 | 215484 | |
| 213856 | 215485 | #define testcase(x) |
| 213857 | | -#define ALWAYS(x) 1 |
| 213858 | | -#define NEVER(x) 0 |
| 215486 | + |
| 215487 | +#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST) |
| 215488 | +# define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1 |
| 215489 | +#endif |
| 215490 | +#if defined(SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS) |
| 215491 | +# define ALWAYS(X) (1) |
| 215492 | +# define NEVER(X) (0) |
| 215493 | +#elif !defined(NDEBUG) |
| 215494 | +# define ALWAYS(X) ((X)?1:(assert(0),0)) |
| 215495 | +# define NEVER(X) ((X)?(assert(0),1):0) |
| 215496 | +#else |
| 215497 | +# define ALWAYS(X) (X) |
| 215498 | +# define NEVER(X) (X) |
| 215499 | +#endif |
| 213859 | 215500 | |
| 213860 | 215501 | #define MIN(x,y) (((x) < (y)) ? (x) : (y)) |
| 213861 | 215502 | #define MAX(x,y) (((x) > (y)) ? (x) : (y)) |
| 213862 | 215503 | |
| 213863 | 215504 | /* |
| | @@ -213913,11 +215554,11 @@ |
| 213913 | 215554 | |
| 213914 | 215555 | /* |
| 213915 | 215556 | ** A version of memcmp() that does not cause asan errors if one of the pointer |
| 213916 | 215557 | ** parameters is NULL and the number of bytes to compare is zero. |
| 213917 | 215558 | */ |
| 213918 | | -#define fts5Memcmp(s1, s2, n) ((n)==0 ? 0 : memcmp((s1), (s2), (n))) |
| 215559 | +#define fts5Memcmp(s1, s2, n) ((n)<=0 ? 0 : memcmp((s1), (s2), (n))) |
| 213919 | 215560 | |
| 213920 | 215561 | /* Mark a function parameter as unused, to suppress nuisance compiler |
| 213921 | 215562 | ** warnings. */ |
| 213922 | 215563 | #ifndef UNUSED_PARAM |
| 213923 | 215564 | # define UNUSED_PARAM(X) (void)(X) |
| | @@ -215032,13 +216673,13 @@ |
| 215032 | 216673 | fts5yyStackEntry *fts5yystackEnd; /* Last entry in the stack */ |
| 215033 | 216674 | #endif |
| 215034 | 216675 | }; |
| 215035 | 216676 | typedef struct fts5yyParser fts5yyParser; |
| 215036 | 216677 | |
| 215037 | | -#ifndef NDEBUG |
| 215038 | | -/* #include <stdio.h> */ |
| 215039 | 216678 | /* #include <assert.h> */ |
| 216679 | +#ifndef NDEBUG |
| 216680 | +/* #include <stdio.h> */ |
| 215040 | 216681 | static FILE *fts5yyTraceFILE = 0; |
| 215041 | 216682 | static char *fts5yyTracePrompt = 0; |
| 215042 | 216683 | #endif /* NDEBUG */ |
| 215043 | 216684 | |
| 215044 | 216685 | #ifndef NDEBUG |
| | @@ -215971,12 +217612,12 @@ |
| 215971 | 217612 | assert( fts5yypParser->fts5yytos>=fts5yypParser->fts5yystack ); |
| 215972 | 217613 | assert( fts5yyact==fts5yypParser->fts5yytos->stateno ); |
| 215973 | 217614 | fts5yyact = fts5yy_find_shift_action((fts5YYCODETYPE)fts5yymajor,fts5yyact); |
| 215974 | 217615 | if( fts5yyact >= fts5YY_MIN_REDUCE ){ |
| 215975 | 217616 | unsigned int fts5yyruleno = fts5yyact - fts5YY_MIN_REDUCE; /* Reduce by this rule */ |
| 215976 | | - assert( fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) ); |
| 215977 | 217617 | #ifndef NDEBUG |
| 217618 | + assert( fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) ); |
| 215978 | 217619 | if( fts5yyTraceFILE ){ |
| 215979 | 217620 | int fts5yysize = fts5yyRuleInfoNRhs[fts5yyruleno]; |
| 215980 | 217621 | if( fts5yysize ){ |
| 215981 | 217622 | fprintf(fts5yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", |
| 215982 | 217623 | fts5yyTracePrompt, |
| | @@ -216939,11 +218580,10 @@ |
| 216939 | 218580 | int *pRc, |
| 216940 | 218581 | Fts5Buffer *pBuf, |
| 216941 | 218582 | u32 nData, |
| 216942 | 218583 | const u8 *pData |
| 216943 | 218584 | ){ |
| 216944 | | - assert_nc( *pRc || nData>=0 ); |
| 216945 | 218585 | if( nData ){ |
| 216946 | 218586 | if( fts5BufferGrow(pRc, pBuf, nData) ) return; |
| 216947 | 218587 | memcpy(&pBuf->p[pBuf->n], pData, nData); |
| 216948 | 218588 | pBuf->n += nData; |
| 216949 | 218589 | } |
| | @@ -217051,11 +218691,10 @@ |
| 217051 | 218691 | return 1; |
| 217052 | 218692 | }else{ |
| 217053 | 218693 | i64 iOff = *piOff; |
| 217054 | 218694 | u32 iVal; |
| 217055 | 218695 | fts5FastGetVarint32(a, i, iVal); |
| 217056 | | - assert( iVal>=0 ); |
| 217057 | 218696 | if( iVal<=1 ){ |
| 217058 | 218697 | if( iVal==0 ){ |
| 217059 | 218698 | *pi = i; |
| 217060 | 218699 | return 0; |
| 217061 | 218700 | } |
| | @@ -217846,10 +219485,11 @@ |
| 217846 | 219485 | |
| 217847 | 219486 | z = fts5ConfigGobbleWord(&rc, zOrig, &zOne, &bMustBeCol); |
| 217848 | 219487 | z = fts5ConfigSkipWhitespace(z); |
| 217849 | 219488 | if( z && *z=='=' ){ |
| 217850 | 219489 | bOption = 1; |
| 219490 | + assert( zOne!=0 ); |
| 217851 | 219491 | z++; |
| 217852 | 219492 | if( bMustBeCol ) z = 0; |
| 217853 | 219493 | } |
| 217854 | 219494 | z = fts5ConfigSkipWhitespace(z); |
| 217855 | 219495 | if( z && z[0] ){ |
| | @@ -217862,11 +219502,15 @@ |
| 217862 | 219502 | if( z==0 ){ |
| 217863 | 219503 | *pzErr = sqlite3_mprintf("parse error in \"%s\"", zOrig); |
| 217864 | 219504 | rc = SQLITE_ERROR; |
| 217865 | 219505 | }else{ |
| 217866 | 219506 | if( bOption ){ |
| 217867 | | - rc = fts5ConfigParseSpecial(pGlobal, pRet, zOne, zTwo?zTwo:"", pzErr); |
| 219507 | + rc = fts5ConfigParseSpecial(pGlobal, pRet, |
| 219508 | + ALWAYS(zOne)?zOne:"", |
| 219509 | + zTwo?zTwo:"", |
| 219510 | + pzErr |
| 219511 | + ); |
| 217868 | 219512 | }else{ |
| 217869 | 219513 | rc = fts5ConfigParseColumn(pRet, zOne, zTwo, pzErr); |
| 217870 | 219514 | zOne = 0; |
| 217871 | 219515 | } |
| 217872 | 219516 | } |
| | @@ -218679,10 +220323,11 @@ |
| 218679 | 220323 | static i64 fts5ExprSynonymRowid(Fts5ExprTerm *pTerm, int bDesc, int *pbEof){ |
| 218680 | 220324 | i64 iRet = 0; |
| 218681 | 220325 | int bRetValid = 0; |
| 218682 | 220326 | Fts5ExprTerm *p; |
| 218683 | 220327 | |
| 220328 | + assert( pTerm ); |
| 218684 | 220329 | assert( pTerm->pSynonym ); |
| 218685 | 220330 | assert( bDesc==0 || bDesc==1 ); |
| 218686 | 220331 | for(p=pTerm; p; p=p->pSynonym){ |
| 218687 | 220332 | if( 0==sqlite3Fts5IterEof(p->pIter) ){ |
| 218688 | 220333 | i64 iRowid = p->pIter->iRowid; |
| | @@ -220119,11 +221764,11 @@ |
| 220119 | 221764 | /* This happens when parsing a token or quoted phrase that contains |
| 220120 | 221765 | ** no token characters at all. (e.g ... MATCH '""'). */ |
| 220121 | 221766 | sCtx.pPhrase = sqlite3Fts5MallocZero(&rc, sizeof(Fts5ExprPhrase)); |
| 220122 | 221767 | } |
| 220123 | 221768 | |
| 220124 | | - if( rc==SQLITE_OK ){ |
| 221769 | + if( rc==SQLITE_OK && ALWAYS(sCtx.pPhrase) ){ |
| 220125 | 221770 | /* All the allocations succeeded. Put the expression object together. */ |
| 220126 | 221771 | pNew->pIndex = pExpr->pIndex; |
| 220127 | 221772 | pNew->pConfig = pExpr->pConfig; |
| 220128 | 221773 | pNew->nPhrase = 1; |
| 220129 | 221774 | pNew->apExprPhrase[0] = sCtx.pPhrase; |
| | @@ -221100,20 +222745,29 @@ |
| 221100 | 222745 | Fts5PoslistWriter writer; |
| 221101 | 222746 | int bOk; /* True if ok to populate */ |
| 221102 | 222747 | int bMiss; |
| 221103 | 222748 | }; |
| 221104 | 222749 | |
| 222750 | +/* |
| 222751 | +** Clear the position lists associated with all phrases in the expression |
| 222752 | +** passed as the first argument. Argument bLive is true if the expression |
| 222753 | +** might be pointing to a real entry, otherwise it has just been reset. |
| 222754 | +** |
| 222755 | +** At present this function is only used for detail=col and detail=none |
| 222756 | +** fts5 tables. This implies that all phrases must be at most 1 token |
| 222757 | +** in size, as phrase matches are not supported without detail=full. |
| 222758 | +*/ |
| 221105 | 222759 | static Fts5PoslistPopulator *sqlite3Fts5ExprClearPoslists(Fts5Expr *pExpr, int bLive){ |
| 221106 | 222760 | Fts5PoslistPopulator *pRet; |
| 221107 | 222761 | pRet = sqlite3_malloc64(sizeof(Fts5PoslistPopulator)*pExpr->nPhrase); |
| 221108 | 222762 | if( pRet ){ |
| 221109 | 222763 | int i; |
| 221110 | 222764 | memset(pRet, 0, sizeof(Fts5PoslistPopulator)*pExpr->nPhrase); |
| 221111 | 222765 | for(i=0; i<pExpr->nPhrase; i++){ |
| 221112 | 222766 | Fts5Buffer *pBuf = &pExpr->apExprPhrase[i]->poslist; |
| 221113 | 222767 | Fts5ExprNode *pNode = pExpr->apExprPhrase[i]->pNode; |
| 221114 | | - assert( pExpr->apExprPhrase[i]->nTerm==1 ); |
| 222768 | + assert( pExpr->apExprPhrase[i]->nTerm<=1 ); |
| 221115 | 222769 | if( bLive && |
| 221116 | 222770 | (pBuf->n==0 || pNode->iRowid!=pExpr->pRoot->iRowid || pNode->bEof) |
| 221117 | 222771 | ){ |
| 221118 | 222772 | pRet[i].bMiss = 1; |
| 221119 | 222773 | }else{ |
| | @@ -221660,11 +223314,11 @@ |
| 221660 | 223314 | if( iCol>=0 ){ |
| 221661 | 223315 | if( pHash->eDetail==FTS5_DETAIL_NONE ){ |
| 221662 | 223316 | p->bContent = 1; |
| 221663 | 223317 | }else{ |
| 221664 | 223318 | /* Append a new column value, if necessary */ |
| 221665 | | - assert( iCol>=p->iCol ); |
| 223319 | + assert_nc( iCol>=p->iCol ); |
| 221666 | 223320 | if( iCol!=p->iCol ){ |
| 221667 | 223321 | if( pHash->eDetail==FTS5_DETAIL_FULL ){ |
| 221668 | 223322 | pPtr[p->nData++] = 0x01; |
| 221669 | 223323 | p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iCol); |
| 221670 | 223324 | p->iCol = (i16)iCol; |
| | @@ -222465,12 +224119,15 @@ |
| 222465 | 224119 | ** +ve if pRight is smaller than pLeft. In other words: |
| 222466 | 224120 | ** |
| 222467 | 224121 | ** res = *pLeft - *pRight |
| 222468 | 224122 | */ |
| 222469 | 224123 | static int fts5BufferCompare(Fts5Buffer *pLeft, Fts5Buffer *pRight){ |
| 222470 | | - int nCmp = MIN(pLeft->n, pRight->n); |
| 222471 | | - int res = fts5Memcmp(pLeft->p, pRight->p, nCmp); |
| 224124 | + int nCmp, res; |
| 224125 | + nCmp = MIN(pLeft->n, pRight->n); |
| 224126 | + assert( nCmp<=0 || pLeft->p!=0 ); |
| 224127 | + assert( nCmp<=0 || pRight->p!=0 ); |
| 224128 | + res = fts5Memcmp(pLeft->p, pRight->p, nCmp); |
| 222472 | 224129 | return (res==0 ? (pLeft->n - pRight->n) : res); |
| 222473 | 224130 | } |
| 222474 | 224131 | |
| 222475 | 224132 | static int fts5LeafFirstTermOff(Fts5Data *pLeaf){ |
| 222476 | 224133 | int ret; |
| | @@ -222712,11 +224369,11 @@ |
| 222712 | 224369 | ** an error occurs, (*pRc) is set to an SQLite error code before returning. |
| 222713 | 224370 | */ |
| 222714 | 224371 | static void fts5StructureMakeWritable(int *pRc, Fts5Structure **pp){ |
| 222715 | 224372 | Fts5Structure *p = *pp; |
| 222716 | 224373 | if( *pRc==SQLITE_OK && p->nRef>1 ){ |
| 222717 | | - int nByte = sizeof(Fts5Structure)+(p->nLevel-1)*sizeof(Fts5StructureLevel); |
| 224374 | + i64 nByte = sizeof(Fts5Structure)+(p->nLevel-1)*sizeof(Fts5StructureLevel); |
| 222718 | 224375 | Fts5Structure *pNew; |
| 222719 | 224376 | pNew = (Fts5Structure*)sqlite3Fts5MallocZero(pRc, nByte); |
| 222720 | 224377 | if( pNew ){ |
| 222721 | 224378 | int i; |
| 222722 | 224379 | memcpy(pNew, p, nByte); |
| | @@ -223638,10 +225295,11 @@ |
| 223638 | 225295 | fts5SegIterNextPage(p, pIter); |
| 223639 | 225296 | } |
| 223640 | 225297 | |
| 223641 | 225298 | if( p->rc==SQLITE_OK ){ |
| 223642 | 225299 | pIter->iLeafOffset = 4; |
| 225300 | + assert( pIter->pLeaf!=0 ); |
| 223643 | 225301 | assert_nc( pIter->pLeaf->nn>4 ); |
| 223644 | 225302 | assert_nc( fts5LeafFirstTermOff(pIter->pLeaf)==4 ); |
| 223645 | 225303 | pIter->iPgidxOff = pIter->pLeaf->szLeaf+1; |
| 223646 | 225304 | fts5SegIterLoadTerm(p, pIter, 0); |
| 223647 | 225305 | fts5SegIterLoadNPos(p, pIter); |
| | @@ -223740,12 +225398,16 @@ |
| 223740 | 225398 | } |
| 223741 | 225399 | }else{ |
| 223742 | 225400 | int iRowidOff; |
| 223743 | 225401 | iRowidOff = fts5LeafFirstRowidOff(pNew); |
| 223744 | 225402 | if( iRowidOff ){ |
| 223745 | | - pIter->pLeaf = pNew; |
| 223746 | | - pIter->iLeafOffset = iRowidOff; |
| 225403 | + if( iRowidOff>=pNew->szLeaf ){ |
| 225404 | + p->rc = FTS5_CORRUPT; |
| 225405 | + }else{ |
| 225406 | + pIter->pLeaf = pNew; |
| 225407 | + pIter->iLeafOffset = iRowidOff; |
| 225408 | + } |
| 223747 | 225409 | } |
| 223748 | 225410 | } |
| 223749 | 225411 | |
| 223750 | 225412 | if( pIter->pLeaf ){ |
| 223751 | 225413 | u8 *a = &pIter->pLeaf->p[pIter->iLeafOffset]; |
| | @@ -224142,25 +225804,24 @@ |
| 224142 | 225804 | Fts5Index *p, /* Leave any error code here */ |
| 224143 | 225805 | int bGe, /* True for a >= search */ |
| 224144 | 225806 | Fts5SegIter *pIter, /* Iterator to seek */ |
| 224145 | 225807 | const u8 *pTerm, int nTerm /* Term to search for */ |
| 224146 | 225808 | ){ |
| 224147 | | - int iOff; |
| 225809 | + u32 iOff; |
| 224148 | 225810 | const u8 *a = pIter->pLeaf->p; |
| 224149 | | - int szLeaf = pIter->pLeaf->szLeaf; |
| 224150 | | - int n = pIter->pLeaf->nn; |
| 225811 | + u32 n = (u32)pIter->pLeaf->nn; |
| 224151 | 225812 | |
| 224152 | 225813 | u32 nMatch = 0; |
| 224153 | 225814 | u32 nKeep = 0; |
| 224154 | 225815 | u32 nNew = 0; |
| 224155 | 225816 | u32 iTermOff; |
| 224156 | | - int iPgidx; /* Current offset in pgidx */ |
| 225817 | + u32 iPgidx; /* Current offset in pgidx */ |
| 224157 | 225818 | int bEndOfPage = 0; |
| 224158 | 225819 | |
| 224159 | 225820 | assert( p->rc==SQLITE_OK ); |
| 224160 | 225821 | |
| 224161 | | - iPgidx = szLeaf; |
| 225822 | + iPgidx = (u32)pIter->pLeaf->szLeaf; |
| 224162 | 225823 | iPgidx += fts5GetVarint32(&a[iPgidx], iTermOff); |
| 224163 | 225824 | iOff = iTermOff; |
| 224164 | 225825 | if( iOff>n ){ |
| 224165 | 225826 | p->rc = FTS5_CORRUPT; |
| 224166 | 225827 | return; |
| | @@ -224222,19 +225883,19 @@ |
| 224222 | 225883 | do { |
| 224223 | 225884 | fts5SegIterNextPage(p, pIter); |
| 224224 | 225885 | if( pIter->pLeaf==0 ) return; |
| 224225 | 225886 | a = pIter->pLeaf->p; |
| 224226 | 225887 | if( fts5LeafIsTermless(pIter->pLeaf)==0 ){ |
| 224227 | | - iPgidx = pIter->pLeaf->szLeaf; |
| 225888 | + iPgidx = (u32)pIter->pLeaf->szLeaf; |
| 224228 | 225889 | iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff); |
| 224229 | | - if( iOff<4 || iOff>=pIter->pLeaf->szLeaf ){ |
| 225890 | + if( iOff<4 || (i64)iOff>=pIter->pLeaf->szLeaf ){ |
| 224230 | 225891 | p->rc = FTS5_CORRUPT; |
| 224231 | 225892 | return; |
| 224232 | 225893 | }else{ |
| 224233 | 225894 | nKeep = 0; |
| 224234 | 225895 | iTermOff = iOff; |
| 224235 | | - n = pIter->pLeaf->nn; |
| 225896 | + n = (u32)pIter->pLeaf->nn; |
| 224236 | 225897 | iOff += fts5GetVarint32(&a[iOff], nNew); |
| 224237 | 225898 | break; |
| 224238 | 225899 | } |
| 224239 | 225900 | } |
| 224240 | 225901 | }while( 1 ); |
| | @@ -224598,11 +226259,11 @@ |
| 224598 | 226259 | pIter->pNextLeaf = 0; |
| 224599 | 226260 | pIter->iLeafPgno = iLeafPgno-1; |
| 224600 | 226261 | fts5SegIterNextPage(p, pIter); |
| 224601 | 226262 | assert( p->rc!=SQLITE_OK || pIter->iLeafPgno==iLeafPgno ); |
| 224602 | 226263 | |
| 224603 | | - if( p->rc==SQLITE_OK ){ |
| 226264 | + if( p->rc==SQLITE_OK && ALWAYS(pIter->pLeaf!=0) ){ |
| 224604 | 226265 | int iOff; |
| 224605 | 226266 | u8 *a = pIter->pLeaf->p; |
| 224606 | 226267 | int n = pIter->pLeaf->szLeaf; |
| 224607 | 226268 | |
| 224608 | 226269 | iOff = fts5LeafFirstRowidOff(pIter->pLeaf); |
| | @@ -225030,11 +226691,15 @@ |
| 225030 | 226691 | Fts5Index *p, |
| 225031 | 226692 | Fts5SegIter *pSeg, |
| 225032 | 226693 | Fts5Colset *pColset, |
| 225033 | 226694 | Fts5Buffer *pBuf |
| 225034 | 226695 | ){ |
| 226696 | + assert( pBuf!=0 ); |
| 226697 | + assert( pSeg!=0 ); |
| 225035 | 226698 | if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos+FTS5_DATA_ZERO_PADDING) ){ |
| 226699 | + assert( pBuf->p!=0 ); |
| 226700 | + assert( pBuf->nSpace >= pBuf->n+pSeg->nPos+FTS5_DATA_ZERO_PADDING ); |
| 225036 | 226701 | memset(&pBuf->p[pBuf->n+pSeg->nPos], 0, FTS5_DATA_ZERO_PADDING); |
| 225037 | 226702 | if( pColset==0 ){ |
| 225038 | 226703 | fts5ChunkIterate(p, pSeg, (void*)pBuf, fts5PoslistCallback); |
| 225039 | 226704 | }else{ |
| 225040 | 226705 | if( p->pConfig->eDetail==FTS5_DETAIL_FULL ){ |
| | @@ -225254,10 +226919,11 @@ |
| 225254 | 226919 | pIter->base.nData = pIter->poslist.n; |
| 225255 | 226920 | } |
| 225256 | 226921 | } |
| 225257 | 226922 | |
| 225258 | 226923 | static void fts5IterSetOutputCb(int *pRc, Fts5Iter *pIter){ |
| 226924 | + assert( pIter!=0 || (*pRc)!=SQLITE_OK ); |
| 225259 | 226925 | if( *pRc==SQLITE_OK ){ |
| 225260 | 226926 | Fts5Config *pConfig = pIter->pIndex->pConfig; |
| 225261 | 226927 | if( pConfig->eDetail==FTS5_DETAIL_NONE ){ |
| 225262 | 226928 | pIter->xSetOutputs = fts5IterSetOutputs_None; |
| 225263 | 226929 | } |
| | @@ -225325,11 +226991,14 @@ |
| 225325 | 226991 | }else{ |
| 225326 | 226992 | nSeg = MIN(pStruct->aLevel[iLevel].nSeg, nSegment); |
| 225327 | 226993 | } |
| 225328 | 226994 | } |
| 225329 | 226995 | *ppOut = pNew = fts5MultiIterAlloc(p, nSeg); |
| 225330 | | - if( pNew==0 ) return; |
| 226996 | + if( pNew==0 ){ |
| 226997 | + assert( p->rc!=SQLITE_OK ); |
| 226998 | + goto fts5MultiIterNew_post_check; |
| 226999 | + } |
| 225331 | 227000 | pNew->bRev = (0!=(flags & FTS5INDEX_QUERY_DESC)); |
| 225332 | 227001 | pNew->bSkipEmpty = (0!=(flags & FTS5INDEX_QUERY_SKIPEMPTY)); |
| 225333 | 227002 | pNew->pColset = pColset; |
| 225334 | 227003 | if( (flags & FTS5INDEX_QUERY_NOOUTPUT)==0 ){ |
| 225335 | 227004 | fts5IterSetOutputCb(&p->rc, pNew); |
| | @@ -225389,10 +227058,14 @@ |
| 225389 | 227058 | |
| 225390 | 227059 | }else{ |
| 225391 | 227060 | fts5MultiIterFree(pNew); |
| 225392 | 227061 | *ppOut = 0; |
| 225393 | 227062 | } |
| 227063 | + |
| 227064 | +fts5MultiIterNew_post_check: |
| 227065 | + assert( (*ppOut)!=0 || p->rc!=SQLITE_OK ); |
| 227066 | + return; |
| 225394 | 227067 | } |
| 225395 | 227068 | |
| 225396 | 227069 | /* |
| 225397 | 227070 | ** Create an Fts5Iter that iterates through the doclist provided |
| 225398 | 227071 | ** as the second argument. |
| | @@ -225436,11 +227109,12 @@ |
| 225436 | 227109 | /* |
| 225437 | 227110 | ** Return true if the iterator is at EOF or if an error has occurred. |
| 225438 | 227111 | ** False otherwise. |
| 225439 | 227112 | */ |
| 225440 | 227113 | static int fts5MultiIterEof(Fts5Index *p, Fts5Iter *pIter){ |
| 225441 | | - assert( p->rc |
| 227114 | + assert( pIter!=0 || p->rc!=SQLITE_OK ); |
| 227115 | + assert( p->rc!=SQLITE_OK |
| 225442 | 227116 | || (pIter->aSeg[ pIter->aFirst[1].iFirst ].pLeaf==0)==pIter->base.bEof |
| 225443 | 227117 | ); |
| 225444 | 227118 | return (p->rc || pIter->base.bEof); |
| 225445 | 227119 | } |
| 225446 | 227120 | |
| | @@ -226240,10 +227914,11 @@ |
| 226240 | 227914 | |
| 226241 | 227915 | /* Flush the last leaf page to disk. Set the output segment b-tree height |
| 226242 | 227916 | ** and last leaf page number at the same time. */ |
| 226243 | 227917 | fts5WriteFinish(p, &writer, &pSeg->pgnoLast); |
| 226244 | 227918 | |
| 227919 | + assert( pIter!=0 || p->rc!=SQLITE_OK ); |
| 226245 | 227920 | if( fts5MultiIterEof(p, pIter) ){ |
| 226246 | 227921 | int i; |
| 226247 | 227922 | |
| 226248 | 227923 | /* Remove the redundant segments from the %_data table */ |
| 226249 | 227924 | for(i=0; i<nInput; i++){ |
| | @@ -226340,11 +228015,11 @@ |
| 226340 | 228015 | static void fts5IndexAutomerge( |
| 226341 | 228016 | Fts5Index *p, /* FTS5 backend object */ |
| 226342 | 228017 | Fts5Structure **ppStruct, /* IN/OUT: Current structure of index */ |
| 226343 | 228018 | int nLeaf /* Number of output leaves just written */ |
| 226344 | 228019 | ){ |
| 226345 | | - if( p->rc==SQLITE_OK && p->pConfig->nAutomerge>0 ){ |
| 228020 | + if( p->rc==SQLITE_OK && p->pConfig->nAutomerge>0 && ALWAYS((*ppStruct)!=0) ){ |
| 226346 | 228021 | Fts5Structure *pStruct = *ppStruct; |
| 226347 | 228022 | u64 nWrite; /* Initial value of write-counter */ |
| 226348 | 228023 | int nWork; /* Number of work-quanta to perform */ |
| 226349 | 228024 | int nRem; /* Number of leaf pages left to write */ |
| 226350 | 228025 | |
| | @@ -227450,15 +229125,19 @@ |
| 227450 | 229125 | } |
| 227451 | 229126 | }else{ |
| 227452 | 229127 | /* Scan multiple terms in the main index */ |
| 227453 | 229128 | int bDesc = (flags & FTS5INDEX_QUERY_DESC)!=0; |
| 227454 | 229129 | fts5SetupPrefixIter(p, bDesc, iPrefixIdx, buf.p, nToken+1, pColset,&pRet); |
| 227455 | | - assert( p->rc!=SQLITE_OK || pRet->pColset==0 ); |
| 227456 | | - fts5IterSetOutputCb(&p->rc, pRet); |
| 227457 | | - if( p->rc==SQLITE_OK ){ |
| 227458 | | - Fts5SegIter *pSeg = &pRet->aSeg[pRet->aFirst[1].iFirst]; |
| 227459 | | - if( pSeg->pLeaf ) pRet->xSetOutputs(pRet, pSeg); |
| 229130 | + if( pRet==0 ){ |
| 229131 | + assert( p->rc!=SQLITE_OK ); |
| 229132 | + }else{ |
| 229133 | + assert( pRet->pColset==0 ); |
| 229134 | + fts5IterSetOutputCb(&p->rc, pRet); |
| 229135 | + if( p->rc==SQLITE_OK ){ |
| 229136 | + Fts5SegIter *pSeg = &pRet->aSeg[pRet->aFirst[1].iFirst]; |
| 229137 | + if( pSeg->pLeaf ) pRet->xSetOutputs(pRet, pSeg); |
| 229138 | + } |
| 227460 | 229139 | } |
| 227461 | 229140 | } |
| 227462 | 229141 | |
| 227463 | 229142 | if( p->rc ){ |
| 227464 | 229143 | sqlite3Fts5IterClose((Fts5IndexIter*)pRet); |
| | @@ -227702,11 +229381,11 @@ |
| 227702 | 229381 | int eDetail = p->pConfig->eDetail; |
| 227703 | 229382 | u64 cksum = *pCksum; |
| 227704 | 229383 | Fts5IndexIter *pIter = 0; |
| 227705 | 229384 | int rc = sqlite3Fts5IndexQuery(p, z, n, flags, 0, &pIter); |
| 227706 | 229385 | |
| 227707 | | - while( rc==SQLITE_OK && 0==sqlite3Fts5IterEof(pIter) ){ |
| 229386 | + while( rc==SQLITE_OK && ALWAYS(pIter!=0) && 0==sqlite3Fts5IterEof(pIter) ){ |
| 227708 | 229387 | i64 rowid = pIter->iRowid; |
| 227709 | 229388 | |
| 227710 | 229389 | if( eDetail==FTS5_DETAIL_NONE ){ |
| 227711 | 229390 | cksum ^= sqlite3Fts5IndexEntryCksum(rowid, 0, 0, iIdx, z, n); |
| 227712 | 229391 | }else{ |
| | @@ -228067,10 +229746,11 @@ |
| 228067 | 229746 | int eDetail = p->pConfig->eDetail; |
| 228068 | 229747 | u64 cksum2 = 0; /* Checksum based on contents of indexes */ |
| 228069 | 229748 | Fts5Buffer poslist = {0,0,0}; /* Buffer used to hold a poslist */ |
| 228070 | 229749 | Fts5Iter *pIter; /* Used to iterate through entire index */ |
| 228071 | 229750 | Fts5Structure *pStruct; /* Index structure */ |
| 229751 | + int iLvl, iSeg; |
| 228072 | 229752 | |
| 228073 | 229753 | #ifdef SQLITE_DEBUG |
| 228074 | 229754 | /* Used by extra internal tests only run if NDEBUG is not defined */ |
| 228075 | 229755 | u64 cksum3 = 0; /* Checksum based on contents of indexes */ |
| 228076 | 229756 | Fts5Buffer term = {0,0,0}; /* Buffer used to hold most recent term */ |
| | @@ -228077,19 +229757,20 @@ |
| 228077 | 229757 | #endif |
| 228078 | 229758 | const int flags = FTS5INDEX_QUERY_NOOUTPUT; |
| 228079 | 229759 | |
| 228080 | 229760 | /* Load the FTS index structure */ |
| 228081 | 229761 | pStruct = fts5StructureRead(p); |
| 229762 | + if( pStruct==0 ){ |
| 229763 | + assert( p->rc!=SQLITE_OK ); |
| 229764 | + return fts5IndexReturn(p); |
| 229765 | + } |
| 228082 | 229766 | |
| 228083 | 229767 | /* Check that the internal nodes of each segment match the leaves */ |
| 228084 | | - if( pStruct ){ |
| 228085 | | - int iLvl, iSeg; |
| 228086 | | - for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){ |
| 228087 | | - for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){ |
| 228088 | | - Fts5StructureSegment *pSeg = &pStruct->aLevel[iLvl].aSeg[iSeg]; |
| 228089 | | - fts5IndexIntegrityCheckSegment(p, pSeg); |
| 228090 | | - } |
| 229768 | + for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){ |
| 229769 | + for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){ |
| 229770 | + Fts5StructureSegment *pSeg = &pStruct->aLevel[iLvl].aSeg[iSeg]; |
| 229771 | + fts5IndexIntegrityCheckSegment(p, pSeg); |
| 228091 | 229772 | } |
| 228092 | 229773 | } |
| 228093 | 229774 | |
| 228094 | 229775 | /* The cksum argument passed to this function is a checksum calculated |
| 228095 | 229776 | ** based on all expected entries in the FTS index (including prefix index |
| | @@ -230032,11 +231713,12 @@ |
| 230032 | 231713 | pCsr->ePlan = (pRowidEq ? FTS5_PLAN_ROWID : FTS5_PLAN_SCAN); |
| 230033 | 231714 | rc = sqlite3Fts5StorageStmt( |
| 230034 | 231715 | pTab->pStorage, fts5StmtType(pCsr), &pCsr->pStmt, &pTab->p.base.zErrMsg |
| 230035 | 231716 | ); |
| 230036 | 231717 | if( rc==SQLITE_OK ){ |
| 230037 | | - if( pCsr->ePlan==FTS5_PLAN_ROWID ){ |
| 231718 | + if( pRowidEq!=0 ){ |
| 231719 | + assert( pCsr->ePlan==FTS5_PLAN_ROWID ); |
| 230038 | 231720 | sqlite3_bind_value(pCsr->pStmt, 1, pRowidEq); |
| 230039 | 231721 | }else{ |
| 230040 | 231722 | sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iFirstRowid); |
| 230041 | 231723 | sqlite3_bind_int64(pCsr->pStmt, 2, pCsr->iLastRowid); |
| 230042 | 231724 | } |
| | @@ -231450,11 +233132,11 @@ |
| 231450 | 233132 | int nArg, /* Number of args */ |
| 231451 | 233133 | sqlite3_value **apUnused /* Function arguments */ |
| 231452 | 233134 | ){ |
| 231453 | 233135 | assert( nArg==0 ); |
| 231454 | 233136 | UNUSED_PARAM2(nArg, apUnused); |
| 231455 | | - sqlite3_result_text(pCtx, "fts5: 2021-10-04 11:10:15 8b24c177061c38361588f419eda9b7943b72a0c6b2855b6f39272451b8a1b813", -1, SQLITE_TRANSIENT); |
| 233137 | + sqlite3_result_text(pCtx, "fts5: 2021-12-09 20:06:18 633bfeeea2bccdd44126acf3f61ecca163c9d933bdc787a2c18a697dc9406882", -1, SQLITE_TRANSIENT); |
| 231456 | 233138 | } |
| 231457 | 233139 | |
| 231458 | 233140 | /* |
| 231459 | 233141 | ** Return true if zName is the extension on one of the shadow tables used |
| 231460 | 233142 | ** by this module. |
| | @@ -232001,16 +233683,20 @@ |
| 232001 | 233683 | rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 1, iDel); |
| 232002 | 233684 | for(iCol=1; rc==SQLITE_OK && iCol<=pConfig->nCol; iCol++){ |
| 232003 | 233685 | if( pConfig->abUnindexed[iCol-1]==0 ){ |
| 232004 | 233686 | const char *zText; |
| 232005 | 233687 | int nText; |
| 233688 | + assert( pSeek==0 || apVal==0 ); |
| 233689 | + assert( pSeek!=0 || apVal!=0 ); |
| 232006 | 233690 | if( pSeek ){ |
| 232007 | 233691 | zText = (const char*)sqlite3_column_text(pSeek, iCol); |
| 232008 | 233692 | nText = sqlite3_column_bytes(pSeek, iCol); |
| 232009 | | - }else{ |
| 233693 | + }else if( ALWAYS(apVal) ){ |
| 232010 | 233694 | zText = (const char*)sqlite3_value_text(apVal[iCol-1]); |
| 232011 | 233695 | nText = sqlite3_value_bytes(apVal[iCol-1]); |
| 233696 | + }else{ |
| 233697 | + continue; |
| 232012 | 233698 | } |
| 232013 | 233699 | ctx.szCol = 0; |
| 232014 | 233700 | rc = sqlite3Fts5Tokenize(pConfig, FTS5_TOKENIZE_DOCUMENT, |
| 232015 | 233701 | zText, nText, (void*)&ctx, fts5StorageInsertCallback |
| 232016 | 233702 | ); |
| | @@ -232642,12 +234328,13 @@ |
| 232642 | 234328 | sqlite3_stmt *pLookup = 0; /* Statement to query %_docsize */ |
| 232643 | 234329 | int rc; /* Return Code */ |
| 232644 | 234330 | |
| 232645 | 234331 | assert( p->pConfig->bColumnsize ); |
| 232646 | 234332 | rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0); |
| 232647 | | - if( rc==SQLITE_OK ){ |
| 234333 | + if( pLookup ){ |
| 232648 | 234334 | int bCorrupt = 1; |
| 234335 | + assert( rc==SQLITE_OK ); |
| 232649 | 234336 | sqlite3_bind_int64(pLookup, 1, iRowid); |
| 232650 | 234337 | if( SQLITE_ROW==sqlite3_step(pLookup) ){ |
| 232651 | 234338 | const u8 *aBlob = sqlite3_column_blob(pLookup, 0); |
| 232652 | 234339 | int nBlob = sqlite3_column_bytes(pLookup, 0); |
| 232653 | 234340 | if( 0==fts5StorageDecodeSizeArray(aCol, nCol, aBlob, nBlob) ){ |
| | @@ -232656,10 +234343,12 @@ |
| 232656 | 234343 | } |
| 232657 | 234344 | rc = sqlite3_reset(pLookup); |
| 232658 | 234345 | if( bCorrupt && rc==SQLITE_OK ){ |
| 232659 | 234346 | rc = FTS5_CORRUPT; |
| 232660 | 234347 | } |
| 234348 | + }else{ |
| 234349 | + assert( rc!=SQLITE_OK ); |
| 232661 | 234350 | } |
| 232662 | 234351 | |
| 232663 | 234352 | return rc; |
| 232664 | 234353 | } |
| 232665 | 234354 | |
| | @@ -235660,11 +237349,11 @@ |
| 235660 | 237349 | rc = sqlite3Fts5FlushToDisk(pFts5); |
| 235661 | 237350 | } |
| 235662 | 237351 | } |
| 235663 | 237352 | |
| 235664 | 237353 | if( rc==SQLITE_OK ){ |
| 235665 | | - int nByte = pFts5->pConfig->nCol * sizeof(i64)*2 + sizeof(Fts5VocabCursor); |
| 237354 | + i64 nByte = pFts5->pConfig->nCol * sizeof(i64)*2 + sizeof(Fts5VocabCursor); |
| 235666 | 237355 | pCsr = (Fts5VocabCursor*)sqlite3Fts5MallocZero(&rc, nByte); |
| 235667 | 237356 | } |
| 235668 | 237357 | |
| 235669 | 237358 | if( pCsr ){ |
| 235670 | 237359 | pCsr->pFts5 = pFts5; |
| 235671 | 237360 | |