| | @@ -452,11 +452,11 @@ |
| 452 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | 454 | */ |
| 455 | 455 | #define SQLITE_VERSION "3.40.0" |
| 456 | 456 | #define SQLITE_VERSION_NUMBER 3040000 |
| 457 | | -#define SQLITE_SOURCE_ID "2022-09-28 19:14:01 f25cf63471cbed1edb27591e57fead62550d4046dbdcb61312288f0f6f24c646" |
| 457 | +#define SQLITE_SOURCE_ID "2022-10-26 11:11:31 3dfdfb3f12edb3f4267942598efd05d573e13b7c5d6cdbc3404373f41b8993dd" |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| | @@ -974,17 +974,21 @@ |
| 974 | 974 | /* |
| 975 | 975 | ** CAPI3REF: File Locking Levels |
| 976 | 976 | ** |
| 977 | 977 | ** SQLite uses one of these integer values as the second |
| 978 | 978 | ** argument to calls it makes to the xLock() and xUnlock() methods |
| 979 | | -** of an [sqlite3_io_methods] object. |
| 979 | +** of an [sqlite3_io_methods] object. These values are ordered from |
| 980 | +** lest restrictive to most restrictive. |
| 981 | +** |
| 982 | +** The argument to xLock() is always SHARED or higher. The argument to |
| 983 | +** xUnlock is either SHARED or NONE. |
| 980 | 984 | */ |
| 981 | | -#define SQLITE_LOCK_NONE 0 |
| 982 | | -#define SQLITE_LOCK_SHARED 1 |
| 983 | | -#define SQLITE_LOCK_RESERVED 2 |
| 984 | | -#define SQLITE_LOCK_PENDING 3 |
| 985 | | -#define SQLITE_LOCK_EXCLUSIVE 4 |
| 985 | +#define SQLITE_LOCK_NONE 0 /* xUnlock() only */ |
| 986 | +#define SQLITE_LOCK_SHARED 1 /* xLock() or xUnlock() */ |
| 987 | +#define SQLITE_LOCK_RESERVED 2 /* xLock() only */ |
| 988 | +#define SQLITE_LOCK_PENDING 3 /* xLock() only */ |
| 989 | +#define SQLITE_LOCK_EXCLUSIVE 4 /* xLock() only */ |
| 986 | 990 | |
| 987 | 991 | /* |
| 988 | 992 | ** CAPI3REF: Synchronization Type Flags |
| 989 | 993 | ** |
| 990 | 994 | ** When SQLite invokes the xSync() method of an |
| | @@ -1058,11 +1062,18 @@ |
| 1058 | 1062 | ** <li> [SQLITE_LOCK_SHARED], |
| 1059 | 1063 | ** <li> [SQLITE_LOCK_RESERVED], |
| 1060 | 1064 | ** <li> [SQLITE_LOCK_PENDING], or |
| 1061 | 1065 | ** <li> [SQLITE_LOCK_EXCLUSIVE]. |
| 1062 | 1066 | ** </ul> |
| 1063 | | -** xLock() increases the lock. xUnlock() decreases the lock. |
| 1067 | +** xLock() upgrades the database file lock. In other words, xLock() moves the |
| 1068 | +** database file lock in the direction NONE toward EXCLUSIVE. The argument to |
| 1069 | +** xLock() is always on of SHARED, RESERVED, PENDING, or EXCLUSIVE, never |
| 1070 | +** SQLITE_LOCK_NONE. If the database file lock is already at or above the |
| 1071 | +** requested lock, then the call to xLock() is a no-op. |
| 1072 | +** xUnlock() downgrades the database file lock to either SHARED or NONE. |
| 1073 | +* If the lock is already at or below the requested lock state, then the call |
| 1074 | +** to xUnlock() is a no-op. |
| 1064 | 1075 | ** The xCheckReservedLock() method checks whether any database connection, |
| 1065 | 1076 | ** either in this process or in some other process, is holding a RESERVED, |
| 1066 | 1077 | ** PENDING, or EXCLUSIVE lock on the file. It returns true |
| 1067 | 1078 | ** if such a lock exists and false otherwise. |
| 1068 | 1079 | ** |
| | @@ -1163,13 +1174,12 @@ |
| 1163 | 1174 | ** <li>[[SQLITE_FCNTL_LOCKSTATE]] |
| 1164 | 1175 | ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This |
| 1165 | 1176 | ** opcode causes the xFileControl method to write the current state of |
| 1166 | 1177 | ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED], |
| 1167 | 1178 | ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE]) |
| 1168 | | -** into an integer that the pArg argument points to. This capability |
| 1169 | | -** is used during testing and is only available when the SQLITE_TEST |
| 1170 | | -** compile-time option is used. |
| 1179 | +** into an integer that the pArg argument points to. |
| 1180 | +** This capability is only available if SQLite is compiled with [SQLITE_DEBUG]. |
| 1171 | 1181 | ** |
| 1172 | 1182 | ** <li>[[SQLITE_FCNTL_SIZE_HINT]] |
| 1173 | 1183 | ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS |
| 1174 | 1184 | ** layer a hint of how large the database file will grow to be during the |
| 1175 | 1185 | ** current transaction. This hint is not guaranteed to be accurate but it |
| | @@ -5815,10 +5825,20 @@ |
| 5815 | 5825 | ** such a conversion is possible without loss of information (in other |
| 5816 | 5826 | ** words, if the value is a string that looks like a number) |
| 5817 | 5827 | ** then the conversion is performed. Otherwise no conversion occurs. |
| 5818 | 5828 | ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^ |
| 5819 | 5829 | ** |
| 5830 | +** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8], |
| 5831 | +** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current encoding |
| 5832 | +** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X) |
| 5833 | +** returns something other than SQLITE_TEXT, then the return value from |
| 5834 | +** sqlite3_value_encoding(X) is meaningless. ^Calls to |
| 5835 | +** sqlite3_value_text(X), sqlite3_value_text16(X), sqlite3_value_text16be(X), |
| 5836 | +** sqlite3_value_text16le(X), sqlite3_value_bytes(X), or |
| 5837 | +** sqlite3_value_bytes16(X) might change the encoding of the value X and |
| 5838 | +** thus change the return from subsequent calls to sqlite3_value_encoding(X). |
| 5839 | +** |
| 5820 | 5840 | ** ^Within the [xUpdate] method of a [virtual table], the |
| 5821 | 5841 | ** sqlite3_value_nochange(X) interface returns true if and only if |
| 5822 | 5842 | ** the column corresponding to X is unchanged by the UPDATE operation |
| 5823 | 5843 | ** that the xUpdate method call was invoked to implement and if |
| 5824 | 5844 | ** and the prior [xColumn] method call that was invoked to extracted |
| | @@ -5879,10 +5899,11 @@ |
| 5879 | 5899 | SQLITE_API int sqlite3_value_bytes16(sqlite3_value*); |
| 5880 | 5900 | SQLITE_API int sqlite3_value_type(sqlite3_value*); |
| 5881 | 5901 | SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*); |
| 5882 | 5902 | SQLITE_API int sqlite3_value_nochange(sqlite3_value*); |
| 5883 | 5903 | SQLITE_API int sqlite3_value_frombind(sqlite3_value*); |
| 5904 | +SQLITE_API int sqlite3_value_encoding(sqlite3_value*); |
| 5884 | 5905 | |
| 5885 | 5906 | /* |
| 5886 | 5907 | ** CAPI3REF: Finding The Subtype Of SQL Values |
| 5887 | 5908 | ** METHOD: sqlite3_value |
| 5888 | 5909 | ** |
| | @@ -5932,11 +5953,11 @@ |
| 5932 | 5953 | ** In those cases, sqlite3_aggregate_context() might be called for the |
| 5933 | 5954 | ** first time from within xFinal().)^ |
| 5934 | 5955 | ** |
| 5935 | 5956 | ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer |
| 5936 | 5957 | ** when first called if N is less than or equal to zero or if a memory |
| 5937 | | -** allocate error occurs. |
| 5958 | +** allocation error occurs. |
| 5938 | 5959 | ** |
| 5939 | 5960 | ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is |
| 5940 | 5961 | ** determined by the N parameter on first successful call. Changing the |
| 5941 | 5962 | ** value of N in any subsequent call to sqlite3_aggregate_context() within |
| 5942 | 5963 | ** the same aggregate function instance will not resize the memory |
| | @@ -13160,11 +13181,11 @@ |
| 13160 | 13181 | /* |
| 13161 | 13182 | ** Include the configuration header output by 'configure' if we're using the |
| 13162 | 13183 | ** autoconf-based build |
| 13163 | 13184 | */ |
| 13164 | 13185 | #if defined(_HAVE_SQLITE_CONFIG_H) && !defined(SQLITECONFIG_H) |
| 13165 | | -#include "config.h" |
| 13186 | +#include "sqlite_cfg.h" |
| 13166 | 13187 | #define SQLITECONFIG_H 1 |
| 13167 | 13188 | #endif |
| 13168 | 13189 | |
| 13169 | 13190 | /************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/ |
| 13170 | 13191 | /************** Begin file sqliteLimit.h *************************************/ |
| | @@ -14643,10 +14664,11 @@ |
| 14643 | 14664 | typedef struct FuncDestructor FuncDestructor; |
| 14644 | 14665 | typedef struct FuncDef FuncDef; |
| 14645 | 14666 | typedef struct FuncDefHash FuncDefHash; |
| 14646 | 14667 | typedef struct IdList IdList; |
| 14647 | 14668 | typedef struct Index Index; |
| 14669 | +typedef struct IndexedExpr IndexedExpr; |
| 14648 | 14670 | typedef struct IndexSample IndexSample; |
| 14649 | 14671 | typedef struct KeyClass KeyClass; |
| 14650 | 14672 | typedef struct KeyInfo KeyInfo; |
| 14651 | 14673 | typedef struct Lookaside Lookaside; |
| 14652 | 14674 | typedef struct LookasideSlot LookasideSlot; |
| | @@ -14708,10 +14730,11 @@ |
| 14708 | 14730 | #define MASKBIT(n) (((Bitmask)1)<<(n)) |
| 14709 | 14731 | #define MASKBIT64(n) (((u64)1)<<(n)) |
| 14710 | 14732 | #define MASKBIT32(n) (((unsigned int)1)<<(n)) |
| 14711 | 14733 | #define SMASKBIT32(n) ((n)<=31?((unsigned int)1)<<(n):0) |
| 14712 | 14734 | #define ALLBITS ((Bitmask)-1) |
| 14735 | +#define TOPBIT (((Bitmask)1)<<(BMS-1)) |
| 14713 | 14736 | |
| 14714 | 14737 | /* A VList object records a mapping between parameters/variables/wildcards |
| 14715 | 14738 | ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer |
| 14716 | 14739 | ** variable number associated with that parameter. See the format description |
| 14717 | 14740 | ** on the sqlite3VListAdd() routine for more information. A VList is really |
| | @@ -14722,10 +14745,335 @@ |
| 14722 | 14745 | /* |
| 14723 | 14746 | ** Defer sourcing vdbe.h and btree.h until after the "u8" and |
| 14724 | 14747 | ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque |
| 14725 | 14748 | ** pointer types (i.e. FuncDef) defined above. |
| 14726 | 14749 | */ |
| 14750 | +/************** Include os.h in the middle of sqliteInt.h ********************/ |
| 14751 | +/************** Begin file os.h **********************************************/ |
| 14752 | +/* |
| 14753 | +** 2001 September 16 |
| 14754 | +** |
| 14755 | +** The author disclaims copyright to this source code. In place of |
| 14756 | +** a legal notice, here is a blessing: |
| 14757 | +** |
| 14758 | +** May you do good and not evil. |
| 14759 | +** May you find forgiveness for yourself and forgive others. |
| 14760 | +** May you share freely, never taking more than you give. |
| 14761 | +** |
| 14762 | +****************************************************************************** |
| 14763 | +** |
| 14764 | +** This header file (together with is companion C source-code file |
| 14765 | +** "os.c") attempt to abstract the underlying operating system so that |
| 14766 | +** the SQLite library will work on both POSIX and windows systems. |
| 14767 | +** |
| 14768 | +** This header file is #include-ed by sqliteInt.h and thus ends up |
| 14769 | +** being included by every source file. |
| 14770 | +*/ |
| 14771 | +#ifndef _SQLITE_OS_H_ |
| 14772 | +#define _SQLITE_OS_H_ |
| 14773 | + |
| 14774 | +/* |
| 14775 | +** Attempt to automatically detect the operating system and setup the |
| 14776 | +** necessary pre-processor macros for it. |
| 14777 | +*/ |
| 14778 | +/************** Include os_setup.h in the middle of os.h *********************/ |
| 14779 | +/************** Begin file os_setup.h ****************************************/ |
| 14780 | +/* |
| 14781 | +** 2013 November 25 |
| 14782 | +** |
| 14783 | +** The author disclaims copyright to this source code. In place of |
| 14784 | +** a legal notice, here is a blessing: |
| 14785 | +** |
| 14786 | +** May you do good and not evil. |
| 14787 | +** May you find forgiveness for yourself and forgive others. |
| 14788 | +** May you share freely, never taking more than you give. |
| 14789 | +** |
| 14790 | +****************************************************************************** |
| 14791 | +** |
| 14792 | +** This file contains pre-processor directives related to operating system |
| 14793 | +** detection and/or setup. |
| 14794 | +*/ |
| 14795 | +#ifndef SQLITE_OS_SETUP_H |
| 14796 | +#define SQLITE_OS_SETUP_H |
| 14797 | + |
| 14798 | +/* |
| 14799 | +** Figure out if we are dealing with Unix, Windows, or some other operating |
| 14800 | +** system. |
| 14801 | +** |
| 14802 | +** After the following block of preprocess macros, all of |
| 14803 | +** |
| 14804 | +** SQLITE_OS_KV |
| 14805 | +** SQLITE_OS_OTHER |
| 14806 | +** SQLITE_OS_UNIX |
| 14807 | +** SQLITE_OS_WIN |
| 14808 | +** |
| 14809 | +** will defined to either 1 or 0. One of them will be 1. The others will be 0. |
| 14810 | +** If none of the macros are initially defined, then select either |
| 14811 | +** SQLITE_OS_UNIX or SQLITE_OS_WIN depending on the target platform. |
| 14812 | +** |
| 14813 | +** If SQLITE_OS_OTHER=1 is specified at compile-time, then the application |
| 14814 | +** must provide its own VFS implementation together with sqlite3_os_init() |
| 14815 | +** and sqlite3_os_end() routines. |
| 14816 | +*/ |
| 14817 | +#if !defined(SQLITE_OS_KV) && !defined(SQLITE_OS_OTHER) && \ |
| 14818 | + !defined(SQLITE_OS_UNIX) && !defined(SQLITE_OS_WIN) |
| 14819 | +# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || \ |
| 14820 | + defined(__MINGW32__) || defined(__BORLANDC__) |
| 14821 | +# define SQLITE_OS_WIN 1 |
| 14822 | +# define SQLITE_OS_UNIX 0 |
| 14823 | +# else |
| 14824 | +# define SQLITE_OS_WIN 0 |
| 14825 | +# define SQLITE_OS_UNIX 1 |
| 14826 | +# endif |
| 14827 | +#endif |
| 14828 | +#if SQLITE_OS_OTHER+1>1 |
| 14829 | +# undef SQLITE_OS_KV |
| 14830 | +# define SQLITE_OS_KV 0 |
| 14831 | +# undef SQLITE_OS_UNIX |
| 14832 | +# define SQLITE_OS_UNIX 0 |
| 14833 | +# undef SQLITE_OS_WIN |
| 14834 | +# define SQLITE_OS_WIN 0 |
| 14835 | +#endif |
| 14836 | +#if SQLITE_OS_KV+1>1 |
| 14837 | +# undef SQLITE_OS_OTHER |
| 14838 | +# define SQLITE_OS_OTHER 0 |
| 14839 | +# undef SQLITE_OS_UNIX |
| 14840 | +# define SQLITE_OS_UNIX 0 |
| 14841 | +# undef SQLITE_OS_WIN |
| 14842 | +# define SQLITE_OS_WIN 0 |
| 14843 | +# define SQLITE_OMIT_LOAD_EXTENSION 1 |
| 14844 | +# define SQLITE_OMIT_WAL 1 |
| 14845 | +# define SQLITE_OMIT_DEPRECATED 1 |
| 14846 | +# undef SQLITE_TEMP_STORE |
| 14847 | +# define SQLITE_TEMP_STORE 3 /* Always use memory for temporary storage */ |
| 14848 | +# define SQLITE_DQS 0 |
| 14849 | +# define SQLITE_OMIT_SHARED_CACHE 1 |
| 14850 | +# define SQLITE_OMIT_AUTOINIT 1 |
| 14851 | +#endif |
| 14852 | +#if SQLITE_OS_UNIX+1>1 |
| 14853 | +# undef SQLITE_OS_KV |
| 14854 | +# define SQLITE_OS_KV 0 |
| 14855 | +# undef SQLITE_OS_OTHER |
| 14856 | +# define SQLITE_OS_OTHER 0 |
| 14857 | +# undef SQLITE_OS_WIN |
| 14858 | +# define SQLITE_OS_WIN 0 |
| 14859 | +#endif |
| 14860 | +#if SQLITE_OS_WIN+1>1 |
| 14861 | +# undef SQLITE_OS_KV |
| 14862 | +# define SQLITE_OS_KV 0 |
| 14863 | +# undef SQLITE_OS_OTHER |
| 14864 | +# define SQLITE_OS_OTHER 0 |
| 14865 | +# undef SQLITE_OS_UNIX |
| 14866 | +# define SQLITE_OS_UNIX 0 |
| 14867 | +#endif |
| 14868 | + |
| 14869 | + |
| 14870 | +#endif /* SQLITE_OS_SETUP_H */ |
| 14871 | + |
| 14872 | +/************** End of os_setup.h ********************************************/ |
| 14873 | +/************** Continuing where we left off in os.h *************************/ |
| 14874 | + |
| 14875 | +/* If the SET_FULLSYNC macro is not defined above, then make it |
| 14876 | +** a no-op |
| 14877 | +*/ |
| 14878 | +#ifndef SET_FULLSYNC |
| 14879 | +# define SET_FULLSYNC(x,y) |
| 14880 | +#endif |
| 14881 | + |
| 14882 | +/* Maximum pathname length. Note: FILENAME_MAX defined by stdio.h |
| 14883 | +*/ |
| 14884 | +#ifndef SQLITE_MAX_PATHLEN |
| 14885 | +# define SQLITE_MAX_PATHLEN FILENAME_MAX |
| 14886 | +#endif |
| 14887 | + |
| 14888 | +/* Maximum number of symlinks that will be resolved while trying to |
| 14889 | +** expand a filename in xFullPathname() in the VFS. |
| 14890 | +*/ |
| 14891 | +#ifndef SQLITE_MAX_SYMLINK |
| 14892 | +# define SQLITE_MAX_SYMLINK 200 |
| 14893 | +#endif |
| 14894 | + |
| 14895 | +/* |
| 14896 | +** The default size of a disk sector |
| 14897 | +*/ |
| 14898 | +#ifndef SQLITE_DEFAULT_SECTOR_SIZE |
| 14899 | +# define SQLITE_DEFAULT_SECTOR_SIZE 4096 |
| 14900 | +#endif |
| 14901 | + |
| 14902 | +/* |
| 14903 | +** Temporary files are named starting with this prefix followed by 16 random |
| 14904 | +** alphanumeric characters, and no file extension. They are stored in the |
| 14905 | +** OS's standard temporary file directory, and are deleted prior to exit. |
| 14906 | +** If sqlite is being embedded in another program, you may wish to change the |
| 14907 | +** prefix to reflect your program's name, so that if your program exits |
| 14908 | +** prematurely, old temporary files can be easily identified. This can be done |
| 14909 | +** using -DSQLITE_TEMP_FILE_PREFIX=myprefix_ on the compiler command line. |
| 14910 | +** |
| 14911 | +** 2006-10-31: The default prefix used to be "sqlite_". But then |
| 14912 | +** Mcafee started using SQLite in their anti-virus product and it |
| 14913 | +** started putting files with the "sqlite" name in the c:/temp folder. |
| 14914 | +** This annoyed many windows users. Those users would then do a |
| 14915 | +** Google search for "sqlite", find the telephone numbers of the |
| 14916 | +** developers and call to wake them up at night and complain. |
| 14917 | +** For this reason, the default name prefix is changed to be "sqlite" |
| 14918 | +** spelled backwards. So the temp files are still identified, but |
| 14919 | +** anybody smart enough to figure out the code is also likely smart |
| 14920 | +** enough to know that calling the developer will not help get rid |
| 14921 | +** of the file. |
| 14922 | +*/ |
| 14923 | +#ifndef SQLITE_TEMP_FILE_PREFIX |
| 14924 | +# define SQLITE_TEMP_FILE_PREFIX "etilqs_" |
| 14925 | +#endif |
| 14926 | + |
| 14927 | +/* |
| 14928 | +** The following values may be passed as the second argument to |
| 14929 | +** sqlite3OsLock(). The various locks exhibit the following semantics: |
| 14930 | +** |
| 14931 | +** SHARED: Any number of processes may hold a SHARED lock simultaneously. |
| 14932 | +** RESERVED: A single process may hold a RESERVED lock on a file at |
| 14933 | +** any time. Other processes may hold and obtain new SHARED locks. |
| 14934 | +** PENDING: A single process may hold a PENDING lock on a file at |
| 14935 | +** any one time. Existing SHARED locks may persist, but no new |
| 14936 | +** SHARED locks may be obtained by other processes. |
| 14937 | +** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks. |
| 14938 | +** |
| 14939 | +** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a |
| 14940 | +** process that requests an EXCLUSIVE lock may actually obtain a PENDING |
| 14941 | +** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to |
| 14942 | +** sqlite3OsLock(). |
| 14943 | +*/ |
| 14944 | +#define NO_LOCK 0 |
| 14945 | +#define SHARED_LOCK 1 |
| 14946 | +#define RESERVED_LOCK 2 |
| 14947 | +#define PENDING_LOCK 3 |
| 14948 | +#define EXCLUSIVE_LOCK 4 |
| 14949 | + |
| 14950 | +/* |
| 14951 | +** File Locking Notes: (Mostly about windows but also some info for Unix) |
| 14952 | +** |
| 14953 | +** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because |
| 14954 | +** those functions are not available. So we use only LockFile() and |
| 14955 | +** UnlockFile(). |
| 14956 | +** |
| 14957 | +** LockFile() prevents not just writing but also reading by other processes. |
| 14958 | +** A SHARED_LOCK is obtained by locking a single randomly-chosen |
| 14959 | +** byte out of a specific range of bytes. The lock byte is obtained at |
| 14960 | +** random so two separate readers can probably access the file at the |
| 14961 | +** same time, unless they are unlucky and choose the same lock byte. |
| 14962 | +** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range. |
| 14963 | +** There can only be one writer. A RESERVED_LOCK is obtained by locking |
| 14964 | +** a single byte of the file that is designated as the reserved lock byte. |
| 14965 | +** A PENDING_LOCK is obtained by locking a designated byte different from |
| 14966 | +** the RESERVED_LOCK byte. |
| 14967 | +** |
| 14968 | +** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available, |
| 14969 | +** which means we can use reader/writer locks. When reader/writer locks |
| 14970 | +** are used, the lock is placed on the same range of bytes that is used |
| 14971 | +** for probabilistic locking in Win95/98/ME. Hence, the locking scheme |
| 14972 | +** will support two or more Win95 readers or two or more WinNT readers. |
| 14973 | +** But a single Win95 reader will lock out all WinNT readers and a single |
| 14974 | +** WinNT reader will lock out all other Win95 readers. |
| 14975 | +** |
| 14976 | +** The following #defines specify the range of bytes used for locking. |
| 14977 | +** SHARED_SIZE is the number of bytes available in the pool from which |
| 14978 | +** a random byte is selected for a shared lock. The pool of bytes for |
| 14979 | +** shared locks begins at SHARED_FIRST. |
| 14980 | +** |
| 14981 | +** The same locking strategy and |
| 14982 | +** byte ranges are used for Unix. This leaves open the possibility of having |
| 14983 | +** clients on win95, winNT, and unix all talking to the same shared file |
| 14984 | +** and all locking correctly. To do so would require that samba (or whatever |
| 14985 | +** tool is being used for file sharing) implements locks correctly between |
| 14986 | +** windows and unix. I'm guessing that isn't likely to happen, but by |
| 14987 | +** using the same locking range we are at least open to the possibility. |
| 14988 | +** |
| 14989 | +** Locking in windows is manditory. For this reason, we cannot store |
| 14990 | +** actual data in the bytes used for locking. The pager never allocates |
| 14991 | +** the pages involved in locking therefore. SHARED_SIZE is selected so |
| 14992 | +** that all locks will fit on a single page even at the minimum page size. |
| 14993 | +** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE |
| 14994 | +** is set high so that we don't have to allocate an unused page except |
| 14995 | +** for very large databases. But one should test the page skipping logic |
| 14996 | +** by setting PENDING_BYTE low and running the entire regression suite. |
| 14997 | +** |
| 14998 | +** Changing the value of PENDING_BYTE results in a subtly incompatible |
| 14999 | +** file format. Depending on how it is changed, you might not notice |
| 15000 | +** the incompatibility right away, even running a full regression test. |
| 15001 | +** The default location of PENDING_BYTE is the first byte past the |
| 15002 | +** 1GB boundary. |
| 15003 | +** |
| 15004 | +*/ |
| 15005 | +#ifdef SQLITE_OMIT_WSD |
| 15006 | +# define PENDING_BYTE (0x40000000) |
| 15007 | +#else |
| 15008 | +# define PENDING_BYTE sqlite3PendingByte |
| 15009 | +#endif |
| 15010 | +#define RESERVED_BYTE (PENDING_BYTE+1) |
| 15011 | +#define SHARED_FIRST (PENDING_BYTE+2) |
| 15012 | +#define SHARED_SIZE 510 |
| 15013 | + |
| 15014 | +/* |
| 15015 | +** Wrapper around OS specific sqlite3_os_init() function. |
| 15016 | +*/ |
| 15017 | +SQLITE_PRIVATE int sqlite3OsInit(void); |
| 15018 | + |
| 15019 | +/* |
| 15020 | +** Functions for accessing sqlite3_file methods |
| 15021 | +*/ |
| 15022 | +SQLITE_PRIVATE void sqlite3OsClose(sqlite3_file*); |
| 15023 | +SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset); |
| 15024 | +SQLITE_PRIVATE int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset); |
| 15025 | +SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file*, i64 size); |
| 15026 | +SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file*, int); |
| 15027 | +SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize); |
| 15028 | +SQLITE_PRIVATE int sqlite3OsLock(sqlite3_file*, int); |
| 15029 | +SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file*, int); |
| 15030 | +SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut); |
| 15031 | +SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file*,int,void*); |
| 15032 | +SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file*,int,void*); |
| 15033 | +#define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0 |
| 15034 | +SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id); |
| 15035 | +SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id); |
| 15036 | +#ifndef SQLITE_OMIT_WAL |
| 15037 | +SQLITE_PRIVATE int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **); |
| 15038 | +SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int, int, int); |
| 15039 | +SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id); |
| 15040 | +SQLITE_PRIVATE int sqlite3OsShmUnmap(sqlite3_file *id, int); |
| 15041 | +#endif /* SQLITE_OMIT_WAL */ |
| 15042 | +SQLITE_PRIVATE int sqlite3OsFetch(sqlite3_file *id, i64, int, void **); |
| 15043 | +SQLITE_PRIVATE int sqlite3OsUnfetch(sqlite3_file *, i64, void *); |
| 15044 | + |
| 15045 | + |
| 15046 | +/* |
| 15047 | +** Functions for accessing sqlite3_vfs methods |
| 15048 | +*/ |
| 15049 | +SQLITE_PRIVATE int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *); |
| 15050 | +SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *, const char *, int); |
| 15051 | +SQLITE_PRIVATE int sqlite3OsAccess(sqlite3_vfs *, const char *, int, int *pResOut); |
| 15052 | +SQLITE_PRIVATE int sqlite3OsFullPathname(sqlite3_vfs *, const char *, int, char *); |
| 15053 | +#ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 15054 | +SQLITE_PRIVATE void *sqlite3OsDlOpen(sqlite3_vfs *, const char *); |
| 15055 | +SQLITE_PRIVATE void sqlite3OsDlError(sqlite3_vfs *, int, char *); |
| 15056 | +SQLITE_PRIVATE void (*sqlite3OsDlSym(sqlite3_vfs *, void *, const char *))(void); |
| 15057 | +SQLITE_PRIVATE void sqlite3OsDlClose(sqlite3_vfs *, void *); |
| 15058 | +#endif /* SQLITE_OMIT_LOAD_EXTENSION */ |
| 15059 | +SQLITE_PRIVATE int sqlite3OsRandomness(sqlite3_vfs *, int, char *); |
| 15060 | +SQLITE_PRIVATE int sqlite3OsSleep(sqlite3_vfs *, int); |
| 15061 | +SQLITE_PRIVATE int sqlite3OsGetLastError(sqlite3_vfs*); |
| 15062 | +SQLITE_PRIVATE int sqlite3OsCurrentTimeInt64(sqlite3_vfs *, sqlite3_int64*); |
| 15063 | + |
| 15064 | +/* |
| 15065 | +** Convenience functions for opening and closing files using |
| 15066 | +** sqlite3_malloc() to obtain space for the file-handle structure. |
| 15067 | +*/ |
| 15068 | +SQLITE_PRIVATE int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*); |
| 15069 | +SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *); |
| 15070 | + |
| 15071 | +#endif /* _SQLITE_OS_H_ */ |
| 15072 | + |
| 15073 | +/************** End of os.h **************************************************/ |
| 15074 | +/************** Continuing where we left off in sqliteInt.h ******************/ |
| 14727 | 15075 | /************** Include pager.h in the middle of sqliteInt.h *****************/ |
| 14728 | 15076 | /************** Begin file pager.h *******************************************/ |
| 14729 | 15077 | /* |
| 14730 | 15078 | ** 2001 September 15 |
| 14731 | 15079 | ** |
| | @@ -15576,11 +15924,11 @@ |
| 15576 | 15924 | #define OP_MustBeInt 13 /* jump */ |
| 15577 | 15925 | #define OP_Jump 14 /* jump */ |
| 15578 | 15926 | #define OP_Once 15 /* jump */ |
| 15579 | 15927 | #define OP_If 16 /* jump */ |
| 15580 | 15928 | #define OP_IfNot 17 /* jump */ |
| 15581 | | -#define OP_IsNullOrType 18 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */ |
| 15929 | +#define OP_IsType 18 /* jump, synopsis: if typeof(P1.P3) in P5 goto P2 */ |
| 15582 | 15930 | #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */ |
| 15583 | 15931 | #define OP_IfNullRow 20 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */ |
| 15584 | 15932 | #define OP_SeekLT 21 /* jump, synopsis: key=r[P3@P4] */ |
| 15585 | 15933 | #define OP_SeekLE 22 /* jump, synopsis: key=r[P3@P4] */ |
| 15586 | 15934 | #define OP_SeekGE 23 /* jump, synopsis: key=r[P3@P4] */ |
| | @@ -15759,11 +16107,11 @@ |
| 15759 | 16107 | #define OPFLG_OUT2 0x10 /* out2: P2 is an output */ |
| 15760 | 16108 | #define OPFLG_OUT3 0x20 /* out3: P3 is an output */ |
| 15761 | 16109 | #define OPFLG_INITIALIZER {\ |
| 15762 | 16110 | /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\ |
| 15763 | 16111 | /* 8 */ 0x01, 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01,\ |
| 15764 | | -/* 16 */ 0x03, 0x03, 0x03, 0x12, 0x01, 0x09, 0x09, 0x09,\ |
| 16112 | +/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x09, 0x09, 0x09,\ |
| 15765 | 16113 | /* 24 */ 0x09, 0x01, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\ |
| 15766 | 16114 | /* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\ |
| 15767 | 16115 | /* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x01, 0x23, 0x0b,\ |
| 15768 | 16116 | /* 48 */ 0x01, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\ |
| 15769 | 16117 | /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01,\ |
| | @@ -15856,10 +16204,11 @@ |
| 15856 | 16204 | SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe*, int addr, u8); |
| 15857 | 16205 | SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1); |
| 15858 | 16206 | SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2); |
| 15859 | 16207 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3); |
| 15860 | 16208 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5); |
| 16209 | +SQLITE_PRIVATE void sqlite3VdbeTypeofColumn(Vdbe*, int); |
| 15861 | 16210 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 15862 | 16211 | SQLITE_PRIVATE void sqlite3VdbeJumpHereOrPopInst(Vdbe*, int addr); |
| 15863 | 16212 | SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 15864 | 16213 | SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op); |
| 15865 | 16214 | #ifdef SQLITE_DEBUG |
| | @@ -16218,301 +16567,10 @@ |
| 16218 | 16567 | #endif |
| 16219 | 16568 | |
| 16220 | 16569 | #endif /* _PCACHE_H_ */ |
| 16221 | 16570 | |
| 16222 | 16571 | /************** End of pcache.h **********************************************/ |
| 16223 | | -/************** Continuing where we left off in sqliteInt.h ******************/ |
| 16224 | | -/************** Include os.h in the middle of sqliteInt.h ********************/ |
| 16225 | | -/************** Begin file os.h **********************************************/ |
| 16226 | | -/* |
| 16227 | | -** 2001 September 16 |
| 16228 | | -** |
| 16229 | | -** The author disclaims copyright to this source code. In place of |
| 16230 | | -** a legal notice, here is a blessing: |
| 16231 | | -** |
| 16232 | | -** May you do good and not evil. |
| 16233 | | -** May you find forgiveness for yourself and forgive others. |
| 16234 | | -** May you share freely, never taking more than you give. |
| 16235 | | -** |
| 16236 | | -****************************************************************************** |
| 16237 | | -** |
| 16238 | | -** This header file (together with is companion C source-code file |
| 16239 | | -** "os.c") attempt to abstract the underlying operating system so that |
| 16240 | | -** the SQLite library will work on both POSIX and windows systems. |
| 16241 | | -** |
| 16242 | | -** This header file is #include-ed by sqliteInt.h and thus ends up |
| 16243 | | -** being included by every source file. |
| 16244 | | -*/ |
| 16245 | | -#ifndef _SQLITE_OS_H_ |
| 16246 | | -#define _SQLITE_OS_H_ |
| 16247 | | - |
| 16248 | | -/* |
| 16249 | | -** Attempt to automatically detect the operating system and setup the |
| 16250 | | -** necessary pre-processor macros for it. |
| 16251 | | -*/ |
| 16252 | | -/************** Include os_setup.h in the middle of os.h *********************/ |
| 16253 | | -/************** Begin file os_setup.h ****************************************/ |
| 16254 | | -/* |
| 16255 | | -** 2013 November 25 |
| 16256 | | -** |
| 16257 | | -** The author disclaims copyright to this source code. In place of |
| 16258 | | -** a legal notice, here is a blessing: |
| 16259 | | -** |
| 16260 | | -** May you do good and not evil. |
| 16261 | | -** May you find forgiveness for yourself and forgive others. |
| 16262 | | -** May you share freely, never taking more than you give. |
| 16263 | | -** |
| 16264 | | -****************************************************************************** |
| 16265 | | -** |
| 16266 | | -** This file contains pre-processor directives related to operating system |
| 16267 | | -** detection and/or setup. |
| 16268 | | -*/ |
| 16269 | | -#ifndef SQLITE_OS_SETUP_H |
| 16270 | | -#define SQLITE_OS_SETUP_H |
| 16271 | | - |
| 16272 | | -/* |
| 16273 | | -** Figure out if we are dealing with Unix, Windows, or some other operating |
| 16274 | | -** system. |
| 16275 | | -** |
| 16276 | | -** After the following block of preprocess macros, all of SQLITE_OS_UNIX, |
| 16277 | | -** SQLITE_OS_WIN, and SQLITE_OS_OTHER will defined to either 1 or 0. One of |
| 16278 | | -** the three will be 1. The other two will be 0. |
| 16279 | | -*/ |
| 16280 | | -#if defined(SQLITE_OS_OTHER) |
| 16281 | | -# if SQLITE_OS_OTHER==1 |
| 16282 | | -# undef SQLITE_OS_UNIX |
| 16283 | | -# define SQLITE_OS_UNIX 0 |
| 16284 | | -# undef SQLITE_OS_WIN |
| 16285 | | -# define SQLITE_OS_WIN 0 |
| 16286 | | -# else |
| 16287 | | -# undef SQLITE_OS_OTHER |
| 16288 | | -# endif |
| 16289 | | -#endif |
| 16290 | | -#if !defined(SQLITE_OS_UNIX) && !defined(SQLITE_OS_OTHER) |
| 16291 | | -# define SQLITE_OS_OTHER 0 |
| 16292 | | -# ifndef SQLITE_OS_WIN |
| 16293 | | -# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || \ |
| 16294 | | - defined(__MINGW32__) || defined(__BORLANDC__) |
| 16295 | | -# define SQLITE_OS_WIN 1 |
| 16296 | | -# define SQLITE_OS_UNIX 0 |
| 16297 | | -# else |
| 16298 | | -# define SQLITE_OS_WIN 0 |
| 16299 | | -# define SQLITE_OS_UNIX 1 |
| 16300 | | -# endif |
| 16301 | | -# else |
| 16302 | | -# define SQLITE_OS_UNIX 0 |
| 16303 | | -# endif |
| 16304 | | -#else |
| 16305 | | -# ifndef SQLITE_OS_WIN |
| 16306 | | -# define SQLITE_OS_WIN 0 |
| 16307 | | -# endif |
| 16308 | | -#endif |
| 16309 | | - |
| 16310 | | -#endif /* SQLITE_OS_SETUP_H */ |
| 16311 | | - |
| 16312 | | -/************** End of os_setup.h ********************************************/ |
| 16313 | | -/************** Continuing where we left off in os.h *************************/ |
| 16314 | | - |
| 16315 | | -/* If the SET_FULLSYNC macro is not defined above, then make it |
| 16316 | | -** a no-op |
| 16317 | | -*/ |
| 16318 | | -#ifndef SET_FULLSYNC |
| 16319 | | -# define SET_FULLSYNC(x,y) |
| 16320 | | -#endif |
| 16321 | | - |
| 16322 | | -/* Maximum pathname length. Note: FILENAME_MAX defined by stdio.h |
| 16323 | | -*/ |
| 16324 | | -#ifndef SQLITE_MAX_PATHLEN |
| 16325 | | -# define SQLITE_MAX_PATHLEN FILENAME_MAX |
| 16326 | | -#endif |
| 16327 | | - |
| 16328 | | -/* Maximum number of symlinks that will be resolved while trying to |
| 16329 | | -** expand a filename in xFullPathname() in the VFS. |
| 16330 | | -*/ |
| 16331 | | -#ifndef SQLITE_MAX_SYMLINK |
| 16332 | | -# define SQLITE_MAX_SYMLINK 200 |
| 16333 | | -#endif |
| 16334 | | - |
| 16335 | | -/* |
| 16336 | | -** The default size of a disk sector |
| 16337 | | -*/ |
| 16338 | | -#ifndef SQLITE_DEFAULT_SECTOR_SIZE |
| 16339 | | -# define SQLITE_DEFAULT_SECTOR_SIZE 4096 |
| 16340 | | -#endif |
| 16341 | | - |
| 16342 | | -/* |
| 16343 | | -** Temporary files are named starting with this prefix followed by 16 random |
| 16344 | | -** alphanumeric characters, and no file extension. They are stored in the |
| 16345 | | -** OS's standard temporary file directory, and are deleted prior to exit. |
| 16346 | | -** If sqlite is being embedded in another program, you may wish to change the |
| 16347 | | -** prefix to reflect your program's name, so that if your program exits |
| 16348 | | -** prematurely, old temporary files can be easily identified. This can be done |
| 16349 | | -** using -DSQLITE_TEMP_FILE_PREFIX=myprefix_ on the compiler command line. |
| 16350 | | -** |
| 16351 | | -** 2006-10-31: The default prefix used to be "sqlite_". But then |
| 16352 | | -** Mcafee started using SQLite in their anti-virus product and it |
| 16353 | | -** started putting files with the "sqlite" name in the c:/temp folder. |
| 16354 | | -** This annoyed many windows users. Those users would then do a |
| 16355 | | -** Google search for "sqlite", find the telephone numbers of the |
| 16356 | | -** developers and call to wake them up at night and complain. |
| 16357 | | -** For this reason, the default name prefix is changed to be "sqlite" |
| 16358 | | -** spelled backwards. So the temp files are still identified, but |
| 16359 | | -** anybody smart enough to figure out the code is also likely smart |
| 16360 | | -** enough to know that calling the developer will not help get rid |
| 16361 | | -** of the file. |
| 16362 | | -*/ |
| 16363 | | -#ifndef SQLITE_TEMP_FILE_PREFIX |
| 16364 | | -# define SQLITE_TEMP_FILE_PREFIX "etilqs_" |
| 16365 | | -#endif |
| 16366 | | - |
| 16367 | | -/* |
| 16368 | | -** The following values may be passed as the second argument to |
| 16369 | | -** sqlite3OsLock(). The various locks exhibit the following semantics: |
| 16370 | | -** |
| 16371 | | -** SHARED: Any number of processes may hold a SHARED lock simultaneously. |
| 16372 | | -** RESERVED: A single process may hold a RESERVED lock on a file at |
| 16373 | | -** any time. Other processes may hold and obtain new SHARED locks. |
| 16374 | | -** PENDING: A single process may hold a PENDING lock on a file at |
| 16375 | | -** any one time. Existing SHARED locks may persist, but no new |
| 16376 | | -** SHARED locks may be obtained by other processes. |
| 16377 | | -** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks. |
| 16378 | | -** |
| 16379 | | -** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a |
| 16380 | | -** process that requests an EXCLUSIVE lock may actually obtain a PENDING |
| 16381 | | -** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to |
| 16382 | | -** sqlite3OsLock(). |
| 16383 | | -*/ |
| 16384 | | -#define NO_LOCK 0 |
| 16385 | | -#define SHARED_LOCK 1 |
| 16386 | | -#define RESERVED_LOCK 2 |
| 16387 | | -#define PENDING_LOCK 3 |
| 16388 | | -#define EXCLUSIVE_LOCK 4 |
| 16389 | | - |
| 16390 | | -/* |
| 16391 | | -** File Locking Notes: (Mostly about windows but also some info for Unix) |
| 16392 | | -** |
| 16393 | | -** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because |
| 16394 | | -** those functions are not available. So we use only LockFile() and |
| 16395 | | -** UnlockFile(). |
| 16396 | | -** |
| 16397 | | -** LockFile() prevents not just writing but also reading by other processes. |
| 16398 | | -** A SHARED_LOCK is obtained by locking a single randomly-chosen |
| 16399 | | -** byte out of a specific range of bytes. The lock byte is obtained at |
| 16400 | | -** random so two separate readers can probably access the file at the |
| 16401 | | -** same time, unless they are unlucky and choose the same lock byte. |
| 16402 | | -** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range. |
| 16403 | | -** There can only be one writer. A RESERVED_LOCK is obtained by locking |
| 16404 | | -** a single byte of the file that is designated as the reserved lock byte. |
| 16405 | | -** A PENDING_LOCK is obtained by locking a designated byte different from |
| 16406 | | -** the RESERVED_LOCK byte. |
| 16407 | | -** |
| 16408 | | -** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available, |
| 16409 | | -** which means we can use reader/writer locks. When reader/writer locks |
| 16410 | | -** are used, the lock is placed on the same range of bytes that is used |
| 16411 | | -** for probabilistic locking in Win95/98/ME. Hence, the locking scheme |
| 16412 | | -** will support two or more Win95 readers or two or more WinNT readers. |
| 16413 | | -** But a single Win95 reader will lock out all WinNT readers and a single |
| 16414 | | -** WinNT reader will lock out all other Win95 readers. |
| 16415 | | -** |
| 16416 | | -** The following #defines specify the range of bytes used for locking. |
| 16417 | | -** SHARED_SIZE is the number of bytes available in the pool from which |
| 16418 | | -** a random byte is selected for a shared lock. The pool of bytes for |
| 16419 | | -** shared locks begins at SHARED_FIRST. |
| 16420 | | -** |
| 16421 | | -** The same locking strategy and |
| 16422 | | -** byte ranges are used for Unix. This leaves open the possibility of having |
| 16423 | | -** clients on win95, winNT, and unix all talking to the same shared file |
| 16424 | | -** and all locking correctly. To do so would require that samba (or whatever |
| 16425 | | -** tool is being used for file sharing) implements locks correctly between |
| 16426 | | -** windows and unix. I'm guessing that isn't likely to happen, but by |
| 16427 | | -** using the same locking range we are at least open to the possibility. |
| 16428 | | -** |
| 16429 | | -** Locking in windows is manditory. For this reason, we cannot store |
| 16430 | | -** actual data in the bytes used for locking. The pager never allocates |
| 16431 | | -** the pages involved in locking therefore. SHARED_SIZE is selected so |
| 16432 | | -** that all locks will fit on a single page even at the minimum page size. |
| 16433 | | -** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE |
| 16434 | | -** is set high so that we don't have to allocate an unused page except |
| 16435 | | -** for very large databases. But one should test the page skipping logic |
| 16436 | | -** by setting PENDING_BYTE low and running the entire regression suite. |
| 16437 | | -** |
| 16438 | | -** Changing the value of PENDING_BYTE results in a subtly incompatible |
| 16439 | | -** file format. Depending on how it is changed, you might not notice |
| 16440 | | -** the incompatibility right away, even running a full regression test. |
| 16441 | | -** The default location of PENDING_BYTE is the first byte past the |
| 16442 | | -** 1GB boundary. |
| 16443 | | -** |
| 16444 | | -*/ |
| 16445 | | -#ifdef SQLITE_OMIT_WSD |
| 16446 | | -# define PENDING_BYTE (0x40000000) |
| 16447 | | -#else |
| 16448 | | -# define PENDING_BYTE sqlite3PendingByte |
| 16449 | | -#endif |
| 16450 | | -#define RESERVED_BYTE (PENDING_BYTE+1) |
| 16451 | | -#define SHARED_FIRST (PENDING_BYTE+2) |
| 16452 | | -#define SHARED_SIZE 510 |
| 16453 | | - |
| 16454 | | -/* |
| 16455 | | -** Wrapper around OS specific sqlite3_os_init() function. |
| 16456 | | -*/ |
| 16457 | | -SQLITE_PRIVATE int sqlite3OsInit(void); |
| 16458 | | - |
| 16459 | | -/* |
| 16460 | | -** Functions for accessing sqlite3_file methods |
| 16461 | | -*/ |
| 16462 | | -SQLITE_PRIVATE void sqlite3OsClose(sqlite3_file*); |
| 16463 | | -SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset); |
| 16464 | | -SQLITE_PRIVATE int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset); |
| 16465 | | -SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file*, i64 size); |
| 16466 | | -SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file*, int); |
| 16467 | | -SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize); |
| 16468 | | -SQLITE_PRIVATE int sqlite3OsLock(sqlite3_file*, int); |
| 16469 | | -SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file*, int); |
| 16470 | | -SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut); |
| 16471 | | -SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file*,int,void*); |
| 16472 | | -SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file*,int,void*); |
| 16473 | | -#define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0 |
| 16474 | | -SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id); |
| 16475 | | -SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id); |
| 16476 | | -#ifndef SQLITE_OMIT_WAL |
| 16477 | | -SQLITE_PRIVATE int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **); |
| 16478 | | -SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int, int, int); |
| 16479 | | -SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id); |
| 16480 | | -SQLITE_PRIVATE int sqlite3OsShmUnmap(sqlite3_file *id, int); |
| 16481 | | -#endif /* SQLITE_OMIT_WAL */ |
| 16482 | | -SQLITE_PRIVATE int sqlite3OsFetch(sqlite3_file *id, i64, int, void **); |
| 16483 | | -SQLITE_PRIVATE int sqlite3OsUnfetch(sqlite3_file *, i64, void *); |
| 16484 | | - |
| 16485 | | - |
| 16486 | | -/* |
| 16487 | | -** Functions for accessing sqlite3_vfs methods |
| 16488 | | -*/ |
| 16489 | | -SQLITE_PRIVATE int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *); |
| 16490 | | -SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *, const char *, int); |
| 16491 | | -SQLITE_PRIVATE int sqlite3OsAccess(sqlite3_vfs *, const char *, int, int *pResOut); |
| 16492 | | -SQLITE_PRIVATE int sqlite3OsFullPathname(sqlite3_vfs *, const char *, int, char *); |
| 16493 | | -#ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 16494 | | -SQLITE_PRIVATE void *sqlite3OsDlOpen(sqlite3_vfs *, const char *); |
| 16495 | | -SQLITE_PRIVATE void sqlite3OsDlError(sqlite3_vfs *, int, char *); |
| 16496 | | -SQLITE_PRIVATE void (*sqlite3OsDlSym(sqlite3_vfs *, void *, const char *))(void); |
| 16497 | | -SQLITE_PRIVATE void sqlite3OsDlClose(sqlite3_vfs *, void *); |
| 16498 | | -#endif /* SQLITE_OMIT_LOAD_EXTENSION */ |
| 16499 | | -SQLITE_PRIVATE int sqlite3OsRandomness(sqlite3_vfs *, int, char *); |
| 16500 | | -SQLITE_PRIVATE int sqlite3OsSleep(sqlite3_vfs *, int); |
| 16501 | | -SQLITE_PRIVATE int sqlite3OsGetLastError(sqlite3_vfs*); |
| 16502 | | -SQLITE_PRIVATE int sqlite3OsCurrentTimeInt64(sqlite3_vfs *, sqlite3_int64*); |
| 16503 | | - |
| 16504 | | -/* |
| 16505 | | -** Convenience functions for opening and closing files using |
| 16506 | | -** sqlite3_malloc() to obtain space for the file-handle structure. |
| 16507 | | -*/ |
| 16508 | | -SQLITE_PRIVATE int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*); |
| 16509 | | -SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *); |
| 16510 | | - |
| 16511 | | -#endif /* _SQLITE_OS_H_ */ |
| 16512 | | - |
| 16513 | | -/************** End of os.h **************************************************/ |
| 16514 | 16572 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| 16515 | 16573 | /************** Include mutex.h in the middle of sqliteInt.h *****************/ |
| 16516 | 16574 | /************** Begin file mutex.h *******************************************/ |
| 16517 | 16575 | /* |
| 16518 | 16576 | ** 2007 August 28 |
| | @@ -17100,10 +17158,11 @@ |
| 17100 | 17158 | #define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */ |
| 17101 | 17159 | #define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */ |
| 17102 | 17160 | #define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */ |
| 17103 | 17161 | #define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */ |
| 17104 | 17162 | /* TH3 expects this value ^^^^^^^^^^ See flatten04.test */ |
| 17163 | +#define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */ |
| 17105 | 17164 | #define SQLITE_AllOpts 0xffffffff /* All optimizations */ |
| 17106 | 17165 | |
| 17107 | 17166 | /* |
| 17108 | 17167 | ** Macros for testing whether or not optimizations are enabled or disabled. |
| 17109 | 17168 | */ |
| | @@ -17672,11 +17731,11 @@ |
| 17672 | 17731 | ** table support is omitted from the build. |
| 17673 | 17732 | */ |
| 17674 | 17733 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 17675 | 17734 | # define IsVirtual(X) ((X)->eTabType==TABTYP_VTAB) |
| 17676 | 17735 | # define ExprIsVtab(X) \ |
| 17677 | | - ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->eTabType==TABTYP_VTAB) |
| 17736 | + ((X)->op==TK_COLUMN && (X)->y.pTab->eTabType==TABTYP_VTAB) |
| 17678 | 17737 | #else |
| 17679 | 17738 | # define IsVirtual(X) 0 |
| 17680 | 17739 | # define ExprIsVtab(X) 0 |
| 17681 | 17740 | #endif |
| 17682 | 17741 | |
| | @@ -17889,13 +17948,25 @@ |
| 17889 | 17948 | ** Ex1.aCol[], hence Ex2.aiColumn[1]==0. |
| 17890 | 17949 | ** |
| 17891 | 17950 | ** The Index.onError field determines whether or not the indexed columns |
| 17892 | 17951 | ** must be unique and what to do if they are not. When Index.onError=OE_None, |
| 17893 | 17952 | ** it means this is not a unique index. Otherwise it is a unique index |
| 17894 | | -** and the value of Index.onError indicate the which conflict resolution |
| 17895 | | -** algorithm to employ whenever an attempt is made to insert a non-unique |
| 17953 | +** and the value of Index.onError indicates which conflict resolution |
| 17954 | +** algorithm to employ when an attempt is made to insert a non-unique |
| 17896 | 17955 | ** element. |
| 17956 | +** |
| 17957 | +** The colNotIdxed bitmask is used in combination with SrcItem.colUsed |
| 17958 | +** for a fast test to see if an index can serve as a covering index. |
| 17959 | +** colNotIdxed has a 1 bit for every column of the original table that |
| 17960 | +** is *not* available in the index. Thus the expression |
| 17961 | +** "colUsed & colNotIdxed" will be non-zero if the index is not a |
| 17962 | +** covering index. The most significant bit of of colNotIdxed will always |
| 17963 | +** be true (note-20221022-a). If a column beyond the 63rd column of the |
| 17964 | +** table is used, the "colUsed & colNotIdxed" test will always be non-zero |
| 17965 | +** and we have to assume either that the index is not covering, or use |
| 17966 | +** an alternative (slower) algorithm to determine whether or not |
| 17967 | +** the index is covering. |
| 17897 | 17968 | ** |
| 17898 | 17969 | ** While parsing a CREATE TABLE or CREATE INDEX statement in order to |
| 17899 | 17970 | ** generate VDBE code (as opposed to parsing one read from an sqlite_schema |
| 17900 | 17971 | ** table as part of parsing an existing database schema), transient instances |
| 17901 | 17972 | ** of this structure may be created. In this case the Index.tnum variable is |
| | @@ -17928,19 +17999,21 @@ |
| 17928 | 17999 | unsigned noSkipScan:1; /* Do not try to use skip-scan if true */ |
| 17929 | 18000 | unsigned hasStat1:1; /* aiRowLogEst values come from sqlite_stat1 */ |
| 17930 | 18001 | unsigned bNoQuery:1; /* Do not use this index to optimize queries */ |
| 17931 | 18002 | unsigned bAscKeyBug:1; /* True if the bba7b69f9849b5bf bug applies */ |
| 17932 | 18003 | unsigned bHasVCol:1; /* Index references one or more VIRTUAL columns */ |
| 18004 | + unsigned bHasExpr:1; /* Index contains an expression, either a literal |
| 18005 | + ** expression, or a reference to a VIRTUAL column */ |
| 17933 | 18006 | #ifdef SQLITE_ENABLE_STAT4 |
| 17934 | 18007 | int nSample; /* Number of elements in aSample[] */ |
| 17935 | 18008 | int nSampleCol; /* Size of IndexSample.anEq[] and so on */ |
| 17936 | 18009 | tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */ |
| 17937 | 18010 | IndexSample *aSample; /* Samples of the left-most key */ |
| 17938 | 18011 | tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this index */ |
| 17939 | 18012 | tRowcnt nRowEst0; /* Non-logarithmic number of rows in the index */ |
| 17940 | 18013 | #endif |
| 17941 | | - Bitmask colNotIdxed; /* 0 for unindexed columns in pTab */ |
| 18014 | + Bitmask colNotIdxed; /* Unindexed columns in pTab */ |
| 17942 | 18015 | }; |
| 17943 | 18016 | |
| 17944 | 18017 | /* |
| 17945 | 18018 | ** Allowed values for Index.idxType |
| 17946 | 18019 | */ |
| | @@ -18389,10 +18462,18 @@ |
| 18389 | 18462 | |
| 18390 | 18463 | /* |
| 18391 | 18464 | ** The SrcItem object represents a single term in the FROM clause of a query. |
| 18392 | 18465 | ** The SrcList object is mostly an array of SrcItems. |
| 18393 | 18466 | ** |
| 18467 | +** The jointype starts out showing the join type between the current table |
| 18468 | +** and the next table on the list. The parser builds the list this way. |
| 18469 | +** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each |
| 18470 | +** jointype expresses the join between the table and the previous table. |
| 18471 | +** |
| 18472 | +** In the colUsed field, the high-order bit (bit 63) is set if the table |
| 18473 | +** contains more than 63 columns and the 64-th or later column is used. |
| 18474 | +** |
| 18394 | 18475 | ** Union member validity: |
| 18395 | 18476 | ** |
| 18396 | 18477 | ** u1.zIndexedBy fg.isIndexedBy && !fg.isTabFunc |
| 18397 | 18478 | ** u1.pFuncArg fg.isTabFunc && !fg.isIndexedBy |
| 18398 | 18479 | ** u2.pIBIndex fg.isIndexedBy && !fg.isCte |
| | @@ -18428,18 +18509,18 @@ |
| 18428 | 18509 | int iCursor; /* The VDBE cursor number used to access this table */ |
| 18429 | 18510 | union { |
| 18430 | 18511 | Expr *pOn; /* fg.isUsing==0 => The ON clause of a join */ |
| 18431 | 18512 | IdList *pUsing; /* fg.isUsing==1 => The USING clause of a join */ |
| 18432 | 18513 | } u3; |
| 18433 | | - Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */ |
| 18514 | + Bitmask colUsed; /* Bit N set if column N used. Details above for N>62 */ |
| 18434 | 18515 | union { |
| 18435 | 18516 | char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */ |
| 18436 | 18517 | ExprList *pFuncArg; /* Arguments to table-valued-function */ |
| 18437 | 18518 | } u1; |
| 18438 | 18519 | union { |
| 18439 | 18520 | Index *pIBIndex; /* Index structure corresponding to u1.zIndexedBy */ |
| 18440 | | - CteUse *pCteUse; /* CTE Usage info info fg.isCte is true */ |
| 18521 | + CteUse *pCteUse; /* CTE Usage info when fg.isCte is true */ |
| 18441 | 18522 | } u2; |
| 18442 | 18523 | }; |
| 18443 | 18524 | |
| 18444 | 18525 | /* |
| 18445 | 18526 | ** The OnOrUsing object represents either an ON clause or a USING clause. |
| | @@ -18449,27 +18530,15 @@ |
| 18449 | 18530 | Expr *pOn; /* The ON clause of a join */ |
| 18450 | 18531 | IdList *pUsing; /* The USING clause of a join */ |
| 18451 | 18532 | }; |
| 18452 | 18533 | |
| 18453 | 18534 | /* |
| 18454 | | -** The following structure describes the FROM clause of a SELECT statement. |
| 18455 | | -** Each table or subquery in the FROM clause is a separate element of |
| 18456 | | -** the SrcList.a[] array. |
| 18457 | | -** |
| 18458 | | -** With the addition of multiple database support, the following structure |
| 18459 | | -** can also be used to describe a particular table such as the table that |
| 18460 | | -** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL, |
| 18461 | | -** such a table must be a simple name: ID. But in SQLite, the table can |
| 18462 | | -** now be identified by a database name, a dot, then the table name: ID.ID. |
| 18463 | | -** |
| 18464 | | -** The jointype starts out showing the join type between the current table |
| 18465 | | -** and the next table on the list. The parser builds the list this way. |
| 18466 | | -** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each |
| 18467 | | -** jointype expresses the join between the table and the previous table. |
| 18468 | | -** |
| 18469 | | -** In the colUsed field, the high-order bit (bit 63) is set if the table |
| 18470 | | -** contains more than 63 columns and the 64-th or later column is used. |
| 18535 | +** This object represents one or more tables that are the source of |
| 18536 | +** content for an SQL statement. For example, a single SrcList object |
| 18537 | +** is used to hold the FROM clause of a SELECT statement. SrcList also |
| 18538 | +** represents the target tables for DELETE, INSERT, and UPDATE statements. |
| 18539 | +** |
| 18471 | 18540 | */ |
| 18472 | 18541 | struct SrcList { |
| 18473 | 18542 | int nSrc; /* Number of tables or subqueries in the FROM clause */ |
| 18474 | 18543 | u32 nAlloc; /* Number of entries allocated in a[] below */ |
| 18475 | 18544 | SrcItem a[1]; /* One entry for each identifier on the list */ |
| | @@ -18875,10 +18944,32 @@ |
| 18875 | 18944 | # define DbMaskSet(M,I) (M)|=(((yDbMask)1)<<(I)) |
| 18876 | 18945 | # define DbMaskAllZero(M) (M)==0 |
| 18877 | 18946 | # define DbMaskNonZero(M) (M)!=0 |
| 18878 | 18947 | #endif |
| 18879 | 18948 | |
| 18949 | +/* |
| 18950 | +** For each index X that has as one of its arguments either an expression |
| 18951 | +** or the name of a virtual generated column, and if X is in scope such that |
| 18952 | +** the value of the expression can simply be read from the index, then |
| 18953 | +** there is an instance of this object on the Parse.pIdxExpr list. |
| 18954 | +** |
| 18955 | +** During code generation, while generating code to evaluate expressions, |
| 18956 | +** this list is consulted and if a matching expression is found, the value |
| 18957 | +** is read from the index rather than being recomputed. |
| 18958 | +*/ |
| 18959 | +struct IndexedExpr { |
| 18960 | + Expr *pExpr; /* The expression contained in the index */ |
| 18961 | + int iDataCur; /* The data cursor associated with the index */ |
| 18962 | + int iIdxCur; /* The index cursor */ |
| 18963 | + int iIdxCol; /* The index column that contains value of pExpr */ |
| 18964 | + u8 bMaybeNullRow; /* True if we need an OP_IfNullRow check */ |
| 18965 | + IndexedExpr *pIENext; /* Next in a list of all indexed expressions */ |
| 18966 | +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 18967 | + const char *zIdxName; /* Name of index, used only for bytecode comments */ |
| 18968 | +#endif |
| 18969 | +}; |
| 18970 | + |
| 18880 | 18971 | /* |
| 18881 | 18972 | ** An instance of the ParseCleanup object specifies an operation that |
| 18882 | 18973 | ** should be performed after parsing to deallocation resources obtained |
| 18883 | 18974 | ** during the parse and which are no longer needed. |
| 18884 | 18975 | */ |
| | @@ -18916,11 +19007,11 @@ |
| 18916 | 19007 | u8 isMultiWrite; /* True if statement may modify/insert multiple rows */ |
| 18917 | 19008 | u8 mayAbort; /* True if statement may throw an ABORT exception */ |
| 18918 | 19009 | u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */ |
| 18919 | 19010 | u8 okConstFactor; /* OK to factor out constants */ |
| 18920 | 19011 | u8 disableLookaside; /* Number of times lookaside has been disabled */ |
| 18921 | | - u8 disableVtab; /* Disable all virtual tables for this parse */ |
| 19012 | + u8 prepFlags; /* SQLITE_PREPARE_* flags */ |
| 18922 | 19013 | u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */ |
| 18923 | 19014 | #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST) |
| 18924 | 19015 | u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */ |
| 18925 | 19016 | #endif |
| 18926 | 19017 | int nRangeReg; /* Size of the temporary register block */ |
| | @@ -18933,10 +19024,11 @@ |
| 18933 | 19024 | ** of the base register during check-constraint eval */ |
| 18934 | 19025 | int nLabel; /* The *negative* of the number of labels used */ |
| 18935 | 19026 | int nLabelAlloc; /* Number of slots in aLabel */ |
| 18936 | 19027 | int *aLabel; /* Space to hold the labels */ |
| 18937 | 19028 | ExprList *pConstExpr;/* Constant expressions */ |
| 19029 | + IndexedExpr *pIdxExpr;/* List of expressions used by active indexes */ |
| 18938 | 19030 | Token constraintName;/* Name of the constraint currently being parsed */ |
| 18939 | 19031 | yDbMask writeMask; /* Start a write transaction on these databases */ |
| 18940 | 19032 | yDbMask cookieMask; /* Bitmask of schema verified databases */ |
| 18941 | 19033 | int regRowid; /* Register holding rowid of CREATE TABLE entry */ |
| 18942 | 19034 | int regRoot; /* Register holding root page number for new objects */ |
| | @@ -19368,19 +19460,19 @@ |
| 19368 | 19460 | SrcList *pSrcList; /* FROM clause */ |
| 19369 | 19461 | struct CCurHint *pCCurHint; /* Used by codeCursorHint() */ |
| 19370 | 19462 | struct RefSrcList *pRefSrcList; /* sqlite3ReferencesSrcList() */ |
| 19371 | 19463 | int *aiCol; /* array of column indexes */ |
| 19372 | 19464 | struct IdxCover *pIdxCover; /* Check for index coverage */ |
| 19373 | | - struct IdxExprTrans *pIdxTrans; /* Convert idxed expr to column */ |
| 19374 | 19465 | ExprList *pGroupBy; /* GROUP BY clause */ |
| 19375 | 19466 | Select *pSelect; /* HAVING to WHERE clause ctx */ |
| 19376 | 19467 | struct WindowRewrite *pRewrite; /* Window rewrite context */ |
| 19377 | 19468 | struct WhereConst *pConst; /* WHERE clause constants */ |
| 19378 | 19469 | struct RenameCtx *pRename; /* RENAME COLUMN context */ |
| 19379 | 19470 | struct Table *pTab; /* Table of generated column */ |
| 19471 | + struct CoveringIndexCheck *pCovIdxCk; /* Check for covering index */ |
| 19380 | 19472 | SrcItem *pSrcItem; /* A single FROM clause item */ |
| 19381 | | - DbFixer *pFix; |
| 19473 | + DbFixer *pFix; /* See sqlite3FixSelect() */ |
| 19382 | 19474 | } u; |
| 19383 | 19475 | }; |
| 19384 | 19476 | |
| 19385 | 19477 | /* |
| 19386 | 19478 | ** The following structure contains information used by the sqliteFix... |
| | @@ -19703,16 +19795,20 @@ |
| 19703 | 19795 | ** The alloca() routine never returns NULL. This will cause code paths |
| 19704 | 19796 | ** that deal with sqlite3StackAlloc() failures to be unreachable. |
| 19705 | 19797 | */ |
| 19706 | 19798 | #ifdef SQLITE_USE_ALLOCA |
| 19707 | 19799 | # define sqlite3StackAllocRaw(D,N) alloca(N) |
| 19800 | +# define sqlite3StackAllocRawNN(D,N) alloca(N) |
| 19708 | 19801 | # define sqlite3StackAllocZero(D,N) memset(alloca(N), 0, N) |
| 19709 | 19802 | # define sqlite3StackFree(D,P) |
| 19803 | +# define sqlite3StackFreeNN(D,P) |
| 19710 | 19804 | #else |
| 19711 | 19805 | # define sqlite3StackAllocRaw(D,N) sqlite3DbMallocRaw(D,N) |
| 19806 | +# define sqlite3StackAllocRawNN(D,N) sqlite3DbMallocRawNN(D,N) |
| 19712 | 19807 | # define sqlite3StackAllocZero(D,N) sqlite3DbMallocZero(D,N) |
| 19713 | 19808 | # define sqlite3StackFree(D,P) sqlite3DbFree(D,P) |
| 19809 | +# define sqlite3StackFreeNN(D,P) sqlite3DbFreeNN(D,P) |
| 19714 | 19810 | #endif |
| 19715 | 19811 | |
| 19716 | 19812 | /* Do not allow both MEMSYS5 and MEMSYS3 to be defined together. If they |
| 19717 | 19813 | ** are, disable MEMSYS3 |
| 19718 | 19814 | */ |
| | @@ -20324,11 +20420,10 @@ |
| 20324 | 20420 | #ifndef SQLITE_AMALGAMATION |
| 20325 | 20421 | SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[]; |
| 20326 | 20422 | SQLITE_PRIVATE const char sqlite3StrBINARY[]; |
| 20327 | 20423 | SQLITE_PRIVATE const unsigned char sqlite3StdTypeLen[]; |
| 20328 | 20424 | SQLITE_PRIVATE const char sqlite3StdTypeAffinity[]; |
| 20329 | | -SQLITE_PRIVATE const char sqlite3StdTypeMap[]; |
| 20330 | 20425 | SQLITE_PRIVATE const char *sqlite3StdType[]; |
| 20331 | 20426 | SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[]; |
| 20332 | 20427 | SQLITE_PRIVATE const unsigned char *sqlite3aLTb; |
| 20333 | 20428 | SQLITE_PRIVATE const unsigned char *sqlite3aEQb; |
| 20334 | 20429 | SQLITE_PRIVATE const unsigned char *sqlite3aGTb; |
| | @@ -20767,10 +20862,14 @@ |
| 20767 | 20862 | SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse*, Expr*); |
| 20768 | 20863 | |
| 20769 | 20864 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 20770 | 20865 | SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt); |
| 20771 | 20866 | #endif |
| 20867 | + |
| 20868 | +#if SQLITE_OS_UNIX && defined(SQLITE_OS_KV_OPTIONAL) |
| 20869 | +SQLITE_PRIVATE int sqlite3KvvfsInit(void); |
| 20870 | +#endif |
| 20772 | 20871 | |
| 20773 | 20872 | #endif /* SQLITEINT_H */ |
| 20774 | 20873 | |
| 20775 | 20874 | /************** End of sqliteInt.h *******************************************/ |
| 20776 | 20875 | /************** Begin file os_common.h ***************************************/ |
| | @@ -20999,11 +21098,11 @@ |
| 20999 | 21098 | /* |
| 21000 | 21099 | ** Include the configuration header output by 'configure' if we're using the |
| 21001 | 21100 | ** autoconf-based build |
| 21002 | 21101 | */ |
| 21003 | 21102 | #if defined(_HAVE_SQLITE_CONFIG_H) && !defined(SQLITECONFIG_H) |
| 21004 | | -/* #include "config.h" */ |
| 21103 | +/* #include "sqlite_cfg.h" */ |
| 21005 | 21104 | #define SQLITECONFIG_H 1 |
| 21006 | 21105 | #endif |
| 21007 | 21106 | |
| 21008 | 21107 | /* These macros are provided to "stringify" the value of the define |
| 21009 | 21108 | ** for those options in which the value is meaningful. */ |
| | @@ -21164,10 +21263,13 @@ |
| 21164 | 21263 | "DISABLE_PAGECACHE_OVERFLOW_STATS", |
| 21165 | 21264 | #endif |
| 21166 | 21265 | #ifdef SQLITE_DISABLE_SKIPAHEAD_DISTINCT |
| 21167 | 21266 | "DISABLE_SKIPAHEAD_DISTINCT", |
| 21168 | 21267 | #endif |
| 21268 | +#ifdef SQLITE_DQS |
| 21269 | + "DQS=" CTIMEOPT_VAL(SQLITE_DQS), |
| 21270 | +#endif |
| 21169 | 21271 | #ifdef SQLITE_ENABLE_8_3_NAMES |
| 21170 | 21272 | "ENABLE_8_3_NAMES=" CTIMEOPT_VAL(SQLITE_ENABLE_8_3_NAMES), |
| 21171 | 21273 | #endif |
| 21172 | 21274 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 21173 | 21275 | "ENABLE_API_ARMOR", |
| | @@ -22133,14 +22235,10 @@ |
| 22133 | 22235 | ** sqlite3StdTypeLen[] The length (in bytes) of each entry |
| 22134 | 22236 | ** in sqlite3StdType[]. |
| 22135 | 22237 | ** |
| 22136 | 22238 | ** sqlite3StdTypeAffinity[] The affinity associated with each entry |
| 22137 | 22239 | ** in sqlite3StdType[]. |
| 22138 | | -** |
| 22139 | | -** sqlite3StdTypeMap[] The type value (as returned from |
| 22140 | | -** sqlite3_column_type() or sqlite3_value_type()) |
| 22141 | | -** for each entry in sqlite3StdType[]. |
| 22142 | 22240 | */ |
| 22143 | 22241 | SQLITE_PRIVATE const unsigned char sqlite3StdTypeLen[] = { 3, 4, 3, 7, 4, 4 }; |
| 22144 | 22242 | SQLITE_PRIVATE const char sqlite3StdTypeAffinity[] = { |
| 22145 | 22243 | SQLITE_AFF_NUMERIC, |
| 22146 | 22244 | SQLITE_AFF_BLOB, |
| | @@ -22147,18 +22245,10 @@ |
| 22147 | 22245 | SQLITE_AFF_INTEGER, |
| 22148 | 22246 | SQLITE_AFF_INTEGER, |
| 22149 | 22247 | SQLITE_AFF_REAL, |
| 22150 | 22248 | SQLITE_AFF_TEXT |
| 22151 | 22249 | }; |
| 22152 | | -SQLITE_PRIVATE const char sqlite3StdTypeMap[] = { |
| 22153 | | - 0, |
| 22154 | | - SQLITE_BLOB, |
| 22155 | | - SQLITE_INTEGER, |
| 22156 | | - SQLITE_INTEGER, |
| 22157 | | - SQLITE_FLOAT, |
| 22158 | | - SQLITE_TEXT |
| 22159 | | -}; |
| 22160 | 22250 | SQLITE_PRIVATE const char *sqlite3StdType[] = { |
| 22161 | 22251 | "ANY", |
| 22162 | 22252 | "BLOB", |
| 22163 | 22253 | "INT", |
| 22164 | 22254 | "INTEGER", |
| | @@ -24740,13 +24830,15 @@ |
| 24740 | 24830 | DO_OS_MALLOC_TEST(id); |
| 24741 | 24831 | return id->pMethods->xFileSize(id, pSize); |
| 24742 | 24832 | } |
| 24743 | 24833 | SQLITE_PRIVATE int sqlite3OsLock(sqlite3_file *id, int lockType){ |
| 24744 | 24834 | DO_OS_MALLOC_TEST(id); |
| 24835 | + assert( lockType>=SQLITE_LOCK_SHARED && lockType<=SQLITE_LOCK_EXCLUSIVE ); |
| 24745 | 24836 | return id->pMethods->xLock(id, lockType); |
| 24746 | 24837 | } |
| 24747 | 24838 | SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file *id, int lockType){ |
| 24839 | + assert( lockType==SQLITE_LOCK_NONE || lockType==SQLITE_LOCK_SHARED ); |
| 24748 | 24840 | return id->pMethods->xUnlock(id, lockType); |
| 24749 | 24841 | } |
| 24750 | 24842 | SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut){ |
| 24751 | 24843 | DO_OS_MALLOC_TEST(id); |
| 24752 | 24844 | return id->pMethods->xCheckReservedLock(id, pResOut); |
| | @@ -35382,11 +35474,11 @@ |
| 35382 | 35474 | /* 13 */ "MustBeInt" OpHelp(""), |
| 35383 | 35475 | /* 14 */ "Jump" OpHelp(""), |
| 35384 | 35476 | /* 15 */ "Once" OpHelp(""), |
| 35385 | 35477 | /* 16 */ "If" OpHelp(""), |
| 35386 | 35478 | /* 17 */ "IfNot" OpHelp(""), |
| 35387 | | - /* 18 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"), |
| 35479 | + /* 18 */ "IsType" OpHelp("if typeof(P1.P3) in P5 goto P2"), |
| 35388 | 35480 | /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"), |
| 35389 | 35481 | /* 20 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"), |
| 35390 | 35482 | /* 21 */ "SeekLT" OpHelp("key=r[P3@P4]"), |
| 35391 | 35483 | /* 22 */ "SeekLE" OpHelp("key=r[P3@P4]"), |
| 35392 | 35484 | /* 23 */ "SeekGE" OpHelp("key=r[P3@P4]"), |
| | @@ -35557,10 +35649,982 @@ |
| 35557 | 35649 | return azName[i]; |
| 35558 | 35650 | } |
| 35559 | 35651 | #endif |
| 35560 | 35652 | |
| 35561 | 35653 | /************** End of opcodes.c *********************************************/ |
| 35654 | +/************** Begin file os_kv.c *******************************************/ |
| 35655 | +/* |
| 35656 | +** 2022-09-06 |
| 35657 | +** |
| 35658 | +** The author disclaims copyright to this source code. In place of |
| 35659 | +** a legal notice, here is a blessing: |
| 35660 | +** |
| 35661 | +** May you do good and not evil. |
| 35662 | +** May you find forgiveness for yourself and forgive others. |
| 35663 | +** May you share freely, never taking more than you give. |
| 35664 | +** |
| 35665 | +****************************************************************************** |
| 35666 | +** |
| 35667 | +** This file contains an experimental VFS layer that operates on a |
| 35668 | +** Key/Value storage engine where both keys and values must be pure |
| 35669 | +** text. |
| 35670 | +*/ |
| 35671 | +/* #include <sqliteInt.h> */ |
| 35672 | +#if SQLITE_OS_KV || (SQLITE_OS_UNIX && defined(SQLITE_OS_KV_OPTIONAL)) |
| 35673 | + |
| 35674 | +/***************************************************************************** |
| 35675 | +** Debugging logic |
| 35676 | +*/ |
| 35677 | + |
| 35678 | +/* SQLITE_KV_TRACE() is used for tracing calls to kvstorage routines. */ |
| 35679 | +#if 0 |
| 35680 | +#define SQLITE_KV_TRACE(X) printf X |
| 35681 | +#else |
| 35682 | +#define SQLITE_KV_TRACE(X) |
| 35683 | +#endif |
| 35684 | + |
| 35685 | +/* SQLITE_KV_LOG() is used for tracing calls to the VFS interface */ |
| 35686 | +#if 0 |
| 35687 | +#define SQLITE_KV_LOG(X) printf X |
| 35688 | +#else |
| 35689 | +#define SQLITE_KV_LOG(X) |
| 35690 | +#endif |
| 35691 | + |
| 35692 | + |
| 35693 | +/* |
| 35694 | +** Forward declaration of objects used by this VFS implementation |
| 35695 | +*/ |
| 35696 | +typedef struct KVVfsFile KVVfsFile; |
| 35697 | + |
| 35698 | +/* A single open file. There are only two files represented by this |
| 35699 | +** VFS - the database and the rollback journal. |
| 35700 | +*/ |
| 35701 | +struct KVVfsFile { |
| 35702 | + sqlite3_file base; /* IO methods */ |
| 35703 | + const char *zClass; /* Storage class */ |
| 35704 | + int isJournal; /* True if this is a journal file */ |
| 35705 | + unsigned int nJrnl; /* Space allocated for aJrnl[] */ |
| 35706 | + char *aJrnl; /* Journal content */ |
| 35707 | + int szPage; /* Last known page size */ |
| 35708 | + sqlite3_int64 szDb; /* Database file size. -1 means unknown */ |
| 35709 | +}; |
| 35710 | + |
| 35711 | +/* |
| 35712 | +** Methods for KVVfsFile |
| 35713 | +*/ |
| 35714 | +static int kvvfsClose(sqlite3_file*); |
| 35715 | +static int kvvfsReadDb(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); |
| 35716 | +static int kvvfsReadJrnl(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); |
| 35717 | +static int kvvfsWriteDb(sqlite3_file*,const void*,int iAmt, sqlite3_int64); |
| 35718 | +static int kvvfsWriteJrnl(sqlite3_file*,const void*,int iAmt, sqlite3_int64); |
| 35719 | +static int kvvfsTruncateDb(sqlite3_file*, sqlite3_int64 size); |
| 35720 | +static int kvvfsTruncateJrnl(sqlite3_file*, sqlite3_int64 size); |
| 35721 | +static int kvvfsSyncDb(sqlite3_file*, int flags); |
| 35722 | +static int kvvfsSyncJrnl(sqlite3_file*, int flags); |
| 35723 | +static int kvvfsFileSizeDb(sqlite3_file*, sqlite3_int64 *pSize); |
| 35724 | +static int kvvfsFileSizeJrnl(sqlite3_file*, sqlite3_int64 *pSize); |
| 35725 | +static int kvvfsLock(sqlite3_file*, int); |
| 35726 | +static int kvvfsUnlock(sqlite3_file*, int); |
| 35727 | +static int kvvfsCheckReservedLock(sqlite3_file*, int *pResOut); |
| 35728 | +static int kvvfsFileControlDb(sqlite3_file*, int op, void *pArg); |
| 35729 | +static int kvvfsFileControlJrnl(sqlite3_file*, int op, void *pArg); |
| 35730 | +static int kvvfsSectorSize(sqlite3_file*); |
| 35731 | +static int kvvfsDeviceCharacteristics(sqlite3_file*); |
| 35732 | + |
| 35733 | +/* |
| 35734 | +** Methods for sqlite3_vfs |
| 35735 | +*/ |
| 35736 | +static int kvvfsOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *); |
| 35737 | +static int kvvfsDelete(sqlite3_vfs*, const char *zName, int syncDir); |
| 35738 | +static int kvvfsAccess(sqlite3_vfs*, const char *zName, int flags, int *); |
| 35739 | +static int kvvfsFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut); |
| 35740 | +static void *kvvfsDlOpen(sqlite3_vfs*, const char *zFilename); |
| 35741 | +static int kvvfsRandomness(sqlite3_vfs*, int nByte, char *zOut); |
| 35742 | +static int kvvfsSleep(sqlite3_vfs*, int microseconds); |
| 35743 | +static int kvvfsCurrentTime(sqlite3_vfs*, double*); |
| 35744 | +static int kvvfsCurrentTimeInt64(sqlite3_vfs*, sqlite3_int64*); |
| 35745 | + |
| 35746 | +static sqlite3_vfs sqlite3OsKvvfsObject = { |
| 35747 | + 1, /* iVersion */ |
| 35748 | + sizeof(KVVfsFile), /* szOsFile */ |
| 35749 | + 1024, /* mxPathname */ |
| 35750 | + 0, /* pNext */ |
| 35751 | + "kvvfs", /* zName */ |
| 35752 | + 0, /* pAppData */ |
| 35753 | + kvvfsOpen, /* xOpen */ |
| 35754 | + kvvfsDelete, /* xDelete */ |
| 35755 | + kvvfsAccess, /* xAccess */ |
| 35756 | + kvvfsFullPathname, /* xFullPathname */ |
| 35757 | + kvvfsDlOpen, /* xDlOpen */ |
| 35758 | + 0, /* xDlError */ |
| 35759 | + 0, /* xDlSym */ |
| 35760 | + 0, /* xDlClose */ |
| 35761 | + kvvfsRandomness, /* xRandomness */ |
| 35762 | + kvvfsSleep, /* xSleep */ |
| 35763 | + kvvfsCurrentTime, /* xCurrentTime */ |
| 35764 | + 0, /* xGetLastError */ |
| 35765 | + kvvfsCurrentTimeInt64 /* xCurrentTimeInt64 */ |
| 35766 | +}; |
| 35767 | + |
| 35768 | +/* Methods for sqlite3_file objects referencing a database file |
| 35769 | +*/ |
| 35770 | +static sqlite3_io_methods kvvfs_db_io_methods = { |
| 35771 | + 1, /* iVersion */ |
| 35772 | + kvvfsClose, /* xClose */ |
| 35773 | + kvvfsReadDb, /* xRead */ |
| 35774 | + kvvfsWriteDb, /* xWrite */ |
| 35775 | + kvvfsTruncateDb, /* xTruncate */ |
| 35776 | + kvvfsSyncDb, /* xSync */ |
| 35777 | + kvvfsFileSizeDb, /* xFileSize */ |
| 35778 | + kvvfsLock, /* xLock */ |
| 35779 | + kvvfsUnlock, /* xUnlock */ |
| 35780 | + kvvfsCheckReservedLock, /* xCheckReservedLock */ |
| 35781 | + kvvfsFileControlDb, /* xFileControl */ |
| 35782 | + kvvfsSectorSize, /* xSectorSize */ |
| 35783 | + kvvfsDeviceCharacteristics, /* xDeviceCharacteristics */ |
| 35784 | + 0, /* xShmMap */ |
| 35785 | + 0, /* xShmLock */ |
| 35786 | + 0, /* xShmBarrier */ |
| 35787 | + 0, /* xShmUnmap */ |
| 35788 | + 0, /* xFetch */ |
| 35789 | + 0 /* xUnfetch */ |
| 35790 | +}; |
| 35791 | + |
| 35792 | +/* Methods for sqlite3_file objects referencing a rollback journal |
| 35793 | +*/ |
| 35794 | +static sqlite3_io_methods kvvfs_jrnl_io_methods = { |
| 35795 | + 1, /* iVersion */ |
| 35796 | + kvvfsClose, /* xClose */ |
| 35797 | + kvvfsReadJrnl, /* xRead */ |
| 35798 | + kvvfsWriteJrnl, /* xWrite */ |
| 35799 | + kvvfsTruncateJrnl, /* xTruncate */ |
| 35800 | + kvvfsSyncJrnl, /* xSync */ |
| 35801 | + kvvfsFileSizeJrnl, /* xFileSize */ |
| 35802 | + kvvfsLock, /* xLock */ |
| 35803 | + kvvfsUnlock, /* xUnlock */ |
| 35804 | + kvvfsCheckReservedLock, /* xCheckReservedLock */ |
| 35805 | + kvvfsFileControlJrnl, /* xFileControl */ |
| 35806 | + kvvfsSectorSize, /* xSectorSize */ |
| 35807 | + kvvfsDeviceCharacteristics, /* xDeviceCharacteristics */ |
| 35808 | + 0, /* xShmMap */ |
| 35809 | + 0, /* xShmLock */ |
| 35810 | + 0, /* xShmBarrier */ |
| 35811 | + 0, /* xShmUnmap */ |
| 35812 | + 0, /* xFetch */ |
| 35813 | + 0 /* xUnfetch */ |
| 35814 | +}; |
| 35815 | + |
| 35816 | +/****** Storage subsystem **************************************************/ |
| 35817 | +#include <sys/types.h> |
| 35818 | +#include <sys/stat.h> |
| 35819 | +#include <unistd.h> |
| 35820 | + |
| 35821 | +/* Forward declarations for the low-level storage engine |
| 35822 | +*/ |
| 35823 | +static int kvstorageWrite(const char*, const char *zKey, const char *zData); |
| 35824 | +static int kvstorageDelete(const char*, const char *zKey); |
| 35825 | +static int kvstorageRead(const char*, const char *zKey, char *zBuf, int nBuf); |
| 35826 | +#define KVSTORAGE_KEY_SZ 32 |
| 35827 | + |
| 35828 | +/* Expand the key name with an appropriate prefix and put the result |
| 35829 | +** zKeyOut[]. The zKeyOut[] buffer is assumed to hold at least |
| 35830 | +** KVSTORAGE_KEY_SZ bytes. |
| 35831 | +*/ |
| 35832 | +static void kvstorageMakeKey( |
| 35833 | + const char *zClass, |
| 35834 | + const char *zKeyIn, |
| 35835 | + char *zKeyOut |
| 35836 | +){ |
| 35837 | + sqlite3_snprintf(KVSTORAGE_KEY_SZ, zKeyOut, "kvvfs-%s-%s", zClass, zKeyIn); |
| 35838 | +} |
| 35839 | + |
| 35840 | +/* Write content into a key. zClass is the particular namespace of the |
| 35841 | +** underlying key/value store to use - either "local" or "session". |
| 35842 | +** |
| 35843 | +** Both zKey and zData are zero-terminated pure text strings. |
| 35844 | +** |
| 35845 | +** Return the number of errors. |
| 35846 | +*/ |
| 35847 | +static int kvstorageWrite( |
| 35848 | + const char *zClass, |
| 35849 | + const char *zKey, |
| 35850 | + const char *zData |
| 35851 | +){ |
| 35852 | + FILE *fd; |
| 35853 | + char zXKey[KVSTORAGE_KEY_SZ]; |
| 35854 | + kvstorageMakeKey(zClass, zKey, zXKey); |
| 35855 | + fd = fopen(zXKey, "wb"); |
| 35856 | + if( fd ){ |
| 35857 | + SQLITE_KV_TRACE(("KVVFS-WRITE %-15s (%d) %.50s%s\n", zXKey, |
| 35858 | + (int)strlen(zData), zData, |
| 35859 | + strlen(zData)>50 ? "..." : "")); |
| 35860 | + fputs(zData, fd); |
| 35861 | + fclose(fd); |
| 35862 | + return 0; |
| 35863 | + }else{ |
| 35864 | + return 1; |
| 35865 | + } |
| 35866 | +} |
| 35867 | + |
| 35868 | +/* Delete a key (with its corresponding data) from the key/value |
| 35869 | +** namespace given by zClass. If the key does not previously exist, |
| 35870 | +** this routine is a no-op. |
| 35871 | +*/ |
| 35872 | +static int kvstorageDelete(const char *zClass, const char *zKey){ |
| 35873 | + char zXKey[KVSTORAGE_KEY_SZ]; |
| 35874 | + kvstorageMakeKey(zClass, zKey, zXKey); |
| 35875 | + unlink(zXKey); |
| 35876 | + SQLITE_KV_TRACE(("KVVFS-DELETE %-15s\n", zXKey)); |
| 35877 | + return 0; |
| 35878 | +} |
| 35879 | + |
| 35880 | +/* Read the value associated with a zKey from the key/value namespace given |
| 35881 | +** by zClass and put the text data associated with that key in the first |
| 35882 | +** nBuf bytes of zBuf[]. The value might be truncated if zBuf is not large |
| 35883 | +** enough to hold it all. The value put into zBuf must always be zero |
| 35884 | +** terminated, even if it gets truncated because nBuf is not large enough. |
| 35885 | +** |
| 35886 | +** Return the total number of bytes in the data, without truncation, and |
| 35887 | +** not counting the final zero terminator. Return -1 if the key does |
| 35888 | +** not exist. |
| 35889 | +** |
| 35890 | +** If nBuf<=0 then this routine simply returns the size of the data without |
| 35891 | +** actually reading it. |
| 35892 | +*/ |
| 35893 | +static int kvstorageRead( |
| 35894 | + const char *zClass, |
| 35895 | + const char *zKey, |
| 35896 | + char *zBuf, |
| 35897 | + int nBuf |
| 35898 | +){ |
| 35899 | + FILE *fd; |
| 35900 | + struct stat buf; |
| 35901 | + char zXKey[KVSTORAGE_KEY_SZ]; |
| 35902 | + kvstorageMakeKey(zClass, zKey, zXKey); |
| 35903 | + if( access(zXKey, R_OK)!=0 |
| 35904 | + || stat(zXKey, &buf)!=0 |
| 35905 | + || !S_ISREG(buf.st_mode) |
| 35906 | + ){ |
| 35907 | + SQLITE_KV_TRACE(("KVVFS-READ %-15s (-1)\n", zXKey)); |
| 35908 | + return -1; |
| 35909 | + } |
| 35910 | + if( nBuf<=0 ){ |
| 35911 | + return (int)buf.st_size; |
| 35912 | + }else if( nBuf==1 ){ |
| 35913 | + zBuf[0] = 0; |
| 35914 | + SQLITE_KV_TRACE(("KVVFS-READ %-15s (%d)\n", zXKey, |
| 35915 | + (int)buf.st_size)); |
| 35916 | + return (int)buf.st_size; |
| 35917 | + } |
| 35918 | + if( nBuf > buf.st_size + 1 ){ |
| 35919 | + nBuf = buf.st_size + 1; |
| 35920 | + } |
| 35921 | + fd = fopen(zXKey, "rb"); |
| 35922 | + if( fd==0 ){ |
| 35923 | + SQLITE_KV_TRACE(("KVVFS-READ %-15s (-1)\n", zXKey)); |
| 35924 | + return -1; |
| 35925 | + }else{ |
| 35926 | + sqlite3_int64 n = fread(zBuf, 1, nBuf-1, fd); |
| 35927 | + fclose(fd); |
| 35928 | + zBuf[n] = 0; |
| 35929 | + SQLITE_KV_TRACE(("KVVFS-READ %-15s (%lld) %.50s%s\n", zXKey, |
| 35930 | + n, zBuf, n>50 ? "..." : "")); |
| 35931 | + return (int)n; |
| 35932 | + } |
| 35933 | +} |
| 35934 | + |
| 35935 | +/* |
| 35936 | +** An internal level of indirection which enables us to replace the |
| 35937 | +** kvvfs i/o methods with JavaScript implementations in WASM builds. |
| 35938 | +** Maintenance reminder: if this struct changes in any way, the JSON |
| 35939 | +** rendering of its structure must be updated in |
| 35940 | +** sqlite3_wasm_enum_json(). There are no binary compatibility |
| 35941 | +** concerns, so it does not need an iVersion member. This file is |
| 35942 | +** necessarily always compiled together with sqlite3_wasm_enum_json(), |
| 35943 | +** and JS code dynamically creates the mapping of members based on |
| 35944 | +** that JSON description. |
| 35945 | +*/ |
| 35946 | +typedef struct sqlite3_kvvfs_methods sqlite3_kvvfs_methods; |
| 35947 | +struct sqlite3_kvvfs_methods { |
| 35948 | + int (*xRead)(const char *zClass, const char *zKey, char *zBuf, int nBuf); |
| 35949 | + int (*xWrite)(const char *zClass, const char *zKey, const char *zData); |
| 35950 | + int (*xDelete)(const char *zClass, const char *zKey); |
| 35951 | + const int nKeySize; |
| 35952 | +}; |
| 35953 | + |
| 35954 | +/* |
| 35955 | +** This object holds the kvvfs I/O methods which may be swapped out |
| 35956 | +** for JavaScript-side implementations in WASM builds. In such builds |
| 35957 | +** it cannot be const, but in native builds it should be so that |
| 35958 | +** the compiler can hopefully optimize this level of indirection out. |
| 35959 | +** That said, kvvfs is intended primarily for use in WASM builds. |
| 35960 | +** |
| 35961 | +** Note that this is not explicitly flagged as static because the |
| 35962 | +** amalgamation build will tag it with SQLITE_PRIVATE. |
| 35963 | +*/ |
| 35964 | +#ifndef SQLITE_WASM |
| 35965 | +const |
| 35966 | +#endif |
| 35967 | +SQLITE_PRIVATE sqlite3_kvvfs_methods sqlite3KvvfsMethods = { |
| 35968 | +kvstorageRead, |
| 35969 | +kvstorageWrite, |
| 35970 | +kvstorageDelete, |
| 35971 | +KVSTORAGE_KEY_SZ |
| 35972 | +}; |
| 35973 | + |
| 35974 | +/****** Utility subroutines ************************************************/ |
| 35975 | + |
| 35976 | +/* |
| 35977 | +** Encode binary into the text encoded used to persist on disk. |
| 35978 | +** The output text is stored in aOut[], which must be at least |
| 35979 | +** nData+1 bytes in length. |
| 35980 | +** |
| 35981 | +** Return the actual length of the encoded text, not counting the |
| 35982 | +** zero terminator at the end. |
| 35983 | +** |
| 35984 | +** Encoding format |
| 35985 | +** --------------- |
| 35986 | +** |
| 35987 | +** * Non-zero bytes are encoded as upper-case hexadecimal |
| 35988 | +** |
| 35989 | +** * A sequence of one or more zero-bytes that are not at the |
| 35990 | +** beginning of the buffer are encoded as a little-endian |
| 35991 | +** base-26 number using a..z. "a" means 0. "b" means 1, |
| 35992 | +** "z" means 25. "ab" means 26. "ac" means 52. And so forth. |
| 35993 | +** |
| 35994 | +** * Because there is no overlap between the encoding characters |
| 35995 | +** of hexadecimal and base-26 numbers, it is always clear where |
| 35996 | +** one stops and the next begins. |
| 35997 | +*/ |
| 35998 | +static int kvvfsEncode(const char *aData, int nData, char *aOut){ |
| 35999 | + int i, j; |
| 36000 | + const unsigned char *a = (const unsigned char*)aData; |
| 36001 | + for(i=j=0; i<nData; i++){ |
| 36002 | + unsigned char c = a[i]; |
| 36003 | + if( c!=0 ){ |
| 36004 | + aOut[j++] = "0123456789ABCDEF"[c>>4]; |
| 36005 | + aOut[j++] = "0123456789ABCDEF"[c&0xf]; |
| 36006 | + }else{ |
| 36007 | + /* A sequence of 1 or more zeros is stored as a little-endian |
| 36008 | + ** base-26 number using a..z as the digits. So one zero is "b". |
| 36009 | + ** Two zeros is "c". 25 zeros is "z", 26 zeros is "ab", 27 is "bb", |
| 36010 | + ** and so forth. |
| 36011 | + */ |
| 36012 | + int k; |
| 36013 | + for(k=1; i+k<nData && a[i+k]==0; k++){} |
| 36014 | + i += k-1; |
| 36015 | + while( k>0 ){ |
| 36016 | + aOut[j++] = 'a'+(k%26); |
| 36017 | + k /= 26; |
| 36018 | + } |
| 36019 | + } |
| 36020 | + } |
| 36021 | + aOut[j] = 0; |
| 36022 | + return j; |
| 36023 | +} |
| 36024 | + |
| 36025 | +static const signed char kvvfsHexValue[256] = { |
| 36026 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 36027 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 36028 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 36029 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, |
| 36030 | + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 36031 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 36032 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 36033 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 36034 | + |
| 36035 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 36036 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 36037 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 36038 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 36039 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 36040 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 36041 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 36042 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 |
| 36043 | +}; |
| 36044 | + |
| 36045 | +/* |
| 36046 | +** Decode the text encoding back to binary. The binary content is |
| 36047 | +** written into pOut, which must be at least nOut bytes in length. |
| 36048 | +** |
| 36049 | +** The return value is the number of bytes actually written into aOut[]. |
| 36050 | +*/ |
| 36051 | +static int kvvfsDecode(const char *a, char *aOut, int nOut){ |
| 36052 | + int i, j; |
| 36053 | + int c; |
| 36054 | + const unsigned char *aIn = (const unsigned char*)a; |
| 36055 | + i = 0; |
| 36056 | + j = 0; |
| 36057 | + while( 1 ){ |
| 36058 | + c = kvvfsHexValue[aIn[i]]; |
| 36059 | + if( c<0 ){ |
| 36060 | + int n = 0; |
| 36061 | + int mult = 1; |
| 36062 | + c = aIn[i]; |
| 36063 | + if( c==0 ) break; |
| 36064 | + while( c>='a' && c<='z' ){ |
| 36065 | + n += (c - 'a')*mult; |
| 36066 | + mult *= 26; |
| 36067 | + c = aIn[++i]; |
| 36068 | + } |
| 36069 | + if( j+n>nOut ) return -1; |
| 36070 | + memset(&aOut[j], 0, n); |
| 36071 | + j += n; |
| 36072 | + c = aIn[i]; |
| 36073 | + if( c==0 ) break; |
| 36074 | + }else{ |
| 36075 | + aOut[j] = c<<4; |
| 36076 | + c = kvvfsHexValue[aIn[++i]]; |
| 36077 | + if( c<0 ) break; |
| 36078 | + aOut[j++] += c; |
| 36079 | + i++; |
| 36080 | + } |
| 36081 | + } |
| 36082 | + return j; |
| 36083 | +} |
| 36084 | + |
| 36085 | +/* |
| 36086 | +** Decode a complete journal file. Allocate space in pFile->aJrnl |
| 36087 | +** and store the decoding there. Or leave pFile->aJrnl set to NULL |
| 36088 | +** if an error is encountered. |
| 36089 | +** |
| 36090 | +** The first few characters of the text encoding will be a little-endian |
| 36091 | +** base-26 number (digits a..z) that is the total number of bytes |
| 36092 | +** in the decoded journal file image. This base-26 number is followed |
| 36093 | +** by a single space, then the encoding of the journal. The space |
| 36094 | +** separator is required to act as a terminator for the base-26 number. |
| 36095 | +*/ |
| 36096 | +static void kvvfsDecodeJournal( |
| 36097 | + KVVfsFile *pFile, /* Store decoding in pFile->aJrnl */ |
| 36098 | + const char *zTxt, /* Text encoding. Zero-terminated */ |
| 36099 | + int nTxt /* Bytes in zTxt, excluding zero terminator */ |
| 36100 | +){ |
| 36101 | + unsigned int n = 0; |
| 36102 | + int c, i, mult; |
| 36103 | + i = 0; |
| 36104 | + mult = 1; |
| 36105 | + while( (c = zTxt[i++])>='a' && c<='z' ){ |
| 36106 | + n += (zTxt[i] - 'a')*mult; |
| 36107 | + mult *= 26; |
| 36108 | + } |
| 36109 | + sqlite3_free(pFile->aJrnl); |
| 36110 | + pFile->aJrnl = sqlite3_malloc64( n ); |
| 36111 | + if( pFile->aJrnl==0 ){ |
| 36112 | + pFile->nJrnl = 0; |
| 36113 | + return; |
| 36114 | + } |
| 36115 | + pFile->nJrnl = n; |
| 36116 | + n = kvvfsDecode(zTxt+i, pFile->aJrnl, pFile->nJrnl); |
| 36117 | + if( n<pFile->nJrnl ){ |
| 36118 | + sqlite3_free(pFile->aJrnl); |
| 36119 | + pFile->aJrnl = 0; |
| 36120 | + pFile->nJrnl = 0; |
| 36121 | + } |
| 36122 | +} |
| 36123 | + |
| 36124 | +/* |
| 36125 | +** Read or write the "sz" element, containing the database file size. |
| 36126 | +*/ |
| 36127 | +static sqlite3_int64 kvvfsReadFileSize(KVVfsFile *pFile){ |
| 36128 | + char zData[50]; |
| 36129 | + zData[0] = 0; |
| 36130 | + sqlite3KvvfsMethods.xRead(pFile->zClass, "sz", zData, sizeof(zData)-1); |
| 36131 | + return strtoll(zData, 0, 0); |
| 36132 | +} |
| 36133 | +static int kvvfsWriteFileSize(KVVfsFile *pFile, sqlite3_int64 sz){ |
| 36134 | + char zData[50]; |
| 36135 | + sqlite3_snprintf(sizeof(zData), zData, "%lld", sz); |
| 36136 | + return sqlite3KvvfsMethods.xWrite(pFile->zClass, "sz", zData); |
| 36137 | +} |
| 36138 | + |
| 36139 | +/****** sqlite3_io_methods methods ******************************************/ |
| 36140 | + |
| 36141 | +/* |
| 36142 | +** Close an kvvfs-file. |
| 36143 | +*/ |
| 36144 | +static int kvvfsClose(sqlite3_file *pProtoFile){ |
| 36145 | + KVVfsFile *pFile = (KVVfsFile *)pProtoFile; |
| 36146 | + |
| 36147 | + SQLITE_KV_LOG(("xClose %s %s\n", pFile->zClass, |
| 36148 | + pFile->isJournal ? "journal" : "db")); |
| 36149 | + sqlite3_free(pFile->aJrnl); |
| 36150 | + return SQLITE_OK; |
| 36151 | +} |
| 36152 | + |
| 36153 | +/* |
| 36154 | +** Read from the -journal file. |
| 36155 | +*/ |
| 36156 | +static int kvvfsReadJrnl( |
| 36157 | + sqlite3_file *pProtoFile, |
| 36158 | + void *zBuf, |
| 36159 | + int iAmt, |
| 36160 | + sqlite_int64 iOfst |
| 36161 | +){ |
| 36162 | + KVVfsFile *pFile = (KVVfsFile*)pProtoFile; |
| 36163 | + assert( pFile->isJournal ); |
| 36164 | + SQLITE_KV_LOG(("xRead('%s-journal',%d,%lld)\n", pFile->zClass, iAmt, iOfst)); |
| 36165 | + if( pFile->aJrnl==0 ){ |
| 36166 | + int szTxt = kvstorageRead(pFile->zClass, "jrnl", 0, 0); |
| 36167 | + char *aTxt; |
| 36168 | + if( szTxt<=4 ){ |
| 36169 | + return SQLITE_IOERR; |
| 36170 | + } |
| 36171 | + aTxt = sqlite3_malloc64( szTxt+1 ); |
| 36172 | + if( aTxt==0 ) return SQLITE_NOMEM; |
| 36173 | + kvstorageRead(pFile->zClass, "jrnl", aTxt, szTxt+1); |
| 36174 | + kvvfsDecodeJournal(pFile, aTxt, szTxt); |
| 36175 | + sqlite3_free(aTxt); |
| 36176 | + if( pFile->aJrnl==0 ) return SQLITE_IOERR; |
| 36177 | + } |
| 36178 | + if( iOfst+iAmt>pFile->nJrnl ){ |
| 36179 | + return SQLITE_IOERR_SHORT_READ; |
| 36180 | + } |
| 36181 | + memcpy(zBuf, pFile->aJrnl+iOfst, iAmt); |
| 36182 | + return SQLITE_OK; |
| 36183 | +} |
| 36184 | + |
| 36185 | +/* |
| 36186 | +** Read from the database file. |
| 36187 | +*/ |
| 36188 | +static int kvvfsReadDb( |
| 36189 | + sqlite3_file *pProtoFile, |
| 36190 | + void *zBuf, |
| 36191 | + int iAmt, |
| 36192 | + sqlite_int64 iOfst |
| 36193 | +){ |
| 36194 | + KVVfsFile *pFile = (KVVfsFile*)pProtoFile; |
| 36195 | + unsigned int pgno; |
| 36196 | + int got, n; |
| 36197 | + char zKey[30]; |
| 36198 | + char aData[133073]; |
| 36199 | + assert( iOfst>=0 ); |
| 36200 | + assert( iAmt>=0 ); |
| 36201 | + SQLITE_KV_LOG(("xRead('%s-db',%d,%lld)\n", pFile->zClass, iAmt, iOfst)); |
| 36202 | + if( iOfst+iAmt>=512 ){ |
| 36203 | + if( (iOfst % iAmt)!=0 ){ |
| 36204 | + return SQLITE_IOERR_READ; |
| 36205 | + } |
| 36206 | + if( (iAmt & (iAmt-1))!=0 || iAmt<512 || iAmt>65536 ){ |
| 36207 | + return SQLITE_IOERR_READ; |
| 36208 | + } |
| 36209 | + pFile->szPage = iAmt; |
| 36210 | + pgno = 1 + iOfst/iAmt; |
| 36211 | + }else{ |
| 36212 | + pgno = 1; |
| 36213 | + } |
| 36214 | + sqlite3_snprintf(sizeof(zKey), zKey, "%u", pgno); |
| 36215 | + got = sqlite3KvvfsMethods.xRead(pFile->zClass, zKey, aData, sizeof(aData)-1); |
| 36216 | + if( got<0 ){ |
| 36217 | + n = 0; |
| 36218 | + }else{ |
| 36219 | + aData[got] = 0; |
| 36220 | + if( iOfst+iAmt<512 ){ |
| 36221 | + int k = iOfst+iAmt; |
| 36222 | + aData[k*2] = 0; |
| 36223 | + n = kvvfsDecode(aData, &aData[2000], sizeof(aData)-2000); |
| 36224 | + if( n>=iOfst+iAmt ){ |
| 36225 | + memcpy(zBuf, &aData[2000+iOfst], iAmt); |
| 36226 | + n = iAmt; |
| 36227 | + }else{ |
| 36228 | + n = 0; |
| 36229 | + } |
| 36230 | + }else{ |
| 36231 | + n = kvvfsDecode(aData, zBuf, iAmt); |
| 36232 | + } |
| 36233 | + } |
| 36234 | + if( n<iAmt ){ |
| 36235 | + memset(zBuf+n, 0, iAmt-n); |
| 36236 | + return SQLITE_IOERR_SHORT_READ; |
| 36237 | + } |
| 36238 | + return SQLITE_OK; |
| 36239 | +} |
| 36240 | + |
| 36241 | + |
| 36242 | +/* |
| 36243 | +** Write into the -journal file. |
| 36244 | +*/ |
| 36245 | +static int kvvfsWriteJrnl( |
| 36246 | + sqlite3_file *pProtoFile, |
| 36247 | + const void *zBuf, |
| 36248 | + int iAmt, |
| 36249 | + sqlite_int64 iOfst |
| 36250 | +){ |
| 36251 | + KVVfsFile *pFile = (KVVfsFile*)pProtoFile; |
| 36252 | + sqlite3_int64 iEnd = iOfst+iAmt; |
| 36253 | + SQLITE_KV_LOG(("xWrite('%s-journal',%d,%lld)\n", pFile->zClass, iAmt, iOfst)); |
| 36254 | + if( iEnd>=0x10000000 ) return SQLITE_FULL; |
| 36255 | + if( pFile->aJrnl==0 || pFile->nJrnl<iEnd ){ |
| 36256 | + char *aNew = sqlite3_realloc(pFile->aJrnl, iEnd); |
| 36257 | + if( aNew==0 ){ |
| 36258 | + return SQLITE_IOERR_NOMEM; |
| 36259 | + } |
| 36260 | + pFile->aJrnl = aNew; |
| 36261 | + if( pFile->nJrnl<iOfst ){ |
| 36262 | + memset(pFile->aJrnl+pFile->nJrnl, 0, iOfst-pFile->nJrnl); |
| 36263 | + } |
| 36264 | + pFile->nJrnl = iEnd; |
| 36265 | + } |
| 36266 | + memcpy(pFile->aJrnl+iOfst, zBuf, iAmt); |
| 36267 | + return SQLITE_OK; |
| 36268 | +} |
| 36269 | + |
| 36270 | +/* |
| 36271 | +** Write into the database file. |
| 36272 | +*/ |
| 36273 | +static int kvvfsWriteDb( |
| 36274 | + sqlite3_file *pProtoFile, |
| 36275 | + const void *zBuf, |
| 36276 | + int iAmt, |
| 36277 | + sqlite_int64 iOfst |
| 36278 | +){ |
| 36279 | + KVVfsFile *pFile = (KVVfsFile*)pProtoFile; |
| 36280 | + unsigned int pgno; |
| 36281 | + char zKey[30]; |
| 36282 | + char aData[131073]; |
| 36283 | + SQLITE_KV_LOG(("xWrite('%s-db',%d,%lld)\n", pFile->zClass, iAmt, iOfst)); |
| 36284 | + assert( iAmt>=512 && iAmt<=65536 ); |
| 36285 | + assert( (iAmt & (iAmt-1))==0 ); |
| 36286 | + pgno = 1 + iOfst/iAmt; |
| 36287 | + sqlite3_snprintf(sizeof(zKey), zKey, "%u", pgno); |
| 36288 | + kvvfsEncode(zBuf, iAmt, aData); |
| 36289 | + if( sqlite3KvvfsMethods.xWrite(pFile->zClass, zKey, aData) ){ |
| 36290 | + return SQLITE_IOERR; |
| 36291 | + } |
| 36292 | + if( iOfst+iAmt > pFile->szDb ){ |
| 36293 | + pFile->szDb = iOfst + iAmt; |
| 36294 | + } |
| 36295 | + return SQLITE_OK; |
| 36296 | +} |
| 36297 | + |
| 36298 | +/* |
| 36299 | +** Truncate an kvvfs-file. |
| 36300 | +*/ |
| 36301 | +static int kvvfsTruncateJrnl(sqlite3_file *pProtoFile, sqlite_int64 size){ |
| 36302 | + KVVfsFile *pFile = (KVVfsFile *)pProtoFile; |
| 36303 | + SQLITE_KV_LOG(("xTruncate('%s-journal',%lld)\n", pFile->zClass, size)); |
| 36304 | + assert( size==0 ); |
| 36305 | + sqlite3KvvfsMethods.xDelete(pFile->zClass, "jrnl"); |
| 36306 | + sqlite3_free(pFile->aJrnl); |
| 36307 | + pFile->aJrnl = 0; |
| 36308 | + pFile->nJrnl = 0; |
| 36309 | + return SQLITE_OK; |
| 36310 | +} |
| 36311 | +static int kvvfsTruncateDb(sqlite3_file *pProtoFile, sqlite_int64 size){ |
| 36312 | + KVVfsFile *pFile = (KVVfsFile *)pProtoFile; |
| 36313 | + if( pFile->szDb>size |
| 36314 | + && pFile->szPage>0 |
| 36315 | + && (size % pFile->szPage)==0 |
| 36316 | + ){ |
| 36317 | + char zKey[50]; |
| 36318 | + unsigned int pgno, pgnoMax; |
| 36319 | + SQLITE_KV_LOG(("xTruncate('%s-db',%lld)\n", pFile->zClass, size)); |
| 36320 | + pgno = 1 + size/pFile->szPage; |
| 36321 | + pgnoMax = 2 + pFile->szDb/pFile->szPage; |
| 36322 | + while( pgno<=pgnoMax ){ |
| 36323 | + sqlite3_snprintf(sizeof(zKey), zKey, "%u", pgno); |
| 36324 | + sqlite3KvvfsMethods.xDelete(pFile->zClass, zKey); |
| 36325 | + pgno++; |
| 36326 | + } |
| 36327 | + pFile->szDb = size; |
| 36328 | + return kvvfsWriteFileSize(pFile, size) ? SQLITE_IOERR : SQLITE_OK; |
| 36329 | + } |
| 36330 | + return SQLITE_IOERR; |
| 36331 | +} |
| 36332 | + |
| 36333 | +/* |
| 36334 | +** Sync an kvvfs-file. |
| 36335 | +*/ |
| 36336 | +static int kvvfsSyncJrnl(sqlite3_file *pProtoFile, int flags){ |
| 36337 | + int i, n; |
| 36338 | + KVVfsFile *pFile = (KVVfsFile *)pProtoFile; |
| 36339 | + char *zOut; |
| 36340 | + SQLITE_KV_LOG(("xSync('%s-journal')\n", pFile->zClass)); |
| 36341 | + if( pFile->nJrnl<=0 ){ |
| 36342 | + return kvvfsTruncateJrnl(pProtoFile, 0); |
| 36343 | + } |
| 36344 | + zOut = sqlite3_malloc64( pFile->nJrnl*2 + 50 ); |
| 36345 | + if( zOut==0 ){ |
| 36346 | + return SQLITE_IOERR_NOMEM; |
| 36347 | + } |
| 36348 | + n = pFile->nJrnl; |
| 36349 | + i = 0; |
| 36350 | + do{ |
| 36351 | + zOut[i++] = 'a' + (n%26); |
| 36352 | + n /= 26; |
| 36353 | + }while( n>0 ); |
| 36354 | + zOut[i++] = ' '; |
| 36355 | + kvvfsEncode(pFile->aJrnl, pFile->nJrnl, &zOut[i]); |
| 36356 | + i = sqlite3KvvfsMethods.xWrite(pFile->zClass, "jrnl", zOut); |
| 36357 | + sqlite3_free(zOut); |
| 36358 | + return i ? SQLITE_IOERR : SQLITE_OK; |
| 36359 | +} |
| 36360 | +static int kvvfsSyncDb(sqlite3_file *pProtoFile, int flags){ |
| 36361 | + return SQLITE_OK; |
| 36362 | +} |
| 36363 | + |
| 36364 | +/* |
| 36365 | +** Return the current file-size of an kvvfs-file. |
| 36366 | +*/ |
| 36367 | +static int kvvfsFileSizeJrnl(sqlite3_file *pProtoFile, sqlite_int64 *pSize){ |
| 36368 | + KVVfsFile *pFile = (KVVfsFile *)pProtoFile; |
| 36369 | + SQLITE_KV_LOG(("xFileSize('%s-journal')\n", pFile->zClass)); |
| 36370 | + *pSize = pFile->nJrnl; |
| 36371 | + return SQLITE_OK; |
| 36372 | +} |
| 36373 | +static int kvvfsFileSizeDb(sqlite3_file *pProtoFile, sqlite_int64 *pSize){ |
| 36374 | + KVVfsFile *pFile = (KVVfsFile *)pProtoFile; |
| 36375 | + SQLITE_KV_LOG(("xFileSize('%s-db')\n", pFile->zClass)); |
| 36376 | + if( pFile->szDb>=0 ){ |
| 36377 | + *pSize = pFile->szDb; |
| 36378 | + }else{ |
| 36379 | + *pSize = kvvfsReadFileSize(pFile); |
| 36380 | + } |
| 36381 | + return SQLITE_OK; |
| 36382 | +} |
| 36383 | + |
| 36384 | +/* |
| 36385 | +** Lock an kvvfs-file. |
| 36386 | +*/ |
| 36387 | +static int kvvfsLock(sqlite3_file *pProtoFile, int eLock){ |
| 36388 | + KVVfsFile *pFile = (KVVfsFile *)pProtoFile; |
| 36389 | + assert( !pFile->isJournal ); |
| 36390 | + SQLITE_KV_LOG(("xLock(%s,%d)\n", pFile->zClass, eLock)); |
| 36391 | + |
| 36392 | + if( eLock!=SQLITE_LOCK_NONE ){ |
| 36393 | + pFile->szDb = kvvfsReadFileSize(pFile); |
| 36394 | + } |
| 36395 | + return SQLITE_OK; |
| 36396 | +} |
| 36397 | + |
| 36398 | +/* |
| 36399 | +** Unlock an kvvfs-file. |
| 36400 | +*/ |
| 36401 | +static int kvvfsUnlock(sqlite3_file *pProtoFile, int eLock){ |
| 36402 | + KVVfsFile *pFile = (KVVfsFile *)pProtoFile; |
| 36403 | + assert( !pFile->isJournal ); |
| 36404 | + SQLITE_KV_LOG(("xUnlock(%s,%d)\n", pFile->zClass, eLock)); |
| 36405 | + if( eLock==SQLITE_LOCK_NONE ){ |
| 36406 | + pFile->szDb = -1; |
| 36407 | + } |
| 36408 | + return SQLITE_OK; |
| 36409 | +} |
| 36410 | + |
| 36411 | +/* |
| 36412 | +** Check if another file-handle holds a RESERVED lock on an kvvfs-file. |
| 36413 | +*/ |
| 36414 | +static int kvvfsCheckReservedLock(sqlite3_file *pProtoFile, int *pResOut){ |
| 36415 | + SQLITE_KV_LOG(("xCheckReservedLock\n")); |
| 36416 | + *pResOut = 0; |
| 36417 | + return SQLITE_OK; |
| 36418 | +} |
| 36419 | + |
| 36420 | +/* |
| 36421 | +** File control method. For custom operations on an kvvfs-file. |
| 36422 | +*/ |
| 36423 | +static int kvvfsFileControlJrnl(sqlite3_file *pProtoFile, int op, void *pArg){ |
| 36424 | + SQLITE_KV_LOG(("xFileControl(%d) on journal\n", op)); |
| 36425 | + return SQLITE_NOTFOUND; |
| 36426 | +} |
| 36427 | +static int kvvfsFileControlDb(sqlite3_file *pProtoFile, int op, void *pArg){ |
| 36428 | + SQLITE_KV_LOG(("xFileControl(%d) on database\n", op)); |
| 36429 | + if( op==SQLITE_FCNTL_SYNC ){ |
| 36430 | + KVVfsFile *pFile = (KVVfsFile *)pProtoFile; |
| 36431 | + int rc = SQLITE_OK; |
| 36432 | + SQLITE_KV_LOG(("xSync('%s-db')\n", pFile->zClass)); |
| 36433 | + if( pFile->szDb>0 && 0!=kvvfsWriteFileSize(pFile, pFile->szDb) ){ |
| 36434 | + rc = SQLITE_IOERR; |
| 36435 | + } |
| 36436 | + return rc; |
| 36437 | + } |
| 36438 | + return SQLITE_NOTFOUND; |
| 36439 | +} |
| 36440 | + |
| 36441 | +/* |
| 36442 | +** Return the sector-size in bytes for an kvvfs-file. |
| 36443 | +*/ |
| 36444 | +static int kvvfsSectorSize(sqlite3_file *pFile){ |
| 36445 | + return 512; |
| 36446 | +} |
| 36447 | + |
| 36448 | +/* |
| 36449 | +** Return the device characteristic flags supported by an kvvfs-file. |
| 36450 | +*/ |
| 36451 | +static int kvvfsDeviceCharacteristics(sqlite3_file *pProtoFile){ |
| 36452 | + return 0; |
| 36453 | +} |
| 36454 | + |
| 36455 | +/****** sqlite3_vfs methods *************************************************/ |
| 36456 | + |
| 36457 | +/* |
| 36458 | +** Open an kvvfs file handle. |
| 36459 | +*/ |
| 36460 | +static int kvvfsOpen( |
| 36461 | + sqlite3_vfs *pProtoVfs, |
| 36462 | + const char *zName, |
| 36463 | + sqlite3_file *pProtoFile, |
| 36464 | + int flags, |
| 36465 | + int *pOutFlags |
| 36466 | +){ |
| 36467 | + KVVfsFile *pFile = (KVVfsFile*)pProtoFile; |
| 36468 | + SQLITE_KV_LOG(("xOpen(\"%s\")\n", zName)); |
| 36469 | + if( strcmp(zName, "local")==0 |
| 36470 | + || strcmp(zName, "session")==0 |
| 36471 | + ){ |
| 36472 | + pFile->isJournal = 0; |
| 36473 | + pFile->base.pMethods = &kvvfs_db_io_methods; |
| 36474 | + }else |
| 36475 | + if( strcmp(zName, "local-journal")==0 |
| 36476 | + || strcmp(zName, "session-journal")==0 |
| 36477 | + ){ |
| 36478 | + pFile->isJournal = 1; |
| 36479 | + pFile->base.pMethods = &kvvfs_jrnl_io_methods; |
| 36480 | + }else{ |
| 36481 | + return SQLITE_CANTOPEN; |
| 36482 | + } |
| 36483 | + if( zName[0]=='s' ){ |
| 36484 | + pFile->zClass = "session"; |
| 36485 | + }else{ |
| 36486 | + pFile->zClass = "local"; |
| 36487 | + } |
| 36488 | + pFile->aJrnl = 0; |
| 36489 | + pFile->nJrnl = 0; |
| 36490 | + pFile->szPage = -1; |
| 36491 | + pFile->szDb = -1; |
| 36492 | + return SQLITE_OK; |
| 36493 | +} |
| 36494 | + |
| 36495 | +/* |
| 36496 | +** Delete the file located at zPath. If the dirSync argument is true, |
| 36497 | +** ensure the file-system modifications are synced to disk before |
| 36498 | +** returning. |
| 36499 | +*/ |
| 36500 | +static int kvvfsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){ |
| 36501 | + if( strcmp(zPath, "local-journal")==0 ){ |
| 36502 | + sqlite3KvvfsMethods.xDelete("local", "jrnl"); |
| 36503 | + }else |
| 36504 | + if( strcmp(zPath, "session-journal")==0 ){ |
| 36505 | + sqlite3KvvfsMethods.xDelete("session", "jrnl"); |
| 36506 | + } |
| 36507 | + return SQLITE_OK; |
| 36508 | +} |
| 36509 | + |
| 36510 | +/* |
| 36511 | +** Test for access permissions. Return true if the requested permission |
| 36512 | +** is available, or false otherwise. |
| 36513 | +*/ |
| 36514 | +static int kvvfsAccess( |
| 36515 | + sqlite3_vfs *pProtoVfs, |
| 36516 | + const char *zPath, |
| 36517 | + int flags, |
| 36518 | + int *pResOut |
| 36519 | +){ |
| 36520 | + SQLITE_KV_LOG(("xAccess(\"%s\")\n", zPath)); |
| 36521 | + if( strcmp(zPath, "local-journal")==0 ){ |
| 36522 | + *pResOut = sqlite3KvvfsMethods.xRead("local", "jrnl", 0, 0)>0; |
| 36523 | + }else |
| 36524 | + if( strcmp(zPath, "session-journal")==0 ){ |
| 36525 | + *pResOut = sqlite3KvvfsMethods.xRead("session", "jrnl", 0, 0)>0; |
| 36526 | + }else |
| 36527 | + if( strcmp(zPath, "local")==0 ){ |
| 36528 | + *pResOut = sqlite3KvvfsMethods.xRead("local", "sz", 0, 0)>0; |
| 36529 | + }else |
| 36530 | + if( strcmp(zPath, "session")==0 ){ |
| 36531 | + *pResOut = sqlite3KvvfsMethods.xRead("session", "sz", 0, 0)>0; |
| 36532 | + }else |
| 36533 | + { |
| 36534 | + *pResOut = 0; |
| 36535 | + } |
| 36536 | + SQLITE_KV_LOG(("xAccess returns %d\n",*pResOut)); |
| 36537 | + return SQLITE_OK; |
| 36538 | +} |
| 36539 | + |
| 36540 | +/* |
| 36541 | +** Populate buffer zOut with the full canonical pathname corresponding |
| 36542 | +** to the pathname in zPath. zOut is guaranteed to point to a buffer |
| 36543 | +** of at least (INST_MAX_PATHNAME+1) bytes. |
| 36544 | +*/ |
| 36545 | +static int kvvfsFullPathname( |
| 36546 | + sqlite3_vfs *pVfs, |
| 36547 | + const char *zPath, |
| 36548 | + int nOut, |
| 36549 | + char *zOut |
| 36550 | +){ |
| 36551 | + size_t nPath; |
| 36552 | +#ifdef SQLITE_OS_KV_ALWAYS_LOCAL |
| 36553 | + zPath = "local"; |
| 36554 | +#endif |
| 36555 | + nPath = strlen(zPath); |
| 36556 | + SQLITE_KV_LOG(("xFullPathname(\"%s\")\n", zPath)); |
| 36557 | + if( nOut<nPath+1 ) nPath = nOut - 1; |
| 36558 | + memcpy(zOut, zPath, nPath); |
| 36559 | + zOut[nPath] = 0; |
| 36560 | + return SQLITE_OK; |
| 36561 | +} |
| 36562 | + |
| 36563 | +/* |
| 36564 | +** Open the dynamic library located at zPath and return a handle. |
| 36565 | +*/ |
| 36566 | +static void *kvvfsDlOpen(sqlite3_vfs *pVfs, const char *zPath){ |
| 36567 | + return 0; |
| 36568 | +} |
| 36569 | + |
| 36570 | +/* |
| 36571 | +** Populate the buffer pointed to by zBufOut with nByte bytes of |
| 36572 | +** random data. |
| 36573 | +*/ |
| 36574 | +static int kvvfsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){ |
| 36575 | + memset(zBufOut, 0, nByte); |
| 36576 | + return nByte; |
| 36577 | +} |
| 36578 | + |
| 36579 | +/* |
| 36580 | +** Sleep for nMicro microseconds. Return the number of microseconds |
| 36581 | +** actually slept. |
| 36582 | +*/ |
| 36583 | +static int kvvfsSleep(sqlite3_vfs *pVfs, int nMicro){ |
| 36584 | + return SQLITE_OK; |
| 36585 | +} |
| 36586 | + |
| 36587 | +/* |
| 36588 | +** Return the current time as a Julian Day number in *pTimeOut. |
| 36589 | +*/ |
| 36590 | +static int kvvfsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){ |
| 36591 | + sqlite3_int64 i = 0; |
| 36592 | + int rc; |
| 36593 | + rc = kvvfsCurrentTimeInt64(0, &i); |
| 36594 | + *pTimeOut = i/86400000.0; |
| 36595 | + return rc; |
| 36596 | +} |
| 36597 | +#include <sys/time.h> |
| 36598 | +static int kvvfsCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *pTimeOut){ |
| 36599 | + static const sqlite3_int64 unixEpoch = 24405875*(sqlite3_int64)8640000; |
| 36600 | + struct timeval sNow; |
| 36601 | + (void)gettimeofday(&sNow, 0); /* Cannot fail given valid arguments */ |
| 36602 | + *pTimeOut = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000; |
| 36603 | + return SQLITE_OK; |
| 36604 | +} |
| 36605 | +#endif /* SQLITE_OS_KV || SQLITE_OS_UNIX */ |
| 36606 | + |
| 36607 | +#if SQLITE_OS_KV |
| 36608 | +/* |
| 36609 | +** This routine is called initialize the KV-vfs as the default VFS. |
| 36610 | +*/ |
| 36611 | +SQLITE_API int sqlite3_os_init(void){ |
| 36612 | + return sqlite3_vfs_register(&sqlite3OsKvvfsObject, 1); |
| 36613 | +} |
| 36614 | +SQLITE_API int sqlite3_os_end(void){ |
| 36615 | + return SQLITE_OK; |
| 36616 | +} |
| 36617 | +#endif /* SQLITE_OS_KV */ |
| 36618 | + |
| 36619 | +#if SQLITE_OS_UNIX && defined(SQLITE_OS_KV_OPTIONAL) |
| 36620 | +SQLITE_PRIVATE int sqlite3KvvfsInit(void){ |
| 36621 | + return sqlite3_vfs_register(&sqlite3OsKvvfsObject, 0); |
| 36622 | +} |
| 36623 | +#endif |
| 36624 | + |
| 36625 | +/************** End of os_kv.c ***********************************************/ |
| 35562 | 36626 | /************** Begin file os_unix.c *****************************************/ |
| 35563 | 36627 | /* |
| 35564 | 36628 | ** 2004 May 22 |
| 35565 | 36629 | ** |
| 35566 | 36630 | ** The author disclaims copyright to this source code. In place of |
| | @@ -35647,17 +36711,17 @@ |
| 35647 | 36711 | #endif |
| 35648 | 36712 | |
| 35649 | 36713 | /* |
| 35650 | 36714 | ** standard include files. |
| 35651 | 36715 | */ |
| 35652 | | -#include <sys/types.h> |
| 35653 | | -#include <sys/stat.h> |
| 36716 | +#include <sys/types.h> /* amalgamator: keep */ |
| 36717 | +#include <sys/stat.h> /* amalgamator: keep */ |
| 35654 | 36718 | #include <fcntl.h> |
| 35655 | 36719 | #include <sys/ioctl.h> |
| 35656 | | -#include <unistd.h> |
| 36720 | +#include <unistd.h> /* amalgamator: keep */ |
| 35657 | 36721 | /* #include <time.h> */ |
| 35658 | | -#include <sys/time.h> |
| 36722 | +#include <sys/time.h> /* amalgamator: keep */ |
| 35659 | 36723 | #include <errno.h> |
| 35660 | 36724 | #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 35661 | 36725 | # include <sys/mman.h> |
| 35662 | 36726 | #endif |
| 35663 | 36727 | |
| | @@ -43625,10 +44689,13 @@ |
| 43625 | 44689 | 0==strcmp(aVfs[i].zName,SQLITE_DEFAULT_UNIX_VFS)); |
| 43626 | 44690 | #else |
| 43627 | 44691 | sqlite3_vfs_register(&aVfs[i], i==0); |
| 43628 | 44692 | #endif |
| 43629 | 44693 | } |
| 44694 | +#ifdef SQLITE_OS_KV_OPTIONAL |
| 44695 | + sqlite3KvvfsInit(); |
| 44696 | +#endif |
| 43630 | 44697 | unixBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1); |
| 43631 | 44698 | |
| 43632 | 44699 | #ifndef SQLITE_OMIT_WAL |
| 43633 | 44700 | /* Validate lock assumptions */ |
| 43634 | 44701 | assert( SQLITE_SHM_NLOCK==8 ); /* Number of available locks */ |
| | @@ -70722,10 +71789,13 @@ |
| 70722 | 71789 | put4byte(pCell+info.nSize-4, iTo); |
| 70723 | 71790 | break; |
| 70724 | 71791 | } |
| 70725 | 71792 | } |
| 70726 | 71793 | }else{ |
| 71794 | + if( pCell+4 > pPage->aData+pPage->pBt->usableSize ){ |
| 71795 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 71796 | + } |
| 70727 | 71797 | if( get4byte(pCell)==iFrom ){ |
| 70728 | 71798 | put4byte(pCell, iTo); |
| 70729 | 71799 | break; |
| 70730 | 71800 | } |
| 70731 | 71801 | } |
| | @@ -73056,18 +74126,11 @@ |
| 73056 | 74126 | } |
| 73057 | 74127 | } |
| 73058 | 74128 | |
| 73059 | 74129 | pPage = pCur->pPage; |
| 73060 | 74130 | idx = ++pCur->ix; |
| 73061 | | - if( !pPage->isInit || sqlite3FaultSim(412) ){ |
| 73062 | | - /* The only known way for this to happen is for there to be a |
| 73063 | | - ** recursive SQL function that does a DELETE operation as part of a |
| 73064 | | - ** SELECT which deletes content out from under an active cursor |
| 73065 | | - ** in a corrupt database file where the table being DELETE-ed from |
| 73066 | | - ** has pages in common with the table being queried. See TH3 |
| 73067 | | - ** module cov1/btree78.test testcase 220 (2018-06-08) for an |
| 73068 | | - ** example. */ |
| 74131 | + if( NEVER(!pPage->isInit) || sqlite3FaultSim(412) ){ |
| 73069 | 74132 | return SQLITE_CORRUPT_BKPT; |
| 73070 | 74133 | } |
| 73071 | 74134 | |
| 73072 | 74135 | if( idx>=pPage->nCell ){ |
| 73073 | 74136 | if( !pPage->leaf ){ |
| | @@ -75753,10 +76816,15 @@ |
| 75753 | 76816 | assert( pCur->pPage->nOverflow ); |
| 75754 | 76817 | } |
| 75755 | 76818 | }else{ |
| 75756 | 76819 | break; |
| 75757 | 76820 | } |
| 76821 | + }else if( sqlite3PagerPageRefcount(pPage->pDbPage)>1 ){ |
| 76822 | + /* The page being written is not a root page, and there is currently |
| 76823 | + ** more than one reference to it. This only happens if the page is one |
| 76824 | + ** of its own ancestor pages. Corruption. */ |
| 76825 | + rc = SQLITE_CORRUPT_BKPT; |
| 75758 | 76826 | }else{ |
| 75759 | 76827 | MemPage * const pParent = pCur->apPage[iPage-1]; |
| 75760 | 76828 | int const iIdx = pCur->aiIdx[iPage-1]; |
| 75761 | 76829 | |
| 75762 | 76830 | rc = sqlite3PagerWrite(pParent->pDbPage); |
| | @@ -79679,10 +80747,11 @@ |
| 79679 | 80747 | assert( MEM_Str==(MEM_Blob>>3) ); |
| 79680 | 80748 | pMem->flags |= (pMem->flags&MEM_Blob)>>3; |
| 79681 | 80749 | sqlite3ValueApplyAffinity(pMem, SQLITE_AFF_TEXT, encoding); |
| 79682 | 80750 | assert( pMem->flags & MEM_Str || pMem->db->mallocFailed ); |
| 79683 | 80751 | pMem->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal|MEM_Blob|MEM_Zero); |
| 80752 | + if( encoding!=SQLITE_UTF8 ) pMem->n &= ~1; |
| 79684 | 80753 | return sqlite3VdbeChangeEncoding(pMem, encoding); |
| 79685 | 80754 | } |
| 79686 | 80755 | } |
| 79687 | 80756 | return SQLITE_OK; |
| 79688 | 80757 | } |
| | @@ -80813,10 +81882,13 @@ |
| 80813 | 81882 | SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value *pVal, u8 enc){ |
| 80814 | 81883 | Mem *p = (Mem*)pVal; |
| 80815 | 81884 | assert( (p->flags & MEM_Null)==0 || (p->flags & (MEM_Str|MEM_Blob))==0 ); |
| 80816 | 81885 | if( (p->flags & MEM_Str)!=0 && pVal->enc==enc ){ |
| 80817 | 81886 | return p->n; |
| 81887 | + } |
| 81888 | + if( (p->flags & MEM_Str)!=0 && enc!=SQLITE_UTF8 && pVal->enc!=SQLITE_UTF8 ){ |
| 81889 | + return p->n; |
| 80818 | 81890 | } |
| 80819 | 81891 | if( (p->flags & MEM_Blob)!=0 ){ |
| 80820 | 81892 | if( p->flags & MEM_Zero ){ |
| 80821 | 81893 | return p->n + p->u.nZero; |
| 80822 | 81894 | }else{ |
| | @@ -81983,10 +83055,22 @@ |
| 81983 | 83055 | } |
| 81984 | 83056 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u16 p5){ |
| 81985 | 83057 | assert( p->nOp>0 || p->db->mallocFailed ); |
| 81986 | 83058 | if( p->nOp>0 ) p->aOp[p->nOp-1].p5 = p5; |
| 81987 | 83059 | } |
| 83060 | + |
| 83061 | +/* |
| 83062 | +** If the previous opcode is an OP_Column that delivers results |
| 83063 | +** into register iDest, then add the OPFLAG_TYPEOFARG flag to that |
| 83064 | +** opcode. |
| 83065 | +*/ |
| 83066 | +SQLITE_PRIVATE void sqlite3VdbeTypeofColumn(Vdbe *p, int iDest){ |
| 83067 | + VdbeOp *pOp = sqlite3VdbeGetLastOp(p); |
| 83068 | + if( pOp->p3==iDest && pOp->opcode==OP_Column ){ |
| 83069 | + pOp->p5 |= OPFLAG_TYPEOFARG; |
| 83070 | + } |
| 83071 | +} |
| 81988 | 83072 | |
| 81989 | 83073 | /* |
| 81990 | 83074 | ** Change the P2 operand of instruction addr so that it points to |
| 81991 | 83075 | ** the address of the next instruction to be coded. |
| 81992 | 83076 | */ |
| | @@ -85402,11 +86486,11 @@ |
| 85402 | 86486 | testcase( pRhs->flags & MEM_Int ); |
| 85403 | 86487 | testcase( pRhs->flags & MEM_IntReal ); |
| 85404 | 86488 | serial_type = aKey1[idx1]; |
| 85405 | 86489 | testcase( serial_type==12 ); |
| 85406 | 86490 | if( serial_type>=10 ){ |
| 85407 | | - rc = +1; |
| 86491 | + rc = serial_type==10 ? -1 : +1; |
| 85408 | 86492 | }else if( serial_type==0 ){ |
| 85409 | 86493 | rc = -1; |
| 85410 | 86494 | }else if( serial_type==7 ){ |
| 85411 | 86495 | sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1); |
| 85412 | 86496 | rc = -sqlite3IntFloatCompare(pRhs->u.i, mem1.u.r); |
| | @@ -85427,11 +86511,11 @@ |
| 85427 | 86511 | if( serial_type>=10 ){ |
| 85428 | 86512 | /* Serial types 12 or greater are strings and blobs (greater than |
| 85429 | 86513 | ** numbers). Types 10 and 11 are currently "reserved for future |
| 85430 | 86514 | ** use", so it doesn't really matter what the results of comparing |
| 85431 | 86515 | ** them to numberic values are. */ |
| 85432 | | - rc = +1; |
| 86516 | + rc = serial_type==10 ? -1 : +1; |
| 85433 | 86517 | }else if( serial_type==0 ){ |
| 85434 | 86518 | rc = -1; |
| 85435 | 86519 | }else{ |
| 85436 | 86520 | sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1); |
| 85437 | 86521 | if( serial_type==7 ){ |
| | @@ -85508,11 +86592,11 @@ |
| 85508 | 86592 | } |
| 85509 | 86593 | |
| 85510 | 86594 | /* RHS is null */ |
| 85511 | 86595 | else{ |
| 85512 | 86596 | serial_type = aKey1[idx1]; |
| 85513 | | - rc = (serial_type!=0); |
| 86597 | + rc = (serial_type!=0 && serial_type!=10); |
| 85514 | 86598 | } |
| 85515 | 86599 | |
| 85516 | 86600 | if( rc!=0 ){ |
| 85517 | 86601 | int sortFlags = pPKey2->pKeyInfo->aSortFlags[i]; |
| 85518 | 86602 | if( sortFlags ){ |
| | @@ -86457,10 +87541,13 @@ |
| 86457 | 87541 | } |
| 86458 | 87542 | assert( eType == aType[pVal->flags&MEM_AffMask] ); |
| 86459 | 87543 | } |
| 86460 | 87544 | #endif |
| 86461 | 87545 | return aType[pVal->flags&MEM_AffMask]; |
| 87546 | +} |
| 87547 | +SQLITE_API int sqlite3_value_encoding(sqlite3_value *pVal){ |
| 87548 | + return pVal->enc; |
| 86462 | 87549 | } |
| 86463 | 87550 | |
| 86464 | 87551 | /* Return true if a parameter to xUpdate represents an unchanged column */ |
| 86465 | 87552 | SQLITE_API int sqlite3_value_nochange(sqlite3_value *pVal){ |
| 86466 | 87553 | return (pVal->flags&(MEM_Null|MEM_Zero))==(MEM_Null|MEM_Zero); |
| | @@ -91094,23 +92181,94 @@ |
| 91094 | 92181 | goto jump_to_p2; |
| 91095 | 92182 | } |
| 91096 | 92183 | break; |
| 91097 | 92184 | } |
| 91098 | 92185 | |
| 91099 | | -/* Opcode: IsNullOrType P1 P2 P3 * * |
| 91100 | | -** Synopsis: if typeof(r[P1]) IN (P3,5) goto P2 |
| 92186 | +/* Opcode: IsType P1 P2 P3 P4 P5 |
| 92187 | +** Synopsis: if typeof(P1.P3) in P5 goto P2 |
| 91101 | 92188 | ** |
| 91102 | | -** Jump to P2 if the value in register P1 is NULL or has a datatype P3. |
| 91103 | | -** P3 is an integer which should be one of SQLITE_INTEGER, SQLITE_FLOAT, |
| 91104 | | -** SQLITE_BLOB, SQLITE_NULL, or SQLITE_TEXT. |
| 92189 | +** Jump to P2 if the type of a column in a btree is one of the types specified |
| 92190 | +** by the P5 bitmask. |
| 92191 | +** |
| 92192 | +** P1 is normally a cursor on a btree for which the row decode cache is |
| 92193 | +** valid through at least column P3. In other words, there should have been |
| 92194 | +** a prior OP_Column for column P3 or greater. If the cursor is not valid, |
| 92195 | +** then this opcode might give spurious results. |
| 92196 | +** The the btree row has fewer than P3 columns, then use P4 as the |
| 92197 | +** datatype. |
| 92198 | +** |
| 92199 | +** If P1 is -1, then P3 is a register number and the datatype is taken |
| 92200 | +** from the value in that register. |
| 92201 | +** |
| 92202 | +** P5 is a bitmask of data types. SQLITE_INTEGER is the least significant |
| 92203 | +** (0x01) bit. SQLITE_FLOAT is the 0x02 bit. SQLITE_TEXT is 0x04. |
| 92204 | +** SQLITE_BLOB is 0x08. SQLITE_NULL is 0x10. |
| 92205 | +** |
| 92206 | +** Take the jump to address P2 if and only if the datatype of the |
| 92207 | +** value determined by P1 and P3 corresponds to one of the bits in the |
| 92208 | +** P5 bitmask. |
| 92209 | +** |
| 91105 | 92210 | */ |
| 91106 | | -case OP_IsNullOrType: { /* jump, in1 */ |
| 91107 | | - int doTheJump; |
| 91108 | | - pIn1 = &aMem[pOp->p1]; |
| 91109 | | - doTheJump = (pIn1->flags & MEM_Null)!=0 || sqlite3_value_type(pIn1)==pOp->p3; |
| 91110 | | - VdbeBranchTaken( doTheJump, 2); |
| 91111 | | - if( doTheJump ) goto jump_to_p2; |
| 92211 | +case OP_IsType: { /* jump */ |
| 92212 | + VdbeCursor *pC; |
| 92213 | + u16 typeMask; |
| 92214 | + u32 serialType; |
| 92215 | + |
| 92216 | + assert( pOp->p1>=(-1) && pOp->p1<p->nCursor ); |
| 92217 | + assert( pOp->p1>=0 || (pOp->p3>=0 && pOp->p3<=(p->nMem+1 - p->nCursor)) ); |
| 92218 | + if( pOp->p1>=0 ){ |
| 92219 | + pC = p->apCsr[pOp->p1]; |
| 92220 | + assert( pC!=0 ); |
| 92221 | + assert( pOp->p3>=0 ); |
| 92222 | + if( pOp->p3<pC->nHdrParsed ){ |
| 92223 | + serialType = pC->aType[pOp->p3]; |
| 92224 | + if( serialType>=12 ){ |
| 92225 | + if( serialType&1 ){ |
| 92226 | + typeMask = 0x04; /* SQLITE_TEXT */ |
| 92227 | + }else{ |
| 92228 | + typeMask = 0x08; /* SQLITE_BLOB */ |
| 92229 | + } |
| 92230 | + }else{ |
| 92231 | + static const unsigned char aMask[] = { |
| 92232 | + 0x10, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x2, |
| 92233 | + 0x01, 0x01, 0x10, 0x10 |
| 92234 | + }; |
| 92235 | + testcase( serialType==0 ); |
| 92236 | + testcase( serialType==1 ); |
| 92237 | + testcase( serialType==2 ); |
| 92238 | + testcase( serialType==3 ); |
| 92239 | + testcase( serialType==4 ); |
| 92240 | + testcase( serialType==5 ); |
| 92241 | + testcase( serialType==6 ); |
| 92242 | + testcase( serialType==7 ); |
| 92243 | + testcase( serialType==8 ); |
| 92244 | + testcase( serialType==9 ); |
| 92245 | + testcase( serialType==10 ); |
| 92246 | + testcase( serialType==11 ); |
| 92247 | + typeMask = aMask[serialType]; |
| 92248 | + } |
| 92249 | + }else{ |
| 92250 | + typeMask = 1 << (pOp->p4.i - 1); |
| 92251 | + testcase( typeMask==0x01 ); |
| 92252 | + testcase( typeMask==0x02 ); |
| 92253 | + testcase( typeMask==0x04 ); |
| 92254 | + testcase( typeMask==0x08 ); |
| 92255 | + testcase( typeMask==0x10 ); |
| 92256 | + } |
| 92257 | + }else{ |
| 92258 | + assert( memIsValid(&aMem[pOp->p3]) ); |
| 92259 | + typeMask = 1 << (sqlite3_value_type((sqlite3_value*)&aMem[pOp->p3])-1); |
| 92260 | + testcase( typeMask==0x01 ); |
| 92261 | + testcase( typeMask==0x02 ); |
| 92262 | + testcase( typeMask==0x04 ); |
| 92263 | + testcase( typeMask==0x08 ); |
| 92264 | + testcase( typeMask==0x10 ); |
| 92265 | + } |
| 92266 | + VdbeBranchTaken( (typeMask & pOp->p5)!=0, 2); |
| 92267 | + if( typeMask & pOp->p5 ){ |
| 92268 | + goto jump_to_p2; |
| 92269 | + } |
| 91112 | 92270 | break; |
| 91113 | 92271 | } |
| 91114 | 92272 | |
| 91115 | 92273 | /* Opcode: ZeroOrNull P1 P2 P3 * * |
| 91116 | 92274 | ** Synopsis: r[P2] = 0 OR NULL |
| | @@ -91207,23 +92365,25 @@ |
| 91207 | 92365 | ** Synopsis: r[P3]=PX cursor P1 column P2 |
| 91208 | 92366 | ** |
| 91209 | 92367 | ** Interpret the data that cursor P1 points to as a structure built using |
| 91210 | 92368 | ** the MakeRecord instruction. (See the MakeRecord opcode for additional |
| 91211 | 92369 | ** information about the format of the data.) Extract the P2-th column |
| 91212 | | -** from this record. If there are less that (P2+1) |
| 92370 | +** from this record. If there are less than (P2+1) |
| 91213 | 92371 | ** values in the record, extract a NULL. |
| 91214 | 92372 | ** |
| 91215 | 92373 | ** The value extracted is stored in register P3. |
| 91216 | 92374 | ** |
| 91217 | 92375 | ** If the record contains fewer than P2 fields, then extract a NULL. Or, |
| 91218 | 92376 | ** if the P4 argument is a P4_MEM use the value of the P4 argument as |
| 91219 | 92377 | ** the result. |
| 91220 | 92378 | ** |
| 91221 | | -** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 then |
| 91222 | | -** the result is guaranteed to only be used as the argument of a length() |
| 91223 | | -** or typeof() function, respectively. The loading of large blobs can be |
| 91224 | | -** skipped for length() and all content loading can be skipped for typeof(). |
| 92379 | +** If the OPFLAG_LENGTHARG bit is set in P5 then the result is guaranteed |
| 92380 | +** to only be used by the length() function or the equivalent. The content |
| 92381 | +** of large blobs is not loaded, thus saving CPU cycles. If the |
| 92382 | +** OPFLAG_TYPEOFARG bit is set then the result will only be used by the |
| 92383 | +** typeof() function or the IS NULL or IS NOT NULL operators or the |
| 92384 | +** equivalent. In this case, all content loading can be omitted. |
| 91225 | 92385 | */ |
| 91226 | 92386 | case OP_Column: { |
| 91227 | 92387 | u32 p2; /* column number to retrieve */ |
| 91228 | 92388 | VdbeCursor *pC; /* The VDBE cursor */ |
| 91229 | 92389 | BtCursor *pCrsr; /* The B-Tree cursor corresponding to pC */ |
| | @@ -93158,11 +94318,17 @@ |
| 93158 | 94318 | assert( oc!=OP_SeekGE || r.default_rc==+1 ); |
| 93159 | 94319 | assert( oc!=OP_SeekLT || r.default_rc==+1 ); |
| 93160 | 94320 | |
| 93161 | 94321 | r.aMem = &aMem[pOp->p3]; |
| 93162 | 94322 | #ifdef SQLITE_DEBUG |
| 93163 | | - { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } |
| 94323 | + { |
| 94324 | + int i; |
| 94325 | + for(i=0; i<r.nField; i++){ |
| 94326 | + assert( memIsValid(&r.aMem[i]) ); |
| 94327 | + if( i>0 ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]); |
| 94328 | + } |
| 94329 | + } |
| 93164 | 94330 | #endif |
| 93165 | 94331 | r.eqSeen = 0; |
| 93166 | 94332 | rc = sqlite3BtreeIndexMoveto(pC->uc.pCursor, &r, &res); |
| 93167 | 94333 | if( rc!=SQLITE_OK ){ |
| 93168 | 94334 | goto abort_due_to_error; |
| | @@ -93221,54 +94387,76 @@ |
| 93221 | 94387 | } |
| 93222 | 94388 | break; |
| 93223 | 94389 | } |
| 93224 | 94390 | |
| 93225 | 94391 | |
| 93226 | | -/* Opcode: SeekScan P1 P2 * * * |
| 94392 | +/* Opcode: SeekScan P1 P2 * * P5 |
| 93227 | 94393 | ** Synopsis: Scan-ahead up to P1 rows |
| 93228 | 94394 | ** |
| 93229 | 94395 | ** This opcode is a prefix opcode to OP_SeekGE. In other words, this |
| 93230 | 94396 | ** opcode must be immediately followed by OP_SeekGE. This constraint is |
| 93231 | 94397 | ** checked by assert() statements. |
| 93232 | 94398 | ** |
| 93233 | 94399 | ** This opcode uses the P1 through P4 operands of the subsequent |
| 93234 | 94400 | ** OP_SeekGE. In the text that follows, the operands of the subsequent |
| 93235 | 94401 | ** OP_SeekGE opcode are denoted as SeekOP.P1 through SeekOP.P4. Only |
| 93236 | | -** the P1 and P2 operands of this opcode are also used, and are called |
| 93237 | | -** This.P1 and This.P2. |
| 94402 | +** the P1, P2 and P5 operands of this opcode are also used, and are called |
| 94403 | +** This.P1, This.P2 and This.P5. |
| 93238 | 94404 | ** |
| 93239 | 94405 | ** This opcode helps to optimize IN operators on a multi-column index |
| 93240 | 94406 | ** where the IN operator is on the later terms of the index by avoiding |
| 93241 | 94407 | ** unnecessary seeks on the btree, substituting steps to the next row |
| 93242 | 94408 | ** of the b-tree instead. A correct answer is obtained if this opcode |
| 93243 | 94409 | ** is omitted or is a no-op. |
| 93244 | 94410 | ** |
| 93245 | 94411 | ** The SeekGE.P3 and SeekGE.P4 operands identify an unpacked key which |
| 93246 | 94412 | ** is the desired entry that we want the cursor SeekGE.P1 to be pointing |
| 93247 | | -** to. Call this SeekGE.P4/P5 row the "target". |
| 94413 | +** to. Call this SeekGE.P3/P4 row the "target". |
| 93248 | 94414 | ** |
| 93249 | 94415 | ** If the SeekGE.P1 cursor is not currently pointing to a valid row, |
| 93250 | 94416 | ** then this opcode is a no-op and control passes through into the OP_SeekGE. |
| 93251 | 94417 | ** |
| 93252 | 94418 | ** If the SeekGE.P1 cursor is pointing to a valid row, then that row |
| 93253 | 94419 | ** might be the target row, or it might be near and slightly before the |
| 93254 | | -** target row. This opcode attempts to position the cursor on the target |
| 93255 | | -** row by, perhaps by invoking sqlite3BtreeStep() on the cursor |
| 93256 | | -** between 0 and This.P1 times. |
| 93257 | | -** |
| 93258 | | -** There are three possible outcomes from this opcode:<ol> |
| 93259 | | -** |
| 93260 | | -** <li> If after This.P1 steps, the cursor is still pointing to a place that |
| 93261 | | -** is earlier in the btree than the target row, then fall through |
| 93262 | | -** into the subsquence OP_SeekGE opcode. |
| 93263 | | -** |
| 93264 | | -** <li> If the cursor is successfully moved to the target row by 0 or more |
| 93265 | | -** sqlite3BtreeNext() calls, then jump to This.P2, which will land just |
| 93266 | | -** past the OP_IdxGT or OP_IdxGE opcode that follows the OP_SeekGE. |
| 93267 | | -** |
| 93268 | | -** <li> If the cursor ends up past the target row (indicating that the target |
| 93269 | | -** row does not exist in the btree) then jump to SeekOP.P2. |
| 94420 | +** target row, or it might be after the target row. If the cursor is |
| 94421 | +** currently before the target row, then this opcode attempts to position |
| 94422 | +** the cursor on or after the target row by invoking sqlite3BtreeStep() |
| 94423 | +** on the cursor between 1 and This.P1 times. |
| 94424 | +** |
| 94425 | +** The This.P5 parameter is a flag that indicates what to do if the |
| 94426 | +** cursor ends up pointing at a valid row that is past the target |
| 94427 | +** row. If This.P5 is false (0) then a jump is made to SeekGE.P2. If |
| 94428 | +** This.P5 is true (non-zero) then a jump is made to This.P2. The P5==0 |
| 94429 | +** case occurs when there are no inequality constraints to the right of |
| 94430 | +** the IN constraing. The jump to SeekGE.P2 ends the loop. The P5!=0 case |
| 94431 | +** occurs when there are inequality constraints to the right of the IN |
| 94432 | +** operator. In that case, the This.P2 will point either directly to or |
| 94433 | +** to setup code prior to the OP_IdxGT or OP_IdxGE opcode that checks for |
| 94434 | +** loop terminate. |
| 94435 | +** |
| 94436 | +** Possible outcomes from this opcode:<ol> |
| 94437 | +** |
| 94438 | +** <li> If the cursor is initally not pointed to any valid row, then |
| 94439 | +** fall through into the subsequent OP_SeekGE opcode. |
| 94440 | +** |
| 94441 | +** <li> If the cursor is left pointing to a row that is before the target |
| 94442 | +** row, even after making as many as This.P1 calls to |
| 94443 | +** sqlite3BtreeNext(), then also fall through into OP_SeekGE. |
| 94444 | +** |
| 94445 | +** <li> If the cursor is left pointing at the target row, either because it |
| 94446 | +** was at the target row to begin with or because one or more |
| 94447 | +** sqlite3BtreeNext() calls moved the cursor to the target row, |
| 94448 | +** then jump to This.P2.., |
| 94449 | +** |
| 94450 | +** <li> If the cursor started out before the target row and a call to |
| 94451 | +** to sqlite3BtreeNext() moved the cursor off the end of the index |
| 94452 | +** (indicating that the target row definitely does not exist in the |
| 94453 | +** btree) then jump to SeekGE.P2, ending the loop. |
| 94454 | +** |
| 94455 | +** <li> If the cursor ends up on a valid row that is past the target row |
| 94456 | +** (indicating that the target row does not exist in the btree) then |
| 94457 | +** jump to SeekOP.P2 if This.P5==0 or to This.P2 if This.P5>0. |
| 93270 | 94458 | ** </ol> |
| 93271 | 94459 | */ |
| 93272 | 94460 | case OP_SeekScan: { |
| 93273 | 94461 | VdbeCursor *pC; |
| 93274 | 94462 | int res; |
| | @@ -93275,18 +94463,29 @@ |
| 93275 | 94463 | int nStep; |
| 93276 | 94464 | UnpackedRecord r; |
| 93277 | 94465 | |
| 93278 | 94466 | assert( pOp[1].opcode==OP_SeekGE ); |
| 93279 | 94467 | |
| 93280 | | - /* pOp->p2 points to the first instruction past the OP_IdxGT that |
| 93281 | | - ** follows the OP_SeekGE. */ |
| 94468 | + /* If pOp->p5 is clear, then pOp->p2 points to the first instruction past the |
| 94469 | + ** OP_IdxGT that follows the OP_SeekGE. Otherwise, it points to the first |
| 94470 | + ** opcode past the OP_SeekGE itself. */ |
| 93282 | 94471 | assert( pOp->p2>=(int)(pOp-aOp)+2 ); |
| 93283 | | - assert( aOp[pOp->p2-1].opcode==OP_IdxGT || aOp[pOp->p2-1].opcode==OP_IdxGE ); |
| 93284 | | - testcase( aOp[pOp->p2-1].opcode==OP_IdxGE ); |
| 93285 | | - assert( pOp[1].p1==aOp[pOp->p2-1].p1 ); |
| 93286 | | - assert( pOp[1].p2==aOp[pOp->p2-1].p2 ); |
| 93287 | | - assert( pOp[1].p3==aOp[pOp->p2-1].p3 ); |
| 94472 | +#ifdef SQLITE_DEBUG |
| 94473 | + if( pOp->p5==0 ){ |
| 94474 | + /* There are no inequality constraints following the IN constraint. */ |
| 94475 | + assert( pOp[1].p1==aOp[pOp->p2-1].p1 ); |
| 94476 | + assert( pOp[1].p2==aOp[pOp->p2-1].p2 ); |
| 94477 | + assert( pOp[1].p3==aOp[pOp->p2-1].p3 ); |
| 94478 | + assert( aOp[pOp->p2-1].opcode==OP_IdxGT |
| 94479 | + || aOp[pOp->p2-1].opcode==OP_IdxGE ); |
| 94480 | + testcase( aOp[pOp->p2-1].opcode==OP_IdxGE ); |
| 94481 | + }else{ |
| 94482 | + /* There are inequality constraints. */ |
| 94483 | + assert( pOp->p2==(int)(pOp-aOp)+2 ); |
| 94484 | + assert( aOp[pOp->p2-1].opcode==OP_SeekGE ); |
| 94485 | + } |
| 94486 | +#endif |
| 93288 | 94487 | |
| 93289 | 94488 | assert( pOp->p1>0 ); |
| 93290 | 94489 | pC = p->apCsr[pOp[1].p1]; |
| 93291 | 94490 | assert( pC!=0 ); |
| 93292 | 94491 | assert( pC->eCurType==CURTYPE_BTREE ); |
| | @@ -93316,22 +94515,24 @@ |
| 93316 | 94515 | #endif |
| 93317 | 94516 | res = 0; /* Not needed. Only used to silence a warning. */ |
| 93318 | 94517 | while(1){ |
| 93319 | 94518 | rc = sqlite3VdbeIdxKeyCompare(db, pC, &r, &res); |
| 93320 | 94519 | if( rc ) goto abort_due_to_error; |
| 93321 | | - if( res>0 ){ |
| 94520 | + if( res>0 && pOp->p5==0 ){ |
| 93322 | 94521 | seekscan_search_fail: |
| 94522 | + /* Jump to SeekGE.P2, ending the loop */ |
| 93323 | 94523 | #ifdef SQLITE_DEBUG |
| 93324 | 94524 | if( db->flags&SQLITE_VdbeTrace ){ |
| 93325 | 94525 | printf("... %d steps and then skip\n", pOp->p1 - nStep); |
| 93326 | 94526 | } |
| 93327 | 94527 | #endif |
| 93328 | 94528 | VdbeBranchTaken(1,3); |
| 93329 | 94529 | pOp++; |
| 93330 | 94530 | goto jump_to_p2; |
| 93331 | 94531 | } |
| 93332 | | - if( res==0 ){ |
| 94532 | + if( res>=0 ){ |
| 94533 | + /* Jump to This.P2, bypassing the OP_SeekGE opcode */ |
| 93333 | 94534 | #ifdef SQLITE_DEBUG |
| 93334 | 94535 | if( db->flags&SQLITE_VdbeTrace ){ |
| 93335 | 94536 | printf("... %d steps and then success\n", pOp->p1 - nStep); |
| 93336 | 94537 | } |
| 93337 | 94538 | #endif |
| | @@ -103867,13 +105068,12 @@ |
| 103867 | 105068 | } |
| 103868 | 105069 | op = pExpr->op; |
| 103869 | 105070 | if( op==TK_REGISTER ) op = pExpr->op2; |
| 103870 | 105071 | if( op==TK_COLUMN || op==TK_AGG_COLUMN ){ |
| 103871 | 105072 | assert( ExprUseYTab(pExpr) ); |
| 103872 | | - if( pExpr->y.pTab ){ |
| 103873 | | - return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn); |
| 103874 | | - } |
| 105073 | + assert( pExpr->y.pTab!=0 ); |
| 105074 | + return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn); |
| 103875 | 105075 | } |
| 103876 | 105076 | if( op==TK_SELECT ){ |
| 103877 | 105077 | assert( ExprUseXSelect(pExpr) ); |
| 103878 | 105078 | assert( pExpr->x.pSelect!=0 ); |
| 103879 | 105079 | assert( pExpr->x.pSelect->pEList!=0 ); |
| | @@ -103987,21 +105187,18 @@ |
| 103987 | 105187 | const Expr *p = pExpr; |
| 103988 | 105188 | while( p ){ |
| 103989 | 105189 | int op = p->op; |
| 103990 | 105190 | if( op==TK_REGISTER ) op = p->op2; |
| 103991 | 105191 | if( op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_TRIGGER ){ |
| 105192 | + int j; |
| 103992 | 105193 | assert( ExprUseYTab(p) ); |
| 103993 | | - if( p->y.pTab!=0 ){ |
| 103994 | | - /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally |
| 103995 | | - ** a TK_COLUMN but was previously evaluated and cached in a register */ |
| 103996 | | - int j = p->iColumn; |
| 103997 | | - if( j>=0 ){ |
| 103998 | | - const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]); |
| 103999 | | - pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0); |
| 104000 | | - } |
| 104001 | | - break; |
| 104002 | | - } |
| 105194 | + assert( p->y.pTab!=0 ); |
| 105195 | + if( (j = p->iColumn)>=0 ){ |
| 105196 | + const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]); |
| 105197 | + pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0); |
| 105198 | + } |
| 105199 | + break; |
| 104003 | 105200 | } |
| 104004 | 105201 | if( op==TK_CAST || op==TK_UPLUS ){ |
| 104005 | 105202 | p = p->pLeft; |
| 104006 | 105203 | continue; |
| 104007 | 105204 | } |
| | @@ -107602,14 +108799,11 @@ |
| 107602 | 108799 | int iCol, /* Index of the column to extract */ |
| 107603 | 108800 | int regOut /* Extract the value into this register */ |
| 107604 | 108801 | ){ |
| 107605 | 108802 | Column *pCol; |
| 107606 | 108803 | assert( v!=0 ); |
| 107607 | | - if( pTab==0 ){ |
| 107608 | | - sqlite3VdbeAddOp3(v, OP_Column, iTabCur, iCol, regOut); |
| 107609 | | - return; |
| 107610 | | - } |
| 108804 | + assert( pTab!=0 ); |
| 107611 | 108805 | if( iCol<0 || iCol==pTab->iPKey ){ |
| 107612 | 108806 | sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut); |
| 107613 | 108807 | VdbeComment((v, "%s.rowid", pTab->zName)); |
| 107614 | 108808 | }else{ |
| 107615 | 108809 | int op; |
| | @@ -107855,10 +109049,57 @@ |
| 107855 | 109049 | #endif /* !defined(SQLITE_UNTESTABLE) */ |
| 107856 | 109050 | } |
| 107857 | 109051 | return target; |
| 107858 | 109052 | } |
| 107859 | 109053 | |
| 109054 | +/* |
| 109055 | +** Check to see if pExpr is one of the indexed expressions on pParse->pIdxExpr. |
| 109056 | +** If it is, then resolve the expression by reading from the index and |
| 109057 | +** return the register into which the value has been read. If pExpr is |
| 109058 | +** not an indexed expression, then return negative. |
| 109059 | +*/ |
| 109060 | +static SQLITE_NOINLINE int sqlite3IndexedExprLookup( |
| 109061 | + Parse *pParse, /* The parsing context */ |
| 109062 | + Expr *pExpr, /* The expression to potentially bypass */ |
| 109063 | + int target /* Where to store the result of the expression */ |
| 109064 | +){ |
| 109065 | + IndexedExpr *p; |
| 109066 | + Vdbe *v; |
| 109067 | + for(p=pParse->pIdxExpr; p; p=p->pIENext){ |
| 109068 | + int iDataCur = p->iDataCur; |
| 109069 | + if( iDataCur<0 ) continue; |
| 109070 | + if( pParse->iSelfTab ){ |
| 109071 | + if( p->iDataCur!=pParse->iSelfTab-1 ) continue; |
| 109072 | + iDataCur = -1; |
| 109073 | + } |
| 109074 | + if( sqlite3ExprCompare(0, pExpr, p->pExpr, iDataCur)!=0 ) continue; |
| 109075 | + v = pParse->pVdbe; |
| 109076 | + assert( v!=0 ); |
| 109077 | + if( p->bMaybeNullRow ){ |
| 109078 | + /* If the index is on a NULL row due to an outer join, then we |
| 109079 | + ** cannot extract the value from the index. The value must be |
| 109080 | + ** computed using the original expression. */ |
| 109081 | + int addr = sqlite3VdbeCurrentAddr(v); |
| 109082 | + sqlite3VdbeAddOp3(v, OP_IfNullRow, p->iIdxCur, addr+3, target); |
| 109083 | + VdbeCoverage(v); |
| 109084 | + sqlite3VdbeAddOp3(v, OP_Column, p->iIdxCur, p->iIdxCol, target); |
| 109085 | + VdbeComment((v, "%s expr-column %d", p->zIdxName, p->iIdxCol)); |
| 109086 | + sqlite3VdbeGoto(v, 0); |
| 109087 | + p = pParse->pIdxExpr; |
| 109088 | + pParse->pIdxExpr = 0; |
| 109089 | + sqlite3ExprCode(pParse, pExpr, target); |
| 109090 | + pParse->pIdxExpr = p; |
| 109091 | + sqlite3VdbeJumpHere(v, addr+2); |
| 109092 | + }else{ |
| 109093 | + sqlite3VdbeAddOp3(v, OP_Column, p->iIdxCur, p->iIdxCol, target); |
| 109094 | + VdbeComment((v, "%s expr-column %d", p->zIdxName, p->iIdxCol)); |
| 109095 | + } |
| 109096 | + return target; |
| 109097 | + } |
| 109098 | + return -1; /* Not found */ |
| 109099 | +} |
| 109100 | + |
| 107860 | 109101 | |
| 107861 | 109102 | /* |
| 107862 | 109103 | ** Generate code into the current Vdbe to evaluate the given |
| 107863 | 109104 | ** expression. Attempt to store the results in register "target". |
| 107864 | 109105 | ** Return the register where results are stored. |
| | @@ -107883,10 +109124,15 @@ |
| 107883 | 109124 | assert( v!=0 ); |
| 107884 | 109125 | |
| 107885 | 109126 | expr_code_doover: |
| 107886 | 109127 | if( pExpr==0 ){ |
| 107887 | 109128 | op = TK_NULL; |
| 109129 | + }else if( pParse->pIdxExpr!=0 |
| 109130 | + && !ExprHasProperty(pExpr, EP_Leaf) |
| 109131 | + && (r1 = sqlite3IndexedExprLookup(pParse, pExpr, target))>=0 |
| 109132 | + ){ |
| 109133 | + return r1; |
| 107888 | 109134 | }else{ |
| 107889 | 109135 | assert( !ExprHasVVAProperty(pExpr,EP_Immutable) ); |
| 107890 | 109136 | op = pExpr->op; |
| 107891 | 109137 | } |
| 107892 | 109138 | switch( op ){ |
| | @@ -107928,15 +109174,12 @@ |
| 107928 | 109174 | ** constant. |
| 107929 | 109175 | */ |
| 107930 | 109176 | int aff; |
| 107931 | 109177 | iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target); |
| 107932 | 109178 | assert( ExprUseYTab(pExpr) ); |
| 107933 | | - if( pExpr->y.pTab ){ |
| 107934 | | - aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn); |
| 107935 | | - }else{ |
| 107936 | | - aff = pExpr->affExpr; |
| 107937 | | - } |
| 109179 | + assert( pExpr->y.pTab!=0 ); |
| 109180 | + aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn); |
| 107938 | 109181 | if( aff>SQLITE_AFF_BLOB ){ |
| 107939 | 109182 | static const char zAff[] = "B\000C\000D\000E"; |
| 107940 | 109183 | assert( SQLITE_AFF_BLOB=='A' ); |
| 107941 | 109184 | assert( SQLITE_AFF_TEXT=='B' ); |
| 107942 | 109185 | sqlite3VdbeAddOp4(v, OP_Affinity, iReg, 1, 0, |
| | @@ -107994,16 +109237,14 @@ |
| 107994 | 109237 | ** in the index refer to the table to which the index belongs */ |
| 107995 | 109238 | iTab = pParse->iSelfTab - 1; |
| 107996 | 109239 | } |
| 107997 | 109240 | } |
| 107998 | 109241 | assert( ExprUseYTab(pExpr) ); |
| 109242 | + assert( pExpr->y.pTab!=0 ); |
| 107999 | 109243 | iReg = sqlite3ExprCodeGetColumn(pParse, pExpr->y.pTab, |
| 108000 | 109244 | pExpr->iColumn, iTab, target, |
| 108001 | 109245 | pExpr->op2); |
| 108002 | | - if( pExpr->y.pTab==0 && pExpr->affExpr==SQLITE_AFF_REAL ){ |
| 108003 | | - sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg); |
| 108004 | | - } |
| 108005 | 109246 | return iReg; |
| 108006 | 109247 | } |
| 108007 | 109248 | case TK_INTEGER: { |
| 108008 | 109249 | codeInteger(pParse, pExpr, 0, target); |
| 108009 | 109250 | return target; |
| | @@ -109053,10 +110294,11 @@ |
| 109053 | 110294 | case TK_ISNULL: |
| 109054 | 110295 | case TK_NOTNULL: { |
| 109055 | 110296 | assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL ); |
| 109056 | 110297 | assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL ); |
| 109057 | 110298 | r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); |
| 110299 | + sqlite3VdbeTypeofColumn(v, r1); |
| 109058 | 110300 | sqlite3VdbeAddOp2(v, op, r1, dest); |
| 109059 | 110301 | VdbeCoverageIf(v, op==TK_ISNULL); |
| 109060 | 110302 | VdbeCoverageIf(v, op==TK_NOTNULL); |
| 109061 | 110303 | testcase( regFree1==0 ); |
| 109062 | 110304 | break; |
| | @@ -109227,10 +110469,11 @@ |
| 109227 | 110469 | break; |
| 109228 | 110470 | } |
| 109229 | 110471 | case TK_ISNULL: |
| 109230 | 110472 | case TK_NOTNULL: { |
| 109231 | 110473 | r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); |
| 110474 | + sqlite3VdbeTypeofColumn(v, r1); |
| 109232 | 110475 | sqlite3VdbeAddOp2(v, op, r1, dest); |
| 109233 | 110476 | testcase( op==TK_ISNULL ); VdbeCoverageIf(v, op==TK_ISNULL); |
| 109234 | 110477 | testcase( op==TK_NOTNULL ); VdbeCoverageIf(v, op==TK_NOTNULL); |
| 109235 | 110478 | testcase( regFree1==0 ); |
| 109236 | 110479 | break; |
| | @@ -109380,11 +110623,17 @@ |
| 109380 | 110623 | return 1; |
| 109381 | 110624 | } |
| 109382 | 110625 | if( pB->op==TK_COLLATE && sqlite3ExprCompare(pParse, pA,pB->pLeft,iTab)<2 ){ |
| 109383 | 110626 | return 1; |
| 109384 | 110627 | } |
| 109385 | | - return 2; |
| 110628 | + if( pA->op==TK_AGG_COLUMN && pB->op==TK_COLUMN |
| 110629 | + && pB->iTable<0 && pA->iTable==iTab |
| 110630 | + ){ |
| 110631 | + /* fall through */ |
| 110632 | + }else{ |
| 110633 | + return 2; |
| 110634 | + } |
| 109386 | 110635 | } |
| 109387 | 110636 | assert( !ExprHasProperty(pA, EP_IntValue) ); |
| 109388 | 110637 | assert( !ExprHasProperty(pB, EP_IntValue) ); |
| 109389 | 110638 | if( pA->u.zToken ){ |
| 109390 | 110639 | if( pA->op==TK_FUNCTION || pA->op==TK_AGG_FUNCTION ){ |
| | @@ -109682,14 +110931,14 @@ |
| 109682 | 110931 | /* The y.pTab=0 assignment in wherecode.c always happens after the |
| 109683 | 110932 | ** impliesNotNullRow() test */ |
| 109684 | 110933 | assert( pLeft->op!=TK_COLUMN || ExprUseYTab(pLeft) ); |
| 109685 | 110934 | assert( pRight->op!=TK_COLUMN || ExprUseYTab(pRight) ); |
| 109686 | 110935 | if( (pLeft->op==TK_COLUMN |
| 109687 | | - && pLeft->y.pTab!=0 |
| 110936 | + && ALWAYS(pLeft->y.pTab!=0) |
| 109688 | 110937 | && IsVirtual(pLeft->y.pTab)) |
| 109689 | 110938 | || (pRight->op==TK_COLUMN |
| 109690 | | - && pRight->y.pTab!=0 |
| 110939 | + && ALWAYS(pRight->y.pTab!=0) |
| 109691 | 110940 | && IsVirtual(pRight->y.pTab)) |
| 109692 | 110941 | ){ |
| 109693 | 110942 | return WRC_Prune; |
| 109694 | 110943 | } |
| 109695 | 110944 | /* no break */ deliberate_fall_through |
| | @@ -113510,10 +114759,11 @@ |
| 113510 | 114759 | assert( k>=0 && k<pIdx->nColumn ); |
| 113511 | 114760 | i = pIdx->aiColumn[k]; |
| 113512 | 114761 | if( NEVER(i==XN_ROWID) ){ |
| 113513 | 114762 | VdbeComment((v,"%s.rowid",pIdx->zName)); |
| 113514 | 114763 | }else if( i==XN_EXPR ){ |
| 114764 | + assert( pIdx->bHasExpr ); |
| 113515 | 114765 | VdbeComment((v,"%s.expr(%d)",pIdx->zName, k)); |
| 113516 | 114766 | }else{ |
| 113517 | 114767 | VdbeComment((v,"%s.%s", pIdx->zName, pIdx->pTable->aCol[i].zCnName)); |
| 113518 | 114768 | } |
| 113519 | 114769 | } |
| | @@ -115825,11 +117075,11 @@ |
| 115825 | 117075 | if( p==0 ){ |
| 115826 | 117076 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 115827 | 117077 | /* If zName is the not the name of a table in the schema created using |
| 115828 | 117078 | ** CREATE, then check to see if it is the name of an virtual table that |
| 115829 | 117079 | ** can be an eponymous virtual table. */ |
| 115830 | | - if( pParse->disableVtab==0 && db->init.busy==0 ){ |
| 117080 | + if( (pParse->prepFlags & SQLITE_PREPARE_NO_VTAB)==0 && db->init.busy==0 ){ |
| 115831 | 117081 | Module *pMod = (Module*)sqlite3HashFind(&db->aModule, zName); |
| 115832 | 117082 | if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){ |
| 115833 | 117083 | pMod = sqlite3PragmaVtabRegister(db, zName); |
| 115834 | 117084 | } |
| 115835 | 117085 | if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){ |
| | @@ -115838,11 +117088,11 @@ |
| 115838 | 117088 | } |
| 115839 | 117089 | } |
| 115840 | 117090 | #endif |
| 115841 | 117091 | if( flags & LOCATE_NOERR ) return 0; |
| 115842 | 117092 | pParse->checkSchema = 1; |
| 115843 | | - }else if( IsVirtual(p) && pParse->disableVtab ){ |
| 117093 | + }else if( IsVirtual(p) && (pParse->prepFlags & SQLITE_PREPARE_NO_VTAB)!=0 ){ |
| 115844 | 117094 | p = 0; |
| 115845 | 117095 | } |
| 115846 | 117096 | |
| 115847 | 117097 | if( p==0 ){ |
| 115848 | 117098 | const char *zMsg = flags & LOCATE_VIEW ? "no such view" : "no such table"; |
| | @@ -117648,11 +118898,12 @@ |
| 117648 | 118898 | } |
| 117649 | 118899 | |
| 117650 | 118900 | /* Recompute the colNotIdxed field of the Index. |
| 117651 | 118901 | ** |
| 117652 | 118902 | ** colNotIdxed is a bitmask that has a 0 bit representing each indexed |
| 117653 | | -** columns that are within the first 63 columns of the table. The |
| 118903 | +** columns that are within the first 63 columns of the table and a 1 for |
| 118904 | +** all other bits (all columns that are not in the index). The |
| 117654 | 118905 | ** high-order bit of colNotIdxed is always 1. All unindexed columns |
| 117655 | 118906 | ** of the table have a 1. |
| 117656 | 118907 | ** |
| 117657 | 118908 | ** 2019-10-24: For the purpose of this computation, virtual columns are |
| 117658 | 118909 | ** not considered to be covered by the index, even if they are in the |
| | @@ -117676,11 +118927,11 @@ |
| 117676 | 118927 | testcase( x==BMS-2 ); |
| 117677 | 118928 | if( x<BMS-1 ) m |= MASKBIT(x); |
| 117678 | 118929 | } |
| 117679 | 118930 | } |
| 117680 | 118931 | pIdx->colNotIdxed = ~m; |
| 117681 | | - assert( (pIdx->colNotIdxed>>63)==1 ); |
| 118932 | + assert( (pIdx->colNotIdxed>>63)==1 ); /* See note-20221022-a */ |
| 117682 | 118933 | } |
| 117683 | 118934 | |
| 117684 | 118935 | /* |
| 117685 | 118936 | ** This routine runs at the end of parsing a CREATE TABLE statement that |
| 117686 | 118937 | ** has a WITHOUT ROWID clause. The job of this routine is to convert both |
| | @@ -119564,10 +120815,11 @@ |
| 119564 | 120815 | pList = 0; |
| 119565 | 120816 | } |
| 119566 | 120817 | j = XN_EXPR; |
| 119567 | 120818 | pIndex->aiColumn[i] = XN_EXPR; |
| 119568 | 120819 | pIndex->uniqNotNull = 0; |
| 120820 | + pIndex->bHasExpr = 1; |
| 119569 | 120821 | }else{ |
| 119570 | 120822 | j = pCExpr->iColumn; |
| 119571 | 120823 | assert( j<=0x7fff ); |
| 119572 | 120824 | if( j<0 ){ |
| 119573 | 120825 | j = pTab->iPKey; |
| | @@ -119575,10 +120827,11 @@ |
| 119575 | 120827 | if( pTab->aCol[j].notNull==0 ){ |
| 119576 | 120828 | pIndex->uniqNotNull = 0; |
| 119577 | 120829 | } |
| 119578 | 120830 | if( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL ){ |
| 119579 | 120831 | pIndex->bHasVCol = 1; |
| 120832 | + pIndex->bHasExpr = 1; |
| 119580 | 120833 | } |
| 119581 | 120834 | } |
| 119582 | 120835 | pIndex->aiColumn[i] = (i16)j; |
| 119583 | 120836 | } |
| 119584 | 120837 | zColl = 0; |
| | @@ -123352,11 +124605,11 @@ |
| 123352 | 124605 | ** |
| 123353 | 124606 | ** For a case-insensitive search, set variable cx to be the same as |
| 123354 | 124607 | ** c but in the other case and search the input string for either |
| 123355 | 124608 | ** c or cx. |
| 123356 | 124609 | */ |
| 123357 | | - if( c<=0x80 ){ |
| 124610 | + if( c<0x80 ){ |
| 123358 | 124611 | char zStop[3]; |
| 123359 | 124612 | int bMatch; |
| 123360 | 124613 | if( noCase ){ |
| 123361 | 124614 | zStop[0] = sqlite3Toupper(c); |
| 123362 | 124615 | zStop[1] = sqlite3Tolower(c); |
| | @@ -123435,19 +124688,31 @@ |
| 123435 | 124688 | /* |
| 123436 | 124689 | ** The sqlite3_strglob() interface. Return 0 on a match (like strcmp()) and |
| 123437 | 124690 | ** non-zero if there is no match. |
| 123438 | 124691 | */ |
| 123439 | 124692 | SQLITE_API int sqlite3_strglob(const char *zGlobPattern, const char *zString){ |
| 123440 | | - return patternCompare((u8*)zGlobPattern, (u8*)zString, &globInfo, '['); |
| 124693 | + if( zString==0 ){ |
| 124694 | + return zGlobPattern!=0; |
| 124695 | + }else if( zGlobPattern==0 ){ |
| 124696 | + return 1; |
| 124697 | + }else { |
| 124698 | + return patternCompare((u8*)zGlobPattern, (u8*)zString, &globInfo, '['); |
| 124699 | + } |
| 123441 | 124700 | } |
| 123442 | 124701 | |
| 123443 | 124702 | /* |
| 123444 | 124703 | ** The sqlite3_strlike() interface. Return 0 on a match and non-zero for |
| 123445 | 124704 | ** a miss - like strcmp(). |
| 123446 | 124705 | */ |
| 123447 | 124706 | SQLITE_API int sqlite3_strlike(const char *zPattern, const char *zStr, unsigned int esc){ |
| 123448 | | - return patternCompare((u8*)zPattern, (u8*)zStr, &likeInfoNorm, esc); |
| 124707 | + if( zStr==0 ){ |
| 124708 | + return zPattern!=0; |
| 124709 | + }else if( zPattern==0 ){ |
| 124710 | + return 1; |
| 124711 | + }else{ |
| 124712 | + return patternCompare((u8*)zPattern, (u8*)zStr, &likeInfoNorm, esc); |
| 124713 | + } |
| 123449 | 124714 | } |
| 123450 | 124715 | |
| 123451 | 124716 | /* |
| 123452 | 124717 | ** Count the number of times that the LIKE operator (or GLOB which is |
| 123453 | 124718 | ** just a variation of LIKE) gets called. This is used for testing |
| | @@ -126572,10 +127837,11 @@ |
| 126572 | 127837 | aff = pTab->aCol[x].affinity; |
| 126573 | 127838 | }else if( x==XN_ROWID ){ |
| 126574 | 127839 | aff = SQLITE_AFF_INTEGER; |
| 126575 | 127840 | }else{ |
| 126576 | 127841 | assert( x==XN_EXPR ); |
| 127842 | + assert( pIdx->bHasExpr ); |
| 126577 | 127843 | assert( pIdx->aColExpr!=0 ); |
| 126578 | 127844 | aff = sqlite3ExprAffinity(pIdx->aColExpr->a[n].pExpr); |
| 126579 | 127845 | } |
| 126580 | 127846 | if( aff<SQLITE_AFF_BLOB ) aff = SQLITE_AFF_BLOB; |
| 126581 | 127847 | if( aff>SQLITE_AFF_NUMERIC) aff = SQLITE_AFF_NUMERIC; |
| | @@ -130146,10 +131412,12 @@ |
| 130146 | 131412 | int (*deserialize)(sqlite3*,const char*,unsigned char*, |
| 130147 | 131413 | sqlite3_int64,sqlite3_int64,unsigned); |
| 130148 | 131414 | unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*, |
| 130149 | 131415 | unsigned int); |
| 130150 | 131416 | const char *(*db_name)(sqlite3*,int); |
| 131417 | + /* Version 3.40.0 and later */ |
| 131418 | + int (*value_encoding)(sqlite3_value*); |
| 130151 | 131419 | }; |
| 130152 | 131420 | |
| 130153 | 131421 | /* |
| 130154 | 131422 | ** This is the function signature used for all extension entry points. It |
| 130155 | 131423 | ** is also defined in the file "loadext.c". |
| | @@ -130470,10 +131738,12 @@ |
| 130470 | 131738 | #ifndef SQLITE_OMIT_DESERIALIZE |
| 130471 | 131739 | #define sqlite3_deserialize sqlite3_api->deserialize |
| 130472 | 131740 | #define sqlite3_serialize sqlite3_api->serialize |
| 130473 | 131741 | #endif |
| 130474 | 131742 | #define sqlite3_db_name sqlite3_api->db_name |
| 131743 | +/* Version 3.40.0 and later */ |
| 131744 | +#define sqlite3_value_encoding sqlite3_api->value_encoding |
| 130475 | 131745 | #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ |
| 130476 | 131746 | |
| 130477 | 131747 | #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 130478 | 131748 | /* This case when the file really is being compiled as a loadable |
| 130479 | 131749 | ** extension */ |
| | @@ -130982,11 +132252,13 @@ |
| 130982 | 132252 | sqlite3_serialize, |
| 130983 | 132253 | #else |
| 130984 | 132254 | 0, |
| 130985 | 132255 | 0, |
| 130986 | 132256 | #endif |
| 130987 | | - sqlite3_db_name |
| 132257 | + sqlite3_db_name, |
| 132258 | + /* Version 3.40.0 and later */ |
| 132259 | + sqlite3_value_type |
| 130988 | 132260 | }; |
| 130989 | 132261 | |
| 130990 | 132262 | /* True if x is the directory separator character |
| 130991 | 132263 | */ |
| 130992 | 132264 | #if SQLITE_OS_WIN |
| | @@ -133786,12 +135058,13 @@ |
| 133786 | 135058 | Index *pIdx, *pPk; |
| 133787 | 135059 | Index *pPrior = 0; /* Previous index */ |
| 133788 | 135060 | int loopTop; |
| 133789 | 135061 | int iDataCur, iIdxCur; |
| 133790 | 135062 | int r1 = -1; |
| 133791 | | - int bStrict; |
| 135063 | + int bStrict; /* True for a STRICT table */ |
| 133792 | 135064 | int r2; /* Previous key for WITHOUT ROWID tables */ |
| 135065 | + int mxCol; /* Maximum non-virtual column number */ |
| 133793 | 135066 | |
| 133794 | 135067 | if( !IsOrdinaryTable(pTab) ) continue; |
| 133795 | 135068 | if( pObjTab && pObjTab!=pTab ) continue; |
| 133796 | 135069 | if( isQuick || HasRowid(pTab) ){ |
| 133797 | 135070 | pPk = 0; |
| | @@ -133812,15 +135085,26 @@ |
| 133812 | 135085 | } |
| 133813 | 135086 | assert( pParse->nMem>=8+j ); |
| 133814 | 135087 | assert( sqlite3NoTempsInRange(pParse,1,7+j) ); |
| 133815 | 135088 | sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v); |
| 133816 | 135089 | loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1); |
| 135090 | + |
| 135091 | + /* Fetch the right-most column from the table. This will cause |
| 135092 | + ** the entire record header to be parsed and sanity checked. It |
| 135093 | + ** will also prepopulate the cursor column cache that is used |
| 135094 | + ** by the OP_IsType code, so it is a required step. |
| 135095 | + */ |
| 135096 | + mxCol = pTab->nCol-1; |
| 135097 | + while( mxCol>=0 |
| 135098 | + && ((pTab->aCol[mxCol].colFlags & COLFLAG_VIRTUAL)!=0 |
| 135099 | + || pTab->iPKey==mxCol) ) mxCol--; |
| 135100 | + if( mxCol>=0 ){ |
| 135101 | + sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, mxCol, 3); |
| 135102 | + sqlite3VdbeTypeofColumn(v, 3); |
| 135103 | + } |
| 135104 | + |
| 133817 | 135105 | if( !isQuick ){ |
| 133818 | | - /* Sanity check on record header decoding */ |
| 133819 | | - sqlite3VdbeAddOp3(v, OP_Column, iDataCur, pTab->nNVCol-1,3); |
| 133820 | | - sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG); |
| 133821 | | - VdbeComment((v, "(right-most column)")); |
| 133822 | 135106 | if( pPk ){ |
| 133823 | 135107 | /* Verify WITHOUT ROWID keys are in ascending order */ |
| 133824 | 135108 | int a1; |
| 133825 | 135109 | char *zErr; |
| 133826 | 135110 | a1 = sqlite3VdbeAddOp4Int(v, OP_IdxGT, iDataCur, 0,r2,pPk->nKeyCol); |
| | @@ -133836,48 +135120,126 @@ |
| 133836 | 135120 | for(j=0; j<pPk->nKeyCol; j++){ |
| 133837 | 135121 | sqlite3ExprCodeLoadIndexColumn(pParse, pPk, iDataCur, j, r2+j); |
| 133838 | 135122 | } |
| 133839 | 135123 | } |
| 133840 | 135124 | } |
| 133841 | | - /* Verify that all NOT NULL columns really are NOT NULL. At the |
| 133842 | | - ** same time verify the type of the content of STRICT tables */ |
| 135125 | + /* Verify datatypes for all columns: |
| 135126 | + ** |
| 135127 | + ** (1) NOT NULL columns may not contain a NULL |
| 135128 | + ** (2) Datatype must be exact for non-ANY columns in STRICT tables |
| 135129 | + ** (3) Datatype for TEXT columns in non-STRICT tables must be |
| 135130 | + ** NULL, TEXT, or BLOB. |
| 135131 | + ** (4) Datatype for numeric columns in non-STRICT tables must not |
| 135132 | + ** be a TEXT value that can be losslessly converted to numeric. |
| 135133 | + */ |
| 133843 | 135134 | bStrict = (pTab->tabFlags & TF_Strict)!=0; |
| 133844 | 135135 | for(j=0; j<pTab->nCol; j++){ |
| 133845 | 135136 | char *zErr; |
| 133846 | | - Column *pCol = pTab->aCol + j; |
| 133847 | | - int doError, jmp2; |
| 135137 | + Column *pCol = pTab->aCol + j; /* The column to be checked */ |
| 135138 | + int labelError; /* Jump here to report an error */ |
| 135139 | + int labelOk; /* Jump here if all looks ok */ |
| 135140 | + int p1, p3, p4; /* Operands to the OP_IsType opcode */ |
| 135141 | + int doTypeCheck; /* Check datatypes (besides NOT NULL) */ |
| 135142 | + |
| 133848 | 135143 | if( j==pTab->iPKey ) continue; |
| 133849 | | - if( pCol->notNull==0 && !bStrict ) continue; |
| 133850 | | - doError = bStrict ? sqlite3VdbeMakeLabel(pParse) : 0; |
| 133851 | | - sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3); |
| 133852 | | - if( sqlite3VdbeGetLastOp(v)->opcode==OP_Column ){ |
| 133853 | | - sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG); |
| 135144 | + if( bStrict ){ |
| 135145 | + doTypeCheck = pCol->eCType>COLTYPE_ANY; |
| 135146 | + }else{ |
| 135147 | + doTypeCheck = pCol->affinity>SQLITE_AFF_BLOB; |
| 133854 | 135148 | } |
| 135149 | + if( pCol->notNull==0 && !doTypeCheck ) continue; |
| 135150 | + |
| 135151 | + /* Compute the operands that will be needed for OP_IsType */ |
| 135152 | + p4 = SQLITE_NULL; |
| 135153 | + if( pCol->colFlags & COLFLAG_VIRTUAL ){ |
| 135154 | + sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3); |
| 135155 | + p1 = -1; |
| 135156 | + p3 = 3; |
| 135157 | + }else{ |
| 135158 | + if( pCol->iDflt ){ |
| 135159 | + sqlite3_value *pDfltValue = 0; |
| 135160 | + sqlite3ValueFromExpr(db, sqlite3ColumnExpr(pTab,pCol), ENC(db), |
| 135161 | + pCol->affinity, &pDfltValue); |
| 135162 | + if( pDfltValue ){ |
| 135163 | + p4 = sqlite3_value_type(pDfltValue); |
| 135164 | + sqlite3ValueFree(pDfltValue); |
| 135165 | + } |
| 135166 | + } |
| 135167 | + p1 = iDataCur; |
| 135168 | + if( !HasRowid(pTab) ){ |
| 135169 | + testcase( j!=sqlite3TableColumnToStorage(pTab, j) ); |
| 135170 | + p3 = sqlite3TableColumnToIndex(sqlite3PrimaryKeyIndex(pTab), j); |
| 135171 | + }else{ |
| 135172 | + p3 = sqlite3TableColumnToStorage(pTab,j); |
| 135173 | + testcase( p3!=j); |
| 135174 | + } |
| 135175 | + } |
| 135176 | + |
| 135177 | + labelError = sqlite3VdbeMakeLabel(pParse); |
| 135178 | + labelOk = sqlite3VdbeMakeLabel(pParse); |
| 133855 | 135179 | if( pCol->notNull ){ |
| 133856 | | - jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v); |
| 135180 | + /* (1) NOT NULL columns may not contain a NULL */ |
| 135181 | + int jmp2 = sqlite3VdbeAddOp4Int(v, OP_IsType, p1, labelOk, p3, p4); |
| 135182 | + sqlite3VdbeChangeP5(v, 0x0f); |
| 135183 | + VdbeCoverage(v); |
| 133857 | 135184 | zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName, |
| 133858 | 135185 | pCol->zCnName); |
| 133859 | 135186 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
| 133860 | | - if( bStrict && pCol->eCType!=COLTYPE_ANY ){ |
| 133861 | | - sqlite3VdbeGoto(v, doError); |
| 135187 | + if( doTypeCheck ){ |
| 135188 | + sqlite3VdbeGoto(v, labelError); |
| 135189 | + sqlite3VdbeJumpHere(v, jmp2); |
| 133862 | 135190 | }else{ |
| 133863 | | - integrityCheckResultRow(v); |
| 135191 | + /* VDBE byte code will fall thru */ |
| 133864 | 135192 | } |
| 133865 | | - sqlite3VdbeJumpHere(v, jmp2); |
| 133866 | 135193 | } |
| 133867 | | - if( bStrict && pCol->eCType!=COLTYPE_ANY ){ |
| 133868 | | - jmp2 = sqlite3VdbeAddOp3(v, OP_IsNullOrType, 3, 0, |
| 133869 | | - sqlite3StdTypeMap[pCol->eCType-1]); |
| 135194 | + if( bStrict && doTypeCheck ){ |
| 135195 | + /* (2) Datatype must be exact for non-ANY columns in STRICT tables*/ |
| 135196 | + static unsigned char aStdTypeMask[] = { |
| 135197 | + 0x1f, /* ANY */ |
| 135198 | + 0x18, /* BLOB */ |
| 135199 | + 0x11, /* INT */ |
| 135200 | + 0x11, /* INTEGER */ |
| 135201 | + 0x13, /* REAL */ |
| 135202 | + 0x14 /* TEXT */ |
| 135203 | + }; |
| 135204 | + sqlite3VdbeAddOp4Int(v, OP_IsType, p1, labelOk, p3, p4); |
| 135205 | + assert( pCol->eCType>=1 && pCol->eCType<=sizeof(aStdTypeMask) ); |
| 135206 | + sqlite3VdbeChangeP5(v, aStdTypeMask[pCol->eCType-1]); |
| 133870 | 135207 | VdbeCoverage(v); |
| 133871 | 135208 | zErr = sqlite3MPrintf(db, "non-%s value in %s.%s", |
| 133872 | 135209 | sqlite3StdType[pCol->eCType-1], |
| 133873 | 135210 | pTab->zName, pTab->aCol[j].zCnName); |
| 133874 | 135211 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
| 133875 | | - sqlite3VdbeResolveLabel(v, doError); |
| 133876 | | - integrityCheckResultRow(v); |
| 133877 | | - sqlite3VdbeJumpHere(v, jmp2); |
| 135212 | + }else if( !bStrict && pCol->affinity==SQLITE_AFF_TEXT ){ |
| 135213 | + /* (3) Datatype for TEXT columns in non-STRICT tables must be |
| 135214 | + ** NULL, TEXT, or BLOB. */ |
| 135215 | + sqlite3VdbeAddOp4Int(v, OP_IsType, p1, labelOk, p3, p4); |
| 135216 | + sqlite3VdbeChangeP5(v, 0x1c); /* NULL, TEXT, or BLOB */ |
| 135217 | + VdbeCoverage(v); |
| 135218 | + zErr = sqlite3MPrintf(db, "NUMERIC value in %s.%s", |
| 135219 | + pTab->zName, pTab->aCol[j].zCnName); |
| 135220 | + sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
| 135221 | + }else if( !bStrict && pCol->affinity>=SQLITE_AFF_NUMERIC ){ |
| 135222 | + /* (4) Datatype for numeric columns in non-STRICT tables must not |
| 135223 | + ** be a TEXT value that can be converted to numeric. */ |
| 135224 | + sqlite3VdbeAddOp4Int(v, OP_IsType, p1, labelOk, p3, p4); |
| 135225 | + sqlite3VdbeChangeP5(v, 0x1b); /* NULL, INT, FLOAT, or BLOB */ |
| 135226 | + VdbeCoverage(v); |
| 135227 | + if( p1>=0 ){ |
| 135228 | + sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3); |
| 135229 | + } |
| 135230 | + sqlite3VdbeAddOp4(v, OP_Affinity, 3, 1, 0, "C", P4_STATIC); |
| 135231 | + sqlite3VdbeAddOp4Int(v, OP_IsType, -1, labelOk, 3, p4); |
| 135232 | + sqlite3VdbeChangeP5(v, 0x1c); /* NULL, TEXT, or BLOB */ |
| 135233 | + VdbeCoverage(v); |
| 135234 | + zErr = sqlite3MPrintf(db, "TEXT value in %s.%s", |
| 135235 | + pTab->zName, pTab->aCol[j].zCnName); |
| 135236 | + sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
| 133878 | 135237 | } |
| 135238 | + sqlite3VdbeResolveLabel(v, labelError); |
| 135239 | + integrityCheckResultRow(v); |
| 135240 | + sqlite3VdbeResolveLabel(v, labelOk); |
| 133879 | 135241 | } |
| 133880 | 135242 | /* Verify CHECK constraints */ |
| 133881 | 135243 | if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){ |
| 133882 | 135244 | ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0); |
| 133883 | 135245 | if( db->mallocFailed==0 ){ |
| | @@ -135493,11 +136855,11 @@ |
| 135493 | 136855 | */ |
| 135494 | 136856 | if( prepFlags & SQLITE_PREPARE_PERSISTENT ){ |
| 135495 | 136857 | sParse.disableLookaside++; |
| 135496 | 136858 | DisableLookaside; |
| 135497 | 136859 | } |
| 135498 | | - sParse.disableVtab = (prepFlags & SQLITE_PREPARE_NO_VTAB)!=0; |
| 136860 | + sParse.prepFlags = prepFlags & 0xff; |
| 135499 | 136861 | |
| 135500 | 136862 | /* Check to verify that it is possible to get a read lock on all |
| 135501 | 136863 | ** database schemas. The inability to get a read lock indicates that |
| 135502 | 136864 | ** some other database connection is holding a write-lock, which in |
| 135503 | 136865 | ** turn means that the other connection has made uncommitted changes |
| | @@ -135534,11 +136896,13 @@ |
| 135534 | 136896 | } |
| 135535 | 136897 | } |
| 135536 | 136898 | } |
| 135537 | 136899 | } |
| 135538 | 136900 | |
| 135539 | | - sqlite3VtabUnlockList(db); |
| 136901 | +#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 136902 | + if( db->pDisconnect ) sqlite3VtabUnlockList(db); |
| 136903 | +#endif |
| 135540 | 136904 | |
| 135541 | 136905 | if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){ |
| 135542 | 136906 | char *zSqlCopy; |
| 135543 | 136907 | int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; |
| 135544 | 136908 | testcase( nBytes==mxLen ); |
| | @@ -139603,10 +140967,11 @@ |
| 139603 | 140967 | Parse *pParse; /* The parsing context */ |
| 139604 | 140968 | int iTable; /* Replace references to this table */ |
| 139605 | 140969 | int iNewTable; /* New table number */ |
| 139606 | 140970 | int isOuterJoin; /* Add TK_IF_NULL_ROW opcodes on each replacement */ |
| 139607 | 140971 | ExprList *pEList; /* Replacement expressions */ |
| 140972 | + ExprList *pCList; /* Collation sequences for replacement expr */ |
| 139608 | 140973 | } SubstContext; |
| 139609 | 140974 | |
| 139610 | 140975 | /* Forward Declarations */ |
| 139611 | 140976 | static void substExprList(SubstContext*, ExprList*); |
| 139612 | 140977 | static void substSelect(SubstContext*, Select*, int); |
| | @@ -139644,13 +141009,14 @@ |
| 139644 | 141009 | pExpr->op = TK_NULL; |
| 139645 | 141010 | }else |
| 139646 | 141011 | #endif |
| 139647 | 141012 | { |
| 139648 | 141013 | Expr *pNew; |
| 139649 | | - Expr *pCopy = pSubst->pEList->a[pExpr->iColumn].pExpr; |
| 141014 | + int iColumn = pExpr->iColumn; |
| 141015 | + Expr *pCopy = pSubst->pEList->a[iColumn].pExpr; |
| 139650 | 141016 | Expr ifNullRow; |
| 139651 | | - assert( pSubst->pEList!=0 && pExpr->iColumn<pSubst->pEList->nExpr ); |
| 141017 | + assert( pSubst->pEList!=0 && iColumn<pSubst->pEList->nExpr ); |
| 139652 | 141018 | assert( pExpr->pRight==0 ); |
| 139653 | 141019 | if( sqlite3ExprIsVector(pCopy) ){ |
| 139654 | 141020 | sqlite3VectorErrorMsg(pSubst->pParse, pCopy); |
| 139655 | 141021 | }else{ |
| 139656 | 141022 | sqlite3 *db = pSubst->pParse->db; |
| | @@ -139684,15 +141050,20 @@ |
| 139684 | 141050 | ExprSetProperty(pExpr, EP_IntValue); |
| 139685 | 141051 | } |
| 139686 | 141052 | |
| 139687 | 141053 | /* Ensure that the expression now has an implicit collation sequence, |
| 139688 | 141054 | ** just as it did when it was a column of a view or sub-query. */ |
| 139689 | | - if( pExpr->op!=TK_COLUMN && pExpr->op!=TK_COLLATE ){ |
| 139690 | | - CollSeq *pColl = sqlite3ExprCollSeq(pSubst->pParse, pExpr); |
| 139691 | | - pExpr = sqlite3ExprAddCollateString(pSubst->pParse, pExpr, |
| 139692 | | - (pColl ? pColl->zName : "BINARY") |
| 141055 | + { |
| 141056 | + CollSeq *pNat = sqlite3ExprCollSeq(pSubst->pParse, pExpr); |
| 141057 | + CollSeq *pColl = sqlite3ExprCollSeq(pSubst->pParse, |
| 141058 | + pSubst->pCList->a[iColumn].pExpr |
| 139693 | 141059 | ); |
| 141060 | + if( pNat!=pColl || (pExpr->op!=TK_COLUMN && pExpr->op!=TK_COLLATE) ){ |
| 141061 | + pExpr = sqlite3ExprAddCollateString(pSubst->pParse, pExpr, |
| 141062 | + (pColl ? pColl->zName : "BINARY") |
| 141063 | + ); |
| 141064 | + } |
| 139694 | 141065 | } |
| 139695 | 141066 | ExprClearProperty(pExpr, EP_Collate); |
| 139696 | 141067 | } |
| 139697 | 141068 | } |
| 139698 | 141069 | }else{ |
| | @@ -139880,10 +141251,22 @@ |
| 139880 | 141251 | w.xExprCallback = renumberCursorsCb; |
| 139881 | 141252 | w.xSelectCallback = sqlite3SelectWalkNoop; |
| 139882 | 141253 | sqlite3WalkSelect(&w, p); |
| 139883 | 141254 | } |
| 139884 | 141255 | #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */ |
| 141256 | + |
| 141257 | +/* |
| 141258 | +** If pSel is not part of a compound SELECT, return a pointer to its |
| 141259 | +** expression list. Otherwise, return a pointer to the expression list |
| 141260 | +** of the leftmost SELECT in the compound. |
| 141261 | +*/ |
| 141262 | +static ExprList *findLeftmostExprlist(Select *pSel){ |
| 141263 | + while( pSel->pPrior ){ |
| 141264 | + pSel = pSel->pPrior; |
| 141265 | + } |
| 141266 | + return pSel->pEList; |
| 141267 | +} |
| 139885 | 141268 | |
| 139886 | 141269 | #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 139887 | 141270 | /* |
| 139888 | 141271 | ** This routine attempts to flatten subqueries as a performance optimization. |
| 139889 | 141272 | ** This routine returns 1 if it makes changes and 0 if no flattening occurs. |
| | @@ -140433,10 +141816,11 @@ |
| 140433 | 141816 | x.pParse = pParse; |
| 140434 | 141817 | x.iTable = iParent; |
| 140435 | 141818 | x.iNewTable = iNewParent; |
| 140436 | 141819 | x.isOuterJoin = isOuterJoin; |
| 140437 | 141820 | x.pEList = pSub->pEList; |
| 141821 | + x.pCList = findLeftmostExprlist(pSub); |
| 140438 | 141822 | substSelect(&x, pParent, 0); |
| 140439 | 141823 | } |
| 140440 | 141824 | |
| 140441 | 141825 | /* The flattened query is a compound if either the inner or the |
| 140442 | 141826 | ** outer query is a compound. */ |
| | @@ -140452,11 +141836,11 @@ |
| 140452 | 141836 | if( pSub->pLimit ){ |
| 140453 | 141837 | pParent->pLimit = pSub->pLimit; |
| 140454 | 141838 | pSub->pLimit = 0; |
| 140455 | 141839 | } |
| 140456 | 141840 | |
| 140457 | | - /* Recompute the SrcList_item.colUsed masks for the flattened |
| 141841 | + /* Recompute the SrcItem.colUsed masks for the flattened |
| 140458 | 141842 | ** tables. */ |
| 140459 | 141843 | for(i=0; i<nSubSrc; i++){ |
| 140460 | 141844 | recomputeColumnsUsed(pParent, &pSrc->a[i+iFrom]); |
| 140461 | 141845 | } |
| 140462 | 141846 | } |
| | @@ -140915,10 +142299,11 @@ |
| 140915 | 142299 | x.pParse = pParse; |
| 140916 | 142300 | x.iTable = pSrc->iCursor; |
| 140917 | 142301 | x.iNewTable = pSrc->iCursor; |
| 140918 | 142302 | x.isOuterJoin = 0; |
| 140919 | 142303 | x.pEList = pSubq->pEList; |
| 142304 | + x.pCList = findLeftmostExprlist(pSubq); |
| 140920 | 142305 | pNew = substExpr(&x, pNew); |
| 140921 | 142306 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 140922 | 142307 | if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){ |
| 140923 | 142308 | /* Restriction 6c has prevented push-down in this case */ |
| 140924 | 142309 | sqlite3ExprDelete(pParse->db, pNew); |
| | @@ -141439,13 +142824,13 @@ |
| 141439 | 142824 | } |
| 141440 | 142825 | } |
| 141441 | 142826 | #endif |
| 141442 | 142827 | |
| 141443 | 142828 | /* |
| 141444 | | -** The SrcList_item structure passed as the second argument represents a |
| 142829 | +** The SrcItem structure passed as the second argument represents a |
| 141445 | 142830 | ** sub-query in the FROM clause of a SELECT statement. This function |
| 141446 | | -** allocates and populates the SrcList_item.pTab object. If successful, |
| 142831 | +** allocates and populates the SrcItem.pTab object. If successful, |
| 141447 | 142832 | ** SQLITE_OK is returned. Otherwise, if an OOM error is encountered, |
| 141448 | 142833 | ** SQLITE_NOMEM. |
| 141449 | 142834 | */ |
| 141450 | 142835 | SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse *pParse, SrcItem *pFrom){ |
| 141451 | 142836 | Select *pSel = pFrom->pSelect; |
| | @@ -142274,11 +143659,11 @@ |
| 142274 | 143659 | #endif |
| 142275 | 143660 | } |
| 142276 | 143661 | |
| 142277 | 143662 | /* |
| 142278 | 143663 | ** Check to see if the pThis entry of pTabList is a self-join of a prior view. |
| 142279 | | -** If it is, then return the SrcList_item for the prior view. If it is not, |
| 143664 | +** If it is, then return the SrcItem for the prior view. If it is not, |
| 142280 | 143665 | ** then return 0. |
| 142281 | 143666 | */ |
| 142282 | 143667 | static SrcItem *isSelfJoinView( |
| 142283 | 143668 | SrcList *pTabList, /* Search for self-joins in this FROM clause */ |
| 142284 | 143669 | SrcItem *pThis /* Search for prior reference to this subquery */ |
| | @@ -143318,11 +144703,11 @@ |
| 143318 | 144703 | ** in the right order to begin with. |
| 143319 | 144704 | */ |
| 143320 | 144705 | sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset); |
| 143321 | 144706 | SELECTTRACE(1,pParse,p,("WhereBegin\n")); |
| 143322 | 144707 | pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct, |
| 143323 | | - 0, (sDistinct.isTnct==2 ? WHERE_DISTINCTBY : WHERE_GROUPBY) |
| 144708 | + p, (sDistinct.isTnct==2 ? WHERE_DISTINCTBY : WHERE_GROUPBY) |
| 143324 | 144709 | | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0 |
| 143325 | 144710 | ); |
| 143326 | 144711 | if( pWInfo==0 ){ |
| 143327 | 144712 | sqlite3ExprListDelete(db, pDistinct); |
| 143328 | 144713 | goto select_end; |
| | @@ -143617,11 +145002,11 @@ |
| 143617 | 145002 | assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 ); |
| 143618 | 145003 | assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 ); |
| 143619 | 145004 | |
| 143620 | 145005 | SELECTTRACE(1,pParse,p,("WhereBegin\n")); |
| 143621 | 145006 | pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy, |
| 143622 | | - pDistinct, 0, minMaxFlag|distFlag, 0); |
| 145007 | + pDistinct, p, minMaxFlag|distFlag, 0); |
| 143623 | 145008 | if( pWInfo==0 ){ |
| 143624 | 145009 | goto select_end; |
| 143625 | 145010 | } |
| 143626 | 145011 | SELECTTRACE(1,pParse,p,("WhereBegin returns\n")); |
| 143627 | 145012 | eDist = sqlite3WhereIsDistinct(pWInfo); |
| | @@ -145101,11 +146486,11 @@ |
| 145101 | 146486 | sSubParse.pTriggerTab = pTab; |
| 145102 | 146487 | sSubParse.pToplevel = pTop; |
| 145103 | 146488 | sSubParse.zAuthContext = pTrigger->zName; |
| 145104 | 146489 | sSubParse.eTriggerOp = pTrigger->op; |
| 145105 | 146490 | sSubParse.nQueryLoop = pParse->nQueryLoop; |
| 145106 | | - sSubParse.disableVtab = pParse->disableVtab; |
| 146491 | + sSubParse.prepFlags = pParse->prepFlags; |
| 145107 | 146492 | |
| 145108 | 146493 | v = sqlite3GetVdbe(&sSubParse); |
| 145109 | 146494 | if( v ){ |
| 145110 | 146495 | VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)", |
| 145111 | 146496 | pTrigger->zName, onErrorText(orconf), |
| | @@ -145447,15 +146832,18 @@ |
| 145447 | 146832 | ** (not a virtual table) then the value might have been stored as an |
| 145448 | 146833 | ** integer. In that case, add an OP_RealAffinity opcode to make sure |
| 145449 | 146834 | ** it has been converted into REAL. |
| 145450 | 146835 | */ |
| 145451 | 146836 | SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i, int iReg){ |
| 146837 | + Column *pCol; |
| 145452 | 146838 | assert( pTab!=0 ); |
| 145453 | | - if( !IsView(pTab) ){ |
| 146839 | + assert( pTab->nCol>i ); |
| 146840 | + pCol = &pTab->aCol[i]; |
| 146841 | + if( pCol->iDflt ){ |
| 145454 | 146842 | sqlite3_value *pValue = 0; |
| 145455 | 146843 | u8 enc = ENC(sqlite3VdbeDb(v)); |
| 145456 | | - Column *pCol = &pTab->aCol[i]; |
| 146844 | + assert( !IsView(pTab) ); |
| 145457 | 146845 | VdbeComment((v, "%s.%s", pTab->zName, pCol->zCnName)); |
| 145458 | 146846 | assert( i<pTab->nCol ); |
| 145459 | 146847 | sqlite3ValueFromExpr(sqlite3VdbeDb(v), |
| 145460 | 146848 | sqlite3ColumnExpr(pTab,pCol), enc, |
| 145461 | 146849 | pCol->affinity, &pValue); |
| | @@ -145462,11 +146850,11 @@ |
| 145462 | 146850 | if( pValue ){ |
| 145463 | 146851 | sqlite3VdbeAppendP4(v, pValue, P4_MEM); |
| 145464 | 146852 | } |
| 145465 | 146853 | } |
| 145466 | 146854 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 145467 | | - if( pTab->aCol[i].affinity==SQLITE_AFF_REAL && !IsVirtual(pTab) ){ |
| 146855 | + if( pCol->affinity==SQLITE_AFF_REAL && !IsVirtual(pTab) ){ |
| 145468 | 146856 | sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg); |
| 145469 | 146857 | } |
| 145470 | 146858 | #endif |
| 145471 | 146859 | } |
| 145472 | 146860 | |
| | @@ -146902,10 +148290,11 @@ |
| 146902 | 148290 | Expr *pExpr; |
| 146903 | 148291 | sCol[0].u.zToken = (char*)pIdx->azColl[ii]; |
| 146904 | 148292 | if( pIdx->aiColumn[ii]==XN_EXPR ){ |
| 146905 | 148293 | assert( pIdx->aColExpr!=0 ); |
| 146906 | 148294 | assert( pIdx->aColExpr->nExpr>ii ); |
| 148295 | + assert( pIdx->bHasExpr ); |
| 146907 | 148296 | pExpr = pIdx->aColExpr->a[ii].pExpr; |
| 146908 | 148297 | if( pExpr->op!=TK_COLLATE ){ |
| 146909 | 148298 | sCol[0].pLeft = pExpr; |
| 146910 | 148299 | pExpr = &sCol[0]; |
| 146911 | 148300 | } |
| | @@ -147215,10 +148604,11 @@ |
| 147215 | 148604 | int isMemDb; /* True if vacuuming a :memory: database */ |
| 147216 | 148605 | int nRes; /* Bytes of reserved space at the end of each page */ |
| 147217 | 148606 | int nDb; /* Number of attached databases */ |
| 147218 | 148607 | const char *zDbMain; /* Schema name of database to vacuum */ |
| 147219 | 148608 | const char *zOut; /* Name of output file */ |
| 148609 | + u32 pgflags = PAGER_SYNCHRONOUS_OFF; /* sync flags for output db */ |
| 147220 | 148610 | |
| 147221 | 148611 | if( !db->autoCommit ){ |
| 147222 | 148612 | sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction"); |
| 147223 | 148613 | return SQLITE_ERROR; /* IMP: R-12218-18073 */ |
| 147224 | 148614 | } |
| | @@ -147286,16 +148676,21 @@ |
| 147286 | 148676 | rc = SQLITE_ERROR; |
| 147287 | 148677 | sqlite3SetString(pzErrMsg, db, "output file already exists"); |
| 147288 | 148678 | goto end_of_vacuum; |
| 147289 | 148679 | } |
| 147290 | 148680 | db->mDbFlags |= DBFLAG_VacuumInto; |
| 148681 | + |
| 148682 | + /* For a VACUUM INTO, the pager-flags are set to the same values as |
| 148683 | + ** they are for the database being vacuumed, except that PAGER_CACHESPILL |
| 148684 | + ** is always set. */ |
| 148685 | + pgflags = db->aDb[iDb].safety_level | (db->flags & PAGER_FLAGS_MASK); |
| 147291 | 148686 | } |
| 147292 | 148687 | nRes = sqlite3BtreeGetRequestedReserve(pMain); |
| 147293 | 148688 | |
| 147294 | 148689 | sqlite3BtreeSetCacheSize(pTemp, db->aDb[iDb].pSchema->cache_size); |
| 147295 | 148690 | sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0)); |
| 147296 | | - sqlite3BtreeSetPagerFlags(pTemp, PAGER_SYNCHRONOUS_OFF|PAGER_CACHESPILL); |
| 148691 | + sqlite3BtreeSetPagerFlags(pTemp, pgflags|PAGER_CACHESPILL); |
| 147297 | 148692 | |
| 147298 | 148693 | /* Begin a transaction and take an exclusive lock on the main database |
| 147299 | 148694 | ** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below, |
| 147300 | 148695 | ** to ensure that we do not try to change the page-size on a WAL database. |
| 147301 | 148696 | */ |
| | @@ -148605,11 +150000,11 @@ |
| 148605 | 150000 | /* Check to see the left operand is a column in a virtual table */ |
| 148606 | 150001 | if( NEVER(pExpr==0) ) return pDef; |
| 148607 | 150002 | if( pExpr->op!=TK_COLUMN ) return pDef; |
| 148608 | 150003 | assert( ExprUseYTab(pExpr) ); |
| 148609 | 150004 | pTab = pExpr->y.pTab; |
| 148610 | | - if( pTab==0 ) return pDef; |
| 150005 | + if( NEVER(pTab==0) ) return pDef; |
| 148611 | 150006 | if( !IsVirtual(pTab) ) return pDef; |
| 148612 | 150007 | pVtab = sqlite3GetVTable(db, pTab)->pVtab; |
| 148613 | 150008 | assert( pVtab!=0 ); |
| 148614 | 150009 | assert( pVtab->pModule!=0 ); |
| 148615 | 150010 | pMod = (sqlite3_module *)pVtab->pModule; |
| | @@ -149212,11 +150607,11 @@ |
| 149212 | 150607 | /* |
| 149213 | 150608 | ** An instance of the following structure keeps track of a mapping |
| 149214 | 150609 | ** between VDBE cursor numbers and bits of the bitmasks in WhereTerm. |
| 149215 | 150610 | ** |
| 149216 | 150611 | ** The VDBE cursor numbers are small integers contained in |
| 149217 | | -** SrcList_item.iCursor and Expr.iTable fields. For any given WHERE |
| 150612 | +** SrcItem.iCursor and Expr.iTable fields. For any given WHERE |
| 149218 | 150613 | ** clause, the cursor numbers might not begin with 0 and they might |
| 149219 | 150614 | ** contain gaps in the numbering sequence. But we want to make maximum |
| 149220 | 150615 | ** use of the bits in our bitmasks. This structure provides a mapping |
| 149221 | 150616 | ** from the sparse cursor numbers into consecutive integers beginning |
| 149222 | 150617 | ** with 0. |
| | @@ -149283,24 +150678,10 @@ |
| 149283 | 150678 | #endif |
| 149284 | 150679 | #ifndef SQLITE_QUERY_PLANNER_LIMIT_INCR |
| 149285 | 150680 | # define SQLITE_QUERY_PLANNER_LIMIT_INCR 1000 |
| 149286 | 150681 | #endif |
| 149287 | 150682 | |
| 149288 | | -/* |
| 149289 | | -** Each instance of this object records a change to a single node |
| 149290 | | -** in an expression tree to cause that node to point to a column |
| 149291 | | -** of an index rather than an expression or a virtual column. All |
| 149292 | | -** such transformations need to be undone at the end of WHERE clause |
| 149293 | | -** processing. |
| 149294 | | -*/ |
| 149295 | | -typedef struct WhereExprMod WhereExprMod; |
| 149296 | | -struct WhereExprMod { |
| 149297 | | - WhereExprMod *pNext; /* Next translation on a list of them all */ |
| 149298 | | - Expr *pExpr; /* The Expr node that was transformed */ |
| 149299 | | - Expr orig; /* Original value of the Expr node */ |
| 149300 | | -}; |
| 149301 | | - |
| 149302 | 150683 | /* |
| 149303 | 150684 | ** The WHERE clause processing routine has two halves. The |
| 149304 | 150685 | ** first part does the start of the WHERE loop and the second |
| 149305 | 150686 | ** half does the tail of the WHERE loop. An instance of |
| 149306 | 150687 | ** this structure is returned by the first half and passed |
| | @@ -149312,14 +150693,14 @@ |
| 149312 | 150693 | struct WhereInfo { |
| 149313 | 150694 | Parse *pParse; /* Parsing and code generating context */ |
| 149314 | 150695 | SrcList *pTabList; /* List of tables in the join */ |
| 149315 | 150696 | ExprList *pOrderBy; /* The ORDER BY clause or NULL */ |
| 149316 | 150697 | ExprList *pResultSet; /* Result set of the query */ |
| 150698 | +#if WHERETRACE_ENABLED |
| 149317 | 150699 | Expr *pWhere; /* The complete WHERE clause */ |
| 149318 | | -#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 149319 | | - Select *pLimit; /* Used to access LIMIT expr/registers for vtabs */ |
| 149320 | 150700 | #endif |
| 150701 | + Select *pSelect; /* The entire SELECT statement containing WHERE */ |
| 149321 | 150702 | int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */ |
| 149322 | 150703 | int iContinue; /* Jump here to continue with next record */ |
| 149323 | 150704 | int iBreak; /* Jump here to break out of the loop */ |
| 149324 | 150705 | int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */ |
| 149325 | 150706 | u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */ |
| | @@ -149334,11 +150715,10 @@ |
| 149334 | 150715 | unsigned sorted :1; /* True if really sorted (not just grouped) */ |
| 149335 | 150716 | LogEst nRowOut; /* Estimated number of output rows */ |
| 149336 | 150717 | int iTop; /* The very beginning of the WHERE loop */ |
| 149337 | 150718 | int iEndWhere; /* End of the WHERE clause itself */ |
| 149338 | 150719 | WhereLoop *pLoops; /* List of all WhereLoop objects */ |
| 149339 | | - WhereExprMod *pExprMods; /* Expression modifications */ |
| 149340 | 150720 | WhereMemBlock *pMemToFree;/* Memory to free when this object destroyed */ |
| 149341 | 150721 | Bitmask revMask; /* Mask of ORDER BY terms that need reversing */ |
| 149342 | 150722 | WhereClause sWC; /* Decomposition of the WHERE clause */ |
| 149343 | 150723 | WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */ |
| 149344 | 150724 | WhereLevel a[1]; /* Information about each nest loop in WHERE */ |
| | @@ -150686,147 +152066,10 @@ |
| 150686 | 152066 | assert( nReg==1 || pParse->nErr ); |
| 150687 | 152067 | sqlite3ExprCode(pParse, p, iReg); |
| 150688 | 152068 | } |
| 150689 | 152069 | } |
| 150690 | 152070 | |
| 150691 | | -/* An instance of the IdxExprTrans object carries information about a |
| 150692 | | -** mapping from an expression on table columns into a column in an index |
| 150693 | | -** down through the Walker. |
| 150694 | | -*/ |
| 150695 | | -typedef struct IdxExprTrans { |
| 150696 | | - Expr *pIdxExpr; /* The index expression */ |
| 150697 | | - int iTabCur; /* The cursor of the corresponding table */ |
| 150698 | | - int iIdxCur; /* The cursor for the index */ |
| 150699 | | - int iIdxCol; /* The column for the index */ |
| 150700 | | - int iTabCol; /* The column for the table */ |
| 150701 | | - WhereInfo *pWInfo; /* Complete WHERE clause information */ |
| 150702 | | - sqlite3 *db; /* Database connection (for malloc()) */ |
| 150703 | | -} IdxExprTrans; |
| 150704 | | - |
| 150705 | | -/* |
| 150706 | | -** Preserve pExpr on the WhereETrans list of the WhereInfo. |
| 150707 | | -*/ |
| 150708 | | -static void preserveExpr(IdxExprTrans *pTrans, Expr *pExpr){ |
| 150709 | | - WhereExprMod *pNew; |
| 150710 | | - pNew = sqlite3DbMallocRaw(pTrans->db, sizeof(*pNew)); |
| 150711 | | - if( pNew==0 ) return; |
| 150712 | | - pNew->pNext = pTrans->pWInfo->pExprMods; |
| 150713 | | - pTrans->pWInfo->pExprMods = pNew; |
| 150714 | | - pNew->pExpr = pExpr; |
| 150715 | | - memcpy(&pNew->orig, pExpr, sizeof(*pExpr)); |
| 150716 | | -} |
| 150717 | | - |
| 150718 | | -/* The walker node callback used to transform matching expressions into |
| 150719 | | -** a reference to an index column for an index on an expression. |
| 150720 | | -** |
| 150721 | | -** If pExpr matches, then transform it into a reference to the index column |
| 150722 | | -** that contains the value of pExpr. |
| 150723 | | -*/ |
| 150724 | | -static int whereIndexExprTransNode(Walker *p, Expr *pExpr){ |
| 150725 | | - IdxExprTrans *pX = p->u.pIdxTrans; |
| 150726 | | - if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){ |
| 150727 | | - pExpr = sqlite3ExprSkipCollate(pExpr); |
| 150728 | | - preserveExpr(pX, pExpr); |
| 150729 | | - pExpr->affExpr = sqlite3ExprAffinity(pExpr); |
| 150730 | | - pExpr->op = TK_COLUMN; |
| 150731 | | - pExpr->iTable = pX->iIdxCur; |
| 150732 | | - pExpr->iColumn = pX->iIdxCol; |
| 150733 | | - testcase( ExprHasProperty(pExpr, EP_Unlikely) ); |
| 150734 | | - ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn); |
| 150735 | | - pExpr->y.pTab = 0; |
| 150736 | | - return WRC_Prune; |
| 150737 | | - }else{ |
| 150738 | | - return WRC_Continue; |
| 150739 | | - } |
| 150740 | | -} |
| 150741 | | - |
| 150742 | | -#ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 150743 | | -/* A walker node callback that translates a column reference to a table |
| 150744 | | -** into a corresponding column reference of an index. |
| 150745 | | -*/ |
| 150746 | | -static int whereIndexExprTransColumn(Walker *p, Expr *pExpr){ |
| 150747 | | - if( pExpr->op==TK_COLUMN ){ |
| 150748 | | - IdxExprTrans *pX = p->u.pIdxTrans; |
| 150749 | | - if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){ |
| 150750 | | - assert( ExprUseYTab(pExpr) && pExpr->y.pTab!=0 ); |
| 150751 | | - preserveExpr(pX, pExpr); |
| 150752 | | - pExpr->affExpr = sqlite3TableColumnAffinity(pExpr->y.pTab,pExpr->iColumn); |
| 150753 | | - pExpr->iTable = pX->iIdxCur; |
| 150754 | | - pExpr->iColumn = pX->iIdxCol; |
| 150755 | | - pExpr->y.pTab = 0; |
| 150756 | | - } |
| 150757 | | - } |
| 150758 | | - return WRC_Continue; |
| 150759 | | -} |
| 150760 | | -#endif /* SQLITE_OMIT_GENERATED_COLUMNS */ |
| 150761 | | - |
| 150762 | | -/* |
| 150763 | | -** For an indexes on expression X, locate every instance of expression X |
| 150764 | | -** in pExpr and change that subexpression into a reference to the appropriate |
| 150765 | | -** column of the index. |
| 150766 | | -** |
| 150767 | | -** 2019-10-24: Updated to also translate references to a VIRTUAL column in |
| 150768 | | -** the table into references to the corresponding (stored) column of the |
| 150769 | | -** index. |
| 150770 | | -*/ |
| 150771 | | -static void whereIndexExprTrans( |
| 150772 | | - Index *pIdx, /* The Index */ |
| 150773 | | - int iTabCur, /* Cursor of the table that is being indexed */ |
| 150774 | | - int iIdxCur, /* Cursor of the index itself */ |
| 150775 | | - WhereInfo *pWInfo /* Transform expressions in this WHERE clause */ |
| 150776 | | -){ |
| 150777 | | - int iIdxCol; /* Column number of the index */ |
| 150778 | | - ExprList *aColExpr; /* Expressions that are indexed */ |
| 150779 | | - Table *pTab; |
| 150780 | | - Walker w; |
| 150781 | | - IdxExprTrans x; |
| 150782 | | - aColExpr = pIdx->aColExpr; |
| 150783 | | - if( aColExpr==0 && !pIdx->bHasVCol ){ |
| 150784 | | - /* The index does not reference any expressions or virtual columns |
| 150785 | | - ** so no translations are needed. */ |
| 150786 | | - return; |
| 150787 | | - } |
| 150788 | | - pTab = pIdx->pTable; |
| 150789 | | - memset(&w, 0, sizeof(w)); |
| 150790 | | - w.u.pIdxTrans = &x; |
| 150791 | | - x.iTabCur = iTabCur; |
| 150792 | | - x.iIdxCur = iIdxCur; |
| 150793 | | - x.pWInfo = pWInfo; |
| 150794 | | - x.db = pWInfo->pParse->db; |
| 150795 | | - for(iIdxCol=0; iIdxCol<pIdx->nColumn; iIdxCol++){ |
| 150796 | | - i16 iRef = pIdx->aiColumn[iIdxCol]; |
| 150797 | | - if( iRef==XN_EXPR ){ |
| 150798 | | - assert( aColExpr!=0 && aColExpr->a[iIdxCol].pExpr!=0 ); |
| 150799 | | - x.pIdxExpr = aColExpr->a[iIdxCol].pExpr; |
| 150800 | | - if( sqlite3ExprIsConstant(x.pIdxExpr) ) continue; |
| 150801 | | - w.xExprCallback = whereIndexExprTransNode; |
| 150802 | | -#ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 150803 | | - }else if( iRef>=0 |
| 150804 | | - && (pTab->aCol[iRef].colFlags & COLFLAG_VIRTUAL)!=0 |
| 150805 | | - && ((pTab->aCol[iRef].colFlags & COLFLAG_HASCOLL)==0 |
| 150806 | | - || sqlite3StrICmp(sqlite3ColumnColl(&pTab->aCol[iRef]), |
| 150807 | | - sqlite3StrBINARY)==0) |
| 150808 | | - ){ |
| 150809 | | - /* Check to see if there are direct references to generated columns |
| 150810 | | - ** that are contained in the index. Pulling the generated column |
| 150811 | | - ** out of the index is an optimization only - the main table is always |
| 150812 | | - ** available if the index cannot be used. To avoid unnecessary |
| 150813 | | - ** complication, omit this optimization if the collating sequence for |
| 150814 | | - ** the column is non-standard */ |
| 150815 | | - x.iTabCol = iRef; |
| 150816 | | - w.xExprCallback = whereIndexExprTransColumn; |
| 150817 | | -#endif /* SQLITE_OMIT_GENERATED_COLUMNS */ |
| 150818 | | - }else{ |
| 150819 | | - continue; |
| 150820 | | - } |
| 150821 | | - x.iIdxCol = iIdxCol; |
| 150822 | | - sqlite3WalkExpr(&w, pWInfo->pWhere); |
| 150823 | | - sqlite3WalkExprList(&w, pWInfo->pOrderBy); |
| 150824 | | - sqlite3WalkExprList(&w, pWInfo->pResultSet); |
| 150825 | | - } |
| 150826 | | -} |
| 150827 | | - |
| 150828 | 152071 | /* |
| 150829 | 152072 | ** The pTruth expression is always true because it is the WHERE clause |
| 150830 | 152073 | ** a partial index that is driving a query loop. Look through all of the |
| 150831 | 152074 | ** WHERE clause terms on the query, and if any of those terms must be |
| 150832 | 152075 | ** true because pTruth is true, then mark those WHERE clause terms as |
| | @@ -150891,10 +152134,12 @@ |
| 150891 | 152134 | assert( pTerm!=0 ); |
| 150892 | 152135 | assert( pTerm->pExpr!=0 ); |
| 150893 | 152136 | testcase( pTerm->wtFlags & TERM_VIRTUAL ); |
| 150894 | 152137 | regRowid = sqlite3GetTempReg(pParse); |
| 150895 | 152138 | regRowid = codeEqualityTerm(pParse, pTerm, pLevel, 0, 0, regRowid); |
| 152139 | + sqlite3VdbeAddOp2(pParse->pVdbe, OP_MustBeInt, regRowid, addrNxt); |
| 152140 | + VdbeCoverage(pParse->pVdbe); |
| 150896 | 152141 | sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter, |
| 150897 | 152142 | addrNxt, regRowid, 1); |
| 150898 | 152143 | VdbeCoverage(pParse->pVdbe); |
| 150899 | 152144 | }else{ |
| 150900 | 152145 | u16 nEq = pLoop->u.btree.nEq; |
| | @@ -151042,13 +152287,13 @@ |
| 151042 | 152287 | codeExprOrVector(pParse, pRight, iTarget, 1); |
| 151043 | 152288 | if( pTerm->eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET |
| 151044 | 152289 | && pLoop->u.vtab.bOmitOffset |
| 151045 | 152290 | ){ |
| 151046 | 152291 | assert( pTerm->eOperator==WO_AUX ); |
| 151047 | | - assert( pWInfo->pLimit!=0 ); |
| 151048 | | - assert( pWInfo->pLimit->iOffset>0 ); |
| 151049 | | - sqlite3VdbeAddOp2(v, OP_Integer, 0, pWInfo->pLimit->iOffset); |
| 152292 | + assert( pWInfo->pSelect!=0 ); |
| 152293 | + assert( pWInfo->pSelect->iOffset>0 ); |
| 152294 | + sqlite3VdbeAddOp2(v, OP_Integer, 0, pWInfo->pSelect->iOffset); |
| 151050 | 152295 | VdbeComment((v,"Zero OFFSET counter")); |
| 151051 | 152296 | } |
| 151052 | 152297 | } |
| 151053 | 152298 | } |
| 151054 | 152299 | sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg); |
| | @@ -151152,10 +152397,12 @@ |
| 151152 | 152397 | iReleaseReg = ++pParse->nMem; |
| 151153 | 152398 | iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg); |
| 151154 | 152399 | if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg); |
| 151155 | 152400 | addrNxt = pLevel->addrNxt; |
| 151156 | 152401 | if( pLevel->regFilter ){ |
| 152402 | + sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt); |
| 152403 | + VdbeCoverage(v); |
| 151157 | 152404 | sqlite3VdbeAddOp4Int(v, OP_Filter, pLevel->regFilter, addrNxt, |
| 151158 | 152405 | iRowidReg, 1); |
| 151159 | 152406 | VdbeCoverage(v); |
| 151160 | 152407 | filterPullDown(pParse, pWInfo, iLevel, addrNxt, notReady); |
| 151161 | 152408 | } |
| | @@ -151503,10 +152750,15 @@ |
| 151503 | 152750 | ** of entries in the tree, so basing the number of steps to try |
| 151504 | 152751 | ** on the estimated number of rows in the btree seems like a good |
| 151505 | 152752 | ** guess. */ |
| 151506 | 152753 | addrSeekScan = sqlite3VdbeAddOp1(v, OP_SeekScan, |
| 151507 | 152754 | (pIdx->aiRowLogEst[0]+9)/10); |
| 152755 | + if( pRangeStart ){ |
| 152756 | + sqlite3VdbeChangeP5(v, 1); |
| 152757 | + sqlite3VdbeChangeP2(v, addrSeekScan, sqlite3VdbeCurrentAddr(v)+1); |
| 152758 | + addrSeekScan = 0; |
| 152759 | + } |
| 151508 | 152760 | VdbeCoverage(v); |
| 151509 | 152761 | } |
| 151510 | 152762 | sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint); |
| 151511 | 152763 | VdbeCoverage(v); |
| 151512 | 152764 | VdbeCoverageIf(v, op==OP_Rewind); testcase( op==OP_Rewind ); |
| | @@ -151641,31 +152893,10 @@ |
| 151641 | 152893 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont, |
| 151642 | 152894 | iRowidReg, pPk->nKeyCol); VdbeCoverage(v); |
| 151643 | 152895 | } |
| 151644 | 152896 | |
| 151645 | 152897 | if( pLevel->iLeftJoin==0 ){ |
| 151646 | | - /* If pIdx is an index on one or more expressions, then look through |
| 151647 | | - ** all the expressions in pWInfo and try to transform matching expressions |
| 151648 | | - ** into reference to index columns. Also attempt to translate references |
| 151649 | | - ** to virtual columns in the table into references to (stored) columns |
| 151650 | | - ** of the index. |
| 151651 | | - ** |
| 151652 | | - ** Do not do this for the RHS of a LEFT JOIN. This is because the |
| 151653 | | - ** expression may be evaluated after OP_NullRow has been executed on |
| 151654 | | - ** the cursor. In this case it is important to do the full evaluation, |
| 151655 | | - ** as the result of the expression may not be NULL, even if all table |
| 151656 | | - ** column values are. https://www.sqlite.org/src/info/7fa8049685b50b5a |
| 151657 | | - ** |
| 151658 | | - ** Also, do not do this when processing one index an a multi-index |
| 151659 | | - ** OR clause, since the transformation will become invalid once we |
| 151660 | | - ** move forward to the next index. |
| 151661 | | - ** https://sqlite.org/src/info/4e8e4857d32d401f |
| 151662 | | - */ |
| 151663 | | - if( (pWInfo->wctrlFlags & (WHERE_OR_SUBCLAUSE|WHERE_RIGHT_JOIN))==0 ){ |
| 151664 | | - whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo); |
| 151665 | | - } |
| 151666 | | - |
| 151667 | 152898 | /* If a partial index is driving the loop, try to eliminate WHERE clause |
| 151668 | 152899 | ** terms from the query that must be true due to the WHERE clause of |
| 151669 | 152900 | ** the partial index. |
| 151670 | 152901 | ** |
| 151671 | 152902 | ** 2019-11-02 ticket 623eff57e76d45f6: This optimization does not work |
| | @@ -151774,11 +153005,11 @@ |
| 151774 | 153005 | */ |
| 151775 | 153006 | if( pWInfo->nLevel>1 ){ |
| 151776 | 153007 | int nNotReady; /* The number of notReady tables */ |
| 151777 | 153008 | SrcItem *origSrc; /* Original list of tables */ |
| 151778 | 153009 | nNotReady = pWInfo->nLevel - iLevel - 1; |
| 151779 | | - pOrTab = sqlite3StackAllocRaw(db, |
| 153010 | + pOrTab = sqlite3DbMallocRawNN(db, |
| 151780 | 153011 | sizeof(*pOrTab)+ nNotReady*sizeof(pOrTab->a[0])); |
| 151781 | 153012 | if( pOrTab==0 ) return notReady; |
| 151782 | 153013 | pOrTab->nAlloc = (u8)(nNotReady + 1); |
| 151783 | 153014 | pOrTab->nSrc = pOrTab->nAlloc; |
| 151784 | 153015 | memcpy(pOrTab->a, pTabItem, sizeof(*pTabItem)); |
| | @@ -152027,11 +153258,11 @@ |
| 152027 | 153258 | ** indent everything in between the this point and the final OP_Return. |
| 152028 | 153259 | ** See tag-20220407a in vdbe.c and shell.c */ |
| 152029 | 153260 | assert( pLevel->op==OP_Return ); |
| 152030 | 153261 | pLevel->p2 = sqlite3VdbeCurrentAddr(v); |
| 152031 | 153262 | |
| 152032 | | - if( pWInfo->nLevel>1 ){ sqlite3StackFree(db, pOrTab); } |
| 153263 | + if( pWInfo->nLevel>1 ){ sqlite3DbFreeNN(db, pOrTab); } |
| 152033 | 153264 | if( !untestedTerms ) disableTerm(pLevel, pTerm); |
| 152034 | 153265 | }else |
| 152035 | 153266 | #endif /* SQLITE_OMIT_OR_OPTIMIZATION */ |
| 152036 | 153267 | |
| 152037 | 153268 | { |
| | @@ -152655,11 +153886,11 @@ |
| 152655 | 153886 | ** 2019-09-03 https://sqlite.org/src/info/0f0428096f17252a |
| 152656 | 153887 | */ |
| 152657 | 153888 | if( pLeft->op!=TK_COLUMN |
| 152658 | 153889 | || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT |
| 152659 | 153890 | || (ALWAYS( ExprUseYTab(pLeft) ) |
| 152660 | | - && pLeft->y.pTab |
| 153891 | + && ALWAYS(pLeft->y.pTab) |
| 152661 | 153892 | && IsVirtual(pLeft->y.pTab)) /* Might be numeric */ |
| 152662 | 153893 | ){ |
| 152663 | 153894 | int isNum; |
| 152664 | 153895 | double rDummy; |
| 152665 | 153896 | isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8); |
| | @@ -152772,12 +154003,11 @@ |
| 152772 | 154003 | ** |
| 152773 | 154004 | ** vtab_column MATCH expression |
| 152774 | 154005 | ** MATCH(expression,vtab_column) |
| 152775 | 154006 | */ |
| 152776 | 154007 | pCol = pList->a[1].pExpr; |
| 152777 | | - assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) ); |
| 152778 | | - testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 ); |
| 154008 | + assert( pCol->op!=TK_COLUMN || (ExprUseYTab(pCol) && pCol->y.pTab!=0) ); |
| 152779 | 154009 | if( ExprIsVtab(pCol) ){ |
| 152780 | 154010 | for(i=0; i<ArraySize(aOp); i++){ |
| 152781 | 154011 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 152782 | 154012 | if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){ |
| 152783 | 154013 | *peOp2 = aOp[i].eOp2; |
| | @@ -152798,11 +154028,11 @@ |
| 152798 | 154028 | ** names. But for this use case, xFindFunction is expected to deal |
| 152799 | 154029 | ** with function names in an arbitrary case. |
| 152800 | 154030 | */ |
| 152801 | 154031 | pCol = pList->a[0].pExpr; |
| 152802 | 154032 | assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) ); |
| 152803 | | - testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 ); |
| 154033 | + assert( pCol->op!=TK_COLUMN || (ExprUseYTab(pCol) && pCol->y.pTab!=0) ); |
| 152804 | 154034 | if( ExprIsVtab(pCol) ){ |
| 152805 | 154035 | sqlite3_vtab *pVtab; |
| 152806 | 154036 | sqlite3_module *pMod; |
| 152807 | 154037 | void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**); |
| 152808 | 154038 | void *pNotUsed; |
| | @@ -152823,17 +154053,16 @@ |
| 152823 | 154053 | } |
| 152824 | 154054 | }else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){ |
| 152825 | 154055 | int res = 0; |
| 152826 | 154056 | Expr *pLeft = pExpr->pLeft; |
| 152827 | 154057 | Expr *pRight = pExpr->pRight; |
| 152828 | | - assert( pLeft->op!=TK_COLUMN || ExprUseYTab(pLeft) ); |
| 152829 | | - testcase( pLeft->op==TK_COLUMN && pLeft->y.pTab==0 ); |
| 154058 | + assert( pLeft->op!=TK_COLUMN || (ExprUseYTab(pLeft) && pLeft->y.pTab!=0) ); |
| 152830 | 154059 | if( ExprIsVtab(pLeft) ){ |
| 152831 | 154060 | res++; |
| 152832 | 154061 | } |
| 152833 | | - assert( pRight==0 || pRight->op!=TK_COLUMN || ExprUseYTab(pRight) ); |
| 152834 | | - testcase( pRight && pRight->op==TK_COLUMN && pRight->y.pTab==0 ); |
| 154062 | + assert( pRight==0 || pRight->op!=TK_COLUMN |
| 154063 | + || (ExprUseYTab(pRight) && pRight->y.pTab!=0) ); |
| 152835 | 154064 | if( pRight && ExprIsVtab(pRight) ){ |
| 152836 | 154065 | res++; |
| 152837 | 154066 | SWAP(Expr*, pLeft, pRight); |
| 152838 | 154067 | } |
| 152839 | 154068 | *ppLeft = pLeft; |
| | @@ -153378,10 +154607,11 @@ |
| 153378 | 154607 | iCur = pFrom->a[i].iCursor; |
| 153379 | 154608 | for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 153380 | 154609 | if( pIdx->aColExpr==0 ) continue; |
| 153381 | 154610 | for(i=0; i<pIdx->nKeyCol; i++){ |
| 153382 | 154611 | if( pIdx->aiColumn[i]!=XN_EXPR ) continue; |
| 154612 | + assert( pIdx->bHasExpr ); |
| 153383 | 154613 | if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){ |
| 153384 | 154614 | aiCurCol[0] = iCur; |
| 153385 | 154615 | aiCurCol[1] = XN_EXPR; |
| 153386 | 154616 | return 1; |
| 153387 | 154617 | } |
| | @@ -153991,13 +155221,13 @@ |
| 153991 | 155221 | ** |
| 153992 | 155222 | ** LIMIT and OFFSET terms are ignored by most of the planner code. They |
| 153993 | 155223 | ** exist only so that they may be passed to the xBestIndex method of the |
| 153994 | 155224 | ** single virtual table in the FROM clause of the SELECT. |
| 153995 | 155225 | */ |
| 153996 | | -SQLITE_PRIVATE void sqlite3WhereAddLimit(WhereClause *pWC, Select *p){ |
| 153997 | | - assert( p==0 || (p->pGroupBy==0 && (p->selFlags & SF_Aggregate)==0) ); |
| 153998 | | - if( (p && p->pLimit) /* 1 */ |
| 155226 | +SQLITE_PRIVATE void SQLITE_NOINLINE sqlite3WhereAddLimit(WhereClause *pWC, Select *p){ |
| 155227 | + assert( p!=0 && p->pLimit!=0 ); /* 1 -- checked by caller */ |
| 155228 | + if( p->pGroupBy==0 |
| 153999 | 155229 | && (p->selFlags & (SF_Distinct|SF_Aggregate))==0 /* 2 */ |
| 154000 | 155230 | && (p->pSrc->nSrc==1 && IsVirtual(p->pSrc->a[0].pTab)) /* 3 */ |
| 154001 | 155231 | ){ |
| 154002 | 155232 | ExprList *pOrderBy = p->pOrderBy; |
| 154003 | 155233 | int iCsr = p->pSrc->a[0].iCursor; |
| | @@ -156530,30 +157760,18 @@ |
| 156530 | 157760 | while( pWInfo->pLoops ){ |
| 156531 | 157761 | WhereLoop *p = pWInfo->pLoops; |
| 156532 | 157762 | pWInfo->pLoops = p->pNextLoop; |
| 156533 | 157763 | whereLoopDelete(db, p); |
| 156534 | 157764 | } |
| 156535 | | - assert( pWInfo->pExprMods==0 ); |
| 156536 | 157765 | while( pWInfo->pMemToFree ){ |
| 156537 | 157766 | WhereMemBlock *pNext = pWInfo->pMemToFree->pNext; |
| 156538 | 157767 | sqlite3DbNNFreeNN(db, pWInfo->pMemToFree); |
| 156539 | 157768 | pWInfo->pMemToFree = pNext; |
| 156540 | 157769 | } |
| 156541 | 157770 | sqlite3DbNNFreeNN(db, pWInfo); |
| 156542 | 157771 | } |
| 156543 | 157772 | |
| 156544 | | -/* Undo all Expr node modifications |
| 156545 | | -*/ |
| 156546 | | -static void whereUndoExprMods(WhereInfo *pWInfo){ |
| 156547 | | - while( pWInfo->pExprMods ){ |
| 156548 | | - WhereExprMod *p = pWInfo->pExprMods; |
| 156549 | | - pWInfo->pExprMods = p->pNext; |
| 156550 | | - memcpy(p->pExpr, &p->orig, sizeof(p->orig)); |
| 156551 | | - sqlite3DbFree(pWInfo->pParse->db, p); |
| 156552 | | - } |
| 156553 | | -} |
| 156554 | | - |
| 156555 | 157773 | /* |
| 156556 | 157774 | ** Return TRUE if all of the following are true: |
| 156557 | 157775 | ** |
| 156558 | 157776 | ** (1) X has the same or lower cost, or returns the same or fewer rows, |
| 156559 | 157777 | ** than Y. |
| | @@ -157501,10 +158719,98 @@ |
| 157501 | 158719 | return 1; |
| 157502 | 158720 | } |
| 157503 | 158721 | } |
| 157504 | 158722 | return 0; |
| 157505 | 158723 | } |
| 158724 | + |
| 158725 | +/* |
| 158726 | +** Structure passed to the whereIsCoveringIndex Walker callback. |
| 158727 | +*/ |
| 158728 | +struct CoveringIndexCheck { |
| 158729 | + Index *pIdx; /* The index */ |
| 158730 | + int iTabCur; /* Cursor number for the corresponding table */ |
| 158731 | +}; |
| 158732 | + |
| 158733 | +/* |
| 158734 | +** Information passed in is pWalk->u.pCovIdxCk. Call is pCk. |
| 158735 | +** |
| 158736 | +** If the Expr node references the table with cursor pCk->iTabCur, then |
| 158737 | +** make sure that column is covered by the index pCk->pIdx. We know that |
| 158738 | +** all columns less than 63 (really BMS-1) are covered, so we don't need |
| 158739 | +** to check them. But we do need to check any column at 63 or greater. |
| 158740 | +** |
| 158741 | +** If the index does not cover the column, then set pWalk->eCode to |
| 158742 | +** non-zero and return WRC_Abort to stop the search. |
| 158743 | +** |
| 158744 | +** If this node does not disprove that the index can be a covering index, |
| 158745 | +** then just return WRC_Continue, to continue the search. |
| 158746 | +*/ |
| 158747 | +static int whereIsCoveringIndexWalkCallback(Walker *pWalk, Expr *pExpr){ |
| 158748 | + int i; /* Loop counter */ |
| 158749 | + const Index *pIdx; /* The index of interest */ |
| 158750 | + const i16 *aiColumn; /* Columns contained in the index */ |
| 158751 | + u16 nColumn; /* Number of columns in the index */ |
| 158752 | + if( pExpr->op!=TK_COLUMN && pExpr->op!=TK_AGG_COLUMN ) return WRC_Continue; |
| 158753 | + if( pExpr->iColumn<(BMS-1) ) return WRC_Continue; |
| 158754 | + if( pExpr->iTable!=pWalk->u.pCovIdxCk->iTabCur ) return WRC_Continue; |
| 158755 | + pIdx = pWalk->u.pCovIdxCk->pIdx; |
| 158756 | + aiColumn = pIdx->aiColumn; |
| 158757 | + nColumn = pIdx->nColumn; |
| 158758 | + for(i=0; i<nColumn; i++){ |
| 158759 | + if( aiColumn[i]==pExpr->iColumn ) return WRC_Continue; |
| 158760 | + } |
| 158761 | + pWalk->eCode = 1; |
| 158762 | + return WRC_Abort; |
| 158763 | +} |
| 158764 | + |
| 158765 | + |
| 158766 | +/* |
| 158767 | +** pIdx is an index that covers all of the low-number columns used by |
| 158768 | +** pWInfo->pSelect (columns from 0 through 62). But there are columns |
| 158769 | +** in pWInfo->pSelect beyond 62. This routine tries to answer the question |
| 158770 | +** of whether pIdx covers *all* columns in the query. |
| 158771 | +** |
| 158772 | +** Return 0 if pIdx is a covering index. Return non-zero if pIdx is |
| 158773 | +** not a covering index or if we are unable to determine if pIdx is a |
| 158774 | +** covering index. |
| 158775 | +** |
| 158776 | +** This routine is an optimization. It is always safe to return non-zero. |
| 158777 | +** But returning zero when non-zero should have been returned can lead to |
| 158778 | +** incorrect bytecode and assertion faults. |
| 158779 | +*/ |
| 158780 | +static SQLITE_NOINLINE u32 whereIsCoveringIndex( |
| 158781 | + WhereInfo *pWInfo, /* The WHERE clause context */ |
| 158782 | + Index *pIdx, /* Index that is being tested */ |
| 158783 | + int iTabCur /* Cursor for the table being indexed */ |
| 158784 | +){ |
| 158785 | + int i; |
| 158786 | + struct CoveringIndexCheck ck; |
| 158787 | + Walker w; |
| 158788 | + if( pWInfo->pSelect==0 ){ |
| 158789 | + /* We don't have access to the full query, so we cannot check to see |
| 158790 | + ** if pIdx is covering. Assume it is not. */ |
| 158791 | + return 1; |
| 158792 | + } |
| 158793 | + for(i=0; i<pIdx->nColumn; i++){ |
| 158794 | + if( pIdx->aiColumn[i]>=BMS-1 ) break; |
| 158795 | + } |
| 158796 | + if( i>=pIdx->nColumn ){ |
| 158797 | + /* pIdx does not index any columns greater than 62, but we know from |
| 158798 | + ** colMask that columns greater than 62 are used, so this is not a |
| 158799 | + ** covering index */ |
| 158800 | + return 1; |
| 158801 | + } |
| 158802 | + ck.pIdx = pIdx; |
| 158803 | + ck.iTabCur = iTabCur; |
| 158804 | + memset(&w, 0, sizeof(w)); |
| 158805 | + w.xExprCallback = whereIsCoveringIndexWalkCallback; |
| 158806 | + w.xSelectCallback = sqlite3SelectWalkNoop; |
| 158807 | + w.u.pCovIdxCk = &ck; |
| 158808 | + w.eCode = 0; |
| 158809 | + sqlite3WalkSelect(&w, pWInfo->pSelect); |
| 158810 | + return w.eCode; |
| 158811 | +} |
| 157506 | 158812 | |
| 157507 | 158813 | /* |
| 157508 | 158814 | ** Add all WhereLoop objects for a single table of the join where the table |
| 157509 | 158815 | ** is identified by pBuilder->pNew->iTab. That table is guaranteed to be |
| 157510 | 158816 | ** a b-tree table, not a virtual table. |
| | @@ -157719,10 +159025,13 @@ |
| 157719 | 159025 | if( pProbe->isCovering ){ |
| 157720 | 159026 | pNew->wsFlags = WHERE_IDX_ONLY | WHERE_INDEXED; |
| 157721 | 159027 | m = 0; |
| 157722 | 159028 | }else{ |
| 157723 | 159029 | m = pSrc->colUsed & pProbe->colNotIdxed; |
| 159030 | + if( m==TOPBIT ){ |
| 159031 | + m = whereIsCoveringIndex(pWInfo, pProbe, pSrc->iCursor); |
| 159032 | + } |
| 157724 | 159033 | pNew->wsFlags = (m==0) ? (WHERE_IDX_ONLY|WHERE_INDEXED) : WHERE_INDEXED; |
| 157725 | 159034 | } |
| 157726 | 159035 | |
| 157727 | 159036 | /* Full scan via index */ |
| 157728 | 159037 | if( b |
| | @@ -158944,11 +160253,10 @@ |
| 158944 | 160253 | */ |
| 158945 | 160254 | static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ |
| 158946 | 160255 | int mxChoice; /* Maximum number of simultaneous paths tracked */ |
| 158947 | 160256 | int nLoop; /* Number of terms in the join */ |
| 158948 | 160257 | Parse *pParse; /* Parsing context */ |
| 158949 | | - sqlite3 *db; /* The database connection */ |
| 158950 | 160258 | int iLoop; /* Loop counter over the terms of the join */ |
| 158951 | 160259 | int ii, jj; /* Loop counters */ |
| 158952 | 160260 | int mxI = 0; /* Index of next entry to replace */ |
| 158953 | 160261 | int nOrderBy; /* Number of ORDER BY clause terms */ |
| 158954 | 160262 | LogEst mxCost = 0; /* Maximum cost of a set of paths */ |
| | @@ -158963,11 +160271,10 @@ |
| 158963 | 160271 | LogEst *aSortCost = 0; /* Sorting and partial sorting costs */ |
| 158964 | 160272 | char *pSpace; /* Temporary memory used by this routine */ |
| 158965 | 160273 | int nSpace; /* Bytes of space allocated at pSpace */ |
| 158966 | 160274 | |
| 158967 | 160275 | pParse = pWInfo->pParse; |
| 158968 | | - db = pParse->db; |
| 158969 | 160276 | nLoop = pWInfo->nLevel; |
| 158970 | 160277 | /* TUNING: For simple queries, only the best path is tracked. |
| 158971 | 160278 | ** For 2-way joins, the 5 best paths are followed. |
| 158972 | 160279 | ** For joins of 3 or more tables, track the 10 best paths */ |
| 158973 | 160280 | mxChoice = (nLoop<=1) ? 1 : (nLoop==2 ? 5 : 10); |
| | @@ -158986,11 +160293,11 @@ |
| 158986 | 160293 | } |
| 158987 | 160294 | |
| 158988 | 160295 | /* Allocate and initialize space for aTo, aFrom and aSortCost[] */ |
| 158989 | 160296 | nSpace = (sizeof(WherePath)+sizeof(WhereLoop*)*nLoop)*mxChoice*2; |
| 158990 | 160297 | nSpace += sizeof(LogEst) * nOrderBy; |
| 158991 | | - pSpace = sqlite3DbMallocRawNN(db, nSpace); |
| 160298 | + pSpace = sqlite3StackAllocRawNN(pParse->db, nSpace); |
| 158992 | 160299 | if( pSpace==0 ) return SQLITE_NOMEM_BKPT; |
| 158993 | 160300 | aTo = (WherePath*)pSpace; |
| 158994 | 160301 | aFrom = aTo+mxChoice; |
| 158995 | 160302 | memset(aFrom, 0, sizeof(aFrom[0])); |
| 158996 | 160303 | pX = (WhereLoop**)(aFrom+mxChoice); |
| | @@ -159244,11 +160551,11 @@ |
| 159244 | 160551 | nFrom = nTo; |
| 159245 | 160552 | } |
| 159246 | 160553 | |
| 159247 | 160554 | if( nFrom==0 ){ |
| 159248 | 160555 | sqlite3ErrorMsg(pParse, "no query solution"); |
| 159249 | | - sqlite3DbFreeNN(db, pSpace); |
| 160556 | + sqlite3StackFreeNN(pParse->db, pSpace); |
| 159250 | 160557 | return SQLITE_ERROR; |
| 159251 | 160558 | } |
| 159252 | 160559 | |
| 159253 | 160560 | /* Find the lowest cost path. pFrom will be left pointing to that path */ |
| 159254 | 160561 | pFrom = aFrom; |
| | @@ -159326,12 +160633,11 @@ |
| 159326 | 160633 | |
| 159327 | 160634 | |
| 159328 | 160635 | pWInfo->nRowOut = pFrom->nRow; |
| 159329 | 160636 | |
| 159330 | 160637 | /* Free temporary memory and return success */ |
| 159331 | | - assert( db!=0 ); |
| 159332 | | - sqlite3DbNNFreeNN(db, pSpace); |
| 160638 | + sqlite3StackFreeNN(pParse->db, pSpace); |
| 159333 | 160639 | return SQLITE_OK; |
| 159334 | 160640 | } |
| 159335 | 160641 | |
| 159336 | 160642 | /* |
| 159337 | 160643 | ** Most queries use only a single table (they are not joins) and have |
| | @@ -159625,10 +160931,81 @@ |
| 159625 | 160931 | } |
| 159626 | 160932 | } |
| 159627 | 160933 | nSearch += pLoop->nOut; |
| 159628 | 160934 | } |
| 159629 | 160935 | } |
| 160936 | + |
| 160937 | +/* |
| 160938 | +** This is an sqlite3ParserAddCleanup() callback that is invoked to |
| 160939 | +** free the Parse->pIdxExpr list when the Parse object is destroyed. |
| 160940 | +*/ |
| 160941 | +static void whereIndexedExprCleanup(sqlite3 *db, void *pObject){ |
| 160942 | + Parse *pParse = (Parse*)pObject; |
| 160943 | + while( pParse->pIdxExpr!=0 ){ |
| 160944 | + IndexedExpr *p = pParse->pIdxExpr; |
| 160945 | + pParse->pIdxExpr = p->pIENext; |
| 160946 | + sqlite3ExprDelete(db, p->pExpr); |
| 160947 | + sqlite3DbFreeNN(db, p); |
| 160948 | + } |
| 160949 | +} |
| 160950 | + |
| 160951 | +/* |
| 160952 | +** The index pIdx is used by a query and contains one or more expressions. |
| 160953 | +** In other words pIdx is an index on an expression. iIdxCur is the cursor |
| 160954 | +** number for the index and iDataCur is the cursor number for the corresponding |
| 160955 | +** table. |
| 160956 | +** |
| 160957 | +** This routine adds IndexedExpr entries to the Parse->pIdxExpr field for |
| 160958 | +** each of the expressions in the index so that the expression code generator |
| 160959 | +** will know to replace occurrences of the indexed expression with |
| 160960 | +** references to the corresponding column of the index. |
| 160961 | +*/ |
| 160962 | +static SQLITE_NOINLINE void whereAddIndexedExpr( |
| 160963 | + Parse *pParse, /* Add IndexedExpr entries to pParse->pIdxExpr */ |
| 160964 | + Index *pIdx, /* The index-on-expression that contains the expressions */ |
| 160965 | + int iIdxCur, /* Cursor number for pIdx */ |
| 160966 | + SrcItem *pTabItem /* The FROM clause entry for the table */ |
| 160967 | +){ |
| 160968 | + int i; |
| 160969 | + IndexedExpr *p; |
| 160970 | + Table *pTab; |
| 160971 | + assert( pIdx->bHasExpr ); |
| 160972 | + pTab = pIdx->pTable; |
| 160973 | + for(i=0; i<pIdx->nColumn; i++){ |
| 160974 | + Expr *pExpr; |
| 160975 | + int j = pIdx->aiColumn[i]; |
| 160976 | + int bMaybeNullRow; |
| 160977 | + if( j==XN_EXPR ){ |
| 160978 | + pExpr = pIdx->aColExpr->a[i].pExpr; |
| 160979 | + testcase( pTabItem->fg.jointype & JT_LEFT ); |
| 160980 | + testcase( pTabItem->fg.jointype & JT_RIGHT ); |
| 160981 | + testcase( pTabItem->fg.jointype & JT_LTORJ ); |
| 160982 | + bMaybeNullRow = (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0; |
| 160983 | + }else if( j>=0 && (pTab->aCol[j].colFlags & COLFLAG_VIRTUAL)!=0 ){ |
| 160984 | + pExpr = sqlite3ColumnExpr(pTab, &pTab->aCol[j]); |
| 160985 | + bMaybeNullRow = 0; |
| 160986 | + }else{ |
| 160987 | + continue; |
| 160988 | + } |
| 160989 | + if( sqlite3ExprIsConstant(pExpr) ) continue; |
| 160990 | + p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexedExpr)); |
| 160991 | + if( p==0 ) break; |
| 160992 | + p->pIENext = pParse->pIdxExpr; |
| 160993 | + p->pExpr = sqlite3ExprDup(pParse->db, pExpr, 0); |
| 160994 | + p->iDataCur = pTabItem->iCursor; |
| 160995 | + p->iIdxCur = iIdxCur; |
| 160996 | + p->iIdxCol = i; |
| 160997 | + p->bMaybeNullRow = bMaybeNullRow; |
| 160998 | +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 160999 | + p->zIdxName = pIdx->zName; |
| 161000 | +#endif |
| 161001 | + pParse->pIdxExpr = p; |
| 161002 | + if( p->pIENext==0 ){ |
| 161003 | + sqlite3ParserAddCleanup(pParse, whereIndexedExprCleanup, pParse); |
| 161004 | + } |
| 161005 | + } |
| 161006 | +} |
| 159630 | 161007 | |
| 159631 | 161008 | /* |
| 159632 | 161009 | ** Generate the beginning of the loop used for WHERE clause processing. |
| 159633 | 161010 | ** The return value is a pointer to an opaque structure that contains |
| 159634 | 161011 | ** information needed to terminate the loop. Later, the calling routine |
| | @@ -159720,11 +161097,11 @@ |
| 159720 | 161097 | Parse *pParse, /* The parser context */ |
| 159721 | 161098 | SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */ |
| 159722 | 161099 | Expr *pWhere, /* The WHERE clause */ |
| 159723 | 161100 | ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */ |
| 159724 | 161101 | ExprList *pResultSet, /* Query result set. Req'd for DISTINCT */ |
| 159725 | | - Select *pLimit, /* Use this LIMIT/OFFSET clause, if any */ |
| 161102 | + Select *pSelect, /* The entire SELECT statement */ |
| 159726 | 161103 | u16 wctrlFlags, /* The WHERE_* flags defined in sqliteInt.h */ |
| 159727 | 161104 | int iAuxArg /* If WHERE_OR_SUBCLAUSE is set, index cursor number |
| 159728 | 161105 | ** If WHERE_USE_LIMIT, then the limit amount */ |
| 159729 | 161106 | ){ |
| 159730 | 161107 | int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */ |
| | @@ -159789,21 +161166,21 @@ |
| 159789 | 161166 | goto whereBeginError; |
| 159790 | 161167 | } |
| 159791 | 161168 | pWInfo->pParse = pParse; |
| 159792 | 161169 | pWInfo->pTabList = pTabList; |
| 159793 | 161170 | pWInfo->pOrderBy = pOrderBy; |
| 161171 | +#if WHERETRACE_ENABLED |
| 159794 | 161172 | pWInfo->pWhere = pWhere; |
| 161173 | +#endif |
| 159795 | 161174 | pWInfo->pResultSet = pResultSet; |
| 159796 | 161175 | pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1; |
| 159797 | 161176 | pWInfo->nLevel = nTabList; |
| 159798 | 161177 | pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(pParse); |
| 159799 | 161178 | pWInfo->wctrlFlags = wctrlFlags; |
| 159800 | 161179 | pWInfo->iLimit = iAuxArg; |
| 159801 | 161180 | pWInfo->savedNQueryLoop = pParse->nQueryLoop; |
| 159802 | | -#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 159803 | | - pWInfo->pLimit = pLimit; |
| 159804 | | -#endif |
| 161181 | + pWInfo->pSelect = pSelect; |
| 159805 | 161182 | memset(&pWInfo->nOBSat, 0, |
| 159806 | 161183 | offsetof(WhereInfo,sWC) - offsetof(WhereInfo,nOBSat)); |
| 159807 | 161184 | memset(&pWInfo->a[0], 0, sizeof(WhereLoop)+nTabList*sizeof(WhereLevel)); |
| 159808 | 161185 | assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */ |
| 159809 | 161186 | pMaskSet = &pWInfo->sMaskSet; |
| | @@ -159868,11 +161245,13 @@ |
| 159868 | 161245 | #endif |
| 159869 | 161246 | } |
| 159870 | 161247 | |
| 159871 | 161248 | /* Analyze all of the subexpressions. */ |
| 159872 | 161249 | sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC); |
| 159873 | | - sqlite3WhereAddLimit(&pWInfo->sWC, pLimit); |
| 161250 | + if( pSelect && pSelect->pLimit ){ |
| 161251 | + sqlite3WhereAddLimit(&pWInfo->sWC, pSelect); |
| 161252 | + } |
| 159874 | 161253 | if( pParse->nErr ) goto whereBeginError; |
| 159875 | 161254 | |
| 159876 | 161255 | /* Special case: WHERE terms that do not refer to any tables in the join |
| 159877 | 161256 | ** (constant expressions). Evaluate each such term, and jump over all the |
| 159878 | 161257 | ** generated code if the result is not true. |
| | @@ -160171,10 +161550,13 @@ |
| 160171 | 161550 | }else if( iAuxArg && (wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 ){ |
| 160172 | 161551 | iIndexCur = iAuxArg; |
| 160173 | 161552 | op = OP_ReopenIdx; |
| 160174 | 161553 | }else{ |
| 160175 | 161554 | iIndexCur = pParse->nTab++; |
| 161555 | + if( pIx->bHasExpr && OptimizationEnabled(db, SQLITE_IndexedExpr) ){ |
| 161556 | + whereAddIndexedExpr(pParse, pIx, iIndexCur, pTabItem); |
| 161557 | + } |
| 160176 | 161558 | } |
| 160177 | 161559 | pLevel->iIdxCur = iIndexCur; |
| 160178 | 161560 | assert( pIx!=0 ); |
| 160179 | 161561 | assert( pIx->pSchema==pTab->pSchema ); |
| 160180 | 161562 | assert( iIndexCur>=0 ); |
| | @@ -160293,12 +161675,10 @@ |
| 160293 | 161675 | return pWInfo; |
| 160294 | 161676 | |
| 160295 | 161677 | /* Jump here if malloc fails */ |
| 160296 | 161678 | whereBeginError: |
| 160297 | 161679 | if( pWInfo ){ |
| 160298 | | - testcase( pWInfo->pExprMods!=0 ); |
| 160299 | | - whereUndoExprMods(pWInfo); |
| 160300 | 161680 | pParse->nQueryLoop = pWInfo->savedNQueryLoop; |
| 160301 | 161681 | whereInfoFree(db, pWInfo); |
| 160302 | 161682 | } |
| 160303 | 161683 | return 0; |
| 160304 | 161684 | } |
| | @@ -160513,11 +161893,10 @@ |
| 160513 | 161893 | VdbeModuleComment((v, "End WHERE-loop%d: %s", i, |
| 160514 | 161894 | pWInfo->pTabList->a[pLevel->iFrom].pTab->zName)); |
| 160515 | 161895 | } |
| 160516 | 161896 | |
| 160517 | 161897 | assert( pWInfo->nLevel<=pTabList->nSrc ); |
| 160518 | | - if( pWInfo->pExprMods ) whereUndoExprMods(pWInfo); |
| 160519 | 161898 | for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){ |
| 160520 | 161899 | int k, last; |
| 160521 | 161900 | VdbeOp *pOp, *pLastOp; |
| 160522 | 161901 | Index *pIdx = 0; |
| 160523 | 161902 | SrcItem *pTabItem = &pTabList->a[pLevel->iFrom]; |
| | @@ -160566,10 +161945,20 @@ |
| 160566 | 161945 | ){ |
| 160567 | 161946 | if( pWInfo->eOnePass==ONEPASS_OFF || !HasRowid(pIdx->pTable) ){ |
| 160568 | 161947 | last = iEnd; |
| 160569 | 161948 | }else{ |
| 160570 | 161949 | last = pWInfo->iEndWhere; |
| 161950 | + } |
| 161951 | + if( pIdx->bHasExpr ){ |
| 161952 | + IndexedExpr *p = pParse->pIdxExpr; |
| 161953 | + while( p ){ |
| 161954 | + if( p->iIdxCur==pLevel->iIdxCur ){ |
| 161955 | + p->iDataCur = -1; |
| 161956 | + p->iIdxCur = -1; |
| 161957 | + } |
| 161958 | + p = p->pIENext; |
| 161959 | + } |
| 160571 | 161960 | } |
| 160572 | 161961 | k = pLevel->addrBody + 1; |
| 160573 | 161962 | #ifdef SQLITE_DEBUG |
| 160574 | 161963 | if( db->flags & SQLITE_VdbeAddopTrace ){ |
| 160575 | 161964 | printf("TRANSLATE opcodes in range %d..%d\n", k, last-1); |
| | @@ -174293,10 +175682,23 @@ |
| 174293 | 175682 | createCollation(db, "RTRIM", SQLITE_UTF8, 0, rtrimCollFunc, 0); |
| 174294 | 175683 | if( db->mallocFailed ){ |
| 174295 | 175684 | goto opendb_out; |
| 174296 | 175685 | } |
| 174297 | 175686 | |
| 175687 | +#if SQLITE_OS_UNIX && defined(SQLITE_OS_KV_OPTIONAL) |
| 175688 | + /* Process magic filenames ":localStorage:" and ":sessionStorage:" */ |
| 175689 | + if( zFilename && zFilename[0]==':' ){ |
| 175690 | + if( strcmp(zFilename, ":localStorage:")==0 ){ |
| 175691 | + zFilename = "file:local?vfs=kvvfs"; |
| 175692 | + flags |= SQLITE_OPEN_URI; |
| 175693 | + }else if( strcmp(zFilename, ":sessionStorage:")==0 ){ |
| 175694 | + zFilename = "file:session?vfs=kvvfs"; |
| 175695 | + flags |= SQLITE_OPEN_URI; |
| 175696 | + } |
| 175697 | + } |
| 175698 | +#endif /* SQLITE_OS_UNIX && defined(SQLITE_OS_KV_OPTIONAL) */ |
| 175699 | + |
| 174298 | 175700 | /* Parse the filename/URI argument |
| 174299 | 175701 | ** |
| 174300 | 175702 | ** Only allow sensible combinations of bits in the flags argument. |
| 174301 | 175703 | ** Throw an error if any non-sense combination is used. If we |
| 174302 | 175704 | ** do not block illegal combinations here, it could trigger |
| | @@ -175722,12 +177124,12 @@ |
| 175722 | 177124 | ** Recover as many snapshots as possible from the wal file associated with |
| 175723 | 177125 | ** schema zDb of database db. |
| 175724 | 177126 | */ |
| 175725 | 177127 | SQLITE_API int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb){ |
| 175726 | 177128 | int rc = SQLITE_ERROR; |
| 175727 | | - int iDb; |
| 175728 | 177129 | #ifndef SQLITE_OMIT_WAL |
| 177130 | + int iDb; |
| 175729 | 177131 | |
| 175730 | 177132 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 175731 | 177133 | if( !sqlite3SafetyCheckOk(db) ){ |
| 175732 | 177134 | return SQLITE_MISUSE_BKPT; |
| 175733 | 177135 | } |
| | @@ -201626,11 +203028,11 @@ |
| 201626 | 203028 | return SQLITE_LOCKED_VTAB; |
| 201627 | 203029 | } |
| 201628 | 203030 | rtreeReference(pRtree); |
| 201629 | 203031 | assert(nData>=1); |
| 201630 | 203032 | |
| 201631 | | - cell.iRowid = 0; /* Used only to suppress a compiler warning */ |
| 203033 | + memset(&cell, 0, sizeof(cell)); |
| 201632 | 203034 | |
| 201633 | 203035 | /* Constraint handling. A write operation on an r-tree table may return |
| 201634 | 203036 | ** SQLITE_CONSTRAINT for two reasons: |
| 201635 | 203037 | ** |
| 201636 | 203038 | ** 1. A duplicate rowid value, or |
| | @@ -236984,11 +238386,11 @@ |
| 236984 | 238386 | int nArg, /* Number of args */ |
| 236985 | 238387 | sqlite3_value **apUnused /* Function arguments */ |
| 236986 | 238388 | ){ |
| 236987 | 238389 | assert( nArg==0 ); |
| 236988 | 238390 | UNUSED_PARAM2(nArg, apUnused); |
| 236989 | | - sqlite3_result_text(pCtx, "fts5: 2022-09-28 19:14:01 f25cf63471cbed1edb27591e57fead62550d4046dbdcb61312288f0f6f24c646", -1, SQLITE_TRANSIENT); |
| 238391 | + sqlite3_result_text(pCtx, "fts5: 2022-10-26 11:11:31 3dfdfb3f12edb3f4267942598efd05d573e13b7c5d6cdbc3404373f41b8993dd", -1, SQLITE_TRANSIENT); |
| 236990 | 238392 | } |
| 236991 | 238393 | |
| 236992 | 238394 | /* |
| 236993 | 238395 | ** Return true if zName is the extension on one of the shadow tables used |
| 236994 | 238396 | ** by this module. |
| 236995 | 238397 | |