| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | | -** version 3.8.3.1. By combining all the individual C code files into this |
| 3 | +** version 3.8.4. By combining all the individual C code files into this |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| | @@ -23,10 +23,64 @@ |
| 23 | 23 | # define SQLITE_PRIVATE static |
| 24 | 24 | #endif |
| 25 | 25 | #ifndef SQLITE_API |
| 26 | 26 | # define SQLITE_API |
| 27 | 27 | #endif |
| 28 | +/************** Begin file sqliteInt.h ***************************************/ |
| 29 | +/* |
| 30 | +** 2001 September 15 |
| 31 | +** |
| 32 | +** The author disclaims copyright to this source code. In place of |
| 33 | +** a legal notice, here is a blessing: |
| 34 | +** |
| 35 | +** May you do good and not evil. |
| 36 | +** May you find forgiveness for yourself and forgive others. |
| 37 | +** May you share freely, never taking more than you give. |
| 38 | +** |
| 39 | +************************************************************************* |
| 40 | +** Internal interface definitions for SQLite. |
| 41 | +** |
| 42 | +*/ |
| 43 | +#ifndef _SQLITEINT_H_ |
| 44 | +#define _SQLITEINT_H_ |
| 45 | + |
| 46 | +/* |
| 47 | +** These #defines should enable >2GB file support on POSIX if the |
| 48 | +** underlying operating system supports it. If the OS lacks |
| 49 | +** large file support, or if the OS is windows, these should be no-ops. |
| 50 | +** |
| 51 | +** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any |
| 52 | +** system #includes. Hence, this block of code must be the very first |
| 53 | +** code in all source files. |
| 54 | +** |
| 55 | +** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch |
| 56 | +** on the compiler command line. This is necessary if you are compiling |
| 57 | +** on a recent machine (ex: Red Hat 7.2) but you want your code to work |
| 58 | +** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2 |
| 59 | +** without this option, LFS is enable. But LFS does not exist in the kernel |
| 60 | +** in Red Hat 6.0, so the code won't work. Hence, for maximum binary |
| 61 | +** portability you should omit LFS. |
| 62 | +** |
| 63 | +** The previous paragraph was written in 2005. (This paragraph is written |
| 64 | +** on 2008-11-28.) These days, all Linux kernels support large files, so |
| 65 | +** you should probably leave LFS enabled. But some embedded platforms might |
| 66 | +** lack LFS in which case the SQLITE_DISABLE_LFS macro might still be useful. |
| 67 | +** |
| 68 | +** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later. |
| 69 | +*/ |
| 70 | +#ifndef SQLITE_DISABLE_LFS |
| 71 | +# define _LARGE_FILE 1 |
| 72 | +# ifndef _FILE_OFFSET_BITS |
| 73 | +# define _FILE_OFFSET_BITS 64 |
| 74 | +# endif |
| 75 | +# define _LARGEFILE_SOURCE 1 |
| 76 | +#endif |
| 77 | + |
| 78 | +/* The public SQLite interface. The _FILE_OFFSET_BITS macro must appear |
| 79 | +** first in QNX. |
| 80 | +*/ |
| 81 | +/************** Include sqlite3.h in the middle of sqliteInt.h ***************/ |
| 28 | 82 | /************** Begin file sqlite3.h *****************************************/ |
| 29 | 83 | /* |
| 30 | 84 | ** 2001 September 15 |
| 31 | 85 | ** |
| 32 | 86 | ** The author disclaims copyright to this source code. In place of |
| | @@ -133,13 +187,13 @@ |
| 133 | 187 | ** |
| 134 | 188 | ** See also: [sqlite3_libversion()], |
| 135 | 189 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 136 | 190 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 137 | 191 | */ |
| 138 | | -#define SQLITE_VERSION "3.8.3.1" |
| 139 | | -#define SQLITE_VERSION_NUMBER 3008003 |
| 140 | | -#define SQLITE_SOURCE_ID "2014-02-11 14:52:19 ea3317a4803d71d88183b29f1d3086f46d68a00e" |
| 192 | +#define SQLITE_VERSION "3.8.4" |
| 193 | +#define SQLITE_VERSION_NUMBER 3008004 |
| 194 | +#define SQLITE_SOURCE_ID "2014-02-27 15:04:13 a6690400235705ecc0d1a60dacff6ad5fb1f944a" |
| 141 | 195 | |
| 142 | 196 | /* |
| 143 | 197 | ** CAPI3REF: Run-Time Library Version Numbers |
| 144 | 198 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 145 | 199 | ** |
| | @@ -6148,11 +6202,12 @@ |
| 6148 | 6202 | #define SQLITE_TESTCTRL_ISKEYWORD 16 |
| 6149 | 6203 | #define SQLITE_TESTCTRL_SCRATCHMALLOC 17 |
| 6150 | 6204 | #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18 |
| 6151 | 6205 | #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 |
| 6152 | 6206 | #define SQLITE_TESTCTRL_NEVER_CORRUPT 20 |
| 6153 | | -#define SQLITE_TESTCTRL_LAST 20 |
| 6207 | +#define SQLITE_TESTCTRL_VDBE_COVERAGE 21 |
| 6208 | +#define SQLITE_TESTCTRL_LAST 21 |
| 6154 | 6209 | |
| 6155 | 6210 | /* |
| 6156 | 6211 | ** CAPI3REF: SQLite Runtime Status |
| 6157 | 6212 | ** |
| 6158 | 6213 | ** ^This interface is used to retrieve runtime status information |
| | @@ -7411,54 +7466,11 @@ |
| 7411 | 7466 | |
| 7412 | 7467 | #endif /* ifndef _SQLITE3RTREE_H_ */ |
| 7413 | 7468 | |
| 7414 | 7469 | |
| 7415 | 7470 | /************** End of sqlite3.h *********************************************/ |
| 7416 | | -/************** Begin file sqliteInt.h ***************************************/ |
| 7417 | | -/* |
| 7418 | | -** 2001 September 15 |
| 7419 | | -** |
| 7420 | | -** The author disclaims copyright to this source code. In place of |
| 7421 | | -** a legal notice, here is a blessing: |
| 7422 | | -** |
| 7423 | | -** May you do good and not evil. |
| 7424 | | -** May you find forgiveness for yourself and forgive others. |
| 7425 | | -** May you share freely, never taking more than you give. |
| 7426 | | -** |
| 7427 | | -************************************************************************* |
| 7428 | | -** Internal interface definitions for SQLite. |
| 7429 | | -** |
| 7430 | | -*/ |
| 7431 | | -#ifndef _SQLITEINT_H_ |
| 7432 | | -#define _SQLITEINT_H_ |
| 7433 | | - |
| 7434 | | -/* |
| 7435 | | -** These #defines should enable >2GB file support on POSIX if the |
| 7436 | | -** underlying operating system supports it. If the OS lacks |
| 7437 | | -** large file support, or if the OS is windows, these should be no-ops. |
| 7438 | | -** |
| 7439 | | -** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any |
| 7440 | | -** system #includes. Hence, this block of code must be the very first |
| 7441 | | -** code in all source files. |
| 7442 | | -** |
| 7443 | | -** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch |
| 7444 | | -** on the compiler command line. This is necessary if you are compiling |
| 7445 | | -** on a recent machine (ex: Red Hat 7.2) but you want your code to work |
| 7446 | | -** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2 |
| 7447 | | -** without this option, LFS is enable. But LFS does not exist in the kernel |
| 7448 | | -** in Red Hat 6.0, so the code won't work. Hence, for maximum binary |
| 7449 | | -** portability you should omit LFS. |
| 7450 | | -** |
| 7451 | | -** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later. |
| 7452 | | -*/ |
| 7453 | | -#ifndef SQLITE_DISABLE_LFS |
| 7454 | | -# define _LARGE_FILE 1 |
| 7455 | | -# ifndef _FILE_OFFSET_BITS |
| 7456 | | -# define _FILE_OFFSET_BITS 64 |
| 7457 | | -# endif |
| 7458 | | -# define _LARGEFILE_SOURCE 1 |
| 7459 | | -#endif |
| 7471 | +/************** Continuing where we left off in sqliteInt.h ******************/ |
| 7460 | 7472 | |
| 7461 | 7473 | /* |
| 7462 | 7474 | ** Include the configuration header output by 'configure' if we're using the |
| 7463 | 7475 | ** autoconf-based build |
| 7464 | 7476 | */ |
| | @@ -8841,12 +8853,10 @@ |
| 8841 | 8853 | SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*); |
| 8842 | 8854 | SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt); |
| 8843 | 8855 | SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt); |
| 8844 | 8856 | SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize); |
| 8845 | 8857 | SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*); |
| 8846 | | -SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64); |
| 8847 | | -SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*); |
| 8848 | 8858 | |
| 8849 | 8859 | SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*); |
| 8850 | 8860 | SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*); |
| 8851 | 8861 | |
| 8852 | 8862 | SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*); |
| | @@ -8982,13 +8992,16 @@ |
| 8982 | 8992 | } p4; |
| 8983 | 8993 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 8984 | 8994 | char *zComment; /* Comment to improve readability */ |
| 8985 | 8995 | #endif |
| 8986 | 8996 | #ifdef VDBE_PROFILE |
| 8987 | | - int cnt; /* Number of times this instruction was executed */ |
| 8997 | + u32 cnt; /* Number of times this instruction was executed */ |
| 8988 | 8998 | u64 cycles; /* Total time spent executing this instruction */ |
| 8989 | 8999 | #endif |
| 9000 | +#ifdef SQLITE_VDBE_COVERAGE |
| 9001 | + int iSrcLine; /* Source-code line that generated this opcode */ |
| 9002 | +#endif |
| 8990 | 9003 | }; |
| 8991 | 9004 | typedef struct VdbeOp VdbeOp; |
| 8992 | 9005 | |
| 8993 | 9006 | |
| 8994 | 9007 | /* |
| | @@ -9094,75 +9107,75 @@ |
| 9094 | 9107 | #define OP_VUpdate 15 /* synopsis: data=r[P3@P2] */ |
| 9095 | 9108 | #define OP_Goto 16 |
| 9096 | 9109 | #define OP_Gosub 17 |
| 9097 | 9110 | #define OP_Return 18 |
| 9098 | 9111 | #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */ |
| 9099 | | -#define OP_Yield 20 |
| 9100 | | -#define OP_HaltIfNull 21 /* synopsis: if r[P3] null then halt */ |
| 9101 | | -#define OP_Halt 22 |
| 9102 | | -#define OP_Integer 23 /* synopsis: r[P2]=P1 */ |
| 9103 | | -#define OP_Int64 24 /* synopsis: r[P2]=P4 */ |
| 9104 | | -#define OP_String 25 /* synopsis: r[P2]='P4' (len=P1) */ |
| 9105 | | -#define OP_Null 26 /* synopsis: r[P2..P3]=NULL */ |
| 9106 | | -#define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */ |
| 9107 | | -#define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 9108 | | -#define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 9109 | | -#define OP_Copy 30 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ |
| 9110 | | -#define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */ |
| 9111 | | -#define OP_ResultRow 32 /* synopsis: output=r[P1@P2] */ |
| 9112 | | -#define OP_CollSeq 33 |
| 9113 | | -#define OP_AddImm 34 /* synopsis: r[P1]=r[P1]+P2 */ |
| 9114 | | -#define OP_MustBeInt 35 |
| 9115 | | -#define OP_RealAffinity 36 |
| 9116 | | -#define OP_Permutation 37 |
| 9117 | | -#define OP_Compare 38 |
| 9118 | | -#define OP_Jump 39 |
| 9119 | | -#define OP_Once 40 |
| 9120 | | -#define OP_If 41 |
| 9121 | | -#define OP_IfNot 42 |
| 9122 | | -#define OP_Column 43 /* synopsis: r[P3]=PX */ |
| 9123 | | -#define OP_Affinity 44 /* synopsis: affinity(r[P1@P2]) */ |
| 9124 | | -#define OP_MakeRecord 45 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 9125 | | -#define OP_Count 46 /* synopsis: r[P2]=count() */ |
| 9126 | | -#define OP_ReadCookie 47 |
| 9127 | | -#define OP_SetCookie 48 |
| 9128 | | -#define OP_VerifyCookie 49 |
| 9129 | | -#define OP_OpenRead 50 /* synopsis: root=P2 iDb=P3 */ |
| 9130 | | -#define OP_OpenWrite 51 /* synopsis: root=P2 iDb=P3 */ |
| 9131 | | -#define OP_OpenAutoindex 52 /* synopsis: nColumn=P2 */ |
| 9132 | | -#define OP_OpenEphemeral 53 /* synopsis: nColumn=P2 */ |
| 9133 | | -#define OP_SorterOpen 54 |
| 9134 | | -#define OP_OpenPseudo 55 /* synopsis: content in r[P2@P3] */ |
| 9135 | | -#define OP_Close 56 |
| 9136 | | -#define OP_SeekLt 57 /* synopsis: key=r[P3@P4] */ |
| 9137 | | -#define OP_SeekLe 58 /* synopsis: key=r[P3@P4] */ |
| 9138 | | -#define OP_SeekGe 59 /* synopsis: key=r[P3@P4] */ |
| 9139 | | -#define OP_SeekGt 60 /* synopsis: key=r[P3@P4] */ |
| 9140 | | -#define OP_Seek 61 /* synopsis: intkey=r[P2] */ |
| 9141 | | -#define OP_NoConflict 62 /* synopsis: key=r[P3@P4] */ |
| 9142 | | -#define OP_NotFound 63 /* synopsis: key=r[P3@P4] */ |
| 9143 | | -#define OP_Found 64 /* synopsis: key=r[P3@P4] */ |
| 9144 | | -#define OP_NotExists 65 /* synopsis: intkey=r[P3] */ |
| 9145 | | -#define OP_Sequence 66 /* synopsis: r[P2]=rowid */ |
| 9146 | | -#define OP_NewRowid 67 /* synopsis: r[P2]=rowid */ |
| 9147 | | -#define OP_Insert 68 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 9148 | | -#define OP_InsertInt 69 /* synopsis: intkey=P3 data=r[P2] */ |
| 9149 | | -#define OP_Delete 70 |
| 9112 | +#define OP_InitCoroutine 20 |
| 9113 | +#define OP_EndCoroutine 21 |
| 9114 | +#define OP_Yield 22 |
| 9115 | +#define OP_HaltIfNull 23 /* synopsis: if r[P3]=null halt */ |
| 9116 | +#define OP_Halt 24 |
| 9117 | +#define OP_Integer 25 /* synopsis: r[P2]=P1 */ |
| 9118 | +#define OP_Int64 26 /* synopsis: r[P2]=P4 */ |
| 9119 | +#define OP_String 27 /* synopsis: r[P2]='P4' (len=P1) */ |
| 9120 | +#define OP_Null 28 /* synopsis: r[P2..P3]=NULL */ |
| 9121 | +#define OP_SoftNull 29 /* synopsis: r[P1]=NULL */ |
| 9122 | +#define OP_Blob 30 /* synopsis: r[P2]=P4 (len=P1) */ |
| 9123 | +#define OP_Variable 31 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 9124 | +#define OP_Move 32 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 9125 | +#define OP_Copy 33 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ |
| 9126 | +#define OP_SCopy 34 /* synopsis: r[P2]=r[P1] */ |
| 9127 | +#define OP_ResultRow 35 /* synopsis: output=r[P1@P2] */ |
| 9128 | +#define OP_CollSeq 36 |
| 9129 | +#define OP_AddImm 37 /* synopsis: r[P1]=r[P1]+P2 */ |
| 9130 | +#define OP_MustBeInt 38 |
| 9131 | +#define OP_RealAffinity 39 |
| 9132 | +#define OP_Permutation 40 |
| 9133 | +#define OP_Compare 41 |
| 9134 | +#define OP_Jump 42 |
| 9135 | +#define OP_Once 43 |
| 9136 | +#define OP_If 44 |
| 9137 | +#define OP_IfNot 45 |
| 9138 | +#define OP_Column 46 /* synopsis: r[P3]=PX */ |
| 9139 | +#define OP_Affinity 47 /* synopsis: affinity(r[P1@P2]) */ |
| 9140 | +#define OP_MakeRecord 48 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 9141 | +#define OP_Count 49 /* synopsis: r[P2]=count() */ |
| 9142 | +#define OP_ReadCookie 50 |
| 9143 | +#define OP_SetCookie 51 |
| 9144 | +#define OP_OpenRead 52 /* synopsis: root=P2 iDb=P3 */ |
| 9145 | +#define OP_OpenWrite 53 /* synopsis: root=P2 iDb=P3 */ |
| 9146 | +#define OP_OpenAutoindex 54 /* synopsis: nColumn=P2 */ |
| 9147 | +#define OP_OpenEphemeral 55 /* synopsis: nColumn=P2 */ |
| 9148 | +#define OP_SorterOpen 56 |
| 9149 | +#define OP_OpenPseudo 57 /* synopsis: P3 columns in r[P2] */ |
| 9150 | +#define OP_Close 58 |
| 9151 | +#define OP_SeekLT 59 |
| 9152 | +#define OP_SeekLE 60 |
| 9153 | +#define OP_SeekGE 61 |
| 9154 | +#define OP_SeekGT 62 |
| 9155 | +#define OP_Seek 63 /* synopsis: intkey=r[P2] */ |
| 9156 | +#define OP_NoConflict 64 /* synopsis: key=r[P3@P4] */ |
| 9157 | +#define OP_NotFound 65 /* synopsis: key=r[P3@P4] */ |
| 9158 | +#define OP_Found 66 /* synopsis: key=r[P3@P4] */ |
| 9159 | +#define OP_NotExists 67 /* synopsis: intkey=r[P3] */ |
| 9160 | +#define OP_Sequence 68 /* synopsis: r[P2]=rowid */ |
| 9161 | +#define OP_NewRowid 69 /* synopsis: r[P2]=rowid */ |
| 9162 | +#define OP_Insert 70 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 9150 | 9163 | #define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */ |
| 9151 | 9164 | #define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */ |
| 9152 | | -#define OP_ResetCount 73 |
| 9153 | | -#define OP_SorterCompare 74 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */ |
| 9154 | | -#define OP_SorterData 75 /* synopsis: r[P2]=data */ |
| 9165 | +#define OP_InsertInt 73 /* synopsis: intkey=P3 data=r[P2] */ |
| 9166 | +#define OP_Delete 74 |
| 9167 | +#define OP_ResetCount 75 |
| 9155 | 9168 | #define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */ |
| 9156 | 9169 | #define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */ |
| 9157 | 9170 | #define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */ |
| 9158 | 9171 | #define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */ |
| 9159 | 9172 | #define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */ |
| 9160 | 9173 | #define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */ |
| 9161 | 9174 | #define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */ |
| 9162 | 9175 | #define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */ |
| 9163 | | -#define OP_RowKey 84 /* synopsis: r[P2]=key */ |
| 9176 | +#define OP_SorterCompare 84 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */ |
| 9164 | 9177 | #define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */ |
| 9165 | 9178 | #define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */ |
| 9166 | 9179 | #define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */ |
| 9167 | 9180 | #define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */ |
| 9168 | 9181 | #define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */ |
| | @@ -9169,68 +9182,72 @@ |
| 9169 | 9182 | #define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */ |
| 9170 | 9183 | #define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */ |
| 9171 | 9184 | #define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */ |
| 9172 | 9185 | #define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */ |
| 9173 | 9186 | #define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */ |
| 9174 | | -#define OP_RowData 95 /* synopsis: r[P2]=data */ |
| 9187 | +#define OP_SorterData 95 /* synopsis: r[P2]=data */ |
| 9175 | 9188 | #define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */ |
| 9176 | 9189 | #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */ |
| 9177 | | -#define OP_Rowid 98 /* synopsis: r[P2]=rowid */ |
| 9178 | | -#define OP_NullRow 99 |
| 9179 | | -#define OP_Last 100 |
| 9180 | | -#define OP_SorterSort 101 |
| 9181 | | -#define OP_Sort 102 |
| 9182 | | -#define OP_Rewind 103 |
| 9183 | | -#define OP_SorterInsert 104 |
| 9184 | | -#define OP_IdxInsert 105 /* synopsis: key=r[P2] */ |
| 9185 | | -#define OP_IdxDelete 106 /* synopsis: key=r[P2@P3] */ |
| 9186 | | -#define OP_IdxRowid 107 /* synopsis: r[P2]=rowid */ |
| 9187 | | -#define OP_IdxLT 108 /* synopsis: key=r[P3@P4] */ |
| 9188 | | -#define OP_IdxGE 109 /* synopsis: key=r[P3@P4] */ |
| 9189 | | -#define OP_Destroy 110 |
| 9190 | | -#define OP_Clear 111 |
| 9191 | | -#define OP_CreateIndex 112 /* synopsis: r[P2]=root iDb=P1 */ |
| 9192 | | -#define OP_CreateTable 113 /* synopsis: r[P2]=root iDb=P1 */ |
| 9193 | | -#define OP_ParseSchema 114 |
| 9194 | | -#define OP_LoadAnalysis 115 |
| 9195 | | -#define OP_DropTable 116 |
| 9196 | | -#define OP_DropIndex 117 |
| 9197 | | -#define OP_DropTrigger 118 |
| 9198 | | -#define OP_IntegrityCk 119 |
| 9199 | | -#define OP_RowSetAdd 120 /* synopsis: rowset(P1)=r[P2] */ |
| 9200 | | -#define OP_RowSetRead 121 /* synopsis: r[P3]=rowset(P1) */ |
| 9201 | | -#define OP_RowSetTest 122 /* synopsis: if r[P3] in rowset(P1) goto P2 */ |
| 9202 | | -#define OP_Program 123 |
| 9203 | | -#define OP_Param 124 |
| 9204 | | -#define OP_FkCounter 125 /* synopsis: fkctr[P1]+=P2 */ |
| 9205 | | -#define OP_FkIfZero 126 /* synopsis: if fkctr[P1]==0 goto P2 */ |
| 9206 | | -#define OP_MemMax 127 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 9207 | | -#define OP_IfPos 128 /* synopsis: if r[P1]>0 goto P2 */ |
| 9208 | | -#define OP_IfNeg 129 /* synopsis: if r[P1]<0 goto P2 */ |
| 9209 | | -#define OP_IfZero 130 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */ |
| 9210 | | -#define OP_AggFinal 131 /* synopsis: accum=r[P1] N=P2 */ |
| 9211 | | -#define OP_IncrVacuum 132 |
| 9190 | +#define OP_RowKey 98 /* synopsis: r[P2]=key */ |
| 9191 | +#define OP_RowData 99 /* synopsis: r[P2]=data */ |
| 9192 | +#define OP_Rowid 100 /* synopsis: r[P2]=rowid */ |
| 9193 | +#define OP_NullRow 101 |
| 9194 | +#define OP_Last 102 |
| 9195 | +#define OP_SorterSort 103 |
| 9196 | +#define OP_Sort 104 |
| 9197 | +#define OP_Rewind 105 |
| 9198 | +#define OP_SorterInsert 106 |
| 9199 | +#define OP_IdxInsert 107 /* synopsis: key=r[P2] */ |
| 9200 | +#define OP_IdxDelete 108 /* synopsis: key=r[P2@P3] */ |
| 9201 | +#define OP_IdxRowid 109 /* synopsis: r[P2]=rowid */ |
| 9202 | +#define OP_IdxLE 110 /* synopsis: key=r[P3@P4] */ |
| 9203 | +#define OP_IdxGT 111 /* synopsis: key=r[P3@P4] */ |
| 9204 | +#define OP_IdxLT 112 /* synopsis: key=r[P3@P4] */ |
| 9205 | +#define OP_IdxGE 113 /* synopsis: key=r[P3@P4] */ |
| 9206 | +#define OP_Destroy 114 |
| 9207 | +#define OP_Clear 115 |
| 9208 | +#define OP_CreateIndex 116 /* synopsis: r[P2]=root iDb=P1 */ |
| 9209 | +#define OP_CreateTable 117 /* synopsis: r[P2]=root iDb=P1 */ |
| 9210 | +#define OP_ParseSchema 118 |
| 9211 | +#define OP_LoadAnalysis 119 |
| 9212 | +#define OP_DropTable 120 |
| 9213 | +#define OP_DropIndex 121 |
| 9214 | +#define OP_DropTrigger 122 |
| 9215 | +#define OP_IntegrityCk 123 |
| 9216 | +#define OP_RowSetAdd 124 /* synopsis: rowset(P1)=r[P2] */ |
| 9217 | +#define OP_RowSetRead 125 /* synopsis: r[P3]=rowset(P1) */ |
| 9218 | +#define OP_RowSetTest 126 /* synopsis: if r[P3] in rowset(P1) goto P2 */ |
| 9219 | +#define OP_Program 127 |
| 9220 | +#define OP_Param 128 |
| 9221 | +#define OP_FkCounter 129 /* synopsis: fkctr[P1]+=P2 */ |
| 9222 | +#define OP_FkIfZero 130 /* synopsis: if fkctr[P1]==0 goto P2 */ |
| 9223 | +#define OP_MemMax 131 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 9224 | +#define OP_IfPos 132 /* synopsis: if r[P1]>0 goto P2 */ |
| 9212 | 9225 | #define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */ |
| 9213 | | -#define OP_Expire 134 |
| 9214 | | -#define OP_TableLock 135 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 9215 | | -#define OP_VBegin 136 |
| 9216 | | -#define OP_VCreate 137 |
| 9217 | | -#define OP_VDestroy 138 |
| 9218 | | -#define OP_VOpen 139 |
| 9219 | | -#define OP_VColumn 140 /* synopsis: r[P3]=vcolumn(P2) */ |
| 9220 | | -#define OP_VNext 141 |
| 9221 | | -#define OP_VRename 142 |
| 9226 | +#define OP_IfNeg 134 /* synopsis: if r[P1]<0 goto P2 */ |
| 9227 | +#define OP_IfZero 135 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */ |
| 9228 | +#define OP_AggFinal 136 /* synopsis: accum=r[P1] N=P2 */ |
| 9229 | +#define OP_IncrVacuum 137 |
| 9230 | +#define OP_Expire 138 |
| 9231 | +#define OP_TableLock 139 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 9232 | +#define OP_VBegin 140 |
| 9233 | +#define OP_VCreate 141 |
| 9234 | +#define OP_VDestroy 142 |
| 9222 | 9235 | #define OP_ToText 143 /* same as TK_TO_TEXT */ |
| 9223 | 9236 | #define OP_ToBlob 144 /* same as TK_TO_BLOB */ |
| 9224 | 9237 | #define OP_ToNumeric 145 /* same as TK_TO_NUMERIC */ |
| 9225 | 9238 | #define OP_ToInt 146 /* same as TK_TO_INT */ |
| 9226 | 9239 | #define OP_ToReal 147 /* same as TK_TO_REAL */ |
| 9227 | | -#define OP_Pagecount 148 |
| 9228 | | -#define OP_MaxPgcnt 149 |
| 9229 | | -#define OP_Trace 150 |
| 9230 | | -#define OP_Noop 151 |
| 9231 | | -#define OP_Explain 152 |
| 9240 | +#define OP_VOpen 148 |
| 9241 | +#define OP_VColumn 149 /* synopsis: r[P3]=vcolumn(P2) */ |
| 9242 | +#define OP_VNext 150 |
| 9243 | +#define OP_VRename 151 |
| 9244 | +#define OP_Pagecount 152 |
| 9245 | +#define OP_MaxPgcnt 153 |
| 9246 | +#define OP_Init 154 /* synopsis: Start at P2 */ |
| 9247 | +#define OP_Noop 155 |
| 9248 | +#define OP_Explain 156 |
| 9232 | 9249 | |
| 9233 | 9250 | |
| 9234 | 9251 | /* Properties such as "out2" or "jump" that are specified in |
| 9235 | 9252 | ** comments following the "case" for each opcode in the vdbe.c |
| 9236 | 9253 | ** are encoded into bitvectors as follows: |
| | @@ -9243,28 +9260,28 @@ |
| 9243 | 9260 | #define OPFLG_OUT2 0x0020 /* out2: P2 is an output */ |
| 9244 | 9261 | #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */ |
| 9245 | 9262 | #define OPFLG_INITIALIZER {\ |
| 9246 | 9263 | /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\ |
| 9247 | 9264 | /* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\ |
| 9248 | | -/* 16 */ 0x01, 0x01, 0x04, 0x24, 0x04, 0x10, 0x00, 0x02,\ |
| 9249 | | -/* 24 */ 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x20,\ |
| 9250 | | -/* 32 */ 0x00, 0x00, 0x04, 0x05, 0x04, 0x00, 0x00, 0x01,\ |
| 9251 | | -/* 40 */ 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02, 0x02,\ |
| 9252 | | -/* 48 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 9253 | | -/* 56 */ 0x00, 0x11, 0x11, 0x11, 0x11, 0x08, 0x11, 0x11,\ |
| 9254 | | -/* 64 */ 0x11, 0x11, 0x02, 0x02, 0x00, 0x00, 0x00, 0x4c,\ |
| 9265 | +/* 16 */ 0x01, 0x01, 0x04, 0x24, 0x01, 0x04, 0x05, 0x10,\ |
| 9266 | +/* 24 */ 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02,\ |
| 9267 | +/* 32 */ 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x05, 0x04,\ |
| 9268 | +/* 40 */ 0x00, 0x00, 0x01, 0x01, 0x05, 0x05, 0x00, 0x00,\ |
| 9269 | +/* 48 */ 0x00, 0x02, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00,\ |
| 9270 | +/* 56 */ 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x08,\ |
| 9271 | +/* 64 */ 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x00, 0x4c,\ |
| 9255 | 9272 | /* 72 */ 0x4c, 0x00, 0x00, 0x00, 0x05, 0x05, 0x15, 0x15,\ |
| 9256 | 9273 | /* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\ |
| 9257 | 9274 | /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\ |
| 9258 | | -/* 96 */ 0x24, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01,\ |
| 9259 | | -/* 104 */ 0x08, 0x08, 0x00, 0x02, 0x01, 0x01, 0x02, 0x00,\ |
| 9260 | | -/* 112 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 9261 | | -/* 120 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08,\ |
| 9262 | | -/* 128 */ 0x05, 0x05, 0x05, 0x00, 0x01, 0x02, 0x00, 0x00,\ |
| 9263 | | -/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04,\ |
| 9264 | | -/* 144 */ 0x04, 0x04, 0x04, 0x04, 0x02, 0x02, 0x00, 0x00,\ |
| 9265 | | -/* 152 */ 0x00,} |
| 9275 | +/* 96 */ 0x24, 0x02, 0x00, 0x00, 0x02, 0x00, 0x01, 0x01,\ |
| 9276 | +/* 104 */ 0x01, 0x01, 0x08, 0x08, 0x00, 0x02, 0x01, 0x01,\ |
| 9277 | +/* 112 */ 0x01, 0x01, 0x02, 0x00, 0x02, 0x02, 0x00, 0x00,\ |
| 9278 | +/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x0c, 0x45, 0x15, 0x01,\ |
| 9279 | +/* 128 */ 0x02, 0x00, 0x01, 0x08, 0x05, 0x02, 0x05, 0x05,\ |
| 9280 | +/* 136 */ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,\ |
| 9281 | +/* 144 */ 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x01, 0x00,\ |
| 9282 | +/* 152 */ 0x02, 0x02, 0x01, 0x00, 0x00,} |
| 9266 | 9283 | |
| 9267 | 9284 | /************** End of opcodes.h *********************************************/ |
| 9268 | 9285 | /************** Continuing where we left off in vdbe.h ***********************/ |
| 9269 | 9286 | |
| 9270 | 9287 | /* |
| | @@ -9276,11 +9293,11 @@ |
| 9276 | 9293 | SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int); |
| 9277 | 9294 | SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int); |
| 9278 | 9295 | SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int); |
| 9279 | 9296 | SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int); |
| 9280 | 9297 | SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int); |
| 9281 | | -SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp); |
| 9298 | +SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno); |
| 9282 | 9299 | SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*); |
| 9283 | 9300 | SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1); |
| 9284 | 9301 | SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2); |
| 9285 | 9302 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3); |
| 9286 | 9303 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5); |
| | @@ -9347,10 +9364,45 @@ |
| 9347 | 9364 | # define VdbeComment(X) |
| 9348 | 9365 | # define VdbeNoopComment(X) |
| 9349 | 9366 | # define VdbeModuleComment(X) |
| 9350 | 9367 | #endif |
| 9351 | 9368 | |
| 9369 | +/* |
| 9370 | +** The VdbeCoverage macros are used to set a coverage testing point |
| 9371 | +** for VDBE branch instructions. The coverage testing points are line |
| 9372 | +** numbers in the sqlite3.c source file. VDBE branch coverage testing |
| 9373 | +** only works with an amalagmation build. That's ok since a VDBE branch |
| 9374 | +** coverage build designed for testing the test suite only. No application |
| 9375 | +** should ever ship with VDBE branch coverage measuring turned on. |
| 9376 | +** |
| 9377 | +** VdbeCoverage(v) // Mark the previously coded instruction |
| 9378 | +** // as a branch |
| 9379 | +** |
| 9380 | +** VdbeCoverageIf(v, conditional) // Mark previous if conditional true |
| 9381 | +** |
| 9382 | +** VdbeCoverageAlwaysTaken(v) // Previous branch is always taken |
| 9383 | +** |
| 9384 | +** VdbeCoverageNeverTaken(v) // Previous branch is never taken |
| 9385 | +** |
| 9386 | +** Every VDBE branch operation must be tagged with one of the macros above. |
| 9387 | +** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and |
| 9388 | +** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch() |
| 9389 | +** routine in vdbe.c, alerting the developer to the missed tag. |
| 9390 | +*/ |
| 9391 | +#ifdef SQLITE_VDBE_COVERAGE |
| 9392 | +SQLITE_PRIVATE void sqlite3VdbeSetLineNumber(Vdbe*,int); |
| 9393 | +# define VdbeCoverage(v) sqlite3VdbeSetLineNumber(v,__LINE__) |
| 9394 | +# define VdbeCoverageIf(v,x) if(x)sqlite3VdbeSetLineNumber(v,__LINE__) |
| 9395 | +# define VdbeCoverageAlwaysTaken(v) sqlite3VdbeSetLineNumber(v,2); |
| 9396 | +# define VdbeCoverageNeverTaken(v) sqlite3VdbeSetLineNumber(v,1); |
| 9397 | +#else |
| 9398 | +# define VdbeCoverage(v) |
| 9399 | +# define VdbeCoverageIf(v,x) |
| 9400 | +# define VdbeCoverageAlwaysTaken(v) |
| 9401 | +# define VdbeCoverageNeverTaken(v) |
| 9402 | +#endif |
| 9403 | + |
| 9352 | 9404 | #endif |
| 9353 | 9405 | |
| 9354 | 9406 | /************** End of vdbe.h ************************************************/ |
| 9355 | 9407 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| 9356 | 9408 | /************** Include pager.h in the middle of sqliteInt.h *****************/ |
| | @@ -10404,12 +10456,11 @@ |
| 10404 | 10456 | |
| 10405 | 10457 | /* |
| 10406 | 10458 | ** Return true if it OK to factor constant expressions into the initialization |
| 10407 | 10459 | ** code. The argument is a Parse object for the code generator. |
| 10408 | 10460 | */ |
| 10409 | | -#define ConstFactorOk(P) \ |
| 10410 | | - ((P)->cookieGoto>0 && OptimizationEnabled((P)->db,SQLITE_FactorOutConst)) |
| 10461 | +#define ConstFactorOk(P) ((P)->okConstFactor) |
| 10411 | 10462 | |
| 10412 | 10463 | /* |
| 10413 | 10464 | ** Possible values for the sqlite.magic field. |
| 10414 | 10465 | ** The numbers are obtained at random and have no special meaning, other |
| 10415 | 10466 | ** than being distinct from one another. |
| | @@ -10631,14 +10682,20 @@ |
| 10631 | 10682 | #define SQLITE_AFF_MASK 0x67 |
| 10632 | 10683 | |
| 10633 | 10684 | /* |
| 10634 | 10685 | ** Additional bit values that can be ORed with an affinity without |
| 10635 | 10686 | ** changing the affinity. |
| 10687 | +** |
| 10688 | +** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL. |
| 10689 | +** It causes an assert() to fire if either operand to a comparison |
| 10690 | +** operator is NULL. It is added to certain comparison operators to |
| 10691 | +** prove that the operands are always NOT NULL. |
| 10636 | 10692 | */ |
| 10637 | 10693 | #define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */ |
| 10638 | 10694 | #define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump */ |
| 10639 | 10695 | #define SQLITE_NULLEQ 0x80 /* NULL=NULL */ |
| 10696 | +#define SQLITE_NOTNULL 0x88 /* Assert that operands are never NULL */ |
| 10640 | 10697 | |
| 10641 | 10698 | /* |
| 10642 | 10699 | ** An object of this type is created for each virtual table present in |
| 10643 | 10700 | ** the database schema. |
| 10644 | 10701 | ** |
| | @@ -11336,10 +11393,11 @@ |
| 11336 | 11393 | char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */ |
| 11337 | 11394 | Table *pTab; /* An SQL table corresponding to zName */ |
| 11338 | 11395 | Select *pSelect; /* A SELECT statement used in place of a table name */ |
| 11339 | 11396 | int addrFillSub; /* Address of subroutine to manifest a subquery */ |
| 11340 | 11397 | int regReturn; /* Register holding return address of addrFillSub */ |
| 11398 | + int regResult; /* Registers holding results of a co-routine */ |
| 11341 | 11399 | u8 jointype; /* Type of join between this able and the previous */ |
| 11342 | 11400 | unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */ |
| 11343 | 11401 | unsigned isCorrelated :1; /* True if sub-query is correlated */ |
| 11344 | 11402 | unsigned viaCoroutine :1; /* Implemented as a co-routine */ |
| 11345 | 11403 | unsigned isRecursive :1; /* True for recursive reference in WITH */ |
| | @@ -11464,11 +11522,10 @@ |
| 11464 | 11522 | ExprList *pGroupBy; /* The GROUP BY clause */ |
| 11465 | 11523 | Expr *pHaving; /* The HAVING clause */ |
| 11466 | 11524 | ExprList *pOrderBy; /* The ORDER BY clause */ |
| 11467 | 11525 | Select *pPrior; /* Prior select in a compound select statement */ |
| 11468 | 11526 | Select *pNext; /* Next select to the left in a compound */ |
| 11469 | | - Select *pRightmost; /* Right-most select in a compound select statement */ |
| 11470 | 11527 | Expr *pLimit; /* LIMIT expression. NULL means not used. */ |
| 11471 | 11528 | Expr *pOffset; /* OFFSET expression. NULL means not used. */ |
| 11472 | 11529 | With *pWith; /* WITH clause attached to this select. Or NULL. */ |
| 11473 | 11530 | }; |
| 11474 | 11531 | |
| | @@ -11482,14 +11539,15 @@ |
| 11482 | 11539 | #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */ |
| 11483 | 11540 | #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */ |
| 11484 | 11541 | #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */ |
| 11485 | 11542 | #define SF_UseSorter 0x0040 /* Sort using a sorter */ |
| 11486 | 11543 | #define SF_Values 0x0080 /* Synthesized from VALUES clause */ |
| 11487 | | -#define SF_Materialize 0x0100 /* Force materialization of views */ |
| 11544 | +#define SF_Materialize 0x0100 /* NOT USED */ |
| 11488 | 11545 | #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */ |
| 11489 | 11546 | #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */ |
| 11490 | 11547 | #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */ |
| 11548 | +#define SF_Compound 0x1000 /* Part of a compound query */ |
| 11491 | 11549 | |
| 11492 | 11550 | |
| 11493 | 11551 | /* |
| 11494 | 11552 | ** The results of a SELECT can be distributed in several ways, as defined |
| 11495 | 11553 | ** by one of the following macros. The "SRT" prefix means "SELECT Result |
| | @@ -11664,49 +11722,48 @@ |
| 11664 | 11722 | int rc; /* Return code from execution */ |
| 11665 | 11723 | u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */ |
| 11666 | 11724 | u8 checkSchema; /* Causes schema cookie check after an error */ |
| 11667 | 11725 | u8 nested; /* Number of nested calls to the parser/code generator */ |
| 11668 | 11726 | u8 nTempReg; /* Number of temporary registers in aTempReg[] */ |
| 11669 | | - u8 nTempInUse; /* Number of aTempReg[] currently checked out */ |
| 11670 | 11727 | u8 nColCache; /* Number of entries in aColCache[] */ |
| 11671 | 11728 | u8 iColCache; /* Next entry in aColCache[] to replace */ |
| 11672 | 11729 | u8 isMultiWrite; /* True if statement may modify/insert multiple rows */ |
| 11673 | 11730 | u8 mayAbort; /* True if statement may throw an ABORT exception */ |
| 11674 | 11731 | u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */ |
| 11732 | + u8 okConstFactor; /* OK to factor out constants */ |
| 11675 | 11733 | int aTempReg[8]; /* Holding area for temporary registers */ |
| 11676 | 11734 | int nRangeReg; /* Size of the temporary register block */ |
| 11677 | 11735 | int iRangeReg; /* First register in temporary register block */ |
| 11678 | 11736 | int nErr; /* Number of errors seen */ |
| 11679 | 11737 | int nTab; /* Number of previously allocated VDBE cursors */ |
| 11680 | 11738 | int nMem; /* Number of memory cells used so far */ |
| 11681 | 11739 | int nSet; /* Number of sets used so far */ |
| 11682 | 11740 | int nOnce; /* Number of OP_Once instructions so far */ |
| 11683 | 11741 | int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */ |
| 11684 | | - int nLabel; /* Number of labels used */ |
| 11685 | | - int *aLabel; /* Space to hold the labels */ |
| 11686 | 11742 | int iFixedOp; /* Never back out opcodes iFixedOp-1 or earlier */ |
| 11687 | 11743 | int ckBase; /* Base register of data during check constraints */ |
| 11688 | 11744 | int iPartIdxTab; /* Table corresponding to a partial index */ |
| 11689 | 11745 | int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */ |
| 11690 | 11746 | int iCacheCnt; /* Counter used to generate aColCache[].lru values */ |
| 11747 | + int nLabel; /* Number of labels used */ |
| 11748 | + int *aLabel; /* Space to hold the labels */ |
| 11691 | 11749 | struct yColCache { |
| 11692 | 11750 | int iTable; /* Table cursor number */ |
| 11693 | | - int iColumn; /* Table column number */ |
| 11751 | + i16 iColumn; /* Table column number */ |
| 11694 | 11752 | u8 tempReg; /* iReg is a temp register that needs to be freed */ |
| 11695 | 11753 | int iLevel; /* Nesting level */ |
| 11696 | 11754 | int iReg; /* Reg with value of this column. 0 means none. */ |
| 11697 | 11755 | int lru; /* Least recently used entry has the smallest value */ |
| 11698 | 11756 | } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */ |
| 11699 | 11757 | ExprList *pConstExpr;/* Constant expressions */ |
| 11758 | + Token constraintName;/* Name of the constraint currently being parsed */ |
| 11700 | 11759 | yDbMask writeMask; /* Start a write transaction on these databases */ |
| 11701 | 11760 | yDbMask cookieMask; /* Bitmask of schema verified databases */ |
| 11702 | | - int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */ |
| 11703 | 11761 | int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */ |
| 11704 | 11762 | int regRowid; /* Register holding rowid of CREATE TABLE entry */ |
| 11705 | 11763 | int regRoot; /* Register holding root page number for new objects */ |
| 11706 | 11764 | int nMaxArg; /* Max args passed to user function by sub-program */ |
| 11707 | | - Token constraintName;/* Name of the constraint currently being parsed */ |
| 11708 | 11765 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 11709 | 11766 | int nTableLock; /* Number of locks in aTableLock */ |
| 11710 | 11767 | TableLock *aTableLock; /* Required table locks for shared-cache mode */ |
| 11711 | 11768 | #endif |
| 11712 | 11769 | AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */ |
| | @@ -11721,16 +11778,21 @@ |
| 11721 | 11778 | u32 newmask; /* Mask of new.* columns referenced */ |
| 11722 | 11779 | u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */ |
| 11723 | 11780 | u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */ |
| 11724 | 11781 | u8 disableTriggers; /* True to disable triggers */ |
| 11725 | 11782 | |
| 11726 | | - /* Above is constant between recursions. Below is reset before and after |
| 11727 | | - ** each recursion */ |
| 11783 | + /************************************************************************ |
| 11784 | + ** Above is constant between recursions. Below is reset before and after |
| 11785 | + ** each recursion. The boundary between these two regions is determined |
| 11786 | + ** using offsetof(Parse,nVar) so the nVar field must be the first field |
| 11787 | + ** in the recursive region. |
| 11788 | + ************************************************************************/ |
| 11728 | 11789 | |
| 11729 | 11790 | int nVar; /* Number of '?' variables seen in the SQL so far */ |
| 11730 | 11791 | int nzVar; /* Number of available slots in azVar[] */ |
| 11731 | 11792 | u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */ |
| 11793 | + u8 bFreeWith; /* True if pWith should be freed with parser */ |
| 11732 | 11794 | u8 explain; /* True if the EXPLAIN flag is found on the query */ |
| 11733 | 11795 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 11734 | 11796 | u8 declareVtab; /* True if inside sqlite3_declare_vtab() */ |
| 11735 | 11797 | int nVtabLock; /* Number of virtual tables to lock */ |
| 11736 | 11798 | #endif |
| | @@ -11753,11 +11815,10 @@ |
| 11753 | 11815 | Table **apVtabLock; /* Pointer to virtual tables needing locking */ |
| 11754 | 11816 | #endif |
| 11755 | 11817 | Table *pZombieTab; /* List of Table objects to delete after code gen */ |
| 11756 | 11818 | TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */ |
| 11757 | 11819 | With *pWith; /* Current WITH clause, or NULL */ |
| 11758 | | - u8 bFreeWith; /* True if pWith should be freed with parser */ |
| 11759 | 11820 | }; |
| 11760 | 11821 | |
| 11761 | 11822 | /* |
| 11762 | 11823 | ** Return true if currently inside an sqlite3_declare_vtab() call. |
| 11763 | 11824 | */ |
| | @@ -11969,10 +12030,17 @@ |
| 11969 | 12030 | int bLocaltimeFault; /* True to fail localtime() calls */ |
| 11970 | 12031 | #ifdef SQLITE_ENABLE_SQLLOG |
| 11971 | 12032 | void(*xSqllog)(void*,sqlite3*,const char*, int); |
| 11972 | 12033 | void *pSqllogArg; |
| 11973 | 12034 | #endif |
| 12035 | +#ifdef SQLITE_VDBE_COVERAGE |
| 12036 | + /* The following callback (if not NULL) is invoked on every VDBE branch |
| 12037 | + ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE. |
| 12038 | + */ |
| 12039 | + void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx); /* Callback */ |
| 12040 | + void *pVdbeBranchArg; /* 1st argument */ |
| 12041 | +#endif |
| 11974 | 12042 | }; |
| 11975 | 12043 | |
| 11976 | 12044 | /* |
| 11977 | 12045 | ** This macro is used inside of assert() statements to indicate that |
| 11978 | 12046 | ** the assert is only valid on a well-formed database. Instead of: |
| | @@ -12302,11 +12370,10 @@ |
| 12302 | 12370 | SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse); |
| 12303 | 12371 | #else |
| 12304 | 12372 | # define sqlite3AutoincrementBegin(X) |
| 12305 | 12373 | # define sqlite3AutoincrementEnd(X) |
| 12306 | 12374 | #endif |
| 12307 | | -SQLITE_PRIVATE int sqlite3CodeCoroutine(Parse*, Select*, SelectDest*); |
| 12308 | 12375 | SQLITE_PRIVATE void sqlite3Insert(Parse*, SrcList*, Select*, IdList*, int); |
| 12309 | 12376 | SQLITE_PRIVATE void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*); |
| 12310 | 12377 | SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*); |
| 12311 | 12378 | SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*); |
| 12312 | 12379 | SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int); |
| | @@ -12350,15 +12417,16 @@ |
| 12350 | 12417 | SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*); |
| 12351 | 12418 | SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int); |
| 12352 | 12419 | SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int); |
| 12353 | 12420 | SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*); |
| 12354 | 12421 | SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int); |
| 12355 | | -SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int); |
| 12422 | +SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int); |
| 12423 | +SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int); |
| 12356 | 12424 | SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8); |
| 12357 | 12425 | SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*); |
| 12358 | 12426 | SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int); |
| 12359 | | -SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int); |
| 12427 | +SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int); |
| 12360 | 12428 | SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, u8); |
| 12361 | 12429 | #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */ |
| 12362 | 12430 | #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */ |
| 12363 | 12431 | SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int); |
| 12364 | 12432 | SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int); |
| | @@ -12392,11 +12460,10 @@ |
| 12392 | 12460 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*); |
| 12393 | 12461 | SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*); |
| 12394 | 12462 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*); |
| 12395 | 12463 | SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*); |
| 12396 | 12464 | SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); |
| 12397 | | -SQLITE_PRIVATE void sqlite3ExprCodeIsNullJump(Vdbe*, const Expr*, int, int); |
| 12398 | 12465 | SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char); |
| 12399 | 12466 | SQLITE_PRIVATE int sqlite3IsRowid(const char*); |
| 12400 | 12467 | SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8); |
| 12401 | 12468 | SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*); |
| 12402 | 12469 | SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int); |
| | @@ -12536,11 +12603,11 @@ |
| 12536 | 12603 | #define getVarint sqlite3GetVarint |
| 12537 | 12604 | #define putVarint sqlite3PutVarint |
| 12538 | 12605 | |
| 12539 | 12606 | |
| 12540 | 12607 | SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *, Index *); |
| 12541 | | -SQLITE_PRIVATE void sqlite3TableAffinityStr(Vdbe *, Table *); |
| 12608 | +SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int); |
| 12542 | 12609 | SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2); |
| 12543 | 12610 | SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); |
| 12544 | 12611 | SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr); |
| 12545 | 12612 | SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8); |
| 12546 | 12613 | SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...); |
| | @@ -13640,11 +13707,10 @@ |
| 13640 | 13707 | u8 rowidIsValid; /* True if lastRowid is valid */ |
| 13641 | 13708 | u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */ |
| 13642 | 13709 | Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */ |
| 13643 | 13710 | Bool isTable:1; /* True if a table requiring integer keys */ |
| 13644 | 13711 | Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */ |
| 13645 | | - Bool multiPseudo:1; /* Multi-register pseudo-cursor */ |
| 13646 | 13712 | sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */ |
| 13647 | 13713 | i64 seqCount; /* Sequence counter */ |
| 13648 | 13714 | i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */ |
| 13649 | 13715 | i64 lastRowid; /* Rowid being deleted by OP_Delete */ |
| 13650 | 13716 | VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */ |
| | @@ -13734,11 +13800,11 @@ |
| 13734 | 13800 | RowSet *pRowSet; /* Used only when flags==MEM_RowSet */ |
| 13735 | 13801 | VdbeFrame *pFrame; /* Used when flags==MEM_Frame */ |
| 13736 | 13802 | } u; |
| 13737 | 13803 | int n; /* Number of characters in string value, excluding '\0' */ |
| 13738 | 13804 | u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */ |
| 13739 | | - u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */ |
| 13805 | + u8 memType; /* Lower 5 bits of flags */ |
| 13740 | 13806 | u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */ |
| 13741 | 13807 | #ifdef SQLITE_DEBUG |
| 13742 | 13808 | Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */ |
| 13743 | 13809 | void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */ |
| 13744 | 13810 | #endif |
| | @@ -13763,11 +13829,11 @@ |
| 13763 | 13829 | #define MEM_Int 0x0004 /* Value is an integer */ |
| 13764 | 13830 | #define MEM_Real 0x0008 /* Value is a real number */ |
| 13765 | 13831 | #define MEM_Blob 0x0010 /* Value is a BLOB */ |
| 13766 | 13832 | #define MEM_RowSet 0x0020 /* Value is a RowSet object */ |
| 13767 | 13833 | #define MEM_Frame 0x0040 /* Value is a VdbeFrame object */ |
| 13768 | | -#define MEM_Invalid 0x0080 /* Value is undefined */ |
| 13834 | +#define MEM_Undefined 0x0080 /* Value is undefined */ |
| 13769 | 13835 | #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */ |
| 13770 | 13836 | #define MEM_TypeMask 0x01ff /* Mask of type bits */ |
| 13771 | 13837 | |
| 13772 | 13838 | |
| 13773 | 13839 | /* Whenever Mem contains a valid string or blob representation, one of |
| | @@ -13795,11 +13861,11 @@ |
| 13795 | 13861 | /* |
| 13796 | 13862 | ** Return true if a memory cell is not marked as invalid. This macro |
| 13797 | 13863 | ** is for use inside assert() statements only. |
| 13798 | 13864 | */ |
| 13799 | 13865 | #ifdef SQLITE_DEBUG |
| 13800 | | -#define memIsValid(M) ((M)->flags & MEM_Invalid)==0 |
| 13866 | +#define memIsValid(M) ((M)->flags & MEM_Undefined)==0 |
| 13801 | 13867 | #endif |
| 13802 | 13868 | |
| 13803 | 13869 | /* |
| 13804 | 13870 | ** Each auxilliary data pointer stored by a user defined function |
| 13805 | 13871 | ** implementation calling sqlite3_set_auxdata() is stored in an instance |
| | @@ -13990,20 +14056,22 @@ |
| 13990 | 14056 | SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*); |
| 13991 | 14057 | SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*); |
| 13992 | 14058 | SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*); |
| 13993 | 14059 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p); |
| 13994 | 14060 | SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p); |
| 14061 | +#define VdbeMemDynamic(X) \ |
| 14062 | + (((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame))!=0) |
| 13995 | 14063 | #define VdbeMemRelease(X) \ |
| 13996 | | - if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \ |
| 13997 | | - sqlite3VdbeMemReleaseExternal(X); |
| 14064 | + if( VdbeMemDynamic(X) ) sqlite3VdbeMemReleaseExternal(X); |
| 13998 | 14065 | SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*); |
| 13999 | 14066 | SQLITE_PRIVATE const char *sqlite3OpcodeName(int); |
| 14000 | 14067 | SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve); |
| 14001 | 14068 | SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int); |
| 14002 | 14069 | SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*); |
| 14003 | 14070 | SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *); |
| 14004 | | -SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem); |
| 14071 | +#define sqlite3VdbeMemStoreType(X) (X)->memType = (u8)((X)->flags&0x1f) |
| 14072 | +/* void sqlite3VdbeMemStoreType(Mem *pMem); */ |
| 14005 | 14073 | SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p); |
| 14006 | 14074 | |
| 14007 | 14075 | SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, VdbeCursor *); |
| 14008 | 14076 | SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *); |
| 14009 | 14077 | SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *); |
| | @@ -17767,10 +17835,16 @@ |
| 17767 | 17835 | mem5.totalExcess += iFullSz - nByte; |
| 17768 | 17836 | mem5.currentCount++; |
| 17769 | 17837 | mem5.currentOut += iFullSz; |
| 17770 | 17838 | if( mem5.maxCount<mem5.currentCount ) mem5.maxCount = mem5.currentCount; |
| 17771 | 17839 | if( mem5.maxOut<mem5.currentOut ) mem5.maxOut = mem5.currentOut; |
| 17840 | + |
| 17841 | +#ifdef SQLITE_DEBUG |
| 17842 | + /* Make sure the allocated memory does not assume that it is set to zero |
| 17843 | + ** or retains a value from a previous allocation */ |
| 17844 | + memset(&mem5.zPool[i*mem5.szAtom], 0xAA, iFullSz); |
| 17845 | +#endif |
| 17772 | 17846 | |
| 17773 | 17847 | /* Return a pointer to the allocated memory. */ |
| 17774 | 17848 | return (void*)&mem5.zPool[i*mem5.szAtom]; |
| 17775 | 17849 | } |
| 17776 | 17850 | |
| | @@ -17825,10 +17899,17 @@ |
| 17825 | 17899 | mem5.aCtrl[iBlock] = CTRL_FREE | iLogsize; |
| 17826 | 17900 | mem5.aCtrl[iBuddy] = 0; |
| 17827 | 17901 | } |
| 17828 | 17902 | size *= 2; |
| 17829 | 17903 | } |
| 17904 | + |
| 17905 | +#ifdef SQLITE_DEBUG |
| 17906 | + /* Overwrite freed memory with the 0x55 bit pattern to verify that it is |
| 17907 | + ** not used after being freed */ |
| 17908 | + memset(&mem5.zPool[iBlock*mem5.szAtom], 0x55, size); |
| 17909 | +#endif |
| 17910 | + |
| 17830 | 17911 | memsys5Link(iBlock, iLogsize); |
| 17831 | 17912 | } |
| 17832 | 17913 | |
| 17833 | 17914 | /* |
| 17834 | 17915 | ** Allocate nBytes of memory. |
| | @@ -22728,17 +22809,16 @@ |
| 22728 | 22809 | testcase( iB==-1 ); testcase( iB==0 ); |
| 22729 | 22810 | if( iB>=0 ){ |
| 22730 | 22811 | testcase( iA>0 && LARGEST_INT64 - iA == iB ); |
| 22731 | 22812 | testcase( iA>0 && LARGEST_INT64 - iA == iB - 1 ); |
| 22732 | 22813 | if( iA>0 && LARGEST_INT64 - iA < iB ) return 1; |
| 22733 | | - *pA += iB; |
| 22734 | 22814 | }else{ |
| 22735 | 22815 | testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 1 ); |
| 22736 | 22816 | testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 ); |
| 22737 | 22817 | if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1; |
| 22738 | | - *pA += iB; |
| 22739 | 22818 | } |
| 22819 | + *pA += iB; |
| 22740 | 22820 | return 0; |
| 22741 | 22821 | } |
| 22742 | 22822 | SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){ |
| 22743 | 22823 | testcase( iB==SMALLEST_INT64+1 ); |
| 22744 | 22824 | if( iB==SMALLEST_INT64 ){ |
| | @@ -22758,13 +22838,22 @@ |
| 22758 | 22838 | |
| 22759 | 22839 | iA1 = iA/TWOPOWER32; |
| 22760 | 22840 | iA0 = iA % TWOPOWER32; |
| 22761 | 22841 | iB1 = iB/TWOPOWER32; |
| 22762 | 22842 | iB0 = iB % TWOPOWER32; |
| 22763 | | - if( iA1*iB1 != 0 ) return 1; |
| 22764 | | - assert( iA1*iB0==0 || iA0*iB1==0 ); |
| 22765 | | - r = iA1*iB0 + iA0*iB1; |
| 22843 | + if( iA1==0 ){ |
| 22844 | + if( iB1==0 ){ |
| 22845 | + *pA *= iB; |
| 22846 | + return 0; |
| 22847 | + } |
| 22848 | + r = iA0*iB1; |
| 22849 | + }else if( iB1==0 ){ |
| 22850 | + r = iA1*iB0; |
| 22851 | + }else{ |
| 22852 | + /* If both iA1 and iB1 are non-zero, overflow will result */ |
| 22853 | + return 1; |
| 22854 | + } |
| 22766 | 22855 | testcase( r==(-TWOPOWER31)-1 ); |
| 22767 | 22856 | testcase( r==(-TWOPOWER31) ); |
| 22768 | 22857 | testcase( r==TWOPOWER31 ); |
| 22769 | 22858 | testcase( r==TWOPOWER31-1 ); |
| 22770 | 22859 | if( r<(-TWOPOWER31) || r>=TWOPOWER31 ) return 1; |
| | @@ -23206,75 +23295,75 @@ |
| 23206 | 23295 | /* 15 */ "VUpdate" OpHelp("data=r[P3@P2]"), |
| 23207 | 23296 | /* 16 */ "Goto" OpHelp(""), |
| 23208 | 23297 | /* 17 */ "Gosub" OpHelp(""), |
| 23209 | 23298 | /* 18 */ "Return" OpHelp(""), |
| 23210 | 23299 | /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"), |
| 23211 | | - /* 20 */ "Yield" OpHelp(""), |
| 23212 | | - /* 21 */ "HaltIfNull" OpHelp("if r[P3] null then halt"), |
| 23213 | | - /* 22 */ "Halt" OpHelp(""), |
| 23214 | | - /* 23 */ "Integer" OpHelp("r[P2]=P1"), |
| 23215 | | - /* 24 */ "Int64" OpHelp("r[P2]=P4"), |
| 23216 | | - /* 25 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 23217 | | - /* 26 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 23218 | | - /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 23219 | | - /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 23220 | | - /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 23221 | | - /* 30 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), |
| 23222 | | - /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 23223 | | - /* 32 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 23224 | | - /* 33 */ "CollSeq" OpHelp(""), |
| 23225 | | - /* 34 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 23226 | | - /* 35 */ "MustBeInt" OpHelp(""), |
| 23227 | | - /* 36 */ "RealAffinity" OpHelp(""), |
| 23228 | | - /* 37 */ "Permutation" OpHelp(""), |
| 23229 | | - /* 38 */ "Compare" OpHelp(""), |
| 23230 | | - /* 39 */ "Jump" OpHelp(""), |
| 23231 | | - /* 40 */ "Once" OpHelp(""), |
| 23232 | | - /* 41 */ "If" OpHelp(""), |
| 23233 | | - /* 42 */ "IfNot" OpHelp(""), |
| 23234 | | - /* 43 */ "Column" OpHelp("r[P3]=PX"), |
| 23235 | | - /* 44 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 23236 | | - /* 45 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 23237 | | - /* 46 */ "Count" OpHelp("r[P2]=count()"), |
| 23238 | | - /* 47 */ "ReadCookie" OpHelp(""), |
| 23239 | | - /* 48 */ "SetCookie" OpHelp(""), |
| 23240 | | - /* 49 */ "VerifyCookie" OpHelp(""), |
| 23241 | | - /* 50 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 23242 | | - /* 51 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 23243 | | - /* 52 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 23244 | | - /* 53 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 23245 | | - /* 54 */ "SorterOpen" OpHelp(""), |
| 23246 | | - /* 55 */ "OpenPseudo" OpHelp("content in r[P2@P3]"), |
| 23247 | | - /* 56 */ "Close" OpHelp(""), |
| 23248 | | - /* 57 */ "SeekLt" OpHelp("key=r[P3@P4]"), |
| 23249 | | - /* 58 */ "SeekLe" OpHelp("key=r[P3@P4]"), |
| 23250 | | - /* 59 */ "SeekGe" OpHelp("key=r[P3@P4]"), |
| 23251 | | - /* 60 */ "SeekGt" OpHelp("key=r[P3@P4]"), |
| 23252 | | - /* 61 */ "Seek" OpHelp("intkey=r[P2]"), |
| 23253 | | - /* 62 */ "NoConflict" OpHelp("key=r[P3@P4]"), |
| 23254 | | - /* 63 */ "NotFound" OpHelp("key=r[P3@P4]"), |
| 23255 | | - /* 64 */ "Found" OpHelp("key=r[P3@P4]"), |
| 23256 | | - /* 65 */ "NotExists" OpHelp("intkey=r[P3]"), |
| 23257 | | - /* 66 */ "Sequence" OpHelp("r[P2]=rowid"), |
| 23258 | | - /* 67 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 23259 | | - /* 68 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 23260 | | - /* 69 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"), |
| 23261 | | - /* 70 */ "Delete" OpHelp(""), |
| 23300 | + /* 20 */ "InitCoroutine" OpHelp(""), |
| 23301 | + /* 21 */ "EndCoroutine" OpHelp(""), |
| 23302 | + /* 22 */ "Yield" OpHelp(""), |
| 23303 | + /* 23 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), |
| 23304 | + /* 24 */ "Halt" OpHelp(""), |
| 23305 | + /* 25 */ "Integer" OpHelp("r[P2]=P1"), |
| 23306 | + /* 26 */ "Int64" OpHelp("r[P2]=P4"), |
| 23307 | + /* 27 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 23308 | + /* 28 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 23309 | + /* 29 */ "SoftNull" OpHelp("r[P1]=NULL"), |
| 23310 | + /* 30 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 23311 | + /* 31 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 23312 | + /* 32 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 23313 | + /* 33 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), |
| 23314 | + /* 34 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 23315 | + /* 35 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 23316 | + /* 36 */ "CollSeq" OpHelp(""), |
| 23317 | + /* 37 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 23318 | + /* 38 */ "MustBeInt" OpHelp(""), |
| 23319 | + /* 39 */ "RealAffinity" OpHelp(""), |
| 23320 | + /* 40 */ "Permutation" OpHelp(""), |
| 23321 | + /* 41 */ "Compare" OpHelp(""), |
| 23322 | + /* 42 */ "Jump" OpHelp(""), |
| 23323 | + /* 43 */ "Once" OpHelp(""), |
| 23324 | + /* 44 */ "If" OpHelp(""), |
| 23325 | + /* 45 */ "IfNot" OpHelp(""), |
| 23326 | + /* 46 */ "Column" OpHelp("r[P3]=PX"), |
| 23327 | + /* 47 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 23328 | + /* 48 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 23329 | + /* 49 */ "Count" OpHelp("r[P2]=count()"), |
| 23330 | + /* 50 */ "ReadCookie" OpHelp(""), |
| 23331 | + /* 51 */ "SetCookie" OpHelp(""), |
| 23332 | + /* 52 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 23333 | + /* 53 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 23334 | + /* 54 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 23335 | + /* 55 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 23336 | + /* 56 */ "SorterOpen" OpHelp(""), |
| 23337 | + /* 57 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), |
| 23338 | + /* 58 */ "Close" OpHelp(""), |
| 23339 | + /* 59 */ "SeekLT" OpHelp(""), |
| 23340 | + /* 60 */ "SeekLE" OpHelp(""), |
| 23341 | + /* 61 */ "SeekGE" OpHelp(""), |
| 23342 | + /* 62 */ "SeekGT" OpHelp(""), |
| 23343 | + /* 63 */ "Seek" OpHelp("intkey=r[P2]"), |
| 23344 | + /* 64 */ "NoConflict" OpHelp("key=r[P3@P4]"), |
| 23345 | + /* 65 */ "NotFound" OpHelp("key=r[P3@P4]"), |
| 23346 | + /* 66 */ "Found" OpHelp("key=r[P3@P4]"), |
| 23347 | + /* 67 */ "NotExists" OpHelp("intkey=r[P3]"), |
| 23348 | + /* 68 */ "Sequence" OpHelp("r[P2]=rowid"), |
| 23349 | + /* 69 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 23350 | + /* 70 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 23262 | 23351 | /* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"), |
| 23263 | 23352 | /* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"), |
| 23264 | | - /* 73 */ "ResetCount" OpHelp(""), |
| 23265 | | - /* 74 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"), |
| 23266 | | - /* 75 */ "SorterData" OpHelp("r[P2]=data"), |
| 23353 | + /* 73 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"), |
| 23354 | + /* 74 */ "Delete" OpHelp(""), |
| 23355 | + /* 75 */ "ResetCount" OpHelp(""), |
| 23267 | 23356 | /* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"), |
| 23268 | 23357 | /* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"), |
| 23269 | 23358 | /* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"), |
| 23270 | 23359 | /* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"), |
| 23271 | 23360 | /* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"), |
| 23272 | 23361 | /* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"), |
| 23273 | 23362 | /* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"), |
| 23274 | 23363 | /* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"), |
| 23275 | | - /* 84 */ "RowKey" OpHelp("r[P2]=key"), |
| 23364 | + /* 84 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"), |
| 23276 | 23365 | /* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"), |
| 23277 | 23366 | /* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"), |
| 23278 | 23367 | /* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"), |
| 23279 | 23368 | /* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"), |
| 23280 | 23369 | /* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"), |
| | @@ -23281,68 +23370,72 @@ |
| 23281 | 23370 | /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"), |
| 23282 | 23371 | /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"), |
| 23283 | 23372 | /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"), |
| 23284 | 23373 | /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"), |
| 23285 | 23374 | /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"), |
| 23286 | | - /* 95 */ "RowData" OpHelp("r[P2]=data"), |
| 23375 | + /* 95 */ "SorterData" OpHelp("r[P2]=data"), |
| 23287 | 23376 | /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"), |
| 23288 | 23377 | /* 97 */ "String8" OpHelp("r[P2]='P4'"), |
| 23289 | | - /* 98 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 23290 | | - /* 99 */ "NullRow" OpHelp(""), |
| 23291 | | - /* 100 */ "Last" OpHelp(""), |
| 23292 | | - /* 101 */ "SorterSort" OpHelp(""), |
| 23293 | | - /* 102 */ "Sort" OpHelp(""), |
| 23294 | | - /* 103 */ "Rewind" OpHelp(""), |
| 23295 | | - /* 104 */ "SorterInsert" OpHelp(""), |
| 23296 | | - /* 105 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 23297 | | - /* 106 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 23298 | | - /* 107 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 23299 | | - /* 108 */ "IdxLT" OpHelp("key=r[P3@P4]"), |
| 23300 | | - /* 109 */ "IdxGE" OpHelp("key=r[P3@P4]"), |
| 23301 | | - /* 110 */ "Destroy" OpHelp(""), |
| 23302 | | - /* 111 */ "Clear" OpHelp(""), |
| 23303 | | - /* 112 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"), |
| 23304 | | - /* 113 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"), |
| 23305 | | - /* 114 */ "ParseSchema" OpHelp(""), |
| 23306 | | - /* 115 */ "LoadAnalysis" OpHelp(""), |
| 23307 | | - /* 116 */ "DropTable" OpHelp(""), |
| 23308 | | - /* 117 */ "DropIndex" OpHelp(""), |
| 23309 | | - /* 118 */ "DropTrigger" OpHelp(""), |
| 23310 | | - /* 119 */ "IntegrityCk" OpHelp(""), |
| 23311 | | - /* 120 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 23312 | | - /* 121 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"), |
| 23313 | | - /* 122 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"), |
| 23314 | | - /* 123 */ "Program" OpHelp(""), |
| 23315 | | - /* 124 */ "Param" OpHelp(""), |
| 23316 | | - /* 125 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 23317 | | - /* 126 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"), |
| 23318 | | - /* 127 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 23319 | | - /* 128 */ "IfPos" OpHelp("if r[P1]>0 goto P2"), |
| 23320 | | - /* 129 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"), |
| 23321 | | - /* 130 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"), |
| 23322 | | - /* 131 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 23323 | | - /* 132 */ "IncrVacuum" OpHelp(""), |
| 23378 | + /* 98 */ "RowKey" OpHelp("r[P2]=key"), |
| 23379 | + /* 99 */ "RowData" OpHelp("r[P2]=data"), |
| 23380 | + /* 100 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 23381 | + /* 101 */ "NullRow" OpHelp(""), |
| 23382 | + /* 102 */ "Last" OpHelp(""), |
| 23383 | + /* 103 */ "SorterSort" OpHelp(""), |
| 23384 | + /* 104 */ "Sort" OpHelp(""), |
| 23385 | + /* 105 */ "Rewind" OpHelp(""), |
| 23386 | + /* 106 */ "SorterInsert" OpHelp(""), |
| 23387 | + /* 107 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 23388 | + /* 108 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 23389 | + /* 109 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 23390 | + /* 110 */ "IdxLE" OpHelp("key=r[P3@P4]"), |
| 23391 | + /* 111 */ "IdxGT" OpHelp("key=r[P3@P4]"), |
| 23392 | + /* 112 */ "IdxLT" OpHelp("key=r[P3@P4]"), |
| 23393 | + /* 113 */ "IdxGE" OpHelp("key=r[P3@P4]"), |
| 23394 | + /* 114 */ "Destroy" OpHelp(""), |
| 23395 | + /* 115 */ "Clear" OpHelp(""), |
| 23396 | + /* 116 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"), |
| 23397 | + /* 117 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"), |
| 23398 | + /* 118 */ "ParseSchema" OpHelp(""), |
| 23399 | + /* 119 */ "LoadAnalysis" OpHelp(""), |
| 23400 | + /* 120 */ "DropTable" OpHelp(""), |
| 23401 | + /* 121 */ "DropIndex" OpHelp(""), |
| 23402 | + /* 122 */ "DropTrigger" OpHelp(""), |
| 23403 | + /* 123 */ "IntegrityCk" OpHelp(""), |
| 23404 | + /* 124 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 23405 | + /* 125 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"), |
| 23406 | + /* 126 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"), |
| 23407 | + /* 127 */ "Program" OpHelp(""), |
| 23408 | + /* 128 */ "Param" OpHelp(""), |
| 23409 | + /* 129 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 23410 | + /* 130 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"), |
| 23411 | + /* 131 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 23412 | + /* 132 */ "IfPos" OpHelp("if r[P1]>0 goto P2"), |
| 23324 | 23413 | /* 133 */ "Real" OpHelp("r[P2]=P4"), |
| 23325 | | - /* 134 */ "Expire" OpHelp(""), |
| 23326 | | - /* 135 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 23327 | | - /* 136 */ "VBegin" OpHelp(""), |
| 23328 | | - /* 137 */ "VCreate" OpHelp(""), |
| 23329 | | - /* 138 */ "VDestroy" OpHelp(""), |
| 23330 | | - /* 139 */ "VOpen" OpHelp(""), |
| 23331 | | - /* 140 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 23332 | | - /* 141 */ "VNext" OpHelp(""), |
| 23333 | | - /* 142 */ "VRename" OpHelp(""), |
| 23414 | + /* 134 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"), |
| 23415 | + /* 135 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"), |
| 23416 | + /* 136 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 23417 | + /* 137 */ "IncrVacuum" OpHelp(""), |
| 23418 | + /* 138 */ "Expire" OpHelp(""), |
| 23419 | + /* 139 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 23420 | + /* 140 */ "VBegin" OpHelp(""), |
| 23421 | + /* 141 */ "VCreate" OpHelp(""), |
| 23422 | + /* 142 */ "VDestroy" OpHelp(""), |
| 23334 | 23423 | /* 143 */ "ToText" OpHelp(""), |
| 23335 | 23424 | /* 144 */ "ToBlob" OpHelp(""), |
| 23336 | 23425 | /* 145 */ "ToNumeric" OpHelp(""), |
| 23337 | 23426 | /* 146 */ "ToInt" OpHelp(""), |
| 23338 | 23427 | /* 147 */ "ToReal" OpHelp(""), |
| 23339 | | - /* 148 */ "Pagecount" OpHelp(""), |
| 23340 | | - /* 149 */ "MaxPgcnt" OpHelp(""), |
| 23341 | | - /* 150 */ "Trace" OpHelp(""), |
| 23342 | | - /* 151 */ "Noop" OpHelp(""), |
| 23343 | | - /* 152 */ "Explain" OpHelp(""), |
| 23428 | + /* 148 */ "VOpen" OpHelp(""), |
| 23429 | + /* 149 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 23430 | + /* 150 */ "VNext" OpHelp(""), |
| 23431 | + /* 151 */ "VRename" OpHelp(""), |
| 23432 | + /* 152 */ "Pagecount" OpHelp(""), |
| 23433 | + /* 153 */ "MaxPgcnt" OpHelp(""), |
| 23434 | + /* 154 */ "Init" OpHelp("Start at P2"), |
| 23435 | + /* 155 */ "Noop" OpHelp(""), |
| 23436 | + /* 156 */ "Explain" OpHelp(""), |
| 23344 | 23437 | }; |
| 23345 | 23438 | return azName[i]; |
| 23346 | 23439 | } |
| 23347 | 23440 | #endif |
| 23348 | 23441 | |
| | @@ -23430,36 +23523,10 @@ |
| 23430 | 23523 | # else |
| 23431 | 23524 | # define OS_VXWORKS 0 |
| 23432 | 23525 | # endif |
| 23433 | 23526 | #endif |
| 23434 | 23527 | |
| 23435 | | -/* |
| 23436 | | -** These #defines should enable >2GB file support on Posix if the |
| 23437 | | -** underlying operating system supports it. If the OS lacks |
| 23438 | | -** large file support, these should be no-ops. |
| 23439 | | -** |
| 23440 | | -** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch |
| 23441 | | -** on the compiler command line. This is necessary if you are compiling |
| 23442 | | -** on a recent machine (ex: RedHat 7.2) but you want your code to work |
| 23443 | | -** on an older machine (ex: RedHat 6.0). If you compile on RedHat 7.2 |
| 23444 | | -** without this option, LFS is enable. But LFS does not exist in the kernel |
| 23445 | | -** in RedHat 6.0, so the code won't work. Hence, for maximum binary |
| 23446 | | -** portability you should omit LFS. |
| 23447 | | -** |
| 23448 | | -** The previous paragraph was written in 2005. (This paragraph is written |
| 23449 | | -** on 2008-11-28.) These days, all Linux kernels support large files, so |
| 23450 | | -** you should probably leave LFS enabled. But some embedded platforms might |
| 23451 | | -** lack LFS in which case the SQLITE_DISABLE_LFS macro might still be useful. |
| 23452 | | -*/ |
| 23453 | | -#ifndef SQLITE_DISABLE_LFS |
| 23454 | | -# define _LARGE_FILE 1 |
| 23455 | | -# ifndef _FILE_OFFSET_BITS |
| 23456 | | -# define _FILE_OFFSET_BITS 64 |
| 23457 | | -# endif |
| 23458 | | -# define _LARGEFILE_SOURCE 1 |
| 23459 | | -#endif |
| 23460 | | - |
| 23461 | 23528 | /* |
| 23462 | 23529 | ** standard include files. |
| 23463 | 23530 | */ |
| 23464 | 23531 | #include <sys/types.h> |
| 23465 | 23532 | #include <sys/stat.h> |
| | @@ -34444,11 +34511,11 @@ |
| 34444 | 34511 | ** Windows will only let you create file view mappings |
| 34445 | 34512 | ** on allocation size granularity boundaries. |
| 34446 | 34513 | ** During sqlite3_os_init() we do a GetSystemInfo() |
| 34447 | 34514 | ** to get the granularity size. |
| 34448 | 34515 | */ |
| 34449 | | -SYSTEM_INFO winSysInfo; |
| 34516 | +static SYSTEM_INFO winSysInfo; |
| 34450 | 34517 | |
| 34451 | 34518 | #ifndef SQLITE_OMIT_WAL |
| 34452 | 34519 | |
| 34453 | 34520 | /* |
| 34454 | 34521 | ** Helper functions to obtain and relinquish the global mutex. The |
| | @@ -36378,19 +36445,16 @@ |
| 36378 | 36445 | #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 36379 | 36446 | /* |
| 36380 | 36447 | ** Interfaces for opening a shared library, finding entry points |
| 36381 | 36448 | ** within the shared library, and closing the shared library. |
| 36382 | 36449 | */ |
| 36383 | | -/* |
| 36384 | | -** Interfaces for opening a shared library, finding entry points |
| 36385 | | -** within the shared library, and closing the shared library. |
| 36386 | | -*/ |
| 36387 | 36450 | static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){ |
| 36388 | 36451 | HANDLE h; |
| 36389 | 36452 | void *zConverted = winConvertFromUtf8Filename(zFilename); |
| 36390 | 36453 | UNUSED_PARAMETER(pVfs); |
| 36391 | 36454 | if( zConverted==0 ){ |
| 36455 | + OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0)); |
| 36392 | 36456 | return 0; |
| 36393 | 36457 | } |
| 36394 | 36458 | if( osIsNT() ){ |
| 36395 | 36459 | #if SQLITE_OS_WINRT |
| 36396 | 36460 | h = osLoadPackagedLibrary((LPCWSTR)zConverted, 0); |
| | @@ -36401,24 +36465,30 @@ |
| 36401 | 36465 | #ifdef SQLITE_WIN32_HAS_ANSI |
| 36402 | 36466 | else{ |
| 36403 | 36467 | h = osLoadLibraryA((char*)zConverted); |
| 36404 | 36468 | } |
| 36405 | 36469 | #endif |
| 36470 | + OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h)); |
| 36406 | 36471 | sqlite3_free(zConverted); |
| 36407 | 36472 | return (void*)h; |
| 36408 | 36473 | } |
| 36409 | 36474 | static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){ |
| 36410 | 36475 | UNUSED_PARAMETER(pVfs); |
| 36411 | 36476 | winGetLastErrorMsg(osGetLastError(), nBuf, zBufOut); |
| 36412 | 36477 | } |
| 36413 | 36478 | static void (*winDlSym(sqlite3_vfs *pVfs,void *pH,const char *zSym))(void){ |
| 36479 | + FARPROC proc; |
| 36414 | 36480 | UNUSED_PARAMETER(pVfs); |
| 36415 | | - return (void(*)(void))osGetProcAddressA((HANDLE)pH, zSym); |
| 36481 | + proc = osGetProcAddressA((HANDLE)pH, zSym); |
| 36482 | + OSTRACE(("DLSYM handle=%p, symbol=%s, address=%p\n", |
| 36483 | + (void*)pH, zSym, (void*)proc)); |
| 36484 | + return (void(*)(void))proc; |
| 36416 | 36485 | } |
| 36417 | 36486 | static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){ |
| 36418 | 36487 | UNUSED_PARAMETER(pVfs); |
| 36419 | 36488 | osFreeLibrary((HANDLE)pHandle); |
| 36489 | + OSTRACE(("DLCLOSE handle=%p\n", (void*)pHandle)); |
| 36420 | 36490 | } |
| 36421 | 36491 | #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */ |
| 36422 | 36492 | #define winDlOpen 0 |
| 36423 | 36493 | #define winDlError 0 |
| 36424 | 36494 | #define winDlSym 0 |
| | @@ -37110,11 +37180,12 @@ |
| 37110 | 37180 | PgHdr *pSynced; /* Last synced page in dirty page list */ |
| 37111 | 37181 | int nRef; /* Number of referenced pages */ |
| 37112 | 37182 | int szCache; /* Configured cache size */ |
| 37113 | 37183 | int szPage; /* Size of every page in this cache */ |
| 37114 | 37184 | int szExtra; /* Size of extra space for each page */ |
| 37115 | | - int bPurgeable; /* True if pages are on backing store */ |
| 37185 | + u8 bPurgeable; /* True if pages are on backing store */ |
| 37186 | + u8 eCreate; /* eCreate value for for xFetch() */ |
| 37116 | 37187 | int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */ |
| 37117 | 37188 | void *pStress; /* Argument to xStress */ |
| 37118 | 37189 | sqlite3_pcache *pCache; /* Pluggable cache module */ |
| 37119 | 37190 | PgHdr *pPage1; /* Reference to page 1 */ |
| 37120 | 37191 | }; |
| | @@ -37177,10 +37248,14 @@ |
| 37177 | 37248 | if( pPage->pDirtyPrev ){ |
| 37178 | 37249 | pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext; |
| 37179 | 37250 | }else{ |
| 37180 | 37251 | assert( pPage==p->pDirty ); |
| 37181 | 37252 | p->pDirty = pPage->pDirtyNext; |
| 37253 | + if( p->pDirty==0 && p->bPurgeable ){ |
| 37254 | + assert( p->eCreate==1 ); |
| 37255 | + p->eCreate = 2; |
| 37256 | + } |
| 37182 | 37257 | } |
| 37183 | 37258 | pPage->pDirtyNext = 0; |
| 37184 | 37259 | pPage->pDirtyPrev = 0; |
| 37185 | 37260 | |
| 37186 | 37261 | expensive_assert( pcacheCheckSynced(p) ); |
| | @@ -37197,10 +37272,13 @@ |
| 37197 | 37272 | |
| 37198 | 37273 | pPage->pDirtyNext = p->pDirty; |
| 37199 | 37274 | if( pPage->pDirtyNext ){ |
| 37200 | 37275 | assert( pPage->pDirtyNext->pDirtyPrev==0 ); |
| 37201 | 37276 | pPage->pDirtyNext->pDirtyPrev = pPage; |
| 37277 | + }else if( p->bPurgeable ){ |
| 37278 | + assert( p->eCreate==2 ); |
| 37279 | + p->eCreate = 1; |
| 37202 | 37280 | } |
| 37203 | 37281 | p->pDirty = pPage; |
| 37204 | 37282 | if( !p->pDirtyTail ){ |
| 37205 | 37283 | p->pDirtyTail = pPage; |
| 37206 | 37284 | } |
| | @@ -37266,10 +37344,11 @@ |
| 37266 | 37344 | ){ |
| 37267 | 37345 | memset(p, 0, sizeof(PCache)); |
| 37268 | 37346 | p->szPage = szPage; |
| 37269 | 37347 | p->szExtra = szExtra; |
| 37270 | 37348 | p->bPurgeable = bPurgeable; |
| 37349 | + p->eCreate = 2; |
| 37271 | 37350 | p->xStress = xStress; |
| 37272 | 37351 | p->pStress = pStress; |
| 37273 | 37352 | p->szCache = 100; |
| 37274 | 37353 | } |
| 37275 | 37354 | |
| | @@ -37305,11 +37384,11 @@ |
| 37305 | 37384 | PCache *pCache, /* Obtain the page from this cache */ |
| 37306 | 37385 | Pgno pgno, /* Page number to obtain */ |
| 37307 | 37386 | int createFlag, /* If true, create page if it does not exist already */ |
| 37308 | 37387 | PgHdr **ppPage /* Write the page here */ |
| 37309 | 37388 | ){ |
| 37310 | | - sqlite3_pcache_page *pPage = 0; |
| 37389 | + sqlite3_pcache_page *pPage; |
| 37311 | 37390 | PgHdr *pPgHdr = 0; |
| 37312 | 37391 | int eCreate; |
| 37313 | 37392 | |
| 37314 | 37393 | assert( pCache!=0 ); |
| 37315 | 37394 | assert( createFlag==1 || createFlag==0 ); |
| | @@ -37316,12 +37395,16 @@ |
| 37316 | 37395 | assert( pgno>0 ); |
| 37317 | 37396 | |
| 37318 | 37397 | /* If the pluggable cache (sqlite3_pcache*) has not been allocated, |
| 37319 | 37398 | ** allocate it now. |
| 37320 | 37399 | */ |
| 37321 | | - if( !pCache->pCache && createFlag ){ |
| 37400 | + if( !pCache->pCache ){ |
| 37322 | 37401 | sqlite3_pcache *p; |
| 37402 | + if( !createFlag ){ |
| 37403 | + *ppPage = 0; |
| 37404 | + return SQLITE_OK; |
| 37405 | + } |
| 37323 | 37406 | p = sqlite3GlobalConfig.pcache2.xCreate( |
| 37324 | 37407 | pCache->szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable |
| 37325 | 37408 | ); |
| 37326 | 37409 | if( !p ){ |
| 37327 | 37410 | return SQLITE_NOMEM; |
| | @@ -37328,15 +37411,20 @@ |
| 37328 | 37411 | } |
| 37329 | 37412 | sqlite3GlobalConfig.pcache2.xCachesize(p, numberOfCachePages(pCache)); |
| 37330 | 37413 | pCache->pCache = p; |
| 37331 | 37414 | } |
| 37332 | 37415 | |
| 37333 | | - eCreate = createFlag * (1 + (!pCache->bPurgeable || !pCache->pDirty)); |
| 37334 | | - if( pCache->pCache ){ |
| 37335 | | - pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate); |
| 37336 | | - } |
| 37337 | | - |
| 37416 | + /* eCreate defines what to do if the page does not exist. |
| 37417 | + ** 0 Do not allocate a new page. (createFlag==0) |
| 37418 | + ** 1 Allocate a new page if doing so is inexpensive. |
| 37419 | + ** (createFlag==1 AND bPurgeable AND pDirty) |
| 37420 | + ** 2 Allocate a new page even it doing so is difficult. |
| 37421 | + ** (createFlag==1 AND !(bPurgeable AND pDirty) |
| 37422 | + */ |
| 37423 | + eCreate = createFlag==0 ? 0 : pCache->eCreate; |
| 37424 | + assert( (createFlag*(1+(!pCache->bPurgeable||!pCache->pDirty)))==eCreate ); |
| 37425 | + pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate); |
| 37338 | 37426 | if( !pPage && eCreate==1 ){ |
| 37339 | 37427 | PgHdr *pPg; |
| 37340 | 37428 | |
| 37341 | 37429 | /* Find a dirty page to write-out and recycle. First try to find a |
| 37342 | 37430 | ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC |
| | @@ -47920,11 +48008,11 @@ |
| 47920 | 48008 | if( rc!=SQLITE_OK ){ |
| 47921 | 48009 | walIndexClose(pRet, 0); |
| 47922 | 48010 | sqlite3OsClose(pRet->pWalFd); |
| 47923 | 48011 | sqlite3_free(pRet); |
| 47924 | 48012 | }else{ |
| 47925 | | - int iDC = sqlite3OsDeviceCharacteristics(pRet->pWalFd); |
| 48013 | + int iDC = sqlite3OsDeviceCharacteristics(pDbFd); |
| 47926 | 48014 | if( iDC & SQLITE_IOCAP_SEQUENTIAL ){ pRet->syncHeader = 0; } |
| 47927 | 48015 | if( iDC & SQLITE_IOCAP_POWERSAFE_OVERWRITE ){ |
| 47928 | 48016 | pRet->padToSectorBoundary = 0; |
| 47929 | 48017 | } |
| 47930 | 48018 | *ppWal = pRet; |
| | @@ -49291,11 +49379,11 @@ |
| 49291 | 49379 | if( rc ) return rc; |
| 49292 | 49380 | iOffset += iFirstAmt; |
| 49293 | 49381 | iAmt -= iFirstAmt; |
| 49294 | 49382 | pContent = (void*)(iFirstAmt + (char*)pContent); |
| 49295 | 49383 | assert( p->syncFlags & (SQLITE_SYNC_NORMAL|SQLITE_SYNC_FULL) ); |
| 49296 | | - rc = sqlite3OsSync(p->pFd, p->syncFlags); |
| 49384 | + rc = sqlite3OsSync(p->pFd, p->syncFlags & SQLITE_SYNC_MASK); |
| 49297 | 49385 | if( iAmt==0 || rc ) return rc; |
| 49298 | 49386 | } |
| 49299 | 49387 | rc = sqlite3OsWrite(p->pFd, pContent, iAmt, iOffset); |
| 49300 | 49388 | return rc; |
| 49301 | 49389 | } |
| | @@ -50229,11 +50317,10 @@ |
| 50229 | 50317 | struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */ |
| 50230 | 50318 | #ifndef SQLITE_OMIT_INCRBLOB |
| 50231 | 50319 | Pgno *aOverflow; /* Cache of overflow page locations */ |
| 50232 | 50320 | #endif |
| 50233 | 50321 | Pgno pgnoRoot; /* The root page of this tree */ |
| 50234 | | - sqlite3_int64 cachedRowid; /* Next rowid cache. 0 means not valid */ |
| 50235 | 50322 | CellInfo info; /* A parse of the cell we are pointing at */ |
| 50236 | 50323 | i64 nKey; /* Size of pKey, or last integer key */ |
| 50237 | 50324 | void *pKey; /* Saved key that was cursor's last known position */ |
| 50238 | 50325 | int skipNext; /* Prev() is noop if negative. Next() is noop if positive */ |
| 50239 | 50326 | u8 wrFlag; /* True if writable */ |
| | @@ -52213,17 +52300,16 @@ |
| 52213 | 52300 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 52214 | 52301 | if( pBt->btsFlags & BTS_SECURE_DELETE ){ |
| 52215 | 52302 | memset(&data[hdr], 0, pBt->usableSize - hdr); |
| 52216 | 52303 | } |
| 52217 | 52304 | data[hdr] = (char)flags; |
| 52218 | | - first = hdr + 8 + 4*((flags&PTF_LEAF)==0 ?1:0); |
| 52305 | + first = hdr + ((flags&PTF_LEAF)==0 ? 12 : 8); |
| 52219 | 52306 | memset(&data[hdr+1], 0, 4); |
| 52220 | 52307 | data[hdr+7] = 0; |
| 52221 | 52308 | put2byte(&data[hdr+5], pBt->usableSize); |
| 52222 | 52309 | pPage->nFree = (u16)(pBt->usableSize - first); |
| 52223 | 52310 | decodeFlags(pPage, flags); |
| 52224 | | - pPage->hdrOffset = hdr; |
| 52225 | 52311 | pPage->cellOffset = first; |
| 52226 | 52312 | pPage->aDataEnd = &data[pBt->usableSize]; |
| 52227 | 52313 | pPage->aCellIdx = &data[first]; |
| 52228 | 52314 | pPage->nOverflow = 0; |
| 52229 | 52315 | assert( pBt->pageSize>=512 && pBt->pageSize<=65536 ); |
| | @@ -54303,11 +54389,10 @@ |
| 54303 | 54389 | if( pCur->pNext ){ |
| 54304 | 54390 | pCur->pNext->pPrev = pCur; |
| 54305 | 54391 | } |
| 54306 | 54392 | pBt->pCursor = pCur; |
| 54307 | 54393 | pCur->eState = CURSOR_INVALID; |
| 54308 | | - pCur->cachedRowid = 0; |
| 54309 | 54394 | return SQLITE_OK; |
| 54310 | 54395 | } |
| 54311 | 54396 | SQLITE_PRIVATE int sqlite3BtreeCursor( |
| 54312 | 54397 | Btree *p, /* The btree */ |
| 54313 | 54398 | int iTable, /* Root page of table to open */ |
| | @@ -54344,40 +54429,10 @@ |
| 54344 | 54429 | */ |
| 54345 | 54430 | SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor *p){ |
| 54346 | 54431 | memset(p, 0, offsetof(BtCursor, iPage)); |
| 54347 | 54432 | } |
| 54348 | 54433 | |
| 54349 | | -/* |
| 54350 | | -** Set the cached rowid value of every cursor in the same database file |
| 54351 | | -** as pCur and having the same root page number as pCur. The value is |
| 54352 | | -** set to iRowid. |
| 54353 | | -** |
| 54354 | | -** Only positive rowid values are considered valid for this cache. |
| 54355 | | -** The cache is initialized to zero, indicating an invalid cache. |
| 54356 | | -** A btree will work fine with zero or negative rowids. We just cannot |
| 54357 | | -** cache zero or negative rowids, which means tables that use zero or |
| 54358 | | -** negative rowids might run a little slower. But in practice, zero |
| 54359 | | -** or negative rowids are very uncommon so this should not be a problem. |
| 54360 | | -*/ |
| 54361 | | -SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor *pCur, sqlite3_int64 iRowid){ |
| 54362 | | - BtCursor *p; |
| 54363 | | - for(p=pCur->pBt->pCursor; p; p=p->pNext){ |
| 54364 | | - if( p->pgnoRoot==pCur->pgnoRoot ) p->cachedRowid = iRowid; |
| 54365 | | - } |
| 54366 | | - assert( pCur->cachedRowid==iRowid ); |
| 54367 | | -} |
| 54368 | | - |
| 54369 | | -/* |
| 54370 | | -** Return the cached rowid for the given cursor. A negative or zero |
| 54371 | | -** return value indicates that the rowid cache is invalid and should be |
| 54372 | | -** ignored. If the rowid cache has never before been set, then a |
| 54373 | | -** zero is returned. |
| 54374 | | -*/ |
| 54375 | | -SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor *pCur){ |
| 54376 | | - return pCur->cachedRowid; |
| 54377 | | -} |
| 54378 | | - |
| 54379 | 54434 | /* |
| 54380 | 54435 | ** Close a cursor. The read lock on the database file is released |
| 54381 | 54436 | ** when the last cursor is closed. |
| 54382 | 54437 | */ |
| 54383 | 54438 | SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *pCur){ |
| | @@ -55448,18 +55503,28 @@ |
| 55448 | 55503 | /* |
| 55449 | 55504 | ** Advance the cursor to the next entry in the database. If |
| 55450 | 55505 | ** successful then set *pRes=0. If the cursor |
| 55451 | 55506 | ** was already pointing to the last entry in the database before |
| 55452 | 55507 | ** this routine was called, then set *pRes=1. |
| 55508 | +** |
| 55509 | +** The calling function will set *pRes to 0 or 1. The initial *pRes value |
| 55510 | +** will be 1 if the cursor being stepped corresponds to an SQL index and |
| 55511 | +** if this routine could have been skipped if that SQL index had been |
| 55512 | +** a unique index. Otherwise the caller will have set *pRes to zero. |
| 55513 | +** Zero is the common case. The btree implementation is free to use the |
| 55514 | +** initial *pRes value as a hint to improve performance, but the current |
| 55515 | +** SQLite btree implementation does not. (Note that the comdb2 btree |
| 55516 | +** implementation does use this hint, however.) |
| 55453 | 55517 | */ |
| 55454 | 55518 | SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int *pRes){ |
| 55455 | 55519 | int rc; |
| 55456 | 55520 | int idx; |
| 55457 | 55521 | MemPage *pPage; |
| 55458 | 55522 | |
| 55459 | 55523 | assert( cursorHoldsMutex(pCur) ); |
| 55460 | 55524 | assert( pRes!=0 ); |
| 55525 | + assert( *pRes==0 || *pRes==1 ); |
| 55461 | 55526 | assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID ); |
| 55462 | 55527 | if( pCur->eState!=CURSOR_VALID ){ |
| 55463 | 55528 | rc = restoreCursorPosition(pCur); |
| 55464 | 55529 | if( rc!=SQLITE_OK ){ |
| 55465 | 55530 | *pRes = 0; |
| | @@ -55534,17 +55599,27 @@ |
| 55534 | 55599 | /* |
| 55535 | 55600 | ** Step the cursor to the back to the previous entry in the database. If |
| 55536 | 55601 | ** successful then set *pRes=0. If the cursor |
| 55537 | 55602 | ** was already pointing to the first entry in the database before |
| 55538 | 55603 | ** this routine was called, then set *pRes=1. |
| 55604 | +** |
| 55605 | +** The calling function will set *pRes to 0 or 1. The initial *pRes value |
| 55606 | +** will be 1 if the cursor being stepped corresponds to an SQL index and |
| 55607 | +** if this routine could have been skipped if that SQL index had been |
| 55608 | +** a unique index. Otherwise the caller will have set *pRes to zero. |
| 55609 | +** Zero is the common case. The btree implementation is free to use the |
| 55610 | +** initial *pRes value as a hint to improve performance, but the current |
| 55611 | +** SQLite btree implementation does not. (Note that the comdb2 btree |
| 55612 | +** implementation does use this hint, however.) |
| 55539 | 55613 | */ |
| 55540 | 55614 | SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){ |
| 55541 | 55615 | int rc; |
| 55542 | 55616 | MemPage *pPage; |
| 55543 | 55617 | |
| 55544 | 55618 | assert( cursorHoldsMutex(pCur) ); |
| 55545 | 55619 | assert( pRes!=0 ); |
| 55620 | + assert( *pRes==0 || *pRes==1 ); |
| 55546 | 55621 | assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID ); |
| 55547 | 55622 | pCur->atLast = 0; |
| 55548 | 55623 | if( pCur->eState!=CURSOR_VALID ){ |
| 55549 | 55624 | if( ALWAYS(pCur->eState>=CURSOR_REQUIRESEEK) ){ |
| 55550 | 55625 | rc = btreeRestoreCursorPosition(pCur); |
| | @@ -57637,15 +57712,21 @@ |
| 57637 | 57712 | ** not to clear the cursor here. |
| 57638 | 57713 | */ |
| 57639 | 57714 | rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur); |
| 57640 | 57715 | if( rc ) return rc; |
| 57641 | 57716 | |
| 57642 | | - /* If this is an insert into a table b-tree, invalidate any incrblob |
| 57643 | | - ** cursors open on the row being replaced (assuming this is a replace |
| 57644 | | - ** operation - if it is not, the following is a no-op). */ |
| 57645 | 57717 | if( pCur->pKeyInfo==0 ){ |
| 57718 | + /* If this is an insert into a table b-tree, invalidate any incrblob |
| 57719 | + ** cursors open on the row being replaced */ |
| 57646 | 57720 | invalidateIncrblobCursors(p, nKey, 0); |
| 57721 | + |
| 57722 | + /* If the cursor is currently on the last row and we are appending a |
| 57723 | + ** new row onto the end, set the "loc" to avoid an unnecessary btreeMoveto() |
| 57724 | + ** call */ |
| 57725 | + if( pCur->validNKey && nKey>0 && pCur->info.nKey==nKey-1 ){ |
| 57726 | + loc = -1; |
| 57727 | + } |
| 57647 | 57728 | } |
| 57648 | 57729 | |
| 57649 | 57730 | if( !loc ){ |
| 57650 | 57731 | rc = btreeMoveto(pCur, pKey, nKey, appendBias, &loc); |
| 57651 | 57732 | if( rc ) return rc; |
| | @@ -57711,12 +57792,12 @@ |
| 57711 | 57792 | ** entry in the table, and the next row inserted has an integer key |
| 57712 | 57793 | ** larger than the largest existing key, it is possible to insert the |
| 57713 | 57794 | ** row without seeking the cursor. This can be a big performance boost. |
| 57714 | 57795 | */ |
| 57715 | 57796 | pCur->info.nSize = 0; |
| 57716 | | - pCur->validNKey = 0; |
| 57717 | 57797 | if( rc==SQLITE_OK && pPage->nOverflow ){ |
| 57798 | + pCur->validNKey = 0; |
| 57718 | 57799 | rc = balance(pCur); |
| 57719 | 57800 | |
| 57720 | 57801 | /* Must make sure nOverflow is reset to zero even if the balance() |
| 57721 | 57802 | ** fails. Internal data structure corruption will result otherwise. |
| 57722 | 57803 | ** Also, set the cursor state to invalid. This stops saveCursorPosition() |
| | @@ -57767,11 +57848,11 @@ |
| 57767 | 57848 | ** from the internal node. The 'previous' entry is used for this instead |
| 57768 | 57849 | ** of the 'next' entry, as the previous entry is always a part of the |
| 57769 | 57850 | ** sub-tree headed by the child page of the cell being deleted. This makes |
| 57770 | 57851 | ** balancing the tree following the delete operation easier. */ |
| 57771 | 57852 | if( !pPage->leaf ){ |
| 57772 | | - int notUsed; |
| 57853 | + int notUsed = 0; |
| 57773 | 57854 | rc = sqlite3BtreePrevious(pCur, ¬Used); |
| 57774 | 57855 | if( rc ) return rc; |
| 57775 | 57856 | } |
| 57776 | 57857 | |
| 57777 | 57858 | /* Save the positions of any other cursors open on this table before |
| | @@ -60192,11 +60273,11 @@ |
| 60192 | 60273 | } |
| 60193 | 60274 | |
| 60194 | 60275 | /* |
| 60195 | 60276 | ** Release any memory held by the Mem. This may leave the Mem in an |
| 60196 | 60277 | ** inconsistent state, for example with (Mem.z==0) and |
| 60197 | | -** (Mem.type==SQLITE_TEXT). |
| 60278 | +** (Mem.memType==MEM_Str). |
| 60198 | 60279 | */ |
| 60199 | 60280 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){ |
| 60200 | 60281 | VdbeMemRelease(p); |
| 60201 | 60282 | if( p->zMalloc ){ |
| 60202 | 60283 | sqlite3DbFree(p->db, p->zMalloc); |
| | @@ -60383,11 +60464,11 @@ |
| 60383 | 60464 | } |
| 60384 | 60465 | if( pMem->flags & MEM_RowSet ){ |
| 60385 | 60466 | sqlite3RowSetClear(pMem->u.pRowSet); |
| 60386 | 60467 | } |
| 60387 | 60468 | MemSetTypeFlag(pMem, MEM_Null); |
| 60388 | | - pMem->type = SQLITE_NULL; |
| 60469 | + pMem->memType = MEM_Null; |
| 60389 | 60470 | } |
| 60390 | 60471 | SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){ |
| 60391 | 60472 | sqlite3VdbeMemSetNull((Mem*)p); |
| 60392 | 60473 | } |
| 60393 | 60474 | |
| | @@ -60396,11 +60477,11 @@ |
| 60396 | 60477 | ** n containing all zeros. |
| 60397 | 60478 | */ |
| 60398 | 60479 | SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){ |
| 60399 | 60480 | sqlite3VdbeMemRelease(pMem); |
| 60400 | 60481 | pMem->flags = MEM_Blob|MEM_Zero; |
| 60401 | | - pMem->type = SQLITE_BLOB; |
| 60482 | + pMem->memType = MEM_Blob; |
| 60402 | 60483 | pMem->n = 0; |
| 60403 | 60484 | if( n<0 ) n = 0; |
| 60404 | 60485 | pMem->u.nZero = n; |
| 60405 | 60486 | pMem->enc = SQLITE_UTF8; |
| 60406 | 60487 | |
| | @@ -60419,11 +60500,11 @@ |
| 60419 | 60500 | */ |
| 60420 | 60501 | SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){ |
| 60421 | 60502 | sqlite3VdbeMemRelease(pMem); |
| 60422 | 60503 | pMem->u.i = val; |
| 60423 | 60504 | pMem->flags = MEM_Int; |
| 60424 | | - pMem->type = SQLITE_INTEGER; |
| 60505 | + pMem->memType = MEM_Int; |
| 60425 | 60506 | } |
| 60426 | 60507 | |
| 60427 | 60508 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 60428 | 60509 | /* |
| 60429 | 60510 | ** Delete any previous value and set the value stored in *pMem to val, |
| | @@ -60434,11 +60515,11 @@ |
| 60434 | 60515 | sqlite3VdbeMemSetNull(pMem); |
| 60435 | 60516 | }else{ |
| 60436 | 60517 | sqlite3VdbeMemRelease(pMem); |
| 60437 | 60518 | pMem->r = val; |
| 60438 | 60519 | pMem->flags = MEM_Real; |
| 60439 | | - pMem->type = SQLITE_FLOAT; |
| 60520 | + pMem->memType = MEM_Real; |
| 60440 | 60521 | } |
| 60441 | 60522 | } |
| 60442 | 60523 | #endif |
| 60443 | 60524 | |
| 60444 | 60525 | /* |
| | @@ -60490,11 +60571,11 @@ |
| 60490 | 60571 | SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){ |
| 60491 | 60572 | int i; |
| 60492 | 60573 | Mem *pX; |
| 60493 | 60574 | for(i=1, pX=&pVdbe->aMem[1]; i<=pVdbe->nMem; i++, pX++){ |
| 60494 | 60575 | if( pX->pScopyFrom==pMem ){ |
| 60495 | | - pX->flags |= MEM_Invalid; |
| 60576 | + pX->flags |= MEM_Undefined; |
| 60496 | 60577 | pX->pScopyFrom = 0; |
| 60497 | 60578 | } |
| 60498 | 60579 | } |
| 60499 | 60580 | pMem->pScopyFrom = 0; |
| 60500 | 60581 | } |
| | @@ -60642,11 +60723,11 @@ |
| 60642 | 60723 | } |
| 60643 | 60724 | |
| 60644 | 60725 | pMem->n = nByte; |
| 60645 | 60726 | pMem->flags = flags; |
| 60646 | 60727 | pMem->enc = (enc==0 ? SQLITE_UTF8 : enc); |
| 60647 | | - pMem->type = (enc==0 ? SQLITE_BLOB : SQLITE_TEXT); |
| 60728 | + pMem->memType = flags&0x1f; |
| 60648 | 60729 | |
| 60649 | 60730 | #ifndef SQLITE_OMIT_UTF16 |
| 60650 | 60731 | if( pMem->enc!=SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){ |
| 60651 | 60732 | return SQLITE_NOMEM; |
| 60652 | 60733 | } |
| | @@ -60813,11 +60894,11 @@ |
| 60813 | 60894 | pMem->z = &zData[offset]; |
| 60814 | 60895 | pMem->flags = MEM_Blob|MEM_Ephem; |
| 60815 | 60896 | }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){ |
| 60816 | 60897 | pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term; |
| 60817 | 60898 | pMem->enc = 0; |
| 60818 | | - pMem->type = SQLITE_BLOB; |
| 60899 | + pMem->memType = MEM_Blob; |
| 60819 | 60900 | if( key ){ |
| 60820 | 60901 | rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z); |
| 60821 | 60902 | }else{ |
| 60822 | 60903 | rc = sqlite3BtreeData(pCur, offset, amt, pMem->z); |
| 60823 | 60904 | } |
| | @@ -60883,11 +60964,11 @@ |
| 60883 | 60964 | */ |
| 60884 | 60965 | SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *db){ |
| 60885 | 60966 | Mem *p = sqlite3DbMallocZero(db, sizeof(*p)); |
| 60886 | 60967 | if( p ){ |
| 60887 | 60968 | p->flags = MEM_Null; |
| 60888 | | - p->type = SQLITE_NULL; |
| 60969 | + p->memType = MEM_Null; |
| 60889 | 60970 | p->db = db; |
| 60890 | 60971 | } |
| 60891 | 60972 | return p; |
| 60892 | 60973 | } |
| 60893 | 60974 | |
| | @@ -60933,11 +61014,11 @@ |
| 60933 | 61014 | assert( pRec->pKeyInfo->enc==ENC(db) ); |
| 60934 | 61015 | pRec->flags = UNPACKED_PREFIX_MATCH; |
| 60935 | 61016 | pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord))); |
| 60936 | 61017 | for(i=0; i<nCol; i++){ |
| 60937 | 61018 | pRec->aMem[i].flags = MEM_Null; |
| 60938 | | - pRec->aMem[i].type = SQLITE_NULL; |
| 61019 | + pRec->aMem[i].memType = MEM_Null; |
| 60939 | 61020 | pRec->aMem[i].db = db; |
| 60940 | 61021 | } |
| 60941 | 61022 | }else{ |
| 60942 | 61023 | sqlite3DbFree(db, pRec); |
| 60943 | 61024 | pRec = 0; |
| | @@ -61006,11 +61087,11 @@ |
| 61006 | 61087 | sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue*negInt); |
| 61007 | 61088 | }else{ |
| 61008 | 61089 | zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken); |
| 61009 | 61090 | if( zVal==0 ) goto no_mem; |
| 61010 | 61091 | sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC); |
| 61011 | | - if( op==TK_FLOAT ) pVal->type = SQLITE_FLOAT; |
| 61092 | + if( op==TK_FLOAT ) pVal->memType = MEM_Real; |
| 61012 | 61093 | } |
| 61013 | 61094 | if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){ |
| 61014 | 61095 | sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8); |
| 61015 | 61096 | }else{ |
| 61016 | 61097 | sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8); |
| | @@ -61464,10 +61545,13 @@ |
| 61464 | 61545 | #endif |
| 61465 | 61546 | #ifdef VDBE_PROFILE |
| 61466 | 61547 | pOp->cycles = 0; |
| 61467 | 61548 | pOp->cnt = 0; |
| 61468 | 61549 | #endif |
| 61550 | +#ifdef SQLITE_VDBE_COVERAGE |
| 61551 | + pOp->iSrcLine = 0; |
| 61552 | +#endif |
| 61469 | 61553 | return i; |
| 61470 | 61554 | } |
| 61471 | 61555 | SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe *p, int op){ |
| 61472 | 61556 | return sqlite3VdbeAddOp3(p, op, 0, 0, 0); |
| 61473 | 61557 | } |
| | @@ -61825,11 +61909,11 @@ |
| 61825 | 61909 | |
| 61826 | 61910 | /* |
| 61827 | 61911 | ** Add a whole list of operations to the operation stack. Return the |
| 61828 | 61912 | ** address of the first operation added. |
| 61829 | 61913 | */ |
| 61830 | | -SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){ |
| 61914 | +SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp, int iLineno){ |
| 61831 | 61915 | int addr; |
| 61832 | 61916 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 61833 | 61917 | if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){ |
| 61834 | 61918 | return 0; |
| 61835 | 61919 | } |
| | @@ -61852,10 +61936,15 @@ |
| 61852 | 61936 | pOut->p4type = P4_NOTUSED; |
| 61853 | 61937 | pOut->p4.p = 0; |
| 61854 | 61938 | pOut->p5 = 0; |
| 61855 | 61939 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 61856 | 61940 | pOut->zComment = 0; |
| 61941 | +#endif |
| 61942 | +#ifdef SQLITE_VDBE_COVERAGE |
| 61943 | + pOut->iSrcLine = iLineno+i; |
| 61944 | +#else |
| 61945 | + (void)iLineno; |
| 61857 | 61946 | #endif |
| 61858 | 61947 | #ifdef SQLITE_DEBUG |
| 61859 | 61948 | if( p->db->flags & SQLITE_VdbeAddopTrace ){ |
| 61860 | 61949 | sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]); |
| 61861 | 61950 | } |
| | @@ -62141,10 +62230,19 @@ |
| 62141 | 62230 | va_end(ap); |
| 62142 | 62231 | } |
| 62143 | 62232 | } |
| 62144 | 62233 | #endif /* NDEBUG */ |
| 62145 | 62234 | |
| 62235 | +#ifdef SQLITE_VDBE_COVERAGE |
| 62236 | +/* |
| 62237 | +** Set the value if the iSrcLine field for the previously coded instruction. |
| 62238 | +*/ |
| 62239 | +SQLITE_PRIVATE void sqlite3VdbeSetLineNumber(Vdbe *v, int iLine){ |
| 62240 | + sqlite3VdbeGetOp(v,-1)->iSrcLine = iLine; |
| 62241 | +} |
| 62242 | +#endif /* SQLITE_VDBE_COVERAGE */ |
| 62243 | + |
| 62146 | 62244 | /* |
| 62147 | 62245 | ** Return the opcode for a given address. If the address is -1, then |
| 62148 | 62246 | ** return the most recently inserted opcode. |
| 62149 | 62247 | ** |
| 62150 | 62248 | ** If a memory allocation error has occurred prior to the calling of this |
| | @@ -62153,28 +62251,17 @@ |
| 62153 | 62251 | ** The return of a dummy opcode allows the call to continue functioning |
| 62154 | 62252 | ** after a OOM fault without having to check to see if the return from |
| 62155 | 62253 | ** this routine is a valid pointer. But because the dummy.opcode is 0, |
| 62156 | 62254 | ** dummy will never be written to. This is verified by code inspection and |
| 62157 | 62255 | ** by running with Valgrind. |
| 62158 | | -** |
| 62159 | | -** About the #ifdef SQLITE_OMIT_TRACE: Normally, this routine is never called |
| 62160 | | -** unless p->nOp>0. This is because in the absense of SQLITE_OMIT_TRACE, |
| 62161 | | -** an OP_Trace instruction is always inserted by sqlite3VdbeGet() as soon as |
| 62162 | | -** a new VDBE is created. So we are free to set addr to p->nOp-1 without |
| 62163 | | -** having to double-check to make sure that the result is non-negative. But |
| 62164 | | -** if SQLITE_OMIT_TRACE is defined, the OP_Trace is omitted and we do need to |
| 62165 | | -** check the value of p->nOp-1 before continuing. |
| 62166 | 62256 | */ |
| 62167 | 62257 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){ |
| 62168 | 62258 | /* C89 specifies that the constant "dummy" will be initialized to all |
| 62169 | 62259 | ** zeros, which is correct. MSVC generates a warning, nevertheless. */ |
| 62170 | 62260 | static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */ |
| 62171 | 62261 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 62172 | 62262 | if( addr<0 ){ |
| 62173 | | -#ifdef SQLITE_OMIT_TRACE |
| 62174 | | - if( p->nOp==0 ) return (VdbeOp*)&dummy; |
| 62175 | | -#endif |
| 62176 | 62263 | addr = p->nOp - 1; |
| 62177 | 62264 | } |
| 62178 | 62265 | assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed ); |
| 62179 | 62266 | if( p->db->mallocFailed ){ |
| 62180 | 62267 | return (VdbeOp*)&dummy; |
| | @@ -62475,11 +62562,11 @@ |
| 62475 | 62562 | if( pOut==0 ) pOut = stdout; |
| 62476 | 62563 | zP4 = displayP4(pOp, zPtr, sizeof(zPtr)); |
| 62477 | 62564 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 62478 | 62565 | displayComment(pOp, zP4, zCom, sizeof(zCom)); |
| 62479 | 62566 | #else |
| 62480 | | - zCom[0] = 0 |
| 62567 | + zCom[0] = 0; |
| 62481 | 62568 | #endif |
| 62482 | 62569 | /* NB: The sqlite3OpcodeName() function is implemented by code created |
| 62483 | 62570 | ** by the mkopcodeh.awk and mkopcodec.awk scripts which extract the |
| 62484 | 62571 | ** information from the vdbe.c source text */ |
| 62485 | 62572 | fprintf(pOut, zFormat1, pc, |
| | @@ -62524,11 +62611,11 @@ |
| 62524 | 62611 | }else if( p->zMalloc ){ |
| 62525 | 62612 | sqlite3DbFree(db, p->zMalloc); |
| 62526 | 62613 | p->zMalloc = 0; |
| 62527 | 62614 | } |
| 62528 | 62615 | |
| 62529 | | - p->flags = MEM_Invalid; |
| 62616 | + p->flags = MEM_Undefined; |
| 62530 | 62617 | } |
| 62531 | 62618 | db->mallocFailed = malloc_failed; |
| 62532 | 62619 | } |
| 62533 | 62620 | } |
| 62534 | 62621 | |
| | @@ -62646,19 +62733,19 @@ |
| 62646 | 62733 | } |
| 62647 | 62734 | pOp = &apSub[j]->aOp[i]; |
| 62648 | 62735 | } |
| 62649 | 62736 | if( p->explain==1 ){ |
| 62650 | 62737 | pMem->flags = MEM_Int; |
| 62651 | | - pMem->type = SQLITE_INTEGER; |
| 62738 | + pMem->memType = MEM_Int; |
| 62652 | 62739 | pMem->u.i = i; /* Program counter */ |
| 62653 | 62740 | pMem++; |
| 62654 | 62741 | |
| 62655 | 62742 | pMem->flags = MEM_Static|MEM_Str|MEM_Term; |
| 62656 | 62743 | pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */ |
| 62657 | 62744 | assert( pMem->z!=0 ); |
| 62658 | 62745 | pMem->n = sqlite3Strlen30(pMem->z); |
| 62659 | | - pMem->type = SQLITE_TEXT; |
| 62746 | + pMem->memType = MEM_Str; |
| 62660 | 62747 | pMem->enc = SQLITE_UTF8; |
| 62661 | 62748 | pMem++; |
| 62662 | 62749 | |
| 62663 | 62750 | /* When an OP_Program opcode is encounter (the only opcode that has |
| 62664 | 62751 | ** a P4_SUBPROGRAM argument), expand the size of the array of subprograms |
| | @@ -62680,21 +62767,21 @@ |
| 62680 | 62767 | } |
| 62681 | 62768 | } |
| 62682 | 62769 | |
| 62683 | 62770 | pMem->flags = MEM_Int; |
| 62684 | 62771 | pMem->u.i = pOp->p1; /* P1 */ |
| 62685 | | - pMem->type = SQLITE_INTEGER; |
| 62772 | + pMem->memType = MEM_Int; |
| 62686 | 62773 | pMem++; |
| 62687 | 62774 | |
| 62688 | 62775 | pMem->flags = MEM_Int; |
| 62689 | 62776 | pMem->u.i = pOp->p2; /* P2 */ |
| 62690 | | - pMem->type = SQLITE_INTEGER; |
| 62777 | + pMem->memType = MEM_Int; |
| 62691 | 62778 | pMem++; |
| 62692 | 62779 | |
| 62693 | 62780 | pMem->flags = MEM_Int; |
| 62694 | 62781 | pMem->u.i = pOp->p3; /* P3 */ |
| 62695 | | - pMem->type = SQLITE_INTEGER; |
| 62782 | + pMem->memType = MEM_Int; |
| 62696 | 62783 | pMem++; |
| 62697 | 62784 | |
| 62698 | 62785 | if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */ |
| 62699 | 62786 | assert( p->db->mallocFailed ); |
| 62700 | 62787 | return SQLITE_ERROR; |
| | @@ -62706,11 +62793,11 @@ |
| 62706 | 62793 | }else{ |
| 62707 | 62794 | assert( pMem->z!=0 ); |
| 62708 | 62795 | pMem->n = sqlite3Strlen30(pMem->z); |
| 62709 | 62796 | pMem->enc = SQLITE_UTF8; |
| 62710 | 62797 | } |
| 62711 | | - pMem->type = SQLITE_TEXT; |
| 62798 | + pMem->memType = MEM_Str; |
| 62712 | 62799 | pMem++; |
| 62713 | 62800 | |
| 62714 | 62801 | if( p->explain==1 ){ |
| 62715 | 62802 | if( sqlite3VdbeMemGrow(pMem, 4, 0) ){ |
| 62716 | 62803 | assert( p->db->mallocFailed ); |
| | @@ -62717,11 +62804,11 @@ |
| 62717 | 62804 | return SQLITE_ERROR; |
| 62718 | 62805 | } |
| 62719 | 62806 | pMem->flags = MEM_Dyn|MEM_Str|MEM_Term; |
| 62720 | 62807 | pMem->n = 2; |
| 62721 | 62808 | sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */ |
| 62722 | | - pMem->type = SQLITE_TEXT; |
| 62809 | + pMem->memType = MEM_Str; |
| 62723 | 62810 | pMem->enc = SQLITE_UTF8; |
| 62724 | 62811 | pMem++; |
| 62725 | 62812 | |
| 62726 | 62813 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 62727 | 62814 | if( sqlite3VdbeMemGrow(pMem, 500, 0) ){ |
| | @@ -62728,15 +62815,15 @@ |
| 62728 | 62815 | assert( p->db->mallocFailed ); |
| 62729 | 62816 | return SQLITE_ERROR; |
| 62730 | 62817 | } |
| 62731 | 62818 | pMem->flags = MEM_Dyn|MEM_Str|MEM_Term; |
| 62732 | 62819 | pMem->n = displayComment(pOp, zP4, pMem->z, 500); |
| 62733 | | - pMem->type = SQLITE_TEXT; |
| 62820 | + pMem->memType = MEM_Str; |
| 62734 | 62821 | pMem->enc = SQLITE_UTF8; |
| 62735 | 62822 | #else |
| 62736 | 62823 | pMem->flags = MEM_Null; /* Comment */ |
| 62737 | | - pMem->type = SQLITE_NULL; |
| 62824 | + pMem->memType = MEM_Null; |
| 62738 | 62825 | #endif |
| 62739 | 62826 | } |
| 62740 | 62827 | |
| 62741 | 62828 | p->nResColumn = 8 - 4*(p->explain-1); |
| 62742 | 62829 | p->pResultSet = &p->aMem[1]; |
| | @@ -62755,11 +62842,11 @@ |
| 62755 | 62842 | const char *z = 0; |
| 62756 | 62843 | if( p->zSql ){ |
| 62757 | 62844 | z = p->zSql; |
| 62758 | 62845 | }else if( p->nOp>=1 ){ |
| 62759 | 62846 | const VdbeOp *pOp = &p->aOp[0]; |
| 62760 | | - if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){ |
| 62847 | + if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){ |
| 62761 | 62848 | z = pOp->p4.z; |
| 62762 | 62849 | while( sqlite3Isspace(*z) ) z++; |
| 62763 | 62850 | } |
| 62764 | 62851 | } |
| 62765 | 62852 | if( z ) printf("SQL: [%s]\n", z); |
| | @@ -62774,11 +62861,11 @@ |
| 62774 | 62861 | int nOp = p->nOp; |
| 62775 | 62862 | VdbeOp *pOp; |
| 62776 | 62863 | if( sqlite3IoTrace==0 ) return; |
| 62777 | 62864 | if( nOp<1 ) return; |
| 62778 | 62865 | pOp = &p->aOp[0]; |
| 62779 | | - if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){ |
| 62866 | + if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){ |
| 62780 | 62867 | int i, j; |
| 62781 | 62868 | char z[1000]; |
| 62782 | 62869 | sqlite3_snprintf(sizeof(z), z, "%s", pOp->p4.z); |
| 62783 | 62870 | for(i=0; sqlite3Isspace(z[i]); i++){} |
| 62784 | 62871 | for(j=0; z[i]; i++){ |
| | @@ -62992,11 +63079,11 @@ |
| 62992 | 63079 | } |
| 62993 | 63080 | if( p->aMem ){ |
| 62994 | 63081 | p->aMem--; /* aMem[] goes from 1..nMem */ |
| 62995 | 63082 | p->nMem = nMem; /* not from 0..nMem-1 */ |
| 62996 | 63083 | for(n=1; n<=nMem; n++){ |
| 62997 | | - p->aMem[n].flags = MEM_Invalid; |
| 63084 | + p->aMem[n].flags = MEM_Undefined; |
| 62998 | 63085 | p->aMem[n].db = db; |
| 62999 | 63086 | } |
| 63000 | 63087 | } |
| 63001 | 63088 | p->explain = pParse->explain; |
| 63002 | 63089 | sqlite3VdbeRewind(p); |
| | @@ -63104,11 +63191,11 @@ |
| 63104 | 63191 | /* Execute assert() statements to ensure that the Vdbe.apCsr[] and |
| 63105 | 63192 | ** Vdbe.aMem[] arrays have already been cleaned up. */ |
| 63106 | 63193 | int i; |
| 63107 | 63194 | if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 ); |
| 63108 | 63195 | if( p->aMem ){ |
| 63109 | | - for(i=1; i<=p->nMem; i++) assert( p->aMem[i].flags==MEM_Invalid ); |
| 63196 | + for(i=1; i<=p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined ); |
| 63110 | 63197 | } |
| 63111 | 63198 | #endif |
| 63112 | 63199 | |
| 63113 | 63200 | sqlite3DbFree(db, p->zErrMsg); |
| 63114 | 63201 | p->zErrMsg = 0; |
| | @@ -63853,16 +63940,28 @@ |
| 63853 | 63940 | fprintf(out, "---- "); |
| 63854 | 63941 | for(i=0; i<p->nOp; i++){ |
| 63855 | 63942 | fprintf(out, "%02x", p->aOp[i].opcode); |
| 63856 | 63943 | } |
| 63857 | 63944 | fprintf(out, "\n"); |
| 63945 | + if( p->zSql ){ |
| 63946 | + char c, pc = 0; |
| 63947 | + fprintf(out, "-- "); |
| 63948 | + for(i=0; (c = p->zSql[i])!=0; i++){ |
| 63949 | + if( pc=='\n' ) fprintf(out, "-- "); |
| 63950 | + putc(c, out); |
| 63951 | + pc = c; |
| 63952 | + } |
| 63953 | + if( pc!='\n' ) fprintf(out, "\n"); |
| 63954 | + } |
| 63858 | 63955 | for(i=0; i<p->nOp; i++){ |
| 63859 | | - fprintf(out, "%6d %10lld %8lld ", |
| 63956 | + char zHdr[100]; |
| 63957 | + sqlite3_snprintf(sizeof(zHdr), zHdr, "%6u %12llu %8llu ", |
| 63860 | 63958 | p->aOp[i].cnt, |
| 63861 | 63959 | p->aOp[i].cycles, |
| 63862 | 63960 | p->aOp[i].cnt>0 ? p->aOp[i].cycles/p->aOp[i].cnt : 0 |
| 63863 | 63961 | ); |
| 63962 | + fprintf(out, "%s", zHdr); |
| 63864 | 63963 | sqlite3VdbePrintOp(out, i, &p->aOp[i]); |
| 63865 | 63964 | } |
| 63866 | 63965 | fclose(out); |
| 63867 | 63966 | } |
| 63868 | 63967 | } |
| | @@ -64895,11 +64994,45 @@ |
| 64895 | 64994 | SQLITE_API const void *sqlite3_value_text16le(sqlite3_value *pVal){ |
| 64896 | 64995 | return sqlite3ValueText(pVal, SQLITE_UTF16LE); |
| 64897 | 64996 | } |
| 64898 | 64997 | #endif /* SQLITE_OMIT_UTF16 */ |
| 64899 | 64998 | SQLITE_API int sqlite3_value_type(sqlite3_value* pVal){ |
| 64900 | | - return pVal->type; |
| 64999 | + static const u8 aType[] = { |
| 65000 | + SQLITE_BLOB, /* 0x00 */ |
| 65001 | + SQLITE_NULL, /* 0x01 */ |
| 65002 | + SQLITE_TEXT, /* 0x02 */ |
| 65003 | + SQLITE_NULL, /* 0x03 */ |
| 65004 | + SQLITE_INTEGER, /* 0x04 */ |
| 65005 | + SQLITE_NULL, /* 0x05 */ |
| 65006 | + SQLITE_INTEGER, /* 0x06 */ |
| 65007 | + SQLITE_NULL, /* 0x07 */ |
| 65008 | + SQLITE_FLOAT, /* 0x08 */ |
| 65009 | + SQLITE_NULL, /* 0x09 */ |
| 65010 | + SQLITE_FLOAT, /* 0x0a */ |
| 65011 | + SQLITE_NULL, /* 0x0b */ |
| 65012 | + SQLITE_INTEGER, /* 0x0c */ |
| 65013 | + SQLITE_NULL, /* 0x0d */ |
| 65014 | + SQLITE_INTEGER, /* 0x0e */ |
| 65015 | + SQLITE_NULL, /* 0x0f */ |
| 65016 | + SQLITE_BLOB, /* 0x10 */ |
| 65017 | + SQLITE_NULL, /* 0x11 */ |
| 65018 | + SQLITE_TEXT, /* 0x12 */ |
| 65019 | + SQLITE_NULL, /* 0x13 */ |
| 65020 | + SQLITE_INTEGER, /* 0x14 */ |
| 65021 | + SQLITE_NULL, /* 0x15 */ |
| 65022 | + SQLITE_INTEGER, /* 0x16 */ |
| 65023 | + SQLITE_NULL, /* 0x17 */ |
| 65024 | + SQLITE_FLOAT, /* 0x18 */ |
| 65025 | + SQLITE_NULL, /* 0x19 */ |
| 65026 | + SQLITE_FLOAT, /* 0x1a */ |
| 65027 | + SQLITE_NULL, /* 0x1b */ |
| 65028 | + SQLITE_INTEGER, /* 0x1c */ |
| 65029 | + SQLITE_NULL, /* 0x1d */ |
| 65030 | + SQLITE_INTEGER, /* 0x1e */ |
| 65031 | + SQLITE_NULL, /* 0x1f */ |
| 65032 | + }; |
| 65033 | + return aType[pVal->memType&0x1f]; |
| 64901 | 65034 | } |
| 64902 | 65035 | |
| 64903 | 65036 | /**************************** sqlite3_result_ ******************************* |
| 64904 | 65037 | ** The following routines are used by user-defined functions to specify |
| 64905 | 65038 | ** the function result. |
| | @@ -65854,11 +65987,11 @@ |
| 65854 | 65987 | return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE); |
| 65855 | 65988 | } |
| 65856 | 65989 | #endif /* SQLITE_OMIT_UTF16 */ |
| 65857 | 65990 | SQLITE_API int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){ |
| 65858 | 65991 | int rc; |
| 65859 | | - switch( pValue->type ){ |
| 65992 | + switch( sqlite3_value_type((sqlite3_value*)pValue) ){ |
| 65860 | 65993 | case SQLITE_INTEGER: { |
| 65861 | 65994 | rc = sqlite3_bind_int64(pStmt, i, pValue->u.i); |
| 65862 | 65995 | break; |
| 65863 | 65996 | } |
| 65864 | 65997 | case SQLITE_FLOAT: { |
| | @@ -66355,37 +66488,12 @@ |
| 66355 | 66488 | ** May you do good and not evil. |
| 66356 | 66489 | ** May you find forgiveness for yourself and forgive others. |
| 66357 | 66490 | ** May you share freely, never taking more than you give. |
| 66358 | 66491 | ** |
| 66359 | 66492 | ************************************************************************* |
| 66360 | | -** The code in this file implements execution method of the |
| 66361 | | -** Virtual Database Engine (VDBE). A separate file ("vdbeaux.c") |
| 66362 | | -** handles housekeeping details such as creating and deleting |
| 66363 | | -** VDBE instances. This file is solely interested in executing |
| 66364 | | -** the VDBE program. |
| 66365 | | -** |
| 66366 | | -** In the external interface, an "sqlite3_stmt*" is an opaque pointer |
| 66367 | | -** to a VDBE. |
| 66368 | | -** |
| 66369 | | -** The SQL parser generates a program which is then executed by |
| 66370 | | -** the VDBE to do the work of the SQL statement. VDBE programs are |
| 66371 | | -** similar in form to assembly language. The program consists of |
| 66372 | | -** a linear sequence of operations. Each operation has an opcode |
| 66373 | | -** and 5 operands. Operands P1, P2, and P3 are integers. Operand P4 |
| 66374 | | -** is a null-terminated string. Operand P5 is an unsigned character. |
| 66375 | | -** Few opcodes use all 5 operands. |
| 66376 | | -** |
| 66377 | | -** Computation results are stored on a set of registers numbered beginning |
| 66378 | | -** with 1 and going up to Vdbe.nMem. Each register can store |
| 66379 | | -** either an integer, a null-terminated string, a floating point |
| 66380 | | -** number, or the SQL "NULL" value. An implicit conversion from one |
| 66381 | | -** type to the other occurs as necessary. |
| 66382 | | -** |
| 66383 | | -** Most of the code in this file is taken up by the sqlite3VdbeExec() |
| 66384 | | -** function which does the work of interpreting a VDBE program. |
| 66385 | | -** But other routines are also provided to help in building up |
| 66386 | | -** a program instruction by instruction. |
| 66493 | +** The code in this file implements the function that runs the |
| 66494 | +** bytecode of a prepared statement. |
| 66387 | 66495 | ** |
| 66388 | 66496 | ** Various scripts scan this source file in order to generate HTML |
| 66389 | 66497 | ** documentation, headers files, or other derived files. The formatting |
| 66390 | 66498 | ** of the code in this file is, therefore, important. See other comments |
| 66391 | 66499 | ** in this file for details. If in doubt, do not deviate from existing |
| | @@ -66393,11 +66501,15 @@ |
| 66393 | 66501 | */ |
| 66394 | 66502 | |
| 66395 | 66503 | /* |
| 66396 | 66504 | ** Invoke this macro on memory cells just prior to changing the |
| 66397 | 66505 | ** value of the cell. This macro verifies that shallow copies are |
| 66398 | | -** not misused. |
| 66506 | +** not misused. A shallow copy of a string or blob just copies a |
| 66507 | +** pointer to the string or blob, not the content. If the original |
| 66508 | +** is changed while the copy is still in use, the string or blob might |
| 66509 | +** be changed out from under the copy. This macro verifies that nothing |
| 66510 | +** like that every happens. |
| 66399 | 66511 | */ |
| 66400 | 66512 | #ifdef SQLITE_DEBUG |
| 66401 | 66513 | # define memAboutToChange(P,M) sqlite3VdbeMemAboutToChange(P,M) |
| 66402 | 66514 | #else |
| 66403 | 66515 | # define memAboutToChange(P,M) |
| | @@ -66452,11 +66564,11 @@ |
| 66452 | 66564 | } |
| 66453 | 66565 | } |
| 66454 | 66566 | #endif |
| 66455 | 66567 | |
| 66456 | 66568 | /* |
| 66457 | | -** The next global variable is incremented each type the OP_Found opcode |
| 66569 | +** The next global variable is incremented each time the OP_Found opcode |
| 66458 | 66570 | ** is executed. This is used to test whether or not the foreign key |
| 66459 | 66571 | ** operation implemented using OP_FkIsZero is working. This variable |
| 66460 | 66572 | ** has no function other than to help verify the correct operation of the |
| 66461 | 66573 | ** library. |
| 66462 | 66574 | */ |
| | @@ -66472,10 +66584,38 @@ |
| 66472 | 66584 | # define UPDATE_MAX_BLOBSIZE(P) updateMaxBlobsize(P) |
| 66473 | 66585 | #else |
| 66474 | 66586 | # define UPDATE_MAX_BLOBSIZE(P) |
| 66475 | 66587 | #endif |
| 66476 | 66588 | |
| 66589 | +/* |
| 66590 | +** Invoke the VDBE coverage callback, if that callback is defined. This |
| 66591 | +** feature is used for test suite validation only and does not appear an |
| 66592 | +** production builds. |
| 66593 | +** |
| 66594 | +** M is an integer, 2 or 3, that indices how many different ways the |
| 66595 | +** branch can go. It is usually 2. "I" is the direction the branch |
| 66596 | +** goes. 0 means falls through. 1 means branch is taken. 2 means the |
| 66597 | +** second alternative branch is taken. |
| 66598 | +*/ |
| 66599 | +#if !defined(SQLITE_VDBE_COVERAGE) |
| 66600 | +# define VdbeBranchTaken(I,M) |
| 66601 | +#else |
| 66602 | +# define VdbeBranchTaken(I,M) vdbeTakeBranch(pOp->iSrcLine,I,M) |
| 66603 | + static void vdbeTakeBranch(int iSrcLine, u8 I, u8 M){ |
| 66604 | + if( iSrcLine<=2 && ALWAYS(iSrcLine>0) ){ |
| 66605 | + M = iSrcLine; |
| 66606 | + /* Assert the truth of VdbeCoverageAlwaysTaken() and |
| 66607 | + ** VdbeCoverageNeverTaken() */ |
| 66608 | + assert( (M & I)==I ); |
| 66609 | + }else{ |
| 66610 | + if( sqlite3GlobalConfig.xVdbeBranch==0 ) return; /*NO_TEST*/ |
| 66611 | + sqlite3GlobalConfig.xVdbeBranch(sqlite3GlobalConfig.pVdbeBranchArg, |
| 66612 | + iSrcLine,I,M); |
| 66613 | + } |
| 66614 | + } |
| 66615 | +#endif |
| 66616 | + |
| 66477 | 66617 | /* |
| 66478 | 66618 | ** Convert the given register into a string if it isn't one |
| 66479 | 66619 | ** already. Return non-zero if a malloc() fails. |
| 66480 | 66620 | */ |
| 66481 | 66621 | #define Stringify(P, enc) \ |
| | @@ -66496,35 +66636,11 @@ |
| 66496 | 66636 | #define Deephemeralize(P) \ |
| 66497 | 66637 | if( ((P)->flags&MEM_Ephem)!=0 \ |
| 66498 | 66638 | && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;} |
| 66499 | 66639 | |
| 66500 | 66640 | /* Return true if the cursor was opened using the OP_OpenSorter opcode. */ |
| 66501 | | -# define isSorter(x) ((x)->pSorter!=0) |
| 66502 | | - |
| 66503 | | -/* |
| 66504 | | -** Argument pMem points at a register that will be passed to a |
| 66505 | | -** user-defined function or returned to the user as the result of a query. |
| 66506 | | -** This routine sets the pMem->type variable used by the sqlite3_value_*() |
| 66507 | | -** routines. |
| 66508 | | -*/ |
| 66509 | | -SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem){ |
| 66510 | | - int flags = pMem->flags; |
| 66511 | | - if( flags & MEM_Null ){ |
| 66512 | | - pMem->type = SQLITE_NULL; |
| 66513 | | - } |
| 66514 | | - else if( flags & MEM_Int ){ |
| 66515 | | - pMem->type = SQLITE_INTEGER; |
| 66516 | | - } |
| 66517 | | - else if( flags & MEM_Real ){ |
| 66518 | | - pMem->type = SQLITE_FLOAT; |
| 66519 | | - } |
| 66520 | | - else if( flags & MEM_Str ){ |
| 66521 | | - pMem->type = SQLITE_TEXT; |
| 66522 | | - }else{ |
| 66523 | | - pMem->type = SQLITE_BLOB; |
| 66524 | | - } |
| 66525 | | -} |
| 66641 | +#define isSorter(x) ((x)->pSorter!=0) |
| 66526 | 66642 | |
| 66527 | 66643 | /* |
| 66528 | 66644 | ** Allocate VdbeCursor number iCur. Return a pointer to it. Return NULL |
| 66529 | 66645 | ** if we run out of memory. |
| 66530 | 66646 | */ |
| | @@ -66650,16 +66766,18 @@ |
| 66650 | 66766 | ** into a numeric representation. Use either INTEGER or REAL whichever |
| 66651 | 66767 | ** is appropriate. But only do the conversion if it is possible without |
| 66652 | 66768 | ** loss of information and return the revised type of the argument. |
| 66653 | 66769 | */ |
| 66654 | 66770 | SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){ |
| 66655 | | - Mem *pMem = (Mem*)pVal; |
| 66656 | | - if( pMem->type==SQLITE_TEXT ){ |
| 66771 | + int eType = sqlite3_value_type(pVal); |
| 66772 | + if( eType==SQLITE_TEXT ){ |
| 66773 | + Mem *pMem = (Mem*)pVal; |
| 66657 | 66774 | applyNumericAffinity(pMem); |
| 66658 | 66775 | sqlite3VdbeMemStoreType(pMem); |
| 66776 | + eType = sqlite3_value_type(pVal); |
| 66659 | 66777 | } |
| 66660 | | - return pMem->type; |
| 66778 | + return eType; |
| 66661 | 66779 | } |
| 66662 | 66780 | |
| 66663 | 66781 | /* |
| 66664 | 66782 | ** Exported version of applyAffinity(). This one works on sqlite3_value*, |
| 66665 | 66783 | ** not the internal Mem* type. |
| | @@ -66758,11 +66876,11 @@ |
| 66758 | 66876 | #ifdef SQLITE_DEBUG |
| 66759 | 66877 | /* |
| 66760 | 66878 | ** Print the value of a register for tracing purposes: |
| 66761 | 66879 | */ |
| 66762 | 66880 | static void memTracePrint(Mem *p){ |
| 66763 | | - if( p->flags & MEM_Invalid ){ |
| 66881 | + if( p->flags & MEM_Undefined ){ |
| 66764 | 66882 | printf(" undefined"); |
| 66765 | 66883 | }else if( p->flags & MEM_Null ){ |
| 66766 | 66884 | printf(" NULL"); |
| 66767 | 66885 | }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){ |
| 66768 | 66886 | printf(" si:%lld", p->u.i); |
| | @@ -66890,24 +67008,10 @@ |
| 66890 | 67008 | |
| 66891 | 67009 | /************** End of hwtime.h **********************************************/ |
| 66892 | 67010 | /************** Continuing where we left off in vdbe.c ***********************/ |
| 66893 | 67011 | |
| 66894 | 67012 | #endif |
| 66895 | | - |
| 66896 | | -/* |
| 66897 | | -** The CHECK_FOR_INTERRUPT macro defined here looks to see if the |
| 66898 | | -** sqlite3_interrupt() routine has been called. If it has been, then |
| 66899 | | -** processing of the VDBE program is interrupted. |
| 66900 | | -** |
| 66901 | | -** This macro added to every instruction that does a jump in order to |
| 66902 | | -** implement a loop. This test used to be on every single instruction, |
| 66903 | | -** but that meant we more testing than we needed. By only testing the |
| 66904 | | -** flag on jump instructions, we get a (small) speed improvement. |
| 66905 | | -*/ |
| 66906 | | -#define CHECK_FOR_INTERRUPT \ |
| 66907 | | - if( db->u1.isInterrupted ) goto abort_due_to_interrupt; |
| 66908 | | - |
| 66909 | 67013 | |
| 66910 | 67014 | #ifndef NDEBUG |
| 66911 | 67015 | /* |
| 66912 | 67016 | ** This function is only called from within an assert() expression. It |
| 66913 | 67017 | ** checks that the sqlite3.nTransaction variable is correctly set to |
| | @@ -66927,39 +67031,12 @@ |
| 66927 | 67031 | } |
| 66928 | 67032 | #endif |
| 66929 | 67033 | |
| 66930 | 67034 | |
| 66931 | 67035 | /* |
| 66932 | | -** Execute as much of a VDBE program as we can then return. |
| 66933 | | -** |
| 66934 | | -** sqlite3VdbeMakeReady() must be called before this routine in order to |
| 66935 | | -** close the program with a final OP_Halt and to set up the callbacks |
| 66936 | | -** and the error message pointer. |
| 66937 | | -** |
| 66938 | | -** Whenever a row or result data is available, this routine will either |
| 66939 | | -** invoke the result callback (if there is one) or return with |
| 66940 | | -** SQLITE_ROW. |
| 66941 | | -** |
| 66942 | | -** If an attempt is made to open a locked database, then this routine |
| 66943 | | -** will either invoke the busy callback (if there is one) or it will |
| 66944 | | -** return SQLITE_BUSY. |
| 66945 | | -** |
| 66946 | | -** If an error occurs, an error message is written to memory obtained |
| 66947 | | -** from sqlite3_malloc() and p->zErrMsg is made to point to that memory. |
| 66948 | | -** The error code is stored in p->rc and this routine returns SQLITE_ERROR. |
| 66949 | | -** |
| 66950 | | -** If the callback ever returns non-zero, then the program exits |
| 66951 | | -** immediately. There will be no error message but the p->rc field is |
| 66952 | | -** set to SQLITE_ABORT and this routine will return SQLITE_ERROR. |
| 66953 | | -** |
| 66954 | | -** A memory allocation error causes p->rc to be set to SQLITE_NOMEM and this |
| 66955 | | -** routine to return SQLITE_ERROR. |
| 66956 | | -** |
| 66957 | | -** Other fatal errors return SQLITE_ERROR. |
| 66958 | | -** |
| 66959 | | -** After this routine has finished, sqlite3VdbeFinalize() should be |
| 66960 | | -** used to clean up the mess that was left behind. |
| 67036 | +** Execute as much of a VDBE program as we can. |
| 67037 | +** This is the core of sqlite3_step(). |
| 66961 | 67038 | */ |
| 66962 | 67039 | SQLITE_PRIVATE int sqlite3VdbeExec( |
| 66963 | 67040 | Vdbe *p /* The VDBE */ |
| 66964 | 67041 | ){ |
| 66965 | 67042 | int pc=0; /* The program counter */ |
| | @@ -66981,11 +67058,10 @@ |
| 66981 | 67058 | Mem *pOut = 0; /* Output operand */ |
| 66982 | 67059 | int *aPermute = 0; /* Permutation of columns for OP_Compare */ |
| 66983 | 67060 | i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */ |
| 66984 | 67061 | #ifdef VDBE_PROFILE |
| 66985 | 67062 | u64 start; /* CPU clock count at start of opcode */ |
| 66986 | | - int origPc; /* Program counter at start of opcode */ |
| 66987 | 67063 | #endif |
| 66988 | 67064 | /*** INSERT STACK UNION HERE ***/ |
| 66989 | 67065 | |
| 66990 | 67066 | assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */ |
| 66991 | 67067 | sqlite3VdbeEnter(p); |
| | @@ -66999,11 +67075,11 @@ |
| 66999 | 67075 | p->rc = SQLITE_OK; |
| 67000 | 67076 | p->iCurrentTime = 0; |
| 67001 | 67077 | assert( p->explain==0 ); |
| 67002 | 67078 | p->pResultSet = 0; |
| 67003 | 67079 | db->busyHandler.nBusy = 0; |
| 67004 | | - CHECK_FOR_INTERRUPT; |
| 67080 | + if( db->u1.isInterrupted ) goto abort_due_to_interrupt; |
| 67005 | 67081 | sqlite3VdbeIOTraceSql(p); |
| 67006 | 67082 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 67007 | 67083 | if( db->xProgress ){ |
| 67008 | 67084 | assert( 0 < db->nProgressOps ); |
| 67009 | 67085 | nProgressLimit = (unsigned)p->aCounter[SQLITE_STMTSTATUS_VM_STEP]; |
| | @@ -67043,11 +67119,10 @@ |
| 67043 | 67119 | #endif |
| 67044 | 67120 | for(pc=p->pc; rc==SQLITE_OK; pc++){ |
| 67045 | 67121 | assert( pc>=0 && pc<p->nOp ); |
| 67046 | 67122 | if( db->mallocFailed ) goto no_mem; |
| 67047 | 67123 | #ifdef VDBE_PROFILE |
| 67048 | | - origPc = pc; |
| 67049 | 67124 | start = sqlite3Hwtime(); |
| 67050 | 67125 | #endif |
| 67051 | 67126 | nVmStep++; |
| 67052 | 67127 | pOp = &aOp[pc]; |
| 67053 | 67128 | |
| | @@ -67175,11 +67250,11 @@ |
| 67175 | 67250 | ** But that is not due to sloppy coding habits. The code is written this |
| 67176 | 67251 | ** way for performance, to avoid having to run the interrupt and progress |
| 67177 | 67252 | ** checks on every opcode. This helps sqlite3_step() to run about 1.5% |
| 67178 | 67253 | ** faster according to "valgrind --tool=cachegrind" */ |
| 67179 | 67254 | check_for_interrupt: |
| 67180 | | - CHECK_FOR_INTERRUPT; |
| 67255 | + if( db->u1.isInterrupted ) goto abort_due_to_interrupt; |
| 67181 | 67256 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 67182 | 67257 | /* Call the progress callback if it is configured and the required number |
| 67183 | 67258 | ** of VDBE ops have been executed (either since this invocation of |
| 67184 | 67259 | ** sqlite3VdbeExec() or since last time the progress callback was called). |
| 67185 | 67260 | ** If the progress callback returns non-zero, exit the virtual machine with |
| | @@ -67215,24 +67290,70 @@ |
| 67215 | 67290 | break; |
| 67216 | 67291 | } |
| 67217 | 67292 | |
| 67218 | 67293 | /* Opcode: Return P1 * * * * |
| 67219 | 67294 | ** |
| 67220 | | -** Jump to the next instruction after the address in register P1. |
| 67295 | +** Jump to the next instruction after the address in register P1. After |
| 67296 | +** the jump, register P1 becomes undefined. |
| 67221 | 67297 | */ |
| 67222 | 67298 | case OP_Return: { /* in1 */ |
| 67223 | 67299 | pIn1 = &aMem[pOp->p1]; |
| 67224 | | - assert( pIn1->flags & MEM_Int ); |
| 67300 | + assert( pIn1->flags==MEM_Int ); |
| 67225 | 67301 | pc = (int)pIn1->u.i; |
| 67302 | + pIn1->flags = MEM_Undefined; |
| 67226 | 67303 | break; |
| 67227 | 67304 | } |
| 67228 | 67305 | |
| 67229 | | -/* Opcode: Yield P1 * * * * |
| 67306 | +/* Opcode: InitCoroutine P1 P2 P3 * * |
| 67307 | +** |
| 67308 | +** Set up register P1 so that it will OP_Yield to the co-routine |
| 67309 | +** located at address P3. |
| 67310 | +** |
| 67311 | +** If P2!=0 then the co-routine implementation immediately follows |
| 67312 | +** this opcode. So jump over the co-routine implementation to |
| 67313 | +** address P2. |
| 67314 | +*/ |
| 67315 | +case OP_InitCoroutine: { /* jump */ |
| 67316 | + assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) ); |
| 67317 | + assert( pOp->p2>=0 && pOp->p2<p->nOp ); |
| 67318 | + assert( pOp->p3>=0 && pOp->p3<p->nOp ); |
| 67319 | + pOut = &aMem[pOp->p1]; |
| 67320 | + assert( !VdbeMemDynamic(pOut) ); |
| 67321 | + pOut->u.i = pOp->p3 - 1; |
| 67322 | + pOut->flags = MEM_Int; |
| 67323 | + if( pOp->p2 ) pc = pOp->p2 - 1; |
| 67324 | + break; |
| 67325 | +} |
| 67326 | + |
| 67327 | +/* Opcode: EndCoroutine P1 * * * * |
| 67328 | +** |
| 67329 | +** The instruction at the address in register P1 is an OP_Yield. |
| 67330 | +** Jump to the P2 parameter of that OP_Yield. |
| 67331 | +** After the jump, register P1 becomes undefined. |
| 67332 | +*/ |
| 67333 | +case OP_EndCoroutine: { /* in1 */ |
| 67334 | + VdbeOp *pCaller; |
| 67335 | + pIn1 = &aMem[pOp->p1]; |
| 67336 | + assert( pIn1->flags==MEM_Int ); |
| 67337 | + assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp ); |
| 67338 | + pCaller = &aOp[pIn1->u.i]; |
| 67339 | + assert( pCaller->opcode==OP_Yield ); |
| 67340 | + assert( pCaller->p2>=0 && pCaller->p2<p->nOp ); |
| 67341 | + pc = pCaller->p2 - 1; |
| 67342 | + pIn1->flags = MEM_Undefined; |
| 67343 | + break; |
| 67344 | +} |
| 67345 | + |
| 67346 | +/* Opcode: Yield P1 P2 * * * |
| 67230 | 67347 | ** |
| 67231 | 67348 | ** Swap the program counter with the value in register P1. |
| 67349 | +** |
| 67350 | +** If the co-routine ends with OP_Yield or OP_Return then continue |
| 67351 | +** to the next instruction. But if the co-routine ends with |
| 67352 | +** OP_EndCoroutine, jump immediately to P2. |
| 67232 | 67353 | */ |
| 67233 | | -case OP_Yield: { /* in1 */ |
| 67354 | +case OP_Yield: { /* in1, jump */ |
| 67234 | 67355 | int pcDest; |
| 67235 | 67356 | pIn1 = &aMem[pOp->p1]; |
| 67236 | 67357 | assert( (pIn1->flags & MEM_Dyn)==0 ); |
| 67237 | 67358 | pIn1->flags = MEM_Int; |
| 67238 | 67359 | pcDest = (int)pIn1->u.i; |
| | @@ -67241,11 +67362,11 @@ |
| 67241 | 67362 | pc = pcDest; |
| 67242 | 67363 | break; |
| 67243 | 67364 | } |
| 67244 | 67365 | |
| 67245 | 67366 | /* Opcode: HaltIfNull P1 P2 P3 P4 P5 |
| 67246 | | -** Synopsis: if r[P3] null then halt |
| 67367 | +** Synopsis: if r[P3]=null halt |
| 67247 | 67368 | ** |
| 67248 | 67369 | ** Check the value in register P3. If it is NULL then Halt using |
| 67249 | 67370 | ** parameter P1, P2, and P4 as if this were a Halt instruction. If the |
| 67250 | 67371 | ** value in register P3 is not NULL, then this routine is a no-op. |
| 67251 | 67372 | ** The P5 parameter should be 1. |
| | @@ -67389,11 +67510,13 @@ |
| 67389 | 67510 | |
| 67390 | 67511 | /* Opcode: String8 * P2 * P4 * |
| 67391 | 67512 | ** Synopsis: r[P2]='P4' |
| 67392 | 67513 | ** |
| 67393 | 67514 | ** P4 points to a nul terminated UTF-8 string. This opcode is transformed |
| 67394 | | -** into an OP_String before it is executed for the first time. |
| 67515 | +** into an OP_String before it is executed for the first time. During |
| 67516 | +** this transformation, the length of string P4 is computed and stored |
| 67517 | +** as the P1 parameter. |
| 67395 | 67518 | */ |
| 67396 | 67519 | case OP_String8: { /* same as TK_STRING, out2-prerelease */ |
| 67397 | 67520 | assert( pOp->p4.z!=0 ); |
| 67398 | 67521 | pOp->opcode = OP_String; |
| 67399 | 67522 | pOp->p1 = sqlite3Strlen30(pOp->p4.z); |
| | @@ -67463,12 +67586,26 @@ |
| 67463 | 67586 | cnt--; |
| 67464 | 67587 | } |
| 67465 | 67588 | break; |
| 67466 | 67589 | } |
| 67467 | 67590 | |
| 67591 | +/* Opcode: SoftNull P1 * * * * |
| 67592 | +** Synopsis: r[P1]=NULL |
| 67593 | +** |
| 67594 | +** Set register P1 to have the value NULL as seen by the OP_MakeRecord |
| 67595 | +** instruction, but do not free any string or blob memory associated with |
| 67596 | +** the register, so that if the value was a string or blob that was |
| 67597 | +** previously copied using OP_SCopy, the copies will continue to be valid. |
| 67598 | +*/ |
| 67599 | +case OP_SoftNull: { |
| 67600 | + assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) ); |
| 67601 | + pOut = &aMem[pOp->p1]; |
| 67602 | + pOut->flags = (pOut->flags|MEM_Null)&~MEM_Undefined; |
| 67603 | + break; |
| 67604 | +} |
| 67468 | 67605 | |
| 67469 | | -/* Opcode: Blob P1 P2 * P4 |
| 67606 | +/* Opcode: Blob P1 P2 * P4 * |
| 67470 | 67607 | ** Synopsis: r[P2]=P4 (len=P1) |
| 67471 | 67608 | ** |
| 67472 | 67609 | ** P4 points to a blob of data P1 bytes long. Store this |
| 67473 | 67610 | ** blob in register P2. |
| 67474 | 67611 | */ |
| | @@ -67483,11 +67620,11 @@ |
| 67483 | 67620 | /* Opcode: Variable P1 P2 * P4 * |
| 67484 | 67621 | ** Synopsis: r[P2]=parameter(P1,P4) |
| 67485 | 67622 | ** |
| 67486 | 67623 | ** Transfer the values of bound parameter P1 into register P2 |
| 67487 | 67624 | ** |
| 67488 | | -** If the parameter is named, then its name appears in P4 and P3==1. |
| 67625 | +** If the parameter is named, then its name appears in P4. |
| 67489 | 67626 | ** The P4 value is used by sqlite3_bind_parameter_name(). |
| 67490 | 67627 | */ |
| 67491 | 67628 | case OP_Variable: { /* out2-prerelease */ |
| 67492 | 67629 | Mem *pVar; /* Value being transferred */ |
| 67493 | 67630 | |
| | @@ -67602,12 +67739,12 @@ |
| 67602 | 67739 | ** Synopsis: output=r[P1@P2] |
| 67603 | 67740 | ** |
| 67604 | 67741 | ** The registers P1 through P1+P2-1 contain a single row of |
| 67605 | 67742 | ** results. This opcode causes the sqlite3_step() call to terminate |
| 67606 | 67743 | ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt |
| 67607 | | -** structure to provide access to the top P1 values as the result |
| 67608 | | -** row. |
| 67744 | +** structure to provide access to the r(P1)..r(P1+P2-1) values as |
| 67745 | +** the result row. |
| 67609 | 67746 | */ |
| 67610 | 67747 | case OP_ResultRow: { |
| 67611 | 67748 | Mem *pMem; |
| 67612 | 67749 | int i; |
| 67613 | 67750 | assert( p->nResColumn==pOp->p2 ); |
| | @@ -68093,10 +68230,11 @@ |
| 68093 | 68230 | */ |
| 68094 | 68231 | case OP_MustBeInt: { /* jump, in1 */ |
| 68095 | 68232 | pIn1 = &aMem[pOp->p1]; |
| 68096 | 68233 | if( (pIn1->flags & MEM_Int)==0 ){ |
| 68097 | 68234 | applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding); |
| 68235 | + VdbeBranchTaken((pIn1->flags&MEM_Int)==0, 2); |
| 68098 | 68236 | if( (pIn1->flags & MEM_Int)==0 ){ |
| 68099 | 68237 | if( pOp->p2==0 ){ |
| 68100 | 68238 | rc = SQLITE_MISMATCH; |
| 68101 | 68239 | goto abort_due_to_error; |
| 68102 | 68240 | }else{ |
| | @@ -68131,11 +68269,11 @@ |
| 68131 | 68269 | #ifndef SQLITE_OMIT_CAST |
| 68132 | 68270 | /* Opcode: ToText P1 * * * * |
| 68133 | 68271 | ** |
| 68134 | 68272 | ** Force the value in register P1 to be text. |
| 68135 | 68273 | ** If the value is numeric, convert it to a string using the |
| 68136 | | -** equivalent of printf(). Blob values are unchanged and |
| 68274 | +** equivalent of sprintf(). Blob values are unchanged and |
| 68137 | 68275 | ** are afterwards simply interpreted as text. |
| 68138 | 68276 | ** |
| 68139 | 68277 | ** A NULL value is not changed by this routine. It remains NULL. |
| 68140 | 68278 | */ |
| 68141 | 68279 | case OP_ToText: { /* same as TK_TO_TEXT, in1 */ |
| | @@ -68333,10 +68471,11 @@ |
| 68333 | 68471 | ** OP_Eq or OP_Ne) then take the jump or not depending on whether |
| 68334 | 68472 | ** or not both operands are null. |
| 68335 | 68473 | */ |
| 68336 | 68474 | assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne ); |
| 68337 | 68475 | assert( (flags1 & MEM_Cleared)==0 ); |
| 68476 | + assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 ); |
| 68338 | 68477 | if( (flags1&MEM_Null)!=0 |
| 68339 | 68478 | && (flags3&MEM_Null)!=0 |
| 68340 | 68479 | && (flags3&MEM_Cleared)==0 |
| 68341 | 68480 | ){ |
| 68342 | 68481 | res = 0; /* Results are equal */ |
| | @@ -68346,16 +68485,19 @@ |
| 68346 | 68485 | }else{ |
| 68347 | 68486 | /* SQLITE_NULLEQ is clear and at least one operand is NULL, |
| 68348 | 68487 | ** then the result is always NULL. |
| 68349 | 68488 | ** The jump is taken if the SQLITE_JUMPIFNULL bit is set. |
| 68350 | 68489 | */ |
| 68351 | | - if( pOp->p5 & SQLITE_JUMPIFNULL ){ |
| 68352 | | - pc = pOp->p2-1; |
| 68353 | | - }else if( pOp->p5 & SQLITE_STOREP2 ){ |
| 68490 | + if( pOp->p5 & SQLITE_STOREP2 ){ |
| 68354 | 68491 | pOut = &aMem[pOp->p2]; |
| 68355 | 68492 | MemSetTypeFlag(pOut, MEM_Null); |
| 68356 | 68493 | REGISTER_TRACE(pOp->p2, pOut); |
| 68494 | + }else{ |
| 68495 | + VdbeBranchTaken(2,3); |
| 68496 | + if( pOp->p5 & SQLITE_JUMPIFNULL ){ |
| 68497 | + pc = pOp->p2-1; |
| 68498 | + } |
| 68357 | 68499 | } |
| 68358 | 68500 | break; |
| 68359 | 68501 | } |
| 68360 | 68502 | }else{ |
| 68361 | 68503 | /* Neither operand is NULL. Do a comparison. */ |
| | @@ -68384,14 +68526,16 @@ |
| 68384 | 68526 | pOut = &aMem[pOp->p2]; |
| 68385 | 68527 | memAboutToChange(p, pOut); |
| 68386 | 68528 | MemSetTypeFlag(pOut, MEM_Int); |
| 68387 | 68529 | pOut->u.i = res; |
| 68388 | 68530 | REGISTER_TRACE(pOp->p2, pOut); |
| 68389 | | - }else if( res ){ |
| 68390 | | - pc = pOp->p2-1; |
| 68531 | + }else{ |
| 68532 | + VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3); |
| 68533 | + if( res ){ |
| 68534 | + pc = pOp->p2-1; |
| 68535 | + } |
| 68391 | 68536 | } |
| 68392 | | - |
| 68393 | 68537 | /* Undo any changes made by applyAffinity() to the input registers. */ |
| 68394 | 68538 | pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask); |
| 68395 | 68539 | pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask); |
| 68396 | 68540 | break; |
| 68397 | 68541 | } |
| | @@ -68484,15 +68628,15 @@ |
| 68484 | 68628 | ** in the most recent OP_Compare instruction the P1 vector was less than |
| 68485 | 68629 | ** equal to, or greater than the P2 vector, respectively. |
| 68486 | 68630 | */ |
| 68487 | 68631 | case OP_Jump: { /* jump */ |
| 68488 | 68632 | if( iCompare<0 ){ |
| 68489 | | - pc = pOp->p1 - 1; |
| 68633 | + pc = pOp->p1 - 1; VdbeBranchTaken(0,3); |
| 68490 | 68634 | }else if( iCompare==0 ){ |
| 68491 | | - pc = pOp->p2 - 1; |
| 68635 | + pc = pOp->p2 - 1; VdbeBranchTaken(1,3); |
| 68492 | 68636 | }else{ |
| 68493 | | - pc = pOp->p3 - 1; |
| 68637 | + pc = pOp->p3 - 1; VdbeBranchTaken(2,3); |
| 68494 | 68638 | } |
| 68495 | 68639 | break; |
| 68496 | 68640 | } |
| 68497 | 68641 | |
| 68498 | 68642 | /* Opcode: And P1 P2 P3 * * |
| | @@ -68586,14 +68730,17 @@ |
| 68586 | 68730 | } |
| 68587 | 68731 | |
| 68588 | 68732 | /* Opcode: Once P1 P2 * * * |
| 68589 | 68733 | ** |
| 68590 | 68734 | ** Check if OP_Once flag P1 is set. If so, jump to instruction P2. Otherwise, |
| 68591 | | -** set the flag and fall through to the next instruction. |
| 68735 | +** set the flag and fall through to the next instruction. In other words, |
| 68736 | +** this opcode causes all following up codes up through P2 (but not including |
| 68737 | +** P2) to run just once and skipped on subsequent times through the loop. |
| 68592 | 68738 | */ |
| 68593 | 68739 | case OP_Once: { /* jump */ |
| 68594 | 68740 | assert( pOp->p1<p->nOnceFlag ); |
| 68741 | + VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2); |
| 68595 | 68742 | if( p->aOnceFlag[pOp->p1] ){ |
| 68596 | 68743 | pc = pOp->p2-1; |
| 68597 | 68744 | }else{ |
| 68598 | 68745 | p->aOnceFlag[pOp->p1] = 1; |
| 68599 | 68746 | } |
| | @@ -68624,10 +68771,11 @@ |
| 68624 | 68771 | #else |
| 68625 | 68772 | c = sqlite3VdbeRealValue(pIn1)!=0.0; |
| 68626 | 68773 | #endif |
| 68627 | 68774 | if( pOp->opcode==OP_IfNot ) c = !c; |
| 68628 | 68775 | } |
| 68776 | + VdbeBranchTaken(c!=0, 2); |
| 68629 | 68777 | if( c ){ |
| 68630 | 68778 | pc = pOp->p2-1; |
| 68631 | 68779 | } |
| 68632 | 68780 | break; |
| 68633 | 68781 | } |
| | @@ -68637,10 +68785,11 @@ |
| 68637 | 68785 | ** |
| 68638 | 68786 | ** Jump to P2 if the value in register P1 is NULL. |
| 68639 | 68787 | */ |
| 68640 | 68788 | case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */ |
| 68641 | 68789 | pIn1 = &aMem[pOp->p1]; |
| 68790 | + VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2); |
| 68642 | 68791 | if( (pIn1->flags & MEM_Null)!=0 ){ |
| 68643 | 68792 | pc = pOp->p2 - 1; |
| 68644 | 68793 | } |
| 68645 | 68794 | break; |
| 68646 | 68795 | } |
| | @@ -68650,10 +68799,11 @@ |
| 68650 | 68799 | ** |
| 68651 | 68800 | ** Jump to P2 if the value in register P1 is not NULL. |
| 68652 | 68801 | */ |
| 68653 | 68802 | case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */ |
| 68654 | 68803 | pIn1 = &aMem[pOp->p1]; |
| 68804 | + VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2); |
| 68655 | 68805 | if( (pIn1->flags & MEM_Null)==0 ){ |
| 68656 | 68806 | pc = pOp->p2 - 1; |
| 68657 | 68807 | } |
| 68658 | 68808 | break; |
| 68659 | 68809 | } |
| | @@ -68726,15 +68876,10 @@ |
| 68726 | 68876 | if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){ |
| 68727 | 68877 | if( pC->nullRow ){ |
| 68728 | 68878 | if( pCrsr==0 ){ |
| 68729 | 68879 | assert( pC->pseudoTableReg>0 ); |
| 68730 | 68880 | pReg = &aMem[pC->pseudoTableReg]; |
| 68731 | | - if( pC->multiPseudo ){ |
| 68732 | | - sqlite3VdbeMemShallowCopy(pDest, pReg+p2, MEM_Ephem); |
| 68733 | | - Deephemeralize(pDest); |
| 68734 | | - goto op_column_out; |
| 68735 | | - } |
| 68736 | 68881 | assert( pReg->flags & MEM_Blob ); |
| 68737 | 68882 | assert( memIsValid(pReg) ); |
| 68738 | 68883 | pC->payloadSize = pC->szRow = avail = pReg->n; |
| 68739 | 68884 | pC->aRow = (u8*)pReg->z; |
| 68740 | 68885 | }else{ |
| | @@ -68956,11 +69101,10 @@ |
| 68956 | 69101 | assert( zAffinity[pOp->p2]==0 ); |
| 68957 | 69102 | pIn1 = &aMem[pOp->p1]; |
| 68958 | 69103 | while( (cAff = *(zAffinity++))!=0 ){ |
| 68959 | 69104 | assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] ); |
| 68960 | 69105 | assert( memIsValid(pIn1) ); |
| 68961 | | - ExpandBlob(pIn1); |
| 68962 | 69106 | applyAffinity(pIn1, cAff, encoding); |
| 68963 | 69107 | pIn1++; |
| 68964 | 69108 | } |
| 68965 | 69109 | break; |
| 68966 | 69110 | } |
| | @@ -69034,12 +69178,13 @@ |
| 69034 | 69178 | */ |
| 69035 | 69179 | assert( pData0<=pLast ); |
| 69036 | 69180 | if( zAffinity ){ |
| 69037 | 69181 | pRec = pData0; |
| 69038 | 69182 | do{ |
| 69039 | | - applyAffinity(pRec, *(zAffinity++), encoding); |
| 69040 | | - }while( (++pRec)<=pLast ); |
| 69183 | + applyAffinity(pRec++, *(zAffinity++), encoding); |
| 69184 | + assert( zAffinity[0]==0 || pRec<=pLast ); |
| 69185 | + }while( zAffinity[0] ); |
| 69041 | 69186 | } |
| 69042 | 69187 | |
| 69043 | 69188 | /* Loop through the elements that will make up the record to figure |
| 69044 | 69189 | ** out how much space is required for the new record. |
| 69045 | 69190 | */ |
| | @@ -69379,29 +69524,23 @@ |
| 69379 | 69524 | rc = SQLITE_ERROR; |
| 69380 | 69525 | } |
| 69381 | 69526 | break; |
| 69382 | 69527 | } |
| 69383 | 69528 | |
| 69384 | | -/* Opcode: Transaction P1 P2 * * * |
| 69529 | +/* Opcode: Transaction P1 P2 P3 P4 P5 |
| 69385 | 69530 | ** |
| 69386 | | -** Begin a transaction. The transaction ends when a Commit or Rollback |
| 69387 | | -** opcode is encountered. Depending on the ON CONFLICT setting, the |
| 69388 | | -** transaction might also be rolled back if an error is encountered. |
| 69531 | +** Begin a transaction on database P1 if a transaction is not already |
| 69532 | +** active. |
| 69533 | +** If P2 is non-zero, then a write-transaction is started, or if a |
| 69534 | +** read-transaction is already active, it is upgraded to a write-transaction. |
| 69535 | +** If P2 is zero, then a read-transaction is started. |
| 69389 | 69536 | ** |
| 69390 | 69537 | ** P1 is the index of the database file on which the transaction is |
| 69391 | 69538 | ** started. Index 0 is the main database file and index 1 is the |
| 69392 | 69539 | ** file used for temporary tables. Indices of 2 or more are used for |
| 69393 | 69540 | ** attached databases. |
| 69394 | 69541 | ** |
| 69395 | | -** If P2 is non-zero, then a write-transaction is started. A RESERVED lock is |
| 69396 | | -** obtained on the database file when a write-transaction is started. No |
| 69397 | | -** other process can start another write transaction while this transaction is |
| 69398 | | -** underway. Starting a write transaction also creates a rollback journal. A |
| 69399 | | -** write transaction must be started before any changes can be made to the |
| 69400 | | -** database. If P2 is greater than or equal to 2 then an EXCLUSIVE lock is |
| 69401 | | -** also obtained on the file. |
| 69402 | | -** |
| 69403 | 69542 | ** If a write-transaction is started and the Vdbe.usesStmtJournal flag is |
| 69404 | 69543 | ** true (this flag is set if the Vdbe may modify more than one row and may |
| 69405 | 69544 | ** throw an ABORT exception), a statement transaction may also be opened. |
| 69406 | 69545 | ** More specifically, a statement transaction is opened iff the database |
| 69407 | 69546 | ** connection is currently not in autocommit mode, or if there are other |
| | @@ -69408,14 +69547,25 @@ |
| 69408 | 69547 | ** active statements. A statement transaction allows the changes made by this |
| 69409 | 69548 | ** VDBE to be rolled back after an error without having to roll back the |
| 69410 | 69549 | ** entire transaction. If no error is encountered, the statement transaction |
| 69411 | 69550 | ** will automatically commit when the VDBE halts. |
| 69412 | 69551 | ** |
| 69413 | | -** If P2 is zero, then a read-lock is obtained on the database file. |
| 69552 | +** If P5!=0 then this opcode also checks the schema cookie against P3 |
| 69553 | +** and the schema generation counter against P4. |
| 69554 | +** The cookie changes its value whenever the database schema changes. |
| 69555 | +** This operation is used to detect when that the cookie has changed |
| 69556 | +** and that the current process needs to reread the schema. If the schema |
| 69557 | +** cookie in P3 differs from the schema cookie in the database header or |
| 69558 | +** if the schema generation counter in P4 differs from the current |
| 69559 | +** generation counter, then an SQLITE_SCHEMA error is raised and execution |
| 69560 | +** halts. The sqlite3_step() wrapper function might then reprepare the |
| 69561 | +** statement and rerun it from the beginning. |
| 69414 | 69562 | */ |
| 69415 | 69563 | case OP_Transaction: { |
| 69416 | 69564 | Btree *pBt; |
| 69565 | + int iMeta; |
| 69566 | + int iGen; |
| 69417 | 69567 | |
| 69418 | 69568 | assert( p->bIsReader ); |
| 69419 | 69569 | assert( p->readOnly==0 || pOp->p2==0 ); |
| 69420 | 69570 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 69421 | 69571 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| | @@ -69455,10 +69605,39 @@ |
| 69455 | 69605 | ** counter. If the statement transaction needs to be rolled back, |
| 69456 | 69606 | ** the value of this counter needs to be restored too. */ |
| 69457 | 69607 | p->nStmtDefCons = db->nDeferredCons; |
| 69458 | 69608 | p->nStmtDefImmCons = db->nDeferredImmCons; |
| 69459 | 69609 | } |
| 69610 | + |
| 69611 | + /* Gather the schema version number for checking */ |
| 69612 | + sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta); |
| 69613 | + iGen = db->aDb[pOp->p1].pSchema->iGeneration; |
| 69614 | + }else{ |
| 69615 | + iGen = iMeta = 0; |
| 69616 | + } |
| 69617 | + assert( pOp->p5==0 || pOp->p4type==P4_INT32 ); |
| 69618 | + if( pOp->p5 && (iMeta!=pOp->p3 || iGen!=pOp->p4.i) ){ |
| 69619 | + sqlite3DbFree(db, p->zErrMsg); |
| 69620 | + p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed"); |
| 69621 | + /* If the schema-cookie from the database file matches the cookie |
| 69622 | + ** stored with the in-memory representation of the schema, do |
| 69623 | + ** not reload the schema from the database file. |
| 69624 | + ** |
| 69625 | + ** If virtual-tables are in use, this is not just an optimization. |
| 69626 | + ** Often, v-tables store their data in other SQLite tables, which |
| 69627 | + ** are queried from within xNext() and other v-table methods using |
| 69628 | + ** prepared queries. If such a query is out-of-date, we do not want to |
| 69629 | + ** discard the database schema, as the user code implementing the |
| 69630 | + ** v-table would have to be ready for the sqlite3_vtab structure itself |
| 69631 | + ** to be invalidated whenever sqlite3_step() is called from within |
| 69632 | + ** a v-table method. |
| 69633 | + */ |
| 69634 | + if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){ |
| 69635 | + sqlite3ResetOneSchema(db, pOp->p1); |
| 69636 | + } |
| 69637 | + p->expired = 1; |
| 69638 | + rc = SQLITE_SCHEMA; |
| 69460 | 69639 | } |
| 69461 | 69640 | break; |
| 69462 | 69641 | } |
| 69463 | 69642 | |
| 69464 | 69643 | /* Opcode: ReadCookie P1 P2 P3 * * |
| | @@ -69526,70 +69705,10 @@ |
| 69526 | 69705 | /* Invalidate all prepared statements whenever the TEMP database |
| 69527 | 69706 | ** schema is changed. Ticket #1644 */ |
| 69528 | 69707 | sqlite3ExpirePreparedStatements(db); |
| 69529 | 69708 | p->expired = 0; |
| 69530 | 69709 | } |
| 69531 | | - break; |
| 69532 | | -} |
| 69533 | | - |
| 69534 | | -/* Opcode: VerifyCookie P1 P2 P3 * * |
| 69535 | | -** |
| 69536 | | -** Check the value of global database parameter number 0 (the |
| 69537 | | -** schema version) and make sure it is equal to P2 and that the |
| 69538 | | -** generation counter on the local schema parse equals P3. |
| 69539 | | -** |
| 69540 | | -** P1 is the database number which is 0 for the main database file |
| 69541 | | -** and 1 for the file holding temporary tables and some higher number |
| 69542 | | -** for auxiliary databases. |
| 69543 | | -** |
| 69544 | | -** The cookie changes its value whenever the database schema changes. |
| 69545 | | -** This operation is used to detect when that the cookie has changed |
| 69546 | | -** and that the current process needs to reread the schema. |
| 69547 | | -** |
| 69548 | | -** Either a transaction needs to have been started or an OP_Open needs |
| 69549 | | -** to be executed (to establish a read lock) before this opcode is |
| 69550 | | -** invoked. |
| 69551 | | -*/ |
| 69552 | | -case OP_VerifyCookie: { |
| 69553 | | - int iMeta; |
| 69554 | | - int iGen; |
| 69555 | | - Btree *pBt; |
| 69556 | | - |
| 69557 | | - assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 69558 | | - assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 69559 | | - assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) ); |
| 69560 | | - assert( p->bIsReader ); |
| 69561 | | - pBt = db->aDb[pOp->p1].pBt; |
| 69562 | | - if( pBt ){ |
| 69563 | | - sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta); |
| 69564 | | - iGen = db->aDb[pOp->p1].pSchema->iGeneration; |
| 69565 | | - }else{ |
| 69566 | | - iGen = iMeta = 0; |
| 69567 | | - } |
| 69568 | | - if( iMeta!=pOp->p2 || iGen!=pOp->p3 ){ |
| 69569 | | - sqlite3DbFree(db, p->zErrMsg); |
| 69570 | | - p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed"); |
| 69571 | | - /* If the schema-cookie from the database file matches the cookie |
| 69572 | | - ** stored with the in-memory representation of the schema, do |
| 69573 | | - ** not reload the schema from the database file. |
| 69574 | | - ** |
| 69575 | | - ** If virtual-tables are in use, this is not just an optimization. |
| 69576 | | - ** Often, v-tables store their data in other SQLite tables, which |
| 69577 | | - ** are queried from within xNext() and other v-table methods using |
| 69578 | | - ** prepared queries. If such a query is out-of-date, we do not want to |
| 69579 | | - ** discard the database schema, as the user code implementing the |
| 69580 | | - ** v-table would have to be ready for the sqlite3_vtab structure itself |
| 69581 | | - ** to be invalidated whenever sqlite3_step() is called from within |
| 69582 | | - ** a v-table method. |
| 69583 | | - */ |
| 69584 | | - if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){ |
| 69585 | | - sqlite3ResetOneSchema(db, pOp->p1); |
| 69586 | | - } |
| 69587 | | - |
| 69588 | | - p->expired = 1; |
| 69589 | | - rc = SQLITE_SCHEMA; |
| 69590 | | - } |
| 69591 | 69710 | break; |
| 69592 | 69711 | } |
| 69593 | 69712 | |
| 69594 | 69713 | /* Opcode: OpenRead P1 P2 P3 P4 P5 |
| 69595 | 69714 | ** Synopsis: root=P2 iDb=P3 |
| | @@ -69802,11 +69921,11 @@ |
| 69802 | 69921 | } |
| 69803 | 69922 | pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED); |
| 69804 | 69923 | break; |
| 69805 | 69924 | } |
| 69806 | 69925 | |
| 69807 | | -/* Opcode: SorterOpen P1 * * P4 * |
| 69926 | +/* Opcode: SorterOpen P1 P2 * P4 * |
| 69808 | 69927 | ** |
| 69809 | 69928 | ** This opcode works like OP_OpenEphemeral except that it opens |
| 69810 | 69929 | ** a transient index that is specifically designed to sort large |
| 69811 | 69930 | ** tables using an external merge-sort algorithm. |
| 69812 | 69931 | */ |
| | @@ -69822,18 +69941,17 @@ |
| 69822 | 69941 | assert( pCx->pKeyInfo->enc==ENC(db) ); |
| 69823 | 69942 | rc = sqlite3VdbeSorterInit(db, pCx); |
| 69824 | 69943 | break; |
| 69825 | 69944 | } |
| 69826 | 69945 | |
| 69827 | | -/* Opcode: OpenPseudo P1 P2 P3 * P5 |
| 69828 | | -** Synopsis: content in r[P2@P3] |
| 69946 | +/* Opcode: OpenPseudo P1 P2 P3 * * |
| 69947 | +** Synopsis: P3 columns in r[P2] |
| 69829 | 69948 | ** |
| 69830 | 69949 | ** Open a new cursor that points to a fake table that contains a single |
| 69831 | | -** row of data. The content of that one row in the content of memory |
| 69832 | | -** register P2 when P5==0. In other words, cursor P1 becomes an alias for the |
| 69833 | | -** MEM_Blob content contained in register P2. When P5==1, then the |
| 69834 | | -** row is represented by P3 consecutive registers beginning with P2. |
| 69950 | +** row of data. The content of that one row is the content of memory |
| 69951 | +** register P2. In other words, cursor P1 becomes an alias for the |
| 69952 | +** MEM_Blob content contained in register P2. |
| 69835 | 69953 | ** |
| 69836 | 69954 | ** A pseudo-table created by this opcode is used to hold a single |
| 69837 | 69955 | ** row output from the sorter so that the row can be decomposed into |
| 69838 | 69956 | ** individual columns using the OP_Column opcode. The OP_Column opcode |
| 69839 | 69957 | ** is the only cursor opcode that works with a pseudo-table. |
| | @@ -69849,11 +69967,11 @@ |
| 69849 | 69967 | pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0); |
| 69850 | 69968 | if( pCx==0 ) goto no_mem; |
| 69851 | 69969 | pCx->nullRow = 1; |
| 69852 | 69970 | pCx->pseudoTableReg = pOp->p2; |
| 69853 | 69971 | pCx->isTable = 1; |
| 69854 | | - pCx->multiPseudo = pOp->p5; |
| 69972 | + assert( pOp->p5==0 ); |
| 69855 | 69973 | break; |
| 69856 | 69974 | } |
| 69857 | 69975 | |
| 69858 | 69976 | /* Opcode: Close P1 * * * * |
| 69859 | 69977 | ** |
| | @@ -69921,14 +70039,14 @@ |
| 69921 | 70039 | ** is less than or equal to the key value. If there are no records |
| 69922 | 70040 | ** less than or equal to the key and P2 is not zero, then jump to P2. |
| 69923 | 70041 | ** |
| 69924 | 70042 | ** See also: Found, NotFound, Distinct, SeekGt, SeekGe, SeekLt |
| 69925 | 70043 | */ |
| 69926 | | -case OP_SeekLt: /* jump, in3 */ |
| 69927 | | -case OP_SeekLe: /* jump, in3 */ |
| 69928 | | -case OP_SeekGe: /* jump, in3 */ |
| 69929 | | -case OP_SeekGt: { /* jump, in3 */ |
| 70044 | +case OP_SeekLT: /* jump, in3 */ |
| 70045 | +case OP_SeekLE: /* jump, in3 */ |
| 70046 | +case OP_SeekGE: /* jump, in3 */ |
| 70047 | +case OP_SeekGT: { /* jump, in3 */ |
| 69930 | 70048 | int res; |
| 69931 | 70049 | int oc; |
| 69932 | 70050 | VdbeCursor *pC; |
| 69933 | 70051 | UnpackedRecord r; |
| 69934 | 70052 | int nField; |
| | @@ -69937,13 +70055,13 @@ |
| 69937 | 70055 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 69938 | 70056 | assert( pOp->p2!=0 ); |
| 69939 | 70057 | pC = p->apCsr[pOp->p1]; |
| 69940 | 70058 | assert( pC!=0 ); |
| 69941 | 70059 | assert( pC->pseudoTableReg==0 ); |
| 69942 | | - assert( OP_SeekLe == OP_SeekLt+1 ); |
| 69943 | | - assert( OP_SeekGe == OP_SeekLt+2 ); |
| 69944 | | - assert( OP_SeekGt == OP_SeekLt+3 ); |
| 70060 | + assert( OP_SeekLE == OP_SeekLT+1 ); |
| 70061 | + assert( OP_SeekGE == OP_SeekLT+2 ); |
| 70062 | + assert( OP_SeekGT == OP_SeekLT+3 ); |
| 69945 | 70063 | assert( pC->isOrdered ); |
| 69946 | 70064 | assert( pC->pCursor!=0 ); |
| 69947 | 70065 | oc = pOp->opcode; |
| 69948 | 70066 | pC->nullRow = 0; |
| 69949 | 70067 | if( pC->isTable ){ |
| | @@ -69959,11 +70077,11 @@ |
| 69959 | 70077 | ** loss of information, then special processing is required... */ |
| 69960 | 70078 | if( (pIn3->flags & MEM_Int)==0 ){ |
| 69961 | 70079 | if( (pIn3->flags & MEM_Real)==0 ){ |
| 69962 | 70080 | /* If the P3 value cannot be converted into any kind of a number, |
| 69963 | 70081 | ** then the seek is not possible, so jump to P2 */ |
| 69964 | | - pc = pOp->p2 - 1; |
| 70082 | + pc = pOp->p2 - 1; VdbeBranchTaken(1,2); |
| 69965 | 70083 | break; |
| 69966 | 70084 | } |
| 69967 | 70085 | |
| 69968 | 70086 | /* If the approximation iKey is larger than the actual real search |
| 69969 | 70087 | ** term, substitute >= for > and < for <=. e.g. if the search term |
| | @@ -69971,23 +70089,23 @@ |
| 69971 | 70089 | ** |
| 69972 | 70090 | ** (x > 4.9) -> (x >= 5) |
| 69973 | 70091 | ** (x <= 4.9) -> (x < 5) |
| 69974 | 70092 | */ |
| 69975 | 70093 | if( pIn3->r<(double)iKey ){ |
| 69976 | | - assert( OP_SeekGe==(OP_SeekGt-1) ); |
| 69977 | | - assert( OP_SeekLt==(OP_SeekLe-1) ); |
| 69978 | | - assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) ); |
| 69979 | | - if( (oc & 0x0001)==(OP_SeekGt & 0x0001) ) oc--; |
| 70094 | + assert( OP_SeekGE==(OP_SeekGT-1) ); |
| 70095 | + assert( OP_SeekLT==(OP_SeekLE-1) ); |
| 70096 | + assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) ); |
| 70097 | + if( (oc & 0x0001)==(OP_SeekGT & 0x0001) ) oc--; |
| 69980 | 70098 | } |
| 69981 | 70099 | |
| 69982 | 70100 | /* If the approximation iKey is smaller than the actual real search |
| 69983 | 70101 | ** term, substitute <= for < and > for >=. */ |
| 69984 | 70102 | else if( pIn3->r>(double)iKey ){ |
| 69985 | | - assert( OP_SeekLe==(OP_SeekLt+1) ); |
| 69986 | | - assert( OP_SeekGt==(OP_SeekGe+1) ); |
| 69987 | | - assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) ); |
| 69988 | | - if( (oc & 0x0001)==(OP_SeekLt & 0x0001) ) oc++; |
| 70103 | + assert( OP_SeekLE==(OP_SeekLT+1) ); |
| 70104 | + assert( OP_SeekGT==(OP_SeekGE+1) ); |
| 70105 | + assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) ); |
| 70106 | + if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++; |
| 69989 | 70107 | } |
| 69990 | 70108 | } |
| 69991 | 70109 | rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res); |
| 69992 | 70110 | if( rc!=SQLITE_OK ){ |
| 69993 | 70111 | goto abort_due_to_error; |
| | @@ -70002,21 +70120,21 @@ |
| 70002 | 70120 | assert( nField>0 ); |
| 70003 | 70121 | r.pKeyInfo = pC->pKeyInfo; |
| 70004 | 70122 | r.nField = (u16)nField; |
| 70005 | 70123 | |
| 70006 | 70124 | /* The next line of code computes as follows, only faster: |
| 70007 | | - ** if( oc==OP_SeekGt || oc==OP_SeekLe ){ |
| 70125 | + ** if( oc==OP_SeekGT || oc==OP_SeekLE ){ |
| 70008 | 70126 | ** r.flags = UNPACKED_INCRKEY; |
| 70009 | 70127 | ** }else{ |
| 70010 | 70128 | ** r.flags = 0; |
| 70011 | 70129 | ** } |
| 70012 | 70130 | */ |
| 70013 | | - r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLt))); |
| 70014 | | - assert( oc!=OP_SeekGt || r.flags==UNPACKED_INCRKEY ); |
| 70015 | | - assert( oc!=OP_SeekLe || r.flags==UNPACKED_INCRKEY ); |
| 70016 | | - assert( oc!=OP_SeekGe || r.flags==0 ); |
| 70017 | | - assert( oc!=OP_SeekLt || r.flags==0 ); |
| 70131 | + r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLT))); |
| 70132 | + assert( oc!=OP_SeekGT || r.flags==UNPACKED_INCRKEY ); |
| 70133 | + assert( oc!=OP_SeekLE || r.flags==UNPACKED_INCRKEY ); |
| 70134 | + assert( oc!=OP_SeekGE || r.flags==0 ); |
| 70135 | + assert( oc!=OP_SeekLT || r.flags==0 ); |
| 70018 | 70136 | |
| 70019 | 70137 | r.aMem = &aMem[pOp->p3]; |
| 70020 | 70138 | #ifdef SQLITE_DEBUG |
| 70021 | 70139 | { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } |
| 70022 | 70140 | #endif |
| | @@ -70030,21 +70148,23 @@ |
| 70030 | 70148 | pC->deferredMoveto = 0; |
| 70031 | 70149 | pC->cacheStatus = CACHE_STALE; |
| 70032 | 70150 | #ifdef SQLITE_TEST |
| 70033 | 70151 | sqlite3_search_count++; |
| 70034 | 70152 | #endif |
| 70035 | | - if( oc>=OP_SeekGe ){ assert( oc==OP_SeekGe || oc==OP_SeekGt ); |
| 70036 | | - if( res<0 || (res==0 && oc==OP_SeekGt) ){ |
| 70153 | + if( oc>=OP_SeekGE ){ assert( oc==OP_SeekGE || oc==OP_SeekGT ); |
| 70154 | + if( res<0 || (res==0 && oc==OP_SeekGT) ){ |
| 70155 | + res = 0; |
| 70037 | 70156 | rc = sqlite3BtreeNext(pC->pCursor, &res); |
| 70038 | 70157 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 70039 | 70158 | pC->rowidIsValid = 0; |
| 70040 | 70159 | }else{ |
| 70041 | 70160 | res = 0; |
| 70042 | 70161 | } |
| 70043 | 70162 | }else{ |
| 70044 | | - assert( oc==OP_SeekLt || oc==OP_SeekLe ); |
| 70045 | | - if( res>0 || (res==0 && oc==OP_SeekLt) ){ |
| 70163 | + assert( oc==OP_SeekLT || oc==OP_SeekLE ); |
| 70164 | + if( res>0 || (res==0 && oc==OP_SeekLT) ){ |
| 70165 | + res = 0; |
| 70046 | 70166 | rc = sqlite3BtreePrevious(pC->pCursor, &res); |
| 70047 | 70167 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 70048 | 70168 | pC->rowidIsValid = 0; |
| 70049 | 70169 | }else{ |
| 70050 | 70170 | /* res might be negative because the table is empty. Check to |
| | @@ -70052,10 +70172,11 @@ |
| 70052 | 70172 | */ |
| 70053 | 70173 | res = sqlite3BtreeEof(pC->pCursor); |
| 70054 | 70174 | } |
| 70055 | 70175 | } |
| 70056 | 70176 | assert( pOp->p2>0 ); |
| 70177 | + VdbeBranchTaken(res!=0,2); |
| 70057 | 70178 | if( res ){ |
| 70058 | 70179 | pc = pOp->p2 - 1; |
| 70059 | 70180 | } |
| 70060 | 70181 | break; |
| 70061 | 70182 | } |
| | @@ -70160,19 +70281,17 @@ |
| 70160 | 70281 | pFree = 0; /* Not needed. Only used to suppress a compiler warning. */ |
| 70161 | 70282 | if( pOp->p4.i>0 ){ |
| 70162 | 70283 | r.pKeyInfo = pC->pKeyInfo; |
| 70163 | 70284 | r.nField = (u16)pOp->p4.i; |
| 70164 | 70285 | r.aMem = pIn3; |
| 70286 | + for(ii=0; ii<r.nField; ii++){ |
| 70287 | + assert( memIsValid(&r.aMem[ii]) ); |
| 70288 | + ExpandBlob(&r.aMem[ii]); |
| 70165 | 70289 | #ifdef SQLITE_DEBUG |
| 70166 | | - { |
| 70167 | | - int i; |
| 70168 | | - for(i=0; i<r.nField; i++){ |
| 70169 | | - assert( memIsValid(&r.aMem[i]) ); |
| 70170 | | - if( i ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]); |
| 70171 | | - } |
| 70172 | | - } |
| 70173 | | -#endif |
| 70290 | + if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]); |
| 70291 | +#endif |
| 70292 | + } |
| 70174 | 70293 | r.flags = UNPACKED_PREFIX_MATCH; |
| 70175 | 70294 | pIdxKey = &r; |
| 70176 | 70295 | }else{ |
| 70177 | 70296 | pIdxKey = sqlite3VdbeAllocUnpackedRecord( |
| 70178 | 70297 | pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree |
| | @@ -70187,11 +70306,11 @@ |
| 70187 | 70306 | /* For the OP_NoConflict opcode, take the jump if any of the |
| 70188 | 70307 | ** input fields are NULL, since any key with a NULL will not |
| 70189 | 70308 | ** conflict */ |
| 70190 | 70309 | for(ii=0; ii<r.nField; ii++){ |
| 70191 | 70310 | if( r.aMem[ii].flags & MEM_Null ){ |
| 70192 | | - pc = pOp->p2 - 1; |
| 70311 | + pc = pOp->p2 - 1; VdbeBranchTaken(1,2); |
| 70193 | 70312 | break; |
| 70194 | 70313 | } |
| 70195 | 70314 | } |
| 70196 | 70315 | } |
| 70197 | 70316 | rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res); |
| | @@ -70205,12 +70324,14 @@ |
| 70205 | 70324 | alreadyExists = (res==0); |
| 70206 | 70325 | pC->nullRow = 1-alreadyExists; |
| 70207 | 70326 | pC->deferredMoveto = 0; |
| 70208 | 70327 | pC->cacheStatus = CACHE_STALE; |
| 70209 | 70328 | if( pOp->opcode==OP_Found ){ |
| 70329 | + VdbeBranchTaken(alreadyExists!=0,2); |
| 70210 | 70330 | if( alreadyExists ) pc = pOp->p2 - 1; |
| 70211 | 70331 | }else{ |
| 70332 | + VdbeBranchTaken(alreadyExists==0,2); |
| 70212 | 70333 | if( !alreadyExists ) pc = pOp->p2 - 1; |
| 70213 | 70334 | } |
| 70214 | 70335 | break; |
| 70215 | 70336 | } |
| 70216 | 70337 | |
| | @@ -70249,10 +70370,11 @@ |
| 70249 | 70370 | pC->lastRowid = pIn3->u.i; |
| 70250 | 70371 | pC->rowidIsValid = res==0 ?1:0; |
| 70251 | 70372 | pC->nullRow = 0; |
| 70252 | 70373 | pC->cacheStatus = CACHE_STALE; |
| 70253 | 70374 | pC->deferredMoveto = 0; |
| 70375 | + VdbeBranchTaken(res!=0,2); |
| 70254 | 70376 | if( res!=0 ){ |
| 70255 | 70377 | pc = pOp->p2 - 1; |
| 70256 | 70378 | assert( pC->rowidIsValid==0 ); |
| 70257 | 70379 | } |
| 70258 | 70380 | pC->seekResult = res; |
| | @@ -70330,63 +70452,58 @@ |
| 70330 | 70452 | */ |
| 70331 | 70453 | # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff ) |
| 70332 | 70454 | #endif |
| 70333 | 70455 | |
| 70334 | 70456 | if( !pC->useRandomRowid ){ |
| 70335 | | - v = sqlite3BtreeGetCachedRowid(pC->pCursor); |
| 70336 | | - if( v==0 ){ |
| 70337 | | - rc = sqlite3BtreeLast(pC->pCursor, &res); |
| 70338 | | - if( rc!=SQLITE_OK ){ |
| 70339 | | - goto abort_due_to_error; |
| 70340 | | - } |
| 70341 | | - if( res ){ |
| 70342 | | - v = 1; /* IMP: R-61914-48074 */ |
| 70343 | | - }else{ |
| 70344 | | - assert( sqlite3BtreeCursorIsValid(pC->pCursor) ); |
| 70345 | | - rc = sqlite3BtreeKeySize(pC->pCursor, &v); |
| 70346 | | - assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */ |
| 70347 | | - if( v>=MAX_ROWID ){ |
| 70348 | | - pC->useRandomRowid = 1; |
| 70349 | | - }else{ |
| 70350 | | - v++; /* IMP: R-29538-34987 */ |
| 70351 | | - } |
| 70352 | | - } |
| 70353 | | - } |
| 70354 | | - |
| 70355 | | -#ifndef SQLITE_OMIT_AUTOINCREMENT |
| 70356 | | - if( pOp->p3 ){ |
| 70357 | | - /* Assert that P3 is a valid memory cell. */ |
| 70358 | | - assert( pOp->p3>0 ); |
| 70359 | | - if( p->pFrame ){ |
| 70360 | | - for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent); |
| 70361 | | - /* Assert that P3 is a valid memory cell. */ |
| 70362 | | - assert( pOp->p3<=pFrame->nMem ); |
| 70363 | | - pMem = &pFrame->aMem[pOp->p3]; |
| 70364 | | - }else{ |
| 70365 | | - /* Assert that P3 is a valid memory cell. */ |
| 70366 | | - assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 70367 | | - pMem = &aMem[pOp->p3]; |
| 70368 | | - memAboutToChange(p, pMem); |
| 70369 | | - } |
| 70370 | | - assert( memIsValid(pMem) ); |
| 70371 | | - |
| 70372 | | - REGISTER_TRACE(pOp->p3, pMem); |
| 70373 | | - sqlite3VdbeMemIntegerify(pMem); |
| 70374 | | - assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */ |
| 70375 | | - if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){ |
| 70376 | | - rc = SQLITE_FULL; /* IMP: R-12275-61338 */ |
| 70377 | | - goto abort_due_to_error; |
| 70378 | | - } |
| 70379 | | - if( v<pMem->u.i+1 ){ |
| 70380 | | - v = pMem->u.i + 1; |
| 70381 | | - } |
| 70382 | | - pMem->u.i = v; |
| 70383 | | - } |
| 70384 | | -#endif |
| 70385 | | - |
| 70386 | | - sqlite3BtreeSetCachedRowid(pC->pCursor, v<MAX_ROWID ? v+1 : 0); |
| 70387 | | - } |
| 70457 | + rc = sqlite3BtreeLast(pC->pCursor, &res); |
| 70458 | + if( rc!=SQLITE_OK ){ |
| 70459 | + goto abort_due_to_error; |
| 70460 | + } |
| 70461 | + if( res ){ |
| 70462 | + v = 1; /* IMP: R-61914-48074 */ |
| 70463 | + }else{ |
| 70464 | + assert( sqlite3BtreeCursorIsValid(pC->pCursor) ); |
| 70465 | + rc = sqlite3BtreeKeySize(pC->pCursor, &v); |
| 70466 | + assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */ |
| 70467 | + if( v>=MAX_ROWID ){ |
| 70468 | + pC->useRandomRowid = 1; |
| 70469 | + }else{ |
| 70470 | + v++; /* IMP: R-29538-34987 */ |
| 70471 | + } |
| 70472 | + } |
| 70473 | + } |
| 70474 | + |
| 70475 | +#ifndef SQLITE_OMIT_AUTOINCREMENT |
| 70476 | + if( pOp->p3 ){ |
| 70477 | + /* Assert that P3 is a valid memory cell. */ |
| 70478 | + assert( pOp->p3>0 ); |
| 70479 | + if( p->pFrame ){ |
| 70480 | + for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent); |
| 70481 | + /* Assert that P3 is a valid memory cell. */ |
| 70482 | + assert( pOp->p3<=pFrame->nMem ); |
| 70483 | + pMem = &pFrame->aMem[pOp->p3]; |
| 70484 | + }else{ |
| 70485 | + /* Assert that P3 is a valid memory cell. */ |
| 70486 | + assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 70487 | + pMem = &aMem[pOp->p3]; |
| 70488 | + memAboutToChange(p, pMem); |
| 70489 | + } |
| 70490 | + assert( memIsValid(pMem) ); |
| 70491 | + |
| 70492 | + REGISTER_TRACE(pOp->p3, pMem); |
| 70493 | + sqlite3VdbeMemIntegerify(pMem); |
| 70494 | + assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */ |
| 70495 | + if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){ |
| 70496 | + rc = SQLITE_FULL; /* IMP: R-12275-61338 */ |
| 70497 | + goto abort_due_to_error; |
| 70498 | + } |
| 70499 | + if( v<pMem->u.i+1 ){ |
| 70500 | + v = pMem->u.i + 1; |
| 70501 | + } |
| 70502 | + pMem->u.i = v; |
| 70503 | + } |
| 70504 | +#endif |
| 70388 | 70505 | if( pC->useRandomRowid ){ |
| 70389 | 70506 | /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the |
| 70390 | 70507 | ** largest possible integer (9223372036854775807) then the database |
| 70391 | 70508 | ** engine starts picking positive candidate ROWIDs at random until |
| 70392 | 70509 | ** it finds one that is not previously used. */ |
| | @@ -70516,11 +70633,10 @@ |
| 70516 | 70633 | if( pData->flags & MEM_Zero ){ |
| 70517 | 70634 | nZero = pData->u.nZero; |
| 70518 | 70635 | }else{ |
| 70519 | 70636 | nZero = 0; |
| 70520 | 70637 | } |
| 70521 | | - sqlite3BtreeSetCachedRowid(pC->pCursor, 0); |
| 70522 | 70638 | rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey, |
| 70523 | 70639 | pData->z, pData->n, nZero, |
| 70524 | 70640 | (pOp->p5 & OPFLAG_APPEND)!=0, seekResult |
| 70525 | 70641 | ); |
| 70526 | 70642 | pC->rowidIsValid = 0; |
| | @@ -70578,11 +70694,10 @@ |
| 70578 | 70694 | **/ |
| 70579 | 70695 | assert( pC->deferredMoveto==0 ); |
| 70580 | 70696 | rc = sqlite3VdbeCursorMoveto(pC); |
| 70581 | 70697 | if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error; |
| 70582 | 70698 | |
| 70583 | | - sqlite3BtreeSetCachedRowid(pC->pCursor, 0); |
| 70584 | 70699 | rc = sqlite3BtreeDelete(pC->pCursor); |
| 70585 | 70700 | pC->cacheStatus = CACHE_STALE; |
| 70586 | 70701 | |
| 70587 | 70702 | /* Invoke the update-hook if required. */ |
| 70588 | 70703 | if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){ |
| | @@ -70630,10 +70745,11 @@ |
| 70630 | 70745 | assert( isSorter(pC) ); |
| 70631 | 70746 | assert( pOp->p4type==P4_INT32 ); |
| 70632 | 70747 | pIn3 = &aMem[pOp->p3]; |
| 70633 | 70748 | nIgnore = pOp->p4.i; |
| 70634 | 70749 | rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res); |
| 70750 | + VdbeBranchTaken(res!=0,2); |
| 70635 | 70751 | if( res ){ |
| 70636 | 70752 | pc = pOp->p2-1; |
| 70637 | 70753 | } |
| 70638 | 70754 | break; |
| 70639 | 70755 | }; |
| | @@ -70667,11 +70783,11 @@ |
| 70667 | 70783 | /* Opcode: RowKey P1 P2 * * * |
| 70668 | 70784 | ** Synopsis: r[P2]=key |
| 70669 | 70785 | ** |
| 70670 | 70786 | ** Write into register P2 the complete row key for cursor P1. |
| 70671 | 70787 | ** There is no interpretation of the data. |
| 70672 | | -** The key is copied onto the P3 register exactly as |
| 70788 | +** The key is copied onto the P2 register exactly as |
| 70673 | 70789 | ** it is found in the database file. |
| 70674 | 70790 | ** |
| 70675 | 70791 | ** If the P1 cursor must be pointing to a valid row (not a NULL row) |
| 70676 | 70792 | ** of a real table, not a pseudo-table. |
| 70677 | 70793 | */ |
| | @@ -70829,12 +70945,13 @@ |
| 70829 | 70945 | rc = sqlite3BtreeLast(pCrsr, &res); |
| 70830 | 70946 | pC->nullRow = (u8)res; |
| 70831 | 70947 | pC->deferredMoveto = 0; |
| 70832 | 70948 | pC->rowidIsValid = 0; |
| 70833 | 70949 | pC->cacheStatus = CACHE_STALE; |
| 70834 | | - if( pOp->p2>0 && res ){ |
| 70835 | | - pc = pOp->p2 - 1; |
| 70950 | + if( pOp->p2>0 ){ |
| 70951 | + VdbeBranchTaken(res!=0,2); |
| 70952 | + if( res ) pc = pOp->p2 - 1; |
| 70836 | 70953 | } |
| 70837 | 70954 | break; |
| 70838 | 70955 | } |
| 70839 | 70956 | |
| 70840 | 70957 | |
| | @@ -70887,56 +71004,67 @@ |
| 70887 | 71004 | pC->cacheStatus = CACHE_STALE; |
| 70888 | 71005 | pC->rowidIsValid = 0; |
| 70889 | 71006 | } |
| 70890 | 71007 | pC->nullRow = (u8)res; |
| 70891 | 71008 | assert( pOp->p2>0 && pOp->p2<p->nOp ); |
| 71009 | + VdbeBranchTaken(res!=0,2); |
| 70892 | 71010 | if( res ){ |
| 70893 | 71011 | pc = pOp->p2 - 1; |
| 70894 | 71012 | } |
| 70895 | 71013 | break; |
| 70896 | 71014 | } |
| 70897 | 71015 | |
| 70898 | | -/* Opcode: Next P1 P2 * * P5 |
| 71016 | +/* Opcode: Next P1 P2 P3 P4 P5 |
| 70899 | 71017 | ** |
| 70900 | 71018 | ** Advance cursor P1 so that it points to the next key/data pair in its |
| 70901 | 71019 | ** table or index. If there are no more key/value pairs then fall through |
| 70902 | 71020 | ** to the following instruction. But if the cursor advance was successful, |
| 70903 | 71021 | ** jump immediately to P2. |
| 70904 | 71022 | ** |
| 70905 | 71023 | ** The P1 cursor must be for a real table, not a pseudo-table. P1 must have |
| 70906 | 71024 | ** been opened prior to this opcode or the program will segfault. |
| 71025 | +** |
| 71026 | +** The P3 value is a hint to the btree implementation. If P3==1, that |
| 71027 | +** means P1 is an SQL index and that this instruction could have been |
| 71028 | +** omitted if that index had been unique. P3 is usually 0. P3 is |
| 71029 | +** always either 0 or 1. |
| 70907 | 71030 | ** |
| 70908 | 71031 | ** P4 is always of type P4_ADVANCE. The function pointer points to |
| 70909 | 71032 | ** sqlite3BtreeNext(). |
| 70910 | 71033 | ** |
| 70911 | 71034 | ** If P5 is positive and the jump is taken, then event counter |
| 70912 | 71035 | ** number P5-1 in the prepared statement is incremented. |
| 70913 | 71036 | ** |
| 70914 | 71037 | ** See also: Prev, NextIfOpen |
| 70915 | 71038 | */ |
| 70916 | | -/* Opcode: NextIfOpen P1 P2 * * P5 |
| 71039 | +/* Opcode: NextIfOpen P1 P2 P3 P4 P5 |
| 70917 | 71040 | ** |
| 70918 | 71041 | ** This opcode works just like OP_Next except that if cursor P1 is not |
| 70919 | 71042 | ** open it behaves a no-op. |
| 70920 | 71043 | */ |
| 70921 | | -/* Opcode: Prev P1 P2 * * P5 |
| 71044 | +/* Opcode: Prev P1 P2 P3 P4 P5 |
| 70922 | 71045 | ** |
| 70923 | 71046 | ** Back up cursor P1 so that it points to the previous key/data pair in its |
| 70924 | 71047 | ** table or index. If there is no previous key/value pairs then fall through |
| 70925 | 71048 | ** to the following instruction. But if the cursor backup was successful, |
| 70926 | 71049 | ** jump immediately to P2. |
| 70927 | 71050 | ** |
| 70928 | 71051 | ** The P1 cursor must be for a real table, not a pseudo-table. If P1 is |
| 70929 | 71052 | ** not open then the behavior is undefined. |
| 71053 | +** |
| 71054 | +** The P3 value is a hint to the btree implementation. If P3==1, that |
| 71055 | +** means P1 is an SQL index and that this instruction could have been |
| 71056 | +** omitted if that index had been unique. P3 is usually 0. P3 is |
| 71057 | +** always either 0 or 1. |
| 70930 | 71058 | ** |
| 70931 | 71059 | ** P4 is always of type P4_ADVANCE. The function pointer points to |
| 70932 | 71060 | ** sqlite3BtreePrevious(). |
| 70933 | 71061 | ** |
| 70934 | 71062 | ** If P5 is positive and the jump is taken, then event counter |
| 70935 | 71063 | ** number P5-1 in the prepared statement is incremented. |
| 70936 | 71064 | */ |
| 70937 | | -/* Opcode: PrevIfOpen P1 P2 * * P5 |
| 71065 | +/* Opcode: PrevIfOpen P1 P2 P3 P4 P5 |
| 70938 | 71066 | ** |
| 70939 | 71067 | ** This opcode works just like OP_Prev except that if cursor P1 is not |
| 70940 | 71068 | ** open it behaves a no-op. |
| 70941 | 71069 | */ |
| 70942 | 71070 | case OP_SorterNext: { /* jump */ |
| | @@ -70954,20 +71082,24 @@ |
| 70954 | 71082 | case OP_Prev: /* jump */ |
| 70955 | 71083 | case OP_Next: /* jump */ |
| 70956 | 71084 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70957 | 71085 | assert( pOp->p5<ArraySize(p->aCounter) ); |
| 70958 | 71086 | pC = p->apCsr[pOp->p1]; |
| 71087 | + res = pOp->p3; |
| 70959 | 71088 | assert( pC!=0 ); |
| 70960 | 71089 | assert( pC->deferredMoveto==0 ); |
| 70961 | 71090 | assert( pC->pCursor ); |
| 71091 | + assert( res==0 || (res==1 && pC->isTable==0) ); |
| 71092 | + testcase( res==1 ); |
| 70962 | 71093 | assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 70963 | 71094 | assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); |
| 70964 | 71095 | assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 70965 | 71096 | assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious); |
| 70966 | 71097 | rc = pOp->p4.xAdvance(pC->pCursor, &res); |
| 70967 | 71098 | next_tail: |
| 70968 | 71099 | pC->cacheStatus = CACHE_STALE; |
| 71100 | + VdbeBranchTaken(res==0,2); |
| 70969 | 71101 | if( res==0 ){ |
| 70970 | 71102 | pC->nullRow = 0; |
| 70971 | 71103 | pc = pOp->p2 - 1; |
| 70972 | 71104 | p->aCounter[pOp->p5]++; |
| 70973 | 71105 | #ifdef SQLITE_TEST |
| | @@ -70987,10 +71119,18 @@ |
| 70987 | 71119 | ** MakeRecord instructions. This opcode writes that key |
| 70988 | 71120 | ** into the index P1. Data for the entry is nil. |
| 70989 | 71121 | ** |
| 70990 | 71122 | ** P3 is a flag that provides a hint to the b-tree layer that this |
| 70991 | 71123 | ** insert is likely to be an append. |
| 71124 | +** |
| 71125 | +** If P5 has the OPFLAG_NCHANGE bit set, then the change counter is |
| 71126 | +** incremented by this instruction. If the OPFLAG_NCHANGE bit is clear, |
| 71127 | +** then the change counter is unchanged. |
| 71128 | +** |
| 71129 | +** If P5 has the OPFLAG_USESEEKRESULT bit set, then the cursor must have |
| 71130 | +** just done a seek to the spot where the new entry is to be inserted. |
| 71131 | +** This flag avoids doing an extra seek. |
| 70992 | 71132 | ** |
| 70993 | 71133 | ** This instruction only works for indices. The equivalent instruction |
| 70994 | 71134 | ** for tables is OP_Insert. |
| 70995 | 71135 | */ |
| 70996 | 71136 | case OP_SorterInsert: /* in2 */ |
| | @@ -71102,36 +71242,54 @@ |
| 71102 | 71242 | |
| 71103 | 71243 | /* Opcode: IdxGE P1 P2 P3 P4 P5 |
| 71104 | 71244 | ** Synopsis: key=r[P3@P4] |
| 71105 | 71245 | ** |
| 71106 | 71246 | ** The P4 register values beginning with P3 form an unpacked index |
| 71107 | | -** key that omits the ROWID. Compare this key value against the index |
| 71108 | | -** that P1 is currently pointing to, ignoring the ROWID on the P1 index. |
| 71247 | +** key that omits the PRIMARY KEY. Compare this key value against the index |
| 71248 | +** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID |
| 71249 | +** fields at the end. |
| 71109 | 71250 | ** |
| 71110 | 71251 | ** If the P1 index entry is greater than or equal to the key value |
| 71111 | 71252 | ** then jump to P2. Otherwise fall through to the next instruction. |
| 71253 | +*/ |
| 71254 | +/* Opcode: IdxGT P1 P2 P3 P4 P5 |
| 71255 | +** Synopsis: key=r[P3@P4] |
| 71112 | 71256 | ** |
| 71113 | | -** If P5 is non-zero then the key value is increased by an epsilon |
| 71114 | | -** prior to the comparison. This make the opcode work like IdxGT except |
| 71115 | | -** that if the key from register P3 is a prefix of the key in the cursor, |
| 71116 | | -** the result is false whereas it would be true with IdxGT. |
| 71257 | +** The P4 register values beginning with P3 form an unpacked index |
| 71258 | +** key that omits the PRIMARY KEY. Compare this key value against the index |
| 71259 | +** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID |
| 71260 | +** fields at the end. |
| 71261 | +** |
| 71262 | +** If the P1 index entry is greater than the key value |
| 71263 | +** then jump to P2. Otherwise fall through to the next instruction. |
| 71117 | 71264 | */ |
| 71118 | 71265 | /* Opcode: IdxLT P1 P2 P3 P4 P5 |
| 71119 | 71266 | ** Synopsis: key=r[P3@P4] |
| 71120 | 71267 | ** |
| 71121 | 71268 | ** The P4 register values beginning with P3 form an unpacked index |
| 71122 | | -** key that omits the ROWID. Compare this key value against the index |
| 71123 | | -** that P1 is currently pointing to, ignoring the ROWID on the P1 index. |
| 71269 | +** key that omits the PRIMARY KEY or ROWID. Compare this key value against |
| 71270 | +** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or |
| 71271 | +** ROWID on the P1 index. |
| 71124 | 71272 | ** |
| 71125 | 71273 | ** If the P1 index entry is less than the key value then jump to P2. |
| 71126 | 71274 | ** Otherwise fall through to the next instruction. |
| 71275 | +*/ |
| 71276 | +/* Opcode: IdxLE P1 P2 P3 P4 P5 |
| 71277 | +** Synopsis: key=r[P3@P4] |
| 71127 | 71278 | ** |
| 71128 | | -** If P5 is non-zero then the key value is increased by an epsilon prior |
| 71129 | | -** to the comparison. This makes the opcode work like IdxLE. |
| 71279 | +** The P4 register values beginning with P3 form an unpacked index |
| 71280 | +** key that omits the PRIMARY KEY or ROWID. Compare this key value against |
| 71281 | +** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or |
| 71282 | +** ROWID on the P1 index. |
| 71283 | +** |
| 71284 | +** If the P1 index entry is less than or equal to the key value then jump |
| 71285 | +** to P2. Otherwise fall through to the next instruction. |
| 71130 | 71286 | */ |
| 71287 | +case OP_IdxLE: /* jump */ |
| 71288 | +case OP_IdxGT: /* jump */ |
| 71131 | 71289 | case OP_IdxLT: /* jump */ |
| 71132 | | -case OP_IdxGE: { /* jump */ |
| 71290 | +case OP_IdxGE: { /* jump */ |
| 71133 | 71291 | VdbeCursor *pC; |
| 71134 | 71292 | int res; |
| 71135 | 71293 | UnpackedRecord r; |
| 71136 | 71294 | |
| 71137 | 71295 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| | @@ -71142,27 +71300,32 @@ |
| 71142 | 71300 | assert( pC->deferredMoveto==0 ); |
| 71143 | 71301 | assert( pOp->p5==0 || pOp->p5==1 ); |
| 71144 | 71302 | assert( pOp->p4type==P4_INT32 ); |
| 71145 | 71303 | r.pKeyInfo = pC->pKeyInfo; |
| 71146 | 71304 | r.nField = (u16)pOp->p4.i; |
| 71147 | | - if( pOp->p5 ){ |
| 71305 | + if( pOp->opcode<OP_IdxLT ){ |
| 71306 | + assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxGT ); |
| 71148 | 71307 | r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH; |
| 71149 | 71308 | }else{ |
| 71309 | + assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxLT ); |
| 71150 | 71310 | r.flags = UNPACKED_PREFIX_MATCH; |
| 71151 | 71311 | } |
| 71152 | 71312 | r.aMem = &aMem[pOp->p3]; |
| 71153 | 71313 | #ifdef SQLITE_DEBUG |
| 71154 | 71314 | { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } |
| 71155 | 71315 | #endif |
| 71156 | 71316 | res = 0; /* Not needed. Only used to silence a warning. */ |
| 71157 | 71317 | rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res); |
| 71158 | | - if( pOp->opcode==OP_IdxLT ){ |
| 71318 | + assert( (OP_IdxLE&1)==(OP_IdxLT&1) && (OP_IdxGE&1)==(OP_IdxGT&1) ); |
| 71319 | + if( (pOp->opcode&1)==(OP_IdxLT&1) ){ |
| 71320 | + assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxLT ); |
| 71159 | 71321 | res = -res; |
| 71160 | 71322 | }else{ |
| 71161 | | - assert( pOp->opcode==OP_IdxGE ); |
| 71323 | + assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT ); |
| 71162 | 71324 | res++; |
| 71163 | 71325 | } |
| 71326 | + VdbeBranchTaken(res>0,2); |
| 71164 | 71327 | if( res>0 ){ |
| 71165 | 71328 | pc = pOp->p2 - 1 ; |
| 71166 | 71329 | } |
| 71167 | 71330 | break; |
| 71168 | 71331 | } |
| | @@ -71251,11 +71414,10 @@ |
| 71251 | 71414 | case OP_Clear: { |
| 71252 | 71415 | int nChange; |
| 71253 | 71416 | |
| 71254 | 71417 | nChange = 0; |
| 71255 | 71418 | assert( p->readOnly==0 ); |
| 71256 | | - assert( pOp->p1!=1 ); |
| 71257 | 71419 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 ); |
| 71258 | 71420 | rc = sqlite3BtreeClearTable( |
| 71259 | 71421 | db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0) |
| 71260 | 71422 | ); |
| 71261 | 71423 | if( pOp->p3 ){ |
| | @@ -71520,13 +71682,15 @@ |
| 71520 | 71682 | || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0 |
| 71521 | 71683 | ){ |
| 71522 | 71684 | /* The boolean index is empty */ |
| 71523 | 71685 | sqlite3VdbeMemSetNull(pIn1); |
| 71524 | 71686 | pc = pOp->p2 - 1; |
| 71687 | + VdbeBranchTaken(1,2); |
| 71525 | 71688 | }else{ |
| 71526 | 71689 | /* A value was pulled from the index */ |
| 71527 | 71690 | sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val); |
| 71691 | + VdbeBranchTaken(0,2); |
| 71528 | 71692 | } |
| 71529 | 71693 | goto check_for_interrupt; |
| 71530 | 71694 | } |
| 71531 | 71695 | |
| 71532 | 71696 | /* Opcode: RowSetTest P1 P2 P3 P4 |
| | @@ -71574,10 +71738,11 @@ |
| 71574 | 71738 | assert( iSet==-1 || iSet>=0 ); |
| 71575 | 71739 | if( iSet ){ |
| 71576 | 71740 | exists = sqlite3RowSetTest(pIn1->u.pRowSet, |
| 71577 | 71741 | (u8)(iSet>=0 ? iSet & 0xf : 0xff), |
| 71578 | 71742 | pIn3->u.i); |
| 71743 | + VdbeBranchTaken(exists!=0,2); |
| 71579 | 71744 | if( exists ){ |
| 71580 | 71745 | pc = pOp->p2 - 1; |
| 71581 | 71746 | break; |
| 71582 | 71747 | } |
| 71583 | 71748 | } |
| | @@ -71588,11 +71753,11 @@ |
| 71588 | 71753 | } |
| 71589 | 71754 | |
| 71590 | 71755 | |
| 71591 | 71756 | #ifndef SQLITE_OMIT_TRIGGER |
| 71592 | 71757 | |
| 71593 | | -/* Opcode: Program P1 P2 P3 P4 * |
| 71758 | +/* Opcode: Program P1 P2 P3 P4 P5 |
| 71594 | 71759 | ** |
| 71595 | 71760 | ** Execute the trigger program passed as P4 (type P4_SUBPROGRAM). |
| 71596 | 71761 | ** |
| 71597 | 71762 | ** P1 contains the address of the memory cell that contains the first memory |
| 71598 | 71763 | ** cell in an array of values used as arguments to the sub-program. P2 |
| | @@ -71600,10 +71765,12 @@ |
| 71600 | 71765 | ** exception using the RAISE() function. Register P3 contains the address |
| 71601 | 71766 | ** of a memory cell in this (the parent) VM that is used to allocate the |
| 71602 | 71767 | ** memory required by the sub-vdbe at runtime. |
| 71603 | 71768 | ** |
| 71604 | 71769 | ** P4 is a pointer to the VM containing the trigger program. |
| 71770 | +** |
| 71771 | +** If P5 is non-zero, then recursive program invocation is enabled. |
| 71605 | 71772 | */ |
| 71606 | 71773 | case OP_Program: { /* jump */ |
| 71607 | 71774 | int nMem; /* Number of memory registers for sub-program */ |
| 71608 | 71775 | int nByte; /* Bytes of runtime space required for sub-program */ |
| 71609 | 71776 | Mem *pRt; /* Register to allocate runtime space */ |
| | @@ -71677,11 +71844,11 @@ |
| 71677 | 71844 | pFrame->aOnceFlag = p->aOnceFlag; |
| 71678 | 71845 | pFrame->nOnceFlag = p->nOnceFlag; |
| 71679 | 71846 | |
| 71680 | 71847 | pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem]; |
| 71681 | 71848 | for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){ |
| 71682 | | - pMem->flags = MEM_Invalid; |
| 71849 | + pMem->flags = MEM_Undefined; |
| 71683 | 71850 | pMem->db = db; |
| 71684 | 71851 | } |
| 71685 | 71852 | }else{ |
| 71686 | 71853 | pFrame = pRt->u.pFrame; |
| 71687 | 71854 | assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem ); |
| | @@ -71764,12 +71931,14 @@ |
| 71764 | 71931 | ** zero, the jump is taken if the statement constraint-counter is zero |
| 71765 | 71932 | ** (immediate foreign key constraint violations). |
| 71766 | 71933 | */ |
| 71767 | 71934 | case OP_FkIfZero: { /* jump */ |
| 71768 | 71935 | if( pOp->p1 ){ |
| 71936 | + VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2); |
| 71769 | 71937 | if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1; |
| 71770 | 71938 | }else{ |
| 71939 | + VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2); |
| 71771 | 71940 | if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1; |
| 71772 | 71941 | } |
| 71773 | 71942 | break; |
| 71774 | 71943 | } |
| 71775 | 71944 | #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */ |
| | @@ -71814,10 +71983,11 @@ |
| 71814 | 71983 | ** not contain an integer. An assertion fault will result if you try. |
| 71815 | 71984 | */ |
| 71816 | 71985 | case OP_IfPos: { /* jump, in1 */ |
| 71817 | 71986 | pIn1 = &aMem[pOp->p1]; |
| 71818 | 71987 | assert( pIn1->flags&MEM_Int ); |
| 71988 | + VdbeBranchTaken( pIn1->u.i>0, 2); |
| 71819 | 71989 | if( pIn1->u.i>0 ){ |
| 71820 | 71990 | pc = pOp->p2 - 1; |
| 71821 | 71991 | } |
| 71822 | 71992 | break; |
| 71823 | 71993 | } |
| | @@ -71831,10 +72001,11 @@ |
| 71831 | 72001 | ** not contain an integer. An assertion fault will result if you try. |
| 71832 | 72002 | */ |
| 71833 | 72003 | case OP_IfNeg: { /* jump, in1 */ |
| 71834 | 72004 | pIn1 = &aMem[pOp->p1]; |
| 71835 | 72005 | assert( pIn1->flags&MEM_Int ); |
| 72006 | + VdbeBranchTaken(pIn1->u.i<0, 2); |
| 71836 | 72007 | if( pIn1->u.i<0 ){ |
| 71837 | 72008 | pc = pOp->p2 - 1; |
| 71838 | 72009 | } |
| 71839 | 72010 | break; |
| 71840 | 72011 | } |
| | @@ -71850,10 +72021,11 @@ |
| 71850 | 72021 | */ |
| 71851 | 72022 | case OP_IfZero: { /* jump, in1 */ |
| 71852 | 72023 | pIn1 = &aMem[pOp->p1]; |
| 71853 | 72024 | assert( pIn1->flags&MEM_Int ); |
| 71854 | 72025 | pIn1->u.i += pOp->p3; |
| 72026 | + VdbeBranchTaken(pIn1->u.i==0, 2); |
| 71855 | 72027 | if( pIn1->u.i==0 ){ |
| 71856 | 72028 | pc = pOp->p2 - 1; |
| 71857 | 72029 | } |
| 71858 | 72030 | break; |
| 71859 | 72031 | } |
| | @@ -71987,11 +72159,11 @@ |
| 71987 | 72159 | break; |
| 71988 | 72160 | }; |
| 71989 | 72161 | #endif |
| 71990 | 72162 | |
| 71991 | 72163 | #ifndef SQLITE_OMIT_PRAGMA |
| 71992 | | -/* Opcode: JournalMode P1 P2 P3 * P5 |
| 72164 | +/* Opcode: JournalMode P1 P2 P3 * * |
| 71993 | 72165 | ** |
| 71994 | 72166 | ** Change the journal mode of database P1 to P3. P3 must be one of the |
| 71995 | 72167 | ** PAGER_JOURNALMODE_XXX values. If changing between the various rollback |
| 71996 | 72168 | ** modes (delete, truncate, persist, off and memory), this is a simple |
| 71997 | 72169 | ** operation. No IO is required. |
| | @@ -72121,10 +72293,11 @@ |
| 72121 | 72293 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 72122 | 72294 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 72123 | 72295 | assert( p->readOnly==0 ); |
| 72124 | 72296 | pBt = db->aDb[pOp->p1].pBt; |
| 72125 | 72297 | rc = sqlite3BtreeIncrVacuum(pBt); |
| 72298 | + VdbeBranchTaken(rc==SQLITE_DONE,2); |
| 72126 | 72299 | if( rc==SQLITE_DONE ){ |
| 72127 | 72300 | pc = pOp->p2 - 1; |
| 72128 | 72301 | rc = SQLITE_OK; |
| 72129 | 72302 | } |
| 72130 | 72303 | break; |
| | @@ -72327,11 +72500,11 @@ |
| 72327 | 72500 | p->inVtabMethod = 0; |
| 72328 | 72501 | sqlite3VtabImportErrmsg(p, pVtab); |
| 72329 | 72502 | if( rc==SQLITE_OK ){ |
| 72330 | 72503 | res = pModule->xEof(pVtabCursor); |
| 72331 | 72504 | } |
| 72332 | | - |
| 72505 | + VdbeBranchTaken(res!=0,2); |
| 72333 | 72506 | if( res ){ |
| 72334 | 72507 | pc = pOp->p2 - 1; |
| 72335 | 72508 | } |
| 72336 | 72509 | } |
| 72337 | 72510 | pCur->nullRow = 0; |
| | @@ -72432,11 +72605,11 @@ |
| 72432 | 72605 | p->inVtabMethod = 0; |
| 72433 | 72606 | sqlite3VtabImportErrmsg(p, pVtab); |
| 72434 | 72607 | if( rc==SQLITE_OK ){ |
| 72435 | 72608 | res = pModule->xEof(pCur->pVtabCursor); |
| 72436 | 72609 | } |
| 72437 | | - |
| 72610 | + VdbeBranchTaken(!res,2); |
| 72438 | 72611 | if( !res ){ |
| 72439 | 72612 | /* If there is data, jump to P2 */ |
| 72440 | 72613 | pc = pOp->p2 - 1; |
| 72441 | 72614 | } |
| 72442 | 72615 | goto check_for_interrupt; |
| | @@ -72473,11 +72646,11 @@ |
| 72473 | 72646 | break; |
| 72474 | 72647 | } |
| 72475 | 72648 | #endif |
| 72476 | 72649 | |
| 72477 | 72650 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 72478 | | -/* Opcode: VUpdate P1 P2 P3 P4 * |
| 72651 | +/* Opcode: VUpdate P1 P2 P3 P4 P5 |
| 72479 | 72652 | ** Synopsis: data=r[P3@P2] |
| 72480 | 72653 | ** |
| 72481 | 72654 | ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure. |
| 72482 | 72655 | ** This opcode invokes the corresponding xUpdate method. P2 values |
| 72483 | 72656 | ** are contiguous memory cells starting at P3 to pass to the xUpdate |
| | @@ -72496,10 +72669,13 @@ |
| 72496 | 72669 | ** a row to delete. |
| 72497 | 72670 | ** |
| 72498 | 72671 | ** P1 is a boolean flag. If it is set to true and the xUpdate call |
| 72499 | 72672 | ** is successful, then the value returned by sqlite3_last_insert_rowid() |
| 72500 | 72673 | ** is set to the value of the rowid for the row just inserted. |
| 72674 | +** |
| 72675 | +** P5 is the error actions (OE_Replace, OE_Fail, OE_Ignore, etc) to |
| 72676 | +** apply in the case of a constraint failure on an insert or update. |
| 72501 | 72677 | */ |
| 72502 | 72678 | case OP_VUpdate: { |
| 72503 | 72679 | sqlite3_vtab *pVtab; |
| 72504 | 72680 | sqlite3_module *pModule; |
| 72505 | 72681 | int nArg; |
| | @@ -72584,20 +72760,30 @@ |
| 72584 | 72760 | break; |
| 72585 | 72761 | } |
| 72586 | 72762 | #endif |
| 72587 | 72763 | |
| 72588 | 72764 | |
| 72589 | | -#ifndef SQLITE_OMIT_TRACE |
| 72590 | | -/* Opcode: Trace * * * P4 * |
| 72765 | +/* Opcode: Init * P2 * P4 * |
| 72766 | +** Synopsis: Start at P2 |
| 72767 | +** |
| 72768 | +** Programs contain a single instance of this opcode as the very first |
| 72769 | +** opcode. |
| 72591 | 72770 | ** |
| 72592 | 72771 | ** If tracing is enabled (by the sqlite3_trace()) interface, then |
| 72593 | 72772 | ** the UTF-8 string contained in P4 is emitted on the trace callback. |
| 72773 | +** Or if P4 is blank, use the string returned by sqlite3_sql(). |
| 72774 | +** |
| 72775 | +** If P2 is not zero, jump to instruction P2. |
| 72594 | 72776 | */ |
| 72595 | | -case OP_Trace: { |
| 72777 | +case OP_Init: { /* jump */ |
| 72596 | 72778 | char *zTrace; |
| 72597 | 72779 | char *z; |
| 72598 | 72780 | |
| 72781 | + if( pOp->p2 ){ |
| 72782 | + pc = pOp->p2 - 1; |
| 72783 | + } |
| 72784 | +#ifndef SQLITE_OMIT_TRACE |
| 72599 | 72785 | if( db->xTrace |
| 72600 | 72786 | && !p->doingRerun |
| 72601 | 72787 | && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 |
| 72602 | 72788 | ){ |
| 72603 | 72789 | z = sqlite3VdbeExpandSql(p, zTrace); |
| | @@ -72619,13 +72805,13 @@ |
| 72619 | 72805 | && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 |
| 72620 | 72806 | ){ |
| 72621 | 72807 | sqlite3DebugPrintf("SQL-trace: %s\n", zTrace); |
| 72622 | 72808 | } |
| 72623 | 72809 | #endif /* SQLITE_DEBUG */ |
| 72810 | +#endif /* SQLITE_OMIT_TRACE */ |
| 72624 | 72811 | break; |
| 72625 | 72812 | } |
| 72626 | | -#endif |
| 72627 | 72813 | |
| 72628 | 72814 | |
| 72629 | 72815 | /* Opcode: Noop * * * * * |
| 72630 | 72816 | ** |
| 72631 | 72817 | ** Do nothing. This instruction is often useful as a jump |
| | @@ -72653,14 +72839,10 @@ |
| 72653 | 72839 | #ifdef VDBE_PROFILE |
| 72654 | 72840 | { |
| 72655 | 72841 | u64 elapsed = sqlite3Hwtime() - start; |
| 72656 | 72842 | pOp->cycles += elapsed; |
| 72657 | 72843 | pOp->cnt++; |
| 72658 | | -#if 0 |
| 72659 | | - fprintf(stdout, "%10llu ", elapsed); |
| 72660 | | - sqlite3VdbePrintOp(stdout, origPc, &aOp[origPc]); |
| 72661 | | -#endif |
| 72662 | 72844 | } |
| 72663 | 72845 | #endif |
| 72664 | 72846 | |
| 72665 | 72847 | /* The following code adds nothing to the actual functionality |
| 72666 | 72848 | ** of the program. It is only here for testing and debugging. |
| | @@ -72882,26 +73064,24 @@ |
| 72882 | 73064 | ** |
| 72883 | 73065 | ** The sqlite3_blob_close() function finalizes the vdbe program, |
| 72884 | 73066 | ** which closes the b-tree cursor and (possibly) commits the |
| 72885 | 73067 | ** transaction. |
| 72886 | 73068 | */ |
| 73069 | + static const int iLn = __LINE__+4; |
| 72887 | 73070 | static const VdbeOpList openBlob[] = { |
| 72888 | | - {OP_Transaction, 0, 0, 0}, /* 0: Start a transaction */ |
| 72889 | | - {OP_VerifyCookie, 0, 0, 0}, /* 1: Check the schema cookie */ |
| 72890 | | - {OP_TableLock, 0, 0, 0}, /* 2: Acquire a read or write lock */ |
| 72891 | | - |
| 73071 | + /* {OP_Transaction, 0, 0, 0}, // 0: Inserted separately */ |
| 73072 | + {OP_TableLock, 0, 0, 0}, /* 1: Acquire a read or write lock */ |
| 72892 | 73073 | /* One of the following two instructions is replaced by an OP_Noop. */ |
| 72893 | | - {OP_OpenRead, 0, 0, 0}, /* 3: Open cursor 0 for reading */ |
| 72894 | | - {OP_OpenWrite, 0, 0, 0}, /* 4: Open cursor 0 for read/write */ |
| 72895 | | - |
| 72896 | | - {OP_Variable, 1, 1, 1}, /* 5: Push the rowid to the stack */ |
| 72897 | | - {OP_NotExists, 0, 10, 1}, /* 6: Seek the cursor */ |
| 72898 | | - {OP_Column, 0, 0, 1}, /* 7 */ |
| 72899 | | - {OP_ResultRow, 1, 0, 0}, /* 8 */ |
| 72900 | | - {OP_Goto, 0, 5, 0}, /* 9 */ |
| 72901 | | - {OP_Close, 0, 0, 0}, /* 10 */ |
| 72902 | | - {OP_Halt, 0, 0, 0}, /* 11 */ |
| 73074 | + {OP_OpenRead, 0, 0, 0}, /* 2: Open cursor 0 for reading */ |
| 73075 | + {OP_OpenWrite, 0, 0, 0}, /* 3: Open cursor 0 for read/write */ |
| 73076 | + {OP_Variable, 1, 1, 1}, /* 4: Push the rowid to the stack */ |
| 73077 | + {OP_NotExists, 0, 10, 1}, /* 5: Seek the cursor */ |
| 73078 | + {OP_Column, 0, 0, 1}, /* 6 */ |
| 73079 | + {OP_ResultRow, 1, 0, 0}, /* 7 */ |
| 73080 | + {OP_Goto, 0, 4, 0}, /* 8 */ |
| 73081 | + {OP_Close, 0, 0, 0}, /* 9 */ |
| 73082 | + {OP_Halt, 0, 0, 0}, /* 10 */ |
| 72903 | 73083 | }; |
| 72904 | 73084 | |
| 72905 | 73085 | int rc = SQLITE_OK; |
| 72906 | 73086 | char *zErr = 0; |
| 72907 | 73087 | Table *pTab; |
| | @@ -73010,50 +73190,45 @@ |
| 73010 | 73190 | assert( pBlob->pStmt || db->mallocFailed ); |
| 73011 | 73191 | if( pBlob->pStmt ){ |
| 73012 | 73192 | Vdbe *v = (Vdbe *)pBlob->pStmt; |
| 73013 | 73193 | int iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 73014 | 73194 | |
| 73015 | | - sqlite3VdbeAddOpList(v, sizeof(openBlob)/sizeof(VdbeOpList), openBlob); |
| 73016 | | - |
| 73017 | | - |
| 73018 | | - /* Configure the OP_Transaction */ |
| 73019 | | - sqlite3VdbeChangeP1(v, 0, iDb); |
| 73020 | | - sqlite3VdbeChangeP2(v, 0, flags); |
| 73021 | | - |
| 73022 | | - /* Configure the OP_VerifyCookie */ |
| 73023 | | - sqlite3VdbeChangeP1(v, 1, iDb); |
| 73024 | | - sqlite3VdbeChangeP2(v, 1, pTab->pSchema->schema_cookie); |
| 73025 | | - sqlite3VdbeChangeP3(v, 1, pTab->pSchema->iGeneration); |
| 73195 | + |
| 73196 | + sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, flags, |
| 73197 | + pTab->pSchema->schema_cookie, |
| 73198 | + pTab->pSchema->iGeneration); |
| 73199 | + sqlite3VdbeChangeP5(v, 1); |
| 73200 | + sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn); |
| 73026 | 73201 | |
| 73027 | 73202 | /* Make sure a mutex is held on the table to be accessed */ |
| 73028 | 73203 | sqlite3VdbeUsesBtree(v, iDb); |
| 73029 | 73204 | |
| 73030 | 73205 | /* Configure the OP_TableLock instruction */ |
| 73031 | 73206 | #ifdef SQLITE_OMIT_SHARED_CACHE |
| 73032 | | - sqlite3VdbeChangeToNoop(v, 2); |
| 73207 | + sqlite3VdbeChangeToNoop(v, 1); |
| 73033 | 73208 | #else |
| 73034 | | - sqlite3VdbeChangeP1(v, 2, iDb); |
| 73035 | | - sqlite3VdbeChangeP2(v, 2, pTab->tnum); |
| 73036 | | - sqlite3VdbeChangeP3(v, 2, flags); |
| 73037 | | - sqlite3VdbeChangeP4(v, 2, pTab->zName, P4_TRANSIENT); |
| 73209 | + sqlite3VdbeChangeP1(v, 1, iDb); |
| 73210 | + sqlite3VdbeChangeP2(v, 1, pTab->tnum); |
| 73211 | + sqlite3VdbeChangeP3(v, 1, flags); |
| 73212 | + sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT); |
| 73038 | 73213 | #endif |
| 73039 | 73214 | |
| 73040 | 73215 | /* Remove either the OP_OpenWrite or OpenRead. Set the P2 |
| 73041 | 73216 | ** parameter of the other to pTab->tnum. */ |
| 73042 | | - sqlite3VdbeChangeToNoop(v, 4 - flags); |
| 73043 | | - sqlite3VdbeChangeP2(v, 3 + flags, pTab->tnum); |
| 73044 | | - sqlite3VdbeChangeP3(v, 3 + flags, iDb); |
| 73217 | + sqlite3VdbeChangeToNoop(v, 3 - flags); |
| 73218 | + sqlite3VdbeChangeP2(v, 2 + flags, pTab->tnum); |
| 73219 | + sqlite3VdbeChangeP3(v, 2 + flags, iDb); |
| 73045 | 73220 | |
| 73046 | 73221 | /* Configure the number of columns. Configure the cursor to |
| 73047 | 73222 | ** think that the table has one more column than it really |
| 73048 | 73223 | ** does. An OP_Column to retrieve this imaginary column will |
| 73049 | 73224 | ** always return an SQL NULL. This is useful because it means |
| 73050 | 73225 | ** we can invoke OP_Column to fill in the vdbe cursors type |
| 73051 | 73226 | ** and offset cache without causing any IO. |
| 73052 | 73227 | */ |
| 73053 | | - sqlite3VdbeChangeP4(v, 3+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32); |
| 73054 | | - sqlite3VdbeChangeP2(v, 7, pTab->nCol); |
| 73228 | + sqlite3VdbeChangeP4(v, 2+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32); |
| 73229 | + sqlite3VdbeChangeP2(v, 6, pTab->nCol); |
| 73055 | 73230 | if( !db->mallocFailed ){ |
| 73056 | 73231 | pParse->nVar = 1; |
| 73057 | 73232 | pParse->nMem = 1; |
| 73058 | 73233 | pParse->nTab = 1; |
| 73059 | 73234 | sqlite3VdbeMakeReady(v, pParse); |
| | @@ -75317,12 +75492,12 @@ |
| 75317 | 75492 | #endif /* !defined(SQLITE_OMIT_TRIGGER) */ |
| 75318 | 75493 | |
| 75319 | 75494 | /* |
| 75320 | 75495 | ** Perhaps the name is a reference to the ROWID |
| 75321 | 75496 | */ |
| 75322 | | - assert( pTab!=0 || cntTab==0 ); |
| 75323 | | - if( cnt==0 && cntTab==1 && sqlite3IsRowid(zCol) && HasRowid(pTab) ){ |
| 75497 | + if( cnt==0 && cntTab==1 && pMatch && sqlite3IsRowid(zCol) |
| 75498 | + && HasRowid(pMatch->pTab) ){ |
| 75324 | 75499 | cnt = 1; |
| 75325 | 75500 | pExpr->iColumn = -1; /* IMP: R-44911-55124 */ |
| 75326 | 75501 | pExpr->affinity = SQLITE_AFF_INTEGER; |
| 75327 | 75502 | } |
| 75328 | 75503 | |
| | @@ -77449,11 +77624,10 @@ |
| 77449 | 77624 | pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags); |
| 77450 | 77625 | pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags); |
| 77451 | 77626 | pNew->iLimit = 0; |
| 77452 | 77627 | pNew->iOffset = 0; |
| 77453 | 77628 | pNew->selFlags = p->selFlags & ~SF_UsesEphemeral; |
| 77454 | | - pNew->pRightmost = 0; |
| 77455 | 77629 | pNew->addrOpenEphm[0] = -1; |
| 77456 | 77630 | pNew->addrOpenEphm[1] = -1; |
| 77457 | 77631 | pNew->addrOpenEphm[2] = -1; |
| 77458 | 77632 | pNew->nSelectRow = p->nSelectRow; |
| 77459 | 77633 | pNew->pWith = withDup(db, p->pWith); |
| | @@ -77759,28 +77933,10 @@ |
| 77759 | 77933 | default: |
| 77760 | 77934 | return 1; |
| 77761 | 77935 | } |
| 77762 | 77936 | } |
| 77763 | 77937 | |
| 77764 | | -/* |
| 77765 | | -** Generate an OP_IsNull instruction that tests register iReg and jumps |
| 77766 | | -** to location iDest if the value in iReg is NULL. The value in iReg |
| 77767 | | -** was computed by pExpr. If we can look at pExpr at compile-time and |
| 77768 | | -** determine that it can never generate a NULL, then the OP_IsNull operation |
| 77769 | | -** can be omitted. |
| 77770 | | -*/ |
| 77771 | | -SQLITE_PRIVATE void sqlite3ExprCodeIsNullJump( |
| 77772 | | - Vdbe *v, /* The VDBE under construction */ |
| 77773 | | - const Expr *pExpr, /* Only generate OP_IsNull if this expr can be NULL */ |
| 77774 | | - int iReg, /* Test the value in this register for NULL */ |
| 77775 | | - int iDest /* Jump here if the value is null */ |
| 77776 | | -){ |
| 77777 | | - if( sqlite3ExprCanBeNull(pExpr) ){ |
| 77778 | | - sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iDest); |
| 77779 | | - } |
| 77780 | | -} |
| 77781 | | - |
| 77782 | 77938 | /* |
| 77783 | 77939 | ** Return TRUE if the given expression is a constant which would be |
| 77784 | 77940 | ** unchanged by OP_Affinity with the affinity given in the second |
| 77785 | 77941 | ** argument. |
| 77786 | 77942 | ** |
| | @@ -77973,11 +78129,11 @@ |
| 77973 | 78129 | assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */ |
| 77974 | 78130 | pTab = p->pSrc->a[0].pTab; |
| 77975 | 78131 | pExpr = p->pEList->a[0].pExpr; |
| 77976 | 78132 | iCol = (i16)pExpr->iColumn; |
| 77977 | 78133 | |
| 77978 | | - /* Code an OP_VerifyCookie and OP_TableLock for <table>. */ |
| 78134 | + /* Code an OP_Transaction and OP_TableLock for <table>. */ |
| 77979 | 78135 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 77980 | 78136 | sqlite3CodeVerifySchema(pParse, iDb); |
| 77981 | 78137 | sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); |
| 77982 | 78138 | |
| 77983 | 78139 | /* This function is only called from two places. In both cases the vdbe |
| | @@ -77984,13 +78140,12 @@ |
| 77984 | 78140 | ** has already been allocated. So assume sqlite3GetVdbe() is always |
| 77985 | 78141 | ** successful here. |
| 77986 | 78142 | */ |
| 77987 | 78143 | assert(v); |
| 77988 | 78144 | if( iCol<0 ){ |
| 77989 | | - int iAddr; |
| 77990 | | - |
| 77991 | | - iAddr = sqlite3CodeOnce(pParse); |
| 78145 | + int iAddr = sqlite3CodeOnce(pParse); |
| 78146 | + VdbeCoverage(v); |
| 77992 | 78147 | |
| 77993 | 78148 | sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead); |
| 77994 | 78149 | eType = IN_INDEX_ROWID; |
| 77995 | 78150 | |
| 77996 | 78151 | sqlite3VdbeJumpHere(v, iAddr); |
| | @@ -78011,22 +78166,22 @@ |
| 78011 | 78166 | for(pIdx=pTab->pIndex; pIdx && eType==0 && affinity_ok; pIdx=pIdx->pNext){ |
| 78012 | 78167 | if( (pIdx->aiColumn[0]==iCol) |
| 78013 | 78168 | && sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq |
| 78014 | 78169 | && (!mustBeUnique || (pIdx->nKeyCol==1 && pIdx->onError!=OE_None)) |
| 78015 | 78170 | ){ |
| 78016 | | - int iAddr = sqlite3CodeOnce(pParse); |
| 78171 | + int iAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v); |
| 78017 | 78172 | sqlite3VdbeAddOp3(v, OP_OpenRead, iTab, pIdx->tnum, iDb); |
| 78018 | 78173 | sqlite3VdbeSetP4KeyInfo(pParse, pIdx); |
| 78019 | 78174 | VdbeComment((v, "%s", pIdx->zName)); |
| 78020 | 78175 | assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 ); |
| 78021 | 78176 | eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0]; |
| 78022 | 78177 | |
| 78023 | | - sqlite3VdbeJumpHere(v, iAddr); |
| 78024 | 78178 | if( prNotFound && !pTab->aCol[iCol].notNull ){ |
| 78025 | 78179 | *prNotFound = ++pParse->nMem; |
| 78026 | 78180 | sqlite3VdbeAddOp2(v, OP_Null, 0, *prNotFound); |
| 78027 | 78181 | } |
| 78182 | + sqlite3VdbeJumpHere(v, iAddr); |
| 78028 | 78183 | } |
| 78029 | 78184 | } |
| 78030 | 78185 | } |
| 78031 | 78186 | } |
| 78032 | 78187 | |
| | @@ -78111,11 +78266,11 @@ |
| 78111 | 78266 | ** |
| 78112 | 78267 | ** If all of the above are false, then we can run this code just once |
| 78113 | 78268 | ** save the results, and reuse the same result on subsequent invocations. |
| 78114 | 78269 | */ |
| 78115 | 78270 | if( !ExprHasProperty(pExpr, EP_VarSelect) ){ |
| 78116 | | - testAddr = sqlite3CodeOnce(pParse); |
| 78271 | + testAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v); |
| 78117 | 78272 | } |
| 78118 | 78273 | |
| 78119 | 78274 | #ifndef SQLITE_OMIT_EXPLAIN |
| 78120 | 78275 | if( pParse->explain==2 ){ |
| 78121 | 78276 | char *zMsg = sqlite3MPrintf( |
| | @@ -78152,11 +78307,10 @@ |
| 78152 | 78307 | ** 'x' nor the SELECT... statement are columns, then numeric affinity |
| 78153 | 78308 | ** is used. |
| 78154 | 78309 | */ |
| 78155 | 78310 | pExpr->iTable = pParse->nTab++; |
| 78156 | 78311 | addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid); |
| 78157 | | - if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED); |
| 78158 | 78312 | pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1, 1); |
| 78159 | 78313 | |
| 78160 | 78314 | if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 78161 | 78315 | /* Case 1: expr IN (SELECT ...) |
| 78162 | 78316 | ** |
| | @@ -78228,10 +78382,11 @@ |
| 78228 | 78382 | }else{ |
| 78229 | 78383 | r3 = sqlite3ExprCodeTarget(pParse, pE2, r1); |
| 78230 | 78384 | if( isRowid ){ |
| 78231 | 78385 | sqlite3VdbeAddOp2(v, OP_MustBeInt, r3, |
| 78232 | 78386 | sqlite3VdbeCurrentAddr(v)+2); |
| 78387 | + VdbeCoverage(v); |
| 78233 | 78388 | sqlite3VdbeAddOp3(v, OP_Insert, pExpr->iTable, r2, r3); |
| 78234 | 78389 | }else{ |
| 78235 | 78390 | sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1); |
| 78236 | 78391 | sqlite3ExprCacheAffinityChange(pParse, r3, 1); |
| 78237 | 78392 | sqlite3VdbeAddOp2(v, OP_IdxInsert, pExpr->iTable, r2); |
| | @@ -78351,23 +78506,25 @@ |
| 78351 | 78506 | ** on whether the RHS is empty or not, respectively. |
| 78352 | 78507 | */ |
| 78353 | 78508 | if( destIfNull==destIfFalse ){ |
| 78354 | 78509 | /* Shortcut for the common case where the false and NULL outcomes are |
| 78355 | 78510 | ** the same. */ |
| 78356 | | - sqlite3VdbeAddOp2(v, OP_IsNull, r1, destIfNull); |
| 78511 | + sqlite3VdbeAddOp2(v, OP_IsNull, r1, destIfNull); VdbeCoverage(v); |
| 78357 | 78512 | }else{ |
| 78358 | | - int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1); |
| 78513 | + int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1); VdbeCoverage(v); |
| 78359 | 78514 | sqlite3VdbeAddOp2(v, OP_Rewind, pExpr->iTable, destIfFalse); |
| 78515 | + VdbeCoverage(v); |
| 78360 | 78516 | sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull); |
| 78361 | 78517 | sqlite3VdbeJumpHere(v, addr1); |
| 78362 | 78518 | } |
| 78363 | 78519 | |
| 78364 | 78520 | if( eType==IN_INDEX_ROWID ){ |
| 78365 | 78521 | /* In this case, the RHS is the ROWID of table b-tree |
| 78366 | 78522 | */ |
| 78367 | | - sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, destIfFalse); |
| 78523 | + sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, destIfFalse); VdbeCoverage(v); |
| 78368 | 78524 | sqlite3VdbeAddOp3(v, OP_NotExists, pExpr->iTable, destIfFalse, r1); |
| 78525 | + VdbeCoverage(v); |
| 78369 | 78526 | }else{ |
| 78370 | 78527 | /* In this case, the RHS is an index b-tree. |
| 78371 | 78528 | */ |
| 78372 | 78529 | sqlite3VdbeAddOp4(v, OP_Affinity, r1, 1, 0, &affinity, 1); |
| 78373 | 78530 | |
| | @@ -78384,42 +78541,40 @@ |
| 78384 | 78541 | ** |
| 78385 | 78542 | ** Also run this branch if NULL is equivalent to FALSE |
| 78386 | 78543 | ** for this particular IN operator. |
| 78387 | 78544 | */ |
| 78388 | 78545 | sqlite3VdbeAddOp4Int(v, OP_NotFound, pExpr->iTable, destIfFalse, r1, 1); |
| 78389 | | - |
| 78546 | + VdbeCoverage(v); |
| 78390 | 78547 | }else{ |
| 78391 | 78548 | /* In this branch, the RHS of the IN might contain a NULL and |
| 78392 | 78549 | ** the presence of a NULL on the RHS makes a difference in the |
| 78393 | 78550 | ** outcome. |
| 78394 | 78551 | */ |
| 78395 | | - int j1, j2, j3; |
| 78552 | + int j1, j2; |
| 78396 | 78553 | |
| 78397 | 78554 | /* First check to see if the LHS is contained in the RHS. If so, |
| 78398 | 78555 | ** then the presence of NULLs in the RHS does not matter, so jump |
| 78399 | 78556 | ** over all of the code that follows. |
| 78400 | 78557 | */ |
| 78401 | 78558 | j1 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, r1, 1); |
| 78559 | + VdbeCoverage(v); |
| 78402 | 78560 | |
| 78403 | 78561 | /* Here we begin generating code that runs if the LHS is not |
| 78404 | 78562 | ** contained within the RHS. Generate additional code that |
| 78405 | 78563 | ** tests the RHS for NULLs. If the RHS contains a NULL then |
| 78406 | 78564 | ** jump to destIfNull. If there are no NULLs in the RHS then |
| 78407 | 78565 | ** jump to destIfFalse. |
| 78408 | 78566 | */ |
| 78409 | | - j2 = sqlite3VdbeAddOp1(v, OP_NotNull, rRhsHasNull); |
| 78410 | | - j3 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, rRhsHasNull, 1); |
| 78411 | | - sqlite3VdbeAddOp2(v, OP_Integer, -1, rRhsHasNull); |
| 78412 | | - sqlite3VdbeJumpHere(v, j3); |
| 78413 | | - sqlite3VdbeAddOp2(v, OP_AddImm, rRhsHasNull, 1); |
| 78567 | + sqlite3VdbeAddOp2(v, OP_If, rRhsHasNull, destIfNull); VdbeCoverage(v); |
| 78568 | + sqlite3VdbeAddOp2(v, OP_IfNot, rRhsHasNull, destIfFalse); VdbeCoverage(v); |
| 78569 | + j2 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, rRhsHasNull, 1); |
| 78570 | + VdbeCoverage(v); |
| 78571 | + sqlite3VdbeAddOp2(v, OP_Integer, 0, rRhsHasNull); |
| 78572 | + sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse); |
| 78414 | 78573 | sqlite3VdbeJumpHere(v, j2); |
| 78415 | | - |
| 78416 | | - /* Jump to the appropriate target depending on whether or not |
| 78417 | | - ** the RHS contains a NULL |
| 78418 | | - */ |
| 78419 | | - sqlite3VdbeAddOp2(v, OP_If, rRhsHasNull, destIfNull); |
| 78420 | | - sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse); |
| 78574 | + sqlite3VdbeAddOp2(v, OP_Integer, 1, rRhsHasNull); |
| 78575 | + sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull); |
| 78421 | 78576 | |
| 78422 | 78577 | /* The OP_Found at the top of this branch jumps here when true, |
| 78423 | 78578 | ** causing the overall IN expression evaluation to fall through. |
| 78424 | 78579 | */ |
| 78425 | 78580 | sqlite3VdbeJumpHere(v, j1); |
| | @@ -78936,26 +79091,20 @@ |
| 78936 | 79091 | case TK_LE: |
| 78937 | 79092 | case TK_GT: |
| 78938 | 79093 | case TK_GE: |
| 78939 | 79094 | case TK_NE: |
| 78940 | 79095 | case TK_EQ: { |
| 78941 | | - assert( TK_LT==OP_Lt ); |
| 78942 | | - assert( TK_LE==OP_Le ); |
| 78943 | | - assert( TK_GT==OP_Gt ); |
| 78944 | | - assert( TK_GE==OP_Ge ); |
| 78945 | | - assert( TK_EQ==OP_Eq ); |
| 78946 | | - assert( TK_NE==OP_Ne ); |
| 78947 | | - testcase( op==TK_LT ); |
| 78948 | | - testcase( op==TK_LE ); |
| 78949 | | - testcase( op==TK_GT ); |
| 78950 | | - testcase( op==TK_GE ); |
| 78951 | | - testcase( op==TK_EQ ); |
| 78952 | | - testcase( op==TK_NE ); |
| 78953 | 79096 | r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); |
| 78954 | 79097 | r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, ®Free2); |
| 78955 | 79098 | codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op, |
| 78956 | 79099 | r1, r2, inReg, SQLITE_STOREP2); |
| 79100 | + assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt); |
| 79101 | + assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le); |
| 79102 | + assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt); |
| 79103 | + assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge); |
| 79104 | + assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq); |
| 79105 | + assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne); |
| 78957 | 79106 | testcase( regFree1==0 ); |
| 78958 | 79107 | testcase( regFree2==0 ); |
| 78959 | 79108 | break; |
| 78960 | 79109 | } |
| 78961 | 79110 | case TK_IS: |
| | @@ -78965,10 +79114,12 @@ |
| 78965 | 79114 | r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); |
| 78966 | 79115 | r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, ®Free2); |
| 78967 | 79116 | op = (op==TK_IS) ? TK_EQ : TK_NE; |
| 78968 | 79117 | codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op, |
| 78969 | 79118 | r1, r2, inReg, SQLITE_STOREP2 | SQLITE_NULLEQ); |
| 79119 | + VdbeCoverageIf(v, op==TK_EQ); |
| 79120 | + VdbeCoverageIf(v, op==TK_NE); |
| 78970 | 79121 | testcase( regFree1==0 ); |
| 78971 | 79122 | testcase( regFree2==0 ); |
| 78972 | 79123 | break; |
| 78973 | 79124 | } |
| 78974 | 79125 | case TK_AND: |
| | @@ -78981,32 +79132,21 @@ |
| 78981 | 79132 | case TK_BITOR: |
| 78982 | 79133 | case TK_SLASH: |
| 78983 | 79134 | case TK_LSHIFT: |
| 78984 | 79135 | case TK_RSHIFT: |
| 78985 | 79136 | case TK_CONCAT: { |
| 78986 | | - assert( TK_AND==OP_And ); |
| 78987 | | - assert( TK_OR==OP_Or ); |
| 78988 | | - assert( TK_PLUS==OP_Add ); |
| 78989 | | - assert( TK_MINUS==OP_Subtract ); |
| 78990 | | - assert( TK_REM==OP_Remainder ); |
| 78991 | | - assert( TK_BITAND==OP_BitAnd ); |
| 78992 | | - assert( TK_BITOR==OP_BitOr ); |
| 78993 | | - assert( TK_SLASH==OP_Divide ); |
| 78994 | | - assert( TK_LSHIFT==OP_ShiftLeft ); |
| 78995 | | - assert( TK_RSHIFT==OP_ShiftRight ); |
| 78996 | | - assert( TK_CONCAT==OP_Concat ); |
| 78997 | | - testcase( op==TK_AND ); |
| 78998 | | - testcase( op==TK_OR ); |
| 78999 | | - testcase( op==TK_PLUS ); |
| 79000 | | - testcase( op==TK_MINUS ); |
| 79001 | | - testcase( op==TK_REM ); |
| 79002 | | - testcase( op==TK_BITAND ); |
| 79003 | | - testcase( op==TK_BITOR ); |
| 79004 | | - testcase( op==TK_SLASH ); |
| 79005 | | - testcase( op==TK_LSHIFT ); |
| 79006 | | - testcase( op==TK_RSHIFT ); |
| 79007 | | - testcase( op==TK_CONCAT ); |
| 79137 | + assert( TK_AND==OP_And ); testcase( op==TK_AND ); |
| 79138 | + assert( TK_OR==OP_Or ); testcase( op==TK_OR ); |
| 79139 | + assert( TK_PLUS==OP_Add ); testcase( op==TK_PLUS ); |
| 79140 | + assert( TK_MINUS==OP_Subtract ); testcase( op==TK_MINUS ); |
| 79141 | + assert( TK_REM==OP_Remainder ); testcase( op==TK_REM ); |
| 79142 | + assert( TK_BITAND==OP_BitAnd ); testcase( op==TK_BITAND ); |
| 79143 | + assert( TK_BITOR==OP_BitOr ); testcase( op==TK_BITOR ); |
| 79144 | + assert( TK_SLASH==OP_Divide ); testcase( op==TK_SLASH ); |
| 79145 | + assert( TK_LSHIFT==OP_ShiftLeft ); testcase( op==TK_LSHIFT ); |
| 79146 | + assert( TK_RSHIFT==OP_ShiftRight ); testcase( op==TK_RSHIFT ); |
| 79147 | + assert( TK_CONCAT==OP_Concat ); testcase( op==TK_CONCAT ); |
| 79008 | 79148 | r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); |
| 79009 | 79149 | r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, ®Free2); |
| 79010 | 79150 | sqlite3VdbeAddOp3(v, op, r2, r1, target); |
| 79011 | 79151 | testcase( regFree1==0 ); |
| 79012 | 79152 | testcase( regFree2==0 ); |
| | @@ -79034,31 +79174,29 @@ |
| 79034 | 79174 | inReg = target; |
| 79035 | 79175 | break; |
| 79036 | 79176 | } |
| 79037 | 79177 | case TK_BITNOT: |
| 79038 | 79178 | case TK_NOT: { |
| 79039 | | - assert( TK_BITNOT==OP_BitNot ); |
| 79040 | | - assert( TK_NOT==OP_Not ); |
| 79041 | | - testcase( op==TK_BITNOT ); |
| 79042 | | - testcase( op==TK_NOT ); |
| 79179 | + assert( TK_BITNOT==OP_BitNot ); testcase( op==TK_BITNOT ); |
| 79180 | + assert( TK_NOT==OP_Not ); testcase( op==TK_NOT ); |
| 79043 | 79181 | r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); |
| 79044 | 79182 | testcase( regFree1==0 ); |
| 79045 | 79183 | inReg = target; |
| 79046 | 79184 | sqlite3VdbeAddOp2(v, op, r1, inReg); |
| 79047 | 79185 | break; |
| 79048 | 79186 | } |
| 79049 | 79187 | case TK_ISNULL: |
| 79050 | 79188 | case TK_NOTNULL: { |
| 79051 | 79189 | int addr; |
| 79052 | | - assert( TK_ISNULL==OP_IsNull ); |
| 79053 | | - assert( TK_NOTNULL==OP_NotNull ); |
| 79054 | | - testcase( op==TK_ISNULL ); |
| 79055 | | - testcase( op==TK_NOTNULL ); |
| 79190 | + assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL ); |
| 79191 | + assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL ); |
| 79056 | 79192 | sqlite3VdbeAddOp2(v, OP_Integer, 1, target); |
| 79057 | 79193 | r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); |
| 79058 | 79194 | testcase( regFree1==0 ); |
| 79059 | 79195 | addr = sqlite3VdbeAddOp1(v, op, r1); |
| 79196 | + VdbeCoverageIf(v, op==TK_ISNULL); |
| 79197 | + VdbeCoverageIf(v, op==TK_NOTNULL); |
| 79060 | 79198 | sqlite3VdbeAddOp2(v, OP_AddImm, target, -1); |
| 79061 | 79199 | sqlite3VdbeJumpHere(v, addr); |
| 79062 | 79200 | break; |
| 79063 | 79201 | } |
| 79064 | 79202 | case TK_AGG_FUNCTION: { |
| | @@ -79106,10 +79244,11 @@ |
| 79106 | 79244 | int endCoalesce = sqlite3VdbeMakeLabel(v); |
| 79107 | 79245 | assert( nFarg>=2 ); |
| 79108 | 79246 | sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target); |
| 79109 | 79247 | for(i=1; i<nFarg; i++){ |
| 79110 | 79248 | sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce); |
| 79249 | + VdbeCoverage(v); |
| 79111 | 79250 | sqlite3ExprCacheRemove(pParse, target, 1); |
| 79112 | 79251 | sqlite3ExprCachePush(pParse); |
| 79113 | 79252 | sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target); |
| 79114 | 79253 | sqlite3ExprCachePop(pParse, 1); |
| 79115 | 79254 | } |
| | @@ -79243,17 +79382,18 @@ |
| 79243 | 79382 | testcase( regFree1==0 ); |
| 79244 | 79383 | testcase( regFree2==0 ); |
| 79245 | 79384 | r3 = sqlite3GetTempReg(pParse); |
| 79246 | 79385 | r4 = sqlite3GetTempReg(pParse); |
| 79247 | 79386 | codeCompare(pParse, pLeft, pRight, OP_Ge, |
| 79248 | | - r1, r2, r3, SQLITE_STOREP2); |
| 79387 | + r1, r2, r3, SQLITE_STOREP2); VdbeCoverage(v); |
| 79249 | 79388 | pLItem++; |
| 79250 | 79389 | pRight = pLItem->pExpr; |
| 79251 | 79390 | sqlite3ReleaseTempReg(pParse, regFree2); |
| 79252 | 79391 | r2 = sqlite3ExprCodeTemp(pParse, pRight, ®Free2); |
| 79253 | 79392 | testcase( regFree2==0 ); |
| 79254 | 79393 | codeCompare(pParse, pLeft, pRight, OP_Le, r1, r2, r4, SQLITE_STOREP2); |
| 79394 | + VdbeCoverage(v); |
| 79255 | 79395 | sqlite3VdbeAddOp3(v, OP_And, r3, r4, target); |
| 79256 | 79396 | sqlite3ReleaseTempReg(pParse, r3); |
| 79257 | 79397 | sqlite3ReleaseTempReg(pParse, r4); |
| 79258 | 79398 | break; |
| 79259 | 79399 | } |
| | @@ -79416,10 +79556,11 @@ |
| 79416 | 79556 | } |
| 79417 | 79557 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 79418 | 79558 | if( pExpr->affinity==OE_Ignore ){ |
| 79419 | 79559 | sqlite3VdbeAddOp4( |
| 79420 | 79560 | v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0); |
| 79561 | + VdbeCoverage(v); |
| 79421 | 79562 | }else{ |
| 79422 | 79563 | sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_TRIGGER, |
| 79423 | 79564 | pExpr->affinity, pExpr->u.zToken, 0, 0); |
| 79424 | 79565 | } |
| 79425 | 79566 | |
| | @@ -79503,11 +79644,11 @@ |
| 79503 | 79644 | /* |
| 79504 | 79645 | ** Generate code that will evaluate expression pExpr and store the |
| 79505 | 79646 | ** results in register target. The results are guaranteed to appear |
| 79506 | 79647 | ** in register target. |
| 79507 | 79648 | */ |
| 79508 | | -SQLITE_PRIVATE int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){ |
| 79649 | +SQLITE_PRIVATE void sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){ |
| 79509 | 79650 | int inReg; |
| 79510 | 79651 | |
| 79511 | 79652 | assert( target>0 && target<=pParse->nMem ); |
| 79512 | 79653 | if( pExpr && pExpr->op==TK_REGISTER ){ |
| 79513 | 79654 | sqlite3VdbeAddOp2(pParse->pVdbe, OP_Copy, pExpr->iTable, target); |
| | @@ -79516,11 +79657,24 @@ |
| 79516 | 79657 | assert( pParse->pVdbe || pParse->db->mallocFailed ); |
| 79517 | 79658 | if( inReg!=target && pParse->pVdbe ){ |
| 79518 | 79659 | sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, inReg, target); |
| 79519 | 79660 | } |
| 79520 | 79661 | } |
| 79521 | | - return target; |
| 79662 | +} |
| 79663 | + |
| 79664 | +/* |
| 79665 | +** Generate code that will evaluate expression pExpr and store the |
| 79666 | +** results in register target. The results are guaranteed to appear |
| 79667 | +** in register target. If the expression is constant, then this routine |
| 79668 | +** might choose to code the expression at initialization time. |
| 79669 | +*/ |
| 79670 | +SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse *pParse, Expr *pExpr, int target){ |
| 79671 | + if( pParse->okConstFactor && sqlite3ExprIsConstant(pExpr) ){ |
| 79672 | + sqlite3ExprCodeAtInit(pParse, pExpr, target, 0); |
| 79673 | + }else{ |
| 79674 | + sqlite3ExprCode(pParse, pExpr, target); |
| 79675 | + } |
| 79522 | 79676 | } |
| 79523 | 79677 | |
| 79524 | 79678 | /* |
| 79525 | 79679 | ** Generate code that evalutes the given expression and puts the result |
| 79526 | 79680 | ** in register target. |
| | @@ -79531,29 +79685,20 @@ |
| 79531 | 79685 | ** |
| 79532 | 79686 | ** This routine is used for expressions that are used multiple |
| 79533 | 79687 | ** times. They are evaluated once and the results of the expression |
| 79534 | 79688 | ** are reused. |
| 79535 | 79689 | */ |
| 79536 | | -SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){ |
| 79690 | +SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){ |
| 79537 | 79691 | Vdbe *v = pParse->pVdbe; |
| 79538 | | - int inReg; |
| 79539 | | - inReg = sqlite3ExprCode(pParse, pExpr, target); |
| 79692 | + int iMem; |
| 79693 | + |
| 79540 | 79694 | assert( target>0 ); |
| 79541 | | - /* The only place, other than this routine, where expressions can be |
| 79542 | | - ** converted to TK_REGISTER is internal subexpressions in BETWEEN and |
| 79543 | | - ** CASE operators. Neither ever calls this routine. And this routine |
| 79544 | | - ** is never called twice on the same expression. Hence it is impossible |
| 79545 | | - ** for the input to this routine to already be a register. Nevertheless, |
| 79546 | | - ** it seems prudent to keep the ALWAYS() in case the conditions above |
| 79547 | | - ** change with future modifications or enhancements. */ |
| 79548 | | - if( ALWAYS(pExpr->op!=TK_REGISTER) ){ |
| 79549 | | - int iMem; |
| 79550 | | - iMem = ++pParse->nMem; |
| 79551 | | - sqlite3VdbeAddOp2(v, OP_Copy, inReg, iMem); |
| 79552 | | - exprToRegister(pExpr, iMem); |
| 79553 | | - } |
| 79554 | | - return inReg; |
| 79695 | + assert( pExpr->op!=TK_REGISTER ); |
| 79696 | + sqlite3ExprCode(pParse, pExpr, target); |
| 79697 | + iMem = ++pParse->nMem; |
| 79698 | + sqlite3VdbeAddOp2(v, OP_Copy, target, iMem); |
| 79699 | + exprToRegister(pExpr, iMem); |
| 79555 | 79700 | } |
| 79556 | 79701 | |
| 79557 | 79702 | #if defined(SQLITE_ENABLE_TREE_EXPLAIN) |
| 79558 | 79703 | /* |
| 79559 | 79704 | ** Generate a human-readable explanation of an expression tree. |
| | @@ -79984,27 +80129,21 @@ |
| 79984 | 80129 | case TK_LE: |
| 79985 | 80130 | case TK_GT: |
| 79986 | 80131 | case TK_GE: |
| 79987 | 80132 | case TK_NE: |
| 79988 | 80133 | case TK_EQ: { |
| 79989 | | - assert( TK_LT==OP_Lt ); |
| 79990 | | - assert( TK_LE==OP_Le ); |
| 79991 | | - assert( TK_GT==OP_Gt ); |
| 79992 | | - assert( TK_GE==OP_Ge ); |
| 79993 | | - assert( TK_EQ==OP_Eq ); |
| 79994 | | - assert( TK_NE==OP_Ne ); |
| 79995 | | - testcase( op==TK_LT ); |
| 79996 | | - testcase( op==TK_LE ); |
| 79997 | | - testcase( op==TK_GT ); |
| 79998 | | - testcase( op==TK_GE ); |
| 79999 | | - testcase( op==TK_EQ ); |
| 80000 | | - testcase( op==TK_NE ); |
| 80001 | 80134 | testcase( jumpIfNull==0 ); |
| 80002 | 80135 | r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); |
| 80003 | 80136 | r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, ®Free2); |
| 80004 | 80137 | codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op, |
| 80005 | 80138 | r1, r2, dest, jumpIfNull); |
| 80139 | + assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt); |
| 80140 | + assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le); |
| 80141 | + assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt); |
| 80142 | + assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge); |
| 80143 | + assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq); |
| 80144 | + assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne); |
| 80006 | 80145 | testcase( regFree1==0 ); |
| 80007 | 80146 | testcase( regFree2==0 ); |
| 80008 | 80147 | break; |
| 80009 | 80148 | } |
| 80010 | 80149 | case TK_IS: |
| | @@ -80014,22 +80153,24 @@ |
| 80014 | 80153 | r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); |
| 80015 | 80154 | r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, ®Free2); |
| 80016 | 80155 | op = (op==TK_IS) ? TK_EQ : TK_NE; |
| 80017 | 80156 | codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op, |
| 80018 | 80157 | r1, r2, dest, SQLITE_NULLEQ); |
| 80158 | + VdbeCoverageIf(v, op==TK_EQ); |
| 80159 | + VdbeCoverageIf(v, op==TK_NE); |
| 80019 | 80160 | testcase( regFree1==0 ); |
| 80020 | 80161 | testcase( regFree2==0 ); |
| 80021 | 80162 | break; |
| 80022 | 80163 | } |
| 80023 | 80164 | case TK_ISNULL: |
| 80024 | 80165 | case TK_NOTNULL: { |
| 80025 | | - assert( TK_ISNULL==OP_IsNull ); |
| 80026 | | - assert( TK_NOTNULL==OP_NotNull ); |
| 80027 | | - testcase( op==TK_ISNULL ); |
| 80028 | | - testcase( op==TK_NOTNULL ); |
| 80166 | + assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL ); |
| 80167 | + assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL ); |
| 80029 | 80168 | r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); |
| 80030 | 80169 | sqlite3VdbeAddOp2(v, op, r1, dest); |
| 80170 | + VdbeCoverageIf(v, op==TK_ISNULL); |
| 80171 | + VdbeCoverageIf(v, op==TK_NOTNULL); |
| 80031 | 80172 | testcase( regFree1==0 ); |
| 80032 | 80173 | break; |
| 80033 | 80174 | } |
| 80034 | 80175 | case TK_BETWEEN: { |
| 80035 | 80176 | testcase( jumpIfNull==0 ); |
| | @@ -80052,10 +80193,11 @@ |
| 80052 | 80193 | }else if( exprAlwaysFalse(pExpr) ){ |
| 80053 | 80194 | /* No-op */ |
| 80054 | 80195 | }else{ |
| 80055 | 80196 | r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); |
| 80056 | 80197 | sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0); |
| 80198 | + VdbeCoverage(v); |
| 80057 | 80199 | testcase( regFree1==0 ); |
| 80058 | 80200 | testcase( jumpIfNull==0 ); |
| 80059 | 80201 | } |
| 80060 | 80202 | break; |
| 80061 | 80203 | } |
| | @@ -80143,21 +80285,21 @@ |
| 80143 | 80285 | case TK_LE: |
| 80144 | 80286 | case TK_GT: |
| 80145 | 80287 | case TK_GE: |
| 80146 | 80288 | case TK_NE: |
| 80147 | 80289 | case TK_EQ: { |
| 80148 | | - testcase( op==TK_LT ); |
| 80149 | | - testcase( op==TK_LE ); |
| 80150 | | - testcase( op==TK_GT ); |
| 80151 | | - testcase( op==TK_GE ); |
| 80152 | | - testcase( op==TK_EQ ); |
| 80153 | | - testcase( op==TK_NE ); |
| 80154 | 80290 | testcase( jumpIfNull==0 ); |
| 80155 | 80291 | r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); |
| 80156 | 80292 | r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, ®Free2); |
| 80157 | 80293 | codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op, |
| 80158 | 80294 | r1, r2, dest, jumpIfNull); |
| 80295 | + assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt); |
| 80296 | + assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le); |
| 80297 | + assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt); |
| 80298 | + assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge); |
| 80299 | + assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq); |
| 80300 | + assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne); |
| 80159 | 80301 | testcase( regFree1==0 ); |
| 80160 | 80302 | testcase( regFree2==0 ); |
| 80161 | 80303 | break; |
| 80162 | 80304 | } |
| 80163 | 80305 | case TK_IS: |
| | @@ -80167,20 +80309,22 @@ |
| 80167 | 80309 | r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); |
| 80168 | 80310 | r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, ®Free2); |
| 80169 | 80311 | op = (pExpr->op==TK_IS) ? TK_NE : TK_EQ; |
| 80170 | 80312 | codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op, |
| 80171 | 80313 | r1, r2, dest, SQLITE_NULLEQ); |
| 80314 | + VdbeCoverageIf(v, op==TK_EQ); |
| 80315 | + VdbeCoverageIf(v, op==TK_NE); |
| 80172 | 80316 | testcase( regFree1==0 ); |
| 80173 | 80317 | testcase( regFree2==0 ); |
| 80174 | 80318 | break; |
| 80175 | 80319 | } |
| 80176 | 80320 | case TK_ISNULL: |
| 80177 | 80321 | case TK_NOTNULL: { |
| 80178 | | - testcase( op==TK_ISNULL ); |
| 80179 | | - testcase( op==TK_NOTNULL ); |
| 80180 | 80322 | r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free1); |
| 80181 | 80323 | sqlite3VdbeAddOp2(v, op, r1, dest); |
| 80324 | + testcase( op==TK_ISNULL ); VdbeCoverageIf(v, op==TK_ISNULL); |
| 80325 | + testcase( op==TK_NOTNULL ); VdbeCoverageIf(v, op==TK_NOTNULL); |
| 80182 | 80326 | testcase( regFree1==0 ); |
| 80183 | 80327 | break; |
| 80184 | 80328 | } |
| 80185 | 80329 | case TK_BETWEEN: { |
| 80186 | 80330 | testcase( jumpIfNull==0 ); |
| | @@ -80205,10 +80349,11 @@ |
| 80205 | 80349 | }else if( exprAlwaysTrue(pExpr) ){ |
| 80206 | 80350 | /* no-op */ |
| 80207 | 80351 | }else{ |
| 80208 | 80352 | r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); |
| 80209 | 80353 | sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0); |
| 80354 | + VdbeCoverage(v); |
| 80210 | 80355 | testcase( regFree1==0 ); |
| 80211 | 80356 | testcase( jumpIfNull==0 ); |
| 80212 | 80357 | } |
| 80213 | 80358 | break; |
| 80214 | 80359 | } |
| | @@ -80751,12 +80896,12 @@ |
| 80751 | 80896 | len = sqlite3GetToken(zCsr, &token); |
| 80752 | 80897 | } while( token==TK_SPACE ); |
| 80753 | 80898 | assert( len>0 ); |
| 80754 | 80899 | } while( token!=TK_LP && token!=TK_USING ); |
| 80755 | 80900 | |
| 80756 | | - zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql, |
| 80757 | | - zTableName, tname.z+tname.n); |
| 80901 | + zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", (int)(((u8*)tname.z) - zSql), |
| 80902 | + zSql, zTableName, tname.z+tname.n); |
| 80758 | 80903 | sqlite3_result_text(context, zRet, -1, SQLITE_DYNAMIC); |
| 80759 | 80904 | } |
| 80760 | 80905 | } |
| 80761 | 80906 | |
| 80762 | 80907 | /* |
| | @@ -80804,11 +80949,11 @@ |
| 80804 | 80949 | zParent = sqlite3DbStrNDup(db, (const char *)z, n); |
| 80805 | 80950 | if( zParent==0 ) break; |
| 80806 | 80951 | sqlite3Dequote(zParent); |
| 80807 | 80952 | if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){ |
| 80808 | 80953 | char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"", |
| 80809 | | - (zOutput?zOutput:""), z-zInput, zInput, (const char *)zNew |
| 80954 | + (zOutput?zOutput:""), (int)(z-zInput), zInput, (const char *)zNew |
| 80810 | 80955 | ); |
| 80811 | 80956 | sqlite3DbFree(db, zOutput); |
| 80812 | 80957 | zOutput = zOut; |
| 80813 | 80958 | zInput = &z[n]; |
| 80814 | 80959 | } |
| | @@ -80890,12 +81035,12 @@ |
| 80890 | 81035 | } while( dist!=2 || (token!=TK_WHEN && token!=TK_FOR && token!=TK_BEGIN) ); |
| 80891 | 81036 | |
| 80892 | 81037 | /* Variable tname now contains the token that is the old table-name |
| 80893 | 81038 | ** in the CREATE TRIGGER statement. |
| 80894 | 81039 | */ |
| 80895 | | - zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql, |
| 80896 | | - zTableName, tname.z+tname.n); |
| 81040 | + zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", (int)(((u8*)tname.z) - zSql), |
| 81041 | + zSql, zTableName, tname.z+tname.n); |
| 80897 | 81042 | sqlite3_result_text(context, zRet, -1, SQLITE_DYNAMIC); |
| 80898 | 81043 | } |
| 80899 | 81044 | } |
| 80900 | 81045 | #endif /* !SQLITE_OMIT_TRIGGER */ |
| 80901 | 81046 | |
| | @@ -81143,11 +81288,11 @@ |
| 81143 | 81288 | pVTab = 0; |
| 81144 | 81289 | } |
| 81145 | 81290 | } |
| 81146 | 81291 | #endif |
| 81147 | 81292 | |
| 81148 | | - /* Begin a transaction and code the VerifyCookie for database iDb. |
| 81293 | + /* Begin a transaction for database iDb. |
| 81149 | 81294 | ** Then modify the schema cookie (since the ALTER TABLE modifies the |
| 81150 | 81295 | ** schema). Open a statement transaction if the table is a virtual |
| 81151 | 81296 | ** table. |
| 81152 | 81297 | */ |
| 81153 | 81298 | v = sqlite3GetVdbe(pParse); |
| | @@ -81279,10 +81424,11 @@ |
| 81279 | 81424 | int j1; |
| 81280 | 81425 | sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT); |
| 81281 | 81426 | sqlite3VdbeUsesBtree(v, iDb); |
| 81282 | 81427 | sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2); |
| 81283 | 81428 | j1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1); |
| 81429 | + sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); VdbeCoverage(v); |
| 81284 | 81430 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, r2); |
| 81285 | 81431 | sqlite3VdbeJumpHere(v, j1); |
| 81286 | 81432 | sqlite3ReleaseTempReg(pParse, r1); |
| 81287 | 81433 | sqlite3ReleaseTempReg(pParse, r2); |
| 81288 | 81434 | } |
| | @@ -82579,10 +82725,11 @@ |
| 82579 | 82725 | ** regChng = 0 |
| 82580 | 82726 | ** goto next_push_0; |
| 82581 | 82727 | ** |
| 82582 | 82728 | */ |
| 82583 | 82729 | addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur); |
| 82730 | + VdbeCoverage(v); |
| 82584 | 82731 | sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng); |
| 82585 | 82732 | addrGotoChng0 = sqlite3VdbeAddOp0(v, OP_Goto); |
| 82586 | 82733 | |
| 82587 | 82734 | /* |
| 82588 | 82735 | ** next_row: |
| | @@ -82600,10 +82747,11 @@ |
| 82600 | 82747 | sqlite3VdbeAddOp2(v, OP_Integer, i, regChng); |
| 82601 | 82748 | sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp); |
| 82602 | 82749 | aGotoChng[i] = |
| 82603 | 82750 | sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ); |
| 82604 | 82751 | sqlite3VdbeChangeP5(v, SQLITE_NULLEQ); |
| 82752 | + VdbeCoverage(v); |
| 82605 | 82753 | } |
| 82606 | 82754 | sqlite3VdbeAddOp2(v, OP_Integer, nCol, regChng); |
| 82607 | 82755 | aGotoChng[nCol] = sqlite3VdbeAddOp0(v, OP_Goto); |
| 82608 | 82756 | |
| 82609 | 82757 | /* |
| | @@ -82646,11 +82794,11 @@ |
| 82646 | 82794 | #endif |
| 82647 | 82795 | assert( regChng==(regStat4+1) ); |
| 82648 | 82796 | sqlite3VdbeAddOp3(v, OP_Function, 1, regStat4, regTemp); |
| 82649 | 82797 | sqlite3VdbeChangeP4(v, -1, (char*)&statPushFuncdef, P4_FUNCDEF); |
| 82650 | 82798 | sqlite3VdbeChangeP5(v, 2+IsStat34); |
| 82651 | | - sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); |
| 82799 | + sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v); |
| 82652 | 82800 | |
| 82653 | 82801 | /* Add the entry to the stat1 table. */ |
| 82654 | 82802 | callStatGet(v, regStat4, STAT_GET_STAT1, regStat1); |
| 82655 | 82803 | sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0); |
| 82656 | 82804 | sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid); |
| | @@ -82673,14 +82821,16 @@ |
| 82673 | 82821 | pParse->nMem = MAX(pParse->nMem, regCol+nCol+1); |
| 82674 | 82822 | |
| 82675 | 82823 | addrNext = sqlite3VdbeCurrentAddr(v); |
| 82676 | 82824 | callStatGet(v, regStat4, STAT_GET_ROWID, regSampleRowid); |
| 82677 | 82825 | addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regSampleRowid); |
| 82826 | + VdbeCoverage(v); |
| 82678 | 82827 | callStatGet(v, regStat4, STAT_GET_NEQ, regEq); |
| 82679 | 82828 | callStatGet(v, regStat4, STAT_GET_NLT, regLt); |
| 82680 | 82829 | callStatGet(v, regStat4, STAT_GET_NDLT, regDLt); |
| 82681 | 82830 | sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0); |
| 82831 | + VdbeCoverage(v); |
| 82682 | 82832 | #ifdef SQLITE_ENABLE_STAT3 |
| 82683 | 82833 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, |
| 82684 | 82834 | pIdx->aiColumn[0], regSample); |
| 82685 | 82835 | #else |
| 82686 | 82836 | for(i=0; i<nCol; i++){ |
| | @@ -82687,11 +82837,11 @@ |
| 82687 | 82837 | i16 iCol = pIdx->aiColumn[i]; |
| 82688 | 82838 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, iCol, regCol+i); |
| 82689 | 82839 | } |
| 82690 | 82840 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nCol+1, regSample); |
| 82691 | 82841 | #endif |
| 82692 | | - sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 6, regTemp, "bbbbbb", 0); |
| 82842 | + sqlite3VdbeAddOp3(v, OP_MakeRecord, regTabname, 6, regTemp); |
| 82693 | 82843 | sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid); |
| 82694 | 82844 | sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regTemp, regNewRowid); |
| 82695 | 82845 | sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNext); |
| 82696 | 82846 | sqlite3VdbeJumpHere(v, addrIsNull); |
| 82697 | 82847 | } |
| | @@ -82707,11 +82857,11 @@ |
| 82707 | 82857 | ** name and the row count as the content. |
| 82708 | 82858 | */ |
| 82709 | 82859 | if( pOnlyIdx==0 && needTableCnt ){ |
| 82710 | 82860 | VdbeComment((v, "%s", pTab->zName)); |
| 82711 | 82861 | sqlite3VdbeAddOp2(v, OP_Count, iTabCur, regStat1); |
| 82712 | | - jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1); |
| 82862 | + jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1); VdbeCoverage(v); |
| 82713 | 82863 | sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname); |
| 82714 | 82864 | sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0); |
| 82715 | 82865 | sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid); |
| 82716 | 82866 | sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid); |
| 82717 | 82867 | sqlite3VdbeChangeP5(v, OPFLAG_APPEND); |
| | @@ -84245,24 +84395,26 @@ |
| 84245 | 84395 | ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are |
| 84246 | 84396 | ** set for each database that is used. Generate code to start a |
| 84247 | 84397 | ** transaction on each used database and to verify the schema cookie |
| 84248 | 84398 | ** on each used database. |
| 84249 | 84399 | */ |
| 84250 | | - if( pParse->cookieGoto>0 ){ |
| 84400 | + if( db->mallocFailed==0 && (pParse->cookieMask || pParse->pConstExpr) ){ |
| 84251 | 84401 | yDbMask mask; |
| 84252 | | - int iDb, i, addr; |
| 84253 | | - sqlite3VdbeJumpHere(v, pParse->cookieGoto-1); |
| 84402 | + int iDb, i; |
| 84403 | + assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init ); |
| 84404 | + sqlite3VdbeJumpHere(v, 0); |
| 84254 | 84405 | for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){ |
| 84255 | 84406 | if( (mask & pParse->cookieMask)==0 ) continue; |
| 84256 | 84407 | sqlite3VdbeUsesBtree(v, iDb); |
| 84257 | | - sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0); |
| 84258 | | - if( db->init.busy==0 ){ |
| 84259 | | - assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 84260 | | - sqlite3VdbeAddOp3(v, OP_VerifyCookie, |
| 84261 | | - iDb, pParse->cookieValue[iDb], |
| 84262 | | - db->aDb[iDb].pSchema->iGeneration); |
| 84263 | | - } |
| 84408 | + sqlite3VdbeAddOp4Int(v, |
| 84409 | + OP_Transaction, /* Opcode */ |
| 84410 | + iDb, /* P1 */ |
| 84411 | + (mask & pParse->writeMask)!=0, /* P2 */ |
| 84412 | + pParse->cookieValue[iDb], /* P3 */ |
| 84413 | + db->aDb[iDb].pSchema->iGeneration /* P4 */ |
| 84414 | + ); |
| 84415 | + if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1); |
| 84264 | 84416 | } |
| 84265 | 84417 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 84266 | 84418 | for(i=0; i<pParse->nVtabLock; i++){ |
| 84267 | 84419 | char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]); |
| 84268 | 84420 | sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB); |
| | @@ -84279,21 +84431,20 @@ |
| 84279 | 84431 | /* Initialize any AUTOINCREMENT data structures required. |
| 84280 | 84432 | */ |
| 84281 | 84433 | sqlite3AutoincrementBegin(pParse); |
| 84282 | 84434 | |
| 84283 | 84435 | /* Code constant expressions that where factored out of inner loops */ |
| 84284 | | - addr = pParse->cookieGoto; |
| 84285 | 84436 | if( pParse->pConstExpr ){ |
| 84286 | 84437 | ExprList *pEL = pParse->pConstExpr; |
| 84287 | | - pParse->cookieGoto = 0; |
| 84438 | + pParse->okConstFactor = 0; |
| 84288 | 84439 | for(i=0; i<pEL->nExpr; i++){ |
| 84289 | 84440 | sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg); |
| 84290 | 84441 | } |
| 84291 | 84442 | } |
| 84292 | 84443 | |
| 84293 | 84444 | /* Finally, jump back to the beginning of the executable code. */ |
| 84294 | | - sqlite3VdbeAddOp2(v, OP_Goto, 0, addr); |
| 84445 | + sqlite3VdbeAddOp2(v, OP_Goto, 0, 1); |
| 84295 | 84446 | } |
| 84296 | 84447 | } |
| 84297 | 84448 | |
| 84298 | 84449 | |
| 84299 | 84450 | /* Get the VDBE program ready for execution |
| | @@ -84312,11 +84463,10 @@ |
| 84312 | 84463 | pParse->nTab = 0; |
| 84313 | 84464 | pParse->nMem = 0; |
| 84314 | 84465 | pParse->nSet = 0; |
| 84315 | 84466 | pParse->nVar = 0; |
| 84316 | 84467 | pParse->cookieMask = 0; |
| 84317 | | - pParse->cookieGoto = 0; |
| 84318 | 84468 | } |
| 84319 | 84469 | |
| 84320 | 84470 | /* |
| 84321 | 84471 | ** Run the parser and code generator recursively in order to generate |
| 84322 | 84472 | ** code for the SQL statement given onto the end of the pParse context |
| | @@ -85044,11 +85194,11 @@ |
| 85044 | 85194 | reg1 = pParse->regRowid = ++pParse->nMem; |
| 85045 | 85195 | reg2 = pParse->regRoot = ++pParse->nMem; |
| 85046 | 85196 | reg3 = ++pParse->nMem; |
| 85047 | 85197 | sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT); |
| 85048 | 85198 | sqlite3VdbeUsesBtree(v, iDb); |
| 85049 | | - j1 = sqlite3VdbeAddOp1(v, OP_If, reg3); |
| 85199 | + j1 = sqlite3VdbeAddOp1(v, OP_If, reg3); VdbeCoverage(v); |
| 85050 | 85200 | fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ? |
| 85051 | 85201 | 1 : SQLITE_MAX_FILE_FORMAT; |
| 85052 | 85202 | sqlite3VdbeAddOp2(v, OP_Integer, fileFormat, reg3); |
| 85053 | 85203 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, reg3); |
| 85054 | 85204 | sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3); |
| | @@ -86771,40 +86921,40 @@ |
| 86771 | 86921 | sqlite3KeyInfoRef(pKey), P4_KEYINFO); |
| 86772 | 86922 | |
| 86773 | 86923 | /* Open the table. Loop through all rows of the table, inserting index |
| 86774 | 86924 | ** records into the sorter. */ |
| 86775 | 86925 | sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead); |
| 86776 | | - addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0); |
| 86926 | + addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0); VdbeCoverage(v); |
| 86777 | 86927 | regRecord = sqlite3GetTempReg(pParse); |
| 86778 | 86928 | |
| 86779 | 86929 | sqlite3GenerateIndexKey(pParse,pIndex,iTab,regRecord,0,&iPartIdxLabel,0,0); |
| 86780 | 86930 | sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord); |
| 86781 | 86931 | sqlite3VdbeResolveLabel(v, iPartIdxLabel); |
| 86782 | | - sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1); |
| 86932 | + sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1); VdbeCoverage(v); |
| 86783 | 86933 | sqlite3VdbeJumpHere(v, addr1); |
| 86784 | 86934 | if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb); |
| 86785 | 86935 | sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb, |
| 86786 | 86936 | (char *)pKey, P4_KEYINFO); |
| 86787 | 86937 | sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0)); |
| 86788 | 86938 | |
| 86789 | | - addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); |
| 86939 | + addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v); |
| 86790 | 86940 | assert( pKey!=0 || db->mallocFailed || pParse->nErr ); |
| 86791 | 86941 | if( pIndex->onError!=OE_None && pKey!=0 ){ |
| 86792 | 86942 | int j2 = sqlite3VdbeCurrentAddr(v) + 3; |
| 86793 | 86943 | sqlite3VdbeAddOp2(v, OP_Goto, 0, j2); |
| 86794 | 86944 | addr2 = sqlite3VdbeCurrentAddr(v); |
| 86795 | 86945 | sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord, |
| 86796 | | - pKey->nField - pIndex->nKeyCol); |
| 86946 | + pKey->nField - pIndex->nKeyCol); VdbeCoverage(v); |
| 86797 | 86947 | sqlite3UniqueConstraint(pParse, OE_Abort, pIndex); |
| 86798 | 86948 | }else{ |
| 86799 | 86949 | addr2 = sqlite3VdbeCurrentAddr(v); |
| 86800 | 86950 | } |
| 86801 | 86951 | sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord); |
| 86802 | 86952 | sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1); |
| 86803 | 86953 | sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 86804 | 86954 | sqlite3ReleaseTempReg(pParse, regRecord); |
| 86805 | | - sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); |
| 86955 | + sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v); |
| 86806 | 86956 | sqlite3VdbeJumpHere(v, addr1); |
| 86807 | 86957 | |
| 86808 | 86958 | sqlite3VdbeAddOp1(v, OP_Close, iTab); |
| 86809 | 86959 | sqlite3VdbeAddOp1(v, OP_Close, iIdx); |
| 86810 | 86960 | sqlite3VdbeAddOp1(v, OP_Close, iSorter); |
| | @@ -87921,63 +88071,30 @@ |
| 87921 | 88071 | } |
| 87922 | 88072 | return 0; |
| 87923 | 88073 | } |
| 87924 | 88074 | |
| 87925 | 88075 | /* |
| 87926 | | -** Generate VDBE code that will verify the schema cookie and start |
| 87927 | | -** a read-transaction for all named database files. |
| 87928 | | -** |
| 87929 | | -** It is important that all schema cookies be verified and all |
| 87930 | | -** read transactions be started before anything else happens in |
| 87931 | | -** the VDBE program. But this routine can be called after much other |
| 87932 | | -** code has been generated. So here is what we do: |
| 87933 | | -** |
| 87934 | | -** The first time this routine is called, we code an OP_Goto that |
| 87935 | | -** will jump to a subroutine at the end of the program. Then we |
| 87936 | | -** record every database that needs its schema verified in the |
| 87937 | | -** pParse->cookieMask field. Later, after all other code has been |
| 87938 | | -** generated, the subroutine that does the cookie verifications and |
| 87939 | | -** starts the transactions will be coded and the OP_Goto P2 value |
| 87940 | | -** will be made to point to that subroutine. The generation of the |
| 87941 | | -** cookie verification subroutine code happens in sqlite3FinishCoding(). |
| 87942 | | -** |
| 87943 | | -** If iDb<0 then code the OP_Goto only - don't set flag to verify the |
| 87944 | | -** schema on any databases. This can be used to position the OP_Goto |
| 87945 | | -** early in the code, before we know if any database tables will be used. |
| 88076 | +** Record the fact that the schema cookie will need to be verified |
| 88077 | +** for database iDb. The code to actually verify the schema cookie |
| 88078 | +** will occur at the end of the top-level VDBE and will be generated |
| 88079 | +** later, by sqlite3FinishCoding(). |
| 87946 | 88080 | */ |
| 87947 | 88081 | SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){ |
| 87948 | 88082 | Parse *pToplevel = sqlite3ParseToplevel(pParse); |
| 87949 | | - |
| 87950 | | -#ifndef SQLITE_OMIT_TRIGGER |
| 87951 | | - if( pToplevel!=pParse ){ |
| 87952 | | - /* This branch is taken if a trigger is currently being coded. In this |
| 87953 | | - ** case, set cookieGoto to a non-zero value to show that this function |
| 87954 | | - ** has been called. This is used by the sqlite3ExprCodeConstants() |
| 87955 | | - ** function. */ |
| 87956 | | - pParse->cookieGoto = -1; |
| 87957 | | - } |
| 87958 | | -#endif |
| 87959 | | - if( pToplevel->cookieGoto==0 ){ |
| 87960 | | - Vdbe *v = sqlite3GetVdbe(pToplevel); |
| 87961 | | - if( v==0 ) return; /* This only happens if there was a prior error */ |
| 87962 | | - pToplevel->cookieGoto = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0)+1; |
| 87963 | | - } |
| 87964 | | - if( iDb>=0 ){ |
| 87965 | | - sqlite3 *db = pToplevel->db; |
| 87966 | | - yDbMask mask; |
| 87967 | | - |
| 87968 | | - assert( iDb<db->nDb ); |
| 87969 | | - assert( db->aDb[iDb].pBt!=0 || iDb==1 ); |
| 87970 | | - assert( iDb<SQLITE_MAX_ATTACHED+2 ); |
| 87971 | | - assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 87972 | | - mask = ((yDbMask)1)<<iDb; |
| 87973 | | - if( (pToplevel->cookieMask & mask)==0 ){ |
| 87974 | | - pToplevel->cookieMask |= mask; |
| 87975 | | - pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie; |
| 87976 | | - if( !OMIT_TEMPDB && iDb==1 ){ |
| 87977 | | - sqlite3OpenTempDatabase(pToplevel); |
| 87978 | | - } |
| 88083 | + sqlite3 *db = pToplevel->db; |
| 88084 | + yDbMask mask; |
| 88085 | + |
| 88086 | + assert( iDb>=0 && iDb<db->nDb ); |
| 88087 | + assert( db->aDb[iDb].pBt!=0 || iDb==1 ); |
| 88088 | + assert( iDb<SQLITE_MAX_ATTACHED+2 ); |
| 88089 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 88090 | + mask = ((yDbMask)1)<<iDb; |
| 88091 | + if( (pToplevel->cookieMask & mask)==0 ){ |
| 88092 | + pToplevel->cookieMask |= mask; |
| 88093 | + pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie; |
| 88094 | + if( !OMIT_TEMPDB && iDb==1 ){ |
| 88095 | + sqlite3OpenTempDatabase(pToplevel); |
| 87979 | 88096 | } |
| 87980 | 88097 | } |
| 87981 | 88098 | } |
| 87982 | 88099 | |
| 87983 | 88100 | /* |
| | @@ -88944,25 +89061,20 @@ |
| 88944 | 89061 | SelectDest dest; |
| 88945 | 89062 | Select *pSel; |
| 88946 | 89063 | SrcList *pFrom; |
| 88947 | 89064 | sqlite3 *db = pParse->db; |
| 88948 | 89065 | int iDb = sqlite3SchemaToIndex(db, pView->pSchema); |
| 88949 | | - |
| 88950 | 89066 | pWhere = sqlite3ExprDup(db, pWhere, 0); |
| 88951 | 89067 | pFrom = sqlite3SrcListAppend(db, 0, 0, 0); |
| 88952 | | - |
| 88953 | 89068 | if( pFrom ){ |
| 88954 | 89069 | assert( pFrom->nSrc==1 ); |
| 88955 | 89070 | pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName); |
| 88956 | 89071 | pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName); |
| 88957 | 89072 | assert( pFrom->a[0].pOn==0 ); |
| 88958 | 89073 | assert( pFrom->a[0].pUsing==0 ); |
| 88959 | 89074 | } |
| 88960 | | - |
| 88961 | 89075 | pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0); |
| 88962 | | - if( pSel ) pSel->selFlags |= SF_Materialize; |
| 88963 | | - |
| 88964 | 89076 | sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur); |
| 88965 | 89077 | sqlite3Select(pParse, pSel, &dest); |
| 88966 | 89078 | sqlite3SelectDelete(db, pSel); |
| 88967 | 89079 | } |
| 88968 | 89080 | #endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */ |
| | @@ -89295,11 +89407,11 @@ |
| 89295 | 89407 | }else if( pPk ){ |
| 89296 | 89408 | /* Construct a composite key for the row to be deleted and remember it */ |
| 89297 | 89409 | iKey = ++pParse->nMem; |
| 89298 | 89410 | nKey = 0; /* Zero tells OP_Found to use a composite key */ |
| 89299 | 89411 | sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey, |
| 89300 | | - sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT); |
| 89412 | + sqlite3IndexAffinityStr(v, pPk), nPk); |
| 89301 | 89413 | sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey); |
| 89302 | 89414 | }else{ |
| 89303 | 89415 | /* Get the rowid of the row to be deleted and remember it in the RowSet */ |
| 89304 | 89416 | nKey = 1; /* OP_Seek always uses a single rowid */ |
| 89305 | 89417 | sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey); |
| | @@ -89333,17 +89445,19 @@ |
| 89333 | 89445 | /* Just one row. Hence the top-of-loop is a no-op */ |
| 89334 | 89446 | assert( nKey==nPk ); /* OP_Found will use an unpacked key */ |
| 89335 | 89447 | if( aToOpen[iDataCur-iTabCur] ){ |
| 89336 | 89448 | assert( pPk!=0 ); |
| 89337 | 89449 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey); |
| 89450 | + VdbeCoverage(v); |
| 89338 | 89451 | } |
| 89339 | 89452 | }else if( pPk ){ |
| 89340 | | - addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); |
| 89453 | + addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v); |
| 89341 | 89454 | sqlite3VdbeAddOp2(v, OP_RowKey, iEphCur, iKey); |
| 89342 | 89455 | assert( nKey==0 ); /* OP_Found will use a composite key */ |
| 89343 | 89456 | }else{ |
| 89344 | 89457 | addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey); |
| 89458 | + VdbeCoverage(v); |
| 89345 | 89459 | assert( nKey==1 ); |
| 89346 | 89460 | } |
| 89347 | 89461 | |
| 89348 | 89462 | /* Delete the row */ |
| 89349 | 89463 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| | @@ -89363,11 +89477,11 @@ |
| 89363 | 89477 | |
| 89364 | 89478 | /* End of the loop over all rowids/primary-keys. */ |
| 89365 | 89479 | if( okOnePass ){ |
| 89366 | 89480 | sqlite3VdbeResolveLabel(v, addrBypass); |
| 89367 | 89481 | }else if( pPk ){ |
| 89368 | | - sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); |
| 89482 | + sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v); |
| 89369 | 89483 | sqlite3VdbeJumpHere(v, addrLoop); |
| 89370 | 89484 | }else{ |
| 89371 | 89485 | sqlite3VdbeAddOp2(v, OP_Goto, 0, addrLoop); |
| 89372 | 89486 | sqlite3VdbeJumpHere(v, addrLoop); |
| 89373 | 89487 | } |
| | @@ -89461,11 +89575,15 @@ |
| 89461 | 89575 | /* Seek cursor iCur to the row to delete. If this row no longer exists |
| 89462 | 89576 | ** (this can happen if a trigger program has already deleted it), do |
| 89463 | 89577 | ** not attempt to delete it or fire any DELETE triggers. */ |
| 89464 | 89578 | iLabel = sqlite3VdbeMakeLabel(v); |
| 89465 | 89579 | opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound; |
| 89466 | | - if( !bNoSeek ) sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk); |
| 89580 | + if( !bNoSeek ){ |
| 89581 | + sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk); |
| 89582 | + VdbeCoverageIf(v, opSeek==OP_NotExists); |
| 89583 | + VdbeCoverageIf(v, opSeek==OP_NotFound); |
| 89584 | + } |
| 89467 | 89585 | |
| 89468 | 89586 | /* If there are any triggers to fire, allocate a range of registers to |
| 89469 | 89587 | ** use for the old.* references in the triggers. */ |
| 89470 | 89588 | if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){ |
| 89471 | 89589 | u32 mask; /* Mask of OLD.* columns in use */ |
| | @@ -89503,10 +89621,12 @@ |
| 89503 | 89621 | ** the cursor or of already deleted the row that the cursor was |
| 89504 | 89622 | ** pointing to. |
| 89505 | 89623 | */ |
| 89506 | 89624 | if( addrStart<sqlite3VdbeCurrentAddr(v) ){ |
| 89507 | 89625 | sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk); |
| 89626 | + VdbeCoverageIf(v, opSeek==OP_NotExists); |
| 89627 | + VdbeCoverageIf(v, opSeek==OP_NotFound); |
| 89508 | 89628 | } |
| 89509 | 89629 | |
| 89510 | 89630 | /* Do FK processing. This call checks that any FK constraints that |
| 89511 | 89631 | ** refer to this table (i.e. constraints attached to other tables) |
| 89512 | 89632 | ** are not violated by deleting this row. */ |
| | @@ -91760,14 +91880,15 @@ |
| 91760 | 91880 | ** Check if any of the key columns in the child table row are NULL. If |
| 91761 | 91881 | ** any are, then the constraint is considered satisfied. No need to |
| 91762 | 91882 | ** search for a matching row in the parent table. */ |
| 91763 | 91883 | if( nIncr<0 ){ |
| 91764 | 91884 | sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, iOk); |
| 91885 | + VdbeCoverage(v); |
| 91765 | 91886 | } |
| 91766 | 91887 | for(i=0; i<pFKey->nCol; i++){ |
| 91767 | 91888 | int iReg = aiCol[i] + regData + 1; |
| 91768 | | - sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iOk); |
| 91889 | + sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iOk); VdbeCoverage(v); |
| 91769 | 91890 | } |
| 91770 | 91891 | |
| 91771 | 91892 | if( isIgnore==0 ){ |
| 91772 | 91893 | if( pIdx==0 ){ |
| 91773 | 91894 | /* If pIdx is NULL, then the parent key is the INTEGER PRIMARY KEY |
| | @@ -91780,21 +91901,23 @@ |
| 91780 | 91901 | ** is no matching parent key. Before using MustBeInt, make a copy of |
| 91781 | 91902 | ** the value. Otherwise, the value inserted into the child key column |
| 91782 | 91903 | ** will have INTEGER affinity applied to it, which may not be correct. */ |
| 91783 | 91904 | sqlite3VdbeAddOp2(v, OP_SCopy, aiCol[0]+1+regData, regTemp); |
| 91784 | 91905 | iMustBeInt = sqlite3VdbeAddOp2(v, OP_MustBeInt, regTemp, 0); |
| 91906 | + VdbeCoverage(v); |
| 91785 | 91907 | |
| 91786 | 91908 | /* If the parent table is the same as the child table, and we are about |
| 91787 | 91909 | ** to increment the constraint-counter (i.e. this is an INSERT operation), |
| 91788 | 91910 | ** then check if the row being inserted matches itself. If so, do not |
| 91789 | 91911 | ** increment the constraint-counter. */ |
| 91790 | 91912 | if( pTab==pFKey->pFrom && nIncr==1 ){ |
| 91791 | | - sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp); |
| 91913 | + sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp); VdbeCoverage(v); |
| 91914 | + sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); |
| 91792 | 91915 | } |
| 91793 | 91916 | |
| 91794 | 91917 | sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead); |
| 91795 | | - sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); |
| 91918 | + sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); VdbeCoverage(v); |
| 91796 | 91919 | sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk); |
| 91797 | 91920 | sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2); |
| 91798 | 91921 | sqlite3VdbeJumpHere(v, iMustBeInt); |
| 91799 | 91922 | sqlite3ReleaseTempReg(pParse, regTemp); |
| 91800 | 91923 | }else{ |
| | @@ -91826,19 +91949,19 @@ |
| 91826 | 91949 | assert( aiCol[i]!=pTab->iPKey ); |
| 91827 | 91950 | if( pIdx->aiColumn[i]==pTab->iPKey ){ |
| 91828 | 91951 | /* The parent key is a composite key that includes the IPK column */ |
| 91829 | 91952 | iParent = regData; |
| 91830 | 91953 | } |
| 91831 | | - sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent); |
| 91954 | + sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent); VdbeCoverage(v); |
| 91832 | 91955 | sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL); |
| 91833 | 91956 | } |
| 91834 | 91957 | sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk); |
| 91835 | 91958 | } |
| 91836 | 91959 | |
| 91837 | | - sqlite3VdbeAddOp3(v, OP_MakeRecord, regTemp, nCol, regRec); |
| 91838 | | - sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v,pIdx), P4_TRANSIENT); |
| 91839 | | - sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); |
| 91960 | + sqlite3VdbeAddOp4(v, OP_MakeRecord, regTemp, nCol, regRec, |
| 91961 | + sqlite3IndexAffinityStr(v,pIdx), nCol); |
| 91962 | + sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); VdbeCoverage(v); |
| 91840 | 91963 | |
| 91841 | 91964 | sqlite3ReleaseTempReg(pParse, regRec); |
| 91842 | 91965 | sqlite3ReleaseTempRange(pParse, regTemp, nCol); |
| 91843 | 91966 | } |
| 91844 | 91967 | } |
| | @@ -91972,10 +92095,11 @@ |
| 91972 | 92095 | assert( pIdx!=0 || pFKey->nCol==1 ); |
| 91973 | 92096 | assert( pIdx!=0 || HasRowid(pTab) ); |
| 91974 | 92097 | |
| 91975 | 92098 | if( nIncr<0 ){ |
| 91976 | 92099 | iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0); |
| 92100 | + VdbeCoverage(v); |
| 91977 | 92101 | } |
| 91978 | 92102 | |
| 91979 | 92103 | /* Create an Expr object representing an SQL expression like: |
| 91980 | 92104 | ** |
| 91981 | 92105 | ** <parent-key1> = <child-key1> AND <parent-key2> = <child-key2> ... |
| | @@ -92134,11 +92258,11 @@ |
| 92134 | 92258 | for(p=pTab->pFKey; p; p=p->pNextFrom){ |
| 92135 | 92259 | if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break; |
| 92136 | 92260 | } |
| 92137 | 92261 | if( !p ) return; |
| 92138 | 92262 | iSkip = sqlite3VdbeMakeLabel(v); |
| 92139 | | - sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); |
| 92263 | + sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v); |
| 92140 | 92264 | } |
| 92141 | 92265 | |
| 92142 | 92266 | pParse->disableTriggers = 1; |
| 92143 | 92267 | sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0); |
| 92144 | 92268 | pParse->disableTriggers = 0; |
| | @@ -92152,10 +92276,11 @@ |
| 92152 | 92276 | ** the statement transaction will not be rolled back even if FK |
| 92153 | 92277 | ** constraints are violated. |
| 92154 | 92278 | */ |
| 92155 | 92279 | if( (db->flags & SQLITE_DeferFKs)==0 ){ |
| 92156 | 92280 | sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2); |
| 92281 | + VdbeCoverage(v); |
| 92157 | 92282 | sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY, |
| 92158 | 92283 | OE_Abort, 0, P4_STATIC, P5_ConstraintFK); |
| 92159 | 92284 | } |
| 92160 | 92285 | |
| 92161 | 92286 | if( iSkip ){ |
| | @@ -92311,11 +92436,11 @@ |
| 92311 | 92436 | */ |
| 92312 | 92437 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 92313 | 92438 | int iJump = sqlite3VdbeCurrentAddr(v) + pFKey->nCol + 1; |
| 92314 | 92439 | for(i=0; i<pFKey->nCol; i++){ |
| 92315 | 92440 | int iReg = pFKey->aCol[i].iFrom + regOld + 1; |
| 92316 | | - sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iJump); |
| 92441 | + sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iJump); VdbeCoverage(v); |
| 92317 | 92442 | } |
| 92318 | 92443 | sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, -1); |
| 92319 | 92444 | } |
| 92320 | 92445 | continue; |
| 92321 | 92446 | } |
| | @@ -92878,69 +93003,74 @@ |
| 92878 | 93003 | |
| 92879 | 93004 | return pIdx->zColAff; |
| 92880 | 93005 | } |
| 92881 | 93006 | |
| 92882 | 93007 | /* |
| 92883 | | -** Set P4 of the most recently inserted opcode to a column affinity |
| 92884 | | -** string for table pTab. A column affinity string has one character |
| 92885 | | -** for each column indexed by the index, according to the affinity of the |
| 92886 | | -** column: |
| 93008 | +** Compute the affinity string for table pTab, if it has not already been |
| 93009 | +** computed. As an optimization, omit trailing SQLITE_AFF_NONE affinities. |
| 93010 | +** |
| 93011 | +** If the affinity exists (if it is no entirely SQLITE_AFF_NONE values and |
| 93012 | +** if iReg>0 then code an OP_Affinity opcode that will set the affinities |
| 93013 | +** for register iReg and following. Or if affinities exists and iReg==0, |
| 93014 | +** then just set the P4 operand of the previous opcode (which should be |
| 93015 | +** an OP_MakeRecord) to the affinity string. |
| 93016 | +** |
| 93017 | +** A column affinity string has one character column: |
| 92887 | 93018 | ** |
| 92888 | 93019 | ** Character Column affinity |
| 92889 | 93020 | ** ------------------------------ |
| 92890 | 93021 | ** 'a' TEXT |
| 92891 | 93022 | ** 'b' NONE |
| 92892 | 93023 | ** 'c' NUMERIC |
| 92893 | 93024 | ** 'd' INTEGER |
| 92894 | 93025 | ** 'e' REAL |
| 92895 | 93026 | */ |
| 92896 | | -SQLITE_PRIVATE void sqlite3TableAffinityStr(Vdbe *v, Table *pTab){ |
| 92897 | | - /* The first time a column affinity string for a particular table |
| 92898 | | - ** is required, it is allocated and populated here. It is then |
| 92899 | | - ** stored as a member of the Table structure for subsequent use. |
| 92900 | | - ** |
| 92901 | | - ** The column affinity string will eventually be deleted by |
| 92902 | | - ** sqlite3DeleteTable() when the Table structure itself is cleaned up. |
| 92903 | | - */ |
| 92904 | | - if( !pTab->zColAff ){ |
| 92905 | | - char *zColAff; |
| 92906 | | - int i; |
| 93027 | +SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){ |
| 93028 | + int i; |
| 93029 | + char *zColAff = pTab->zColAff; |
| 93030 | + if( zColAff==0 ){ |
| 92907 | 93031 | sqlite3 *db = sqlite3VdbeDb(v); |
| 92908 | | - |
| 92909 | 93032 | zColAff = (char *)sqlite3DbMallocRaw(0, pTab->nCol+1); |
| 92910 | 93033 | if( !zColAff ){ |
| 92911 | 93034 | db->mallocFailed = 1; |
| 92912 | 93035 | return; |
| 92913 | 93036 | } |
| 92914 | 93037 | |
| 92915 | 93038 | for(i=0; i<pTab->nCol; i++){ |
| 92916 | 93039 | zColAff[i] = pTab->aCol[i].affinity; |
| 92917 | 93040 | } |
| 92918 | | - zColAff[pTab->nCol] = '\0'; |
| 92919 | | - |
| 93041 | + do{ |
| 93042 | + zColAff[i--] = 0; |
| 93043 | + }while( i>=0 && zColAff[i]==SQLITE_AFF_NONE ); |
| 92920 | 93044 | pTab->zColAff = zColAff; |
| 92921 | 93045 | } |
| 92922 | | - |
| 92923 | | - sqlite3VdbeChangeP4(v, -1, pTab->zColAff, P4_TRANSIENT); |
| 93046 | + i = sqlite3Strlen30(zColAff); |
| 93047 | + if( i ){ |
| 93048 | + if( iReg ){ |
| 93049 | + sqlite3VdbeAddOp4(v, OP_Affinity, iReg, i, 0, zColAff, i); |
| 93050 | + }else{ |
| 93051 | + sqlite3VdbeChangeP4(v, -1, zColAff, i); |
| 93052 | + } |
| 93053 | + } |
| 92924 | 93054 | } |
| 92925 | 93055 | |
| 92926 | 93056 | /* |
| 92927 | 93057 | ** Return non-zero if the table pTab in database iDb or any of its indices |
| 92928 | 93058 | ** have been opened at any point in the VDBE program beginning at location |
| 92929 | 93059 | ** iStartAddr throught the end of the program. This is used to see if |
| 92930 | 93060 | ** a statement of the form "INSERT INTO <iDb, pTab> SELECT ..." can |
| 92931 | 93061 | ** run without using temporary table for the results of the SELECT. |
| 92932 | 93062 | */ |
| 92933 | | -static int readsTable(Parse *p, int iStartAddr, int iDb, Table *pTab){ |
| 93063 | +static int readsTable(Parse *p, int iDb, Table *pTab){ |
| 92934 | 93064 | Vdbe *v = sqlite3GetVdbe(p); |
| 92935 | 93065 | int i; |
| 92936 | 93066 | int iEnd = sqlite3VdbeCurrentAddr(v); |
| 92937 | 93067 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 92938 | 93068 | VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0; |
| 92939 | 93069 | #endif |
| 92940 | 93070 | |
| 92941 | | - for(i=iStartAddr; i<iEnd; i++){ |
| 93071 | + for(i=1; i<iEnd; i++){ |
| 92942 | 93072 | VdbeOp *pOp = sqlite3VdbeGetOp(v, i); |
| 92943 | 93073 | assert( pOp!=0 ); |
| 92944 | 93074 | if( pOp->opcode==OP_OpenRead && pOp->p3==iDb ){ |
| 92945 | 93075 | Index *pIndex; |
| 92946 | 93076 | int tnum = pOp->p2; |
| | @@ -93037,18 +93167,18 @@ |
| 93037 | 93167 | assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) ); |
| 93038 | 93168 | sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead); |
| 93039 | 93169 | sqlite3VdbeAddOp3(v, OP_Null, 0, memId, memId+1); |
| 93040 | 93170 | addr = sqlite3VdbeCurrentAddr(v); |
| 93041 | 93171 | sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0); |
| 93042 | | - sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9); |
| 93172 | + sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9); VdbeCoverage(v); |
| 93043 | 93173 | sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId); |
| 93044 | | - sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId); |
| 93174 | + sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId); VdbeCoverage(v); |
| 93045 | 93175 | sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL); |
| 93046 | 93176 | sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1); |
| 93047 | 93177 | sqlite3VdbeAddOp3(v, OP_Column, 0, 1, memId); |
| 93048 | 93178 | sqlite3VdbeAddOp2(v, OP_Goto, 0, addr+9); |
| 93049 | | - sqlite3VdbeAddOp2(v, OP_Next, 0, addr+2); |
| 93179 | + sqlite3VdbeAddOp2(v, OP_Next, 0, addr+2); VdbeCoverage(v); |
| 93050 | 93180 | sqlite3VdbeAddOp2(v, OP_Integer, 0, memId); |
| 93051 | 93181 | sqlite3VdbeAddOp0(v, OP_Close); |
| 93052 | 93182 | } |
| 93053 | 93183 | } |
| 93054 | 93184 | |
| | @@ -93079,29 +93209,20 @@ |
| 93079 | 93209 | sqlite3 *db = pParse->db; |
| 93080 | 93210 | |
| 93081 | 93211 | assert( v ); |
| 93082 | 93212 | for(p = pParse->pAinc; p; p = p->pNext){ |
| 93083 | 93213 | Db *pDb = &db->aDb[p->iDb]; |
| 93084 | | - int j1, j2, j3, j4, j5; |
| 93214 | + int j1; |
| 93085 | 93215 | int iRec; |
| 93086 | 93216 | int memId = p->regCtr; |
| 93087 | 93217 | |
| 93088 | 93218 | iRec = sqlite3GetTempReg(pParse); |
| 93089 | 93219 | assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) ); |
| 93090 | 93220 | sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite); |
| 93091 | | - j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1); |
| 93092 | | - j2 = sqlite3VdbeAddOp0(v, OP_Rewind); |
| 93093 | | - j3 = sqlite3VdbeAddOp3(v, OP_Column, 0, 0, iRec); |
| 93094 | | - j4 = sqlite3VdbeAddOp3(v, OP_Eq, memId-1, 0, iRec); |
| 93095 | | - sqlite3VdbeAddOp2(v, OP_Next, 0, j3); |
| 93096 | | - sqlite3VdbeJumpHere(v, j2); |
| 93221 | + j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1); VdbeCoverage(v); |
| 93097 | 93222 | sqlite3VdbeAddOp2(v, OP_NewRowid, 0, memId+1); |
| 93098 | | - j5 = sqlite3VdbeAddOp0(v, OP_Goto); |
| 93099 | | - sqlite3VdbeJumpHere(v, j4); |
| 93100 | | - sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1); |
| 93101 | 93223 | sqlite3VdbeJumpHere(v, j1); |
| 93102 | | - sqlite3VdbeJumpHere(v, j5); |
| 93103 | 93224 | sqlite3VdbeAddOp3(v, OP_MakeRecord, memId-1, 2, iRec); |
| 93104 | 93225 | sqlite3VdbeAddOp3(v, OP_Insert, 0, iRec, memId+1); |
| 93105 | 93226 | sqlite3VdbeChangeP5(v, OPFLAG_APPEND); |
| 93106 | 93227 | sqlite3VdbeAddOp0(v, OP_Close); |
| 93107 | 93228 | sqlite3ReleaseTempReg(pParse, iRec); |
| | @@ -93113,101 +93234,10 @@ |
| 93113 | 93234 | ** above are all no-ops |
| 93114 | 93235 | */ |
| 93115 | 93236 | # define autoIncBegin(A,B,C) (0) |
| 93116 | 93237 | # define autoIncStep(A,B,C) |
| 93117 | 93238 | #endif /* SQLITE_OMIT_AUTOINCREMENT */ |
| 93118 | | - |
| 93119 | | - |
| 93120 | | -/* |
| 93121 | | -** Generate code for a co-routine that will evaluate a subquery one |
| 93122 | | -** row at a time. |
| 93123 | | -** |
| 93124 | | -** The pSelect parameter is the subquery that the co-routine will evaluation. |
| 93125 | | -** Information about the location of co-routine and the registers it will use |
| 93126 | | -** is returned by filling in the pDest object. |
| 93127 | | -** |
| 93128 | | -** Registers are allocated as follows: |
| 93129 | | -** |
| 93130 | | -** pDest->iSDParm The register holding the next entry-point of the |
| 93131 | | -** co-routine. Run the co-routine to its next breakpoint |
| 93132 | | -** by calling "OP_Yield $X" where $X is pDest->iSDParm. |
| 93133 | | -** |
| 93134 | | -** pDest->iSDParm+1 The register holding the "completed" flag for the |
| 93135 | | -** co-routine. This register is 0 if the previous Yield |
| 93136 | | -** generated a new result row, or 1 if the subquery |
| 93137 | | -** has completed. If the Yield is called again |
| 93138 | | -** after this register becomes 1, then the VDBE will |
| 93139 | | -** halt with an SQLITE_INTERNAL error. |
| 93140 | | -** |
| 93141 | | -** pDest->iSdst First result register. |
| 93142 | | -** |
| 93143 | | -** pDest->nSdst Number of result registers. |
| 93144 | | -** |
| 93145 | | -** This routine handles all of the register allocation and fills in the |
| 93146 | | -** pDest structure appropriately. |
| 93147 | | -** |
| 93148 | | -** Here is a schematic of the generated code assuming that X is the |
| 93149 | | -** co-routine entry-point register reg[pDest->iSDParm], that EOF is the |
| 93150 | | -** completed flag reg[pDest->iSDParm+1], and R and S are the range of |
| 93151 | | -** registers that hold the result set, reg[pDest->iSdst] through |
| 93152 | | -** reg[pDest->iSdst+pDest->nSdst-1]: |
| 93153 | | -** |
| 93154 | | -** X <- A |
| 93155 | | -** EOF <- 0 |
| 93156 | | -** goto B |
| 93157 | | -** A: setup for the SELECT |
| 93158 | | -** loop rows in the SELECT |
| 93159 | | -** load results into registers R..S |
| 93160 | | -** yield X |
| 93161 | | -** end loop |
| 93162 | | -** cleanup after the SELECT |
| 93163 | | -** EOF <- 1 |
| 93164 | | -** yield X |
| 93165 | | -** halt-error |
| 93166 | | -** B: |
| 93167 | | -** |
| 93168 | | -** To use this subroutine, the caller generates code as follows: |
| 93169 | | -** |
| 93170 | | -** [ Co-routine generated by this subroutine, shown above ] |
| 93171 | | -** S: yield X |
| 93172 | | -** if EOF goto E |
| 93173 | | -** if skip this row, goto C |
| 93174 | | -** if terminate loop, goto E |
| 93175 | | -** deal with this row |
| 93176 | | -** C: goto S |
| 93177 | | -** E: |
| 93178 | | -*/ |
| 93179 | | -SQLITE_PRIVATE int sqlite3CodeCoroutine(Parse *pParse, Select *pSelect, SelectDest *pDest){ |
| 93180 | | - int regYield; /* Register holding co-routine entry-point */ |
| 93181 | | - int regEof; /* Register holding co-routine completion flag */ |
| 93182 | | - int addrTop; /* Top of the co-routine */ |
| 93183 | | - int j1; /* Jump instruction */ |
| 93184 | | - int rc; /* Result code */ |
| 93185 | | - Vdbe *v; /* VDBE under construction */ |
| 93186 | | - |
| 93187 | | - regYield = ++pParse->nMem; |
| 93188 | | - regEof = ++pParse->nMem; |
| 93189 | | - v = sqlite3GetVdbe(pParse); |
| 93190 | | - addrTop = sqlite3VdbeCurrentAddr(v); |
| 93191 | | - sqlite3VdbeAddOp2(v, OP_Integer, addrTop+2, regYield); /* X <- A */ |
| 93192 | | - VdbeComment((v, "Co-routine entry point")); |
| 93193 | | - sqlite3VdbeAddOp2(v, OP_Integer, 0, regEof); /* EOF <- 0 */ |
| 93194 | | - VdbeComment((v, "Co-routine completion flag")); |
| 93195 | | - sqlite3SelectDestInit(pDest, SRT_Coroutine, regYield); |
| 93196 | | - j1 = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0); |
| 93197 | | - rc = sqlite3Select(pParse, pSelect, pDest); |
| 93198 | | - assert( pParse->nErr==0 || rc ); |
| 93199 | | - if( pParse->db->mallocFailed && rc==SQLITE_OK ) rc = SQLITE_NOMEM; |
| 93200 | | - if( rc ) return rc; |
| 93201 | | - sqlite3VdbeAddOp2(v, OP_Integer, 1, regEof); /* EOF <- 1 */ |
| 93202 | | - sqlite3VdbeAddOp1(v, OP_Yield, regYield); /* yield X */ |
| 93203 | | - sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_INTERNAL, OE_Abort); |
| 93204 | | - VdbeComment((v, "End of coroutine")); |
| 93205 | | - sqlite3VdbeJumpHere(v, j1); /* label B: */ |
| 93206 | | - return rc; |
| 93207 | | -} |
| 93208 | | - |
| 93209 | 93239 | |
| 93210 | 93240 | |
| 93211 | 93241 | /* Forward declaration */ |
| 93212 | 93242 | static int xferOptimization( |
| 93213 | 93243 | Parse *pParse, /* Parser context */ |
| | @@ -93268,25 +93298,21 @@ |
| 93268 | 93298 | ** |
| 93269 | 93299 | ** The 3rd template is for when the second template does not apply |
| 93270 | 93300 | ** and the SELECT clause does not read from <table> at any time. |
| 93271 | 93301 | ** The generated code follows this template: |
| 93272 | 93302 | ** |
| 93273 | | -** EOF <- 0 |
| 93274 | 93303 | ** X <- A |
| 93275 | 93304 | ** goto B |
| 93276 | 93305 | ** A: setup for the SELECT |
| 93277 | 93306 | ** loop over the rows in the SELECT |
| 93278 | 93307 | ** load values into registers R..R+n |
| 93279 | 93308 | ** yield X |
| 93280 | 93309 | ** end loop |
| 93281 | 93310 | ** cleanup after the SELECT |
| 93282 | | -** EOF <- 1 |
| 93283 | | -** yield X |
| 93284 | | -** goto A |
| 93311 | +** end-coroutine X |
| 93285 | 93312 | ** B: open write cursor to <table> and its indices |
| 93286 | | -** C: yield X |
| 93287 | | -** if EOF goto D |
| 93313 | +** C: yield X, at EOF goto D |
| 93288 | 93314 | ** insert the select result into <table> from R..R+n |
| 93289 | 93315 | ** goto C |
| 93290 | 93316 | ** D: cleanup |
| 93291 | 93317 | ** |
| 93292 | 93318 | ** The 4th template is used if the insert statement takes its |
| | @@ -93293,25 +93319,21 @@ |
| 93293 | 93319 | ** values from a SELECT but the data is being inserted into a table |
| 93294 | 93320 | ** that is also read as part of the SELECT. In the third form, |
| 93295 | 93321 | ** we have to use a intermediate table to store the results of |
| 93296 | 93322 | ** the select. The template is like this: |
| 93297 | 93323 | ** |
| 93298 | | -** EOF <- 0 |
| 93299 | 93324 | ** X <- A |
| 93300 | 93325 | ** goto B |
| 93301 | 93326 | ** A: setup for the SELECT |
| 93302 | 93327 | ** loop over the tables in the SELECT |
| 93303 | 93328 | ** load value into register R..R+n |
| 93304 | 93329 | ** yield X |
| 93305 | 93330 | ** end loop |
| 93306 | 93331 | ** cleanup after the SELECT |
| 93307 | | -** EOF <- 1 |
| 93308 | | -** yield X |
| 93309 | | -** halt-error |
| 93332 | +** end co-routine R |
| 93310 | 93333 | ** B: open temp table |
| 93311 | | -** L: yield X |
| 93312 | | -** if EOF goto M |
| 93334 | +** L: yield X, at EOF goto M |
| 93313 | 93335 | ** insert row from R..R+n into temp table |
| 93314 | 93336 | ** goto L |
| 93315 | 93337 | ** M: open write cursor to <table> and its indices |
| 93316 | 93338 | ** rewind temp table |
| 93317 | 93339 | ** C: loop over rows of intermediate table |
| | @@ -93337,30 +93359,29 @@ |
| 93337 | 93359 | int nHidden = 0; /* Number of hidden columns if TABLE is virtual */ |
| 93338 | 93360 | int iDataCur = 0; /* VDBE cursor that is the main data repository */ |
| 93339 | 93361 | int iIdxCur = 0; /* First index cursor */ |
| 93340 | 93362 | int ipkColumn = -1; /* Column that is the INTEGER PRIMARY KEY */ |
| 93341 | 93363 | int endOfLoop; /* Label for the end of the insertion loop */ |
| 93342 | | - int useTempTable = 0; /* Store SELECT results in intermediate table */ |
| 93343 | 93364 | int srcTab = 0; /* Data comes from this temporary cursor if >=0 */ |
| 93344 | 93365 | int addrInsTop = 0; /* Jump to label "D" */ |
| 93345 | 93366 | int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */ |
| 93346 | | - int addrSelect = 0; /* Address of coroutine that implements the SELECT */ |
| 93347 | 93367 | SelectDest dest; /* Destination for SELECT on rhs of INSERT */ |
| 93348 | 93368 | int iDb; /* Index of database holding TABLE */ |
| 93349 | 93369 | Db *pDb; /* The database containing table being inserted into */ |
| 93350 | | - int appendFlag = 0; /* True if the insert is likely to be an append */ |
| 93351 | | - int withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */ |
| 93370 | + u8 useTempTable = 0; /* Store SELECT results in intermediate table */ |
| 93371 | + u8 appendFlag = 0; /* True if the insert is likely to be an append */ |
| 93372 | + u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */ |
| 93373 | + u8 bIdListInOrder = 1; /* True if IDLIST is in table order */ |
| 93352 | 93374 | ExprList *pList = 0; /* List of VALUES() to be inserted */ |
| 93353 | 93375 | |
| 93354 | 93376 | /* Register allocations */ |
| 93355 | 93377 | int regFromSelect = 0;/* Base register for data coming from SELECT */ |
| 93356 | 93378 | int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */ |
| 93357 | 93379 | int regRowCount = 0; /* Memory cell used for the row counter */ |
| 93358 | 93380 | int regIns; /* Block of regs holding rowid+data being inserted */ |
| 93359 | 93381 | int regRowid; /* registers holding insert rowid */ |
| 93360 | 93382 | int regData; /* register holding first column to insert */ |
| 93361 | | - int regEof = 0; /* Register recording end of SELECT data */ |
| 93362 | 93383 | int *aRegIdx = 0; /* One register allocated to each index */ |
| 93363 | 93384 | |
| 93364 | 93385 | #ifndef SQLITE_OMIT_TRIGGER |
| 93365 | 93386 | int isView; /* True if attempting to insert into a view */ |
| 93366 | 93387 | Trigger *pTrigger; /* List of triggers on pTab, if required */ |
| | @@ -93458,26 +93479,86 @@ |
| 93458 | 93479 | |
| 93459 | 93480 | /* If this is an AUTOINCREMENT table, look up the sequence number in the |
| 93460 | 93481 | ** sqlite_sequence table and store it in memory cell regAutoinc. |
| 93461 | 93482 | */ |
| 93462 | 93483 | regAutoinc = autoIncBegin(pParse, iDb, pTab); |
| 93484 | + |
| 93485 | + /* Allocate registers for holding the rowid of the new row, |
| 93486 | + ** the content of the new row, and the assemblied row record. |
| 93487 | + */ |
| 93488 | + regRowid = regIns = pParse->nMem+1; |
| 93489 | + pParse->nMem += pTab->nCol + 1; |
| 93490 | + if( IsVirtual(pTab) ){ |
| 93491 | + regRowid++; |
| 93492 | + pParse->nMem++; |
| 93493 | + } |
| 93494 | + regData = regRowid+1; |
| 93495 | + |
| 93496 | + /* If the INSERT statement included an IDLIST term, then make sure |
| 93497 | + ** all elements of the IDLIST really are columns of the table and |
| 93498 | + ** remember the column indices. |
| 93499 | + ** |
| 93500 | + ** If the table has an INTEGER PRIMARY KEY column and that column |
| 93501 | + ** is named in the IDLIST, then record in the ipkColumn variable |
| 93502 | + ** the index into IDLIST of the primary key column. ipkColumn is |
| 93503 | + ** the index of the primary key as it appears in IDLIST, not as |
| 93504 | + ** is appears in the original table. (The index of the INTEGER |
| 93505 | + ** PRIMARY KEY in the original table is pTab->iPKey.) |
| 93506 | + */ |
| 93507 | + if( pColumn ){ |
| 93508 | + for(i=0; i<pColumn->nId; i++){ |
| 93509 | + pColumn->a[i].idx = -1; |
| 93510 | + } |
| 93511 | + for(i=0; i<pColumn->nId; i++){ |
| 93512 | + for(j=0; j<pTab->nCol; j++){ |
| 93513 | + if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){ |
| 93514 | + pColumn->a[i].idx = j; |
| 93515 | + if( i!=j ) bIdListInOrder = 0; |
| 93516 | + if( j==pTab->iPKey ){ |
| 93517 | + ipkColumn = i; assert( !withoutRowid ); |
| 93518 | + } |
| 93519 | + break; |
| 93520 | + } |
| 93521 | + } |
| 93522 | + if( j>=pTab->nCol ){ |
| 93523 | + if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){ |
| 93524 | + ipkColumn = i; |
| 93525 | + }else{ |
| 93526 | + sqlite3ErrorMsg(pParse, "table %S has no column named %s", |
| 93527 | + pTabList, 0, pColumn->a[i].zName); |
| 93528 | + pParse->checkSchema = 1; |
| 93529 | + goto insert_cleanup; |
| 93530 | + } |
| 93531 | + } |
| 93532 | + } |
| 93533 | + } |
| 93463 | 93534 | |
| 93464 | 93535 | /* Figure out how many columns of data are supplied. If the data |
| 93465 | 93536 | ** is coming from a SELECT statement, then generate a co-routine that |
| 93466 | 93537 | ** produces a single row of the SELECT on each invocation. The |
| 93467 | 93538 | ** co-routine is the common header to the 3rd and 4th templates. |
| 93468 | 93539 | */ |
| 93469 | 93540 | if( pSelect ){ |
| 93470 | 93541 | /* Data is coming from a SELECT. Generate a co-routine to run the SELECT */ |
| 93471 | | - int rc = sqlite3CodeCoroutine(pParse, pSelect, &dest); |
| 93472 | | - if( rc ) goto insert_cleanup; |
| 93542 | + int regYield; /* Register holding co-routine entry-point */ |
| 93543 | + int addrTop; /* Top of the co-routine */ |
| 93544 | + int rc; /* Result code */ |
| 93473 | 93545 | |
| 93474 | | - regEof = dest.iSDParm + 1; |
| 93546 | + regYield = ++pParse->nMem; |
| 93547 | + addrTop = sqlite3VdbeCurrentAddr(v) + 1; |
| 93548 | + sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop); |
| 93549 | + sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield); |
| 93550 | + dest.iSdst = bIdListInOrder ? regData : 0; |
| 93551 | + dest.nSdst = pTab->nCol; |
| 93552 | + rc = sqlite3Select(pParse, pSelect, &dest); |
| 93475 | 93553 | regFromSelect = dest.iSdst; |
| 93554 | + assert( pParse->nErr==0 || rc ); |
| 93555 | + if( rc || db->mallocFailed ) goto insert_cleanup; |
| 93556 | + sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield); |
| 93557 | + sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */ |
| 93476 | 93558 | assert( pSelect->pEList ); |
| 93477 | 93559 | nColumn = pSelect->pEList->nExpr; |
| 93478 | | - assert( dest.nSdst==nColumn ); |
| 93479 | 93560 | |
| 93480 | 93561 | /* Set useTempTable to TRUE if the result of the SELECT statement |
| 93481 | 93562 | ** should be written into a temporary table (template 4). Set to |
| 93482 | 93563 | ** FALSE if each output row of the SELECT can be written directly into |
| 93483 | 93564 | ** the destination table (template 3). |
| | @@ -93484,42 +93565,39 @@ |
| 93484 | 93565 | ** |
| 93485 | 93566 | ** A temp table must be used if the table being updated is also one |
| 93486 | 93567 | ** of the tables being read by the SELECT statement. Also use a |
| 93487 | 93568 | ** temp table in the case of row triggers. |
| 93488 | 93569 | */ |
| 93489 | | - if( pTrigger || readsTable(pParse, addrSelect, iDb, pTab) ){ |
| 93570 | + if( pTrigger || readsTable(pParse, iDb, pTab) ){ |
| 93490 | 93571 | useTempTable = 1; |
| 93491 | 93572 | } |
| 93492 | 93573 | |
| 93493 | 93574 | if( useTempTable ){ |
| 93494 | 93575 | /* Invoke the coroutine to extract information from the SELECT |
| 93495 | 93576 | ** and add it to a transient table srcTab. The code generated |
| 93496 | 93577 | ** here is from the 4th template: |
| 93497 | 93578 | ** |
| 93498 | 93579 | ** B: open temp table |
| 93499 | | - ** L: yield X |
| 93500 | | - ** if EOF goto M |
| 93580 | + ** L: yield X, goto M at EOF |
| 93501 | 93581 | ** insert row from R..R+n into temp table |
| 93502 | 93582 | ** goto L |
| 93503 | 93583 | ** M: ... |
| 93504 | 93584 | */ |
| 93505 | 93585 | int regRec; /* Register to hold packed record */ |
| 93506 | 93586 | int regTempRowid; /* Register to hold temp table ROWID */ |
| 93507 | | - int addrTop; /* Label "L" */ |
| 93508 | | - int addrIf; /* Address of jump to M */ |
| 93587 | + int addrL; /* Label "L" */ |
| 93509 | 93588 | |
| 93510 | 93589 | srcTab = pParse->nTab++; |
| 93511 | 93590 | regRec = sqlite3GetTempReg(pParse); |
| 93512 | 93591 | regTempRowid = sqlite3GetTempReg(pParse); |
| 93513 | 93592 | sqlite3VdbeAddOp2(v, OP_OpenEphemeral, srcTab, nColumn); |
| 93514 | | - addrTop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); |
| 93515 | | - addrIf = sqlite3VdbeAddOp1(v, OP_If, regEof); |
| 93593 | + addrL = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); VdbeCoverage(v); |
| 93516 | 93594 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regFromSelect, nColumn, regRec); |
| 93517 | 93595 | sqlite3VdbeAddOp2(v, OP_NewRowid, srcTab, regTempRowid); |
| 93518 | 93596 | sqlite3VdbeAddOp3(v, OP_Insert, srcTab, regRec, regTempRowid); |
| 93519 | | - sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop); |
| 93520 | | - sqlite3VdbeJumpHere(v, addrIf); |
| 93597 | + sqlite3VdbeAddOp2(v, OP_Goto, 0, addrL); |
| 93598 | + sqlite3VdbeJumpHere(v, addrL); |
| 93521 | 93599 | sqlite3ReleaseTempReg(pParse, regRec); |
| 93522 | 93600 | sqlite3ReleaseTempReg(pParse, regTempRowid); |
| 93523 | 93601 | } |
| 93524 | 93602 | }else{ |
| 93525 | 93603 | /* This is the case if the data for the INSERT is coming from a VALUES |
| | @@ -93535,10 +93613,18 @@ |
| 93535 | 93613 | if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){ |
| 93536 | 93614 | goto insert_cleanup; |
| 93537 | 93615 | } |
| 93538 | 93616 | } |
| 93539 | 93617 | } |
| 93618 | + |
| 93619 | + /* If there is no IDLIST term but the table has an integer primary |
| 93620 | + ** key, the set the ipkColumn variable to the integer primary key |
| 93621 | + ** column index in the original table definition. |
| 93622 | + */ |
| 93623 | + if( pColumn==0 && nColumn>0 ){ |
| 93624 | + ipkColumn = pTab->iPKey; |
| 93625 | + } |
| 93540 | 93626 | |
| 93541 | 93627 | /* Make sure the number of columns in the source data matches the number |
| 93542 | 93628 | ** of columns to be inserted into the table. |
| 93543 | 93629 | */ |
| 93544 | 93630 | if( IsVirtual(pTab) ){ |
| | @@ -93554,56 +93640,10 @@ |
| 93554 | 93640 | } |
| 93555 | 93641 | if( pColumn!=0 && nColumn!=pColumn->nId ){ |
| 93556 | 93642 | sqlite3ErrorMsg(pParse, "%d values for %d columns", nColumn, pColumn->nId); |
| 93557 | 93643 | goto insert_cleanup; |
| 93558 | 93644 | } |
| 93559 | | - |
| 93560 | | - /* If the INSERT statement included an IDLIST term, then make sure |
| 93561 | | - ** all elements of the IDLIST really are columns of the table and |
| 93562 | | - ** remember the column indices. |
| 93563 | | - ** |
| 93564 | | - ** If the table has an INTEGER PRIMARY KEY column and that column |
| 93565 | | - ** is named in the IDLIST, then record in the ipkColumn variable |
| 93566 | | - ** the index into IDLIST of the primary key column. ipkColumn is |
| 93567 | | - ** the index of the primary key as it appears in IDLIST, not as |
| 93568 | | - ** is appears in the original table. (The index of the INTEGER |
| 93569 | | - ** PRIMARY KEY in the original table is pTab->iPKey.) |
| 93570 | | - */ |
| 93571 | | - if( pColumn ){ |
| 93572 | | - for(i=0; i<pColumn->nId; i++){ |
| 93573 | | - pColumn->a[i].idx = -1; |
| 93574 | | - } |
| 93575 | | - for(i=0; i<pColumn->nId; i++){ |
| 93576 | | - for(j=0; j<pTab->nCol; j++){ |
| 93577 | | - if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){ |
| 93578 | | - pColumn->a[i].idx = j; |
| 93579 | | - if( j==pTab->iPKey ){ |
| 93580 | | - ipkColumn = i; assert( !withoutRowid ); |
| 93581 | | - } |
| 93582 | | - break; |
| 93583 | | - } |
| 93584 | | - } |
| 93585 | | - if( j>=pTab->nCol ){ |
| 93586 | | - if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){ |
| 93587 | | - ipkColumn = i; |
| 93588 | | - }else{ |
| 93589 | | - sqlite3ErrorMsg(pParse, "table %S has no column named %s", |
| 93590 | | - pTabList, 0, pColumn->a[i].zName); |
| 93591 | | - pParse->checkSchema = 1; |
| 93592 | | - goto insert_cleanup; |
| 93593 | | - } |
| 93594 | | - } |
| 93595 | | - } |
| 93596 | | - } |
| 93597 | | - |
| 93598 | | - /* If there is no IDLIST term but the table has an integer primary |
| 93599 | | - ** key, the set the ipkColumn variable to the integer primary key |
| 93600 | | - ** column index in the original table definition. |
| 93601 | | - */ |
| 93602 | | - if( pColumn==0 && nColumn>0 ){ |
| 93603 | | - ipkColumn = pTab->iPKey; |
| 93604 | | - } |
| 93605 | 93645 | |
| 93606 | 93646 | /* Initialize the count of rows to be inserted |
| 93607 | 93647 | */ |
| 93608 | 93648 | if( db->flags & SQLITE_CountRows ){ |
| 93609 | 93649 | regRowCount = ++pParse->nMem; |
| | @@ -93627,42 +93667,30 @@ |
| 93627 | 93667 | /* This is the top of the main insertion loop */ |
| 93628 | 93668 | if( useTempTable ){ |
| 93629 | 93669 | /* This block codes the top of loop only. The complete loop is the |
| 93630 | 93670 | ** following pseudocode (template 4): |
| 93631 | 93671 | ** |
| 93632 | | - ** rewind temp table |
| 93672 | + ** rewind temp table, if empty goto D |
| 93633 | 93673 | ** C: loop over rows of intermediate table |
| 93634 | 93674 | ** transfer values form intermediate table into <table> |
| 93635 | 93675 | ** end loop |
| 93636 | 93676 | ** D: ... |
| 93637 | 93677 | */ |
| 93638 | | - addrInsTop = sqlite3VdbeAddOp1(v, OP_Rewind, srcTab); |
| 93678 | + addrInsTop = sqlite3VdbeAddOp1(v, OP_Rewind, srcTab); VdbeCoverage(v); |
| 93639 | 93679 | addrCont = sqlite3VdbeCurrentAddr(v); |
| 93640 | 93680 | }else if( pSelect ){ |
| 93641 | 93681 | /* This block codes the top of loop only. The complete loop is the |
| 93642 | 93682 | ** following pseudocode (template 3): |
| 93643 | 93683 | ** |
| 93644 | | - ** C: yield X |
| 93645 | | - ** if EOF goto D |
| 93684 | + ** C: yield X, at EOF goto D |
| 93646 | 93685 | ** insert the select result into <table> from R..R+n |
| 93647 | 93686 | ** goto C |
| 93648 | 93687 | ** D: ... |
| 93649 | 93688 | */ |
| 93650 | | - addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); |
| 93651 | | - addrInsTop = sqlite3VdbeAddOp1(v, OP_If, regEof); |
| 93652 | | - } |
| 93653 | | - |
| 93654 | | - /* Allocate registers for holding the rowid of the new row, |
| 93655 | | - ** the content of the new row, and the assemblied row record. |
| 93656 | | - */ |
| 93657 | | - regRowid = regIns = pParse->nMem+1; |
| 93658 | | - pParse->nMem += pTab->nCol + 1; |
| 93659 | | - if( IsVirtual(pTab) ){ |
| 93660 | | - regRowid++; |
| 93661 | | - pParse->nMem++; |
| 93662 | | - } |
| 93663 | | - regData = regRowid+1; |
| 93689 | + addrInsTop = addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); |
| 93690 | + VdbeCoverage(v); |
| 93691 | + } |
| 93664 | 93692 | |
| 93665 | 93693 | /* Run the BEFORE and INSTEAD OF triggers, if there are any |
| 93666 | 93694 | */ |
| 93667 | 93695 | endOfLoop = sqlite3VdbeMakeLabel(v); |
| 93668 | 93696 | if( tmask & TRIGGER_BEFORE ){ |
| | @@ -93683,14 +93711,14 @@ |
| 93683 | 93711 | sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regCols); |
| 93684 | 93712 | }else{ |
| 93685 | 93713 | assert( pSelect==0 ); /* Otherwise useTempTable is true */ |
| 93686 | 93714 | sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regCols); |
| 93687 | 93715 | } |
| 93688 | | - j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols); |
| 93716 | + j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols); VdbeCoverage(v); |
| 93689 | 93717 | sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols); |
| 93690 | 93718 | sqlite3VdbeJumpHere(v, j1); |
| 93691 | | - sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols); |
| 93719 | + sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols); VdbeCoverage(v); |
| 93692 | 93720 | } |
| 93693 | 93721 | |
| 93694 | 93722 | /* Cannot have triggers on a virtual table. If it were possible, |
| 93695 | 93723 | ** this block would have to account for hidden column. |
| 93696 | 93724 | */ |
| | @@ -93720,12 +93748,11 @@ |
| 93720 | 93748 | ** do not attempt any conversions before assembling the record. |
| 93721 | 93749 | ** If this is a real table, attempt conversions as required by the |
| 93722 | 93750 | ** table column affinities. |
| 93723 | 93751 | */ |
| 93724 | 93752 | if( !isView ){ |
| 93725 | | - sqlite3VdbeAddOp2(v, OP_Affinity, regCols+1, pTab->nCol); |
| 93726 | | - sqlite3TableAffinityStr(v, pTab); |
| 93753 | + sqlite3TableAffinity(v, pTab, regCols+1); |
| 93727 | 93754 | } |
| 93728 | 93755 | |
| 93729 | 93756 | /* Fire BEFORE or INSTEAD OF triggers */ |
| 93730 | 93757 | sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_BEFORE, |
| 93731 | 93758 | pTab, regCols-pTab->nCol-1, onError, endOfLoop); |
| | @@ -93743,11 +93770,11 @@ |
| 93743 | 93770 | } |
| 93744 | 93771 | if( ipkColumn>=0 ){ |
| 93745 | 93772 | if( useTempTable ){ |
| 93746 | 93773 | sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regRowid); |
| 93747 | 93774 | }else if( pSelect ){ |
| 93748 | | - sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+ipkColumn, regRowid); |
| 93775 | + sqlite3VdbeAddOp2(v, OP_Copy, regFromSelect+ipkColumn, regRowid); |
| 93749 | 93776 | }else{ |
| 93750 | 93777 | VdbeOp *pOp; |
| 93751 | 93778 | sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regRowid); |
| 93752 | 93779 | pOp = sqlite3VdbeGetOp(v, -1); |
| 93753 | 93780 | if( ALWAYS(pOp) && pOp->opcode==OP_Null && !IsVirtual(pTab) ){ |
| | @@ -93762,18 +93789,18 @@ |
| 93762 | 93789 | ** to generate a unique primary key value. |
| 93763 | 93790 | */ |
| 93764 | 93791 | if( !appendFlag ){ |
| 93765 | 93792 | int j1; |
| 93766 | 93793 | if( !IsVirtual(pTab) ){ |
| 93767 | | - j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid); |
| 93794 | + j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid); VdbeCoverage(v); |
| 93768 | 93795 | sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc); |
| 93769 | 93796 | sqlite3VdbeJumpHere(v, j1); |
| 93770 | 93797 | }else{ |
| 93771 | 93798 | j1 = sqlite3VdbeCurrentAddr(v); |
| 93772 | | - sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, j1+2); |
| 93799 | + sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, j1+2); VdbeCoverage(v); |
| 93773 | 93800 | } |
| 93774 | | - sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid); |
| 93801 | + sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid); VdbeCoverage(v); |
| 93775 | 93802 | } |
| 93776 | 93803 | }else if( IsVirtual(pTab) || withoutRowid ){ |
| 93777 | 93804 | sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid); |
| 93778 | 93805 | }else{ |
| 93779 | 93806 | sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc); |
| | @@ -93789,12 +93816,13 @@ |
| 93789 | 93816 | int iRegStore = regRowid+1+i; |
| 93790 | 93817 | if( i==pTab->iPKey ){ |
| 93791 | 93818 | /* The value of the INTEGER PRIMARY KEY column is always a NULL. |
| 93792 | 93819 | ** Whenever this column is read, the rowid will be substituted |
| 93793 | 93820 | ** in its place. Hence, fill this column with a NULL to avoid |
| 93794 | | - ** taking up data space with information that will never be used. */ |
| 93795 | | - sqlite3VdbeAddOp2(v, OP_Null, 0, iRegStore); |
| 93821 | + ** taking up data space with information that will never be used. |
| 93822 | + ** As there may be shallow copies of this value, make it a soft-NULL */ |
| 93823 | + sqlite3VdbeAddOp1(v, OP_SoftNull, iRegStore); |
| 93796 | 93824 | continue; |
| 93797 | 93825 | } |
| 93798 | 93826 | if( pColumn==0 ){ |
| 93799 | 93827 | if( IsHiddenColumn(&pTab->aCol[i]) ){ |
| 93800 | 93828 | assert( IsVirtual(pTab) ); |
| | @@ -93807,15 +93835,17 @@ |
| 93807 | 93835 | for(j=0; j<pColumn->nId; j++){ |
| 93808 | 93836 | if( pColumn->a[j].idx==i ) break; |
| 93809 | 93837 | } |
| 93810 | 93838 | } |
| 93811 | 93839 | if( j<0 || nColumn==0 || (pColumn && j>=pColumn->nId) ){ |
| 93812 | | - sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, iRegStore); |
| 93840 | + sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore); |
| 93813 | 93841 | }else if( useTempTable ){ |
| 93814 | 93842 | sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, iRegStore); |
| 93815 | 93843 | }else if( pSelect ){ |
| 93816 | | - sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+j, iRegStore); |
| 93844 | + if( regFromSelect!=regData ){ |
| 93845 | + sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+j, iRegStore); |
| 93846 | + } |
| 93817 | 93847 | }else{ |
| 93818 | 93848 | sqlite3ExprCode(pParse, pList->a[j].pExpr, iRegStore); |
| 93819 | 93849 | } |
| 93820 | 93850 | } |
| 93821 | 93851 | |
| | @@ -93857,11 +93887,11 @@ |
| 93857 | 93887 | /* The bottom of the main insertion loop, if the data source |
| 93858 | 93888 | ** is a SELECT statement. |
| 93859 | 93889 | */ |
| 93860 | 93890 | sqlite3VdbeResolveLabel(v, endOfLoop); |
| 93861 | 93891 | if( useTempTable ){ |
| 93862 | | - sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); |
| 93892 | + sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); VdbeCoverage(v); |
| 93863 | 93893 | sqlite3VdbeJumpHere(v, addrInsTop); |
| 93864 | 93894 | sqlite3VdbeAddOp1(v, OP_Close, srcTab); |
| 93865 | 93895 | }else if( pSelect ){ |
| 93866 | 93896 | sqlite3VdbeAddOp2(v, OP_Goto, 0, addrCont); |
| 93867 | 93897 | sqlite3VdbeJumpHere(v, addrInsTop); |
| | @@ -94024,10 +94054,11 @@ |
| 94024 | 94054 | int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */ |
| 94025 | 94055 | int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */ |
| 94026 | 94056 | int ipkTop = 0; /* Top of the rowid change constraint check */ |
| 94027 | 94057 | int ipkBottom = 0; /* Bottom of the rowid change constraint check */ |
| 94028 | 94058 | u8 isUpdate; /* True if this is an UPDATE operation */ |
| 94059 | + u8 bAffinityDone = 0; /* True if the OP_Affinity operation has been run */ |
| 94029 | 94060 | int regRowid = -1; /* Register holding ROWID value */ |
| 94030 | 94061 | |
| 94031 | 94062 | isUpdate = regOldData!=0; |
| 94032 | 94063 | db = pParse->db; |
| 94033 | 94064 | v = sqlite3GetVdbe(pParse); |
| | @@ -94078,19 +94109,21 @@ |
| 94078 | 94109 | char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName, |
| 94079 | 94110 | pTab->aCol[i].zName); |
| 94080 | 94111 | sqlite3VdbeAddOp4(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, onError, |
| 94081 | 94112 | regNewData+1+i, zMsg, P4_DYNAMIC); |
| 94082 | 94113 | sqlite3VdbeChangeP5(v, P5_ConstraintNotNull); |
| 94114 | + VdbeCoverage(v); |
| 94083 | 94115 | break; |
| 94084 | 94116 | } |
| 94085 | 94117 | case OE_Ignore: { |
| 94086 | 94118 | sqlite3VdbeAddOp2(v, OP_IsNull, regNewData+1+i, ignoreDest); |
| 94119 | + VdbeCoverage(v); |
| 94087 | 94120 | break; |
| 94088 | 94121 | } |
| 94089 | 94122 | default: { |
| 94090 | 94123 | assert( onError==OE_Replace ); |
| 94091 | | - j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regNewData+1+i); |
| 94124 | + j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regNewData+1+i); VdbeCoverage(v); |
| 94092 | 94125 | sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i); |
| 94093 | 94126 | sqlite3VdbeJumpHere(v, j1); |
| 94094 | 94127 | break; |
| 94095 | 94128 | } |
| 94096 | 94129 | } |
| | @@ -94138,10 +94171,12 @@ |
| 94138 | 94171 | if( isUpdate ){ |
| 94139 | 94172 | /* pkChng!=0 does not mean that the rowid has change, only that |
| 94140 | 94173 | ** it might have changed. Skip the conflict logic below if the rowid |
| 94141 | 94174 | ** is unchanged. */ |
| 94142 | 94175 | sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRowidOk, regOldData); |
| 94176 | + sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); |
| 94177 | + VdbeCoverage(v); |
| 94143 | 94178 | } |
| 94144 | 94179 | |
| 94145 | 94180 | /* If the response to a rowid conflict is REPLACE but the response |
| 94146 | 94181 | ** to some other UNIQUE constraint is FAIL or IGNORE, then we need |
| 94147 | 94182 | ** to defer the running of the rowid conflict checking until after |
| | @@ -94157,10 +94192,11 @@ |
| 94157 | 94192 | } |
| 94158 | 94193 | |
| 94159 | 94194 | /* Check to see if the new rowid already exists in the table. Skip |
| 94160 | 94195 | ** the following conflict logic if it does not. */ |
| 94161 | 94196 | sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, addrRowidOk, regNewData); |
| 94197 | + VdbeCoverage(v); |
| 94162 | 94198 | |
| 94163 | 94199 | /* Generate code that deals with a rowid collision */ |
| 94164 | 94200 | switch( onError ){ |
| 94165 | 94201 | default: { |
| 94166 | 94202 | onError = OE_Abort; |
| | @@ -94235,10 +94271,14 @@ |
| 94235 | 94271 | int regR; /* Range of registers holding conflicting PK */ |
| 94236 | 94272 | int iThisCur; /* Cursor for this UNIQUE index */ |
| 94237 | 94273 | int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */ |
| 94238 | 94274 | |
| 94239 | 94275 | if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */ |
| 94276 | + if( bAffinityDone==0 ){ |
| 94277 | + sqlite3TableAffinity(v, pTab, regNewData+1); |
| 94278 | + bAffinityDone = 1; |
| 94279 | + } |
| 94240 | 94280 | iThisCur = iIdxCur+ix; |
| 94241 | 94281 | addrUniqueOk = sqlite3VdbeMakeLabel(v); |
| 94242 | 94282 | |
| 94243 | 94283 | /* Skip partial indices for which the WHERE clause is not true */ |
| 94244 | 94284 | if( pIdx->pPartIdxWhere ){ |
| | @@ -94265,11 +94305,10 @@ |
| 94265 | 94305 | } |
| 94266 | 94306 | sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i); |
| 94267 | 94307 | VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName)); |
| 94268 | 94308 | } |
| 94269 | 94309 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]); |
| 94270 | | - sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT); |
| 94271 | 94310 | VdbeComment((v, "for %s", pIdx->zName)); |
| 94272 | 94311 | sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn); |
| 94273 | 94312 | |
| 94274 | 94313 | /* In an UPDATE operation, if this index is the PRIMARY KEY index |
| 94275 | 94314 | ** of a WITHOUT ROWID table and there has been no change the |
| | @@ -94293,11 +94332,11 @@ |
| 94293 | 94332 | onError = OE_Abort; |
| 94294 | 94333 | } |
| 94295 | 94334 | |
| 94296 | 94335 | /* Check to see if the new index entry will be unique */ |
| 94297 | 94336 | sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk, |
| 94298 | | - regIdx, pIdx->nKeyCol); |
| 94337 | + regIdx, pIdx->nKeyCol); VdbeCoverage(v); |
| 94299 | 94338 | |
| 94300 | 94339 | /* Generate code to handle collisions */ |
| 94301 | 94340 | regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField); |
| 94302 | 94341 | if( isUpdate || onError==OE_Replace ){ |
| 94303 | 94342 | if( HasRowid(pTab) ){ |
| | @@ -94304,10 +94343,12 @@ |
| 94304 | 94343 | sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR); |
| 94305 | 94344 | /* Conflict only if the rowid of the existing index entry |
| 94306 | 94345 | ** is different from old-rowid */ |
| 94307 | 94346 | if( isUpdate ){ |
| 94308 | 94347 | sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData); |
| 94348 | + sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); |
| 94349 | + VdbeCoverage(v); |
| 94309 | 94350 | } |
| 94310 | 94351 | }else{ |
| 94311 | 94352 | int x; |
| 94312 | 94353 | /* Extract the PRIMARY KEY from the end of the index entry and |
| 94313 | 94354 | ** store it in registers regR..regR+nPk-1 */ |
| | @@ -94339,10 +94380,13 @@ |
| 94339 | 94380 | op = OP_Eq; |
| 94340 | 94381 | } |
| 94341 | 94382 | sqlite3VdbeAddOp4(v, op, |
| 94342 | 94383 | regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ |
| 94343 | 94384 | ); |
| 94385 | + sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); |
| 94386 | + VdbeCoverageIf(v, op==OP_Eq); |
| 94387 | + VdbeCoverageIf(v, op==OP_Ne); |
| 94344 | 94388 | } |
| 94345 | 94389 | } |
| 94346 | 94390 | } |
| 94347 | 94391 | } |
| 94348 | 94392 | |
| | @@ -94410,18 +94454,21 @@ |
| 94410 | 94454 | Index *pIdx; /* An index being inserted or updated */ |
| 94411 | 94455 | u8 pik_flags; /* flag values passed to the btree insert */ |
| 94412 | 94456 | int regData; /* Content registers (after the rowid) */ |
| 94413 | 94457 | int regRec; /* Register holding assemblied record for the table */ |
| 94414 | 94458 | int i; /* Loop counter */ |
| 94459 | + u8 bAffinityDone = 0; /* True if OP_Affinity has been run already */ |
| 94415 | 94460 | |
| 94416 | 94461 | v = sqlite3GetVdbe(pParse); |
| 94417 | 94462 | assert( v!=0 ); |
| 94418 | 94463 | assert( pTab->pSelect==0 ); /* This table is not a VIEW */ |
| 94419 | 94464 | for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){ |
| 94420 | 94465 | if( aRegIdx[i]==0 ) continue; |
| 94466 | + bAffinityDone = 1; |
| 94421 | 94467 | if( pIdx->pPartIdxWhere ){ |
| 94422 | 94468 | sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2); |
| 94469 | + VdbeCoverage(v); |
| 94423 | 94470 | } |
| 94424 | 94471 | sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i]); |
| 94425 | 94472 | pik_flags = 0; |
| 94426 | 94473 | if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT; |
| 94427 | 94474 | if( pIdx->autoIndex==2 && !HasRowid(pTab) ){ |
| | @@ -94432,11 +94479,11 @@ |
| 94432 | 94479 | } |
| 94433 | 94480 | if( !HasRowid(pTab) ) return; |
| 94434 | 94481 | regData = regNewData + 1; |
| 94435 | 94482 | regRec = sqlite3GetTempReg(pParse); |
| 94436 | 94483 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec); |
| 94437 | | - sqlite3TableAffinityStr(v, pTab); |
| 94484 | + if( !bAffinityDone ) sqlite3TableAffinity(v, pTab, 0); |
| 94438 | 94485 | sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol); |
| 94439 | 94486 | if( pParse->nested ){ |
| 94440 | 94487 | pik_flags = 0; |
| 94441 | 94488 | }else{ |
| 94442 | 94489 | pik_flags = OPFLAG_NCHANGE; |
| | @@ -94801,20 +94848,21 @@ |
| 94801 | 94848 | ** (2) The destination has a unique index. (The xfer optimization |
| 94802 | 94849 | ** is unable to test uniqueness.) |
| 94803 | 94850 | ** |
| 94804 | 94851 | ** (3) onError is something other than OE_Abort and OE_Rollback. |
| 94805 | 94852 | */ |
| 94806 | | - addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); |
| 94853 | + addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v); |
| 94807 | 94854 | emptyDestTest = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0); |
| 94808 | 94855 | sqlite3VdbeJumpHere(v, addr1); |
| 94809 | 94856 | } |
| 94810 | 94857 | if( HasRowid(pSrc) ){ |
| 94811 | 94858 | sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead); |
| 94812 | | - emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); |
| 94859 | + emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v); |
| 94813 | 94860 | if( pDest->iPKey>=0 ){ |
| 94814 | 94861 | addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid); |
| 94815 | 94862 | addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid); |
| 94863 | + VdbeCoverage(v); |
| 94816 | 94864 | sqlite3RowidConstraint(pParse, onError, pDest); |
| 94817 | 94865 | sqlite3VdbeJumpHere(v, addr2); |
| 94818 | 94866 | autoIncStep(pParse, regAutoinc, regRowid); |
| 94819 | 94867 | }else if( pDest->pIndex==0 ){ |
| 94820 | 94868 | addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid); |
| | @@ -94824,11 +94872,11 @@ |
| 94824 | 94872 | } |
| 94825 | 94873 | sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData); |
| 94826 | 94874 | sqlite3VdbeAddOp3(v, OP_Insert, iDest, regData, regRowid); |
| 94827 | 94875 | sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND); |
| 94828 | 94876 | sqlite3VdbeChangeP4(v, -1, pDest->zName, 0); |
| 94829 | | - sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); |
| 94877 | + sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); VdbeCoverage(v); |
| 94830 | 94878 | sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0); |
| 94831 | 94879 | sqlite3VdbeAddOp2(v, OP_Close, iDest, 0); |
| 94832 | 94880 | }else{ |
| 94833 | 94881 | sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName); |
| 94834 | 94882 | sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName); |
| | @@ -94843,19 +94891,19 @@ |
| 94843 | 94891 | VdbeComment((v, "%s", pSrcIdx->zName)); |
| 94844 | 94892 | sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest); |
| 94845 | 94893 | sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx); |
| 94846 | 94894 | sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR); |
| 94847 | 94895 | VdbeComment((v, "%s", pDestIdx->zName)); |
| 94848 | | - addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); |
| 94896 | + addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v); |
| 94849 | 94897 | sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData); |
| 94850 | 94898 | sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1); |
| 94851 | | - sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); |
| 94899 | + sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v); |
| 94852 | 94900 | sqlite3VdbeJumpHere(v, addr1); |
| 94853 | 94901 | sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0); |
| 94854 | 94902 | sqlite3VdbeAddOp2(v, OP_Close, iDest, 0); |
| 94855 | 94903 | } |
| 94856 | | - sqlite3VdbeJumpHere(v, emptySrcTest); |
| 94904 | + if( emptySrcTest ) sqlite3VdbeJumpHere(v, emptySrcTest); |
| 94857 | 94905 | sqlite3ReleaseTempReg(pParse, regRowid); |
| 94858 | 94906 | sqlite3ReleaseTempReg(pParse, regData); |
| 94859 | 94907 | if( emptyDestTest ){ |
| 94860 | 94908 | sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_OK, 0); |
| 94861 | 94909 | sqlite3VdbeJumpHere(v, emptyDestTest); |
| | @@ -97085,10 +97133,11 @@ |
| 97085 | 97133 | ** is always on by default regardless of the sign of the default cache |
| 97086 | 97134 | ** size. But continue to take the absolute value of the default cache |
| 97087 | 97135 | ** size of historical compatibility. |
| 97088 | 97136 | */ |
| 97089 | 97137 | case PragTyp_DEFAULT_CACHE_SIZE: { |
| 97138 | + static const int iLn = __LINE__+2; |
| 97090 | 97139 | static const VdbeOpList getCacheSize[] = { |
| 97091 | 97140 | { OP_Transaction, 0, 0, 0}, /* 0 */ |
| 97092 | 97141 | { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */ |
| 97093 | 97142 | { OP_IfPos, 1, 8, 0}, |
| 97094 | 97143 | { OP_Integer, 0, 2, 0}, |
| | @@ -97102,11 +97151,11 @@ |
| 97102 | 97151 | sqlite3VdbeUsesBtree(v, iDb); |
| 97103 | 97152 | if( !zRight ){ |
| 97104 | 97153 | sqlite3VdbeSetNumCols(v, 1); |
| 97105 | 97154 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC); |
| 97106 | 97155 | pParse->nMem += 2; |
| 97107 | | - addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize); |
| 97156 | + addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize,iLn); |
| 97108 | 97157 | sqlite3VdbeChangeP1(v, addr, iDb); |
| 97109 | 97158 | sqlite3VdbeChangeP1(v, addr+1, iDb); |
| 97110 | 97159 | sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE); |
| 97111 | 97160 | }else{ |
| 97112 | 97161 | int size = sqlite3AbsInt32(sqlite3Atoi(zRight)); |
| | @@ -97347,20 +97396,21 @@ |
| 97347 | 97396 | /* When setting the auto_vacuum mode to either "full" or |
| 97348 | 97397 | ** "incremental", write the value of meta[6] in the database |
| 97349 | 97398 | ** file. Before writing to meta[6], check that meta[3] indicates |
| 97350 | 97399 | ** that this really is an auto-vacuum capable database. |
| 97351 | 97400 | */ |
| 97401 | + static const int iLn = __LINE__+2; |
| 97352 | 97402 | static const VdbeOpList setMeta6[] = { |
| 97353 | 97403 | { OP_Transaction, 0, 1, 0}, /* 0 */ |
| 97354 | 97404 | { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE}, |
| 97355 | 97405 | { OP_If, 1, 0, 0}, /* 2 */ |
| 97356 | 97406 | { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */ |
| 97357 | 97407 | { OP_Integer, 0, 1, 0}, /* 4 */ |
| 97358 | 97408 | { OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */ |
| 97359 | 97409 | }; |
| 97360 | 97410 | int iAddr; |
| 97361 | | - iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6); |
| 97411 | + iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6, iLn); |
| 97362 | 97412 | sqlite3VdbeChangeP1(v, iAddr, iDb); |
| 97363 | 97413 | sqlite3VdbeChangeP1(v, iAddr+1, iDb); |
| 97364 | 97414 | sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4); |
| 97365 | 97415 | sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1); |
| 97366 | 97416 | sqlite3VdbeChangeP1(v, iAddr+5, iDb); |
| | @@ -97382,14 +97432,14 @@ |
| 97382 | 97432 | if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){ |
| 97383 | 97433 | iLimit = 0x7fffffff; |
| 97384 | 97434 | } |
| 97385 | 97435 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 97386 | 97436 | sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1); |
| 97387 | | - addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb); |
| 97437 | + addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb); VdbeCoverage(v); |
| 97388 | 97438 | sqlite3VdbeAddOp1(v, OP_ResultRow, 1); |
| 97389 | 97439 | sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); |
| 97390 | | - sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr); |
| 97440 | + sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr); VdbeCoverage(v); |
| 97391 | 97441 | sqlite3VdbeJumpHere(v, addr); |
| 97392 | 97442 | break; |
| 97393 | 97443 | } |
| 97394 | 97444 | #endif |
| 97395 | 97445 | |
| | @@ -97956,11 +98006,11 @@ |
| 97956 | 98006 | } |
| 97957 | 98007 | } |
| 97958 | 98008 | assert( pParse->nErr>0 || pFK==0 ); |
| 97959 | 98009 | if( pFK ) break; |
| 97960 | 98010 | if( pParse->nTab<i ) pParse->nTab = i; |
| 97961 | | - addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); |
| 98011 | + addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v); |
| 97962 | 98012 | for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
| 97963 | 98013 | pParent = sqlite3FindTable(db, pFK->zTo, zDb); |
| 97964 | 98014 | pIdx = 0; |
| 97965 | 98015 | aiCols = 0; |
| 97966 | 98016 | if( pParent ){ |
| | @@ -97972,30 +98022,30 @@ |
| 97972 | 98022 | int iKey = pFK->aCol[0].iFrom; |
| 97973 | 98023 | assert( iKey>=0 && iKey<pTab->nCol ); |
| 97974 | 98024 | if( iKey!=pTab->iPKey ){ |
| 97975 | 98025 | sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow); |
| 97976 | 98026 | sqlite3ColumnDefault(v, pTab, iKey, regRow); |
| 97977 | | - sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); |
| 97978 | | - sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow, |
| 97979 | | - sqlite3VdbeCurrentAddr(v)+3); |
| 98027 | + sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v); |
| 98028 | + sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow, |
| 98029 | + sqlite3VdbeCurrentAddr(v)+3); VdbeCoverage(v); |
| 97980 | 98030 | }else{ |
| 97981 | 98031 | sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow); |
| 97982 | 98032 | } |
| 97983 | | - sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); |
| 98033 | + sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); VdbeCoverage(v); |
| 97984 | 98034 | sqlite3VdbeAddOp2(v, OP_Goto, 0, addrOk); |
| 97985 | 98035 | sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2); |
| 97986 | 98036 | }else{ |
| 97987 | 98037 | for(j=0; j<pFK->nCol; j++){ |
| 97988 | 98038 | sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, |
| 97989 | 98039 | aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j); |
| 97990 | | - sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); |
| 98040 | + sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v); |
| 97991 | 98041 | } |
| 97992 | 98042 | if( pParent ){ |
| 97993 | | - sqlite3VdbeAddOp3(v, OP_MakeRecord, regRow, pFK->nCol, regKey); |
| 97994 | | - sqlite3VdbeChangeP4(v, -1, |
| 97995 | | - sqlite3IndexAffinityStr(v,pIdx), P4_TRANSIENT); |
| 98043 | + sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey, |
| 98044 | + sqlite3IndexAffinityStr(v,pIdx), pFK->nCol); |
| 97996 | 98045 | sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0); |
| 98046 | + VdbeCoverage(v); |
| 97997 | 98047 | } |
| 97998 | 98048 | } |
| 97999 | 98049 | sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1); |
| 98000 | 98050 | sqlite3VdbeAddOp4(v, OP_String8, 0, regResult+2, 0, |
| 98001 | 98051 | pFK->zTo, P4_TRANSIENT); |
| | @@ -98002,11 +98052,11 @@ |
| 98002 | 98052 | sqlite3VdbeAddOp2(v, OP_Integer, i-1, regResult+3); |
| 98003 | 98053 | sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4); |
| 98004 | 98054 | sqlite3VdbeResolveLabel(v, addrOk); |
| 98005 | 98055 | sqlite3DbFree(db, aiCols); |
| 98006 | 98056 | } |
| 98007 | | - sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); |
| 98057 | + sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v); |
| 98008 | 98058 | sqlite3VdbeJumpHere(v, addrTop); |
| 98009 | 98059 | } |
| 98010 | 98060 | } |
| 98011 | 98061 | break; |
| 98012 | 98062 | #endif /* !defined(SQLITE_OMIT_TRIGGER) */ |
| | @@ -98049,10 +98099,11 @@ |
| 98049 | 98099 | |
| 98050 | 98100 | /* Code that appears at the end of the integrity check. If no error |
| 98051 | 98101 | ** messages have been generated, output OK. Otherwise output the |
| 98052 | 98102 | ** error message |
| 98053 | 98103 | */ |
| 98104 | + static const int iLn = __LINE__+2; |
| 98054 | 98105 | static const VdbeOpList endCode[] = { |
| 98055 | 98106 | { OP_AddImm, 1, 0, 0}, /* 0 */ |
| 98056 | 98107 | { OP_IfNeg, 1, 0, 0}, /* 1 */ |
| 98057 | 98108 | { OP_String8, 0, 3, 0}, /* 2 */ |
| 98058 | 98109 | { OP_ResultRow, 3, 1, 0}, |
| | @@ -98097,10 +98148,11 @@ |
| 98097 | 98148 | if( OMIT_TEMPDB && i==1 ) continue; |
| 98098 | 98149 | if( iDb>=0 && i!=iDb ) continue; |
| 98099 | 98150 | |
| 98100 | 98151 | sqlite3CodeVerifySchema(pParse, i); |
| 98101 | 98152 | addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */ |
| 98153 | + VdbeCoverage(v); |
| 98102 | 98154 | sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); |
| 98103 | 98155 | sqlite3VdbeJumpHere(v, addr); |
| 98104 | 98156 | |
| 98105 | 98157 | /* Do an integrity check of the B-Tree |
| 98106 | 98158 | ** |
| | @@ -98128,11 +98180,11 @@ |
| 98128 | 98180 | pParse->nMem = MAX( pParse->nMem, cnt+8 ); |
| 98129 | 98181 | |
| 98130 | 98182 | /* Do the b-tree integrity checks */ |
| 98131 | 98183 | sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1); |
| 98132 | 98184 | sqlite3VdbeChangeP5(v, (u8)i); |
| 98133 | | - addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); |
| 98185 | + addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v); |
| 98134 | 98186 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, |
| 98135 | 98187 | sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName), |
| 98136 | 98188 | P4_DYNAMIC); |
| 98137 | 98189 | sqlite3VdbeAddOp2(v, OP_Move, 2, 4); |
| 98138 | 98190 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2); |
| | @@ -98150,10 +98202,11 @@ |
| 98150 | 98202 | int r1 = -1; |
| 98151 | 98203 | |
| 98152 | 98204 | if( pTab->pIndex==0 ) continue; |
| 98153 | 98205 | pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab); |
| 98154 | 98206 | addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */ |
| 98207 | + VdbeCoverage(v); |
| 98155 | 98208 | sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); |
| 98156 | 98209 | sqlite3VdbeJumpHere(v, addr); |
| 98157 | 98210 | sqlite3ExprCacheClear(pParse); |
| 98158 | 98211 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, |
| 98159 | 98212 | 1, 0, &iDataCur, &iIdxCur); |
| | @@ -98160,57 +98213,58 @@ |
| 98160 | 98213 | sqlite3VdbeAddOp2(v, OP_Integer, 0, 7); |
| 98161 | 98214 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
| 98162 | 98215 | sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */ |
| 98163 | 98216 | } |
| 98164 | 98217 | pParse->nMem = MAX(pParse->nMem, 8+j); |
| 98165 | | - sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); |
| 98218 | + sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v); |
| 98166 | 98219 | loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1); |
| 98167 | 98220 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
| 98168 | 98221 | int jmp2, jmp3, jmp4; |
| 98169 | 98222 | if( pPk==pIdx ) continue; |
| 98170 | 98223 | r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3, |
| 98171 | 98224 | pPrior, r1); |
| 98172 | 98225 | pPrior = pIdx; |
| 98173 | 98226 | sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */ |
| 98174 | 98227 | jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, 0, r1, |
| 98175 | | - pIdx->nColumn); |
| 98228 | + pIdx->nColumn); VdbeCoverage(v); |
| 98176 | 98229 | sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */ |
| 98177 | 98230 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, "row ", P4_STATIC); |
| 98178 | 98231 | sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3); |
| 98179 | 98232 | sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, " missing from index ", |
| 98180 | 98233 | P4_STATIC); |
| 98181 | 98234 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); |
| 98182 | 98235 | sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, pIdx->zName, P4_TRANSIENT); |
| 98183 | 98236 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); |
| 98184 | 98237 | sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1); |
| 98185 | | - jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); |
| 98238 | + jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v); |
| 98186 | 98239 | sqlite3VdbeAddOp0(v, OP_Halt); |
| 98187 | 98240 | sqlite3VdbeJumpHere(v, jmp4); |
| 98188 | 98241 | sqlite3VdbeJumpHere(v, jmp2); |
| 98189 | 98242 | sqlite3VdbeResolveLabel(v, jmp3); |
| 98190 | 98243 | } |
| 98191 | | - sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); |
| 98244 | + sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v); |
| 98192 | 98245 | sqlite3VdbeJumpHere(v, loopTop-1); |
| 98193 | 98246 | #ifndef SQLITE_OMIT_BTREECOUNT |
| 98194 | 98247 | sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, |
| 98195 | 98248 | "wrong # of entries in index ", P4_STATIC); |
| 98196 | 98249 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
| 98197 | 98250 | if( pPk==pIdx ) continue; |
| 98198 | 98251 | addr = sqlite3VdbeCurrentAddr(v); |
| 98199 | | - sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); |
| 98252 | + sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v); |
| 98200 | 98253 | sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); |
| 98201 | 98254 | sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3); |
| 98202 | | - sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); |
| 98255 | + sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v); |
| 98256 | + sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); |
| 98203 | 98257 | sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); |
| 98204 | 98258 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT); |
| 98205 | 98259 | sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7); |
| 98206 | 98260 | sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1); |
| 98207 | 98261 | } |
| 98208 | 98262 | #endif /* SQLITE_OMIT_BTREECOUNT */ |
| 98209 | 98263 | } |
| 98210 | 98264 | } |
| 98211 | | - addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode); |
| 98265 | + addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn); |
| 98212 | 98266 | sqlite3VdbeChangeP2(v, addr, -mxErr); |
| 98213 | 98267 | sqlite3VdbeJumpHere(v, addr+1); |
| 98214 | 98268 | sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC); |
| 98215 | 98269 | } |
| 98216 | 98270 | break; |
| | @@ -98344,11 +98398,11 @@ |
| 98344 | 98398 | static const VdbeOpList setCookie[] = { |
| 98345 | 98399 | { OP_Transaction, 0, 1, 0}, /* 0 */ |
| 98346 | 98400 | { OP_Integer, 0, 1, 0}, /* 1 */ |
| 98347 | 98401 | { OP_SetCookie, 0, 0, 1}, /* 2 */ |
| 98348 | 98402 | }; |
| 98349 | | - int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie); |
| 98403 | + int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0); |
| 98350 | 98404 | sqlite3VdbeChangeP1(v, addr, iDb); |
| 98351 | 98405 | sqlite3VdbeChangeP1(v, addr+1, sqlite3Atoi(zRight)); |
| 98352 | 98406 | sqlite3VdbeChangeP1(v, addr+2, iDb); |
| 98353 | 98407 | sqlite3VdbeChangeP2(v, addr+2, iCookie); |
| 98354 | 98408 | }else{ |
| | @@ -98356,11 +98410,11 @@ |
| 98356 | 98410 | static const VdbeOpList readCookie[] = { |
| 98357 | 98411 | { OP_Transaction, 0, 0, 0}, /* 0 */ |
| 98358 | 98412 | { OP_ReadCookie, 0, 1, 0}, /* 1 */ |
| 98359 | 98413 | { OP_ResultRow, 1, 1, 0} |
| 98360 | 98414 | }; |
| 98361 | | - int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie); |
| 98415 | + int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie, 0); |
| 98362 | 98416 | sqlite3VdbeChangeP1(v, addr, iDb); |
| 98363 | 98417 | sqlite3VdbeChangeP1(v, addr+1, iDb); |
| 98364 | 98418 | sqlite3VdbeChangeP3(v, addr+1, iCookie); |
| 98365 | 98419 | sqlite3VdbeSetNumCols(v, 1); |
| 98366 | 98420 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT); |
| | @@ -99562,10 +99616,18 @@ |
| 99562 | 99616 | if( p ){ |
| 99563 | 99617 | clearSelect(db, p); |
| 99564 | 99618 | sqlite3DbFree(db, p); |
| 99565 | 99619 | } |
| 99566 | 99620 | } |
| 99621 | + |
| 99622 | +/* |
| 99623 | +** Return a pointer to the right-most SELECT statement in a compound. |
| 99624 | +*/ |
| 99625 | +static Select *findRightmost(Select *p){ |
| 99626 | + while( p->pNext ) p = p->pNext; |
| 99627 | + return p; |
| 99628 | +} |
| 99567 | 99629 | |
| 99568 | 99630 | /* |
| 99569 | 99631 | ** Given 1 to 3 identifiers preceding the JOIN keyword, determine the |
| 99570 | 99632 | ** type of join. Return an integer constant that expresses that type |
| 99571 | 99633 | ** in terms of the following bit values: |
| | @@ -99901,11 +99963,11 @@ |
| 99901 | 99963 | if( pSelect->iOffset ){ |
| 99902 | 99964 | iLimit = pSelect->iOffset+1; |
| 99903 | 99965 | }else{ |
| 99904 | 99966 | iLimit = pSelect->iLimit; |
| 99905 | 99967 | } |
| 99906 | | - addr1 = sqlite3VdbeAddOp1(v, OP_IfZero, iLimit); |
| 99968 | + addr1 = sqlite3VdbeAddOp1(v, OP_IfZero, iLimit); VdbeCoverage(v); |
| 99907 | 99969 | sqlite3VdbeAddOp2(v, OP_AddImm, iLimit, -1); |
| 99908 | 99970 | addr2 = sqlite3VdbeAddOp0(v, OP_Goto); |
| 99909 | 99971 | sqlite3VdbeJumpHere(v, addr1); |
| 99910 | 99972 | sqlite3VdbeAddOp1(v, OP_Last, pOrderBy->iECursor); |
| 99911 | 99973 | sqlite3VdbeAddOp1(v, OP_Delete, pOrderBy->iECursor); |
| | @@ -99922,11 +99984,11 @@ |
| 99922 | 99984 | int iContinue /* Jump here to skip the current record */ |
| 99923 | 99985 | ){ |
| 99924 | 99986 | if( iOffset>0 && iContinue!=0 ){ |
| 99925 | 99987 | int addr; |
| 99926 | 99988 | sqlite3VdbeAddOp2(v, OP_AddImm, iOffset, -1); |
| 99927 | | - addr = sqlite3VdbeAddOp1(v, OP_IfNeg, iOffset); |
| 99989 | + addr = sqlite3VdbeAddOp1(v, OP_IfNeg, iOffset); VdbeCoverage(v); |
| 99928 | 99990 | sqlite3VdbeAddOp2(v, OP_Goto, 0, iContinue); |
| 99929 | 99991 | VdbeComment((v, "skip OFFSET records")); |
| 99930 | 99992 | sqlite3VdbeJumpHere(v, addr); |
| 99931 | 99993 | } |
| 99932 | 99994 | } |
| | @@ -99950,11 +100012,11 @@ |
| 99950 | 100012 | Vdbe *v; |
| 99951 | 100013 | int r1; |
| 99952 | 100014 | |
| 99953 | 100015 | v = pParse->pVdbe; |
| 99954 | 100016 | r1 = sqlite3GetTempReg(pParse); |
| 99955 | | - sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); |
| 100017 | + sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v); |
| 99956 | 100018 | sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1); |
| 99957 | 100019 | sqlite3VdbeAddOp2(v, OP_IdxInsert, iTab, r1); |
| 99958 | 100020 | sqlite3ReleaseTempReg(pParse, r1); |
| 99959 | 100021 | } |
| 99960 | 100022 | |
| | @@ -100031,17 +100093,23 @@ |
| 100031 | 100093 | } |
| 100032 | 100094 | |
| 100033 | 100095 | /* Pull the requested columns. |
| 100034 | 100096 | */ |
| 100035 | 100097 | nResultCol = pEList->nExpr; |
| 100098 | + |
| 100036 | 100099 | if( pDest->iSdst==0 ){ |
| 100037 | 100100 | pDest->iSdst = pParse->nMem+1; |
| 100038 | | - pDest->nSdst = nResultCol; |
| 100101 | + pParse->nMem += nResultCol; |
| 100102 | + }else if( pDest->iSdst+nResultCol > pParse->nMem ){ |
| 100103 | + /* This is an error condition that can result, for example, when a SELECT |
| 100104 | + ** on the right-hand side of an INSERT contains more result columns than |
| 100105 | + ** there are columns in the table on the left. The error will be caught |
| 100106 | + ** and reported later. But we need to make sure enough memory is allocated |
| 100107 | + ** to avoid other spurious errors in the meantime. */ |
| 100039 | 100108 | pParse->nMem += nResultCol; |
| 100040 | | - }else{ |
| 100041 | | - assert( pDest->nSdst==nResultCol ); |
| 100042 | 100109 | } |
| 100110 | + pDest->nSdst = nResultCol; |
| 100043 | 100111 | regResult = pDest->iSdst; |
| 100044 | 100112 | if( srcTab>=0 ){ |
| 100045 | 100113 | for(i=0; i<nResultCol; i++){ |
| 100046 | 100114 | sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i); |
| 100047 | 100115 | VdbeComment((v, "%s", pEList->a[i].zName)); |
| | @@ -100084,13 +100152,15 @@ |
| 100084 | 100152 | iJump = sqlite3VdbeCurrentAddr(v) + nResultCol; |
| 100085 | 100153 | for(i=0; i<nResultCol; i++){ |
| 100086 | 100154 | CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr); |
| 100087 | 100155 | if( i<nResultCol-1 ){ |
| 100088 | 100156 | sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i); |
| 100157 | + VdbeCoverage(v); |
| 100089 | 100158 | }else{ |
| 100090 | 100159 | sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i); |
| 100091 | | - } |
| 100160 | + VdbeCoverage(v); |
| 100161 | + } |
| 100092 | 100162 | sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ); |
| 100093 | 100163 | sqlite3VdbeChangeP5(v, SQLITE_NULLEQ); |
| 100094 | 100164 | } |
| 100095 | 100165 | assert( sqlite3VdbeCurrentAddr(v)==iJump ); |
| 100096 | 100166 | sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nResultCol-1); |
| | @@ -100152,11 +100222,11 @@ |
| 100152 | 100222 | ** on an ephemeral index. If the current row is already present |
| 100153 | 100223 | ** in the index, do not write it to the output. If not, add the |
| 100154 | 100224 | ** current row to the index and proceed with writing it to the |
| 100155 | 100225 | ** output table as well. */ |
| 100156 | 100226 | int addr = sqlite3VdbeCurrentAddr(v) + 4; |
| 100157 | | - sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0); |
| 100227 | + sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0); VdbeCoverage(v); |
| 100158 | 100228 | sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r1); |
| 100159 | 100229 | assert( pOrderBy==0 ); |
| 100160 | 100230 | } |
| 100161 | 100231 | #endif |
| 100162 | 100232 | if( pOrderBy ){ |
| | @@ -100219,16 +100289,12 @@ |
| 100219 | 100289 | } |
| 100220 | 100290 | break; |
| 100221 | 100291 | } |
| 100222 | 100292 | #endif /* #ifndef SQLITE_OMIT_SUBQUERY */ |
| 100223 | 100293 | |
| 100224 | | - /* Send the data to the callback function or to a subroutine. In the |
| 100225 | | - ** case of a subroutine, the subroutine itself is responsible for |
| 100226 | | - ** popping the data from the stack. |
| 100227 | | - */ |
| 100228 | | - case SRT_Coroutine: |
| 100229 | | - case SRT_Output: { |
| 100294 | + case SRT_Coroutine: /* Send data to a co-routine */ |
| 100295 | + case SRT_Output: { /* Return the results */ |
| 100230 | 100296 | testcase( eDest==SRT_Coroutine ); |
| 100231 | 100297 | testcase( eDest==SRT_Output ); |
| 100232 | 100298 | if( pOrderBy ){ |
| 100233 | 100299 | int r1 = sqlite3GetTempReg(pParse); |
| 100234 | 100300 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1); |
| | @@ -100260,17 +100326,20 @@ |
| 100260 | 100326 | assert( pSO ); |
| 100261 | 100327 | nKey = pSO->nExpr; |
| 100262 | 100328 | r1 = sqlite3GetTempReg(pParse); |
| 100263 | 100329 | r2 = sqlite3GetTempRange(pParse, nKey+2); |
| 100264 | 100330 | r3 = r2+nKey+1; |
| 100265 | | - sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r3); |
| 100266 | 100331 | if( eDest==SRT_DistQueue ){ |
| 100267 | 100332 | /* If the destination is DistQueue, then cursor (iParm+1) is open |
| 100268 | 100333 | ** on a second ephemeral index that holds all values every previously |
| 100269 | | - ** added to the queue. Only add this new value if it has never before |
| 100270 | | - ** been added */ |
| 100271 | | - addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0, r3, 0); |
| 100334 | + ** added to the queue. */ |
| 100335 | + addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0, |
| 100336 | + regResult, nResultCol); |
| 100337 | + VdbeCoverage(v); |
| 100338 | + } |
| 100339 | + sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r3); |
| 100340 | + if( eDest==SRT_DistQueue ){ |
| 100272 | 100341 | sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r3); |
| 100273 | 100342 | sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 100274 | 100343 | } |
| 100275 | 100344 | for(i=0; i<nKey; i++){ |
| 100276 | 100345 | sqlite3VdbeAddOp2(v, OP_SCopy, |
| | @@ -100305,11 +100374,11 @@ |
| 100305 | 100374 | /* Jump to the end of the loop if the LIMIT is reached. Except, if |
| 100306 | 100375 | ** there is a sorter, in which case the sorter has already limited |
| 100307 | 100376 | ** the output for us. |
| 100308 | 100377 | */ |
| 100309 | 100378 | if( pOrderBy==0 && p->iLimit ){ |
| 100310 | | - sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); |
| 100379 | + sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); VdbeCoverage(v); |
| 100311 | 100380 | } |
| 100312 | 100381 | } |
| 100313 | 100382 | |
| 100314 | 100383 | /* |
| 100315 | 100384 | ** Allocate a KeyInfo object sufficient for an index of N key columns and |
| | @@ -100524,16 +100593,17 @@ |
| 100524 | 100593 | if( p->selFlags & SF_UseSorter ){ |
| 100525 | 100594 | int regSortOut = ++pParse->nMem; |
| 100526 | 100595 | int ptab2 = pParse->nTab++; |
| 100527 | 100596 | sqlite3VdbeAddOp3(v, OP_OpenPseudo, ptab2, regSortOut, pOrderBy->nExpr+2); |
| 100528 | 100597 | addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak); |
| 100598 | + VdbeCoverage(v); |
| 100529 | 100599 | codeOffset(v, p->iOffset, addrContinue); |
| 100530 | 100600 | sqlite3VdbeAddOp2(v, OP_SorterData, iTab, regSortOut); |
| 100531 | 100601 | sqlite3VdbeAddOp3(v, OP_Column, ptab2, pOrderBy->nExpr+1, regRow); |
| 100532 | 100602 | sqlite3VdbeChangeP5(v, OPFLAG_CLEARCACHE); |
| 100533 | 100603 | }else{ |
| 100534 | | - addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); |
| 100604 | + addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v); |
| 100535 | 100605 | codeOffset(v, p->iOffset, addrContinue); |
| 100536 | 100606 | sqlite3VdbeAddOp3(v, OP_Column, iTab, pOrderBy->nExpr+1, regRow); |
| 100537 | 100607 | } |
| 100538 | 100608 | switch( eDest ){ |
| 100539 | 100609 | case SRT_Table: |
| | @@ -100587,13 +100657,13 @@ |
| 100587 | 100657 | |
| 100588 | 100658 | /* The bottom of the loop |
| 100589 | 100659 | */ |
| 100590 | 100660 | sqlite3VdbeResolveLabel(v, addrContinue); |
| 100591 | 100661 | if( p->selFlags & SF_UseSorter ){ |
| 100592 | | - sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr); |
| 100662 | + sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr); VdbeCoverage(v); |
| 100593 | 100663 | }else{ |
| 100594 | | - sqlite3VdbeAddOp2(v, OP_Next, iTab, addr); |
| 100664 | + sqlite3VdbeAddOp2(v, OP_Next, iTab, addr); VdbeCoverage(v); |
| 100595 | 100665 | } |
| 100596 | 100666 | sqlite3VdbeResolveLabel(v, addrBreak); |
| 100597 | 100667 | if( eDest==SRT_Output || eDest==SRT_Coroutine ){ |
| 100598 | 100668 | sqlite3VdbeAddOp2(v, OP_Close, pseudoTab, 0); |
| 100599 | 100669 | } |
| | @@ -101073,15 +101143,17 @@ |
| 101073 | 101143 | */ |
| 101074 | 101144 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){ |
| 101075 | 101145 | Vdbe *v = pParse->pVdbe; |
| 101076 | 101146 | if( v==0 ){ |
| 101077 | 101147 | v = pParse->pVdbe = sqlite3VdbeCreate(pParse); |
| 101078 | | -#ifndef SQLITE_OMIT_TRACE |
| 101079 | | - if( v ){ |
| 101080 | | - sqlite3VdbeAddOp0(v, OP_Trace); |
| 101148 | + if( v ) sqlite3VdbeAddOp0(v, OP_Init); |
| 101149 | + if( pParse->pToplevel==0 |
| 101150 | + && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst) |
| 101151 | + ){ |
| 101152 | + pParse->okConstFactor = 1; |
| 101081 | 101153 | } |
| 101082 | | -#endif |
| 101154 | + |
| 101083 | 101155 | } |
| 101084 | 101156 | return v; |
| 101085 | 101157 | } |
| 101086 | 101158 | |
| 101087 | 101159 | |
| | @@ -101135,26 +101207,26 @@ |
| 101135 | 101207 | }else if( n>=0 && p->nSelectRow>(u64)n ){ |
| 101136 | 101208 | p->nSelectRow = n; |
| 101137 | 101209 | } |
| 101138 | 101210 | }else{ |
| 101139 | 101211 | sqlite3ExprCode(pParse, p->pLimit, iLimit); |
| 101140 | | - sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); |
| 101212 | + sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v); |
| 101141 | 101213 | VdbeComment((v, "LIMIT counter")); |
| 101142 | | - sqlite3VdbeAddOp2(v, OP_IfZero, iLimit, iBreak); |
| 101214 | + sqlite3VdbeAddOp2(v, OP_IfZero, iLimit, iBreak); VdbeCoverage(v); |
| 101143 | 101215 | } |
| 101144 | 101216 | if( p->pOffset ){ |
| 101145 | 101217 | p->iOffset = iOffset = ++pParse->nMem; |
| 101146 | 101218 | pParse->nMem++; /* Allocate an extra register for limit+offset */ |
| 101147 | 101219 | sqlite3ExprCode(pParse, p->pOffset, iOffset); |
| 101148 | | - sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); |
| 101220 | + sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v); |
| 101149 | 101221 | VdbeComment((v, "OFFSET counter")); |
| 101150 | | - addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iOffset); |
| 101222 | + addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iOffset); VdbeCoverage(v); |
| 101151 | 101223 | sqlite3VdbeAddOp2(v, OP_Integer, 0, iOffset); |
| 101152 | 101224 | sqlite3VdbeJumpHere(v, addr1); |
| 101153 | 101225 | sqlite3VdbeAddOp3(v, OP_Add, iLimit, iOffset, iOffset+1); |
| 101154 | 101226 | VdbeComment((v, "LIMIT+OFFSET")); |
| 101155 | | - addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iLimit); |
| 101227 | + addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iLimit); VdbeCoverage(v); |
| 101156 | 101228 | sqlite3VdbeAddOp2(v, OP_Integer, -1, iOffset+1); |
| 101157 | 101229 | sqlite3VdbeJumpHere(v, addr1); |
| 101158 | 101230 | } |
| 101159 | 101231 | } |
| 101160 | 101232 | } |
| | @@ -101333,15 +101405,17 @@ |
| 101333 | 101405 | |
| 101334 | 101406 | /* Detach the ORDER BY clause from the compound SELECT */ |
| 101335 | 101407 | p->pOrderBy = 0; |
| 101336 | 101408 | |
| 101337 | 101409 | /* Store the results of the setup-query in Queue. */ |
| 101410 | + pSetup->pNext = 0; |
| 101338 | 101411 | rc = sqlite3Select(pParse, pSetup, &destQueue); |
| 101412 | + pSetup->pNext = p; |
| 101339 | 101413 | if( rc ) goto end_of_recursive_query; |
| 101340 | 101414 | |
| 101341 | 101415 | /* Find the next row in the Queue and output that row */ |
| 101342 | | - addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iQueue, addrBreak); |
| 101416 | + addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iQueue, addrBreak); VdbeCoverage(v); |
| 101343 | 101417 | |
| 101344 | 101418 | /* Transfer the next row in Queue over to Current */ |
| 101345 | 101419 | sqlite3VdbeAddOp1(v, OP_NullRow, iCurrent); /* To reset column cache */ |
| 101346 | 101420 | if( pOrderBy ){ |
| 101347 | 101421 | sqlite3VdbeAddOp3(v, OP_Column, iQueue, pOrderBy->nExpr+1, regCurrent); |
| | @@ -101353,11 +101427,14 @@ |
| 101353 | 101427 | /* Output the single row in Current */ |
| 101354 | 101428 | addrCont = sqlite3VdbeMakeLabel(v); |
| 101355 | 101429 | codeOffset(v, regOffset, addrCont); |
| 101356 | 101430 | selectInnerLoop(pParse, p, p->pEList, iCurrent, |
| 101357 | 101431 | 0, 0, pDest, addrCont, addrBreak); |
| 101358 | | - if( regLimit ) sqlite3VdbeAddOp3(v, OP_IfZero, regLimit, addrBreak, -1); |
| 101432 | + if( regLimit ){ |
| 101433 | + sqlite3VdbeAddOp3(v, OP_IfZero, regLimit, addrBreak, -1); |
| 101434 | + VdbeCoverage(v); |
| 101435 | + } |
| 101359 | 101436 | sqlite3VdbeResolveLabel(v, addrCont); |
| 101360 | 101437 | |
| 101361 | 101438 | /* Execute the recursive SELECT taking the single row in Current as |
| 101362 | 101439 | ** the value for the recursive-table. Store the results in the Queue. |
| 101363 | 101440 | */ |
| | @@ -101438,12 +101515,10 @@ |
| 101438 | 101515 | */ |
| 101439 | 101516 | assert( p && p->pPrior ); /* Calling function guarantees this much */ |
| 101440 | 101517 | assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION ); |
| 101441 | 101518 | db = pParse->db; |
| 101442 | 101519 | pPrior = p->pPrior; |
| 101443 | | - assert( pPrior->pRightmost!=pPrior ); |
| 101444 | | - assert( pPrior->pRightmost==p->pRightmost ); |
| 101445 | 101520 | dest = *pDest; |
| 101446 | 101521 | if( pPrior->pOrderBy ){ |
| 101447 | 101522 | sqlite3ErrorMsg(pParse,"ORDER BY clause should come after %s not before", |
| 101448 | 101523 | selectOpName(p->op)); |
| 101449 | 101524 | rc = 1; |
| | @@ -101515,11 +101590,11 @@ |
| 101515 | 101590 | } |
| 101516 | 101591 | p->pPrior = 0; |
| 101517 | 101592 | p->iLimit = pPrior->iLimit; |
| 101518 | 101593 | p->iOffset = pPrior->iOffset; |
| 101519 | 101594 | if( p->iLimit ){ |
| 101520 | | - addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit); |
| 101595 | + addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit); VdbeCoverage(v); |
| 101521 | 101596 | VdbeComment((v, "Jump ahead if LIMIT reached")); |
| 101522 | 101597 | } |
| 101523 | 101598 | explainSetInteger(iSub2, pParse->iNextSelectId); |
| 101524 | 101599 | rc = sqlite3Select(pParse, p, &dest); |
| 101525 | 101600 | testcase( rc!=SQLITE_OK ); |
| | @@ -101547,16 +101622,14 @@ |
| 101547 | 101622 | SelectDest uniondest; |
| 101548 | 101623 | |
| 101549 | 101624 | testcase( p->op==TK_EXCEPT ); |
| 101550 | 101625 | testcase( p->op==TK_UNION ); |
| 101551 | 101626 | priorOp = SRT_Union; |
| 101552 | | - if( dest.eDest==priorOp && ALWAYS(!p->pLimit &&!p->pOffset) ){ |
| 101627 | + if( dest.eDest==priorOp ){ |
| 101553 | 101628 | /* We can reuse a temporary table generated by a SELECT to our |
| 101554 | 101629 | ** right. |
| 101555 | 101630 | */ |
| 101556 | | - assert( p->pRightmost!=p ); /* Can only happen for leftward elements |
| 101557 | | - ** of a 3-way or more compound */ |
| 101558 | 101631 | assert( p->pLimit==0 ); /* Not allowed on leftward elements */ |
| 101559 | 101632 | assert( p->pOffset==0 ); /* Not allowed on leftward elements */ |
| 101560 | 101633 | unionTab = dest.iSDParm; |
| 101561 | 101634 | }else{ |
| 101562 | 101635 | /* We will need to create our own temporary table to hold the |
| | @@ -101565,11 +101638,11 @@ |
| 101565 | 101638 | unionTab = pParse->nTab++; |
| 101566 | 101639 | assert( p->pOrderBy==0 ); |
| 101567 | 101640 | addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, unionTab, 0); |
| 101568 | 101641 | assert( p->addrOpenEphm[0] == -1 ); |
| 101569 | 101642 | p->addrOpenEphm[0] = addr; |
| 101570 | | - p->pRightmost->selFlags |= SF_UsesEphemeral; |
| 101643 | + findRightmost(p)->selFlags |= SF_UsesEphemeral; |
| 101571 | 101644 | assert( p->pEList ); |
| 101572 | 101645 | } |
| 101573 | 101646 | |
| 101574 | 101647 | /* Code the SELECT statements to our left |
| 101575 | 101648 | */ |
| | @@ -101624,16 +101697,16 @@ |
| 101624 | 101697 | generateColumnNames(pParse, 0, pFirst->pEList); |
| 101625 | 101698 | } |
| 101626 | 101699 | iBreak = sqlite3VdbeMakeLabel(v); |
| 101627 | 101700 | iCont = sqlite3VdbeMakeLabel(v); |
| 101628 | 101701 | computeLimitRegisters(pParse, p, iBreak); |
| 101629 | | - sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); |
| 101702 | + sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v); |
| 101630 | 101703 | iStart = sqlite3VdbeCurrentAddr(v); |
| 101631 | 101704 | selectInnerLoop(pParse, p, p->pEList, unionTab, |
| 101632 | 101705 | 0, 0, &dest, iCont, iBreak); |
| 101633 | 101706 | sqlite3VdbeResolveLabel(v, iCont); |
| 101634 | | - sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); |
| 101707 | + sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); VdbeCoverage(v); |
| 101635 | 101708 | sqlite3VdbeResolveLabel(v, iBreak); |
| 101636 | 101709 | sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0); |
| 101637 | 101710 | } |
| 101638 | 101711 | break; |
| 101639 | 101712 | } |
| | @@ -101654,11 +101727,11 @@ |
| 101654 | 101727 | assert( p->pOrderBy==0 ); |
| 101655 | 101728 | |
| 101656 | 101729 | addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab1, 0); |
| 101657 | 101730 | assert( p->addrOpenEphm[0] == -1 ); |
| 101658 | 101731 | p->addrOpenEphm[0] = addr; |
| 101659 | | - p->pRightmost->selFlags |= SF_UsesEphemeral; |
| 101732 | + findRightmost(p)->selFlags |= SF_UsesEphemeral; |
| 101660 | 101733 | assert( p->pEList ); |
| 101661 | 101734 | |
| 101662 | 101735 | /* Code the SELECTs to our left into temporary table "tab1". |
| 101663 | 101736 | */ |
| 101664 | 101737 | sqlite3SelectDestInit(&intersectdest, SRT_Union, tab1); |
| | @@ -101699,19 +101772,19 @@ |
| 101699 | 101772 | generateColumnNames(pParse, 0, pFirst->pEList); |
| 101700 | 101773 | } |
| 101701 | 101774 | iBreak = sqlite3VdbeMakeLabel(v); |
| 101702 | 101775 | iCont = sqlite3VdbeMakeLabel(v); |
| 101703 | 101776 | computeLimitRegisters(pParse, p, iBreak); |
| 101704 | | - sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); |
| 101777 | + sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v); |
| 101705 | 101778 | r1 = sqlite3GetTempReg(pParse); |
| 101706 | 101779 | iStart = sqlite3VdbeAddOp2(v, OP_RowKey, tab1, r1); |
| 101707 | | - sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0); |
| 101780 | + sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0); VdbeCoverage(v); |
| 101708 | 101781 | sqlite3ReleaseTempReg(pParse, r1); |
| 101709 | 101782 | selectInnerLoop(pParse, p, p->pEList, tab1, |
| 101710 | 101783 | 0, 0, &dest, iCont, iBreak); |
| 101711 | 101784 | sqlite3VdbeResolveLabel(v, iCont); |
| 101712 | | - sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); |
| 101785 | + sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); VdbeCoverage(v); |
| 101713 | 101786 | sqlite3VdbeResolveLabel(v, iBreak); |
| 101714 | 101787 | sqlite3VdbeAddOp2(v, OP_Close, tab2, 0); |
| 101715 | 101788 | sqlite3VdbeAddOp2(v, OP_Close, tab1, 0); |
| 101716 | 101789 | break; |
| 101717 | 101790 | } |
| | @@ -101733,11 +101806,11 @@ |
| 101733 | 101806 | KeyInfo *pKeyInfo; /* Collating sequence for the result set */ |
| 101734 | 101807 | Select *pLoop; /* For looping through SELECT statements */ |
| 101735 | 101808 | CollSeq **apColl; /* For looping through pKeyInfo->aColl[] */ |
| 101736 | 101809 | int nCol; /* Number of columns in result set */ |
| 101737 | 101810 | |
| 101738 | | - assert( p->pRightmost==p ); |
| 101811 | + assert( p->pNext==0 ); |
| 101739 | 101812 | nCol = p->pEList->nExpr; |
| 101740 | 101813 | pKeyInfo = sqlite3KeyInfoAlloc(db, nCol, 1); |
| 101741 | 101814 | if( !pKeyInfo ){ |
| 101742 | 101815 | rc = SQLITE_NOMEM; |
| 101743 | 101816 | goto multi_select_end; |
| | @@ -101814,14 +101887,14 @@ |
| 101814 | 101887 | |
| 101815 | 101888 | /* Suppress duplicates for UNION, EXCEPT, and INTERSECT |
| 101816 | 101889 | */ |
| 101817 | 101890 | if( regPrev ){ |
| 101818 | 101891 | int j1, j2; |
| 101819 | | - j1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev); |
| 101892 | + j1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev); VdbeCoverage(v); |
| 101820 | 101893 | j2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iSdst, regPrev+1, pIn->nSdst, |
| 101821 | 101894 | (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO); |
| 101822 | | - sqlite3VdbeAddOp3(v, OP_Jump, j2+2, iContinue, j2+2); |
| 101895 | + sqlite3VdbeAddOp3(v, OP_Jump, j2+2, iContinue, j2+2); VdbeCoverage(v); |
| 101823 | 101896 | sqlite3VdbeJumpHere(v, j1); |
| 101824 | 101897 | sqlite3VdbeAddOp3(v, OP_Copy, pIn->iSdst, regPrev+1, pIn->nSdst-1); |
| 101825 | 101898 | sqlite3VdbeAddOp2(v, OP_Integer, 1, regPrev); |
| 101826 | 101899 | } |
| 101827 | 101900 | if( pParse->db->mallocFailed ) return 0; |
| | @@ -101918,11 +101991,11 @@ |
| 101918 | 101991 | } |
| 101919 | 101992 | |
| 101920 | 101993 | /* Jump to the end of the loop if the LIMIT is reached. |
| 101921 | 101994 | */ |
| 101922 | 101995 | if( p->iLimit ){ |
| 101923 | | - sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); |
| 101996 | + sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); VdbeCoverage(v); |
| 101924 | 101997 | } |
| 101925 | 101998 | |
| 101926 | 101999 | /* Generate the subroutine return |
| 101927 | 102000 | */ |
| 101928 | 102001 | sqlite3VdbeResolveLabel(v, iContinue); |
| | @@ -102026,20 +102099,19 @@ |
| 102026 | 102099 | Select *pPrior; /* Another SELECT immediately to our left */ |
| 102027 | 102100 | Vdbe *v; /* Generate code to this VDBE */ |
| 102028 | 102101 | SelectDest destA; /* Destination for coroutine A */ |
| 102029 | 102102 | SelectDest destB; /* Destination for coroutine B */ |
| 102030 | 102103 | int regAddrA; /* Address register for select-A coroutine */ |
| 102031 | | - int regEofA; /* Flag to indicate when select-A is complete */ |
| 102032 | 102104 | int regAddrB; /* Address register for select-B coroutine */ |
| 102033 | | - int regEofB; /* Flag to indicate when select-B is complete */ |
| 102034 | 102105 | int addrSelectA; /* Address of the select-A coroutine */ |
| 102035 | 102106 | int addrSelectB; /* Address of the select-B coroutine */ |
| 102036 | 102107 | int regOutA; /* Address register for the output-A subroutine */ |
| 102037 | 102108 | int regOutB; /* Address register for the output-B subroutine */ |
| 102038 | 102109 | int addrOutA; /* Address of the output-A subroutine */ |
| 102039 | 102110 | int addrOutB = 0; /* Address of the output-B subroutine */ |
| 102040 | 102111 | int addrEofA; /* Address of the select-A-exhausted subroutine */ |
| 102112 | + int addrEofA_noB; /* Alternate addrEofA if B is uninitialized */ |
| 102041 | 102113 | int addrEofB; /* Address of the select-B-exhausted subroutine */ |
| 102042 | 102114 | int addrAltB; /* Address of the A<B subroutine */ |
| 102043 | 102115 | int addrAeqB; /* Address of the A==B subroutine */ |
| 102044 | 102116 | int addrAgtB; /* Address of the A>B subroutine */ |
| 102045 | 102117 | int regLimitA; /* Limit register for select-A */ |
| | @@ -102150,10 +102222,11 @@ |
| 102150 | 102222 | } |
| 102151 | 102223 | |
| 102152 | 102224 | /* Separate the left and the right query from one another |
| 102153 | 102225 | */ |
| 102154 | 102226 | p->pPrior = 0; |
| 102227 | + pPrior->pNext = 0; |
| 102155 | 102228 | sqlite3ResolveOrderGroupBy(pParse, p, p->pOrderBy, "ORDER"); |
| 102156 | 102229 | if( pPrior->pPrior==0 ){ |
| 102157 | 102230 | sqlite3ResolveOrderGroupBy(pParse, pPrior, pPrior->pOrderBy, "ORDER"); |
| 102158 | 102231 | } |
| 102159 | 102232 | |
| | @@ -102172,52 +102245,43 @@ |
| 102172 | 102245 | p->pLimit = 0; |
| 102173 | 102246 | sqlite3ExprDelete(db, p->pOffset); |
| 102174 | 102247 | p->pOffset = 0; |
| 102175 | 102248 | |
| 102176 | 102249 | regAddrA = ++pParse->nMem; |
| 102177 | | - regEofA = ++pParse->nMem; |
| 102178 | 102250 | regAddrB = ++pParse->nMem; |
| 102179 | | - regEofB = ++pParse->nMem; |
| 102180 | 102251 | regOutA = ++pParse->nMem; |
| 102181 | 102252 | regOutB = ++pParse->nMem; |
| 102182 | 102253 | sqlite3SelectDestInit(&destA, SRT_Coroutine, regAddrA); |
| 102183 | 102254 | sqlite3SelectDestInit(&destB, SRT_Coroutine, regAddrB); |
| 102184 | | - |
| 102185 | | - /* Jump past the various subroutines and coroutines to the main |
| 102186 | | - ** merge loop |
| 102187 | | - */ |
| 102188 | | - j1 = sqlite3VdbeAddOp0(v, OP_Goto); |
| 102189 | | - addrSelectA = sqlite3VdbeCurrentAddr(v); |
| 102190 | | - |
| 102191 | 102255 | |
| 102192 | 102256 | /* Generate a coroutine to evaluate the SELECT statement to the |
| 102193 | 102257 | ** left of the compound operator - the "A" select. |
| 102194 | 102258 | */ |
| 102195 | | - VdbeNoopComment((v, "Begin coroutine for left SELECT")); |
| 102259 | + addrSelectA = sqlite3VdbeCurrentAddr(v) + 1; |
| 102260 | + j1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrA, 0, addrSelectA); |
| 102261 | + VdbeComment((v, "left SELECT")); |
| 102196 | 102262 | pPrior->iLimit = regLimitA; |
| 102197 | 102263 | explainSetInteger(iSub1, pParse->iNextSelectId); |
| 102198 | 102264 | sqlite3Select(pParse, pPrior, &destA); |
| 102199 | | - sqlite3VdbeAddOp2(v, OP_Integer, 1, regEofA); |
| 102200 | | - sqlite3VdbeAddOp1(v, OP_Yield, regAddrA); |
| 102201 | | - VdbeNoopComment((v, "End coroutine for left SELECT")); |
| 102265 | + sqlite3VdbeAddOp1(v, OP_EndCoroutine, regAddrA); |
| 102266 | + sqlite3VdbeJumpHere(v, j1); |
| 102202 | 102267 | |
| 102203 | 102268 | /* Generate a coroutine to evaluate the SELECT statement on |
| 102204 | 102269 | ** the right - the "B" select |
| 102205 | 102270 | */ |
| 102206 | | - addrSelectB = sqlite3VdbeCurrentAddr(v); |
| 102207 | | - VdbeNoopComment((v, "Begin coroutine for right SELECT")); |
| 102271 | + addrSelectB = sqlite3VdbeCurrentAddr(v) + 1; |
| 102272 | + j1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrB, 0, addrSelectB); |
| 102273 | + VdbeComment((v, "right SELECT")); |
| 102208 | 102274 | savedLimit = p->iLimit; |
| 102209 | 102275 | savedOffset = p->iOffset; |
| 102210 | 102276 | p->iLimit = regLimitB; |
| 102211 | 102277 | p->iOffset = 0; |
| 102212 | 102278 | explainSetInteger(iSub2, pParse->iNextSelectId); |
| 102213 | 102279 | sqlite3Select(pParse, p, &destB); |
| 102214 | 102280 | p->iLimit = savedLimit; |
| 102215 | 102281 | p->iOffset = savedOffset; |
| 102216 | | - sqlite3VdbeAddOp2(v, OP_Integer, 1, regEofB); |
| 102217 | | - sqlite3VdbeAddOp1(v, OP_Yield, regAddrB); |
| 102218 | | - VdbeNoopComment((v, "End coroutine for right SELECT")); |
| 102282 | + sqlite3VdbeAddOp1(v, OP_EndCoroutine, regAddrB); |
| 102219 | 102283 | |
| 102220 | 102284 | /* Generate a subroutine that outputs the current row of the A |
| 102221 | 102285 | ** select as the next output row of the compound select. |
| 102222 | 102286 | */ |
| 102223 | 102287 | VdbeNoopComment((v, "Output routine for A")); |
| | @@ -102237,17 +102301,17 @@ |
| 102237 | 102301 | sqlite3KeyInfoUnref(pKeyDup); |
| 102238 | 102302 | |
| 102239 | 102303 | /* Generate a subroutine to run when the results from select A |
| 102240 | 102304 | ** are exhausted and only data in select B remains. |
| 102241 | 102305 | */ |
| 102242 | | - VdbeNoopComment((v, "eof-A subroutine")); |
| 102243 | 102306 | if( op==TK_EXCEPT || op==TK_INTERSECT ){ |
| 102244 | | - addrEofA = sqlite3VdbeAddOp2(v, OP_Goto, 0, labelEnd); |
| 102307 | + addrEofA_noB = addrEofA = labelEnd; |
| 102245 | 102308 | }else{ |
| 102246 | | - addrEofA = sqlite3VdbeAddOp2(v, OP_If, regEofB, labelEnd); |
| 102247 | | - sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB); |
| 102248 | | - sqlite3VdbeAddOp1(v, OP_Yield, regAddrB); |
| 102309 | + VdbeNoopComment((v, "eof-A subroutine")); |
| 102310 | + addrEofA = sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB); |
| 102311 | + addrEofA_noB = sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, labelEnd); |
| 102312 | + VdbeCoverage(v); |
| 102249 | 102313 | sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofA); |
| 102250 | 102314 | p->nSelectRow += pPrior->nSelectRow; |
| 102251 | 102315 | } |
| 102252 | 102316 | |
| 102253 | 102317 | /* Generate a subroutine to run when the results from select B |
| | @@ -102256,22 +102320,20 @@ |
| 102256 | 102320 | if( op==TK_INTERSECT ){ |
| 102257 | 102321 | addrEofB = addrEofA; |
| 102258 | 102322 | if( p->nSelectRow > pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow; |
| 102259 | 102323 | }else{ |
| 102260 | 102324 | VdbeNoopComment((v, "eof-B subroutine")); |
| 102261 | | - addrEofB = sqlite3VdbeAddOp2(v, OP_If, regEofA, labelEnd); |
| 102262 | | - sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA); |
| 102263 | | - sqlite3VdbeAddOp1(v, OP_Yield, regAddrA); |
| 102325 | + addrEofB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA); |
| 102326 | + sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, labelEnd); VdbeCoverage(v); |
| 102264 | 102327 | sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofB); |
| 102265 | 102328 | } |
| 102266 | 102329 | |
| 102267 | 102330 | /* Generate code to handle the case of A<B |
| 102268 | 102331 | */ |
| 102269 | 102332 | VdbeNoopComment((v, "A-lt-B subroutine")); |
| 102270 | 102333 | addrAltB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA); |
| 102271 | | - sqlite3VdbeAddOp1(v, OP_Yield, regAddrA); |
| 102272 | | - sqlite3VdbeAddOp2(v, OP_If, regEofA, addrEofA); |
| 102334 | + sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v); |
| 102273 | 102335 | sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr); |
| 102274 | 102336 | |
| 102275 | 102337 | /* Generate code to handle the case of A==B |
| 102276 | 102338 | */ |
| 102277 | 102339 | if( op==TK_ALL ){ |
| | @@ -102280,12 +102342,11 @@ |
| 102280 | 102342 | addrAeqB = addrAltB; |
| 102281 | 102343 | addrAltB++; |
| 102282 | 102344 | }else{ |
| 102283 | 102345 | VdbeNoopComment((v, "A-eq-B subroutine")); |
| 102284 | 102346 | addrAeqB = |
| 102285 | | - sqlite3VdbeAddOp1(v, OP_Yield, regAddrA); |
| 102286 | | - sqlite3VdbeAddOp2(v, OP_If, regEofA, addrEofA); |
| 102347 | + sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v); |
| 102287 | 102348 | sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr); |
| 102288 | 102349 | } |
| 102289 | 102350 | |
| 102290 | 102351 | /* Generate code to handle the case of A>B |
| 102291 | 102352 | */ |
| | @@ -102292,32 +102353,27 @@ |
| 102292 | 102353 | VdbeNoopComment((v, "A-gt-B subroutine")); |
| 102293 | 102354 | addrAgtB = sqlite3VdbeCurrentAddr(v); |
| 102294 | 102355 | if( op==TK_ALL || op==TK_UNION ){ |
| 102295 | 102356 | sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB); |
| 102296 | 102357 | } |
| 102297 | | - sqlite3VdbeAddOp1(v, OP_Yield, regAddrB); |
| 102298 | | - sqlite3VdbeAddOp2(v, OP_If, regEofB, addrEofB); |
| 102358 | + sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v); |
| 102299 | 102359 | sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr); |
| 102300 | 102360 | |
| 102301 | 102361 | /* This code runs once to initialize everything. |
| 102302 | 102362 | */ |
| 102303 | 102363 | sqlite3VdbeJumpHere(v, j1); |
| 102304 | | - sqlite3VdbeAddOp2(v, OP_Integer, 0, regEofA); |
| 102305 | | - sqlite3VdbeAddOp2(v, OP_Integer, 0, regEofB); |
| 102306 | | - sqlite3VdbeAddOp2(v, OP_Gosub, regAddrA, addrSelectA); |
| 102307 | | - sqlite3VdbeAddOp2(v, OP_Gosub, regAddrB, addrSelectB); |
| 102308 | | - sqlite3VdbeAddOp2(v, OP_If, regEofA, addrEofA); |
| 102309 | | - sqlite3VdbeAddOp2(v, OP_If, regEofB, addrEofB); |
| 102364 | + sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA_noB); VdbeCoverage(v); |
| 102365 | + sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v); |
| 102310 | 102366 | |
| 102311 | 102367 | /* Implement the main merge loop |
| 102312 | 102368 | */ |
| 102313 | 102369 | sqlite3VdbeResolveLabel(v, labelCmpr); |
| 102314 | 102370 | sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY); |
| 102315 | 102371 | sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy, |
| 102316 | 102372 | (char*)pKeyMerge, P4_KEYINFO); |
| 102317 | 102373 | sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE); |
| 102318 | | - sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB); |
| 102374 | + sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB); VdbeCoverage(v); |
| 102319 | 102375 | |
| 102320 | 102376 | /* Jump to the this point in order to terminate the query. |
| 102321 | 102377 | */ |
| 102322 | 102378 | sqlite3VdbeResolveLabel(v, labelEnd); |
| 102323 | 102379 | |
| | @@ -102333,10 +102389,11 @@ |
| 102333 | 102389 | ** by the calling function */ |
| 102334 | 102390 | if( p->pPrior ){ |
| 102335 | 102391 | sqlite3SelectDelete(db, p->pPrior); |
| 102336 | 102392 | } |
| 102337 | 102393 | p->pPrior = pPrior; |
| 102394 | + pPrior->pNext = p; |
| 102338 | 102395 | |
| 102339 | 102396 | /*** TBD: Insert subroutine calls to close cursors on incomplete |
| 102340 | 102397 | **** subqueries ****/ |
| 102341 | 102398 | explainComposite(pParse, p->op, iSub1, iSub2, 0); |
| 102342 | 102399 | return SQLITE_OK; |
| | @@ -102598,11 +102655,11 @@ |
| 102598 | 102655 | ** because they could be computed at compile-time. But when LIMIT and OFFSET |
| 102599 | 102656 | ** became arbitrary expressions, we were forced to add restrictions (13) |
| 102600 | 102657 | ** and (14). */ |
| 102601 | 102658 | if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */ |
| 102602 | 102659 | if( pSub->pOffset ) return 0; /* Restriction (14) */ |
| 102603 | | - if( p->pRightmost && pSub->pLimit ){ |
| 102660 | + if( (p->selFlags & SF_Compound)!=0 && pSub->pLimit ){ |
| 102604 | 102661 | return 0; /* Restriction (15) */ |
| 102605 | 102662 | } |
| 102606 | 102663 | if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */ |
| 102607 | 102664 | if( pSub->selFlags & SF_Distinct ) return 0; /* Restriction (5) */ |
| 102608 | 102665 | if( pSub->pLimit && (pSrc->nSrc>1 || isAgg) ){ |
| | @@ -102749,18 +102806,18 @@ |
| 102749 | 102806 | p->pOffset = pOffset; |
| 102750 | 102807 | p->pLimit = pLimit; |
| 102751 | 102808 | p->pOrderBy = pOrderBy; |
| 102752 | 102809 | p->pSrc = pSrc; |
| 102753 | 102810 | p->op = TK_ALL; |
| 102754 | | - p->pRightmost = 0; |
| 102755 | 102811 | if( pNew==0 ){ |
| 102756 | | - pNew = pPrior; |
| 102812 | + p->pPrior = pPrior; |
| 102757 | 102813 | }else{ |
| 102758 | 102814 | pNew->pPrior = pPrior; |
| 102759 | | - pNew->pRightmost = 0; |
| 102815 | + if( pPrior ) pPrior->pNext = pNew; |
| 102816 | + pNew->pNext = p; |
| 102817 | + p->pPrior = pNew; |
| 102760 | 102818 | } |
| 102761 | | - p->pPrior = pNew; |
| 102762 | 102819 | if( db->mallocFailed ) return 1; |
| 102763 | 102820 | } |
| 102764 | 102821 | |
| 102765 | 102822 | /* Begin flattening the iFrom-th entry of the FROM clause |
| 102766 | 102823 | ** in the outer query. |
| | @@ -103095,10 +103152,14 @@ |
| 103095 | 103152 | p->pWhere = 0; |
| 103096 | 103153 | pNew->pGroupBy = 0; |
| 103097 | 103154 | pNew->pHaving = 0; |
| 103098 | 103155 | pNew->pOrderBy = 0; |
| 103099 | 103156 | p->pPrior = 0; |
| 103157 | + p->pNext = 0; |
| 103158 | + p->selFlags &= ~SF_Compound; |
| 103159 | + assert( pNew->pPrior!=0 ); |
| 103160 | + pNew->pPrior->pNext = pNew; |
| 103100 | 103161 | pNew->pLimit = 0; |
| 103101 | 103162 | pNew->pOffset = 0; |
| 103102 | 103163 | return WRC_Continue; |
| 103103 | 103164 | } |
| 103104 | 103165 | |
| | @@ -103282,13 +103343,14 @@ |
| 103282 | 103343 | ** sqlite3SelectExpand() when walking a SELECT tree to resolve table |
| 103283 | 103344 | ** names and other FROM clause elements. |
| 103284 | 103345 | */ |
| 103285 | 103346 | static void selectPopWith(Walker *pWalker, Select *p){ |
| 103286 | 103347 | Parse *pParse = pWalker->pParse; |
| 103287 | | - if( p->pWith ){ |
| 103288 | | - assert( pParse->pWith==p->pWith ); |
| 103289 | | - pParse->pWith = p->pWith->pOuter; |
| 103348 | + With *pWith = findRightmost(p)->pWith; |
| 103349 | + if( pWith!=0 ){ |
| 103350 | + assert( pParse->pWith==pWith ); |
| 103351 | + pParse->pWith = pWith->pOuter; |
| 103290 | 103352 | } |
| 103291 | 103353 | } |
| 103292 | 103354 | #else |
| 103293 | 103355 | #define selectPopWith 0 |
| 103294 | 103356 | #endif |
| | @@ -103334,11 +103396,11 @@ |
| 103334 | 103396 | if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){ |
| 103335 | 103397 | return WRC_Prune; |
| 103336 | 103398 | } |
| 103337 | 103399 | pTabList = p->pSrc; |
| 103338 | 103400 | pEList = p->pEList; |
| 103339 | | - sqlite3WithPush(pParse, p->pWith, 0); |
| 103401 | + sqlite3WithPush(pParse, findRightmost(p)->pWith, 0); |
| 103340 | 103402 | |
| 103341 | 103403 | /* Make sure cursor numbers have been assigned to all entries in |
| 103342 | 103404 | ** the FROM clause of the SELECT statement. |
| 103343 | 103405 | */ |
| 103344 | 103406 | sqlite3SrcListAssignCursors(pParse, pTabList); |
| | @@ -103847,11 +103909,11 @@ |
| 103847 | 103909 | ** |
| 103848 | 103910 | ** Another solution would be to change the OP_SCopy used to copy cached |
| 103849 | 103911 | ** values to an OP_Copy. |
| 103850 | 103912 | */ |
| 103851 | 103913 | if( regHit ){ |
| 103852 | | - addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit); |
| 103914 | + addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit); VdbeCoverage(v); |
| 103853 | 103915 | } |
| 103854 | 103916 | sqlite3ExprCacheClear(pParse); |
| 103855 | 103917 | for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){ |
| 103856 | 103918 | sqlite3ExprCode(pParse, pC->pExpr, pC->iMem); |
| 103857 | 103919 | } |
| | @@ -104006,46 +104068,28 @@ |
| 104006 | 104068 | if( isAggSub ){ |
| 104007 | 104069 | isAgg = 1; |
| 104008 | 104070 | p->selFlags |= SF_Aggregate; |
| 104009 | 104071 | } |
| 104010 | 104072 | i = -1; |
| 104011 | | - }else if( pTabList->nSrc==1 && (p->selFlags & SF_Materialize)==0 |
| 104012 | | - && OptimizationEnabled(db, SQLITE_SubqCoroutine) |
| 104073 | + }else if( pTabList->nSrc==1 |
| 104074 | + && OptimizationEnabled(db, SQLITE_SubqCoroutine) |
| 104013 | 104075 | ){ |
| 104014 | 104076 | /* Implement a co-routine that will return a single row of the result |
| 104015 | 104077 | ** set on each invocation. |
| 104016 | 104078 | */ |
| 104017 | | - int addrTop; |
| 104018 | | - int addrEof; |
| 104079 | + int addrTop = sqlite3VdbeCurrentAddr(v)+1; |
| 104019 | 104080 | pItem->regReturn = ++pParse->nMem; |
| 104020 | | - addrEof = ++pParse->nMem; |
| 104021 | | - /* Before coding the OP_Goto to jump to the start of the main routine, |
| 104022 | | - ** ensure that the jump to the verify-schema routine has already |
| 104023 | | - ** been coded. Otherwise, the verify-schema would likely be coded as |
| 104024 | | - ** part of the co-routine. If the main routine then accessed the |
| 104025 | | - ** database before invoking the co-routine for the first time (for |
| 104026 | | - ** example to initialize a LIMIT register from a sub-select), it would |
| 104027 | | - ** be doing so without having verified the schema version and obtained |
| 104028 | | - ** the required db locks. See ticket d6b36be38. */ |
| 104029 | | - sqlite3CodeVerifySchema(pParse, -1); |
| 104030 | | - sqlite3VdbeAddOp0(v, OP_Goto); |
| 104031 | | - addrTop = sqlite3VdbeAddOp1(v, OP_OpenPseudo, pItem->iCursor); |
| 104032 | | - sqlite3VdbeChangeP5(v, 1); |
| 104033 | | - VdbeComment((v, "coroutine for %s", pItem->pTab->zName)); |
| 104081 | + sqlite3VdbeAddOp3(v, OP_InitCoroutine, pItem->regReturn, 0, addrTop); |
| 104082 | + VdbeComment((v, "%s", pItem->pTab->zName)); |
| 104034 | 104083 | pItem->addrFillSub = addrTop; |
| 104035 | | - sqlite3VdbeAddOp2(v, OP_Integer, 0, addrEof); |
| 104036 | | - sqlite3VdbeChangeP5(v, 1); |
| 104037 | 104084 | sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn); |
| 104038 | 104085 | explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId); |
| 104039 | 104086 | sqlite3Select(pParse, pSub, &dest); |
| 104040 | 104087 | pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow; |
| 104041 | 104088 | pItem->viaCoroutine = 1; |
| 104042 | | - sqlite3VdbeChangeP2(v, addrTop, dest.iSdst); |
| 104043 | | - sqlite3VdbeChangeP3(v, addrTop, dest.nSdst); |
| 104044 | | - sqlite3VdbeAddOp2(v, OP_Integer, 1, addrEof); |
| 104045 | | - sqlite3VdbeAddOp1(v, OP_Yield, pItem->regReturn); |
| 104046 | | - VdbeComment((v, "end %s", pItem->pTab->zName)); |
| 104089 | + pItem->regResult = dest.iSdst; |
| 104090 | + sqlite3VdbeAddOp1(v, OP_EndCoroutine, pItem->regReturn); |
| 104047 | 104091 | sqlite3VdbeJumpHere(v, addrTop-1); |
| 104048 | 104092 | sqlite3ClearTempRegCache(pParse); |
| 104049 | 104093 | }else{ |
| 104050 | 104094 | /* Generate a subroutine that will fill an ephemeral table with |
| 104051 | 104095 | ** the content of this subquery. pItem->addrFillSub will point |
| | @@ -104057,16 +104101,18 @@ |
| 104057 | 104101 | int retAddr; |
| 104058 | 104102 | assert( pItem->addrFillSub==0 ); |
| 104059 | 104103 | pItem->regReturn = ++pParse->nMem; |
| 104060 | 104104 | topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn); |
| 104061 | 104105 | pItem->addrFillSub = topAddr+1; |
| 104062 | | - VdbeNoopComment((v, "materialize %s", pItem->pTab->zName)); |
| 104063 | 104106 | if( pItem->isCorrelated==0 ){ |
| 104064 | 104107 | /* If the subquery is not correlated and if we are not inside of |
| 104065 | 104108 | ** a trigger, then we only need to compute the value of the subquery |
| 104066 | 104109 | ** once. */ |
| 104067 | | - onceAddr = sqlite3CodeOnce(pParse); |
| 104110 | + onceAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v); |
| 104111 | + VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName)); |
| 104112 | + }else{ |
| 104113 | + VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName)); |
| 104068 | 104114 | } |
| 104069 | 104115 | sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor); |
| 104070 | 104116 | explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId); |
| 104071 | 104117 | sqlite3Select(pParse, pSub, &dest); |
| 104072 | 104118 | pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow; |
| | @@ -104094,25 +104140,10 @@ |
| 104094 | 104140 | |
| 104095 | 104141 | #ifndef SQLITE_OMIT_COMPOUND_SELECT |
| 104096 | 104142 | /* If there is are a sequence of queries, do the earlier ones first. |
| 104097 | 104143 | */ |
| 104098 | 104144 | if( p->pPrior ){ |
| 104099 | | - if( p->pRightmost==0 ){ |
| 104100 | | - Select *pLoop, *pRight = 0; |
| 104101 | | - int cnt = 0; |
| 104102 | | - int mxSelect; |
| 104103 | | - for(pLoop=p; pLoop; pLoop=pLoop->pPrior, cnt++){ |
| 104104 | | - pLoop->pRightmost = p; |
| 104105 | | - pLoop->pNext = pRight; |
| 104106 | | - pRight = pLoop; |
| 104107 | | - } |
| 104108 | | - mxSelect = db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT]; |
| 104109 | | - if( mxSelect && cnt>mxSelect ){ |
| 104110 | | - sqlite3ErrorMsg(pParse, "too many terms in compound SELECT"); |
| 104111 | | - goto select_end; |
| 104112 | | - } |
| 104113 | | - } |
| 104114 | 104145 | rc = multiSelect(pParse, p, pDest); |
| 104115 | 104146 | explainSetInteger(pParse->iSelectId, iRestoreSelectId); |
| 104116 | 104147 | return rc; |
| 104117 | 104148 | } |
| 104118 | 104149 | #endif |
| | @@ -104412,11 +104443,11 @@ |
| 104412 | 104443 | sqlite3WhereEnd(pWInfo); |
| 104413 | 104444 | sAggInfo.sortingIdxPTab = sortPTab = pParse->nTab++; |
| 104414 | 104445 | sortOut = sqlite3GetTempReg(pParse); |
| 104415 | 104446 | sqlite3VdbeAddOp3(v, OP_OpenPseudo, sortPTab, sortOut, nCol); |
| 104416 | 104447 | sqlite3VdbeAddOp2(v, OP_SorterSort, sAggInfo.sortingIdx, addrEnd); |
| 104417 | | - VdbeComment((v, "GROUP BY sort")); |
| 104448 | + VdbeComment((v, "GROUP BY sort")); VdbeCoverage(v); |
| 104418 | 104449 | sAggInfo.useSortingIdx = 1; |
| 104419 | 104450 | sqlite3ExprCacheClear(pParse); |
| 104420 | 104451 | } |
| 104421 | 104452 | |
| 104422 | 104453 | /* Evaluate the current GROUP BY terms and store in b0, b1, b2... |
| | @@ -104439,11 +104470,11 @@ |
| 104439 | 104470 | } |
| 104440 | 104471 | } |
| 104441 | 104472 | sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr, |
| 104442 | 104473 | (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO); |
| 104443 | 104474 | j1 = sqlite3VdbeCurrentAddr(v); |
| 104444 | | - sqlite3VdbeAddOp3(v, OP_Jump, j1+1, 0, j1+1); |
| 104475 | + sqlite3VdbeAddOp3(v, OP_Jump, j1+1, 0, j1+1); VdbeCoverage(v); |
| 104445 | 104476 | |
| 104446 | 104477 | /* Generate code that runs whenever the GROUP BY changes. |
| 104447 | 104478 | ** Changes in the GROUP BY are detected by the previous code |
| 104448 | 104479 | ** block. If there were no changes, this block is skipped. |
| 104449 | 104480 | ** |
| | @@ -104453,11 +104484,11 @@ |
| 104453 | 104484 | ** for the next GROUP BY batch. |
| 104454 | 104485 | */ |
| 104455 | 104486 | sqlite3ExprCodeMove(pParse, iBMem, iAMem, pGroupBy->nExpr); |
| 104456 | 104487 | sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow); |
| 104457 | 104488 | VdbeComment((v, "output one row")); |
| 104458 | | - sqlite3VdbeAddOp2(v, OP_IfPos, iAbortFlag, addrEnd); |
| 104489 | + sqlite3VdbeAddOp2(v, OP_IfPos, iAbortFlag, addrEnd); VdbeCoverage(v); |
| 104459 | 104490 | VdbeComment((v, "check abort flag")); |
| 104460 | 104491 | sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset); |
| 104461 | 104492 | VdbeComment((v, "reset accumulator")); |
| 104462 | 104493 | |
| 104463 | 104494 | /* Update the aggregate accumulators based on the content of |
| | @@ -104470,10 +104501,11 @@ |
| 104470 | 104501 | |
| 104471 | 104502 | /* End of the loop |
| 104472 | 104503 | */ |
| 104473 | 104504 | if( groupBySort ){ |
| 104474 | 104505 | sqlite3VdbeAddOp2(v, OP_SorterNext, sAggInfo.sortingIdx, addrTopOfLoop); |
| 104506 | + VdbeCoverage(v); |
| 104475 | 104507 | }else{ |
| 104476 | 104508 | sqlite3WhereEnd(pWInfo); |
| 104477 | 104509 | sqlite3VdbeChangeToNoop(v, addrSortingIdx); |
| 104478 | 104510 | } |
| 104479 | 104511 | |
| | @@ -104497,11 +104529,11 @@ |
| 104497 | 104529 | sqlite3VdbeAddOp2(v, OP_Integer, 1, iAbortFlag); |
| 104498 | 104530 | VdbeComment((v, "set abort flag")); |
| 104499 | 104531 | sqlite3VdbeAddOp1(v, OP_Return, regOutputRow); |
| 104500 | 104532 | sqlite3VdbeResolveLabel(v, addrOutputRow); |
| 104501 | 104533 | addrOutputRow = sqlite3VdbeCurrentAddr(v); |
| 104502 | | - sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2); |
| 104534 | + sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2); VdbeCoverage(v); |
| 104503 | 104535 | VdbeComment((v, "Groupby result generator entry point")); |
| 104504 | 104536 | sqlite3VdbeAddOp1(v, OP_Return, regOutputRow); |
| 104505 | 104537 | finalizeAggFunctions(pParse, &sAggInfo); |
| 104506 | 104538 | sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL); |
| 104507 | 104539 | selectInnerLoop(pParse, p, p->pEList, -1, pOrderBy, |
| | @@ -104770,14 +104802,10 @@ |
| 104770 | 104802 | SQLITE_PRIVATE void sqlite3ExplainSelect(Vdbe *pVdbe, Select *p){ |
| 104771 | 104803 | if( p==0 ){ |
| 104772 | 104804 | sqlite3ExplainPrintf(pVdbe, "(null-select)"); |
| 104773 | 104805 | return; |
| 104774 | 104806 | } |
| 104775 | | - while( p->pPrior ){ |
| 104776 | | - p->pPrior->pNext = p; |
| 104777 | | - p = p->pPrior; |
| 104778 | | - } |
| 104779 | 104807 | sqlite3ExplainPush(pVdbe); |
| 104780 | 104808 | while( p ){ |
| 104781 | 104809 | explainOneSelect(pVdbe, p); |
| 104782 | 104810 | p = p->pNext; |
| 104783 | 104811 | if( p==0 ) break; |
| | @@ -105558,10 +105586,11 @@ |
| 105558 | 105586 | /* Generate code to destroy the database record of the trigger. |
| 105559 | 105587 | */ |
| 105560 | 105588 | assert( pTable!=0 ); |
| 105561 | 105589 | if( (v = sqlite3GetVdbe(pParse))!=0 ){ |
| 105562 | 105590 | int base; |
| 105591 | + static const int iLn = __LINE__+2; |
| 105563 | 105592 | static const VdbeOpList dropTrigger[] = { |
| 105564 | 105593 | { OP_Rewind, 0, ADDR(9), 0}, |
| 105565 | 105594 | { OP_String8, 0, 1, 0}, /* 1 */ |
| 105566 | 105595 | { OP_Column, 0, 1, 2}, |
| 105567 | 105596 | { OP_Ne, 2, ADDR(8), 1}, |
| | @@ -105572,11 +105601,11 @@ |
| 105572 | 105601 | { OP_Next, 0, ADDR(1), 0}, /* 8 */ |
| 105573 | 105602 | }; |
| 105574 | 105603 | |
| 105575 | 105604 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 105576 | 105605 | sqlite3OpenMasterTable(pParse, iDb); |
| 105577 | | - base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger); |
| 105606 | + base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger, iLn); |
| 105578 | 105607 | sqlite3VdbeChangeP4(v, base+1, pTrigger->zName, P4_TRANSIENT); |
| 105579 | 105608 | sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC); |
| 105580 | 105609 | sqlite3ChangeCookie(pParse, iDb); |
| 105581 | 105610 | sqlite3VdbeAddOp2(v, OP_Close, 0, 0); |
| 105582 | 105611 | sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0); |
| | @@ -105718,19 +105747,11 @@ |
| 105718 | 105747 | ** |
| 105719 | 105748 | ** INSERT INTO t1 ... ; -- insert into t2 uses REPLACE policy |
| 105720 | 105749 | ** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy |
| 105721 | 105750 | */ |
| 105722 | 105751 | pParse->eOrconf = (orconf==OE_Default)?pStep->orconf:(u8)orconf; |
| 105723 | | - |
| 105724 | | - /* Clear the cookieGoto flag. When coding triggers, the cookieGoto |
| 105725 | | - ** variable is used as a flag to indicate to sqlite3ExprCodeConstants() |
| 105726 | | - ** that it is not safe to refactor constants (this happens after the |
| 105727 | | - ** start of the first loop in the SQL statement is coded - at that |
| 105728 | | - ** point code may be conditionally executed, so it is no longer safe to |
| 105729 | | - ** initialize constant register values). */ |
| 105730 | | - assert( pParse->cookieGoto==0 || pParse->cookieGoto==-1 ); |
| 105731 | | - pParse->cookieGoto = 0; |
| 105752 | + assert( pParse->okConstFactor==0 ); |
| 105732 | 105753 | |
| 105733 | 105754 | switch( pStep->op ){ |
| 105734 | 105755 | case TK_UPDATE: { |
| 105735 | 105756 | sqlite3Update(pParse, |
| 105736 | 105757 | targetSrcList(pParse, pStep), |
| | @@ -106515,11 +106536,11 @@ |
| 106515 | 106536 | sqlite3VdbeChangeToNoop(v, addrOpen); |
| 106516 | 106537 | nKey = nPk; |
| 106517 | 106538 | regKey = iPk; |
| 106518 | 106539 | }else{ |
| 106519 | 106540 | sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey, |
| 106520 | | - sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT); |
| 106541 | + sqlite3IndexAffinityStr(v, pPk), nPk); |
| 106521 | 106542 | sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, regKey); |
| 106522 | 106543 | } |
| 106523 | 106544 | sqlite3WhereEnd(pWInfo); |
| 106524 | 106545 | } |
| 106525 | 106546 | |
| | @@ -106559,32 +106580,37 @@ |
| 106559 | 106580 | /* Top of the update loop */ |
| 106560 | 106581 | if( okOnePass ){ |
| 106561 | 106582 | if( aToOpen[iDataCur-iBaseCur] ){ |
| 106562 | 106583 | assert( pPk!=0 ); |
| 106563 | 106584 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey); |
| 106585 | + VdbeCoverageNeverTaken(v); |
| 106564 | 106586 | } |
| 106565 | 106587 | labelContinue = labelBreak; |
| 106566 | 106588 | sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak); |
| 106589 | + VdbeCoverage(v); |
| 106567 | 106590 | }else if( pPk ){ |
| 106568 | 106591 | labelContinue = sqlite3VdbeMakeLabel(v); |
| 106569 | | - sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak); |
| 106592 | + sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak); VdbeCoverage(v); |
| 106570 | 106593 | addrTop = sqlite3VdbeAddOp2(v, OP_RowKey, iEph, regKey); |
| 106571 | 106594 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey, 0); |
| 106595 | + VdbeCoverage(v); |
| 106572 | 106596 | }else{ |
| 106573 | 106597 | labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, labelBreak, |
| 106574 | 106598 | regOldRowid); |
| 106599 | + VdbeCoverage(v); |
| 106575 | 106600 | sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid); |
| 106601 | + VdbeCoverage(v); |
| 106576 | 106602 | } |
| 106577 | 106603 | |
| 106578 | 106604 | /* If the record number will change, set register regNewRowid to |
| 106579 | 106605 | ** contain the new value. If the record number is not being modified, |
| 106580 | 106606 | ** then regNewRowid is the same register as regOldRowid, which is |
| 106581 | 106607 | ** already populated. */ |
| 106582 | 106608 | assert( chngKey || pTrigger || hasFK || regOldRowid==regNewRowid ); |
| 106583 | 106609 | if( chngRowid ){ |
| 106584 | 106610 | sqlite3ExprCode(pParse, pRowidExpr, regNewRowid); |
| 106585 | | - sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid); |
| 106611 | + sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid); VdbeCoverage(v); |
| 106586 | 106612 | } |
| 106587 | 106613 | |
| 106588 | 106614 | /* Compute the old pre-UPDATE content of the row being changed, if that |
| 106589 | 106615 | ** information is needed */ |
| 106590 | 106616 | if( chngPk || hasFK || pTrigger ){ |
| | @@ -106649,12 +106675,11 @@ |
| 106649 | 106675 | |
| 106650 | 106676 | /* Fire any BEFORE UPDATE triggers. This happens before constraints are |
| 106651 | 106677 | ** verified. One could argue that this is wrong. |
| 106652 | 106678 | */ |
| 106653 | 106679 | if( tmask&TRIGGER_BEFORE ){ |
| 106654 | | - sqlite3VdbeAddOp2(v, OP_Affinity, regNew, pTab->nCol); |
| 106655 | | - sqlite3TableAffinityStr(v, pTab); |
| 106680 | + sqlite3TableAffinity(v, pTab, regNew); |
| 106656 | 106681 | sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges, |
| 106657 | 106682 | TRIGGER_BEFORE, pTab, regOldRowid, onError, labelContinue); |
| 106658 | 106683 | |
| 106659 | 106684 | /* The row-trigger may have deleted the row being updated. In this |
| 106660 | 106685 | ** case, jump to the next row. No updates or AFTER triggers are |
| | @@ -106662,12 +106687,14 @@ |
| 106662 | 106687 | ** is deleted or renamed by a BEFORE trigger - is left undefined in the |
| 106663 | 106688 | ** documentation. |
| 106664 | 106689 | */ |
| 106665 | 106690 | if( pPk ){ |
| 106666 | 106691 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue,regKey,nKey); |
| 106692 | + VdbeCoverage(v); |
| 106667 | 106693 | }else{ |
| 106668 | 106694 | sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid); |
| 106695 | + VdbeCoverage(v); |
| 106669 | 106696 | } |
| 106670 | 106697 | |
| 106671 | 106698 | /* If it did not delete it, the row-trigger may still have modified |
| 106672 | 106699 | ** some of the columns of the row being updated. Load the values for |
| 106673 | 106700 | ** all columns not modified by the update statement into their |
| | @@ -106699,10 +106726,11 @@ |
| 106699 | 106726 | if( pPk ){ |
| 106700 | 106727 | j1 = sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, 0, regKey, nKey); |
| 106701 | 106728 | }else{ |
| 106702 | 106729 | j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid); |
| 106703 | 106730 | } |
| 106731 | + VdbeCoverageNeverTaken(v); |
| 106704 | 106732 | } |
| 106705 | 106733 | sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx); |
| 106706 | 106734 | |
| 106707 | 106735 | /* If changing the record number, delete the old record. */ |
| 106708 | 106736 | if( hasFK || chngKey || pPk!=0 ){ |
| | @@ -106742,11 +106770,11 @@ |
| 106742 | 106770 | */ |
| 106743 | 106771 | if( okOnePass ){ |
| 106744 | 106772 | /* Nothing to do at end-of-loop for a single-pass */ |
| 106745 | 106773 | }else if( pPk ){ |
| 106746 | 106774 | sqlite3VdbeResolveLabel(v, labelContinue); |
| 106747 | | - sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); |
| 106775 | + sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v); |
| 106748 | 106776 | }else{ |
| 106749 | 106777 | sqlite3VdbeAddOp2(v, OP_Goto, 0, labelContinue); |
| 106750 | 106778 | } |
| 106751 | 106779 | sqlite3VdbeResolveLabel(v, labelBreak); |
| 106752 | 106780 | |
| | @@ -106871,21 +106899,21 @@ |
| 106871 | 106899 | sqlite3Select(pParse, pSelect, &dest); |
| 106872 | 106900 | |
| 106873 | 106901 | /* Generate code to scan the ephemeral table and call VUpdate. */ |
| 106874 | 106902 | iReg = ++pParse->nMem; |
| 106875 | 106903 | pParse->nMem += pTab->nCol+1; |
| 106876 | | - addr = sqlite3VdbeAddOp2(v, OP_Rewind, ephemTab, 0); |
| 106904 | + addr = sqlite3VdbeAddOp2(v, OP_Rewind, ephemTab, 0); VdbeCoverage(v); |
| 106877 | 106905 | sqlite3VdbeAddOp3(v, OP_Column, ephemTab, 0, iReg); |
| 106878 | 106906 | sqlite3VdbeAddOp3(v, OP_Column, ephemTab, (pRowid?1:0), iReg+1); |
| 106879 | 106907 | for(i=0; i<pTab->nCol; i++){ |
| 106880 | 106908 | sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i+1+(pRowid!=0), iReg+2+i); |
| 106881 | 106909 | } |
| 106882 | 106910 | sqlite3VtabMakeWritable(pParse, pTab); |
| 106883 | 106911 | sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB); |
| 106884 | 106912 | sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError); |
| 106885 | 106913 | sqlite3MayAbort(pParse); |
| 106886 | | - sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1); |
| 106914 | + sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1); VdbeCoverage(v); |
| 106887 | 106915 | sqlite3VdbeJumpHere(v, addr); |
| 106888 | 106916 | sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0); |
| 106889 | 106917 | |
| 106890 | 106918 | /* Cleanup */ |
| 106891 | 106919 | sqlite3SelectDelete(db, pSelect); |
| | @@ -108453,11 +108481,11 @@ |
| 108453 | 108481 | int addrSkip; /* Jump here for next iteration of skip-scan */ |
| 108454 | 108482 | int addrCont; /* Jump here to continue with the next loop cycle */ |
| 108455 | 108483 | int addrFirst; /* First instruction of interior of the loop */ |
| 108456 | 108484 | int addrBody; /* Beginning of the body of this loop */ |
| 108457 | 108485 | u8 iFrom; /* Which entry in the FROM clause */ |
| 108458 | | - u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */ |
| 108486 | + u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */ |
| 108459 | 108487 | int p1, p2; /* Operands of the opcode used to ends the loop */ |
| 108460 | 108488 | union { /* Information that depends on pWLoop->wsFlags */ |
| 108461 | 108489 | struct { |
| 108462 | 108490 | int nIn; /* Number of entries in aInLoop[] */ |
| 108463 | 108491 | struct InLoop { |
| | @@ -108840,10 +108868,11 @@ |
| 108840 | 108868 | #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */ |
| 108841 | 108869 | #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */ |
| 108842 | 108870 | #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */ |
| 108843 | 108871 | #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */ |
| 108844 | 108872 | #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */ |
| 108873 | +#define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/ |
| 108845 | 108874 | |
| 108846 | 108875 | /************** End of whereInt.h ********************************************/ |
| 108847 | 108876 | /************** Continuing where we left off in where.c **********************/ |
| 108848 | 108877 | |
| 108849 | 108878 | /* |
| | @@ -110426,11 +110455,11 @@ |
| 110426 | 110455 | |
| 110427 | 110456 | /* Generate code to skip over the creation and initialization of the |
| 110428 | 110457 | ** transient index on 2nd and subsequent iterations of the loop. */ |
| 110429 | 110458 | v = pParse->pVdbe; |
| 110430 | 110459 | assert( v!=0 ); |
| 110431 | | - addrInit = sqlite3CodeOnce(pParse); |
| 110460 | + addrInit = sqlite3CodeOnce(pParse); VdbeCoverage(v); |
| 110432 | 110461 | |
| 110433 | 110462 | /* Count the number of columns that will be added to the index |
| 110434 | 110463 | ** and used to match WHERE clause constraints */ |
| 110435 | 110464 | nKeyCol = 0; |
| 110436 | 110465 | pTable = pSrc->pTab; |
| | @@ -110533,16 +110562,16 @@ |
| 110533 | 110562 | sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1); |
| 110534 | 110563 | sqlite3VdbeSetP4KeyInfo(pParse, pIdx); |
| 110535 | 110564 | VdbeComment((v, "for %s", pTable->zName)); |
| 110536 | 110565 | |
| 110537 | 110566 | /* Fill the automatic index with content */ |
| 110538 | | - addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); |
| 110567 | + addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v); |
| 110539 | 110568 | regRecord = sqlite3GetTempReg(pParse); |
| 110540 | 110569 | sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0); |
| 110541 | 110570 | sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord); |
| 110542 | 110571 | sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 110543 | | - sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); |
| 110572 | + sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v); |
| 110544 | 110573 | sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX); |
| 110545 | 110574 | sqlite3VdbeJumpHere(v, addrTop); |
| 110546 | 110575 | sqlite3ReleaseTempReg(pParse, regRecord); |
| 110547 | 110576 | |
| 110548 | 110577 | /* Jump here when skipping the initialization */ |
| | @@ -111214,10 +111243,12 @@ |
| 111214 | 111243 | testcase( bRev ); |
| 111215 | 111244 | bRev = !bRev; |
| 111216 | 111245 | } |
| 111217 | 111246 | iTab = pX->iTable; |
| 111218 | 111247 | sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0); |
| 111248 | + VdbeCoverageIf(v, bRev); |
| 111249 | + VdbeCoverageIf(v, !bRev); |
| 111219 | 111250 | assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 ); |
| 111220 | 111251 | pLoop->wsFlags |= WHERE_IN_ABLE; |
| 111221 | 111252 | if( pLevel->u.in.nIn==0 ){ |
| 111222 | 111253 | pLevel->addrNxt = sqlite3VdbeMakeLabel(v); |
| 111223 | 111254 | } |
| | @@ -111233,11 +111264,11 @@ |
| 111233 | 111264 | pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg); |
| 111234 | 111265 | }else{ |
| 111235 | 111266 | pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg); |
| 111236 | 111267 | } |
| 111237 | 111268 | pIn->eEndLoopOp = bRev ? OP_PrevIfOpen : OP_NextIfOpen; |
| 111238 | | - sqlite3VdbeAddOp1(v, OP_IsNull, iReg); |
| 111269 | + sqlite3VdbeAddOp1(v, OP_IsNull, iReg); VdbeCoverage(v); |
| 111239 | 111270 | }else{ |
| 111240 | 111271 | pLevel->u.in.nIn = 0; |
| 111241 | 111272 | } |
| 111242 | 111273 | #endif |
| 111243 | 111274 | } |
| | @@ -111328,14 +111359,18 @@ |
| 111328 | 111359 | } |
| 111329 | 111360 | |
| 111330 | 111361 | if( nSkip ){ |
| 111331 | 111362 | int iIdxCur = pLevel->iIdxCur; |
| 111332 | 111363 | sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur); |
| 111364 | + VdbeCoverageIf(v, bRev==0); |
| 111365 | + VdbeCoverageIf(v, bRev!=0); |
| 111333 | 111366 | VdbeComment((v, "begin skip-scan on %s", pIdx->zName)); |
| 111334 | 111367 | j = sqlite3VdbeAddOp0(v, OP_Goto); |
| 111335 | | - pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLt:OP_SeekGt), |
| 111368 | + pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLT:OP_SeekGT), |
| 111336 | 111369 | iIdxCur, 0, regBase, nSkip); |
| 111370 | + VdbeCoverageIf(v, bRev==0); |
| 111371 | + VdbeCoverageIf(v, bRev!=0); |
| 111337 | 111372 | sqlite3VdbeJumpHere(v, j); |
| 111338 | 111373 | for(j=0; j<nSkip; j++){ |
| 111339 | 111374 | sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j); |
| 111340 | 111375 | assert( pIdx->aiColumn[j]>=0 ); |
| 111341 | 111376 | VdbeComment((v, "%s", pIdx->pTable->aCol[pIdx->aiColumn[j]].zName)); |
| | @@ -111364,11 +111399,14 @@ |
| 111364 | 111399 | } |
| 111365 | 111400 | testcase( pTerm->eOperator & WO_ISNULL ); |
| 111366 | 111401 | testcase( pTerm->eOperator & WO_IN ); |
| 111367 | 111402 | if( (pTerm->eOperator & (WO_ISNULL|WO_IN))==0 ){ |
| 111368 | 111403 | Expr *pRight = pTerm->pExpr->pRight; |
| 111369 | | - sqlite3ExprCodeIsNullJump(v, pRight, regBase+j, pLevel->addrBrk); |
| 111404 | + if( sqlite3ExprCanBeNull(pRight) ){ |
| 111405 | + sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk); |
| 111406 | + VdbeCoverage(v); |
| 111407 | + } |
| 111370 | 111408 | if( zAff ){ |
| 111371 | 111409 | if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_NONE ){ |
| 111372 | 111410 | zAff[j] = SQLITE_AFF_NONE; |
| 111373 | 111411 | } |
| 111374 | 111412 | if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){ |
| | @@ -111610,14 +111648,14 @@ |
| 111610 | 111648 | } |
| 111611 | 111649 | |
| 111612 | 111650 | /* Special case of a FROM clause subquery implemented as a co-routine */ |
| 111613 | 111651 | if( pTabItem->viaCoroutine ){ |
| 111614 | 111652 | int regYield = pTabItem->regReturn; |
| 111615 | | - sqlite3VdbeAddOp2(v, OP_Integer, pTabItem->addrFillSub-1, regYield); |
| 111616 | | - pLevel->p2 = sqlite3VdbeAddOp1(v, OP_Yield, regYield); |
| 111617 | | - VdbeComment((v, "next row of co-routine %s", pTabItem->pTab->zName)); |
| 111618 | | - sqlite3VdbeAddOp2(v, OP_If, regYield+1, addrBrk); |
| 111653 | + sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub); |
| 111654 | + pLevel->p2 = sqlite3VdbeAddOp2(v, OP_Yield, regYield, addrBrk); |
| 111655 | + VdbeCoverage(v); |
| 111656 | + VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName)); |
| 111619 | 111657 | pLevel->op = OP_Goto; |
| 111620 | 111658 | }else |
| 111621 | 111659 | |
| 111622 | 111660 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 111623 | 111661 | if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){ |
| | @@ -111645,10 +111683,11 @@ |
| 111645 | 111683 | sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg); |
| 111646 | 111684 | sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1); |
| 111647 | 111685 | sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg, |
| 111648 | 111686 | pLoop->u.vtab.idxStr, |
| 111649 | 111687 | pLoop->u.vtab.needFree ? P4_MPRINTF : P4_STATIC); |
| 111688 | + VdbeCoverage(v); |
| 111650 | 111689 | pLoop->u.vtab.needFree = 0; |
| 111651 | 111690 | for(j=0; j<nConstraint && j<16; j++){ |
| 111652 | 111691 | if( (pLoop->u.vtab.omitMask>>j)&1 ){ |
| 111653 | 111692 | disableTerm(pLevel, pLoop->aLTerm[j]); |
| 111654 | 111693 | } |
| | @@ -111668,20 +111707,22 @@ |
| 111668 | 111707 | ** equality comparison against the ROWID field. Or |
| 111669 | 111708 | ** we reference multiple rows using a "rowid IN (...)" |
| 111670 | 111709 | ** construct. |
| 111671 | 111710 | */ |
| 111672 | 111711 | assert( pLoop->u.btree.nEq==1 ); |
| 111673 | | - iReleaseReg = sqlite3GetTempReg(pParse); |
| 111674 | 111712 | pTerm = pLoop->aLTerm[0]; |
| 111675 | 111713 | assert( pTerm!=0 ); |
| 111676 | 111714 | assert( pTerm->pExpr!=0 ); |
| 111677 | 111715 | assert( omitTable==0 ); |
| 111678 | 111716 | testcase( pTerm->wtFlags & TERM_VIRTUAL ); |
| 111717 | + iReleaseReg = ++pParse->nMem; |
| 111679 | 111718 | iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg); |
| 111719 | + if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg); |
| 111680 | 111720 | addrNxt = pLevel->addrNxt; |
| 111681 | | - sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt); |
| 111721 | + sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt); VdbeCoverage(v); |
| 111682 | 111722 | sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg); |
| 111723 | + VdbeCoverage(v); |
| 111683 | 111724 | sqlite3ExprCacheAffinityChange(pParse, iRowidReg, 1); |
| 111684 | 111725 | sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg); |
| 111685 | 111726 | VdbeComment((v, "pk")); |
| 111686 | 111727 | pLevel->op = OP_Noop; |
| 111687 | 111728 | }else if( (pLoop->wsFlags & WHERE_IPK)!=0 |
| | @@ -111711,14 +111752,14 @@ |
| 111711 | 111752 | |
| 111712 | 111753 | /* The following constant maps TK_xx codes into corresponding |
| 111713 | 111754 | ** seek opcodes. It depends on a particular ordering of TK_xx |
| 111714 | 111755 | */ |
| 111715 | 111756 | const u8 aMoveOp[] = { |
| 111716 | | - /* TK_GT */ OP_SeekGt, |
| 111717 | | - /* TK_LE */ OP_SeekLe, |
| 111718 | | - /* TK_LT */ OP_SeekLt, |
| 111719 | | - /* TK_GE */ OP_SeekGe |
| 111757 | + /* TK_GT */ OP_SeekGT, |
| 111758 | + /* TK_LE */ OP_SeekLE, |
| 111759 | + /* TK_LT */ OP_SeekLT, |
| 111760 | + /* TK_GE */ OP_SeekGE |
| 111720 | 111761 | }; |
| 111721 | 111762 | assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */ |
| 111722 | 111763 | assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */ |
| 111723 | 111764 | assert( TK_GE==TK_GT+3 ); /* ... is correcct. */ |
| 111724 | 111765 | |
| | @@ -111728,15 +111769,21 @@ |
| 111728 | 111769 | assert( pX!=0 ); |
| 111729 | 111770 | testcase( pStart->leftCursor!=iCur ); /* transitive constraints */ |
| 111730 | 111771 | r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp); |
| 111731 | 111772 | sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1); |
| 111732 | 111773 | VdbeComment((v, "pk")); |
| 111774 | + VdbeCoverageIf(v, pX->op==TK_GT); |
| 111775 | + VdbeCoverageIf(v, pX->op==TK_LE); |
| 111776 | + VdbeCoverageIf(v, pX->op==TK_LT); |
| 111777 | + VdbeCoverageIf(v, pX->op==TK_GE); |
| 111733 | 111778 | sqlite3ExprCacheAffinityChange(pParse, r1, 1); |
| 111734 | 111779 | sqlite3ReleaseTempReg(pParse, rTemp); |
| 111735 | 111780 | disableTerm(pLevel, pStart); |
| 111736 | 111781 | }else{ |
| 111737 | 111782 | sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrBrk); |
| 111783 | + VdbeCoverageIf(v, bRev==0); |
| 111784 | + VdbeCoverageIf(v, bRev!=0); |
| 111738 | 111785 | } |
| 111739 | 111786 | if( pEnd ){ |
| 111740 | 111787 | Expr *pX; |
| 111741 | 111788 | pX = pEnd->pExpr; |
| 111742 | 111789 | assert( pX!=0 ); |
| | @@ -111756,14 +111803,18 @@ |
| 111756 | 111803 | pLevel->op = bRev ? OP_Prev : OP_Next; |
| 111757 | 111804 | pLevel->p1 = iCur; |
| 111758 | 111805 | pLevel->p2 = start; |
| 111759 | 111806 | assert( pLevel->p5==0 ); |
| 111760 | 111807 | if( testOp!=OP_Noop ){ |
| 111761 | | - iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse); |
| 111808 | + iRowidReg = ++pParse->nMem; |
| 111762 | 111809 | sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg); |
| 111763 | 111810 | sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg); |
| 111764 | 111811 | sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg); |
| 111812 | + VdbeCoverageIf(v, testOp==OP_Le); |
| 111813 | + VdbeCoverageIf(v, testOp==OP_Lt); |
| 111814 | + VdbeCoverageIf(v, testOp==OP_Ge); |
| 111815 | + VdbeCoverageIf(v, testOp==OP_Gt); |
| 111765 | 111816 | sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL); |
| 111766 | 111817 | } |
| 111767 | 111818 | }else if( pLoop->wsFlags & WHERE_INDEXED ){ |
| 111768 | 111819 | /* Case 4: A scan using an index. |
| 111769 | 111820 | ** |
| | @@ -111799,24 +111850,23 @@ |
| 111799 | 111850 | static const u8 aStartOp[] = { |
| 111800 | 111851 | 0, |
| 111801 | 111852 | 0, |
| 111802 | 111853 | OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */ |
| 111803 | 111854 | OP_Last, /* 3: (!start_constraints && startEq && bRev) */ |
| 111804 | | - OP_SeekGt, /* 4: (start_constraints && !startEq && !bRev) */ |
| 111805 | | - OP_SeekLt, /* 5: (start_constraints && !startEq && bRev) */ |
| 111806 | | - OP_SeekGe, /* 6: (start_constraints && startEq && !bRev) */ |
| 111807 | | - OP_SeekLe /* 7: (start_constraints && startEq && bRev) */ |
| 111855 | + OP_SeekGT, /* 4: (start_constraints && !startEq && !bRev) */ |
| 111856 | + OP_SeekLT, /* 5: (start_constraints && !startEq && bRev) */ |
| 111857 | + OP_SeekGE, /* 6: (start_constraints && startEq && !bRev) */ |
| 111858 | + OP_SeekLE /* 7: (start_constraints && startEq && bRev) */ |
| 111808 | 111859 | }; |
| 111809 | 111860 | static const u8 aEndOp[] = { |
| 111810 | | - OP_Noop, /* 0: (!end_constraints) */ |
| 111811 | | - OP_IdxGE, /* 1: (end_constraints && !bRev) */ |
| 111812 | | - OP_IdxLT /* 2: (end_constraints && bRev) */ |
| 111861 | + OP_IdxGE, /* 0: (end_constraints && !bRev && !endEq) */ |
| 111862 | + OP_IdxGT, /* 1: (end_constraints && !bRev && endEq) */ |
| 111863 | + OP_IdxLE, /* 2: (end_constraints && bRev && !endEq) */ |
| 111864 | + OP_IdxLT, /* 3: (end_constraints && bRev && endEq) */ |
| 111813 | 111865 | }; |
| 111814 | 111866 | u16 nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */ |
| 111815 | | - int isMinQuery = 0; /* If this is an optimized SELECT min(x).. */ |
| 111816 | 111867 | int regBase; /* Base register holding constraint values */ |
| 111817 | | - int r1; /* Temp register */ |
| 111818 | 111868 | WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */ |
| 111819 | 111869 | WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */ |
| 111820 | 111870 | int startEq; /* True if range start uses ==, >= or <= */ |
| 111821 | 111871 | int endEq; /* True if range end uses ==, >= or <= */ |
| 111822 | 111872 | int start_constraints; /* Start of range is constrained */ |
| | @@ -111825,10 +111875,12 @@ |
| 111825 | 111875 | int iIdxCur; /* The VDBE cursor for the index */ |
| 111826 | 111876 | int nExtraReg = 0; /* Number of extra registers needed */ |
| 111827 | 111877 | int op; /* Instruction opcode */ |
| 111828 | 111878 | char *zStartAff; /* Affinity for start of range constraint */ |
| 111829 | 111879 | char cEndAff = 0; /* Affinity for end of range constraint */ |
| 111880 | + u8 bSeekPastNull = 0; /* True to seek past initial nulls */ |
| 111881 | + u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */ |
| 111830 | 111882 | |
| 111831 | 111883 | pIdx = pLoop->u.btree.pIndex; |
| 111832 | 111884 | iIdxCur = pLevel->iIdxCur; |
| 111833 | 111885 | assert( nEq>=pLoop->u.btree.nSkip ); |
| 111834 | 111886 | |
| | @@ -111843,11 +111895,11 @@ |
| 111843 | 111895 | if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0 |
| 111844 | 111896 | && (pWInfo->bOBSat!=0) |
| 111845 | 111897 | && (pIdx->nKeyCol>nEq) |
| 111846 | 111898 | ){ |
| 111847 | 111899 | assert( pLoop->u.btree.nSkip==0 ); |
| 111848 | | - isMinQuery = 1; |
| 111900 | + bSeekPastNull = 1; |
| 111849 | 111901 | nExtraReg = 1; |
| 111850 | 111902 | } |
| 111851 | 111903 | |
| 111852 | 111904 | /* Find any inequality constraint terms for the start and end |
| 111853 | 111905 | ** of the range. |
| | @@ -111858,10 +111910,17 @@ |
| 111858 | 111910 | nExtraReg = 1; |
| 111859 | 111911 | } |
| 111860 | 111912 | if( pLoop->wsFlags & WHERE_TOP_LIMIT ){ |
| 111861 | 111913 | pRangeEnd = pLoop->aLTerm[j++]; |
| 111862 | 111914 | nExtraReg = 1; |
| 111915 | + if( pRangeStart==0 |
| 111916 | + && (pRangeEnd->wtFlags & TERM_VNULL)==0 |
| 111917 | + && (j = pIdx->aiColumn[nEq])>=0 |
| 111918 | + && pIdx->pTable->aCol[j].notNull==0 |
| 111919 | + ){ |
| 111920 | + bSeekPastNull = 1; |
| 111921 | + } |
| 111863 | 111922 | } |
| 111864 | 111923 | |
| 111865 | 111924 | /* Generate code to evaluate all constraint terms using == or IN |
| 111866 | 111925 | ** and store the values of those terms in an array of registers |
| 111867 | 111926 | ** starting at regBase. |
| | @@ -111877,10 +111936,11 @@ |
| 111877 | 111936 | */ |
| 111878 | 111937 | if( (nEq<pIdx->nKeyCol && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC)) |
| 111879 | 111938 | || (bRev && pIdx->nKeyCol==nEq) |
| 111880 | 111939 | ){ |
| 111881 | 111940 | SWAP(WhereTerm *, pRangeEnd, pRangeStart); |
| 111941 | + SWAP(u8, bSeekPastNull, bStopAtNull); |
| 111882 | 111942 | } |
| 111883 | 111943 | |
| 111884 | 111944 | testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 ); |
| 111885 | 111945 | testcase( pRangeStart && (pRangeStart->eOperator & WO_GE)!=0 ); |
| 111886 | 111946 | testcase( pRangeEnd && (pRangeEnd->eOperator & WO_LE)!=0 ); |
| | @@ -111892,12 +111952,15 @@ |
| 111892 | 111952 | /* Seek the index cursor to the start of the range. */ |
| 111893 | 111953 | nConstraint = nEq; |
| 111894 | 111954 | if( pRangeStart ){ |
| 111895 | 111955 | Expr *pRight = pRangeStart->pExpr->pRight; |
| 111896 | 111956 | sqlite3ExprCode(pParse, pRight, regBase+nEq); |
| 111897 | | - if( (pRangeStart->wtFlags & TERM_VNULL)==0 ){ |
| 111898 | | - sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt); |
| 111957 | + if( (pRangeStart->wtFlags & TERM_VNULL)==0 |
| 111958 | + && sqlite3ExprCanBeNull(pRight) |
| 111959 | + ){ |
| 111960 | + sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt); |
| 111961 | + VdbeCoverage(v); |
| 111899 | 111962 | } |
| 111900 | 111963 | if( zStartAff ){ |
| 111901 | 111964 | if( sqlite3CompareAffinity(pRight, zStartAff[nEq])==SQLITE_AFF_NONE){ |
| 111902 | 111965 | /* Since the comparison is to be performed with no conversions |
| 111903 | 111966 | ** applied to the operands, set the affinity to apply to pRight to |
| | @@ -111908,86 +111971,76 @@ |
| 111908 | 111971 | zStartAff[nEq] = SQLITE_AFF_NONE; |
| 111909 | 111972 | } |
| 111910 | 111973 | } |
| 111911 | 111974 | nConstraint++; |
| 111912 | 111975 | testcase( pRangeStart->wtFlags & TERM_VIRTUAL ); |
| 111913 | | - }else if( isMinQuery ){ |
| 111976 | + }else if( bSeekPastNull ){ |
| 111914 | 111977 | sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq); |
| 111915 | 111978 | nConstraint++; |
| 111916 | 111979 | startEq = 0; |
| 111917 | 111980 | start_constraints = 1; |
| 111918 | 111981 | } |
| 111919 | | - codeApplyAffinity(pParse, regBase, nConstraint, zStartAff); |
| 111982 | + codeApplyAffinity(pParse, regBase, nConstraint - bSeekPastNull, zStartAff); |
| 111920 | 111983 | op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev]; |
| 111921 | 111984 | assert( op!=0 ); |
| 111922 | | - testcase( op==OP_Rewind ); |
| 111923 | | - testcase( op==OP_Last ); |
| 111924 | | - testcase( op==OP_SeekGt ); |
| 111925 | | - testcase( op==OP_SeekGe ); |
| 111926 | | - testcase( op==OP_SeekLe ); |
| 111927 | | - testcase( op==OP_SeekLt ); |
| 111928 | 111985 | sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint); |
| 111986 | + VdbeCoverage(v); |
| 111987 | + VdbeCoverageIf(v, op==OP_Rewind); testcase( op==OP_Rewind ); |
| 111988 | + VdbeCoverageIf(v, op==OP_Last); testcase( op==OP_Last ); |
| 111989 | + VdbeCoverageIf(v, op==OP_SeekGT); testcase( op==OP_SeekGT ); |
| 111990 | + VdbeCoverageIf(v, op==OP_SeekGE); testcase( op==OP_SeekGE ); |
| 111991 | + VdbeCoverageIf(v, op==OP_SeekLE); testcase( op==OP_SeekLE ); |
| 111992 | + VdbeCoverageIf(v, op==OP_SeekLT); testcase( op==OP_SeekLT ); |
| 111929 | 111993 | |
| 111930 | 111994 | /* Load the value for the inequality constraint at the end of the |
| 111931 | 111995 | ** range (if any). |
| 111932 | 111996 | */ |
| 111933 | 111997 | nConstraint = nEq; |
| 111934 | 111998 | if( pRangeEnd ){ |
| 111935 | 111999 | Expr *pRight = pRangeEnd->pExpr->pRight; |
| 111936 | 112000 | sqlite3ExprCacheRemove(pParse, regBase+nEq, 1); |
| 111937 | 112001 | sqlite3ExprCode(pParse, pRight, regBase+nEq); |
| 111938 | | - if( (pRangeEnd->wtFlags & TERM_VNULL)==0 ){ |
| 111939 | | - sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt); |
| 112002 | + if( (pRangeEnd->wtFlags & TERM_VNULL)==0 |
| 112003 | + && sqlite3ExprCanBeNull(pRight) |
| 112004 | + ){ |
| 112005 | + sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt); |
| 112006 | + VdbeCoverage(v); |
| 111940 | 112007 | } |
| 111941 | 112008 | if( sqlite3CompareAffinity(pRight, cEndAff)!=SQLITE_AFF_NONE |
| 111942 | 112009 | && !sqlite3ExprNeedsNoAffinityChange(pRight, cEndAff) |
| 111943 | 112010 | ){ |
| 111944 | 112011 | codeApplyAffinity(pParse, regBase+nEq, 1, &cEndAff); |
| 111945 | 112012 | } |
| 111946 | 112013 | nConstraint++; |
| 111947 | 112014 | testcase( pRangeEnd->wtFlags & TERM_VIRTUAL ); |
| 112015 | + }else if( bStopAtNull ){ |
| 112016 | + sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq); |
| 112017 | + endEq = 0; |
| 112018 | + nConstraint++; |
| 111948 | 112019 | } |
| 111949 | 112020 | sqlite3DbFree(db, zStartAff); |
| 111950 | 112021 | |
| 111951 | 112022 | /* Top of the loop body */ |
| 111952 | 112023 | pLevel->p2 = sqlite3VdbeCurrentAddr(v); |
| 111953 | 112024 | |
| 111954 | 112025 | /* Check if the index cursor is past the end of the range. */ |
| 111955 | | - op = aEndOp[(pRangeEnd || nEq) * (1 + bRev)]; |
| 111956 | | - testcase( op==OP_Noop ); |
| 111957 | | - testcase( op==OP_IdxGE ); |
| 111958 | | - testcase( op==OP_IdxLT ); |
| 111959 | | - if( op!=OP_Noop ){ |
| 112026 | + if( nConstraint ){ |
| 112027 | + op = aEndOp[bRev*2 + endEq]; |
| 111960 | 112028 | sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint); |
| 111961 | | - sqlite3VdbeChangeP5(v, endEq!=bRev ?1:0); |
| 111962 | | - } |
| 111963 | | - |
| 111964 | | - /* If there are inequality constraints, check that the value |
| 111965 | | - ** of the table column that the inequality contrains is not NULL. |
| 111966 | | - ** If it is, jump to the next iteration of the loop. |
| 111967 | | - */ |
| 111968 | | - r1 = sqlite3GetTempReg(pParse); |
| 111969 | | - testcase( pLoop->wsFlags & WHERE_BTM_LIMIT ); |
| 111970 | | - testcase( pLoop->wsFlags & WHERE_TOP_LIMIT ); |
| 111971 | | - if( (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0 |
| 111972 | | - && (j = pIdx->aiColumn[nEq])>=0 |
| 111973 | | - && pIdx->pTable->aCol[j].notNull==0 |
| 111974 | | - && (nEq || (pLoop->wsFlags & WHERE_BTM_LIMIT)==0) |
| 111975 | | - ){ |
| 111976 | | - sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, nEq, r1); |
| 111977 | | - VdbeComment((v, "%s", pIdx->pTable->aCol[j].zName)); |
| 111978 | | - sqlite3VdbeAddOp2(v, OP_IsNull, r1, addrCont); |
| 111979 | | - } |
| 111980 | | - sqlite3ReleaseTempReg(pParse, r1); |
| 112029 | + testcase( op==OP_IdxGT ); VdbeCoverageIf(v, op==OP_IdxGT ); |
| 112030 | + testcase( op==OP_IdxGE ); VdbeCoverageIf(v, op==OP_IdxGE ); |
| 112031 | + testcase( op==OP_IdxLT ); VdbeCoverageIf(v, op==OP_IdxLT ); |
| 112032 | + testcase( op==OP_IdxLE ); VdbeCoverageIf(v, op==OP_IdxLE ); |
| 112033 | + } |
| 111981 | 112034 | |
| 111982 | 112035 | /* Seek the table cursor, if required */ |
| 111983 | 112036 | disableTerm(pLevel, pRangeStart); |
| 111984 | 112037 | disableTerm(pLevel, pRangeEnd); |
| 111985 | 112038 | if( omitTable ){ |
| 111986 | 112039 | /* pIdx is a covering index. No need to access the main table. */ |
| 111987 | 112040 | }else if( HasRowid(pIdx->pTable) ){ |
| 111988 | | - iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse); |
| 112041 | + iRowidReg = ++pParse->nMem; |
| 111989 | 112042 | sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg); |
| 111990 | 112043 | sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg); |
| 111991 | 112044 | sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */ |
| 111992 | 112045 | }else{ |
| 111993 | 112046 | Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable); |
| | @@ -111995,11 +112048,11 @@ |
| 111995 | 112048 | for(j=0; j<pPk->nKeyCol; j++){ |
| 111996 | 112049 | k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]); |
| 111997 | 112050 | sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j); |
| 111998 | 112051 | } |
| 111999 | 112052 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont, |
| 112000 | | - iRowidReg, pPk->nKeyCol); |
| 112053 | + iRowidReg, pPk->nKeyCol); VdbeCoverage(v); |
| 112001 | 112054 | } |
| 112002 | 112055 | |
| 112003 | 112056 | /* Record the instruction used to terminate the loop. Disable |
| 112004 | 112057 | ** WHERE clause terms made redundant by the index range scan. |
| 112005 | 112058 | */ |
| | @@ -112009,10 +112062,12 @@ |
| 112009 | 112062 | pLevel->op = OP_Prev; |
| 112010 | 112063 | }else{ |
| 112011 | 112064 | pLevel->op = OP_Next; |
| 112012 | 112065 | } |
| 112013 | 112066 | pLevel->p1 = iIdxCur; |
| 112067 | + assert( (WHERE_UNQ_WANTED>>16)==1 ); |
| 112068 | + pLevel->p3 = (pLoop->wsFlags>>16)&1; |
| 112014 | 112069 | if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){ |
| 112015 | 112070 | pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP; |
| 112016 | 112071 | }else{ |
| 112017 | 112072 | assert( pLevel->p5==0 ); |
| 112018 | 112073 | } |
| | @@ -112177,10 +112232,11 @@ |
| 112177 | 112232 | int r; |
| 112178 | 112233 | r = sqlite3ExprCodeGetColumn(pParse, pTabItem->pTab, -1, iCur, |
| 112179 | 112234 | regRowid, 0); |
| 112180 | 112235 | sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset, |
| 112181 | 112236 | sqlite3VdbeCurrentAddr(v)+2, r, iSet); |
| 112237 | + VdbeCoverage(v); |
| 112182 | 112238 | } |
| 112183 | 112239 | sqlite3VdbeAddOp2(v, OP_Gosub, regReturn, iLoopBody); |
| 112184 | 112240 | |
| 112185 | 112241 | /* The pSubWInfo->untestedTerms flag means that this OR term |
| 112186 | 112242 | ** contained one or more AND term from a notReady table. The |
| | @@ -112245,10 +112301,12 @@ |
| 112245 | 112301 | pLevel->op = OP_Noop; |
| 112246 | 112302 | }else{ |
| 112247 | 112303 | pLevel->op = aStep[bRev]; |
| 112248 | 112304 | pLevel->p1 = iCur; |
| 112249 | 112305 | pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk); |
| 112306 | + VdbeCoverageIf(v, bRev==0); |
| 112307 | + VdbeCoverageIf(v, bRev!=0); |
| 112250 | 112308 | pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP; |
| 112251 | 112309 | } |
| 112252 | 112310 | } |
| 112253 | 112311 | |
| 112254 | 112312 | /* Insert code to test every subexpression that can be completely |
| | @@ -112326,11 +112384,10 @@ |
| 112326 | 112384 | assert( pTerm->pExpr ); |
| 112327 | 112385 | sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL); |
| 112328 | 112386 | pTerm->wtFlags |= TERM_CODED; |
| 112329 | 112387 | } |
| 112330 | 112388 | } |
| 112331 | | - sqlite3ReleaseTempReg(pParse, iReleaseReg); |
| 112332 | 112389 | |
| 112333 | 112390 | return pLevel->notReady; |
| 112334 | 112391 | } |
| 112335 | 112392 | |
| 112336 | 112393 | #if defined(WHERETRACE_ENABLED) && defined(SQLITE_ENABLE_TREE_EXPLAIN) |
| | @@ -112813,16 +112870,17 @@ |
| 112813 | 112870 | assert( |
| 112814 | 112871 | (pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN|WHERE_SKIPSCAN))!=0 |
| 112815 | 112872 | || nInMul==0 |
| 112816 | 112873 | ); |
| 112817 | 112874 | pNew->wsFlags |= WHERE_COLUMN_EQ; |
| 112818 | | - if( iCol<0 |
| 112819 | | - || (pProbe->onError!=OE_None && nInMul==0 |
| 112820 | | - && pNew->u.btree.nEq==pProbe->nKeyCol-1) |
| 112821 | | - ){ |
| 112875 | + if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1)){ |
| 112822 | 112876 | assert( (pNew->wsFlags & WHERE_COLUMN_IN)==0 || iCol<0 ); |
| 112823 | | - pNew->wsFlags |= WHERE_ONEROW; |
| 112877 | + if( iCol>=0 && pProbe->onError==OE_None ){ |
| 112878 | + pNew->wsFlags |= WHERE_UNQ_WANTED; |
| 112879 | + }else{ |
| 112880 | + pNew->wsFlags |= WHERE_ONEROW; |
| 112881 | + } |
| 112824 | 112882 | } |
| 112825 | 112883 | pNew->u.btree.nEq++; |
| 112826 | 112884 | pNew->nOut = nRowEst + nInMul; |
| 112827 | 112885 | }else if( pTerm->eOperator & (WO_ISNULL) ){ |
| 112828 | 112886 | pNew->wsFlags |= WHERE_COLUMN_NULL; |
| | @@ -113697,13 +113755,16 @@ |
| 113697 | 113755 | /* Mark off any other ORDER BY terms that reference pLoop */ |
| 113698 | 113756 | if( isOrderDistinct ){ |
| 113699 | 113757 | orderDistinctMask |= pLoop->maskSelf; |
| 113700 | 113758 | for(i=0; i<nOrderBy; i++){ |
| 113701 | 113759 | Expr *p; |
| 113760 | + Bitmask mTerm; |
| 113702 | 113761 | if( MASKBIT(i) & obSat ) continue; |
| 113703 | 113762 | p = pOrderBy->a[i].pExpr; |
| 113704 | | - if( (exprTableUsage(&pWInfo->sMaskSet, p)&~orderDistinctMask)==0 ){ |
| 113763 | + mTerm = exprTableUsage(&pWInfo->sMaskSet,p); |
| 113764 | + if( mTerm==0 && !sqlite3ExprIsConstant(p) ) continue; |
| 113765 | + if( (mTerm&~orderDistinctMask)==0 ){ |
| 113705 | 113766 | obSat |= MASKBIT(i); |
| 113706 | 113767 | } |
| 113707 | 113768 | } |
| 113708 | 113769 | } |
| 113709 | 113770 | } /* End the loop over all WhereLoops from outer-most down to inner-most */ |
| | @@ -114261,11 +114322,10 @@ |
| 114261 | 114322 | ** subexpression is separated by an AND operator. |
| 114262 | 114323 | */ |
| 114263 | 114324 | initMaskSet(pMaskSet); |
| 114264 | 114325 | whereClauseInit(&pWInfo->sWC, pWInfo); |
| 114265 | 114326 | whereSplit(&pWInfo->sWC, pWhere, TK_AND); |
| 114266 | | - sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */ |
| 114267 | 114327 | |
| 114268 | 114328 | /* Special case: a WHERE clause that is constant. Evaluate the |
| 114269 | 114329 | ** expression and either jump over all of the code or fall thru. |
| 114270 | 114330 | */ |
| 114271 | 114331 | for(ii=0; ii<sWLB.pWC->nTerm; ii++){ |
| | @@ -114323,26 +114383,10 @@ |
| 114323 | 114383 | exprAnalyzeAll(pTabList, &pWInfo->sWC); |
| 114324 | 114384 | if( db->mallocFailed ){ |
| 114325 | 114385 | goto whereBeginError; |
| 114326 | 114386 | } |
| 114327 | 114387 | |
| 114328 | | - /* If the ORDER BY (or GROUP BY) clause contains references to general |
| 114329 | | - ** expressions, then we won't be able to satisfy it using indices, so |
| 114330 | | - ** go ahead and disable it now. |
| 114331 | | - */ |
| 114332 | | - if( pOrderBy && (wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){ |
| 114333 | | - for(ii=0; ii<pOrderBy->nExpr; ii++){ |
| 114334 | | - Expr *pExpr = sqlite3ExprSkipCollate(pOrderBy->a[ii].pExpr); |
| 114335 | | - if( pExpr->op!=TK_COLUMN ){ |
| 114336 | | - pWInfo->pOrderBy = pOrderBy = 0; |
| 114337 | | - break; |
| 114338 | | - }else if( pExpr->iColumn<0 ){ |
| 114339 | | - break; |
| 114340 | | - } |
| 114341 | | - } |
| 114342 | | - } |
| 114343 | | - |
| 114344 | 114388 | if( wctrlFlags & WHERE_WANT_DISTINCT ){ |
| 114345 | 114389 | if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){ |
| 114346 | 114390 | /* The DISTINCT marking is pointless. Ignore it. */ |
| 114347 | 114391 | pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE; |
| 114348 | 114392 | }else if( pOrderBy==0 ){ |
| | @@ -114550,11 +114594,11 @@ |
| 114550 | 114594 | assert( iIndexCur>=0 ); |
| 114551 | 114595 | sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb); |
| 114552 | 114596 | sqlite3VdbeSetP4KeyInfo(pParse, pIx); |
| 114553 | 114597 | VdbeComment((v, "%s", pIx->zName)); |
| 114554 | 114598 | } |
| 114555 | | - sqlite3CodeVerifySchema(pParse, iDb); |
| 114599 | + if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb); |
| 114556 | 114600 | notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor); |
| 114557 | 114601 | } |
| 114558 | 114602 | pWInfo->iTop = sqlite3VdbeCurrentAddr(v); |
| 114559 | 114603 | if( db->mallocFailed ) goto whereBeginError; |
| 114560 | 114604 | |
| | @@ -114612,20 +114656,27 @@ |
| 114612 | 114656 | int addr; |
| 114613 | 114657 | pLevel = &pWInfo->a[i]; |
| 114614 | 114658 | pLoop = pLevel->pWLoop; |
| 114615 | 114659 | sqlite3VdbeResolveLabel(v, pLevel->addrCont); |
| 114616 | 114660 | if( pLevel->op!=OP_Noop ){ |
| 114617 | | - sqlite3VdbeAddOp2(v, pLevel->op, pLevel->p1, pLevel->p2); |
| 114661 | + sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3); |
| 114618 | 114662 | sqlite3VdbeChangeP5(v, pLevel->p5); |
| 114663 | + VdbeCoverage(v); |
| 114664 | + VdbeCoverageIf(v, pLevel->op==OP_Next); |
| 114665 | + VdbeCoverageIf(v, pLevel->op==OP_Prev); |
| 114666 | + VdbeCoverageIf(v, pLevel->op==OP_VNext); |
| 114619 | 114667 | } |
| 114620 | 114668 | if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){ |
| 114621 | 114669 | struct InLoop *pIn; |
| 114622 | 114670 | int j; |
| 114623 | 114671 | sqlite3VdbeResolveLabel(v, pLevel->addrNxt); |
| 114624 | 114672 | for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){ |
| 114625 | 114673 | sqlite3VdbeJumpHere(v, pIn->addrInTop+1); |
| 114626 | 114674 | sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop); |
| 114675 | + VdbeCoverage(v); |
| 114676 | + VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen); |
| 114677 | + VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen); |
| 114627 | 114678 | sqlite3VdbeJumpHere(v, pIn->addrInTop-1); |
| 114628 | 114679 | } |
| 114629 | 114680 | sqlite3DbFree(db, pLevel->u.in.aInLoop); |
| 114630 | 114681 | } |
| 114631 | 114682 | sqlite3VdbeResolveLabel(v, pLevel->addrBrk); |
| | @@ -114634,11 +114685,11 @@ |
| 114634 | 114685 | VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName)); |
| 114635 | 114686 | sqlite3VdbeJumpHere(v, pLevel->addrSkip); |
| 114636 | 114687 | sqlite3VdbeJumpHere(v, pLevel->addrSkip-2); |
| 114637 | 114688 | } |
| 114638 | 114689 | if( pLevel->iLeftJoin ){ |
| 114639 | | - addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); |
| 114690 | + addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v); |
| 114640 | 114691 | assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 |
| 114641 | 114692 | || (pLoop->wsFlags & WHERE_INDEXED)!=0 ); |
| 114642 | 114693 | if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 ){ |
| 114643 | 114694 | sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor); |
| 114644 | 114695 | } |
| | @@ -114661,15 +114712,41 @@ |
| 114661 | 114712 | */ |
| 114662 | 114713 | sqlite3VdbeResolveLabel(v, pWInfo->iBreak); |
| 114663 | 114714 | |
| 114664 | 114715 | assert( pWInfo->nLevel<=pTabList->nSrc ); |
| 114665 | 114716 | for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){ |
| 114717 | + int k, last; |
| 114718 | + VdbeOp *pOp; |
| 114666 | 114719 | Index *pIdx = 0; |
| 114667 | 114720 | struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom]; |
| 114668 | 114721 | Table *pTab = pTabItem->pTab; |
| 114669 | 114722 | assert( pTab!=0 ); |
| 114670 | 114723 | pLoop = pLevel->pWLoop; |
| 114724 | + |
| 114725 | + /* For a co-routine, change all OP_Column references to the table of |
| 114726 | + ** the co-routine into OP_SCopy of result contained in a register. |
| 114727 | + ** OP_Rowid becomes OP_Null. |
| 114728 | + */ |
| 114729 | + if( pTabItem->viaCoroutine ){ |
| 114730 | + last = sqlite3VdbeCurrentAddr(v); |
| 114731 | + k = pLevel->addrBody; |
| 114732 | + pOp = sqlite3VdbeGetOp(v, k); |
| 114733 | + for(; k<last; k++, pOp++){ |
| 114734 | + if( pOp->p1!=pLevel->iTabCur ) continue; |
| 114735 | + if( pOp->opcode==OP_Column ){ |
| 114736 | + pOp->opcode = OP_SCopy; |
| 114737 | + pOp->p1 = pOp->p2 + pTabItem->regResult; |
| 114738 | + pOp->p2 = pOp->p3; |
| 114739 | + pOp->p3 = 0; |
| 114740 | + }else if( pOp->opcode==OP_Rowid ){ |
| 114741 | + pOp->opcode = OP_Null; |
| 114742 | + pOp->p1 = 0; |
| 114743 | + pOp->p3 = 0; |
| 114744 | + } |
| 114745 | + } |
| 114746 | + continue; |
| 114747 | + } |
| 114671 | 114748 | |
| 114672 | 114749 | /* Close all of the cursors that were opened by sqlite3WhereBegin. |
| 114673 | 114750 | ** Except, do not close cursors that will be reused by the OR optimization |
| 114674 | 114751 | ** (WHERE_OMIT_OPEN_CLOSE). And do not close the OP_OpenWrite cursors |
| 114675 | 114752 | ** created for the ONEPASS optimization. |
| | @@ -114705,13 +114782,10 @@ |
| 114705 | 114782 | pIdx = pLoop->u.btree.pIndex; |
| 114706 | 114783 | }else if( pLoop->wsFlags & WHERE_MULTI_OR ){ |
| 114707 | 114784 | pIdx = pLevel->u.pCovidx; |
| 114708 | 114785 | } |
| 114709 | 114786 | if( pIdx && !db->mallocFailed ){ |
| 114710 | | - int k, last; |
| 114711 | | - VdbeOp *pOp; |
| 114712 | | - |
| 114713 | 114787 | last = sqlite3VdbeCurrentAddr(v); |
| 114714 | 114788 | k = pLevel->addrBody; |
| 114715 | 114789 | pOp = sqlite3VdbeGetOp(v, k); |
| 114716 | 114790 | for(; k<last; k++, pOp++){ |
| 114717 | 114791 | if( pOp->p1!=pLevel->iTabCur ) continue; |
| | @@ -117121,33 +117195,54 @@ |
| 117121 | 117195 | sqlite3ExplainFinish(pParse->pVdbe); |
| 117122 | 117196 | sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3); |
| 117123 | 117197 | } |
| 117124 | 117198 | break; |
| 117125 | 117199 | case 112: /* select ::= with selectnowith */ |
| 117126 | | -{ |
| 117127 | | - if( yymsp[0].minor.yy3 ){ |
| 117128 | | - yymsp[0].minor.yy3->pWith = yymsp[-1].minor.yy59; |
| 117200 | +{ |
| 117201 | + Select *p = yymsp[0].minor.yy3, *pNext, *pLoop; |
| 117202 | + if( p ){ |
| 117203 | + int cnt = 0, mxSelect; |
| 117204 | + p->pWith = yymsp[-1].minor.yy59; |
| 117205 | + if( p->pPrior ){ |
| 117206 | + pNext = 0; |
| 117207 | + for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){ |
| 117208 | + pLoop->pNext = pNext; |
| 117209 | + pLoop->selFlags |= SF_Compound; |
| 117210 | + } |
| 117211 | + mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT]; |
| 117212 | + if( mxSelect && cnt>mxSelect ){ |
| 117213 | + sqlite3ErrorMsg(pParse, "too many terms in compound SELECT"); |
| 117214 | + } |
| 117215 | + } |
| 117129 | 117216 | }else{ |
| 117130 | 117217 | sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59); |
| 117131 | 117218 | } |
| 117132 | | - yygotominor.yy3 = yymsp[0].minor.yy3; |
| 117219 | + yygotominor.yy3 = p; |
| 117133 | 117220 | } |
| 117134 | 117221 | break; |
| 117135 | 117222 | case 113: /* selectnowith ::= oneselect */ |
| 117136 | 117223 | case 119: /* oneselect ::= values */ yytestcase(yyruleno==119); |
| 117137 | 117224 | {yygotominor.yy3 = yymsp[0].minor.yy3;} |
| 117138 | 117225 | break; |
| 117139 | 117226 | case 114: /* selectnowith ::= selectnowith multiselect_op oneselect */ |
| 117140 | 117227 | { |
| 117141 | | - if( yymsp[0].minor.yy3 ){ |
| 117142 | | - yymsp[0].minor.yy3->op = (u8)yymsp[-1].minor.yy328; |
| 117143 | | - yymsp[0].minor.yy3->pPrior = yymsp[-2].minor.yy3; |
| 117228 | + Select *pRhs = yymsp[0].minor.yy3; |
| 117229 | + if( pRhs && pRhs->pPrior ){ |
| 117230 | + SrcList *pFrom; |
| 117231 | + Token x; |
| 117232 | + x.n = 0; |
| 117233 | + pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0); |
| 117234 | + pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0); |
| 117235 | + } |
| 117236 | + if( pRhs ){ |
| 117237 | + pRhs->op = (u8)yymsp[-1].minor.yy328; |
| 117238 | + pRhs->pPrior = yymsp[-2].minor.yy3; |
| 117144 | 117239 | if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1; |
| 117145 | 117240 | }else{ |
| 117146 | 117241 | sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3); |
| 117147 | 117242 | } |
| 117148 | | - yygotominor.yy3 = yymsp[0].minor.yy3; |
| 117243 | + yygotominor.yy3 = pRhs; |
| 117149 | 117244 | } |
| 117150 | 117245 | break; |
| 117151 | 117246 | case 116: /* multiselect_op ::= UNION ALL */ |
| 117152 | 117247 | {yygotominor.yy328 = TK_ALL;} |
| 117153 | 117248 | break; |
| | @@ -122711,10 +122806,25 @@ |
| 122711 | 122806 | case SQLITE_TESTCTRL_NEVER_CORRUPT: { |
| 122712 | 122807 | sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int); |
| 122713 | 122808 | break; |
| 122714 | 122809 | } |
| 122715 | 122810 | |
| 122811 | + |
| 122812 | + /* sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, xCallback, ptr); |
| 122813 | + ** |
| 122814 | + ** Set the VDBE coverage callback function to xCallback with context |
| 122815 | + ** pointer ptr. |
| 122816 | + */ |
| 122817 | + case SQLITE_TESTCTRL_VDBE_COVERAGE: { |
| 122818 | +#ifdef SQLITE_VDBE_COVERAGE |
| 122819 | + typedef void (*branch_callback)(void*,int,u8,u8); |
| 122820 | + sqlite3GlobalConfig.xVdbeBranch = va_arg(ap,branch_callback); |
| 122821 | + sqlite3GlobalConfig.pVdbeBranchArg = va_arg(ap,void*); |
| 122822 | +#endif |
| 122823 | + break; |
| 122824 | + } |
| 122825 | + |
| 122716 | 122826 | } |
| 122717 | 122827 | va_end(ap); |
| 122718 | 122828 | #endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 122719 | 122829 | return rc; |
| 122720 | 122830 | } |
| 122721 | 122831 | |