summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2022-09-03 21:32:49 +0200
committerGravatar Vincent Rischmann2022-09-03 21:53:18 +0200
commit34207955c63460166c8eaa5b2491d7aae1e7d2dd (patch)
tree4d85e8b978b8bad241404150acfb7fa89ceb444b
parentci: disable tests for Windows (diff)
downloadzig-sqlite-34207955c63460166c8eaa5b2491d7aae1e7d2dd.tar.gz
zig-sqlite-34207955c63460166c8eaa5b2491d7aae1e7d2dd.tar.xz
zig-sqlite-34207955c63460166c8eaa5b2491d7aae1e7d2dd.zip
update sqlite bundled source code to 3.39.2
-rw-r--r--c/sqlite3.c9292
-rw-r--r--c/sqlite3.h42
2 files changed, 5802 insertions, 3532 deletions
diff --git a/c/sqlite3.c b/c/sqlite3.c
index 0b227f0..b8f98c7 100644
--- a/c/sqlite3.c
+++ b/c/sqlite3.c
@@ -1,6 +1,6 @@
1/****************************************************************************** 1/******************************************************************************
2** This file is an amalgamation of many separate C source files from SQLite 2** This file is an amalgamation of many separate C source files from SQLite
3** version 3.38.2. By combining all the individual C code files into this 3** version 3.39.2. By combining all the individual C code files into this
4** single large file, the entire code can be compiled as a single translation 4** single large file, the entire code can be compiled as a single translation
5** unit. This allows many compilers to do optimizations that would not be 5** unit. This allows many compilers to do optimizations that would not be
6** possible if the files were compiled separately. Performance improvements 6** possible if the files were compiled separately. Performance improvements
@@ -452,9 +452,9 @@ extern "C" {
452** [sqlite3_libversion_number()], [sqlite3_sourceid()], 452** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453** [sqlite_version()] and [sqlite_source_id()]. 453** [sqlite_version()] and [sqlite_source_id()].
454*/ 454*/
455#define SQLITE_VERSION "3.38.2" 455#define SQLITE_VERSION "3.39.2"
456#define SQLITE_VERSION_NUMBER 3038002 456#define SQLITE_VERSION_NUMBER 3039002
457#define SQLITE_SOURCE_ID "2022-03-26 13:51:10 d33c709cc0af66bc5b6dc6216eba9f1f0b40960b9ae83694c986fbf4c1d6f08f" 457#define SQLITE_SOURCE_ID "2022-07-21 15:24:47 698edb77537b67c41adc68f9b892db56bcf9a55e00371a61420f3ddd668e6603"
458 458
459/* 459/*
460** CAPI3REF: Run-Time Library Version Numbers 460** CAPI3REF: Run-Time Library Version Numbers
@@ -5899,7 +5899,8 @@ SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*);
5899** object D and returns a pointer to that copy. ^The [sqlite3_value] returned 5899** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
5900** is a [protected sqlite3_value] object even if the input is not. 5900** is a [protected sqlite3_value] object even if the input is not.
5901** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a 5901** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
5902** memory allocation fails. 5902** memory allocation fails. ^If V is a [pointer value], then the result
5903** of sqlite3_value_dup(V) is a NULL value.
5903** 5904**
5904** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object 5905** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
5905** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer 5906** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer
@@ -6582,6 +6583,28 @@ SQLITE_API int sqlite3_get_autocommit(sqlite3*);
6582SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*); 6583SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
6583 6584
6584/* 6585/*
6586** CAPI3REF: Return The Schema Name For A Database Connection
6587** METHOD: sqlite3
6588**
6589** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
6590** for the N-th database on database connection D, or a NULL pointer of N is
6591** out of range. An N value of 0 means the main database file. An N of 1 is
6592** the "temp" schema. Larger values of N correspond to various ATTACH-ed
6593** databases.
6594**
6595** Space to hold the string that is returned by sqlite3_db_name() is managed
6596** by SQLite itself. The string might be deallocated by any operation that
6597** changes the schema, including [ATTACH] or [DETACH] or calls to
6598** [sqlite3_serialize()] or [sqlite3_deserialize()], even operations that
6599** occur on a different thread. Applications that need to
6600** remember the string long-term should make their own copy. Applications that
6601** are accessing the same database connection simultaneously on multiple
6602** threads should mutex-protect calls to this API and should make their own
6603** private copy of the result prior to releasing the mutex.
6604*/
6605SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N);
6606
6607/*
6585** CAPI3REF: Return The Filename For A Database Connection 6608** CAPI3REF: Return The Filename For A Database Connection
6586** METHOD: sqlite3 6609** METHOD: sqlite3
6587** 6610**
@@ -9860,8 +9883,8 @@ SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_
9860** of a [virtual table] implementation. The result of calling this 9883** of a [virtual table] implementation. The result of calling this
9861** interface from outside of xBestIndex() is undefined and probably harmful. 9884** interface from outside of xBestIndex() is undefined and probably harmful.
9862** 9885**
9863** ^The sqlite3_vtab_distinct() interface returns an integer that is 9886** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and
9864** either 0, 1, or 2. The integer returned by sqlite3_vtab_distinct() 9887** 3. The integer returned by sqlite3_vtab_distinct()
9865** gives the virtual table additional information about how the query 9888** gives the virtual table additional information about how the query
9866** planner wants the output to be ordered. As long as the virtual table 9889** planner wants the output to be ordered. As long as the virtual table
9867** can meet the ordering requirements of the query planner, it may set 9890** can meet the ordering requirements of the query planner, it may set
@@ -9893,6 +9916,13 @@ SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_
9893** that have the same value for all columns identified by "aOrderBy". 9916** that have the same value for all columns identified by "aOrderBy".
9894** ^However omitting the extra rows is optional. 9917** ^However omitting the extra rows is optional.
9895** This mode is used for a DISTINCT query. 9918** This mode is used for a DISTINCT query.
9919** <li value="3"><p>
9920** ^(If the sqlite3_vtab_distinct() interface returns 3, that means
9921** that the query planner needs only distinct rows but it does need the
9922** rows to be sorted.)^ ^The virtual table implementation is free to omit
9923** rows that are identical in all aOrderBy columns, if it wants to, but
9924** it is not required to omit any rows. This mode is used for queries
9925** that have both DISTINCT and ORDER BY clauses.
9896** </ol> 9926** </ol>
9897** 9927**
9898** ^For the purposes of comparing virtual table output values to see if the 9928** ^For the purposes of comparing virtual table output values to see if the
@@ -14357,8 +14387,19 @@ typedef INT16_TYPE LogEst;
14357/* 14387/*
14358** Round up a number to the next larger multiple of 8. This is used 14388** Round up a number to the next larger multiple of 8. This is used
14359** to force 8-byte alignment on 64-bit architectures. 14389** to force 8-byte alignment on 64-bit architectures.
14390**
14391** ROUND8() always does the rounding, for any argument.
14392**
14393** ROUND8P() assumes that the argument is already an integer number of
14394** pointers in size, and so it is a no-op on systems where the pointer
14395** size is 8.
14360*/ 14396*/
14361#define ROUND8(x) (((x)+7)&~7) 14397#define ROUND8(x) (((x)+7)&~7)
14398#if SQLITE_PTRSIZE==8
14399# define ROUND8P(x) (x)
14400#else
14401# define ROUND8P(x) (((x)+7)&~7)
14402#endif
14362 14403
14363/* 14404/*
14364** Round down to the nearest multiple of 8 14405** Round down to the nearest multiple of 8
@@ -14421,22 +14462,23 @@ typedef INT16_TYPE LogEst;
14421#endif 14462#endif
14422 14463
14423/* 14464/*
14424** SELECTTRACE_ENABLED will be either 1 or 0 depending on whether or not 14465** TREETRACE_ENABLED will be either 1 or 0 depending on whether or not
14425** the Select query generator tracing logic is turned on. 14466** the Abstract Syntax Tree tracing logic is turned on.
14426*/ 14467*/
14427#if !defined(SQLITE_AMALGAMATION) 14468#if !defined(SQLITE_AMALGAMATION)
14428SQLITE_PRIVATE u32 sqlite3SelectTrace; 14469SQLITE_PRIVATE u32 sqlite3TreeTrace;
14429#endif 14470#endif
14430#if defined(SQLITE_DEBUG) \ 14471#if defined(SQLITE_DEBUG) \
14431 && (defined(SQLITE_TEST) || defined(SQLITE_ENABLE_SELECTTRACE)) 14472 && (defined(SQLITE_TEST) || defined(SQLITE_ENABLE_SELECTTRACE) \
14432# define SELECTTRACE_ENABLED 1 14473 || defined(SQLITE_ENABLE_TREETRACE))
14474# define TREETRACE_ENABLED 1
14433# define SELECTTRACE(K,P,S,X) \ 14475# define SELECTTRACE(K,P,S,X) \
14434 if(sqlite3SelectTrace&(K)) \ 14476 if(sqlite3TreeTrace&(K)) \
14435 sqlite3DebugPrintf("%u/%d/%p: ",(S)->selId,(P)->addrExplain,(S)),\ 14477 sqlite3DebugPrintf("%u/%d/%p: ",(S)->selId,(P)->addrExplain,(S)),\
14436 sqlite3DebugPrintf X 14478 sqlite3DebugPrintf X
14437#else 14479#else
14438# define SELECTTRACE(K,P,S,X) 14480# define SELECTTRACE(K,P,S,X)
14439# define SELECTTRACE_ENABLED 0 14481# define TREETRACE_ENABLED 0
14440#endif 14482#endif
14441 14483
14442/* 14484/*
@@ -14521,7 +14563,7 @@ struct BusyHandler {
14521** pointer will work here as long as it is distinct from SQLITE_STATIC 14563** pointer will work here as long as it is distinct from SQLITE_STATIC
14522** and SQLITE_TRANSIENT. 14564** and SQLITE_TRANSIENT.
14523*/ 14565*/
14524#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3OomFault) 14566#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3OomClear)
14525 14567
14526/* 14568/*
14527** When SQLITE_OMIT_WSD is defined, it means that the target platform does 14569** When SQLITE_OMIT_WSD is defined, it means that the target platform does
@@ -14597,6 +14639,7 @@ typedef struct Lookaside Lookaside;
14597typedef struct LookasideSlot LookasideSlot; 14639typedef struct LookasideSlot LookasideSlot;
14598typedef struct Module Module; 14640typedef struct Module Module;
14599typedef struct NameContext NameContext; 14641typedef struct NameContext NameContext;
14642typedef struct OnOrUsing OnOrUsing;
14600typedef struct Parse Parse; 14643typedef struct Parse Parse;
14601typedef struct ParseCleanup ParseCleanup; 14644typedef struct ParseCleanup ParseCleanup;
14602typedef struct PreUpdate PreUpdate; 14645typedef struct PreUpdate PreUpdate;
@@ -14715,14 +14758,15 @@ typedef struct Pager Pager;
14715typedef struct PgHdr DbPage; 14758typedef struct PgHdr DbPage;
14716 14759
14717/* 14760/*
14718** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is 14761** Page number PAGER_SJ_PGNO is never used in an SQLite database (it is
14719** reserved for working around a windows/posix incompatibility). It is 14762** reserved for working around a windows/posix incompatibility). It is
14720** used in the journal to signify that the remainder of the journal file 14763** used in the journal to signify that the remainder of the journal file
14721** is devoted to storing a super-journal name - there are no more pages to 14764** is devoted to storing a super-journal name - there are no more pages to
14722** roll back. See comments for function writeSuperJournal() in pager.c 14765** roll back. See comments for function writeSuperJournal() in pager.c
14723** for details. 14766** for details.
14724*/ 14767*/
14725#define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1)) 14768#define PAGER_SJ_PGNO_COMPUTED(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
14769#define PAGER_SJ_PGNO(x) ((x)->lckPgno)
14726 14770
14727/* 14771/*
14728** Allowed values for the flags parameter to sqlite3PagerOpen(). 14772** Allowed values for the flags parameter to sqlite3PagerOpen().
@@ -15399,7 +15443,6 @@ struct VdbeOp {
15399#ifdef SQLITE_ENABLE_CURSOR_HINTS 15443#ifdef SQLITE_ENABLE_CURSOR_HINTS
15400 Expr *pExpr; /* Used when p4type is P4_EXPR */ 15444 Expr *pExpr; /* Used when p4type is P4_EXPR */
15401#endif 15445#endif
15402 int (*xAdvance)(BtCursor *, int);
15403 } p4; 15446 } p4;
15404#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS 15447#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
15405 char *zComment; /* Comment to improve readability */ 15448 char *zComment; /* Comment to improve readability */
@@ -15450,21 +15493,19 @@ typedef struct VdbeOpList VdbeOpList;
15450#define P4_COLLSEQ (-2) /* P4 is a pointer to a CollSeq structure */ 15493#define P4_COLLSEQ (-2) /* P4 is a pointer to a CollSeq structure */
15451#define P4_INT32 (-3) /* P4 is a 32-bit signed integer */ 15494#define P4_INT32 (-3) /* P4 is a 32-bit signed integer */
15452#define P4_SUBPROGRAM (-4) /* P4 is a pointer to a SubProgram structure */ 15495#define P4_SUBPROGRAM (-4) /* P4 is a pointer to a SubProgram structure */
15453#define P4_ADVANCE (-5) /* P4 is a pointer to BtreeNext() or BtreePrev() */ 15496#define P4_TABLE (-5) /* P4 is a pointer to a Table structure */
15454#define P4_TABLE (-6) /* P4 is a pointer to a Table structure */
15455/* Above do not own any resources. Must free those below */ 15497/* Above do not own any resources. Must free those below */
15456#define P4_FREE_IF_LE (-7) 15498#define P4_FREE_IF_LE (-6)
15457#define P4_DYNAMIC (-7) /* Pointer to memory from sqliteMalloc() */ 15499#define P4_DYNAMIC (-6) /* Pointer to memory from sqliteMalloc() */
15458#define P4_FUNCDEF (-8) /* P4 is a pointer to a FuncDef structure */ 15500#define P4_FUNCDEF (-7) /* P4 is a pointer to a FuncDef structure */
15459#define P4_KEYINFO (-9) /* P4 is a pointer to a KeyInfo structure */ 15501#define P4_KEYINFO (-8) /* P4 is a pointer to a KeyInfo structure */
15460#define P4_EXPR (-10) /* P4 is a pointer to an Expr tree */ 15502#define P4_EXPR (-9) /* P4 is a pointer to an Expr tree */
15461#define P4_MEM (-11) /* P4 is a pointer to a Mem* structure */ 15503#define P4_MEM (-10) /* P4 is a pointer to a Mem* structure */
15462#define P4_VTAB (-12) /* P4 is a pointer to an sqlite3_vtab structure */ 15504#define P4_VTAB (-11) /* P4 is a pointer to an sqlite3_vtab structure */
15463#define P4_REAL (-13) /* P4 is a 64-bit floating point value */ 15505#define P4_REAL (-12) /* P4 is a 64-bit floating point value */
15464#define P4_INT64 (-14) /* P4 is a 64-bit signed integer */ 15506#define P4_INT64 (-13) /* P4 is a 64-bit signed integer */
15465#define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */ 15507#define P4_INTARRAY (-14) /* P4 is a vector of 32-bit integers */
15466#define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */ 15508#define P4_FUNCCTX (-15) /* P4 is a pointer to an sqlite3_context object */
15467#define P4_DYNBLOB (-17) /* Pointer to memory from sqliteMalloc() */
15468 15509
15469/* Error message codes for OP_Halt */ 15510/* Error message codes for OP_Halt */
15470#define P5_ConstraintNotNull 1 15511#define P5_ConstraintNotNull 1
@@ -15509,42 +15550,42 @@ typedef struct VdbeOpList VdbeOpList;
15509#define OP_Savepoint 0 15550#define OP_Savepoint 0
15510#define OP_AutoCommit 1 15551#define OP_AutoCommit 1
15511#define OP_Transaction 2 15552#define OP_Transaction 2
15512#define OP_SorterNext 3 /* jump */ 15553#define OP_Checkpoint 3
15513#define OP_Prev 4 /* jump */ 15554#define OP_JournalMode 4
15514#define OP_Next 5 /* jump */ 15555#define OP_Vacuum 5
15515#define OP_Checkpoint 6 15556#define OP_VFilter 6 /* jump, synopsis: iplan=r[P3] zplan='P4' */
15516#define OP_JournalMode 7 15557#define OP_VUpdate 7 /* synopsis: data=r[P3@P2] */
15517#define OP_Vacuum 8 15558#define OP_Goto 8 /* jump */
15518#define OP_VFilter 9 /* jump, synopsis: iplan=r[P3] zplan='P4' */ 15559#define OP_Gosub 9 /* jump */
15519#define OP_VUpdate 10 /* synopsis: data=r[P3@P2] */ 15560#define OP_InitCoroutine 10 /* jump */
15520#define OP_Goto 11 /* jump */ 15561#define OP_Yield 11 /* jump */
15521#define OP_Gosub 12 /* jump */ 15562#define OP_MustBeInt 12 /* jump */
15522#define OP_InitCoroutine 13 /* jump */ 15563#define OP_Jump 13 /* jump */
15523#define OP_Yield 14 /* jump */ 15564#define OP_Once 14 /* jump */
15524#define OP_MustBeInt 15 /* jump */ 15565#define OP_If 15 /* jump */
15525#define OP_Jump 16 /* jump */ 15566#define OP_IfNot 16 /* jump */
15526#define OP_Once 17 /* jump */ 15567#define OP_IsNullOrType 17 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */
15527#define OP_If 18 /* jump */ 15568#define OP_IfNullRow 18 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
15528#define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */ 15569#define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
15529#define OP_IfNot 20 /* jump */ 15570#define OP_SeekLT 20 /* jump, synopsis: key=r[P3@P4] */
15530#define OP_IsNullOrType 21 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */ 15571#define OP_SeekLE 21 /* jump, synopsis: key=r[P3@P4] */
15531#define OP_IfNullRow 22 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */ 15572#define OP_SeekGE 22 /* jump, synopsis: key=r[P3@P4] */
15532#define OP_SeekLT 23 /* jump, synopsis: key=r[P3@P4] */ 15573#define OP_SeekGT 23 /* jump, synopsis: key=r[P3@P4] */
15533#define OP_SeekLE 24 /* jump, synopsis: key=r[P3@P4] */ 15574#define OP_IfNotOpen 24 /* jump, synopsis: if( !csr[P1] ) goto P2 */
15534#define OP_SeekGE 25 /* jump, synopsis: key=r[P3@P4] */ 15575#define OP_IfNoHope 25 /* jump, synopsis: key=r[P3@P4] */
15535#define OP_SeekGT 26 /* jump, synopsis: key=r[P3@P4] */ 15576#define OP_NoConflict 26 /* jump, synopsis: key=r[P3@P4] */
15536#define OP_IfNotOpen 27 /* jump, synopsis: if( !csr[P1] ) goto P2 */ 15577#define OP_NotFound 27 /* jump, synopsis: key=r[P3@P4] */
15537#define OP_IfNoHope 28 /* jump, synopsis: key=r[P3@P4] */ 15578#define OP_Found 28 /* jump, synopsis: key=r[P3@P4] */
15538#define OP_NoConflict 29 /* jump, synopsis: key=r[P3@P4] */ 15579#define OP_SeekRowid 29 /* jump, synopsis: intkey=r[P3] */
15539#define OP_NotFound 30 /* jump, synopsis: key=r[P3@P4] */ 15580#define OP_NotExists 30 /* jump, synopsis: intkey=r[P3] */
15540#define OP_Found 31 /* jump, synopsis: key=r[P3@P4] */ 15581#define OP_Last 31 /* jump */
15541#define OP_SeekRowid 32 /* jump, synopsis: intkey=r[P3] */ 15582#define OP_IfSmaller 32 /* jump */
15542#define OP_NotExists 33 /* jump, synopsis: intkey=r[P3] */ 15583#define OP_SorterSort 33 /* jump */
15543#define OP_Last 34 /* jump */ 15584#define OP_Sort 34 /* jump */
15544#define OP_IfSmaller 35 /* jump */ 15585#define OP_Rewind 35 /* jump */
15545#define OP_SorterSort 36 /* jump */ 15586#define OP_SorterNext 36 /* jump */
15546#define OP_Sort 37 /* jump */ 15587#define OP_Prev 37 /* jump */
15547#define OP_Rewind 38 /* jump */ 15588#define OP_Next 38 /* jump */
15548#define OP_IdxLE 39 /* jump, synopsis: key=r[P3@P4] */ 15589#define OP_IdxLE 39 /* jump, synopsis: key=r[P3@P4] */
15549#define OP_IdxGT 40 /* jump, synopsis: key=r[P3@P4] */ 15590#define OP_IdxGT 40 /* jump, synopsis: key=r[P3@P4] */
15550#define OP_IdxLT 41 /* jump, synopsis: key=r[P3@P4] */ 15591#define OP_IdxLT 41 /* jump, synopsis: key=r[P3@P4] */
@@ -15580,34 +15621,34 @@ typedef struct VdbeOpList VdbeOpList;
15580#define OP_Integer 71 /* synopsis: r[P2]=P1 */ 15621#define OP_Integer 71 /* synopsis: r[P2]=P1 */
15581#define OP_Int64 72 /* synopsis: r[P2]=P4 */ 15622#define OP_Int64 72 /* synopsis: r[P2]=P4 */
15582#define OP_String 73 /* synopsis: r[P2]='P4' (len=P1) */ 15623#define OP_String 73 /* synopsis: r[P2]='P4' (len=P1) */
15583#define OP_Null 74 /* synopsis: r[P2..P3]=NULL */ 15624#define OP_BeginSubrtn 74 /* synopsis: r[P2]=NULL */
15584#define OP_SoftNull 75 /* synopsis: r[P1]=NULL */ 15625#define OP_Null 75 /* synopsis: r[P2..P3]=NULL */
15585#define OP_Blob 76 /* synopsis: r[P2]=P4 (len=P1) */ 15626#define OP_SoftNull 76 /* synopsis: r[P1]=NULL */
15586#define OP_Variable 77 /* synopsis: r[P2]=parameter(P1,P4) */ 15627#define OP_Blob 77 /* synopsis: r[P2]=P4 (len=P1) */
15587#define OP_Move 78 /* synopsis: r[P2@P3]=r[P1@P3] */ 15628#define OP_Variable 78 /* synopsis: r[P2]=parameter(P1,P4) */
15588#define OP_Copy 79 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ 15629#define OP_Move 79 /* synopsis: r[P2@P3]=r[P1@P3] */
15589#define OP_SCopy 80 /* synopsis: r[P2]=r[P1] */ 15630#define OP_Copy 80 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
15590#define OP_IntCopy 81 /* synopsis: r[P2]=r[P1] */ 15631#define OP_SCopy 81 /* synopsis: r[P2]=r[P1] */
15591#define OP_FkCheck 82 15632#define OP_IntCopy 82 /* synopsis: r[P2]=r[P1] */
15592#define OP_ResultRow 83 /* synopsis: output=r[P1@P2] */ 15633#define OP_FkCheck 83
15593#define OP_CollSeq 84 15634#define OP_ResultRow 84 /* synopsis: output=r[P1@P2] */
15594#define OP_AddImm 85 /* synopsis: r[P1]=r[P1]+P2 */ 15635#define OP_CollSeq 85
15595#define OP_RealAffinity 86 15636#define OP_AddImm 86 /* synopsis: r[P1]=r[P1]+P2 */
15596#define OP_Cast 87 /* synopsis: affinity(r[P1]) */ 15637#define OP_RealAffinity 87
15597#define OP_Permutation 88 15638#define OP_Cast 88 /* synopsis: affinity(r[P1]) */
15598#define OP_Compare 89 /* synopsis: r[P1@P3] <-> r[P2@P3] */ 15639#define OP_Permutation 89
15599#define OP_IsTrue 90 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */ 15640#define OP_Compare 90 /* synopsis: r[P1@P3] <-> r[P2@P3] */
15600#define OP_ZeroOrNull 91 /* synopsis: r[P2] = 0 OR NULL */ 15641#define OP_IsTrue 91 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
15601#define OP_Offset 92 /* synopsis: r[P3] = sqlite_offset(P1) */ 15642#define OP_ZeroOrNull 92 /* synopsis: r[P2] = 0 OR NULL */
15602#define OP_Column 93 /* synopsis: r[P3]=PX */ 15643#define OP_Offset 93 /* synopsis: r[P3] = sqlite_offset(P1) */
15603#define OP_TypeCheck 94 /* synopsis: typecheck(r[P1@P2]) */ 15644#define OP_Column 94 /* synopsis: r[P3]=PX cursor P1 column P2 */
15604#define OP_Affinity 95 /* synopsis: affinity(r[P1@P2]) */ 15645#define OP_TypeCheck 95 /* synopsis: typecheck(r[P1@P2]) */
15605#define OP_MakeRecord 96 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ 15646#define OP_Affinity 96 /* synopsis: affinity(r[P1@P2]) */
15606#define OP_Count 97 /* synopsis: r[P2]=count() */ 15647#define OP_MakeRecord 97 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
15607#define OP_ReadCookie 98 15648#define OP_Count 98 /* synopsis: r[P2]=count() */
15608#define OP_SetCookie 99 15649#define OP_ReadCookie 99
15609#define OP_ReopenIdx 100 /* synopsis: root=P2 iDb=P3 */ 15650#define OP_SetCookie 100
15610#define OP_OpenRead 101 /* synopsis: root=P2 iDb=P3 */ 15651#define OP_ReopenIdx 101 /* synopsis: root=P2 iDb=P3 */
15611#define OP_BitAnd 102 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */ 15652#define OP_BitAnd 102 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
15612#define OP_BitOr 103 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */ 15653#define OP_BitOr 103 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
15613#define OP_ShiftLeft 104 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */ 15654#define OP_ShiftLeft 104 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
@@ -15618,79 +15659,81 @@ typedef struct VdbeOpList VdbeOpList;
15618#define OP_Divide 109 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */ 15659#define OP_Divide 109 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
15619#define OP_Remainder 110 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */ 15660#define OP_Remainder 110 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
15620#define OP_Concat 111 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */ 15661#define OP_Concat 111 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
15621#define OP_OpenWrite 112 /* synopsis: root=P2 iDb=P3 */ 15662#define OP_OpenRead 112 /* synopsis: root=P2 iDb=P3 */
15622#define OP_OpenDup 113 15663#define OP_OpenWrite 113 /* synopsis: root=P2 iDb=P3 */
15623#define OP_BitNot 114 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */ 15664#define OP_BitNot 114 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
15624#define OP_OpenAutoindex 115 /* synopsis: nColumn=P2 */ 15665#define OP_OpenDup 115
15625#define OP_OpenEphemeral 116 /* synopsis: nColumn=P2 */ 15666#define OP_OpenAutoindex 116 /* synopsis: nColumn=P2 */
15626#define OP_String8 117 /* same as TK_STRING, synopsis: r[P2]='P4' */ 15667#define OP_String8 117 /* same as TK_STRING, synopsis: r[P2]='P4' */
15627#define OP_SorterOpen 118 15668#define OP_OpenEphemeral 118 /* synopsis: nColumn=P2 */
15628#define OP_SequenceTest 119 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ 15669#define OP_SorterOpen 119
15629#define OP_OpenPseudo 120 /* synopsis: P3 columns in r[P2] */ 15670#define OP_SequenceTest 120 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
15630#define OP_Close 121 15671#define OP_OpenPseudo 121 /* synopsis: P3 columns in r[P2] */
15631#define OP_ColumnsUsed 122 15672#define OP_Close 122
15632#define OP_SeekScan 123 /* synopsis: Scan-ahead up to P1 rows */ 15673#define OP_ColumnsUsed 123
15633#define OP_SeekHit 124 /* synopsis: set P2<=seekHit<=P3 */ 15674#define OP_SeekScan 124 /* synopsis: Scan-ahead up to P1 rows */
15634#define OP_Sequence 125 /* synopsis: r[P2]=cursor[P1].ctr++ */ 15675#define OP_SeekHit 125 /* synopsis: set P2<=seekHit<=P3 */
15635#define OP_NewRowid 126 /* synopsis: r[P2]=rowid */ 15676#define OP_Sequence 126 /* synopsis: r[P2]=cursor[P1].ctr++ */
15636#define OP_Insert 127 /* synopsis: intkey=r[P3] data=r[P2] */ 15677#define OP_NewRowid 127 /* synopsis: r[P2]=rowid */
15637#define OP_RowCell 128 15678#define OP_Insert 128 /* synopsis: intkey=r[P3] data=r[P2] */
15638#define OP_Delete 129 15679#define OP_RowCell 129
15639#define OP_ResetCount 130 15680#define OP_Delete 130
15640#define OP_SorterCompare 131 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ 15681#define OP_ResetCount 131
15641#define OP_SorterData 132 /* synopsis: r[P2]=data */ 15682#define OP_SorterCompare 132 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
15642#define OP_RowData 133 /* synopsis: r[P2]=data */ 15683#define OP_SorterData 133 /* synopsis: r[P2]=data */
15643#define OP_Rowid 134 /* synopsis: r[P2]=rowid */ 15684#define OP_RowData 134 /* synopsis: r[P2]=data */
15644#define OP_NullRow 135 15685#define OP_Rowid 135 /* synopsis: r[P2]=PX rowid of P1 */
15645#define OP_SeekEnd 136 15686#define OP_NullRow 136
15646#define OP_IdxInsert 137 /* synopsis: key=r[P2] */ 15687#define OP_SeekEnd 137
15647#define OP_SorterInsert 138 /* synopsis: key=r[P2] */ 15688#define OP_IdxInsert 138 /* synopsis: key=r[P2] */
15648#define OP_IdxDelete 139 /* synopsis: key=r[P2@P3] */ 15689#define OP_SorterInsert 139 /* synopsis: key=r[P2] */
15649#define OP_DeferredSeek 140 /* synopsis: Move P3 to P1.rowid if needed */ 15690#define OP_IdxDelete 140 /* synopsis: key=r[P2@P3] */
15650#define OP_IdxRowid 141 /* synopsis: r[P2]=rowid */ 15691#define OP_DeferredSeek 141 /* synopsis: Move P3 to P1.rowid if needed */
15651#define OP_FinishSeek 142 15692#define OP_IdxRowid 142 /* synopsis: r[P2]=rowid */
15652#define OP_Destroy 143 15693#define OP_FinishSeek 143
15653#define OP_Clear 144 15694#define OP_Destroy 144
15654#define OP_ResetSorter 145 15695#define OP_Clear 145
15655#define OP_CreateBtree 146 /* synopsis: r[P2]=root iDb=P1 flags=P3 */ 15696#define OP_ResetSorter 146
15656#define OP_SqlExec 147 15697#define OP_CreateBtree 147 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
15657#define OP_ParseSchema 148 15698#define OP_SqlExec 148
15658#define OP_LoadAnalysis 149 15699#define OP_ParseSchema 149
15659#define OP_DropTable 150 15700#define OP_LoadAnalysis 150
15660#define OP_DropIndex 151 15701#define OP_DropTable 151
15661#define OP_DropTrigger 152 15702#define OP_DropIndex 152
15662#define OP_Real 153 /* same as TK_FLOAT, synopsis: r[P2]=P4 */ 15703#define OP_Real 153 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
15663#define OP_IntegrityCk 154 15704#define OP_DropTrigger 154
15664#define OP_RowSetAdd 155 /* synopsis: rowset(P1)=r[P2] */ 15705#define OP_IntegrityCk 155
15665#define OP_Param 156 15706#define OP_RowSetAdd 156 /* synopsis: rowset(P1)=r[P2] */
15666#define OP_FkCounter 157 /* synopsis: fkctr[P1]+=P2 */ 15707#define OP_Param 157
15667#define OP_MemMax 158 /* synopsis: r[P1]=max(r[P1],r[P2]) */ 15708#define OP_FkCounter 158 /* synopsis: fkctr[P1]+=P2 */
15668#define OP_OffsetLimit 159 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ 15709#define OP_MemMax 159 /* synopsis: r[P1]=max(r[P1],r[P2]) */
15669#define OP_AggInverse 160 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */ 15710#define OP_OffsetLimit 160 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
15670#define OP_AggStep 161 /* synopsis: accum=r[P3] step(r[P2@P5]) */ 15711#define OP_AggInverse 161 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */
15671#define OP_AggStep1 162 /* synopsis: accum=r[P3] step(r[P2@P5]) */ 15712#define OP_AggStep 162 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15672#define OP_AggValue 163 /* synopsis: r[P3]=value N=P2 */ 15713#define OP_AggStep1 163 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15673#define OP_AggFinal 164 /* synopsis: accum=r[P1] N=P2 */ 15714#define OP_AggValue 164 /* synopsis: r[P3]=value N=P2 */
15674#define OP_Expire 165 15715#define OP_AggFinal 165 /* synopsis: accum=r[P1] N=P2 */
15675#define OP_CursorLock 166 15716#define OP_Expire 166
15676#define OP_CursorUnlock 167 15717#define OP_CursorLock 167
15677#define OP_TableLock 168 /* synopsis: iDb=P1 root=P2 write=P3 */ 15718#define OP_CursorUnlock 168
15678#define OP_VBegin 169 15719#define OP_TableLock 169 /* synopsis: iDb=P1 root=P2 write=P3 */
15679#define OP_VCreate 170 15720#define OP_VBegin 170
15680#define OP_VDestroy 171 15721#define OP_VCreate 171
15681#define OP_VOpen 172 15722#define OP_VDestroy 172
15682#define OP_VInitIn 173 /* synopsis: r[P2]=ValueList(P1,P3) */ 15723#define OP_VOpen 173
15683#define OP_VColumn 174 /* synopsis: r[P3]=vcolumn(P2) */ 15724#define OP_VInitIn 174 /* synopsis: r[P2]=ValueList(P1,P3) */
15684#define OP_VRename 175 15725#define OP_VColumn 175 /* synopsis: r[P3]=vcolumn(P2) */
15685#define OP_Pagecount 176 15726#define OP_VRename 176
15686#define OP_MaxPgcnt 177 15727#define OP_Pagecount 177
15687#define OP_FilterAdd 178 /* synopsis: filter(P1) += key(P3@P4) */ 15728#define OP_MaxPgcnt 178
15688#define OP_Trace 179 15729#define OP_ClrSubtype 179 /* synopsis: r[P1].subtype = 0 */
15689#define OP_CursorHint 180 15730#define OP_FilterAdd 180 /* synopsis: filter(P1) += key(P3@P4) */
15690#define OP_ReleaseReg 181 /* synopsis: release r[P1@P2] mask P3 */ 15731#define OP_Trace 181
15691#define OP_Noop 182 15732#define OP_CursorHint 182
15692#define OP_Explain 183 15733#define OP_ReleaseReg 183 /* synopsis: release r[P1@P2] mask P3 */
15693#define OP_Abortable 184 15734#define OP_Noop 184
15735#define OP_Explain 185
15736#define OP_Abortable 186
15694 15737
15695/* Properties such as "out2" or "jump" that are specified in 15738/* Properties such as "out2" or "jump" that are specified in
15696** comments following the "case" for each opcode in the vdbe.c 15739** comments following the "case" for each opcode in the vdbe.c
@@ -15703,30 +15746,30 @@ typedef struct VdbeOpList VdbeOpList;
15703#define OPFLG_OUT2 0x10 /* out2: P2 is an output */ 15746#define OPFLG_OUT2 0x10 /* out2: P2 is an output */
15704#define OPFLG_OUT3 0x20 /* out3: P3 is an output */ 15747#define OPFLG_OUT3 0x20 /* out3: P3 is an output */
15705#define OPFLG_INITIALIZER {\ 15748#define OPFLG_INITIALIZER {\
15706/* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x10,\ 15749/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\
15707/* 8 */ 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03,\ 15750/* 8 */ 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0x03,\
15708/* 16 */ 0x01, 0x01, 0x03, 0x12, 0x03, 0x03, 0x01, 0x09,\ 15751/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x09, 0x09, 0x09, 0x09,\
15709/* 24 */ 0x09, 0x09, 0x09, 0x01, 0x09, 0x09, 0x09, 0x09,\ 15752/* 24 */ 0x01, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x01,\
15710/* 32 */ 0x09, 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\ 15753/* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
15711/* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x23, 0x0b, 0x01,\ 15754/* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x23, 0x0b, 0x01,\
15712/* 48 */ 0x01, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\ 15755/* 48 */ 0x01, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15713/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x01, 0x01, 0x01,\ 15756/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x01, 0x01, 0x01,\
15714/* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\ 15757/* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\
15715/* 72 */ 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00,\ 15758/* 72 */ 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10, 0x00,\
15716/* 80 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02,\ 15759/* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02,\
15717/* 88 */ 0x00, 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00, 0x00,\ 15760/* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00,\
15718/* 96 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x26, 0x26,\ 15761/* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x26, 0x26,\
15719/* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\ 15762/* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
15720/* 112 */ 0x00, 0x00, 0x12, 0x00, 0x00, 0x10, 0x00, 0x00,\ 15763/* 112 */ 0x00, 0x00, 0x12, 0x00, 0x00, 0x10, 0x00, 0x00,\
15721/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\ 15764/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
15722/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\ 15765/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
15723/* 136 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00, 0x10,\ 15766/* 136 */ 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00,\
15724/* 144 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\ 15767/* 144 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
15725/* 152 */ 0x00, 0x10, 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a,\ 15768/* 152 */ 0x00, 0x10, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
15726/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ 15769/* 160 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15727/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,\ 15770/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\
15728/* 176 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ 15771/* 176 */ 0x00, 0x10, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00,\
15729/* 184 */ 0x00,} 15772/* 184 */ 0x00, 0x00, 0x00,}
15730 15773
15731/* The resolve3P2Values() routine is able to run faster if it knows 15774/* The resolve3P2Values() routine is able to run faster if it knows
15732** the value of the largest JUMP opcode. The smaller the maximum 15775** the value of the largest JUMP opcode. The smaller the maximum
@@ -15772,8 +15815,10 @@ SQLITE_PRIVATE void sqlite3VdbeVerifyNoResultRow(Vdbe *p);
15772#endif 15815#endif
15773#if defined(SQLITE_DEBUG) 15816#if defined(SQLITE_DEBUG)
15774SQLITE_PRIVATE void sqlite3VdbeVerifyAbortable(Vdbe *p, int); 15817SQLITE_PRIVATE void sqlite3VdbeVerifyAbortable(Vdbe *p, int);
15818SQLITE_PRIVATE void sqlite3VdbeNoJumpsOutsideSubrtn(Vdbe*,int,int,int);
15775#else 15819#else
15776# define sqlite3VdbeVerifyAbortable(A,B) 15820# define sqlite3VdbeVerifyAbortable(A,B)
15821# define sqlite3VdbeNoJumpsOutsideSubrtn(A,B,C,D)
15777#endif 15822#endif
15778SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno); 15823SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno);
15779#ifndef SQLITE_OMIT_EXPLAIN 15824#ifndef SQLITE_OMIT_EXPLAIN
@@ -15818,7 +15863,6 @@ SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Parse*);
15818SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*); 15863SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
15819SQLITE_PRIVATE void sqlite3VdbeReusable(Vdbe*); 15864SQLITE_PRIVATE void sqlite3VdbeReusable(Vdbe*);
15820SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*); 15865SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*);
15821SQLITE_PRIVATE void sqlite3VdbeClearObject(sqlite3*,Vdbe*);
15822SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,Parse*); 15866SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,Parse*);
15823SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*); 15867SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*);
15824SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int); 15868SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int);
@@ -16267,6 +16311,13 @@ SQLITE_PRIVATE int sqlite3PCacheIsDirty(PCache *pCache);
16267# define SQLITE_MAX_PATHLEN FILENAME_MAX 16311# define SQLITE_MAX_PATHLEN FILENAME_MAX
16268#endif 16312#endif
16269 16313
16314/* Maximum number of symlinks that will be resolved while trying to
16315** expand a filename in xFullPathname() in the VFS.
16316*/
16317#ifndef SQLITE_MAX_SYMLINK
16318# define SQLITE_MAX_SYMLINK 200
16319#endif
16320
16270/* 16321/*
16271** The default size of a disk sector 16322** The default size of a disk sector
16272*/ 16323*/
@@ -17033,6 +17084,9 @@ struct sqlite3 {
17033#define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */ 17084#define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */
17034#define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */ 17085#define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */
17035#define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */ 17086#define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
17087#define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
17088#define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */
17089 /* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
17036#define SQLITE_AllOpts 0xffffffff /* All optimizations */ 17090#define SQLITE_AllOpts 0xffffffff /* All optimizations */
17037 17091
17038/* 17092/*
@@ -17135,7 +17189,7 @@ struct FuncDestructor {
17135#define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a 17189#define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
17136 ** single query - might change over time */ 17190 ** single query - might change over time */
17137#define SQLITE_FUNC_TEST 0x4000 /* Built-in testing functions */ 17191#define SQLITE_FUNC_TEST 0x4000 /* Built-in testing functions */
17138#define SQLITE_FUNC_OFFSET 0x8000 /* Built-in sqlite_offset() function */ 17192/* 0x8000 -- available for reuse */
17139#define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */ 17193#define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */
17140#define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */ 17194#define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
17141#define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */ 17195#define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */
@@ -17152,6 +17206,7 @@ struct FuncDestructor {
17152#define INLINEFUNC_expr_compare 3 17206#define INLINEFUNC_expr_compare 3
17153#define INLINEFUNC_affinity 4 17207#define INLINEFUNC_affinity 4
17154#define INLINEFUNC_iif 5 17208#define INLINEFUNC_iif 5
17209#define INLINEFUNC_sqlite_offset 6
17155#define INLINEFUNC_unlikely 99 /* Default case */ 17210#define INLINEFUNC_unlikely 99 /* Default case */
17156 17211
17157/* 17212/*
@@ -17378,6 +17433,7 @@ struct Column {
17378#define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */ 17433#define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
17379#define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */ 17434#define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
17380#define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */ 17435#define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */
17436#define COLFLAG_NOEXPAND 0x0400 /* Omit this column when expanding "*" */
17381#define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */ 17437#define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
17382#define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */ 17438#define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
17383 17439
@@ -17784,6 +17840,11 @@ struct KeyInfo {
17784struct UnpackedRecord { 17840struct UnpackedRecord {
17785 KeyInfo *pKeyInfo; /* Collation and sort-order information */ 17841 KeyInfo *pKeyInfo; /* Collation and sort-order information */
17786 Mem *aMem; /* Values */ 17842 Mem *aMem; /* Values */
17843 union {
17844 char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */
17845 i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */
17846 } u;
17847 int n; /* Cache of aMem[0].n used by vdbeRecordCompareString() */
17787 u16 nField; /* Number of entries in apMem[] */ 17848 u16 nField; /* Number of entries in apMem[] */
17788 i8 default_rc; /* Comparison result if keys are equal */ 17849 i8 default_rc; /* Comparison result if keys are equal */
17789 u8 errCode; /* Error detected by xRecordCompare (CORRUPT or NOMEM) */ 17850 u8 errCode; /* Error detected by xRecordCompare (CORRUPT or NOMEM) */
@@ -18092,7 +18153,7 @@ struct Expr {
18092 ** TK_SELECT_COLUMN: column of the result vector */ 18153 ** TK_SELECT_COLUMN: column of the result vector */
18093 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ 18154 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
18094 union { 18155 union {
18095 int iRightJoinTable; /* If EP_FromJoin, the right table of the join */ 18156 int iJoin; /* If EP_OuterON or EP_InnerON, the right table */
18096 int iOfst; /* else: start of token from start of statement */ 18157 int iOfst; /* else: start of token from start of statement */
18097 } w; 18158 } w;
18098 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ 18159 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
@@ -18113,29 +18174,29 @@ struct Expr {
18113** EP_Agg == NC_HasAgg == SF_HasAgg 18174** EP_Agg == NC_HasAgg == SF_HasAgg
18114** EP_Win == NC_HasWin 18175** EP_Win == NC_HasWin
18115*/ 18176*/
18116#define EP_FromJoin 0x000001 /* Originates in ON/USING clause of outer join */ 18177#define EP_OuterON 0x000001 /* Originates in ON/USING clause of outer join */
18117#define EP_Distinct 0x000002 /* Aggregate function with DISTINCT keyword */ 18178#define EP_InnerON 0x000002 /* Originates in ON/USING of an inner join */
18118#define EP_HasFunc 0x000004 /* Contains one or more functions of any kind */ 18179#define EP_Distinct 0x000004 /* Aggregate function with DISTINCT keyword */
18119#define EP_FixedCol 0x000008 /* TK_Column with a known fixed value */ 18180#define EP_HasFunc 0x000008 /* Contains one or more functions of any kind */
18120#define EP_Agg 0x000010 /* Contains one or more aggregate functions */ 18181#define EP_Agg 0x000010 /* Contains one or more aggregate functions */
18121#define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */ 18182#define EP_FixedCol 0x000020 /* TK_Column with a known fixed value */
18122#define EP_DblQuoted 0x000040 /* token.z was originally in "..." */ 18183#define EP_VarSelect 0x000040 /* pSelect is correlated, not constant */
18123#define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */ 18184#define EP_DblQuoted 0x000080 /* token.z was originally in "..." */
18124#define EP_Collate 0x000100 /* Tree contains a TK_COLLATE operator */ 18185#define EP_InfixFunc 0x000100 /* True for an infix function: LIKE, GLOB, etc */
18125#define EP_Commuted 0x000200 /* Comparison operator has been commuted */ 18186#define EP_Collate 0x000200 /* Tree contains a TK_COLLATE operator */
18126#define EP_IntValue 0x000400 /* Integer value contained in u.iValue */ 18187#define EP_Commuted 0x000400 /* Comparison operator has been commuted */
18127#define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */ 18188#define EP_IntValue 0x000800 /* Integer value contained in u.iValue */
18128#define EP_Skip 0x001000 /* Operator does not contribute to affinity */ 18189#define EP_xIsSelect 0x001000 /* x.pSelect is valid (otherwise x.pList is) */
18129#define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */ 18190#define EP_Skip 0x002000 /* Operator does not contribute to affinity */
18130#define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */ 18191#define EP_Reduced 0x004000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
18131#define EP_Win 0x008000 /* Contains window functions */ 18192#define EP_Win 0x008000 /* Contains window functions */
18132#define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */ 18193#define EP_TokenOnly 0x010000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
18133#define EP_IfNullRow 0x020000 /* The TK_IF_NULL_ROW opcode */ 18194#define EP_MemToken 0x020000 /* Need to sqlite3DbFree() Expr.zToken */
18134#define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */ 18195#define EP_IfNullRow 0x040000 /* The TK_IF_NULL_ROW opcode */
18135#define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */ 18196#define EP_Unlikely 0x080000 /* unlikely() or likelihood() function */
18136#define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */ 18197#define EP_ConstFunc 0x100000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
18137#define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */ 18198#define EP_CanBeNull 0x200000 /* Can be null despite NOT NULL constraint */
18138 /* 0x400000 // Available */ 18199#define EP_Subquery 0x400000 /* Tree contains a TK_SELECT operator */
18139#define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */ 18200#define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
18140#define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */ 18201#define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
18141#define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */ 18202#define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
@@ -18158,8 +18219,8 @@ struct Expr {
18158#define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P)) 18219#define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P))
18159#define ExprSetProperty(E,P) (E)->flags|=(P) 18220#define ExprSetProperty(E,P) (E)->flags|=(P)
18160#define ExprClearProperty(E,P) (E)->flags&=~(P) 18221#define ExprClearProperty(E,P) (E)->flags&=~(P)
18161#define ExprAlwaysTrue(E) (((E)->flags&(EP_FromJoin|EP_IsTrue))==EP_IsTrue) 18222#define ExprAlwaysTrue(E) (((E)->flags&(EP_OuterON|EP_IsTrue))==EP_IsTrue)
18162#define ExprAlwaysFalse(E) (((E)->flags&(EP_FromJoin|EP_IsFalse))==EP_IsFalse) 18223#define ExprAlwaysFalse(E) (((E)->flags&(EP_OuterON|EP_IsFalse))==EP_IsFalse)
18163 18224
18164/* Macros used to ensure that the correct members of unions are accessed 18225/* Macros used to ensure that the correct members of unions are accessed
18165** in Expr. 18226** in Expr.
@@ -18246,12 +18307,18 @@ struct ExprList {
18246 struct ExprList_item { /* For each expression in the list */ 18307 struct ExprList_item { /* For each expression in the list */
18247 Expr *pExpr; /* The parse tree for this expression */ 18308 Expr *pExpr; /* The parse tree for this expression */
18248 char *zEName; /* Token associated with this expression */ 18309 char *zEName; /* Token associated with this expression */
18249 u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */ 18310 struct {
18250 unsigned eEName :2; /* Meaning of zEName */ 18311 u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18251 unsigned done :1; /* A flag to indicate when processing is finished */ 18312 unsigned eEName :2; /* Meaning of zEName */
18252 unsigned reusable :1; /* Constant expression is reusable */ 18313 unsigned done :1; /* Indicates when processing is finished */
18253 unsigned bSorterRef :1; /* Defer evaluation until after sorting */ 18314 unsigned reusable :1; /* Constant expression is reusable */
18254 unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */ 18315 unsigned bSorterRef :1; /* Defer evaluation until after sorting */
18316 unsigned bNulls :1; /* True if explicit "NULLS FIRST/LAST" */
18317 unsigned bUsed :1; /* This column used in a SF_NestedFrom subquery */
18318 unsigned bUsingTerm:1; /* Term from the USING clause of a NestedFrom */
18319 unsigned bNoExpand: 1; /* Term is an auxiliary in NestedFrom and should
18320 ** not be expanded by "*" in parent queries */
18321 } fg;
18255 union { 18322 union {
18256 struct { /* Used by any ExprList other than Parse.pConsExpr */ 18323 struct { /* Used by any ExprList other than Parse.pConsExpr */
18257 u16 iOrderByCol; /* For ORDER BY, column number in result set */ 18324 u16 iOrderByCol; /* For ORDER BY, column number in result set */
@@ -18286,14 +18353,26 @@ struct ExprList {
18286** If "a" is the k-th column of table "t", then IdList.a[0].idx==k. 18353** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
18287*/ 18354*/
18288struct IdList { 18355struct IdList {
18356 int nId; /* Number of identifiers on the list */
18357 u8 eU4; /* Which element of a.u4 is valid */
18289 struct IdList_item { 18358 struct IdList_item {
18290 char *zName; /* Name of the identifier */ 18359 char *zName; /* Name of the identifier */
18291 int idx; /* Index in some Table.aCol[] of a column named zName */ 18360 union {
18292 } *a; 18361 int idx; /* Index in some Table.aCol[] of a column named zName */
18293 int nId; /* Number of identifiers on the list */ 18362 Expr *pExpr; /* Expr to implement a USING variable -- NOT USED */
18363 } u4;
18364 } a[1];
18294}; 18365};
18295 18366
18296/* 18367/*
18368** Allowed values for IdList.eType, which determines which value of the a.u4
18369** is valid.
18370*/
18371#define EU4_NONE 0 /* Does not use IdList.a.u4 */
18372#define EU4_IDX 1 /* Uses IdList.a.u4.idx */
18373#define EU4_EXPR 2 /* Uses IdList.a.u4.pExpr -- NOT CURRENTLY USED */
18374
18375/*
18297** The SrcItem object represents a single term in the FROM clause of a query. 18376** The SrcItem object represents a single term in the FROM clause of a query.
18298** The SrcList object is mostly an array of SrcItems. 18377** The SrcList object is mostly an array of SrcItems.
18299** 18378**
@@ -18320,15 +18399,22 @@ struct SrcItem {
18320 unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */ 18399 unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
18321 unsigned isTabFunc :1; /* True if table-valued-function syntax */ 18400 unsigned isTabFunc :1; /* True if table-valued-function syntax */
18322 unsigned isCorrelated :1; /* True if sub-query is correlated */ 18401 unsigned isCorrelated :1; /* True if sub-query is correlated */
18402 unsigned isMaterialized:1; /* This is a materialized view */
18323 unsigned viaCoroutine :1; /* Implemented as a co-routine */ 18403 unsigned viaCoroutine :1; /* Implemented as a co-routine */
18324 unsigned isRecursive :1; /* True for recursive reference in WITH */ 18404 unsigned isRecursive :1; /* True for recursive reference in WITH */
18325 unsigned fromDDL :1; /* Comes from sqlite_schema */ 18405 unsigned fromDDL :1; /* Comes from sqlite_schema */
18326 unsigned isCte :1; /* This is a CTE */ 18406 unsigned isCte :1; /* This is a CTE */
18327 unsigned notCte :1; /* This item may not match a CTE */ 18407 unsigned notCte :1; /* This item may not match a CTE */
18408 unsigned isUsing :1; /* u3.pUsing is valid */
18409 unsigned isOn :1; /* u3.pOn was once valid and non-NULL */
18410 unsigned isSynthUsing :1; /* u3.pUsing is synthensized from NATURAL */
18411 unsigned isNestedFrom :1; /* pSelect is a SF_NestedFrom subquery */
18328 } fg; 18412 } fg;
18329 int iCursor; /* The VDBE cursor number used to access this table */ 18413 int iCursor; /* The VDBE cursor number used to access this table */
18330 Expr *pOn; /* The ON clause of a join */ 18414 union {
18331 IdList *pUsing; /* The USING clause of a join */ 18415 Expr *pOn; /* fg.isUsing==0 => The ON clause of a join */
18416 IdList *pUsing; /* fg.isUsing==1 => The USING clause of a join */
18417 } u3;
18332 Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */ 18418 Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
18333 union { 18419 union {
18334 char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */ 18420 char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */
@@ -18341,6 +18427,15 @@ struct SrcItem {
18341}; 18427};
18342 18428
18343/* 18429/*
18430** The OnOrUsing object represents either an ON clause or a USING clause.
18431** It can never be both at the same time, but it can be neither.
18432*/
18433struct OnOrUsing {
18434 Expr *pOn; /* The ON clause of a join */
18435 IdList *pUsing; /* The USING clause of a join */
18436};
18437
18438/*
18344** The following structure describes the FROM clause of a SELECT statement. 18439** The following structure describes the FROM clause of a SELECT statement.
18345** Each table or subquery in the FROM clause is a separate element of 18440** Each table or subquery in the FROM clause is a separate element of
18346** the SrcList.a[] array. 18441** the SrcList.a[] array.
@@ -18368,14 +18463,15 @@ struct SrcList {
18368/* 18463/*
18369** Permitted values of the SrcList.a.jointype field 18464** Permitted values of the SrcList.a.jointype field
18370*/ 18465*/
18371#define JT_INNER 0x0001 /* Any kind of inner or cross join */ 18466#define JT_INNER 0x01 /* Any kind of inner or cross join */
18372#define JT_CROSS 0x0002 /* Explicit use of the CROSS keyword */ 18467#define JT_CROSS 0x02 /* Explicit use of the CROSS keyword */
18373#define JT_NATURAL 0x0004 /* True for a "natural" join */ 18468#define JT_NATURAL 0x04 /* True for a "natural" join */
18374#define JT_LEFT 0x0008 /* Left outer join */ 18469#define JT_LEFT 0x08 /* Left outer join */
18375#define JT_RIGHT 0x0010 /* Right outer join */ 18470#define JT_RIGHT 0x10 /* Right outer join */
18376#define JT_OUTER 0x0020 /* The "OUTER" keyword is present */ 18471#define JT_OUTER 0x20 /* The "OUTER" keyword is present */
18377#define JT_ERROR 0x0040 /* unknown or unsupported join type */ 18472#define JT_LTORJ 0x40 /* One of the LEFT operands of a RIGHT JOIN
18378 18473 ** Mnemonic: Left Table Of Right Join */
18474#define JT_ERROR 0x80 /* unknown or unsupported join type */
18379 18475
18380/* 18476/*
18381** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin() 18477** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin()
@@ -18398,7 +18494,7 @@ struct SrcList {
18398#define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */ 18494#define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */
18399#define WHERE_AGG_DISTINCT 0x0400 /* Query is "SELECT agg(DISTINCT ...)" */ 18495#define WHERE_AGG_DISTINCT 0x0400 /* Query is "SELECT agg(DISTINCT ...)" */
18400#define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */ 18496#define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */
18401 /* 0x1000 not currently used */ 18497#define WHERE_RIGHT_JOIN 0x1000 /* Processing a RIGHT JOIN */
18402 /* 0x2000 not currently used */ 18498 /* 0x2000 not currently used */
18403#define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */ 18499#define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */
18404 /* 0x8000 not currently used */ 18500 /* 0x8000 not currently used */
@@ -18594,6 +18690,9 @@ struct Select {
18594#define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */ 18690#define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */
18595#define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */ 18691#define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */
18596 18692
18693/* True if S exists and has SF_NestedFrom */
18694#define IsNestedFrom(S) ((S)!=0 && ((S)->selFlags&SF_NestedFrom)!=0)
18695
18597/* 18696/*
18598** The results of a SELECT can be distributed in several ways, as defined 18697** The results of a SELECT can be distributed in several ways, as defined
18599** by one of the following macros. The "SRT" prefix means "SELECT Result 18698** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -18805,6 +18904,7 @@ struct Parse {
18805 u8 okConstFactor; /* OK to factor out constants */ 18904 u8 okConstFactor; /* OK to factor out constants */
18806 u8 disableLookaside; /* Number of times lookaside has been disabled */ 18905 u8 disableLookaside; /* Number of times lookaside has been disabled */
18807 u8 disableVtab; /* Disable all virtual tables for this parse */ 18906 u8 disableVtab; /* Disable all virtual tables for this parse */
18907 u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
18808#if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST) 18908#if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
18809 u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */ 18909 u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
18810#endif 18910#endif
@@ -18977,20 +19077,20 @@ struct AuthContext {
18977#define OPFLAG_PREFORMAT 0x80 /* OP_Insert uses preformatted cell */ 19077#define OPFLAG_PREFORMAT 0x80 /* OP_Insert uses preformatted cell */
18978 19078
18979/* 19079/*
18980 * Each trigger present in the database schema is stored as an instance of 19080** Each trigger present in the database schema is stored as an instance of
18981 * struct Trigger. 19081** struct Trigger.
18982 * 19082**
18983 * Pointers to instances of struct Trigger are stored in two ways. 19083** Pointers to instances of struct Trigger are stored in two ways.
18984 * 1. In the "trigHash" hash table (part of the sqlite3* that represents the 19084** 1. In the "trigHash" hash table (part of the sqlite3* that represents the
18985 * database). This allows Trigger structures to be retrieved by name. 19085** database). This allows Trigger structures to be retrieved by name.
18986 * 2. All triggers associated with a single table form a linked list, using the 19086** 2. All triggers associated with a single table form a linked list, using the
18987 * pNext member of struct Trigger. A pointer to the first element of the 19087** pNext member of struct Trigger. A pointer to the first element of the
18988 * linked list is stored as the "pTrigger" member of the associated 19088** linked list is stored as the "pTrigger" member of the associated
18989 * struct Table. 19089** struct Table.
18990 * 19090**
18991 * The "step_list" member points to the first element of a linked list 19091** The "step_list" member points to the first element of a linked list
18992 * containing the SQL statements specified as the trigger program. 19092** containing the SQL statements specified as the trigger program.
18993 */ 19093*/
18994struct Trigger { 19094struct Trigger {
18995 char *zName; /* The name of the trigger */ 19095 char *zName; /* The name of the trigger */
18996 char *table; /* The table or view to which the trigger applies */ 19096 char *table; /* The table or view to which the trigger applies */
@@ -19017,43 +19117,48 @@ struct Trigger {
19017#define TRIGGER_AFTER 2 19117#define TRIGGER_AFTER 2
19018 19118
19019/* 19119/*
19020 * An instance of struct TriggerStep is used to store a single SQL statement 19120** An instance of struct TriggerStep is used to store a single SQL statement
19021 * that is a part of a trigger-program. 19121** that is a part of a trigger-program.
19022 * 19122**
19023 * Instances of struct TriggerStep are stored in a singly linked list (linked 19123** Instances of struct TriggerStep are stored in a singly linked list (linked
19024 * using the "pNext" member) referenced by the "step_list" member of the 19124** using the "pNext" member) referenced by the "step_list" member of the
19025 * associated struct Trigger instance. The first element of the linked list is 19125** associated struct Trigger instance. The first element of the linked list is
19026 * the first step of the trigger-program. 19126** the first step of the trigger-program.
19027 * 19127**
19028 * The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or 19128** The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or
19029 * "SELECT" statement. The meanings of the other members is determined by the 19129** "SELECT" statement. The meanings of the other members is determined by the
19030 * value of "op" as follows: 19130** value of "op" as follows:
19031 * 19131**
19032 * (op == TK_INSERT) 19132** (op == TK_INSERT)
19033 * orconf -> stores the ON CONFLICT algorithm 19133** orconf -> stores the ON CONFLICT algorithm
19034 * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then 19134** pSelect -> The content to be inserted - either a SELECT statement or
19035 * this stores a pointer to the SELECT statement. Otherwise NULL. 19135** a VALUES clause.
19036 * zTarget -> Dequoted name of the table to insert into. 19136** zTarget -> Dequoted name of the table to insert into.
19037 * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then 19137** pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
19038 * this stores values to be inserted. Otherwise NULL. 19138** statement, then this stores the column-names to be
19039 * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ... 19139** inserted into.
19040 * statement, then this stores the column-names to be 19140** pUpsert -> The ON CONFLICT clauses for an Upsert
19041 * inserted into. 19141**
19042 * 19142** (op == TK_DELETE)
19043 * (op == TK_DELETE) 19143** zTarget -> Dequoted name of the table to delete from.
19044 * zTarget -> Dequoted name of the table to delete from. 19144** pWhere -> The WHERE clause of the DELETE statement if one is specified.
19045 * pWhere -> The WHERE clause of the DELETE statement if one is specified. 19145** Otherwise NULL.
19046 * Otherwise NULL. 19146**
19047 * 19147** (op == TK_UPDATE)
19048 * (op == TK_UPDATE) 19148** zTarget -> Dequoted name of the table to update.
19049 * zTarget -> Dequoted name of the table to update. 19149** pWhere -> The WHERE clause of the UPDATE statement if one is specified.
19050 * pWhere -> The WHERE clause of the UPDATE statement if one is specified. 19150** Otherwise NULL.
19051 * Otherwise NULL. 19151** pExprList -> A list of the columns to update and the expressions to update
19052 * pExprList -> A list of the columns to update and the expressions to update 19152** them to. See sqlite3Update() documentation of "pChanges"
19053 * them to. See sqlite3Update() documentation of "pChanges" 19153** argument.
19054 * argument. 19154**
19055 * 19155** (op == TK_SELECT)
19056 */ 19156** pSelect -> The SELECT statement
19157**
19158** (op == TK_RETURNING)
19159** pExprList -> The list of expressions that follow the RETURNING keyword.
19160**
19161*/
19057struct TriggerStep { 19162struct TriggerStep {
19058 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT, 19163 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT,
19059 ** or TK_RETURNING */ 19164 ** or TK_RETURNING */
@@ -19408,7 +19513,7 @@ struct Window {
19408 Window **ppThis; /* Pointer to this object in Select.pWin list */ 19513 Window **ppThis; /* Pointer to this object in Select.pWin list */
19409 Window *pNextWin; /* Next window function belonging to this SELECT */ 19514 Window *pNextWin; /* Next window function belonging to this SELECT */
19410 Expr *pFilter; /* The FILTER expression */ 19515 Expr *pFilter; /* The FILTER expression */
19411 FuncDef *pFunc; /* The function */ 19516 FuncDef *pWFunc; /* The function */
19412 int iEphCsr; /* Partition buffer or Peer buffer */ 19517 int iEphCsr; /* Partition buffer or Peer buffer */
19413 int regAccum; /* Accumulator */ 19518 int regAccum; /* Accumulator */
19414 int regResult; /* Interim result */ 19519 int regResult; /* Interim result */
@@ -19663,18 +19768,53 @@ SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
19663#endif 19768#endif
19664 19769
19665#if defined(SQLITE_DEBUG) 19770#if defined(SQLITE_DEBUG)
19771SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView*, const char *zFormat, ...);
19666SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8); 19772SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
19667SQLITE_PRIVATE void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*); 19773SQLITE_PRIVATE void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*);
19668SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*); 19774SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
19775SQLITE_PRIVATE void sqlite3TreeViewBareIdList(TreeView*, const IdList*, const char*);
19776SQLITE_PRIVATE void sqlite3TreeViewIdList(TreeView*, const IdList*, u8, const char*);
19777SQLITE_PRIVATE void sqlite3TreeViewColumnList(TreeView*, const Column*, int, u8);
19669SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView*, const SrcList*); 19778SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView*, const SrcList*);
19670SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8); 19779SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
19671SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8); 19780SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8);
19781SQLITE_PRIVATE void sqlite3TreeViewUpsert(TreeView*, const Upsert*, u8);
19782#if TREETRACE_ENABLED
19783SQLITE_PRIVATE void sqlite3TreeViewDelete(const With*, const SrcList*, const Expr*,
19784 const ExprList*,const Expr*, const Trigger*);
19785SQLITE_PRIVATE void sqlite3TreeViewInsert(const With*, const SrcList*,
19786 const IdList*, const Select*, const ExprList*,
19787 int, const Upsert*, const Trigger*);
19788SQLITE_PRIVATE void sqlite3TreeViewUpdate(const With*, const SrcList*, const ExprList*,
19789 const Expr*, int, const ExprList*, const Expr*,
19790 const Upsert*, const Trigger*);
19791#endif
19792#ifndef SQLITE_OMIT_TRIGGER
19793SQLITE_PRIVATE void sqlite3TreeViewTriggerStep(TreeView*, const TriggerStep*, u8, u8);
19794SQLITE_PRIVATE void sqlite3TreeViewTrigger(TreeView*, const Trigger*, u8, u8);
19795#endif
19672#ifndef SQLITE_OMIT_WINDOWFUNC 19796#ifndef SQLITE_OMIT_WINDOWFUNC
19673SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView*, const Window*, u8); 19797SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView*, const Window*, u8);
19674SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView*, const Window*, u8); 19798SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView*, const Window*, u8);
19675#endif 19799#endif
19800SQLITE_PRIVATE void sqlite3ShowExpr(const Expr*);
19801SQLITE_PRIVATE void sqlite3ShowExprList(const ExprList*);
19802SQLITE_PRIVATE void sqlite3ShowIdList(const IdList*);
19803SQLITE_PRIVATE void sqlite3ShowSrcList(const SrcList*);
19804SQLITE_PRIVATE void sqlite3ShowSelect(const Select*);
19805SQLITE_PRIVATE void sqlite3ShowWith(const With*);
19806SQLITE_PRIVATE void sqlite3ShowUpsert(const Upsert*);
19807#ifndef SQLITE_OMIT_TRIGGER
19808SQLITE_PRIVATE void sqlite3ShowTriggerStep(const TriggerStep*);
19809SQLITE_PRIVATE void sqlite3ShowTriggerStepList(const TriggerStep*);
19810SQLITE_PRIVATE void sqlite3ShowTrigger(const Trigger*);
19811SQLITE_PRIVATE void sqlite3ShowTriggerList(const Trigger*);
19812#endif
19813#ifndef SQLITE_OMIT_WINDOWFUNC
19814SQLITE_PRIVATE void sqlite3ShowWindow(const Window*);
19815SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window*);
19816#endif
19676#endif 19817#endif
19677
19678 19818
19679SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*); 19819SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
19680SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...); 19820SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
@@ -19823,13 +19963,14 @@ SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(Parse*, SrcList*, int, int);
19823SQLITE_PRIVATE SrcList *sqlite3SrcListAppendList(Parse *pParse, SrcList *p1, SrcList *p2); 19963SQLITE_PRIVATE SrcList *sqlite3SrcListAppendList(Parse *pParse, SrcList *p1, SrcList *p2);
19824SQLITE_PRIVATE SrcList *sqlite3SrcListAppend(Parse*, SrcList*, Token*, Token*); 19964SQLITE_PRIVATE SrcList *sqlite3SrcListAppend(Parse*, SrcList*, Token*, Token*);
19825SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*, 19965SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*,
19826 Token*, Select*, Expr*, IdList*); 19966 Token*, Select*, OnOrUsing*);
19827SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *); 19967SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *);
19828SQLITE_PRIVATE void sqlite3SrcListFuncArgs(Parse*, SrcList*, ExprList*); 19968SQLITE_PRIVATE void sqlite3SrcListFuncArgs(Parse*, SrcList*, ExprList*);
19829SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, SrcItem *); 19969SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, SrcItem *);
19830SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList*); 19970SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(Parse*,SrcList*);
19831SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*); 19971SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*);
19832SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*); 19972SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
19973SQLITE_PRIVATE void sqlite3ClearOnOrUsing(sqlite3*, OnOrUsing*);
19833SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*); 19974SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
19834SQLITE_PRIVATE Index *sqlite3AllocateIndexObject(sqlite3*,i16,int,char**); 19975SQLITE_PRIVATE Index *sqlite3AllocateIndexObject(sqlite3*,i16,int,char**);
19835SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*, 19976SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
@@ -19929,6 +20070,7 @@ SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
19929SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8); 20070SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
19930SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*); 20071SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
19931SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int); 20072SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
20073SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr*,const SrcItem*);
19932#ifdef SQLITE_ENABLE_CURSOR_HINTS 20074#ifdef SQLITE_ENABLE_CURSOR_HINTS
19933SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*); 20075SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
19934#endif 20076#endif
@@ -20026,7 +20168,8 @@ SQLITE_PRIVATE SrcList *sqlite3TriggerStepSrc(Parse*, TriggerStep*);
20026 20168
20027SQLITE_PRIVATE int sqlite3JoinType(Parse*, Token*, Token*, Token*); 20169SQLITE_PRIVATE int sqlite3JoinType(Parse*, Token*, Token*, Token*);
20028SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol); 20170SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol);
20029SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr*,int); 20171SQLITE_PRIVATE void sqlite3SrcItemColumnUsed(SrcItem*,int);
20172SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr*,int,u32);
20030SQLITE_PRIVATE void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int); 20173SQLITE_PRIVATE void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int);
20031SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse*, int); 20174SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse*, int);
20032#ifndef SQLITE_OMIT_AUTHORIZATION 20175#ifndef SQLITE_OMIT_AUTHORIZATION
@@ -20372,7 +20515,7 @@ SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *);
20372SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*); 20515SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
20373#if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \ 20516#if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \
20374 && !defined(SQLITE_OMIT_VIRTUALTABLE) 20517 && !defined(SQLITE_OMIT_VIRTUALTABLE)
20375SQLITE_PRIVATE void sqlite3VtabWriteAll(sqlite3_index_info*); 20518SQLITE_PRIVATE void sqlite3VtabUsesAllSchemas(sqlite3_index_info*);
20376#endif 20519#endif
20377SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*); 20520SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
20378SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int); 20521SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
@@ -21120,9 +21263,6 @@ static const char * const sqlite3azCompileOpt[] = {
21120#ifdef SQLITE_ENABLE_RTREE 21263#ifdef SQLITE_ENABLE_RTREE
21121 "ENABLE_RTREE", 21264 "ENABLE_RTREE",
21122#endif 21265#endif
21123#ifdef SQLITE_ENABLE_SELECTTRACE
21124 "ENABLE_SELECTTRACE",
21125#endif
21126#ifdef SQLITE_ENABLE_SESSION 21266#ifdef SQLITE_ENABLE_SESSION
21127 "ENABLE_SESSION", 21267 "ENABLE_SESSION",
21128#endif 21268#endif
@@ -21144,6 +21284,9 @@ static const char * const sqlite3azCompileOpt[] = {
21144#ifdef SQLITE_ENABLE_STMT_SCANSTATUS 21284#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
21145 "ENABLE_STMT_SCANSTATUS", 21285 "ENABLE_STMT_SCANSTATUS",
21146#endif 21286#endif
21287#ifdef SQLITE_ENABLE_TREETRACE
21288 "ENABLE_TREETRACE",
21289#endif
21147#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION 21290#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
21148 "ENABLE_UNKNOWN_SQL_FUNCTION", 21291 "ENABLE_UNKNOWN_SQL_FUNCTION",
21149#endif 21292#endif
@@ -21893,6 +22036,9 @@ SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
21893 0x7ffffffe, /* iOnceResetThreshold */ 22036 0x7ffffffe, /* iOnceResetThreshold */
21894 SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */ 22037 SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
21895 0, /* iPrngSeed */ 22038 0, /* iPrngSeed */
22039#ifdef SQLITE_DEBUG
22040 {0,0,0,0,0,0} /* aTune */
22041#endif
21896}; 22042};
21897 22043
21898/* 22044/*
@@ -21947,7 +22093,7 @@ SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
21947/* 22093/*
21948** Tracing flags set by SQLITE_TESTCTRL_TRACEFLAGS. 22094** Tracing flags set by SQLITE_TESTCTRL_TRACEFLAGS.
21949*/ 22095*/
21950SQLITE_PRIVATE u32 sqlite3SelectTrace = 0; 22096SQLITE_PRIVATE u32 sqlite3TreeTrace = 0;
21951SQLITE_PRIVATE u32 sqlite3WhereTrace = 0; 22097SQLITE_PRIVATE u32 sqlite3WhereTrace = 0;
21952 22098
21953/* #include "opcodes.h" */ 22099/* #include "opcodes.h" */
@@ -22114,7 +22260,7 @@ struct VdbeCursor {
22114 Bool isEphemeral:1; /* True for an ephemeral table */ 22260 Bool isEphemeral:1; /* True for an ephemeral table */
22115 Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */ 22261 Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */
22116 Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */ 22262 Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
22117 Bool hasBeenDuped:1; /* This cursor was source or target of OP_OpenDup */ 22263 Bool noReuse:1; /* OpenEphemeral may not reuse this cursor */
22118 u16 seekHit; /* See the OP_SeekHit and OP_IfNoHope opcodes */ 22264 u16 seekHit; /* See the OP_SeekHit and OP_IfNoHope opcodes */
22119 union { /* pBtx for isEphermeral. pAltMap otherwise */ 22265 union { /* pBtx for isEphermeral. pAltMap otherwise */
22120 Btree *pBtx; /* Separate file holding temporary table */ 22266 Btree *pBtx; /* Separate file holding temporary table */
@@ -22162,6 +22308,11 @@ struct VdbeCursor {
22162 u32 aType[1]; /* Type values record decode. MUST BE LAST */ 22308 u32 aType[1]; /* Type values record decode. MUST BE LAST */
22163}; 22309};
22164 22310
22311/* Return true if P is a null-only cursor
22312*/
22313#define IsNullCursor(P) \
22314 ((P)->eCurType==CURTYPE_PSEUDO && (P)->nullRow && (P)->seekResult==0)
22315
22165 22316
22166/* 22317/*
22167** A value for VdbeCursor.cacheStatus that means the cache is always invalid. 22318** A value for VdbeCursor.cacheStatus that means the cache is always invalid.
@@ -22236,16 +22387,16 @@ struct sqlite3_value {
22236 const char *zPType; /* Pointer type when MEM_Term|MEM_Subtype|MEM_Null */ 22387 const char *zPType; /* Pointer type when MEM_Term|MEM_Subtype|MEM_Null */
22237 FuncDef *pDef; /* Used only when flags==MEM_Agg */ 22388 FuncDef *pDef; /* Used only when flags==MEM_Agg */
22238 } u; 22389 } u;
22390 char *z; /* String or BLOB value */
22391 int n; /* Number of characters in string value, excluding '\0' */
22239 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */ 22392 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
22240 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */ 22393 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
22241 u8 eSubtype; /* Subtype for this value */ 22394 u8 eSubtype; /* Subtype for this value */
22242 int n; /* Number of characters in string value, excluding '\0' */
22243 char *z; /* String or BLOB value */
22244 /* ShallowCopy only needs to copy the information above */ 22395 /* ShallowCopy only needs to copy the information above */
22245 char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */ 22396 sqlite3 *db; /* The associated database connection */
22246 int szMalloc; /* Size of the zMalloc allocation */ 22397 int szMalloc; /* Size of the zMalloc allocation */
22247 u32 uTemp; /* Transient storage for serial_type in OP_MakeRecord */ 22398 u32 uTemp; /* Transient storage for serial_type in OP_MakeRecord */
22248 sqlite3 *db; /* The associated database connection */ 22399 char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
22249 void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */ 22400 void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
22250#ifdef SQLITE_DEBUG 22401#ifdef SQLITE_DEBUG
22251 Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */ 22402 Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
@@ -22257,11 +22408,43 @@ struct sqlite3_value {
22257** Size of struct Mem not including the Mem.zMalloc member or anything that 22408** Size of struct Mem not including the Mem.zMalloc member or anything that
22258** follows. 22409** follows.
22259*/ 22410*/
22260#define MEMCELLSIZE offsetof(Mem,zMalloc) 22411#define MEMCELLSIZE offsetof(Mem,db)
22261 22412
22262/* One or more of the following flags are set to indicate the validOK 22413/* One or more of the following flags are set to indicate the
22263** representations of the value stored in the Mem struct. 22414** representations of the value stored in the Mem struct.
22264** 22415**
22416** * MEM_Null An SQL NULL value
22417**
22418** * MEM_Null|MEM_Zero An SQL NULL with the virtual table
22419** UPDATE no-change flag set
22420**
22421** * MEM_Null|MEM_Term| An SQL NULL, but also contains a
22422** MEM_Subtype pointer accessible using
22423** sqlite3_value_pointer().
22424**
22425** * MEM_Null|MEM_Cleared Special SQL NULL that compares non-equal
22426** to other NULLs even using the IS operator.
22427**
22428** * MEM_Str A string, stored in Mem.z with
22429** length Mem.n. Zero-terminated if
22430** MEM_Term is set. This flag is
22431** incompatible with MEM_Blob and
22432** MEM_Null, but can appear with MEM_Int,
22433** MEM_Real, and MEM_IntReal.
22434**
22435** * MEM_Blob A blob, stored in Mem.z length Mem.n.
22436** Incompatible with MEM_Str, MEM_Null,
22437** MEM_Int, MEM_Real, and MEM_IntReal.
22438**
22439** * MEM_Blob|MEM_Zero A blob in Mem.z of length Mem.n plus
22440** MEM.u.i extra 0x00 bytes at the end.
22441**
22442** * MEM_Int Integer stored in Mem.u.i.
22443**
22444** * MEM_Real Real stored in Mem.u.r.
22445**
22446** * MEM_IntReal Real stored as an integer in Mem.u.i.
22447**
22265** If the MEM_Null flag is set, then the value is an SQL NULL value. 22448** If the MEM_Null flag is set, then the value is an SQL NULL value.
22266** For a pointer type created using sqlite3_bind_pointer() or 22449** For a pointer type created using sqlite3_bind_pointer() or
22267** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set. 22450** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set.
@@ -22272,6 +22455,7 @@ struct sqlite3_value {
22272** set, then the string is nul terminated. The MEM_Int and MEM_Real 22455** set, then the string is nul terminated. The MEM_Int and MEM_Real
22273** flags may coexist with the MEM_Str flag. 22456** flags may coexist with the MEM_Str flag.
22274*/ 22457*/
22458#define MEM_Undefined 0x0000 /* Value is undefined */
22275#define MEM_Null 0x0001 /* Value is NULL (or a pointer) */ 22459#define MEM_Null 0x0001 /* Value is NULL (or a pointer) */
22276#define MEM_Str 0x0002 /* Value is a string */ 22460#define MEM_Str 0x0002 /* Value is a string */
22277#define MEM_Int 0x0004 /* Value is an integer */ 22461#define MEM_Int 0x0004 /* Value is an integer */
@@ -22279,28 +22463,24 @@ struct sqlite3_value {
22279#define MEM_Blob 0x0010 /* Value is a BLOB */ 22463#define MEM_Blob 0x0010 /* Value is a BLOB */
22280#define MEM_IntReal 0x0020 /* MEM_Int that stringifies like MEM_Real */ 22464#define MEM_IntReal 0x0020 /* MEM_Int that stringifies like MEM_Real */
22281#define MEM_AffMask 0x003f /* Mask of affinity bits */ 22465#define MEM_AffMask 0x003f /* Mask of affinity bits */
22466
22467/* Extra bits that modify the meanings of the core datatypes above
22468*/
22282#define MEM_FromBind 0x0040 /* Value originates from sqlite3_bind() */ 22469#define MEM_FromBind 0x0040 /* Value originates from sqlite3_bind() */
22283#define MEM_Undefined 0x0080 /* Value is undefined */ 22470 /* 0x0080 // Available */
22284#define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */ 22471#define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
22285#define MEM_TypeMask 0xc1bf /* Mask of type bits */ 22472#define MEM_Term 0x0200 /* String in Mem.z is zero terminated */
22286 22473#define MEM_Zero 0x0400 /* Mem.i contains count of 0s appended to blob */
22474#define MEM_Subtype 0x0800 /* Mem.eSubtype is valid */
22475#define MEM_TypeMask 0x0dbf /* Mask of type bits */
22287 22476
22288/* Whenever Mem contains a valid string or blob representation, one of 22477/* Bits that determine the storage for Mem.z for a string or blob or
22289** the following flags must be set to determine the memory management 22478** aggregate accumulator.
22290** policy for Mem.z. The MEM_Term flag tells us whether or not the
22291** string is \000 or \u0000 terminated
22292*/ 22479*/
22293#define MEM_Term 0x0200 /* String in Mem.z is zero terminated */ 22480#define MEM_Dyn 0x1000 /* Need to call Mem.xDel() on Mem.z */
22294#define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */ 22481#define MEM_Static 0x2000 /* Mem.z points to a static string */
22295#define MEM_Static 0x0800 /* Mem.z points to a static string */ 22482#define MEM_Ephem 0x4000 /* Mem.z points to an ephemeral string */
22296#define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */ 22483#define MEM_Agg 0x8000 /* Mem.z points to an agg function context */
22297#define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
22298#define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
22299#define MEM_Subtype 0x8000 /* Mem.eSubtype is valid */
22300#ifdef SQLITE_OMIT_INCRBLOB
22301 #undef MEM_Zero
22302 #define MEM_Zero 0x0000
22303#endif
22304 22484
22305/* Return TRUE if Mem X contains dynamically allocated content - anything 22485/* Return TRUE if Mem X contains dynamically allocated content - anything
22306** that needs to be deallocated to avoid a leak. 22486** that needs to be deallocated to avoid a leak.
@@ -22322,11 +22502,15 @@ struct sqlite3_value {
22322 && (X)->n==0 && (X)->u.nZero==0) 22502 && (X)->n==0 && (X)->u.nZero==0)
22323 22503
22324/* 22504/*
22325** Return true if a memory cell is not marked as invalid. This macro 22505** Return true if a memory cell has been initialized and is valid.
22326** is for use inside assert() statements only. 22506** is for use inside assert() statements only.
22507**
22508** A Memory cell is initialized if at least one of the
22509** MEM_Null, MEM_Str, MEM_Int, MEM_Real, MEM_Blob, or MEM_IntReal bits
22510** is set. It is "undefined" if all those bits are zero.
22327*/ 22511*/
22328#ifdef SQLITE_DEBUG 22512#ifdef SQLITE_DEBUG
22329#define memIsValid(M) ((M)->flags & MEM_Undefined)==0 22513#define memIsValid(M) ((M)->flags & MEM_AffMask)!=0
22330#endif 22514#endif
22331 22515
22332/* 22516/*
@@ -22364,6 +22548,7 @@ struct sqlite3_context {
22364 Vdbe *pVdbe; /* The VM that owns this context */ 22548 Vdbe *pVdbe; /* The VM that owns this context */
22365 int iOp; /* Instruction number of OP_Function */ 22549 int iOp; /* Instruction number of OP_Function */
22366 int isError; /* Error code returned by the function. */ 22550 int isError; /* Error code returned by the function. */
22551 u8 enc; /* Encoding to use for results */
22367 u8 skipFlag; /* Skip accumulator loading if true */ 22552 u8 skipFlag; /* Skip accumulator loading if true */
22368 u8 argc; /* Number of arguments */ 22553 u8 argc; /* Number of arguments */
22369 sqlite3_value *argv[1]; /* Argument set */ 22554 sqlite3_value *argv[1]; /* Argument set */
@@ -22412,7 +22597,6 @@ struct Vdbe {
22412 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ 22597 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
22413 Parse *pParse; /* Parsing context used to create this Vdbe */ 22598 Parse *pParse; /* Parsing context used to create this Vdbe */
22414 ynVar nVar; /* Number of entries in aVar[] */ 22599 ynVar nVar; /* Number of entries in aVar[] */
22415 u32 iVdbeMagic; /* Magic number defining state of the SQL statement */
22416 int nMem; /* Number of memory locations currently allocated */ 22600 int nMem; /* Number of memory locations currently allocated */
22417 int nCursor; /* Number of slots in apCsr[] */ 22601 int nCursor; /* Number of slots in apCsr[] */
22418 u32 cacheCtr; /* VdbeCursor row cache generation counter */ 22602 u32 cacheCtr; /* VdbeCursor row cache generation counter */
@@ -22450,11 +22634,10 @@ struct Vdbe {
22450 u8 errorAction; /* Recovery action to do in case of an error */ 22634 u8 errorAction; /* Recovery action to do in case of an error */
22451 u8 minWriteFileFormat; /* Minimum file format for writable database files */ 22635 u8 minWriteFileFormat; /* Minimum file format for writable database files */
22452 u8 prepFlags; /* SQLITE_PREPARE_* flags */ 22636 u8 prepFlags; /* SQLITE_PREPARE_* flags */
22453 u8 doingRerun; /* True if rerunning after an auto-reprepare */ 22637 u8 eVdbeState; /* On of the VDBE_*_STATE values */
22454 bft expired:2; /* 1: recompile VM immediately 2: when convenient */ 22638 bft expired:2; /* 1: recompile VM immediately 2: when convenient */
22455 bft explain:2; /* True if EXPLAIN present on SQL command */ 22639 bft explain:2; /* True if EXPLAIN present on SQL command */
22456 bft changeCntOn:1; /* True to update the change-counter */ 22640 bft changeCntOn:1; /* True to update the change-counter */
22457 bft runOnlyOnce:1; /* Automatically expire on reset */
22458 bft usesStmtJournal:1; /* True if uses a statement journal */ 22641 bft usesStmtJournal:1; /* True if uses a statement journal */
22459 bft readOnly:1; /* True for statements that do not write */ 22642 bft readOnly:1; /* True for statements that do not write */
22460 bft bIsReader:1; /* True for statements that read */ 22643 bft bIsReader:1; /* True for statements that read */
@@ -22481,13 +22664,12 @@ struct Vdbe {
22481}; 22664};
22482 22665
22483/* 22666/*
22484** The following are allowed values for Vdbe.magic 22667** The following are allowed values for Vdbe.eVdbeState
22485*/ 22668*/
22486#define VDBE_MAGIC_INIT 0x16bceaa5 /* Building a VDBE program */ 22669#define VDBE_INIT_STATE 0 /* Prepared statement under construction */
22487#define VDBE_MAGIC_RUN 0x2df20da3 /* VDBE is ready to execute */ 22670#define VDBE_READY_STATE 1 /* Ready to run but not yet started */
22488#define VDBE_MAGIC_HALT 0x319c2973 /* VDBE has completed execution */ 22671#define VDBE_RUN_STATE 2 /* Run in progress */
22489#define VDBE_MAGIC_RESET 0x48fa9f76 /* Reset and ready to run again */ 22672#define VDBE_HALT_STATE 3 /* Finished. Need reset() or finalize() */
22490#define VDBE_MAGIC_DEAD 0x5606c3c8 /* The VDBE has been deallocated */
22491 22673
22492/* 22674/*
22493** Structure used to store the context required by the 22675** Structure used to store the context required by the
@@ -22528,18 +22710,31 @@ struct ValueList {
22528 sqlite3_value *pOut; /* Register to hold each decoded output value */ 22710 sqlite3_value *pOut; /* Register to hold each decoded output value */
22529}; 22711};
22530 22712
22713/* Size of content associated with serial types that fit into a
22714** single-byte varint.
22715*/
22716#ifndef SQLITE_AMALGAMATION
22717SQLITE_PRIVATE const u8 sqlite3SmallTypeSizes[];
22718#endif
22719
22531/* 22720/*
22532** Function prototypes 22721** Function prototypes
22533*/ 22722*/
22534SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...); 22723SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...);
22535SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*); 22724SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
22725SQLITE_PRIVATE void sqlite3VdbeFreeCursorNN(Vdbe*,VdbeCursor*);
22536void sqliteVdbePopStack(Vdbe*,int); 22726void sqliteVdbePopStack(Vdbe*,int);
22727SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeHandleMovedCursor(VdbeCursor *p);
22537SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*); 22728SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*);
22538SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, u32*);
22539SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*); 22729SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*);
22540SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32); 22730SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
22541SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8); 22731SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8);
22542SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32); 22732#ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
22733SQLITE_PRIVATE u64 sqlite3FloatSwap(u64 in);
22734# define swapMixedEndianFloat(X) X = sqlite3FloatSwap(X)
22735#else
22736# define swapMixedEndianFloat(X)
22737#endif
22543SQLITE_PRIVATE void sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); 22738SQLITE_PRIVATE void sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
22544SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(sqlite3*, AuxData**, int, int); 22739SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(sqlite3*, AuxData**, int, int);
22545 22740
@@ -22597,6 +22792,7 @@ SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem*,u8,u8);
22597SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*); 22792SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
22598SQLITE_PRIVATE int sqlite3VdbeMemFromBtreeZeroOffset(BtCursor*,u32,Mem*); 22793SQLITE_PRIVATE int sqlite3VdbeMemFromBtreeZeroOffset(BtCursor*,u32,Mem*);
22599SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p); 22794SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
22795SQLITE_PRIVATE void sqlite3VdbeMemReleaseMalloc(Mem*p);
22600SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*); 22796SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
22601#ifndef SQLITE_OMIT_WINDOWFUNC 22797#ifndef SQLITE_OMIT_WINDOWFUNC
22602SQLITE_PRIVATE int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*); 22798SQLITE_PRIVATE int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*);
@@ -22999,8 +23195,7 @@ SQLITE_API int sqlite3_db_status(
22999 23195
23000 db->pnBytesFreed = &nByte; 23196 db->pnBytesFreed = &nByte;
23001 for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){ 23197 for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
23002 sqlite3VdbeClearObject(db, pVdbe); 23198 sqlite3VdbeDelete(pVdbe);
23003 sqlite3DbFree(db, pVdbe);
23004 } 23199 }
23005 db->pnBytesFreed = 0; 23200 db->pnBytesFreed = 0;
23006 23201
@@ -26955,8 +27150,13 @@ static void *memsys5Realloc(void *pPrior, int nBytes){
26955*/ 27150*/
26956static int memsys5Roundup(int n){ 27151static int memsys5Roundup(int n){
26957 int iFullSz; 27152 int iFullSz;
26958 if( n > 0x40000000 ) return 0; 27153 if( n<=mem5.szAtom*2 ){
26959 for(iFullSz=mem5.szAtom; iFullSz<n; iFullSz *= 2); 27154 if( n<=mem5.szAtom ) return mem5.szAtom;
27155 return mem5.szAtom*2;
27156 }
27157 if( n>0x40000000 ) return 0;
27158 for(iFullSz=mem5.szAtom*8; iFullSz<n; iFullSz *= 4);
27159 if( (iFullSz/2)>=n ) return iFullSz/2;
26960 return iFullSz; 27160 return iFullSz;
26961} 27161}
26962 27162
@@ -29337,8 +29537,9 @@ SQLITE_PRIVATE char *sqlite3DbSpanDup(sqlite3 *db, const char *zStart, const cha
29337** Free any prior content in *pz and replace it with a copy of zNew. 29537** Free any prior content in *pz and replace it with a copy of zNew.
29338*/ 29538*/
29339SQLITE_PRIVATE void sqlite3SetString(char **pz, sqlite3 *db, const char *zNew){ 29539SQLITE_PRIVATE void sqlite3SetString(char **pz, sqlite3 *db, const char *zNew){
29540 char *z = sqlite3DbStrDup(db, zNew);
29340 sqlite3DbFree(db, *pz); 29541 sqlite3DbFree(db, *pz);
29341 *pz = sqlite3DbStrDup(db, zNew); 29542 *pz = z;
29342} 29543}
29343 29544
29344/* 29545/*
@@ -30229,8 +30430,8 @@ SQLITE_API void sqlite3_str_vappendf(
30229 case etSQLESCAPE: /* %q: Escape ' characters */ 30430 case etSQLESCAPE: /* %q: Escape ' characters */
30230 case etSQLESCAPE2: /* %Q: Escape ' and enclose in '...' */ 30431 case etSQLESCAPE2: /* %Q: Escape ' and enclose in '...' */
30231 case etSQLESCAPE3: { /* %w: Escape " characters */ 30432 case etSQLESCAPE3: { /* %w: Escape " characters */
30232 int i, j, k, n, isnull; 30433 i64 i, j, k, n;
30233 int needQuote; 30434 int needQuote, isnull;
30234 char ch; 30435 char ch;
30235 char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */ 30436 char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
30236 char *escarg; 30437 char *escarg;
@@ -30310,8 +30511,14 @@ SQLITE_API void sqlite3_str_vappendf(
30310 sqlite3_str_appendall(pAccum, pItem->zName); 30511 sqlite3_str_appendall(pAccum, pItem->zName);
30311 }else if( pItem->zAlias ){ 30512 }else if( pItem->zAlias ){
30312 sqlite3_str_appendall(pAccum, pItem->zAlias); 30513 sqlite3_str_appendall(pAccum, pItem->zAlias);
30313 }else if( ALWAYS(pItem->pSelect) ){ 30514 }else{
30314 sqlite3_str_appendf(pAccum, "SUBQUERY %u", pItem->pSelect->selId); 30515 Select *pSel = pItem->pSelect;
30516 assert( pSel!=0 );
30517 if( pSel->selFlags & SF_NestedFrom ){
30518 sqlite3_str_appendf(pAccum, "(join-%u)", pSel->selId);
30519 }else{
30520 sqlite3_str_appendf(pAccum, "(subquery-%u)", pSel->selId);
30521 }
30315 } 30522 }
30316 length = width = 0; 30523 length = width = 0;
30317 break; 30524 break;
@@ -30374,7 +30581,9 @@ SQLITE_PRIVATE void sqlite3RecordErrorByteOffset(sqlite3 *db, const char *z){
30374** as the error offset. 30581** as the error offset.
30375*/ 30582*/
30376SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3 *db, const Expr *pExpr){ 30583SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3 *db, const Expr *pExpr){
30377 while( pExpr && (ExprHasProperty(pExpr,EP_FromJoin) || pExpr->w.iOfst<=0) ){ 30584 while( pExpr
30585 && (ExprHasProperty(pExpr,EP_OuterON|EP_InnerON) || pExpr->w.iOfst<=0)
30586 ){
30378 pExpr = pExpr->pLeft; 30587 pExpr = pExpr->pLeft;
30379 } 30588 }
30380 if( pExpr==0 ) return; 30589 if( pExpr==0 ) return;
@@ -30834,40 +31043,44 @@ SQLITE_API void sqlite3_str_appendf(StrAccum *p, const char *zFormat, ...){
30834** Add a new subitem to the tree. The moreToFollow flag indicates that this 31043** Add a new subitem to the tree. The moreToFollow flag indicates that this
30835** is not the last item in the tree. 31044** is not the last item in the tree.
30836*/ 31045*/
30837static TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){ 31046static void sqlite3TreeViewPush(TreeView **pp, u8 moreToFollow){
31047 TreeView *p = *pp;
30838 if( p==0 ){ 31048 if( p==0 ){
30839 p = sqlite3_malloc64( sizeof(*p) ); 31049 *pp = p = sqlite3_malloc64( sizeof(*p) );
30840 if( p==0 ) return 0; 31050 if( p==0 ) return;
30841 memset(p, 0, sizeof(*p)); 31051 memset(p, 0, sizeof(*p));
30842 }else{ 31052 }else{
30843 p->iLevel++; 31053 p->iLevel++;
30844 } 31054 }
30845 assert( moreToFollow==0 || moreToFollow==1 ); 31055 assert( moreToFollow==0 || moreToFollow==1 );
30846 if( p->iLevel<sizeof(p->bLine) ) p->bLine[p->iLevel] = moreToFollow; 31056 if( p->iLevel<(int)sizeof(p->bLine) ) p->bLine[p->iLevel] = moreToFollow;
30847 return p;
30848} 31057}
30849 31058
30850/* 31059/*
30851** Finished with one layer of the tree 31060** Finished with one layer of the tree
30852*/ 31061*/
30853static void sqlite3TreeViewPop(TreeView *p){ 31062static void sqlite3TreeViewPop(TreeView **pp){
31063 TreeView *p = *pp;
30854 if( p==0 ) return; 31064 if( p==0 ) return;
30855 p->iLevel--; 31065 p->iLevel--;
30856 if( p->iLevel<0 ) sqlite3_free(p); 31066 if( p->iLevel<0 ){
31067 sqlite3_free(p);
31068 *pp = 0;
31069 }
30857} 31070}
30858 31071
30859/* 31072/*
30860** Generate a single line of output for the tree, with a prefix that contains 31073** Generate a single line of output for the tree, with a prefix that contains
30861** all the appropriate tree lines 31074** all the appropriate tree lines
30862*/ 31075*/
30863static void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){ 31076SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
30864 va_list ap; 31077 va_list ap;
30865 int i; 31078 int i;
30866 StrAccum acc; 31079 StrAccum acc;
30867 char zBuf[500]; 31080 char zBuf[1000];
30868 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); 31081 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
30869 if( p ){ 31082 if( p ){
30870 for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){ 31083 for(i=0; i<p->iLevel && i<(int)sizeof(p->bLine)-1; i++){
30871 sqlite3_str_append(&acc, p->bLine[i] ? "| " : " ", 4); 31084 sqlite3_str_append(&acc, p->bLine[i] ? "| " : " ", 4);
30872 } 31085 }
30873 sqlite3_str_append(&acc, p->bLine[i] ? "|-- " : "'-- ", 4); 31086 sqlite3_str_append(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
@@ -30888,11 +31101,58 @@ static void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
30888** Shorthand for starting a new tree item that consists of a single label 31101** Shorthand for starting a new tree item that consists of a single label
30889*/ 31102*/
30890static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){ 31103static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){
30891 p = sqlite3TreeViewPush(p, moreFollows); 31104 sqlite3TreeViewPush(&p, moreFollows);
30892 sqlite3TreeViewLine(p, "%s", zLabel); 31105 sqlite3TreeViewLine(p, "%s", zLabel);
30893} 31106}
30894 31107
30895/* 31108/*
31109** Show a list of Column objects in tree format.
31110*/
31111SQLITE_PRIVATE void sqlite3TreeViewColumnList(
31112 TreeView *pView,
31113 const Column *aCol,
31114 int nCol,
31115 u8 moreToFollow
31116){
31117 int i;
31118 sqlite3TreeViewPush(&pView, moreToFollow);
31119 sqlite3TreeViewLine(pView, "COLUMNS");
31120 for(i=0; i<nCol; i++){
31121 u16 flg = aCol[i].colFlags;
31122 int colMoreToFollow = i<(nCol - 1);
31123 sqlite3TreeViewPush(&pView, colMoreToFollow);
31124 sqlite3TreeViewLine(pView, 0);
31125 printf(" %s", aCol[i].zCnName);
31126 switch( aCol[i].eCType ){
31127 case COLTYPE_ANY: printf(" ANY"); break;
31128 case COLTYPE_BLOB: printf(" BLOB"); break;
31129 case COLTYPE_INT: printf(" INT"); break;
31130 case COLTYPE_INTEGER: printf(" INTEGER"); break;
31131 case COLTYPE_REAL: printf(" REAL"); break;
31132 case COLTYPE_TEXT: printf(" TEXT"); break;
31133 case COLTYPE_CUSTOM: {
31134 if( flg & COLFLAG_HASTYPE ){
31135 const char *z = aCol[i].zCnName;
31136 z += strlen(z)+1;
31137 printf(" X-%s", z);
31138 break;
31139 }
31140 }
31141 }
31142 if( flg & COLFLAG_PRIMKEY ) printf(" PRIMARY KEY");
31143 if( flg & COLFLAG_HIDDEN ) printf(" HIDDEN");
31144#ifdef COLFLAG_NOEXPAND
31145 if( flg & COLFLAG_NOEXPAND ) printf(" NO-EXPAND");
31146#endif
31147 if( flg ) printf(" flags=%04x", flg);
31148 printf("\n");
31149 fflush(stdout);
31150 sqlite3TreeViewPop(&pView);
31151 }
31152 sqlite3TreeViewPop(&pView);
31153}
31154
31155/*
30896** Generate a human-readable description of a WITH clause. 31156** Generate a human-readable description of a WITH clause.
30897*/ 31157*/
30898SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){ 31158SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){
@@ -30905,7 +31165,7 @@ SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 m
30905 sqlite3TreeViewLine(pView, "WITH (0x%p)", pWith); 31165 sqlite3TreeViewLine(pView, "WITH (0x%p)", pWith);
30906 } 31166 }
30907 if( pWith->nCte>0 ){ 31167 if( pWith->nCte>0 ){
30908 pView = sqlite3TreeViewPush(pView, 1); 31168 sqlite3TreeViewPush(&pView, moreToFollow);
30909 for(i=0; i<pWith->nCte; i++){ 31169 for(i=0; i<pWith->nCte; i++){
30910 StrAccum x; 31170 StrAccum x;
30911 char zLine[1000]; 31171 char zLine[1000];
@@ -30921,6 +31181,10 @@ SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 m
30921 } 31181 }
30922 sqlite3_str_appendf(&x, ")"); 31182 sqlite3_str_appendf(&x, ")");
30923 } 31183 }
31184 if( pCte->eM10d!=M10d_Any ){
31185 sqlite3_str_appendf(&x, " %sMATERIALIZED",
31186 pCte->eM10d==M10d_No ? "NOT " : "");
31187 }
30924 if( pCte->pUse ){ 31188 if( pCte->pUse ){
30925 sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse, 31189 sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse,
30926 pCte->pUse->nUse); 31190 pCte->pUse->nUse);
@@ -30928,9 +31192,9 @@ SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 m
30928 sqlite3StrAccumFinish(&x); 31192 sqlite3StrAccumFinish(&x);
30929 sqlite3TreeViewItem(pView, zLine, i<pWith->nCte-1); 31193 sqlite3TreeViewItem(pView, zLine, i<pWith->nCte-1);
30930 sqlite3TreeViewSelect(pView, pCte->pSelect, 0); 31194 sqlite3TreeViewSelect(pView, pCte->pSelect, 0);
30931 sqlite3TreeViewPop(pView); 31195 sqlite3TreeViewPop(&pView);
30932 } 31196 }
30933 sqlite3TreeViewPop(pView); 31197 sqlite3TreeViewPop(&pView);
30934 } 31198 }
30935} 31199}
30936 31200
@@ -30939,10 +31203,12 @@ SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 m
30939*/ 31203*/
30940SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc){ 31204SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc){
30941 int i; 31205 int i;
31206 if( pSrc==0 ) return;
30942 for(i=0; i<pSrc->nSrc; i++){ 31207 for(i=0; i<pSrc->nSrc; i++){
30943 const SrcItem *pItem = &pSrc->a[i]; 31208 const SrcItem *pItem = &pSrc->a[i];
30944 StrAccum x; 31209 StrAccum x;
30945 char zLine[100]; 31210 int n = 0;
31211 char zLine[1000];
30946 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); 31212 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
30947 x.printfFlags |= SQLITE_PRINTF_INTERNAL; 31213 x.printfFlags |= SQLITE_PRINTF_INTERNAL;
30948 sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem); 31214 sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
@@ -30950,26 +31216,48 @@ SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc)
30950 sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx", 31216 sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx",
30951 pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed); 31217 pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed);
30952 } 31218 }
30953 if( pItem->fg.jointype & JT_LEFT ){ 31219 if( (pItem->fg.jointype & (JT_LEFT|JT_RIGHT))==(JT_LEFT|JT_RIGHT) ){
31220 sqlite3_str_appendf(&x, " FULL-OUTER-JOIN");
31221 }else if( pItem->fg.jointype & JT_LEFT ){
30954 sqlite3_str_appendf(&x, " LEFT-JOIN"); 31222 sqlite3_str_appendf(&x, " LEFT-JOIN");
31223 }else if( pItem->fg.jointype & JT_RIGHT ){
31224 sqlite3_str_appendf(&x, " RIGHT-JOIN");
30955 }else if( pItem->fg.jointype & JT_CROSS ){ 31225 }else if( pItem->fg.jointype & JT_CROSS ){
30956 sqlite3_str_appendf(&x, " CROSS-JOIN"); 31226 sqlite3_str_appendf(&x, " CROSS-JOIN");
30957 } 31227 }
31228 if( pItem->fg.jointype & JT_LTORJ ){
31229 sqlite3_str_appendf(&x, " LTORJ");
31230 }
30958 if( pItem->fg.fromDDL ){ 31231 if( pItem->fg.fromDDL ){
30959 sqlite3_str_appendf(&x, " DDL"); 31232 sqlite3_str_appendf(&x, " DDL");
30960 } 31233 }
30961 if( pItem->fg.isCte ){ 31234 if( pItem->fg.isCte ){
30962 sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse); 31235 sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
30963 } 31236 }
31237 if( pItem->fg.isOn || (pItem->fg.isUsing==0 && pItem->u3.pOn!=0) ){
31238 sqlite3_str_appendf(&x, " ON");
31239 }
30964 sqlite3StrAccumFinish(&x); 31240 sqlite3StrAccumFinish(&x);
30965 sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1); 31241 sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
31242 n = 0;
31243 if( pItem->pSelect ) n++;
31244 if( pItem->fg.isTabFunc ) n++;
31245 if( pItem->fg.isUsing ) n++;
31246 if( pItem->fg.isUsing ){
31247 sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING");
31248 }
30966 if( pItem->pSelect ){ 31249 if( pItem->pSelect ){
30967 sqlite3TreeViewSelect(pView, pItem->pSelect, 0); 31250 if( pItem->pTab ){
31251 Table *pTab = pItem->pTab;
31252 sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1);
31253 }
31254 assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
31255 sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0);
30968 } 31256 }
30969 if( pItem->fg.isTabFunc ){ 31257 if( pItem->fg.isTabFunc ){
30970 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:"); 31258 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
30971 } 31259 }
30972 sqlite3TreeViewPop(pView); 31260 sqlite3TreeViewPop(&pView);
30973 } 31261 }
30974} 31262}
30975 31263
@@ -30983,11 +31271,11 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m
30983 sqlite3TreeViewLine(pView, "nil-SELECT"); 31271 sqlite3TreeViewLine(pView, "nil-SELECT");
30984 return; 31272 return;
30985 } 31273 }
30986 pView = sqlite3TreeViewPush(pView, moreToFollow); 31274 sqlite3TreeViewPush(&pView, moreToFollow);
30987 if( p->pWith ){ 31275 if( p->pWith ){
30988 sqlite3TreeViewWith(pView, p->pWith, 1); 31276 sqlite3TreeViewWith(pView, p->pWith, 1);
30989 cnt = 1; 31277 cnt = 1;
30990 sqlite3TreeViewPush(pView, 1); 31278 sqlite3TreeViewPush(&pView, 1);
30991 } 31279 }
30992 do{ 31280 do{
30993 if( p->selFlags & SF_WhereBegin ){ 31281 if( p->selFlags & SF_WhereBegin ){
@@ -31001,7 +31289,7 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m
31001 (int)p->nSelectRow 31289 (int)p->nSelectRow
31002 ); 31290 );
31003 } 31291 }
31004 if( cnt++ ) sqlite3TreeViewPop(pView); 31292 if( cnt++ ) sqlite3TreeViewPop(&pView);
31005 if( p->pPrior ){ 31293 if( p->pPrior ){
31006 n = 1000; 31294 n = 1000;
31007 }else{ 31295 }else{
@@ -31024,24 +31312,24 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m
31024#ifndef SQLITE_OMIT_WINDOWFUNC 31312#ifndef SQLITE_OMIT_WINDOWFUNC
31025 if( p->pWin ){ 31313 if( p->pWin ){
31026 Window *pX; 31314 Window *pX;
31027 pView = sqlite3TreeViewPush(pView, (n--)>0); 31315 sqlite3TreeViewPush(&pView, (n--)>0);
31028 sqlite3TreeViewLine(pView, "window-functions"); 31316 sqlite3TreeViewLine(pView, "window-functions");
31029 for(pX=p->pWin; pX; pX=pX->pNextWin){ 31317 for(pX=p->pWin; pX; pX=pX->pNextWin){
31030 sqlite3TreeViewWinFunc(pView, pX, pX->pNextWin!=0); 31318 sqlite3TreeViewWinFunc(pView, pX, pX->pNextWin!=0);
31031 } 31319 }
31032 sqlite3TreeViewPop(pView); 31320 sqlite3TreeViewPop(&pView);
31033 } 31321 }
31034#endif 31322#endif
31035 if( p->pSrc && p->pSrc->nSrc ){ 31323 if( p->pSrc && p->pSrc->nSrc ){
31036 pView = sqlite3TreeViewPush(pView, (n--)>0); 31324 sqlite3TreeViewPush(&pView, (n--)>0);
31037 sqlite3TreeViewLine(pView, "FROM"); 31325 sqlite3TreeViewLine(pView, "FROM");
31038 sqlite3TreeViewSrcList(pView, p->pSrc); 31326 sqlite3TreeViewSrcList(pView, p->pSrc);
31039 sqlite3TreeViewPop(pView); 31327 sqlite3TreeViewPop(&pView);
31040 } 31328 }
31041 if( p->pWhere ){ 31329 if( p->pWhere ){
31042 sqlite3TreeViewItem(pView, "WHERE", (n--)>0); 31330 sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
31043 sqlite3TreeViewExpr(pView, p->pWhere, 0); 31331 sqlite3TreeViewExpr(pView, p->pWhere, 0);
31044 sqlite3TreeViewPop(pView); 31332 sqlite3TreeViewPop(&pView);
31045 } 31333 }
31046 if( p->pGroupBy ){ 31334 if( p->pGroupBy ){
31047 sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY"); 31335 sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY");
@@ -31049,7 +31337,7 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m
31049 if( p->pHaving ){ 31337 if( p->pHaving ){
31050 sqlite3TreeViewItem(pView, "HAVING", (n--)>0); 31338 sqlite3TreeViewItem(pView, "HAVING", (n--)>0);
31051 sqlite3TreeViewExpr(pView, p->pHaving, 0); 31339 sqlite3TreeViewExpr(pView, p->pHaving, 0);
31052 sqlite3TreeViewPop(pView); 31340 sqlite3TreeViewPop(&pView);
31053 } 31341 }
31054#ifndef SQLITE_OMIT_WINDOWFUNC 31342#ifndef SQLITE_OMIT_WINDOWFUNC
31055 if( p->pWinDefn ){ 31343 if( p->pWinDefn ){
@@ -31058,7 +31346,7 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m
31058 for(pX=p->pWinDefn; pX; pX=pX->pNextWin){ 31346 for(pX=p->pWinDefn; pX; pX=pX->pNextWin){
31059 sqlite3TreeViewWindow(pView, pX, pX->pNextWin!=0); 31347 sqlite3TreeViewWindow(pView, pX, pX->pNextWin!=0);
31060 } 31348 }
31061 sqlite3TreeViewPop(pView); 31349 sqlite3TreeViewPop(&pView);
31062 } 31350 }
31063#endif 31351#endif
31064 if( p->pOrderBy ){ 31352 if( p->pOrderBy ){
@@ -31070,9 +31358,9 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m
31070 if( p->pLimit->pRight ){ 31358 if( p->pLimit->pRight ){
31071 sqlite3TreeViewItem(pView, "OFFSET", (n--)>0); 31359 sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
31072 sqlite3TreeViewExpr(pView, p->pLimit->pRight, 0); 31360 sqlite3TreeViewExpr(pView, p->pLimit->pRight, 0);
31073 sqlite3TreeViewPop(pView); 31361 sqlite3TreeViewPop(&pView);
31074 } 31362 }
31075 sqlite3TreeViewPop(pView); 31363 sqlite3TreeViewPop(&pView);
31076 } 31364 }
31077 if( p->pPrior ){ 31365 if( p->pPrior ){
31078 const char *zOp = "UNION"; 31366 const char *zOp = "UNION";
@@ -31085,7 +31373,7 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m
31085 } 31373 }
31086 p = p->pPrior; 31374 p = p->pPrior;
31087 }while( p!=0 ); 31375 }while( p!=0 );
31088 sqlite3TreeViewPop(pView); 31376 sqlite3TreeViewPop(&pView);
31089} 31377}
31090 31378
31091#ifndef SQLITE_OMIT_WINDOWFUNC 31379#ifndef SQLITE_OMIT_WINDOWFUNC
@@ -31101,24 +31389,24 @@ SQLITE_PRIVATE void sqlite3TreeViewBound(
31101 switch( eBound ){ 31389 switch( eBound ){
31102 case TK_UNBOUNDED: { 31390 case TK_UNBOUNDED: {
31103 sqlite3TreeViewItem(pView, "UNBOUNDED", moreToFollow); 31391 sqlite3TreeViewItem(pView, "UNBOUNDED", moreToFollow);
31104 sqlite3TreeViewPop(pView); 31392 sqlite3TreeViewPop(&pView);
31105 break; 31393 break;
31106 } 31394 }
31107 case TK_CURRENT: { 31395 case TK_CURRENT: {
31108 sqlite3TreeViewItem(pView, "CURRENT", moreToFollow); 31396 sqlite3TreeViewItem(pView, "CURRENT", moreToFollow);
31109 sqlite3TreeViewPop(pView); 31397 sqlite3TreeViewPop(&pView);
31110 break; 31398 break;
31111 } 31399 }
31112 case TK_PRECEDING: { 31400 case TK_PRECEDING: {
31113 sqlite3TreeViewItem(pView, "PRECEDING", moreToFollow); 31401 sqlite3TreeViewItem(pView, "PRECEDING", moreToFollow);
31114 sqlite3TreeViewExpr(pView, pExpr, 0); 31402 sqlite3TreeViewExpr(pView, pExpr, 0);
31115 sqlite3TreeViewPop(pView); 31403 sqlite3TreeViewPop(&pView);
31116 break; 31404 break;
31117 } 31405 }
31118 case TK_FOLLOWING: { 31406 case TK_FOLLOWING: {
31119 sqlite3TreeViewItem(pView, "FOLLOWING", moreToFollow); 31407 sqlite3TreeViewItem(pView, "FOLLOWING", moreToFollow);
31120 sqlite3TreeViewExpr(pView, pExpr, 0); 31408 sqlite3TreeViewExpr(pView, pExpr, 0);
31121 sqlite3TreeViewPop(pView); 31409 sqlite3TreeViewPop(&pView);
31122 break; 31410 break;
31123 } 31411 }
31124 } 31412 }
@@ -31131,12 +31419,13 @@ SQLITE_PRIVATE void sqlite3TreeViewBound(
31131*/ 31419*/
31132SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){ 31420SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
31133 int nElement = 0; 31421 int nElement = 0;
31422 if( pWin==0 ) return;
31134 if( pWin->pFilter ){ 31423 if( pWin->pFilter ){
31135 sqlite3TreeViewItem(pView, "FILTER", 1); 31424 sqlite3TreeViewItem(pView, "FILTER", 1);
31136 sqlite3TreeViewExpr(pView, pWin->pFilter, 0); 31425 sqlite3TreeViewExpr(pView, pWin->pFilter, 0);
31137 sqlite3TreeViewPop(pView); 31426 sqlite3TreeViewPop(&pView);
31138 } 31427 }
31139 pView = sqlite3TreeViewPush(pView, more); 31428 sqlite3TreeViewPush(&pView, more);
31140 if( pWin->zName ){ 31429 if( pWin->zName ){
31141 sqlite3TreeViewLine(pView, "OVER %s (%p)", pWin->zName, pWin); 31430 sqlite3TreeViewLine(pView, "OVER %s (%p)", pWin->zName, pWin);
31142 }else{ 31431 }else{
@@ -31147,9 +31436,9 @@ SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u
31147 if( pWin->eFrmType ) nElement++; 31436 if( pWin->eFrmType ) nElement++;
31148 if( pWin->eExclude ) nElement++; 31437 if( pWin->eExclude ) nElement++;
31149 if( pWin->zBase ){ 31438 if( pWin->zBase ){
31150 sqlite3TreeViewPush(pView, (--nElement)>0); 31439 sqlite3TreeViewPush(&pView, (--nElement)>0);
31151 sqlite3TreeViewLine(pView, "window: %s", pWin->zBase); 31440 sqlite3TreeViewLine(pView, "window: %s", pWin->zBase);
31152 sqlite3TreeViewPop(pView); 31441 sqlite3TreeViewPop(&pView);
31153 } 31442 }
31154 if( pWin->pPartition ){ 31443 if( pWin->pPartition ){
31155 sqlite3TreeViewExprList(pView, pWin->pPartition, nElement>0,"PARTITION-BY"); 31444 sqlite3TreeViewExprList(pView, pWin->pPartition, nElement>0,"PARTITION-BY");
@@ -31167,7 +31456,7 @@ SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u
31167 sqlite3TreeViewItem(pView, zBuf, (--nElement)>0); 31456 sqlite3TreeViewItem(pView, zBuf, (--nElement)>0);
31168 sqlite3TreeViewBound(pView, pWin->eStart, pWin->pStart, 1); 31457 sqlite3TreeViewBound(pView, pWin->eStart, pWin->pStart, 1);
31169 sqlite3TreeViewBound(pView, pWin->eEnd, pWin->pEnd, 0); 31458 sqlite3TreeViewBound(pView, pWin->eEnd, pWin->pEnd, 0);
31170 sqlite3TreeViewPop(pView); 31459 sqlite3TreeViewPop(&pView);
31171 } 31460 }
31172 if( pWin->eExclude ){ 31461 if( pWin->eExclude ){
31173 char zBuf[30]; 31462 char zBuf[30];
@@ -31182,11 +31471,11 @@ SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u
31182 zExclude = zBuf; 31471 zExclude = zBuf;
31183 break; 31472 break;
31184 } 31473 }
31185 sqlite3TreeViewPush(pView, 0); 31474 sqlite3TreeViewPush(&pView, 0);
31186 sqlite3TreeViewLine(pView, "EXCLUDE %s", zExclude); 31475 sqlite3TreeViewLine(pView, "EXCLUDE %s", zExclude);
31187 sqlite3TreeViewPop(pView); 31476 sqlite3TreeViewPop(&pView);
31188 } 31477 }
31189 sqlite3TreeViewPop(pView); 31478 sqlite3TreeViewPop(&pView);
31190} 31479}
31191#endif /* SQLITE_OMIT_WINDOWFUNC */ 31480#endif /* SQLITE_OMIT_WINDOWFUNC */
31192 31481
@@ -31195,11 +31484,12 @@ SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u
31195** Generate a human-readable explanation for a Window Function object 31484** Generate a human-readable explanation for a Window Function object
31196*/ 31485*/
31197SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){ 31486SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){
31198 pView = sqlite3TreeViewPush(pView, more); 31487 if( pWin==0 ) return;
31488 sqlite3TreeViewPush(&pView, more);
31199 sqlite3TreeViewLine(pView, "WINFUNC %s(%d)", 31489 sqlite3TreeViewLine(pView, "WINFUNC %s(%d)",
31200 pWin->pFunc->zName, pWin->pFunc->nArg); 31490 pWin->pWFunc->zName, pWin->pWFunc->nArg);
31201 sqlite3TreeViewWindow(pView, pWin, 0); 31491 sqlite3TreeViewWindow(pView, pWin, 0);
31202 sqlite3TreeViewPop(pView); 31492 sqlite3TreeViewPop(&pView);
31203} 31493}
31204#endif /* SQLITE_OMIT_WINDOWFUNC */ 31494#endif /* SQLITE_OMIT_WINDOWFUNC */
31205 31495
@@ -31210,10 +31500,10 @@ SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 m
31210 const char *zBinOp = 0; /* Binary operator */ 31500 const char *zBinOp = 0; /* Binary operator */
31211 const char *zUniOp = 0; /* Unary operator */ 31501 const char *zUniOp = 0; /* Unary operator */
31212 char zFlgs[200]; 31502 char zFlgs[200];
31213 pView = sqlite3TreeViewPush(pView, moreToFollow); 31503 sqlite3TreeViewPush(&pView, moreToFollow);
31214 if( pExpr==0 ){ 31504 if( pExpr==0 ){
31215 sqlite3TreeViewLine(pView, "nil"); 31505 sqlite3TreeViewLine(pView, "nil");
31216 sqlite3TreeViewPop(pView); 31506 sqlite3TreeViewPop(&pView);
31217 return; 31507 return;
31218 } 31508 }
31219 if( pExpr->flags || pExpr->affExpr || pExpr->vvaFlags ){ 31509 if( pExpr->flags || pExpr->affExpr || pExpr->vvaFlags ){
@@ -31221,8 +31511,11 @@ SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 m
31221 sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0); 31511 sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0);
31222 sqlite3_str_appendf(&x, " fg.af=%x.%c", 31512 sqlite3_str_appendf(&x, " fg.af=%x.%c",
31223 pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n'); 31513 pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
31224 if( ExprHasProperty(pExpr, EP_FromJoin) ){ 31514 if( ExprHasProperty(pExpr, EP_OuterON) ){
31225 sqlite3_str_appendf(&x, " iRJT=%d", pExpr->w.iRightJoinTable); 31515 sqlite3_str_appendf(&x, " outer.iJoin=%d", pExpr->w.iJoin);
31516 }
31517 if( ExprHasProperty(pExpr, EP_InnerON) ){
31518 sqlite3_str_appendf(&x, " inner.iJoin=%d", pExpr->w.iJoin);
31226 } 31519 }
31227 if( ExprHasProperty(pExpr, EP_FromDDL) ){ 31520 if( ExprHasProperty(pExpr, EP_FromDDL) ){
31228 sqlite3_str_appendf(&x, " DDL"); 31521 sqlite3_str_appendf(&x, " DDL");
@@ -31446,7 +31739,17 @@ SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 m
31446 break; 31739 break;
31447 } 31740 }
31448 case TK_IN: { 31741 case TK_IN: {
31449 sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags); 31742 sqlite3_str *pStr = sqlite3_str_new(0);
31743 char *z;
31744 sqlite3_str_appendf(pStr, "IN flags=0x%x", pExpr->flags);
31745 if( pExpr->iTable ) sqlite3_str_appendf(pStr, " iTable=%d",pExpr->iTable);
31746 if( ExprHasProperty(pExpr, EP_Subrtn) ){
31747 sqlite3_str_appendf(pStr, " subrtn(%d,%d)",
31748 pExpr->y.sub.regReturn, pExpr->y.sub.iAddr);
31749 }
31750 z = sqlite3_str_finish(pStr);
31751 sqlite3TreeViewLine(pView, z);
31752 sqlite3_free(z);
31450 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); 31753 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
31451 if( ExprUseXSelect(pExpr) ){ 31754 if( ExprUseXSelect(pExpr) ){
31452 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); 31755 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
@@ -31570,7 +31873,7 @@ SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 m
31570 sqlite3TreeViewLine(pView, "%s%s", zUniOp, zFlgs); 31873 sqlite3TreeViewLine(pView, "%s%s", zUniOp, zFlgs);
31571 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); 31874 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
31572 } 31875 }
31573 sqlite3TreeViewPop(pView); 31876 sqlite3TreeViewPop(&pView);
31574} 31877}
31575 31878
31576 31879
@@ -31592,13 +31895,25 @@ SQLITE_PRIVATE void sqlite3TreeViewBareExprList(
31592 int j = pList->a[i].u.x.iOrderByCol; 31895 int j = pList->a[i].u.x.iOrderByCol;
31593 char *zName = pList->a[i].zEName; 31896 char *zName = pList->a[i].zEName;
31594 int moreToFollow = i<pList->nExpr - 1; 31897 int moreToFollow = i<pList->nExpr - 1;
31595 if( pList->a[i].eEName!=ENAME_NAME ) zName = 0;
31596 if( j || zName ){ 31898 if( j || zName ){
31597 sqlite3TreeViewPush(pView, moreToFollow); 31899 sqlite3TreeViewPush(&pView, moreToFollow);
31598 moreToFollow = 0; 31900 moreToFollow = 0;
31599 sqlite3TreeViewLine(pView, 0); 31901 sqlite3TreeViewLine(pView, 0);
31600 if( zName ){ 31902 if( zName ){
31601 fprintf(stdout, "AS %s ", zName); 31903 switch( pList->a[i].fg.eEName ){
31904 default:
31905 fprintf(stdout, "AS %s ", zName);
31906 break;
31907 case ENAME_TAB:
31908 fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName);
31909 if( pList->a[i].fg.bUsed ) fprintf(stdout, "(used) ");
31910 if( pList->a[i].fg.bUsingTerm ) fprintf(stdout, "(USING-term) ");
31911 if( pList->a[i].fg.bNoExpand ) fprintf(stdout, "(NoExpand) ");
31912 break;
31913 case ENAME_SPAN:
31914 fprintf(stdout, "SPAN(\"%s\") ", zName);
31915 break;
31916 }
31602 } 31917 }
31603 if( j ){ 31918 if( j ){
31604 fprintf(stdout, "iOrderByCol=%d", j); 31919 fprintf(stdout, "iOrderByCol=%d", j);
@@ -31608,7 +31923,7 @@ SQLITE_PRIVATE void sqlite3TreeViewBareExprList(
31608 } 31923 }
31609 sqlite3TreeViewExpr(pView, pList->a[i].pExpr, moreToFollow); 31924 sqlite3TreeViewExpr(pView, pList->a[i].pExpr, moreToFollow);
31610 if( j || zName ){ 31925 if( j || zName ){
31611 sqlite3TreeViewPop(pView); 31926 sqlite3TreeViewPop(&pView);
31612 } 31927 }
31613 } 31928 }
31614 } 31929 }
@@ -31619,10 +31934,377 @@ SQLITE_PRIVATE void sqlite3TreeViewExprList(
31619 u8 moreToFollow, 31934 u8 moreToFollow,
31620 const char *zLabel 31935 const char *zLabel
31621){ 31936){
31622 pView = sqlite3TreeViewPush(pView, moreToFollow); 31937 sqlite3TreeViewPush(&pView, moreToFollow);
31623 sqlite3TreeViewBareExprList(pView, pList, zLabel); 31938 sqlite3TreeViewBareExprList(pView, pList, zLabel);
31624 sqlite3TreeViewPop(pView); 31939 sqlite3TreeViewPop(&pView);
31940}
31941
31942/*
31943** Generate a human-readable explanation of an id-list.
31944*/
31945SQLITE_PRIVATE void sqlite3TreeViewBareIdList(
31946 TreeView *pView,
31947 const IdList *pList,
31948 const char *zLabel
31949){
31950 if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST";
31951 if( pList==0 ){
31952 sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
31953 }else{
31954 int i;
31955 sqlite3TreeViewLine(pView, "%s", zLabel);
31956 for(i=0; i<pList->nId; i++){
31957 char *zName = pList->a[i].zName;
31958 int moreToFollow = i<pList->nId - 1;
31959 if( zName==0 ) zName = "(null)";
31960 sqlite3TreeViewPush(&pView, moreToFollow);
31961 sqlite3TreeViewLine(pView, 0);
31962 if( pList->eU4==EU4_NONE ){
31963 fprintf(stdout, "%s\n", zName);
31964 }else if( pList->eU4==EU4_IDX ){
31965 fprintf(stdout, "%s (%d)\n", zName, pList->a[i].u4.idx);
31966 }else{
31967 assert( pList->eU4==EU4_EXPR );
31968 if( pList->a[i].u4.pExpr==0 ){
31969 fprintf(stdout, "%s (pExpr=NULL)\n", zName);
31970 }else{
31971 fprintf(stdout, "%s\n", zName);
31972 sqlite3TreeViewPush(&pView, i<pList->nId-1);
31973 sqlite3TreeViewExpr(pView, pList->a[i].u4.pExpr, 0);
31974 sqlite3TreeViewPop(&pView);
31975 }
31976 }
31977 sqlite3TreeViewPop(&pView);
31978 }
31979 }
31980}
31981SQLITE_PRIVATE void sqlite3TreeViewIdList(
31982 TreeView *pView,
31983 const IdList *pList,
31984 u8 moreToFollow,
31985 const char *zLabel
31986){
31987 sqlite3TreeViewPush(&pView, moreToFollow);
31988 sqlite3TreeViewBareIdList(pView, pList, zLabel);
31989 sqlite3TreeViewPop(&pView);
31990}
31991
31992/*
31993** Generate a human-readable explanation of a list of Upsert objects
31994*/
31995SQLITE_PRIVATE void sqlite3TreeViewUpsert(
31996 TreeView *pView,
31997 const Upsert *pUpsert,
31998 u8 moreToFollow
31999){
32000 if( pUpsert==0 ) return;
32001 sqlite3TreeViewPush(&pView, moreToFollow);
32002 while( pUpsert ){
32003 int n;
32004 sqlite3TreeViewPush(&pView, pUpsert->pNextUpsert!=0 || moreToFollow);
32005 sqlite3TreeViewLine(pView, "ON CONFLICT DO %s",
32006 pUpsert->isDoUpdate ? "UPDATE" : "NOTHING");
32007 n = (pUpsert->pUpsertSet!=0) + (pUpsert->pUpsertWhere!=0);
32008 sqlite3TreeViewExprList(pView, pUpsert->pUpsertTarget, (n--)>0, "TARGET");
32009 sqlite3TreeViewExprList(pView, pUpsert->pUpsertSet, (n--)>0, "SET");
32010 if( pUpsert->pUpsertWhere ){
32011 sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
32012 sqlite3TreeViewExpr(pView, pUpsert->pUpsertWhere, 0);
32013 sqlite3TreeViewPop(&pView);
32014 }
32015 sqlite3TreeViewPop(&pView);
32016 pUpsert = pUpsert->pNextUpsert;
32017 }
32018 sqlite3TreeViewPop(&pView);
32019}
32020
32021#if TREETRACE_ENABLED
32022/*
32023** Generate a human-readable diagram of the data structure that go
32024** into generating an DELETE statement.
32025*/
32026SQLITE_PRIVATE void sqlite3TreeViewDelete(
32027 const With *pWith,
32028 const SrcList *pTabList,
32029 const Expr *pWhere,
32030 const ExprList *pOrderBy,
32031 const Expr *pLimit,
32032 const Trigger *pTrigger
32033){
32034 int n = 0;
32035 TreeView *pView = 0;
32036 sqlite3TreeViewPush(&pView, 0);
32037 sqlite3TreeViewLine(pView, "DELETE");
32038 if( pWith ) n++;
32039 if( pTabList ) n++;
32040 if( pWhere ) n++;
32041 if( pOrderBy ) n++;
32042 if( pLimit ) n++;
32043 if( pTrigger ) n++;
32044 if( pWith ){
32045 sqlite3TreeViewPush(&pView, (--n)>0);
32046 sqlite3TreeViewWith(pView, pWith, 0);
32047 sqlite3TreeViewPop(&pView);
32048 }
32049 if( pTabList ){
32050 sqlite3TreeViewPush(&pView, (--n)>0);
32051 sqlite3TreeViewLine(pView, "FROM");
32052 sqlite3TreeViewSrcList(pView, pTabList);
32053 sqlite3TreeViewPop(&pView);
32054 }
32055 if( pWhere ){
32056 sqlite3TreeViewPush(&pView, (--n)>0);
32057 sqlite3TreeViewLine(pView, "WHERE");
32058 sqlite3TreeViewExpr(pView, pWhere, 0);
32059 sqlite3TreeViewPop(&pView);
32060 }
32061 if( pOrderBy ){
32062 sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY");
32063 }
32064 if( pLimit ){
32065 sqlite3TreeViewPush(&pView, (--n)>0);
32066 sqlite3TreeViewLine(pView, "LIMIT");
32067 sqlite3TreeViewExpr(pView, pLimit, 0);
32068 sqlite3TreeViewPop(&pView);
32069 }
32070 if( pTrigger ){
32071 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
32072 }
32073 sqlite3TreeViewPop(&pView);
32074}
32075#endif /* TREETRACE_ENABLED */
32076
32077#if TREETRACE_ENABLED
32078/*
32079** Generate a human-readable diagram of the data structure that go
32080** into generating an INSERT statement.
32081*/
32082SQLITE_PRIVATE void sqlite3TreeViewInsert(
32083 const With *pWith,
32084 const SrcList *pTabList,
32085 const IdList *pColumnList,
32086 const Select *pSelect,
32087 const ExprList *pExprList,
32088 int onError,
32089 const Upsert *pUpsert,
32090 const Trigger *pTrigger
32091){
32092 TreeView *pView = 0;
32093 int n = 0;
32094 const char *zLabel = "INSERT";
32095 switch( onError ){
32096 case OE_Replace: zLabel = "REPLACE"; break;
32097 case OE_Ignore: zLabel = "INSERT OR IGNORE"; break;
32098 case OE_Rollback: zLabel = "INSERT OR ROLLBACK"; break;
32099 case OE_Abort: zLabel = "INSERT OR ABORT"; break;
32100 case OE_Fail: zLabel = "INSERT OR FAIL"; break;
32101 }
32102 sqlite3TreeViewPush(&pView, 0);
32103 sqlite3TreeViewLine(pView, zLabel);
32104 if( pWith ) n++;
32105 if( pTabList ) n++;
32106 if( pColumnList ) n++;
32107 if( pSelect ) n++;
32108 if( pExprList ) n++;
32109 if( pUpsert ) n++;
32110 if( pTrigger ) n++;
32111 if( pWith ){
32112 sqlite3TreeViewPush(&pView, (--n)>0);
32113 sqlite3TreeViewWith(pView, pWith, 0);
32114 sqlite3TreeViewPop(&pView);
32115 }
32116 if( pTabList ){
32117 sqlite3TreeViewPush(&pView, (--n)>0);
32118 sqlite3TreeViewLine(pView, "INTO");
32119 sqlite3TreeViewSrcList(pView, pTabList);
32120 sqlite3TreeViewPop(&pView);
32121 }
32122 if( pColumnList ){
32123 sqlite3TreeViewIdList(pView, pColumnList, (--n)>0, "COLUMNS");
32124 }
32125 if( pSelect ){
32126 sqlite3TreeViewPush(&pView, (--n)>0);
32127 sqlite3TreeViewLine(pView, "DATA-SOURCE");
32128 sqlite3TreeViewSelect(pView, pSelect, 0);
32129 sqlite3TreeViewPop(&pView);
32130 }
32131 if( pExprList ){
32132 sqlite3TreeViewExprList(pView, pExprList, (--n)>0, "VALUES");
32133 }
32134 if( pUpsert ){
32135 sqlite3TreeViewPush(&pView, (--n)>0);
32136 sqlite3TreeViewLine(pView, "UPSERT");
32137 sqlite3TreeViewUpsert(pView, pUpsert, 0);
32138 sqlite3TreeViewPop(&pView);
32139 }
32140 if( pTrigger ){
32141 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
32142 }
32143 sqlite3TreeViewPop(&pView);
31625} 32144}
32145#endif /* TREETRACE_ENABLED */
32146
32147#if TREETRACE_ENABLED
32148/*
32149** Generate a human-readable diagram of the data structure that go
32150** into generating an UPDATE statement.
32151*/
32152SQLITE_PRIVATE void sqlite3TreeViewUpdate(
32153 const With *pWith,
32154 const SrcList *pTabList,
32155 const ExprList *pChanges,
32156 const Expr *pWhere,
32157 int onError,
32158 const ExprList *pOrderBy,
32159 const Expr *pLimit,
32160 const Upsert *pUpsert,
32161 const Trigger *pTrigger
32162){
32163 int n = 0;
32164 TreeView *pView = 0;
32165 const char *zLabel = "UPDATE";
32166 switch( onError ){
32167 case OE_Replace: zLabel = "UPDATE OR REPLACE"; break;
32168 case OE_Ignore: zLabel = "UPDATE OR IGNORE"; break;
32169 case OE_Rollback: zLabel = "UPDATE OR ROLLBACK"; break;
32170 case OE_Abort: zLabel = "UPDATE OR ABORT"; break;
32171 case OE_Fail: zLabel = "UPDATE OR FAIL"; break;
32172 }
32173 sqlite3TreeViewPush(&pView, 0);
32174 sqlite3TreeViewLine(pView, zLabel);
32175 if( pWith ) n++;
32176 if( pTabList ) n++;
32177 if( pChanges ) n++;
32178 if( pWhere ) n++;
32179 if( pOrderBy ) n++;
32180 if( pLimit ) n++;
32181 if( pUpsert ) n++;
32182 if( pTrigger ) n++;
32183 if( pWith ){
32184 sqlite3TreeViewPush(&pView, (--n)>0);
32185 sqlite3TreeViewWith(pView, pWith, 0);
32186 sqlite3TreeViewPop(&pView);
32187 }
32188 if( pTabList ){
32189 sqlite3TreeViewPush(&pView, (--n)>0);
32190 sqlite3TreeViewLine(pView, "FROM");
32191 sqlite3TreeViewSrcList(pView, pTabList);
32192 sqlite3TreeViewPop(&pView);
32193 }
32194 if( pChanges ){
32195 sqlite3TreeViewExprList(pView, pChanges, (--n)>0, "SET");
32196 }
32197 if( pWhere ){
32198 sqlite3TreeViewPush(&pView, (--n)>0);
32199 sqlite3TreeViewLine(pView, "WHERE");
32200 sqlite3TreeViewExpr(pView, pWhere, 0);
32201 sqlite3TreeViewPop(&pView);
32202 }
32203 if( pOrderBy ){
32204 sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY");
32205 }
32206 if( pLimit ){
32207 sqlite3TreeViewPush(&pView, (--n)>0);
32208 sqlite3TreeViewLine(pView, "LIMIT");
32209 sqlite3TreeViewExpr(pView, pLimit, 0);
32210 sqlite3TreeViewPop(&pView);
32211 }
32212 if( pUpsert ){
32213 sqlite3TreeViewPush(&pView, (--n)>0);
32214 sqlite3TreeViewLine(pView, "UPSERT");
32215 sqlite3TreeViewUpsert(pView, pUpsert, 0);
32216 sqlite3TreeViewPop(&pView);
32217 }
32218 if( pTrigger ){
32219 sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
32220 }
32221 sqlite3TreeViewPop(&pView);
32222}
32223#endif /* TREETRACE_ENABLED */
32224
32225#ifndef SQLITE_OMIT_TRIGGER
32226/*
32227** Show a human-readable graph of a TriggerStep
32228*/
32229SQLITE_PRIVATE void sqlite3TreeViewTriggerStep(
32230 TreeView *pView,
32231 const TriggerStep *pStep,
32232 u8 moreToFollow,
32233 u8 showFullList
32234){
32235 int cnt = 0;
32236 if( pStep==0 ) return;
32237 sqlite3TreeViewPush(&pView,
32238 moreToFollow || (showFullList && pStep->pNext!=0));
32239 do{
32240 if( cnt++ && pStep->pNext==0 ){
32241 sqlite3TreeViewPop(&pView);
32242 sqlite3TreeViewPush(&pView, 0);
32243 }
32244 sqlite3TreeViewLine(pView, "%s", pStep->zSpan ? pStep->zSpan : "RETURNING");
32245 }while( showFullList && (pStep = pStep->pNext)!=0 );
32246 sqlite3TreeViewPop(&pView);
32247}
32248
32249/*
32250** Show a human-readable graph of a Trigger
32251*/
32252SQLITE_PRIVATE void sqlite3TreeViewTrigger(
32253 TreeView *pView,
32254 const Trigger *pTrigger,
32255 u8 moreToFollow,
32256 u8 showFullList
32257){
32258 int cnt = 0;
32259 if( pTrigger==0 ) return;
32260 sqlite3TreeViewPush(&pView,
32261 moreToFollow || (showFullList && pTrigger->pNext!=0));
32262 do{
32263 if( cnt++ && pTrigger->pNext==0 ){
32264 sqlite3TreeViewPop(&pView);
32265 sqlite3TreeViewPush(&pView, 0);
32266 }
32267 sqlite3TreeViewLine(pView, "TRIGGER %s", pTrigger->zName);
32268 sqlite3TreeViewPush(&pView, 0);
32269 sqlite3TreeViewTriggerStep(pView, pTrigger->step_list, 0, 1);
32270 sqlite3TreeViewPop(&pView);
32271 }while( showFullList && (pTrigger = pTrigger->pNext)!=0 );
32272 sqlite3TreeViewPop(&pView);
32273}
32274#endif /* SQLITE_OMIT_TRIGGER */
32275
32276
32277/*
32278** These simplified versions of the tree-view routines omit unnecessary
32279** parameters. These variants are intended to be used from a symbolic
32280** debugger, such as "gdb", during interactive debugging sessions.
32281**
32282** This routines are given external linkage so that they will always be
32283** accessible to the debugging, and to avoid warnings about unused
32284** functions. But these routines only exist in debugging builds, so they
32285** do not contaminate the interface.
32286*/
32287SQLITE_PRIVATE void sqlite3ShowExpr(const Expr *p){ sqlite3TreeViewExpr(0,p,0); }
32288SQLITE_PRIVATE void sqlite3ShowExprList(const ExprList *p){ sqlite3TreeViewExprList(0,p,0,0);}
32289SQLITE_PRIVATE void sqlite3ShowIdList(const IdList *p){ sqlite3TreeViewIdList(0,p,0,0); }
32290SQLITE_PRIVATE void sqlite3ShowSrcList(const SrcList *p){ sqlite3TreeViewSrcList(0,p); }
32291SQLITE_PRIVATE void sqlite3ShowSelect(const Select *p){ sqlite3TreeViewSelect(0,p,0); }
32292SQLITE_PRIVATE void sqlite3ShowWith(const With *p){ sqlite3TreeViewWith(0,p,0); }
32293SQLITE_PRIVATE void sqlite3ShowUpsert(const Upsert *p){ sqlite3TreeViewUpsert(0,p,0); }
32294#ifndef SQLITE_OMIT_TRIGGER
32295SQLITE_PRIVATE void sqlite3ShowTriggerStep(const TriggerStep *p){
32296 sqlite3TreeViewTriggerStep(0,p,0,0);
32297}
32298SQLITE_PRIVATE void sqlite3ShowTriggerStepList(const TriggerStep *p){
32299 sqlite3TreeViewTriggerStep(0,p,0,1);
32300}
32301SQLITE_PRIVATE void sqlite3ShowTrigger(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,0); }
32302SQLITE_PRIVATE void sqlite3ShowTriggerList(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,1);}
32303#endif
32304#ifndef SQLITE_OMIT_WINDOWFUNC
32305SQLITE_PRIVATE void sqlite3ShowWindow(const Window *p){ sqlite3TreeViewWindow(0,p,0); }
32306SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window *p){ sqlite3TreeViewWinFunc(0,p,0); }
32307#endif
31626 32308
31627#endif /* SQLITE_DEBUG */ 32309#endif /* SQLITE_DEBUG */
31628 32310
@@ -34590,42 +35272,42 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
34590 /* 0 */ "Savepoint" OpHelp(""), 35272 /* 0 */ "Savepoint" OpHelp(""),
34591 /* 1 */ "AutoCommit" OpHelp(""), 35273 /* 1 */ "AutoCommit" OpHelp(""),
34592 /* 2 */ "Transaction" OpHelp(""), 35274 /* 2 */ "Transaction" OpHelp(""),
34593 /* 3 */ "SorterNext" OpHelp(""), 35275 /* 3 */ "Checkpoint" OpHelp(""),
34594 /* 4 */ "Prev" OpHelp(""), 35276 /* 4 */ "JournalMode" OpHelp(""),
34595 /* 5 */ "Next" OpHelp(""), 35277 /* 5 */ "Vacuum" OpHelp(""),
34596 /* 6 */ "Checkpoint" OpHelp(""), 35278 /* 6 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
34597 /* 7 */ "JournalMode" OpHelp(""), 35279 /* 7 */ "VUpdate" OpHelp("data=r[P3@P2]"),
34598 /* 8 */ "Vacuum" OpHelp(""), 35280 /* 8 */ "Goto" OpHelp(""),
34599 /* 9 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"), 35281 /* 9 */ "Gosub" OpHelp(""),
34600 /* 10 */ "VUpdate" OpHelp("data=r[P3@P2]"), 35282 /* 10 */ "InitCoroutine" OpHelp(""),
34601 /* 11 */ "Goto" OpHelp(""), 35283 /* 11 */ "Yield" OpHelp(""),
34602 /* 12 */ "Gosub" OpHelp(""), 35284 /* 12 */ "MustBeInt" OpHelp(""),
34603 /* 13 */ "InitCoroutine" OpHelp(""), 35285 /* 13 */ "Jump" OpHelp(""),
34604 /* 14 */ "Yield" OpHelp(""), 35286 /* 14 */ "Once" OpHelp(""),
34605 /* 15 */ "MustBeInt" OpHelp(""), 35287 /* 15 */ "If" OpHelp(""),
34606 /* 16 */ "Jump" OpHelp(""), 35288 /* 16 */ "IfNot" OpHelp(""),
34607 /* 17 */ "Once" OpHelp(""), 35289 /* 17 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"),
34608 /* 18 */ "If" OpHelp(""), 35290 /* 18 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
34609 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"), 35291 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
34610 /* 20 */ "IfNot" OpHelp(""), 35292 /* 20 */ "SeekLT" OpHelp("key=r[P3@P4]"),
34611 /* 21 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"), 35293 /* 21 */ "SeekLE" OpHelp("key=r[P3@P4]"),
34612 /* 22 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"), 35294 /* 22 */ "SeekGE" OpHelp("key=r[P3@P4]"),
34613 /* 23 */ "SeekLT" OpHelp("key=r[P3@P4]"), 35295 /* 23 */ "SeekGT" OpHelp("key=r[P3@P4]"),
34614 /* 24 */ "SeekLE" OpHelp("key=r[P3@P4]"), 35296 /* 24 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"),
34615 /* 25 */ "SeekGE" OpHelp("key=r[P3@P4]"), 35297 /* 25 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
34616 /* 26 */ "SeekGT" OpHelp("key=r[P3@P4]"), 35298 /* 26 */ "NoConflict" OpHelp("key=r[P3@P4]"),
34617 /* 27 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"), 35299 /* 27 */ "NotFound" OpHelp("key=r[P3@P4]"),
34618 /* 28 */ "IfNoHope" OpHelp("key=r[P3@P4]"), 35300 /* 28 */ "Found" OpHelp("key=r[P3@P4]"),
34619 /* 29 */ "NoConflict" OpHelp("key=r[P3@P4]"), 35301 /* 29 */ "SeekRowid" OpHelp("intkey=r[P3]"),
34620 /* 30 */ "NotFound" OpHelp("key=r[P3@P4]"), 35302 /* 30 */ "NotExists" OpHelp("intkey=r[P3]"),
34621 /* 31 */ "Found" OpHelp("key=r[P3@P4]"), 35303 /* 31 */ "Last" OpHelp(""),
34622 /* 32 */ "SeekRowid" OpHelp("intkey=r[P3]"), 35304 /* 32 */ "IfSmaller" OpHelp(""),
34623 /* 33 */ "NotExists" OpHelp("intkey=r[P3]"), 35305 /* 33 */ "SorterSort" OpHelp(""),
34624 /* 34 */ "Last" OpHelp(""), 35306 /* 34 */ "Sort" OpHelp(""),
34625 /* 35 */ "IfSmaller" OpHelp(""), 35307 /* 35 */ "Rewind" OpHelp(""),
34626 /* 36 */ "SorterSort" OpHelp(""), 35308 /* 36 */ "SorterNext" OpHelp(""),
34627 /* 37 */ "Sort" OpHelp(""), 35309 /* 37 */ "Prev" OpHelp(""),
34628 /* 38 */ "Rewind" OpHelp(""), 35310 /* 38 */ "Next" OpHelp(""),
34629 /* 39 */ "IdxLE" OpHelp("key=r[P3@P4]"), 35311 /* 39 */ "IdxLE" OpHelp("key=r[P3@P4]"),
34630 /* 40 */ "IdxGT" OpHelp("key=r[P3@P4]"), 35312 /* 40 */ "IdxGT" OpHelp("key=r[P3@P4]"),
34631 /* 41 */ "IdxLT" OpHelp("key=r[P3@P4]"), 35313 /* 41 */ "IdxLT" OpHelp("key=r[P3@P4]"),
@@ -34661,34 +35343,34 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
34661 /* 71 */ "Integer" OpHelp("r[P2]=P1"), 35343 /* 71 */ "Integer" OpHelp("r[P2]=P1"),
34662 /* 72 */ "Int64" OpHelp("r[P2]=P4"), 35344 /* 72 */ "Int64" OpHelp("r[P2]=P4"),
34663 /* 73 */ "String" OpHelp("r[P2]='P4' (len=P1)"), 35345 /* 73 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
34664 /* 74 */ "Null" OpHelp("r[P2..P3]=NULL"), 35346 /* 74 */ "BeginSubrtn" OpHelp("r[P2]=NULL"),
34665 /* 75 */ "SoftNull" OpHelp("r[P1]=NULL"), 35347 /* 75 */ "Null" OpHelp("r[P2..P3]=NULL"),
34666 /* 76 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), 35348 /* 76 */ "SoftNull" OpHelp("r[P1]=NULL"),
34667 /* 77 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), 35349 /* 77 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
34668 /* 78 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), 35350 /* 78 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
34669 /* 79 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), 35351 /* 79 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
34670 /* 80 */ "SCopy" OpHelp("r[P2]=r[P1]"), 35352 /* 80 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
34671 /* 81 */ "IntCopy" OpHelp("r[P2]=r[P1]"), 35353 /* 81 */ "SCopy" OpHelp("r[P2]=r[P1]"),
34672 /* 82 */ "FkCheck" OpHelp(""), 35354 /* 82 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
34673 /* 83 */ "ResultRow" OpHelp("output=r[P1@P2]"), 35355 /* 83 */ "FkCheck" OpHelp(""),
34674 /* 84 */ "CollSeq" OpHelp(""), 35356 /* 84 */ "ResultRow" OpHelp("output=r[P1@P2]"),
34675 /* 85 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), 35357 /* 85 */ "CollSeq" OpHelp(""),
34676 /* 86 */ "RealAffinity" OpHelp(""), 35358 /* 86 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
34677 /* 87 */ "Cast" OpHelp("affinity(r[P1])"), 35359 /* 87 */ "RealAffinity" OpHelp(""),
34678 /* 88 */ "Permutation" OpHelp(""), 35360 /* 88 */ "Cast" OpHelp("affinity(r[P1])"),
34679 /* 89 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), 35361 /* 89 */ "Permutation" OpHelp(""),
34680 /* 90 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"), 35362 /* 90 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
34681 /* 91 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"), 35363 /* 91 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
34682 /* 92 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"), 35364 /* 92 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"),
34683 /* 93 */ "Column" OpHelp("r[P3]=PX"), 35365 /* 93 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
34684 /* 94 */ "TypeCheck" OpHelp("typecheck(r[P1@P2])"), 35366 /* 94 */ "Column" OpHelp("r[P3]=PX cursor P1 column P2"),
34685 /* 95 */ "Affinity" OpHelp("affinity(r[P1@P2])"), 35367 /* 95 */ "TypeCheck" OpHelp("typecheck(r[P1@P2])"),
34686 /* 96 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), 35368 /* 96 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
34687 /* 97 */ "Count" OpHelp("r[P2]=count()"), 35369 /* 97 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
34688 /* 98 */ "ReadCookie" OpHelp(""), 35370 /* 98 */ "Count" OpHelp("r[P2]=count()"),
34689 /* 99 */ "SetCookie" OpHelp(""), 35371 /* 99 */ "ReadCookie" OpHelp(""),
34690 /* 100 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), 35372 /* 100 */ "SetCookie" OpHelp(""),
34691 /* 101 */ "OpenRead" OpHelp("root=P2 iDb=P3"), 35373 /* 101 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
34692 /* 102 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"), 35374 /* 102 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
34693 /* 103 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"), 35375 /* 103 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
34694 /* 104 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"), 35376 /* 104 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
@@ -34699,79 +35381,81 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
34699 /* 109 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"), 35381 /* 109 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
34700 /* 110 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"), 35382 /* 110 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
34701 /* 111 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"), 35383 /* 111 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
34702 /* 112 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), 35384 /* 112 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
34703 /* 113 */ "OpenDup" OpHelp(""), 35385 /* 113 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
34704 /* 114 */ "BitNot" OpHelp("r[P2]= ~r[P1]"), 35386 /* 114 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
34705 /* 115 */ "OpenAutoindex" OpHelp("nColumn=P2"), 35387 /* 115 */ "OpenDup" OpHelp(""),
34706 /* 116 */ "OpenEphemeral" OpHelp("nColumn=P2"), 35388 /* 116 */ "OpenAutoindex" OpHelp("nColumn=P2"),
34707 /* 117 */ "String8" OpHelp("r[P2]='P4'"), 35389 /* 117 */ "String8" OpHelp("r[P2]='P4'"),
34708 /* 118 */ "SorterOpen" OpHelp(""), 35390 /* 118 */ "OpenEphemeral" OpHelp("nColumn=P2"),
34709 /* 119 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), 35391 /* 119 */ "SorterOpen" OpHelp(""),
34710 /* 120 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), 35392 /* 120 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
34711 /* 121 */ "Close" OpHelp(""), 35393 /* 121 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
34712 /* 122 */ "ColumnsUsed" OpHelp(""), 35394 /* 122 */ "Close" OpHelp(""),
34713 /* 123 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"), 35395 /* 123 */ "ColumnsUsed" OpHelp(""),
34714 /* 124 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"), 35396 /* 124 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"),
34715 /* 125 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), 35397 /* 125 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"),
34716 /* 126 */ "NewRowid" OpHelp("r[P2]=rowid"), 35398 /* 126 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
34717 /* 127 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), 35399 /* 127 */ "NewRowid" OpHelp("r[P2]=rowid"),
34718 /* 128 */ "RowCell" OpHelp(""), 35400 /* 128 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
34719 /* 129 */ "Delete" OpHelp(""), 35401 /* 129 */ "RowCell" OpHelp(""),
34720 /* 130 */ "ResetCount" OpHelp(""), 35402 /* 130 */ "Delete" OpHelp(""),
34721 /* 131 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), 35403 /* 131 */ "ResetCount" OpHelp(""),
34722 /* 132 */ "SorterData" OpHelp("r[P2]=data"), 35404 /* 132 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
34723 /* 133 */ "RowData" OpHelp("r[P2]=data"), 35405 /* 133 */ "SorterData" OpHelp("r[P2]=data"),
34724 /* 134 */ "Rowid" OpHelp("r[P2]=rowid"), 35406 /* 134 */ "RowData" OpHelp("r[P2]=data"),
34725 /* 135 */ "NullRow" OpHelp(""), 35407 /* 135 */ "Rowid" OpHelp("r[P2]=PX rowid of P1"),
34726 /* 136 */ "SeekEnd" OpHelp(""), 35408 /* 136 */ "NullRow" OpHelp(""),
34727 /* 137 */ "IdxInsert" OpHelp("key=r[P2]"), 35409 /* 137 */ "SeekEnd" OpHelp(""),
34728 /* 138 */ "SorterInsert" OpHelp("key=r[P2]"), 35410 /* 138 */ "IdxInsert" OpHelp("key=r[P2]"),
34729 /* 139 */ "IdxDelete" OpHelp("key=r[P2@P3]"), 35411 /* 139 */ "SorterInsert" OpHelp("key=r[P2]"),
34730 /* 140 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), 35412 /* 140 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
34731 /* 141 */ "IdxRowid" OpHelp("r[P2]=rowid"), 35413 /* 141 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
34732 /* 142 */ "FinishSeek" OpHelp(""), 35414 /* 142 */ "IdxRowid" OpHelp("r[P2]=rowid"),
34733 /* 143 */ "Destroy" OpHelp(""), 35415 /* 143 */ "FinishSeek" OpHelp(""),
34734 /* 144 */ "Clear" OpHelp(""), 35416 /* 144 */ "Destroy" OpHelp(""),
34735 /* 145 */ "ResetSorter" OpHelp(""), 35417 /* 145 */ "Clear" OpHelp(""),
34736 /* 146 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"), 35418 /* 146 */ "ResetSorter" OpHelp(""),
34737 /* 147 */ "SqlExec" OpHelp(""), 35419 /* 147 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
34738 /* 148 */ "ParseSchema" OpHelp(""), 35420 /* 148 */ "SqlExec" OpHelp(""),
34739 /* 149 */ "LoadAnalysis" OpHelp(""), 35421 /* 149 */ "ParseSchema" OpHelp(""),
34740 /* 150 */ "DropTable" OpHelp(""), 35422 /* 150 */ "LoadAnalysis" OpHelp(""),
34741 /* 151 */ "DropIndex" OpHelp(""), 35423 /* 151 */ "DropTable" OpHelp(""),
34742 /* 152 */ "DropTrigger" OpHelp(""), 35424 /* 152 */ "DropIndex" OpHelp(""),
34743 /* 153 */ "Real" OpHelp("r[P2]=P4"), 35425 /* 153 */ "Real" OpHelp("r[P2]=P4"),
34744 /* 154 */ "IntegrityCk" OpHelp(""), 35426 /* 154 */ "DropTrigger" OpHelp(""),
34745 /* 155 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), 35427 /* 155 */ "IntegrityCk" OpHelp(""),
34746 /* 156 */ "Param" OpHelp(""), 35428 /* 156 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
34747 /* 157 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), 35429 /* 157 */ "Param" OpHelp(""),
34748 /* 158 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), 35430 /* 158 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
34749 /* 159 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), 35431 /* 159 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
34750 /* 160 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"), 35432 /* 160 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
34751 /* 161 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), 35433 /* 161 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"),
34752 /* 162 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"), 35434 /* 162 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
34753 /* 163 */ "AggValue" OpHelp("r[P3]=value N=P2"), 35435 /* 163 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"),
34754 /* 164 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), 35436 /* 164 */ "AggValue" OpHelp("r[P3]=value N=P2"),
34755 /* 165 */ "Expire" OpHelp(""), 35437 /* 165 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
34756 /* 166 */ "CursorLock" OpHelp(""), 35438 /* 166 */ "Expire" OpHelp(""),
34757 /* 167 */ "CursorUnlock" OpHelp(""), 35439 /* 167 */ "CursorLock" OpHelp(""),
34758 /* 168 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), 35440 /* 168 */ "CursorUnlock" OpHelp(""),
34759 /* 169 */ "VBegin" OpHelp(""), 35441 /* 169 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
34760 /* 170 */ "VCreate" OpHelp(""), 35442 /* 170 */ "VBegin" OpHelp(""),
34761 /* 171 */ "VDestroy" OpHelp(""), 35443 /* 171 */ "VCreate" OpHelp(""),
34762 /* 172 */ "VOpen" OpHelp(""), 35444 /* 172 */ "VDestroy" OpHelp(""),
34763 /* 173 */ "VInitIn" OpHelp("r[P2]=ValueList(P1,P3)"), 35445 /* 173 */ "VOpen" OpHelp(""),
34764 /* 174 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), 35446 /* 174 */ "VInitIn" OpHelp("r[P2]=ValueList(P1,P3)"),
34765 /* 175 */ "VRename" OpHelp(""), 35447 /* 175 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
34766 /* 176 */ "Pagecount" OpHelp(""), 35448 /* 176 */ "VRename" OpHelp(""),
34767 /* 177 */ "MaxPgcnt" OpHelp(""), 35449 /* 177 */ "Pagecount" OpHelp(""),
34768 /* 178 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"), 35450 /* 178 */ "MaxPgcnt" OpHelp(""),
34769 /* 179 */ "Trace" OpHelp(""), 35451 /* 179 */ "ClrSubtype" OpHelp("r[P1].subtype = 0"),
34770 /* 180 */ "CursorHint" OpHelp(""), 35452 /* 180 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"),
34771 /* 181 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"), 35453 /* 181 */ "Trace" OpHelp(""),
34772 /* 182 */ "Noop" OpHelp(""), 35454 /* 182 */ "CursorHint" OpHelp(""),
34773 /* 183 */ "Explain" OpHelp(""), 35455 /* 183 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
34774 /* 184 */ "Abortable" OpHelp(""), 35456 /* 184 */ "Noop" OpHelp(""),
35457 /* 185 */ "Explain" OpHelp(""),
35458 /* 186 */ "Abortable" OpHelp(""),
34775 }; 35459 };
34776 return azName[i]; 35460 return azName[i];
34777} 35461}
@@ -40798,20 +41482,23 @@ static int findCreateFileMode(
40798 ** 41482 **
40799 ** where NN is a decimal number. The NN naming schemes are 41483 ** where NN is a decimal number. The NN naming schemes are
40800 ** used by the test_multiplex.c module. 41484 ** used by the test_multiplex.c module.
41485 **
41486 ** In normal operation, the journal file name will always contain
41487 ** a '-' character. However in 8+3 filename mode, or if a corrupt
41488 ** rollback journal specifies a super-journal with a goofy name, then
41489 ** the '-' might be missing or the '-' might be the first character in
41490 ** the filename. In that case, just return SQLITE_OK with *pMode==0.
40801 */ 41491 */
40802 nDb = sqlite3Strlen30(zPath) - 1; 41492 nDb = sqlite3Strlen30(zPath) - 1;
40803 while( zPath[nDb]!='-' ){ 41493 while( nDb>0 && zPath[nDb]!='.' ){
40804 /* In normal operation, the journal file name will always contain 41494 if( zPath[nDb]=='-' ){
40805 ** a '-' character. However in 8+3 filename mode, or if a corrupt 41495 memcpy(zDb, zPath, nDb);
40806 ** rollback journal specifies a super-journal with a goofy name, then 41496 zDb[nDb] = '\0';
40807 ** the '-' might be missing. */ 41497 rc = getFileMode(zDb, pMode, pUid, pGid);
40808 if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK; 41498 break;
41499 }
40809 nDb--; 41500 nDb--;
40810 } 41501 }
40811 memcpy(zDb, zPath, nDb);
40812 zDb[nDb] = '\0';
40813
40814 rc = getFileMode(zDb, pMode, pUid, pGid);
40815 }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){ 41502 }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
40816 *pMode = 0600; 41503 *pMode = 0600;
40817 }else if( flags & SQLITE_OPEN_URI ){ 41504 }else if( flags & SQLITE_OPEN_URI ){
@@ -41201,86 +41888,99 @@ static int unixAccess(
41201} 41888}
41202 41889
41203/* 41890/*
41204** If the last component of the pathname in z[0]..z[j-1] is something 41891** A pathname under construction
41205** other than ".." then back it out and return true. If the last
41206** component is empty or if it is ".." then return false.
41207*/ 41892*/
41208static int unixBackupDir(const char *z, int *pJ){ 41893typedef struct DbPath DbPath;
41209 int j = *pJ; 41894struct DbPath {
41210 int i; 41895 int rc; /* Non-zero following any error */
41211 if( j<=0 ) return 0; 41896 int nSymlink; /* Number of symlinks resolved */
41212 for(i=j-1; i>0 && z[i-1]!='/'; i--){} 41897 char *zOut; /* Write the pathname here */
41213 if( i==0 ) return 0; 41898 int nOut; /* Bytes of space available to zOut[] */
41214 if( z[i]=='.' && i==j-2 && z[i+1]=='.' ) return 0; 41899 int nUsed; /* Bytes of zOut[] currently being used */
41215 *pJ = i-1; 41900};
41216 return 1; 41901
41217} 41902/* Forward reference */
41903static void appendAllPathElements(DbPath*,const char*);
41218 41904
41219/* 41905/*
41220** Convert a relative pathname into a full pathname. Also 41906** Append a single path element to the DbPath under construction
41221** simplify the pathname as follows:
41222**
41223** Remove all instances of /./
41224** Remove all isntances of /X/../ for any X
41225*/ 41907*/
41226static int mkFullPathname( 41908static void appendOnePathElement(
41227 const char *zPath, /* Input path */ 41909 DbPath *pPath, /* Path under construction, to which to append zName */
41228 char *zOut, /* Output buffer */ 41910 const char *zName, /* Name to append to pPath. Not zero-terminated */
41229 int nOut /* Allocated size of buffer zOut */ 41911 int nName /* Number of significant bytes in zName */
41230){ 41912){
41231 int nPath = sqlite3Strlen30(zPath); 41913 assert( nName>0 );
41232 int iOff = 0; 41914 assert( zName!=0 );
41233 int i, j; 41915 if( zName[0]=='.' ){
41234 if( zPath[0]!='/' ){ 41916 if( nName==1 ) return;
41235 if( osGetcwd(zOut, nOut-2)==0 ){ 41917 if( zName[1]=='.' && nName==2 ){
41236 return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath); 41918 if( pPath->nUsed<=1 ){
41919 pPath->rc = SQLITE_ERROR;
41920 return;
41921 }
41922 assert( pPath->zOut[0]=='/' );
41923 while( pPath->zOut[--pPath->nUsed]!='/' ){}
41924 return;
41237 } 41925 }
41238 iOff = sqlite3Strlen30(zOut);
41239 zOut[iOff++] = '/';
41240 } 41926 }
41241 if( (iOff+nPath+1)>nOut ){ 41927 if( pPath->nUsed + nName + 2 >= pPath->nOut ){
41242 /* SQLite assumes that xFullPathname() nul-terminates the output buffer 41928 pPath->rc = SQLITE_ERROR;
41243 ** even if it returns an error. */ 41929 return;
41244 zOut[iOff] = '\0';
41245 return SQLITE_CANTOPEN_BKPT;
41246 }
41247 sqlite3_snprintf(nOut-iOff, &zOut[iOff], "%s", zPath);
41248
41249 /* Remove duplicate '/' characters. Except, two // at the beginning
41250 ** of a pathname is allowed since this is important on windows. */
41251 for(i=j=1; zOut[i]; i++){
41252 zOut[j++] = zOut[i];
41253 while( zOut[i]=='/' && zOut[i+1]=='/' ) i++;
41254 } 41930 }
41255 zOut[j] = 0; 41931 pPath->zOut[pPath->nUsed++] = '/';
41256 41932 memcpy(&pPath->zOut[pPath->nUsed], zName, nName);
41257 assert( zOut[0]=='/' ); 41933 pPath->nUsed += nName;
41258 for(i=j=0; zOut[i]; i++){ 41934#if defined(HAVE_READLINK) && defined(HAVE_LSTAT)
41259 if( zOut[i]=='/' ){ 41935 if( pPath->rc==SQLITE_OK ){
41260 /* Skip over internal "/." directory components */ 41936 const char *zIn;
41261 if( zOut[i+1]=='.' && zOut[i+2]=='/' ){ 41937 struct stat buf;
41262 i += 1; 41938 pPath->zOut[pPath->nUsed] = 0;
41263 continue; 41939 zIn = pPath->zOut;
41940 if( osLstat(zIn, &buf)!=0 ){
41941 if( errno!=ENOENT ){
41942 pPath->rc = unixLogError(SQLITE_CANTOPEN_BKPT, "lstat", zIn);
41264 } 41943 }
41265 41944 }else if( S_ISLNK(buf.st_mode) ){
41266 /* If this is a "/.." directory component then back out the 41945 ssize_t got;
41267 ** previous term of the directory if it is something other than "..". 41946 char zLnk[SQLITE_MAX_PATHLEN+2];
41268 */ 41947 if( pPath->nSymlink++ > SQLITE_MAX_SYMLINK ){
41269 if( zOut[i+1]=='.' 41948 pPath->rc = SQLITE_CANTOPEN_BKPT;
41270 && zOut[i+2]=='.' 41949 return;
41271 && zOut[i+3]=='/' 41950 }
41272 && unixBackupDir(zOut, &j) 41951 got = osReadlink(zIn, zLnk, sizeof(zLnk)-2);
41273 ){ 41952 if( got<=0 || got>=(ssize_t)sizeof(zLnk)-2 ){
41274 i += 2; 41953 pPath->rc = unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zIn);
41275 continue; 41954 return;
41955 }
41956 zLnk[got] = 0;
41957 if( zLnk[0]=='/' ){
41958 pPath->nUsed = 0;
41959 }else{
41960 pPath->nUsed -= nName + 1;
41276 } 41961 }
41962 appendAllPathElements(pPath, zLnk);
41277 } 41963 }
41278 if( ALWAYS(j>=0) ) zOut[j] = zOut[i];
41279 j++;
41280 } 41964 }
41281 if( NEVER(j==0) ) zOut[j++] = '/'; 41965#endif
41282 zOut[j] = 0; 41966}
41283 return SQLITE_OK; 41967
41968/*
41969** Append all path elements in zPath to the DbPath under construction.
41970*/
41971static void appendAllPathElements(
41972 DbPath *pPath, /* Path under construction, to which to append zName */
41973 const char *zPath /* Path to append to pPath. Is zero-terminated */
41974){
41975 int i = 0;
41976 int j = 0;
41977 do{
41978 while( zPath[i] && zPath[i]!='/' ){ i++; }
41979 if( i>j ){
41980 appendOnePathElement(pPath, &zPath[j], i-j);
41981 }
41982 j = i+1;
41983 }while( zPath[i++] );
41284} 41984}
41285 41985
41286/* 41986/*
@@ -41298,86 +41998,27 @@ static int unixFullPathname(
41298 int nOut, /* Size of output buffer in bytes */ 41998 int nOut, /* Size of output buffer in bytes */
41299 char *zOut /* Output buffer */ 41999 char *zOut /* Output buffer */
41300){ 42000){
41301#if !defined(HAVE_READLINK) || !defined(HAVE_LSTAT) 42001 DbPath path;
41302 return mkFullPathname(zPath, zOut, nOut);
41303#else
41304 int rc = SQLITE_OK;
41305 int nByte;
41306 int nLink = 0; /* Number of symbolic links followed so far */
41307 const char *zIn = zPath; /* Input path for each iteration of loop */
41308 char *zDel = 0;
41309
41310 assert( pVfs->mxPathname==MAX_PATHNAME );
41311 UNUSED_PARAMETER(pVfs); 42002 UNUSED_PARAMETER(pVfs);
41312 42003 path.rc = 0;
41313 /* It's odd to simulate an io-error here, but really this is just 42004 path.nUsed = 0;
41314 ** using the io-error infrastructure to test that SQLite handles this 42005 path.nSymlink = 0;
41315 ** function failing. This function could fail if, for example, the 42006 path.nOut = nOut;
41316 ** current working directory has been unlinked. 42007 path.zOut = zOut;
41317 */ 42008 if( zPath[0]!='/' ){
41318 SimulateIOError( return SQLITE_ERROR ); 42009 char zPwd[SQLITE_MAX_PATHLEN+2];
41319 42010 if( osGetcwd(zPwd, sizeof(zPwd)-2)==0 ){
41320 do { 42011 return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
41321
41322 /* Call stat() on path zIn. Set bLink to true if the path is a symbolic
41323 ** link, or false otherwise. */
41324 int bLink = 0;
41325 struct stat buf;
41326 if( osLstat(zIn, &buf)!=0 ){
41327 if( errno!=ENOENT ){
41328 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "lstat", zIn);
41329 }
41330 }else{
41331 bLink = S_ISLNK(buf.st_mode);
41332 }
41333
41334 if( bLink ){
41335 nLink++;
41336 if( zDel==0 ){
41337 zDel = sqlite3_malloc(nOut);
41338 if( zDel==0 ) rc = SQLITE_NOMEM_BKPT;
41339 }else if( nLink>=SQLITE_MAX_SYMLINKS ){
41340 rc = SQLITE_CANTOPEN_BKPT;
41341 }
41342
41343 if( rc==SQLITE_OK ){
41344 nByte = osReadlink(zIn, zDel, nOut-1);
41345 if( nByte<0 ){
41346 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zIn);
41347 }else{
41348 if( zDel[0]!='/' ){
41349 int n;
41350 for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--);
41351 if( nByte+n+1>nOut ){
41352 rc = SQLITE_CANTOPEN_BKPT;
41353 }else{
41354 memmove(&zDel[n], zDel, nByte+1);
41355 memcpy(zDel, zIn, n);
41356 nByte += n;
41357 }
41358 }
41359 zDel[nByte] = '\0';
41360 }
41361 }
41362
41363 zIn = zDel;
41364 }
41365
41366 assert( rc!=SQLITE_OK || zIn!=zOut || zIn[0]=='/' );
41367 if( rc==SQLITE_OK && zIn!=zOut ){
41368 rc = mkFullPathname(zIn, zOut, nOut);
41369 } 42012 }
41370 if( bLink==0 ) break; 42013 appendAllPathElements(&path, zPwd);
41371 zIn = zOut; 42014 }
41372 }while( rc==SQLITE_OK ); 42015 appendAllPathElements(&path, zPath);
41373 42016 zOut[path.nUsed] = 0;
41374 sqlite3_free(zDel); 42017 if( path.rc || path.nUsed<2 ) return SQLITE_CANTOPEN_BKPT;
41375 if( rc==SQLITE_OK && nLink ) rc = SQLITE_OK_SYMLINK; 42018 if( path.nSymlink ) return SQLITE_OK_SYMLINK;
41376 return rc; 42019 return SQLITE_OK;
41377#endif /* HAVE_READLINK && HAVE_LSTAT */
41378} 42020}
41379 42021
41380
41381#ifndef SQLITE_OMIT_LOAD_EXTENSION 42022#ifndef SQLITE_OMIT_LOAD_EXTENSION
41382/* 42023/*
41383** Interfaces for opening a shared library, finding entry points 42024** Interfaces for opening a shared library, finding entry points
@@ -50926,8 +51567,7 @@ SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr *p){
50926** make it so. 51567** make it so.
50927*/ 51568*/
50928SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){ 51569SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){
50929 assert( p->nRef>0 || p->pCache->bPurgeable==0 ); 51570 assert( p->nRef>0 );
50930 testcase( p->nRef==0 );
50931 assert( sqlite3PcachePageSanity(p) ); 51571 assert( sqlite3PcachePageSanity(p) );
50932 if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/ 51572 if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/
50933 p->flags &= ~PGHDR_DONT_WRITE; 51573 p->flags &= ~PGHDR_DONT_WRITE;
@@ -53896,6 +54536,7 @@ struct Pager {
53896 u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */ 54536 u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */
53897 u32 sectorSize; /* Assumed sector size during rollback */ 54537 u32 sectorSize; /* Assumed sector size during rollback */
53898 Pgno mxPgno; /* Maximum allowed size of the database */ 54538 Pgno mxPgno; /* Maximum allowed size of the database */
54539 Pgno lckPgno; /* Page number for the locking page */
53899 i64 pageSize; /* Number of bytes in a page */ 54540 i64 pageSize; /* Number of bytes in a page */
53900 i64 journalSizeLimit; /* Size limit for persistent journal files */ 54541 i64 journalSizeLimit; /* Size limit for persistent journal files */
53901 char *zFilename; /* Name of the database file */ 54542 char *zFilename; /* Name of the database file */
@@ -54882,7 +55523,7 @@ static int readJournalHdr(
54882** journal file descriptor is advanced to the next sector boundary before 55523** journal file descriptor is advanced to the next sector boundary before
54883** anything is written. The format is: 55524** anything is written. The format is:
54884** 55525**
54885** + 4 bytes: PAGER_MJ_PGNO. 55526** + 4 bytes: PAGER_SJ_PGNO.
54886** + N bytes: super-journal filename in utf-8. 55527** + N bytes: super-journal filename in utf-8.
54887** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator). 55528** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator).
54888** + 4 bytes: super-journal name checksum. 55529** + 4 bytes: super-journal name checksum.
@@ -54930,7 +55571,7 @@ static int writeSuperJournal(Pager *pPager, const char *zSuper){
54930 /* Write the super-journal data to the end of the journal file. If 55571 /* Write the super-journal data to the end of the journal file. If
54931 ** an error occurs, return the error code to the caller. 55572 ** an error occurs, return the error code to the caller.
54932 */ 55573 */
54933 if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_MJ_PGNO(pPager)))) 55574 if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_SJ_PGNO(pPager))))
54934 || (0 != (rc = sqlite3OsWrite(pPager->jfd, zSuper, nSuper, iHdrOff+4))) 55575 || (0 != (rc = sqlite3OsWrite(pPager->jfd, zSuper, nSuper, iHdrOff+4)))
54935 || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper, nSuper))) 55576 || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper, nSuper)))
54936 || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper+4, cksum))) 55577 || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper+4, cksum)))
@@ -55440,7 +56081,7 @@ static u32 pager_cksum(Pager *pPager, const u8 *aData){
55440** corrupted, SQLITE_DONE is returned. Data is considered corrupted in 56081** corrupted, SQLITE_DONE is returned. Data is considered corrupted in
55441** two circumstances: 56082** two circumstances:
55442** 56083**
55443** * If the record page-number is illegal (0 or PAGER_MJ_PGNO), or 56084** * If the record page-number is illegal (0 or PAGER_SJ_PGNO), or
55444** * If the record is being rolled back from the main journal file 56085** * If the record is being rolled back from the main journal file
55445** and the checksum field does not match the record content. 56086** and the checksum field does not match the record content.
55446** 56087**
@@ -55500,7 +56141,7 @@ static int pager_playback_one_page(
55500 ** it could cause invalid data to be written into the journal. We need to 56141 ** it could cause invalid data to be written into the journal. We need to
55501 ** detect this invalid data (with high probability) and ignore it. 56142 ** detect this invalid data (with high probability) and ignore it.
55502 */ 56143 */
55503 if( pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){ 56144 if( pgno==0 || pgno==PAGER_SJ_PGNO(pPager) ){
55504 assert( !isSavepnt ); 56145 assert( !isSavepnt );
55505 return SQLITE_DONE; 56146 return SQLITE_DONE;
55506 } 56147 }
@@ -55837,6 +56478,7 @@ static int pager_truncate(Pager *pPager, Pgno nPage){
55837 memset(pTmp, 0, szPage); 56478 memset(pTmp, 0, szPage);
55838 testcase( (newSize-szPage) == currentSize ); 56479 testcase( (newSize-szPage) == currentSize );
55839 testcase( (newSize-szPage) > currentSize ); 56480 testcase( (newSize-szPage) > currentSize );
56481 sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_SIZE_HINT, &newSize);
55840 rc = sqlite3OsWrite(pPager->fd, pTmp, szPage, newSize-szPage); 56482 rc = sqlite3OsWrite(pPager->fd, pTmp, szPage, newSize-szPage);
55841 } 56483 }
55842 if( rc==SQLITE_OK ){ 56484 if( rc==SQLITE_OK ){
@@ -56958,6 +57600,7 @@ SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager *pPager, u32 *pPageSize, int nR
56958 pPager->pTmpSpace = pNew; 57600 pPager->pTmpSpace = pNew;
56959 pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize); 57601 pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
56960 pPager->pageSize = pageSize; 57602 pPager->pageSize = pageSize;
57603 pPager->lckPgno = (Pgno)(PENDING_BYTE/pageSize) + 1;
56961 }else{ 57604 }else{
56962 sqlite3PageFree(pNew); 57605 sqlite3PageFree(pNew);
56963 } 57606 }
@@ -58727,7 +59370,7 @@ static int getPageNormal(
58727 if( pPg->pPager && !noContent ){ 59370 if( pPg->pPager && !noContent ){
58728 /* In this case the pcache already contains an initialized copy of 59371 /* In this case the pcache already contains an initialized copy of
58729 ** the page. Return without further ado. */ 59372 ** the page. Return without further ado. */
58730 assert( pgno!=PAGER_MJ_PGNO(pPager) ); 59373 assert( pgno!=PAGER_SJ_PGNO(pPager) );
58731 pPager->aStat[PAGER_STAT_HIT]++; 59374 pPager->aStat[PAGER_STAT_HIT]++;
58732 return SQLITE_OK; 59375 return SQLITE_OK;
58733 59376
@@ -58738,7 +59381,7 @@ static int getPageNormal(
58738 ** (*) obsolete. Was: maximum page number is 2^31 59381 ** (*) obsolete. Was: maximum page number is 2^31
58739 ** (2) Never try to fetch the locking page 59382 ** (2) Never try to fetch the locking page
58740 */ 59383 */
58741 if( pgno==PAGER_MJ_PGNO(pPager) ){ 59384 if( pgno==PAGER_SJ_PGNO(pPager) ){
58742 rc = SQLITE_CORRUPT_BKPT; 59385 rc = SQLITE_CORRUPT_BKPT;
58743 goto pager_acquire_err; 59386 goto pager_acquire_err;
58744 } 59387 }
@@ -59137,7 +59780,7 @@ static SQLITE_NOINLINE int pagerAddPageToRollbackJournal(PgHdr *pPg){
59137 /* We should never write to the journal file the page that 59780 /* We should never write to the journal file the page that
59138 ** contains the database locks. The following assert verifies 59781 ** contains the database locks. The following assert verifies
59139 ** that we do not. */ 59782 ** that we do not. */
59140 assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) ); 59783 assert( pPg->pgno!=PAGER_SJ_PGNO(pPager) );
59141 59784
59142 assert( pPager->journalHdr<=pPager->journalOff ); 59785 assert( pPager->journalHdr<=pPager->journalOff );
59143 pData2 = pPg->pData; 59786 pData2 = pPg->pData;
@@ -59316,7 +59959,7 @@ static SQLITE_NOINLINE int pagerWriteLargeSector(PgHdr *pPg){
59316 Pgno pg = pg1+ii; 59959 Pgno pg = pg1+ii;
59317 PgHdr *pPage; 59960 PgHdr *pPage;
59318 if( pg==pPg->pgno || !sqlite3BitvecTest(pPager->pInJournal, pg) ){ 59961 if( pg==pPg->pgno || !sqlite3BitvecTest(pPager->pInJournal, pg) ){
59319 if( pg!=PAGER_MJ_PGNO(pPager) ){ 59962 if( pg!=PAGER_SJ_PGNO(pPager) ){
59320 rc = sqlite3PagerGet(pPager, pg, &pPage, 0); 59963 rc = sqlite3PagerGet(pPager, pg, &pPage, 0);
59321 if( rc==SQLITE_OK ){ 59964 if( rc==SQLITE_OK ){
59322 rc = pager_write(pPage); 59965 rc = pager_write(pPage);
@@ -59794,7 +60437,7 @@ SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(
59794 ** last page is never written out to disk, leaving the database file 60437 ** last page is never written out to disk, leaving the database file
59795 ** undersized. Fix this now if it is the case. */ 60438 ** undersized. Fix this now if it is the case. */
59796 if( pPager->dbSize>pPager->dbFileSize ){ 60439 if( pPager->dbSize>pPager->dbFileSize ){
59797 Pgno nNew = pPager->dbSize - (pPager->dbSize==PAGER_MJ_PGNO(pPager)); 60440 Pgno nNew = pPager->dbSize - (pPager->dbSize==PAGER_SJ_PGNO(pPager));
59798 assert( pPager->eState==PAGER_WRITER_DBMOD ); 60441 assert( pPager->eState==PAGER_WRITER_DBMOD );
59799 rc = pager_truncate(pPager, nNew); 60442 rc = pager_truncate(pPager, nNew);
59800 if( rc!=SQLITE_OK ) goto commit_phase_one_exit; 60443 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
@@ -65423,7 +66066,7 @@ struct MemPage {
65423 u8 *aData; /* Pointer to disk image of the page data */ 66066 u8 *aData; /* Pointer to disk image of the page data */
65424 u8 *aDataEnd; /* One byte past the end of the entire page - not just 66067 u8 *aDataEnd; /* One byte past the end of the entire page - not just
65425 ** the usable space, the entire page. Used to prevent 66068 ** the usable space, the entire page. Used to prevent
65426 ** corruption-induced of buffer overflow. */ 66069 ** corruption-induced buffer overflow. */
65427 u8 *aCellIdx; /* The cell index area */ 66070 u8 *aCellIdx; /* The cell index area */
65428 u8 *aDataOfst; /* Same as aData for leaves. aData+4 for interior */ 66071 u8 *aDataOfst; /* Same as aData for leaves. aData+4 for interior */
65429 DbPage *pDbPage; /* Pager page handle */ 66072 DbPage *pDbPage; /* Pager page handle */
@@ -65728,7 +66371,7 @@ struct BtCursor {
65728/* 66371/*
65729** The database page the PENDING_BYTE occupies. This page is never used. 66372** The database page the PENDING_BYTE occupies. This page is never used.
65730*/ 66373*/
65731# define PENDING_BYTE_PAGE(pBt) PAGER_MJ_PGNO(pBt) 66374#define PENDING_BYTE_PAGE(pBt) ((Pgno)((PENDING_BYTE/((pBt)->pageSize))+1))
65732 66375
65733/* 66376/*
65734** These macros define the location of the pointer-map entry for a 66377** These macros define the location of the pointer-map entry for a
@@ -66369,7 +67012,7 @@ static int hasSharedCacheTableLock(
66369 int bSeen = 0; 67012 int bSeen = 0;
66370 for(p=sqliteHashFirst(&pSchema->idxHash); p; p=sqliteHashNext(p)){ 67013 for(p=sqliteHashFirst(&pSchema->idxHash); p; p=sqliteHashNext(p)){
66371 Index *pIdx = (Index *)sqliteHashData(p); 67014 Index *pIdx = (Index *)sqliteHashData(p);
66372 if( pIdx->tnum==(int)iRoot ){ 67015 if( pIdx->tnum==iRoot ){
66373 if( bSeen ){ 67016 if( bSeen ){
66374 /* Two or more indexes share the same root page. There must 67017 /* Two or more indexes share the same root page. There must
66375 ** be imposter tables. So just return true. The assert is not 67018 ** be imposter tables. So just return true. The assert is not
@@ -66962,7 +67605,7 @@ SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *pCur){
66962/* 67605/*
66963** In this version of BtreeMoveto, pKey is a packed index record 67606** In this version of BtreeMoveto, pKey is a packed index record
66964** such as is generated by the OP_MakeRecord opcode. Unpack the 67607** such as is generated by the OP_MakeRecord opcode. Unpack the
66965** record and then call BtreeMovetoUnpacked() to do the work. 67608** record and then call sqlite3BtreeIndexMoveto() to do the work.
66966*/ 67609*/
66967static int btreeMoveto( 67610static int btreeMoveto(
66968 BtCursor *pCur, /* Cursor open on the btree to be searched */ 67611 BtCursor *pCur, /* Cursor open on the btree to be searched */
@@ -67482,6 +68125,7 @@ static void btreeParseCell(
67482** the space used by the cell pointer. 68125** the space used by the cell pointer.
67483** 68126**
67484** cellSizePtrNoPayload() => table internal nodes 68127** cellSizePtrNoPayload() => table internal nodes
68128** cellSizePtrTableLeaf() => table leaf nodes
67485** cellSizePtr() => all index nodes & table leaf nodes 68129** cellSizePtr() => all index nodes & table leaf nodes
67486*/ 68130*/
67487static u16 cellSizePtr(MemPage *pPage, u8 *pCell){ 68131static u16 cellSizePtr(MemPage *pPage, u8 *pCell){
@@ -67507,13 +68151,6 @@ static u16 cellSizePtr(MemPage *pPage, u8 *pCell){
67507 }while( *(pIter)>=0x80 && pIter<pEnd ); 68151 }while( *(pIter)>=0x80 && pIter<pEnd );
67508 } 68152 }
67509 pIter++; 68153 pIter++;
67510 if( pPage->intKey ){
67511 /* pIter now points at the 64-bit integer key value, a variable length
67512 ** integer. The following block moves pIter to point at the first byte
67513 ** past the end of the key value. */
67514 pEnd = &pIter[9];
67515 while( (*pIter++)&0x80 && pIter<pEnd );
67516 }
67517 testcase( nSize==pPage->maxLocal ); 68154 testcase( nSize==pPage->maxLocal );
67518 testcase( nSize==(u32)pPage->maxLocal+1 ); 68155 testcase( nSize==(u32)pPage->maxLocal+1 );
67519 if( nSize<=pPage->maxLocal ){ 68156 if( nSize<=pPage->maxLocal ){
@@ -67553,6 +68190,58 @@ static u16 cellSizePtrNoPayload(MemPage *pPage, u8 *pCell){
67553 assert( debuginfo.nSize==(u16)(pIter - pCell) || CORRUPT_DB ); 68190 assert( debuginfo.nSize==(u16)(pIter - pCell) || CORRUPT_DB );
67554 return (u16)(pIter - pCell); 68191 return (u16)(pIter - pCell);
67555} 68192}
68193static u16 cellSizePtrTableLeaf(MemPage *pPage, u8 *pCell){
68194 u8 *pIter = pCell; /* For looping over bytes of pCell */
68195 u8 *pEnd; /* End mark for a varint */
68196 u32 nSize; /* Size value to return */
68197
68198#ifdef SQLITE_DEBUG
68199 /* The value returned by this function should always be the same as
68200 ** the (CellInfo.nSize) value found by doing a full parse of the
68201 ** cell. If SQLITE_DEBUG is defined, an assert() at the bottom of
68202 ** this function verifies that this invariant is not violated. */
68203 CellInfo debuginfo;
68204 pPage->xParseCell(pPage, pCell, &debuginfo);
68205#endif
68206
68207 nSize = *pIter;
68208 if( nSize>=0x80 ){
68209 pEnd = &pIter[8];
68210 nSize &= 0x7f;
68211 do{
68212 nSize = (nSize<<7) | (*++pIter & 0x7f);
68213 }while( *(pIter)>=0x80 && pIter<pEnd );
68214 }
68215 pIter++;
68216 /* pIter now points at the 64-bit integer key value, a variable length
68217 ** integer. The following block moves pIter to point at the first byte
68218 ** past the end of the key value. */
68219 if( (*pIter++)&0x80
68220 && (*pIter++)&0x80
68221 && (*pIter++)&0x80
68222 && (*pIter++)&0x80
68223 && (*pIter++)&0x80
68224 && (*pIter++)&0x80
68225 && (*pIter++)&0x80
68226 && (*pIter++)&0x80 ){ pIter++; }
68227 testcase( nSize==pPage->maxLocal );
68228 testcase( nSize==(u32)pPage->maxLocal+1 );
68229 if( nSize<=pPage->maxLocal ){
68230 nSize += (u32)(pIter - pCell);
68231 if( nSize<4 ) nSize = 4;
68232 }else{
68233 int minLocal = pPage->minLocal;
68234 nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4);
68235 testcase( nSize==pPage->maxLocal );
68236 testcase( nSize==(u32)pPage->maxLocal+1 );
68237 if( nSize>pPage->maxLocal ){
68238 nSize = minLocal;
68239 }
68240 nSize += 4 + (u16)(pIter - pCell);
68241 }
68242 assert( nSize==debuginfo.nSize || CORRUPT_DB );
68243 return (u16)nSize;
68244}
67556 68245
67557 68246
67558#ifdef SQLITE_DEBUG 68247#ifdef SQLITE_DEBUG
@@ -67566,7 +68255,7 @@ static u16 cellSize(MemPage *pPage, int iCell){
67566#ifndef SQLITE_OMIT_AUTOVACUUM 68255#ifndef SQLITE_OMIT_AUTOVACUUM
67567/* 68256/*
67568** The cell pCell is currently part of page pSrc but will ultimately be part 68257** The cell pCell is currently part of page pSrc but will ultimately be part
67569** of pPage. (pSrc and pPager are often the same.) If pCell contains a 68258** of pPage. (pSrc and pPage are often the same.) If pCell contains a
67570** pointer to an overflow page, insert an entry into the pointer-map for 68259** pointer to an overflow page, insert an entry into the pointer-map for
67571** the overflow page that will be valid after pCell has been moved to pPage. 68260** the overflow page that will be valid after pCell has been moved to pPage.
67572*/ 68261*/
@@ -67741,7 +68430,8 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
67741 const int hdr = pPg->hdrOffset; /* Offset to page header */ 68430 const int hdr = pPg->hdrOffset; /* Offset to page header */
67742 u8 * const aData = pPg->aData; /* Page data */ 68431 u8 * const aData = pPg->aData; /* Page data */
67743 int iAddr = hdr + 1; /* Address of ptr to pc */ 68432 int iAddr = hdr + 1; /* Address of ptr to pc */
67744 int pc = get2byte(&aData[iAddr]); /* Address of a free slot */ 68433 u8 *pTmp = &aData[iAddr]; /* Temporary ptr into aData[] */
68434 int pc = get2byte(pTmp); /* Address of a free slot */
67745 int x; /* Excess size of the slot */ 68435 int x; /* Excess size of the slot */
67746 int maxPC = pPg->pBt->usableSize - nByte; /* Max address for a usable slot */ 68436 int maxPC = pPg->pBt->usableSize - nByte; /* Max address for a usable slot */
67747 int size; /* Size of the free slot */ 68437 int size; /* Size of the free slot */
@@ -67751,7 +68441,8 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
67751 /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each 68441 /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each
67752 ** freeblock form a big-endian integer which is the size of the freeblock 68442 ** freeblock form a big-endian integer which is the size of the freeblock
67753 ** in bytes, including the 4-byte header. */ 68443 ** in bytes, including the 4-byte header. */
67754 size = get2byte(&aData[pc+2]); 68444 pTmp = &aData[pc+2];
68445 size = get2byte(pTmp);
67755 if( (x = size - nByte)>=0 ){ 68446 if( (x = size - nByte)>=0 ){
67756 testcase( x==4 ); 68447 testcase( x==4 );
67757 testcase( x==3 ); 68448 testcase( x==3 );
@@ -67764,6 +68455,8 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
67764 ** fragmented bytes within the page. */ 68455 ** fragmented bytes within the page. */
67765 memcpy(&aData[iAddr], &aData[pc], 2); 68456 memcpy(&aData[iAddr], &aData[pc], 2);
67766 aData[hdr+7] += (u8)x; 68457 aData[hdr+7] += (u8)x;
68458 testcase( pc+x>maxPC );
68459 return &aData[pc];
67767 }else if( x+pc > maxPC ){ 68460 }else if( x+pc > maxPC ){
67768 /* This slot extends off the end of the usable part of the page */ 68461 /* This slot extends off the end of the usable part of the page */
67769 *pRc = SQLITE_CORRUPT_PAGE(pPg); 68462 *pRc = SQLITE_CORRUPT_PAGE(pPg);
@@ -67776,7 +68469,8 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
67776 return &aData[pc + x]; 68469 return &aData[pc + x];
67777 } 68470 }
67778 iAddr = pc; 68471 iAddr = pc;
67779 pc = get2byte(&aData[pc]); 68472 pTmp = &aData[pc];
68473 pc = get2byte(pTmp);
67780 if( pc<=iAddr+size ){ 68474 if( pc<=iAddr+size ){
67781 if( pc ){ 68475 if( pc ){
67782 /* The next slot in the chain is not past the end of the current slot */ 68476 /* The next slot in the chain is not past the end of the current slot */
@@ -67810,6 +68504,7 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
67810 u8 * const data = pPage->aData; /* Local cache of pPage->aData */ 68504 u8 * const data = pPage->aData; /* Local cache of pPage->aData */
67811 int top; /* First byte of cell content area */ 68505 int top; /* First byte of cell content area */
67812 int rc = SQLITE_OK; /* Integer return code */ 68506 int rc = SQLITE_OK; /* Integer return code */
68507 u8 *pTmp; /* Temp ptr into data[] */
67813 int gap; /* First byte of gap between cell pointers and cell content */ 68508 int gap; /* First byte of gap between cell pointers and cell content */
67814 68509
67815 assert( sqlite3PagerIswriteable(pPage->pDbPage) ); 68510 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
@@ -67828,7 +68523,8 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
67828 ** then the cell content offset of an empty page wants to be 65536. 68523 ** then the cell content offset of an empty page wants to be 65536.
67829 ** However, that integer is too large to be stored in a 2-byte unsigned 68524 ** However, that integer is too large to be stored in a 2-byte unsigned
67830 ** integer, so a value of 0 is used in its place. */ 68525 ** integer, so a value of 0 is used in its place. */
67831 top = get2byte(&data[hdr+5]); 68526 pTmp = &data[hdr+5];
68527 top = get2byte(pTmp);
67832 assert( top<=(int)pPage->pBt->usableSize ); /* by btreeComputeFreeSpace() */ 68528 assert( top<=(int)pPage->pBt->usableSize ); /* by btreeComputeFreeSpace() */
67833 if( gap>top ){ 68529 if( gap>top ){
67834 if( top==0 && pPage->pBt->usableSize==65536 ){ 68530 if( top==0 && pPage->pBt->usableSize==65536 ){
@@ -67910,6 +68606,7 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
67910 u16 x; /* Offset to cell content area */ 68606 u16 x; /* Offset to cell content area */
67911 u32 iEnd = iStart + iSize; /* First byte past the iStart buffer */ 68607 u32 iEnd = iStart + iSize; /* First byte past the iStart buffer */
67912 unsigned char *data = pPage->aData; /* Page content */ 68608 unsigned char *data = pPage->aData; /* Page content */
68609 u8 *pTmp; /* Temporary ptr into data[] */
67913 68610
67914 assert( pPage->pBt!=0 ); 68611 assert( pPage->pBt!=0 );
67915 assert( sqlite3PagerIswriteable(pPage->pDbPage) ); 68612 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
@@ -67972,7 +68669,8 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
67972 if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PAGE(pPage); 68669 if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PAGE(pPage);
67973 data[hdr+7] -= nFrag; 68670 data[hdr+7] -= nFrag;
67974 } 68671 }
67975 x = get2byte(&data[hdr+5]); 68672 pTmp = &data[hdr+5];
68673 x = get2byte(pTmp);
67976 if( iStart<=x ){ 68674 if( iStart<=x ){
67977 /* The new freeblock is at the beginning of the cell content area, 68675 /* The new freeblock is at the beginning of the cell content area,
67978 ** so just extend the cell content area rather than create another 68676 ** so just extend the cell content area rather than create another
@@ -68016,7 +68714,6 @@ static int decodeFlags(MemPage *pPage, int flagByte){
68016 pPage->leaf = (u8)(flagByte>>3); assert( PTF_LEAF == 1<<3 ); 68714 pPage->leaf = (u8)(flagByte>>3); assert( PTF_LEAF == 1<<3 );
68017 flagByte &= ~PTF_LEAF; 68715 flagByte &= ~PTF_LEAF;
68018 pPage->childPtrSize = 4-4*pPage->leaf; 68716 pPage->childPtrSize = 4-4*pPage->leaf;
68019 pPage->xCellSize = cellSizePtr;
68020 pBt = pPage->pBt; 68717 pBt = pPage->pBt;
68021 if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){ 68718 if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
68022 /* EVIDENCE-OF: R-07291-35328 A value of 5 (0x05) means the page is an 68719 /* EVIDENCE-OF: R-07291-35328 A value of 5 (0x05) means the page is an
@@ -68028,6 +68725,7 @@ static int decodeFlags(MemPage *pPage, int flagByte){
68028 pPage->intKey = 1; 68725 pPage->intKey = 1;
68029 if( pPage->leaf ){ 68726 if( pPage->leaf ){
68030 pPage->intKeyLeaf = 1; 68727 pPage->intKeyLeaf = 1;
68728 pPage->xCellSize = cellSizePtrTableLeaf;
68031 pPage->xParseCell = btreeParseCellPtr; 68729 pPage->xParseCell = btreeParseCellPtr;
68032 }else{ 68730 }else{
68033 pPage->intKeyLeaf = 0; 68731 pPage->intKeyLeaf = 0;
@@ -68045,12 +68743,17 @@ static int decodeFlags(MemPage *pPage, int flagByte){
68045 assert( (PTF_ZERODATA|PTF_LEAF)==10 ); 68743 assert( (PTF_ZERODATA|PTF_LEAF)==10 );
68046 pPage->intKey = 0; 68744 pPage->intKey = 0;
68047 pPage->intKeyLeaf = 0; 68745 pPage->intKeyLeaf = 0;
68746 pPage->xCellSize = cellSizePtr;
68048 pPage->xParseCell = btreeParseCellPtrIndex; 68747 pPage->xParseCell = btreeParseCellPtrIndex;
68049 pPage->maxLocal = pBt->maxLocal; 68748 pPage->maxLocal = pBt->maxLocal;
68050 pPage->minLocal = pBt->minLocal; 68749 pPage->minLocal = pBt->minLocal;
68051 }else{ 68750 }else{
68052 /* EVIDENCE-OF: R-47608-56469 Any other value for the b-tree page type is 68751 /* EVIDENCE-OF: R-47608-56469 Any other value for the b-tree page type is
68053 ** an error. */ 68752 ** an error. */
68753 pPage->intKey = 0;
68754 pPage->intKeyLeaf = 0;
68755 pPage->xCellSize = cellSizePtr;
68756 pPage->xParseCell = btreeParseCellPtrIndex;
68054 return SQLITE_CORRUPT_PAGE(pPage); 68757 return SQLITE_CORRUPT_PAGE(pPage);
68055 } 68758 }
68056 pPage->max1bytePayload = pBt->max1bytePayload; 68759 pPage->max1bytePayload = pBt->max1bytePayload;
@@ -68404,7 +69107,9 @@ getAndInitPage_error1:
68404 pCur->pPage = pCur->apPage[pCur->iPage]; 69107 pCur->pPage = pCur->apPage[pCur->iPage];
68405 } 69108 }
68406 testcase( pgno==0 ); 69109 testcase( pgno==0 );
68407 assert( pgno!=0 || rc==SQLITE_CORRUPT ); 69110 assert( pgno!=0 || rc==SQLITE_CORRUPT
69111 || rc==SQLITE_IOERR_NOMEM
69112 || rc==SQLITE_NOMEM );
68408 return rc; 69113 return rc;
68409} 69114}
68410 69115
@@ -70026,12 +70731,17 @@ static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg, int bCommit){
70026 } 70731 }
70027 do { 70732 do {
70028 MemPage *pFreePg; 70733 MemPage *pFreePg;
70734 Pgno dbSize = btreePagecount(pBt);
70029 rc = allocateBtreePage(pBt, &pFreePg, &iFreePg, iNear, eMode); 70735 rc = allocateBtreePage(pBt, &pFreePg, &iFreePg, iNear, eMode);
70030 if( rc!=SQLITE_OK ){ 70736 if( rc!=SQLITE_OK ){
70031 releasePage(pLastPg); 70737 releasePage(pLastPg);
70032 return rc; 70738 return rc;
70033 } 70739 }
70034 releasePage(pFreePg); 70740 releasePage(pFreePg);
70741 if( iFreePg>dbSize ){
70742 releasePage(pLastPg);
70743 return SQLITE_CORRUPT_BKPT;
70744 }
70035 }while( bCommit && iFreePg>nFin ); 70745 }while( bCommit && iFreePg>nFin );
70036 assert( iFreePg<iLastPg ); 70746 assert( iFreePg<iLastPg );
70037 70747
@@ -71793,6 +72503,69 @@ moveto_table_finish:
71793 return rc; 72503 return rc;
71794} 72504}
71795 72505
72506/*
72507** Compare the "idx"-th cell on the page the cursor pCur is currently
72508** pointing to to pIdxKey using xRecordCompare. Return negative or
72509** zero if the cell is less than or equal pIdxKey. Return positive
72510** if unknown.
72511**
72512** Return value negative: Cell at pCur[idx] less than pIdxKey
72513**
72514** Return value is zero: Cell at pCur[idx] equals pIdxKey
72515**
72516** Return value positive: Nothing is known about the relationship
72517** of the cell at pCur[idx] and pIdxKey.
72518**
72519** This routine is part of an optimization. It is always safe to return
72520** a positive value as that will cause the optimization to be skipped.
72521*/
72522static int indexCellCompare(
72523 BtCursor *pCur,
72524 int idx,
72525 UnpackedRecord *pIdxKey,
72526 RecordCompare xRecordCompare
72527){
72528 MemPage *pPage = pCur->pPage;
72529 int c;
72530 int nCell; /* Size of the pCell cell in bytes */
72531 u8 *pCell = findCellPastPtr(pPage, idx);
72532
72533 nCell = pCell[0];
72534 if( nCell<=pPage->max1bytePayload ){
72535 /* This branch runs if the record-size field of the cell is a
72536 ** single byte varint and the record fits entirely on the main
72537 ** b-tree page. */
72538 testcase( pCell+nCell+1==pPage->aDataEnd );
72539 c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
72540 }else if( !(pCell[1] & 0x80)
72541 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
72542 ){
72543 /* The record-size field is a 2 byte varint and the record
72544 ** fits entirely on the main b-tree page. */
72545 testcase( pCell+nCell+2==pPage->aDataEnd );
72546 c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
72547 }else{
72548 /* If the record extends into overflow pages, do not attempt
72549 ** the optimization. */
72550 c = 99;
72551 }
72552 return c;
72553}
72554
72555/*
72556** Return true (non-zero) if pCur is current pointing to the last
72557** page of a table.
72558*/
72559static int cursorOnLastPage(BtCursor *pCur){
72560 int i;
72561 assert( pCur->eState==CURSOR_VALID );
72562 for(i=0; i<pCur->iPage; i++){
72563 MemPage *pPage = pCur->apPage[i];
72564 if( pCur->aiIdx[i]<pPage->nCell ) return 0;
72565 }
72566 return 1;
72567}
72568
71796/* Move the cursor so that it points to an entry in an index table 72569/* Move the cursor so that it points to an entry in an index table
71797** near the key pIdxKey. Return a success code. 72570** near the key pIdxKey. Return a success code.
71798** 72571**
@@ -71843,6 +72616,43 @@ SQLITE_PRIVATE int sqlite3BtreeIndexMoveto(
71843 || pIdxKey->default_rc==-1 72616 || pIdxKey->default_rc==-1
71844 ); 72617 );
71845 72618
72619
72620 /* Check to see if we can skip a lot of work. Two cases:
72621 **
72622 ** (1) If the cursor is already pointing to the very last cell
72623 ** in the table and the pIdxKey search key is greater than or
72624 ** equal to that last cell, then no movement is required.
72625 **
72626 ** (2) If the cursor is on the last page of the table and the first
72627 ** cell on that last page is less than or equal to the pIdxKey
72628 ** search key, then we can start the search on the current page
72629 ** without needing to go back to root.
72630 */
72631 if( pCur->eState==CURSOR_VALID
72632 && pCur->pPage->leaf
72633 && cursorOnLastPage(pCur)
72634 ){
72635 int c;
72636 if( pCur->ix==pCur->pPage->nCell-1
72637 && (c = indexCellCompare(pCur, pCur->ix, pIdxKey, xRecordCompare))<=0
72638 && pIdxKey->errCode==SQLITE_OK
72639 ){
72640 *pRes = c;
72641 return SQLITE_OK; /* Cursor already pointing at the correct spot */
72642 }
72643 if( pCur->iPage>0
72644 && indexCellCompare(pCur, 0, pIdxKey, xRecordCompare)<=0
72645 && pIdxKey->errCode==SQLITE_OK
72646 ){
72647 pCur->curFlags &= ~BTCF_ValidOvfl;
72648 if( !pCur->pPage->isInit ){
72649 return SQLITE_CORRUPT_BKPT;
72650 }
72651 goto bypass_moveto_root; /* Start search on the current page */
72652 }
72653 pIdxKey->errCode = SQLITE_OK;
72654 }
72655
71846 rc = moveToRoot(pCur); 72656 rc = moveToRoot(pCur);
71847 if( rc ){ 72657 if( rc ){
71848 if( rc==SQLITE_EMPTY ){ 72658 if( rc==SQLITE_EMPTY ){
@@ -71852,12 +72662,14 @@ SQLITE_PRIVATE int sqlite3BtreeIndexMoveto(
71852 } 72662 }
71853 return rc; 72663 return rc;
71854 } 72664 }
72665
72666bypass_moveto_root:
71855 assert( pCur->pPage ); 72667 assert( pCur->pPage );
71856 assert( pCur->pPage->isInit ); 72668 assert( pCur->pPage->isInit );
71857 assert( pCur->eState==CURSOR_VALID ); 72669 assert( pCur->eState==CURSOR_VALID );
71858 assert( pCur->pPage->nCell > 0 ); 72670 assert( pCur->pPage->nCell > 0 );
71859 assert( pCur->iPage==0 || pCur->apPage[0]->intKey==pCur->curIntKey ); 72671 assert( pCur->curIntKey==0 );
71860 assert( pCur->curIntKey || pIdxKey ); 72672 assert( pIdxKey!=0 );
71861 for(;;){ 72673 for(;;){
71862 int lwr, upr, idx, c; 72674 int lwr, upr, idx, c;
71863 Pgno chldPg; 72675 Pgno chldPg;
@@ -71871,7 +72683,7 @@ SQLITE_PRIVATE int sqlite3BtreeIndexMoveto(
71871 ** be the right kind (index or table) of b-tree page. Otherwise 72683 ** be the right kind (index or table) of b-tree page. Otherwise
71872 ** a moveToChild() or moveToRoot() call would have detected corruption. */ 72684 ** a moveToChild() or moveToRoot() call would have detected corruption. */
71873 assert( pPage->nCell>0 ); 72685 assert( pPage->nCell>0 );
71874 assert( pPage->intKey==(pIdxKey==0) ); 72686 assert( pPage->intKey==0 );
71875 lwr = 0; 72687 lwr = 0;
71876 upr = pPage->nCell-1; 72688 upr = pPage->nCell-1;
71877 idx = upr>>1; /* idx = (lwr+upr)/2; */ 72689 idx = upr>>1; /* idx = (lwr+upr)/2; */
@@ -71963,7 +72775,7 @@ SQLITE_PRIVATE int sqlite3BtreeIndexMoveto(
71963 assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) ); 72775 assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
71964 assert( pPage->isInit ); 72776 assert( pPage->isInit );
71965 if( pPage->leaf ){ 72777 if( pPage->leaf ){
71966 assert( pCur->ix<pCur->pPage->nCell ); 72778 assert( pCur->ix<pCur->pPage->nCell || CORRUPT_DB );
71967 pCur->ix = (u16)idx; 72779 pCur->ix = (u16)idx;
71968 *pRes = c; 72780 *pRes = c;
71969 rc = SQLITE_OK; 72781 rc = SQLITE_OK;
@@ -74487,7 +75299,7 @@ static int balance_nonroot(
74487 iOvflSpace += sz; 75299 iOvflSpace += sz;
74488 assert( sz<=pBt->maxLocal+23 ); 75300 assert( sz<=pBt->maxLocal+23 );
74489 assert( iOvflSpace <= (int)pBt->pageSize ); 75301 assert( iOvflSpace <= (int)pBt->pageSize );
74490 for(k=0; b.ixNx[k]<=i && ALWAYS(k<NB*2); k++){} 75302 for(k=0; b.ixNx[k]<=j && ALWAYS(k<NB*2); k++){}
74491 pSrcEnd = b.apEnd[k]; 75303 pSrcEnd = b.apEnd[k];
74492 if( SQLITE_WITHIN(pSrcEnd, pCell, pCell+sz) ){ 75304 if( SQLITE_WITHIN(pSrcEnd, pCell, pCell+sz) ){
74493 rc = SQLITE_CORRUPT_BKPT; 75305 rc = SQLITE_CORRUPT_BKPT;
@@ -74738,7 +75550,6 @@ static int anotherValidCursor(BtCursor *pCur){
74738*/ 75550*/
74739static int balance(BtCursor *pCur){ 75551static int balance(BtCursor *pCur){
74740 int rc = SQLITE_OK; 75552 int rc = SQLITE_OK;
74741 const int nMin = pCur->pBt->usableSize * 2 / 3;
74742 u8 aBalanceQuickSpace[13]; 75553 u8 aBalanceQuickSpace[13];
74743 u8 *pFree = 0; 75554 u8 *pFree = 0;
74744 75555
@@ -74750,7 +75561,11 @@ static int balance(BtCursor *pCur){
74750 MemPage *pPage = pCur->pPage; 75561 MemPage *pPage = pCur->pPage;
74751 75562
74752 if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break; 75563 if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
74753 if( pPage->nOverflow==0 && pPage->nFree<=nMin ){ 75564 if( pPage->nOverflow==0 && pPage->nFree*3<=(int)pCur->pBt->usableSize*2 ){
75565 /* No rebalance required as long as:
75566 ** (1) There are no overflow cells
75567 ** (2) The amount of free space on the page is less than 2/3rds of
75568 ** the total usable space on the page. */
74754 break; 75569 break;
74755 }else if( (iPage = pCur->iPage)==0 ){ 75570 }else if( (iPage = pCur->iPage)==0 ){
74756 if( pPage->nOverflow && (rc = anotherValidCursor(pCur))==SQLITE_OK ){ 75571 if( pPage->nOverflow && (rc = anotherValidCursor(pCur))==SQLITE_OK ){
@@ -74970,7 +75785,7 @@ static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){
74970** pX.pData,nData,nZero fields must be zero. 75785** pX.pData,nData,nZero fields must be zero.
74971** 75786**
74972** If the seekResult parameter is non-zero, then a successful call to 75787** If the seekResult parameter is non-zero, then a successful call to
74973** MovetoUnpacked() to seek cursor pCur to (pKey,nKey) has already 75788** sqlite3BtreeIndexMoveto() to seek cursor pCur to (pKey,nKey) has already
74974** been performed. In other words, if seekResult!=0 then the cursor 75789** been performed. In other words, if seekResult!=0 then the cursor
74975** is currently pointing to a cell that will be adjacent to the cell 75790** is currently pointing to a cell that will be adjacent to the cell
74976** to be inserted. If seekResult<0 then pCur points to a cell that is 75791** to be inserted. If seekResult<0 then pCur points to a cell that is
@@ -74988,7 +75803,7 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
74988 BtCursor *pCur, /* Insert data into the table of this cursor */ 75803 BtCursor *pCur, /* Insert data into the table of this cursor */
74989 const BtreePayload *pX, /* Content of the row to be inserted */ 75804 const BtreePayload *pX, /* Content of the row to be inserted */
74990 int flags, /* True if this is likely an append */ 75805 int flags, /* True if this is likely an append */
74991 int seekResult /* Result of prior MovetoUnpacked() call */ 75806 int seekResult /* Result of prior IndexMoveto() call */
74992){ 75807){
74993 int rc; 75808 int rc;
74994 int loc = seekResult; /* -1: before desired location +1: after */ 75809 int loc = seekResult; /* -1: before desired location +1: after */
@@ -75027,7 +75842,12 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
75027 } 75842 }
75028 } 75843 }
75029 75844
75845 /* Ensure that the cursor is not in the CURSOR_FAULT state and that it
75846 ** points to a valid cell.
75847 */
75030 if( pCur->eState>=CURSOR_REQUIRESEEK ){ 75848 if( pCur->eState>=CURSOR_REQUIRESEEK ){
75849 testcase( pCur->eState==CURSOR_REQUIRESEEK );
75850 testcase( pCur->eState==CURSOR_FAULT );
75031 rc = moveToRoot(pCur); 75851 rc = moveToRoot(pCur);
75032 if( rc && rc!=SQLITE_EMPTY ) return rc; 75852 if( rc && rc!=SQLITE_EMPTY ) return rc;
75033 } 75853 }
@@ -75139,7 +75959,8 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
75139 assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) ); 75959 assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
75140 assert( pPage->leaf || !pPage->intKey ); 75960 assert( pPage->leaf || !pPage->intKey );
75141 if( pPage->nFree<0 ){ 75961 if( pPage->nFree<0 ){
75142 if( pCur->eState>CURSOR_INVALID ){ 75962 if( NEVER(pCur->eState>CURSOR_INVALID) ){
75963 /* ^^^^^--- due to the moveToRoot() call above */
75143 rc = SQLITE_CORRUPT_BKPT; 75964 rc = SQLITE_CORRUPT_BKPT;
75144 }else{ 75965 }else{
75145 rc = btreeComputeFreeSpace(pPage); 75966 rc = btreeComputeFreeSpace(pPage);
@@ -75150,7 +75971,7 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
75150 TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n", 75971 TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
75151 pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno, 75972 pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
75152 loc==0 ? "overwrite" : "new entry")); 75973 loc==0 ? "overwrite" : "new entry"));
75153 assert( pPage->isInit ); 75974 assert( pPage->isInit || CORRUPT_DB );
75154 newCell = pBt->pTmpSpace; 75975 newCell = pBt->pTmpSpace;
75155 assert( newCell!=0 ); 75976 assert( newCell!=0 );
75156 if( flags & BTREE_PREFORMAT ){ 75977 if( flags & BTREE_PREFORMAT ){
@@ -75301,7 +76122,11 @@ SQLITE_PRIVATE int sqlite3BtreeTransferRow(BtCursor *pDest, BtCursor *pSrc, i64
75301 u32 nRem; /* Bytes of data still to copy */ 76122 u32 nRem; /* Bytes of data still to copy */
75302 76123
75303 getCellInfo(pSrc); 76124 getCellInfo(pSrc);
75304 aOut += putVarint32(aOut, pSrc->info.nPayload); 76125 if( pSrc->info.nPayload<0x80 ){
76126 *(aOut++) = pSrc->info.nPayload;
76127 }else{
76128 aOut += sqlite3PutVarint(aOut, pSrc->info.nPayload);
76129 }
75305 if( pDest->pKeyInfo==0 ) aOut += putVarint(aOut, iKey); 76130 if( pDest->pKeyInfo==0 ) aOut += putVarint(aOut, iKey);
75306 nIn = pSrc->info.nLocal; 76131 nIn = pSrc->info.nLocal;
75307 aIn = pSrc->info.pPayload; 76132 aIn = pSrc->info.pPayload;
@@ -75461,7 +76286,8 @@ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
75461 bPreserve = (flags & BTREE_SAVEPOSITION)!=0; 76286 bPreserve = (flags & BTREE_SAVEPOSITION)!=0;
75462 if( bPreserve ){ 76287 if( bPreserve ){
75463 if( !pPage->leaf 76288 if( !pPage->leaf
75464 || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3) 76289 || (pPage->nFree+pPage->xCellSize(pPage,pCell)+2) >
76290 (int)(pBt->usableSize*2/3)
75465 || pPage->nCell==1 /* See dbfuzz001.test for a test case */ 76291 || pPage->nCell==1 /* See dbfuzz001.test for a test case */
75466 ){ 76292 ){
75467 /* A b-tree rebalance will be required after deleting this entry. 76293 /* A b-tree rebalance will be required after deleting this entry.
@@ -75557,7 +76383,15 @@ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
75557 ** been corrected, so be it. Otherwise, after balancing the leaf node, 76383 ** been corrected, so be it. Otherwise, after balancing the leaf node,
75558 ** walk the cursor up the tree to the internal node and balance it as 76384 ** walk the cursor up the tree to the internal node and balance it as
75559 ** well. */ 76385 ** well. */
75560 rc = balance(pCur); 76386 assert( pCur->pPage->nOverflow==0 );
76387 assert( pCur->pPage->nFree>=0 );
76388 if( pCur->pPage->nFree*3<=(int)pCur->pBt->usableSize*2 ){
76389 /* Optimization: If the free space is less than 2/3rds of the page,
76390 ** then balance() will always be a no-op. No need to invoke it. */
76391 rc = SQLITE_OK;
76392 }else{
76393 rc = balance(pCur);
76394 }
75561 if( rc==SQLITE_OK && pCur->iPage>iCellDepth ){ 76395 if( rc==SQLITE_OK && pCur->iPage>iCellDepth ){
75562 releasePageNotNull(pCur->pPage); 76396 releasePageNotNull(pCur->pPage);
75563 pCur->iPage--; 76397 pCur->iPage--;
@@ -78052,7 +78886,11 @@ SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){
78052 assert( !sqlite3VdbeMemIsRowSet(pMem) ); 78886 assert( !sqlite3VdbeMemIsRowSet(pMem) );
78053 assert( desiredEnc==SQLITE_UTF8 || desiredEnc==SQLITE_UTF16LE 78887 assert( desiredEnc==SQLITE_UTF8 || desiredEnc==SQLITE_UTF16LE
78054 || desiredEnc==SQLITE_UTF16BE ); 78888 || desiredEnc==SQLITE_UTF16BE );
78055 if( !(pMem->flags&MEM_Str) || pMem->enc==desiredEnc ){ 78889 if( !(pMem->flags&MEM_Str) ){
78890 pMem->enc = desiredEnc;
78891 return SQLITE_OK;
78892 }
78893 if( pMem->enc==desiredEnc ){
78056 return SQLITE_OK; 78894 return SQLITE_OK;
78057 } 78895 }
78058 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); 78896 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
@@ -78301,9 +79139,10 @@ SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem *pMem, FuncDef *pFunc){
78301 Mem t; 79139 Mem t;
78302 assert( pFunc!=0 ); 79140 assert( pFunc!=0 );
78303 assert( pMem!=0 ); 79141 assert( pMem!=0 );
79142 assert( pMem->db!=0 );
78304 assert( pFunc->xFinalize!=0 ); 79143 assert( pFunc->xFinalize!=0 );
78305 assert( (pMem->flags & MEM_Null)!=0 || pFunc==pMem->u.pDef ); 79144 assert( (pMem->flags & MEM_Null)!=0 || pFunc==pMem->u.pDef );
78306 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); 79145 assert( sqlite3_mutex_held(pMem->db->mutex) );
78307 memset(&ctx, 0, sizeof(ctx)); 79146 memset(&ctx, 0, sizeof(ctx));
78308 memset(&t, 0, sizeof(t)); 79147 memset(&t, 0, sizeof(t));
78309 t.flags = MEM_Null; 79148 t.flags = MEM_Null;
@@ -78311,6 +79150,7 @@ SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem *pMem, FuncDef *pFunc){
78311 ctx.pOut = &t; 79150 ctx.pOut = &t;
78312 ctx.pMem = pMem; 79151 ctx.pMem = pMem;
78313 ctx.pFunc = pFunc; 79152 ctx.pFunc = pFunc;
79153 ctx.enc = ENC(t.db);
78314 pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */ 79154 pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
78315 assert( (pMem->flags & MEM_Dyn)==0 ); 79155 assert( (pMem->flags & MEM_Dyn)==0 );
78316 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc); 79156 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
@@ -78332,12 +79172,14 @@ SQLITE_PRIVATE int sqlite3VdbeMemAggValue(Mem *pAccum, Mem *pOut, FuncDef *pFunc
78332 assert( pFunc!=0 ); 79172 assert( pFunc!=0 );
78333 assert( pFunc->xValue!=0 ); 79173 assert( pFunc->xValue!=0 );
78334 assert( (pAccum->flags & MEM_Null)!=0 || pFunc==pAccum->u.pDef ); 79174 assert( (pAccum->flags & MEM_Null)!=0 || pFunc==pAccum->u.pDef );
78335 assert( pAccum->db==0 || sqlite3_mutex_held(pAccum->db->mutex) ); 79175 assert( pAccum->db!=0 );
79176 assert( sqlite3_mutex_held(pAccum->db->mutex) );
78336 memset(&ctx, 0, sizeof(ctx)); 79177 memset(&ctx, 0, sizeof(ctx));
78337 sqlite3VdbeMemSetNull(pOut); 79178 sqlite3VdbeMemSetNull(pOut);
78338 ctx.pOut = pOut; 79179 ctx.pOut = pOut;
78339 ctx.pMem = pAccum; 79180 ctx.pMem = pAccum;
78340 ctx.pFunc = pFunc; 79181 ctx.pFunc = pFunc;
79182 ctx.enc = ENC(pAccum->db);
78341 pFunc->xValue(&ctx); 79183 pFunc->xValue(&ctx);
78342 return ctx.isError; 79184 return ctx.isError;
78343} 79185}
@@ -78403,6 +79245,14 @@ SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
78403 } 79245 }
78404} 79246}
78405 79247
79248/* Like sqlite3VdbeMemRelease() but faster for cases where we
79249** know in advance that the Mem is not MEM_Dyn or MEM_Agg.
79250*/
79251SQLITE_PRIVATE void sqlite3VdbeMemReleaseMalloc(Mem *p){
79252 assert( !VdbeMemDynamic(p) );
79253 if( p->szMalloc ) vdbeMemClear(p);
79254}
79255
78406/* 79256/*
78407** Convert a 64-bit IEEE double into a 64-bit signed integer. 79257** Convert a 64-bit IEEE double into a 64-bit signed integer.
78408** If the double is out of range of a 64-bit signed integer then 79258** If the double is out of range of a 64-bit signed integer then
@@ -78947,6 +79797,13 @@ SQLITE_PRIVATE void sqlite3VdbeMemMove(Mem *pTo, Mem *pFrom){
78947** stored without allocating memory, then it is. If a memory allocation 79797** stored without allocating memory, then it is. If a memory allocation
78948** is required to store the string, then value of pMem is unchanged. In 79798** is required to store the string, then value of pMem is unchanged. In
78949** either case, SQLITE_TOOBIG is returned. 79799** either case, SQLITE_TOOBIG is returned.
79800**
79801** The "enc" parameter is the text encoding for the string, or zero
79802** to store a blob.
79803**
79804** If n is negative, then the string consists of all bytes up to but
79805** excluding the first zero character. The n parameter must be
79806** non-negative for blobs.
78950*/ 79807*/
78951SQLITE_PRIVATE int sqlite3VdbeMemSetStr( 79808SQLITE_PRIVATE int sqlite3VdbeMemSetStr(
78952 Mem *pMem, /* Memory cell to set to string value */ 79809 Mem *pMem, /* Memory cell to set to string value */
@@ -78957,11 +79814,12 @@ SQLITE_PRIVATE int sqlite3VdbeMemSetStr(
78957){ 79814){
78958 i64 nByte = n; /* New value for pMem->n */ 79815 i64 nByte = n; /* New value for pMem->n */
78959 int iLimit; /* Maximum allowed string or blob size */ 79816 int iLimit; /* Maximum allowed string or blob size */
78960 u16 flags = 0; /* New value for pMem->flags */ 79817 u16 flags; /* New value for pMem->flags */
78961 79818
78962 assert( pMem!=0 ); 79819 assert( pMem!=0 );
78963 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); 79820 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
78964 assert( !sqlite3VdbeMemIsRowSet(pMem) ); 79821 assert( !sqlite3VdbeMemIsRowSet(pMem) );
79822 assert( enc!=0 || n>=0 );
78965 79823
78966 /* If z is a NULL pointer, set pMem to contain an SQL NULL. */ 79824 /* If z is a NULL pointer, set pMem to contain an SQL NULL. */
78967 if( !z ){ 79825 if( !z ){
@@ -78974,7 +79832,6 @@ SQLITE_PRIVATE int sqlite3VdbeMemSetStr(
78974 }else{ 79832 }else{
78975 iLimit = SQLITE_MAX_LENGTH; 79833 iLimit = SQLITE_MAX_LENGTH;
78976 } 79834 }
78977 flags = (enc==0?MEM_Blob:MEM_Str);
78978 if( nByte<0 ){ 79835 if( nByte<0 ){
78979 assert( enc!=0 ); 79836 assert( enc!=0 );
78980 if( enc==SQLITE_UTF8 ){ 79837 if( enc==SQLITE_UTF8 ){
@@ -78982,7 +79839,23 @@ SQLITE_PRIVATE int sqlite3VdbeMemSetStr(
78982 }else{ 79839 }else{
78983 for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){} 79840 for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
78984 } 79841 }
78985 flags |= MEM_Term; 79842 flags= MEM_Str|MEM_Term;
79843 }else if( enc==0 ){
79844 flags = MEM_Blob;
79845 enc = SQLITE_UTF8;
79846 }else{
79847 flags = MEM_Str;
79848 }
79849 if( nByte>iLimit ){
79850 if( xDel && xDel!=SQLITE_TRANSIENT ){
79851 if( xDel==SQLITE_DYNAMIC ){
79852 sqlite3DbFree(pMem->db, (void*)z);
79853 }else{
79854 xDel((void*)z);
79855 }
79856 }
79857 sqlite3VdbeMemSetNull(pMem);
79858 return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG);
78986 } 79859 }
78987 79860
78988 /* The following block sets the new values of Mem.z and Mem.xDel. It 79861 /* The following block sets the new values of Mem.z and Mem.xDel. It
@@ -78994,9 +79867,6 @@ SQLITE_PRIVATE int sqlite3VdbeMemSetStr(
78994 if( flags&MEM_Term ){ 79867 if( flags&MEM_Term ){
78995 nAlloc += (enc==SQLITE_UTF8?1:2); 79868 nAlloc += (enc==SQLITE_UTF8?1:2);
78996 } 79869 }
78997 if( nByte>iLimit ){
78998 return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG);
78999 }
79000 testcase( nAlloc==0 ); 79870 testcase( nAlloc==0 );
79001 testcase( nAlloc==31 ); 79871 testcase( nAlloc==31 );
79002 testcase( nAlloc==32 ); 79872 testcase( nAlloc==32 );
@@ -79018,16 +79888,7 @@ SQLITE_PRIVATE int sqlite3VdbeMemSetStr(
79018 79888
79019 pMem->n = (int)(nByte & 0x7fffffff); 79889 pMem->n = (int)(nByte & 0x7fffffff);
79020 pMem->flags = flags; 79890 pMem->flags = flags;
79021 if( enc ){ 79891 pMem->enc = enc;
79022 pMem->enc = enc;
79023#ifdef SQLITE_ENABLE_SESSION
79024 }else if( pMem->db==0 ){
79025 pMem->enc = SQLITE_UTF8;
79026#endif
79027 }else{
79028 assert( pMem->db!=0 );
79029 pMem->enc = ENC(pMem->db);
79030 }
79031 79892
79032#ifndef SQLITE_OMIT_UTF16 79893#ifndef SQLITE_OMIT_UTF16
79033 if( enc>SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){ 79894 if( enc>SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
@@ -79035,9 +79896,6 @@ SQLITE_PRIVATE int sqlite3VdbeMemSetStr(
79035 } 79896 }
79036#endif 79897#endif
79037 79898
79038 if( nByte>iLimit ){
79039 return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG);
79040 }
79041 79899
79042 return SQLITE_OK; 79900 return SQLITE_OK;
79043} 79901}
@@ -79315,10 +80173,12 @@ static int valueFromFunction(
79315 goto value_from_function_out; 80173 goto value_from_function_out;
79316 } 80174 }
79317 80175
79318 assert( pCtx->pParse->rc==SQLITE_OK ); 80176 testcase( pCtx->pParse->rc==SQLITE_ERROR );
80177 testcase( pCtx->pParse->rc==SQLITE_OK );
79319 memset(&ctx, 0, sizeof(ctx)); 80178 memset(&ctx, 0, sizeof(ctx));
79320 ctx.pOut = pVal; 80179 ctx.pOut = pVal;
79321 ctx.pFunc = pFunc; 80180 ctx.pFunc = pFunc;
80181 ctx.enc = ENC(db);
79322 pFunc->xSFunc(&ctx, nVal, apVal); 80182 pFunc->xSFunc(&ctx, nVal, apVal);
79323 if( ctx.isError ){ 80183 if( ctx.isError ){
79324 rc = ctx.isError; 80184 rc = ctx.isError;
@@ -79394,8 +80254,8 @@ static int valueFromExpr(
79394 rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx); 80254 rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
79395 testcase( rc!=SQLITE_OK ); 80255 testcase( rc!=SQLITE_OK );
79396 if( *ppVal ){ 80256 if( *ppVal ){
79397 sqlite3VdbeMemCast(*ppVal, aff, SQLITE_UTF8); 80257 sqlite3VdbeMemCast(*ppVal, aff, enc);
79398 sqlite3ValueApplyAffinity(*ppVal, affinity, SQLITE_UTF8); 80258 sqlite3ValueApplyAffinity(*ppVal, affinity, enc);
79399 } 80259 }
79400 return rc; 80260 return rc;
79401 } 80261 }
@@ -79829,7 +80689,7 @@ SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse *pParse){
79829 p->pNext = db->pVdbe; 80689 p->pNext = db->pVdbe;
79830 p->pPrev = 0; 80690 p->pPrev = 0;
79831 db->pVdbe = p; 80691 db->pVdbe = p;
79832 p->iVdbeMagic = VDBE_MAGIC_INIT; 80692 assert( p->eVdbeState==VDBE_INIT_STATE );
79833 p->pParse = pParse; 80693 p->pParse = pParse;
79834 pParse->pVdbe = p; 80694 pParse->pVdbe = p;
79835 assert( pParse->aLabel==0 ); 80695 assert( pParse->aLabel==0 );
@@ -79974,7 +80834,7 @@ static int growOpArray(Vdbe *v, int nOp){
79974 return SQLITE_NOMEM; 80834 return SQLITE_NOMEM;
79975 } 80835 }
79976 80836
79977 assert( nOp<=(1024/sizeof(Op)) ); 80837 assert( nOp<=(int)(1024/sizeof(Op)) );
79978 assert( nNew>=(v->nOpAlloc+nOp) ); 80838 assert( nNew>=(v->nOpAlloc+nOp) );
79979 pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op)); 80839 pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
79980 if( pNew ){ 80840 if( pNew ){
@@ -80030,7 +80890,7 @@ SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
80030 VdbeOp *pOp; 80890 VdbeOp *pOp;
80031 80891
80032 i = p->nOp; 80892 i = p->nOp;
80033 assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); 80893 assert( p->eVdbeState==VDBE_INIT_STATE );
80034 assert( op>=0 && op<0xff ); 80894 assert( op>=0 && op<0xff );
80035 if( p->nOpAlloc<=i ){ 80895 if( p->nOpAlloc<=i ){
80036 return growOp3(p, op, p1, p2, p3); 80896 return growOp3(p, op, p1, p2, p3);
@@ -80362,7 +81222,7 @@ static SQLITE_NOINLINE void resizeResolveLabel(Parse *p, Vdbe *v, int j){
80362SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){ 81222SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
80363 Parse *p = v->pParse; 81223 Parse *p = v->pParse;
80364 int j = ADDR(x); 81224 int j = ADDR(x);
80365 assert( v->iVdbeMagic==VDBE_MAGIC_INIT ); 81225 assert( v->eVdbeState==VDBE_INIT_STATE );
80366 assert( j<-p->nLabel ); 81226 assert( j<-p->nLabel );
80367 assert( j>=0 ); 81227 assert( j>=0 );
80368#ifdef SQLITE_DEBUG 81228#ifdef SQLITE_DEBUG
@@ -80382,14 +81242,20 @@ SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
80382** Mark the VDBE as one that can only be run one time. 81242** Mark the VDBE as one that can only be run one time.
80383*/ 81243*/
80384SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe *p){ 81244SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe *p){
80385 p->runOnlyOnce = 1; 81245 sqlite3VdbeAddOp2(p, OP_Expire, 1, 1);
80386} 81246}
80387 81247
80388/* 81248/*
80389** Mark the VDBE as one that can only be run multiple times. 81249** Mark the VDBE as one that can be run multiple times.
80390*/ 81250*/
80391SQLITE_PRIVATE void sqlite3VdbeReusable(Vdbe *p){ 81251SQLITE_PRIVATE void sqlite3VdbeReusable(Vdbe *p){
80392 p->runOnlyOnce = 0; 81252 int i;
81253 for(i=1; ALWAYS(i<p->nOp); i++){
81254 if( ALWAYS(p->aOp[i].opcode==OP_Expire) ){
81255 p->aOp[1].opcode = OP_Noop;
81256 break;
81257 }
81258 }
80393} 81259}
80394 81260
80395#ifdef SQLITE_DEBUG /* sqlite3AssertMayAbort() logic */ 81261#ifdef SQLITE_DEBUG /* sqlite3AssertMayAbort() logic */
@@ -80493,6 +81359,8 @@ SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){
80493 int hasInitCoroutine = 0; 81359 int hasInitCoroutine = 0;
80494 Op *pOp; 81360 Op *pOp;
80495 VdbeOpIter sIter; 81361 VdbeOpIter sIter;
81362
81363 if( v==0 ) return 0;
80496 memset(&sIter, 0, sizeof(sIter)); 81364 memset(&sIter, 0, sizeof(sIter));
80497 sIter.v = v; 81365 sIter.v = v;
80498 81366
@@ -80576,7 +81444,7 @@ SQLITE_PRIVATE void sqlite3VdbeAssertAbortable(Vdbe *p){
80576** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately 81444** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately
80577** indicate what the prepared statement actually does. 81445** indicate what the prepared statement actually does.
80578** 81446**
80579** (4) Initialize the p4.xAdvance pointer on opcodes that use it. 81447** (4) (discontinued)
80580** 81448**
80581** (5) Reclaim the memory allocated for storing labels. 81449** (5) Reclaim the memory allocated for storing labels.
80582** 81450**
@@ -80622,25 +81490,6 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
80622 p->bIsReader = 1; 81490 p->bIsReader = 1;
80623 break; 81491 break;
80624 } 81492 }
80625 case OP_Next:
80626 case OP_SorterNext: {
80627 pOp->p4.xAdvance = sqlite3BtreeNext;
80628 pOp->p4type = P4_ADVANCE;
80629 /* The code generator never codes any of these opcodes as a jump
80630 ** to a label. They are always coded as a jump backwards to a
80631 ** known address */
80632 assert( pOp->p2>=0 );
80633 break;
80634 }
80635 case OP_Prev: {
80636 pOp->p4.xAdvance = sqlite3BtreePrevious;
80637 pOp->p4type = P4_ADVANCE;
80638 /* The code generator never codes any of these opcodes as a jump
80639 ** to a label. They are always coded as a jump backwards to a
80640 ** known address */
80641 assert( pOp->p2>=0 );
80642 break;
80643 }
80644#ifndef SQLITE_OMIT_VIRTUALTABLE 81493#ifndef SQLITE_OMIT_VIRTUALTABLE
80645 case OP_VUpdate: { 81494 case OP_VUpdate: {
80646 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2; 81495 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
@@ -80676,18 +81525,104 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
80676 if( pOp==p->aOp ) break; 81525 if( pOp==p->aOp ) break;
80677 pOp--; 81526 pOp--;
80678 } 81527 }
80679 sqlite3DbFree(p->db, pParse->aLabel); 81528 if( aLabel ){
80680 pParse->aLabel = 0; 81529 sqlite3DbFreeNN(p->db, pParse->aLabel);
81530 pParse->aLabel = 0;
81531 }
80681 pParse->nLabel = 0; 81532 pParse->nLabel = 0;
80682 *pMaxFuncArgs = nMaxArgs; 81533 *pMaxFuncArgs = nMaxArgs;
80683 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) ); 81534 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
80684} 81535}
80685 81536
81537#ifdef SQLITE_DEBUG
81538/*
81539** Check to see if a subroutine contains a jump to a location outside of
81540** the subroutine. If a jump outside the subroutine is detected, add code
81541** that will cause the program to halt with an error message.
81542**
81543** The subroutine consists of opcodes between iFirst and iLast. Jumps to
81544** locations within the subroutine are acceptable. iRetReg is a register
81545** that contains the return address. Jumps to outside the range of iFirst
81546** through iLast are also acceptable as long as the jump destination is
81547** an OP_Return to iReturnAddr.
81548**
81549** A jump to an unresolved label means that the jump destination will be
81550** beyond the current address. That is normally a jump to an early
81551** termination and is consider acceptable.
81552**
81553** This routine only runs during debug builds. The purpose is (of course)
81554** to detect invalid escapes out of a subroutine. The OP_Halt opcode
81555** is generated rather than an assert() or other error, so that ".eqp full"
81556** will still work to show the original bytecode, to aid in debugging.
81557*/
81558SQLITE_PRIVATE void sqlite3VdbeNoJumpsOutsideSubrtn(
81559 Vdbe *v, /* The byte-code program under construction */
81560 int iFirst, /* First opcode of the subroutine */
81561 int iLast, /* Last opcode of the subroutine */
81562 int iRetReg /* Subroutine return address register */
81563){
81564 VdbeOp *pOp;
81565 Parse *pParse;
81566 int i;
81567 sqlite3_str *pErr = 0;
81568 assert( v!=0 );
81569 pParse = v->pParse;
81570 assert( pParse!=0 );
81571 if( pParse->nErr ) return;
81572 assert( iLast>=iFirst );
81573 assert( iLast<v->nOp );
81574 pOp = &v->aOp[iFirst];
81575 for(i=iFirst; i<=iLast; i++, pOp++){
81576 if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 ){
81577 int iDest = pOp->p2; /* Jump destination */
81578 if( iDest==0 ) continue;
81579 if( pOp->opcode==OP_Gosub ) continue;
81580 if( iDest<0 ){
81581 int j = ADDR(iDest);
81582 assert( j>=0 );
81583 if( j>=-pParse->nLabel || pParse->aLabel[j]<0 ){
81584 continue;
81585 }
81586 iDest = pParse->aLabel[j];
81587 }
81588 if( iDest<iFirst || iDest>iLast ){
81589 int j = iDest;
81590 for(; j<v->nOp; j++){
81591 VdbeOp *pX = &v->aOp[j];
81592 if( pX->opcode==OP_Return ){
81593 if( pX->p1==iRetReg ) break;
81594 continue;
81595 }
81596 if( pX->opcode==OP_Noop ) continue;
81597 if( pX->opcode==OP_Explain ) continue;
81598 if( pErr==0 ){
81599 pErr = sqlite3_str_new(0);
81600 }else{
81601 sqlite3_str_appendchar(pErr, 1, '\n');
81602 }
81603 sqlite3_str_appendf(pErr,
81604 "Opcode at %d jumps to %d which is outside the "
81605 "subroutine at %d..%d",
81606 i, iDest, iFirst, iLast);
81607 break;
81608 }
81609 }
81610 }
81611 }
81612 if( pErr ){
81613 char *zErr = sqlite3_str_finish(pErr);
81614 sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_INTERNAL, OE_Abort, 0, zErr, 0);
81615 sqlite3_free(zErr);
81616 sqlite3MayAbort(pParse);
81617 }
81618}
81619#endif /* SQLITE_DEBUG */
81620
80686/* 81621/*
80687** Return the address of the next instruction to be inserted. 81622** Return the address of the next instruction to be inserted.
80688*/ 81623*/
80689SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){ 81624SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){
80690 assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); 81625 assert( p->eVdbeState==VDBE_INIT_STATE );
80691 return p->nOp; 81626 return p->nOp;
80692} 81627}
80693 81628
@@ -80772,7 +81707,7 @@ SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(
80772 int i; 81707 int i;
80773 VdbeOp *pOut, *pFirst; 81708 VdbeOp *pOut, *pFirst;
80774 assert( nOp>0 ); 81709 assert( nOp>0 );
80775 assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); 81710 assert( p->eVdbeState==VDBE_INIT_STATE );
80776 if( p->nOp + nOp > p->nOpAlloc && growOpArray(p, nOp) ){ 81711 if( p->nOp + nOp > p->nOpAlloc && growOpArray(p, nOp) ){
80777 return 0; 81712 return 0;
80778 } 81713 }
@@ -80924,7 +81859,6 @@ static void freeP4(sqlite3 *db, int p4type, void *p4){
80924 case P4_REAL: 81859 case P4_REAL:
80925 case P4_INT64: 81860 case P4_INT64:
80926 case P4_DYNAMIC: 81861 case P4_DYNAMIC:
80927 case P4_DYNBLOB:
80928 case P4_INTARRAY: { 81862 case P4_INTARRAY: {
80929 sqlite3DbFree(db, p4); 81863 sqlite3DbFree(db, p4);
80930 break; 81864 break;
@@ -80964,13 +81898,16 @@ static void freeP4(sqlite3 *db, int p4type, void *p4){
80964** nOp entries. 81898** nOp entries.
80965*/ 81899*/
80966static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){ 81900static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
81901 assert( nOp>=0 );
80967 if( aOp ){ 81902 if( aOp ){
80968 Op *pOp; 81903 Op *pOp = &aOp[nOp-1];
80969 for(pOp=&aOp[nOp-1]; pOp>=aOp; pOp--){ 81904 while(1){ /* Exit via break */
80970 if( pOp->p4type <= P4_FREE_IF_LE ) freeP4(db, pOp->p4type, pOp->p4.p); 81905 if( pOp->p4type <= P4_FREE_IF_LE ) freeP4(db, pOp->p4type, pOp->p4.p);
80971#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS 81906#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
80972 sqlite3DbFree(db, pOp->zComment); 81907 sqlite3DbFree(db, pOp->zComment);
80973#endif 81908#endif
81909 if( pOp==aOp ) break;
81910 pOp--;
80974 } 81911 }
80975 sqlite3DbFreeNN(db, aOp); 81912 sqlite3DbFreeNN(db, aOp);
80976 } 81913 }
@@ -81032,7 +81969,7 @@ SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(
81032 u32 mask, /* Mask of registers to NOT release */ 81969 u32 mask, /* Mask of registers to NOT release */
81033 int bUndefine /* If true, mark registers as undefined */ 81970 int bUndefine /* If true, mark registers as undefined */
81034){ 81971){
81035 if( N==0 ) return; 81972 if( N==0 || OptimizationDisabled(pParse->db, SQLITE_ReleaseReg) ) return;
81036 assert( pParse->pVdbe ); 81973 assert( pParse->pVdbe );
81037 assert( iFirst>=1 ); 81974 assert( iFirst>=1 );
81038 assert( iFirst+N-1<=pParse->nMem ); 81975 assert( iFirst+N-1<=pParse->nMem );
@@ -81096,7 +82033,7 @@ SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int
81096 sqlite3 *db; 82033 sqlite3 *db;
81097 assert( p!=0 ); 82034 assert( p!=0 );
81098 db = p->db; 82035 db = p->db;
81099 assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); 82036 assert( p->eVdbeState==VDBE_INIT_STATE );
81100 assert( p->aOp!=0 || db->mallocFailed ); 82037 assert( p->aOp!=0 || db->mallocFailed );
81101 if( db->mallocFailed ){ 82038 if( db->mallocFailed ){
81102 if( n!=P4_VTAB ) freeP4(db, n, (void*)*(char**)&zP4); 82039 if( n!=P4_VTAB ) freeP4(db, n, (void*)*(char**)&zP4);
@@ -81224,7 +82161,7 @@ SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
81224 /* C89 specifies that the constant "dummy" will be initialized to all 82161 /* C89 specifies that the constant "dummy" will be initialized to all
81225 ** zeros, which is correct. MSVC generates a warning, nevertheless. */ 82162 ** zeros, which is correct. MSVC generates a warning, nevertheless. */
81226 static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */ 82163 static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */
81227 assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); 82164 assert( p->eVdbeState==VDBE_INIT_STATE );
81228 if( addr<0 ){ 82165 if( addr<0 ){
81229 addr = p->nOp - 1; 82166 addr = p->nOp - 1;
81230 } 82167 }
@@ -81291,8 +82228,11 @@ SQLITE_PRIVATE char *sqlite3VdbeDisplayComment(
81291 if( c=='4' ){ 82228 if( c=='4' ){
81292 sqlite3_str_appendall(&x, zP4); 82229 sqlite3_str_appendall(&x, zP4);
81293 }else if( c=='X' ){ 82230 }else if( c=='X' ){
81294 sqlite3_str_appendall(&x, pOp->zComment); 82231 if( pOp->zComment && pOp->zComment[0] ){
81295 seenCom = 1; 82232 sqlite3_str_appendall(&x, pOp->zComment);
82233 seenCom = 1;
82234 break;
82235 }
81296 }else{ 82236 }else{
81297 int v1 = translateP(c, pOp); 82237 int v1 = translateP(c, pOp);
81298 int v2; 82238 int v2;
@@ -81521,10 +82461,6 @@ SQLITE_PRIVATE char *sqlite3VdbeDisplayP4(sqlite3 *db, Op *pOp){
81521 zP4 = "program"; 82461 zP4 = "program";
81522 break; 82462 break;
81523 } 82463 }
81524 case P4_DYNBLOB:
81525 case P4_ADVANCE: {
81526 break;
81527 }
81528 case P4_TABLE: { 82464 case P4_TABLE: {
81529 zP4 = pOp->p4.pTab->zName; 82465 zP4 = pOp->p4.pTab->zName;
81530 break; 82466 break;
@@ -81656,21 +82592,40 @@ SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE *pOut, int pc, VdbeOp *pOp){
81656 82592
81657/* 82593/*
81658** Initialize an array of N Mem element. 82594** Initialize an array of N Mem element.
82595**
82596** This is a high-runner, so only those fields that really do need to
82597** be initialized are set. The Mem structure is organized so that
82598** the fields that get initialized are nearby and hopefully on the same
82599** cache line.
82600**
82601** Mem.flags = flags
82602** Mem.db = db
82603** Mem.szMalloc = 0
82604**
82605** All other fields of Mem can safely remain uninitialized for now. They
82606** will be initialized before use.
81659*/ 82607*/
81660static void initMemArray(Mem *p, int N, sqlite3 *db, u16 flags){ 82608static void initMemArray(Mem *p, int N, sqlite3 *db, u16 flags){
81661 while( (N--)>0 ){ 82609 if( N>0 ){
81662 p->db = db; 82610 do{
81663 p->flags = flags; 82611 p->flags = flags;
81664 p->szMalloc = 0; 82612 p->db = db;
82613 p->szMalloc = 0;
81665#ifdef SQLITE_DEBUG 82614#ifdef SQLITE_DEBUG
81666 p->pScopyFrom = 0; 82615 p->pScopyFrom = 0;
81667#endif 82616#endif
81668 p++; 82617 p++;
82618 }while( (--N)>0 );
81669 } 82619 }
81670} 82620}
81671 82621
81672/* 82622/*
81673** Release an array of N Mem elements 82623** Release auxiliary memory held in an array of N Mem elements.
82624**
82625** After this routine returns, all Mem elements in the array will still
82626** be valid. Those Mem elements that were not holding auxiliary resources
82627** will be unchanged. Mem elements which had something freed will be
82628** set to MEM_Undefined.
81674*/ 82629*/
81675static void releaseMemArray(Mem *p, int N){ 82630static void releaseMemArray(Mem *p, int N){
81676 if( p && N ){ 82631 if( p && N ){
@@ -81703,12 +82658,17 @@ static void releaseMemArray(Mem *p, int N){
81703 if( p->flags&(MEM_Agg|MEM_Dyn) ){ 82658 if( p->flags&(MEM_Agg|MEM_Dyn) ){
81704 testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel ); 82659 testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel );
81705 sqlite3VdbeMemRelease(p); 82660 sqlite3VdbeMemRelease(p);
82661 p->flags = MEM_Undefined;
81706 }else if( p->szMalloc ){ 82662 }else if( p->szMalloc ){
81707 sqlite3DbFreeNN(db, p->zMalloc); 82663 sqlite3DbFreeNN(db, p->zMalloc);
81708 p->szMalloc = 0; 82664 p->szMalloc = 0;
82665 p->flags = MEM_Undefined;
81709 } 82666 }
81710 82667#ifdef SQLITE_DEBUG
81711 p->flags = MEM_Undefined; 82668 else{
82669 p->flags = MEM_Undefined;
82670 }
82671#endif
81712 }while( (++p)<pEnd ); 82672 }while( (++p)<pEnd );
81713 } 82673 }
81714} 82674}
@@ -81867,7 +82827,7 @@ SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame *p){
81867 VdbeCursor **apCsr = (VdbeCursor **)&aMem[p->nChildMem]; 82827 VdbeCursor **apCsr = (VdbeCursor **)&aMem[p->nChildMem];
81868 assert( sqlite3VdbeFrameIsValid(p) ); 82828 assert( sqlite3VdbeFrameIsValid(p) );
81869 for(i=0; i<p->nChildCsr; i++){ 82829 for(i=0; i<p->nChildCsr; i++){
81870 sqlite3VdbeFreeCursor(p->v, apCsr[i]); 82830 if( apCsr[i] ) sqlite3VdbeFreeCursorNN(p->v, apCsr[i]);
81871 } 82831 }
81872 releaseMemArray(aMem, p->nChildMem); 82832 releaseMemArray(aMem, p->nChildMem);
81873 sqlite3VdbeDeleteAuxData(p->v->db, &p->pAuxData, -1, 0); 82833 sqlite3VdbeDeleteAuxData(p->v->db, &p->pAuxData, -1, 0);
@@ -81906,7 +82866,7 @@ SQLITE_PRIVATE int sqlite3VdbeList(
81906 Op *pOp; /* Current opcode */ 82866 Op *pOp; /* Current opcode */
81907 82867
81908 assert( p->explain ); 82868 assert( p->explain );
81909 assert( p->iVdbeMagic==VDBE_MAGIC_RUN ); 82869 assert( p->eVdbeState==VDBE_RUN_STATE );
81910 assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM ); 82870 assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM );
81911 82871
81912 /* Even though this opcode does not use dynamic strings for 82872 /* Even though this opcode does not use dynamic strings for
@@ -82061,11 +83021,11 @@ struct ReusableSpace {
82061static void *allocSpace( 83021static void *allocSpace(
82062 struct ReusableSpace *p, /* Bulk memory available for allocation */ 83022 struct ReusableSpace *p, /* Bulk memory available for allocation */
82063 void *pBuf, /* Pointer to a prior allocation */ 83023 void *pBuf, /* Pointer to a prior allocation */
82064 sqlite3_int64 nByte /* Bytes of memory needed */ 83024 sqlite3_int64 nByte /* Bytes of memory needed. */
82065){ 83025){
82066 assert( EIGHT_BYTE_ALIGNMENT(p->pSpace) ); 83026 assert( EIGHT_BYTE_ALIGNMENT(p->pSpace) );
82067 if( pBuf==0 ){ 83027 if( pBuf==0 ){
82068 nByte = ROUND8(nByte); 83028 nByte = ROUND8P(nByte);
82069 if( nByte <= p->nFree ){ 83029 if( nByte <= p->nFree ){
82070 p->nFree -= nByte; 83030 p->nFree -= nByte;
82071 pBuf = &p->pSpace[p->nFree]; 83031 pBuf = &p->pSpace[p->nFree];
@@ -82086,14 +83046,15 @@ SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){
82086 int i; 83046 int i;
82087#endif 83047#endif
82088 assert( p!=0 ); 83048 assert( p!=0 );
82089 assert( p->iVdbeMagic==VDBE_MAGIC_INIT || p->iVdbeMagic==VDBE_MAGIC_RESET ); 83049 assert( p->eVdbeState==VDBE_INIT_STATE
83050 || p->eVdbeState==VDBE_READY_STATE
83051 || p->eVdbeState==VDBE_HALT_STATE );
82090 83052
82091 /* There should be at least one opcode. 83053 /* There should be at least one opcode.
82092 */ 83054 */
82093 assert( p->nOp>0 ); 83055 assert( p->nOp>0 );
82094 83056
82095 /* Set the magic to VDBE_MAGIC_RUN sooner rather than later. */ 83057 p->eVdbeState = VDBE_READY_STATE;
82096 p->iVdbeMagic = VDBE_MAGIC_RUN;
82097 83058
82098#ifdef SQLITE_DEBUG 83059#ifdef SQLITE_DEBUG
82099 for(i=0; i<p->nMem; i++){ 83060 for(i=0; i<p->nMem; i++){
@@ -82149,7 +83110,7 @@ SQLITE_PRIVATE void sqlite3VdbeMakeReady(
82149 assert( p!=0 ); 83110 assert( p!=0 );
82150 assert( p->nOp>0 ); 83111 assert( p->nOp>0 );
82151 assert( pParse!=0 ); 83112 assert( pParse!=0 );
82152 assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); 83113 assert( p->eVdbeState==VDBE_INIT_STATE );
82153 assert( pParse==p->pParse ); 83114 assert( pParse==p->pParse );
82154 p->pVList = pParse->pVList; 83115 p->pVList = pParse->pVList;
82155 pParse->pVList = 0; 83116 pParse->pVList = 0;
@@ -82172,7 +83133,7 @@ SQLITE_PRIVATE void sqlite3VdbeMakeReady(
82172 ** opcode array. This extra memory will be reallocated for other elements 83133 ** opcode array. This extra memory will be reallocated for other elements
82173 ** of the prepared statement. 83134 ** of the prepared statement.
82174 */ 83135 */
82175 n = ROUND8(sizeof(Op)*p->nOp); /* Bytes of opcode memory used */ 83136 n = ROUND8P(sizeof(Op)*p->nOp); /* Bytes of opcode memory used */
82176 x.pSpace = &((u8*)p->aOp)[n]; /* Unused opcode memory */ 83137 x.pSpace = &((u8*)p->aOp)[n]; /* Unused opcode memory */
82177 assert( EIGHT_BYTE_ALIGNMENT(x.pSpace) ); 83138 assert( EIGHT_BYTE_ALIGNMENT(x.pSpace) );
82178 x.nFree = ROUNDDOWN8(pParse->szOpAlloc - n); /* Bytes of unused memory */ 83139 x.nFree = ROUNDDOWN8(pParse->szOpAlloc - n); /* Bytes of unused memory */
@@ -82260,9 +83221,9 @@ SQLITE_PRIVATE void sqlite3VdbeMakeReady(
82260** happens to hold. 83221** happens to hold.
82261*/ 83222*/
82262SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){ 83223SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){
82263 if( pCx==0 ){ 83224 if( pCx ) sqlite3VdbeFreeCursorNN(p,pCx);
82264 return; 83225}
82265 } 83226SQLITE_PRIVATE void sqlite3VdbeFreeCursorNN(Vdbe *p, VdbeCursor *pCx){
82266 switch( pCx->eCurType ){ 83227 switch( pCx->eCurType ){
82267 case CURTYPE_SORTER: { 83228 case CURTYPE_SORTER: {
82268 sqlite3VdbeSorterClose(p->db, pCx); 83229 sqlite3VdbeSorterClose(p->db, pCx);
@@ -82290,14 +83251,12 @@ SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){
82290** Close all cursors in the current frame. 83251** Close all cursors in the current frame.
82291*/ 83252*/
82292static void closeCursorsInFrame(Vdbe *p){ 83253static void closeCursorsInFrame(Vdbe *p){
82293 if( p->apCsr ){ 83254 int i;
82294 int i; 83255 for(i=0; i<p->nCursor; i++){
82295 for(i=0; i<p->nCursor; i++){ 83256 VdbeCursor *pC = p->apCsr[i];
82296 VdbeCursor *pC = p->apCsr[i]; 83257 if( pC ){
82297 if( pC ){ 83258 sqlite3VdbeFreeCursorNN(p, pC);
82298 sqlite3VdbeFreeCursor(p, pC); 83259 p->apCsr[i] = 0;
82299 p->apCsr[i] = 0;
82300 }
82301 } 83260 }
82302 } 83261 }
82303} 83262}
@@ -82346,9 +83305,7 @@ static void closeAllCursors(Vdbe *p){
82346 } 83305 }
82347 assert( p->nFrame==0 ); 83306 assert( p->nFrame==0 );
82348 closeCursorsInFrame(p); 83307 closeCursorsInFrame(p);
82349 if( p->aMem ){ 83308 releaseMemArray(p->aMem, p->nMem);
82350 releaseMemArray(p->aMem, p->nMem);
82351 }
82352 while( p->pDelFrame ){ 83309 while( p->pDelFrame ){
82353 VdbeFrame *pDel = p->pDelFrame; 83310 VdbeFrame *pDel = p->pDelFrame;
82354 p->pDelFrame = pDel->pParent; 83311 p->pDelFrame = pDel->pParent;
@@ -82788,7 +83745,8 @@ SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *p, int deferred){
82788 p->rc = SQLITE_CONSTRAINT_FOREIGNKEY; 83745 p->rc = SQLITE_CONSTRAINT_FOREIGNKEY;
82789 p->errorAction = OE_Abort; 83746 p->errorAction = OE_Abort;
82790 sqlite3VdbeError(p, "FOREIGN KEY constraint failed"); 83747 sqlite3VdbeError(p, "FOREIGN KEY constraint failed");
82791 return SQLITE_ERROR; 83748 if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)==0 ) return SQLITE_ERROR;
83749 return SQLITE_CONSTRAINT_FOREIGNKEY;
82792 } 83750 }
82793 return SQLITE_OK; 83751 return SQLITE_OK;
82794} 83752}
@@ -82827,9 +83785,7 @@ SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe *p){
82827 ** one, or the complete transaction if there is no statement transaction. 83785 ** one, or the complete transaction if there is no statement transaction.
82828 */ 83786 */
82829 83787
82830 if( p->iVdbeMagic!=VDBE_MAGIC_RUN ){ 83788 assert( p->eVdbeState==VDBE_RUN_STATE );
82831 return SQLITE_OK;
82832 }
82833 if( db->mallocFailed ){ 83789 if( db->mallocFailed ){
82834 p->rc = SQLITE_NOMEM_BKPT; 83790 p->rc = SQLITE_NOMEM_BKPT;
82835 } 83791 }
@@ -82838,7 +83794,7 @@ SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe *p){
82838 83794
82839 /* No commit or rollback needed if the program never started or if the 83795 /* No commit or rollback needed if the program never started or if the
82840 ** SQL statement does not read or write a database file. */ 83796 ** SQL statement does not read or write a database file. */
82841 if( p->pc>=0 && p->bIsReader ){ 83797 if( p->bIsReader ){
82842 int mrc; /* Primary error code from p->rc */ 83798 int mrc; /* Primary error code from p->rc */
82843 int eStatementOp = 0; 83799 int eStatementOp = 0;
82844 int isSpecialError; /* Set to true if a 'special' error */ 83800 int isSpecialError; /* Set to true if a 'special' error */
@@ -82986,15 +83942,13 @@ SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe *p){
82986 } 83942 }
82987 83943
82988 /* We have successfully halted and closed the VM. Record this fact. */ 83944 /* We have successfully halted and closed the VM. Record this fact. */
82989 if( p->pc>=0 ){ 83945 db->nVdbeActive--;
82990 db->nVdbeActive--; 83946 if( !p->readOnly ) db->nVdbeWrite--;
82991 if( !p->readOnly ) db->nVdbeWrite--; 83947 if( p->bIsReader ) db->nVdbeRead--;
82992 if( p->bIsReader ) db->nVdbeRead--; 83948 assert( db->nVdbeActive>=db->nVdbeRead );
82993 assert( db->nVdbeActive>=db->nVdbeRead ); 83949 assert( db->nVdbeRead>=db->nVdbeWrite );
82994 assert( db->nVdbeRead>=db->nVdbeWrite ); 83950 assert( db->nVdbeWrite>=0 );
82995 assert( db->nVdbeWrite>=0 ); 83951 p->eVdbeState = VDBE_HALT_STATE;
82996 }
82997 p->iVdbeMagic = VDBE_MAGIC_HALT;
82998 checkActiveVdbeCnt(db); 83952 checkActiveVdbeCnt(db);
82999 if( db->mallocFailed ){ 83953 if( db->mallocFailed ){
83000 p->rc = SQLITE_NOMEM_BKPT; 83954 p->rc = SQLITE_NOMEM_BKPT;
@@ -83076,8 +84030,8 @@ static void vdbeInvokeSqllog(Vdbe *v){
83076** again. 84030** again.
83077** 84031**
83078** To look at it another way, this routine resets the state of the 84032** To look at it another way, this routine resets the state of the
83079** virtual machine from VDBE_MAGIC_RUN or VDBE_MAGIC_HALT back to 84033** virtual machine from VDBE_RUN_STATE or VDBE_HALT_STATE back to
83080** VDBE_MAGIC_INIT. 84034** VDBE_READY_STATE.
83081*/ 84035*/
83082SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){ 84036SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
83083#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) 84037#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
@@ -83091,7 +84045,7 @@ SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
83091 ** error, then it might not have been halted properly. So halt 84045 ** error, then it might not have been halted properly. So halt
83092 ** it now. 84046 ** it now.
83093 */ 84047 */
83094 sqlite3VdbeHalt(p); 84048 if( p->eVdbeState==VDBE_RUN_STATE ) sqlite3VdbeHalt(p);
83095 84049
83096 /* If the VDBE has been run even partially, then transfer the error code 84050 /* If the VDBE has been run even partially, then transfer the error code
83097 ** and error message from the VDBE into the main database structure. But 84051 ** and error message from the VDBE into the main database structure. But
@@ -83105,13 +84059,6 @@ SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
83105 }else{ 84059 }else{
83106 db->errCode = p->rc; 84060 db->errCode = p->rc;
83107 } 84061 }
83108 if( p->runOnlyOnce ) p->expired = 1;
83109 }else if( p->rc && p->expired ){
83110 /* The expired flag was set on the VDBE before the first call
83111 ** to sqlite3_step(). For consistency (since sqlite3_step() was
83112 ** called), set the database error in this case as well.
83113 */
83114 sqlite3ErrorWithMsg(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
83115 } 84062 }
83116 84063
83117 /* Reset register contents and reclaim error message memory. 84064 /* Reset register contents and reclaim error message memory.
@@ -83168,7 +84115,6 @@ SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
83168 } 84115 }
83169 } 84116 }
83170#endif 84117#endif
83171 p->iVdbeMagic = VDBE_MAGIC_RESET;
83172 return p->rc & db->errMask; 84118 return p->rc & db->errMask;
83173} 84119}
83174 84120
@@ -83178,7 +84124,10 @@ SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
83178*/ 84124*/
83179SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe *p){ 84125SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe *p){
83180 int rc = SQLITE_OK; 84126 int rc = SQLITE_OK;
83181 if( p->iVdbeMagic==VDBE_MAGIC_RUN || p->iVdbeMagic==VDBE_MAGIC_HALT ){ 84127 assert( VDBE_RUN_STATE>VDBE_READY_STATE );
84128 assert( VDBE_HALT_STATE>VDBE_READY_STATE );
84129 assert( VDBE_INIT_STATE<VDBE_READY_STATE );
84130 if( p->eVdbeState>=VDBE_READY_STATE ){
83182 rc = sqlite3VdbeReset(p); 84131 rc = sqlite3VdbeReset(p);
83183 assert( (rc & p->db->errMask)==rc ); 84132 assert( (rc & p->db->errMask)==rc );
83184 } 84133 }
@@ -83230,22 +84179,24 @@ SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(sqlite3 *db, AuxData **pp, int iOp,
83230** VdbeDelete() also unlinks the Vdbe from the list of VMs associated with 84179** VdbeDelete() also unlinks the Vdbe from the list of VMs associated with
83231** the database connection and frees the object itself. 84180** the database connection and frees the object itself.
83232*/ 84181*/
83233SQLITE_PRIVATE void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){ 84182static void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){
83234 SubProgram *pSub, *pNext; 84183 SubProgram *pSub, *pNext;
83235 assert( p->db==0 || p->db==db ); 84184 assert( p->db==0 || p->db==db );
83236 releaseMemArray(p->aColName, p->nResColumn*COLNAME_N); 84185 if( p->aColName ){
84186 releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
84187 sqlite3DbFreeNN(db, p->aColName);
84188 }
83237 for(pSub=p->pProgram; pSub; pSub=pNext){ 84189 for(pSub=p->pProgram; pSub; pSub=pNext){
83238 pNext = pSub->pNext; 84190 pNext = pSub->pNext;
83239 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp); 84191 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
83240 sqlite3DbFree(db, pSub); 84192 sqlite3DbFree(db, pSub);
83241 } 84193 }
83242 if( p->iVdbeMagic!=VDBE_MAGIC_INIT ){ 84194 if( p->eVdbeState!=VDBE_INIT_STATE ){
83243 releaseMemArray(p->aVar, p->nVar); 84195 releaseMemArray(p->aVar, p->nVar);
83244 sqlite3DbFree(db, p->pVList); 84196 if( p->pVList ) sqlite3DbFreeNN(db, p->pVList);
83245 sqlite3DbFree(db, p->pFree); 84197 if( p->pFree ) sqlite3DbFreeNN(db, p->pFree);
83246 } 84198 }
83247 vdbeFreeOpArray(db, p->aOp, p->nOp); 84199 vdbeFreeOpArray(db, p->aOp, p->nOp);
83248 sqlite3DbFree(db, p->aColName);
83249 sqlite3DbFree(db, p->zSql); 84200 sqlite3DbFree(db, p->zSql);
83250#ifdef SQLITE_ENABLE_NORMALIZE 84201#ifdef SQLITE_ENABLE_NORMALIZE
83251 sqlite3DbFree(db, p->zNormSql); 84202 sqlite3DbFree(db, p->zNormSql);
@@ -83278,17 +84229,17 @@ SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe *p){
83278 db = p->db; 84229 db = p->db;
83279 assert( sqlite3_mutex_held(db->mutex) ); 84230 assert( sqlite3_mutex_held(db->mutex) );
83280 sqlite3VdbeClearObject(db, p); 84231 sqlite3VdbeClearObject(db, p);
83281 if( p->pPrev ){ 84232 if( db->pnBytesFreed==0 ){
83282 p->pPrev->pNext = p->pNext; 84233 if( p->pPrev ){
83283 }else{ 84234 p->pPrev->pNext = p->pNext;
83284 assert( db->pVdbe==p ); 84235 }else{
83285 db->pVdbe = p->pNext; 84236 assert( db->pVdbe==p );
83286 } 84237 db->pVdbe = p->pNext;
83287 if( p->pNext ){ 84238 }
83288 p->pNext->pPrev = p->pPrev; 84239 if( p->pNext ){
84240 p->pNext->pPrev = p->pPrev;
84241 }
83289 } 84242 }
83290 p->iVdbeMagic = VDBE_MAGIC_DEAD;
83291 p->db = 0;
83292 sqlite3DbFreeNN(db, p); 84243 sqlite3DbFreeNN(db, p);
83293} 84244}
83294 84245
@@ -83323,7 +84274,7 @@ SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor *p){
83323** is supposed to be pointing. If the row was deleted out from under the 84274** is supposed to be pointing. If the row was deleted out from under the
83324** cursor, set the cursor to point to a NULL row. 84275** cursor, set the cursor to point to a NULL row.
83325*/ 84276*/
83326static int SQLITE_NOINLINE handleMovedCursor(VdbeCursor *p){ 84277SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeHandleMovedCursor(VdbeCursor *p){
83327 int isDifferentRow, rc; 84278 int isDifferentRow, rc;
83328 assert( p->eCurType==CURTYPE_BTREE ); 84279 assert( p->eCurType==CURTYPE_BTREE );
83329 assert( p->uc.pCursor!=0 ); 84280 assert( p->uc.pCursor!=0 );
@@ -83339,41 +84290,9 @@ static int SQLITE_NOINLINE handleMovedCursor(VdbeCursor *p){
83339** if need be. Return any I/O error from the restore operation. 84290** if need be. Return any I/O error from the restore operation.
83340*/ 84291*/
83341SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor *p){ 84292SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor *p){
83342 assert( p->eCurType==CURTYPE_BTREE ); 84293 assert( p->eCurType==CURTYPE_BTREE || IsNullCursor(p) );
83343 if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){
83344 return handleMovedCursor(p);
83345 }
83346 return SQLITE_OK;
83347}
83348
83349/*
83350** Make sure the cursor p is ready to read or write the row to which it
83351** was last positioned. Return an error code if an OOM fault or I/O error
83352** prevents us from positioning the cursor to its correct position.
83353**
83354** If a MoveTo operation is pending on the given cursor, then do that
83355** MoveTo now. If no move is pending, check to see if the row has been
83356** deleted out from under the cursor and if it has, mark the row as
83357** a NULL row.
83358**
83359** If the cursor is already pointing to the correct row and that row has
83360** not been deleted out from under the cursor, then this routine is a no-op.
83361*/
83362SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, u32 *piCol){
83363 VdbeCursor *p = *pp;
83364 assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO );
83365 if( p->deferredMoveto ){
83366 u32 iMap;
83367 assert( !p->isEphemeral );
83368 if( p->ub.aAltMap && (iMap = p->ub.aAltMap[1+*piCol])>0 && !p->nullRow ){
83369 *pp = p->pAltCursor;
83370 *piCol = iMap - 1;
83371 return SQLITE_OK;
83372 }
83373 return sqlite3VdbeFinishMoveto(p);
83374 }
83375 if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){ 84294 if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){
83376 return handleMovedCursor(p); 84295 return sqlite3VdbeHandleMovedCursor(p);
83377 } 84296 }
83378 return SQLITE_OK; 84297 return SQLITE_OK;
83379} 84298}
@@ -83384,7 +84303,7 @@ SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, u32 *piCol){
83384** sqlite3VdbeSerialType() 84303** sqlite3VdbeSerialType()
83385** sqlite3VdbeSerialTypeLen() 84304** sqlite3VdbeSerialTypeLen()
83386** sqlite3VdbeSerialLen() 84305** sqlite3VdbeSerialLen()
83387** sqlite3VdbeSerialPut() 84306** sqlite3VdbeSerialPut() <--- in-lined into OP_MakeRecord as of 2022-04-02
83388** sqlite3VdbeSerialGet() 84307** sqlite3VdbeSerialGet()
83389** 84308**
83390** encapsulate the code that serializes values for storage in SQLite 84309** encapsulate the code that serializes values for storage in SQLite
@@ -83496,7 +84415,7 @@ SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem *pMem, int file_format, u32 *pLen){
83496/* 84415/*
83497** The sizes for serial types less than 128 84416** The sizes for serial types less than 128
83498*/ 84417*/
83499static const u8 sqlite3SmallTypeSizes[] = { 84418SQLITE_PRIVATE const u8 sqlite3SmallTypeSizes[128] = {
83500 /* 0 1 2 3 4 5 6 7 8 9 */ 84419 /* 0 1 2 3 4 5 6 7 8 9 */
83501/* 0 */ 0, 1, 2, 3, 4, 6, 8, 8, 0, 0, 84420/* 0 */ 0, 1, 2, 3, 4, 6, 8, 8, 0, 0,
83502/* 10 */ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 84421/* 10 */ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
@@ -83565,7 +84484,7 @@ SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8 serial_type){
83565** so we trust him. 84484** so we trust him.
83566*/ 84485*/
83567#ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT 84486#ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
83568static u64 floatSwap(u64 in){ 84487SQLITE_PRIVATE u64 sqlite3FloatSwap(u64 in){
83569 union { 84488 union {
83570 u64 r; 84489 u64 r;
83571 u32 i[2]; 84490 u32 i[2];
@@ -83578,59 +84497,8 @@ static u64 floatSwap(u64 in){
83578 u.i[1] = t; 84497 u.i[1] = t;
83579 return u.r; 84498 return u.r;
83580} 84499}
83581# define swapMixedEndianFloat(X) X = floatSwap(X) 84500#endif /* SQLITE_MIXED_ENDIAN_64BIT_FLOAT */
83582#else
83583# define swapMixedEndianFloat(X)
83584#endif
83585 84501
83586/*
83587** Write the serialized data blob for the value stored in pMem into
83588** buf. It is assumed that the caller has allocated sufficient space.
83589** Return the number of bytes written.
83590**
83591** nBuf is the amount of space left in buf[]. The caller is responsible
83592** for allocating enough space to buf[] to hold the entire field, exclusive
83593** of the pMem->u.nZero bytes for a MEM_Zero value.
83594**
83595** Return the number of bytes actually written into buf[]. The number
83596** of bytes in the zero-filled tail is included in the return value only
83597** if those bytes were zeroed in buf[].
83598*/
83599SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(u8 *buf, Mem *pMem, u32 serial_type){
83600 u32 len;
83601
83602 /* Integer and Real */
83603 if( serial_type<=7 && serial_type>0 ){
83604 u64 v;
83605 u32 i;
83606 if( serial_type==7 ){
83607 assert( sizeof(v)==sizeof(pMem->u.r) );
83608 memcpy(&v, &pMem->u.r, sizeof(v));
83609 swapMixedEndianFloat(v);
83610 }else{
83611 v = pMem->u.i;
83612 }
83613 len = i = sqlite3SmallTypeSizes[serial_type];
83614 assert( i>0 );
83615 do{
83616 buf[--i] = (u8)(v&0xFF);
83617 v >>= 8;
83618 }while( i );
83619 return len;
83620 }
83621
83622 /* String or blob */
83623 if( serial_type>=12 ){
83624 assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0)
83625 == (int)sqlite3VdbeSerialTypeLen(serial_type) );
83626 len = pMem->n;
83627 if( len>0 ) memcpy(buf, pMem->z, len);
83628 return len;
83629 }
83630
83631 /* NULL or constants 0 or 1 */
83632 return 0;
83633}
83634 84502
83635/* Input "x" is a sequence of unsigned characters that represent a 84503/* Input "x" is a sequence of unsigned characters that represent a
83636** big-endian integer. Return the equivalent native integer 84504** big-endian integer. Return the equivalent native integer
@@ -83796,10 +84664,10 @@ SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
83796){ 84664){
83797 UnpackedRecord *p; /* Unpacked record to return */ 84665 UnpackedRecord *p; /* Unpacked record to return */
83798 int nByte; /* Number of bytes required for *p */ 84666 int nByte; /* Number of bytes required for *p */
83799 nByte = ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1); 84667 nByte = ROUND8P(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1);
83800 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte); 84668 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
83801 if( !p ) return 0; 84669 if( !p ) return 0;
83802 p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))]; 84670 p->aMem = (Mem*)&((char*)p)[ROUND8P(sizeof(UnpackedRecord))];
83803 assert( pKeyInfo->aSortFlags!=0 ); 84671 assert( pKeyInfo->aSortFlags!=0 );
83804 p->pKeyInfo = pKeyInfo; 84672 p->pKeyInfo = pKeyInfo;
83805 p->nField = pKeyInfo->nKeyField + 1; 84673 p->nField = pKeyInfo->nKeyField + 1;
@@ -84035,8 +84903,8 @@ static int vdbeCompareMemString(
84035 }else{ 84903 }else{
84036 rc = pColl->xCmp(pColl->pUser, c1.n, v1, c2.n, v2); 84904 rc = pColl->xCmp(pColl->pUser, c1.n, v1, c2.n, v2);
84037 } 84905 }
84038 sqlite3VdbeMemRelease(&c1); 84906 sqlite3VdbeMemReleaseMalloc(&c1);
84039 sqlite3VdbeMemRelease(&c2); 84907 sqlite3VdbeMemReleaseMalloc(&c2);
84040 return rc; 84908 return rc;
84041 } 84909 }
84042} 84910}
@@ -84297,14 +85165,22 @@ SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(
84297 ** two elements in the keys are equal. Fix the various stack variables so 85165 ** two elements in the keys are equal. Fix the various stack variables so
84298 ** that this routine begins comparing at the second field. */ 85166 ** that this routine begins comparing at the second field. */
84299 if( bSkip ){ 85167 if( bSkip ){
84300 u32 s1; 85168 u32 s1 = aKey1[1];
84301 idx1 = 1 + getVarint32(&aKey1[1], s1); 85169 if( s1<0x80 ){
85170 idx1 = 2;
85171 }else{
85172 idx1 = 1 + sqlite3GetVarint32(&aKey1[1], &s1);
85173 }
84302 szHdr1 = aKey1[0]; 85174 szHdr1 = aKey1[0];
84303 d1 = szHdr1 + sqlite3VdbeSerialTypeLen(s1); 85175 d1 = szHdr1 + sqlite3VdbeSerialTypeLen(s1);
84304 i = 1; 85176 i = 1;
84305 pRhs++; 85177 pRhs++;
84306 }else{ 85178 }else{
84307 idx1 = getVarint32(aKey1, szHdr1); 85179 if( (szHdr1 = aKey1[0])<0x80 ){
85180 idx1 = 1;
85181 }else{
85182 idx1 = sqlite3GetVarint32(aKey1, &szHdr1);
85183 }
84308 d1 = szHdr1; 85184 d1 = szHdr1;
84309 i = 0; 85185 i = 0;
84310 } 85186 }
@@ -84560,7 +85436,8 @@ static int vdbeRecordCompareInt(
84560 return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2); 85436 return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2);
84561 } 85437 }
84562 85438
84563 v = pPKey2->aMem[0].u.i; 85439 assert( pPKey2->u.i == pPKey2->aMem[0].u.i );
85440 v = pPKey2->u.i;
84564 if( v>lhs ){ 85441 if( v>lhs ){
84565 res = pPKey2->r1; 85442 res = pPKey2->r1;
84566 }else if( v<lhs ){ 85443 }else if( v<lhs ){
@@ -84595,12 +85472,18 @@ static int vdbeRecordCompareString(
84595 int res; 85472 int res;
84596 85473
84597 assert( pPKey2->aMem[0].flags & MEM_Str ); 85474 assert( pPKey2->aMem[0].flags & MEM_Str );
85475 assert( pPKey2->aMem[0].n == pPKey2->n );
85476 assert( pPKey2->aMem[0].z == pPKey2->u.z );
84598 vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo); 85477 vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo);
84599 serial_type = (u8)(aKey1[1]); 85478 serial_type = (signed char)(aKey1[1]);
84600 if( serial_type >= 0x80 ){ 85479
84601 sqlite3GetVarint32(&aKey1[1], (u32*)&serial_type); 85480vrcs_restart:
84602 }
84603 if( serial_type<12 ){ 85481 if( serial_type<12 ){
85482 if( serial_type<0 ){
85483 sqlite3GetVarint32(&aKey1[1], (u32*)&serial_type);
85484 if( serial_type>=12 ) goto vrcs_restart;
85485 assert( CORRUPT_DB );
85486 }
84604 res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */ 85487 res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */
84605 }else if( !(serial_type & 0x01) ){ 85488 }else if( !(serial_type & 0x01) ){
84606 res = pPKey2->r2; /* (pKey1/nKey1) is a blob */ 85489 res = pPKey2->r2; /* (pKey1/nKey1) is a blob */
@@ -84614,15 +85497,15 @@ static int vdbeRecordCompareString(
84614 pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT; 85497 pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
84615 return 0; /* Corruption */ 85498 return 0; /* Corruption */
84616 } 85499 }
84617 nCmp = MIN( pPKey2->aMem[0].n, nStr ); 85500 nCmp = MIN( pPKey2->n, nStr );
84618 res = memcmp(&aKey1[szHdr], pPKey2->aMem[0].z, nCmp); 85501 res = memcmp(&aKey1[szHdr], pPKey2->u.z, nCmp);
84619 85502
84620 if( res>0 ){ 85503 if( res>0 ){
84621 res = pPKey2->r2; 85504 res = pPKey2->r2;
84622 }else if( res<0 ){ 85505 }else if( res<0 ){
84623 res = pPKey2->r1; 85506 res = pPKey2->r1;
84624 }else{ 85507 }else{
84625 res = nStr - pPKey2->aMem[0].n; 85508 res = nStr - pPKey2->n;
84626 if( res==0 ){ 85509 if( res==0 ){
84627 if( pPKey2->nField>1 ){ 85510 if( pPKey2->nField>1 ){
84628 res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); 85511 res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1);
@@ -84677,6 +85560,7 @@ SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord *p){
84677 p->r2 = 1; 85560 p->r2 = 1;
84678 } 85561 }
84679 if( (flags & MEM_Int) ){ 85562 if( (flags & MEM_Int) ){
85563 p->u.i = p->aMem[0].u.i;
84680 return vdbeRecordCompareInt; 85564 return vdbeRecordCompareInt;
84681 } 85565 }
84682 testcase( flags & MEM_Real ); 85566 testcase( flags & MEM_Real );
@@ -84686,6 +85570,8 @@ SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord *p){
84686 && p->pKeyInfo->aColl[0]==0 85570 && p->pKeyInfo->aColl[0]==0
84687 ){ 85571 ){
84688 assert( flags & MEM_Str ); 85572 assert( flags & MEM_Str );
85573 p->u.z = p->aMem[0].z;
85574 p->n = p->aMem[0].n;
84689 return vdbeRecordCompareString; 85575 return vdbeRecordCompareString;
84690 } 85576 }
84691 } 85577 }
@@ -84758,14 +85644,14 @@ SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){
84758 /* Fetch the integer off the end of the index record */ 85644 /* Fetch the integer off the end of the index record */
84759 sqlite3VdbeSerialGet((u8*)&m.z[m.n-lenRowid], typeRowid, &v); 85645 sqlite3VdbeSerialGet((u8*)&m.z[m.n-lenRowid], typeRowid, &v);
84760 *rowid = v.u.i; 85646 *rowid = v.u.i;
84761 sqlite3VdbeMemRelease(&m); 85647 sqlite3VdbeMemReleaseMalloc(&m);
84762 return SQLITE_OK; 85648 return SQLITE_OK;
84763 85649
84764 /* Jump here if database corruption is detected after m has been 85650 /* Jump here if database corruption is detected after m has been
84765 ** allocated. Free the m object and return SQLITE_CORRUPT. */ 85651 ** allocated. Free the m object and return SQLITE_CORRUPT. */
84766idx_rowid_corruption: 85652idx_rowid_corruption:
84767 testcase( m.szMalloc!=0 ); 85653 testcase( m.szMalloc!=0 );
84768 sqlite3VdbeMemRelease(&m); 85654 sqlite3VdbeMemReleaseMalloc(&m);
84769 return SQLITE_CORRUPT_BKPT; 85655 return SQLITE_CORRUPT_BKPT;
84770} 85656}
84771 85657
@@ -84807,7 +85693,7 @@ SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(
84807 return rc; 85693 return rc;
84808 } 85694 }
84809 *res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, pUnpacked, 0); 85695 *res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, pUnpacked, 0);
84810 sqlite3VdbeMemRelease(&m); 85696 sqlite3VdbeMemReleaseMalloc(&m);
84811 return SQLITE_OK; 85697 return SQLITE_OK;
84812} 85698}
84813 85699
@@ -84974,7 +85860,7 @@ static void vdbeFreeUnpacked(sqlite3 *db, int nField, UnpackedRecord *p){
84974 int i; 85860 int i;
84975 for(i=0; i<nField; i++){ 85861 for(i=0; i<nField; i++){
84976 Mem *pMem = &p->aMem[i]; 85862 Mem *pMem = &p->aMem[i];
84977 if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem); 85863 if( pMem->zMalloc ) sqlite3VdbeMemReleaseMalloc(pMem);
84978 } 85864 }
84979 sqlite3DbFreeNN(db, p); 85865 sqlite3DbFreeNN(db, p);
84980 } 85866 }
@@ -85401,6 +86287,9 @@ SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value *pOrig){
85401 sqlite3ValueFree(pNew); 86287 sqlite3ValueFree(pNew);
85402 pNew = 0; 86288 pNew = 0;
85403 } 86289 }
86290 }else if( pNew->flags & MEM_Null ){
86291 /* Do not duplicate pointer values */
86292 pNew->flags &= ~(MEM_Term|MEM_Subtype);
85404 } 86293 }
85405 return pNew; 86294 return pNew;
85406} 86295}
@@ -85431,7 +86320,8 @@ static void setResultStrOrError(
85431 u8 enc, /* Encoding of z. 0 for BLOBs */ 86320 u8 enc, /* Encoding of z. 0 for BLOBs */
85432 void (*xDel)(void*) /* Destructor function */ 86321 void (*xDel)(void*) /* Destructor function */
85433){ 86322){
85434 int rc = sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel); 86323 Mem *pOut = pCtx->pOut;
86324 int rc = sqlite3VdbeMemSetStr(pOut, z, n, enc, xDel);
85435 if( rc ){ 86325 if( rc ){
85436 if( rc==SQLITE_TOOBIG ){ 86326 if( rc==SQLITE_TOOBIG ){
85437 sqlite3_result_error_toobig(pCtx); 86327 sqlite3_result_error_toobig(pCtx);
@@ -85441,6 +86331,11 @@ static void setResultStrOrError(
85441 assert( rc==SQLITE_NOMEM ); 86331 assert( rc==SQLITE_NOMEM );
85442 sqlite3_result_error_nomem(pCtx); 86332 sqlite3_result_error_nomem(pCtx);
85443 } 86333 }
86334 return;
86335 }
86336 sqlite3VdbeChangeEncoding(pOut, pCtx->enc);
86337 if( sqlite3VdbeMemTooBig(pOut) ){
86338 sqlite3_result_error_toobig(pCtx);
85444 } 86339 }
85445} 86340}
85446static int invokeValueDestructor( 86341static int invokeValueDestructor(
@@ -85584,17 +86479,22 @@ SQLITE_API void sqlite3_result_text16le(
85584} 86479}
85585#endif /* SQLITE_OMIT_UTF16 */ 86480#endif /* SQLITE_OMIT_UTF16 */
85586SQLITE_API void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){ 86481SQLITE_API void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){
86482 Mem *pOut = pCtx->pOut;
85587 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); 86483 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
85588 sqlite3VdbeMemCopy(pCtx->pOut, pValue); 86484 sqlite3VdbeMemCopy(pOut, pValue);
86485 sqlite3VdbeChangeEncoding(pOut, pCtx->enc);
86486 if( sqlite3VdbeMemTooBig(pOut) ){
86487 sqlite3_result_error_toobig(pCtx);
86488 }
85589} 86489}
85590SQLITE_API void sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){ 86490SQLITE_API void sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){
85591 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) ); 86491 sqlite3_result_zeroblob64(pCtx, n>0 ? n : 0);
85592 sqlite3VdbeMemSetZeroBlob(pCtx->pOut, n);
85593} 86492}
85594SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context *pCtx, u64 n){ 86493SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context *pCtx, u64 n){
85595 Mem *pOut = pCtx->pOut; 86494 Mem *pOut = pCtx->pOut;
85596 assert( sqlite3_mutex_held(pOut->db->mutex) ); 86495 assert( sqlite3_mutex_held(pOut->db->mutex) );
85597 if( n>(u64)pOut->db->aLimit[SQLITE_LIMIT_LENGTH] ){ 86496 if( n>(u64)pOut->db->aLimit[SQLITE_LIMIT_LENGTH] ){
86497 sqlite3_result_error_toobig(pCtx);
85598 return SQLITE_TOOBIG; 86498 return SQLITE_TOOBIG;
85599 } 86499 }
85600#ifndef SQLITE_OMIT_INCRBLOB 86500#ifndef SQLITE_OMIT_INCRBLOB
@@ -85610,8 +86510,8 @@ SQLITE_API void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){
85610 if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode; 86510 if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode;
85611#endif 86511#endif
85612 if( pCtx->pOut->flags & MEM_Null ){ 86512 if( pCtx->pOut->flags & MEM_Null ){
85613 sqlite3VdbeMemSetStr(pCtx->pOut, sqlite3ErrStr(errCode), -1, 86513 setResultStrOrError(pCtx, sqlite3ErrStr(errCode), -1, SQLITE_UTF8,
85614 SQLITE_UTF8, SQLITE_STATIC); 86514 SQLITE_STATIC);
85615 } 86515 }
85616} 86516}
85617 86517
@@ -85685,80 +86585,83 @@ static int sqlite3Step(Vdbe *p){
85685 int rc; 86585 int rc;
85686 86586
85687 assert(p); 86587 assert(p);
85688 if( p->iVdbeMagic!=VDBE_MAGIC_RUN ){
85689 /* We used to require that sqlite3_reset() be called before retrying
85690 ** sqlite3_step() after any error or after SQLITE_DONE. But beginning
85691 ** with version 3.7.0, we changed this so that sqlite3_reset() would
85692 ** be called automatically instead of throwing the SQLITE_MISUSE error.
85693 ** This "automatic-reset" change is not technically an incompatibility,
85694 ** since any application that receives an SQLITE_MISUSE is broken by
85695 ** definition.
85696 **
85697 ** Nevertheless, some published applications that were originally written
85698 ** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE
85699 ** returns, and those were broken by the automatic-reset change. As a
85700 ** a work-around, the SQLITE_OMIT_AUTORESET compile-time restores the
85701 ** legacy behavior of returning SQLITE_MISUSE for cases where the
85702 ** previous sqlite3_step() returned something other than a SQLITE_LOCKED
85703 ** or SQLITE_BUSY error.
85704 */
85705#ifdef SQLITE_OMIT_AUTORESET
85706 if( (rc = p->rc&0xff)==SQLITE_BUSY || rc==SQLITE_LOCKED ){
85707 sqlite3_reset((sqlite3_stmt*)p);
85708 }else{
85709 return SQLITE_MISUSE_BKPT;
85710 }
85711#else
85712 sqlite3_reset((sqlite3_stmt*)p);
85713#endif
85714 }
85715
85716 /* Check that malloc() has not failed. If it has, return early. */
85717 db = p->db; 86588 db = p->db;
85718 if( db->mallocFailed ){ 86589 if( p->eVdbeState!=VDBE_RUN_STATE ){
85719 p->rc = SQLITE_NOMEM; 86590 restart_step:
85720 return SQLITE_NOMEM_BKPT; 86591 if( p->eVdbeState==VDBE_READY_STATE ){
85721 } 86592 if( p->expired ){
86593 p->rc = SQLITE_SCHEMA;
86594 rc = SQLITE_ERROR;
86595 if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ){
86596 /* If this statement was prepared using saved SQL and an
86597 ** error has occurred, then return the error code in p->rc to the
86598 ** caller. Set the error code in the database handle to the same
86599 ** value.
86600 */
86601 rc = sqlite3VdbeTransferError(p);
86602 }
86603 goto end_of_step;
86604 }
85722 86605
85723 if( p->pc<0 && p->expired ){ 86606 /* If there are no other statements currently running, then
85724 p->rc = SQLITE_SCHEMA; 86607 ** reset the interrupt flag. This prevents a call to sqlite3_interrupt
85725 rc = SQLITE_ERROR; 86608 ** from interrupting a statement that has not yet started.
85726 if( (p->prepFlags & SQLITE_PREPARE_SAVESQL)!=0 ){
85727 /* If this statement was prepared using saved SQL and an
85728 ** error has occurred, then return the error code in p->rc to the
85729 ** caller. Set the error code in the database handle to the same value.
85730 */ 86609 */
85731 rc = sqlite3VdbeTransferError(p); 86610 if( db->nVdbeActive==0 ){
85732 } 86611 AtomicStore(&db->u1.isInterrupted, 0);
85733 goto end_of_step; 86612 }
85734 }
85735 if( p->pc<0 ){
85736 /* If there are no other statements currently running, then
85737 ** reset the interrupt flag. This prevents a call to sqlite3_interrupt
85738 ** from interrupting a statement that has not yet started.
85739 */
85740 if( db->nVdbeActive==0 ){
85741 AtomicStore(&db->u1.isInterrupted, 0);
85742 }
85743 86613
85744 assert( db->nVdbeWrite>0 || db->autoCommit==0 86614 assert( db->nVdbeWrite>0 || db->autoCommit==0
85745 || (db->nDeferredCons==0 && db->nDeferredImmCons==0) 86615 || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
85746 ); 86616 );
85747 86617
85748#ifndef SQLITE_OMIT_TRACE 86618#ifndef SQLITE_OMIT_TRACE
85749 if( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0 86619 if( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0
85750 && !db->init.busy && p->zSql ){ 86620 && !db->init.busy && p->zSql ){
85751 sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime); 86621 sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime);
85752 }else{ 86622 }else{
85753 assert( p->startTime==0 ); 86623 assert( p->startTime==0 );
85754 } 86624 }
85755#endif 86625#endif
85756 86626
85757 db->nVdbeActive++; 86627 db->nVdbeActive++;
85758 if( p->readOnly==0 ) db->nVdbeWrite++; 86628 if( p->readOnly==0 ) db->nVdbeWrite++;
85759 if( p->bIsReader ) db->nVdbeRead++; 86629 if( p->bIsReader ) db->nVdbeRead++;
85760 p->pc = 0; 86630 p->pc = 0;
86631 p->eVdbeState = VDBE_RUN_STATE;
86632 }else
86633
86634 if( ALWAYS(p->eVdbeState==VDBE_HALT_STATE) ){
86635 /* We used to require that sqlite3_reset() be called before retrying
86636 ** sqlite3_step() after any error or after SQLITE_DONE. But beginning
86637 ** with version 3.7.0, we changed this so that sqlite3_reset() would
86638 ** be called automatically instead of throwing the SQLITE_MISUSE error.
86639 ** This "automatic-reset" change is not technically an incompatibility,
86640 ** since any application that receives an SQLITE_MISUSE is broken by
86641 ** definition.
86642 **
86643 ** Nevertheless, some published applications that were originally written
86644 ** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE
86645 ** returns, and those were broken by the automatic-reset change. As a
86646 ** a work-around, the SQLITE_OMIT_AUTORESET compile-time restores the
86647 ** legacy behavior of returning SQLITE_MISUSE for cases where the
86648 ** previous sqlite3_step() returned something other than a SQLITE_LOCKED
86649 ** or SQLITE_BUSY error.
86650 */
86651#ifdef SQLITE_OMIT_AUTORESET
86652 if( (rc = p->rc&0xff)==SQLITE_BUSY || rc==SQLITE_LOCKED ){
86653 sqlite3_reset((sqlite3_stmt*)p);
86654 }else{
86655 return SQLITE_MISUSE_BKPT;
86656 }
86657#else
86658 sqlite3_reset((sqlite3_stmt*)p);
86659#endif
86660 assert( p->eVdbeState==VDBE_READY_STATE );
86661 goto restart_step;
86662 }
85761 } 86663 }
86664
85762#ifdef SQLITE_DEBUG 86665#ifdef SQLITE_DEBUG
85763 p->rcApp = SQLITE_OK; 86666 p->rcApp = SQLITE_OK;
85764#endif 86667#endif
@@ -85773,7 +86676,12 @@ static int sqlite3Step(Vdbe *p){
85773 db->nVdbeExec--; 86676 db->nVdbeExec--;
85774 } 86677 }
85775 86678
85776 if( rc!=SQLITE_ROW ){ 86679 if( rc==SQLITE_ROW ){
86680 assert( p->rc==SQLITE_OK );
86681 assert( db->mallocFailed==0 );
86682 db->errCode = SQLITE_ROW;
86683 return SQLITE_ROW;
86684 }else{
85777#ifndef SQLITE_OMIT_TRACE 86685#ifndef SQLITE_OMIT_TRACE
85778 /* If the statement completed successfully, invoke the profile callback */ 86686 /* If the statement completed successfully, invoke the profile callback */
85779 checkProfileCallback(db, p); 86687 checkProfileCallback(db, p);
@@ -85825,7 +86733,6 @@ SQLITE_API int sqlite3_step(sqlite3_stmt *pStmt){
85825 } 86733 }
85826 db = v->db; 86734 db = v->db;
85827 sqlite3_mutex_enter(db->mutex); 86735 sqlite3_mutex_enter(db->mutex);
85828 v->doingRerun = 0;
85829 while( (rc = sqlite3Step(v))==SQLITE_SCHEMA 86736 while( (rc = sqlite3Step(v))==SQLITE_SCHEMA
85830 && cnt++ < SQLITE_MAX_SCHEMA_RETRY ){ 86737 && cnt++ < SQLITE_MAX_SCHEMA_RETRY ){
85831 int savedPc = v->pc; 86738 int savedPc = v->pc;
@@ -85851,7 +86758,13 @@ SQLITE_API int sqlite3_step(sqlite3_stmt *pStmt){
85851 break; 86758 break;
85852 } 86759 }
85853 sqlite3_reset(pStmt); 86760 sqlite3_reset(pStmt);
85854 if( savedPc>=0 ) v->doingRerun = 1; 86761 if( savedPc>=0 ){
86762 /* Setting minWriteFileFormat to 254 is a signal to the OP_Init and
86763 ** OP_Trace opcodes to *not* perform SQLITE_TRACE_STMT because it has
86764 ** already been done once on a prior invocation that failed due to
86765 ** SQLITE_SCHEMA. tag-20220401a */
86766 v->minWriteFileFormat = 254;
86767 }
85855 assert( v->expired==0 ); 86768 assert( v->expired==0 );
85856 } 86769 }
85857 sqlite3_mutex_leave(db->mutex); 86770 sqlite3_mutex_leave(db->mutex);
@@ -86160,15 +87073,15 @@ static const Mem *columnNullValue(void){
86160#endif 87073#endif
86161 = { 87074 = {
86162 /* .u = */ {0}, 87075 /* .u = */ {0},
87076 /* .z = */ (char*)0,
87077 /* .n = */ (int)0,
86163 /* .flags = */ (u16)MEM_Null, 87078 /* .flags = */ (u16)MEM_Null,
86164 /* .enc = */ (u8)0, 87079 /* .enc = */ (u8)0,
86165 /* .eSubtype = */ (u8)0, 87080 /* .eSubtype = */ (u8)0,
86166 /* .n = */ (int)0, 87081 /* .db = */ (sqlite3*)0,
86167 /* .z = */ (char*)0,
86168 /* .zMalloc = */ (char*)0,
86169 /* .szMalloc = */ (int)0, 87082 /* .szMalloc = */ (int)0,
86170 /* .uTemp = */ (u32)0, 87083 /* .uTemp = */ (u32)0,
86171 /* .db = */ (sqlite3*)0, 87084 /* .zMalloc = */ (char*)0,
86172 /* .xDel = */ (void(*)(void*))0, 87085 /* .xDel = */ (void(*)(void*))0,
86173#ifdef SQLITE_DEBUG 87086#ifdef SQLITE_DEBUG
86174 /* .pScopyFrom = */ (Mem*)0, 87087 /* .pScopyFrom = */ (Mem*)0,
@@ -86465,7 +87378,7 @@ static int vdbeUnbind(Vdbe *p, int i){
86465 return SQLITE_MISUSE_BKPT; 87378 return SQLITE_MISUSE_BKPT;
86466 } 87379 }
86467 sqlite3_mutex_enter(p->db->mutex); 87380 sqlite3_mutex_enter(p->db->mutex);
86468 if( p->iVdbeMagic!=VDBE_MAGIC_RUN || p->pc>=0 ){ 87381 if( p->eVdbeState!=VDBE_READY_STATE ){
86469 sqlite3Error(p->db, SQLITE_MISUSE); 87382 sqlite3Error(p->db, SQLITE_MISUSE);
86470 sqlite3_mutex_leave(p->db->mutex); 87383 sqlite3_mutex_leave(p->db->mutex);
86471 sqlite3_log(SQLITE_MISUSE, 87384 sqlite3_log(SQLITE_MISUSE,
@@ -86818,7 +87731,7 @@ SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt){
86818*/ 87731*/
86819SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){ 87732SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
86820 Vdbe *v = (Vdbe*)pStmt; 87733 Vdbe *v = (Vdbe*)pStmt;
86821 return v!=0 && v->iVdbeMagic==VDBE_MAGIC_RUN && v->pc>=0; 87734 return v!=0 && v->eVdbeState==VDBE_RUN_STATE;
86822} 87735}
86823 87736
86824/* 87737/*
@@ -86864,8 +87777,7 @@ SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){
86864 sqlite3_mutex_enter(db->mutex); 87777 sqlite3_mutex_enter(db->mutex);
86865 v = 0; 87778 v = 0;
86866 db->pnBytesFreed = (int*)&v; 87779 db->pnBytesFreed = (int*)&v;
86867 sqlite3VdbeClearObject(db, pVdbe); 87780 sqlite3VdbeDelete(pVdbe);
86868 sqlite3DbFree(db, pVdbe);
86869 db->pnBytesFreed = 0; 87781 db->pnBytesFreed = 0;
86870 sqlite3_mutex_leave(db->mutex); 87782 sqlite3_mutex_leave(db->mutex);
86871 }else{ 87783 }else{
@@ -87658,12 +88570,12 @@ static VdbeCursor *allocateCursor(
87658 int nByte; 88570 int nByte;
87659 VdbeCursor *pCx = 0; 88571 VdbeCursor *pCx = 0;
87660 nByte = 88572 nByte =
87661 ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField + 88573 ROUND8P(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField +
87662 (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0); 88574 (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0);
87663 88575
87664 assert( iCur>=0 && iCur<p->nCursor ); 88576 assert( iCur>=0 && iCur<p->nCursor );
87665 if( p->apCsr[iCur] ){ /*OPTIMIZATION-IF-FALSE*/ 88577 if( p->apCsr[iCur] ){ /*OPTIMIZATION-IF-FALSE*/
87666 sqlite3VdbeFreeCursor(p, p->apCsr[iCur]); 88578 sqlite3VdbeFreeCursorNN(p, p->apCsr[iCur]);
87667 p->apCsr[iCur] = 0; 88579 p->apCsr[iCur] = 0;
87668 } 88580 }
87669 88581
@@ -87693,7 +88605,7 @@ static VdbeCursor *allocateCursor(
87693 pCx->aOffset = &pCx->aType[nField]; 88605 pCx->aOffset = &pCx->aType[nField];
87694 if( eCurType==CURTYPE_BTREE ){ 88606 if( eCurType==CURTYPE_BTREE ){
87695 pCx->uc.pCursor = (BtCursor*) 88607 pCx->uc.pCursor = (BtCursor*)
87696 &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField]; 88608 &pMem->z[ROUND8P(sizeof(VdbeCursor))+2*sizeof(u32)*nField];
87697 sqlite3BtreeCursorZero(pCx->uc.pCursor); 88609 sqlite3BtreeCursorZero(pCx->uc.pCursor);
87698 } 88610 }
87699 return pCx; 88611 return pCx;
@@ -88132,7 +89044,7 @@ SQLITE_PRIVATE int sqlite3VdbeExec(
88132#endif 89044#endif
88133 /*** INSERT STACK UNION HERE ***/ 89045 /*** INSERT STACK UNION HERE ***/
88134 89046
88135 assert( p->iVdbeMagic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */ 89047 assert( p->eVdbeState==VDBE_RUN_STATE ); /* sqlite3_step() verifies this */
88136 sqlite3VdbeEnter(p); 89048 sqlite3VdbeEnter(p);
88137#ifndef SQLITE_OMIT_PROGRESS_CALLBACK 89049#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
88138 if( db->xProgress ){ 89050 if( db->xProgress ){
@@ -88375,24 +89287,39 @@ case OP_Gosub: { /* jump */
88375 pIn1->flags = MEM_Int; 89287 pIn1->flags = MEM_Int;
88376 pIn1->u.i = (int)(pOp-aOp); 89288 pIn1->u.i = (int)(pOp-aOp);
88377 REGISTER_TRACE(pOp->p1, pIn1); 89289 REGISTER_TRACE(pOp->p1, pIn1);
88378 89290 goto jump_to_p2_and_check_for_interrupt;
88379 /* Most jump operations do a goto to this spot in order to update
88380 ** the pOp pointer. */
88381jump_to_p2:
88382 pOp = &aOp[pOp->p2 - 1];
88383 break;
88384} 89291}
88385 89292
88386/* Opcode: Return P1 * * * * 89293/* Opcode: Return P1 P2 P3 * *
89294**
89295** Jump to the address stored in register P1. If P1 is a return address
89296** register, then this accomplishes a return from a subroutine.
89297**
89298** If P3 is 1, then the jump is only taken if register P1 holds an integer
89299** values, otherwise execution falls through to the next opcode, and the
89300** OP_Return becomes a no-op. If P3 is 0, then register P1 must hold an
89301** integer or else an assert() is raised. P3 should be set to 1 when
89302** this opcode is used in combination with OP_BeginSubrtn, and set to 0
89303** otherwise.
89304**
89305** The value in register P1 is unchanged by this opcode.
88387** 89306**
88388** Jump to the next instruction after the address in register P1. After 89307** P2 is not used by the byte-code engine. However, if P2 is positive
88389** the jump, register P1 becomes undefined. 89308** and also less than the current address, then the "EXPLAIN" output
89309** formatter in the CLI will indent all opcodes from the P2 opcode up
89310** to be not including the current Return. P2 should be the first opcode
89311** in the subroutine from which this opcode is returning. Thus the P2
89312** value is a byte-code indentation hint. See tag-20220407a in
89313** wherecode.c and shell.c.
88390*/ 89314*/
88391case OP_Return: { /* in1 */ 89315case OP_Return: { /* in1 */
88392 pIn1 = &aMem[pOp->p1]; 89316 pIn1 = &aMem[pOp->p1];
88393 assert( pIn1->flags==MEM_Int ); 89317 if( pIn1->flags & MEM_Int ){
88394 pOp = &aOp[pIn1->u.i]; 89318 if( pOp->p3 ){ VdbeBranchTaken(1, 2); }
88395 pIn1->flags = MEM_Undefined; 89319 pOp = &aOp[pIn1->u.i];
89320 }else if( ALWAYS(pOp->p3) ){
89321 VdbeBranchTaken(0, 2);
89322 }
88396 break; 89323 break;
88397} 89324}
88398 89325
@@ -88415,7 +89342,14 @@ case OP_InitCoroutine: { /* jump */
88415 assert( !VdbeMemDynamic(pOut) ); 89342 assert( !VdbeMemDynamic(pOut) );
88416 pOut->u.i = pOp->p3 - 1; 89343 pOut->u.i = pOp->p3 - 1;
88417 pOut->flags = MEM_Int; 89344 pOut->flags = MEM_Int;
88418 if( pOp->p2 ) goto jump_to_p2; 89345 if( pOp->p2==0 ) break;
89346
89347 /* Most jump operations do a goto to this spot in order to update
89348 ** the pOp pointer. */
89349jump_to_p2:
89350 assert( pOp->p2>0 ); /* There are never any jumps to instruction 0 */
89351 assert( pOp->p2<p->nOp ); /* Jumps must be in range */
89352 pOp = &aOp[pOp->p2 - 1];
88419 break; 89353 break;
88420} 89354}
88421 89355
@@ -88517,11 +89451,10 @@ case OP_Halt: {
88517 VdbeFrame *pFrame; 89451 VdbeFrame *pFrame;
88518 int pcx; 89452 int pcx;
88519 89453
88520 pcx = (int)(pOp - aOp);
88521#ifdef SQLITE_DEBUG 89454#ifdef SQLITE_DEBUG
88522 if( pOp->p2==OE_Abort ){ sqlite3VdbeAssertAbortable(p); } 89455 if( pOp->p2==OE_Abort ){ sqlite3VdbeAssertAbortable(p); }
88523#endif 89456#endif
88524 if( pOp->p1==SQLITE_OK && p->pFrame ){ 89457 if( p->pFrame && pOp->p1==SQLITE_OK ){
88525 /* Halt the sub-program. Return control to the parent frame. */ 89458 /* Halt the sub-program. Return control to the parent frame. */
88526 pFrame = p->pFrame; 89459 pFrame = p->pFrame;
88527 p->pFrame = pFrame->pParent; 89460 p->pFrame = pFrame->pParent;
@@ -88543,7 +89476,6 @@ case OP_Halt: {
88543 } 89476 }
88544 p->rc = pOp->p1; 89477 p->rc = pOp->p1;
88545 p->errorAction = (u8)pOp->p2; 89478 p->errorAction = (u8)pOp->p2;
88546 p->pc = pcx;
88547 assert( pOp->p5<=4 ); 89479 assert( pOp->p5<=4 );
88548 if( p->rc ){ 89480 if( p->rc ){
88549 if( pOp->p5 ){ 89481 if( pOp->p5 ){
@@ -88560,6 +89492,7 @@ case OP_Halt: {
88560 }else{ 89492 }else{
88561 sqlite3VdbeError(p, "%s", pOp->p4.z); 89493 sqlite3VdbeError(p, "%s", pOp->p4.z);
88562 } 89494 }
89495 pcx = (int)(pOp - aOp);
88563 sqlite3_log(pOp->p1, "abort at %d in [%s]: %s", pcx, p->zSql, p->zErrMsg); 89496 sqlite3_log(pOp->p1, "abort at %d in [%s]: %s", pcx, p->zSql, p->zErrMsg);
88564 } 89497 }
88565 rc = sqlite3VdbeHalt(p); 89498 rc = sqlite3VdbeHalt(p);
@@ -88685,6 +89618,28 @@ case OP_String: { /* out2 */
88685 break; 89618 break;
88686} 89619}
88687 89620
89621/* Opcode: BeginSubrtn * P2 * * *
89622** Synopsis: r[P2]=NULL
89623**
89624** Mark the beginning of a subroutine that can be entered in-line
89625** or that can be called using OP_Gosub. The subroutine should
89626** be terminated by an OP_Return instruction that has a P1 operand that
89627** is the same as the P2 operand to this opcode and that has P3 set to 1.
89628** If the subroutine is entered in-line, then the OP_Return will simply
89629** fall through. But if the subroutine is entered using OP_Gosub, then
89630** the OP_Return will jump back to the first instruction after the OP_Gosub.
89631**
89632** This routine works by loading a NULL into the P2 register. When the
89633** return address register contains a NULL, the OP_Return instruction is
89634** a no-op that simply falls through to the next instruction (assuming that
89635** the OP_Return opcode has a P3 value of 1). Thus if the subroutine is
89636** entered in-line, then the OP_Return will cause in-line execution to
89637** continue. But if the subroutine is entered via OP_Gosub, then the
89638** OP_Return will cause a return to the address following the OP_Gosub.
89639**
89640** This opcode is identical to OP_Null. It has a different name
89641** only to make the byte code easier to read and verify.
89642*/
88688/* Opcode: Null P1 P2 P3 * * 89643/* Opcode: Null P1 P2 P3 * *
88689** Synopsis: r[P2..P3]=NULL 89644** Synopsis: r[P2..P3]=NULL
88690** 89645**
@@ -88697,6 +89652,7 @@ case OP_String: { /* out2 */
88697** NULL values will not compare equal even if SQLITE_NULLEQ is set on 89652** NULL values will not compare equal even if SQLITE_NULLEQ is set on
88698** OP_Ne or OP_Eq. 89653** OP_Ne or OP_Eq.
88699*/ 89654*/
89655case OP_BeginSubrtn:
88700case OP_Null: { /* out2 */ 89656case OP_Null: { /* out2 */
88701 int cnt; 89657 int cnt;
88702 u16 nullFlag; 89658 u16 nullFlag;
@@ -88827,11 +89783,16 @@ case OP_Move: {
88827 break; 89783 break;
88828} 89784}
88829 89785
88830/* Opcode: Copy P1 P2 P3 * * 89786/* Opcode: Copy P1 P2 P3 * P5
88831** Synopsis: r[P2@P3+1]=r[P1@P3+1] 89787** Synopsis: r[P2@P3+1]=r[P1@P3+1]
88832** 89788**
88833** Make a copy of registers P1..P1+P3 into registers P2..P2+P3. 89789** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
88834** 89790**
89791** If the 0x0002 bit of P5 is set then also clear the MEM_Subtype flag in the
89792** destination. The 0x0001 bit of P5 indicates that this Copy opcode cannot
89793** be merged. The 0x0001 bit is used by the query planner and does not
89794** come into play during query execution.
89795**
88835** This instruction makes a deep copy of the value. A duplicate 89796** This instruction makes a deep copy of the value. A duplicate
88836** is made of any string or blob constant. See also OP_SCopy. 89797** is made of any string or blob constant. See also OP_SCopy.
88837*/ 89798*/
@@ -88846,6 +89807,9 @@ case OP_Copy: {
88846 memAboutToChange(p, pOut); 89807 memAboutToChange(p, pOut);
88847 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem); 89808 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
88848 Deephemeralize(pOut); 89809 Deephemeralize(pOut);
89810 if( (pOut->flags & MEM_Subtype)!=0 && (pOp->p5 & 0x0002)!=0 ){
89811 pOut->flags &= ~MEM_Subtype;
89812 }
88849#ifdef SQLITE_DEBUG 89813#ifdef SQLITE_DEBUG
88850 pOut->pScopyFrom = 0; 89814 pOut->pScopyFrom = 0;
88851#endif 89815#endif
@@ -88926,45 +89890,32 @@ case OP_FkCheck: {
88926** the result row. 89890** the result row.
88927*/ 89891*/
88928case OP_ResultRow: { 89892case OP_ResultRow: {
88929 Mem *pMem;
88930 int i;
88931 assert( p->nResColumn==pOp->p2 ); 89893 assert( p->nResColumn==pOp->p2 );
88932 assert( pOp->p1>0 || CORRUPT_DB ); 89894 assert( pOp->p1>0 || CORRUPT_DB );
88933 assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 ); 89895 assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );
88934 89896
88935 /* Invalidate all ephemeral cursor row caches */
88936 p->cacheCtr = (p->cacheCtr + 2)|1; 89897 p->cacheCtr = (p->cacheCtr + 2)|1;
88937 89898 p->pResultSet = &aMem[pOp->p1];
88938 /* Make sure the results of the current row are \000 terminated
88939 ** and have an assigned type. The results are de-ephemeralized as
88940 ** a side effect.
88941 */
88942 pMem = p->pResultSet = &aMem[pOp->p1];
88943 for(i=0; i<pOp->p2; i++){
88944 assert( memIsValid(&pMem[i]) );
88945 Deephemeralize(&pMem[i]);
88946 assert( (pMem[i].flags & MEM_Ephem)==0
88947 || (pMem[i].flags & (MEM_Str|MEM_Blob))==0 );
88948 sqlite3VdbeMemNulTerminate(&pMem[i]);
88949 REGISTER_TRACE(pOp->p1+i, &pMem[i]);
88950#ifdef SQLITE_DEBUG 89899#ifdef SQLITE_DEBUG
88951 /* The registers in the result will not be used again when the 89900 {
88952 ** prepared statement restarts. This is because sqlite3_column() 89901 Mem *pMem = p->pResultSet;
88953 ** APIs might have caused type conversions of made other changes to 89902 int i;
88954 ** the register values. Therefore, we can go ahead and break any 89903 for(i=0; i<pOp->p2; i++){
88955 ** OP_SCopy dependencies. */ 89904 assert( memIsValid(&pMem[i]) );
88956 pMem[i].pScopyFrom = 0; 89905 REGISTER_TRACE(pOp->p1+i, &pMem[i]);
88957#endif 89906 /* The registers in the result will not be used again when the
89907 ** prepared statement restarts. This is because sqlite3_column()
89908 ** APIs might have caused type conversions of made other changes to
89909 ** the register values. Therefore, we can go ahead and break any
89910 ** OP_SCopy dependencies. */
89911 pMem[i].pScopyFrom = 0;
89912 }
88958 } 89913 }
89914#endif
88959 if( db->mallocFailed ) goto no_mem; 89915 if( db->mallocFailed ) goto no_mem;
88960
88961 if( db->mTrace & SQLITE_TRACE_ROW ){ 89916 if( db->mTrace & SQLITE_TRACE_ROW ){
88962 db->trace.xV2(SQLITE_TRACE_ROW, db->pTraceArg, p, 0); 89917 db->trace.xV2(SQLITE_TRACE_ROW, db->pTraceArg, p, 0);
88963 } 89918 }
88964
88965
88966 /* Return SQLITE_ROW
88967 */
88968 p->pc = (int)(pOp - aOp) + 1; 89919 p->pc = (int)(pOp - aOp) + 1;
88969 rc = SQLITE_ROW; 89920 rc = SQLITE_ROW;
88970 goto vdbe_return; 89921 goto vdbe_return;
@@ -89019,7 +89970,7 @@ case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */
89019 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ 89970 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
89020 goto too_big; 89971 goto too_big;
89021 } 89972 }
89022 if( sqlite3VdbeMemGrow(pOut, (int)nByte+3, pOut==pIn2) ){ 89973 if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){
89023 goto no_mem; 89974 goto no_mem;
89024 } 89975 }
89025 MemSetTypeFlag(pOut, MEM_Str); 89976 MemSetTypeFlag(pOut, MEM_Str);
@@ -89031,9 +89982,9 @@ case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */
89031 memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n); 89982 memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
89032 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) ); 89983 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
89033 pIn1->flags = flags1; 89984 pIn1->flags = flags1;
89985 if( encoding>SQLITE_UTF8 ) nByte &= ~1;
89034 pOut->z[nByte]=0; 89986 pOut->z[nByte]=0;
89035 pOut->z[nByte+1] = 0; 89987 pOut->z[nByte+1] = 0;
89036 pOut->z[nByte+2] = 0;
89037 pOut->flags |= MEM_Term; 89988 pOut->flags |= MEM_Term;
89038 pOut->n = (int)nByte; 89989 pOut->n = (int)nByte;
89039 pOut->enc = encoding; 89990 pOut->enc = encoding;
@@ -89478,23 +90429,23 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
89478 assert( (pOp->p5 & SQLITE_AFF_MASK)!=SQLITE_AFF_TEXT || CORRUPT_DB ); 90429 assert( (pOp->p5 & SQLITE_AFF_MASK)!=SQLITE_AFF_TEXT || CORRUPT_DB );
89479 /* Common case of comparison of two integers */ 90430 /* Common case of comparison of two integers */
89480 if( pIn3->u.i > pIn1->u.i ){ 90431 if( pIn3->u.i > pIn1->u.i ){
89481 iCompare = +1;
89482 if( sqlite3aGTb[pOp->opcode] ){ 90432 if( sqlite3aGTb[pOp->opcode] ){
89483 VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3); 90433 VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3);
89484 goto jump_to_p2; 90434 goto jump_to_p2;
89485 } 90435 }
90436 iCompare = +1;
89486 }else if( pIn3->u.i < pIn1->u.i ){ 90437 }else if( pIn3->u.i < pIn1->u.i ){
89487 iCompare = -1;
89488 if( sqlite3aLTb[pOp->opcode] ){ 90438 if( sqlite3aLTb[pOp->opcode] ){
89489 VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3); 90439 VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3);
89490 goto jump_to_p2; 90440 goto jump_to_p2;
89491 } 90441 }
90442 iCompare = -1;
89492 }else{ 90443 }else{
89493 iCompare = 0;
89494 if( sqlite3aEQb[pOp->opcode] ){ 90444 if( sqlite3aEQb[pOp->opcode] ){
89495 VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3); 90445 VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3);
89496 goto jump_to_p2; 90446 goto jump_to_p2;
89497 } 90447 }
90448 iCompare = 0;
89498 } 90449 }
89499 VdbeBranchTaken(0, (pOp->p5 & SQLITE_NULLEQ)?2:3); 90450 VdbeBranchTaken(0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
89500 break; 90451 break;
@@ -89521,11 +90472,11 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
89521 ** then the result is always NULL. 90472 ** then the result is always NULL.
89522 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set. 90473 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
89523 */ 90474 */
89524 iCompare = 1; /* Operands are not equal */
89525 VdbeBranchTaken(2,3); 90475 VdbeBranchTaken(2,3);
89526 if( pOp->p5 & SQLITE_JUMPIFNULL ){ 90476 if( pOp->p5 & SQLITE_JUMPIFNULL ){
89527 goto jump_to_p2; 90477 goto jump_to_p2;
89528 } 90478 }
90479 iCompare = 1; /* Operands are not equal */
89529 break; 90480 break;
89530 } 90481 }
89531 }else{ 90482 }else{
@@ -89631,9 +90582,8 @@ case OP_ElseEq: { /* same as TK_ESCAPE, jump */
89631** Set the permutation used by the OP_Compare operator in the next 90582** Set the permutation used by the OP_Compare operator in the next
89632** instruction. The permutation is stored in the P4 operand. 90583** instruction. The permutation is stored in the P4 operand.
89633** 90584**
89634** The permutation is only valid until the next OP_Compare that has 90585** The permutation is only valid for the next opcode which must be
89635** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should 90586** an OP_Compare that has the OPFLAG_PERMUTE bit set in P5.
89636** occur immediately prior to the OP_Compare.
89637** 90587**
89638** The first integer in the P4 integer array is the length of the array 90588** The first integer in the P4 integer array is the length of the array
89639** and does not become part of the permutation. 90589** and does not become part of the permutation.
@@ -89665,6 +90615,8 @@ case OP_Permutation: {
89665** The comparison is a sort comparison, so NULLs compare equal, 90615** The comparison is a sort comparison, so NULLs compare equal,
89666** NULLs are less than numbers, numbers are less than strings, 90616** NULLs are less than numbers, numbers are less than strings,
89667** and strings are less than blobs. 90617** and strings are less than blobs.
90618**
90619** This opcode must be immediately followed by an OP_Jump opcode.
89668*/ 90620*/
89669case OP_Compare: { 90621case OP_Compare: {
89670 int n; 90622 int n;
@@ -89723,6 +90675,7 @@ case OP_Compare: {
89723 break; 90675 break;
89724 } 90676 }
89725 } 90677 }
90678 assert( pOp[1].opcode==OP_Jump );
89726 break; 90679 break;
89727} 90680}
89728 90681
@@ -89731,8 +90684,11 @@ case OP_Compare: {
89731** Jump to the instruction at address P1, P2, or P3 depending on whether 90684** Jump to the instruction at address P1, P2, or P3 depending on whether
89732** in the most recent OP_Compare instruction the P1 vector was less than 90685** in the most recent OP_Compare instruction the P1 vector was less than
89733** equal to, or greater than the P2 vector, respectively. 90686** equal to, or greater than the P2 vector, respectively.
90687**
90688** This opcode must immediately follow an OP_Compare opcode.
89734*/ 90689*/
89735case OP_Jump: { /* jump */ 90690case OP_Jump: { /* jump */
90691 assert( pOp>aOp && pOp[-1].opcode==OP_Compare );
89736 if( iCompare<0 ){ 90692 if( iCompare<0 ){
89737 VdbeBranchTaken(0,4); pOp = &aOp[pOp->p1 - 1]; 90693 VdbeBranchTaken(0,4); pOp = &aOp[pOp->p1 - 1];
89738 }else if( iCompare==0 ){ 90694 }else if( iCompare==0 ){
@@ -90037,7 +90993,7 @@ case OP_Offset: { /* out3 */
90037#endif /* SQLITE_ENABLE_OFFSET_SQL_FUNC */ 90993#endif /* SQLITE_ENABLE_OFFSET_SQL_FUNC */
90038 90994
90039/* Opcode: Column P1 P2 P3 P4 P5 90995/* Opcode: Column P1 P2 P3 P4 P5
90040** Synopsis: r[P3]=PX 90996** Synopsis: r[P3]=PX cursor P1 column P2
90041** 90997**
90042** Interpret the data that cursor P1 points to as a structure built using 90998** Interpret the data that cursor P1 points to as a structure built using
90043** the MakeRecord instruction. (See the MakeRecord opcode for additional 90999** the MakeRecord instruction. (See the MakeRecord opcode for additional
@@ -90059,7 +91015,7 @@ case OP_Offset: { /* out3 */
90059case OP_Column: { 91015case OP_Column: {
90060 u32 p2; /* column number to retrieve */ 91016 u32 p2; /* column number to retrieve */
90061 VdbeCursor *pC; /* The VDBE cursor */ 91017 VdbeCursor *pC; /* The VDBE cursor */
90062 BtCursor *pCrsr; /* The BTree cursor */ 91018 BtCursor *pCrsr; /* The B-Tree cursor corresponding to pC */
90063 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */ 91019 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
90064 int len; /* The length of the serialized data for the column */ 91020 int len; /* The length of the serialized data for the column */
90065 int i; /* Loop counter */ 91021 int i; /* Loop counter */
@@ -90073,21 +91029,14 @@ case OP_Column: {
90073 Mem *pReg; /* PseudoTable input register */ 91029 Mem *pReg; /* PseudoTable input register */
90074 91030
90075 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 91031 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
91032 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
90076 pC = p->apCsr[pOp->p1]; 91033 pC = p->apCsr[pOp->p1];
90077 assert( pC!=0 );
90078 p2 = (u32)pOp->p2; 91034 p2 = (u32)pOp->p2;
90079 91035
90080 /* If the cursor cache is stale (meaning it is not currently point at 91036op_column_restart:
90081 ** the correct row) then bring it up-to-date by doing the necessary
90082 ** B-Tree seek. */
90083 rc = sqlite3VdbeCursorMoveto(&pC, &p2);
90084 if( rc ) goto abort_due_to_error;
90085
90086 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
90087 pDest = &aMem[pOp->p3];
90088 memAboutToChange(p, pDest);
90089 assert( pC!=0 ); 91037 assert( pC!=0 );
90090 assert( p2<(u32)pC->nField ); 91038 assert( p2<(u32)pC->nField
91039 || (pC->eCurType==CURTYPE_PSEUDO && pC->seekResult==0) );
90091 aOffset = pC->aOffset; 91040 aOffset = pC->aOffset;
90092 assert( aOffset==pC->aType+pC->nField ); 91041 assert( aOffset==pC->aType+pC->nField );
90093 assert( pC->eCurType!=CURTYPE_VTAB ); 91042 assert( pC->eCurType!=CURTYPE_VTAB );
@@ -90096,21 +91045,37 @@ case OP_Column: {
90096 91045
90097 if( pC->cacheStatus!=p->cacheCtr ){ /*OPTIMIZATION-IF-FALSE*/ 91046 if( pC->cacheStatus!=p->cacheCtr ){ /*OPTIMIZATION-IF-FALSE*/
90098 if( pC->nullRow ){ 91047 if( pC->nullRow ){
90099 if( pC->eCurType==CURTYPE_PSEUDO ){ 91048 if( pC->eCurType==CURTYPE_PSEUDO && pC->seekResult>0 ){
90100 /* For the special case of as pseudo-cursor, the seekResult field 91049 /* For the special case of as pseudo-cursor, the seekResult field
90101 ** identifies the register that holds the record */ 91050 ** identifies the register that holds the record */
90102 assert( pC->seekResult>0 );
90103 pReg = &aMem[pC->seekResult]; 91051 pReg = &aMem[pC->seekResult];
90104 assert( pReg->flags & MEM_Blob ); 91052 assert( pReg->flags & MEM_Blob );
90105 assert( memIsValid(pReg) ); 91053 assert( memIsValid(pReg) );
90106 pC->payloadSize = pC->szRow = pReg->n; 91054 pC->payloadSize = pC->szRow = pReg->n;
90107 pC->aRow = (u8*)pReg->z; 91055 pC->aRow = (u8*)pReg->z;
90108 }else{ 91056 }else{
91057 pDest = &aMem[pOp->p3];
91058 memAboutToChange(p, pDest);
90109 sqlite3VdbeMemSetNull(pDest); 91059 sqlite3VdbeMemSetNull(pDest);
90110 goto op_column_out; 91060 goto op_column_out;
90111 } 91061 }
90112 }else{ 91062 }else{
90113 pCrsr = pC->uc.pCursor; 91063 pCrsr = pC->uc.pCursor;
91064 if( pC->deferredMoveto ){
91065 u32 iMap;
91066 assert( !pC->isEphemeral );
91067 if( pC->ub.aAltMap && (iMap = pC->ub.aAltMap[1+p2])>0 ){
91068 pC = pC->pAltCursor;
91069 p2 = iMap - 1;
91070 goto op_column_restart;
91071 }
91072 rc = sqlite3VdbeFinishMoveto(pC);
91073 if( rc ) goto abort_due_to_error;
91074 }else if( sqlite3BtreeCursorHasMoved(pCrsr) ){
91075 rc = sqlite3VdbeHandleMovedCursor(pC);
91076 if( rc ) goto abort_due_to_error;
91077 goto op_column_restart;
91078 }
90114 assert( pC->eCurType==CURTYPE_BTREE ); 91079 assert( pC->eCurType==CURTYPE_BTREE );
90115 assert( pCrsr ); 91080 assert( pCrsr );
90116 assert( sqlite3BtreeCursorIsValid(pCrsr) ); 91081 assert( sqlite3BtreeCursorIsValid(pCrsr) );
@@ -90118,15 +91083,15 @@ case OP_Column: {
90118 pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &pC->szRow); 91083 pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &pC->szRow);
90119 assert( pC->szRow<=pC->payloadSize ); 91084 assert( pC->szRow<=pC->payloadSize );
90120 assert( pC->szRow<=65536 ); /* Maximum page size is 64KiB */ 91085 assert( pC->szRow<=65536 ); /* Maximum page size is 64KiB */
90121 if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
90122 goto too_big;
90123 }
90124 } 91086 }
90125 pC->cacheStatus = p->cacheCtr; 91087 pC->cacheStatus = p->cacheCtr;
90126 pC->iHdrOffset = getVarint32(pC->aRow, aOffset[0]); 91088 if( (aOffset[0] = pC->aRow[0])<0x80 ){
91089 pC->iHdrOffset = 1;
91090 }else{
91091 pC->iHdrOffset = sqlite3GetVarint32(pC->aRow, aOffset);
91092 }
90127 pC->nHdrParsed = 0; 91093 pC->nHdrParsed = 0;
90128 91094
90129
90130 if( pC->szRow<aOffset[0] ){ /*OPTIMIZATION-IF-FALSE*/ 91095 if( pC->szRow<aOffset[0] ){ /*OPTIMIZATION-IF-FALSE*/
90131 /* pC->aRow does not have to hold the entire row, but it does at least 91096 /* pC->aRow does not have to hold the entire row, but it does at least
90132 ** need to cover the header of the record. If pC->aRow does not contain 91097 ** need to cover the header of the record. If pC->aRow does not contain
@@ -90166,6 +91131,10 @@ case OP_Column: {
90166 testcase( aOffset[0]==0 ); 91131 testcase( aOffset[0]==0 );
90167 goto op_column_read_header; 91132 goto op_column_read_header;
90168 } 91133 }
91134 }else if( sqlite3BtreeCursorHasMoved(pC->uc.pCursor) ){
91135 rc = sqlite3VdbeHandleMovedCursor(pC);
91136 if( rc ) goto abort_due_to_error;
91137 goto op_column_restart;
90169 } 91138 }
90170 91139
90171 /* Make sure at least the first p2+1 entries of the header have been 91140 /* Make sure at least the first p2+1 entries of the header have been
@@ -90234,6 +91203,8 @@ case OP_Column: {
90234 ** columns. So the result will be either the default value or a NULL. 91203 ** columns. So the result will be either the default value or a NULL.
90235 */ 91204 */
90236 if( pC->nHdrParsed<=p2 ){ 91205 if( pC->nHdrParsed<=p2 ){
91206 pDest = &aMem[pOp->p3];
91207 memAboutToChange(p, pDest);
90237 if( pOp->p4type==P4_MEM ){ 91208 if( pOp->p4type==P4_MEM ){
90238 sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static); 91209 sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static);
90239 }else{ 91210 }else{
@@ -90251,6 +91222,8 @@ case OP_Column: {
90251 */ 91222 */
90252 assert( p2<pC->nHdrParsed ); 91223 assert( p2<pC->nHdrParsed );
90253 assert( rc==SQLITE_OK ); 91224 assert( rc==SQLITE_OK );
91225 pDest = &aMem[pOp->p3];
91226 memAboutToChange(p, pDest);
90254 assert( sqlite3VdbeCheckMemInvariants(pDest) ); 91227 assert( sqlite3VdbeCheckMemInvariants(pDest) );
90255 if( VdbeMemDynamic(pDest) ){ 91228 if( VdbeMemDynamic(pDest) ){
90256 sqlite3VdbeMemSetNull(pDest); 91229 sqlite3VdbeMemSetNull(pDest);
@@ -90271,6 +91244,7 @@ case OP_Column: {
90271 pDest->n = len = (t-12)/2; 91244 pDest->n = len = (t-12)/2;
90272 pDest->enc = encoding; 91245 pDest->enc = encoding;
90273 if( pDest->szMalloc < len+2 ){ 91246 if( pDest->szMalloc < len+2 ){
91247 if( len>db->aLimit[SQLITE_LIMIT_LENGTH] ) goto too_big;
90274 pDest->flags = MEM_Null; 91248 pDest->flags = MEM_Null;
90275 if( sqlite3VdbeMemGrow(pDest, len+2, 0) ) goto no_mem; 91249 if( sqlite3VdbeMemGrow(pDest, len+2, 0) ) goto no_mem;
90276 }else{ 91250 }else{
@@ -90303,6 +91277,7 @@ case OP_Column: {
90303 */ 91277 */
90304 sqlite3VdbeSerialGet((u8*)sqlite3CtypeMap, t, pDest); 91278 sqlite3VdbeSerialGet((u8*)sqlite3CtypeMap, t, pDest);
90305 }else{ 91279 }else{
91280 if( len>db->aLimit[SQLITE_LIMIT_LENGTH] ) goto too_big;
90306 rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest); 91281 rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest);
90307 if( rc!=SQLITE_OK ) goto abort_due_to_error; 91282 if( rc!=SQLITE_OK ) goto abort_due_to_error;
90308 sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest); 91283 sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest);
@@ -90515,7 +91490,6 @@ case OP_MakeRecord: {
90515 Mem *pLast; /* Last field of the record */ 91490 Mem *pLast; /* Last field of the record */
90516 int nField; /* Number of fields in the record */ 91491 int nField; /* Number of fields in the record */
90517 char *zAffinity; /* The affinity string for the record */ 91492 char *zAffinity; /* The affinity string for the record */
90518 int file_format; /* File format to use for encoding */
90519 u32 len; /* Length of a field */ 91493 u32 len; /* Length of a field */
90520 u8 *zHdr; /* Where to write next byte of the header */ 91494 u8 *zHdr; /* Where to write next byte of the header */
90521 u8 *zPayload; /* Where to write next byte of the payload */ 91495 u8 *zPayload; /* Where to write next byte of the payload */
@@ -90544,7 +91518,6 @@ case OP_MakeRecord: {
90544 pData0 = &aMem[nField]; 91518 pData0 = &aMem[nField];
90545 nField = pOp->p2; 91519 nField = pOp->p2;
90546 pLast = &pData0[nField-1]; 91520 pLast = &pData0[nField-1];
90547 file_format = p->minWriteFileFormat;
90548 91521
90549 /* Identify the output register */ 91522 /* Identify the output register */
90550 assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 ); 91523 assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
@@ -90646,7 +91619,7 @@ case OP_MakeRecord: {
90646 testcase( uu==2147483647 ); testcase( uu==2147483648LL ); 91619 testcase( uu==2147483647 ); testcase( uu==2147483648LL );
90647 testcase( uu==140737488355327LL ); testcase( uu==140737488355328LL ); 91620 testcase( uu==140737488355327LL ); testcase( uu==140737488355328LL );
90648 if( uu<=127 ){ 91621 if( uu<=127 ){
90649 if( (i&1)==i && file_format>=4 ){ 91622 if( (i&1)==i && p->minWriteFileFormat>=4 ){
90650 pRec->uTemp = 8+(u32)uu; 91623 pRec->uTemp = 8+(u32)uu;
90651 }else{ 91624 }else{
90652 nData++; 91625 nData++;
@@ -90751,18 +91724,60 @@ case OP_MakeRecord: {
90751 zPayload = zHdr + nHdr; 91724 zPayload = zHdr + nHdr;
90752 91725
90753 /* Write the record */ 91726 /* Write the record */
90754 zHdr += putVarint32(zHdr, nHdr); 91727 if( nHdr<0x80 ){
91728 *(zHdr++) = nHdr;
91729 }else{
91730 zHdr += sqlite3PutVarint(zHdr,nHdr);
91731 }
90755 assert( pData0<=pLast ); 91732 assert( pData0<=pLast );
90756 pRec = pData0; 91733 pRec = pData0;
90757 do{ 91734 while( 1 /*exit-by-break*/ ){
90758 serial_type = pRec->uTemp; 91735 serial_type = pRec->uTemp;
90759 /* EVIDENCE-OF: R-06529-47362 Following the size varint are one or more 91736 /* EVIDENCE-OF: R-06529-47362 Following the size varint are one or more
90760 ** additional varints, one per column. */ 91737 ** additional varints, one per column.
90761 zHdr += putVarint32(zHdr, serial_type); /* serial type */ 91738 ** EVIDENCE-OF: R-64536-51728 The values for each column in the record
90762 /* EVIDENCE-OF: R-64536-51728 The values for each column in the record
90763 ** immediately follow the header. */ 91739 ** immediately follow the header. */
90764 zPayload += sqlite3VdbeSerialPut(zPayload, pRec, serial_type); /* content */ 91740 if( serial_type<=7 ){
90765 }while( (++pRec)<=pLast ); 91741 *(zHdr++) = serial_type;
91742 if( serial_type==0 ){
91743 /* NULL value. No change in zPayload */
91744 }else{
91745 u64 v;
91746 u32 i;
91747 if( serial_type==7 ){
91748 assert( sizeof(v)==sizeof(pRec->u.r) );
91749 memcpy(&v, &pRec->u.r, sizeof(v));
91750 swapMixedEndianFloat(v);
91751 }else{
91752 v = pRec->u.i;
91753 }
91754 len = i = sqlite3SmallTypeSizes[serial_type];
91755 assert( i>0 );
91756 while( 1 /*exit-by-break*/ ){
91757 zPayload[--i] = (u8)(v&0xFF);
91758 if( i==0 ) break;
91759 v >>= 8;
91760 }
91761 zPayload += len;
91762 }
91763 }else if( serial_type<0x80 ){
91764 *(zHdr++) = serial_type;
91765 if( serial_type>=14 && pRec->n>0 ){
91766 assert( pRec->z!=0 );
91767 memcpy(zPayload, pRec->z, pRec->n);
91768 zPayload += pRec->n;
91769 }
91770 }else{
91771 zHdr += sqlite3PutVarint(zHdr, serial_type);
91772 if( pRec->n ){
91773 assert( pRec->z!=0 );
91774 memcpy(zPayload, pRec->z, pRec->n);
91775 zPayload += pRec->n;
91776 }
91777 }
91778 if( pRec==pLast ) break;
91779 pRec++;
91780 }
90766 assert( nHdr==(int)(zHdr - (u8*)pOut->z) ); 91781 assert( nHdr==(int)(zHdr - (u8*)pOut->z) );
90767 assert( nByte==(int)(zPayload - (u8*)pOut->z) ); 91782 assert( nByte==(int)(zPayload - (u8*)pOut->z) );
90768 91783
@@ -90981,7 +91996,10 @@ case OP_Savepoint: {
90981 } 91996 }
90982 } 91997 }
90983 if( rc ) goto abort_due_to_error; 91998 if( rc ) goto abort_due_to_error;
90984 91999 if( p->eVdbeState==VDBE_HALT_STATE ){
92000 rc = SQLITE_DONE;
92001 goto vdbe_return;
92002 }
90985 break; 92003 break;
90986} 92004}
90987 92005
@@ -91085,6 +92103,7 @@ case OP_AutoCommit: {
91085*/ 92103*/
91086case OP_Transaction: { 92104case OP_Transaction: {
91087 Btree *pBt; 92105 Btree *pBt;
92106 Db *pDb;
91088 int iMeta = 0; 92107 int iMeta = 0;
91089 92108
91090 assert( p->bIsReader ); 92109 assert( p->bIsReader );
@@ -91104,7 +92123,8 @@ case OP_Transaction: {
91104 } 92123 }
91105 goto abort_due_to_error; 92124 goto abort_due_to_error;
91106 } 92125 }
91107 pBt = db->aDb[pOp->p1].pBt; 92126 pDb = &db->aDb[pOp->p1];
92127 pBt = pDb->pBt;
91108 92128
91109 if( pBt ){ 92129 if( pBt ){
91110 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2, &iMeta); 92130 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2, &iMeta);
@@ -91145,8 +92165,7 @@ case OP_Transaction: {
91145 assert( pOp->p5==0 || pOp->p4type==P4_INT32 ); 92165 assert( pOp->p5==0 || pOp->p4type==P4_INT32 );
91146 if( rc==SQLITE_OK 92166 if( rc==SQLITE_OK
91147 && pOp->p5 92167 && pOp->p5
91148 && (iMeta!=pOp->p3 92168 && (iMeta!=pOp->p3 || pDb->pSchema->iGeneration!=pOp->p4.i)
91149 || db->aDb[pOp->p1].pSchema->iGeneration!=pOp->p4.i)
91150 ){ 92169 ){
91151 /* 92170 /*
91152 ** IMPLEMENTATION-OF: R-03189-51135 As each SQL statement runs, the schema 92171 ** IMPLEMENTATION-OF: R-03189-51135 As each SQL statement runs, the schema
@@ -91173,6 +92192,11 @@ case OP_Transaction: {
91173 } 92192 }
91174 p->expired = 1; 92193 p->expired = 1;
91175 rc = SQLITE_SCHEMA; 92194 rc = SQLITE_SCHEMA;
92195
92196 /* Set changeCntOn to 0 to prevent the value returned by sqlite3_changes()
92197 ** from being modified in sqlite3VdbeHalt(). If this statement is
92198 ** reprepared, changeCntOn will be set again. */
92199 p->changeCntOn = 0;
91176 } 92200 }
91177 if( rc ) goto abort_due_to_error; 92201 if( rc ) goto abort_due_to_error;
91178 break; 92202 break;
@@ -91239,7 +92263,7 @@ case OP_SetCookie: {
91239 rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, pOp->p3); 92263 rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, pOp->p3);
91240 if( pOp->p2==BTREE_SCHEMA_VERSION ){ 92264 if( pOp->p2==BTREE_SCHEMA_VERSION ){
91241 /* When the schema cookie changes, record the new cookie internally */ 92265 /* When the schema cookie changes, record the new cookie internally */
91242 pDb->pSchema->schema_cookie = pOp->p3 - pOp->p5; 92266 *(u32*)&pDb->pSchema->schema_cookie = *(u32*)&pOp->p3 - pOp->p5;
91243 db->mDbFlags |= DBFLAG_SchemaChange; 92267 db->mDbFlags |= DBFLAG_SchemaChange;
91244 sqlite3FkClearTriggerCache(db, pOp->p1); 92268 sqlite3FkClearTriggerCache(db, pOp->p1);
91245 }else if( pOp->p2==BTREE_FILE_FORMAT ){ 92269 }else if( pOp->p2==BTREE_FILE_FORMAT ){
@@ -91472,8 +92496,8 @@ case OP_OpenDup: {
91472 pCx->pgnoRoot = pOrig->pgnoRoot; 92496 pCx->pgnoRoot = pOrig->pgnoRoot;
91473 pCx->isOrdered = pOrig->isOrdered; 92497 pCx->isOrdered = pOrig->isOrdered;
91474 pCx->ub.pBtx = pOrig->ub.pBtx; 92498 pCx->ub.pBtx = pOrig->ub.pBtx;
91475 pCx->hasBeenDuped = 1; 92499 pCx->noReuse = 1;
91476 pOrig->hasBeenDuped = 1; 92500 pOrig->noReuse = 1;
91477 rc = sqlite3BtreeCursor(pCx->ub.pBtx, pCx->pgnoRoot, BTREE_WRCSR, 92501 rc = sqlite3BtreeCursor(pCx->ub.pBtx, pCx->pgnoRoot, BTREE_WRCSR,
91478 pCx->pKeyInfo, pCx->uc.pCursor); 92502 pCx->pKeyInfo, pCx->uc.pCursor);
91479 /* The sqlite3BtreeCursor() routine can only fail for the first cursor 92503 /* The sqlite3BtreeCursor() routine can only fail for the first cursor
@@ -91540,7 +92564,7 @@ case OP_OpenEphemeral: {
91540 aMem[pOp->p3].z = ""; 92564 aMem[pOp->p3].z = "";
91541 } 92565 }
91542 pCx = p->apCsr[pOp->p1]; 92566 pCx = p->apCsr[pOp->p1];
91543 if( pCx && !pCx->hasBeenDuped && ALWAYS(pOp->p2<=pCx->nField) ){ 92567 if( pCx && !pCx->noReuse && ALWAYS(pOp->p2<=pCx->nField) ){
91544 /* If the ephermeral table is already open and has no duplicates from 92568 /* If the ephermeral table is already open and has no duplicates from
91545 ** OP_OpenDup, then erase all existing content so that the table is 92569 ** OP_OpenDup, then erase all existing content so that the table is
91546 ** empty again, rather than creating a new table. */ 92570 ** empty again, rather than creating a new table. */
@@ -92289,11 +93313,8 @@ case OP_NoConflict: /* jump, in3 */
92289case OP_NotFound: /* jump, in3 */ 93313case OP_NotFound: /* jump, in3 */
92290case OP_Found: { /* jump, in3 */ 93314case OP_Found: { /* jump, in3 */
92291 int alreadyExists; 93315 int alreadyExists;
92292 int takeJump;
92293 int ii; 93316 int ii;
92294 VdbeCursor *pC; 93317 VdbeCursor *pC;
92295 int res;
92296 UnpackedRecord *pFree;
92297 UnpackedRecord *pIdxKey; 93318 UnpackedRecord *pIdxKey;
92298 UnpackedRecord r; 93319 UnpackedRecord r;
92299 93320
@@ -92308,14 +93329,15 @@ case OP_Found: { /* jump, in3 */
92308#ifdef SQLITE_DEBUG 93329#ifdef SQLITE_DEBUG
92309 pC->seekOp = pOp->opcode; 93330 pC->seekOp = pOp->opcode;
92310#endif 93331#endif
92311 pIn3 = &aMem[pOp->p3]; 93332 r.aMem = &aMem[pOp->p3];
92312 assert( pC->eCurType==CURTYPE_BTREE ); 93333 assert( pC->eCurType==CURTYPE_BTREE );
92313 assert( pC->uc.pCursor!=0 ); 93334 assert( pC->uc.pCursor!=0 );
92314 assert( pC->isTable==0 ); 93335 assert( pC->isTable==0 );
92315 if( pOp->p4.i>0 ){ 93336 r.nField = (u16)pOp->p4.i;
93337 if( r.nField>0 ){
93338 /* Key values in an array of registers */
92316 r.pKeyInfo = pC->pKeyInfo; 93339 r.pKeyInfo = pC->pKeyInfo;
92317 r.nField = (u16)pOp->p4.i; 93340 r.default_rc = 0;
92318 r.aMem = pIn3;
92319#ifdef SQLITE_DEBUG 93341#ifdef SQLITE_DEBUG
92320 for(ii=0; ii<r.nField; ii++){ 93342 for(ii=0; ii<r.nField; ii++){
92321 assert( memIsValid(&r.aMem[ii]) ); 93343 assert( memIsValid(&r.aMem[ii]) );
@@ -92323,37 +93345,25 @@ case OP_Found: { /* jump, in3 */
92323 if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]); 93345 if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
92324 } 93346 }
92325#endif 93347#endif
92326 pIdxKey = &r; 93348 rc = sqlite3BtreeIndexMoveto(pC->uc.pCursor, &r, &pC->seekResult);
92327 pFree = 0;
92328 }else{ 93349 }else{
92329 assert( pIn3->flags & MEM_Blob ); 93350 /* Composite key generated by OP_MakeRecord */
92330 rc = ExpandBlob(pIn3); 93351 assert( r.aMem->flags & MEM_Blob );
93352 assert( pOp->opcode!=OP_NoConflict );
93353 rc = ExpandBlob(r.aMem);
92331 assert( rc==SQLITE_OK || rc==SQLITE_NOMEM ); 93354 assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
92332 if( rc ) goto no_mem; 93355 if( rc ) goto no_mem;
92333 pFree = pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo); 93356 pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
92334 if( pIdxKey==0 ) goto no_mem; 93357 if( pIdxKey==0 ) goto no_mem;
92335 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey); 93358 sqlite3VdbeRecordUnpack(pC->pKeyInfo, r.aMem->n, r.aMem->z, pIdxKey);
93359 pIdxKey->default_rc = 0;
93360 rc = sqlite3BtreeIndexMoveto(pC->uc.pCursor, pIdxKey, &pC->seekResult);
93361 sqlite3DbFreeNN(db, pIdxKey);
92336 } 93362 }
92337 pIdxKey->default_rc = 0;
92338 takeJump = 0;
92339 if( pOp->opcode==OP_NoConflict ){
92340 /* For the OP_NoConflict opcode, take the jump if any of the
92341 ** input fields are NULL, since any key with a NULL will not
92342 ** conflict */
92343 for(ii=0; ii<pIdxKey->nField; ii++){
92344 if( pIdxKey->aMem[ii].flags & MEM_Null ){
92345 takeJump = 1;
92346 break;
92347 }
92348 }
92349 }
92350 rc = sqlite3BtreeIndexMoveto(pC->uc.pCursor, pIdxKey, &res);
92351 if( pFree ) sqlite3DbFreeNN(db, pFree);
92352 if( rc!=SQLITE_OK ){ 93363 if( rc!=SQLITE_OK ){
92353 goto abort_due_to_error; 93364 goto abort_due_to_error;
92354 } 93365 }
92355 pC->seekResult = res; 93366 alreadyExists = (pC->seekResult==0);
92356 alreadyExists = (res==0);
92357 pC->nullRow = 1-alreadyExists; 93367 pC->nullRow = 1-alreadyExists;
92358 pC->deferredMoveto = 0; 93368 pC->deferredMoveto = 0;
92359 pC->cacheStatus = CACHE_STALE; 93369 pC->cacheStatus = CACHE_STALE;
@@ -92361,9 +93371,25 @@ case OP_Found: { /* jump, in3 */
92361 VdbeBranchTaken(alreadyExists!=0,2); 93371 VdbeBranchTaken(alreadyExists!=0,2);
92362 if( alreadyExists ) goto jump_to_p2; 93372 if( alreadyExists ) goto jump_to_p2;
92363 }else{ 93373 }else{
92364 VdbeBranchTaken(takeJump||alreadyExists==0,2); 93374 if( !alreadyExists ){
92365 if( takeJump || !alreadyExists ) goto jump_to_p2; 93375 VdbeBranchTaken(1,2);
92366 if( pOp->opcode==OP_IfNoHope ) pC->seekHit = pOp->p4.i; 93376 goto jump_to_p2;
93377 }
93378 if( pOp->opcode==OP_NoConflict ){
93379 /* For the OP_NoConflict opcode, take the jump if any of the
93380 ** input fields are NULL, since any key with a NULL will not
93381 ** conflict */
93382 for(ii=0; ii<r.nField; ii++){
93383 if( r.aMem[ii].flags & MEM_Null ){
93384 VdbeBranchTaken(1,2);
93385 goto jump_to_p2;
93386 }
93387 }
93388 }
93389 VdbeBranchTaken(0,2);
93390 if( pOp->opcode==OP_IfNoHope ){
93391 pC->seekHit = pOp->p4.i;
93392 }
92367 } 93393 }
92368 break; 93394 break;
92369} 93395}
@@ -93054,7 +94080,7 @@ case OP_RowData: {
93054} 94080}
93055 94081
93056/* Opcode: Rowid P1 P2 * * * 94082/* Opcode: Rowid P1 P2 * * *
93057** Synopsis: r[P2]=rowid 94083** Synopsis: r[P2]=PX rowid of P1
93058** 94084**
93059** Store in register P2 an integer which is the key of the table entry that 94085** Store in register P2 an integer which is the key of the table entry that
93060** P1 is currently point to. 94086** P1 is currently point to.
@@ -93110,16 +94136,24 @@ case OP_Rowid: { /* out2 */
93110** that occur while the cursor is on the null row will always 94136** that occur while the cursor is on the null row will always
93111** write a NULL. 94137** write a NULL.
93112** 94138**
93113** Or, if P1 is a Pseudo-Cursor (a cursor opened using OP_OpenPseudo) 94139** If cursor P1 is not previously opened, open it now to a special
93114** just reset the cache for that cursor. This causes the row of 94140** pseudo-cursor that always returns NULL for every column.
93115** content held by the pseudo-cursor to be reparsed.
93116*/ 94141*/
93117case OP_NullRow: { 94142case OP_NullRow: {
93118 VdbeCursor *pC; 94143 VdbeCursor *pC;
93119 94144
93120 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 94145 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
93121 pC = p->apCsr[pOp->p1]; 94146 pC = p->apCsr[pOp->p1];
93122 assert( pC!=0 ); 94147 if( pC==0 ){
94148 /* If the cursor is not already open, create a special kind of
94149 ** pseudo-cursor that always gives null rows. */
94150 pC = allocateCursor(p, pOp->p1, 1, CURTYPE_PSEUDO);
94151 if( pC==0 ) goto no_mem;
94152 pC->seekResult = 0;
94153 pC->isTable = 1;
94154 pC->noReuse = 1;
94155 pC->uc.pCursor = sqlite3BtreeFakeValidCursor();
94156 }
93123 pC->nullRow = 1; 94157 pC->nullRow = 1;
93124 pC->cacheStatus = CACHE_STALE; 94158 pC->cacheStatus = CACHE_STALE;
93125 if( pC->eCurType==CURTYPE_BTREE ){ 94159 if( pC->eCurType==CURTYPE_BTREE ){
@@ -93292,7 +94326,7 @@ case OP_Rewind: { /* jump */
93292 break; 94326 break;
93293} 94327}
93294 94328
93295/* Opcode: Next P1 P2 P3 P4 P5 94329/* Opcode: Next P1 P2 P3 * P5
93296** 94330**
93297** Advance cursor P1 so that it points to the next key/data pair in its 94331** Advance cursor P1 so that it points to the next key/data pair in its
93298** table or index. If there are no more key/value pairs then fall through 94332** table or index. If there are no more key/value pairs then fall through
@@ -93311,15 +94345,12 @@ case OP_Rewind: { /* jump */
93311** omitted if that index had been unique. P3 is usually 0. P3 is 94345** omitted if that index had been unique. P3 is usually 0. P3 is
93312** always either 0 or 1. 94346** always either 0 or 1.
93313** 94347**
93314** P4 is always of type P4_ADVANCE. The function pointer points to
93315** sqlite3BtreeNext().
93316**
93317** If P5 is positive and the jump is taken, then event counter 94348** If P5 is positive and the jump is taken, then event counter
93318** number P5-1 in the prepared statement is incremented. 94349** number P5-1 in the prepared statement is incremented.
93319** 94350**
93320** See also: Prev 94351** See also: Prev
93321*/ 94352*/
93322/* Opcode: Prev P1 P2 P3 P4 P5 94353/* Opcode: Prev P1 P2 P3 * P5
93323** 94354**
93324** Back up cursor P1 so that it points to the previous key/data pair in its 94355** Back up cursor P1 so that it points to the previous key/data pair in its
93325** table or index. If there is no previous key/value pairs then fall through 94356** table or index. If there is no previous key/value pairs then fall through
@@ -93339,9 +94370,6 @@ case OP_Rewind: { /* jump */
93339** omitted if that index had been unique. P3 is usually 0. P3 is 94370** omitted if that index had been unique. P3 is usually 0. P3 is
93340** always either 0 or 1. 94371** always either 0 or 1.
93341** 94372**
93342** P4 is always of type P4_ADVANCE. The function pointer points to
93343** sqlite3BtreePrevious().
93344**
93345** If P5 is positive and the jump is taken, then event counter 94373** If P5 is positive and the jump is taken, then event counter
93346** number P5-1 in the prepared statement is incremented. 94374** number P5-1 in the prepared statement is incremented.
93347*/ 94375*/
@@ -93359,30 +94387,33 @@ case OP_SorterNext: { /* jump */
93359 assert( isSorter(pC) ); 94387 assert( isSorter(pC) );
93360 rc = sqlite3VdbeSorterNext(db, pC); 94388 rc = sqlite3VdbeSorterNext(db, pC);
93361 goto next_tail; 94389 goto next_tail;
94390
93362case OP_Prev: /* jump */ 94391case OP_Prev: /* jump */
93363case OP_Next: /* jump */
93364 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 94392 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
93365 assert( pOp->p5<ArraySize(p->aCounter) ); 94393 assert( pOp->p5<ArraySize(p->aCounter) );
93366 pC = p->apCsr[pOp->p1]; 94394 pC = p->apCsr[pOp->p1];
93367 assert( pC!=0 ); 94395 assert( pC!=0 );
93368 assert( pC->deferredMoveto==0 ); 94396 assert( pC->deferredMoveto==0 );
93369 assert( pC->eCurType==CURTYPE_BTREE ); 94397 assert( pC->eCurType==CURTYPE_BTREE );
93370 assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); 94398 assert( pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE
93371 assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); 94399 || pC->seekOp==OP_Last || pC->seekOp==OP_IfNoHope
94400 || pC->seekOp==OP_NullRow);
94401 rc = sqlite3BtreePrevious(pC->uc.pCursor, pOp->p3);
94402 goto next_tail;
93372 94403
93373 /* The Next opcode is only used after SeekGT, SeekGE, Rewind, and Found. 94404case OP_Next: /* jump */
93374 ** The Prev opcode is only used after SeekLT, SeekLE, and Last. */ 94405 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
93375 assert( pOp->opcode!=OP_Next 94406 assert( pOp->p5<ArraySize(p->aCounter) );
93376 || pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE 94407 pC = p->apCsr[pOp->p1];
94408 assert( pC!=0 );
94409 assert( pC->deferredMoveto==0 );
94410 assert( pC->eCurType==CURTYPE_BTREE );
94411 assert( pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE
93377 || pC->seekOp==OP_Rewind || pC->seekOp==OP_Found 94412 || pC->seekOp==OP_Rewind || pC->seekOp==OP_Found
93378 || pC->seekOp==OP_NullRow|| pC->seekOp==OP_SeekRowid 94413 || pC->seekOp==OP_NullRow|| pC->seekOp==OP_SeekRowid
93379 || pC->seekOp==OP_IfNoHope); 94414 || pC->seekOp==OP_IfNoHope);
93380 assert( pOp->opcode!=OP_Prev 94415 rc = sqlite3BtreeNext(pC->uc.pCursor, pOp->p3);
93381 || pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE
93382 || pC->seekOp==OP_Last || pC->seekOp==OP_IfNoHope
93383 || pC->seekOp==OP_NullRow);
93384 94416
93385 rc = pOp->p4.xAdvance(pC->uc.pCursor, pOp->p3);
93386next_tail: 94417next_tail:
93387 pC->cacheStatus = CACHE_STALE; 94418 pC->cacheStatus = CACHE_STALE;
93388 VdbeBranchTaken(rc==SQLITE_OK,2); 94419 VdbeBranchTaken(rc==SQLITE_OK,2);
@@ -93569,9 +94600,9 @@ case OP_IdxRowid: { /* out2 */
93569 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 94600 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
93570 pC = p->apCsr[pOp->p1]; 94601 pC = p->apCsr[pOp->p1];
93571 assert( pC!=0 ); 94602 assert( pC!=0 );
93572 assert( pC->eCurType==CURTYPE_BTREE ); 94603 assert( pC->eCurType==CURTYPE_BTREE || IsNullCursor(pC) );
93573 assert( pC->uc.pCursor!=0 ); 94604 assert( pC->uc.pCursor!=0 );
93574 assert( pC->isTable==0 ); 94605 assert( pC->isTable==0 || IsNullCursor(pC) );
93575 assert( pC->deferredMoveto==0 ); 94606 assert( pC->deferredMoveto==0 );
93576 assert( !pC->nullRow || pOp->opcode==OP_IdxRowid ); 94607 assert( !pC->nullRow || pOp->opcode==OP_IdxRowid );
93577 94608
@@ -93600,6 +94631,7 @@ case OP_IdxRowid: { /* out2 */
93600 pTabCur->nullRow = 0; 94631 pTabCur->nullRow = 0;
93601 pTabCur->movetoTarget = rowid; 94632 pTabCur->movetoTarget = rowid;
93602 pTabCur->deferredMoveto = 1; 94633 pTabCur->deferredMoveto = 1;
94634 pTabCur->cacheStatus = CACHE_STALE;
93603 assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 ); 94635 assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 );
93604 assert( !pTabCur->isEphemeral ); 94636 assert( !pTabCur->isEphemeral );
93605 pTabCur->ub.aAltMap = pOp->p4.ai; 94637 pTabCur->ub.aAltMap = pOp->p4.ai;
@@ -93734,7 +94766,7 @@ case OP_IdxGE: { /* jump */
93734 rc = sqlite3VdbeMemFromBtreeZeroOffset(pCur, (u32)nCellKey, &m); 94766 rc = sqlite3VdbeMemFromBtreeZeroOffset(pCur, (u32)nCellKey, &m);
93735 if( rc ) goto abort_due_to_error; 94767 if( rc ) goto abort_due_to_error;
93736 res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, &r, 0); 94768 res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, &r, 0);
93737 sqlite3VdbeMemRelease(&m); 94769 sqlite3VdbeMemReleaseMalloc(&m);
93738 } 94770 }
93739 /* End of inlined sqlite3VdbeIdxKeyCompare() */ 94771 /* End of inlined sqlite3VdbeIdxKeyCompare() */
93740 94772
@@ -94615,6 +95647,7 @@ case OP_AggStep: {
94615 pCtx->pVdbe = p; 95647 pCtx->pVdbe = p;
94616 pCtx->skipFlag = 0; 95648 pCtx->skipFlag = 0;
94617 pCtx->isError = 0; 95649 pCtx->isError = 0;
95650 pCtx->enc = encoding;
94618 pCtx->argc = n; 95651 pCtx->argc = n;
94619 pOp->p4type = P4_FUNCCTX; 95652 pOp->p4type = P4_FUNCCTX;
94620 pOp->p4.pCtx = pCtx; 95653 pOp->p4.pCtx = pCtx;
@@ -94744,9 +95777,6 @@ case OP_AggFinal: {
94744 } 95777 }
94745 sqlite3VdbeChangeEncoding(pMem, encoding); 95778 sqlite3VdbeChangeEncoding(pMem, encoding);
94746 UPDATE_MAX_BLOBSIZE(pMem); 95779 UPDATE_MAX_BLOBSIZE(pMem);
94747 if( sqlite3VdbeMemTooBig(pMem) ){
94748 goto too_big;
94749 }
94750 break; 95780 break;
94751} 95781}
94752 95782
@@ -95254,7 +96284,6 @@ case OP_VColumn: {
95254 96284
95255 VdbeCursor *pCur = p->apCsr[pOp->p1]; 96285 VdbeCursor *pCur = p->apCsr[pOp->p1];
95256 assert( pCur!=0 ); 96286 assert( pCur!=0 );
95257 assert( pCur->eCurType==CURTYPE_VTAB );
95258 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); 96287 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
95259 pDest = &aMem[pOp->p3]; 96288 pDest = &aMem[pOp->p3];
95260 memAboutToChange(p, pDest); 96289 memAboutToChange(p, pDest);
@@ -95262,11 +96291,13 @@ case OP_VColumn: {
95262 sqlite3VdbeMemSetNull(pDest); 96291 sqlite3VdbeMemSetNull(pDest);
95263 break; 96292 break;
95264 } 96293 }
96294 assert( pCur->eCurType==CURTYPE_VTAB );
95265 pVtab = pCur->uc.pVCur->pVtab; 96295 pVtab = pCur->uc.pVCur->pVtab;
95266 pModule = pVtab->pModule; 96296 pModule = pVtab->pModule;
95267 assert( pModule->xColumn ); 96297 assert( pModule->xColumn );
95268 memset(&sContext, 0, sizeof(sContext)); 96298 memset(&sContext, 0, sizeof(sContext));
95269 sContext.pOut = pDest; 96299 sContext.pOut = pDest;
96300 sContext.enc = encoding;
95270 assert( pOp->p5==OPFLAG_NOCHNG || pOp->p5==0 ); 96301 assert( pOp->p5==OPFLAG_NOCHNG || pOp->p5==0 );
95271 if( pOp->p5 & OPFLAG_NOCHNG ){ 96302 if( pOp->p5 & OPFLAG_NOCHNG ){
95272 sqlite3VdbeMemSetNull(pDest); 96303 sqlite3VdbeMemSetNull(pDest);
@@ -95285,9 +96316,6 @@ case OP_VColumn: {
95285 REGISTER_TRACE(pOp->p3, pDest); 96316 REGISTER_TRACE(pOp->p3, pDest);
95286 UPDATE_MAX_BLOBSIZE(pDest); 96317 UPDATE_MAX_BLOBSIZE(pDest);
95287 96318
95288 if( sqlite3VdbeMemTooBig(pDest) ){
95289 goto too_big;
95290 }
95291 if( rc ) goto abort_due_to_error; 96319 if( rc ) goto abort_due_to_error;
95292 break; 96320 break;
95293} 96321}
@@ -95554,6 +96582,7 @@ case OP_Function: { /* group */
95554 if( pCtx->pOut != pOut ){ 96582 if( pCtx->pOut != pOut ){
95555 pCtx->pVdbe = p; 96583 pCtx->pVdbe = p;
95556 pCtx->pOut = pOut; 96584 pCtx->pOut = pOut;
96585 pCtx->enc = encoding;
95557 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i]; 96586 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
95558 } 96587 }
95559 assert( pCtx->pVdbe==p ); 96588 assert( pCtx->pVdbe==p );
@@ -95580,17 +96609,27 @@ case OP_Function: { /* group */
95580 if( rc ) goto abort_due_to_error; 96609 if( rc ) goto abort_due_to_error;
95581 } 96610 }
95582 96611
95583 /* Copy the result of the function into register P3 */ 96612 assert( (pOut->flags&MEM_Str)==0
95584 if( pOut->flags & (MEM_Str|MEM_Blob) ){ 96613 || pOut->enc==encoding
95585 sqlite3VdbeChangeEncoding(pOut, encoding); 96614 || db->mallocFailed );
95586 if( sqlite3VdbeMemTooBig(pOut) ) goto too_big; 96615 assert( !sqlite3VdbeMemTooBig(pOut) );
95587 }
95588 96616
95589 REGISTER_TRACE(pOp->p3, pOut); 96617 REGISTER_TRACE(pOp->p3, pOut);
95590 UPDATE_MAX_BLOBSIZE(pOut); 96618 UPDATE_MAX_BLOBSIZE(pOut);
95591 break; 96619 break;
95592} 96620}
95593 96621
96622/* Opcode: ClrSubtype P1 * * * *
96623** Synopsis: r[P1].subtype = 0
96624**
96625** Clear the subtype from register P1.
96626*/
96627case OP_ClrSubtype: { /* in1 */
96628 pIn1 = &aMem[pOp->p1];
96629 pIn1->flags &= ~MEM_Subtype;
96630 break;
96631}
96632
95594/* Opcode: FilterAdd P1 * P3 P4 * 96633/* Opcode: FilterAdd P1 * P3 P4 *
95595** Synopsis: filter(P1) += key(P3@P4) 96634** Synopsis: filter(P1) += key(P3@P4)
95596** 96635**
@@ -95710,7 +96749,7 @@ case OP_Init: { /* jump */
95710 96749
95711#ifndef SQLITE_OMIT_TRACE 96750#ifndef SQLITE_OMIT_TRACE
95712 if( (db->mTrace & (SQLITE_TRACE_STMT|SQLITE_TRACE_LEGACY))!=0 96751 if( (db->mTrace & (SQLITE_TRACE_STMT|SQLITE_TRACE_LEGACY))!=0
95713 && !p->doingRerun 96752 && p->minWriteFileFormat!=254 /* tag-20220401a */
95714 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 96753 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
95715 ){ 96754 ){
95716#ifndef SQLITE_OMIT_DEPRECATED 96755#ifndef SQLITE_OMIT_DEPRECATED
@@ -95939,7 +96978,7 @@ abort_due_to_error:
95939 testcase( sqlite3GlobalConfig.xLog!=0 ); 96978 testcase( sqlite3GlobalConfig.xLog!=0 );
95940 sqlite3_log(rc, "statement aborts at %d: [%s] %s", 96979 sqlite3_log(rc, "statement aborts at %d: [%s] %s",
95941 (int)(pOp - aOp), p->zSql, p->zErrMsg); 96980 (int)(pOp - aOp), p->zSql, p->zErrMsg);
95942 sqlite3VdbeHalt(p); 96981 if( p->eVdbeState==VDBE_RUN_STATE ) sqlite3VdbeHalt(p);
95943 if( rc==SQLITE_IOERR_NOMEM ) sqlite3OomFault(db); 96982 if( rc==SQLITE_IOERR_NOMEM ) sqlite3OomFault(db);
95944 if( rc==SQLITE_CORRUPT && db->autoCommit==0 ){ 96983 if( rc==SQLITE_CORRUPT && db->autoCommit==0 ){
95945 db->flags |= SQLITE_CorruptRdOnly; 96984 db->flags |= SQLITE_CorruptRdOnly;
@@ -100501,51 +101540,24 @@ static void resolveAlias(
100501 sqlite3ExprDelete(db, pDup); 101540 sqlite3ExprDelete(db, pDup);
100502 pDup = 0; 101541 pDup = 0;
100503 }else{ 101542 }else{
101543 Expr temp;
100504 incrAggFunctionDepth(pDup, nSubquery); 101544 incrAggFunctionDepth(pDup, nSubquery);
100505 if( pExpr->op==TK_COLLATE ){ 101545 if( pExpr->op==TK_COLLATE ){
100506 assert( !ExprHasProperty(pExpr, EP_IntValue) ); 101546 assert( !ExprHasProperty(pExpr, EP_IntValue) );
100507 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken); 101547 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
100508 } 101548 }
100509 101549 memcpy(&temp, pDup, sizeof(Expr));
100510 /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This 101550 memcpy(pDup, pExpr, sizeof(Expr));
100511 ** prevents ExprDelete() from deleting the Expr structure itself, 101551 memcpy(pExpr, &temp, sizeof(Expr));
100512 ** allowing it to be repopulated by the memcpy() on the following line.
100513 ** The pExpr->u.zToken might point into memory that will be freed by the
100514 ** sqlite3DbFree(db, pDup) on the last line of this block, so be sure to
100515 ** make a copy of the token before doing the sqlite3DbFree().
100516 */
100517 ExprSetProperty(pExpr, EP_Static);
100518 sqlite3ExprDelete(db, pExpr);
100519 memcpy(pExpr, pDup, sizeof(*pExpr));
100520 if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){
100521 assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 );
100522 pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
100523 pExpr->flags |= EP_MemToken;
100524 }
100525 if( ExprHasProperty(pExpr, EP_WinFunc) ){ 101552 if( ExprHasProperty(pExpr, EP_WinFunc) ){
100526 if( ALWAYS(pExpr->y.pWin!=0) ){ 101553 if( ALWAYS(pExpr->y.pWin!=0) ){
100527 pExpr->y.pWin->pOwner = pExpr; 101554 pExpr->y.pWin->pOwner = pExpr;
100528 } 101555 }
100529 } 101556 }
100530 sqlite3DbFree(db, pDup); 101557 sqlite3ParserAddCleanup(pParse,
100531 } 101558 (void(*)(sqlite3*,void*))sqlite3ExprDelete,
100532} 101559 pDup);
100533
100534
100535/*
100536** Return TRUE if the name zCol occurs anywhere in the USING clause.
100537**
100538** Return FALSE if the USING clause is NULL or if it does not contain
100539** zCol.
100540*/
100541static int nameInUsingClause(IdList *pUsing, const char *zCol){
100542 if( pUsing ){
100543 int k;
100544 for(k=0; k<pUsing->nId; k++){
100545 if( sqlite3StrICmp(pUsing->a[k].zName, zCol)==0 ) return 1;
100546 }
100547 } 101560 }
100548 return 0;
100549} 101561}
100550 101562
100551/* 101563/*
@@ -100563,7 +101575,7 @@ SQLITE_PRIVATE int sqlite3MatchEName(
100563){ 101575){
100564 int n; 101576 int n;
100565 const char *zSpan; 101577 const char *zSpan;
100566 if( pItem->eEName!=ENAME_TAB ) return 0; 101578 if( pItem->fg.eEName!=ENAME_TAB ) return 0;
100567 zSpan = pItem->zEName; 101579 zSpan = pItem->zEName;
100568 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){} 101580 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
100569 if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){ 101581 if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
@@ -100625,6 +101637,29 @@ SQLITE_PRIVATE Bitmask sqlite3ExprColUsed(Expr *pExpr){
100625} 101637}
100626 101638
100627/* 101639/*
101640** Create a new expression term for the column specified by pMatch and
101641** iColumn. Append this new expression term to the FULL JOIN Match set
101642** in *ppList. Create a new *ppList if this is the first term in the
101643** set.
101644*/
101645static void extendFJMatch(
101646 Parse *pParse, /* Parsing context */
101647 ExprList **ppList, /* ExprList to extend */
101648 SrcItem *pMatch, /* Source table containing the column */
101649 i16 iColumn /* The column number */
101650){
101651 Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0);
101652 if( pNew ){
101653 pNew->iTable = pMatch->iCursor;
101654 pNew->iColumn = iColumn;
101655 pNew->y.pTab = pMatch->pTab;
101656 assert( (pMatch->fg.jointype & (JT_LEFT|JT_LTORJ))!=0 );
101657 ExprSetProperty(pNew, EP_CanBeNull);
101658 *ppList = sqlite3ExprListAppend(pParse, *ppList, pNew);
101659 }
101660}
101661
101662/*
100628** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up 101663** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up
100629** that name in the set of source tables in pSrcList and make the pExpr 101664** that name in the set of source tables in pSrcList and make the pExpr
100630** expression node refer back to that source column. The following changes 101665** expression node refer back to that source column. The following changes
@@ -100669,11 +101704,13 @@ static int lookupName(
100669 NameContext *pTopNC = pNC; /* First namecontext in the list */ 101704 NameContext *pTopNC = pNC; /* First namecontext in the list */
100670 Schema *pSchema = 0; /* Schema of the expression */ 101705 Schema *pSchema = 0; /* Schema of the expression */
100671 int eNewExprOp = TK_COLUMN; /* New value for pExpr->op on success */ 101706 int eNewExprOp = TK_COLUMN; /* New value for pExpr->op on success */
100672 Table *pTab = 0; /* Table hold the row */ 101707 Table *pTab = 0; /* Table holding the row */
100673 Column *pCol; /* A column of pTab */ 101708 Column *pCol; /* A column of pTab */
101709 ExprList *pFJMatch = 0; /* Matches for FULL JOIN .. USING */
100674 101710
100675 assert( pNC ); /* the name context cannot be NULL. */ 101711 assert( pNC ); /* the name context cannot be NULL. */
100676 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */ 101712 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
101713 assert( zDb==0 || zTab!=0 );
100677 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) ); 101714 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
100678 101715
100679 /* Initialize the node to no-match */ 101716 /* Initialize the node to no-match */
@@ -100722,26 +101759,65 @@ static int lookupName(
100722 pTab = pItem->pTab; 101759 pTab = pItem->pTab;
100723 assert( pTab!=0 && pTab->zName!=0 ); 101760 assert( pTab!=0 && pTab->zName!=0 );
100724 assert( pTab->nCol>0 || pParse->nErr ); 101761 assert( pTab->nCol>0 || pParse->nErr );
100725 if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){ 101762 assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
101763 if( pItem->fg.isNestedFrom ){
101764 /* In this case, pItem is a subquery that has been formed from a
101765 ** parenthesized subset of the FROM clause terms. Example:
101766 ** .... FROM t1 LEFT JOIN (t2 RIGHT JOIN t3 USING(x)) USING(y) ...
101767 ** \_________________________/
101768 ** This pItem -------------^
101769 */
100726 int hit = 0; 101770 int hit = 0;
101771 assert( pItem->pSelect!=0 );
100727 pEList = pItem->pSelect->pEList; 101772 pEList = pItem->pSelect->pEList;
101773 assert( pEList!=0 );
101774 assert( pEList->nExpr==pTab->nCol );
100728 for(j=0; j<pEList->nExpr; j++){ 101775 for(j=0; j<pEList->nExpr; j++){
100729 if( sqlite3MatchEName(&pEList->a[j], zCol, zTab, zDb) ){ 101776 if( !sqlite3MatchEName(&pEList->a[j], zCol, zTab, zDb) ){
100730 cnt++; 101777 continue;
100731 cntTab = 2;
100732 pMatch = pItem;
100733 pExpr->iColumn = j;
100734 hit = 1;
100735 } 101778 }
101779 if( cnt>0 ){
101780 if( pItem->fg.isUsing==0
101781 || sqlite3IdListIndex(pItem->u3.pUsing, zCol)<0
101782 ){
101783 /* Two or more tables have the same column name which is
101784 ** not joined by USING. This is an error. Signal as much
101785 ** by clearing pFJMatch and letting cnt go above 1. */
101786 sqlite3ExprListDelete(db, pFJMatch);
101787 pFJMatch = 0;
101788 }else
101789 if( (pItem->fg.jointype & JT_RIGHT)==0 ){
101790 /* An INNER or LEFT JOIN. Use the left-most table */
101791 continue;
101792 }else
101793 if( (pItem->fg.jointype & JT_LEFT)==0 ){
101794 /* A RIGHT JOIN. Use the right-most table */
101795 cnt = 0;
101796 sqlite3ExprListDelete(db, pFJMatch);
101797 pFJMatch = 0;
101798 }else{
101799 /* For a FULL JOIN, we must construct a coalesce() func */
101800 extendFJMatch(pParse, &pFJMatch, pMatch, pExpr->iColumn);
101801 }
101802 }
101803 cnt++;
101804 cntTab = 2;
101805 pMatch = pItem;
101806 pExpr->iColumn = j;
101807 pEList->a[j].fg.bUsed = 1;
101808 hit = 1;
101809 if( pEList->a[j].fg.bUsingTerm ) break;
100736 } 101810 }
100737 if( hit || zTab==0 ) continue; 101811 if( hit || zTab==0 ) continue;
100738 } 101812 }
100739 if( zDb ){ 101813 assert( zDb==0 || zTab!=0 );
100740 if( pTab->pSchema!=pSchema ) continue;
100741 if( pSchema==0 && strcmp(zDb,"*")!=0 ) continue;
100742 }
100743 if( zTab ){ 101814 if( zTab ){
100744 const char *zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName; 101815 const char *zTabName;
101816 if( zDb ){
101817 if( pTab->pSchema!=pSchema ) continue;
101818 if( pSchema==0 && strcmp(zDb,"*")!=0 ) continue;
101819 }
101820 zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName;
100745 assert( zTabName!=0 ); 101821 assert( zTabName!=0 );
100746 if( sqlite3StrICmp(zTabName, zTab)!=0 ){ 101822 if( sqlite3StrICmp(zTabName, zTab)!=0 ){
100747 continue; 101823 continue;
@@ -100756,18 +101832,37 @@ static int lookupName(
100756 if( pCol->hName==hCol 101832 if( pCol->hName==hCol
100757 && sqlite3StrICmp(pCol->zCnName, zCol)==0 101833 && sqlite3StrICmp(pCol->zCnName, zCol)==0
100758 ){ 101834 ){
100759 /* If there has been exactly one prior match and this match 101835 if( cnt>0 ){
100760 ** is for the right-hand table of a NATURAL JOIN or is in a 101836 if( pItem->fg.isUsing==0
100761 ** USING clause, then skip this match. 101837 || sqlite3IdListIndex(pItem->u3.pUsing, zCol)<0
100762 */ 101838 ){
100763 if( cnt==1 ){ 101839 /* Two or more tables have the same column name which is
100764 if( pItem->fg.jointype & JT_NATURAL ) continue; 101840 ** not joined by USING. This is an error. Signal as much
100765 if( nameInUsingClause(pItem->pUsing, zCol) ) continue; 101841 ** by clearing pFJMatch and letting cnt go above 1. */
101842 sqlite3ExprListDelete(db, pFJMatch);
101843 pFJMatch = 0;
101844 }else
101845 if( (pItem->fg.jointype & JT_RIGHT)==0 ){
101846 /* An INNER or LEFT JOIN. Use the left-most table */
101847 continue;
101848 }else
101849 if( (pItem->fg.jointype & JT_LEFT)==0 ){
101850 /* A RIGHT JOIN. Use the right-most table */
101851 cnt = 0;
101852 sqlite3ExprListDelete(db, pFJMatch);
101853 pFJMatch = 0;
101854 }else{
101855 /* For a FULL JOIN, we must construct a coalesce() func */
101856 extendFJMatch(pParse, &pFJMatch, pMatch, pExpr->iColumn);
101857 }
100766 } 101858 }
100767 cnt++; 101859 cnt++;
100768 pMatch = pItem; 101860 pMatch = pItem;
100769 /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */ 101861 /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
100770 pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j; 101862 pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j;
101863 if( pItem->fg.isNestedFrom ){
101864 sqlite3SrcItemColumnUsed(pItem, j);
101865 }
100771 break; 101866 break;
100772 } 101867 }
100773 } 101868 }
@@ -100780,9 +101875,7 @@ static int lookupName(
100780 pExpr->iTable = pMatch->iCursor; 101875 pExpr->iTable = pMatch->iCursor;
100781 assert( ExprUseYTab(pExpr) ); 101876 assert( ExprUseYTab(pExpr) );
100782 pExpr->y.pTab = pMatch->pTab; 101877 pExpr->y.pTab = pMatch->pTab;
100783 /* RIGHT JOIN not (yet) supported */ 101878 if( (pMatch->fg.jointype & (JT_LEFT|JT_LTORJ))!=0 ){
100784 assert( (pMatch->fg.jointype & JT_RIGHT)==0 );
100785 if( (pMatch->fg.jointype & JT_LEFT)!=0 ){
100786 ExprSetProperty(pExpr, EP_CanBeNull); 101879 ExprSetProperty(pExpr, EP_CanBeNull);
100787 } 101880 }
100788 pSchema = pExpr->y.pTab->pSchema; 101881 pSchema = pExpr->y.pTab->pSchema;
@@ -100936,7 +102029,7 @@ static int lookupName(
100936 assert( pEList!=0 ); 102029 assert( pEList!=0 );
100937 for(j=0; j<pEList->nExpr; j++){ 102030 for(j=0; j<pEList->nExpr; j++){
100938 char *zAs = pEList->a[j].zEName; 102031 char *zAs = pEList->a[j].zEName;
100939 if( pEList->a[j].eEName==ENAME_NAME 102032 if( pEList->a[j].fg.eEName==ENAME_NAME
100940 && sqlite3_stricmp(zAs, zCol)==0 102033 && sqlite3_stricmp(zAs, zCol)==0
100941 ){ 102034 ){
100942 Expr *pOrig; 102035 Expr *pOrig;
@@ -101023,11 +102116,37 @@ static int lookupName(
101023 } 102116 }
101024 102117
101025 /* 102118 /*
101026 ** cnt==0 means there was not match. cnt>1 means there were two or 102119 ** cnt==0 means there was not match.
101027 ** more matches. Either way, we have an error. 102120 ** cnt>1 means there were two or more matches.
102121 **
102122 ** cnt==0 is always an error. cnt>1 is often an error, but might
102123 ** be multiple matches for a NATURAL LEFT JOIN or a LEFT JOIN USING.
101028 */ 102124 */
102125 assert( pFJMatch==0 || cnt>0 );
102126 assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) );
101029 if( cnt!=1 ){ 102127 if( cnt!=1 ){
101030 const char *zErr; 102128 const char *zErr;
102129 if( pFJMatch ){
102130 if( pFJMatch->nExpr==cnt-1 ){
102131 if( ExprHasProperty(pExpr,EP_Leaf) ){
102132 ExprClearProperty(pExpr,EP_Leaf);
102133 }else{
102134 sqlite3ExprDelete(db, pExpr->pLeft);
102135 pExpr->pLeft = 0;
102136 sqlite3ExprDelete(db, pExpr->pRight);
102137 pExpr->pRight = 0;
102138 }
102139 extendFJMatch(pParse, &pFJMatch, pMatch, pExpr->iColumn);
102140 pExpr->op = TK_FUNCTION;
102141 pExpr->u.zToken = "coalesce";
102142 pExpr->x.pList = pFJMatch;
102143 cnt = 1;
102144 goto lookupname_end;
102145 }else{
102146 sqlite3ExprListDelete(db, pFJMatch);
102147 pFJMatch = 0;
102148 }
102149 }
101031 zErr = cnt==0 ? "no such column" : "ambiguous column name"; 102150 zErr = cnt==0 ? "no such column" : "ambiguous column name";
101032 if( zDb ){ 102151 if( zDb ){
101033 sqlite3ErrorMsg(pParse, "%s: %s.%s.%s", zErr, zDb, zTab, zCol); 102152 sqlite3ErrorMsg(pParse, "%s: %s.%s.%s", zErr, zDb, zTab, zCol);
@@ -101040,6 +102159,16 @@ static int lookupName(
101040 pParse->checkSchema = 1; 102159 pParse->checkSchema = 1;
101041 pTopNC->nNcErr++; 102160 pTopNC->nNcErr++;
101042 } 102161 }
102162 assert( pFJMatch==0 );
102163
102164 /* Remove all substructure from pExpr */
102165 if( !ExprHasProperty(pExpr,(EP_TokenOnly|EP_Leaf)) ){
102166 sqlite3ExprDelete(db, pExpr->pLeft);
102167 pExpr->pLeft = 0;
102168 sqlite3ExprDelete(db, pExpr->pRight);
102169 pExpr->pRight = 0;
102170 ExprSetProperty(pExpr, EP_Leaf);
102171 }
101043 102172
101044 /* If a column from a table in pSrcList is referenced, then record 102173 /* If a column from a table in pSrcList is referenced, then record
101045 ** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes 102174 ** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes
@@ -101059,16 +102188,7 @@ static int lookupName(
101059 pMatch->colUsed |= sqlite3ExprColUsed(pExpr); 102188 pMatch->colUsed |= sqlite3ExprColUsed(pExpr);
101060 } 102189 }
101061 102190
101062 /* Clean up and return
101063 */
101064 if( !ExprHasProperty(pExpr,(EP_TokenOnly|EP_Leaf)) ){
101065 sqlite3ExprDelete(db, pExpr->pLeft);
101066 pExpr->pLeft = 0;
101067 sqlite3ExprDelete(db, pExpr->pRight);
101068 pExpr->pRight = 0;
101069 }
101070 pExpr->op = eNewExprOp; 102191 pExpr->op = eNewExprOp;
101071 ExprSetProperty(pExpr, EP_Leaf);
101072lookupname_end: 102192lookupname_end:
101073 if( cnt==1 ){ 102193 if( cnt==1 ){
101074 assert( pNC!=0 ); 102194 assert( pNC!=0 );
@@ -101253,7 +102373,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
101253 } 102373 }
101254 sqlite3WalkExpr(pWalker, pExpr->pLeft); 102374 sqlite3WalkExpr(pWalker, pExpr->pLeft);
101255 if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){ 102375 if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
101256 testcase( ExprHasProperty(pExpr, EP_FromJoin) ); 102376 testcase( ExprHasProperty(pExpr, EP_OuterON) );
101257 assert( !ExprHasProperty(pExpr, EP_IntValue) ); 102377 assert( !ExprHasProperty(pExpr, EP_IntValue) );
101258 if( pExpr->op==TK_NOTNULL ){ 102378 if( pExpr->op==TK_NOTNULL ){
101259 pExpr->u.zToken = "true"; 102379 pExpr->u.zToken = "true";
@@ -101662,7 +102782,7 @@ static int resolveAsName(
101662 assert( !ExprHasProperty(pE, EP_IntValue) ); 102782 assert( !ExprHasProperty(pE, EP_IntValue) );
101663 zCol = pE->u.zToken; 102783 zCol = pE->u.zToken;
101664 for(i=0; i<pEList->nExpr; i++){ 102784 for(i=0; i<pEList->nExpr; i++){
101665 if( pEList->a[i].eEName==ENAME_NAME 102785 if( pEList->a[i].fg.eEName==ENAME_NAME
101666 && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0 102786 && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
101667 ){ 102787 ){
101668 return i+1; 102788 return i+1;
@@ -101783,7 +102903,7 @@ static int resolveCompoundOrderBy(
101783 return 1; 102903 return 1;
101784 } 102904 }
101785 for(i=0; i<pOrderBy->nExpr; i++){ 102905 for(i=0; i<pOrderBy->nExpr; i++){
101786 pOrderBy->a[i].done = 0; 102906 pOrderBy->a[i].fg.done = 0;
101787 } 102907 }
101788 pSelect->pNext = 0; 102908 pSelect->pNext = 0;
101789 while( pSelect->pPrior ){ 102909 while( pSelect->pPrior ){
@@ -101798,7 +102918,7 @@ static int resolveCompoundOrderBy(
101798 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){ 102918 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
101799 int iCol = -1; 102919 int iCol = -1;
101800 Expr *pE, *pDup; 102920 Expr *pE, *pDup;
101801 if( pItem->done ) continue; 102921 if( pItem->fg.done ) continue;
101802 pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr); 102922 pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
101803 if( NEVER(pE==0) ) continue; 102923 if( NEVER(pE==0) ) continue;
101804 if( sqlite3ExprIsInteger(pE, &iCol) ){ 102924 if( sqlite3ExprIsInteger(pE, &iCol) ){
@@ -101851,7 +102971,7 @@ static int resolveCompoundOrderBy(
101851 sqlite3ExprDelete(db, pE); 102971 sqlite3ExprDelete(db, pE);
101852 pItem->u.x.iOrderByCol = (u16)iCol; 102972 pItem->u.x.iOrderByCol = (u16)iCol;
101853 } 102973 }
101854 pItem->done = 1; 102974 pItem->fg.done = 1;
101855 }else{ 102975 }else{
101856 moreToDo = 1; 102976 moreToDo = 1;
101857 } 102977 }
@@ -101859,7 +102979,7 @@ static int resolveCompoundOrderBy(
101859 pSelect = pSelect->pNext; 102979 pSelect = pSelect->pNext;
101860 } 102980 }
101861 for(i=0; i<pOrderBy->nExpr; i++){ 102981 for(i=0; i<pOrderBy->nExpr; i++){
101862 if( pOrderBy->a[i].done==0 ){ 102982 if( pOrderBy->a[i].fg.done==0 ){
101863 sqlite3ErrorMsg(pParse, "%r ORDER BY term does not match any " 102983 sqlite3ErrorMsg(pParse, "%r ORDER BY term does not match any "
101864 "column in the result set", i+1); 102984 "column in the result set", i+1);
101865 return 1; 102985 return 1;
@@ -102149,8 +103269,8 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
102149 sNC.uNC.pEList = p->pEList; 103269 sNC.uNC.pEList = p->pEList;
102150 sNC.ncFlags |= NC_UEList; 103270 sNC.ncFlags |= NC_UEList;
102151 if( p->pHaving ){ 103271 if( p->pHaving ){
102152 if( !pGroupBy ){ 103272 if( (p->selFlags & SF_Aggregate)==0 ){
102153 sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING"); 103273 sqlite3ErrorMsg(pParse, "HAVING clause on a non-aggregate query");
102154 return WRC_Abort; 103274 return WRC_Abort;
102155 } 103275 }
102156 if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort; 103276 if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
@@ -103544,6 +104664,7 @@ SQLITE_PRIVATE Expr *sqlite3ExprFunction(
103544 sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */ 104664 sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
103545 return 0; 104665 return 0;
103546 } 104666 }
104667 assert( !ExprHasProperty(pNew, EP_InnerON|EP_OuterON) );
103547 pNew->w.iOfst = (int)(pToken->z - pParse->zTail); 104668 pNew->w.iOfst = (int)(pToken->z - pParse->zTail);
103548 if( pList 104669 if( pList
103549 && pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] 104670 && pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG]
@@ -103724,6 +104845,18 @@ SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
103724 if( p ) sqlite3ExprDeleteNN(db, p); 104845 if( p ) sqlite3ExprDeleteNN(db, p);
103725} 104846}
103726 104847
104848/*
104849** Clear both elements of an OnOrUsing object
104850*/
104851SQLITE_PRIVATE void sqlite3ClearOnOrUsing(sqlite3 *db, OnOrUsing *p){
104852 if( p==0 ){
104853 /* Nothing to clear */
104854 }else if( p->pOn ){
104855 sqlite3ExprDeleteNN(db, p->pOn);
104856 }else if( p->pUsing ){
104857 sqlite3IdListDelete(db, p->pUsing);
104858 }
104859}
103727 104860
103728/* 104861/*
103729** Arrange to cause pExpr to be deleted when the pParse is deleted. 104862** Arrange to cause pExpr to be deleted when the pParse is deleted.
@@ -103810,7 +104943,7 @@ static int dupedExprStructSize(const Expr *p, int flags){
103810 nSize = EXPR_FULLSIZE; 104943 nSize = EXPR_FULLSIZE;
103811 }else{ 104944 }else{
103812 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) ); 104945 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
103813 assert( !ExprHasProperty(p, EP_FromJoin) ); 104946 assert( !ExprHasProperty(p, EP_OuterON) );
103814 assert( !ExprHasProperty(p, EP_MemToken) ); 104947 assert( !ExprHasProperty(p, EP_MemToken) );
103815 assert( !ExprHasVVAProperty(p, EP_NoReduce) ); 104948 assert( !ExprHasVVAProperty(p, EP_NoReduce) );
103816 if( p->pLeft || p->x.pList ){ 104949 if( p->pLeft || p->x.pList ){
@@ -103990,6 +105123,7 @@ SQLITE_PRIVATE With *sqlite3WithDup(sqlite3 *db, With *p){
103990 pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0); 105123 pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0);
103991 pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0); 105124 pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0);
103992 pRet->a[i].zName = sqlite3DbStrDup(db, p->a[i].zName); 105125 pRet->a[i].zName = sqlite3DbStrDup(db, p->a[i].zName);
105126 pRet->a[i].eM10d = p->a[i].eM10d;
103993 } 105127 }
103994 } 105128 }
103995 } 105129 }
@@ -104090,11 +105224,8 @@ SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, const ExprList *p, int
104090 } 105224 }
104091 } 105225 }
104092 pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName); 105226 pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
104093 pItem->sortFlags = pOldItem->sortFlags; 105227 pItem->fg = pOldItem->fg;
104094 pItem->eEName = pOldItem->eEName; 105228 pItem->fg.done = 0;
104095 pItem->done = 0;
104096 pItem->bNulls = pOldItem->bNulls;
104097 pItem->bSorterRef = pOldItem->bSorterRef;
104098 pItem->u = pOldItem->u; 105229 pItem->u = pOldItem->u;
104099 } 105230 }
104100 return pNew; 105231 return pNew;
@@ -104146,8 +105277,12 @@ SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3 *db, const SrcList *p, int fla
104146 pTab->nTabRef++; 105277 pTab->nTabRef++;
104147 } 105278 }
104148 pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags); 105279 pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
104149 pNewItem->pOn = sqlite3ExprDup(db, pOldItem->pOn, flags); 105280 if( pOldItem->fg.isUsing ){
104150 pNewItem->pUsing = sqlite3IdListDup(db, pOldItem->pUsing); 105281 assert( pNewItem->fg.isUsing );
105282 pNewItem->u3.pUsing = sqlite3IdListDup(db, pOldItem->u3.pUsing);
105283 }else{
105284 pNewItem->u3.pOn = sqlite3ExprDup(db, pOldItem->u3.pOn, flags);
105285 }
104151 pNewItem->colUsed = pOldItem->colUsed; 105286 pNewItem->colUsed = pOldItem->colUsed;
104152 } 105287 }
104153 return pNew; 105288 return pNew;
@@ -104157,22 +105292,16 @@ SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3 *db, const IdList *p){
104157 int i; 105292 int i;
104158 assert( db!=0 ); 105293 assert( db!=0 );
104159 if( p==0 ) return 0; 105294 if( p==0 ) return 0;
104160 pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) ); 105295 assert( p->eU4!=EU4_EXPR );
105296 pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew)+(p->nId-1)*sizeof(p->a[0]) );
104161 if( pNew==0 ) return 0; 105297 if( pNew==0 ) return 0;
104162 pNew->nId = p->nId; 105298 pNew->nId = p->nId;
104163 pNew->a = sqlite3DbMallocRawNN(db, p->nId*sizeof(p->a[0]) ); 105299 pNew->eU4 = p->eU4;
104164 if( pNew->a==0 ){
104165 sqlite3DbFreeNN(db, pNew);
104166 return 0;
104167 }
104168 /* Note that because the size of the allocation for p->a[] is not
104169 ** necessarily a power of two, sqlite3IdListAppend() may not be called
104170 ** on the duplicate created by this function. */
104171 for(i=0; i<p->nId; i++){ 105300 for(i=0; i<p->nId; i++){
104172 struct IdList_item *pNewItem = &pNew->a[i]; 105301 struct IdList_item *pNewItem = &pNew->a[i];
104173 struct IdList_item *pOldItem = &p->a[i]; 105302 const struct IdList_item *pOldItem = &p->a[i];
104174 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName); 105303 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
104175 pNewItem->idx = pOldItem->idx; 105304 pNewItem->u4 = pOldItem->u4;
104176 } 105305 }
104177 return pNew; 105306 return pNew;
104178} 105307}
@@ -104396,16 +105525,16 @@ SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList *p, int iSortOrder, int
104396 ); 105525 );
104397 105526
104398 pItem = &p->a[p->nExpr-1]; 105527 pItem = &p->a[p->nExpr-1];
104399 assert( pItem->bNulls==0 ); 105528 assert( pItem->fg.bNulls==0 );
104400 if( iSortOrder==SQLITE_SO_UNDEFINED ){ 105529 if( iSortOrder==SQLITE_SO_UNDEFINED ){
104401 iSortOrder = SQLITE_SO_ASC; 105530 iSortOrder = SQLITE_SO_ASC;
104402 } 105531 }
104403 pItem->sortFlags = (u8)iSortOrder; 105532 pItem->fg.sortFlags = (u8)iSortOrder;
104404 105533
104405 if( eNulls!=SQLITE_SO_UNDEFINED ){ 105534 if( eNulls!=SQLITE_SO_UNDEFINED ){
104406 pItem->bNulls = 1; 105535 pItem->fg.bNulls = 1;
104407 if( iSortOrder!=eNulls ){ 105536 if( iSortOrder!=eNulls ){
104408 pItem->sortFlags |= KEYINFO_ORDER_BIGNULL; 105537 pItem->fg.sortFlags |= KEYINFO_ORDER_BIGNULL;
104409 } 105538 }
104410 } 105539 }
104411} 105540}
@@ -104431,7 +105560,7 @@ SQLITE_PRIVATE void sqlite3ExprListSetName(
104431 assert( pList->nExpr>0 ); 105560 assert( pList->nExpr>0 );
104432 pItem = &pList->a[pList->nExpr-1]; 105561 pItem = &pList->a[pList->nExpr-1];
104433 assert( pItem->zEName==0 ); 105562 assert( pItem->zEName==0 );
104434 assert( pItem->eEName==ENAME_NAME ); 105563 assert( pItem->fg.eEName==ENAME_NAME );
104435 pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n); 105564 pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
104436 if( dequote ){ 105565 if( dequote ){
104437 /* If dequote==0, then pName->z does not point to part of a DDL 105566 /* If dequote==0, then pName->z does not point to part of a DDL
@@ -104466,7 +105595,7 @@ SQLITE_PRIVATE void sqlite3ExprListSetSpan(
104466 assert( pList->nExpr>0 ); 105595 assert( pList->nExpr>0 );
104467 if( pItem->zEName==0 ){ 105596 if( pItem->zEName==0 ){
104468 pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd); 105597 pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd);
104469 pItem->eEName = ENAME_SPAN; 105598 pItem->fg.eEName = ENAME_SPAN;
104470 } 105599 }
104471 } 105600 }
104472} 105601}
@@ -104638,9 +105767,9 @@ SQLITE_PRIVATE Expr *sqlite3ExprSimplifiedAndOr(Expr *pExpr){
104638static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){ 105767static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
104639 105768
104640 /* If pWalker->eCode is 2 then any term of the expression that comes from 105769 /* If pWalker->eCode is 2 then any term of the expression that comes from
104641 ** the ON or USING clauses of a left join disqualifies the expression 105770 ** the ON or USING clauses of an outer join disqualifies the expression
104642 ** from being considered constant. */ 105771 ** from being considered constant. */
104643 if( pWalker->eCode==2 && ExprHasProperty(pExpr, EP_FromJoin) ){ 105772 if( pWalker->eCode==2 && ExprHasProperty(pExpr, EP_OuterON) ){
104644 pWalker->eCode = 0; 105773 pWalker->eCode = 0;
104645 return WRC_Abort; 105774 return WRC_Abort;
104646 } 105775 }
@@ -104759,6 +105888,42 @@ SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
104759 return exprIsConst(p, 3, iCur); 105888 return exprIsConst(p, 3, iCur);
104760} 105889}
104761 105890
105891/*
105892** Check pExpr to see if it is an invariant constraint on data source pSrc.
105893** This is an optimization. False negatives will perhaps cause slower
105894** queries, but false positives will yield incorrect answers. So when in
105895** doubt, return 0.
105896**
105897** To be an invariant constraint, the following must be true:
105898**
105899** (1) pExpr cannot refer to any table other than pSrc->iCursor.
105900**
105901** (2) pExpr cannot use subqueries or non-deterministic functions.
105902**
105903** (3) pSrc cannot be part of the left operand for a RIGHT JOIN.
105904** (Is there some way to relax this constraint?)
105905**
105906** (4) If pSrc is the right operand of a LEFT JOIN, then...
105907** (4a) pExpr must come from an ON clause..
105908 (4b) and specifically the ON clause associated with the LEFT JOIN.
105909**
105910** (5) If pSrc is not the right operand of a LEFT JOIN or the left
105911** operand of a RIGHT JOIN, then pExpr must be from the WHERE
105912** clause, not an ON clause.
105913*/
105914SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr *pExpr, const SrcItem *pSrc){
105915 if( pSrc->fg.jointype & JT_LTORJ ){
105916 return 0; /* rule (3) */
105917 }
105918 if( pSrc->fg.jointype & JT_LEFT ){
105919 if( !ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (4a) */
105920 if( pExpr->w.iJoin!=pSrc->iCursor ) return 0; /* rule (4b) */
105921 }else{
105922 if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (5) */
105923 }
105924 return sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor); /* rules (1), (2) */
105925}
105926
104762 105927
104763/* 105928/*
104764** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy(). 105929** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
@@ -105086,7 +106251,7 @@ static int sqlite3InRhsIsConstant(Expr *pIn){
105086** all members of the RHS set, skipping duplicates. 106251** all members of the RHS set, skipping duplicates.
105087** 106252**
105088** A cursor is opened on the b-tree object that is the RHS of the IN operator 106253** A cursor is opened on the b-tree object that is the RHS of the IN operator
105089** and pX->iTable is set to the index of that cursor. 106254** and the *piTab parameter is set to the index of that cursor.
105090** 106255**
105091** The returned value of this function indicates the b-tree type, as follows: 106256** The returned value of this function indicates the b-tree type, as follows:
105092** 106257**
@@ -105106,7 +106271,10 @@ static int sqlite3InRhsIsConstant(Expr *pIn){
105106** If the RHS of the IN operator is a list or a more complex subquery, then 106271** If the RHS of the IN operator is a list or a more complex subquery, then
105107** an ephemeral table might need to be generated from the RHS and then 106272** an ephemeral table might need to be generated from the RHS and then
105108** pX->iTable made to point to the ephemeral table instead of an 106273** pX->iTable made to point to the ephemeral table instead of an
105109** existing table. 106274** existing table. In this case, the creation and initialization of the
106275** ephmeral table might be put inside of a subroutine, the EP_Subrtn flag
106276** will be set on pX and the pX->y.sub fields will be set to show where
106277** the subroutine is coded.
105110** 106278**
105111** The inFlags parameter must contain, at a minimum, one of the bits 106279** The inFlags parameter must contain, at a minimum, one of the bits
105112** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains 106280** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains
@@ -105167,12 +106335,13 @@ SQLITE_PRIVATE int sqlite3FindInIndex(
105167){ 106335){
105168 Select *p; /* SELECT to the right of IN operator */ 106336 Select *p; /* SELECT to the right of IN operator */
105169 int eType = 0; /* Type of RHS table. IN_INDEX_* */ 106337 int eType = 0; /* Type of RHS table. IN_INDEX_* */
105170 int iTab = pParse->nTab++; /* Cursor of the RHS table */ 106338 int iTab; /* Cursor of the RHS table */
105171 int mustBeUnique; /* True if RHS must be unique */ 106339 int mustBeUnique; /* True if RHS must be unique */
105172 Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */ 106340 Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */
105173 106341
105174 assert( pX->op==TK_IN ); 106342 assert( pX->op==TK_IN );
105175 mustBeUnique = (inFlags & IN_INDEX_LOOP)!=0; 106343 mustBeUnique = (inFlags & IN_INDEX_LOOP)!=0;
106344 iTab = pParse->nTab++;
105176 106345
105177 /* If the RHS of this IN(...) operator is a SELECT, and if it matters 106346 /* If the RHS of this IN(...) operator is a SELECT, and if it matters
105178 ** whether or not the SELECT result contains NULL values, check whether 106347 ** whether or not the SELECT result contains NULL values, check whether
@@ -105338,6 +106507,8 @@ SQLITE_PRIVATE int sqlite3FindInIndex(
105338 && ExprUseXList(pX) 106507 && ExprUseXList(pX)
105339 && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2) 106508 && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
105340 ){ 106509 ){
106510 pParse->nTab--; /* Back out the allocation of the unused cursor */
106511 iTab = -1; /* Cursor is not allocated */
105341 eType = IN_INDEX_NOOP; 106512 eType = IN_INDEX_NOOP;
105342 } 106513 }
105343 106514
@@ -105504,6 +106675,7 @@ SQLITE_PRIVATE void sqlite3CodeRhsOfIN(
105504 assert( ExprUseYSub(pExpr) ); 106675 assert( ExprUseYSub(pExpr) );
105505 sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn, 106676 sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
105506 pExpr->y.sub.iAddr); 106677 pExpr->y.sub.iAddr);
106678 assert( iTab!=pExpr->iTable );
105507 sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable); 106679 sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
105508 sqlite3VdbeJumpHere(v, addrOnce); 106680 sqlite3VdbeJumpHere(v, addrOnce);
105509 return; 106681 return;
@@ -105515,8 +106687,7 @@ SQLITE_PRIVATE void sqlite3CodeRhsOfIN(
105515 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) ); 106687 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
105516 pExpr->y.sub.regReturn = ++pParse->nMem; 106688 pExpr->y.sub.regReturn = ++pParse->nMem;
105517 pExpr->y.sub.iAddr = 106689 pExpr->y.sub.iAddr =
105518 sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1; 106690 sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pExpr->y.sub.regReturn) + 1;
105519 VdbeComment((v, "return address"));
105520 106691
105521 addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v); 106692 addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
105522 } 106693 }
@@ -105618,6 +106789,7 @@ SQLITE_PRIVATE void sqlite3CodeRhsOfIN(
105618 ** expression we need to rerun this code each time. 106789 ** expression we need to rerun this code each time.
105619 */ 106790 */
105620 if( addrOnce && !sqlite3ExprIsConstant(pE2) ){ 106791 if( addrOnce && !sqlite3ExprIsConstant(pE2) ){
106792 sqlite3VdbeChangeToNoop(v, addrOnce-1);
105621 sqlite3VdbeChangeToNoop(v, addrOnce); 106793 sqlite3VdbeChangeToNoop(v, addrOnce);
105622 ExprClearProperty(pExpr, EP_Subrtn); 106794 ExprClearProperty(pExpr, EP_Subrtn);
105623 addrOnce = 0; 106795 addrOnce = 0;
@@ -105638,8 +106810,11 @@ SQLITE_PRIVATE void sqlite3CodeRhsOfIN(
105638 sqlite3VdbeJumpHere(v, addrOnce); 106810 sqlite3VdbeJumpHere(v, addrOnce);
105639 /* Subroutine return */ 106811 /* Subroutine return */
105640 assert( ExprUseYSub(pExpr) ); 106812 assert( ExprUseYSub(pExpr) );
105641 sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn); 106813 assert( sqlite3VdbeGetOp(v,pExpr->y.sub.iAddr-1)->opcode==OP_BeginSubrtn
105642 sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1); 106814 || pParse->nErr );
106815 sqlite3VdbeAddOp3(v, OP_Return, pExpr->y.sub.regReturn,
106816 pExpr->y.sub.iAddr, 1);
106817 VdbeCoverage(v);
105643 sqlite3ClearTempRegCache(pParse); 106818 sqlite3ClearTempRegCache(pParse);
105644 } 106819 }
105645} 106820}
@@ -105693,9 +106868,7 @@ SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
105693 ExprSetProperty(pExpr, EP_Subrtn); 106868 ExprSetProperty(pExpr, EP_Subrtn);
105694 pExpr->y.sub.regReturn = ++pParse->nMem; 106869 pExpr->y.sub.regReturn = ++pParse->nMem;
105695 pExpr->y.sub.iAddr = 106870 pExpr->y.sub.iAddr =
105696 sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1; 106871 sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pExpr->y.sub.regReturn) + 1;
105697 VdbeComment((v, "return address"));
105698
105699 106872
105700 /* The evaluation of the EXISTS/SELECT must be repeated every time it 106873 /* The evaluation of the EXISTS/SELECT must be repeated every time it
105701 ** is encountered if any of the following is true: 106874 ** is encountered if any of the following is true:
@@ -105768,8 +106941,11 @@ SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
105768 106941
105769 /* Subroutine return */ 106942 /* Subroutine return */
105770 assert( ExprUseYSub(pExpr) ); 106943 assert( ExprUseYSub(pExpr) );
105771 sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn); 106944 assert( sqlite3VdbeGetOp(v,pExpr->y.sub.iAddr-1)->opcode==OP_BeginSubrtn
105772 sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1); 106945 || pParse->nErr );
106946 sqlite3VdbeAddOp3(v, OP_Return, pExpr->y.sub.regReturn,
106947 pExpr->y.sub.iAddr, 1);
106948 VdbeCoverage(v);
105773 sqlite3ClearTempRegCache(pParse); 106949 sqlite3ClearTempRegCache(pParse);
105774 return rReg; 106950 return rReg;
105775} 106951}
@@ -106203,6 +107379,7 @@ SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(
106203 } 107379 }
106204 if( iCol<0 || iCol==pTab->iPKey ){ 107380 if( iCol<0 || iCol==pTab->iPKey ){
106205 sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut); 107381 sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
107382 VdbeComment((v, "%s.rowid", pTab->zName));
106206 }else{ 107383 }else{
106207 int op; 107384 int op;
106208 int x; 107385 int x;
@@ -106373,7 +107550,17 @@ static int exprCodeInlineFunction(
106373 caseExpr.x.pList = pFarg; 107550 caseExpr.x.pList = pFarg;
106374 return sqlite3ExprCodeTarget(pParse, &caseExpr, target); 107551 return sqlite3ExprCodeTarget(pParse, &caseExpr, target);
106375 } 107552 }
106376 107553#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
107554 case INLINEFUNC_sqlite_offset: {
107555 Expr *pArg = pFarg->a[0].pExpr;
107556 if( pArg->op==TK_COLUMN && pArg->iTable>=0 ){
107557 sqlite3VdbeAddOp3(v, OP_Offset, pArg->iTable, pArg->iColumn, target);
107558 }else{
107559 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
107560 }
107561 break;
107562 }
107563#endif
106377 default: { 107564 default: {
106378 /* The UNLIKELY() function is a no-op. The result is the value 107565 /* The UNLIKELY() function is a no-op. The result is the value
106379 ** of the first argument. 107566 ** of the first argument.
@@ -106912,20 +108099,8 @@ expr_code_doover:
106912 if( !pColl ) pColl = db->pDfltColl; 108099 if( !pColl ) pColl = db->pDfltColl;
106913 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ); 108100 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
106914 } 108101 }
106915#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC 108102 sqlite3VdbeAddFunctionCall(pParse, constMask, r1, target, nFarg,
106916 if( (pDef->funcFlags & SQLITE_FUNC_OFFSET)!=0 && ALWAYS(pFarg!=0) ){ 108103 pDef, pExpr->op2);
106917 Expr *pArg = pFarg->a[0].pExpr;
106918 if( pArg->op==TK_COLUMN ){
106919 sqlite3VdbeAddOp3(v, OP_Offset, pArg->iTable, pArg->iColumn, target);
106920 }else{
106921 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
106922 }
106923 }else
106924#endif
106925 {
106926 sqlite3VdbeAddFunctionCall(pParse, constMask, r1, target, nFarg,
106927 pDef, pExpr->op2);
106928 }
106929 if( nFarg ){ 108104 if( nFarg ){
106930 if( constMask==0 ){ 108105 if( constMask==0 ){
106931 sqlite3ReleaseTempRange(pParse, r1, nFarg); 108106 sqlite3ReleaseTempRange(pParse, r1, nFarg);
@@ -106955,16 +108130,18 @@ expr_code_doover:
106955 } 108130 }
106956 case TK_SELECT_COLUMN: { 108131 case TK_SELECT_COLUMN: {
106957 int n; 108132 int n;
106958 if( pExpr->pLeft->iTable==0 ){ 108133 Expr *pLeft = pExpr->pLeft;
106959 pExpr->pLeft->iTable = sqlite3CodeSubselect(pParse, pExpr->pLeft); 108134 if( pLeft->iTable==0 || pParse->withinRJSubrtn > pLeft->op2 ){
108135 pLeft->iTable = sqlite3CodeSubselect(pParse, pLeft);
108136 pLeft->op2 = pParse->withinRJSubrtn;
106960 } 108137 }
106961 assert( pExpr->pLeft->op==TK_SELECT || pExpr->pLeft->op==TK_ERROR ); 108138 assert( pLeft->op==TK_SELECT || pLeft->op==TK_ERROR );
106962 n = sqlite3ExprVectorSize(pExpr->pLeft); 108139 n = sqlite3ExprVectorSize(pLeft);
106963 if( pExpr->iTable!=n ){ 108140 if( pExpr->iTable!=n ){
106964 sqlite3ErrorMsg(pParse, "%d columns assigned %d values", 108141 sqlite3ErrorMsg(pParse, "%d columns assigned %d values",
106965 pExpr->iTable, n); 108142 pExpr->iTable, n);
106966 } 108143 }
106967 return pExpr->pLeft->iTable + pExpr->iColumn; 108144 return pLeft->iTable + pExpr->iColumn;
106968 } 108145 }
106969 case TK_IN: { 108146 case TK_IN: {
106970 int destIfFalse = sqlite3VdbeMakeLabel(pParse); 108147 int destIfFalse = sqlite3VdbeMakeLabel(pParse);
@@ -106995,8 +108172,24 @@ expr_code_doover:
106995 exprCodeBetween(pParse, pExpr, target, 0, 0); 108172 exprCodeBetween(pParse, pExpr, target, 0, 0);
106996 return target; 108173 return target;
106997 } 108174 }
108175 case TK_COLLATE: {
108176 if( !ExprHasProperty(pExpr, EP_Collate)
108177 && ALWAYS(pExpr->pLeft)
108178 && pExpr->pLeft->op==TK_FUNCTION
108179 ){
108180 inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
108181 if( inReg!=target ){
108182 sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
108183 inReg = target;
108184 }
108185 sqlite3VdbeAddOp1(v, OP_ClrSubtype, inReg);
108186 return inReg;
108187 }else{
108188 pExpr = pExpr->pLeft;
108189 goto expr_code_doover; /* 2018-04-28: Prevent deep recursion. */
108190 }
108191 }
106998 case TK_SPAN: 108192 case TK_SPAN:
106999 case TK_COLLATE:
107000 case TK_UPLUS: { 108193 case TK_UPLUS: {
107001 pExpr = pExpr->pLeft; 108194 pExpr = pExpr->pLeft;
107002 goto expr_code_doover; /* 2018-04-28: Prevent deep recursion. OSSFuzz. */ 108195 goto expr_code_doover; /* 2018-04-28: Prevent deep recursion. OSSFuzz. */
@@ -107237,7 +108430,9 @@ SQLITE_PRIVATE int sqlite3ExprCodeRunJustOnce(
107237 struct ExprList_item *pItem; 108430 struct ExprList_item *pItem;
107238 int i; 108431 int i;
107239 for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){ 108432 for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
107240 if( pItem->reusable && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0 ){ 108433 if( pItem->fg.reusable
108434 && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0
108435 ){
107241 return pItem->u.iConstExprReg; 108436 return pItem->u.iConstExprReg;
107242 } 108437 }
107243 } 108438 }
@@ -107260,7 +108455,7 @@ SQLITE_PRIVATE int sqlite3ExprCodeRunJustOnce(
107260 p = sqlite3ExprListAppend(pParse, p, pExpr); 108455 p = sqlite3ExprListAppend(pParse, p, pExpr);
107261 if( p ){ 108456 if( p ){
107262 struct ExprList_item *pItem = &p->a[p->nExpr-1]; 108457 struct ExprList_item *pItem = &p->a[p->nExpr-1];
107263 pItem->reusable = regDest<0; 108458 pItem->fg.reusable = regDest<0;
107264 if( regDest<0 ) regDest = ++pParse->nMem; 108459 if( regDest<0 ) regDest = ++pParse->nMem;
107265 pItem->u.iConstExprReg = regDest; 108460 pItem->u.iConstExprReg = regDest;
107266 } 108461 }
@@ -107394,7 +108589,7 @@ SQLITE_PRIVATE int sqlite3ExprCodeExprList(
107394 for(pItem=pList->a, i=0; i<n; i++, pItem++){ 108589 for(pItem=pList->a, i=0; i<n; i++, pItem++){
107395 Expr *pExpr = pItem->pExpr; 108590 Expr *pExpr = pItem->pExpr;
107396#ifdef SQLITE_ENABLE_SORTER_REFERENCES 108591#ifdef SQLITE_ENABLE_SORTER_REFERENCES
107397 if( pItem->bSorterRef ){ 108592 if( pItem->fg.bSorterRef ){
107398 i--; 108593 i--;
107399 n--; 108594 n--;
107400 }else 108595 }else
@@ -107488,8 +108683,8 @@ static void exprCodeBetween(
107488 ** so that the sqlite3ExprCodeTarget() routine will not attempt to move 108683 ** so that the sqlite3ExprCodeTarget() routine will not attempt to move
107489 ** it into the Parse.pConstExpr list. We should use a new bit for this, 108684 ** it into the Parse.pConstExpr list. We should use a new bit for this,
107490 ** for clarity, but we are out of bits in the Expr.flags field so we 108685 ** for clarity, but we are out of bits in the Expr.flags field so we
107491 ** have to reuse the EP_FromJoin bit. Bummer. */ 108686 ** have to reuse the EP_OuterON bit. Bummer. */
107492 pDel->flags |= EP_FromJoin; 108687 pDel->flags |= EP_OuterON;
107493 sqlite3ExprCodeTarget(pParse, &exprAnd, dest); 108688 sqlite3ExprCodeTarget(pParse, &exprAnd, dest);
107494 } 108689 }
107495 sqlite3ReleaseTempReg(pParse, regFree1); 108690 sqlite3ReleaseTempReg(pParse, regFree1);
@@ -108019,7 +109214,7 @@ SQLITE_PRIVATE int sqlite3ExprListCompare(const ExprList *pA, const ExprList *pB
108019 int res; 109214 int res;
108020 Expr *pExprA = pA->a[i].pExpr; 109215 Expr *pExprA = pA->a[i].pExpr;
108021 Expr *pExprB = pB->a[i].pExpr; 109216 Expr *pExprB = pB->a[i].pExpr;
108022 if( pA->a[i].sortFlags!=pB->a[i].sortFlags ) return 1; 109217 if( pA->a[i].fg.sortFlags!=pB->a[i].fg.sortFlags ) return 1;
108023 if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res; 109218 if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
108024 } 109219 }
108025 return 0; 109220 return 0;
@@ -108174,7 +109369,7 @@ SQLITE_PRIVATE int sqlite3ExprImpliesExpr(
108174static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){ 109369static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
108175 testcase( pExpr->op==TK_AGG_COLUMN ); 109370 testcase( pExpr->op==TK_AGG_COLUMN );
108176 testcase( pExpr->op==TK_AGG_FUNCTION ); 109371 testcase( pExpr->op==TK_AGG_FUNCTION );
108177 if( ExprHasProperty(pExpr, EP_FromJoin) ) return WRC_Prune; 109372 if( ExprHasProperty(pExpr, EP_OuterON) ) return WRC_Prune;
108178 switch( pExpr->op ){ 109373 switch( pExpr->op ){
108179 case TK_ISNOT: 109374 case TK_ISNOT:
108180 case TK_ISNULL: 109375 case TK_ISNULL:
@@ -108271,8 +109466,8 @@ static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
108271** False positives are not allowed, however. A false positive may result 109466** False positives are not allowed, however. A false positive may result
108272** in an incorrect answer. 109467** in an incorrect answer.
108273** 109468**
108274** Terms of p that are marked with EP_FromJoin (and hence that come from 109469** Terms of p that are marked with EP_OuterON (and hence that come from
108275** the ON or USING clauses of LEFT JOINS) are excluded from the analysis. 109470** the ON or USING clauses of OUTER JOINS) are excluded from the analysis.
108276** 109471**
108277** This routine is used to check if a LEFT JOIN can be converted into 109472** This routine is used to check if a LEFT JOIN can be converted into
108278** an ordinary JOIN. The p argument is the WHERE clause. If the WHERE 109473** an ordinary JOIN. The p argument is the WHERE clause. If the WHERE
@@ -109686,11 +110881,10 @@ static void unmapColumnIdlistNames(
109686 Parse *pParse, 110881 Parse *pParse,
109687 const IdList *pIdList 110882 const IdList *pIdList
109688){ 110883){
109689 if( pIdList ){ 110884 int ii;
109690 int ii; 110885 assert( pIdList!=0 );
109691 for(ii=0; ii<pIdList->nId; ii++){ 110886 for(ii=0; ii<pIdList->nId; ii++){
109692 sqlite3RenameTokenRemap(pParse, 0, (const void*)pIdList->a[ii].zName); 110887 sqlite3RenameTokenRemap(pParse, 0, (const void*)pIdList->a[ii].zName);
109693 }
109694 } 110888 }
109695} 110889}
109696 110890
@@ -109709,7 +110903,7 @@ static int renameUnmapSelectCb(Walker *pWalker, Select *p){
109709 if( ALWAYS(p->pEList) ){ 110903 if( ALWAYS(p->pEList) ){
109710 ExprList *pList = p->pEList; 110904 ExprList *pList = p->pEList;
109711 for(i=0; i<pList->nExpr; i++){ 110905 for(i=0; i<pList->nExpr; i++){
109712 if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){ 110906 if( pList->a[i].zEName && pList->a[i].fg.eEName==ENAME_NAME ){
109713 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName); 110907 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
109714 } 110908 }
109715 } 110909 }
@@ -109718,8 +110912,11 @@ static int renameUnmapSelectCb(Walker *pWalker, Select *p){
109718 SrcList *pSrc = p->pSrc; 110912 SrcList *pSrc = p->pSrc;
109719 for(i=0; i<pSrc->nSrc; i++){ 110913 for(i=0; i<pSrc->nSrc; i++){
109720 sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName); 110914 sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName);
109721 sqlite3WalkExpr(pWalker, pSrc->a[i].pOn); 110915 if( pSrc->a[i].fg.isUsing==0 ){
109722 unmapColumnIdlistNames(pParse, pSrc->a[i].pUsing); 110916 sqlite3WalkExpr(pWalker, pSrc->a[i].u3.pOn);
110917 }else{
110918 unmapColumnIdlistNames(pParse, pSrc->a[i].u3.pUsing);
110919 }
109723 } 110920 }
109724 } 110921 }
109725 110922
@@ -109755,7 +110952,7 @@ SQLITE_PRIVATE void sqlite3RenameExprlistUnmap(Parse *pParse, ExprList *pEList){
109755 sWalker.xExprCallback = renameUnmapExprCb; 110952 sWalker.xExprCallback = renameUnmapExprCb;
109756 sqlite3WalkExprList(&sWalker, pEList); 110953 sqlite3WalkExprList(&sWalker, pEList);
109757 for(i=0; i<pEList->nExpr; i++){ 110954 for(i=0; i<pEList->nExpr; i++){
109758 if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) ){ 110955 if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME) ){
109759 sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName); 110956 sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
109760 } 110957 }
109761 } 110958 }
@@ -109913,7 +111110,7 @@ static void renameColumnElistNames(
109913 int i; 111110 int i;
109914 for(i=0; i<pEList->nExpr; i++){ 111111 for(i=0; i<pEList->nExpr; i++){
109915 const char *zName = pEList->a[i].zEName; 111112 const char *zName = pEList->a[i].zEName;
109916 if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) 111113 if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME)
109917 && ALWAYS(zName!=0) 111114 && ALWAYS(zName!=0)
109918 && 0==sqlite3_stricmp(zName, zOld) 111115 && 0==sqlite3_stricmp(zName, zOld)
109919 ){ 111116 ){
@@ -110143,27 +111340,33 @@ static int renameResolveTrigger(Parse *pParse){
110143 if( rc==SQLITE_OK && pStep->zTarget ){ 111340 if( rc==SQLITE_OK && pStep->zTarget ){
110144 SrcList *pSrc = sqlite3TriggerStepSrc(pParse, pStep); 111341 SrcList *pSrc = sqlite3TriggerStepSrc(pParse, pStep);
110145 if( pSrc ){ 111342 if( pSrc ){
110146 int i; 111343 Select *pSel = sqlite3SelectNew(
110147 for(i=0; i<pSrc->nSrc && rc==SQLITE_OK; i++){ 111344 pParse, pStep->pExprList, pSrc, 0, 0, 0, 0, 0, 0
110148 SrcItem *p = &pSrc->a[i]; 111345 );
110149 p->iCursor = pParse->nTab++; 111346 if( pSel==0 ){
110150 if( p->pSelect ){ 111347 pStep->pExprList = 0;
110151 sqlite3SelectPrep(pParse, p->pSelect, 0); 111348 pSrc = 0;
110152 sqlite3ExpandSubquery(pParse, p); 111349 rc = SQLITE_NOMEM;
110153 assert( i>0 ); 111350 }else{
110154 assert( pStep->pFrom->a[i-1].pSelect ); 111351 sqlite3SelectPrep(pParse, pSel, 0);
110155 sqlite3SelectPrep(pParse, pStep->pFrom->a[i-1].pSelect, 0); 111352 rc = pParse->nErr ? SQLITE_ERROR : SQLITE_OK;
110156 }else{ 111353 assert( pStep->pExprList==0 || pStep->pExprList==pSel->pEList );
110157 p->pTab = sqlite3LocateTableItem(pParse, 0, p); 111354 assert( pSrc==pSel->pSrc );
110158 if( p->pTab==0 ){ 111355 if( pStep->pExprList ) pSel->pEList = 0;
110159 rc = SQLITE_ERROR; 111356 pSel->pSrc = 0;
110160 }else{ 111357 sqlite3SelectDelete(db, pSel);
110161 p->pTab->nTabRef++; 111358 }
110162 rc = sqlite3ViewGetColumnNames(pParse, p->pTab); 111359 if( pStep->pFrom ){
111360 int i;
111361 for(i=0; i<pStep->pFrom->nSrc && rc==SQLITE_OK; i++){
111362 SrcItem *p = &pStep->pFrom->a[i];
111363 if( p->pSelect ){
111364 sqlite3SelectPrep(pParse, p->pSelect, 0);
110163 } 111365 }
110164 } 111366 }
110165 } 111367 }
110166 if( rc==SQLITE_OK && db->mallocFailed ){ 111368
111369 if( db->mallocFailed ){
110167 rc = SQLITE_NOMEM; 111370 rc = SQLITE_NOMEM;
110168 } 111371 }
110169 sNC.pSrcList = pSrc; 111372 sNC.pSrcList = pSrc;
@@ -110615,6 +111818,15 @@ static void renameTableFunc(
110615 if( pStep->zTarget && 0==sqlite3_stricmp(pStep->zTarget, zOld) ){ 111818 if( pStep->zTarget && 0==sqlite3_stricmp(pStep->zTarget, zOld) ){
110616 renameTokenFind(&sParse, &sCtx, pStep->zTarget); 111819 renameTokenFind(&sParse, &sCtx, pStep->zTarget);
110617 } 111820 }
111821 if( pStep->pFrom ){
111822 int i;
111823 for(i=0; i<pStep->pFrom->nSrc; i++){
111824 SrcItem *pItem = &pStep->pFrom->a[i];
111825 if( 0==sqlite3_stricmp(pItem->zName, zOld) ){
111826 renameTokenFind(&sParse, &sCtx, pItem->zName);
111827 }
111828 }
111829 }
110618 } 111830 }
110619 } 111831 }
110620 } 111832 }
@@ -111938,9 +113150,14 @@ static void statGet(
111938 ** * "WHERE a=? AND b=?" matches 2 rows. 113150 ** * "WHERE a=? AND b=?" matches 2 rows.
111939 ** 113151 **
111940 ** If D is the count of distinct values and K is the total number of 113152 ** If D is the count of distinct values and K is the total number of
111941 ** rows, then each estimate is computed as: 113153 ** rows, then each estimate is usually computed as:
111942 ** 113154 **
111943 ** I = (K+D-1)/D 113155 ** I = (K+D-1)/D
113156 **
113157 ** In other words, I is K/D rounded up to the next whole integer.
113158 ** However, if I is between 1.0 and 1.1 (in other words if I is
113159 ** close to 1.0 but just a little larger) then do not round up but
113160 ** instead keep the I value at 1.0.
111944 */ 113161 */
111945 sqlite3_str sStat; /* Text of the constructed "stat" line */ 113162 sqlite3_str sStat; /* Text of the constructed "stat" line */
111946 int i; /* Loop counter */ 113163 int i; /* Loop counter */
@@ -111951,6 +113168,7 @@ static void statGet(
111951 for(i=0; i<p->nKeyCol; i++){ 113168 for(i=0; i<p->nKeyCol; i++){
111952 u64 nDistinct = p->current.anDLt[i] + 1; 113169 u64 nDistinct = p->current.anDLt[i] + 1;
111953 u64 iVal = (p->nRow + nDistinct - 1) / nDistinct; 113170 u64 iVal = (p->nRow + nDistinct - 1) / nDistinct;
113171 if( iVal==2 && p->nRow*10 <= nDistinct*11 ) iVal = 1;
111954 sqlite3_str_appendf(&sStat, " %llu", iVal); 113172 sqlite3_str_appendf(&sStat, " %llu", iVal);
111955 assert( p->current.anEq[i] ); 113173 assert( p->current.anEq[i] );
111956 } 113174 }
@@ -112114,7 +113332,7 @@ static void analyzeOneTable(
112114 memcpy(pStat1->zName, "sqlite_stat1", 13); 113332 memcpy(pStat1->zName, "sqlite_stat1", 13);
112115 pStat1->nCol = 3; 113333 pStat1->nCol = 3;
112116 pStat1->iPKey = -1; 113334 pStat1->iPKey = -1;
112117 sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNBLOB); 113335 sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNAMIC);
112118 } 113336 }
112119#endif 113337#endif
112120 113338
@@ -113504,7 +114722,11 @@ static int fixSelectCb(Walker *p, Select *pSelect){
113504 pItem->fg.fromDDL = 1; 114722 pItem->fg.fromDDL = 1;
113505 } 114723 }
113506#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER) 114724#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER)
113507 if( sqlite3WalkExpr(&pFix->w, pList->a[i].pOn) ) return WRC_Abort; 114725 if( pList->a[i].fg.isUsing==0
114726 && sqlite3WalkExpr(&pFix->w, pList->a[i].u3.pOn)
114727 ){
114728 return WRC_Abort;
114729 }
113508#endif 114730#endif
113509 } 114731 }
113510 if( pSelect->pWith ){ 114732 if( pSelect->pWith ){
@@ -114068,9 +115290,7 @@ SQLITE_PRIVATE void sqlite3FinishCoding(Parse *pParse){
114068 int i; 115290 int i;
114069 int reg; 115291 int reg;
114070 115292
114071 if( NEVER(pReturning->nRetCol==0) ){ 115293 if( pReturning->nRetCol ){
114072 assert( CORRUPT_DB );
114073 }else{
114074 sqlite3VdbeAddOp0(v, OP_FkCheck); 115294 sqlite3VdbeAddOp0(v, OP_FkCheck);
114075 addrRewind = 115295 addrRewind =
114076 sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur); 115296 sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
@@ -114110,7 +115330,9 @@ SQLITE_PRIVATE void sqlite3FinishCoding(Parse *pParse){
114110 int iDb, i; 115330 int iDb, i;
114111 assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init ); 115331 assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
114112 sqlite3VdbeJumpHere(v, 0); 115332 sqlite3VdbeJumpHere(v, 0);
114113 for(iDb=0; iDb<db->nDb; iDb++){ 115333 assert( db->nDb>0 );
115334 iDb = 0;
115335 do{
114114 Schema *pSchema; 115336 Schema *pSchema;
114115 if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue; 115337 if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue;
114116 sqlite3VdbeUsesBtree(v, iDb); 115338 sqlite3VdbeUsesBtree(v, iDb);
@@ -114125,7 +115347,7 @@ SQLITE_PRIVATE void sqlite3FinishCoding(Parse *pParse){
114125 if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1); 115347 if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
114126 VdbeComment((v, 115348 VdbeComment((v,
114127 "usesStmtJournal=%d", pParse->mayAbort && pParse->isMultiWrite)); 115349 "usesStmtJournal=%d", pParse->mayAbort && pParse->isMultiWrite));
114128 } 115350 }while( ++iDb<db->nDb );
114129#ifndef SQLITE_OMIT_VIRTUALTABLE 115351#ifndef SQLITE_OMIT_VIRTUALTABLE
114130 for(i=0; i<pParse->nVtabLock; i++){ 115352 for(i=0; i<pParse->nVtabLock; i++){
114131 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]); 115353 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
@@ -114164,9 +115386,7 @@ SQLITE_PRIVATE void sqlite3FinishCoding(Parse *pParse){
114164 115386
114165 if( pParse->bReturning ){ 115387 if( pParse->bReturning ){
114166 Returning *pRet = pParse->u1.pReturning; 115388 Returning *pRet = pParse->u1.pReturning;
114167 if( NEVER(pRet->nRetCol==0) ){ 115389 if( pRet->nRetCol ){
114168 assert( CORRUPT_DB );
114169 }else{
114170 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol); 115390 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
114171 } 115391 }
114172 } 115392 }
@@ -114229,8 +115449,6 @@ SQLITE_PRIVATE void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
114229 memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ); 115449 memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
114230 db->mDbFlags |= DBFLAG_PreferBuiltin; 115450 db->mDbFlags |= DBFLAG_PreferBuiltin;
114231 sqlite3RunParser(pParse, zSql); 115451 sqlite3RunParser(pParse, zSql);
114232 sqlite3DbFree(db, pParse->zErrMsg);
114233 pParse->zErrMsg = 0;
114234 db->mDbFlags = savedDbFlags; 115452 db->mDbFlags = savedDbFlags;
114235 sqlite3DbFree(db, zSql); 115453 sqlite3DbFree(db, zSql);
114236 memcpy(PARSE_TAIL(pParse), saveBuf, PARSE_TAIL_SZ); 115454 memcpy(PARSE_TAIL(pParse), saveBuf, PARSE_TAIL_SZ);
@@ -115788,7 +117006,7 @@ SQLITE_PRIVATE void sqlite3AddPrimaryKey(
115788 pTab->keyConf = (u8)onError; 117006 pTab->keyConf = (u8)onError;
115789 assert( autoInc==0 || autoInc==1 ); 117007 assert( autoInc==0 || autoInc==1 );
115790 pTab->tabFlags |= autoInc*TF_Autoincrement; 117008 pTab->tabFlags |= autoInc*TF_Autoincrement;
115791 if( pList ) pParse->iPkSortOrder = pList->a[0].sortFlags; 117009 if( pList ) pParse->iPkSortOrder = pList->a[0].fg.sortFlags;
115792 (void)sqlite3HasExplicitNulls(pParse, pList); 117010 (void)sqlite3HasExplicitNulls(pParse, pList);
115793 }else if( autoInc ){ 117011 }else if( autoInc ){
115794#ifndef SQLITE_OMIT_AUTOINCREMENT 117012#ifndef SQLITE_OMIT_AUTOINCREMENT
@@ -116282,7 +117500,7 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
116282 if( IN_RENAME_OBJECT ){ 117500 if( IN_RENAME_OBJECT ){
116283 sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey); 117501 sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
116284 } 117502 }
116285 pList->a[0].sortFlags = pParse->iPkSortOrder; 117503 pList->a[0].fg.sortFlags = pParse->iPkSortOrder;
116286 assert( pParse->pNewTable==pTab ); 117504 assert( pParse->pNewTable==pTab );
116287 pTab->iPKey = -1; 117505 pTab->iPKey = -1;
116288 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0, 117506 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
@@ -116953,7 +118171,6 @@ SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
116953 Table *pSelTab; /* A fake table from which we get the result set */ 118171 Table *pSelTab; /* A fake table from which we get the result set */
116954 Select *pSel; /* Copy of the SELECT that implements the view */ 118172 Select *pSel; /* Copy of the SELECT that implements the view */
116955 int nErr = 0; /* Number of errors encountered */ 118173 int nErr = 0; /* Number of errors encountered */
116956 int n; /* Temporarily holds the number of cursors assigned */
116957 sqlite3 *db = pParse->db; /* Database connection for malloc errors */ 118174 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
116958#ifndef SQLITE_OMIT_VIRTUALTABLE 118175#ifndef SQLITE_OMIT_VIRTUALTABLE
116959 int rc; 118176 int rc;
@@ -117011,8 +118228,9 @@ SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
117011 pSel = sqlite3SelectDup(db, pTable->u.view.pSelect, 0); 118228 pSel = sqlite3SelectDup(db, pTable->u.view.pSelect, 0);
117012 if( pSel ){ 118229 if( pSel ){
117013 u8 eParseMode = pParse->eParseMode; 118230 u8 eParseMode = pParse->eParseMode;
118231 int nTab = pParse->nTab;
118232 int nSelect = pParse->nSelect;
117014 pParse->eParseMode = PARSE_MODE_NORMAL; 118233 pParse->eParseMode = PARSE_MODE_NORMAL;
117015 n = pParse->nTab;
117016 sqlite3SrcListAssignCursors(pParse, pSel->pSrc); 118234 sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
117017 pTable->nCol = -1; 118235 pTable->nCol = -1;
117018 DisableLookaside; 118236 DisableLookaside;
@@ -117024,7 +118242,8 @@ SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
117024#else 118242#else
117025 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE); 118243 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
117026#endif 118244#endif
117027 pParse->nTab = n; 118245 pParse->nTab = nTab;
118246 pParse->nSelect = nSelect;
117028 if( pSelTab==0 ){ 118247 if( pSelTab==0 ){
117029 pTable->nCol = 0; 118248 pTable->nCol = 0;
117030 nErr++; 118249 nErr++;
@@ -117769,8 +118988,8 @@ SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
117769 if( pList ){ 118988 if( pList ){
117770 int i; 118989 int i;
117771 for(i=0; i<pList->nExpr; i++){ 118990 for(i=0; i<pList->nExpr; i++){
117772 if( pList->a[i].bNulls ){ 118991 if( pList->a[i].fg.bNulls ){
117773 u8 sf = pList->a[i].sortFlags; 118992 u8 sf = pList->a[i].fg.sortFlags;
117774 sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s", 118993 sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s",
117775 (sf==0 || sf==3) ? "FIRST" : "LAST" 118994 (sf==0 || sf==3) ? "FIRST" : "LAST"
117776 ); 118995 );
@@ -118123,7 +119342,7 @@ SQLITE_PRIVATE void sqlite3CreateIndex(
118123 goto exit_create_index; 119342 goto exit_create_index;
118124 } 119343 }
118125 pIndex->azColl[i] = zColl; 119344 pIndex->azColl[i] = zColl;
118126 requestedSortOrder = pListItem->sortFlags & sortOrderMask; 119345 requestedSortOrder = pListItem->fg.sortFlags & sortOrderMask;
118127 pIndex->aSortOrder[i] = (u8)requestedSortOrder; 119346 pIndex->aSortOrder[i] = (u8)requestedSortOrder;
118128 } 119347 }
118129 119348
@@ -118566,18 +119785,17 @@ SQLITE_PRIVATE IdList *sqlite3IdListAppend(Parse *pParse, IdList *pList, Token *
118566 if( pList==0 ){ 119785 if( pList==0 ){
118567 pList = sqlite3DbMallocZero(db, sizeof(IdList) ); 119786 pList = sqlite3DbMallocZero(db, sizeof(IdList) );
118568 if( pList==0 ) return 0; 119787 if( pList==0 ) return 0;
119788 }else{
119789 IdList *pNew;
119790 pNew = sqlite3DbRealloc(db, pList,
119791 sizeof(IdList) + pList->nId*sizeof(pList->a));
119792 if( pNew==0 ){
119793 sqlite3IdListDelete(db, pList);
119794 return 0;
119795 }
119796 pList = pNew;
118569 } 119797 }
118570 pList->a = sqlite3ArrayAllocate( 119798 i = pList->nId++;
118571 db,
118572 pList->a,
118573 sizeof(pList->a[0]),
118574 &pList->nId,
118575 &i
118576 );
118577 if( i<0 ){
118578 sqlite3IdListDelete(db, pList);
118579 return 0;
118580 }
118581 pList->a[i].zName = sqlite3NameFromToken(db, pToken); 119799 pList->a[i].zName = sqlite3NameFromToken(db, pToken);
118582 if( IN_RENAME_OBJECT && pList->a[i].zName ){ 119800 if( IN_RENAME_OBJECT && pList->a[i].zName ){
118583 sqlite3RenameTokenMap(pParse, (void*)pList->a[i].zName, pToken); 119801 sqlite3RenameTokenMap(pParse, (void*)pList->a[i].zName, pToken);
@@ -118591,10 +119809,10 @@ SQLITE_PRIVATE IdList *sqlite3IdListAppend(Parse *pParse, IdList *pList, Token *
118591SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){ 119809SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
118592 int i; 119810 int i;
118593 if( pList==0 ) return; 119811 if( pList==0 ) return;
119812 assert( pList->eU4!=EU4_EXPR ); /* EU4_EXPR mode is not currently used */
118594 for(i=0; i<pList->nId; i++){ 119813 for(i=0; i<pList->nId; i++){
118595 sqlite3DbFree(db, pList->a[i].zName); 119814 sqlite3DbFree(db, pList->a[i].zName);
118596 } 119815 }
118597 sqlite3DbFree(db, pList->a);
118598 sqlite3DbFreeNN(db, pList); 119816 sqlite3DbFreeNN(db, pList);
118599} 119817}
118600 119818
@@ -118604,7 +119822,7 @@ SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
118604*/ 119822*/
118605SQLITE_PRIVATE int sqlite3IdListIndex(IdList *pList, const char *zName){ 119823SQLITE_PRIVATE int sqlite3IdListIndex(IdList *pList, const char *zName){
118606 int i; 119824 int i;
118607 if( pList==0 ) return -1; 119825 assert( pList!=0 );
118608 for(i=0; i<pList->nId; i++){ 119826 for(i=0; i<pList->nId; i++){
118609 if( sqlite3StrICmp(pList->a[i].zName, zName)==0 ) return i; 119827 if( sqlite3StrICmp(pList->a[i].zName, zName)==0 ) return i;
118610 } 119828 }
@@ -118807,8 +120025,11 @@ SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){
118807 if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg); 120025 if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg);
118808 sqlite3DeleteTable(db, pItem->pTab); 120026 sqlite3DeleteTable(db, pItem->pTab);
118809 if( pItem->pSelect ) sqlite3SelectDelete(db, pItem->pSelect); 120027 if( pItem->pSelect ) sqlite3SelectDelete(db, pItem->pSelect);
118810 if( pItem->pOn ) sqlite3ExprDelete(db, pItem->pOn); 120028 if( pItem->fg.isUsing ){
118811 if( pItem->pUsing ) sqlite3IdListDelete(db, pItem->pUsing); 120029 sqlite3IdListDelete(db, pItem->u3.pUsing);
120030 }else if( pItem->u3.pOn ){
120031 sqlite3ExprDelete(db, pItem->u3.pOn);
120032 }
118812 } 120033 }
118813 sqlite3DbFreeNN(db, pList); 120034 sqlite3DbFreeNN(db, pList);
118814} 120035}
@@ -118836,14 +120057,13 @@ SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm(
118836 Token *pDatabase, /* Name of the database containing pTable */ 120057 Token *pDatabase, /* Name of the database containing pTable */
118837 Token *pAlias, /* The right-hand side of the AS subexpression */ 120058 Token *pAlias, /* The right-hand side of the AS subexpression */
118838 Select *pSubquery, /* A subquery used in place of a table name */ 120059 Select *pSubquery, /* A subquery used in place of a table name */
118839 Expr *pOn, /* The ON clause of a join */ 120060 OnOrUsing *pOnUsing /* Either the ON clause or the USING clause */
118840 IdList *pUsing /* The USING clause of a join */
118841){ 120061){
118842 SrcItem *pItem; 120062 SrcItem *pItem;
118843 sqlite3 *db = pParse->db; 120063 sqlite3 *db = pParse->db;
118844 if( !p && (pOn || pUsing) ){ 120064 if( !p && pOnUsing!=0 && (pOnUsing->pOn || pOnUsing->pUsing) ){
118845 sqlite3ErrorMsg(pParse, "a JOIN clause is required before %s", 120065 sqlite3ErrorMsg(pParse, "a JOIN clause is required before %s",
118846 (pOn ? "ON" : "USING") 120066 (pOnUsing->pOn ? "ON" : "USING")
118847 ); 120067 );
118848 goto append_from_error; 120068 goto append_from_error;
118849 } 120069 }
@@ -118863,15 +120083,27 @@ SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm(
118863 if( pAlias->n ){ 120083 if( pAlias->n ){
118864 pItem->zAlias = sqlite3NameFromToken(db, pAlias); 120084 pItem->zAlias = sqlite3NameFromToken(db, pAlias);
118865 } 120085 }
118866 pItem->pSelect = pSubquery; 120086 if( pSubquery ){
118867 pItem->pOn = pOn; 120087 pItem->pSelect = pSubquery;
118868 pItem->pUsing = pUsing; 120088 if( pSubquery->selFlags & SF_NestedFrom ){
120089 pItem->fg.isNestedFrom = 1;
120090 }
120091 }
120092 assert( pOnUsing==0 || pOnUsing->pOn==0 || pOnUsing->pUsing==0 );
120093 assert( pItem->fg.isUsing==0 );
120094 if( pOnUsing==0 ){
120095 pItem->u3.pOn = 0;
120096 }else if( pOnUsing->pUsing ){
120097 pItem->fg.isUsing = 1;
120098 pItem->u3.pUsing = pOnUsing->pUsing;
120099 }else{
120100 pItem->u3.pOn = pOnUsing->pOn;
120101 }
118869 return p; 120102 return p;
118870 120103
118871append_from_error: 120104append_from_error:
118872 assert( p==0 ); 120105 assert( p==0 );
118873 sqlite3ExprDelete(db, pOn); 120106 sqlite3ClearOnOrUsing(db, pOnUsing);
118874 sqlite3IdListDelete(db, pUsing);
118875 sqlite3SelectDelete(db, pSubquery); 120107 sqlite3SelectDelete(db, pSubquery);
118876 return 0; 120108 return 0;
118877} 120109}
@@ -118916,6 +120148,7 @@ SQLITE_PRIVATE SrcList *sqlite3SrcListAppendList(Parse *pParse, SrcList *p1, Src
118916 p1 = pNew; 120148 p1 = pNew;
118917 memcpy(&p1->a[1], p2->a, p2->nSrc*sizeof(SrcItem)); 120149 memcpy(&p1->a[1], p2->a, p2->nSrc*sizeof(SrcItem));
118918 sqlite3DbFree(pParse->db, p2); 120150 sqlite3DbFree(pParse->db, p2);
120151 p1->a[0].fg.jointype |= (JT_LTORJ & p1->a[1].fg.jointype);
118919 } 120152 }
118920 } 120153 }
118921 return p1; 120154 return p1;
@@ -118952,14 +120185,34 @@ SQLITE_PRIVATE void sqlite3SrcListFuncArgs(Parse *pParse, SrcList *p, ExprList *
118952** The operator is "natural cross join". The A and B operands are stored 120185** The operator is "natural cross join". The A and B operands are stored
118953** in p->a[0] and p->a[1], respectively. The parser initially stores the 120186** in p->a[0] and p->a[1], respectively. The parser initially stores the
118954** operator with A. This routine shifts that operator over to B. 120187** operator with A. This routine shifts that operator over to B.
120188**
120189** Additional changes:
120190**
120191** * All tables to the left of the right-most RIGHT JOIN are tagged with
120192** JT_LTORJ (mnemonic: Left Table Of Right Join) so that the
120193** code generator can easily tell that the table is part of
120194** the left operand of at least one RIGHT JOIN.
118955*/ 120195*/
118956SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){ 120196SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(Parse *pParse, SrcList *p){
118957 if( p ){ 120197 (void)pParse;
118958 int i; 120198 if( p && p->nSrc>1 ){
118959 for(i=p->nSrc-1; i>0; i--){ 120199 int i = p->nSrc-1;
118960 p->a[i].fg.jointype = p->a[i-1].fg.jointype; 120200 u8 allFlags = 0;
118961 } 120201 do{
120202 allFlags |= p->a[i].fg.jointype = p->a[i-1].fg.jointype;
120203 }while( (--i)>0 );
118962 p->a[0].fg.jointype = 0; 120204 p->a[0].fg.jointype = 0;
120205
120206 /* All terms to the left of a RIGHT JOIN should be tagged with the
120207 ** JT_LTORJ flags */
120208 if( allFlags & JT_RIGHT ){
120209 for(i=p->nSrc-1; ALWAYS(i>0) && (p->a[i].fg.jointype&JT_RIGHT)==0; i--){}
120210 i--;
120211 assert( i>=0 );
120212 do{
120213 p->a[i].fg.jointype |= JT_LTORJ;
120214 }while( (--i)>=0 );
120215 }
118963 } 120216 }
118964} 120217}
118965 120218
@@ -120208,8 +121461,8 @@ SQLITE_PRIVATE void sqlite3MaterializeView(
120208 assert( pFrom->nSrc==1 ); 121461 assert( pFrom->nSrc==1 );
120209 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName); 121462 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
120210 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName); 121463 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
120211 assert( pFrom->a[0].pOn==0 ); 121464 assert( pFrom->a[0].fg.isUsing==0 );
120212 assert( pFrom->a[0].pUsing==0 ); 121465 assert( pFrom->a[0].u3.pOn==0 );
120213 } 121466 }
120214 pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, pOrderBy, 121467 pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, pOrderBy,
120215 SF_IncludeHidden, pLimit); 121468 SF_IncludeHidden, pLimit);
@@ -120380,7 +121633,6 @@ SQLITE_PRIVATE void sqlite3DeleteFrom(
120380 assert( db->mallocFailed==0 ); 121633 assert( db->mallocFailed==0 );
120381 assert( pTabList->nSrc==1 ); 121634 assert( pTabList->nSrc==1 );
120382 121635
120383
120384 /* Locate the table which we want to delete. This table has to be 121636 /* Locate the table which we want to delete. This table has to be
120385 ** put in an SrcList structure because some of the subroutines we 121637 ** put in an SrcList structure because some of the subroutines we
120386 ** will be calling are designed to work with multiple tables and expect 121638 ** will be calling are designed to work with multiple tables and expect
@@ -120405,6 +121657,14 @@ SQLITE_PRIVATE void sqlite3DeleteFrom(
120405# define isView 0 121657# define isView 0
120406#endif 121658#endif
120407 121659
121660#if TREETRACE_ENABLED
121661 if( sqlite3TreeTrace & 0x10000 ){
121662 sqlite3TreeViewLine(0, "In sqlite3Delete() at %s:%d", __FILE__, __LINE__);
121663 sqlite3TreeViewDelete(pParse->pWith, pTabList, pWhere,
121664 pOrderBy, pLimit, pTrigger);
121665 }
121666#endif
121667
120408#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT 121668#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
120409 if( !isView ){ 121669 if( !isView ){
120410 pWhere = sqlite3LimitWhere( 121670 pWhere = sqlite3LimitWhere(
@@ -123163,11 +124423,11 @@ static void logFunc(
123163 switch( SQLITE_PTR_TO_INT(sqlite3_user_data(context)) ){ 124423 switch( SQLITE_PTR_TO_INT(sqlite3_user_data(context)) ){
123164 case 1: 124424 case 1:
123165 /* Convert from natural logarithm to log base 10 */ 124425 /* Convert from natural logarithm to log base 10 */
123166 ans *= 1.0/M_LN10; 124426 ans /= M_LN10;
123167 break; 124427 break;
123168 case 2: 124428 case 2:
123169 /* Convert from natural logarithm to log base 2 */ 124429 /* Convert from natural logarithm to log base 2 */
123170 ans *= 1.0/M_LN2; 124430 ans /= M_LN2;
123171 break; 124431 break;
123172 default: 124432 default:
123173 break; 124433 break;
@@ -123306,8 +124566,7 @@ SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(void){
123306 INLINE_FUNC(likelihood, 2, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY), 124566 INLINE_FUNC(likelihood, 2, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
123307 INLINE_FUNC(likely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY), 124567 INLINE_FUNC(likely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
123308#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC 124568#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
123309 {1, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_OFFSET|SQLITE_FUNC_TYPEOF, 124569 INLINE_FUNC(sqlite_offset, 1, INLINEFUNC_sqlite_offset, 0 ),
123310 0, 0, noopFunc, 0, 0, 0, "sqlite_offset", {0} },
123311#endif 124570#endif
123312 FUNCTION(ltrim, 1, 1, 0, trimFunc ), 124571 FUNCTION(ltrim, 1, 1, 0, trimFunc ),
123313 FUNCTION(ltrim, 2, 1, 0, trimFunc ), 124572 FUNCTION(ltrim, 2, 1, 0, trimFunc ),
@@ -123842,7 +125101,6 @@ static void fkLookupParent(
123842 }else{ 125101 }else{
123843 int nCol = pFKey->nCol; 125102 int nCol = pFKey->nCol;
123844 int regTemp = sqlite3GetTempRange(pParse, nCol); 125103 int regTemp = sqlite3GetTempRange(pParse, nCol);
123845 int regRec = sqlite3GetTempReg(pParse);
123846 125104
123847 sqlite3VdbeAddOp3(v, OP_OpenRead, iCur, pIdx->tnum, iDb); 125105 sqlite3VdbeAddOp3(v, OP_OpenRead, iCur, pIdx->tnum, iDb);
123848 sqlite3VdbeSetP4KeyInfo(pParse, pIdx); 125106 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
@@ -123882,11 +125140,10 @@ static void fkLookupParent(
123882 sqlite3VdbeGoto(v, iOk); 125140 sqlite3VdbeGoto(v, iOk);
123883 } 125141 }
123884 125142
123885 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTemp, nCol, regRec, 125143 sqlite3VdbeAddOp4(v, OP_Affinity, regTemp, nCol, 0,
123886 sqlite3IndexAffinityStr(pParse->db,pIdx), nCol); 125144 sqlite3IndexAffinityStr(pParse->db,pIdx), nCol);
123887 sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); VdbeCoverage(v); 125145 sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regTemp, nCol);
123888 125146 VdbeCoverage(v);
123889 sqlite3ReleaseTempReg(pParse, regRec);
123890 sqlite3ReleaseTempRange(pParse, regTemp, nCol); 125147 sqlite3ReleaseTempRange(pParse, regTemp, nCol);
123891 } 125148 }
123892 } 125149 }
@@ -123988,14 +125245,10 @@ static Expr *exprTableColumn(
123988** Operation | FK type | Action taken 125245** Operation | FK type | Action taken
123989** -------------------------------------------------------------------------- 125246** --------------------------------------------------------------------------
123990** DELETE immediate Increment the "immediate constraint counter". 125247** DELETE immediate Increment the "immediate constraint counter".
123991** Or, if the ON (UPDATE|DELETE) action is RESTRICT,
123992** throw a "FOREIGN KEY constraint failed" exception.
123993** 125248**
123994** INSERT immediate Decrement the "immediate constraint counter". 125249** INSERT immediate Decrement the "immediate constraint counter".
123995** 125250**
123996** DELETE deferred Increment the "deferred constraint counter". 125251** DELETE deferred Increment the "deferred constraint counter".
123997** Or, if the ON (UPDATE|DELETE) action is RESTRICT,
123998** throw a "FOREIGN KEY constraint failed" exception.
123999** 125252**
124000** INSERT deferred Decrement the "deferred constraint counter". 125253** INSERT deferred Decrement the "deferred constraint counter".
124001** 125254**
@@ -124643,9 +125896,9 @@ SQLITE_PRIVATE int sqlite3FkRequired(
124643** 125896**
124644** It returns a pointer to a Trigger structure containing a trigger 125897** It returns a pointer to a Trigger structure containing a trigger
124645** equivalent to the ON UPDATE or ON DELETE action specified by pFKey. 125898** equivalent to the ON UPDATE or ON DELETE action specified by pFKey.
124646** If the action is "NO ACTION" or "RESTRICT", then a NULL pointer is 125899** If the action is "NO ACTION" then a NULL pointer is returned (these actions
124647** returned (these actions require no special handling by the triggers 125900** require no special handling by the triggers sub-system, code for them is
124648** sub-system, code for them is created by fkScanChildren()). 125901** created by fkScanChildren()).
124649** 125902**
124650** For example, if pFKey is the foreign key and pTab is table "p" in 125903** For example, if pFKey is the foreign key and pTab is table "p" in
124651** the following schema: 125904** the following schema:
@@ -124774,18 +126027,23 @@ static Trigger *fkActionTrigger(
124774 nFrom = sqlite3Strlen30(zFrom); 126027 nFrom = sqlite3Strlen30(zFrom);
124775 126028
124776 if( action==OE_Restrict ){ 126029 if( action==OE_Restrict ){
126030 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
124777 Token tFrom; 126031 Token tFrom;
126032 Token tDb;
124778 Expr *pRaise; 126033 Expr *pRaise;
124779 126034
124780 tFrom.z = zFrom; 126035 tFrom.z = zFrom;
124781 tFrom.n = nFrom; 126036 tFrom.n = nFrom;
126037 tDb.z = db->aDb[iDb].zDbSName;
126038 tDb.n = sqlite3Strlen30(tDb.z);
126039
124782 pRaise = sqlite3Expr(db, TK_RAISE, "FOREIGN KEY constraint failed"); 126040 pRaise = sqlite3Expr(db, TK_RAISE, "FOREIGN KEY constraint failed");
124783 if( pRaise ){ 126041 if( pRaise ){
124784 pRaise->affExpr = OE_Abort; 126042 pRaise->affExpr = OE_Abort;
124785 } 126043 }
124786 pSelect = sqlite3SelectNew(pParse, 126044 pSelect = sqlite3SelectNew(pParse,
124787 sqlite3ExprListAppend(pParse, 0, pRaise), 126045 sqlite3ExprListAppend(pParse, 0, pRaise),
124788 sqlite3SrcListAppend(pParse, 0, &tFrom, 0), 126046 sqlite3SrcListAppend(pParse, 0, &tDb, &tFrom),
124789 pWhere, 126047 pWhere,
124790 0, 0, 0, 0, 0 126048 0, 0, 0, 0, 0
124791 ); 126049 );
@@ -125695,6 +126953,14 @@ SQLITE_PRIVATE void sqlite3Insert(
125695#endif 126953#endif
125696 assert( (pTrigger && tmask) || (pTrigger==0 && tmask==0) ); 126954 assert( (pTrigger && tmask) || (pTrigger==0 && tmask==0) );
125697 126955
126956#if TREETRACE_ENABLED
126957 if( sqlite3TreeTrace & 0x10000 ){
126958 sqlite3TreeViewLine(0, "In sqlite3Insert() at %s:%d", __FILE__, __LINE__);
126959 sqlite3TreeViewInsert(pParse->pWith, pTabList, pColumn, pSelect, pList,
126960 onError, pUpsert, pTrigger);
126961 }
126962#endif
126963
125698 /* If pTab is really a view, make sure it has been initialized. 126964 /* If pTab is really a view, make sure it has been initialized.
125699 ** ViewGetColumnNames() is a no-op if pTab is not a view. 126965 ** ViewGetColumnNames() is a no-op if pTab is not a view.
125700 */ 126966 */
@@ -125773,13 +127039,15 @@ SQLITE_PRIVATE void sqlite3Insert(
125773 */ 127039 */
125774 bIdListInOrder = (pTab->tabFlags & (TF_OOOHidden|TF_HasStored))==0; 127040 bIdListInOrder = (pTab->tabFlags & (TF_OOOHidden|TF_HasStored))==0;
125775 if( pColumn ){ 127041 if( pColumn ){
127042 assert( pColumn->eU4!=EU4_EXPR );
127043 pColumn->eU4 = EU4_IDX;
125776 for(i=0; i<pColumn->nId; i++){ 127044 for(i=0; i<pColumn->nId; i++){
125777 pColumn->a[i].idx = -1; 127045 pColumn->a[i].u4.idx = -1;
125778 } 127046 }
125779 for(i=0; i<pColumn->nId; i++){ 127047 for(i=0; i<pColumn->nId; i++){
125780 for(j=0; j<pTab->nCol; j++){ 127048 for(j=0; j<pTab->nCol; j++){
125781 if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zCnName)==0 ){ 127049 if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zCnName)==0 ){
125782 pColumn->a[i].idx = j; 127050 pColumn->a[i].u4.idx = j;
125783 if( i!=j ) bIdListInOrder = 0; 127051 if( i!=j ) bIdListInOrder = 0;
125784 if( j==pTab->iPKey ){ 127052 if( j==pTab->iPKey ){
125785 ipkColumn = i; assert( !withoutRowid ); 127053 ipkColumn = i; assert( !withoutRowid );
@@ -126081,7 +127349,8 @@ SQLITE_PRIVATE void sqlite3Insert(
126081 } 127349 }
126082 } 127350 }
126083 if( pColumn ){ 127351 if( pColumn ){
126084 for(j=0; j<pColumn->nId && pColumn->a[j].idx!=i; j++){} 127352 assert( pColumn->eU4==EU4_IDX );
127353 for(j=0; j<pColumn->nId && pColumn->a[j].u4.idx!=i; j++){}
126085 if( j>=pColumn->nId ){ 127354 if( j>=pColumn->nId ){
126086 /* A column not named in the insert column list gets its 127355 /* A column not named in the insert column list gets its
126087 ** default value */ 127356 ** default value */
@@ -127212,7 +128481,7 @@ SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(
127212 if( isUpdate ){ 128481 if( isUpdate ){
127213 /* If currently processing the PRIMARY KEY of a WITHOUT ROWID 128482 /* If currently processing the PRIMARY KEY of a WITHOUT ROWID
127214 ** table, only conflict if the new PRIMARY KEY values are actually 128483 ** table, only conflict if the new PRIMARY KEY values are actually
127215 ** different from the old. 128484 ** different from the old. See TH3 withoutrowid04.test.
127216 ** 128485 **
127217 ** For a UNIQUE index, only conflict if the PRIMARY KEY values 128486 ** For a UNIQUE index, only conflict if the PRIMARY KEY values
127218 ** of the matched index row are different from the original PRIMARY 128487 ** of the matched index row are different from the original PRIMARY
@@ -128576,6 +129845,12 @@ struct sqlite3_api_routines {
128576 int (*vtab_in)(sqlite3_index_info*,int,int); 129845 int (*vtab_in)(sqlite3_index_info*,int,int);
128577 int (*vtab_in_first)(sqlite3_value*,sqlite3_value**); 129846 int (*vtab_in_first)(sqlite3_value*,sqlite3_value**);
128578 int (*vtab_in_next)(sqlite3_value*,sqlite3_value**); 129847 int (*vtab_in_next)(sqlite3_value*,sqlite3_value**);
129848 /* Version 3.39.0 and later */
129849 int (*deserialize)(sqlite3*,const char*,unsigned char*,
129850 sqlite3_int64,sqlite3_int64,unsigned);
129851 unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*,
129852 unsigned int);
129853 const char *(*db_name)(sqlite3*,int);
128579}; 129854};
128580 129855
128581/* 129856/*
@@ -128894,6 +130169,12 @@ typedef int (*sqlite3_loadext_entry)(
128894#define sqlite3_vtab_in sqlite3_api->vtab_in 130169#define sqlite3_vtab_in sqlite3_api->vtab_in
128895#define sqlite3_vtab_in_first sqlite3_api->vtab_in_first 130170#define sqlite3_vtab_in_first sqlite3_api->vtab_in_first
128896#define sqlite3_vtab_in_next sqlite3_api->vtab_in_next 130171#define sqlite3_vtab_in_next sqlite3_api->vtab_in_next
130172/* Version 3.39.0 and later */
130173#ifndef SQLITE_OMIT_DESERIALIZE
130174#define sqlite3_deserialize sqlite3_api->deserialize
130175#define sqlite3_serialize sqlite3_api->serialize
130176#endif
130177#define sqlite3_db_name sqlite3_api->db_name
128897#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ 130178#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
128898 130179
128899#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) 130180#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
@@ -129385,11 +130666,28 @@ static const sqlite3_api_routines sqlite3Apis = {
129385 sqlite3_autovacuum_pages, 130666 sqlite3_autovacuum_pages,
129386 /* Version 3.38.0 and later */ 130667 /* Version 3.38.0 and later */
129387 sqlite3_error_offset, 130668 sqlite3_error_offset,
130669#ifndef SQLITE_OMIT_VIRTUALTABLE
129388 sqlite3_vtab_rhs_value, 130670 sqlite3_vtab_rhs_value,
129389 sqlite3_vtab_distinct, 130671 sqlite3_vtab_distinct,
129390 sqlite3_vtab_in, 130672 sqlite3_vtab_in,
129391 sqlite3_vtab_in_first, 130673 sqlite3_vtab_in_first,
129392 sqlite3_vtab_in_next 130674 sqlite3_vtab_in_next,
130675#else
130676 0,
130677 0,
130678 0,
130679 0,
130680 0,
130681#endif
130682 /* Version 3.39.0 and later */
130683#ifndef SQLITE_OMIT_DESERIALIZE
130684 sqlite3_deserialize,
130685 sqlite3_serialize,
130686#else
130687 0,
130688 0,
130689#endif
130690 sqlite3_db_name
129393}; 130691};
129394 130692
129395/* True if x is the directory separator character 130693/* True if x is the directory separator character
@@ -130060,7 +131358,7 @@ static const PragmaName aPragmaName[] = {
130060#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) 131358#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
130061 {/* zName: */ "database_list", 131359 {/* zName: */ "database_list",
130062 /* ePragTyp: */ PragTyp_DATABASE_LIST, 131360 /* ePragTyp: */ PragTyp_DATABASE_LIST,
130063 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0, 131361 /* ePragFlg: */ PragFlg_Result0,
130064 /* ColNames: */ 47, 3, 131362 /* ColNames: */ 47, 3,
130065 /* iArg: */ 0 }, 131363 /* iArg: */ 0 },
130066#endif 131364#endif
@@ -130748,15 +132046,16 @@ static void pragmaFunclistLine(
130748 int isBuiltin, /* True if this is a built-in function */ 132046 int isBuiltin, /* True if this is a built-in function */
130749 int showInternFuncs /* True if showing internal functions */ 132047 int showInternFuncs /* True if showing internal functions */
130750){ 132048){
132049 u32 mask =
132050 SQLITE_DETERMINISTIC |
132051 SQLITE_DIRECTONLY |
132052 SQLITE_SUBTYPE |
132053 SQLITE_INNOCUOUS |
132054 SQLITE_FUNC_INTERNAL
132055 ;
132056 if( showInternFuncs ) mask = 0xffffffff;
130751 for(; p; p=p->pNext){ 132057 for(; p; p=p->pNext){
130752 const char *zType; 132058 const char *zType;
130753 static const u32 mask =
130754 SQLITE_DETERMINISTIC |
130755 SQLITE_DIRECTONLY |
130756 SQLITE_SUBTYPE |
130757 SQLITE_INNOCUOUS |
130758 SQLITE_FUNC_INTERNAL
130759 ;
130760 static const char *azEnc[] = { 0, "utf8", "utf16le", "utf16be" }; 132059 static const char *azEnc[] = { 0, "utf8", "utf16le", "utf16be" };
130761 132060
130762 assert( SQLITE_FUNC_ENCMASK==0x3 ); 132061 assert( SQLITE_FUNC_ENCMASK==0x3 );
@@ -131248,7 +132547,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
131248 */ 132547 */
131249#ifndef SQLITE_OMIT_AUTOVACUUM 132548#ifndef SQLITE_OMIT_AUTOVACUUM
131250 case PragTyp_INCREMENTAL_VACUUM: { 132549 case PragTyp_INCREMENTAL_VACUUM: {
131251 int iLimit, addr; 132550 int iLimit = 0, addr;
131252 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){ 132551 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
131253 iLimit = 0x7fffffff; 132552 iLimit = 0x7fffffff;
131254 } 132553 }
@@ -131936,7 +133235,6 @@ SQLITE_PRIVATE void sqlite3Pragma(
131936 HashElem *k; /* Loop counter: Next table in schema */ 133235 HashElem *k; /* Loop counter: Next table in schema */
131937 int x; /* result variable */ 133236 int x; /* result variable */
131938 int regResult; /* 3 registers to hold a result row */ 133237 int regResult; /* 3 registers to hold a result row */
131939 int regKey; /* Register to hold key for checking the FK */
131940 int regRow; /* Registers to hold a row from pTab */ 133238 int regRow; /* Registers to hold a row from pTab */
131941 int addrTop; /* Top of a loop checking foreign keys */ 133239 int addrTop; /* Top of a loop checking foreign keys */
131942 int addrOk; /* Jump here if the key is OK */ 133240 int addrOk; /* Jump here if the key is OK */
@@ -131944,7 +133242,6 @@ SQLITE_PRIVATE void sqlite3Pragma(
131944 133242
131945 regResult = pParse->nMem+1; 133243 regResult = pParse->nMem+1;
131946 pParse->nMem += 4; 133244 pParse->nMem += 4;
131947 regKey = ++pParse->nMem;
131948 regRow = ++pParse->nMem; 133245 regRow = ++pParse->nMem;
131949 k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash); 133246 k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash);
131950 while( k ){ 133247 while( k ){
@@ -132011,9 +133308,9 @@ SQLITE_PRIVATE void sqlite3Pragma(
132011 /* Generate code to query the parent index for a matching parent 133308 /* Generate code to query the parent index for a matching parent
132012 ** key. If a match is found, jump to addrOk. */ 133309 ** key. If a match is found, jump to addrOk. */
132013 if( pIdx ){ 133310 if( pIdx ){
132014 sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey, 133311 sqlite3VdbeAddOp4(v, OP_Affinity, regRow, pFK->nCol, 0,
132015 sqlite3IndexAffinityStr(db,pIdx), pFK->nCol); 133312 sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
132016 sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0); 133313 sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regRow, pFK->nCol);
132017 VdbeCoverage(v); 133314 VdbeCoverage(v);
132018 }else if( pParent ){ 133315 }else if( pParent ){
132019 int jmp = sqlite3VdbeCurrentAddr(v)+2; 133316 int jmp = sqlite3VdbeCurrentAddr(v)+2;
@@ -133827,6 +135124,14 @@ SQLITE_PRIVATE void sqlite3ParseObjectInit(Parse *pParse, sqlite3 *db){
133827} 135124}
133828 135125
133829/* 135126/*
135127** Maximum number of times that we will try again to prepare a statement
135128** that returns SQLITE_ERROR_RETRY.
135129*/
135130#ifndef SQLITE_MAX_PREPARE_RETRY
135131# define SQLITE_MAX_PREPARE_RETRY 25
135132#endif
135133
135134/*
133830** Compile the UTF-8 encoded SQL statement zSql into a statement handle. 135135** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
133831*/ 135136*/
133832static int sqlite3Prepare( 135137static int sqlite3Prepare(
@@ -134000,7 +135305,7 @@ static int sqlite3LockAndPrepare(
134000 rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail); 135305 rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
134001 assert( rc==SQLITE_OK || *ppStmt==0 ); 135306 assert( rc==SQLITE_OK || *ppStmt==0 );
134002 if( rc==SQLITE_OK || db->mallocFailed ) break; 135307 if( rc==SQLITE_OK || db->mallocFailed ) break;
134003 }while( rc==SQLITE_ERROR_RETRY 135308 }while( (rc==SQLITE_ERROR_RETRY && (cnt++)<SQLITE_MAX_PREPARE_RETRY)
134004 || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) ); 135309 || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
134005 sqlite3BtreeLeaveAll(db); 135310 sqlite3BtreeLeaveAll(db);
134006 rc = sqlite3ApiExit(db, rc); 135311 rc = sqlite3ApiExit(db, rc);
@@ -134241,7 +135546,7 @@ SQLITE_API int sqlite3_prepare16_v3(
134241*/ 135546*/
134242typedef struct DistinctCtx DistinctCtx; 135547typedef struct DistinctCtx DistinctCtx;
134243struct DistinctCtx { 135548struct DistinctCtx {
134244 u8 isTnct; /* True if the DISTINCT keyword is present */ 135549 u8 isTnct; /* 0: Not distinct. 1: DISTICT 2: DISTINCT and ORDER BY */
134245 u8 eTnctType; /* One of the WHERE_DISTINCT_* operators */ 135550 u8 eTnctType; /* One of the WHERE_DISTINCT_* operators */
134246 int tabTnct; /* Ephemeral table used for DISTINCT processing */ 135551 int tabTnct; /* Ephemeral table used for DISTINCT processing */
134247 int addrTnct; /* Address of OP_OpenEphemeral opcode for tabTnct */ 135552 int addrTnct; /* Address of OP_OpenEphemeral opcode for tabTnct */
@@ -134424,6 +135729,52 @@ static Select *findRightmost(Select *p){
134424** 135729**
134425** If an illegal or unsupported join type is seen, then still return 135730** If an illegal or unsupported join type is seen, then still return
134426** a join type, but put an error in the pParse structure. 135731** a join type, but put an error in the pParse structure.
135732**
135733** These are the valid join types:
135734**
135735**
135736** pA pB pC Return Value
135737** ------- ----- ----- ------------
135738** CROSS - - JT_CROSS
135739** INNER - - JT_INNER
135740** LEFT - - JT_LEFT|JT_OUTER
135741** LEFT OUTER - JT_LEFT|JT_OUTER
135742** RIGHT - - JT_RIGHT|JT_OUTER
135743** RIGHT OUTER - JT_RIGHT|JT_OUTER
135744** FULL - - JT_LEFT|JT_RIGHT|JT_OUTER
135745** FULL OUTER - JT_LEFT|JT_RIGHT|JT_OUTER
135746** NATURAL INNER - JT_NATURAL|JT_INNER
135747** NATURAL LEFT - JT_NATURAL|JT_LEFT|JT_OUTER
135748** NATURAL LEFT OUTER JT_NATURAL|JT_LEFT|JT_OUTER
135749** NATURAL RIGHT - JT_NATURAL|JT_RIGHT|JT_OUTER
135750** NATURAL RIGHT OUTER JT_NATURAL|JT_RIGHT|JT_OUTER
135751** NATURAL FULL - JT_NATURAL|JT_LEFT|JT_RIGHT
135752** NATURAL FULL OUTER JT_NATRUAL|JT_LEFT|JT_RIGHT
135753**
135754** To preserve historical compatibly, SQLite also accepts a variety
135755** of other non-standard and in many cases non-sensical join types.
135756** This routine makes as much sense at it can from the nonsense join
135757** type and returns a result. Examples of accepted nonsense join types
135758** include but are not limited to:
135759**
135760** INNER CROSS JOIN -> same as JOIN
135761** NATURAL CROSS JOIN -> same as NATURAL JOIN
135762** OUTER LEFT JOIN -> same as LEFT JOIN
135763** LEFT NATURAL JOIN -> same as NATURAL LEFT JOIN
135764** LEFT RIGHT JOIN -> same as FULL JOIN
135765** RIGHT OUTER FULL JOIN -> same as FULL JOIN
135766** CROSS CROSS CROSS JOIN -> same as JOIN
135767**
135768** The only restrictions on the join type name are:
135769**
135770** * "INNER" cannot appear together with "OUTER", "LEFT", "RIGHT",
135771** or "FULL".
135772**
135773** * "CROSS" cannot appear together with "OUTER", "LEFT", "RIGHT,
135774** or "FULL".
135775**
135776** * If "OUTER" is present then there must also be one of
135777** "LEFT", "RIGHT", or "FULL"
134427*/ 135778*/
134428SQLITE_PRIVATE int sqlite3JoinType(Parse *pParse, Token *pA, Token *pB, Token *pC){ 135779SQLITE_PRIVATE int sqlite3JoinType(Parse *pParse, Token *pA, Token *pB, Token *pC){
134429 int jointype = 0; 135780 int jointype = 0;
@@ -134436,13 +135787,13 @@ SQLITE_PRIVATE int sqlite3JoinType(Parse *pParse, Token *pA, Token *pB, Token *p
134436 u8 nChar; /* Length of the keyword in characters */ 135787 u8 nChar; /* Length of the keyword in characters */
134437 u8 code; /* Join type mask */ 135788 u8 code; /* Join type mask */
134438 } aKeyword[] = { 135789 } aKeyword[] = {
134439 /* natural */ { 0, 7, JT_NATURAL }, 135790 /* (0) natural */ { 0, 7, JT_NATURAL },
134440 /* left */ { 6, 4, JT_LEFT|JT_OUTER }, 135791 /* (1) left */ { 6, 4, JT_LEFT|JT_OUTER },
134441 /* outer */ { 10, 5, JT_OUTER }, 135792 /* (2) outer */ { 10, 5, JT_OUTER },
134442 /* right */ { 14, 5, JT_RIGHT|JT_OUTER }, 135793 /* (3) right */ { 14, 5, JT_RIGHT|JT_OUTER },
134443 /* full */ { 19, 4, JT_LEFT|JT_RIGHT|JT_OUTER }, 135794 /* (4) full */ { 19, 4, JT_LEFT|JT_RIGHT|JT_OUTER },
134444 /* inner */ { 23, 5, JT_INNER }, 135795 /* (5) inner */ { 23, 5, JT_INNER },
134445 /* cross */ { 28, 5, JT_INNER|JT_CROSS }, 135796 /* (6) cross */ { 28, 5, JT_INNER|JT_CROSS },
134446 }; 135797 };
134447 int i, j; 135798 int i, j;
134448 apAll[0] = pA; 135799 apAll[0] = pA;
@@ -134465,18 +135816,15 @@ SQLITE_PRIVATE int sqlite3JoinType(Parse *pParse, Token *pA, Token *pB, Token *p
134465 } 135816 }
134466 if( 135817 if(
134467 (jointype & (JT_INNER|JT_OUTER))==(JT_INNER|JT_OUTER) || 135818 (jointype & (JT_INNER|JT_OUTER))==(JT_INNER|JT_OUTER) ||
134468 (jointype & JT_ERROR)!=0 135819 (jointype & JT_ERROR)!=0 ||
135820 (jointype & (JT_OUTER|JT_LEFT|JT_RIGHT))==JT_OUTER
134469 ){ 135821 ){
134470 const char *zSp = " "; 135822 const char *zSp1 = " ";
134471 assert( pB!=0 ); 135823 const char *zSp2 = " ";
134472 if( pC==0 ){ zSp++; } 135824 if( pB==0 ){ zSp1++; }
134473 sqlite3ErrorMsg(pParse, "unknown or unsupported join type: " 135825 if( pC==0 ){ zSp2++; }
134474 "%T %T%s%T", pA, pB, zSp, pC); 135826 sqlite3ErrorMsg(pParse, "unknown join type: "
134475 jointype = JT_INNER; 135827 "%T%s%T%s%T", pA, zSp1, pB, zSp2, pC);
134476 }else if( (jointype & JT_OUTER)!=0
134477 && (jointype & (JT_LEFT|JT_RIGHT))!=JT_LEFT ){
134478 sqlite3ErrorMsg(pParse,
134479 "RIGHT and FULL OUTER JOINs are not currently supported");
134480 jointype = JT_INNER; 135828 jointype = JT_INNER;
134481 } 135829 }
134482 return jointype; 135830 return jointype;
@@ -134497,8 +135845,25 @@ SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol){
134497} 135845}
134498 135846
134499/* 135847/*
134500** Search the first N tables in pSrc, from left to right, looking for a 135848** Mark a subquery result column as having been used.
134501** table that has a column named zCol. 135849*/
135850SQLITE_PRIVATE void sqlite3SrcItemColumnUsed(SrcItem *pItem, int iCol){
135851 assert( pItem!=0 );
135852 assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
135853 if( pItem->fg.isNestedFrom ){
135854 ExprList *pResults;
135855 assert( pItem->pSelect!=0 );
135856 pResults = pItem->pSelect->pEList;
135857 assert( pResults!=0 );
135858 assert( iCol>=0 && iCol<pResults->nExpr );
135859 pResults->a[iCol].fg.bUsed = 1;
135860 }
135861}
135862
135863/*
135864** Search the tables iStart..iEnd (inclusive) in pSrc, looking for a
135865** table that has a column named zCol. The search is left-to-right.
135866** The first match found is returned.
134502** 135867**
134503** When found, set *piTab and *piCol to the table index and column index 135868** When found, set *piTab and *piCol to the table index and column index
134504** of the matching column and return TRUE. 135869** of the matching column and return TRUE.
@@ -134507,22 +135872,27 @@ SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol){
134507*/ 135872*/
134508static int tableAndColumnIndex( 135873static int tableAndColumnIndex(
134509 SrcList *pSrc, /* Array of tables to search */ 135874 SrcList *pSrc, /* Array of tables to search */
134510 int N, /* Number of tables in pSrc->a[] to search */ 135875 int iStart, /* First member of pSrc->a[] to check */
135876 int iEnd, /* Last member of pSrc->a[] to check */
134511 const char *zCol, /* Name of the column we are looking for */ 135877 const char *zCol, /* Name of the column we are looking for */
134512 int *piTab, /* Write index of pSrc->a[] here */ 135878 int *piTab, /* Write index of pSrc->a[] here */
134513 int *piCol, /* Write index of pSrc->a[*piTab].pTab->aCol[] here */ 135879 int *piCol, /* Write index of pSrc->a[*piTab].pTab->aCol[] here */
134514 int bIgnoreHidden /* True to ignore hidden columns */ 135880 int bIgnoreHidden /* Ignore hidden columns */
134515){ 135881){
134516 int i; /* For looping over tables in pSrc */ 135882 int i; /* For looping over tables in pSrc */
134517 int iCol; /* Index of column matching zCol */ 135883 int iCol; /* Index of column matching zCol */
134518 135884
135885 assert( iEnd<pSrc->nSrc );
135886 assert( iStart>=0 );
134519 assert( (piTab==0)==(piCol==0) ); /* Both or neither are NULL */ 135887 assert( (piTab==0)==(piCol==0) ); /* Both or neither are NULL */
134520 for(i=0; i<N; i++){ 135888
135889 for(i=iStart; i<=iEnd; i++){
134521 iCol = sqlite3ColumnIndex(pSrc->a[i].pTab, zCol); 135890 iCol = sqlite3ColumnIndex(pSrc->a[i].pTab, zCol);
134522 if( iCol>=0 135891 if( iCol>=0
134523 && (bIgnoreHidden==0 || IsHiddenColumn(&pSrc->a[i].pTab->aCol[iCol])==0) 135892 && (bIgnoreHidden==0 || IsHiddenColumn(&pSrc->a[i].pTab->aCol[iCol])==0)
134524 ){ 135893 ){
134525 if( piTab ){ 135894 if( piTab ){
135895 sqlite3SrcItemColumnUsed(&pSrc->a[i], iCol);
134526 *piTab = i; 135896 *piTab = i;
134527 *piCol = iCol; 135897 *piCol = iCol;
134528 } 135898 }
@@ -134533,66 +135903,19 @@ static int tableAndColumnIndex(
134533} 135903}
134534 135904
134535/* 135905/*
134536** This function is used to add terms implied by JOIN syntax to the 135906** Set the EP_OuterON property on all terms of the given expression.
134537** WHERE clause expression of a SELECT statement. The new term, which 135907** And set the Expr.w.iJoin to iTable for every term in the
134538** is ANDed with the existing WHERE clause, is of the form:
134539**
134540** (tab1.col1 = tab2.col2)
134541**
134542** where tab1 is the iSrc'th table in SrcList pSrc and tab2 is the
134543** (iSrc+1)'th. Column col1 is column iColLeft of tab1, and col2 is
134544** column iColRight of tab2.
134545*/
134546static void addWhereTerm(
134547 Parse *pParse, /* Parsing context */
134548 SrcList *pSrc, /* List of tables in FROM clause */
134549 int iLeft, /* Index of first table to join in pSrc */
134550 int iColLeft, /* Index of column in first table */
134551 int iRight, /* Index of second table in pSrc */
134552 int iColRight, /* Index of column in second table */
134553 int isOuterJoin, /* True if this is an OUTER join */
134554 Expr **ppWhere /* IN/OUT: The WHERE clause to add to */
134555){
134556 sqlite3 *db = pParse->db;
134557 Expr *pE1;
134558 Expr *pE2;
134559 Expr *pEq;
134560
134561 assert( iLeft<iRight );
134562 assert( pSrc->nSrc>iRight );
134563 assert( pSrc->a[iLeft].pTab );
134564 assert( pSrc->a[iRight].pTab );
134565
134566 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);
134567 pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
134568
134569 pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2);
134570 assert( pE2!=0 || pEq==0 ); /* Due to db->mallocFailed test
134571 ** in sqlite3DbMallocRawNN() called from
134572 ** sqlite3PExpr(). */
134573 if( pEq && isOuterJoin ){
134574 ExprSetProperty(pEq, EP_FromJoin);
134575 assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
134576 ExprSetVVAProperty(pEq, EP_NoReduce);
134577 pEq->w.iRightJoinTable = pE2->iTable;
134578 }
134579 *ppWhere = sqlite3ExprAnd(pParse, *ppWhere, pEq);
134580}
134581
134582/*
134583** Set the EP_FromJoin property on all terms of the given expression.
134584** And set the Expr.w.iRightJoinTable to iTable for every term in the
134585** expression. 135908** expression.
134586** 135909**
134587** The EP_FromJoin property is used on terms of an expression to tell 135910** The EP_OuterON property is used on terms of an expression to tell
134588** the LEFT OUTER JOIN processing logic that this term is part of the 135911** the OUTER JOIN processing logic that this term is part of the
134589** join restriction specified in the ON or USING clause and not a part 135912** join restriction specified in the ON or USING clause and not a part
134590** of the more general WHERE clause. These terms are moved over to the 135913** of the more general WHERE clause. These terms are moved over to the
134591** WHERE clause during join processing but we need to remember that they 135914** WHERE clause during join processing but we need to remember that they
134592** originated in the ON or USING clause. 135915** originated in the ON or USING clause.
134593** 135916**
134594** The Expr.w.iRightJoinTable tells the WHERE clause processing that the 135917** The Expr.w.iJoin tells the WHERE clause processing that the
134595** expression depends on table w.iRightJoinTable even if that table is not 135918** expression depends on table w.iJoin even if that table is not
134596** explicitly mentioned in the expression. That information is needed 135919** explicitly mentioned in the expression. That information is needed
134597** for cases like this: 135920** for cases like this:
134598** 135921**
@@ -134605,39 +135928,48 @@ static void addWhereTerm(
134605** after the t1 loop and rows with t1.x!=5 will never appear in 135928** after the t1 loop and rows with t1.x!=5 will never appear in
134606** the output, which is incorrect. 135929** the output, which is incorrect.
134607*/ 135930*/
134608SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr *p, int iTable){ 135931SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr *p, int iTable, u32 joinFlag){
135932 assert( joinFlag==EP_OuterON || joinFlag==EP_InnerON );
134609 while( p ){ 135933 while( p ){
134610 ExprSetProperty(p, EP_FromJoin); 135934 ExprSetProperty(p, joinFlag);
134611 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) ); 135935 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
134612 ExprSetVVAProperty(p, EP_NoReduce); 135936 ExprSetVVAProperty(p, EP_NoReduce);
134613 p->w.iRightJoinTable = iTable; 135937 p->w.iJoin = iTable;
134614 if( p->op==TK_FUNCTION ){ 135938 if( p->op==TK_FUNCTION ){
134615 assert( ExprUseXList(p) ); 135939 assert( ExprUseXList(p) );
134616 if( p->x.pList ){ 135940 if( p->x.pList ){
134617 int i; 135941 int i;
134618 for(i=0; i<p->x.pList->nExpr; i++){ 135942 for(i=0; i<p->x.pList->nExpr; i++){
134619 sqlite3SetJoinExpr(p->x.pList->a[i].pExpr, iTable); 135943 sqlite3SetJoinExpr(p->x.pList->a[i].pExpr, iTable, joinFlag);
134620 } 135944 }
134621 } 135945 }
134622 } 135946 }
134623 sqlite3SetJoinExpr(p->pLeft, iTable); 135947 sqlite3SetJoinExpr(p->pLeft, iTable, joinFlag);
134624 p = p->pRight; 135948 p = p->pRight;
134625 } 135949 }
134626} 135950}
134627 135951
134628/* Undo the work of sqlite3SetJoinExpr(). In the expression p, convert every 135952/* Undo the work of sqlite3SetJoinExpr(). This is used when a LEFT JOIN
134629** term that is marked with EP_FromJoin and w.iRightJoinTable==iTable into 135953** is simplified into an ordinary JOIN, and when an ON expression is
134630** an ordinary term that omits the EP_FromJoin mark. 135954** "pushed down" into the WHERE clause of a subquery.
135955**
135956** Convert every term that is marked with EP_OuterON and w.iJoin==iTable into
135957** an ordinary term that omits the EP_OuterON mark. Or if iTable<0, then
135958** just clear every EP_OuterON and EP_InnerON mark from the expression tree.
134631** 135959**
134632** This happens when a LEFT JOIN is simplified into an ordinary JOIN. 135960** If nullable is true, that means that Expr p might evaluate to NULL even
135961** if it is a reference to a NOT NULL column. This can happen, for example,
135962** if the table that p references is on the left side of a RIGHT JOIN.
135963** If nullable is true, then take care to not remove the EP_CanBeNull bit.
135964** See forum thread https://sqlite.org/forum/forumpost/b40696f50145d21c
134633*/ 135965*/
134634static void unsetJoinExpr(Expr *p, int iTable){ 135966static void unsetJoinExpr(Expr *p, int iTable, int nullable){
134635 while( p ){ 135967 while( p ){
134636 if( ExprHasProperty(p, EP_FromJoin) 135968 if( iTable<0 || (ExprHasProperty(p, EP_OuterON) && p->w.iJoin==iTable) ){
134637 && (iTable<0 || p->w.iRightJoinTable==iTable) ){ 135969 ExprClearProperty(p, EP_OuterON|EP_InnerON);
134638 ExprClearProperty(p, EP_FromJoin); 135970 if( iTable>=0 ) ExprSetProperty(p, EP_InnerON);
134639 } 135971 }
134640 if( p->op==TK_COLUMN && p->iTable==iTable ){ 135972 if( p->op==TK_COLUMN && p->iTable==iTable && !nullable ){
134641 ExprClearProperty(p, EP_CanBeNull); 135973 ExprClearProperty(p, EP_CanBeNull);
134642 } 135974 }
134643 if( p->op==TK_FUNCTION ){ 135975 if( p->op==TK_FUNCTION ){
@@ -134645,30 +135977,37 @@ static void unsetJoinExpr(Expr *p, int iTable){
134645 if( p->x.pList ){ 135977 if( p->x.pList ){
134646 int i; 135978 int i;
134647 for(i=0; i<p->x.pList->nExpr; i++){ 135979 for(i=0; i<p->x.pList->nExpr; i++){
134648 unsetJoinExpr(p->x.pList->a[i].pExpr, iTable); 135980 unsetJoinExpr(p->x.pList->a[i].pExpr, iTable, nullable);
134649 } 135981 }
134650 } 135982 }
134651 } 135983 }
134652 unsetJoinExpr(p->pLeft, iTable); 135984 unsetJoinExpr(p->pLeft, iTable, nullable);
134653 p = p->pRight; 135985 p = p->pRight;
134654 } 135986 }
134655} 135987}
134656 135988
134657/* 135989/*
134658** This routine processes the join information for a SELECT statement. 135990** This routine processes the join information for a SELECT statement.
134659** ON and USING clauses are converted into extra terms of the WHERE clause. 135991**
134660** NATURAL joins also create extra WHERE clause terms. 135992** * A NATURAL join is converted into a USING join. After that, we
135993** do not need to be concerned with NATURAL joins and we only have
135994** think about USING joins.
135995**
135996** * ON and USING clauses result in extra terms being added to the
135997** WHERE clause to enforce the specified constraints. The extra
135998** WHERE clause terms will be tagged with EP_OuterON or
135999** EP_InnerON so that we know that they originated in ON/USING.
134661** 136000**
134662** The terms of a FROM clause are contained in the Select.pSrc structure. 136001** The terms of a FROM clause are contained in the Select.pSrc structure.
134663** The left most table is the first entry in Select.pSrc. The right-most 136002** The left most table is the first entry in Select.pSrc. The right-most
134664** table is the last entry. The join operator is held in the entry to 136003** table is the last entry. The join operator is held in the entry to
134665** the left. Thus entry 0 contains the join operator for the join between 136004** the right. Thus entry 1 contains the join operator for the join between
134666** entries 0 and 1. Any ON or USING clauses associated with the join are 136005** entries 0 and 1. Any ON or USING clauses associated with the join are
134667** also attached to the left entry. 136006** also attached to the right entry.
134668** 136007**
134669** This routine returns the number of errors encountered. 136008** This routine returns the number of errors encountered.
134670*/ 136009*/
134671static int sqliteProcessJoin(Parse *pParse, Select *p){ 136010static int sqlite3ProcessJoin(Parse *pParse, Select *p){
134672 SrcList *pSrc; /* All tables in the FROM clause */ 136011 SrcList *pSrc; /* All tables in the FROM clause */
134673 int i, j; /* Loop counters */ 136012 int i, j; /* Loop counters */
134674 SrcItem *pLeft; /* Left table being joined */ 136013 SrcItem *pLeft; /* Left table being joined */
@@ -134679,49 +136018,41 @@ static int sqliteProcessJoin(Parse *pParse, Select *p){
134679 pRight = &pLeft[1]; 136018 pRight = &pLeft[1];
134680 for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){ 136019 for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
134681 Table *pRightTab = pRight->pTab; 136020 Table *pRightTab = pRight->pTab;
134682 int isOuter; 136021 u32 joinType;
134683 136022
134684 if( NEVER(pLeft->pTab==0 || pRightTab==0) ) continue; 136023 if( NEVER(pLeft->pTab==0 || pRightTab==0) ) continue;
134685 isOuter = (pRight->fg.jointype & JT_OUTER)!=0; 136024 joinType = (pRight->fg.jointype & JT_OUTER)!=0 ? EP_OuterON : EP_InnerON;
134686 136025
134687 /* When the NATURAL keyword is present, add WHERE clause terms for 136026 /* If this is a NATURAL join, synthesize an approprate USING clause
134688 ** every column that the two tables have in common. 136027 ** to specify which columns should be joined.
134689 */ 136028 */
134690 if( pRight->fg.jointype & JT_NATURAL ){ 136029 if( pRight->fg.jointype & JT_NATURAL ){
134691 if( pRight->pOn || pRight->pUsing ){ 136030 IdList *pUsing = 0;
136031 if( pRight->fg.isUsing || pRight->u3.pOn ){
134692 sqlite3ErrorMsg(pParse, "a NATURAL join may not have " 136032 sqlite3ErrorMsg(pParse, "a NATURAL join may not have "
134693 "an ON or USING clause", 0); 136033 "an ON or USING clause", 0);
134694 return 1; 136034 return 1;
134695 } 136035 }
134696 for(j=0; j<pRightTab->nCol; j++){ 136036 for(j=0; j<pRightTab->nCol; j++){
134697 char *zName; /* Name of column in the right table */ 136037 char *zName; /* Name of column in the right table */
134698 int iLeft; /* Matching left table */
134699 int iLeftCol; /* Matching column in the left table */
134700 136038
134701 if( IsHiddenColumn(&pRightTab->aCol[j]) ) continue; 136039 if( IsHiddenColumn(&pRightTab->aCol[j]) ) continue;
134702 zName = pRightTab->aCol[j].zCnName; 136040 zName = pRightTab->aCol[j].zCnName;
134703 if( tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol, 1) ){ 136041 if( tableAndColumnIndex(pSrc, 0, i, zName, 0, 0, 1) ){
134704 addWhereTerm(pParse, pSrc, iLeft, iLeftCol, i+1, j, 136042 pUsing = sqlite3IdListAppend(pParse, pUsing, 0);
134705 isOuter, &p->pWhere); 136043 if( pUsing ){
136044 assert( pUsing->nId>0 );
136045 assert( pUsing->a[pUsing->nId-1].zName==0 );
136046 pUsing->a[pUsing->nId-1].zName = sqlite3DbStrDup(pParse->db, zName);
136047 }
134706 } 136048 }
134707 } 136049 }
134708 } 136050 if( pUsing ){
134709 136051 pRight->fg.isUsing = 1;
134710 /* Disallow both ON and USING clauses in the same join 136052 pRight->fg.isSynthUsing = 1;
134711 */ 136053 pRight->u3.pUsing = pUsing;
134712 if( pRight->pOn && pRight->pUsing ){ 136054 }
134713 sqlite3ErrorMsg(pParse, "cannot have both ON and USING " 136055 if( pParse->nErr ) return 1;
134714 "clauses in the same join");
134715 return 1;
134716 }
134717
134718 /* Add the ON clause to the end of the WHERE clause, connected by
134719 ** an AND operator.
134720 */
134721 if( pRight->pOn ){
134722 if( isOuter ) sqlite3SetJoinExpr(pRight->pOn, pRight->iCursor);
134723 p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->pOn);
134724 pRight->pOn = 0;
134725 } 136056 }
134726 136057
134727 /* Create extra terms on the WHERE clause for each column named 136058 /* Create extra terms on the WHERE clause for each column named
@@ -134731,27 +136062,88 @@ static int sqliteProcessJoin(Parse *pParse, Select *p){
134731 ** Report an error if any column mentioned in the USING clause is 136062 ** Report an error if any column mentioned in the USING clause is
134732 ** not contained in both tables to be joined. 136063 ** not contained in both tables to be joined.
134733 */ 136064 */
134734 if( pRight->pUsing ){ 136065 if( pRight->fg.isUsing ){
134735 IdList *pList = pRight->pUsing; 136066 IdList *pList = pRight->u3.pUsing;
136067 sqlite3 *db = pParse->db;
136068 assert( pList!=0 );
134736 for(j=0; j<pList->nId; j++){ 136069 for(j=0; j<pList->nId; j++){
134737 char *zName; /* Name of the term in the USING clause */ 136070 char *zName; /* Name of the term in the USING clause */
134738 int iLeft; /* Table on the left with matching column name */ 136071 int iLeft; /* Table on the left with matching column name */
134739 int iLeftCol; /* Column number of matching column on the left */ 136072 int iLeftCol; /* Column number of matching column on the left */
134740 int iRightCol; /* Column number of matching column on the right */ 136073 int iRightCol; /* Column number of matching column on the right */
136074 Expr *pE1; /* Reference to the column on the LEFT of the join */
136075 Expr *pE2; /* Reference to the column on the RIGHT of the join */
136076 Expr *pEq; /* Equality constraint. pE1 == pE2 */
134741 136077
134742 zName = pList->a[j].zName; 136078 zName = pList->a[j].zName;
134743 iRightCol = sqlite3ColumnIndex(pRightTab, zName); 136079 iRightCol = sqlite3ColumnIndex(pRightTab, zName);
134744 if( iRightCol<0 136080 if( iRightCol<0
134745 || !tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol, 0) 136081 || tableAndColumnIndex(pSrc, 0, i, zName, &iLeft, &iLeftCol,
136082 pRight->fg.isSynthUsing)==0
134746 ){ 136083 ){
134747 sqlite3ErrorMsg(pParse, "cannot join using column %s - column " 136084 sqlite3ErrorMsg(pParse, "cannot join using column %s - column "
134748 "not present in both tables", zName); 136085 "not present in both tables", zName);
134749 return 1; 136086 return 1;
134750 } 136087 }
134751 addWhereTerm(pParse, pSrc, iLeft, iLeftCol, i+1, iRightCol, 136088 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iLeftCol);
134752 isOuter, &p->pWhere); 136089 sqlite3SrcItemColumnUsed(&pSrc->a[iLeft], iLeftCol);
136090 if( (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
136091 /* This branch runs if the query contains one or more RIGHT or FULL
136092 ** JOINs. If only a single table on the left side of this join
136093 ** contains the zName column, then this branch is a no-op.
136094 ** But if there are two or more tables on the left side
136095 ** of the join, construct a coalesce() function that gathers all
136096 ** such tables. Raise an error if more than one of those references
136097 ** to zName is not also within a prior USING clause.
136098 **
136099 ** We really ought to raise an error if there are two or more
136100 ** non-USING references to zName on the left of an INNER or LEFT
136101 ** JOIN. But older versions of SQLite do not do that, so we avoid
136102 ** adding a new error so as to not break legacy applications.
136103 */
136104 ExprList *pFuncArgs = 0; /* Arguments to the coalesce() */
136105 static const Token tkCoalesce = { "coalesce", 8 };
136106 while( tableAndColumnIndex(pSrc, iLeft+1, i, zName, &iLeft, &iLeftCol,
136107 pRight->fg.isSynthUsing)!=0 ){
136108 if( pSrc->a[iLeft].fg.isUsing==0
136109 || sqlite3IdListIndex(pSrc->a[iLeft].u3.pUsing, zName)<0
136110 ){
136111 sqlite3ErrorMsg(pParse, "ambiguous reference to %s in USING()",
136112 zName);
136113 break;
136114 }
136115 pFuncArgs = sqlite3ExprListAppend(pParse, pFuncArgs, pE1);
136116 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iLeftCol);
136117 sqlite3SrcItemColumnUsed(&pSrc->a[iLeft], iLeftCol);
136118 }
136119 if( pFuncArgs ){
136120 pFuncArgs = sqlite3ExprListAppend(pParse, pFuncArgs, pE1);
136121 pE1 = sqlite3ExprFunction(pParse, pFuncArgs, &tkCoalesce, 0);
136122 }
136123 }
136124 pE2 = sqlite3CreateColumnExpr(db, pSrc, i+1, iRightCol);
136125 sqlite3SrcItemColumnUsed(pRight, iRightCol);
136126 pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2);
136127 assert( pE2!=0 || pEq==0 );
136128 if( pEq ){
136129 ExprSetProperty(pEq, joinType);
136130 assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
136131 ExprSetVVAProperty(pEq, EP_NoReduce);
136132 pEq->w.iJoin = pE2->iTable;
136133 }
136134 p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pEq);
134753 } 136135 }
134754 } 136136 }
136137
136138 /* Add the ON clause to the end of the WHERE clause, connected by
136139 ** an AND operator.
136140 */
136141 else if( pRight->u3.pOn ){
136142 sqlite3SetJoinExpr(pRight->u3.pOn, pRight->iCursor, joinType);
136143 p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->u3.pOn);
136144 pRight->u3.pOn = 0;
136145 pRight->fg.isOn = 1;
136146 }
134755 } 136147 }
134756 return 0; 136148 return 0;
134757} 136149}
@@ -135140,7 +136532,7 @@ static void fixDistinctOpenEph(
135140** retrieved directly from table t1. If the values are very large, this 136532** retrieved directly from table t1. If the values are very large, this
135141** can be more efficient than storing them directly in the sorter records. 136533** can be more efficient than storing them directly in the sorter records.
135142** 136534**
135143** The ExprList_item.bSorterRef flag is set for each expression in pEList 136535** The ExprList_item.fg.bSorterRef flag is set for each expression in pEList
135144** for which the sorter-reference optimization should be enabled. 136536** for which the sorter-reference optimization should be enabled.
135145** Additionally, the pSort->aDefer[] array is populated with entries 136537** Additionally, the pSort->aDefer[] array is populated with entries
135146** for all cursors required to evaluate all selected expressions. Finally. 136538** for all cursors required to evaluate all selected expressions. Finally.
@@ -135200,7 +136592,7 @@ static void selectExprDefer(
135200 nDefer++; 136592 nDefer++;
135201 } 136593 }
135202 } 136594 }
135203 pItem->bSorterRef = 1; 136595 pItem->fg.bSorterRef = 1;
135204 } 136596 }
135205 } 136597 }
135206 } 136598 }
@@ -135331,7 +136723,7 @@ static void selectInnerLoop(
135331 for(i=0; i<pEList->nExpr; i++){ 136723 for(i=0; i<pEList->nExpr; i++){
135332 if( pEList->a[i].u.x.iOrderByCol>0 136724 if( pEList->a[i].u.x.iOrderByCol>0
135333#ifdef SQLITE_ENABLE_SORTER_REFERENCES 136725#ifdef SQLITE_ENABLE_SORTER_REFERENCES
135334 || pEList->a[i].bSorterRef 136726 || pEList->a[i].fg.bSorterRef
135335#endif 136727#endif
135336 ){ 136728 ){
135337 nResultCol--; 136729 nResultCol--;
@@ -135693,7 +137085,7 @@ SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoFromExprList(
135693 assert( sqlite3KeyInfoIsWriteable(pInfo) ); 137085 assert( sqlite3KeyInfoIsWriteable(pInfo) );
135694 for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){ 137086 for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
135695 pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr); 137087 pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr);
135696 pInfo->aSortFlags[i-iStart] = pItem->sortFlags; 137088 pInfo->aSortFlags[i-iStart] = pItem->fg.sortFlags;
135697 } 137089 }
135698 } 137090 }
135699 return pInfo; 137091 return pInfo;
@@ -135832,7 +137224,7 @@ static void generateSortTail(
135832 } 137224 }
135833 for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){ 137225 for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
135834#ifdef SQLITE_ENABLE_SORTER_REFERENCES 137226#ifdef SQLITE_ENABLE_SORTER_REFERENCES
135835 if( aOutEx[i].bSorterRef ) continue; 137227 if( aOutEx[i].fg.bSorterRef ) continue;
135836#endif 137228#endif
135837 if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++; 137229 if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
135838 } 137230 }
@@ -135869,7 +137261,7 @@ static void generateSortTail(
135869#endif 137261#endif
135870 for(i=nColumn-1; i>=0; i--){ 137262 for(i=nColumn-1; i>=0; i--){
135871#ifdef SQLITE_ENABLE_SORTER_REFERENCES 137263#ifdef SQLITE_ENABLE_SORTER_REFERENCES
135872 if( aOutEx[i].bSorterRef ){ 137264 if( aOutEx[i].fg.bSorterRef ){
135873 sqlite3ExprCode(pParse, aOutEx[i].pExpr, regRow+i); 137265 sqlite3ExprCode(pParse, aOutEx[i].pExpr, regRow+i);
135874 }else 137266 }else
135875#endif 137267#endif
@@ -136235,7 +137627,7 @@ SQLITE_PRIVATE void sqlite3GenerateColumnNames(
136235 assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */ 137627 assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
136236 assert( p->op!=TK_COLUMN 137628 assert( p->op!=TK_COLUMN
136237 || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */ 137629 || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
136238 if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){ 137630 if( pEList->a[i].zEName && pEList->a[i].fg.eEName==ENAME_NAME ){
136239 /* An AS clause always takes first priority */ 137631 /* An AS clause always takes first priority */
136240 char *zName = pEList->a[i].zEName; 137632 char *zName = pEList->a[i].zEName;
136241 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT); 137633 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
@@ -136320,22 +137712,25 @@ SQLITE_PRIVATE int sqlite3ColumnsFromExprList(
136320 *paCol = aCol; 137712 *paCol = aCol;
136321 137713
136322 for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){ 137714 for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
137715 struct ExprList_item *pX = &pEList->a[i];
137716 struct ExprList_item *pCollide;
136323 /* Get an appropriate name for the column 137717 /* Get an appropriate name for the column
136324 */ 137718 */
136325 if( (zName = pEList->a[i].zEName)!=0 && pEList->a[i].eEName==ENAME_NAME ){ 137719 if( (zName = pX->zEName)!=0 && pX->fg.eEName==ENAME_NAME ){
136326 /* If the column contains an "AS <name>" phrase, use <name> as the name */ 137720 /* If the column contains an "AS <name>" phrase, use <name> as the name */
136327 }else{ 137721 }else{
136328 Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr); 137722 Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pX->pExpr);
136329 while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){ 137723 while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
136330 pColExpr = pColExpr->pRight; 137724 pColExpr = pColExpr->pRight;
136331 assert( pColExpr!=0 ); 137725 assert( pColExpr!=0 );
136332 } 137726 }
136333 if( pColExpr->op==TK_COLUMN 137727 if( pColExpr->op==TK_COLUMN
136334 && ALWAYS( ExprUseYTab(pColExpr) ) 137728 && ALWAYS( ExprUseYTab(pColExpr) )
136335 && (pTab = pColExpr->y.pTab)!=0 137729 && ALWAYS( pColExpr->y.pTab!=0 )
136336 ){ 137730 ){
136337 /* For columns use the column name name */ 137731 /* For columns use the column name name */
136338 int iCol = pColExpr->iColumn; 137732 int iCol = pColExpr->iColumn;
137733 pTab = pColExpr->y.pTab;
136339 if( iCol<0 ) iCol = pTab->iPKey; 137734 if( iCol<0 ) iCol = pTab->iPKey;
136340 zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid"; 137735 zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid";
136341 }else if( pColExpr->op==TK_ID ){ 137736 }else if( pColExpr->op==TK_ID ){
@@ -136343,7 +137738,7 @@ SQLITE_PRIVATE int sqlite3ColumnsFromExprList(
136343 zName = pColExpr->u.zToken; 137738 zName = pColExpr->u.zToken;
136344 }else{ 137739 }else{
136345 /* Use the original text of the column expression as its name */ 137740 /* Use the original text of the column expression as its name */
136346 zName = pEList->a[i].zEName; 137741 assert( zName==pX->zEName ); /* pointer comparison intended */
136347 } 137742 }
136348 } 137743 }
136349 if( zName && !sqlite3IsTrueOrFalse(zName) ){ 137744 if( zName && !sqlite3IsTrueOrFalse(zName) ){
@@ -136356,7 +137751,10 @@ SQLITE_PRIVATE int sqlite3ColumnsFromExprList(
136356 ** append an integer to the name so that it becomes unique. 137751 ** append an integer to the name so that it becomes unique.
136357 */ 137752 */
136358 cnt = 0; 137753 cnt = 0;
136359 while( zName && sqlite3HashFind(&ht, zName)!=0 ){ 137754 while( zName && (pCollide = sqlite3HashFind(&ht, zName))!=0 ){
137755 if( pCollide->fg.bUsingTerm ){
137756 pCol->colFlags |= COLFLAG_NOEXPAND;
137757 }
136360 nName = sqlite3Strlen30(zName); 137758 nName = sqlite3Strlen30(zName);
136361 if( nName>0 ){ 137759 if( nName>0 ){
136362 for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){} 137760 for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
@@ -136367,8 +137765,11 @@ SQLITE_PRIVATE int sqlite3ColumnsFromExprList(
136367 } 137765 }
136368 pCol->zCnName = zName; 137766 pCol->zCnName = zName;
136369 pCol->hName = sqlite3StrIHash(zName); 137767 pCol->hName = sqlite3StrIHash(zName);
137768 if( pX->fg.bNoExpand ){
137769 pCol->colFlags |= COLFLAG_NOEXPAND;
137770 }
136370 sqlite3ColumnPropertiesFromName(0, pCol); 137771 sqlite3ColumnPropertiesFromName(0, pCol);
136371 if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){ 137772 if( zName && sqlite3HashInsert(&ht, zName, pX)==pX ){
136372 sqlite3OomFault(db); 137773 sqlite3OomFault(db);
136373 } 137774 }
136374 } 137775 }
@@ -136625,7 +138026,7 @@ static KeyInfo *multiSelectOrderByKeyInfo(Parse *pParse, Select *p, int nExtra){
136625 } 138026 }
136626 assert( sqlite3KeyInfoIsWriteable(pRet) ); 138027 assert( sqlite3KeyInfoIsWriteable(pRet) );
136627 pRet->aColl[i] = pColl; 138028 pRet->aColl[i] = pColl;
136628 pRet->aSortFlags[i] = pOrderBy->a[i].sortFlags; 138029 pRet->aSortFlags[i] = pOrderBy->a[i].fg.sortFlags;
136629 } 138030 }
136630 } 138031 }
136631 138032
@@ -136843,7 +138244,7 @@ static int multiSelectOrderBy(
136843** The "LIMIT of exactly 1" case of condition (1) comes about when a VALUES 138244** The "LIMIT of exactly 1" case of condition (1) comes about when a VALUES
136844** clause occurs within scalar expression (ex: "SELECT (VALUES(1),(2),(3))"). 138245** clause occurs within scalar expression (ex: "SELECT (VALUES(1),(2),(3))").
136845** The sqlite3CodeSubselect will have added the LIMIT 1 clause in tht case. 138246** The sqlite3CodeSubselect will have added the LIMIT 1 clause in tht case.
136846** Since the limit is exactly 1, we only need to evalutes the left-most VALUES. 138247** Since the limit is exactly 1, we only need to evaluate the left-most VALUES.
136847*/ 138248*/
136848static int multiSelectValues( 138249static int multiSelectValues(
136849 Parse *pParse, /* Parsing context */ 138250 Parse *pParse, /* Parsing context */
@@ -137836,12 +139237,40 @@ static int multiSelectOrderBy(
137836** 139237**
137837** All references to columns in table iTable are to be replaced by corresponding 139238** All references to columns in table iTable are to be replaced by corresponding
137838** expressions in pEList. 139239** expressions in pEList.
139240**
139241** ## About "isOuterJoin":
139242**
139243** The isOuterJoin column indicates that the replacement will occur into a
139244** position in the parent that NULL-able due to an OUTER JOIN. Either the
139245** target slot in the parent is the right operand of a LEFT JOIN, or one of
139246** the left operands of a RIGHT JOIN. In either case, we need to potentially
139247** bypass the substituted expression with OP_IfNullRow.
139248**
139249** Suppose the original expression integer constant. Even though the table
139250** has the nullRow flag set, because the expression is an integer constant,
139251** it will not be NULLed out. So instead, we insert an OP_IfNullRow opcode
139252** that checks to see if the nullRow flag is set on the table. If the nullRow
139253** flag is set, then the value in the register is set to NULL and the original
139254** expression is bypassed. If the nullRow flag is not set, then the original
139255** expression runs to populate the register.
139256**
139257** Example where this is needed:
139258**
139259** CREATE TABLE t1(a INTEGER PRIMARY KEY, b INT);
139260** CREATE TABLE t2(x INT UNIQUE);
139261**
139262** SELECT a,b,m,x FROM t1 LEFT JOIN (SELECT 59 AS m,x FROM t2) ON b=x;
139263**
139264** When the subquery on the right side of the LEFT JOIN is flattened, we
139265** have to add OP_IfNullRow in front of the OP_Integer that implements the
139266** "m" value of the subquery so that a NULL will be loaded instead of 59
139267** when processing a non-matched row of the left.
137839*/ 139268*/
137840typedef struct SubstContext { 139269typedef struct SubstContext {
137841 Parse *pParse; /* The parsing context */ 139270 Parse *pParse; /* The parsing context */
137842 int iTable; /* Replace references to this table */ 139271 int iTable; /* Replace references to this table */
137843 int iNewTable; /* New table number */ 139272 int iNewTable; /* New table number */
137844 int isLeftJoin; /* Add TK_IF_NULL_ROW opcodes on each replacement */ 139273 int isOuterJoin; /* Add TK_IF_NULL_ROW opcodes on each replacement */
137845 ExprList *pEList; /* Replacement expressions */ 139274 ExprList *pEList; /* Replacement expressions */
137846} SubstContext; 139275} SubstContext;
137847 139276
@@ -137867,10 +139296,11 @@ static Expr *substExpr(
137867 Expr *pExpr /* Expr in which substitution occurs */ 139296 Expr *pExpr /* Expr in which substitution occurs */
137868){ 139297){
137869 if( pExpr==0 ) return 0; 139298 if( pExpr==0 ) return 0;
137870 if( ExprHasProperty(pExpr, EP_FromJoin) 139299 if( ExprHasProperty(pExpr, EP_OuterON|EP_InnerON)
137871 && pExpr->w.iRightJoinTable==pSubst->iTable 139300 && pExpr->w.iJoin==pSubst->iTable
137872 ){ 139301 ){
137873 pExpr->w.iRightJoinTable = pSubst->iNewTable; 139302 testcase( ExprHasProperty(pExpr, EP_InnerON) );
139303 pExpr->w.iJoin = pSubst->iNewTable;
137874 } 139304 }
137875 if( pExpr->op==TK_COLUMN 139305 if( pExpr->op==TK_COLUMN
137876 && pExpr->iTable==pSubst->iTable 139306 && pExpr->iTable==pSubst->iTable
@@ -137891,7 +139321,7 @@ static Expr *substExpr(
137891 sqlite3VectorErrorMsg(pSubst->pParse, pCopy); 139321 sqlite3VectorErrorMsg(pSubst->pParse, pCopy);
137892 }else{ 139322 }else{
137893 sqlite3 *db = pSubst->pParse->db; 139323 sqlite3 *db = pSubst->pParse->db;
137894 if( pSubst->isLeftJoin && pCopy->op!=TK_COLUMN ){ 139324 if( pSubst->isOuterJoin && pCopy->op!=TK_COLUMN ){
137895 memset(&ifNullRow, 0, sizeof(ifNullRow)); 139325 memset(&ifNullRow, 0, sizeof(ifNullRow));
137896 ifNullRow.op = TK_IF_NULL_ROW; 139326 ifNullRow.op = TK_IF_NULL_ROW;
137897 ifNullRow.pLeft = pCopy; 139327 ifNullRow.pLeft = pCopy;
@@ -137905,14 +139335,20 @@ static Expr *substExpr(
137905 sqlite3ExprDelete(db, pNew); 139335 sqlite3ExprDelete(db, pNew);
137906 return pExpr; 139336 return pExpr;
137907 } 139337 }
137908 if( pSubst->isLeftJoin ){ 139338 if( pSubst->isOuterJoin ){
137909 ExprSetProperty(pNew, EP_CanBeNull); 139339 ExprSetProperty(pNew, EP_CanBeNull);
137910 } 139340 }
137911 if( ExprHasProperty(pExpr,EP_FromJoin) ){ 139341 if( ExprHasProperty(pExpr,EP_OuterON|EP_InnerON) ){
137912 sqlite3SetJoinExpr(pNew, pExpr->w.iRightJoinTable); 139342 sqlite3SetJoinExpr(pNew, pExpr->w.iJoin,
139343 pExpr->flags & (EP_OuterON|EP_InnerON));
137913 } 139344 }
137914 sqlite3ExprDelete(db, pExpr); 139345 sqlite3ExprDelete(db, pExpr);
137915 pExpr = pNew; 139346 pExpr = pNew;
139347 if( pExpr->op==TK_TRUEFALSE ){
139348 pExpr->u.iValue = sqlite3ExprTruthValue(pExpr);
139349 pExpr->op = TK_INTEGER;
139350 ExprSetProperty(pExpr, EP_IntValue);
139351 }
137916 139352
137917 /* Ensure that the expression now has an implicit collation sequence, 139353 /* Ensure that the expression now has an implicit collation sequence,
137918 ** just as it did when it was a column of a view or sub-query. */ 139354 ** just as it did when it was a column of a view or sub-query. */
@@ -138073,8 +139509,8 @@ static int renumberCursorsCb(Walker *pWalker, Expr *pExpr){
138073 if( op==TK_COLUMN || op==TK_IF_NULL_ROW ){ 139509 if( op==TK_COLUMN || op==TK_IF_NULL_ROW ){
138074 renumberCursorDoMapping(pWalker, &pExpr->iTable); 139510 renumberCursorDoMapping(pWalker, &pExpr->iTable);
138075 } 139511 }
138076 if( ExprHasProperty(pExpr, EP_FromJoin) ){ 139512 if( ExprHasProperty(pExpr, EP_OuterON) ){
138077 renumberCursorDoMapping(pWalker, &pExpr->w.iRightJoinTable); 139513 renumberCursorDoMapping(pWalker, &pExpr->w.iJoin);
138078 } 139514 }
138079 return WRC_Continue; 139515 return WRC_Continue;
138080} 139516}
@@ -138159,6 +139595,7 @@ static void renumberCursors(
138159** table and 139595** table and
138160** (3c) the outer query may not be an aggregate. 139596** (3c) the outer query may not be an aggregate.
138161** (3d) the outer query may not be DISTINCT. 139597** (3d) the outer query may not be DISTINCT.
139598** See also (26) for restrictions on RIGHT JOIN.
138162** 139599**
138163** (4) The subquery can not be DISTINCT. 139600** (4) The subquery can not be DISTINCT.
138164** 139601**
@@ -138210,6 +139647,9 @@ static void renumberCursors(
138210** (17d2) DISTINCT 139647** (17d2) DISTINCT
138211** (17e) the subquery may not contain window functions, and 139648** (17e) the subquery may not contain window functions, and
138212** (17f) the subquery must not be the RHS of a LEFT JOIN. 139649** (17f) the subquery must not be the RHS of a LEFT JOIN.
139650** (17g) either the subquery is the first element of the outer
139651** query or there are no RIGHT or FULL JOINs in any arm
139652** of the subquery. (This is a duplicate of condition (27b).)
138213** 139653**
138214** The parent and sub-query may contain WHERE clauses. Subject to 139654** The parent and sub-query may contain WHERE clauses. Subject to
138215** rules (11), (13) and (14), they may also contain ORDER BY, 139655** rules (11), (13) and (14), they may also contain ORDER BY,
@@ -138257,6 +139697,23 @@ static void renumberCursors(
138257** function in the select list or ORDER BY clause, flattening 139697** function in the select list or ORDER BY clause, flattening
138258** is not attempted. 139698** is not attempted.
138259** 139699**
139700** (26) The subquery may not be the right operand of a RIGHT JOIN.
139701** See also (3) for restrictions on LEFT JOIN.
139702**
139703** (27) The subquery may not contain a FULL or RIGHT JOIN unless it
139704** is the first element of the parent query. This must be the
139705** the case if:
139706** (27a) the subquery is not compound query, and
139707** (27b) the subquery is a compound query and the RIGHT JOIN occurs
139708** in any arm of the compound query. (See also (17g).)
139709**
139710** (28) The subquery is not a MATERIALIZED CTE.
139711**
139712** (29) Either the subquery is not the right-hand operand of a join with an
139713** ON or USING clause nor the right-hand operand of a NATURAL JOIN, or
139714** the right-most table within the FROM clause of the subquery
139715** is not part of an outer join.
139716**
138260** 139717**
138261** In this routine, the "p" parameter is a pointer to the outer query. 139718** In this routine, the "p" parameter is a pointer to the outer query.
138262** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query 139719** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
@@ -138282,7 +139739,7 @@ static int flattenSubquery(
138282 SrcList *pSubSrc; /* The FROM clause of the subquery */ 139739 SrcList *pSubSrc; /* The FROM clause of the subquery */
138283 int iParent; /* VDBE cursor number of the pSub result set temp table */ 139740 int iParent; /* VDBE cursor number of the pSub result set temp table */
138284 int iNewParent = -1;/* Replacement table for iParent */ 139741 int iNewParent = -1;/* Replacement table for iParent */
138285 int isLeftJoin = 0; /* True if pSub is the right side of a LEFT JOIN */ 139742 int isOuterJoin = 0; /* True if pSub is the right side of a LEFT JOIN */
138286 int i; /* Loop counter */ 139743 int i; /* Loop counter */
138287 Expr *pWhere; /* The WHERE clause */ 139744 Expr *pWhere; /* The WHERE clause */
138288 SrcItem *pSubitem; /* The subquery */ 139745 SrcItem *pSubitem; /* The subquery */
@@ -138355,26 +139812,64 @@ static int flattenSubquery(
138355 ** 139812 **
138356 ** See also tickets #306, #350, and #3300. 139813 ** See also tickets #306, #350, and #3300.
138357 */ 139814 */
138358 if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){ 139815 if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
138359 isLeftJoin = 1; 139816 if( pSubSrc->nSrc>1 /* (3a) */
138360 if( pSubSrc->nSrc>1 /* (3a) */ 139817 || isAgg /* (3c) */
138361 || isAgg /* (3b) */ 139818 || IsVirtual(pSubSrc->a[0].pTab) /* (3b) */
138362 || IsVirtual(pSubSrc->a[0].pTab) /* (3c) */ 139819 || (p->selFlags & SF_Distinct)!=0 /* (3d) */
138363 || (p->selFlags & SF_Distinct)!=0 /* (3d) */ 139820 || (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
138364 ){ 139821 ){
138365 return 0; 139822 return 0;
138366 } 139823 }
139824 isOuterJoin = 1;
138367 } 139825 }
138368#ifdef SQLITE_EXTRA_IFNULLROW 139826#ifdef SQLITE_EXTRA_IFNULLROW
138369 else if( iFrom>0 && !isAgg ){ 139827 else if( iFrom>0 && !isAgg ){
138370 /* Setting isLeftJoin to -1 causes OP_IfNullRow opcodes to be generated for 139828 /* Setting isOuterJoin to -1 causes OP_IfNullRow opcodes to be generated for
138371 ** every reference to any result column from subquery in a join, even 139829 ** every reference to any result column from subquery in a join, even
138372 ** though they are not necessary. This will stress-test the OP_IfNullRow 139830 ** though they are not necessary. This will stress-test the OP_IfNullRow
138373 ** opcode. */ 139831 ** opcode. */
138374 isLeftJoin = -1; 139832 isOuterJoin = -1;
138375 } 139833 }
138376#endif 139834#endif
138377 139835
139836 assert( pSubSrc->nSrc>0 ); /* True by restriction (7) */
139837 if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
139838 return 0; /* Restriction (27a) */
139839 }
139840 if( pSubitem->fg.isCte && pSubitem->u2.pCteUse->eM10d==M10d_Yes ){
139841 return 0; /* (28) */
139842 }
139843
139844 /* Restriction (29):
139845 **
139846 ** We do not want two constraints on the same term of the flattened
139847 ** query where one constraint has EP_InnerON and the other is EP_OuterON.
139848 ** To prevent this, one or the other of the following conditions must be
139849 ** false:
139850 **
139851 ** (29a) The right-most entry in the FROM clause of the subquery
139852 ** must not be part of an outer join.
139853 **
139854 ** (29b) The subquery itself must not be the right operand of a
139855 ** NATURAL join or a join that as an ON or USING clause.
139856 **
139857 ** These conditions are sufficient to keep an EP_OuterON from being
139858 ** flattened into an EP_InnerON. Restrictions (3a) and (27a) prevent
139859 ** an EP_InnerON from being flattened into an EP_OuterON.
139860 */
139861 if( pSubSrc->nSrc>=2
139862 && (pSubSrc->a[pSubSrc->nSrc-1].fg.jointype & JT_OUTER)!=0
139863 ){
139864 if( (pSubitem->fg.jointype & JT_NATURAL)!=0
139865 || pSubitem->fg.isUsing
139866 || NEVER(pSubitem->u3.pOn!=0) /* ON clause already shifted into WHERE */
139867 || pSubitem->fg.isOn
139868 ){
139869 return 0;
139870 }
139871 }
139872
138378 /* Restriction (17): If the sub-query is a compound SELECT, then it must 139873 /* Restriction (17): If the sub-query is a compound SELECT, then it must
138379 ** use only the UNION ALL operator. And none of the simple select queries 139874 ** use only the UNION ALL operator. And none of the simple select queries
138380 ** that make up the compound SELECT are allowed to be aggregate or distinct 139875 ** that make up the compound SELECT are allowed to be aggregate or distinct
@@ -138384,7 +139879,7 @@ static int flattenSubquery(
138384 if( pSub->pOrderBy ){ 139879 if( pSub->pOrderBy ){
138385 return 0; /* Restriction (20) */ 139880 return 0; /* Restriction (20) */
138386 } 139881 }
138387 if( isAgg || (p->selFlags & SF_Distinct)!=0 || isLeftJoin>0 ){ 139882 if( isAgg || (p->selFlags & SF_Distinct)!=0 || isOuterJoin>0 ){
138388 return 0; /* (17d1), (17d2), or (17f) */ 139883 return 0; /* (17d1), (17d2), or (17f) */
138389 } 139884 }
138390 for(pSub1=pSub; pSub1; pSub1=pSub1->pPrior){ 139885 for(pSub1=pSub; pSub1; pSub1=pSub1->pPrior){
@@ -138402,6 +139897,12 @@ static int flattenSubquery(
138402 ){ 139897 ){
138403 return 0; 139898 return 0;
138404 } 139899 }
139900 if( iFrom>0 && (pSub1->pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
139901 /* Without this restriction, the JT_LTORJ flag would end up being
139902 ** omitted on left-hand tables of the right join that is being
139903 ** flattened. */
139904 return 0; /* Restrictions (17g), (27b) */
139905 }
138405 testcase( pSub1->pSrc->nSrc>1 ); 139906 testcase( pSub1->pSrc->nSrc>1 );
138406 } 139907 }
138407 139908
@@ -138418,6 +139919,7 @@ static int flattenSubquery(
138418 139919
138419 if( pSrc->nSrc>1 ){ 139920 if( pSrc->nSrc>1 ){
138420 if( pParse->nSelect>500 ) return 0; 139921 if( pParse->nSelect>500 ) return 0;
139922 if( OptimizationDisabled(db, SQLITE_FlttnUnionAll) ) return 0;
138421 aCsrMap = sqlite3DbMallocZero(db, ((i64)pParse->nTab+1)*sizeof(int)); 139923 aCsrMap = sqlite3DbMallocZero(db, ((i64)pParse->nTab+1)*sizeof(int));
138422 if( aCsrMap ) aCsrMap[0] = pParse->nTab; 139924 if( aCsrMap ) aCsrMap[0] = pParse->nTab;
138423 } 139925 }
@@ -138442,7 +139944,7 @@ static int flattenSubquery(
138442 pSubitem->zName = 0; 139944 pSubitem->zName = 0;
138443 pSubitem->zAlias = 0; 139945 pSubitem->zAlias = 0;
138444 pSubitem->pSelect = 0; 139946 pSubitem->pSelect = 0;
138445 assert( pSubitem->pOn==0 ); 139947 assert( pSubitem->fg.isUsing!=0 || pSubitem->u3.pOn==0 );
138446 139948
138447 /* If the sub-query is a compound SELECT statement, then (by restrictions 139949 /* If the sub-query is a compound SELECT statement, then (by restrictions
138448 ** 17 and 18 above) it must be a UNION ALL and the parent query must 139950 ** 17 and 18 above) it must be a UNION ALL and the parent query must
@@ -138552,6 +140054,7 @@ static int flattenSubquery(
138552 for(pParent=p; pParent; pParent=pParent->pPrior, pSub=pSub->pPrior){ 140054 for(pParent=p; pParent; pParent=pParent->pPrior, pSub=pSub->pPrior){
138553 int nSubSrc; 140055 int nSubSrc;
138554 u8 jointype = 0; 140056 u8 jointype = 0;
140057 u8 ltorj = pSrc->a[iFrom].fg.jointype & JT_LTORJ;
138555 assert( pSub!=0 ); 140058 assert( pSub!=0 );
138556 pSubSrc = pSub->pSrc; /* FROM clause of subquery */ 140059 pSubSrc = pSub->pSrc; /* FROM clause of subquery */
138557 nSubSrc = pSubSrc->nSrc; /* Number of terms in subquery FROM clause */ 140060 nSubSrc = pSubSrc->nSrc; /* Number of terms in subquery FROM clause */
@@ -138586,13 +140089,16 @@ static int flattenSubquery(
138586 ** outer query. 140089 ** outer query.
138587 */ 140090 */
138588 for(i=0; i<nSubSrc; i++){ 140091 for(i=0; i<nSubSrc; i++){
138589 sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing); 140092 SrcItem *pItem = &pSrc->a[i+iFrom];
138590 assert( pSrc->a[i+iFrom].fg.isTabFunc==0 ); 140093 if( pItem->fg.isUsing ) sqlite3IdListDelete(db, pItem->u3.pUsing);
138591 pSrc->a[i+iFrom] = pSubSrc->a[i]; 140094 assert( pItem->fg.isTabFunc==0 );
140095 *pItem = pSubSrc->a[i];
140096 pItem->fg.jointype |= ltorj;
138592 iNewParent = pSubSrc->a[i].iCursor; 140097 iNewParent = pSubSrc->a[i].iCursor;
138593 memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i])); 140098 memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
138594 } 140099 }
138595 pSrc->a[iFrom].fg.jointype = jointype; 140100 pSrc->a[iFrom].fg.jointype &= JT_LTORJ;
140101 pSrc->a[iFrom].fg.jointype |= jointype | ltorj;
138596 140102
138597 /* Now begin substituting subquery result set expressions for 140103 /* Now begin substituting subquery result set expressions for
138598 ** references to the iParent in the outer query. 140104 ** references to the iParent in the outer query.
@@ -138627,8 +140133,8 @@ static int flattenSubquery(
138627 } 140133 }
138628 pWhere = pSub->pWhere; 140134 pWhere = pSub->pWhere;
138629 pSub->pWhere = 0; 140135 pSub->pWhere = 0;
138630 if( isLeftJoin>0 ){ 140136 if( isOuterJoin>0 ){
138631 sqlite3SetJoinExpr(pWhere, iNewParent); 140137 sqlite3SetJoinExpr(pWhere, iNewParent, EP_OuterON);
138632 } 140138 }
138633 if( pWhere ){ 140139 if( pWhere ){
138634 if( pParent->pWhere ){ 140140 if( pParent->pWhere ){
@@ -138642,7 +140148,7 @@ static int flattenSubquery(
138642 x.pParse = pParse; 140148 x.pParse = pParse;
138643 x.iTable = iParent; 140149 x.iTable = iParent;
138644 x.iNewTable = iNewParent; 140150 x.iNewTable = iNewParent;
138645 x.isLeftJoin = isLeftJoin; 140151 x.isOuterJoin = isOuterJoin;
138646 x.pEList = pSub->pEList; 140152 x.pEList = pSub->pEList;
138647 substSelect(&x, pParent, 0); 140153 substSelect(&x, pParent, 0);
138648 } 140154 }
@@ -138677,8 +140183,8 @@ static int flattenSubquery(
138677 sqlite3WalkSelect(&w,pSub1); 140183 sqlite3WalkSelect(&w,pSub1);
138678 sqlite3SelectDelete(db, pSub1); 140184 sqlite3SelectDelete(db, pSub1);
138679 140185
138680#if SELECTTRACE_ENABLED 140186#if TREETRACE_ENABLED
138681 if( sqlite3SelectTrace & 0x100 ){ 140187 if( sqlite3TreeTrace & 0x100 ){
138682 SELECTTRACE(0x100,pParse,p,("After flattening:\n")); 140188 SELECTTRACE(0x100,pParse,p,("After flattening:\n"));
138683 sqlite3TreeViewSelect(0, p, 0); 140189 sqlite3TreeViewSelect(0, p, 0);
138684 } 140190 }
@@ -138699,6 +140205,8 @@ struct WhereConst {
138699 int nConst; /* Number for COLUMN=CONSTANT terms */ 140205 int nConst; /* Number for COLUMN=CONSTANT terms */
138700 int nChng; /* Number of times a constant is propagated */ 140206 int nChng; /* Number of times a constant is propagated */
138701 int bHasAffBlob; /* At least one column in apExpr[] as affinity BLOB */ 140207 int bHasAffBlob; /* At least one column in apExpr[] as affinity BLOB */
140208 u32 mExcludeOn; /* Which ON expressions to exclude from considertion.
140209 ** Either EP_OuterON or EP_InnerON|EP_OuterON */
138702 Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */ 140210 Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */
138703}; 140211};
138704 140212
@@ -138761,7 +140269,11 @@ static void constInsert(
138761static void findConstInWhere(WhereConst *pConst, Expr *pExpr){ 140269static void findConstInWhere(WhereConst *pConst, Expr *pExpr){
138762 Expr *pRight, *pLeft; 140270 Expr *pRight, *pLeft;
138763 if( NEVER(pExpr==0) ) return; 140271 if( NEVER(pExpr==0) ) return;
138764 if( ExprHasProperty(pExpr, EP_FromJoin) ) return; 140272 if( ExprHasProperty(pExpr, pConst->mExcludeOn) ){
140273 testcase( ExprHasProperty(pExpr, EP_OuterON) );
140274 testcase( ExprHasProperty(pExpr, EP_InnerON) );
140275 return;
140276 }
138765 if( pExpr->op==TK_AND ){ 140277 if( pExpr->op==TK_AND ){
138766 findConstInWhere(pConst, pExpr->pRight); 140278 findConstInWhere(pConst, pExpr->pRight);
138767 findConstInWhere(pConst, pExpr->pLeft); 140279 findConstInWhere(pConst, pExpr->pLeft);
@@ -138797,9 +140309,10 @@ static int propagateConstantExprRewriteOne(
138797 int i; 140309 int i;
138798 if( pConst->pOomFault[0] ) return WRC_Prune; 140310 if( pConst->pOomFault[0] ) return WRC_Prune;
138799 if( pExpr->op!=TK_COLUMN ) return WRC_Continue; 140311 if( pExpr->op!=TK_COLUMN ) return WRC_Continue;
138800 if( ExprHasProperty(pExpr, EP_FixedCol|EP_FromJoin) ){ 140312 if( ExprHasProperty(pExpr, EP_FixedCol|pConst->mExcludeOn) ){
138801 testcase( ExprHasProperty(pExpr, EP_FixedCol) ); 140313 testcase( ExprHasProperty(pExpr, EP_FixedCol) );
138802 testcase( ExprHasProperty(pExpr, EP_FromJoin) ); 140314 testcase( ExprHasProperty(pExpr, EP_OuterON) );
140315 testcase( ExprHasProperty(pExpr, EP_InnerON) );
138803 return WRC_Continue; 140316 return WRC_Continue;
138804 } 140317 }
138805 for(i=0; i<pConst->nConst; i++){ 140318 for(i=0; i<pConst->nConst; i++){
@@ -138923,6 +140436,17 @@ static int propagateConstants(
138923 x.nChng = 0; 140436 x.nChng = 0;
138924 x.apExpr = 0; 140437 x.apExpr = 0;
138925 x.bHasAffBlob = 0; 140438 x.bHasAffBlob = 0;
140439 if( ALWAYS(p->pSrc!=0)
140440 && p->pSrc->nSrc>0
140441 && (p->pSrc->a[0].fg.jointype & JT_LTORJ)!=0
140442 ){
140443 /* Do not propagate constants on any ON clause if there is a
140444 ** RIGHT JOIN anywhere in the query */
140445 x.mExcludeOn = EP_InnerON | EP_OuterON;
140446 }else{
140447 /* Do not propagate constants through the ON clause of a LEFT JOIN */
140448 x.mExcludeOn = EP_OuterON;
140449 }
138926 findConstInWhere(&x, p->pWhere); 140450 findConstInWhere(&x, p->pWhere);
138927 if( x.nConst ){ 140451 if( x.nConst ){
138928 memset(&w, 0, sizeof(w)); 140452 memset(&w, 0, sizeof(w));
@@ -139042,13 +140566,13 @@ static int pushDownWhereTerms(
139042 Parse *pParse, /* Parse context (for malloc() and error reporting) */ 140566 Parse *pParse, /* Parse context (for malloc() and error reporting) */
139043 Select *pSubq, /* The subquery whose WHERE clause is to be augmented */ 140567 Select *pSubq, /* The subquery whose WHERE clause is to be augmented */
139044 Expr *pWhere, /* The WHERE clause of the outer query */ 140568 Expr *pWhere, /* The WHERE clause of the outer query */
139045 int iCursor, /* Cursor number of the subquery */ 140569 SrcItem *pSrc /* The subquery term of the outer FROM clause */
139046 int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */
139047){ 140570){
139048 Expr *pNew; 140571 Expr *pNew;
139049 int nChng = 0; 140572 int nChng = 0;
139050 if( pWhere==0 ) return 0; 140573 if( pWhere==0 ) return 0;
139051 if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ) return 0; 140574 if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ) return 0;
140575 if( pSrc->fg.jointype & (JT_LTORJ|JT_RIGHT) ) return 0;
139052 140576
139053#ifndef SQLITE_OMIT_WINDOWFUNC 140577#ifndef SQLITE_OMIT_WINDOWFUNC
139054 if( pSubq->pPrior ){ 140578 if( pSubq->pPrior ){
@@ -139078,32 +140602,35 @@ static int pushDownWhereTerms(
139078 return 0; /* restriction (3) */ 140602 return 0; /* restriction (3) */
139079 } 140603 }
139080 while( pWhere->op==TK_AND ){ 140604 while( pWhere->op==TK_AND ){
139081 nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, 140605 nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, pSrc);
139082 iCursor, isLeftJoin);
139083 pWhere = pWhere->pLeft; 140606 pWhere = pWhere->pLeft;
139084 } 140607 }
140608
140609#if 0 /* Legacy code. Checks now done by sqlite3ExprIsTableConstraint() */
139085 if( isLeftJoin 140610 if( isLeftJoin
139086 && (ExprHasProperty(pWhere,EP_FromJoin)==0 140611 && (ExprHasProperty(pWhere,EP_OuterON)==0
139087 || pWhere->w.iRightJoinTable!=iCursor) 140612 || pWhere->w.iJoin!=iCursor)
139088 ){ 140613 ){
139089 return 0; /* restriction (4) */ 140614 return 0; /* restriction (4) */
139090 } 140615 }
139091 if( ExprHasProperty(pWhere,EP_FromJoin) 140616 if( ExprHasProperty(pWhere,EP_OuterON)
139092 && pWhere->w.iRightJoinTable!=iCursor 140617 && pWhere->w.iJoin!=iCursor
139093 ){ 140618 ){
139094 return 0; /* restriction (5) */ 140619 return 0; /* restriction (5) */
139095 } 140620 }
139096 if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){ 140621#endif
140622
140623 if( sqlite3ExprIsTableConstraint(pWhere, pSrc) ){
139097 nChng++; 140624 nChng++;
139098 pSubq->selFlags |= SF_PushDown; 140625 pSubq->selFlags |= SF_PushDown;
139099 while( pSubq ){ 140626 while( pSubq ){
139100 SubstContext x; 140627 SubstContext x;
139101 pNew = sqlite3ExprDup(pParse->db, pWhere, 0); 140628 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
139102 unsetJoinExpr(pNew, -1); 140629 unsetJoinExpr(pNew, -1, 1);
139103 x.pParse = pParse; 140630 x.pParse = pParse;
139104 x.iTable = iCursor; 140631 x.iTable = pSrc->iCursor;
139105 x.iNewTable = iCursor; 140632 x.iNewTable = pSrc->iCursor;
139106 x.isLeftJoin = 0; 140633 x.isOuterJoin = 0;
139107 x.pEList = pSubq->pEList; 140634 x.pEList = pSubq->pEList;
139108 pNew = substExpr(&x, pNew); 140635 pNew = substExpr(&x, pNew);
139109#ifndef SQLITE_OMIT_WINDOWFUNC 140636#ifndef SQLITE_OMIT_WINDOWFUNC
@@ -139176,7 +140703,7 @@ static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){
139176 } 140703 }
139177 *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0); 140704 *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
139178 assert( pOrderBy!=0 || db->mallocFailed ); 140705 assert( pOrderBy!=0 || db->mallocFailed );
139179 if( pOrderBy ) pOrderBy->a[0].sortFlags = sortFlags; 140706 if( pOrderBy ) pOrderBy->a[0].fg.sortFlags = sortFlags;
139180 return eRet; 140707 return eRet;
139181} 140708}
139182 140709
@@ -139312,7 +140839,7 @@ static int convertCompoundSelectToSubquery(Walker *pWalker, Select *p){
139312 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) ); 140839 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) );
139313 if( pNew==0 ) return WRC_Abort; 140840 if( pNew==0 ) return WRC_Abort;
139314 memset(&dummy, 0, sizeof(dummy)); 140841 memset(&dummy, 0, sizeof(dummy));
139315 pNewSrc = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&dummy,pNew,0,0); 140842 pNewSrc = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&dummy,pNew,0);
139316 if( pNewSrc==0 ) return WRC_Abort; 140843 if( pNewSrc==0 ) return WRC_Abort;
139317 *pNew = *p; 140844 *pNew = *p;
139318 p->pSrc = pNewSrc; 140845 p->pSrc = pNewSrc;
@@ -139645,7 +141172,7 @@ SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse *pParse, SrcItem *pFrom){
139645 if( pFrom->zAlias ){ 141172 if( pFrom->zAlias ){
139646 pTab->zName = sqlite3DbStrDup(pParse->db, pFrom->zAlias); 141173 pTab->zName = sqlite3DbStrDup(pParse->db, pFrom->zAlias);
139647 }else{ 141174 }else{
139648 pTab->zName = sqlite3MPrintf(pParse->db, "subquery_%u", pSel->selId); 141175 pTab->zName = sqlite3MPrintf(pParse->db, "%!S", pFrom);
139649 } 141176 }
139650 while( pSel->pPrior ){ pSel = pSel->pPrior; } 141177 while( pSel->pPrior ){ pSel = pSel->pPrior; }
139651 sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol); 141178 sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
@@ -139657,11 +141184,35 @@ SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse *pParse, SrcItem *pFrom){
139657#else 141184#else
139658 pTab->tabFlags |= TF_Ephemeral; /* Legacy compatibility mode */ 141185 pTab->tabFlags |= TF_Ephemeral; /* Legacy compatibility mode */
139659#endif 141186#endif
141187 return pParse->nErr ? SQLITE_ERROR : SQLITE_OK;
141188}
139660 141189
139661 141190
139662 return pParse->nErr ? SQLITE_ERROR : SQLITE_OK; 141191/*
141192** Check the N SrcItem objects to the right of pBase. (N might be zero!)
141193** If any of those SrcItem objects have a USING clause containing zName
141194** then return true.
141195**
141196** If N is zero, or none of the N SrcItem objects to the right of pBase
141197** contains a USING clause, or if none of the USING clauses contain zName,
141198** then return false.
141199*/
141200static int inAnyUsingClause(
141201 const char *zName, /* Name we are looking for */
141202 SrcItem *pBase, /* The base SrcItem. Looking at pBase[1] and following */
141203 int N /* How many SrcItems to check */
141204){
141205 while( N>0 ){
141206 N--;
141207 pBase++;
141208 if( pBase->fg.isUsing==0 ) continue;
141209 if( NEVER(pBase->u3.pUsing==0) ) continue;
141210 if( sqlite3IdListIndex(pBase->u3.pUsing, zName)>=0 ) return 1;
141211 }
141212 return 0;
139663} 141213}
139664 141214
141215
139665/* 141216/*
139666** This routine is a Walker callback for "expanding" a SELECT statement. 141217** This routine is a Walker callback for "expanding" a SELECT statement.
139667** "Expanding" means to do the following: 141218** "Expanding" means to do the following:
@@ -139811,7 +141362,7 @@ static int selectExpander(Walker *pWalker, Select *p){
139811 /* Process NATURAL keywords, and ON and USING clauses of joins. 141362 /* Process NATURAL keywords, and ON and USING clauses of joins.
139812 */ 141363 */
139813 assert( db->mallocFailed==0 || pParse->nErr!=0 ); 141364 assert( db->mallocFailed==0 || pParse->nErr!=0 );
139814 if( pParse->nErr || sqliteProcessJoin(pParse, p) ){ 141365 if( pParse->nErr || sqlite3ProcessJoin(pParse, p) ){
139815 return WRC_Abort; 141366 return WRC_Abort;
139816 } 141367 }
139817 141368
@@ -139859,7 +141410,7 @@ static int selectExpander(Walker *pWalker, Select *p){
139859 pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr); 141410 pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
139860 if( pNew ){ 141411 if( pNew ){
139861 pNew->a[pNew->nExpr-1].zEName = a[k].zEName; 141412 pNew->a[pNew->nExpr-1].zEName = a[k].zEName;
139862 pNew->a[pNew->nExpr-1].eEName = a[k].eEName; 141413 pNew->a[pNew->nExpr-1].fg.eEName = a[k].fg.eEName;
139863 a[k].zEName = 0; 141414 a[k].zEName = 0;
139864 } 141415 }
139865 a[k].pExpr = 0; 141416 a[k].pExpr = 0;
@@ -139874,32 +141425,60 @@ static int selectExpander(Walker *pWalker, Select *p){
139874 zTName = pE->pLeft->u.zToken; 141425 zTName = pE->pLeft->u.zToken;
139875 } 141426 }
139876 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){ 141427 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
139877 Table *pTab = pFrom->pTab; 141428 Table *pTab = pFrom->pTab; /* Table for this data source */
139878 Select *pSub = pFrom->pSelect; 141429 ExprList *pNestedFrom; /* Result-set of a nested FROM clause */
139879 char *zTabName = pFrom->zAlias; 141430 char *zTabName; /* AS name for this data source */
139880 const char *zSchemaName = 0; 141431 const char *zSchemaName = 0; /* Schema name for this data source */
139881 int iDb; 141432 int iDb; /* Schema index for this data src */
139882 if( zTabName==0 ){ 141433 IdList *pUsing; /* USING clause for pFrom[1] */
141434
141435 if( (zTabName = pFrom->zAlias)==0 ){
139883 zTabName = pTab->zName; 141436 zTabName = pTab->zName;
139884 } 141437 }
139885 if( db->mallocFailed ) break; 141438 if( db->mallocFailed ) break;
139886 if( pSub==0 || (pSub->selFlags & SF_NestedFrom)==0 ){ 141439 assert( (int)pFrom->fg.isNestedFrom == IsNestedFrom(pFrom->pSelect) );
139887 pSub = 0; 141440 if( pFrom->fg.isNestedFrom ){
141441 assert( pFrom->pSelect!=0 );
141442 pNestedFrom = pFrom->pSelect->pEList;
141443 assert( pNestedFrom!=0 );
141444 assert( pNestedFrom->nExpr==pTab->nCol );
141445 }else{
139888 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){ 141446 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
139889 continue; 141447 continue;
139890 } 141448 }
141449 pNestedFrom = 0;
139891 iDb = sqlite3SchemaToIndex(db, pTab->pSchema); 141450 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
139892 zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*"; 141451 zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
139893 } 141452 }
141453 if( i+1<pTabList->nSrc
141454 && pFrom[1].fg.isUsing
141455 && (selFlags & SF_NestedFrom)!=0
141456 ){
141457 int ii;
141458 pUsing = pFrom[1].u3.pUsing;
141459 for(ii=0; ii<pUsing->nId; ii++){
141460 const char *zUName = pUsing->a[ii].zName;
141461 pRight = sqlite3Expr(db, TK_ID, zUName);
141462 pNew = sqlite3ExprListAppend(pParse, pNew, pRight);
141463 if( pNew ){
141464 struct ExprList_item *pX = &pNew->a[pNew->nExpr-1];
141465 assert( pX->zEName==0 );
141466 pX->zEName = sqlite3MPrintf(db,"..%s", zUName);
141467 pX->fg.eEName = ENAME_TAB;
141468 pX->fg.bUsingTerm = 1;
141469 }
141470 }
141471 }else{
141472 pUsing = 0;
141473 }
139894 for(j=0; j<pTab->nCol; j++){ 141474 for(j=0; j<pTab->nCol; j++){
139895 char *zName = pTab->aCol[j].zCnName; 141475 char *zName = pTab->aCol[j].zCnName;
139896 char *zColname; /* The computed column name */ 141476 struct ExprList_item *pX; /* Newly added ExprList term */
139897 char *zToFree; /* Malloced string that needs to be freed */
139898 Token sColname; /* Computed column name as a token */
139899 141477
139900 assert( zName ); 141478 assert( zName );
139901 if( zTName && pSub 141479 if( zTName
139902 && sqlite3MatchEName(&pSub->pEList->a[j], 0, zTName, 0)==0 141480 && pNestedFrom
141481 && sqlite3MatchEName(&pNestedFrom->a[j], 0, zTName, 0)==0
139903 ){ 141482 ){
139904 continue; 141483 continue;
139905 } 141484 }
@@ -139913,57 +141492,75 @@ static int selectExpander(Walker *pWalker, Select *p){
139913 ){ 141492 ){
139914 continue; 141493 continue;
139915 } 141494 }
141495 if( (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
141496 && zTName==0
141497 && (selFlags & (SF_NestedFrom))==0
141498 ){
141499 continue;
141500 }
139916 tableSeen = 1; 141501 tableSeen = 1;
139917 141502
139918 if( i>0 && zTName==0 ){ 141503 if( i>0 && zTName==0 && (selFlags & SF_NestedFrom)==0 ){
139919 if( (pFrom->fg.jointype & JT_NATURAL)!=0 141504 if( pFrom->fg.isUsing
139920 && tableAndColumnIndex(pTabList, i, zName, 0, 0, 1) 141505 && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0
139921 ){ 141506 ){
139922 /* In a NATURAL join, omit the join columns from the
139923 ** table to the right of the join */
139924 continue;
139925 }
139926 if( sqlite3IdListIndex(pFrom->pUsing, zName)>=0 ){
139927 /* In a join with a USING clause, omit columns in the 141507 /* In a join with a USING clause, omit columns in the
139928 ** using clause from the table on the right. */ 141508 ** using clause from the table on the right. */
139929 continue; 141509 continue;
139930 } 141510 }
139931 } 141511 }
139932 pRight = sqlite3Expr(db, TK_ID, zName); 141512 pRight = sqlite3Expr(db, TK_ID, zName);
139933 zColname = zName; 141513 if( (pTabList->nSrc>1
139934 zToFree = 0; 141514 && ( (pFrom->fg.jointype & JT_LTORJ)==0
139935 if( longNames || pTabList->nSrc>1 ){ 141515 || (selFlags & SF_NestedFrom)!=0
141516 || !inAnyUsingClause(zName,pFrom,pTabList->nSrc-i-1)
141517 )
141518 )
141519 || IN_RENAME_OBJECT
141520 ){
139936 Expr *pLeft; 141521 Expr *pLeft;
139937 pLeft = sqlite3Expr(db, TK_ID, zTabName); 141522 pLeft = sqlite3Expr(db, TK_ID, zTabName);
139938 pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight); 141523 pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
141524 if( IN_RENAME_OBJECT && pE->pLeft ){
141525 sqlite3RenameTokenRemap(pParse, pLeft, pE->pLeft);
141526 }
139939 if( zSchemaName ){ 141527 if( zSchemaName ){
139940 pLeft = sqlite3Expr(db, TK_ID, zSchemaName); 141528 pLeft = sqlite3Expr(db, TK_ID, zSchemaName);
139941 pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pExpr); 141529 pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pExpr);
139942 } 141530 }
139943 if( longNames ){
139944 zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
139945 zToFree = zColname;
139946 }
139947 }else{ 141531 }else{
139948 pExpr = pRight; 141532 pExpr = pRight;
139949 } 141533 }
139950 pNew = sqlite3ExprListAppend(pParse, pNew, pExpr); 141534 pNew = sqlite3ExprListAppend(pParse, pNew, pExpr);
139951 sqlite3TokenInit(&sColname, zColname); 141535 if( pNew==0 ){
139952 sqlite3ExprListSetName(pParse, pNew, &sColname, 0); 141536 break; /* OOM */
139953 if( pNew && (p->selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){ 141537 }
139954 struct ExprList_item *pX = &pNew->a[pNew->nExpr-1]; 141538 pX = &pNew->a[pNew->nExpr-1];
139955 sqlite3DbFree(db, pX->zEName); 141539 assert( pX->zEName==0 );
139956 if( pSub ){ 141540 if( (selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){
139957 pX->zEName = sqlite3DbStrDup(db, pSub->pEList->a[j].zEName); 141541 if( pNestedFrom ){
141542 pX->zEName = sqlite3DbStrDup(db, pNestedFrom->a[j].zEName);
139958 testcase( pX->zEName==0 ); 141543 testcase( pX->zEName==0 );
139959 }else{ 141544 }else{
139960 pX->zEName = sqlite3MPrintf(db, "%s.%s.%s", 141545 pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
139961 zSchemaName, zTabName, zColname); 141546 zSchemaName, zTabName, zName);
139962 testcase( pX->zEName==0 ); 141547 testcase( pX->zEName==0 );
139963 } 141548 }
139964 pX->eEName = ENAME_TAB; 141549 pX->fg.eEName = ENAME_TAB;
141550 if( (pFrom->fg.isUsing
141551 && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0)
141552 || (pUsing && sqlite3IdListIndex(pUsing, zName)>=0)
141553 || (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
141554 ){
141555 pX->fg.bNoExpand = 1;
141556 }
141557 }else if( longNames ){
141558 pX->zEName = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
141559 pX->fg.eEName = ENAME_NAME;
141560 }else{
141561 pX->zEName = sqlite3DbStrDup(db, zName);
141562 pX->fg.eEName = ENAME_NAME;
139965 } 141563 }
139966 sqlite3DbFree(db, zToFree);
139967 } 141564 }
139968 } 141565 }
139969 if( !tableSeen ){ 141566 if( !tableSeen ){
@@ -139987,6 +141584,12 @@ static int selectExpander(Walker *pWalker, Select *p){
139987 p->selFlags |= SF_ComplexResult; 141584 p->selFlags |= SF_ComplexResult;
139988 } 141585 }
139989 } 141586 }
141587#if TREETRACE_ENABLED
141588 if( sqlite3TreeTrace & 0x100 ){
141589 SELECTTRACE(0x100,pParse,p,("After result-set wildcard expansion:\n"));
141590 sqlite3TreeViewSelect(0, p, 0);
141591 }
141592#endif
139990 return WRC_Continue; 141593 return WRC_Continue;
139991} 141594}
139992 141595
@@ -140377,8 +141980,8 @@ static void havingToWhere(Parse *pParse, Select *p){
140377 sWalker.xExprCallback = havingToWhereExprCb; 141980 sWalker.xExprCallback = havingToWhereExprCb;
140378 sWalker.u.pSelect = p; 141981 sWalker.u.pSelect = p;
140379 sqlite3WalkExpr(&sWalker, p->pHaving); 141982 sqlite3WalkExpr(&sWalker, p->pHaving);
140380#if SELECTTRACE_ENABLED 141983#if TREETRACE_ENABLED
140381 if( sWalker.eCode && (sqlite3SelectTrace & 0x100)!=0 ){ 141984 if( sWalker.eCode && (sqlite3TreeTrace & 0x100)!=0 ){
140382 SELECTTRACE(0x100,pParse,p,("Move HAVING terms into WHERE:\n")); 141985 SELECTTRACE(0x100,pParse,p,("Move HAVING terms into WHERE:\n"));
140383 sqlite3TreeViewSelect(0, p, 0); 141986 sqlite3TreeViewSelect(0, p, 0);
140384 } 141987 }
@@ -140510,8 +142113,8 @@ static int countOfViewOptimization(Parse *pParse, Select *p){
140510 p->pEList->a[0].pExpr = pExpr; 142113 p->pEList->a[0].pExpr = pExpr;
140511 p->selFlags &= ~SF_Aggregate; 142114 p->selFlags &= ~SF_Aggregate;
140512 142115
140513#if SELECTTRACE_ENABLED 142116#if TREETRACE_ENABLED
140514 if( sqlite3SelectTrace & 0x400 ){ 142117 if( sqlite3TreeTrace & 0x400 ){
140515 SELECTTRACE(0x400,pParse,p,("After count-of-view optimization:\n")); 142118 SELECTTRACE(0x400,pParse,p,("After count-of-view optimization:\n"));
140516 sqlite3TreeViewSelect(0, p, 0); 142119 sqlite3TreeViewSelect(0, p, 0);
140517 } 142120 }
@@ -140521,6 +142124,29 @@ static int countOfViewOptimization(Parse *pParse, Select *p){
140521#endif /* SQLITE_COUNTOFVIEW_OPTIMIZATION */ 142124#endif /* SQLITE_COUNTOFVIEW_OPTIMIZATION */
140522 142125
140523/* 142126/*
142127** If any term of pSrc, or any SF_NestedFrom sub-query, is not the same
142128** as pSrcItem but has the same alias as p0, then return true.
142129** Otherwise return false.
142130*/
142131static int sameSrcAlias(SrcItem *p0, SrcList *pSrc){
142132 int i;
142133 for(i=0; i<pSrc->nSrc; i++){
142134 SrcItem *p1 = &pSrc->a[i];
142135 if( p1==p0 ) continue;
142136 if( p0->pTab==p1->pTab && 0==sqlite3_stricmp(p0->zAlias, p1->zAlias) ){
142137 return 1;
142138 }
142139 if( p1->pSelect
142140 && (p1->pSelect->selFlags & SF_NestedFrom)!=0
142141 && sameSrcAlias(p0, p1->pSelect->pSrc)
142142 ){
142143 return 1;
142144 }
142145 }
142146 return 0;
142147}
142148
142149/*
140524** Generate code for the SELECT statement given in the p argument. 142150** Generate code for the SELECT statement given in the p argument.
140525** 142151**
140526** The results are returned according to the SelectDest structure. 142152** The results are returned according to the SelectDest structure.
@@ -140564,10 +142190,14 @@ SQLITE_PRIVATE int sqlite3Select(
140564 } 142190 }
140565 assert( db->mallocFailed==0 ); 142191 assert( db->mallocFailed==0 );
140566 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1; 142192 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
140567#if SELECTTRACE_ENABLED 142193#if TREETRACE_ENABLED
140568 SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain)); 142194 SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain));
140569 if( sqlite3SelectTrace & 0x100 ){ 142195 if( sqlite3TreeTrace & 0x10100 ){
140570 sqlite3TreeViewSelect(0, p, 0); 142196 if( (sqlite3TreeTrace & 0x10001)==0x10000 ){
142197 sqlite3TreeViewLine(0, "In sqlite3Select() at %s:%d",
142198 __FILE__, __LINE__);
142199 }
142200 sqlite3ShowSelect(p);
140571 } 142201 }
140572#endif 142202#endif
140573 142203
@@ -140581,9 +142211,9 @@ SQLITE_PRIVATE int sqlite3Select(
140581 pDest->eDest==SRT_DistQueue || pDest->eDest==SRT_DistFifo ); 142211 pDest->eDest==SRT_DistQueue || pDest->eDest==SRT_DistFifo );
140582 /* All of these destinations are also able to ignore the ORDER BY clause */ 142212 /* All of these destinations are also able to ignore the ORDER BY clause */
140583 if( p->pOrderBy ){ 142213 if( p->pOrderBy ){
140584#if SELECTTRACE_ENABLED 142214#if TREETRACE_ENABLED
140585 SELECTTRACE(1,pParse,p, ("dropping superfluous ORDER BY:\n")); 142215 SELECTTRACE(1,pParse,p, ("dropping superfluous ORDER BY:\n"));
140586 if( sqlite3SelectTrace & 0x100 ){ 142216 if( sqlite3TreeTrace & 0x100 ){
140587 sqlite3TreeViewExprList(0, p->pOrderBy, 0, "ORDERBY"); 142217 sqlite3TreeViewExprList(0, p->pOrderBy, 0, "ORDERBY");
140588 } 142218 }
140589#endif 142219#endif
@@ -140602,8 +142232,8 @@ SQLITE_PRIVATE int sqlite3Select(
140602 } 142232 }
140603 assert( db->mallocFailed==0 ); 142233 assert( db->mallocFailed==0 );
140604 assert( p->pEList!=0 ); 142234 assert( p->pEList!=0 );
140605#if SELECTTRACE_ENABLED 142235#if TREETRACE_ENABLED
140606 if( sqlite3SelectTrace & 0x104 ){ 142236 if( sqlite3TreeTrace & 0x104 ){
140607 SELECTTRACE(0x104,pParse,p, ("after name resolution:\n")); 142237 SELECTTRACE(0x104,pParse,p, ("after name resolution:\n"));
140608 sqlite3TreeViewSelect(0, p, 0); 142238 sqlite3TreeViewSelect(0, p, 0);
140609 } 142239 }
@@ -140620,15 +142250,12 @@ SQLITE_PRIVATE int sqlite3Select(
140620 ** disallow it altogether. */ 142250 ** disallow it altogether. */
140621 if( p->selFlags & SF_UFSrcCheck ){ 142251 if( p->selFlags & SF_UFSrcCheck ){
140622 SrcItem *p0 = &p->pSrc->a[0]; 142252 SrcItem *p0 = &p->pSrc->a[0];
140623 for(i=1; i<p->pSrc->nSrc; i++){ 142253 if( sameSrcAlias(p0, p->pSrc) ){
140624 SrcItem *p1 = &p->pSrc->a[i]; 142254 sqlite3ErrorMsg(pParse,
140625 if( p0->pTab==p1->pTab && 0==sqlite3_stricmp(p0->zAlias, p1->zAlias) ){ 142255 "target object/alias may not appear in FROM clause: %s",
140626 sqlite3ErrorMsg(pParse, 142256 p0->zAlias ? p0->zAlias : p0->pTab->zName
140627 "target object/alias may not appear in FROM clause: %s", 142257 );
140628 p0->zAlias ? p0->zAlias : p0->pTab->zName 142258 goto select_end;
140629 );
140630 goto select_end;
140631 }
140632 } 142259 }
140633 142260
140634 /* Clear the SF_UFSrcCheck flag. The check has already been performed, 142261 /* Clear the SF_UFSrcCheck flag. The check has already been performed,
@@ -140647,8 +142274,8 @@ SQLITE_PRIVATE int sqlite3Select(
140647 assert( pParse->nErr ); 142274 assert( pParse->nErr );
140648 goto select_end; 142275 goto select_end;
140649 } 142276 }
140650#if SELECTTRACE_ENABLED 142277#if TREETRACE_ENABLED
140651 if( p->pWin && (sqlite3SelectTrace & 0x108)!=0 ){ 142278 if( p->pWin && (sqlite3TreeTrace & 0x108)!=0 ){
140652 SELECTTRACE(0x104,pParse,p, ("after window rewrite:\n")); 142279 SELECTTRACE(0x104,pParse,p, ("after window rewrite:\n"));
140653 sqlite3TreeViewSelect(0, p, 0); 142280 sqlite3TreeViewSelect(0, p, 0);
140654 } 142281 }
@@ -140676,14 +142303,16 @@ SQLITE_PRIVATE int sqlite3Select(
140676 /* Convert LEFT JOIN into JOIN if there are terms of the right table 142303 /* Convert LEFT JOIN into JOIN if there are terms of the right table
140677 ** of the LEFT JOIN used in the WHERE clause. 142304 ** of the LEFT JOIN used in the WHERE clause.
140678 */ 142305 */
140679 if( (pItem->fg.jointype & JT_LEFT)!=0 142306 if( (pItem->fg.jointype & (JT_LEFT|JT_RIGHT))==JT_LEFT
140680 && sqlite3ExprImpliesNonNullRow(p->pWhere, pItem->iCursor) 142307 && sqlite3ExprImpliesNonNullRow(p->pWhere, pItem->iCursor)
140681 && OptimizationEnabled(db, SQLITE_SimplifyJoin) 142308 && OptimizationEnabled(db, SQLITE_SimplifyJoin)
140682 ){ 142309 ){
140683 SELECTTRACE(0x100,pParse,p, 142310 SELECTTRACE(0x100,pParse,p,
140684 ("LEFT-JOIN simplifies to JOIN on term %d\n",i)); 142311 ("LEFT-JOIN simplifies to JOIN on term %d\n",i));
140685 pItem->fg.jointype &= ~(JT_LEFT|JT_OUTER); 142312 pItem->fg.jointype &= ~(JT_LEFT|JT_OUTER);
140686 unsetJoinExpr(p->pWhere, pItem->iCursor); 142313 assert( pItem->iCursor>=0 );
142314 unsetJoinExpr(p->pWhere, pItem->iCursor,
142315 pTabList->a[0].fg.jointype & JT_LTORJ);
140687 } 142316 }
140688 142317
140689 /* No futher action if this term of the FROM clause is no a subquery */ 142318 /* No futher action if this term of the FROM clause is no a subquery */
@@ -140736,7 +142365,9 @@ SQLITE_PRIVATE int sqlite3Select(
140736 ){ 142365 ){
140737 SELECTTRACE(0x100,pParse,p, 142366 SELECTTRACE(0x100,pParse,p,
140738 ("omit superfluous ORDER BY on %r FROM-clause subquery\n",i+1)); 142367 ("omit superfluous ORDER BY on %r FROM-clause subquery\n",i+1));
140739 sqlite3ExprListDelete(db, pSub->pOrderBy); 142368 sqlite3ParserAddCleanup(pParse,
142369 (void(*)(sqlite3*,void*))sqlite3ExprListDelete,
142370 pSub->pOrderBy);
140740 pSub->pOrderBy = 0; 142371 pSub->pOrderBy = 0;
140741 } 142372 }
140742 142373
@@ -140762,7 +142393,7 @@ SQLITE_PRIVATE int sqlite3Select(
140762 && i==0 142393 && i==0
140763 && (p->selFlags & SF_ComplexResult)!=0 142394 && (p->selFlags & SF_ComplexResult)!=0
140764 && (pTabList->nSrc==1 142395 && (pTabList->nSrc==1
140765 || (pTabList->a[1].fg.jointype&(JT_LEFT|JT_CROSS))!=0) 142396 || (pTabList->a[1].fg.jointype&(JT_OUTER|JT_CROSS))!=0)
140766 ){ 142397 ){
140767 continue; 142398 continue;
140768 } 142399 }
@@ -140786,9 +142417,9 @@ SQLITE_PRIVATE int sqlite3Select(
140786 */ 142417 */
140787 if( p->pPrior ){ 142418 if( p->pPrior ){
140788 rc = multiSelect(pParse, p, pDest); 142419 rc = multiSelect(pParse, p, pDest);
140789#if SELECTTRACE_ENABLED 142420#if TREETRACE_ENABLED
140790 SELECTTRACE(0x1,pParse,p,("end compound-select processing\n")); 142421 SELECTTRACE(0x1,pParse,p,("end compound-select processing\n"));
140791 if( (sqlite3SelectTrace & 0x2000)!=0 && ExplainQueryPlanParent(pParse)==0 ){ 142422 if( (sqlite3TreeTrace & 0x2000)!=0 && ExplainQueryPlanParent(pParse)==0 ){
140792 sqlite3TreeViewSelect(0, p, 0); 142423 sqlite3TreeViewSelect(0, p, 0);
140793 } 142424 }
140794#endif 142425#endif
@@ -140807,8 +142438,8 @@ SQLITE_PRIVATE int sqlite3Select(
140807 && OptimizationEnabled(db, SQLITE_PropagateConst) 142438 && OptimizationEnabled(db, SQLITE_PropagateConst)
140808 && propagateConstants(pParse, p) 142439 && propagateConstants(pParse, p)
140809 ){ 142440 ){
140810#if SELECTTRACE_ENABLED 142441#if TREETRACE_ENABLED
140811 if( sqlite3SelectTrace & 0x100 ){ 142442 if( sqlite3TreeTrace & 0x100 ){
140812 SELECTTRACE(0x100,pParse,p,("After constant propagation:\n")); 142443 SELECTTRACE(0x100,pParse,p,("After constant propagation:\n"));
140813 sqlite3TreeViewSelect(0, p, 0); 142444 sqlite3TreeViewSelect(0, p, 0);
140814 } 142445 }
@@ -140884,11 +142515,10 @@ SQLITE_PRIVATE int sqlite3Select(
140884 if( OptimizationEnabled(db, SQLITE_PushDown) 142515 if( OptimizationEnabled(db, SQLITE_PushDown)
140885 && (pItem->fg.isCte==0 142516 && (pItem->fg.isCte==0
140886 || (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2)) 142517 || (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2))
140887 && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor, 142518 && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem)
140888 (pItem->fg.jointype & JT_OUTER)!=0)
140889 ){ 142519 ){
140890#if SELECTTRACE_ENABLED 142520#if TREETRACE_ENABLED
140891 if( sqlite3SelectTrace & 0x100 ){ 142521 if( sqlite3TreeTrace & 0x100 ){
140892 SELECTTRACE(0x100,pParse,p, 142522 SELECTTRACE(0x100,pParse,p,
140893 ("After WHERE-clause push-down into subquery %d:\n", pSub->selId)); 142523 ("After WHERE-clause push-down into subquery %d:\n", pSub->selId));
140894 sqlite3TreeViewSelect(0, p, 0); 142524 sqlite3TreeViewSelect(0, p, 0);
@@ -140904,18 +142534,19 @@ SQLITE_PRIVATE int sqlite3Select(
140904 142534
140905 /* Generate code to implement the subquery 142535 /* Generate code to implement the subquery
140906 ** 142536 **
140907 ** The subquery is implemented as a co-routine if: 142537 ** The subquery is implemented as a co-routine if all of the following are
142538 ** true:
142539 **
140908 ** (1) the subquery is guaranteed to be the outer loop (so that 142540 ** (1) the subquery is guaranteed to be the outer loop (so that
140909 ** it does not need to be computed more than once), and 142541 ** it does not need to be computed more than once), and
140910 ** (2) the subquery is not a CTE that should be materialized 142542 ** (2) the subquery is not a CTE that should be materialized
140911 ** 142543 ** (3) the subquery is not part of a left operand for a RIGHT JOIN
140912 ** TODO: Are there other reasons beside (1) and (2) to use a co-routine
140913 ** implementation?
140914 */ 142544 */
140915 if( i==0 142545 if( i==0
140916 && (pTabList->nSrc==1 142546 && (pTabList->nSrc==1
140917 || (pTabList->a[1].fg.jointype&(JT_LEFT|JT_CROSS))!=0) /* (1) */ 142547 || (pTabList->a[1].fg.jointype&(JT_OUTER|JT_CROSS))!=0) /* (1) */
140918 && (pItem->fg.isCte==0 || pItem->u2.pCteUse->eM10d!=M10d_Yes) /* (2) */ 142548 && (pItem->fg.isCte==0 || pItem->u2.pCteUse->eM10d!=M10d_Yes) /* (2) */
142549 && (pTabList->a[0].fg.jointype & JT_LTORJ)==0 /* (3) */
140919 ){ 142550 ){
140920 /* Implement a co-routine that will return a single row of the result 142551 /* Implement a co-routine that will return a single row of the result
140921 ** set on each invocation. 142552 ** set on each invocation.
@@ -140961,11 +142592,11 @@ SQLITE_PRIVATE int sqlite3Select(
140961 ** the same view can reuse the materialization. */ 142592 ** the same view can reuse the materialization. */
140962 int topAddr; 142593 int topAddr;
140963 int onceAddr = 0; 142594 int onceAddr = 0;
140964 int retAddr;
140965 142595
140966 pItem->regReturn = ++pParse->nMem; 142596 pItem->regReturn = ++pParse->nMem;
140967 topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn); 142597 topAddr = sqlite3VdbeAddOp0(v, OP_Goto);
140968 pItem->addrFillSub = topAddr+1; 142598 pItem->addrFillSub = topAddr+1;
142599 pItem->fg.isMaterialized = 1;
140969 if( pItem->fg.isCorrelated==0 ){ 142600 if( pItem->fg.isCorrelated==0 ){
140970 /* If the subquery is not correlated and if we are not inside of 142601 /* If the subquery is not correlated and if we are not inside of
140971 ** a trigger, then we only need to compute the value of the subquery 142602 ** a trigger, then we only need to compute the value of the subquery
@@ -140980,9 +142611,9 @@ SQLITE_PRIVATE int sqlite3Select(
140980 sqlite3Select(pParse, pSub, &dest); 142611 sqlite3Select(pParse, pSub, &dest);
140981 pItem->pTab->nRowLogEst = pSub->nSelectRow; 142612 pItem->pTab->nRowLogEst = pSub->nSelectRow;
140982 if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr); 142613 if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
140983 retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn); 142614 sqlite3VdbeAddOp2(v, OP_Return, pItem->regReturn, topAddr+1);
140984 VdbeComment((v, "end %!S", pItem)); 142615 VdbeComment((v, "end %!S", pItem));
140985 sqlite3VdbeChangeP1(v, topAddr, retAddr); 142616 sqlite3VdbeJumpHere(v, topAddr);
140986 sqlite3ClearTempRegCache(pParse); 142617 sqlite3ClearTempRegCache(pParse);
140987 if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){ 142618 if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){
140988 CteUse *pCteUse = pItem->u2.pCteUse; 142619 CteUse *pCteUse = pItem->u2.pCteUse;
@@ -141006,8 +142637,8 @@ SQLITE_PRIVATE int sqlite3Select(
141006 pHaving = p->pHaving; 142637 pHaving = p->pHaving;
141007 sDistinct.isTnct = (p->selFlags & SF_Distinct)!=0; 142638 sDistinct.isTnct = (p->selFlags & SF_Distinct)!=0;
141008 142639
141009#if SELECTTRACE_ENABLED 142640#if TREETRACE_ENABLED
141010 if( sqlite3SelectTrace & 0x400 ){ 142641 if( sqlite3TreeTrace & 0x400 ){
141011 SELECTTRACE(0x400,pParse,p,("After all FROM-clause analysis:\n")); 142642 SELECTTRACE(0x400,pParse,p,("After all FROM-clause analysis:\n"));
141012 sqlite3TreeViewSelect(0, p, 0); 142643 sqlite3TreeViewSelect(0, p, 0);
141013 } 142644 }
@@ -141041,9 +142672,10 @@ SQLITE_PRIVATE int sqlite3Select(
141041 ** the sDistinct.isTnct is still set. Hence, isTnct represents the 142672 ** the sDistinct.isTnct is still set. Hence, isTnct represents the
141042 ** original setting of the SF_Distinct flag, not the current setting */ 142673 ** original setting of the SF_Distinct flag, not the current setting */
141043 assert( sDistinct.isTnct ); 142674 assert( sDistinct.isTnct );
142675 sDistinct.isTnct = 2;
141044 142676
141045#if SELECTTRACE_ENABLED 142677#if TREETRACE_ENABLED
141046 if( sqlite3SelectTrace & 0x400 ){ 142678 if( sqlite3TreeTrace & 0x400 ){
141047 SELECTTRACE(0x400,pParse,p,("Transform DISTINCT into GROUP BY:\n")); 142679 SELECTTRACE(0x400,pParse,p,("Transform DISTINCT into GROUP BY:\n"));
141048 sqlite3TreeViewSelect(0, p, 0); 142680 sqlite3TreeViewSelect(0, p, 0);
141049 } 142681 }
@@ -141076,6 +142708,18 @@ SQLITE_PRIVATE int sqlite3Select(
141076 */ 142708 */
141077 if( pDest->eDest==SRT_EphemTab ){ 142709 if( pDest->eDest==SRT_EphemTab ){
141078 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr); 142710 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr);
142711 if( p->selFlags & SF_NestedFrom ){
142712 /* Delete or NULL-out result columns that will never be used */
142713 int ii;
142714 for(ii=pEList->nExpr-1; ii>0 && pEList->a[ii].fg.bUsed==0; ii--){
142715 sqlite3ExprDelete(db, pEList->a[ii].pExpr);
142716 sqlite3DbFree(db, pEList->a[ii].zEName);
142717 pEList->nExpr--;
142718 }
142719 for(ii=0; ii<pEList->nExpr; ii++){
142720 if( pEList->a[ii].fg.bUsed==0 ) pEList->a[ii].pExpr->op = TK_NULL;
142721 }
142722 }
141079 } 142723 }
141080 142724
141081 /* Set the limiter. 142725 /* Set the limiter.
@@ -141225,8 +142869,9 @@ SQLITE_PRIVATE int sqlite3Select(
141225 ** ORDER BY to maximize the chances of rows being delivered in an 142869 ** ORDER BY to maximize the chances of rows being delivered in an
141226 ** order that makes the ORDER BY redundant. */ 142870 ** order that makes the ORDER BY redundant. */
141227 for(ii=0; ii<pGroupBy->nExpr; ii++){ 142871 for(ii=0; ii<pGroupBy->nExpr; ii++){
141228 u8 sortFlags = sSort.pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_DESC; 142872 u8 sortFlags;
141229 pGroupBy->a[ii].sortFlags = sortFlags; 142873 sortFlags = sSort.pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_DESC;
142874 pGroupBy->a[ii].fg.sortFlags = sortFlags;
141230 } 142875 }
141231 if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){ 142876 if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
141232 orderByGrp = 1; 142877 orderByGrp = 1;
@@ -141295,8 +142940,8 @@ SQLITE_PRIVATE int sqlite3Select(
141295 } 142940 }
141296 pAggInfo->mxReg = pParse->nMem; 142941 pAggInfo->mxReg = pParse->nMem;
141297 if( db->mallocFailed ) goto select_end; 142942 if( db->mallocFailed ) goto select_end;
141298#if SELECTTRACE_ENABLED 142943#if TREETRACE_ENABLED
141299 if( sqlite3SelectTrace & 0x400 ){ 142944 if( sqlite3TreeTrace & 0x400 ){
141300 int ii; 142945 int ii;
141301 SELECTTRACE(0x400,pParse,p,("After aggregate analysis %p:\n", pAggInfo)); 142946 SELECTTRACE(0x400,pParse,p,("After aggregate analysis %p:\n", pAggInfo));
141302 sqlite3TreeViewSelect(0, p, 0); 142947 sqlite3TreeViewSelect(0, p, 0);
@@ -141384,7 +143029,8 @@ SQLITE_PRIVATE int sqlite3Select(
141384 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset); 143029 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
141385 SELECTTRACE(1,pParse,p,("WhereBegin\n")); 143030 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
141386 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct, 143031 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct,
141387 0, (WHERE_GROUPBY|(orderByGrp ? WHERE_SORTBYGROUP : 0)|distFlag), 0 143032 0, (sDistinct.isTnct==2 ? WHERE_DISTINCTBY : WHERE_GROUPBY)
143033 | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0
141388 ); 143034 );
141389 if( pWInfo==0 ){ 143035 if( pWInfo==0 ){
141390 sqlite3ExprListDelete(db, pDistinct); 143036 sqlite3ExprListDelete(db, pDistinct);
@@ -141566,7 +143212,7 @@ SQLITE_PRIVATE int sqlite3Select(
141566 VdbeComment((v, "indicate accumulator empty")); 143212 VdbeComment((v, "indicate accumulator empty"));
141567 sqlite3VdbeAddOp1(v, OP_Return, regReset); 143213 sqlite3VdbeAddOp1(v, OP_Return, regReset);
141568 143214
141569 if( eDist!=WHERE_DISTINCT_NOOP ){ 143215 if( distFlag!=0 && eDist!=WHERE_DISTINCT_NOOP ){
141570 struct AggInfo_func *pF = &pAggInfo->aFunc[0]; 143216 struct AggInfo_func *pF = &pAggInfo->aFunc[0];
141571 fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr); 143217 fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr);
141572 } 143218 }
@@ -141690,8 +143336,10 @@ SQLITE_PRIVATE int sqlite3Select(
141690 eDist = sqlite3WhereIsDistinct(pWInfo); 143336 eDist = sqlite3WhereIsDistinct(pWInfo);
141691 updateAccumulator(pParse, regAcc, pAggInfo, eDist); 143337 updateAccumulator(pParse, regAcc, pAggInfo, eDist);
141692 if( eDist!=WHERE_DISTINCT_NOOP ){ 143338 if( eDist!=WHERE_DISTINCT_NOOP ){
141693 struct AggInfo_func *pF = &pAggInfo->aFunc[0]; 143339 struct AggInfo_func *pF = pAggInfo->aFunc;
141694 fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr); 143340 if( pF ){
143341 fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr);
143342 }
141695 } 143343 }
141696 143344
141697 if( regAcc ) sqlite3VdbeAddOp2(v, OP_Integer, 1, regAcc); 143345 if( regAcc ) sqlite3VdbeAddOp2(v, OP_Integer, 1, regAcc);
@@ -141758,9 +143406,9 @@ select_end:
141758 } 143406 }
141759#endif 143407#endif
141760 143408
141761#if SELECTTRACE_ENABLED 143409#if TREETRACE_ENABLED
141762 SELECTTRACE(0x1,pParse,p,("end processing\n")); 143410 SELECTTRACE(0x1,pParse,p,("end processing\n"));
141763 if( (sqlite3SelectTrace & 0x2000)!=0 && ExplainQueryPlanParent(pParse)==0 ){ 143411 if( (sqlite3TreeTrace & 0x2000)!=0 && ExplainQueryPlanParent(pParse)==0 ){
141764 sqlite3TreeViewSelect(0, p, 0); 143412 sqlite3TreeViewSelect(0, p, 0);
141765 } 143413 }
141766#endif 143414#endif
@@ -142025,9 +143673,7 @@ SQLITE_PRIVATE Trigger *sqlite3TriggerList(Parse *pParse, Table *pTab){
142025 Trigger *pList; /* List of triggers to return */ 143673 Trigger *pList; /* List of triggers to return */
142026 HashElem *p; /* Loop variable for TEMP triggers */ 143674 HashElem *p; /* Loop variable for TEMP triggers */
142027 143675
142028 if( pParse->disableTriggers ){ 143676 assert( pParse->disableTriggers==0 );
142029 return 0;
142030 }
142031 pTmpSchema = pParse->db->aDb[1].pSchema; 143677 pTmpSchema = pParse->db->aDb[1].pSchema;
142032 p = sqliteHashFirst(&pTmpSchema->trigHash); 143678 p = sqliteHashFirst(&pTmpSchema->trigHash);
142033 pList = pTab->pTrigger; 143679 pList = pTab->pTrigger;
@@ -142040,11 +143686,10 @@ SQLITE_PRIVATE Trigger *sqlite3TriggerList(Parse *pParse, Table *pTab){
142040 ){ 143686 ){
142041 pTrig->pNext = pList; 143687 pTrig->pNext = pList;
142042 pList = pTrig; 143688 pList = pTrig;
142043 }else if( pTrig->op==TK_RETURNING 143689 }else if( pTrig->op==TK_RETURNING ){
142044#ifndef SQLITE_OMIT_VIRTUALTABLE 143690#ifndef SQLITE_OMIT_VIRTUALTABLE
142045 && pParse->db->pVtabCtx==0 143691 assert( pParse->db->pVtabCtx==0 );
142046#endif 143692#endif
142047 ){
142048 assert( pParse->bReturning ); 143693 assert( pParse->bReturning );
142049 assert( &(pParse->u1.pReturning->retTrig) == pTrig ); 143694 assert( &(pParse->u1.pReturning->retTrig) == pTrig );
142050 pTrig->table = pTab->zName; 143695 pTrig->table = pTab->zName;
@@ -142490,7 +144135,7 @@ SQLITE_PRIVATE TriggerStep *sqlite3TriggerInsertStep(
142490SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep( 144135SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep(
142491 Parse *pParse, /* Parser */ 144136 Parse *pParse, /* Parser */
142492 Token *pTableName, /* Name of the table to be updated */ 144137 Token *pTableName, /* Name of the table to be updated */
142493 SrcList *pFrom, 144138 SrcList *pFrom, /* FROM clause for an UPDATE-FROM, or NULL */
142494 ExprList *pEList, /* The SET clause: list of column and new values */ 144139 ExprList *pEList, /* The SET clause: list of column and new values */
142495 Expr *pWhere, /* The WHERE clause */ 144140 Expr *pWhere, /* The WHERE clause */
142496 u8 orconf, /* The conflict algorithm. (OE_Abort, OE_Ignore, etc) */ 144141 u8 orconf, /* The conflict algorithm. (OE_Abort, OE_Ignore, etc) */
@@ -142704,12 +144349,21 @@ static int checkColumnOverlap(IdList *pIdList, ExprList *pEList){
142704} 144349}
142705 144350
142706/* 144351/*
144352** Return true if any TEMP triggers exist
144353*/
144354static int tempTriggersExist(sqlite3 *db){
144355 if( NEVER(db->aDb[1].pSchema==0) ) return 0;
144356 if( sqliteHashFirst(&db->aDb[1].pSchema->trigHash)==0 ) return 0;
144357 return 1;
144358}
144359
144360/*
142707** Return a list of all triggers on table pTab if there exists at least 144361** Return a list of all triggers on table pTab if there exists at least
142708** one trigger that must be fired when an operation of type 'op' is 144362** one trigger that must be fired when an operation of type 'op' is
142709** performed on the table, and, if that operation is an UPDATE, if at 144363** performed on the table, and, if that operation is an UPDATE, if at
142710** least one of the columns in pChanges is being modified. 144364** least one of the columns in pChanges is being modified.
142711*/ 144365*/
142712SQLITE_PRIVATE Trigger *sqlite3TriggersExist( 144366static SQLITE_NOINLINE Trigger *triggersReallyExist(
142713 Parse *pParse, /* Parse context */ 144367 Parse *pParse, /* Parse context */
142714 Table *pTab, /* The table the contains the triggers */ 144368 Table *pTab, /* The table the contains the triggers */
142715 int op, /* one of TK_DELETE, TK_INSERT, TK_UPDATE */ 144369 int op, /* one of TK_DELETE, TK_INSERT, TK_UPDATE */
@@ -142772,6 +144426,22 @@ exit_triggers_exist:
142772 } 144426 }
142773 return (mask ? pList : 0); 144427 return (mask ? pList : 0);
142774} 144428}
144429SQLITE_PRIVATE Trigger *sqlite3TriggersExist(
144430 Parse *pParse, /* Parse context */
144431 Table *pTab, /* The table the contains the triggers */
144432 int op, /* one of TK_DELETE, TK_INSERT, TK_UPDATE */
144433 ExprList *pChanges, /* Columns that change in an UPDATE statement */
144434 int *pMask /* OUT: Mask of TRIGGER_BEFORE|TRIGGER_AFTER */
144435){
144436 assert( pTab!=0 );
144437 if( (pTab->pTrigger==0 && !tempTriggersExist(pParse->db))
144438 || pParse->disableTriggers
144439 ){
144440 if( pMask ) *pMask = 0;
144441 return 0;
144442 }
144443 return triggersReallyExist(pParse,pTab,op,pChanges,pMask);
144444}
142775 144445
142776/* 144446/*
142777** Convert the pStep->zTarget string into a SrcList and return a pointer 144447** Convert the pStep->zTarget string into a SrcList and return a pointer
@@ -142801,6 +144471,14 @@ SQLITE_PRIVATE SrcList *sqlite3TriggerStepSrc(
142801 } 144471 }
142802 if( pStep->pFrom ){ 144472 if( pStep->pFrom ){
142803 SrcList *pDup = sqlite3SrcListDup(db, pStep->pFrom, 0); 144473 SrcList *pDup = sqlite3SrcListDup(db, pStep->pFrom, 0);
144474 if( pDup && pDup->nSrc>1 && !IN_RENAME_OBJECT ){
144475 Select *pSubquery;
144476 Token as;
144477 pSubquery = sqlite3SelectNew(pParse,0,pDup,0,0,0,0,SF_NestedFrom,0);
144478 as.n = 0;
144479 as.z = 0;
144480 pDup = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&as,pSubquery,0);
144481 }
142804 pSrc = sqlite3SrcListAppendList(pParse, pSrc, pDup); 144482 pSrc = sqlite3SrcListAppendList(pParse, pSrc, pDup);
142805 } 144483 }
142806 }else{ 144484 }else{
@@ -142856,7 +144534,7 @@ static ExprList *sqlite3ExpandReturning(
142856 if( !db->mallocFailed ){ 144534 if( !db->mallocFailed ){
142857 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1]; 144535 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
142858 pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName); 144536 pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName);
142859 pItem->eEName = ENAME_NAME; 144537 pItem->fg.eEName = ENAME_NAME;
142860 } 144538 }
142861 } 144539 }
142862 }else{ 144540 }else{
@@ -142865,7 +144543,7 @@ static ExprList *sqlite3ExpandReturning(
142865 if( !db->mallocFailed && ALWAYS(pList->a[i].zEName!=0) ){ 144543 if( !db->mallocFailed && ALWAYS(pList->a[i].zEName!=0) ){
142866 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1]; 144544 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
142867 pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName); 144545 pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName);
142868 pItem->eEName = pList->a[i].eEName; 144546 pItem->fg.eEName = pList->a[i].fg.eEName;
142869 } 144547 }
142870 } 144548 }
142871 } 144549 }
@@ -143780,6 +145458,14 @@ SQLITE_PRIVATE void sqlite3Update(
143780# define isView 0 145458# define isView 0
143781#endif 145459#endif
143782 145460
145461#if TREETRACE_ENABLED
145462 if( sqlite3TreeTrace & 0x10000 ){
145463 sqlite3TreeViewLine(0, "In sqlite3Update() at %s:%d", __FILE__, __LINE__);
145464 sqlite3TreeViewUpdate(pParse->pWith, pTabList, pChanges, pWhere,
145465 onError, pOrderBy, pLimit, pUpsert, pTrigger);
145466 }
145467#endif
145468
143783 /* If there was a FROM clause, set nChangeFrom to the number of expressions 145469 /* If there was a FROM clause, set nChangeFrom to the number of expressions
143784 ** in the change-list. Otherwise, set it to 0. There cannot be a FROM 145470 ** in the change-list. Otherwise, set it to 0. There cannot be a FROM
143785 ** clause if this function is being called to generate code for part of 145471 ** clause if this function is being called to generate code for part of
@@ -144424,7 +146110,7 @@ SQLITE_PRIVATE void sqlite3Update(
144424 }else{ 146110 }else{
144425 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue,regOldRowid); 146111 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue,regOldRowid);
144426 } 146112 }
144427 VdbeCoverageNeverTaken(v); 146113 VdbeCoverage(v);
144428 } 146114 }
144429 146115
144430 /* Do FK constraint checks. */ 146116 /* Do FK constraint checks. */
@@ -145430,6 +147116,7 @@ SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3RunVacuum(
145430 147116
145431 assert( rc==SQLITE_OK ); 147117 assert( rc==SQLITE_OK );
145432 if( pOut==0 ){ 147118 if( pOut==0 ){
147119 nRes = sqlite3BtreeGetRequestedReserve(pTemp);
145433 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1); 147120 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
145434 } 147121 }
145435 147122
@@ -146872,6 +148559,28 @@ typedef struct WhereLoopBuilder WhereLoopBuilder;
146872typedef struct WhereScan WhereScan; 148559typedef struct WhereScan WhereScan;
146873typedef struct WhereOrCost WhereOrCost; 148560typedef struct WhereOrCost WhereOrCost;
146874typedef struct WhereOrSet WhereOrSet; 148561typedef struct WhereOrSet WhereOrSet;
148562typedef struct WhereMemBlock WhereMemBlock;
148563typedef struct WhereRightJoin WhereRightJoin;
148564
148565/*
148566** This object is a header on a block of allocated memory that will be
148567** automatically freed when its WInfo oject is destructed.
148568*/
148569struct WhereMemBlock {
148570 WhereMemBlock *pNext; /* Next block in the chain */
148571 u64 sz; /* Bytes of space */
148572};
148573
148574/*
148575** Extra information attached to a WhereLevel that is a RIGHT JOIN.
148576*/
148577struct WhereRightJoin {
148578 int iMatch; /* Cursor used to determine prior matched rows */
148579 int regBloom; /* Bloom filter for iRJMatch */
148580 int regReturn; /* Return register for the interior subroutine */
148581 int addrSubrtn; /* Starting address for the interior subroutine */
148582 int endSubrtn; /* The last opcode in the interior subroutine */
148583};
146875 148584
146876/* 148585/*
146877** This object contains information needed to implement a single nested 148586** This object contains information needed to implement a single nested
@@ -146905,6 +148614,7 @@ struct WhereLevel {
146905 int addrLikeRep; /* LIKE range processing address */ 148614 int addrLikeRep; /* LIKE range processing address */
146906#endif 148615#endif
146907 int regFilter; /* Bloom filter */ 148616 int regFilter; /* Bloom filter */
148617 WhereRightJoin *pRJ; /* Extra information for RIGHT JOIN */
146908 u8 iFrom; /* Which entry in the FROM clause */ 148618 u8 iFrom; /* Which entry in the FROM clause */
146909 u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */ 148619 u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */
146910 int p1, p2; /* Operands of the opcode used to end the loop */ 148620 int p1, p2; /* Operands of the opcode used to end the loop */
@@ -147318,6 +149028,7 @@ struct WhereInfo {
147318 int iEndWhere; /* End of the WHERE clause itself */ 149028 int iEndWhere; /* End of the WHERE clause itself */
147319 WhereLoop *pLoops; /* List of all WhereLoop objects */ 149029 WhereLoop *pLoops; /* List of all WhereLoop objects */
147320 WhereExprMod *pExprMods; /* Expression modifications */ 149030 WhereExprMod *pExprMods; /* Expression modifications */
149031 WhereMemBlock *pMemToFree;/* Memory to free when this object destroyed */
147321 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */ 149032 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
147322 WhereClause sWC; /* Decomposition of the WHERE clause */ 149033 WhereClause sWC; /* Decomposition of the WHERE clause */
147323 WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */ 149034 WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */
@@ -147343,6 +149054,8 @@ SQLITE_PRIVATE WhereTerm *sqlite3WhereFindTerm(
147343 u32 op, /* Mask of WO_xx values describing operator */ 149054 u32 op, /* Mask of WO_xx values describing operator */
147344 Index *pIdx /* Must be compatible with this index, if not NULL */ 149055 Index *pIdx /* Must be compatible with this index, if not NULL */
147345); 149056);
149057SQLITE_PRIVATE void *sqlite3WhereMalloc(WhereInfo *pWInfo, u64 nByte);
149058SQLITE_PRIVATE void *sqlite3WhereRealloc(WhereInfo *pWInfo, void *pOld, u64 nByte);
147346 149059
147347/* wherecode.c: */ 149060/* wherecode.c: */
147348#ifndef SQLITE_OMIT_EXPLAIN 149061#ifndef SQLITE_OMIT_EXPLAIN
@@ -147379,6 +149092,11 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
147379 WhereLevel *pLevel, /* The current level pointer */ 149092 WhereLevel *pLevel, /* The current level pointer */
147380 Bitmask notReady /* Which tables are currently available */ 149093 Bitmask notReady /* Which tables are currently available */
147381); 149094);
149095SQLITE_PRIVATE SQLITE_NOINLINE void sqlite3WhereRightJoinLoop(
149096 WhereInfo *pWInfo,
149097 int iLevel,
149098 WhereLevel *pLevel
149099);
147382 149100
147383/* whereexpr.c: */ 149101/* whereexpr.c: */
147384SQLITE_PRIVATE void sqlite3WhereClauseInit(WhereClause*,WhereInfo*); 149102SQLITE_PRIVATE void sqlite3WhereClauseInit(WhereClause*,WhereInfo*);
@@ -147421,8 +149139,9 @@ SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(Parse*, SrcItem*, WhereClause*);
147421#define WO_AND 0x0400 /* Two or more AND-connected terms */ 149139#define WO_AND 0x0400 /* Two or more AND-connected terms */
147422#define WO_EQUIV 0x0800 /* Of the form A==B, both columns */ 149140#define WO_EQUIV 0x0800 /* Of the form A==B, both columns */
147423#define WO_NOOP 0x1000 /* This term does not restrict search space */ 149141#define WO_NOOP 0x1000 /* This term does not restrict search space */
149142#define WO_ROWVAL 0x2000 /* A row-value term */
147424 149143
147425#define WO_ALL 0x1fff /* Mask of all possible WO_* values */ 149144#define WO_ALL 0x3fff /* Mask of all possible WO_* values */
147426#define WO_SINGLE 0x01ff /* Mask of all non-compound WO_* values */ 149145#define WO_SINGLE 0x01ff /* Mask of all non-compound WO_* values */
147427 149146
147428/* 149147/*
@@ -147646,6 +149365,9 @@ SQLITE_PRIVATE int sqlite3WhereExplainOneScan(
147646 pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr); 149365 pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr);
147647 } 149366 }
147648#endif 149367#endif
149368 if( pItem->fg.jointype & JT_LEFT ){
149369 sqlite3_str_appendf(&str, " LEFT-JOIN");
149370 }
147649#ifdef SQLITE_EXPLAIN_ESTIMATED_ROWS 149371#ifdef SQLITE_EXPLAIN_ESTIMATED_ROWS
147650 if( pLoop->nOut>=10 ){ 149372 if( pLoop->nOut>=10 ){
147651 sqlite3_str_appendf(&str, " (~%llu rows)", 149373 sqlite3_str_appendf(&str, " (~%llu rows)",
@@ -147789,7 +149511,7 @@ static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){
147789 int nLoop = 0; 149511 int nLoop = 0;
147790 assert( pTerm!=0 ); 149512 assert( pTerm!=0 );
147791 while( (pTerm->wtFlags & TERM_CODED)==0 149513 while( (pTerm->wtFlags & TERM_CODED)==0
147792 && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_FromJoin)) 149514 && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_OuterON))
147793 && (pLevel->notReady & pTerm->prereqAll)==0 149515 && (pLevel->notReady & pTerm->prereqAll)==0
147794 ){ 149516 ){
147795 if( nLoop && (pTerm->wtFlags & TERM_LIKE)!=0 ){ 149517 if( nLoop && (pTerm->wtFlags & TERM_LIKE)!=0 ){
@@ -148050,16 +149772,21 @@ static int codeEqualityTerm(
148050 if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){ 149772 if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
148051 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab); 149773 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
148052 }else{ 149774 }else{
148053 sqlite3 *db = pParse->db; 149775 Expr *pExpr = pTerm->pExpr;
148054 pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX); 149776 if( pExpr->iTable==0 || !ExprHasProperty(pExpr, EP_Subrtn) ){
148055 149777 sqlite3 *db = pParse->db;
148056 if( !db->mallocFailed ){ 149778 pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
149779 if( !db->mallocFailed ){
149780 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
149781 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap,&iTab);
149782 pExpr->iTable = iTab;
149783 }
149784 sqlite3ExprDelete(db, pX);
149785 }else{
148057 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq); 149786 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
148058 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab); 149787 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
148059 pTerm->pExpr->iTable = iTab;
148060 } 149788 }
148061 sqlite3ExprDelete(db, pX); 149789 pX = pExpr;
148062 pX = pTerm->pExpr;
148063 } 149790 }
148064 149791
148065 if( eType==IN_INDEX_INDEX_DESC ){ 149792 if( eType==IN_INDEX_INDEX_DESC ){
@@ -148082,8 +149809,9 @@ static int codeEqualityTerm(
148082 i = pLevel->u.in.nIn; 149809 i = pLevel->u.in.nIn;
148083 pLevel->u.in.nIn += nEq; 149810 pLevel->u.in.nIn += nEq;
148084 pLevel->u.in.aInLoop = 149811 pLevel->u.in.aInLoop =
148085 sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop, 149812 sqlite3WhereRealloc(pTerm->pWC->pWInfo,
148086 sizeof(pLevel->u.in.aInLoop[0])*pLevel->u.in.nIn); 149813 pLevel->u.in.aInLoop,
149814 sizeof(pLevel->u.in.aInLoop[0])*pLevel->u.in.nIn);
148087 pIn = pLevel->u.in.aInLoop; 149815 pIn = pLevel->u.in.aInLoop;
148088 if( pIn ){ 149816 if( pIn ){
148089 int iMap = 0; /* Index in aiMap[] */ 149817 int iMap = 0; /* Index in aiMap[] */
@@ -148504,8 +150232,8 @@ static void codeCursorHint(
148504 */ 150232 */
148505 if( pTabItem->fg.jointype & JT_LEFT ){ 150233 if( pTabItem->fg.jointype & JT_LEFT ){
148506 Expr *pExpr = pTerm->pExpr; 150234 Expr *pExpr = pTerm->pExpr;
148507 if( !ExprHasProperty(pExpr, EP_FromJoin) 150235 if( !ExprHasProperty(pExpr, EP_OuterON)
148508 || pExpr->w.iRightJoinTable!=pTabItem->iCursor 150236 || pExpr->w.iJoin!=pTabItem->iCursor
148509 ){ 150237 ){
148510 sWalker.eCode = 0; 150238 sWalker.eCode = 0;
148511 sWalker.xExprCallback = codeCursorHintIsOrFunction; 150239 sWalker.xExprCallback = codeCursorHintIsOrFunction;
@@ -148513,7 +150241,7 @@ static void codeCursorHint(
148513 if( sWalker.eCode ) continue; 150241 if( sWalker.eCode ) continue;
148514 } 150242 }
148515 }else{ 150243 }else{
148516 if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) continue; 150244 if( ExprHasProperty(pTerm->pExpr, EP_OuterON) ) continue;
148517 } 150245 }
148518 150246
148519 /* All terms in pWLoop->aLTerm[] except pEndRange are used to initialize 150247 /* All terms in pWLoop->aLTerm[] except pEndRange are used to initialize
@@ -148561,13 +150289,21 @@ static void codeCursorHint(
148561** 150289**
148562** OP_DeferredSeek $iCur $iRowid 150290** OP_DeferredSeek $iCur $iRowid
148563** 150291**
150292** Which causes a seek on $iCur to the row with rowid $iRowid.
150293**
148564** However, if the scan currently being coded is a branch of an OR-loop and 150294** However, if the scan currently being coded is a branch of an OR-loop and
148565** the statement currently being coded is a SELECT, then P3 of OP_DeferredSeek 150295** the statement currently being coded is a SELECT, then additional information
148566** is set to iIdxCur and P4 is set to point to an array of integers 150296** is added that might allow OP_Column to omit the seek and instead do its
148567** containing one entry for each column of the table cursor iCur is open 150297** lookup on the index, thus avoiding an expensive seek operation. To
148568** on. For each table column, if the column is the i'th column of the 150298** enable this optimization, the P3 of OP_DeferredSeek is set to iIdxCur
148569** index, then the corresponding array entry is set to (i+1). If the column 150299** and P4 is set to an array of integers containing one entry for each column
148570** does not appear in the index at all, the array entry is set to 0. 150300** in the table. For each table column, if the column is the i'th
150301** column of the index, then the corresponding array entry is set to (i+1).
150302** If the column does not appear in the index at all, the array entry is set
150303** to 0. The OP_Column opcode can check this array to see if the column it
150304** wants is in the index and if it is, it will substitute the index cursor
150305** and column number and continue with those new values, rather than seeking
150306** the table cursor.
148571*/ 150307*/
148572static void codeDeferredSeek( 150308static void codeDeferredSeek(
148573 WhereInfo *pWInfo, /* Where clause context */ 150309 WhereInfo *pWInfo, /* Where clause context */
@@ -148583,7 +150319,7 @@ static void codeDeferredSeek(
148583 150319
148584 pWInfo->bDeferredSeek = 1; 150320 pWInfo->bDeferredSeek = 1;
148585 sqlite3VdbeAddOp3(v, OP_DeferredSeek, iIdxCur, 0, iCur); 150321 sqlite3VdbeAddOp3(v, OP_DeferredSeek, iIdxCur, 0, iCur);
148586 if( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE) 150322 if( (pWInfo->wctrlFlags & (WHERE_OR_SUBCLAUSE|WHERE_RIGHT_JOIN))
148587 && DbMaskAllZero(sqlite3ParseToplevel(pParse)->writeMask) 150323 && DbMaskAllZero(sqlite3ParseToplevel(pParse)->writeMask)
148588 ){ 150324 ){
148589 int i; 150325 int i;
@@ -148677,12 +150413,12 @@ static void preserveExpr(IdxExprTrans *pTrans, Expr *pExpr){
148677static int whereIndexExprTransNode(Walker *p, Expr *pExpr){ 150413static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
148678 IdxExprTrans *pX = p->u.pIdxTrans; 150414 IdxExprTrans *pX = p->u.pIdxTrans;
148679 if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){ 150415 if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
150416 pExpr = sqlite3ExprSkipCollate(pExpr);
148680 preserveExpr(pX, pExpr); 150417 preserveExpr(pX, pExpr);
148681 pExpr->affExpr = sqlite3ExprAffinity(pExpr); 150418 pExpr->affExpr = sqlite3ExprAffinity(pExpr);
148682 pExpr->op = TK_COLUMN; 150419 pExpr->op = TK_COLUMN;
148683 pExpr->iTable = pX->iIdxCur; 150420 pExpr->iTable = pX->iIdxCur;
148684 pExpr->iColumn = pX->iIdxCol; 150421 pExpr->iColumn = pX->iIdxCol;
148685 testcase( ExprHasProperty(pExpr, EP_Skip) );
148686 testcase( ExprHasProperty(pExpr, EP_Unlikely) ); 150422 testcase( ExprHasProperty(pExpr, EP_Unlikely) );
148687 ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn); 150423 ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn);
148688 pExpr->y.pTab = 0; 150424 pExpr->y.pTab = 0;
@@ -148836,6 +150572,8 @@ static SQLITE_NOINLINE void filterPullDown(
148836 /* ,--- Because sqlite3ConstructBloomFilter() has will not have set 150572 /* ,--- Because sqlite3ConstructBloomFilter() has will not have set
148837 ** vvvvv--' pLevel->regFilter if this were true. */ 150573 ** vvvvv--' pLevel->regFilter if this were true. */
148838 if( NEVER(pLoop->prereq & notReady) ) continue; 150574 if( NEVER(pLoop->prereq & notReady) ) continue;
150575 assert( pLevel->addrBrk==0 );
150576 pLevel->addrBrk = addrNxt;
148839 if( pLoop->wsFlags & WHERE_IPK ){ 150577 if( pLoop->wsFlags & WHERE_IPK ){
148840 WhereTerm *pTerm = pLoop->aLTerm[0]; 150578 WhereTerm *pTerm = pLoop->aLTerm[0];
148841 int regRowid; 150579 int regRowid;
@@ -148862,6 +150600,7 @@ static SQLITE_NOINLINE void filterPullDown(
148862 VdbeCoverage(pParse->pVdbe); 150600 VdbeCoverage(pParse->pVdbe);
148863 } 150601 }
148864 pLevel->regFilter = 0; 150602 pLevel->regFilter = 0;
150603 pLevel->addrBrk = 0;
148865 } 150604 }
148866} 150605}
148867 150606
@@ -148935,7 +150674,7 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
148935 ** initialize a memory cell that records if this table matches any 150674 ** initialize a memory cell that records if this table matches any
148936 ** row of the left table of the join. 150675 ** row of the left table of the join.
148937 */ 150676 */
148938 assert( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE) 150677 assert( (pWInfo->wctrlFlags & (WHERE_OR_SUBCLAUSE|WHERE_RIGHT_JOIN))
148939 || pLevel->iFrom>0 || (pTabItem[0].fg.jointype & JT_LEFT)==0 150678 || pLevel->iFrom>0 || (pTabItem[0].fg.jointype & JT_LEFT)==0
148940 ); 150679 );
148941 if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){ 150680 if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
@@ -148946,7 +150685,10 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
148946 150685
148947 /* Compute a safe address to jump to if we discover that the table for 150686 /* Compute a safe address to jump to if we discover that the table for
148948 ** this loop is empty and can never contribute content. */ 150687 ** this loop is empty and can never contribute content. */
148949 for(j=iLevel; j>0 && pWInfo->a[j].iLeftJoin==0; j--){} 150688 for(j=iLevel; j>0; j--){
150689 if( pWInfo->a[j].iLeftJoin ) break;
150690 if( pWInfo->a[j].pRJ ) break;
150691 }
148950 addrHalt = pWInfo->a[j].addrBrk; 150692 addrHalt = pWInfo->a[j].addrBrk;
148951 150693
148952 /* Special case of a FROM clause subquery implemented as a co-routine */ 150694 /* Special case of a FROM clause subquery implemented as a co-routine */
@@ -149573,7 +151315,7 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
149573 151315
149574 /* Seek the table cursor, if required */ 151316 /* Seek the table cursor, if required */
149575 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0 151317 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
149576 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0; 151318 && (pWInfo->wctrlFlags & (WHERE_OR_SUBCLAUSE|WHERE_RIGHT_JOIN))==0;
149577 if( omitTable ){ 151319 if( omitTable ){
149578 /* pIdx is a covering index. No need to access the main table. */ 151320 /* pIdx is a covering index. No need to access the main table. */
149579 }else if( HasRowid(pIdx->pTable) ){ 151321 }else if( HasRowid(pIdx->pTable) ){
@@ -149607,7 +151349,7 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
149607 ** move forward to the next index. 151349 ** move forward to the next index.
149608 ** https://sqlite.org/src/info/4e8e4857d32d401f 151350 ** https://sqlite.org/src/info/4e8e4857d32d401f
149609 */ 151351 */
149610 if( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ){ 151352 if( (pWInfo->wctrlFlags & (WHERE_OR_SUBCLAUSE|WHERE_RIGHT_JOIN))==0 ){
149611 whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo); 151353 whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
149612 } 151354 }
149613 151355
@@ -149626,7 +151368,7 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
149626 /* The following assert() is not a requirement, merely an observation: 151368 /* The following assert() is not a requirement, merely an observation:
149627 ** The OR-optimization doesn't work for the right hand table of 151369 ** The OR-optimization doesn't work for the right hand table of
149628 ** a LEFT JOIN: */ 151370 ** a LEFT JOIN: */
149629 assert( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ); 151371 assert( (pWInfo->wctrlFlags & (WHERE_OR_SUBCLAUSE|WHERE_RIGHT_JOIN))==0 );
149630 } 151372 }
149631 151373
149632 /* Record the instruction used to terminate the loop. */ 151374 /* Record the instruction used to terminate the loop. */
@@ -149830,7 +151572,7 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
149830 Expr *pDelete; /* Local copy of OR clause term */ 151572 Expr *pDelete; /* Local copy of OR clause term */
149831 int jmp1 = 0; /* Address of jump operation */ 151573 int jmp1 = 0; /* Address of jump operation */
149832 testcase( (pTabItem[0].fg.jointype & JT_LEFT)!=0 151574 testcase( (pTabItem[0].fg.jointype & JT_LEFT)!=0
149833 && !ExprHasProperty(pOrExpr, EP_FromJoin) 151575 && !ExprHasProperty(pOrExpr, EP_OuterON)
149834 ); /* See TH3 vtab25.400 and ticket 614b25314c766238 */ 151576 ); /* See TH3 vtab25.400 and ticket 614b25314c766238 */
149835 pDelete = pOrExpr = sqlite3ExprDup(db, pOrExpr, 0); 151577 pDelete = pOrExpr = sqlite3ExprDup(db, pOrExpr, 0);
149836 if( db->mallocFailed ){ 151578 if( db->mallocFailed ){
@@ -149968,6 +151710,14 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
149968 sqlite3VdbeGoto(v, pLevel->addrBrk); 151710 sqlite3VdbeGoto(v, pLevel->addrBrk);
149969 sqlite3VdbeResolveLabel(v, iLoopBody); 151711 sqlite3VdbeResolveLabel(v, iLoopBody);
149970 151712
151713 /* Set the P2 operand of the OP_Return opcode that will end the current
151714 ** loop to point to this spot, which is the top of the next containing
151715 ** loop. The byte-code formatter will use that P2 value as a hint to
151716 ** indent everything in between the this point and the final OP_Return.
151717 ** See tag-20220407a in vdbe.c and shell.c */
151718 assert( pLevel->op==OP_Return );
151719 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
151720
149971 if( pWInfo->nLevel>1 ){ sqlite3StackFree(db, pOrTab); } 151721 if( pWInfo->nLevel>1 ){ sqlite3StackFree(db, pOrTab); }
149972 if( !untestedTerms ) disableTerm(pLevel, pTerm); 151722 if( !untestedTerms ) disableTerm(pLevel, pTerm);
149973 }else 151723 }else
@@ -150030,10 +151780,22 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
150030 } 151780 }
150031 pE = pTerm->pExpr; 151781 pE = pTerm->pExpr;
150032 assert( pE!=0 ); 151782 assert( pE!=0 );
150033 if( (pTabItem->fg.jointype&JT_LEFT) && !ExprHasProperty(pE,EP_FromJoin) ){ 151783 if( pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT) ){
150034 continue; 151784 if( !ExprHasProperty(pE,EP_OuterON|EP_InnerON) ){
151785 /* Defer processing WHERE clause constraints until after outer
151786 ** join processing. tag-20220513a */
151787 continue;
151788 }else if( (pTabItem->fg.jointype & JT_LEFT)==JT_LEFT
151789 && !ExprHasProperty(pE,EP_OuterON) ){
151790 continue;
151791 }else{
151792 Bitmask m = sqlite3WhereGetMask(&pWInfo->sMaskSet, pE->w.iJoin);
151793 if( m & pLevel->notReady ){
151794 /* An ON clause that is not ripe */
151795 continue;
151796 }
151797 }
150035 } 151798 }
150036
150037 if( iLoop==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){ 151799 if( iLoop==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
150038 iNext = 2; 151800 iNext = 2;
150039 continue; 151801 continue;
@@ -150092,7 +151854,7 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
150092 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) continue; 151854 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) continue;
150093 if( (pTerm->eOperator & WO_EQUIV)==0 ) continue; 151855 if( (pTerm->eOperator & WO_EQUIV)==0 ) continue;
150094 if( pTerm->leftCursor!=iCur ) continue; 151856 if( pTerm->leftCursor!=iCur ) continue;
150095 if( pTabItem->fg.jointype & JT_LEFT ) continue; 151857 if( pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT) ) continue;
150096 pE = pTerm->pExpr; 151858 pE = pTerm->pExpr;
150097#ifdef WHERETRACE_ENABLED /* 0x800 */ 151859#ifdef WHERETRACE_ENABLED /* 0x800 */
150098 if( sqlite3WhereTrace & 0x800 ){ 151860 if( sqlite3WhereTrace & 0x800 ){
@@ -150100,7 +151862,7 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
150100 sqlite3WhereTermPrint(pTerm, pWC->nTerm-j); 151862 sqlite3WhereTermPrint(pTerm, pWC->nTerm-j);
150101 } 151863 }
150102#endif 151864#endif
150103 assert( !ExprHasProperty(pE, EP_FromJoin) ); 151865 assert( !ExprHasProperty(pE, EP_OuterON) );
150104 assert( (pTerm->prereqRight & pLevel->notReady)!=0 ); 151866 assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
150105 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); 151867 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
150106 pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.x.leftColumn, notReady, 151868 pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.x.leftColumn, notReady,
@@ -150123,6 +151885,47 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
150123 pAlt->wtFlags |= TERM_CODED; 151885 pAlt->wtFlags |= TERM_CODED;
150124 } 151886 }
150125 151887
151888 /* For a RIGHT OUTER JOIN, record the fact that the current row has
151889 ** been matched at least once.
151890 */
151891 if( pLevel->pRJ ){
151892 Table *pTab;
151893 int nPk;
151894 int r;
151895 int jmp1 = 0;
151896 WhereRightJoin *pRJ = pLevel->pRJ;
151897
151898 /* pTab is the right-hand table of the RIGHT JOIN. Generate code that
151899 ** will record that the current row of that table has been matched at
151900 ** least once. This is accomplished by storing the PK for the row in
151901 ** both the iMatch index and the regBloom Bloom filter.
151902 */
151903 pTab = pWInfo->pTabList->a[pLevel->iFrom].pTab;
151904 if( HasRowid(pTab) ){
151905 r = sqlite3GetTempRange(pParse, 2);
151906 sqlite3ExprCodeGetColumnOfTable(v, pTab, pLevel->iTabCur, -1, r+1);
151907 nPk = 1;
151908 }else{
151909 int iPk;
151910 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
151911 nPk = pPk->nKeyCol;
151912 r = sqlite3GetTempRange(pParse, nPk+1);
151913 for(iPk=0; iPk<nPk; iPk++){
151914 int iCol = pPk->aiColumn[iPk];
151915 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, iCol,r+1+iPk);
151916 }
151917 }
151918 jmp1 = sqlite3VdbeAddOp4Int(v, OP_Found, pRJ->iMatch, 0, r+1, nPk);
151919 VdbeCoverage(v);
151920 VdbeComment((v, "match against %s", pTab->zName));
151921 sqlite3VdbeAddOp3(v, OP_MakeRecord, r+1, nPk, r);
151922 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pRJ->iMatch, r, r+1, nPk);
151923 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pRJ->regBloom, 0, r+1, nPk);
151924 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
151925 sqlite3VdbeJumpHere(v, jmp1);
151926 sqlite3ReleaseTempRange(pParse, r, nPk+1);
151927 }
151928
150126 /* For a LEFT OUTER JOIN, generate code that will record the fact that 151929 /* For a LEFT OUTER JOIN, generate code that will record the fact that
150127 ** at least one row of the right table has matched the left table. 151930 ** at least one row of the right table has matched the left table.
150128 */ 151931 */
@@ -150130,6 +151933,30 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
150130 pLevel->addrFirst = sqlite3VdbeCurrentAddr(v); 151933 pLevel->addrFirst = sqlite3VdbeCurrentAddr(v);
150131 sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin); 151934 sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin);
150132 VdbeComment((v, "record LEFT JOIN hit")); 151935 VdbeComment((v, "record LEFT JOIN hit"));
151936 if( pLevel->pRJ==0 ){
151937 goto code_outer_join_constraints; /* WHERE clause constraints */
151938 }
151939 }
151940
151941 if( pLevel->pRJ ){
151942 /* Create a subroutine used to process all interior loops and code
151943 ** of the RIGHT JOIN. During normal operation, the subroutine will
151944 ** be in-line with the rest of the code. But at the end, a separate
151945 ** loop will run that invokes this subroutine for unmatched rows
151946 ** of pTab, with all tables to left begin set to NULL.
151947 */
151948 WhereRightJoin *pRJ = pLevel->pRJ;
151949 sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pRJ->regReturn);
151950 pRJ->addrSubrtn = sqlite3VdbeCurrentAddr(v);
151951 assert( pParse->withinRJSubrtn < 255 );
151952 pParse->withinRJSubrtn++;
151953
151954 /* WHERE clause constraints must be deferred until after outer join
151955 ** row elimination has completed, since WHERE clause constraints apply
151956 ** to the results of the OUTER JOIN. The following loop generates the
151957 ** appropriate WHERE clause constraint checks. tag-20220513a.
151958 */
151959 code_outer_join_constraints:
150133 for(pTerm=pWC->a, j=0; j<pWC->nBase; j++, pTerm++){ 151960 for(pTerm=pWC->a, j=0; j<pWC->nBase; j++, pTerm++){
150134 testcase( pTerm->wtFlags & TERM_VIRTUAL ); 151961 testcase( pTerm->wtFlags & TERM_VIRTUAL );
150135 testcase( pTerm->wtFlags & TERM_CODED ); 151962 testcase( pTerm->wtFlags & TERM_CODED );
@@ -150138,6 +151965,7 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
150138 assert( pWInfo->untestedTerms ); 151965 assert( pWInfo->untestedTerms );
150139 continue; 151966 continue;
150140 } 151967 }
151968 if( pTabItem->fg.jointype & JT_LTORJ ) continue;
150141 assert( pTerm->pExpr ); 151969 assert( pTerm->pExpr );
150142 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL); 151970 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
150143 pTerm->wtFlags |= TERM_CODED; 151971 pTerm->wtFlags |= TERM_CODED;
@@ -150158,6 +151986,96 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
150158 return pLevel->notReady; 151986 return pLevel->notReady;
150159} 151987}
150160 151988
151989/*
151990** Generate the code for the loop that finds all non-matched terms
151991** for a RIGHT JOIN.
151992*/
151993SQLITE_PRIVATE SQLITE_NOINLINE void sqlite3WhereRightJoinLoop(
151994 WhereInfo *pWInfo,
151995 int iLevel,
151996 WhereLevel *pLevel
151997){
151998 Parse *pParse = pWInfo->pParse;
151999 Vdbe *v = pParse->pVdbe;
152000 WhereRightJoin *pRJ = pLevel->pRJ;
152001 Expr *pSubWhere = 0;
152002 WhereClause *pWC = &pWInfo->sWC;
152003 WhereInfo *pSubWInfo;
152004 WhereLoop *pLoop = pLevel->pWLoop;
152005 SrcItem *pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
152006 SrcList sFrom;
152007 Bitmask mAll = 0;
152008 int k;
152009
152010 ExplainQueryPlan((pParse, 1, "RIGHT-JOIN %s", pTabItem->pTab->zName));
152011 sqlite3VdbeNoJumpsOutsideSubrtn(v, pRJ->addrSubrtn, pRJ->endSubrtn,
152012 pRJ->regReturn);
152013 for(k=0; k<iLevel; k++){
152014 int iIdxCur;
152015 mAll |= pWInfo->a[k].pWLoop->maskSelf;
152016 sqlite3VdbeAddOp1(v, OP_NullRow, pWInfo->a[k].iTabCur);
152017 iIdxCur = pWInfo->a[k].iIdxCur;
152018 if( iIdxCur ){
152019 sqlite3VdbeAddOp1(v, OP_NullRow, iIdxCur);
152020 }
152021 }
152022 if( (pTabItem->fg.jointype & JT_LTORJ)==0 ){
152023 mAll |= pLoop->maskSelf;
152024 for(k=0; k<pWC->nTerm; k++){
152025 WhereTerm *pTerm = &pWC->a[k];
152026 if( (pTerm->wtFlags & (TERM_VIRTUAL|TERM_SLICE))!=0
152027 && pTerm->eOperator!=WO_ROWVAL
152028 ){
152029 break;
152030 }
152031 if( pTerm->prereqAll & ~mAll ) continue;
152032 if( ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON) ) continue;
152033 pSubWhere = sqlite3ExprAnd(pParse, pSubWhere,
152034 sqlite3ExprDup(pParse->db, pTerm->pExpr, 0));
152035 }
152036 }
152037 sFrom.nSrc = 1;
152038 sFrom.nAlloc = 1;
152039 memcpy(&sFrom.a[0], pTabItem, sizeof(SrcItem));
152040 sFrom.a[0].fg.jointype = 0;
152041 assert( pParse->withinRJSubrtn < 100 );
152042 pParse->withinRJSubrtn++;
152043 pSubWInfo = sqlite3WhereBegin(pParse, &sFrom, pSubWhere, 0, 0, 0,
152044 WHERE_RIGHT_JOIN, 0);
152045 if( pSubWInfo ){
152046 int iCur = pLevel->iTabCur;
152047 int r = ++pParse->nMem;
152048 int nPk;
152049 int jmp;
152050 int addrCont = sqlite3WhereContinueLabel(pSubWInfo);
152051 Table *pTab = pTabItem->pTab;
152052 if( HasRowid(pTab) ){
152053 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, -1, r);
152054 nPk = 1;
152055 }else{
152056 int iPk;
152057 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
152058 nPk = pPk->nKeyCol;
152059 pParse->nMem += nPk - 1;
152060 for(iPk=0; iPk<nPk; iPk++){
152061 int iCol = pPk->aiColumn[iPk];
152062 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, iCol,r+iPk);
152063 }
152064 }
152065 jmp = sqlite3VdbeAddOp4Int(v, OP_Filter, pRJ->regBloom, 0, r, nPk);
152066 VdbeCoverage(v);
152067 sqlite3VdbeAddOp4Int(v, OP_Found, pRJ->iMatch, addrCont, r, nPk);
152068 VdbeCoverage(v);
152069 sqlite3VdbeJumpHere(v, jmp);
152070 sqlite3VdbeAddOp2(v, OP_Gosub, pRJ->regReturn, pRJ->addrSubrtn);
152071 sqlite3WhereEnd(pSubWInfo);
152072 }
152073 sqlite3ExprDelete(pParse->db, pSubWhere);
152074 ExplainQueryPlanPop(pParse);
152075 assert( pParse->withinRJSubrtn>0 );
152076 pParse->withinRJSubrtn--;
152077}
152078
150161/************** End of wherecode.c *******************************************/ 152079/************** End of wherecode.c *******************************************/
150162/************** Begin file whereexpr.c ***************************************/ 152080/************** Begin file whereexpr.c ***************************************/
150163/* 152081/*
@@ -150226,7 +152144,7 @@ static int whereClauseInsert(WhereClause *pWC, Expr *p, u16 wtFlags){
150226 if( pWC->nTerm>=pWC->nSlot ){ 152144 if( pWC->nTerm>=pWC->nSlot ){
150227 WhereTerm *pOld = pWC->a; 152145 WhereTerm *pOld = pWC->a;
150228 sqlite3 *db = pWC->pWInfo->pParse->db; 152146 sqlite3 *db = pWC->pWInfo->pParse->db;
150229 pWC->a = sqlite3DbMallocRawNN(db, sizeof(pWC->a[0])*pWC->nSlot*2 ); 152147 pWC->a = sqlite3WhereMalloc(pWC->pWInfo, sizeof(pWC->a[0])*pWC->nSlot*2 );
150230 if( pWC->a==0 ){ 152148 if( pWC->a==0 ){
150231 if( wtFlags & TERM_DYNAMIC ){ 152149 if( wtFlags & TERM_DYNAMIC ){
150232 sqlite3ExprDelete(db, p); 152150 sqlite3ExprDelete(db, p);
@@ -150235,10 +152153,7 @@ static int whereClauseInsert(WhereClause *pWC, Expr *p, u16 wtFlags){
150235 return 0; 152153 return 0;
150236 } 152154 }
150237 memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm); 152155 memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm);
150238 if( pOld!=pWC->aStatic ){ 152156 pWC->nSlot = pWC->nSlot*2;
150239 sqlite3DbFree(db, pOld);
150240 }
150241 pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
150242 } 152157 }
150243 pTerm = &pWC->a[idx = pWC->nTerm++]; 152158 pTerm = &pWC->a[idx = pWC->nTerm++];
150244 if( (wtFlags & TERM_VIRTUAL)==0 ) pWC->nBase = pWC->nTerm; 152159 if( (wtFlags & TERM_VIRTUAL)==0 ) pWC->nBase = pWC->nTerm;
@@ -150626,9 +152541,9 @@ static int isAuxiliaryVtabOperator(
150626** a join, then transfer the appropriate markings over to derived. 152541** a join, then transfer the appropriate markings over to derived.
150627*/ 152542*/
150628static void transferJoinMarkings(Expr *pDerived, Expr *pBase){ 152543static void transferJoinMarkings(Expr *pDerived, Expr *pBase){
150629 if( pDerived ){ 152544 if( pDerived && ExprHasProperty(pBase, EP_OuterON|EP_InnerON) ){
150630 pDerived->flags |= pBase->flags & EP_FromJoin; 152545 pDerived->flags |= pBase->flags & (EP_OuterON|EP_InnerON);
150631 pDerived->w.iRightJoinTable = pBase->w.iRightJoinTable; 152546 pDerived->w.iJoin = pBase->w.iJoin;
150632 } 152547 }
150633} 152548}
150634 152549
@@ -151082,7 +152997,7 @@ static int termIsEquivalence(Parse *pParse, Expr *pExpr){
151082 CollSeq *pColl; 152997 CollSeq *pColl;
151083 if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0; 152998 if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0;
151084 if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0; 152999 if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0;
151085 if( ExprHasProperty(pExpr, EP_FromJoin) ) return 0; 153000 if( ExprHasProperty(pExpr, EP_OuterON) ) return 0;
151086 aff1 = sqlite3ExprAffinity(pExpr->pLeft); 153001 aff1 = sqlite3ExprAffinity(pExpr->pLeft);
151087 aff2 = sqlite3ExprAffinity(pExpr->pRight); 153002 aff2 = sqlite3ExprAffinity(pExpr->pRight);
151088 if( aff1!=aff2 153003 if( aff1!=aff2
@@ -151113,7 +153028,9 @@ static Bitmask exprSelectUsage(WhereMaskSet *pMaskSet, Select *pS){
151113 int i; 153028 int i;
151114 for(i=0; i<pSrc->nSrc; i++){ 153029 for(i=0; i<pSrc->nSrc; i++){
151115 mask |= exprSelectUsage(pMaskSet, pSrc->a[i].pSelect); 153030 mask |= exprSelectUsage(pMaskSet, pSrc->a[i].pSelect);
151116 mask |= sqlite3WhereExprUsage(pMaskSet, pSrc->a[i].pOn); 153031 if( pSrc->a[i].fg.isUsing==0 ){
153032 mask |= sqlite3WhereExprUsage(pMaskSet, pSrc->a[i].u3.pOn);
153033 }
151117 if( pSrc->a[i].fg.isTabFunc ){ 153034 if( pSrc->a[i].fg.isTabFunc ){
151118 mask |= sqlite3WhereExprListUsage(pMaskSet, pSrc->a[i].u1.pFuncArg); 153035 mask |= sqlite3WhereExprListUsage(pMaskSet, pSrc->a[i].u1.pFuncArg);
151119 } 153036 }
@@ -151268,18 +153185,32 @@ static void exprAnalyze(
151268 if( prereqAll!=sqlite3WhereExprUsageNN(pMaskSet, pExpr) ){ 153185 if( prereqAll!=sqlite3WhereExprUsageNN(pMaskSet, pExpr) ){
151269 printf("\n*** Incorrect prereqAll computed for:\n"); 153186 printf("\n*** Incorrect prereqAll computed for:\n");
151270 sqlite3TreeViewExpr(0,pExpr,0); 153187 sqlite3TreeViewExpr(0,pExpr,0);
151271 abort(); 153188 assert( 0 );
151272 } 153189 }
151273#endif 153190#endif
151274 153191
151275 if( ExprHasProperty(pExpr, EP_FromJoin) ){ 153192 if( ExprHasProperty(pExpr, EP_OuterON|EP_InnerON) ){
151276 Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->w.iRightJoinTable); 153193 Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->w.iJoin);
151277 prereqAll |= x; 153194 if( ExprHasProperty(pExpr, EP_OuterON) ){
151278 extraRight = x-1; /* ON clause terms may not be used with an index 153195 prereqAll |= x;
151279 ** on left table of a LEFT JOIN. Ticket #3015 */ 153196 extraRight = x-1; /* ON clause terms may not be used with an index
151280 if( (prereqAll>>1)>=x ){ 153197 ** on left table of a LEFT JOIN. Ticket #3015 */
151281 sqlite3ErrorMsg(pParse, "ON clause references tables to its right"); 153198 if( (prereqAll>>1)>=x ){
151282 return; 153199 sqlite3ErrorMsg(pParse, "ON clause references tables to its right");
153200 return;
153201 }
153202 }else if( (prereqAll>>1)>=x ){
153203 /* The ON clause of an INNER JOIN references a table to its right.
153204 ** Most other SQL database engines raise an error. But SQLite versions
153205 ** 3.0 through 3.38 just put the ON clause constraint into the WHERE
153206 ** clause and carried on. Beginning with 3.39, raise an error only
153207 ** if there is a RIGHT or FULL JOIN in the query. This makes SQLite
153208 ** more like other systems, and also preserves legacy. */
153209 if( ALWAYS(pSrc->nSrc>0) && (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
153210 sqlite3ErrorMsg(pParse, "ON clause references tables to its right");
153211 return;
153212 }
153213 ExprClearProperty(pExpr, EP_InnerON);
151283 } 153214 }
151284 } 153215 }
151285 pTerm->prereqAll = prereqAll; 153216 pTerm->prereqAll = prereqAll;
@@ -151347,7 +153278,7 @@ static void exprAnalyze(
151347 pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask; 153278 pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
151348 }else 153279 }else
151349 if( op==TK_ISNULL 153280 if( op==TK_ISNULL
151350 && !ExprHasProperty(pExpr,EP_FromJoin) 153281 && !ExprHasProperty(pExpr,EP_OuterON)
151351 && 0==sqlite3ExprCanBeNull(pLeft) 153282 && 0==sqlite3ExprCanBeNull(pLeft)
151352 ){ 153283 ){
151353 assert( !ExprHasProperty(pExpr, EP_IntValue) ); 153284 assert( !ExprHasProperty(pExpr, EP_IntValue) );
@@ -151418,7 +153349,7 @@ static void exprAnalyze(
151418 else if( pExpr->op==TK_NOTNULL ){ 153349 else if( pExpr->op==TK_NOTNULL ){
151419 if( pExpr->pLeft->op==TK_COLUMN 153350 if( pExpr->pLeft->op==TK_COLUMN
151420 && pExpr->pLeft->iColumn>=0 153351 && pExpr->pLeft->iColumn>=0
151421 && !ExprHasProperty(pExpr, EP_FromJoin) 153352 && !ExprHasProperty(pExpr, EP_OuterON)
151422 ){ 153353 ){
151423 Expr *pNewExpr; 153354 Expr *pNewExpr;
151424 Expr *pLeft = pExpr->pLeft; 153355 Expr *pLeft = pExpr->pLeft;
@@ -151566,7 +153497,7 @@ static void exprAnalyze(
151566 } 153497 }
151567 pTerm = &pWC->a[idxTerm]; 153498 pTerm = &pWC->a[idxTerm];
151568 pTerm->wtFlags |= TERM_CODED|TERM_VIRTUAL; /* Disable the original */ 153499 pTerm->wtFlags |= TERM_CODED|TERM_VIRTUAL; /* Disable the original */
151569 pTerm->eOperator = 0; 153500 pTerm->eOperator = WO_ROWVAL;
151570 } 153501 }
151571 153502
151572 /* If there is a vector IN term - e.g. "(a, b) IN (SELECT ...)" - create 153503 /* If there is a vector IN term - e.g. "(a, b) IN (SELECT ...)" - create
@@ -151622,9 +153553,9 @@ static void exprAnalyze(
151622 Expr *pNewExpr; 153553 Expr *pNewExpr;
151623 pNewExpr = sqlite3PExpr(pParse, TK_MATCH, 153554 pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
151624 0, sqlite3ExprDup(db, pRight, 0)); 153555 0, sqlite3ExprDup(db, pRight, 0));
151625 if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){ 153556 if( ExprHasProperty(pExpr, EP_OuterON) && pNewExpr ){
151626 ExprSetProperty(pNewExpr, EP_FromJoin); 153557 ExprSetProperty(pNewExpr, EP_OuterON);
151627 pNewExpr->w.iRightJoinTable = pExpr->w.iRightJoinTable; 153558 pNewExpr->w.iJoin = pExpr->w.iJoin;
151628 } 153559 }
151629 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC); 153560 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
151630 testcase( idxNew==0 ); 153561 testcase( idxNew==0 );
@@ -151767,7 +153698,7 @@ SQLITE_PRIVATE void sqlite3WhereAddLimit(WhereClause *pWC, Select *p){
151767 /* This term is a vector operation that has been decomposed into 153698 /* This term is a vector operation that has been decomposed into
151768 ** other, subsequent terms. It can be ignored. See tag-20220128a */ 153699 ** other, subsequent terms. It can be ignored. See tag-20220128a */
151769 assert( pWC->a[ii].wtFlags & TERM_VIRTUAL ); 153700 assert( pWC->a[ii].wtFlags & TERM_VIRTUAL );
151770 assert( pWC->a[ii].eOperator==0 ); 153701 assert( pWC->a[ii].eOperator==WO_ROWVAL );
151771 continue; 153702 continue;
151772 } 153703 }
151773 if( pWC->a[ii].leftCursor!=iCsr ) return; 153704 if( pWC->a[ii].leftCursor!=iCsr ) return;
@@ -151779,7 +153710,7 @@ SQLITE_PRIVATE void sqlite3WhereAddLimit(WhereClause *pWC, Select *p){
151779 Expr *pExpr = pOrderBy->a[ii].pExpr; 153710 Expr *pExpr = pOrderBy->a[ii].pExpr;
151780 if( pExpr->op!=TK_COLUMN ) return; 153711 if( pExpr->op!=TK_COLUMN ) return;
151781 if( pExpr->iTable!=iCsr ) return; 153712 if( pExpr->iTable!=iCsr ) return;
151782 if( pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_BIGNULL ) return; 153713 if( pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) return;
151783 } 153714 }
151784 } 153715 }
151785 153716
@@ -151846,9 +153777,6 @@ SQLITE_PRIVATE void sqlite3WhereClauseClear(WhereClause *pWC){
151846 a++; 153777 a++;
151847 } 153778 }
151848 } 153779 }
151849 if( pWC->a!=pWC->aStatic ){
151850 sqlite3DbFree(db, pWC->a);
151851 }
151852} 153780}
151853 153781
151854 153782
@@ -151975,6 +153903,7 @@ SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(
151975 if( pArgs==0 ) return; 153903 if( pArgs==0 ) return;
151976 for(j=k=0; j<pArgs->nExpr; j++){ 153904 for(j=k=0; j<pArgs->nExpr; j++){
151977 Expr *pRhs; 153905 Expr *pRhs;
153906 u32 joinType;
151978 while( k<pTab->nCol && (pTab->aCol[k].colFlags & COLFLAG_HIDDEN)==0 ){k++;} 153907 while( k<pTab->nCol && (pTab->aCol[k].colFlags & COLFLAG_HIDDEN)==0 ){k++;}
151979 if( k>=pTab->nCol ){ 153908 if( k>=pTab->nCol ){
151980 sqlite3ErrorMsg(pParse, "too many arguments on %s() - max %d", 153909 sqlite3ErrorMsg(pParse, "too many arguments on %s() - max %d",
@@ -151991,9 +153920,12 @@ SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(
151991 pRhs = sqlite3PExpr(pParse, TK_UPLUS, 153920 pRhs = sqlite3PExpr(pParse, TK_UPLUS,
151992 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0); 153921 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
151993 pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs); 153922 pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs);
151994 if( pItem->fg.jointype & JT_LEFT ){ 153923 if( pItem->fg.jointype & (JT_LEFT|JT_LTORJ) ){
151995 sqlite3SetJoinExpr(pTerm, pItem->iCursor); 153924 joinType = EP_OuterON;
153925 }else{
153926 joinType = EP_InnerON;
151996 } 153927 }
153928 sqlite3SetJoinExpr(pTerm, pItem->iCursor, joinType);
151997 whereClauseInsert(pWC, pTerm, TERM_DYNAMIC); 153929 whereClauseInsert(pWC, pTerm, TERM_DYNAMIC);
151998 } 153930 }
151999} 153931}
@@ -152104,7 +154036,7 @@ SQLITE_PRIVATE int sqlite3WhereOrderByLimitOptLabel(WhereInfo *pWInfo){
152104 } 154036 }
152105 pInner = &pWInfo->a[pWInfo->nLevel-1]; 154037 pInner = &pWInfo->a[pWInfo->nLevel-1];
152106 assert( pInner->addrNxt!=0 ); 154038 assert( pInner->addrNxt!=0 );
152107 return pInner->addrNxt; 154039 return pInner->pRJ ? pWInfo->iContinue : pInner->addrNxt;
152108} 154040}
152109 154041
152110/* 154042/*
@@ -152255,6 +154187,30 @@ SQLITE_PRIVATE Bitmask sqlite3WhereGetMask(WhereMaskSet *pMaskSet, int iCursor){
152255 return 0; 154187 return 0;
152256} 154188}
152257 154189
154190/* Allocate memory that is automatically freed when pWInfo is freed.
154191*/
154192SQLITE_PRIVATE void *sqlite3WhereMalloc(WhereInfo *pWInfo, u64 nByte){
154193 WhereMemBlock *pBlock;
154194 pBlock = sqlite3DbMallocRawNN(pWInfo->pParse->db, nByte+sizeof(*pBlock));
154195 if( pBlock ){
154196 pBlock->pNext = pWInfo->pMemToFree;
154197 pBlock->sz = nByte;
154198 pWInfo->pMemToFree = pBlock;
154199 pBlock++;
154200 }
154201 return (void*)pBlock;
154202}
154203SQLITE_PRIVATE void *sqlite3WhereRealloc(WhereInfo *pWInfo, void *pOld, u64 nByte){
154204 void *pNew = sqlite3WhereMalloc(pWInfo, nByte);
154205 if( pNew && pOld ){
154206 WhereMemBlock *pOldBlk = (WhereMemBlock*)pOld;
154207 pOldBlk--;
154208 assert( pOldBlk->sz<nByte );
154209 memcpy(pNew, pOld, pOldBlk->sz);
154210 }
154211 return pNew;
154212}
154213
152258/* 154214/*
152259** Create a new mask for cursor iCursor. 154215** Create a new mask for cursor iCursor.
152260** 154216**
@@ -152308,7 +154264,7 @@ static WhereTerm *whereScanNext(WhereScan *pScan){
152308 && (iColumn!=XN_EXPR 154264 && (iColumn!=XN_EXPR
152309 || sqlite3ExprCompareSkip(pTerm->pExpr->pLeft, 154265 || sqlite3ExprCompareSkip(pTerm->pExpr->pLeft,
152310 pScan->pIdxExpr,iCur)==0) 154266 pScan->pIdxExpr,iCur)==0)
152311 && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin)) 154267 && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_OuterON))
152312 ){ 154268 ){
152313 if( (pTerm->eOperator & WO_EQUIV)!=0 154269 if( (pTerm->eOperator & WO_EQUIV)!=0
152314 && pScan->nEquiv<ArraySize(pScan->aiCur) 154270 && pScan->nEquiv<ArraySize(pScan->aiCur)
@@ -152660,6 +154616,7 @@ static void translateColumnToCopy(
152660 pOp->p1 = pOp->p2 + iRegister; 154616 pOp->p1 = pOp->p2 + iRegister;
152661 pOp->p2 = pOp->p3; 154617 pOp->p2 = pOp->p3;
152662 pOp->p3 = 0; 154618 pOp->p3 = 0;
154619 pOp->p5 = 2; /* Cause the MEM_Subtype flag to be cleared */
152663 }else if( pOp->opcode==OP_Rowid ){ 154620 }else if( pOp->opcode==OP_Rowid ){
152664 pOp->opcode = OP_Sequence; 154621 pOp->opcode = OP_Sequence;
152665 pOp->p1 = iAutoidxCur; 154622 pOp->p1 = iAutoidxCur;
@@ -152734,14 +154691,17 @@ static int termCanDriveIndex(
152734 char aff; 154691 char aff;
152735 if( pTerm->leftCursor!=pSrc->iCursor ) return 0; 154692 if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
152736 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0; 154693 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0;
152737 if( (pSrc->fg.jointype & JT_LEFT) 154694 assert( (pSrc->fg.jointype & JT_RIGHT)==0 );
152738 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) 154695 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0 ){
152739 && (pTerm->eOperator & WO_IS) 154696 testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LEFT );
152740 ){ 154697 testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LTORJ );
152741 /* Cannot use an IS term from the WHERE clause as an index driver for 154698 testcase( ExprHasProperty(pTerm->pExpr, EP_OuterON) )
152742 ** the RHS of a LEFT JOIN. Such a term can only be used if it is from 154699 testcase( ExprHasProperty(pTerm->pExpr, EP_InnerON) );
152743 ** the ON clause. */ 154700 if( !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON)
152744 return 0; 154701 || pTerm->pExpr->w.iJoin != pSrc->iCursor
154702 ){
154703 return 0; /* See tag-20191211-001 */
154704 }
152745 } 154705 }
152746 if( (pTerm->prereqRight & notReady)!=0 ) return 0; 154706 if( (pTerm->prereqRight & notReady)!=0 ) return 0;
152747 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); 154707 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
@@ -152810,8 +154770,7 @@ static SQLITE_NOINLINE void constructAutomaticIndex(
152810 ** WHERE clause (or the ON clause of a LEFT join) that constrain which 154770 ** WHERE clause (or the ON clause of a LEFT join) that constrain which
152811 ** rows of the target table (pSrc) that can be used. */ 154771 ** rows of the target table (pSrc) that can be used. */
152812 if( (pTerm->wtFlags & TERM_VIRTUAL)==0 154772 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
152813 && ((pSrc->fg.jointype&JT_LEFT)==0 || ExprHasProperty(pExpr,EP_FromJoin)) 154773 && sqlite3ExprIsTableConstraint(pExpr, pSrc)
152814 && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor)
152815 ){ 154774 ){
152816 pPartial = sqlite3ExprAnd(pParse, pPartial, 154775 pPartial = sqlite3ExprAnd(pParse, pPartial,
152817 sqlite3ExprDup(pParse->db, pExpr, 0)); 154776 sqlite3ExprDup(pParse->db, pExpr, 0));
@@ -153050,7 +155009,7 @@ static SQLITE_NOINLINE void sqlite3ConstructBloomFilter(
153050 for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){ 155009 for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){
153051 Expr *pExpr = pTerm->pExpr; 155010 Expr *pExpr = pTerm->pExpr;
153052 if( (pTerm->wtFlags & TERM_VIRTUAL)==0 155011 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
153053 && sqlite3ExprIsTableConstant(pExpr, iCur) 155012 && sqlite3ExprIsTableConstraint(pExpr, pItem)
153054 ){ 155013 ){
153055 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL); 155014 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
153056 } 155015 }
@@ -153083,7 +155042,7 @@ static SQLITE_NOINLINE void sqlite3ConstructBloomFilter(
153083 const SrcItem *pTabItem; 155042 const SrcItem *pTabItem;
153084 pLevel = &pWInfo->a[iLevel]; 155043 pLevel = &pWInfo->a[iLevel];
153085 pTabItem = &pWInfo->pTabList->a[pLevel->iFrom]; 155044 pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
153086 if( pTabItem->fg.jointype & JT_LEFT ) continue; 155045 if( pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ) ) continue;
153087 pLoop = pLevel->pWLoop; 155046 pLoop = pLevel->pWLoop;
153088 if( NEVER(pLoop==0) ) continue; 155047 if( NEVER(pLoop==0) ) continue;
153089 if( pLoop->prereq & notReady ) continue; 155048 if( pLoop->prereq & notReady ) continue;
@@ -153156,12 +155115,20 @@ static sqlite3_index_info *allocateIndexInfo(
153156 assert( pTerm->u.x.leftColumn<pTab->nCol ); 155115 assert( pTerm->u.x.leftColumn<pTab->nCol );
153157 155116
153158 /* tag-20191211-002: WHERE-clause constraints are not useful to the 155117 /* tag-20191211-002: WHERE-clause constraints are not useful to the
153159 ** right-hand table of a LEFT JOIN. See tag-20191211-001 for the 155118 ** right-hand table of a LEFT JOIN nor to the either table of a
155119 ** RIGHT JOIN. See tag-20191211-001 for the
153160 ** equivalent restriction for ordinary tables. */ 155120 ** equivalent restriction for ordinary tables. */
153161 if( (pSrc->fg.jointype & JT_LEFT)!=0 155121 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0 ){
153162 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) 155122 testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LEFT );
153163 ){ 155123 testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_RIGHT );
153164 continue; 155124 testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LTORJ );
155125 testcase( ExprHasProperty(pTerm->pExpr, EP_OuterON) );
155126 testcase( ExprHasProperty(pTerm->pExpr, EP_InnerON) );
155127 if( !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON)
155128 || pTerm->pExpr->w.iJoin != pSrc->iCursor
155129 ){
155130 continue;
155131 }
153165 } 155132 }
153166 nTerm++; 155133 nTerm++;
153167 pTerm->wtFlags |= TERM_OK; 155134 pTerm->wtFlags |= TERM_OK;
@@ -153184,7 +155151,7 @@ static sqlite3_index_info *allocateIndexInfo(
153184 } 155151 }
153185 155152
153186 /* Virtual tables are unable to deal with NULLS FIRST */ 155153 /* Virtual tables are unable to deal with NULLS FIRST */
153187 if( pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL ) break; 155154 if( pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) break;
153188 155155
153189 /* First case - a direct column references without a COLLATE operator */ 155156 /* First case - a direct column references without a COLLATE operator */
153190 if( pExpr->op==TK_COLUMN && pExpr->iTable==pSrc->iCursor ){ 155157 if( pExpr->op==TK_COLUMN && pExpr->iTable==pSrc->iCursor ){
@@ -153214,8 +155181,10 @@ static sqlite3_index_info *allocateIndexInfo(
153214 } 155181 }
153215 if( i==n ){ 155182 if( i==n ){
153216 nOrderBy = n; 155183 nOrderBy = n;
153217 if( (pWInfo->wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY)) ){ 155184 if( (pWInfo->wctrlFlags & WHERE_DISTINCTBY) ){
153218 eDistinct = 1 + ((pWInfo->wctrlFlags & WHERE_DISTINCTBY)!=0); 155185 eDistinct = 2 + ((pWInfo->wctrlFlags & WHERE_SORTBYGROUP)!=0);
155186 }else if( pWInfo->wctrlFlags & WHERE_GROUPBY ){
155187 eDistinct = 1;
153219 } 155188 }
153220 } 155189 }
153221 } 155190 }
@@ -153294,7 +155263,7 @@ static sqlite3_index_info *allocateIndexInfo(
153294 || (pExpr->op==TK_COLLATE && pExpr->pLeft->op==TK_COLUMN 155263 || (pExpr->op==TK_COLLATE && pExpr->pLeft->op==TK_COLUMN
153295 && pExpr->iColumn==pExpr->pLeft->iColumn) ); 155264 && pExpr->iColumn==pExpr->pLeft->iColumn) );
153296 pIdxOrderBy[j].iColumn = pExpr->iColumn; 155265 pIdxOrderBy[j].iColumn = pExpr->iColumn;
153297 pIdxOrderBy[j].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC; 155266 pIdxOrderBy[j].desc = pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC;
153298 j++; 155267 j++;
153299 } 155268 }
153300 pIdxInfo->nOrderBy = j; 155269 pIdxInfo->nOrderBy = j;
@@ -153398,7 +155367,7 @@ static int whereKeyStats(
153398#endif 155367#endif
153399 assert( pRec!=0 ); 155368 assert( pRec!=0 );
153400 assert( pIdx->nSample>0 ); 155369 assert( pIdx->nSample>0 );
153401 assert( pRec->nField>0 && pRec->nField<=pIdx->nSampleCol ); 155370 assert( pRec->nField>0 );
153402 155371
153403 /* Do a binary search to find the first sample greater than or equal 155372 /* Do a binary search to find the first sample greater than or equal
153404 ** to pRec. If pRec contains a single field, the set of samples to search 155373 ** to pRec. If pRec contains a single field, the set of samples to search
@@ -153444,7 +155413,7 @@ static int whereKeyStats(
153444 ** it is extended to two fields. The duplicates that this creates do not 155413 ** it is extended to two fields. The duplicates that this creates do not
153445 ** cause any problems. 155414 ** cause any problems.
153446 */ 155415 */
153447 nField = pRec->nField; 155416 nField = MIN(pRec->nField, pIdx->nSample);
153448 iCol = 0; 155417 iCol = 0;
153449 iSample = pIdx->nSample * nField; 155418 iSample = pIdx->nSample * nField;
153450 do{ 155419 do{
@@ -154035,7 +156004,7 @@ SQLITE_PRIVATE void sqlite3WhereTermPrint(WhereTerm *pTerm, int iTerm){
154035 memcpy(zType, "....", 5); 156004 memcpy(zType, "....", 5);
154036 if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V'; 156005 if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
154037 if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E'; 156006 if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
154038 if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L'; 156007 if( ExprHasProperty(pTerm->pExpr, EP_OuterON) ) zType[2] = 'L';
154039 if( pTerm->wtFlags & TERM_CODED ) zType[3] = 'C'; 156008 if( pTerm->wtFlags & TERM_CODED ) zType[3] = 'C';
154040 if( pTerm->eOperator & WO_SINGLE ){ 156009 if( pTerm->eOperator & WO_SINGLE ){
154041 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); 156010 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
@@ -154216,15 +156185,7 @@ static void whereLoopDelete(sqlite3 *db, WhereLoop *p){
154216** Free a WhereInfo structure 156185** Free a WhereInfo structure
154217*/ 156186*/
154218static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){ 156187static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
154219 int i;
154220 assert( pWInfo!=0 ); 156188 assert( pWInfo!=0 );
154221 for(i=0; i<pWInfo->nLevel; i++){
154222 WhereLevel *pLevel = &pWInfo->a[i];
154223 if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE)!=0 ){
154224 assert( (pLevel->pWLoop->wsFlags & WHERE_MULTI_OR)==0 );
154225 sqlite3DbFree(db, pLevel->u.in.aInLoop);
154226 }
154227 }
154228 sqlite3WhereClauseClear(&pWInfo->sWC); 156189 sqlite3WhereClauseClear(&pWInfo->sWC);
154229 while( pWInfo->pLoops ){ 156190 while( pWInfo->pLoops ){
154230 WhereLoop *p = pWInfo->pLoops; 156191 WhereLoop *p = pWInfo->pLoops;
@@ -154232,6 +156193,11 @@ static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
154232 whereLoopDelete(db, p); 156193 whereLoopDelete(db, p);
154233 } 156194 }
154234 assert( pWInfo->pExprMods==0 ); 156195 assert( pWInfo->pExprMods==0 );
156196 while( pWInfo->pMemToFree ){
156197 WhereMemBlock *pNext = pWInfo->pMemToFree->pNext;
156198 sqlite3DbFreeNN(db, pWInfo->pMemToFree);
156199 pWInfo->pMemToFree = pNext;
156200 }
154235 sqlite3DbFreeNN(db, pWInfo); 156201 sqlite3DbFreeNN(db, pWInfo);
154236} 156202}
154237 156203
@@ -154600,10 +156566,11 @@ static void whereLoopOutputAdjust(
154600 ** 156566 **
154601 ** 2022-03-24: Self-culling only applies if either the extra terms 156567 ** 2022-03-24: Self-culling only applies if either the extra terms
154602 ** are straight comparison operators that are non-true with NULL 156568 ** are straight comparison operators that are non-true with NULL
154603 ** operand, or if the loop is not a LEFT JOIN. 156569 ** operand, or if the loop is not an OUTER JOIN.
154604 */ 156570 */
154605 if( (pTerm->eOperator & 0x3f)!=0 156571 if( (pTerm->eOperator & 0x3f)!=0
154606 || (pWC->pWInfo->pTabList->a[pLoop->iTab].fg.jointype & JT_LEFT)==0 156572 || (pWC->pWInfo->pTabList->a[pLoop->iTab].fg.jointype
156573 & (JT_LEFT|JT_LTORJ))==0
154607 ){ 156574 ){
154608 pLoop->wsFlags |= WHERE_SELFCULL; 156575 pLoop->wsFlags |= WHERE_SELFCULL;
154609 } 156576 }
@@ -154810,12 +156777,29 @@ static int whereLoopAddBtreeIndex(
154810 if( pTerm->wtFlags & TERM_LIKEOPT && pTerm->eOperator==WO_LT ) continue; 156777 if( pTerm->wtFlags & TERM_LIKEOPT && pTerm->eOperator==WO_LT ) continue;
154811 156778
154812 /* tag-20191211-001: Do not allow constraints from the WHERE clause to 156779 /* tag-20191211-001: Do not allow constraints from the WHERE clause to
154813 ** be used by the right table of a LEFT JOIN. Only constraints in the 156780 ** be used by the right table of a LEFT JOIN nor by the left table of a
154814 ** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */ 156781 ** RIGHT JOIN. Only constraints in the ON clause are allowed.
154815 if( (pSrc->fg.jointype & JT_LEFT)!=0 156782 ** See tag-20191211-002 for the vtab equivalent.
154816 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) 156783 **
154817 ){ 156784 ** 2022-06-06: See https://sqlite.org/forum/forumpost/206d99a16dd9212f
154818 continue; 156785 ** for an example of a WHERE clause constraints that may not be used on
156786 ** the right table of a RIGHT JOIN because the constraint implies a
156787 ** not-NULL condition on the left table of the RIGHT JOIN.
156788 **
156789 ** 2022-06-10: The same condition applies to termCanDriveIndex() above.
156790 ** https://sqlite.org/forum/forumpost/51e6959f61
156791 */
156792 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0 ){
156793 testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LEFT );
156794 testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_RIGHT );
156795 testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LTORJ );
156796 testcase( ExprHasProperty(pTerm->pExpr, EP_OuterON) )
156797 testcase( ExprHasProperty(pTerm->pExpr, EP_InnerON) );
156798 if( !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON)
156799 || pTerm->pExpr->w.iJoin != pSrc->iCursor
156800 ){
156801 continue;
156802 }
154819 } 156803 }
154820 156804
154821 if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){ 156805 if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
@@ -155167,23 +157151,26 @@ static int indexMightHelpWithOrderBy(
155167*/ 157151*/
155168static int whereUsablePartialIndex( 157152static int whereUsablePartialIndex(
155169 int iTab, /* The table for which we want an index */ 157153 int iTab, /* The table for which we want an index */
155170 int isLeft, /* True if iTab is the right table of a LEFT JOIN */ 157154 u8 jointype, /* The JT_* flags on the join */
155171 WhereClause *pWC, /* The WHERE clause of the query */ 157155 WhereClause *pWC, /* The WHERE clause of the query */
155172 Expr *pWhere /* The WHERE clause from the partial index */ 157156 Expr *pWhere /* The WHERE clause from the partial index */
155173){ 157157){
155174 int i; 157158 int i;
155175 WhereTerm *pTerm; 157159 WhereTerm *pTerm;
155176 Parse *pParse = pWC->pWInfo->pParse; 157160 Parse *pParse;
157161
157162 if( jointype & JT_LTORJ ) return 0;
157163 pParse = pWC->pWInfo->pParse;
155177 while( pWhere->op==TK_AND ){ 157164 while( pWhere->op==TK_AND ){
155178 if( !whereUsablePartialIndex(iTab,isLeft,pWC,pWhere->pLeft) ) return 0; 157165 if( !whereUsablePartialIndex(iTab,jointype,pWC,pWhere->pLeft) ) return 0;
155179 pWhere = pWhere->pRight; 157166 pWhere = pWhere->pRight;
155180 } 157167 }
155181 if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0; 157168 if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0;
155182 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){ 157169 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
155183 Expr *pExpr; 157170 Expr *pExpr;
155184 pExpr = pTerm->pExpr; 157171 pExpr = pTerm->pExpr;
155185 if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->w.iRightJoinTable==iTab) 157172 if( (!ExprHasProperty(pExpr, EP_OuterON) || pExpr->w.iJoin==iTab)
155186 && (isLeft==0 || ExprHasProperty(pExpr, EP_FromJoin)) 157173 && ((jointype & JT_OUTER)==0 || ExprHasProperty(pExpr, EP_OuterON))
155187 && sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab) 157174 && sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
155188 && (pTerm->wtFlags & TERM_VNULL)==0 157175 && (pTerm->wtFlags & TERM_VNULL)==0
155189 ){ 157176 ){
@@ -155292,13 +157279,14 @@ static int whereLoopAddBtree(
155292#ifndef SQLITE_OMIT_AUTOMATIC_INDEX 157279#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
155293 /* Automatic indexes */ 157280 /* Automatic indexes */
155294 if( !pBuilder->pOrSet /* Not part of an OR optimization */ 157281 if( !pBuilder->pOrSet /* Not part of an OR optimization */
155295 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 157282 && (pWInfo->wctrlFlags & (WHERE_RIGHT_JOIN|WHERE_OR_SUBCLAUSE))==0
155296 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0 157283 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
155297 && !pSrc->fg.isIndexedBy /* Has no INDEXED BY clause */ 157284 && !pSrc->fg.isIndexedBy /* Has no INDEXED BY clause */
155298 && !pSrc->fg.notIndexed /* Has no NOT INDEXED clause */ 157285 && !pSrc->fg.notIndexed /* Has no NOT INDEXED clause */
155299 && HasRowid(pTab) /* Not WITHOUT ROWID table. (FIXME: Why not?) */ 157286 && HasRowid(pTab) /* Not WITHOUT ROWID table. (FIXME: Why not?) */
155300 && !pSrc->fg.isCorrelated /* Not a correlated subquery */ 157287 && !pSrc->fg.isCorrelated /* Not a correlated subquery */
155301 && !pSrc->fg.isRecursive /* Not a recursive common table expression. */ 157288 && !pSrc->fg.isRecursive /* Not a recursive common table expression. */
157289 && (pSrc->fg.jointype & JT_RIGHT)==0 /* Not the right tab of a RIGHT JOIN */
155302 ){ 157290 ){
155303 /* Generate auto-index WhereLoops */ 157291 /* Generate auto-index WhereLoops */
155304 LogEst rLogSize; /* Logarithm of the number of rows in the table */ 157292 LogEst rLogSize; /* Logarithm of the number of rows in the table */
@@ -155348,9 +157336,8 @@ static int whereLoopAddBtree(
155348 for(; rc==SQLITE_OK && pProbe; 157336 for(; rc==SQLITE_OK && pProbe;
155349 pProbe=(pSrc->fg.isIndexedBy ? 0 : pProbe->pNext), iSortIdx++ 157337 pProbe=(pSrc->fg.isIndexedBy ? 0 : pProbe->pNext), iSortIdx++
155350 ){ 157338 ){
155351 int isLeft = (pSrc->fg.jointype & JT_OUTER)!=0;
155352 if( pProbe->pPartIdxWhere!=0 157339 if( pProbe->pPartIdxWhere!=0
155353 && !whereUsablePartialIndex(pSrc->iCursor, isLeft, pWC, 157340 && !whereUsablePartialIndex(pSrc->iCursor, pSrc->fg.jointype, pWC,
155354 pProbe->pPartIdxWhere) 157341 pProbe->pPartIdxWhere)
155355 ){ 157342 ){
155356 testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */ 157343 testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */
@@ -155458,7 +157445,14 @@ static int whereLoopAddBtree(
155458 } 157445 }
155459 ApplyCostMultiplier(pNew->rRun, pTab->costMult); 157446 ApplyCostMultiplier(pNew->rRun, pTab->costMult);
155460 whereLoopOutputAdjust(pWC, pNew, rSize); 157447 whereLoopOutputAdjust(pWC, pNew, rSize);
155461 rc = whereLoopInsert(pBuilder, pNew); 157448 if( (pSrc->fg.jointype & JT_RIGHT)!=0 && pProbe->aColExpr ){
157449 /* Do not do an SCAN of a index-on-expression in a RIGHT JOIN
157450 ** because the cursor used to access the index might not be
157451 ** positioned to the correct row during the right-join no-match
157452 ** loop. */
157453 }else{
157454 rc = whereLoopInsert(pBuilder, pNew);
157455 }
155462 pNew->nOut = rSize; 157456 pNew->nOut = rSize;
155463 if( rc ) break; 157457 if( rc ) break;
155464 } 157458 }
@@ -155633,6 +157627,7 @@ static int whereLoopAddVirtualOne(
155633 *pbIn = 1; assert( (mExclude & WO_IN)==0 ); 157627 *pbIn = 1; assert( (mExclude & WO_IN)==0 );
155634 } 157628 }
155635 157629
157630 assert( pbRetryLimit || !isLimitTerm(pTerm) );
155636 if( isLimitTerm(pTerm) && *pbIn ){ 157631 if( isLimitTerm(pTerm) && *pbIn ){
155637 /* If there is an IN(...) term handled as an == (separate call to 157632 /* If there is an IN(...) term handled as an == (separate call to
155638 ** xFilter for each value on the RHS of the IN) and a LIMIT or 157633 ** xFilter for each value on the RHS of the IN) and a LIMIT or
@@ -155780,9 +157775,7 @@ SQLITE_API int sqlite3_vtab_rhs_value(
155780*/ 157775*/
155781SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info *pIdxInfo){ 157776SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info *pIdxInfo){
155782 HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; 157777 HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
155783 assert( pHidden->eDistinct==0 157778 assert( pHidden->eDistinct>=0 && pHidden->eDistinct<=3 );
155784 || pHidden->eDistinct==1
155785 || pHidden->eDistinct==2 );
155786 return pHidden->eDistinct; 157779 return pHidden->eDistinct;
155787} 157780}
155788 157781
@@ -155790,15 +157783,26 @@ SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info *pIdxInfo){
155790 && !defined(SQLITE_OMIT_VIRTUALTABLE) 157783 && !defined(SQLITE_OMIT_VIRTUALTABLE)
155791/* 157784/*
155792** Cause the prepared statement that is associated with a call to 157785** Cause the prepared statement that is associated with a call to
155793** xBestIndex to open write transactions on all attached schemas. 157786** xBestIndex to potentiall use all schemas. If the statement being
157787** prepared is read-only, then just start read transactions on all
157788** schemas. But if this is a write operation, start writes on all
157789** schemas.
157790**
155794** This is used by the (built-in) sqlite_dbpage virtual table. 157791** This is used by the (built-in) sqlite_dbpage virtual table.
155795*/ 157792*/
155796SQLITE_PRIVATE void sqlite3VtabWriteAll(sqlite3_index_info *pIdxInfo){ 157793SQLITE_PRIVATE void sqlite3VtabUsesAllSchemas(sqlite3_index_info *pIdxInfo){
155797 HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; 157794 HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
155798 Parse *pParse = pHidden->pParse; 157795 Parse *pParse = pHidden->pParse;
155799 int nDb = pParse->db->nDb; 157796 int nDb = pParse->db->nDb;
155800 int i; 157797 int i;
155801 for(i=0; i<nDb; i++) sqlite3BeginWriteOperation(pParse, 0, i); 157798 for(i=0; i<nDb; i++){
157799 sqlite3CodeVerifySchema(pParse, i);
157800 }
157801 if( pParse->writeMask ){
157802 for(i=0; i<nDb; i++){
157803 sqlite3BeginWriteOperation(pParse, 0, i);
157804 }
157805 }
155802} 157806}
155803#endif 157807#endif
155804 157808
@@ -155981,6 +157985,9 @@ static int whereLoopAddOr(
155981 pItem = pWInfo->pTabList->a + pNew->iTab; 157985 pItem = pWInfo->pTabList->a + pNew->iTab;
155982 iCur = pItem->iCursor; 157986 iCur = pItem->iCursor;
155983 157987
157988 /* The multi-index OR optimization does not work for RIGHT and FULL JOIN */
157989 if( pItem->fg.jointype & JT_RIGHT ) return SQLITE_OK;
157990
155984 for(pTerm=pWC->a; pTerm<pWCEnd && rc==SQLITE_OK; pTerm++){ 157991 for(pTerm=pWC->a; pTerm<pWCEnd && rc==SQLITE_OK; pTerm++){
155985 if( (pTerm->eOperator & WO_OR)!=0 157992 if( (pTerm->eOperator & WO_OR)!=0
155986 && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0 157993 && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
@@ -156094,8 +158101,11 @@ static int whereLoopAddAll(WhereLoopBuilder *pBuilder){
156094 SrcItem *pEnd = &pTabList->a[pWInfo->nLevel]; 158101 SrcItem *pEnd = &pTabList->a[pWInfo->nLevel];
156095 sqlite3 *db = pWInfo->pParse->db; 158102 sqlite3 *db = pWInfo->pParse->db;
156096 int rc = SQLITE_OK; 158103 int rc = SQLITE_OK;
158104 int bFirstPastRJ = 0;
158105 int hasRightJoin = 0;
156097 WhereLoop *pNew; 158106 WhereLoop *pNew;
156098 158107
158108
156099 /* Loop over the tables in the join, from left to right */ 158109 /* Loop over the tables in the join, from left to right */
156100 pNew = pBuilder->pNew; 158110 pNew = pBuilder->pNew;
156101 whereLoopInit(pNew); 158111 whereLoopInit(pNew);
@@ -156105,18 +158115,30 @@ static int whereLoopAddAll(WhereLoopBuilder *pBuilder){
156105 pNew->iTab = iTab; 158115 pNew->iTab = iTab;
156106 pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR; 158116 pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
156107 pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor); 158117 pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
156108 if( (pItem->fg.jointype & (JT_LEFT|JT_CROSS))!=0 ){ 158118 if( bFirstPastRJ
156109 /* This condition is true when pItem is the FROM clause term on the 158119 || (pItem->fg.jointype & (JT_OUTER|JT_CROSS|JT_LTORJ))!=0
156110 ** right-hand-side of a LEFT or CROSS JOIN. */ 158120 ){
156111 mPrereq = mPrior; 158121 /* Add prerequisites to prevent reordering of FROM clause terms
156112 }else{ 158122 ** across CROSS joins and outer joins. The bFirstPastRJ boolean
158123 ** prevents the right operand of a RIGHT JOIN from being swapped with
158124 ** other elements even further to the right.
158125 **
158126 ** The JT_LTORJ case and the hasRightJoin flag work together to
158127 ** prevent FROM-clause terms from moving from the right side of
158128 ** a LEFT JOIN over to the left side of that join if the LEFT JOIN
158129 ** is itself on the left side of a RIGHT JOIN.
158130 */
158131 if( pItem->fg.jointype & JT_LTORJ ) hasRightJoin = 1;
158132 mPrereq |= mPrior;
158133 bFirstPastRJ = (pItem->fg.jointype & JT_RIGHT)!=0;
158134 }else if( !hasRightJoin ){
156113 mPrereq = 0; 158135 mPrereq = 0;
156114 } 158136 }
156115#ifndef SQLITE_OMIT_VIRTUALTABLE 158137#ifndef SQLITE_OMIT_VIRTUALTABLE
156116 if( IsVirtual(pItem->pTab) ){ 158138 if( IsVirtual(pItem->pTab) ){
156117 SrcItem *p; 158139 SrcItem *p;
156118 for(p=&pItem[1]; p<pEnd; p++){ 158140 for(p=&pItem[1]; p<pEnd; p++){
156119 if( mUnusable || (p->fg.jointype & (JT_LEFT|JT_CROSS)) ){ 158141 if( mUnusable || (p->fg.jointype & (JT_OUTER|JT_CROSS)) ){
156120 mUnusable |= sqlite3WhereGetMask(&pWInfo->sMaskSet, p->iCursor); 158142 mUnusable |= sqlite3WhereGetMask(&pWInfo->sMaskSet, p->iCursor);
156121 } 158143 }
156122 } 158144 }
@@ -156241,7 +158263,9 @@ static i8 wherePathSatisfiesOrderBy(
156241 pLoop = pLast; 158263 pLoop = pLast;
156242 } 158264 }
156243 if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){ 158265 if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
156244 if( pLoop->u.vtab.isOrdered && (wctrlFlags & WHERE_DISTINCTBY)==0 ){ 158266 if( pLoop->u.vtab.isOrdered
158267 && ((wctrlFlags&(WHERE_DISTINCTBY|WHERE_SORTBYGROUP))!=WHERE_DISTINCTBY)
158268 ){
156245 obSat = obDone; 158269 obSat = obDone;
156246 } 158270 }
156247 break; 158271 break;
@@ -156419,16 +158443,18 @@ static i8 wherePathSatisfiesOrderBy(
156419 /* Make sure the sort order is compatible in an ORDER BY clause. 158443 /* Make sure the sort order is compatible in an ORDER BY clause.
156420 ** Sort order is irrelevant for a GROUP BY clause. */ 158444 ** Sort order is irrelevant for a GROUP BY clause. */
156421 if( revSet ){ 158445 if( revSet ){
156422 if( (rev ^ revIdx)!=(pOrderBy->a[i].sortFlags&KEYINFO_ORDER_DESC) ){ 158446 if( (rev ^ revIdx)
158447 != (pOrderBy->a[i].fg.sortFlags&KEYINFO_ORDER_DESC)
158448 ){
156423 isMatch = 0; 158449 isMatch = 0;
156424 } 158450 }
156425 }else{ 158451 }else{
156426 rev = revIdx ^ (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC); 158452 rev = revIdx ^ (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC);
156427 if( rev ) *pRevMask |= MASKBIT(iLoop); 158453 if( rev ) *pRevMask |= MASKBIT(iLoop);
156428 revSet = 1; 158454 revSet = 1;
156429 } 158455 }
156430 } 158456 }
156431 if( isMatch && (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL) ){ 158457 if( isMatch && (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL) ){
156432 if( j==pLoop->u.btree.nEq ){ 158458 if( j==pLoop->u.btree.nEq ){
156433 pLoop->wsFlags |= WHERE_BIGNULL_SORT; 158459 pLoop->wsFlags |= WHERE_BIGNULL_SORT;
156434 }else{ 158460 }else{
@@ -156508,7 +158534,7 @@ static i8 wherePathSatisfiesOrderBy(
156508** SELECT * FROM t1 GROUP BY y,x ORDER BY y,x; -- IsSorted()==0 158534** SELECT * FROM t1 GROUP BY y,x ORDER BY y,x; -- IsSorted()==0
156509*/ 158535*/
156510SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo *pWInfo){ 158536SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo *pWInfo){
156511 assert( pWInfo->wctrlFlags & WHERE_GROUPBY ); 158537 assert( pWInfo->wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY) );
156512 assert( pWInfo->wctrlFlags & WHERE_SORTBYGROUP ); 158538 assert( pWInfo->wctrlFlags & WHERE_SORTBYGROUP );
156513 return pWInfo->sorted; 158539 return pWInfo->sorted;
156514} 158540}
@@ -156909,12 +158935,12 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
156909 } 158935 }
156910 pWInfo->bOrderedInnerLoop = 0; 158936 pWInfo->bOrderedInnerLoop = 0;
156911 if( pWInfo->pOrderBy ){ 158937 if( pWInfo->pOrderBy ){
158938 pWInfo->nOBSat = pFrom->isOrdered;
156912 if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){ 158939 if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
156913 if( pFrom->isOrdered==pWInfo->pOrderBy->nExpr ){ 158940 if( pFrom->isOrdered==pWInfo->pOrderBy->nExpr ){
156914 pWInfo->eDistinct = WHERE_DISTINCT_ORDERED; 158941 pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
156915 } 158942 }
156916 }else{ 158943 }else{
156917 pWInfo->nOBSat = pFrom->isOrdered;
156918 pWInfo->revMask = pFrom->revLoop; 158944 pWInfo->revMask = pFrom->revLoop;
156919 if( pWInfo->nOBSat<=0 ){ 158945 if( pWInfo->nOBSat<=0 ){
156920 pWInfo->nOBSat = 0; 158946 pWInfo->nOBSat = 0;
@@ -156993,7 +159019,11 @@ static int whereShortCut(WhereLoopBuilder *pBuilder){
156993 pItem = pWInfo->pTabList->a; 159019 pItem = pWInfo->pTabList->a;
156994 pTab = pItem->pTab; 159020 pTab = pItem->pTab;
156995 if( IsVirtual(pTab) ) return 0; 159021 if( IsVirtual(pTab) ) return 0;
156996 if( pItem->fg.isIndexedBy ) return 0; 159022 if( pItem->fg.isIndexedBy || pItem->fg.notIndexed ){
159023 testcase( pItem->fg.isIndexedBy );
159024 testcase( pItem->fg.notIndexed );
159025 return 0;
159026 }
156997 iCur = pItem->iCursor; 159027 iCur = pItem->iCursor;
156998 pWC = &pWInfo->sWC; 159028 pWC = &pWInfo->sWC;
156999 pLoop = pBuilder->pNew; 159029 pLoop = pBuilder->pNew;
@@ -157166,7 +159196,7 @@ static SQLITE_NOINLINE Bitmask whereOmitNoopJoin(
157166 WhereLoop *pLoop; 159196 WhereLoop *pLoop;
157167 pLoop = pWInfo->a[i].pWLoop; 159197 pLoop = pWInfo->a[i].pWLoop;
157168 pItem = &pWInfo->pTabList->a[pLoop->iTab]; 159198 pItem = &pWInfo->pTabList->a[pLoop->iTab];
157169 if( (pItem->fg.jointype & JT_LEFT)==0 ) continue; 159199 if( (pItem->fg.jointype & (JT_LEFT|JT_RIGHT))!=JT_LEFT ) continue;
157170 if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)==0 159200 if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)==0
157171 && (pLoop->wsFlags & WHERE_ONEROW)==0 159201 && (pLoop->wsFlags & WHERE_ONEROW)==0
157172 ){ 159202 ){
@@ -157176,8 +159206,8 @@ static SQLITE_NOINLINE Bitmask whereOmitNoopJoin(
157176 pEnd = pWInfo->sWC.a + pWInfo->sWC.nTerm; 159206 pEnd = pWInfo->sWC.a + pWInfo->sWC.nTerm;
157177 for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){ 159207 for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){
157178 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){ 159208 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
157179 if( !ExprHasProperty(pTerm->pExpr, EP_FromJoin) 159209 if( !ExprHasProperty(pTerm->pExpr, EP_OuterON)
157180 || pTerm->pExpr->w.iRightJoinTable!=pItem->iCursor 159210 || pTerm->pExpr->w.iJoin!=pItem->iCursor
157181 ){ 159211 ){
157182 break; 159212 break;
157183 } 159213 }
@@ -157408,7 +159438,7 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
157408 ** field (type Bitmask) it must be aligned on an 8-byte boundary on 159438 ** field (type Bitmask) it must be aligned on an 8-byte boundary on
157409 ** some architectures. Hence the ROUND8() below. 159439 ** some architectures. Hence the ROUND8() below.
157410 */ 159440 */
157411 nByteWInfo = ROUND8(sizeof(WhereInfo)+(nTabList-1)*sizeof(WhereLevel)); 159441 nByteWInfo = ROUND8P(sizeof(WhereInfo)+(nTabList-1)*sizeof(WhereLevel));
157412 pWInfo = sqlite3DbMallocRawNN(db, nByteWInfo + sizeof(WhereLoop)); 159442 pWInfo = sqlite3DbMallocRawNN(db, nByteWInfo + sizeof(WhereLoop));
157413 if( db->mallocFailed ){ 159443 if( db->mallocFailed ){
157414 sqlite3DbFree(db, pWInfo); 159444 sqlite3DbFree(db, pWInfo);
@@ -157498,7 +159528,7 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
157498 /* Analyze all of the subexpressions. */ 159528 /* Analyze all of the subexpressions. */
157499 sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC); 159529 sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
157500 sqlite3WhereAddLimit(&pWInfo->sWC, pLimit); 159530 sqlite3WhereAddLimit(&pWInfo->sWC, pLimit);
157501 if( db->mallocFailed ) goto whereBeginError; 159531 if( pParse->nErr ) goto whereBeginError;
157502 159532
157503 /* Special case: WHERE terms that do not refer to any tables in the join 159533 /* Special case: WHERE terms that do not refer to any tables in the join
157504 ** (constant expressions). Evaluate each such term, and jump over all the 159534 ** (constant expressions). Evaluate each such term, and jump over all the
@@ -157730,8 +159760,10 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
157730 /* noop */ 159760 /* noop */
157731 }else 159761 }else
157732#endif 159762#endif
157733 if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 159763 if( ((pLoop->wsFlags & WHERE_IDX_ONLY)==0
157734 && (wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ){ 159764 && (wctrlFlags & WHERE_OR_SUBCLAUSE)==0)
159765 || (pTabItem->fg.jointype & (JT_LTORJ|JT_RIGHT))!=0
159766 ){
157735 int op = OP_OpenRead; 159767 int op = OP_OpenRead;
157736 if( pWInfo->eOnePass!=ONEPASS_OFF ){ 159768 if( pWInfo->eOnePass!=ONEPASS_OFF ){
157737 op = OP_OpenWrite; 159769 op = OP_OpenWrite;
@@ -157800,6 +159832,7 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
157800 iIndexCur = pParse->nTab++; 159832 iIndexCur = pParse->nTab++;
157801 } 159833 }
157802 pLevel->iIdxCur = iIndexCur; 159834 pLevel->iIdxCur = iIndexCur;
159835 assert( pIx!=0 );
157803 assert( pIx->pSchema==pTab->pSchema ); 159836 assert( pIx->pSchema==pTab->pSchema );
157804 assert( iIndexCur>=0 ); 159837 assert( iIndexCur>=0 );
157805 if( op ){ 159838 if( op ){
@@ -157833,6 +159866,37 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
157833 } 159866 }
157834 } 159867 }
157835 if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb); 159868 if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
159869 if( (pTabItem->fg.jointype & JT_RIGHT)!=0
159870 && (pLevel->pRJ = sqlite3WhereMalloc(pWInfo, sizeof(WhereRightJoin)))!=0
159871 ){
159872 WhereRightJoin *pRJ = pLevel->pRJ;
159873 pRJ->iMatch = pParse->nTab++;
159874 pRJ->regBloom = ++pParse->nMem;
159875 sqlite3VdbeAddOp2(v, OP_Blob, 65536, pRJ->regBloom);
159876 pRJ->regReturn = ++pParse->nMem;
159877 sqlite3VdbeAddOp2(v, OP_Null, 0, pRJ->regReturn);
159878 assert( pTab==pTabItem->pTab );
159879 if( HasRowid(pTab) ){
159880 KeyInfo *pInfo;
159881 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRJ->iMatch, 1);
159882 pInfo = sqlite3KeyInfoAlloc(pParse->db, 1, 0);
159883 if( pInfo ){
159884 pInfo->aColl[0] = 0;
159885 pInfo->aSortFlags[0] = 0;
159886 sqlite3VdbeAppendP4(v, pInfo, P4_KEYINFO);
159887 }
159888 }else{
159889 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
159890 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRJ->iMatch, pPk->nKeyCol);
159891 sqlite3VdbeSetP4KeyInfo(pParse, pPk);
159892 }
159893 pLoop->wsFlags &= ~WHERE_IDX_ONLY;
159894 /* The nature of RIGHT JOIN processing is such that it messes up
159895 ** the output order. So omit any ORDER BY/GROUP BY elimination
159896 ** optimizations. We need to do an actual sort for RIGHT JOIN. */
159897 pWInfo->nOBSat = 0;
159898 pWInfo->eDistinct = WHERE_DISTINCT_UNORDERED;
159899 }
157836 } 159900 }
157837 pWInfo->iTop = sqlite3VdbeCurrentAddr(v); 159901 pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
157838 if( db->mallocFailed ) goto whereBeginError; 159902 if( db->mallocFailed ) goto whereBeginError;
@@ -157844,9 +159908,20 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
157844 for(ii=0; ii<nTabList; ii++){ 159908 for(ii=0; ii<nTabList; ii++){
157845 int addrExplain; 159909 int addrExplain;
157846 int wsFlags; 159910 int wsFlags;
159911 SrcItem *pSrc;
157847 if( pParse->nErr ) goto whereBeginError; 159912 if( pParse->nErr ) goto whereBeginError;
157848 pLevel = &pWInfo->a[ii]; 159913 pLevel = &pWInfo->a[ii];
157849 wsFlags = pLevel->pWLoop->wsFlags; 159914 wsFlags = pLevel->pWLoop->wsFlags;
159915 pSrc = &pTabList->a[pLevel->iFrom];
159916 if( pSrc->fg.isMaterialized ){
159917 if( pSrc->fg.isCorrelated ){
159918 sqlite3VdbeAddOp2(v, OP_Gosub, pSrc->regReturn, pSrc->addrFillSub);
159919 }else{
159920 int iOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
159921 sqlite3VdbeAddOp2(v, OP_Gosub, pSrc->regReturn, pSrc->addrFillSub);
159922 sqlite3VdbeJumpHere(v, iOnce);
159923 }
159924 }
157850 if( (wsFlags & (WHERE_AUTO_INDEX|WHERE_BLOOMFILTER))!=0 ){ 159925 if( (wsFlags & (WHERE_AUTO_INDEX|WHERE_BLOOMFILTER))!=0 ){
157851 if( (wsFlags & WHERE_AUTO_INDEX)!=0 ){ 159926 if( (wsFlags & WHERE_AUTO_INDEX)!=0 ){
157852#ifndef SQLITE_OMIT_AUTOMATIC_INDEX 159927#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
@@ -157938,6 +160013,7 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
157938 SrcList *pTabList = pWInfo->pTabList; 160013 SrcList *pTabList = pWInfo->pTabList;
157939 sqlite3 *db = pParse->db; 160014 sqlite3 *db = pParse->db;
157940 int iEnd = sqlite3VdbeCurrentAddr(v); 160015 int iEnd = sqlite3VdbeCurrentAddr(v);
160016 int nRJ = 0;
157941 160017
157942 /* Generate loop termination code. 160018 /* Generate loop termination code.
157943 */ 160019 */
@@ -157945,6 +160021,17 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
157945 for(i=pWInfo->nLevel-1; i>=0; i--){ 160021 for(i=pWInfo->nLevel-1; i>=0; i--){
157946 int addr; 160022 int addr;
157947 pLevel = &pWInfo->a[i]; 160023 pLevel = &pWInfo->a[i];
160024 if( pLevel->pRJ ){
160025 /* Terminate the subroutine that forms the interior of the loop of
160026 ** the RIGHT JOIN table */
160027 WhereRightJoin *pRJ = pLevel->pRJ;
160028 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
160029 pLevel->addrCont = 0;
160030 pRJ->endSubrtn = sqlite3VdbeCurrentAddr(v);
160031 sqlite3VdbeAddOp3(v, OP_Return, pRJ->regReturn, pRJ->addrSubrtn, 1);
160032 VdbeCoverage(v);
160033 nRJ++;
160034 }
157948 pLoop = pLevel->pWLoop; 160035 pLoop = pLevel->pWLoop;
157949 if( pLevel->op!=OP_Noop ){ 160036 if( pLevel->op!=OP_Noop ){
157950#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT 160037#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
@@ -157972,7 +160059,7 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
157972 } 160059 }
157973#endif /* SQLITE_DISABLE_SKIPAHEAD_DISTINCT */ 160060#endif /* SQLITE_DISABLE_SKIPAHEAD_DISTINCT */
157974 /* The common case: Advance to the next row */ 160061 /* The common case: Advance to the next row */
157975 sqlite3VdbeResolveLabel(v, pLevel->addrCont); 160062 if( pLevel->addrCont ) sqlite3VdbeResolveLabel(v, pLevel->addrCont);
157976 sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3); 160063 sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
157977 sqlite3VdbeChangeP5(v, pLevel->p5); 160064 sqlite3VdbeChangeP5(v, pLevel->p5);
157978 VdbeCoverage(v); 160065 VdbeCoverage(v);
@@ -157987,7 +160074,7 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
157987#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT 160074#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
157988 if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek); 160075 if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
157989#endif 160076#endif
157990 }else{ 160077 }else if( pLevel->addrCont ){
157991 sqlite3VdbeResolveLabel(v, pLevel->addrCont); 160078 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
157992 } 160079 }
157993 if( (pLoop->wsFlags & WHERE_IN_ABLE)!=0 && pLevel->u.in.nIn>0 ){ 160080 if( (pLoop->wsFlags & WHERE_IN_ABLE)!=0 && pLevel->u.in.nIn>0 ){
@@ -158037,6 +160124,10 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
158037 } 160124 }
158038 } 160125 }
158039 sqlite3VdbeResolveLabel(v, pLevel->addrBrk); 160126 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
160127 if( pLevel->pRJ ){
160128 sqlite3VdbeAddOp3(v, OP_Return, pLevel->pRJ->regReturn, 0, 1);
160129 VdbeCoverage(v);
160130 }
158040 if( pLevel->addrSkip ){ 160131 if( pLevel->addrSkip ){
158041 sqlite3VdbeGoto(v, pLevel->addrSkip); 160132 sqlite3VdbeGoto(v, pLevel->addrSkip);
158042 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName)); 160133 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
@@ -158080,12 +160171,8 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
158080 pWInfo->pTabList->a[pLevel->iFrom].pTab->zName)); 160171 pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
158081 } 160172 }
158082 160173
158083 /* The "break" point is here, just past the end of the outer loop.
158084 ** Set it.
158085 */
158086 sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
158087
158088 assert( pWInfo->nLevel<=pTabList->nSrc ); 160174 assert( pWInfo->nLevel<=pTabList->nSrc );
160175 if( pWInfo->pExprMods ) whereUndoExprMods(pWInfo);
158089 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){ 160176 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
158090 int k, last; 160177 int k, last;
158091 VdbeOp *pOp, *pLastOp; 160178 VdbeOp *pOp, *pLastOp;
@@ -158095,6 +160182,15 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
158095 assert( pTab!=0 ); 160182 assert( pTab!=0 );
158096 pLoop = pLevel->pWLoop; 160183 pLoop = pLevel->pWLoop;
158097 160184
160185 /* Do RIGHT JOIN processing. Generate code that will output the
160186 ** unmatched rows of the right operand of the RIGHT JOIN with
160187 ** all of the columns of the left operand set to NULL.
160188 */
160189 if( pLevel->pRJ ){
160190 sqlite3WhereRightJoinLoop(pWInfo, i, pLevel);
160191 continue;
160192 }
160193
158098 /* For a co-routine, change all OP_Column references to the table of 160194 /* For a co-routine, change all OP_Column references to the table of
158099 ** the co-routine into OP_Copy of result contained in a register. 160195 ** the co-routine into OP_Copy of result contained in a register.
158100 ** OP_Rowid becomes OP_Null. 160196 ** OP_Rowid becomes OP_Null.
@@ -158106,29 +160202,6 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
158106 continue; 160202 continue;
158107 } 160203 }
158108 160204
158109#ifdef SQLITE_ENABLE_EARLY_CURSOR_CLOSE
158110 /* Close all of the cursors that were opened by sqlite3WhereBegin.
158111 ** Except, do not close cursors that will be reused by the OR optimization
158112 ** (WHERE_OR_SUBCLAUSE). And do not close the OP_OpenWrite cursors
158113 ** created for the ONEPASS optimization.
158114 */
158115 if( (pTab->tabFlags & TF_Ephemeral)==0
158116 && !IsView(pTab)
158117 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0
158118 ){
158119 int ws = pLoop->wsFlags;
158120 if( pWInfo->eOnePass==ONEPASS_OFF && (ws & WHERE_IDX_ONLY)==0 ){
158121 sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
158122 }
158123 if( (ws & WHERE_INDEXED)!=0
158124 && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0
158125 && pLevel->iIdxCur!=pWInfo->aiCurOnePass[1]
158126 ){
158127 sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
158128 }
158129 }
158130#endif
158131
158132 /* If this scan uses an index, make VDBE code substitutions to read data 160205 /* If this scan uses an index, make VDBE code substitutions to read data
158133 ** from the index instead of from the table where possible. In some cases 160206 ** from the index instead of from the table where possible. In some cases
158134 ** this optimization prevents the table from ever being read, which can 160207 ** this optimization prevents the table from ever being read, which can
@@ -158229,11 +160302,16 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
158229 } 160302 }
158230 } 160303 }
158231 160304
160305 /* The "break" point is here, just past the end of the outer loop.
160306 ** Set it.
160307 */
160308 sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
160309
158232 /* Final cleanup 160310 /* Final cleanup
158233 */ 160311 */
158234 if( pWInfo->pExprMods ) whereUndoExprMods(pWInfo);
158235 pParse->nQueryLoop = pWInfo->savedNQueryLoop; 160312 pParse->nQueryLoop = pWInfo->savedNQueryLoop;
158236 whereInfoFree(db, pWInfo); 160313 whereInfoFree(db, pWInfo);
160314 pParse->withinRJSubrtn -= nRJ;
158237 return; 160315 return;
158238} 160316}
158239 160317
@@ -158965,7 +161043,7 @@ SQLITE_PRIVATE void sqlite3WindowUpdate(
158965 } 161043 }
158966 } 161044 }
158967 } 161045 }
158968 pWin->pFunc = pFunc; 161046 pWin->pWFunc = pFunc;
158969} 161047}
158970 161048
158971/* 161049/*
@@ -159157,7 +161235,7 @@ static ExprList *exprListAppendList(
159157 } 161235 }
159158 } 161236 }
159159 pList = sqlite3ExprListAppend(pParse, pList, pDup); 161237 pList = sqlite3ExprListAppend(pParse, pList, pDup);
159160 if( pList ) pList->a[nInit+i].sortFlags = pAppend->a[i].sortFlags; 161238 if( pList ) pList->a[nInit+i].fg.sortFlags = pAppend->a[i].fg.sortFlags;
159161 } 161239 }
159162 } 161240 }
159163 return pList; 161241 return pList;
@@ -159277,9 +161355,9 @@ SQLITE_PRIVATE int sqlite3WindowRewrite(Parse *pParse, Select *p){
159277 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ 161355 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
159278 ExprList *pArgs; 161356 ExprList *pArgs;
159279 assert( ExprUseXList(pWin->pOwner) ); 161357 assert( ExprUseXList(pWin->pOwner) );
159280 assert( pWin->pFunc!=0 ); 161358 assert( pWin->pWFunc!=0 );
159281 pArgs = pWin->pOwner->x.pList; 161359 pArgs = pWin->pOwner->x.pList;
159282 if( pWin->pFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){ 161360 if( pWin->pWFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){
159283 selectWindowRewriteEList(pParse, pMWin, pSrc, pArgs, pTab, &pSublist); 161361 selectWindowRewriteEList(pParse, pMWin, pSrc, pArgs, pTab, &pSublist);
159284 pWin->iArgCol = (pSublist ? pSublist->nExpr : 0); 161362 pWin->iArgCol = (pSublist ? pSublist->nExpr : 0);
159285 pWin->bExprArgs = 1; 161363 pWin->bExprArgs = 1;
@@ -159661,7 +161739,7 @@ SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse *pParse, Select *pSelect){
159661 } 161739 }
159662 161740
159663 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ 161741 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
159664 FuncDef *p = pWin->pFunc; 161742 FuncDef *p = pWin->pWFunc;
159665 if( (p->funcFlags & SQLITE_FUNC_MINMAX) && pWin->eStart!=TK_UNBOUNDED ){ 161743 if( (p->funcFlags & SQLITE_FUNC_MINMAX) && pWin->eStart!=TK_UNBOUNDED ){
159666 /* The inline versions of min() and max() require a single ephemeral 161744 /* The inline versions of min() and max() require a single ephemeral
159667 ** table and 3 registers. The registers are used as follows: 161745 ** table and 3 registers. The registers are used as follows:
@@ -159678,7 +161756,7 @@ SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse *pParse, Select *pSelect){
159678 pWin->csrApp = pParse->nTab++; 161756 pWin->csrApp = pParse->nTab++;
159679 pWin->regApp = pParse->nMem+1; 161757 pWin->regApp = pParse->nMem+1;
159680 pParse->nMem += 3; 161758 pParse->nMem += 3;
159681 if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){ 161759 if( pKeyInfo && pWin->pWFunc->zName[1]=='i' ){
159682 assert( pKeyInfo->aSortFlags[0]==0 ); 161760 assert( pKeyInfo->aSortFlags[0]==0 );
159683 pKeyInfo->aSortFlags[0] = KEYINFO_ORDER_DESC; 161761 pKeyInfo->aSortFlags[0] = KEYINFO_ORDER_DESC;
159684 } 161762 }
@@ -159901,7 +161979,7 @@ static void windowAggStep(
159901 Vdbe *v = sqlite3GetVdbe(pParse); 161979 Vdbe *v = sqlite3GetVdbe(pParse);
159902 Window *pWin; 161980 Window *pWin;
159903 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ 161981 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
159904 FuncDef *pFunc = pWin->pFunc; 161982 FuncDef *pFunc = pWin->pWFunc;
159905 int regArg; 161983 int regArg;
159906 int nArg = pWin->bExprArgs ? 0 : windowArgCount(pWin); 161984 int nArg = pWin->bExprArgs ? 0 : windowArgCount(pWin);
159907 int i; 161985 int i;
@@ -159970,7 +162048,7 @@ static void windowAggStep(
159970 162048
159971 for(iEnd=sqlite3VdbeCurrentAddr(v); iOp<iEnd; iOp++){ 162049 for(iEnd=sqlite3VdbeCurrentAddr(v); iOp<iEnd; iOp++){
159972 VdbeOp *pOp = sqlite3VdbeGetOp(v, iOp); 162050 VdbeOp *pOp = sqlite3VdbeGetOp(v, iOp);
159973 if( pOp->opcode==OP_Column && pOp->p1==pWin->iEphCsr ){ 162051 if( pOp->opcode==OP_Column && pOp->p1==pMWin->iEphCsr ){
159974 pOp->p1 = csr; 162052 pOp->p1 = csr;
159975 } 162053 }
159976 } 162054 }
@@ -160015,7 +162093,7 @@ static void windowAggFinal(WindowCodeArg *p, int bFin){
160015 162093
160016 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ 162094 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
160017 if( pMWin->regStartRowid==0 162095 if( pMWin->regStartRowid==0
160018 && (pWin->pFunc->funcFlags & SQLITE_FUNC_MINMAX) 162096 && (pWin->pWFunc->funcFlags & SQLITE_FUNC_MINMAX)
160019 && (pWin->eStart!=TK_UNBOUNDED) 162097 && (pWin->eStart!=TK_UNBOUNDED)
160020 ){ 162098 ){
160021 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult); 162099 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
@@ -160029,12 +162107,12 @@ static void windowAggFinal(WindowCodeArg *p, int bFin){
160029 int nArg = windowArgCount(pWin); 162107 int nArg = windowArgCount(pWin);
160030 if( bFin ){ 162108 if( bFin ){
160031 sqlite3VdbeAddOp2(v, OP_AggFinal, pWin->regAccum, nArg); 162109 sqlite3VdbeAddOp2(v, OP_AggFinal, pWin->regAccum, nArg);
160032 sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF); 162110 sqlite3VdbeAppendP4(v, pWin->pWFunc, P4_FUNCDEF);
160033 sqlite3VdbeAddOp2(v, OP_Copy, pWin->regAccum, pWin->regResult); 162111 sqlite3VdbeAddOp2(v, OP_Copy, pWin->regAccum, pWin->regResult);
160034 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum); 162112 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
160035 }else{ 162113 }else{
160036 sqlite3VdbeAddOp3(v, OP_AggValue,pWin->regAccum,nArg,pWin->regResult); 162114 sqlite3VdbeAddOp3(v, OP_AggValue,pWin->regAccum,nArg,pWin->regResult);
160037 sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF); 162115 sqlite3VdbeAppendP4(v, pWin->pWFunc, P4_FUNCDEF);
160038 } 162116 }
160039 } 162117 }
160040 } 162118 }
@@ -160163,7 +162241,7 @@ static void windowReturnOneRow(WindowCodeArg *p){
160163 Window *pWin; 162241 Window *pWin;
160164 162242
160165 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ 162243 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
160166 FuncDef *pFunc = pWin->pFunc; 162244 FuncDef *pFunc = pWin->pWFunc;
160167 assert( ExprUseXList(pWin->pOwner) ); 162245 assert( ExprUseXList(pWin->pOwner) );
160168 if( pFunc->zName==nth_valueName 162246 if( pFunc->zName==nth_valueName
160169 || pFunc->zName==first_valueName 162247 || pFunc->zName==first_valueName
@@ -160235,7 +162313,7 @@ static int windowInitAccum(Parse *pParse, Window *pMWin){
160235 int nArg = 0; 162313 int nArg = 0;
160236 Window *pWin; 162314 Window *pWin;
160237 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ 162315 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
160238 FuncDef *pFunc = pWin->pFunc; 162316 FuncDef *pFunc = pWin->pWFunc;
160239 assert( pWin->regAccum ); 162317 assert( pWin->regAccum );
160240 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum); 162318 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
160241 nArg = MAX(nArg, windowArgCount(pWin)); 162319 nArg = MAX(nArg, windowArgCount(pWin));
@@ -160265,7 +162343,7 @@ static int windowCacheFrame(Window *pMWin){
160265 Window *pWin; 162343 Window *pWin;
160266 if( pMWin->regStartRowid ) return 1; 162344 if( pMWin->regStartRowid ) return 1;
160267 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ 162345 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
160268 FuncDef *pFunc = pWin->pFunc; 162346 FuncDef *pFunc = pWin->pWFunc;
160269 if( (pFunc->zName==nth_valueName) 162347 if( (pFunc->zName==nth_valueName)
160270 || (pFunc->zName==first_valueName) 162348 || (pFunc->zName==first_valueName)
160271 || (pFunc->zName==leadName) 162349 || (pFunc->zName==leadName)
@@ -160358,7 +162436,7 @@ static void windowCodeRangeTest(
160358 162436
160359 assert( op==OP_Ge || op==OP_Gt || op==OP_Le ); 162437 assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
160360 assert( pOrderBy && pOrderBy->nExpr==1 ); 162438 assert( pOrderBy && pOrderBy->nExpr==1 );
160361 if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){ 162439 if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_DESC ){
160362 switch( op ){ 162440 switch( op ){
160363 case OP_Ge: op = OP_Le; break; 162441 case OP_Ge: op = OP_Le; break;
160364 case OP_Gt: op = OP_Lt; break; 162442 case OP_Gt: op = OP_Lt; break;
@@ -160391,7 +162469,7 @@ static void windowCodeRangeTest(
160391 ** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is 162469 ** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is
160392 ** not taken, control jumps over the comparison operator coded below this 162470 ** not taken, control jumps over the comparison operator coded below this
160393 ** block. */ 162471 ** block. */
160394 if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_BIGNULL ){ 162472 if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_BIGNULL ){
160395 /* This block runs if reg1 contains a NULL. */ 162473 /* This block runs if reg1 contains a NULL. */
160396 int addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v); 162474 int addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v);
160397 switch( op ){ 162475 switch( op ){
@@ -160623,7 +162701,7 @@ SQLITE_PRIVATE Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p){
160623 pNew->zName = sqlite3DbStrDup(db, p->zName); 162701 pNew->zName = sqlite3DbStrDup(db, p->zName);
160624 pNew->zBase = sqlite3DbStrDup(db, p->zBase); 162702 pNew->zBase = sqlite3DbStrDup(db, p->zBase);
160625 pNew->pFilter = sqlite3ExprDup(db, p->pFilter, 0); 162703 pNew->pFilter = sqlite3ExprDup(db, p->pFilter, 0);
160626 pNew->pFunc = p->pFunc; 162704 pNew->pWFunc = p->pWFunc;
160627 pNew->pPartition = sqlite3ExprListDup(db, p->pPartition, 0); 162705 pNew->pPartition = sqlite3ExprListDup(db, p->pPartition, 0);
160628 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, 0); 162706 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, 0);
160629 pNew->eFrmType = p->eFrmType; 162707 pNew->eFrmType = p->eFrmType;
@@ -161509,7 +163587,7 @@ static void updateDeleteLimitError(
161509 p->affExpr = 0; 163587 p->affExpr = 0;
161510 p->flags = EP_Leaf; 163588 p->flags = EP_Leaf;
161511 ExprClearVVAProperties(p); 163589 ExprClearVVAProperties(p);
161512 p->iAgg = -1; 163590 /* p->iAgg = -1; // Not required */
161513 p->pLeft = p->pRight = 0; 163591 p->pLeft = p->pRight = 0;
161514 p->pAggInfo = 0; 163592 p->pAggInfo = 0;
161515 memset(&p->x, 0, sizeof(p->x)); 163593 memset(&p->x, 0, sizeof(p->x));
@@ -161842,6 +163920,7 @@ typedef union {
161842 With* yy521; 163920 With* yy521;
161843 const char* yy522; 163921 const char* yy522;
161844 Expr* yy528; 163922 Expr* yy528;
163923 OnOrUsing yy561;
161845 struct FrameBound yy595; 163924 struct FrameBound yy595;
161846} YYMINORTYPE; 163925} YYMINORTYPE;
161847#ifndef YYSTACKDEPTH 163926#ifndef YYSTACKDEPTH
@@ -161858,18 +163937,18 @@ typedef union {
161858#define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse; 163937#define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse;
161859#define sqlite3ParserCTX_STORE yypParser->pParse=pParse; 163938#define sqlite3ParserCTX_STORE yypParser->pParse=pParse;
161860#define YYFALLBACK 1 163939#define YYFALLBACK 1
161861#define YYNSTATE 574 163940#define YYNSTATE 576
161862#define YYNRULE 402 163941#define YYNRULE 405
161863#define YYNRULE_WITH_ACTION 340 163942#define YYNRULE_WITH_ACTION 342
161864#define YYNTOKEN 185 163943#define YYNTOKEN 185
161865#define YY_MAX_SHIFT 573 163944#define YY_MAX_SHIFT 575
161866#define YY_MIN_SHIFTREDUCE 831 163945#define YY_MIN_SHIFTREDUCE 835
161867#define YY_MAX_SHIFTREDUCE 1232 163946#define YY_MAX_SHIFTREDUCE 1239
161868#define YY_ERROR_ACTION 1233 163947#define YY_ERROR_ACTION 1240
161869#define YY_ACCEPT_ACTION 1234 163948#define YY_ACCEPT_ACTION 1241
161870#define YY_NO_ACTION 1235 163949#define YY_NO_ACTION 1242
161871#define YY_MIN_REDUCE 1236 163950#define YY_MIN_REDUCE 1243
161872#define YY_MAX_REDUCE 1637 163951#define YY_MAX_REDUCE 1647
161873/************* End control #defines *******************************************/ 163952/************* End control #defines *******************************************/
161874#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) 163953#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
161875 163954
@@ -161936,427 +164015,430 @@ typedef union {
161936** yy_default[] Default action for each state. 164015** yy_default[] Default action for each state.
161937** 164016**
161938*********** Begin parsing tables **********************************************/ 164017*********** Begin parsing tables **********************************************/
161939#define YY_ACTTAB_COUNT (2070) 164018#define YY_ACTTAB_COUNT (2098)
161940static const YYACTIONTYPE yy_action[] = { 164019static const YYACTIONTYPE yy_action[] = {
161941 /* 0 */ 566, 1307, 566, 1286, 201, 201, 566, 116, 112, 222, 164020 /* 0 */ 568, 208, 568, 118, 115, 229, 568, 118, 115, 229,
161942 /* 10 */ 566, 1307, 377, 566, 116, 112, 222, 397, 408, 409, 164021 /* 10 */ 568, 1314, 377, 1293, 408, 562, 562, 562, 568, 409,
161943 /* 20 */ 1260, 378, 1269, 41, 41, 41, 41, 1412, 1517, 71, 164022 /* 20 */ 378, 1314, 1276, 41, 41, 41, 41, 208, 1526, 71,
161944 /* 30 */ 71, 967, 1258, 41, 41, 491, 71, 71, 272, 968, 164023 /* 30 */ 71, 971, 419, 41, 41, 491, 303, 279, 303, 972,
161945 /* 40 */ 298, 476, 298, 123, 124, 114, 1210, 1210, 1044, 1047, 164024 /* 40 */ 397, 71, 71, 125, 126, 80, 1217, 1217, 1050, 1053,
161946 /* 50 */ 1036, 1036, 121, 121, 122, 122, 122, 122, 543, 409, 164025 /* 50 */ 1040, 1040, 123, 123, 124, 124, 124, 124, 476, 409,
161947 /* 60 */ 1234, 1, 1, 573, 2, 1238, 548, 116, 112, 222, 164026 /* 60 */ 1241, 1, 1, 575, 2, 1245, 550, 118, 115, 229,
161948 /* 70 */ 309, 480, 142, 548, 1272, 524, 116, 112, 222, 1320, 164027 /* 70 */ 317, 480, 146, 480, 524, 118, 115, 229, 529, 1327,
161949 /* 80 */ 417, 523, 547, 123, 124, 114, 1210, 1210, 1044, 1047, 164028 /* 80 */ 417, 523, 142, 125, 126, 80, 1217, 1217, 1050, 1053,
161950 /* 90 */ 1036, 1036, 121, 121, 122, 122, 122, 122, 424, 116, 164029 /* 90 */ 1040, 1040, 123, 123, 124, 124, 124, 124, 118, 115,
161951 /* 100 */ 112, 222, 120, 120, 120, 120, 119, 119, 118, 118, 164030 /* 100 */ 229, 327, 122, 122, 122, 122, 121, 121, 120, 120,
161952 /* 110 */ 118, 117, 113, 444, 277, 277, 277, 277, 560, 560, 164031 /* 110 */ 120, 119, 116, 444, 284, 284, 284, 284, 442, 442,
161953 /* 120 */ 560, 1558, 376, 1560, 1186, 375, 1157, 563, 1157, 563, 164032 /* 120 */ 442, 1567, 376, 1569, 1192, 375, 1163, 565, 1163, 565,
161954 /* 130 */ 409, 1558, 537, 252, 219, 1553, 99, 141, 449, 6, 164033 /* 130 */ 409, 1567, 537, 259, 226, 444, 101, 145, 449, 316,
161955 /* 140 */ 365, 233, 120, 120, 120, 120, 119, 119, 118, 118, 164034 /* 140 */ 559, 240, 122, 122, 122, 122, 121, 121, 120, 120,
161956 /* 150 */ 118, 117, 113, 444, 123, 124, 114, 1210, 1210, 1044, 164035 /* 150 */ 120, 119, 116, 444, 125, 126, 80, 1217, 1217, 1050,
161957 /* 160 */ 1047, 1036, 1036, 121, 121, 122, 122, 122, 122, 138, 164036 /* 160 */ 1053, 1040, 1040, 123, 123, 124, 124, 124, 124, 142,
161958 /* 170 */ 289, 1186, 1546, 448, 118, 118, 118, 117, 113, 444, 164037 /* 170 */ 294, 1192, 339, 448, 120, 120, 120, 119, 116, 444,
161959 /* 180 */ 125, 1186, 1187, 1188, 144, 465, 334, 566, 150, 127, 164038 /* 180 */ 127, 1192, 1193, 1194, 148, 441, 440, 568, 119, 116,
161960 /* 190 */ 444, 122, 122, 122, 122, 115, 120, 120, 120, 120, 164039 /* 190 */ 444, 124, 124, 124, 124, 117, 122, 122, 122, 122,
161961 /* 200 */ 119, 119, 118, 118, 118, 117, 113, 444, 454, 419, 164040 /* 200 */ 121, 121, 120, 120, 120, 119, 116, 444, 454, 113,
161962 /* 210 */ 13, 13, 215, 120, 120, 120, 120, 119, 119, 118, 164041 /* 210 */ 13, 13, 546, 122, 122, 122, 122, 121, 121, 120,
161963 /* 220 */ 118, 118, 117, 113, 444, 422, 308, 557, 1186, 1187, 164042 /* 220 */ 120, 120, 119, 116, 444, 422, 316, 559, 1192, 1193,
161964 /* 230 */ 1188, 441, 440, 409, 1271, 122, 122, 122, 122, 120, 164043 /* 230 */ 1194, 149, 1224, 409, 1224, 124, 124, 124, 124, 122,
161965 /* 240 */ 120, 120, 120, 119, 119, 118, 118, 118, 117, 113, 164044 /* 240 */ 122, 122, 122, 121, 121, 120, 120, 120, 119, 116,
161966 /* 250 */ 444, 1543, 98, 1033, 1033, 1045, 1048, 123, 124, 114, 164045 /* 250 */ 444, 465, 342, 1037, 1037, 1051, 1054, 125, 126, 80,
161967 /* 260 */ 1210, 1210, 1044, 1047, 1036, 1036, 121, 121, 122, 122, 164046 /* 260 */ 1217, 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124,
161968 /* 270 */ 122, 122, 566, 406, 405, 1186, 566, 409, 1217, 319, 164047 /* 270 */ 124, 124, 1279, 522, 222, 1192, 568, 409, 224, 514,
161969 /* 280 */ 1217, 80, 81, 120, 120, 120, 120, 119, 119, 118, 164048 /* 280 */ 175, 82, 83, 122, 122, 122, 122, 121, 121, 120,
161970 /* 290 */ 118, 118, 117, 113, 444, 70, 70, 1186, 1604, 71, 164049 /* 290 */ 120, 120, 119, 116, 444, 1007, 16, 16, 1192, 133,
161971 /* 300 */ 71, 123, 124, 114, 1210, 1210, 1044, 1047, 1036, 1036, 164050 /* 300 */ 133, 125, 126, 80, 1217, 1217, 1050, 1053, 1040, 1040,
161972 /* 310 */ 121, 121, 122, 122, 122, 122, 120, 120, 120, 120, 164051 /* 310 */ 123, 123, 124, 124, 124, 124, 122, 122, 122, 122,
161973 /* 320 */ 119, 119, 118, 118, 118, 117, 113, 444, 1037, 210, 164052 /* 320 */ 121, 121, 120, 120, 120, 119, 116, 444, 1041, 546,
161974 /* 330 */ 1186, 365, 1186, 1187, 1188, 245, 548, 399, 504, 501, 164053 /* 330 */ 1192, 373, 1192, 1193, 1194, 252, 1434, 399, 504, 501,
161975 /* 340 */ 500, 108, 558, 138, 4, 516, 933, 433, 499, 217, 164054 /* 340 */ 500, 111, 560, 566, 4, 926, 926, 433, 499, 340,
161976 /* 350 */ 514, 522, 352, 879, 1186, 1187, 1188, 383, 561, 566, 164055 /* 350 */ 460, 328, 360, 394, 1237, 1192, 1193, 1194, 563, 568,
161977 /* 360 */ 120, 120, 120, 120, 119, 119, 118, 118, 118, 117, 164056 /* 360 */ 122, 122, 122, 122, 121, 121, 120, 120, 120, 119,
161978 /* 370 */ 113, 444, 277, 277, 16, 16, 1598, 441, 440, 153, 164057 /* 370 */ 116, 444, 284, 284, 369, 1580, 1607, 441, 440, 154,
161979 /* 380 */ 409, 445, 13, 13, 1279, 563, 1214, 1186, 1187, 1188, 164058 /* 380 */ 409, 445, 71, 71, 1286, 565, 1221, 1192, 1193, 1194,
161980 /* 390 */ 1003, 1216, 264, 555, 1574, 186, 566, 427, 138, 1215, 164059 /* 390 */ 85, 1223, 271, 557, 543, 515, 1561, 568, 98, 1222,
161981 /* 400 */ 308, 557, 472, 138, 123, 124, 114, 1210, 1210, 1044, 164060 /* 400 */ 6, 1278, 472, 142, 125, 126, 80, 1217, 1217, 1050,
161982 /* 410 */ 1047, 1036, 1036, 121, 121, 122, 122, 122, 122, 55, 164061 /* 410 */ 1053, 1040, 1040, 123, 123, 124, 124, 124, 124, 550,
161983 /* 420 */ 55, 413, 1023, 507, 1217, 1186, 1217, 474, 106, 106, 164062 /* 420 */ 13, 13, 1027, 507, 1224, 1192, 1224, 549, 109, 109,
161984 /* 430 */ 1312, 1312, 1186, 171, 566, 384, 107, 380, 445, 568, 164063 /* 430 */ 222, 568, 1238, 175, 568, 427, 110, 197, 445, 570,
161985 /* 440 */ 567, 430, 1543, 1013, 332, 549, 565, 263, 280, 360, 164064 /* 440 */ 569, 430, 1552, 1017, 325, 551, 1192, 270, 287, 368,
161986 /* 450 */ 510, 355, 509, 250, 491, 308, 557, 71, 71, 351, 164065 /* 450 */ 510, 363, 509, 257, 71, 71, 543, 71, 71, 359,
161987 /* 460 */ 308, 557, 374, 120, 120, 120, 120, 119, 119, 118, 164066 /* 460 */ 316, 559, 1613, 122, 122, 122, 122, 121, 121, 120,
161988 /* 470 */ 118, 118, 117, 113, 444, 1013, 1013, 1015, 1016, 27, 164067 /* 470 */ 120, 120, 119, 116, 444, 1017, 1017, 1019, 1020, 27,
161989 /* 480 */ 277, 277, 1186, 1187, 1188, 1152, 566, 528, 409, 1186, 164068 /* 480 */ 284, 284, 1192, 1193, 1194, 1158, 568, 1612, 409, 901,
161990 /* 490 */ 1187, 1188, 348, 563, 548, 1260, 533, 517, 1152, 1516, 164069 /* 490 */ 190, 550, 356, 565, 550, 937, 533, 517, 1158, 516,
161991 /* 500 */ 317, 1152, 285, 550, 485, 569, 566, 569, 482, 51, 164070 /* 500 */ 413, 1158, 552, 1192, 1193, 1194, 568, 544, 1554, 51,
161992 /* 510 */ 51, 207, 123, 124, 114, 1210, 1210, 1044, 1047, 1036, 164071 /* 510 */ 51, 214, 125, 126, 80, 1217, 1217, 1050, 1053, 1040,
161993 /* 520 */ 1036, 121, 121, 122, 122, 122, 122, 171, 1412, 13, 164072 /* 520 */ 1040, 123, 123, 124, 124, 124, 124, 1192, 474, 135,
161994 /* 530 */ 13, 409, 277, 277, 1186, 505, 119, 119, 118, 118, 164073 /* 530 */ 135, 409, 284, 284, 1490, 505, 121, 121, 120, 120,
161995 /* 540 */ 118, 117, 113, 444, 429, 563, 518, 220, 515, 1552, 164074 /* 540 */ 120, 119, 116, 444, 1007, 565, 518, 217, 541, 1561,
161996 /* 550 */ 365, 546, 1186, 6, 532, 123, 124, 114, 1210, 1210, 164075 /* 550 */ 316, 559, 142, 6, 532, 125, 126, 80, 1217, 1217,
161997 /* 560 */ 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, 122, 164076 /* 560 */ 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124, 124,
161998 /* 570 */ 145, 120, 120, 120, 120, 119, 119, 118, 118, 118, 164077 /* 570 */ 1555, 122, 122, 122, 122, 121, 121, 120, 120, 120,
161999 /* 580 */ 117, 113, 444, 245, 566, 474, 504, 501, 500, 566, 164078 /* 580 */ 119, 116, 444, 485, 1192, 1193, 1194, 482, 281, 1267,
162000 /* 590 */ 1481, 1186, 1187, 1188, 1310, 1310, 499, 1186, 149, 425, 164079 /* 590 */ 957, 252, 1192, 373, 504, 501, 500, 1192, 340, 571,
162001 /* 600 */ 1186, 480, 409, 274, 365, 952, 872, 56, 56, 1186, 164080 /* 600 */ 1192, 571, 409, 292, 499, 957, 876, 191, 480, 316,
162002 /* 610 */ 1187, 1188, 71, 71, 120, 120, 120, 120, 119, 119, 164081 /* 610 */ 559, 384, 290, 380, 122, 122, 122, 122, 121, 121,
162003 /* 620 */ 118, 118, 118, 117, 113, 444, 123, 124, 114, 1210, 164082 /* 620 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1217,
162004 /* 630 */ 1210, 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, 164083 /* 630 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
162005 /* 640 */ 122, 409, 541, 1552, 83, 865, 98, 6, 928, 529, 164084 /* 640 */ 124, 409, 394, 1136, 1192, 869, 100, 284, 284, 1192,
162006 /* 650 */ 848, 543, 151, 927, 1186, 1187, 1188, 1186, 1187, 1188, 164085 /* 650 */ 1193, 1194, 373, 1093, 1192, 1193, 1194, 1192, 1193, 1194,
162007 /* 660 */ 290, 1543, 187, 1633, 395, 123, 124, 114, 1210, 1210, 164086 /* 660 */ 565, 455, 32, 373, 233, 125, 126, 80, 1217, 1217,
162008 /* 670 */ 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, 122, 164087 /* 670 */ 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124, 124,
162009 /* 680 */ 566, 954, 566, 453, 953, 120, 120, 120, 120, 119, 164088 /* 680 */ 1433, 959, 568, 228, 958, 122, 122, 122, 122, 121,
162010 /* 690 */ 119, 118, 118, 118, 117, 113, 444, 1152, 221, 1186, 164089 /* 690 */ 121, 120, 120, 120, 119, 116, 444, 1158, 228, 1192,
162011 /* 700 */ 331, 453, 452, 13, 13, 13, 13, 1003, 365, 463, 164090 /* 700 */ 157, 1192, 1193, 1194, 1553, 13, 13, 301, 957, 1232,
162012 /* 710 */ 1152, 193, 409, 1152, 382, 1543, 1170, 32, 297, 474, 164091 /* 710 */ 1158, 153, 409, 1158, 373, 1583, 1176, 5, 369, 1580,
162013 /* 720 */ 195, 1527, 5, 952, 120, 120, 120, 120, 119, 119, 164092 /* 720 */ 429, 1238, 3, 957, 122, 122, 122, 122, 121, 121,
162014 /* 730 */ 118, 118, 118, 117, 113, 444, 123, 124, 114, 1210, 164093 /* 730 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1217,
162015 /* 740 */ 1210, 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, 164094 /* 740 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
162016 /* 750 */ 122, 409, 1067, 419, 1186, 1024, 1186, 1187, 1188, 1186, 164095 /* 750 */ 124, 409, 208, 567, 1192, 1028, 1192, 1193, 1194, 1192,
162017 /* 760 */ 419, 332, 460, 320, 544, 1545, 442, 442, 442, 566, 164096 /* 760 */ 388, 852, 155, 1552, 286, 402, 1098, 1098, 488, 568,
162018 /* 770 */ 3, 117, 113, 444, 453, 123, 124, 114, 1210, 1210, 164097 /* 770 */ 465, 342, 1319, 1319, 1552, 125, 126, 80, 1217, 1217,
162019 /* 780 */ 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, 122, 164098 /* 780 */ 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124, 124,
162020 /* 790 */ 1473, 566, 15, 15, 293, 120, 120, 120, 120, 119, 164099 /* 790 */ 129, 568, 13, 13, 374, 122, 122, 122, 122, 121,
162021 /* 800 */ 119, 118, 118, 118, 117, 113, 444, 1186, 566, 1486, 164100 /* 800 */ 121, 120, 120, 120, 119, 116, 444, 302, 568, 453,
162022 /* 810 */ 1412, 1186, 1187, 1188, 13, 13, 1186, 1187, 1188, 1544, 164101 /* 810 */ 528, 1192, 1193, 1194, 13, 13, 1192, 1193, 1194, 1297,
162023 /* 820 */ 271, 271, 409, 286, 308, 557, 1008, 1486, 1488, 196, 164102 /* 820 */ 463, 1267, 409, 1317, 1317, 1552, 1012, 453, 452, 200,
162024 /* 830 */ 288, 71, 71, 563, 120, 120, 120, 120, 119, 119, 164103 /* 830 */ 299, 71, 71, 1265, 122, 122, 122, 122, 121, 121,
162025 /* 840 */ 118, 118, 118, 117, 113, 444, 123, 124, 114, 1210, 164104 /* 840 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1217,
162026 /* 850 */ 1210, 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, 164105 /* 850 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
162027 /* 860 */ 122, 409, 201, 1087, 1186, 1187, 1188, 1324, 304, 1529, 164106 /* 860 */ 124, 409, 227, 1073, 1158, 284, 284, 419, 312, 278,
162028 /* 870 */ 388, 278, 278, 450, 564, 402, 922, 922, 566, 563, 164107 /* 870 */ 278, 285, 285, 1419, 406, 405, 382, 1158, 565, 568,
162029 /* 880 */ 566, 426, 491, 480, 563, 123, 124, 114, 1210, 1210, 164108 /* 880 */ 1158, 1196, 565, 1600, 565, 125, 126, 80, 1217, 1217,
162030 /* 890 */ 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, 122, 164109 /* 890 */ 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124, 124,
162031 /* 900 */ 1486, 71, 71, 13, 13, 120, 120, 120, 120, 119, 164110 /* 900 */ 453, 1482, 13, 13, 1536, 122, 122, 122, 122, 121,
162032 /* 910 */ 119, 118, 118, 118, 117, 113, 444, 566, 545, 566, 164111 /* 910 */ 121, 120, 120, 120, 119, 116, 444, 201, 568, 354,
162033 /* 920 */ 1577, 573, 2, 1238, 1092, 1092, 488, 1480, 309, 1525, 164112 /* 920 */ 1586, 575, 2, 1245, 840, 841, 842, 1562, 317, 1212,
162034 /* 930 */ 142, 324, 409, 836, 837, 838, 312, 1320, 305, 363, 164113 /* 930 */ 146, 6, 409, 255, 254, 253, 206, 1327, 9, 1196,
162035 /* 940 */ 43, 43, 57, 57, 120, 120, 120, 120, 119, 119, 164114 /* 940 */ 262, 71, 71, 424, 122, 122, 122, 122, 121, 121,
162036 /* 950 */ 118, 118, 118, 117, 113, 444, 123, 124, 114, 1210, 164115 /* 950 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1217,
162037 /* 960 */ 1210, 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, 164116 /* 960 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
162038 /* 970 */ 122, 12, 277, 277, 566, 1152, 409, 572, 428, 1238, 164117 /* 970 */ 124, 568, 284, 284, 568, 1213, 409, 574, 313, 1245,
162039 /* 980 */ 465, 334, 296, 474, 309, 563, 142, 249, 1152, 308, 164118 /* 980 */ 349, 1296, 352, 419, 317, 565, 146, 491, 525, 1643,
162040 /* 990 */ 557, 1152, 321, 1320, 323, 491, 455, 71, 71, 233, 164119 /* 990 */ 395, 371, 491, 1327, 70, 70, 1295, 71, 71, 240,
162041 /* 1000 */ 283, 101, 114, 1210, 1210, 1044, 1047, 1036, 1036, 121, 164120 /* 1000 */ 1325, 104, 80, 1217, 1217, 1050, 1053, 1040, 1040, 123,
162042 /* 1010 */ 121, 122, 122, 122, 122, 120, 120, 120, 120, 119, 164121 /* 1010 */ 123, 124, 124, 124, 124, 122, 122, 122, 122, 121,
162043 /* 1020 */ 119, 118, 118, 118, 117, 113, 444, 1108, 277, 277, 164122 /* 1020 */ 121, 120, 120, 120, 119, 116, 444, 1114, 284, 284,
162044 /* 1030 */ 1412, 448, 394, 1230, 439, 277, 277, 248, 247, 246, 164123 /* 1030 */ 428, 448, 1525, 1213, 439, 284, 284, 1489, 1352, 311,
162045 /* 1040 */ 1319, 563, 1109, 313, 198, 294, 491, 1318, 563, 464, 164124 /* 1040 */ 474, 565, 1115, 971, 491, 491, 217, 1263, 565, 1538,
162046 /* 1050 */ 566, 1427, 394, 1130, 1023, 233, 414, 1110, 295, 120, 164125 /* 1050 */ 568, 972, 207, 568, 1027, 240, 383, 1116, 519, 122,
162047 /* 1060 */ 120, 120, 120, 119, 119, 118, 118, 118, 117, 113, 164126 /* 1060 */ 122, 122, 122, 121, 121, 120, 120, 120, 119, 116,
162048 /* 1070 */ 444, 1014, 104, 71, 71, 1013, 322, 496, 908, 566, 164127 /* 1070 */ 444, 1018, 107, 71, 71, 1017, 13, 13, 912, 568,
162049 /* 1080 */ 277, 277, 277, 277, 1108, 1261, 415, 448, 909, 361, 164128 /* 1080 */ 1495, 568, 284, 284, 97, 526, 491, 448, 913, 1326,
162050 /* 1090 */ 1571, 1315, 409, 563, 952, 563, 9, 202, 255, 1109, 164129 /* 1090 */ 1322, 545, 409, 284, 284, 565, 151, 209, 1495, 1497,
162051 /* 1100 */ 316, 487, 44, 44, 249, 559, 415, 1013, 1013, 1015, 164130 /* 1100 */ 262, 450, 55, 55, 56, 56, 565, 1017, 1017, 1019,
162052 /* 1110 */ 443, 1231, 409, 1603, 1110, 897, 123, 124, 114, 1210, 164131 /* 1110 */ 443, 332, 409, 527, 12, 295, 125, 126, 80, 1217,
162053 /* 1120 */ 1210, 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, 164132 /* 1120 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
162054 /* 1130 */ 122, 1231, 409, 1207, 215, 554, 123, 124, 114, 1210, 164133 /* 1130 */ 124, 347, 409, 864, 1534, 1213, 125, 126, 80, 1217,
162055 /* 1140 */ 1210, 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, 164134 /* 1140 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
162056 /* 1150 */ 122, 1131, 1631, 470, 1631, 255, 123, 111, 114, 1210, 164135 /* 1150 */ 124, 1137, 1641, 474, 1641, 371, 125, 114, 80, 1217,
162057 /* 1160 */ 1210, 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, 164136 /* 1160 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
162058 /* 1170 */ 122, 1131, 1632, 414, 1632, 120, 120, 120, 120, 119, 164137 /* 1170 */ 124, 1495, 329, 474, 331, 122, 122, 122, 122, 121,
162059 /* 1180 */ 119, 118, 118, 118, 117, 113, 444, 221, 209, 351, 164138 /* 1180 */ 121, 120, 120, 120, 119, 116, 444, 203, 1419, 568,
162060 /* 1190 */ 1207, 1207, 147, 1426, 491, 120, 120, 120, 120, 119, 164139 /* 1190 */ 1294, 864, 464, 1213, 436, 122, 122, 122, 122, 121,
162061 /* 1200 */ 119, 118, 118, 118, 117, 113, 444, 1256, 539, 519, 164140 /* 1200 */ 121, 120, 120, 120, 119, 116, 444, 553, 1137, 1642,
162062 /* 1210 */ 888, 551, 952, 12, 566, 120, 120, 120, 120, 119, 164141 /* 1210 */ 539, 1642, 15, 15, 892, 122, 122, 122, 122, 121,
162063 /* 1220 */ 119, 118, 118, 118, 117, 113, 444, 538, 566, 860, 164142 /* 1220 */ 121, 120, 120, 120, 119, 116, 444, 568, 298, 538,
162064 /* 1230 */ 1129, 361, 1571, 346, 1356, 409, 1163, 58, 58, 339, 164143 /* 1230 */ 1135, 1419, 1559, 1560, 1331, 409, 6, 6, 1169, 1268,
162065 /* 1240 */ 1355, 508, 277, 277, 277, 277, 277, 277, 1207, 889, 164144 /* 1240 */ 415, 320, 284, 284, 1419, 508, 565, 525, 300, 457,
162066 /* 1250 */ 1129, 59, 59, 459, 363, 563, 566, 563, 96, 563, 164145 /* 1250 */ 43, 43, 568, 893, 12, 565, 330, 478, 425, 407,
162067 /* 1260 */ 124, 114, 1210, 1210, 1044, 1047, 1036, 1036, 121, 121, 164146 /* 1260 */ 126, 80, 1217, 1217, 1050, 1053, 1040, 1040, 123, 123,
162068 /* 1270 */ 122, 122, 122, 122, 566, 1412, 566, 281, 1186, 60, 164147 /* 1270 */ 124, 124, 124, 124, 568, 57, 57, 288, 1192, 1419,
162069 /* 1280 */ 60, 110, 392, 392, 391, 266, 389, 860, 1163, 845, 164148 /* 1280 */ 496, 458, 392, 392, 391, 273, 389, 1135, 1558, 849,
162070 /* 1290 */ 566, 481, 566, 436, 341, 1152, 344, 61, 61, 62, 164149 /* 1290 */ 1169, 407, 6, 568, 321, 1158, 470, 44, 44, 1557,
162071 /* 1300 */ 62, 967, 227, 1550, 315, 431, 540, 6, 1152, 968, 164150 /* 1300 */ 1114, 426, 234, 6, 323, 256, 540, 256, 1158, 431,
162072 /* 1310 */ 566, 1152, 314, 45, 45, 46, 46, 512, 120, 120, 164151 /* 1310 */ 568, 1158, 322, 17, 487, 1115, 58, 58, 122, 122,
162073 /* 1320 */ 120, 120, 119, 119, 118, 118, 118, 117, 113, 444, 164152 /* 1320 */ 122, 122, 121, 121, 120, 120, 120, 119, 116, 444,
162074 /* 1330 */ 416, 173, 1532, 47, 47, 1186, 1187, 1188, 108, 558, 164153 /* 1330 */ 1116, 216, 481, 59, 59, 1192, 1193, 1194, 111, 560,
162075 /* 1340 */ 325, 4, 229, 1551, 928, 566, 437, 6, 566, 927, 164154 /* 1340 */ 324, 4, 236, 456, 526, 568, 237, 456, 568, 437,
162076 /* 1350 */ 164, 566, 1290, 137, 1190, 561, 566, 1549, 566, 1089, 164155 /* 1350 */ 168, 556, 420, 141, 479, 563, 568, 293, 568, 1095,
162077 /* 1360 */ 566, 6, 566, 1089, 531, 566, 868, 8, 49, 49, 164156 /* 1360 */ 568, 293, 568, 1095, 531, 568, 872, 8, 60, 60,
162078 /* 1370 */ 228, 50, 50, 566, 63, 63, 566, 457, 445, 64, 164157 /* 1370 */ 235, 61, 61, 568, 414, 568, 414, 568, 445, 62,
162079 /* 1380 */ 64, 65, 65, 14, 14, 66, 66, 407, 129, 129, 164158 /* 1380 */ 62, 45, 45, 46, 46, 47, 47, 199, 49, 49,
162080 /* 1390 */ 555, 566, 458, 566, 1505, 486, 67, 67, 566, 52, 164159 /* 1390 */ 557, 568, 359, 568, 100, 486, 50, 50, 63, 63,
162081 /* 1400 */ 52, 546, 407, 467, 535, 410, 226, 1023, 566, 534, 164160 /* 1400 */ 64, 64, 561, 415, 535, 410, 568, 1027, 568, 534,
162082 /* 1410 */ 308, 557, 1190, 407, 68, 68, 69, 69, 566, 1023, 164161 /* 1410 */ 316, 559, 316, 559, 65, 65, 14, 14, 568, 1027,
162083 /* 1420 */ 566, 53, 53, 868, 1014, 106, 106, 525, 1013, 566, 164162 /* 1420 */ 568, 512, 932, 872, 1018, 109, 109, 931, 1017, 66,
162084 /* 1430 */ 1504, 159, 159, 107, 451, 445, 568, 567, 471, 307, 164163 /* 1430 */ 66, 131, 131, 110, 451, 445, 570, 569, 416, 177,
162085 /* 1440 */ 1013, 160, 160, 76, 76, 566, 1548, 466, 407, 407, 164164 /* 1440 */ 1017, 132, 132, 67, 67, 568, 467, 568, 932, 471,
162086 /* 1450 */ 6, 1225, 54, 54, 478, 276, 219, 566, 887, 886, 164165 /* 1450 */ 1364, 283, 226, 931, 315, 1363, 407, 568, 459, 407,
162087 /* 1460 */ 1013, 1013, 1015, 84, 206, 1206, 230, 282, 72, 72, 164166 /* 1460 */ 1017, 1017, 1019, 239, 407, 86, 213, 1350, 52, 52,
162088 /* 1470 */ 329, 483, 1013, 1013, 1015, 1016, 27, 1576, 1174, 447, 164167 /* 1470 */ 68, 68, 1017, 1017, 1019, 1020, 27, 1585, 1180, 447,
162089 /* 1480 */ 130, 130, 281, 148, 105, 38, 103, 392, 392, 391, 164168 /* 1480 */ 69, 69, 288, 97, 108, 1541, 106, 392, 392, 391,
162090 /* 1490 */ 266, 389, 566, 1126, 845, 396, 566, 108, 558, 566, 164169 /* 1490 */ 273, 389, 568, 879, 849, 883, 568, 111, 560, 466,
162091 /* 1500 */ 4, 311, 566, 30, 17, 566, 279, 227, 566, 315, 164170 /* 1500 */ 4, 568, 152, 30, 38, 568, 1132, 234, 396, 323,
162092 /* 1510 */ 108, 558, 468, 4, 561, 73, 73, 314, 566, 157, 164171 /* 1510 */ 111, 560, 527, 4, 563, 53, 53, 322, 568, 163,
162093 /* 1520 */ 157, 566, 131, 131, 526, 132, 132, 561, 128, 128, 164172 /* 1520 */ 163, 568, 337, 468, 164, 164, 333, 563, 76, 76,
162094 /* 1530 */ 566, 158, 158, 566, 31, 291, 566, 445, 330, 521, 164173 /* 1530 */ 568, 289, 1514, 568, 31, 1513, 568, 445, 338, 483,
162095 /* 1540 */ 98, 152, 152, 420, 136, 136, 1005, 229, 254, 555, 164174 /* 1540 */ 100, 54, 54, 344, 72, 72, 296, 236, 1080, 557,
162096 /* 1550 */ 445, 479, 336, 135, 135, 164, 133, 133, 137, 134, 164175 /* 1550 */ 445, 879, 1360, 134, 134, 168, 73, 73, 141, 161,
162097 /* 1560 */ 134, 875, 555, 535, 566, 473, 566, 254, 536, 475, 164176 /* 1560 */ 161, 1574, 557, 535, 568, 319, 568, 348, 536, 1009,
162098 /* 1570 */ 335, 254, 98, 894, 895, 228, 535, 566, 1023, 566, 164177 /* 1570 */ 473, 261, 261, 891, 890, 235, 535, 568, 1027, 568,
162099 /* 1580 */ 1074, 534, 210, 232, 106, 106, 1352, 75, 75, 77, 164178 /* 1580 */ 475, 534, 261, 367, 109, 109, 521, 136, 136, 130,
162100 /* 1590 */ 77, 1023, 107, 340, 445, 568, 567, 106, 106, 1013, 164179 /* 1590 */ 130, 1027, 110, 366, 445, 570, 569, 109, 109, 1017,
162101 /* 1600 */ 74, 74, 42, 42, 566, 107, 343, 445, 568, 567, 164180 /* 1600 */ 162, 162, 156, 156, 568, 110, 1080, 445, 570, 569,
162102 /* 1610 */ 410, 497, 1013, 251, 359, 308, 557, 1135, 349, 875, 164181 /* 1610 */ 410, 351, 1017, 568, 353, 316, 559, 568, 343, 568,
162103 /* 1620 */ 98, 1070, 345, 251, 358, 1591, 347, 48, 48, 1017, 164182 /* 1620 */ 100, 497, 357, 258, 100, 898, 899, 140, 140, 355,
162104 /* 1630 */ 1303, 1013, 1013, 1015, 1016, 27, 1289, 1287, 1074, 451, 164183 /* 1630 */ 1310, 1017, 1017, 1019, 1020, 27, 139, 139, 362, 451,
162105 /* 1640 */ 961, 925, 254, 110, 1013, 1013, 1015, 1016, 27, 1174, 164184 /* 1640 */ 137, 137, 138, 138, 1017, 1017, 1019, 1020, 27, 1180,
162106 /* 1650 */ 447, 970, 971, 281, 108, 558, 1288, 4, 392, 392, 164185 /* 1650 */ 447, 568, 372, 288, 111, 560, 1021, 4, 392, 392,
162107 /* 1660 */ 391, 266, 389, 1343, 1086, 845, 1086, 1085, 858, 1085, 164186 /* 1660 */ 391, 273, 389, 568, 1141, 849, 568, 1076, 568, 258,
162108 /* 1670 */ 146, 561, 926, 354, 110, 303, 364, 553, 227, 1364, 164187 /* 1670 */ 492, 563, 568, 211, 75, 75, 555, 962, 234, 261,
162109 /* 1680 */ 315, 108, 558, 1411, 4, 1339, 492, 1017, 314, 1350, 164188 /* 1680 */ 323, 111, 560, 929, 4, 113, 77, 77, 322, 74,
162110 /* 1690 */ 1565, 552, 1417, 1268, 445, 204, 1259, 1247, 561, 1246, 164189 /* 1690 */ 74, 42, 42, 1373, 445, 48, 48, 1418, 563, 974,
162111 /* 1700 */ 1248, 1584, 269, 1336, 367, 369, 555, 371, 11, 212, 164190 /* 1700 */ 975, 1092, 1091, 1092, 1091, 862, 557, 150, 930, 1346,
162112 /* 1710 */ 393, 225, 1393, 284, 1398, 456, 287, 327, 229, 328, 164191 /* 1710 */ 113, 1358, 554, 1424, 1021, 1275, 1266, 1254, 236, 1253,
162113 /* 1720 */ 292, 445, 1386, 216, 333, 1403, 164, 477, 373, 137, 164192 /* 1720 */ 1255, 445, 1593, 1343, 308, 276, 168, 309, 11, 141,
162114 /* 1730 */ 1402, 400, 502, 555, 1286, 1023, 357, 1477, 199, 1587, 164193 /* 1730 */ 393, 310, 232, 557, 1405, 1027, 335, 291, 1400, 219,
162115 /* 1740 */ 211, 106, 106, 932, 1476, 1225, 228, 556, 175, 107, 164194 /* 1740 */ 336, 109, 109, 936, 297, 1410, 235, 341, 477, 110,
162116 /* 1750 */ 200, 445, 568, 567, 258, 387, 1013, 1524, 1522, 223, 164195 /* 1750 */ 502, 445, 570, 569, 1393, 1409, 1017, 400, 1293, 365,
162117 /* 1760 */ 1222, 418, 1023, 83, 208, 79, 82, 184, 106, 106, 164196 /* 1760 */ 223, 1486, 1027, 1485, 1355, 1356, 1354, 1353, 109, 109,
162118 /* 1770 */ 1482, 169, 177, 461, 179, 462, 107, 1399, 445, 568, 164197 /* 1770 */ 204, 1596, 1232, 558, 265, 218, 110, 205, 445, 570,
162119 /* 1780 */ 567, 410, 180, 1013, 495, 181, 308, 557, 1013, 1013, 164198 /* 1780 */ 569, 410, 387, 1017, 1533, 179, 316, 559, 1017, 1017,
162120 /* 1790 */ 1015, 1016, 27, 182, 35, 235, 100, 558, 398, 4, 164199 /* 1790 */ 1019, 1020, 27, 230, 1531, 1229, 79, 560, 85, 4,
162121 /* 1800 */ 96, 1405, 1404, 36, 484, 469, 1407, 188, 401, 1471, 164200 /* 1800 */ 418, 215, 548, 81, 84, 188, 1406, 173, 181, 461,
162122 /* 1810 */ 451, 89, 1493, 561, 239, 1013, 1013, 1015, 1016, 27, 164201 /* 1810 */ 451, 35, 462, 563, 183, 1017, 1017, 1019, 1020, 27,
162123 /* 1820 */ 490, 338, 270, 241, 192, 342, 493, 242, 403, 1249, 164202 /* 1820 */ 184, 1491, 185, 186, 495, 242, 98, 398, 1412, 36,
162124 /* 1830 */ 243, 511, 432, 1297, 1306, 91, 445, 1305, 1304, 879, 164203 /* 1830 */ 1411, 484, 91, 469, 401, 1414, 445, 192, 1480, 246,
162125 /* 1840 */ 217, 434, 435, 1570, 1276, 1602, 520, 1601, 555, 301, 164204 /* 1840 */ 1502, 490, 346, 277, 248, 196, 493, 511, 557, 350,
162126 /* 1850 */ 527, 404, 1275, 302, 356, 1274, 1600, 95, 1347, 366, 164205 /* 1850 */ 1256, 249, 250, 403, 1313, 1312, 111, 560, 432, 4,
162127 /* 1860 */ 1296, 362, 1348, 368, 256, 257, 1556, 1555, 438, 1346, 164206 /* 1860 */ 1311, 1304, 93, 1611, 883, 1610, 224, 404, 434, 520,
162128 /* 1870 */ 370, 126, 1345, 10, 1371, 546, 381, 1023, 102, 1457, 164207 /* 1870 */ 263, 435, 1579, 563, 1283, 1282, 364, 1027, 306, 1281,
162129 /* 1880 */ 97, 530, 34, 106, 106, 570, 1180, 372, 265, 1329, 164208 /* 1880 */ 264, 1609, 1565, 109, 109, 370, 1303, 307, 1564, 438,
162130 /* 1890 */ 379, 107, 203, 445, 568, 567, 1328, 385, 1013, 1370, 164209 /* 1890 */ 128, 110, 1378, 445, 570, 569, 445, 546, 1017, 10,
162131 /* 1900 */ 386, 267, 268, 571, 1244, 161, 1239, 162, 1509, 1510, 164210 /* 1900 */ 1466, 105, 381, 1377, 34, 572, 99, 1336, 557, 314,
162132 /* 1910 */ 1508, 143, 1507, 299, 832, 213, 214, 78, 446, 205, 164211 /* 1910 */ 1186, 530, 272, 274, 379, 210, 1335, 547, 385, 386,
162133 /* 1920 */ 310, 306, 163, 224, 1084, 140, 1082, 318, 165, 176, 164212 /* 1920 */ 275, 573, 1251, 1246, 411, 412, 1518, 165, 178, 1519,
162134 /* 1930 */ 1013, 1013, 1015, 1016, 27, 178, 1206, 231, 911, 234, 164213 /* 1930 */ 1017, 1017, 1019, 1020, 27, 1517, 1516, 1027, 78, 147,
162135 /* 1940 */ 326, 1098, 183, 421, 166, 167, 411, 185, 85, 423, 164214 /* 1940 */ 166, 220, 221, 109, 109, 836, 304, 167, 446, 212,
162136 /* 1950 */ 412, 86, 174, 87, 168, 88, 1101, 236, 1097, 237, 164215 /* 1950 */ 318, 110, 231, 445, 570, 569, 144, 1090, 1017, 1088,
162137 /* 1960 */ 154, 18, 238, 254, 337, 1219, 489, 1090, 240, 190, 164216 /* 1960 */ 326, 180, 169, 1212, 182, 334, 238, 915, 241, 1104,
162138 /* 1970 */ 37, 847, 189, 494, 358, 244, 350, 506, 191, 877, 164217 /* 1970 */ 187, 170, 171, 421, 87, 88, 423, 189, 89, 90,
162139 /* 1980 */ 90, 498, 19, 20, 503, 92, 353, 890, 300, 170, 164218 /* 1980 */ 172, 1107, 243, 1103, 244, 158, 18, 245, 345, 247,
162140 /* 1990 */ 155, 93, 513, 94, 1168, 156, 1050, 1137, 39, 218, 164219 /* 1990 */ 1017, 1017, 1019, 1020, 27, 261, 1096, 193, 1226, 489,
162141 /* 2000 */ 273, 275, 1136, 960, 194, 955, 110, 1154, 1158, 253, 164220 /* 2000 */ 194, 37, 366, 851, 494, 251, 195, 506, 92, 19,
162142 /* 2010 */ 7, 1162, 1156, 21, 22, 1161, 1142, 23, 24, 25, 164221 /* 2010 */ 498, 358, 20, 503, 881, 361, 94, 894, 305, 159,
162143 /* 2020 */ 33, 542, 26, 260, 197, 98, 1065, 1051, 1049, 1053, 164222 /* 2020 */ 513, 39, 95, 1174, 160, 1056, 966, 1143, 96, 174,
162144 /* 2030 */ 1107, 1054, 1106, 259, 28, 40, 562, 1018, 859, 109, 164223 /* 2030 */ 1142, 225, 280, 282, 198, 960, 113, 1164, 1160, 260,
162145 /* 2040 */ 29, 921, 390, 1176, 172, 139, 1175, 1235, 261, 1235, 164224 /* 2040 */ 21, 22, 23, 1162, 1168, 1167, 1148, 24, 33, 25,
162146 /* 2050 */ 1235, 1235, 1235, 1235, 1235, 1235, 1235, 262, 1235, 1235, 164225 /* 2050 */ 202, 542, 26, 100, 1071, 102, 1057, 103, 7, 1055,
162147 /* 2060 */ 1235, 1235, 1235, 1235, 1235, 1235, 1235, 1235, 1593, 1592, 164226 /* 2060 */ 1059, 1113, 1060, 1112, 266, 267, 28, 40, 390, 1022,
164227 /* 2070 */ 863, 112, 29, 564, 1182, 1181, 268, 176, 143, 925,
164228 /* 2080 */ 1242, 1242, 1242, 1242, 1242, 1242, 1242, 1242, 1242, 1242,
164229 /* 2090 */ 1242, 1242, 1242, 1242, 269, 1602, 1242, 1601,
162148}; 164230};
162149static const YYCODETYPE yy_lookahead[] = { 164231static const YYCODETYPE yy_lookahead[] = {
162150 /* 0 */ 193, 223, 193, 225, 193, 193, 193, 274, 275, 276, 164232 /* 0 */ 193, 193, 193, 274, 275, 276, 193, 274, 275, 276,
162151 /* 10 */ 193, 233, 219, 193, 274, 275, 276, 206, 206, 19, 164233 /* 10 */ 193, 223, 219, 225, 206, 210, 211, 212, 193, 19,
162152 /* 20 */ 193, 219, 216, 216, 217, 216, 217, 193, 295, 216, 164234 /* 20 */ 219, 233, 216, 216, 217, 216, 217, 193, 295, 216,
162153 /* 30 */ 217, 31, 205, 216, 217, 193, 216, 217, 213, 39, 164235 /* 30 */ 217, 31, 193, 216, 217, 193, 228, 213, 230, 39,
162154 /* 40 */ 228, 193, 230, 43, 44, 45, 46, 47, 48, 49, 164236 /* 40 */ 206, 216, 217, 43, 44, 45, 46, 47, 48, 49,
162155 /* 50 */ 50, 51, 52, 53, 54, 55, 56, 57, 193, 19, 164237 /* 50 */ 50, 51, 52, 53, 54, 55, 56, 57, 193, 19,
162156 /* 60 */ 185, 186, 187, 188, 189, 190, 253, 274, 275, 276, 164238 /* 60 */ 185, 186, 187, 188, 189, 190, 253, 274, 275, 276,
162157 /* 70 */ 195, 193, 197, 253, 216, 262, 274, 275, 276, 204, 164239 /* 70 */ 195, 193, 197, 193, 261, 274, 275, 276, 253, 204,
162158 /* 80 */ 238, 204, 262, 43, 44, 45, 46, 47, 48, 49, 164240 /* 80 */ 238, 204, 81, 43, 44, 45, 46, 47, 48, 49,
162159 /* 90 */ 50, 51, 52, 53, 54, 55, 56, 57, 264, 274, 164241 /* 90 */ 50, 51, 52, 53, 54, 55, 56, 57, 274, 275,
162160 /* 100 */ 275, 276, 102, 103, 104, 105, 106, 107, 108, 109, 164242 /* 100 */ 276, 262, 102, 103, 104, 105, 106, 107, 108, 109,
162161 /* 110 */ 110, 111, 112, 113, 239, 240, 239, 240, 210, 211, 164243 /* 110 */ 110, 111, 112, 113, 239, 240, 239, 240, 210, 211,
162162 /* 120 */ 212, 314, 315, 314, 59, 316, 86, 252, 88, 252, 164244 /* 120 */ 212, 314, 315, 314, 59, 316, 86, 252, 88, 252,
162163 /* 130 */ 19, 314, 315, 256, 257, 309, 25, 72, 296, 313, 164245 /* 130 */ 19, 314, 315, 256, 257, 113, 25, 72, 296, 138,
162164 /* 140 */ 193, 266, 102, 103, 104, 105, 106, 107, 108, 109, 164246 /* 140 */ 139, 266, 102, 103, 104, 105, 106, 107, 108, 109,
162165 /* 150 */ 110, 111, 112, 113, 43, 44, 45, 46, 47, 48, 164247 /* 150 */ 110, 111, 112, 113, 43, 44, 45, 46, 47, 48,
162166 /* 160 */ 49, 50, 51, 52, 53, 54, 55, 56, 57, 81, 164248 /* 160 */ 49, 50, 51, 52, 53, 54, 55, 56, 57, 81,
162167 /* 170 */ 292, 59, 307, 298, 108, 109, 110, 111, 112, 113, 164249 /* 170 */ 292, 59, 292, 298, 108, 109, 110, 111, 112, 113,
162168 /* 180 */ 69, 116, 117, 118, 72, 128, 129, 193, 241, 22, 164250 /* 180 */ 69, 116, 117, 118, 72, 106, 107, 193, 111, 112,
162169 /* 190 */ 113, 54, 55, 56, 57, 58, 102, 103, 104, 105, 164251 /* 190 */ 113, 54, 55, 56, 57, 58, 102, 103, 104, 105,
162170 /* 200 */ 106, 107, 108, 109, 110, 111, 112, 113, 120, 193, 164252 /* 200 */ 106, 107, 108, 109, 110, 111, 112, 113, 120, 25,
162171 /* 210 */ 216, 217, 25, 102, 103, 104, 105, 106, 107, 108, 164253 /* 210 */ 216, 217, 145, 102, 103, 104, 105, 106, 107, 108,
162172 /* 220 */ 109, 110, 111, 112, 113, 231, 138, 139, 116, 117, 164254 /* 220 */ 109, 110, 111, 112, 113, 231, 138, 139, 116, 117,
162173 /* 230 */ 118, 106, 107, 19, 216, 54, 55, 56, 57, 102, 164255 /* 230 */ 118, 164, 153, 19, 155, 54, 55, 56, 57, 102,
162174 /* 240 */ 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 164256 /* 240 */ 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
162175 /* 250 */ 113, 304, 25, 46, 47, 48, 49, 43, 44, 45, 164257 /* 250 */ 113, 128, 129, 46, 47, 48, 49, 43, 44, 45,
162176 /* 260 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 164258 /* 260 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
162177 /* 270 */ 56, 57, 193, 106, 107, 59, 193, 19, 153, 263, 164259 /* 270 */ 56, 57, 216, 193, 25, 59, 193, 19, 165, 166,
162178 /* 280 */ 155, 67, 24, 102, 103, 104, 105, 106, 107, 108, 164260 /* 280 */ 193, 67, 24, 102, 103, 104, 105, 106, 107, 108,
162179 /* 290 */ 109, 110, 111, 112, 113, 216, 217, 59, 230, 216, 164261 /* 290 */ 109, 110, 111, 112, 113, 73, 216, 217, 59, 216,
162180 /* 300 */ 217, 43, 44, 45, 46, 47, 48, 49, 50, 51, 164262 /* 300 */ 217, 43, 44, 45, 46, 47, 48, 49, 50, 51,
162181 /* 310 */ 52, 53, 54, 55, 56, 57, 102, 103, 104, 105, 164263 /* 310 */ 52, 53, 54, 55, 56, 57, 102, 103, 104, 105,
162182 /* 320 */ 106, 107, 108, 109, 110, 111, 112, 113, 121, 142, 164264 /* 320 */ 106, 107, 108, 109, 110, 111, 112, 113, 121, 145,
162183 /* 330 */ 59, 193, 116, 117, 118, 119, 253, 204, 122, 123, 164265 /* 330 */ 59, 193, 116, 117, 118, 119, 273, 204, 122, 123,
162184 /* 340 */ 124, 19, 20, 81, 22, 262, 108, 19, 132, 165, 164266 /* 340 */ 124, 19, 20, 134, 22, 136, 137, 19, 132, 127,
162185 /* 350 */ 166, 193, 24, 126, 116, 117, 118, 278, 36, 193, 164267 /* 350 */ 128, 129, 24, 22, 23, 116, 117, 118, 36, 193,
162186 /* 360 */ 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 164268 /* 360 */ 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
162187 /* 370 */ 112, 113, 239, 240, 216, 217, 215, 106, 107, 241, 164269 /* 370 */ 112, 113, 239, 240, 311, 312, 215, 106, 107, 241,
162188 /* 380 */ 19, 59, 216, 217, 223, 252, 115, 116, 117, 118, 164270 /* 380 */ 19, 59, 216, 217, 223, 252, 115, 116, 117, 118,
162189 /* 390 */ 73, 120, 26, 71, 193, 22, 193, 231, 81, 128, 164271 /* 390 */ 151, 120, 26, 71, 193, 308, 309, 193, 149, 128,
162190 /* 400 */ 138, 139, 269, 81, 43, 44, 45, 46, 47, 48, 164272 /* 400 */ 313, 216, 269, 81, 43, 44, 45, 46, 47, 48,
162191 /* 410 */ 49, 50, 51, 52, 53, 54, 55, 56, 57, 216, 164273 /* 410 */ 49, 50, 51, 52, 53, 54, 55, 56, 57, 253,
162192 /* 420 */ 217, 198, 100, 95, 153, 59, 155, 193, 106, 107, 164274 /* 420 */ 216, 217, 100, 95, 153, 59, 155, 261, 106, 107,
162193 /* 430 */ 235, 236, 59, 193, 193, 249, 114, 251, 116, 117, 164275 /* 430 */ 25, 193, 101, 193, 193, 231, 114, 25, 116, 117,
162194 /* 440 */ 118, 113, 304, 121, 127, 204, 193, 119, 120, 121, 164276 /* 440 */ 118, 113, 304, 121, 193, 204, 59, 119, 120, 121,
162195 /* 450 */ 122, 123, 124, 125, 193, 138, 139, 216, 217, 131, 164277 /* 450 */ 122, 123, 124, 125, 216, 217, 193, 216, 217, 131,
162196 /* 460 */ 138, 139, 193, 102, 103, 104, 105, 106, 107, 108, 164278 /* 460 */ 138, 139, 230, 102, 103, 104, 105, 106, 107, 108,
162197 /* 470 */ 109, 110, 111, 112, 113, 153, 154, 155, 156, 157, 164279 /* 470 */ 109, 110, 111, 112, 113, 153, 154, 155, 156, 157,
162198 /* 480 */ 239, 240, 116, 117, 118, 76, 193, 193, 19, 116, 164280 /* 480 */ 239, 240, 116, 117, 118, 76, 193, 23, 19, 25,
162199 /* 490 */ 117, 118, 23, 252, 253, 193, 87, 204, 89, 238, 164281 /* 490 */ 22, 253, 23, 252, 253, 108, 87, 204, 89, 261,
162200 /* 500 */ 193, 92, 268, 262, 281, 203, 193, 205, 285, 216, 164282 /* 500 */ 198, 92, 261, 116, 117, 118, 193, 306, 307, 216,
162201 /* 510 */ 217, 150, 43, 44, 45, 46, 47, 48, 49, 50, 164283 /* 510 */ 217, 150, 43, 44, 45, 46, 47, 48, 49, 50,
162202 /* 520 */ 51, 52, 53, 54, 55, 56, 57, 193, 193, 216, 164284 /* 520 */ 51, 52, 53, 54, 55, 56, 57, 59, 193, 216,
162203 /* 530 */ 217, 19, 239, 240, 59, 23, 106, 107, 108, 109, 164285 /* 530 */ 217, 19, 239, 240, 283, 23, 106, 107, 108, 109,
162204 /* 540 */ 110, 111, 112, 113, 231, 252, 253, 193, 308, 309, 164286 /* 540 */ 110, 111, 112, 113, 73, 252, 253, 142, 308, 309,
162205 /* 550 */ 193, 145, 59, 313, 145, 43, 44, 45, 46, 47, 164287 /* 550 */ 138, 139, 81, 313, 145, 43, 44, 45, 46, 47,
162206 /* 560 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 164288 /* 560 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
162207 /* 570 */ 164, 102, 103, 104, 105, 106, 107, 108, 109, 110, 164289 /* 570 */ 307, 102, 103, 104, 105, 106, 107, 108, 109, 110,
162208 /* 580 */ 111, 112, 113, 119, 193, 193, 122, 123, 124, 193, 164290 /* 580 */ 111, 112, 113, 281, 116, 117, 118, 285, 23, 193,
162209 /* 590 */ 283, 116, 117, 118, 235, 236, 132, 59, 241, 264, 164291 /* 590 */ 25, 119, 59, 193, 122, 123, 124, 59, 127, 203,
162210 /* 600 */ 59, 193, 19, 23, 193, 25, 23, 216, 217, 116, 164292 /* 600 */ 59, 205, 19, 268, 132, 25, 23, 22, 193, 138,
162211 /* 610 */ 117, 118, 216, 217, 102, 103, 104, 105, 106, 107, 164293 /* 610 */ 139, 249, 204, 251, 102, 103, 104, 105, 106, 107,
162212 /* 620 */ 108, 109, 110, 111, 112, 113, 43, 44, 45, 46, 164294 /* 620 */ 108, 109, 110, 111, 112, 113, 43, 44, 45, 46,
162213 /* 630 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 164295 /* 630 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
162214 /* 640 */ 57, 19, 308, 309, 151, 23, 25, 313, 135, 253, 164296 /* 640 */ 57, 19, 22, 23, 59, 23, 25, 239, 240, 116,
162215 /* 650 */ 21, 193, 241, 140, 116, 117, 118, 116, 117, 118, 164297 /* 650 */ 117, 118, 193, 11, 116, 117, 118, 116, 117, 118,
162216 /* 660 */ 268, 304, 22, 301, 302, 43, 44, 45, 46, 47, 164298 /* 660 */ 252, 269, 22, 193, 15, 43, 44, 45, 46, 47,
162217 /* 670 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 164299 /* 670 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
162218 /* 680 */ 193, 143, 193, 193, 143, 102, 103, 104, 105, 106, 164300 /* 680 */ 273, 143, 193, 118, 143, 102, 103, 104, 105, 106,
162219 /* 690 */ 107, 108, 109, 110, 111, 112, 113, 76, 118, 59, 164301 /* 690 */ 107, 108, 109, 110, 111, 112, 113, 76, 118, 59,
162220 /* 700 */ 292, 211, 212, 216, 217, 216, 217, 73, 193, 80, 164302 /* 700 */ 241, 116, 117, 118, 304, 216, 217, 292, 143, 60,
162221 /* 710 */ 89, 25, 19, 92, 193, 304, 23, 22, 231, 193, 164303 /* 710 */ 89, 241, 19, 92, 193, 193, 23, 22, 311, 312,
162222 /* 720 */ 231, 193, 22, 143, 102, 103, 104, 105, 106, 107, 164304 /* 720 */ 231, 101, 22, 143, 102, 103, 104, 105, 106, 107,
162223 /* 730 */ 108, 109, 110, 111, 112, 113, 43, 44, 45, 46, 164305 /* 730 */ 108, 109, 110, 111, 112, 113, 43, 44, 45, 46,
162224 /* 740 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 164306 /* 740 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
162225 /* 750 */ 57, 19, 123, 193, 59, 23, 116, 117, 118, 59, 164307 /* 750 */ 57, 19, 193, 193, 59, 23, 116, 117, 118, 59,
162226 /* 760 */ 193, 127, 128, 129, 306, 307, 210, 211, 212, 193, 164308 /* 760 */ 201, 21, 241, 304, 22, 206, 127, 128, 129, 193,
162227 /* 770 */ 22, 111, 112, 113, 284, 43, 44, 45, 46, 47, 164309 /* 770 */ 128, 129, 235, 236, 304, 43, 44, 45, 46, 47,
162228 /* 780 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 164310 /* 780 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
162229 /* 790 */ 161, 193, 216, 217, 268, 102, 103, 104, 105, 106, 164311 /* 790 */ 22, 193, 216, 217, 193, 102, 103, 104, 105, 106,
162230 /* 800 */ 107, 108, 109, 110, 111, 112, 113, 59, 193, 193, 164312 /* 800 */ 107, 108, 109, 110, 111, 112, 113, 231, 193, 193,
162231 /* 810 */ 193, 116, 117, 118, 216, 217, 116, 117, 118, 304, 164313 /* 810 */ 193, 116, 117, 118, 216, 217, 116, 117, 118, 226,
162232 /* 820 */ 239, 240, 19, 263, 138, 139, 23, 211, 212, 231, 164314 /* 820 */ 80, 193, 19, 235, 236, 304, 23, 211, 212, 231,
162233 /* 830 */ 263, 216, 217, 252, 102, 103, 104, 105, 106, 107, 164315 /* 830 */ 204, 216, 217, 205, 102, 103, 104, 105, 106, 107,
162234 /* 840 */ 108, 109, 110, 111, 112, 113, 43, 44, 45, 46, 164316 /* 840 */ 108, 109, 110, 111, 112, 113, 43, 44, 45, 46,
162235 /* 850 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 164317 /* 850 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
162236 /* 860 */ 57, 19, 193, 11, 116, 117, 118, 240, 253, 193, 164318 /* 860 */ 57, 19, 193, 123, 76, 239, 240, 193, 253, 239,
162237 /* 870 */ 201, 239, 240, 193, 134, 206, 136, 137, 193, 252, 164319 /* 870 */ 240, 239, 240, 193, 106, 107, 193, 89, 252, 193,
162238 /* 880 */ 193, 264, 193, 193, 252, 43, 44, 45, 46, 47, 164320 /* 880 */ 92, 59, 252, 141, 252, 43, 44, 45, 46, 47,
162239 /* 890 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 164321 /* 890 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
162240 /* 900 */ 284, 216, 217, 216, 217, 102, 103, 104, 105, 106, 164322 /* 900 */ 284, 161, 216, 217, 193, 102, 103, 104, 105, 106,
162241 /* 910 */ 107, 108, 109, 110, 111, 112, 113, 193, 231, 193, 164323 /* 910 */ 107, 108, 109, 110, 111, 112, 113, 231, 193, 16,
162242 /* 920 */ 187, 188, 189, 190, 127, 128, 129, 238, 195, 193, 164324 /* 920 */ 187, 188, 189, 190, 7, 8, 9, 309, 195, 25,
162243 /* 930 */ 197, 16, 19, 7, 8, 9, 193, 204, 253, 193, 164325 /* 930 */ 197, 313, 19, 127, 128, 129, 262, 204, 22, 117,
162244 /* 940 */ 216, 217, 216, 217, 102, 103, 104, 105, 106, 107, 164326 /* 940 */ 24, 216, 217, 263, 102, 103, 104, 105, 106, 107,
162245 /* 950 */ 108, 109, 110, 111, 112, 113, 43, 44, 45, 46, 164327 /* 950 */ 108, 109, 110, 111, 112, 113, 43, 44, 45, 46,
162246 /* 960 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 164328 /* 960 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
162247 /* 970 */ 57, 213, 239, 240, 193, 76, 19, 188, 232, 190, 164329 /* 970 */ 57, 193, 239, 240, 193, 59, 19, 188, 253, 190,
162248 /* 980 */ 128, 129, 292, 193, 195, 252, 197, 46, 89, 138, 164330 /* 980 */ 77, 226, 79, 193, 195, 252, 197, 193, 19, 301,
162249 /* 990 */ 139, 92, 77, 204, 79, 193, 269, 216, 217, 266, 164331 /* 990 */ 302, 193, 193, 204, 216, 217, 226, 216, 217, 266,
162250 /* 1000 */ 204, 159, 45, 46, 47, 48, 49, 50, 51, 52, 164332 /* 1000 */ 204, 159, 45, 46, 47, 48, 49, 50, 51, 52,
162251 /* 1010 */ 53, 54, 55, 56, 57, 102, 103, 104, 105, 106, 164333 /* 1010 */ 53, 54, 55, 56, 57, 102, 103, 104, 105, 106,
162252 /* 1020 */ 107, 108, 109, 110, 111, 112, 113, 12, 239, 240, 164334 /* 1020 */ 107, 108, 109, 110, 111, 112, 113, 12, 239, 240,
162253 /* 1030 */ 193, 298, 22, 23, 253, 239, 240, 127, 128, 129, 164335 /* 1030 */ 232, 298, 238, 117, 253, 239, 240, 238, 259, 260,
162254 /* 1040 */ 238, 252, 27, 193, 286, 204, 193, 204, 252, 291, 164336 /* 1040 */ 193, 252, 27, 31, 193, 193, 142, 204, 252, 193,
162255 /* 1050 */ 193, 273, 22, 23, 100, 266, 115, 42, 268, 102, 164337 /* 1050 */ 193, 39, 262, 193, 100, 266, 278, 42, 204, 102,
162256 /* 1060 */ 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 164338 /* 1060 */ 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
162257 /* 1070 */ 113, 117, 159, 216, 217, 121, 161, 19, 63, 193, 164339 /* 1070 */ 113, 117, 159, 216, 217, 121, 216, 217, 63, 193,
162258 /* 1080 */ 239, 240, 239, 240, 12, 208, 209, 298, 73, 311, 164340 /* 1080 */ 193, 193, 239, 240, 115, 116, 193, 298, 73, 238,
162259 /* 1090 */ 312, 238, 19, 252, 25, 252, 22, 24, 24, 27, 164341 /* 1090 */ 238, 231, 19, 239, 240, 252, 22, 24, 211, 212,
162260 /* 1100 */ 193, 264, 216, 217, 46, 208, 209, 153, 154, 155, 164342 /* 1100 */ 24, 193, 216, 217, 216, 217, 252, 153, 154, 155,
162261 /* 1110 */ 253, 101, 19, 23, 42, 25, 43, 44, 45, 46, 164343 /* 1110 */ 253, 16, 19, 144, 213, 268, 43, 44, 45, 46,
162262 /* 1120 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 164344 /* 1120 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
162263 /* 1130 */ 57, 101, 19, 59, 25, 63, 43, 44, 45, 46, 164345 /* 1130 */ 57, 238, 19, 59, 193, 59, 43, 44, 45, 46,
162264 /* 1140 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 164346 /* 1140 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
162265 /* 1150 */ 57, 22, 23, 115, 25, 24, 43, 44, 45, 46, 164347 /* 1150 */ 57, 22, 23, 193, 25, 193, 43, 44, 45, 46,
162266 /* 1160 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 164348 /* 1160 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
162267 /* 1170 */ 57, 22, 23, 115, 25, 102, 103, 104, 105, 106, 164349 /* 1170 */ 57, 284, 77, 193, 79, 102, 103, 104, 105, 106,
162268 /* 1180 */ 107, 108, 109, 110, 111, 112, 113, 118, 150, 131, 164350 /* 1180 */ 107, 108, 109, 110, 111, 112, 113, 286, 193, 193,
162269 /* 1190 */ 59, 117, 22, 273, 193, 102, 103, 104, 105, 106, 164351 /* 1190 */ 193, 117, 291, 117, 232, 102, 103, 104, 105, 106,
162270 /* 1200 */ 107, 108, 109, 110, 111, 112, 113, 204, 66, 204, 164352 /* 1200 */ 107, 108, 109, 110, 111, 112, 113, 204, 22, 23,
162271 /* 1210 */ 35, 204, 143, 213, 193, 102, 103, 104, 105, 106, 164353 /* 1210 */ 66, 25, 216, 217, 35, 102, 103, 104, 105, 106,
162272 /* 1220 */ 107, 108, 109, 110, 111, 112, 113, 85, 193, 59, 164354 /* 1220 */ 107, 108, 109, 110, 111, 112, 113, 193, 268, 85,
162273 /* 1230 */ 101, 311, 312, 16, 193, 19, 94, 216, 217, 238, 164355 /* 1230 */ 101, 193, 309, 309, 240, 19, 313, 313, 94, 208,
162274 /* 1240 */ 193, 66, 239, 240, 239, 240, 239, 240, 117, 74, 164356 /* 1240 */ 209, 193, 239, 240, 193, 66, 252, 19, 268, 244,
162275 /* 1250 */ 101, 216, 217, 193, 193, 252, 193, 252, 149, 252, 164357 /* 1250 */ 216, 217, 193, 74, 213, 252, 161, 19, 263, 254,
162276 /* 1260 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 164358 /* 1260 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
162277 /* 1270 */ 54, 55, 56, 57, 193, 193, 193, 5, 59, 216, 164359 /* 1270 */ 54, 55, 56, 57, 193, 216, 217, 5, 59, 193,
162278 /* 1280 */ 217, 25, 10, 11, 12, 13, 14, 117, 146, 17, 164360 /* 1280 */ 19, 244, 10, 11, 12, 13, 14, 101, 309, 17,
162279 /* 1290 */ 193, 291, 193, 232, 77, 76, 79, 216, 217, 216, 164361 /* 1290 */ 146, 254, 313, 193, 193, 76, 115, 216, 217, 309,
162280 /* 1300 */ 217, 31, 30, 309, 32, 130, 87, 313, 89, 39, 164362 /* 1300 */ 12, 263, 30, 313, 32, 46, 87, 46, 89, 130,
162281 /* 1310 */ 193, 92, 40, 216, 217, 216, 217, 108, 102, 103, 164363 /* 1310 */ 193, 92, 40, 22, 263, 27, 216, 217, 102, 103,
162282 /* 1320 */ 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 164364 /* 1320 */ 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
162283 /* 1330 */ 299, 300, 193, 216, 217, 116, 117, 118, 19, 20, 164365 /* 1330 */ 42, 150, 291, 216, 217, 116, 117, 118, 19, 20,
162284 /* 1340 */ 193, 22, 70, 309, 135, 193, 264, 313, 193, 140, 164366 /* 1340 */ 193, 22, 70, 260, 116, 193, 24, 264, 193, 263,
162285 /* 1350 */ 78, 193, 226, 81, 59, 36, 193, 309, 193, 29, 164367 /* 1350 */ 78, 63, 61, 81, 116, 36, 193, 260, 193, 29,
162286 /* 1360 */ 193, 313, 193, 33, 145, 193, 59, 48, 216, 217, 164368 /* 1360 */ 193, 264, 193, 33, 145, 193, 59, 48, 216, 217,
162287 /* 1370 */ 98, 216, 217, 193, 216, 217, 193, 244, 59, 216, 164369 /* 1370 */ 98, 216, 217, 193, 115, 193, 115, 193, 59, 216,
162288 /* 1380 */ 217, 216, 217, 216, 217, 216, 217, 254, 216, 217, 164370 /* 1380 */ 217, 216, 217, 216, 217, 216, 217, 255, 216, 217,
162289 /* 1390 */ 71, 193, 244, 193, 193, 65, 216, 217, 193, 216, 164371 /* 1390 */ 71, 193, 131, 193, 25, 65, 216, 217, 216, 217,
162290 /* 1400 */ 217, 145, 254, 244, 85, 133, 15, 100, 193, 90, 164372 /* 1400 */ 216, 217, 208, 209, 85, 133, 193, 100, 193, 90,
162291 /* 1410 */ 138, 139, 117, 254, 216, 217, 216, 217, 193, 100, 164373 /* 1410 */ 138, 139, 138, 139, 216, 217, 216, 217, 193, 100,
162292 /* 1420 */ 193, 216, 217, 116, 117, 106, 107, 19, 121, 193, 164374 /* 1420 */ 193, 108, 135, 116, 117, 106, 107, 140, 121, 216,
162293 /* 1430 */ 193, 216, 217, 114, 162, 116, 117, 118, 244, 244, 164375 /* 1430 */ 217, 216, 217, 114, 162, 116, 117, 118, 299, 300,
162294 /* 1440 */ 121, 216, 217, 216, 217, 193, 309, 129, 254, 254, 164376 /* 1440 */ 121, 216, 217, 216, 217, 193, 244, 193, 135, 244,
162295 /* 1450 */ 313, 60, 216, 217, 19, 256, 257, 193, 120, 121, 164377 /* 1450 */ 193, 256, 257, 140, 244, 193, 254, 193, 193, 254,
162296 /* 1460 */ 153, 154, 155, 149, 150, 25, 24, 99, 216, 217, 164378 /* 1460 */ 153, 154, 155, 141, 254, 149, 150, 258, 216, 217,
162297 /* 1470 */ 152, 193, 153, 154, 155, 156, 157, 0, 1, 2, 164379 /* 1470 */ 216, 217, 153, 154, 155, 156, 157, 0, 1, 2,
162298 /* 1480 */ 216, 217, 5, 22, 158, 24, 160, 10, 11, 12, 164380 /* 1480 */ 216, 217, 5, 115, 158, 193, 160, 10, 11, 12,
162299 /* 1490 */ 13, 14, 193, 23, 17, 25, 193, 19, 20, 193, 164381 /* 1490 */ 13, 14, 193, 59, 17, 126, 193, 19, 20, 129,
162300 /* 1500 */ 22, 133, 193, 22, 22, 193, 22, 30, 193, 32, 164382 /* 1500 */ 22, 193, 22, 22, 24, 193, 23, 30, 25, 32,
162301 /* 1510 */ 19, 20, 129, 22, 36, 216, 217, 40, 193, 216, 164383 /* 1510 */ 19, 20, 144, 22, 36, 216, 217, 40, 193, 216,
162302 /* 1520 */ 217, 193, 216, 217, 116, 216, 217, 36, 216, 217, 164384 /* 1520 */ 217, 193, 152, 129, 216, 217, 193, 36, 216, 217,
162303 /* 1530 */ 193, 216, 217, 193, 53, 152, 193, 59, 23, 19, 164385 /* 1530 */ 193, 99, 193, 193, 53, 193, 193, 59, 23, 193,
162304 /* 1540 */ 25, 216, 217, 61, 216, 217, 23, 70, 25, 71, 164386 /* 1540 */ 25, 216, 217, 193, 216, 217, 152, 70, 59, 71,
162305 /* 1550 */ 59, 116, 193, 216, 217, 78, 216, 217, 81, 216, 164387 /* 1550 */ 59, 117, 193, 216, 217, 78, 216, 217, 81, 216,
162306 /* 1560 */ 217, 59, 71, 85, 193, 23, 193, 25, 90, 23, 164388 /* 1560 */ 217, 318, 71, 85, 193, 133, 193, 193, 90, 23,
162307 /* 1570 */ 23, 25, 25, 7, 8, 98, 85, 193, 100, 193, 164389 /* 1570 */ 23, 25, 25, 120, 121, 98, 85, 193, 100, 193,
162308 /* 1580 */ 59, 90, 142, 141, 106, 107, 193, 216, 217, 216, 164390 /* 1580 */ 23, 90, 25, 121, 106, 107, 19, 216, 217, 216,
162309 /* 1590 */ 217, 100, 114, 193, 116, 117, 118, 106, 107, 121, 164391 /* 1590 */ 217, 100, 114, 131, 116, 117, 118, 106, 107, 121,
162310 /* 1600 */ 216, 217, 216, 217, 193, 114, 193, 116, 117, 118, 164392 /* 1600 */ 216, 217, 216, 217, 193, 114, 117, 116, 117, 118,
162311 /* 1610 */ 133, 23, 121, 25, 121, 138, 139, 97, 23, 117, 164393 /* 1610 */ 133, 193, 121, 193, 193, 138, 139, 193, 23, 193,
162312 /* 1620 */ 25, 23, 193, 25, 131, 141, 193, 216, 217, 59, 164394 /* 1620 */ 25, 23, 23, 25, 25, 7, 8, 216, 217, 193,
162313 /* 1630 */ 193, 153, 154, 155, 156, 157, 226, 193, 117, 162, 164395 /* 1630 */ 193, 153, 154, 155, 156, 157, 216, 217, 193, 162,
162314 /* 1640 */ 23, 23, 25, 25, 153, 154, 155, 156, 157, 1, 164396 /* 1640 */ 216, 217, 216, 217, 153, 154, 155, 156, 157, 1,
162315 /* 1650 */ 2, 83, 84, 5, 19, 20, 226, 22, 10, 11, 164397 /* 1650 */ 2, 193, 193, 5, 19, 20, 59, 22, 10, 11,
162316 /* 1660 */ 12, 13, 14, 258, 153, 17, 155, 153, 23, 155, 164398 /* 1660 */ 12, 13, 14, 193, 97, 17, 193, 23, 193, 25,
162317 /* 1670 */ 25, 36, 23, 193, 25, 255, 193, 236, 30, 193, 164399 /* 1670 */ 288, 36, 193, 242, 216, 217, 236, 23, 30, 25,
162318 /* 1680 */ 32, 19, 20, 193, 22, 193, 288, 117, 40, 193, 164400 /* 1680 */ 32, 19, 20, 23, 22, 25, 216, 217, 40, 216,
162319 /* 1690 */ 318, 193, 193, 193, 59, 242, 193, 193, 36, 193, 164401 /* 1690 */ 217, 216, 217, 193, 59, 216, 217, 193, 36, 83,
162320 /* 1700 */ 193, 193, 287, 255, 255, 255, 71, 255, 243, 214, 164402 /* 1700 */ 84, 153, 153, 155, 155, 23, 71, 25, 23, 193,
162321 /* 1710 */ 191, 297, 267, 245, 271, 259, 259, 293, 70, 246, 164403 /* 1710 */ 25, 193, 193, 193, 117, 193, 193, 193, 70, 193,
162322 /* 1720 */ 246, 59, 267, 229, 245, 271, 78, 293, 259, 81, 164404 /* 1720 */ 193, 59, 193, 255, 255, 287, 78, 255, 243, 81,
162323 /* 1730 */ 271, 271, 220, 71, 225, 100, 219, 219, 249, 196, 164405 /* 1730 */ 191, 255, 297, 71, 271, 100, 293, 245, 267, 214,
162324 /* 1740 */ 243, 106, 107, 108, 219, 60, 98, 280, 297, 114, 164406 /* 1740 */ 246, 106, 107, 108, 246, 271, 98, 245, 293, 114,
162325 /* 1750 */ 249, 116, 117, 118, 141, 245, 121, 200, 200, 297, 164407 /* 1750 */ 220, 116, 117, 118, 267, 271, 121, 271, 225, 219,
162326 /* 1760 */ 38, 200, 100, 151, 150, 294, 294, 22, 106, 107, 164408 /* 1760 */ 229, 219, 100, 219, 259, 259, 259, 259, 106, 107,
162327 /* 1770 */ 283, 43, 234, 18, 237, 200, 114, 272, 116, 117, 164409 /* 1770 */ 249, 196, 60, 280, 141, 243, 114, 249, 116, 117,
162328 /* 1780 */ 118, 133, 237, 121, 18, 237, 138, 139, 153, 154, 164410 /* 1780 */ 118, 133, 245, 121, 200, 297, 138, 139, 153, 154,
162329 /* 1790 */ 155, 156, 157, 237, 270, 199, 19, 20, 246, 22, 164411 /* 1790 */ 155, 156, 157, 297, 200, 38, 19, 20, 151, 22,
162330 /* 1800 */ 149, 272, 272, 270, 200, 246, 234, 234, 246, 246, 164412 /* 1800 */ 200, 150, 140, 294, 294, 22, 272, 43, 234, 18,
162331 /* 1810 */ 162, 158, 290, 36, 199, 153, 154, 155, 156, 157, 164413 /* 1810 */ 162, 270, 200, 36, 237, 153, 154, 155, 156, 157,
162332 /* 1820 */ 62, 289, 200, 199, 22, 200, 221, 199, 221, 200, 164414 /* 1820 */ 237, 283, 237, 237, 18, 199, 149, 246, 272, 270,
162333 /* 1830 */ 199, 115, 64, 227, 218, 22, 59, 218, 218, 126, 164415 /* 1830 */ 272, 200, 158, 246, 246, 234, 59, 234, 246, 199,
162334 /* 1840 */ 165, 24, 113, 312, 218, 224, 305, 224, 71, 282, 164416 /* 1840 */ 290, 62, 289, 200, 199, 22, 221, 115, 71, 200,
162335 /* 1850 */ 144, 221, 220, 282, 218, 218, 218, 115, 261, 260, 164417 /* 1850 */ 200, 199, 199, 221, 218, 218, 19, 20, 64, 22,
162336 /* 1860 */ 227, 221, 261, 260, 200, 91, 317, 317, 82, 261, 164418 /* 1860 */ 218, 227, 22, 224, 126, 224, 165, 221, 24, 305,
162337 /* 1870 */ 260, 148, 261, 22, 265, 145, 200, 100, 158, 277, 164419 /* 1870 */ 200, 113, 312, 36, 218, 220, 218, 100, 282, 218,
162338 /* 1880 */ 147, 146, 25, 106, 107, 202, 13, 260, 194, 250, 164420 /* 1880 */ 91, 218, 317, 106, 107, 221, 227, 282, 317, 82,
162339 /* 1890 */ 249, 114, 248, 116, 117, 118, 250, 247, 121, 265, 164421 /* 1890 */ 148, 114, 265, 116, 117, 118, 59, 145, 121, 22,
162340 /* 1900 */ 246, 194, 6, 192, 192, 207, 192, 207, 213, 213, 164422 /* 1900 */ 277, 158, 200, 265, 25, 202, 147, 250, 71, 279,
162341 /* 1910 */ 213, 222, 213, 222, 4, 214, 214, 213, 3, 22, 164423 /* 1910 */ 13, 146, 194, 194, 249, 248, 250, 140, 247, 246,
162342 /* 1920 */ 163, 279, 207, 15, 23, 16, 23, 139, 130, 151, 164424 /* 1920 */ 6, 192, 192, 192, 303, 303, 213, 207, 300, 213,
162343 /* 1930 */ 153, 154, 155, 156, 157, 142, 25, 24, 20, 144, 164425 /* 1930 */ 153, 154, 155, 156, 157, 213, 213, 100, 213, 222,
162344 /* 1940 */ 16, 1, 142, 61, 130, 130, 303, 151, 53, 37, 164426 /* 1940 */ 207, 214, 214, 106, 107, 4, 222, 207, 3, 22,
162345 /* 1950 */ 303, 53, 300, 53, 130, 53, 116, 34, 1, 141, 164427 /* 1950 */ 163, 114, 15, 116, 117, 118, 16, 23, 121, 23,
162346 /* 1960 */ 5, 22, 115, 25, 161, 75, 41, 68, 141, 115, 164428 /* 1960 */ 139, 151, 130, 25, 142, 16, 24, 20, 144, 1,
162347 /* 1970 */ 24, 20, 68, 19, 131, 125, 23, 96, 22, 59, 164429 /* 1970 */ 142, 130, 130, 61, 53, 53, 37, 151, 53, 53,
162348 /* 1980 */ 22, 67, 22, 22, 67, 22, 24, 28, 67, 37, 164430 /* 1980 */ 130, 116, 34, 1, 141, 5, 22, 115, 161, 141,
162349 /* 1990 */ 23, 149, 22, 25, 23, 23, 23, 23, 22, 141, 164431 /* 1990 */ 153, 154, 155, 156, 157, 25, 68, 68, 75, 41,
162350 /* 2000 */ 23, 23, 97, 116, 22, 143, 25, 88, 75, 34, 164432 /* 2000 */ 115, 24, 131, 20, 19, 125, 22, 96, 22, 22,
162351 /* 2010 */ 44, 75, 86, 34, 34, 93, 23, 34, 34, 34, 164433 /* 2010 */ 67, 23, 22, 67, 59, 24, 22, 28, 67, 23,
162352 /* 2020 */ 22, 24, 34, 22, 25, 25, 23, 23, 23, 23, 164434 /* 2020 */ 22, 22, 149, 23, 23, 23, 116, 23, 25, 37,
162353 /* 2030 */ 23, 11, 23, 25, 22, 22, 25, 23, 23, 22, 164435 /* 2030 */ 97, 141, 23, 23, 22, 143, 25, 75, 88, 34,
162354 /* 2040 */ 22, 135, 15, 1, 25, 23, 1, 319, 141, 319, 164436 /* 2040 */ 34, 34, 34, 86, 75, 93, 23, 34, 22, 34,
162355 /* 2050 */ 319, 319, 319, 319, 319, 319, 319, 141, 319, 319, 164437 /* 2050 */ 25, 24, 34, 25, 23, 142, 23, 142, 44, 23,
162356 /* 2060 */ 319, 319, 319, 319, 319, 319, 319, 319, 141, 141, 164438 /* 2060 */ 23, 23, 11, 23, 25, 22, 22, 22, 15, 23,
162357 /* 2070 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 164439 /* 2070 */ 23, 22, 22, 25, 1, 1, 141, 25, 23, 135,
162358 /* 2080 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 164440 /* 2080 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
162359 /* 2090 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 164441 /* 2090 */ 319, 319, 319, 319, 141, 141, 319, 141, 319, 319,
162360 /* 2100 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 164442 /* 2100 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
162361 /* 2110 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 164443 /* 2110 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
162362 /* 2120 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 164444 /* 2120 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
@@ -162372,176 +164454,179 @@ static const YYCODETYPE yy_lookahead[] = {
162372 /* 2220 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 164454 /* 2220 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
162373 /* 2230 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 164455 /* 2230 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
162374 /* 2240 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, 164456 /* 2240 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
162375 /* 2250 */ 319, 319, 319, 319, 319, 164457 /* 2250 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164458 /* 2260 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164459 /* 2270 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164460 /* 2280 */ 319, 319, 319,
162376}; 164461};
162377#define YY_SHIFT_COUNT (573) 164462#define YY_SHIFT_COUNT (575)
162378#define YY_SHIFT_MIN (0) 164463#define YY_SHIFT_MIN (0)
162379#define YY_SHIFT_MAX (2045) 164464#define YY_SHIFT_MAX (2074)
162380static const unsigned short int yy_shift_ofst[] = { 164465static const unsigned short int yy_shift_ofst[] = {
162381 /* 0 */ 1648, 1477, 1272, 322, 322, 262, 1319, 1478, 1491, 1662, 164466 /* 0 */ 1648, 1477, 1272, 322, 322, 1, 1319, 1478, 1491, 1837,
162382 /* 10 */ 1662, 1662, 317, 0, 0, 214, 1093, 1662, 1662, 1662, 164467 /* 10 */ 1837, 1837, 471, 0, 0, 214, 1093, 1837, 1837, 1837,
162383 /* 20 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 164468 /* 20 */ 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
162384 /* 30 */ 271, 271, 1219, 1219, 216, 88, 262, 262, 262, 262, 164469 /* 30 */ 271, 271, 1219, 1219, 216, 88, 1, 1, 1, 1,
162385 /* 40 */ 262, 40, 111, 258, 361, 469, 512, 583, 622, 693, 164470 /* 40 */ 1, 40, 111, 258, 361, 469, 512, 583, 622, 693,
162386 /* 50 */ 732, 803, 842, 913, 1073, 1093, 1093, 1093, 1093, 1093, 164471 /* 50 */ 732, 803, 842, 913, 1073, 1093, 1093, 1093, 1093, 1093,
162387 /* 60 */ 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 164472 /* 60 */ 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093,
162388 /* 70 */ 1093, 1093, 1093, 1113, 1093, 1216, 957, 957, 1635, 1662, 164473 /* 70 */ 1093, 1093, 1093, 1113, 1093, 1216, 957, 957, 1635, 1662,
162389 /* 80 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 164474 /* 80 */ 1777, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
162390 /* 90 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 164475 /* 90 */ 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
162391 /* 100 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 164476 /* 100 */ 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
162392 /* 110 */ 1662, 1662, 1662, 1662, 1777, 1662, 1662, 1662, 1662, 1662, 164477 /* 110 */ 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
162393 /* 120 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 137, 181, 164478 /* 120 */ 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
162394 /* 130 */ 181, 181, 181, 181, 94, 430, 66, 65, 112, 366, 164479 /* 130 */ 137, 181, 181, 181, 181, 181, 181, 181, 94, 430,
162395 /* 140 */ 475, 475, 629, 1058, 475, 475, 125, 125, 475, 686, 164480 /* 140 */ 66, 65, 112, 366, 533, 533, 740, 1261, 533, 533,
162396 /* 150 */ 686, 686, 660, 686, 57, 184, 184, 77, 77, 2070, 164481 /* 150 */ 79, 79, 533, 412, 412, 412, 77, 412, 123, 113,
162397 /* 160 */ 2070, 328, 328, 328, 493, 373, 373, 373, 373, 1015, 164482 /* 160 */ 113, 22, 22, 2098, 2098, 328, 328, 328, 239, 468,
162398 /* 170 */ 1015, 409, 366, 1129, 1149, 475, 475, 475, 475, 475, 164483 /* 170 */ 468, 468, 468, 1015, 1015, 409, 366, 1129, 1186, 533,
162399 /* 180 */ 475, 475, 475, 475, 475, 475, 475, 475, 475, 475, 164484 /* 180 */ 533, 533, 533, 533, 533, 533, 533, 533, 533, 533,
162400 /* 190 */ 475, 475, 475, 475, 475, 621, 621, 475, 852, 899, 164485 /* 190 */ 533, 533, 533, 533, 533, 533, 533, 533, 533, 969,
162401 /* 200 */ 899, 1295, 1295, 406, 851, 2070, 2070, 2070, 2070, 2070, 164486 /* 200 */ 621, 621, 533, 642, 788, 788, 1228, 1228, 822, 822,
162402 /* 210 */ 2070, 2070, 1307, 954, 954, 640, 464, 695, 238, 700, 164487 /* 210 */ 67, 1274, 2098, 2098, 2098, 2098, 2098, 2098, 2098, 1307,
162403 /* 220 */ 538, 541, 748, 475, 475, 475, 475, 475, 475, 475, 164488 /* 220 */ 954, 954, 585, 472, 640, 387, 695, 538, 541, 700,
162404 /* 230 */ 475, 475, 475, 634, 475, 475, 475, 475, 475, 475, 164489 /* 230 */ 533, 533, 533, 533, 533, 533, 533, 533, 533, 533,
162405 /* 240 */ 475, 475, 475, 475, 475, 475, 1175, 1175, 1175, 475, 164490 /* 240 */ 222, 533, 533, 533, 533, 533, 533, 533, 533, 533,
162406 /* 250 */ 475, 475, 580, 475, 475, 475, 1074, 1142, 475, 475, 164491 /* 250 */ 533, 533, 533, 1179, 1179, 1179, 533, 533, 533, 565,
162407 /* 260 */ 1072, 475, 475, 475, 475, 475, 475, 475, 475, 797, 164492 /* 260 */ 533, 533, 533, 916, 1144, 533, 533, 1288, 533, 533,
162408 /* 270 */ 1330, 740, 1131, 1131, 1131, 1131, 1069, 740, 740, 1209, 164493 /* 270 */ 533, 533, 533, 533, 533, 533, 639, 1330, 209, 1076,
162409 /* 280 */ 167, 926, 1391, 1038, 1314, 187, 1408, 1314, 1408, 1435, 164494 /* 280 */ 1076, 1076, 1076, 580, 209, 209, 1313, 768, 917, 649,
162410 /* 290 */ 1109, 1038, 1038, 1109, 1038, 187, 1435, 227, 1090, 941, 164495 /* 290 */ 1181, 1316, 405, 1316, 1238, 249, 1181, 1181, 249, 1181,
162411 /* 300 */ 1270, 1270, 1270, 1408, 1256, 1256, 1326, 1440, 513, 1461, 164496 /* 300 */ 405, 1238, 1369, 464, 1259, 1012, 1012, 1012, 1368, 1368,
162412 /* 310 */ 1685, 1685, 1613, 1613, 1722, 1722, 1613, 1612, 1614, 1745, 164497 /* 310 */ 1368, 1368, 184, 184, 1326, 904, 1287, 1480, 1712, 1712,
162413 /* 320 */ 1728, 1755, 1755, 1755, 1755, 1613, 1766, 1651, 1614, 1614, 164498 /* 320 */ 1633, 1633, 1757, 1757, 1633, 1647, 1651, 1783, 1764, 1791,
162414 /* 330 */ 1651, 1745, 1728, 1651, 1728, 1651, 1613, 1766, 1653, 1758, 164499 /* 330 */ 1791, 1791, 1791, 1633, 1806, 1677, 1651, 1651, 1677, 1783,
162415 /* 340 */ 1613, 1766, 1802, 1613, 1766, 1613, 1766, 1802, 1716, 1716, 164500 /* 340 */ 1764, 1677, 1764, 1677, 1633, 1806, 1674, 1779, 1633, 1806,
162416 /* 350 */ 1716, 1768, 1813, 1813, 1802, 1716, 1713, 1716, 1768, 1716, 164501 /* 350 */ 1823, 1633, 1806, 1633, 1806, 1823, 1732, 1732, 1732, 1794,
162417 /* 360 */ 1716, 1675, 1817, 1729, 1729, 1802, 1706, 1742, 1706, 1742, 164502 /* 360 */ 1840, 1840, 1823, 1732, 1738, 1732, 1794, 1732, 1732, 1701,
162418 /* 370 */ 1706, 1742, 1706, 1742, 1613, 1774, 1774, 1786, 1786, 1723, 164503 /* 370 */ 1844, 1758, 1758, 1823, 1633, 1789, 1789, 1807, 1807, 1742,
162419 /* 380 */ 1730, 1851, 1613, 1720, 1723, 1733, 1735, 1651, 1857, 1873, 164504 /* 380 */ 1752, 1877, 1633, 1743, 1742, 1759, 1765, 1677, 1879, 1897,
162420 /* 390 */ 1873, 1896, 1896, 1896, 2070, 2070, 2070, 2070, 2070, 2070, 164505 /* 390 */ 1897, 1914, 1914, 1914, 2098, 2098, 2098, 2098, 2098, 2098,
162421 /* 400 */ 2070, 2070, 2070, 2070, 2070, 2070, 2070, 2070, 2070, 207, 164506 /* 400 */ 2098, 2098, 2098, 2098, 2098, 2098, 2098, 2098, 2098, 207,
162422 /* 410 */ 915, 1010, 1030, 1217, 910, 1170, 1470, 1368, 1481, 1442, 164507 /* 410 */ 1095, 331, 620, 903, 806, 1074, 1483, 1432, 1481, 1322,
162423 /* 420 */ 1318, 1383, 1515, 1482, 1523, 1542, 1546, 1547, 1588, 1595, 164508 /* 420 */ 1370, 1394, 1515, 1291, 1546, 1547, 1557, 1595, 1598, 1599,
162424 /* 430 */ 1502, 1338, 1566, 1493, 1520, 1521, 1598, 1617, 1568, 1618, 164509 /* 430 */ 1434, 1453, 1618, 1462, 1567, 1489, 1644, 1654, 1616, 1660,
162425 /* 440 */ 1511, 1514, 1645, 1649, 1570, 1484, 1910, 1915, 1897, 1757, 164510 /* 440 */ 1548, 1549, 1682, 1685, 1597, 742, 1941, 1945, 1927, 1787,
162426 /* 450 */ 1908, 1909, 1901, 1903, 1788, 1778, 1798, 1911, 1911, 1913, 164511 /* 450 */ 1937, 1940, 1934, 1936, 1821, 1810, 1832, 1938, 1938, 1942,
162427 /* 460 */ 1793, 1918, 1795, 1924, 1940, 1800, 1814, 1911, 1815, 1882, 164512 /* 460 */ 1822, 1947, 1824, 1949, 1968, 1828, 1841, 1938, 1842, 1912,
162428 /* 470 */ 1912, 1911, 1796, 1895, 1898, 1900, 1902, 1824, 1840, 1923, 164513 /* 470 */ 1939, 1938, 1826, 1921, 1922, 1925, 1926, 1850, 1865, 1948,
162429 /* 480 */ 1818, 1957, 1955, 1939, 1847, 1803, 1899, 1938, 1904, 1890, 164514 /* 480 */ 1843, 1982, 1980, 1964, 1872, 1827, 1928, 1970, 1929, 1923,
162430 /* 490 */ 1925, 1827, 1854, 1946, 1951, 1954, 1843, 1850, 1956, 1914, 164515 /* 490 */ 1958, 1848, 1885, 1977, 1983, 1985, 1871, 1880, 1984, 1943,
162431 /* 500 */ 1958, 1960, 1953, 1961, 1917, 1920, 1962, 1881, 1959, 1963, 164516 /* 500 */ 1986, 1987, 1988, 1990, 1946, 1955, 1991, 1911, 1989, 1994,
162432 /* 510 */ 1921, 1952, 1967, 1842, 1970, 1971, 1972, 1973, 1968, 1974, 164517 /* 510 */ 1951, 1992, 1996, 1873, 1998, 2000, 2001, 2002, 2003, 2004,
162433 /* 520 */ 1976, 1905, 1858, 1977, 1978, 1887, 1975, 1982, 1862, 1981, 164518 /* 520 */ 1999, 1933, 1890, 2009, 2010, 1910, 2005, 2012, 1892, 2011,
162434 /* 530 */ 1979, 1980, 1983, 1984, 1919, 1933, 1926, 1966, 1936, 1922, 164519 /* 530 */ 2006, 2007, 2008, 2013, 1950, 1962, 1957, 2014, 1969, 1952,
162435 /* 540 */ 1985, 1993, 1998, 1997, 1999, 2000, 1988, 2003, 1981, 2004, 164520 /* 540 */ 2015, 2023, 2026, 2027, 2025, 2028, 2018, 1913, 1915, 2031,
162436 /* 550 */ 2005, 2006, 2007, 2008, 2009, 2001, 2020, 2012, 2013, 2014, 164521 /* 550 */ 2011, 2033, 2036, 2037, 2038, 2039, 2040, 2043, 2051, 2044,
162437 /* 560 */ 2015, 2017, 2018, 2011, 1906, 1907, 1916, 1927, 1928, 2019, 164522 /* 560 */ 2045, 2046, 2047, 2049, 2050, 2048, 1944, 1935, 1953, 1954,
162438 /* 570 */ 2022, 2027, 2042, 2045, 164523 /* 570 */ 1956, 2052, 2055, 2053, 2073, 2074,
162439}; 164524};
162440#define YY_REDUCE_COUNT (408) 164525#define YY_REDUCE_COUNT (408)
162441#define YY_REDUCE_MIN (-267) 164526#define YY_REDUCE_MIN (-271)
162442#define YY_REDUCE_MAX (1715) 164527#define YY_REDUCE_MAX (1740)
162443static const short yy_reduce_ofst[] = { 164528static const short yy_reduce_ofst[] = {
162444 /* 0 */ -125, 733, 789, 241, 293, -123, -193, -191, -183, -187, 164529 /* 0 */ -125, 733, 789, 241, 293, -123, -193, -191, -183, -187,
162445 /* 10 */ -180, 83, 133, -207, -198, -267, -175, -6, 166, 313, 164530 /* 10 */ 166, 238, 133, -207, -199, -267, -176, -6, 204, 489,
162446 /* 20 */ 487, 396, 489, 598, 615, 685, 687, 79, 781, 857, 164531 /* 20 */ 576, -175, 598, 686, 615, 725, 860, 778, 781, 857,
162447 /* 30 */ 490, 616, 240, 334, -188, 796, 841, 843, 1003, 1005, 164532 /* 30 */ 616, 887, 87, 240, -192, 408, 626, 796, 843, 854,
162448 /* 40 */ 1007, -260, -260, -260, -260, -260, -260, -260, -260, -260, 164533 /* 40 */ 1003, -271, -271, -271, -271, -271, -271, -271, -271, -271,
162449 /* 50 */ -260, -260, -260, -260, -260, -260, -260, -260, -260, -260, 164534 /* 50 */ -271, -271, -271, -271, -271, -271, -271, -271, -271, -271,
162450 /* 60 */ -260, -260, -260, -260, -260, -260, -260, -260, -260, -260, 164535 /* 60 */ -271, -271, -271, -271, -271, -271, -271, -271, -271, -271,
162451 /* 70 */ -260, -260, -260, -260, -260, -260, -260, -260, 158, 203, 164536 /* 70 */ -271, -271, -271, -271, -271, -271, -271, -271, 80, 83,
162452 /* 80 */ 391, 576, 724, 726, 886, 1021, 1035, 1063, 1081, 1083, 164537 /* 80 */ 313, 886, 888, 996, 1034, 1059, 1081, 1100, 1117, 1152,
162453 /* 90 */ 1097, 1099, 1117, 1152, 1155, 1158, 1163, 1165, 1167, 1169, 164538 /* 90 */ 1155, 1163, 1165, 1167, 1169, 1172, 1180, 1182, 1184, 1198,
162454 /* 100 */ 1172, 1180, 1183, 1198, 1200, 1205, 1215, 1225, 1227, 1236, 164539 /* 100 */ 1200, 1213, 1215, 1225, 1227, 1252, 1254, 1264, 1299, 1303,
162455 /* 110 */ 1252, 1264, 1299, 1303, 1306, 1309, 1312, 1315, 1325, 1328, 164540 /* 110 */ 1308, 1312, 1325, 1328, 1337, 1340, 1343, 1371, 1373, 1384,
162456 /* 120 */ 1337, 1340, 1343, 1371, 1373, 1384, 1386, 1411, -260, -260, 164541 /* 120 */ 1386, 1411, 1420, 1424, 1426, 1458, 1470, 1473, 1475, 1479,
162457 /* 130 */ -260, -260, -260, -260, -260, -260, -260, -53, 138, 302, 164542 /* 130 */ -271, -271, -271, -271, -271, -271, -271, -271, -271, -271,
162458 /* 140 */ -158, 357, 223, -222, 411, 458, -92, 556, 669, 581, 164543 /* 140 */ -271, 138, 459, 396, -158, 470, 302, -212, 521, 201,
162459 /* 150 */ 632, 581, -260, 632, 758, 778, 920, -260, -260, -260, 164544 /* 150 */ -195, -92, 559, 630, 632, 630, -271, 632, 901, 63,
162460 /* 160 */ -260, 161, 161, 161, 307, 234, 392, 526, 790, 195, 164545 /* 160 */ 407, -271, -271, -271, -271, 161, 161, 161, 251, 335,
162461 /* 170 */ 359, -174, -173, 362, 362, -189, 16, 560, 567, 261, 164546 /* 170 */ 847, 960, 980, 537, 588, 618, 628, 688, 688, -166,
162462 /* 180 */ 689, 802, 853, -122, -166, 408, 335, 617, 690, 837, 164547 /* 180 */ -161, 674, 790, 794, 799, 851, 852, -122, 680, -120,
162463 /* 190 */ 1001, 746, 1061, 515, 1082, 994, 1034, -135, 1000, 1048, 164548 /* 190 */ 995, 1038, 415, 1051, 893, 798, 962, 400, 1086, 779,
162464 /* 200 */ 1137, 877, 897, 186, 627, 1031, 1133, 1148, 1159, 1194, 164549 /* 200 */ 923, 924, 263, 1041, 979, 990, 1083, 1097, 1031, 1194,
162465 /* 210 */ 1199, 1195, -194, -142, 18, -152, 68, 201, 253, 269, 164550 /* 210 */ 362, 994, 1139, 1005, 1037, 1202, 1205, 1195, 1210, -194,
162466 /* 220 */ 294, 354, 521, 528, 676, 680, 736, 743, 850, 907, 164551 /* 220 */ 56, 185, -135, 232, 522, 560, 601, 617, 669, 683,
162467 /* 230 */ 1041, 1047, 1060, 727, 1139, 1147, 1201, 1237, 1278, 1359, 164552 /* 230 */ 711, 856, 908, 941, 1048, 1101, 1147, 1257, 1262, 1265,
162468 /* 240 */ 1393, 1400, 1413, 1429, 1433, 1437, 1126, 1410, 1430, 1444, 164553 /* 240 */ 392, 1292, 1333, 1339, 1342, 1346, 1350, 1359, 1374, 1418,
162469 /* 250 */ 1480, 1483, 1405, 1486, 1490, 1492, 1420, 1372, 1496, 1498, 164554 /* 250 */ 1421, 1436, 1437, 593, 755, 770, 997, 1445, 1459, 1209,
162470 /* 260 */ 1441, 1499, 253, 1500, 1503, 1504, 1506, 1507, 1508, 1398, 164555 /* 260 */ 1500, 1504, 1516, 1132, 1243, 1518, 1519, 1440, 1520, 560,
162471 /* 270 */ 1415, 1453, 1448, 1449, 1450, 1452, 1405, 1453, 1453, 1465, 164556 /* 270 */ 1522, 1523, 1524, 1526, 1527, 1529, 1382, 1438, 1431, 1468,
162472 /* 280 */ 1495, 1519, 1414, 1443, 1445, 1468, 1456, 1455, 1457, 1424, 164557 /* 280 */ 1469, 1472, 1476, 1209, 1431, 1431, 1485, 1525, 1539, 1435,
162473 /* 290 */ 1473, 1454, 1459, 1474, 1460, 1479, 1434, 1512, 1494, 1509, 164558 /* 290 */ 1463, 1471, 1492, 1487, 1443, 1494, 1474, 1484, 1498, 1486,
162474 /* 300 */ 1517, 1518, 1525, 1469, 1489, 1501, 1467, 1510, 1497, 1543, 164559 /* 300 */ 1502, 1455, 1530, 1531, 1533, 1540, 1542, 1544, 1505, 1506,
162475 /* 310 */ 1451, 1462, 1557, 1558, 1471, 1472, 1561, 1487, 1505, 1524, 164560 /* 310 */ 1507, 1508, 1521, 1528, 1493, 1537, 1532, 1575, 1488, 1496,
162476 /* 320 */ 1538, 1537, 1545, 1548, 1556, 1575, 1596, 1552, 1529, 1530, 164561 /* 320 */ 1584, 1594, 1509, 1510, 1600, 1538, 1534, 1541, 1574, 1577,
162477 /* 330 */ 1559, 1533, 1572, 1562, 1573, 1563, 1604, 1615, 1522, 1532, 164562 /* 330 */ 1583, 1585, 1586, 1612, 1626, 1581, 1556, 1558, 1587, 1559,
162478 /* 340 */ 1622, 1624, 1605, 1625, 1628, 1629, 1631, 1607, 1616, 1619, 164563 /* 340 */ 1601, 1588, 1603, 1592, 1631, 1640, 1550, 1553, 1643, 1645,
162479 /* 350 */ 1620, 1606, 1621, 1623, 1630, 1626, 1632, 1636, 1633, 1637, 164564 /* 350 */ 1625, 1649, 1652, 1650, 1653, 1632, 1636, 1637, 1642, 1634,
162480 /* 360 */ 1638, 1531, 1541, 1567, 1571, 1640, 1597, 1599, 1601, 1603, 164565 /* 360 */ 1639, 1641, 1646, 1656, 1655, 1658, 1659, 1661, 1663, 1560,
162481 /* 370 */ 1608, 1610, 1611, 1627, 1664, 1549, 1550, 1609, 1634, 1639, 164566 /* 370 */ 1564, 1596, 1605, 1664, 1670, 1565, 1571, 1627, 1638, 1657,
162482 /* 380 */ 1641, 1602, 1676, 1642, 1646, 1644, 1650, 1654, 1683, 1694, 164567 /* 380 */ 1665, 1623, 1702, 1630, 1666, 1667, 1671, 1673, 1703, 1718,
162483 /* 390 */ 1707, 1711, 1712, 1714, 1643, 1647, 1652, 1698, 1695, 1696, 164568 /* 390 */ 1719, 1729, 1730, 1731, 1621, 1622, 1628, 1720, 1713, 1716,
162484 /* 400 */ 1697, 1699, 1700, 1689, 1691, 1701, 1702, 1704, 1715, 164569 /* 400 */ 1722, 1723, 1733, 1717, 1724, 1727, 1728, 1725, 1740,
162485}; 164570};
162486static const YYACTIONTYPE yy_default[] = { 164571static const YYACTIONTYPE yy_default[] = {
162487 /* 0 */ 1637, 1637, 1637, 1466, 1233, 1344, 1233, 1233, 1233, 1466, 164572 /* 0 */ 1647, 1647, 1647, 1475, 1240, 1351, 1240, 1240, 1240, 1475,
162488 /* 10 */ 1466, 1466, 1233, 1374, 1374, 1519, 1266, 1233, 1233, 1233, 164573 /* 10 */ 1475, 1475, 1240, 1381, 1381, 1528, 1273, 1240, 1240, 1240,
162489 /* 20 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1465, 1233, 1233, 164574 /* 20 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1474, 1240, 1240,
162490 /* 30 */ 1233, 1233, 1554, 1554, 1233, 1233, 1233, 1233, 1233, 1233, 164575 /* 30 */ 1240, 1240, 1563, 1563, 1240, 1240, 1240, 1240, 1240, 1240,
162491 /* 40 */ 1233, 1233, 1383, 1233, 1390, 1233, 1233, 1233, 1233, 1233, 164576 /* 40 */ 1240, 1240, 1390, 1240, 1397, 1240, 1240, 1240, 1240, 1240,
162492 /* 50 */ 1467, 1468, 1233, 1233, 1233, 1518, 1520, 1483, 1397, 1396, 164577 /* 50 */ 1476, 1477, 1240, 1240, 1240, 1527, 1529, 1492, 1404, 1403,
162493 /* 60 */ 1395, 1394, 1501, 1361, 1388, 1381, 1385, 1461, 1462, 1460, 164578 /* 60 */ 1402, 1401, 1510, 1369, 1395, 1388, 1392, 1470, 1471, 1469,
162494 /* 70 */ 1464, 1468, 1467, 1233, 1384, 1431, 1445, 1430, 1233, 1233, 164579 /* 70 */ 1473, 1477, 1476, 1240, 1391, 1438, 1454, 1437, 1240, 1240,
162495 /* 80 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 164580 /* 80 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
162496 /* 90 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 164581 /* 90 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
162497 /* 100 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 164582 /* 100 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
162498 /* 110 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 164583 /* 110 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
162499 /* 120 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1439, 1444, 164584 /* 120 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
162500 /* 130 */ 1451, 1443, 1440, 1433, 1432, 1434, 1435, 1233, 1233, 1257, 164585 /* 130 */ 1446, 1453, 1452, 1451, 1460, 1450, 1447, 1440, 1439, 1441,
162501 /* 140 */ 1233, 1233, 1254, 1308, 1233, 1233, 1233, 1233, 1233, 1538, 164586 /* 140 */ 1442, 1240, 1240, 1264, 1240, 1240, 1261, 1315, 1240, 1240,
162502 /* 150 */ 1537, 1233, 1436, 1233, 1266, 1425, 1424, 1448, 1437, 1447, 164587 /* 150 */ 1240, 1240, 1240, 1547, 1546, 1240, 1443, 1240, 1273, 1432,
162503 /* 160 */ 1446, 1526, 1590, 1589, 1484, 1233, 1233, 1233, 1233, 1233, 164588 /* 160 */ 1431, 1457, 1444, 1456, 1455, 1535, 1599, 1598, 1493, 1240,
162504 /* 170 */ 1233, 1554, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 164589 /* 170 */ 1240, 1240, 1240, 1240, 1240, 1563, 1240, 1240, 1240, 1240,
162505 /* 180 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 164590 /* 180 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
162506 /* 190 */ 1233, 1233, 1233, 1233, 1233, 1554, 1554, 1233, 1266, 1554, 164591 /* 190 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1371,
162507 /* 200 */ 1554, 1262, 1262, 1368, 1233, 1533, 1335, 1335, 1335, 1335, 164592 /* 200 */ 1563, 1563, 1240, 1273, 1563, 1563, 1372, 1372, 1269, 1269,
162508 /* 210 */ 1344, 1335, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 164593 /* 210 */ 1375, 1240, 1542, 1342, 1342, 1342, 1342, 1351, 1342, 1240,
162509 /* 220 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1523, 1521, 1233, 164594 /* 220 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
162510 /* 230 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 164595 /* 230 */ 1240, 1240, 1240, 1240, 1532, 1530, 1240, 1240, 1240, 1240,
162511 /* 240 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 164596 /* 240 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
162512 /* 250 */ 1233, 1233, 1233, 1233, 1233, 1233, 1340, 1233, 1233, 1233, 164597 /* 250 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
162513 /* 260 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1583, 1233, 164598 /* 260 */ 1240, 1240, 1240, 1347, 1240, 1240, 1240, 1240, 1240, 1240,
162514 /* 270 */ 1496, 1322, 1340, 1340, 1340, 1340, 1342, 1323, 1321, 1334, 164599 /* 270 */ 1240, 1240, 1240, 1240, 1240, 1592, 1240, 1505, 1329, 1347,
162515 /* 280 */ 1267, 1240, 1629, 1400, 1389, 1341, 1363, 1389, 1363, 1626, 164600 /* 280 */ 1347, 1347, 1347, 1349, 1330, 1328, 1341, 1274, 1247, 1639,
162516 /* 290 */ 1387, 1400, 1400, 1387, 1400, 1341, 1626, 1283, 1606, 1278, 164601 /* 290 */ 1407, 1396, 1348, 1396, 1636, 1394, 1407, 1407, 1394, 1407,
162517 /* 300 */ 1374, 1374, 1374, 1363, 1368, 1368, 1463, 1341, 1334, 1233, 164602 /* 300 */ 1348, 1636, 1290, 1615, 1285, 1381, 1381, 1381, 1371, 1371,
162518 /* 310 */ 1629, 1629, 1349, 1349, 1628, 1628, 1349, 1484, 1613, 1409, 164603 /* 310 */ 1371, 1371, 1375, 1375, 1472, 1348, 1341, 1240, 1639, 1639,
162519 /* 320 */ 1311, 1317, 1317, 1317, 1317, 1349, 1251, 1387, 1613, 1613, 164604 /* 320 */ 1357, 1357, 1638, 1638, 1357, 1493, 1623, 1416, 1318, 1324,
162520 /* 330 */ 1387, 1409, 1311, 1387, 1311, 1387, 1349, 1251, 1500, 1623, 164605 /* 330 */ 1324, 1324, 1324, 1357, 1258, 1394, 1623, 1623, 1394, 1416,
162521 /* 340 */ 1349, 1251, 1474, 1349, 1251, 1349, 1251, 1474, 1309, 1309, 164606 /* 340 */ 1318, 1394, 1318, 1394, 1357, 1258, 1509, 1633, 1357, 1258,
162522 /* 350 */ 1309, 1298, 1233, 1233, 1474, 1309, 1283, 1309, 1298, 1309, 164607 /* 350 */ 1483, 1357, 1258, 1357, 1258, 1483, 1316, 1316, 1316, 1305,
162523 /* 360 */ 1309, 1572, 1233, 1478, 1478, 1474, 1367, 1362, 1367, 1362, 164608 /* 360 */ 1240, 1240, 1483, 1316, 1290, 1316, 1305, 1316, 1316, 1581,
162524 /* 370 */ 1367, 1362, 1367, 1362, 1349, 1564, 1564, 1377, 1377, 1382, 164609 /* 370 */ 1240, 1487, 1487, 1483, 1357, 1573, 1573, 1384, 1384, 1389,
162525 /* 380 */ 1368, 1469, 1349, 1233, 1382, 1380, 1378, 1387, 1301, 1586, 164610 /* 380 */ 1375, 1478, 1357, 1240, 1389, 1387, 1385, 1394, 1308, 1595,
162526 /* 390 */ 1586, 1582, 1582, 1582, 1634, 1634, 1533, 1599, 1266, 1266, 164611 /* 390 */ 1595, 1591, 1591, 1591, 1644, 1644, 1542, 1608, 1273, 1273,
162527 /* 400 */ 1266, 1266, 1599, 1285, 1285, 1267, 1267, 1266, 1599, 1233, 164612 /* 400 */ 1273, 1273, 1608, 1292, 1292, 1274, 1274, 1273, 1608, 1240,
162528 /* 410 */ 1233, 1233, 1233, 1233, 1233, 1594, 1233, 1528, 1485, 1353, 164613 /* 410 */ 1240, 1240, 1240, 1240, 1240, 1603, 1240, 1537, 1494, 1361,
162529 /* 420 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 164614 /* 420 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
162530 /* 430 */ 1233, 1233, 1233, 1233, 1539, 1233, 1233, 1233, 1233, 1233, 164615 /* 430 */ 1240, 1240, 1240, 1240, 1548, 1240, 1240, 1240, 1240, 1240,
162531 /* 440 */ 1233, 1233, 1233, 1233, 1233, 1414, 1233, 1236, 1530, 1233, 164616 /* 440 */ 1240, 1240, 1240, 1240, 1240, 1421, 1240, 1243, 1539, 1240,
162532 /* 450 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1391, 1392, 1354, 164617 /* 450 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1398, 1399, 1362,
162533 /* 460 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1406, 1233, 1233, 164618 /* 460 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1413, 1240, 1240,
162534 /* 470 */ 1233, 1401, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 164619 /* 470 */ 1240, 1408, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
162535 /* 480 */ 1625, 1233, 1233, 1233, 1233, 1233, 1233, 1499, 1498, 1233, 164620 /* 480 */ 1635, 1240, 1240, 1240, 1240, 1240, 1240, 1508, 1507, 1240,
162536 /* 490 */ 1233, 1351, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 164621 /* 490 */ 1240, 1359, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
162537 /* 500 */ 1233, 1233, 1233, 1233, 1233, 1281, 1233, 1233, 1233, 1233, 164622 /* 500 */ 1240, 1240, 1240, 1240, 1240, 1288, 1240, 1240, 1240, 1240,
162538 /* 510 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 164623 /* 510 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
162539 /* 520 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1379, 164624 /* 520 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1386,
162540 /* 530 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 164625 /* 530 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
162541 /* 540 */ 1233, 1233, 1233, 1233, 1569, 1369, 1233, 1233, 1616, 1233, 164626 /* 540 */ 1240, 1240, 1240, 1240, 1578, 1376, 1240, 1240, 1240, 1240,
162542 /* 550 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 164627 /* 550 */ 1626, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
162543 /* 560 */ 1233, 1233, 1233, 1610, 1325, 1416, 1233, 1415, 1419, 1255, 164628 /* 560 */ 1240, 1240, 1240, 1240, 1240, 1619, 1332, 1423, 1240, 1422,
162544 /* 570 */ 1233, 1245, 1233, 1233, 164629 /* 570 */ 1426, 1262, 1240, 1252, 1240, 1240,
162545}; 164630};
162546/********** End of lemon-generated parsing tables *****************************/ 164631/********** End of lemon-generated parsing tables *****************************/
162547 164632
@@ -163093,12 +165178,12 @@ static const char *const yyTokenName[] = {
163093 /* 256 */ "seltablist", 165178 /* 256 */ "seltablist",
163094 /* 257 */ "stl_prefix", 165179 /* 257 */ "stl_prefix",
163095 /* 258 */ "joinop", 165180 /* 258 */ "joinop",
163096 /* 259 */ "indexed_opt", 165181 /* 259 */ "on_using",
163097 /* 260 */ "on_opt", 165182 /* 260 */ "indexed_by",
163098 /* 261 */ "using_opt", 165183 /* 261 */ "exprlist",
163099 /* 262 */ "exprlist", 165184 /* 262 */ "xfullname",
163100 /* 263 */ "xfullname", 165185 /* 263 */ "idlist",
163101 /* 264 */ "idlist", 165186 /* 264 */ "indexed_opt",
163102 /* 265 */ "nulls", 165187 /* 265 */ "nulls",
163103 /* 266 */ "with", 165188 /* 266 */ "with",
163104 /* 267 */ "where_opt_ret", 165189 /* 267 */ "where_opt_ret",
@@ -163269,29 +165354,29 @@ static const char *const yyRuleName[] = {
163269 /* 106 */ "from ::= FROM seltablist", 165354 /* 106 */ "from ::= FROM seltablist",
163270 /* 107 */ "stl_prefix ::= seltablist joinop", 165355 /* 107 */ "stl_prefix ::= seltablist joinop",
163271 /* 108 */ "stl_prefix ::=", 165356 /* 108 */ "stl_prefix ::=",
163272 /* 109 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt", 165357 /* 109 */ "seltablist ::= stl_prefix nm dbnm as on_using",
163273 /* 110 */ "seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt", 165358 /* 110 */ "seltablist ::= stl_prefix nm dbnm as indexed_by on_using",
163274 /* 111 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt", 165359 /* 111 */ "seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_using",
163275 /* 112 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt", 165360 /* 112 */ "seltablist ::= stl_prefix LP select RP as on_using",
163276 /* 113 */ "dbnm ::=", 165361 /* 113 */ "seltablist ::= stl_prefix LP seltablist RP as on_using",
163277 /* 114 */ "dbnm ::= DOT nm", 165362 /* 114 */ "dbnm ::=",
163278 /* 115 */ "fullname ::= nm", 165363 /* 115 */ "dbnm ::= DOT nm",
163279 /* 116 */ "fullname ::= nm DOT nm", 165364 /* 116 */ "fullname ::= nm",
163280 /* 117 */ "xfullname ::= nm", 165365 /* 117 */ "fullname ::= nm DOT nm",
163281 /* 118 */ "xfullname ::= nm DOT nm", 165366 /* 118 */ "xfullname ::= nm",
163282 /* 119 */ "xfullname ::= nm DOT nm AS nm", 165367 /* 119 */ "xfullname ::= nm DOT nm",
163283 /* 120 */ "xfullname ::= nm AS nm", 165368 /* 120 */ "xfullname ::= nm DOT nm AS nm",
163284 /* 121 */ "joinop ::= COMMA|JOIN", 165369 /* 121 */ "xfullname ::= nm AS nm",
163285 /* 122 */ "joinop ::= JOIN_KW JOIN", 165370 /* 122 */ "joinop ::= COMMA|JOIN",
163286 /* 123 */ "joinop ::= JOIN_KW nm JOIN", 165371 /* 123 */ "joinop ::= JOIN_KW JOIN",
163287 /* 124 */ "joinop ::= JOIN_KW nm nm JOIN", 165372 /* 124 */ "joinop ::= JOIN_KW nm JOIN",
163288 /* 125 */ "on_opt ::= ON expr", 165373 /* 125 */ "joinop ::= JOIN_KW nm nm JOIN",
163289 /* 126 */ "on_opt ::=", 165374 /* 126 */ "on_using ::= ON expr",
163290 /* 127 */ "indexed_opt ::=", 165375 /* 127 */ "on_using ::= USING LP idlist RP",
163291 /* 128 */ "indexed_opt ::= INDEXED BY nm", 165376 /* 128 */ "on_using ::=",
163292 /* 129 */ "indexed_opt ::= NOT INDEXED", 165377 /* 129 */ "indexed_opt ::=",
163293 /* 130 */ "using_opt ::= USING LP idlist RP", 165378 /* 130 */ "indexed_by ::= INDEXED BY nm",
163294 /* 131 */ "using_opt ::=", 165379 /* 131 */ "indexed_by ::= NOT INDEXED",
163295 /* 132 */ "orderby_opt ::=", 165380 /* 132 */ "orderby_opt ::=",
163296 /* 133 */ "orderby_opt ::= ORDER BY sortlist", 165381 /* 133 */ "orderby_opt ::= ORDER BY sortlist",
163297 /* 134 */ "sortlist ::= sortlist COMMA expr sortorder nulls", 165382 /* 134 */ "sortlist ::= sortlist COMMA expr sortorder nulls",
@@ -163369,199 +165454,202 @@ static const char *const yyRuleName[] = {
163369 /* 206 */ "expr ::= expr NOT NULL", 165454 /* 206 */ "expr ::= expr NOT NULL",
163370 /* 207 */ "expr ::= expr IS expr", 165455 /* 207 */ "expr ::= expr IS expr",
163371 /* 208 */ "expr ::= expr IS NOT expr", 165456 /* 208 */ "expr ::= expr IS NOT expr",
163372 /* 209 */ "expr ::= NOT expr", 165457 /* 209 */ "expr ::= expr IS NOT DISTINCT FROM expr",
163373 /* 210 */ "expr ::= BITNOT expr", 165458 /* 210 */ "expr ::= expr IS DISTINCT FROM expr",
163374 /* 211 */ "expr ::= PLUS|MINUS expr", 165459 /* 211 */ "expr ::= NOT expr",
163375 /* 212 */ "expr ::= expr PTR expr", 165460 /* 212 */ "expr ::= BITNOT expr",
163376 /* 213 */ "between_op ::= BETWEEN", 165461 /* 213 */ "expr ::= PLUS|MINUS expr",
163377 /* 214 */ "between_op ::= NOT BETWEEN", 165462 /* 214 */ "expr ::= expr PTR expr",
163378 /* 215 */ "expr ::= expr between_op expr AND expr", 165463 /* 215 */ "between_op ::= BETWEEN",
163379 /* 216 */ "in_op ::= IN", 165464 /* 216 */ "between_op ::= NOT BETWEEN",
163380 /* 217 */ "in_op ::= NOT IN", 165465 /* 217 */ "expr ::= expr between_op expr AND expr",
163381 /* 218 */ "expr ::= expr in_op LP exprlist RP", 165466 /* 218 */ "in_op ::= IN",
163382 /* 219 */ "expr ::= LP select RP", 165467 /* 219 */ "in_op ::= NOT IN",
163383 /* 220 */ "expr ::= expr in_op LP select RP", 165468 /* 220 */ "expr ::= expr in_op LP exprlist RP",
163384 /* 221 */ "expr ::= expr in_op nm dbnm paren_exprlist", 165469 /* 221 */ "expr ::= LP select RP",
163385 /* 222 */ "expr ::= EXISTS LP select RP", 165470 /* 222 */ "expr ::= expr in_op LP select RP",
163386 /* 223 */ "expr ::= CASE case_operand case_exprlist case_else END", 165471 /* 223 */ "expr ::= expr in_op nm dbnm paren_exprlist",
163387 /* 224 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr", 165472 /* 224 */ "expr ::= EXISTS LP select RP",
163388 /* 225 */ "case_exprlist ::= WHEN expr THEN expr", 165473 /* 225 */ "expr ::= CASE case_operand case_exprlist case_else END",
163389 /* 226 */ "case_else ::= ELSE expr", 165474 /* 226 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
163390 /* 227 */ "case_else ::=", 165475 /* 227 */ "case_exprlist ::= WHEN expr THEN expr",
163391 /* 228 */ "case_operand ::= expr", 165476 /* 228 */ "case_else ::= ELSE expr",
163392 /* 229 */ "case_operand ::=", 165477 /* 229 */ "case_else ::=",
163393 /* 230 */ "exprlist ::=", 165478 /* 230 */ "case_operand ::= expr",
163394 /* 231 */ "nexprlist ::= nexprlist COMMA expr", 165479 /* 231 */ "case_operand ::=",
163395 /* 232 */ "nexprlist ::= expr", 165480 /* 232 */ "exprlist ::=",
163396 /* 233 */ "paren_exprlist ::=", 165481 /* 233 */ "nexprlist ::= nexprlist COMMA expr",
163397 /* 234 */ "paren_exprlist ::= LP exprlist RP", 165482 /* 234 */ "nexprlist ::= expr",
163398 /* 235 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt", 165483 /* 235 */ "paren_exprlist ::=",
163399 /* 236 */ "uniqueflag ::= UNIQUE", 165484 /* 236 */ "paren_exprlist ::= LP exprlist RP",
163400 /* 237 */ "uniqueflag ::=", 165485 /* 237 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
163401 /* 238 */ "eidlist_opt ::=", 165486 /* 238 */ "uniqueflag ::= UNIQUE",
163402 /* 239 */ "eidlist_opt ::= LP eidlist RP", 165487 /* 239 */ "uniqueflag ::=",
163403 /* 240 */ "eidlist ::= eidlist COMMA nm collate sortorder", 165488 /* 240 */ "eidlist_opt ::=",
163404 /* 241 */ "eidlist ::= nm collate sortorder", 165489 /* 241 */ "eidlist_opt ::= LP eidlist RP",
163405 /* 242 */ "collate ::=", 165490 /* 242 */ "eidlist ::= eidlist COMMA nm collate sortorder",
163406 /* 243 */ "collate ::= COLLATE ID|STRING", 165491 /* 243 */ "eidlist ::= nm collate sortorder",
163407 /* 244 */ "cmd ::= DROP INDEX ifexists fullname", 165492 /* 244 */ "collate ::=",
163408 /* 245 */ "cmd ::= VACUUM vinto", 165493 /* 245 */ "collate ::= COLLATE ID|STRING",
163409 /* 246 */ "cmd ::= VACUUM nm vinto", 165494 /* 246 */ "cmd ::= DROP INDEX ifexists fullname",
163410 /* 247 */ "vinto ::= INTO expr", 165495 /* 247 */ "cmd ::= VACUUM vinto",
163411 /* 248 */ "vinto ::=", 165496 /* 248 */ "cmd ::= VACUUM nm vinto",
163412 /* 249 */ "cmd ::= PRAGMA nm dbnm", 165497 /* 249 */ "vinto ::= INTO expr",
163413 /* 250 */ "cmd ::= PRAGMA nm dbnm EQ nmnum", 165498 /* 250 */ "vinto ::=",
163414 /* 251 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP", 165499 /* 251 */ "cmd ::= PRAGMA nm dbnm",
163415 /* 252 */ "cmd ::= PRAGMA nm dbnm EQ minus_num", 165500 /* 252 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
163416 /* 253 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP", 165501 /* 253 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
163417 /* 254 */ "plus_num ::= PLUS INTEGER|FLOAT", 165502 /* 254 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
163418 /* 255 */ "minus_num ::= MINUS INTEGER|FLOAT", 165503 /* 255 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
163419 /* 256 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END", 165504 /* 256 */ "plus_num ::= PLUS INTEGER|FLOAT",
163420 /* 257 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause", 165505 /* 257 */ "minus_num ::= MINUS INTEGER|FLOAT",
163421 /* 258 */ "trigger_time ::= BEFORE|AFTER", 165506 /* 258 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
163422 /* 259 */ "trigger_time ::= INSTEAD OF", 165507 /* 259 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
163423 /* 260 */ "trigger_time ::=", 165508 /* 260 */ "trigger_time ::= BEFORE|AFTER",
163424 /* 261 */ "trigger_event ::= DELETE|INSERT", 165509 /* 261 */ "trigger_time ::= INSTEAD OF",
163425 /* 262 */ "trigger_event ::= UPDATE", 165510 /* 262 */ "trigger_time ::=",
163426 /* 263 */ "trigger_event ::= UPDATE OF idlist", 165511 /* 263 */ "trigger_event ::= DELETE|INSERT",
163427 /* 264 */ "when_clause ::=", 165512 /* 264 */ "trigger_event ::= UPDATE",
163428 /* 265 */ "when_clause ::= WHEN expr", 165513 /* 265 */ "trigger_event ::= UPDATE OF idlist",
163429 /* 266 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI", 165514 /* 266 */ "when_clause ::=",
163430 /* 267 */ "trigger_cmd_list ::= trigger_cmd SEMI", 165515 /* 267 */ "when_clause ::= WHEN expr",
163431 /* 268 */ "trnm ::= nm DOT nm", 165516 /* 268 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
163432 /* 269 */ "tridxby ::= INDEXED BY nm", 165517 /* 269 */ "trigger_cmd_list ::= trigger_cmd SEMI",
163433 /* 270 */ "tridxby ::= NOT INDEXED", 165518 /* 270 */ "trnm ::= nm DOT nm",
163434 /* 271 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt", 165519 /* 271 */ "tridxby ::= INDEXED BY nm",
163435 /* 272 */ "trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt", 165520 /* 272 */ "tridxby ::= NOT INDEXED",
163436 /* 273 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt", 165521 /* 273 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt",
163437 /* 274 */ "trigger_cmd ::= scanpt select scanpt", 165522 /* 274 */ "trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt",
163438 /* 275 */ "expr ::= RAISE LP IGNORE RP", 165523 /* 275 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt",
163439 /* 276 */ "expr ::= RAISE LP raisetype COMMA nm RP", 165524 /* 276 */ "trigger_cmd ::= scanpt select scanpt",
163440 /* 277 */ "raisetype ::= ROLLBACK", 165525 /* 277 */ "expr ::= RAISE LP IGNORE RP",
163441 /* 278 */ "raisetype ::= ABORT", 165526 /* 278 */ "expr ::= RAISE LP raisetype COMMA nm RP",
163442 /* 279 */ "raisetype ::= FAIL", 165527 /* 279 */ "raisetype ::= ROLLBACK",
163443 /* 280 */ "cmd ::= DROP TRIGGER ifexists fullname", 165528 /* 280 */ "raisetype ::= ABORT",
163444 /* 281 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt", 165529 /* 281 */ "raisetype ::= FAIL",
163445 /* 282 */ "cmd ::= DETACH database_kw_opt expr", 165530 /* 282 */ "cmd ::= DROP TRIGGER ifexists fullname",
163446 /* 283 */ "key_opt ::=", 165531 /* 283 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
163447 /* 284 */ "key_opt ::= KEY expr", 165532 /* 284 */ "cmd ::= DETACH database_kw_opt expr",
163448 /* 285 */ "cmd ::= REINDEX", 165533 /* 285 */ "key_opt ::=",
163449 /* 286 */ "cmd ::= REINDEX nm dbnm", 165534 /* 286 */ "key_opt ::= KEY expr",
163450 /* 287 */ "cmd ::= ANALYZE", 165535 /* 287 */ "cmd ::= REINDEX",
163451 /* 288 */ "cmd ::= ANALYZE nm dbnm", 165536 /* 288 */ "cmd ::= REINDEX nm dbnm",
163452 /* 289 */ "cmd ::= ALTER TABLE fullname RENAME TO nm", 165537 /* 289 */ "cmd ::= ANALYZE",
163453 /* 290 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist", 165538 /* 290 */ "cmd ::= ANALYZE nm dbnm",
163454 /* 291 */ "cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm", 165539 /* 291 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
163455 /* 292 */ "add_column_fullname ::= fullname", 165540 /* 292 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist",
163456 /* 293 */ "cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm", 165541 /* 293 */ "cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm",
163457 /* 294 */ "cmd ::= create_vtab", 165542 /* 294 */ "add_column_fullname ::= fullname",
163458 /* 295 */ "cmd ::= create_vtab LP vtabarglist RP", 165543 /* 295 */ "cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm",
163459 /* 296 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm", 165544 /* 296 */ "cmd ::= create_vtab",
163460 /* 297 */ "vtabarg ::=", 165545 /* 297 */ "cmd ::= create_vtab LP vtabarglist RP",
163461 /* 298 */ "vtabargtoken ::= ANY", 165546 /* 298 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
163462 /* 299 */ "vtabargtoken ::= lp anylist RP", 165547 /* 299 */ "vtabarg ::=",
163463 /* 300 */ "lp ::= LP", 165548 /* 300 */ "vtabargtoken ::= ANY",
163464 /* 301 */ "with ::= WITH wqlist", 165549 /* 301 */ "vtabargtoken ::= lp anylist RP",
163465 /* 302 */ "with ::= WITH RECURSIVE wqlist", 165550 /* 302 */ "lp ::= LP",
163466 /* 303 */ "wqas ::= AS", 165551 /* 303 */ "with ::= WITH wqlist",
163467 /* 304 */ "wqas ::= AS MATERIALIZED", 165552 /* 304 */ "with ::= WITH RECURSIVE wqlist",
163468 /* 305 */ "wqas ::= AS NOT MATERIALIZED", 165553 /* 305 */ "wqas ::= AS",
163469 /* 306 */ "wqitem ::= nm eidlist_opt wqas LP select RP", 165554 /* 306 */ "wqas ::= AS MATERIALIZED",
163470 /* 307 */ "wqlist ::= wqitem", 165555 /* 307 */ "wqas ::= AS NOT MATERIALIZED",
163471 /* 308 */ "wqlist ::= wqlist COMMA wqitem", 165556 /* 308 */ "wqitem ::= nm eidlist_opt wqas LP select RP",
163472 /* 309 */ "windowdefn_list ::= windowdefn", 165557 /* 309 */ "wqlist ::= wqitem",
163473 /* 310 */ "windowdefn_list ::= windowdefn_list COMMA windowdefn", 165558 /* 310 */ "wqlist ::= wqlist COMMA wqitem",
163474 /* 311 */ "windowdefn ::= nm AS LP window RP", 165559 /* 311 */ "windowdefn_list ::= windowdefn",
163475 /* 312 */ "window ::= PARTITION BY nexprlist orderby_opt frame_opt", 165560 /* 312 */ "windowdefn_list ::= windowdefn_list COMMA windowdefn",
163476 /* 313 */ "window ::= nm PARTITION BY nexprlist orderby_opt frame_opt", 165561 /* 313 */ "windowdefn ::= nm AS LP window RP",
163477 /* 314 */ "window ::= ORDER BY sortlist frame_opt", 165562 /* 314 */ "window ::= PARTITION BY nexprlist orderby_opt frame_opt",
163478 /* 315 */ "window ::= nm ORDER BY sortlist frame_opt", 165563 /* 315 */ "window ::= nm PARTITION BY nexprlist orderby_opt frame_opt",
163479 /* 316 */ "window ::= frame_opt", 165564 /* 316 */ "window ::= ORDER BY sortlist frame_opt",
163480 /* 317 */ "window ::= nm frame_opt", 165565 /* 317 */ "window ::= nm ORDER BY sortlist frame_opt",
163481 /* 318 */ "frame_opt ::=", 165566 /* 318 */ "window ::= frame_opt",
163482 /* 319 */ "frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt", 165567 /* 319 */ "window ::= nm frame_opt",
163483 /* 320 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt", 165568 /* 320 */ "frame_opt ::=",
163484 /* 321 */ "range_or_rows ::= RANGE|ROWS|GROUPS", 165569 /* 321 */ "frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt",
163485 /* 322 */ "frame_bound_s ::= frame_bound", 165570 /* 322 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt",
163486 /* 323 */ "frame_bound_s ::= UNBOUNDED PRECEDING", 165571 /* 323 */ "range_or_rows ::= RANGE|ROWS|GROUPS",
163487 /* 324 */ "frame_bound_e ::= frame_bound", 165572 /* 324 */ "frame_bound_s ::= frame_bound",
163488 /* 325 */ "frame_bound_e ::= UNBOUNDED FOLLOWING", 165573 /* 325 */ "frame_bound_s ::= UNBOUNDED PRECEDING",
163489 /* 326 */ "frame_bound ::= expr PRECEDING|FOLLOWING", 165574 /* 326 */ "frame_bound_e ::= frame_bound",
163490 /* 327 */ "frame_bound ::= CURRENT ROW", 165575 /* 327 */ "frame_bound_e ::= UNBOUNDED FOLLOWING",
163491 /* 328 */ "frame_exclude_opt ::=", 165576 /* 328 */ "frame_bound ::= expr PRECEDING|FOLLOWING",
163492 /* 329 */ "frame_exclude_opt ::= EXCLUDE frame_exclude", 165577 /* 329 */ "frame_bound ::= CURRENT ROW",
163493 /* 330 */ "frame_exclude ::= NO OTHERS", 165578 /* 330 */ "frame_exclude_opt ::=",
163494 /* 331 */ "frame_exclude ::= CURRENT ROW", 165579 /* 331 */ "frame_exclude_opt ::= EXCLUDE frame_exclude",
163495 /* 332 */ "frame_exclude ::= GROUP|TIES", 165580 /* 332 */ "frame_exclude ::= NO OTHERS",
163496 /* 333 */ "window_clause ::= WINDOW windowdefn_list", 165581 /* 333 */ "frame_exclude ::= CURRENT ROW",
163497 /* 334 */ "filter_over ::= filter_clause over_clause", 165582 /* 334 */ "frame_exclude ::= GROUP|TIES",
163498 /* 335 */ "filter_over ::= over_clause", 165583 /* 335 */ "window_clause ::= WINDOW windowdefn_list",
163499 /* 336 */ "filter_over ::= filter_clause", 165584 /* 336 */ "filter_over ::= filter_clause over_clause",
163500 /* 337 */ "over_clause ::= OVER LP window RP", 165585 /* 337 */ "filter_over ::= over_clause",
163501 /* 338 */ "over_clause ::= OVER nm", 165586 /* 338 */ "filter_over ::= filter_clause",
163502 /* 339 */ "filter_clause ::= FILTER LP WHERE expr RP", 165587 /* 339 */ "over_clause ::= OVER LP window RP",
163503 /* 340 */ "input ::= cmdlist", 165588 /* 340 */ "over_clause ::= OVER nm",
163504 /* 341 */ "cmdlist ::= cmdlist ecmd", 165589 /* 341 */ "filter_clause ::= FILTER LP WHERE expr RP",
163505 /* 342 */ "cmdlist ::= ecmd", 165590 /* 342 */ "input ::= cmdlist",
163506 /* 343 */ "ecmd ::= SEMI", 165591 /* 343 */ "cmdlist ::= cmdlist ecmd",
163507 /* 344 */ "ecmd ::= cmdx SEMI", 165592 /* 344 */ "cmdlist ::= ecmd",
163508 /* 345 */ "ecmd ::= explain cmdx SEMI", 165593 /* 345 */ "ecmd ::= SEMI",
163509 /* 346 */ "trans_opt ::=", 165594 /* 346 */ "ecmd ::= cmdx SEMI",
163510 /* 347 */ "trans_opt ::= TRANSACTION", 165595 /* 347 */ "ecmd ::= explain cmdx SEMI",
163511 /* 348 */ "trans_opt ::= TRANSACTION nm", 165596 /* 348 */ "trans_opt ::=",
163512 /* 349 */ "savepoint_opt ::= SAVEPOINT", 165597 /* 349 */ "trans_opt ::= TRANSACTION",
163513 /* 350 */ "savepoint_opt ::=", 165598 /* 350 */ "trans_opt ::= TRANSACTION nm",
163514 /* 351 */ "cmd ::= create_table create_table_args", 165599 /* 351 */ "savepoint_opt ::= SAVEPOINT",
163515 /* 352 */ "table_option_set ::= table_option", 165600 /* 352 */ "savepoint_opt ::=",
163516 /* 353 */ "columnlist ::= columnlist COMMA columnname carglist", 165601 /* 353 */ "cmd ::= create_table create_table_args",
163517 /* 354 */ "columnlist ::= columnname carglist", 165602 /* 354 */ "table_option_set ::= table_option",
163518 /* 355 */ "nm ::= ID|INDEXED", 165603 /* 355 */ "columnlist ::= columnlist COMMA columnname carglist",
163519 /* 356 */ "nm ::= STRING", 165604 /* 356 */ "columnlist ::= columnname carglist",
163520 /* 357 */ "nm ::= JOIN_KW", 165605 /* 357 */ "nm ::= ID|INDEXED",
163521 /* 358 */ "typetoken ::= typename", 165606 /* 358 */ "nm ::= STRING",
163522 /* 359 */ "typename ::= ID|STRING", 165607 /* 359 */ "nm ::= JOIN_KW",
163523 /* 360 */ "signed ::= plus_num", 165608 /* 360 */ "typetoken ::= typename",
163524 /* 361 */ "signed ::= minus_num", 165609 /* 361 */ "typename ::= ID|STRING",
163525 /* 362 */ "carglist ::= carglist ccons", 165610 /* 362 */ "signed ::= plus_num",
163526 /* 363 */ "carglist ::=", 165611 /* 363 */ "signed ::= minus_num",
163527 /* 364 */ "ccons ::= NULL onconf", 165612 /* 364 */ "carglist ::= carglist ccons",
163528 /* 365 */ "ccons ::= GENERATED ALWAYS AS generated", 165613 /* 365 */ "carglist ::=",
163529 /* 366 */ "ccons ::= AS generated", 165614 /* 366 */ "ccons ::= NULL onconf",
163530 /* 367 */ "conslist_opt ::= COMMA conslist", 165615 /* 367 */ "ccons ::= GENERATED ALWAYS AS generated",
163531 /* 368 */ "conslist ::= conslist tconscomma tcons", 165616 /* 368 */ "ccons ::= AS generated",
163532 /* 369 */ "conslist ::= tcons", 165617 /* 369 */ "conslist_opt ::= COMMA conslist",
163533 /* 370 */ "tconscomma ::=", 165618 /* 370 */ "conslist ::= conslist tconscomma tcons",
163534 /* 371 */ "defer_subclause_opt ::= defer_subclause", 165619 /* 371 */ "conslist ::= tcons",
163535 /* 372 */ "resolvetype ::= raisetype", 165620 /* 372 */ "tconscomma ::=",
163536 /* 373 */ "selectnowith ::= oneselect", 165621 /* 373 */ "defer_subclause_opt ::= defer_subclause",
163537 /* 374 */ "oneselect ::= values", 165622 /* 374 */ "resolvetype ::= raisetype",
163538 /* 375 */ "sclp ::= selcollist COMMA", 165623 /* 375 */ "selectnowith ::= oneselect",
163539 /* 376 */ "as ::= ID|STRING", 165624 /* 376 */ "oneselect ::= values",
163540 /* 377 */ "returning ::=", 165625 /* 377 */ "sclp ::= selcollist COMMA",
163541 /* 378 */ "expr ::= term", 165626 /* 378 */ "as ::= ID|STRING",
163542 /* 379 */ "likeop ::= LIKE_KW|MATCH", 165627 /* 379 */ "indexed_opt ::= indexed_by",
163543 /* 380 */ "exprlist ::= nexprlist", 165628 /* 380 */ "returning ::=",
163544 /* 381 */ "nmnum ::= plus_num", 165629 /* 381 */ "expr ::= term",
163545 /* 382 */ "nmnum ::= nm", 165630 /* 382 */ "likeop ::= LIKE_KW|MATCH",
163546 /* 383 */ "nmnum ::= ON", 165631 /* 383 */ "exprlist ::= nexprlist",
163547 /* 384 */ "nmnum ::= DELETE", 165632 /* 384 */ "nmnum ::= plus_num",
163548 /* 385 */ "nmnum ::= DEFAULT", 165633 /* 385 */ "nmnum ::= nm",
163549 /* 386 */ "plus_num ::= INTEGER|FLOAT", 165634 /* 386 */ "nmnum ::= ON",
163550 /* 387 */ "foreach_clause ::=", 165635 /* 387 */ "nmnum ::= DELETE",
163551 /* 388 */ "foreach_clause ::= FOR EACH ROW", 165636 /* 388 */ "nmnum ::= DEFAULT",
163552 /* 389 */ "trnm ::= nm", 165637 /* 389 */ "plus_num ::= INTEGER|FLOAT",
163553 /* 390 */ "tridxby ::=", 165638 /* 390 */ "foreach_clause ::=",
163554 /* 391 */ "database_kw_opt ::= DATABASE", 165639 /* 391 */ "foreach_clause ::= FOR EACH ROW",
163555 /* 392 */ "database_kw_opt ::=", 165640 /* 392 */ "trnm ::= nm",
163556 /* 393 */ "kwcolumn_opt ::=", 165641 /* 393 */ "tridxby ::=",
163557 /* 394 */ "kwcolumn_opt ::= COLUMNKW", 165642 /* 394 */ "database_kw_opt ::= DATABASE",
163558 /* 395 */ "vtabarglist ::= vtabarg", 165643 /* 395 */ "database_kw_opt ::=",
163559 /* 396 */ "vtabarglist ::= vtabarglist COMMA vtabarg", 165644 /* 396 */ "kwcolumn_opt ::=",
163560 /* 397 */ "vtabarg ::= vtabarg vtabargtoken", 165645 /* 397 */ "kwcolumn_opt ::= COLUMNKW",
163561 /* 398 */ "anylist ::=", 165646 /* 398 */ "vtabarglist ::= vtabarg",
163562 /* 399 */ "anylist ::= anylist LP anylist RP", 165647 /* 399 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
163563 /* 400 */ "anylist ::= anylist ANY", 165648 /* 400 */ "vtabarg ::= vtabarg vtabargtoken",
163564 /* 401 */ "with ::=", 165649 /* 401 */ "anylist ::=",
165650 /* 402 */ "anylist ::= anylist LP anylist RP",
165651 /* 403 */ "anylist ::= anylist ANY",
165652 /* 404 */ "with ::=",
163565}; 165653};
163566#endif /* NDEBUG */ 165654#endif /* NDEBUG */
163567 165655
@@ -163699,7 +165787,6 @@ sqlite3SelectDelete(pParse->db, (yypminor->yy47));
163699 case 217: /* expr */ 165787 case 217: /* expr */
163700 case 246: /* where_opt */ 165788 case 246: /* where_opt */
163701 case 248: /* having_opt */ 165789 case 248: /* having_opt */
163702 case 260: /* on_opt */
163703 case 267: /* where_opt_ret */ 165790 case 267: /* where_opt_ret */
163704 case 278: /* case_operand */ 165791 case 278: /* case_operand */
163705 case 280: /* case_else */ 165792 case 280: /* case_else */
@@ -163719,7 +165806,7 @@ sqlite3ExprDelete(pParse->db, (yypminor->yy528));
163719 case 249: /* orderby_opt */ 165806 case 249: /* orderby_opt */
163720 case 253: /* nexprlist */ 165807 case 253: /* nexprlist */
163721 case 254: /* sclp */ 165808 case 254: /* sclp */
163722 case 262: /* exprlist */ 165809 case 261: /* exprlist */
163723 case 268: /* setlist */ 165810 case 268: /* setlist */
163724 case 277: /* paren_exprlist */ 165811 case 277: /* paren_exprlist */
163725 case 279: /* case_exprlist */ 165812 case 279: /* case_exprlist */
@@ -163732,7 +165819,7 @@ sqlite3ExprListDelete(pParse->db, (yypminor->yy322));
163732 case 245: /* from */ 165819 case 245: /* from */
163733 case 256: /* seltablist */ 165820 case 256: /* seltablist */
163734 case 257: /* stl_prefix */ 165821 case 257: /* stl_prefix */
163735 case 263: /* xfullname */ 165822 case 262: /* xfullname */
163736{ 165823{
163737sqlite3SrcListDelete(pParse->db, (yypminor->yy131)); 165824sqlite3SrcListDelete(pParse->db, (yypminor->yy131));
163738} 165825}
@@ -163748,8 +165835,7 @@ sqlite3WithDelete(pParse->db, (yypminor->yy521));
163748sqlite3WindowListDelete(pParse->db, (yypminor->yy41)); 165835sqlite3WindowListDelete(pParse->db, (yypminor->yy41));
163749} 165836}
163750 break; 165837 break;
163751 case 261: /* using_opt */ 165838 case 263: /* idlist */
163752 case 264: /* idlist */
163753 case 270: /* idlist_opt */ 165839 case 270: /* idlist_opt */
163754{ 165840{
163755sqlite3IdListDelete(pParse->db, (yypminor->yy254)); 165841sqlite3IdListDelete(pParse->db, (yypminor->yy254));
@@ -164179,29 +166265,29 @@ static const YYCODETYPE yyRuleInfoLhs[] = {
164179 245, /* (106) from ::= FROM seltablist */ 166265 245, /* (106) from ::= FROM seltablist */
164180 257, /* (107) stl_prefix ::= seltablist joinop */ 166266 257, /* (107) stl_prefix ::= seltablist joinop */
164181 257, /* (108) stl_prefix ::= */ 166267 257, /* (108) stl_prefix ::= */
164182 256, /* (109) seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */ 166268 256, /* (109) seltablist ::= stl_prefix nm dbnm as on_using */
164183 256, /* (110) seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */ 166269 256, /* (110) seltablist ::= stl_prefix nm dbnm as indexed_by on_using */
164184 256, /* (111) seltablist ::= stl_prefix LP select RP as on_opt using_opt */ 166270 256, /* (111) seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_using */
164185 256, /* (112) seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */ 166271 256, /* (112) seltablist ::= stl_prefix LP select RP as on_using */
164186 200, /* (113) dbnm ::= */ 166272 256, /* (113) seltablist ::= stl_prefix LP seltablist RP as on_using */
164187 200, /* (114) dbnm ::= DOT nm */ 166273 200, /* (114) dbnm ::= */
164188 238, /* (115) fullname ::= nm */ 166274 200, /* (115) dbnm ::= DOT nm */
164189 238, /* (116) fullname ::= nm DOT nm */ 166275 238, /* (116) fullname ::= nm */
164190 263, /* (117) xfullname ::= nm */ 166276 238, /* (117) fullname ::= nm DOT nm */
164191 263, /* (118) xfullname ::= nm DOT nm */ 166277 262, /* (118) xfullname ::= nm */
164192 263, /* (119) xfullname ::= nm DOT nm AS nm */ 166278 262, /* (119) xfullname ::= nm DOT nm */
164193 263, /* (120) xfullname ::= nm AS nm */ 166279 262, /* (120) xfullname ::= nm DOT nm AS nm */
164194 258, /* (121) joinop ::= COMMA|JOIN */ 166280 262, /* (121) xfullname ::= nm AS nm */
164195 258, /* (122) joinop ::= JOIN_KW JOIN */ 166281 258, /* (122) joinop ::= COMMA|JOIN */
164196 258, /* (123) joinop ::= JOIN_KW nm JOIN */ 166282 258, /* (123) joinop ::= JOIN_KW JOIN */
164197 258, /* (124) joinop ::= JOIN_KW nm nm JOIN */ 166283 258, /* (124) joinop ::= JOIN_KW nm JOIN */
164198 260, /* (125) on_opt ::= ON expr */ 166284 258, /* (125) joinop ::= JOIN_KW nm nm JOIN */
164199 260, /* (126) on_opt ::= */ 166285 259, /* (126) on_using ::= ON expr */
164200 259, /* (127) indexed_opt ::= */ 166286 259, /* (127) on_using ::= USING LP idlist RP */
164201 259, /* (128) indexed_opt ::= INDEXED BY nm */ 166287 259, /* (128) on_using ::= */
164202 259, /* (129) indexed_opt ::= NOT INDEXED */ 166288 264, /* (129) indexed_opt ::= */
164203 261, /* (130) using_opt ::= USING LP idlist RP */ 166289 260, /* (130) indexed_by ::= INDEXED BY nm */
164204 261, /* (131) using_opt ::= */ 166290 260, /* (131) indexed_by ::= NOT INDEXED */
164205 249, /* (132) orderby_opt ::= */ 166291 249, /* (132) orderby_opt ::= */
164206 249, /* (133) orderby_opt ::= ORDER BY sortlist */ 166292 249, /* (133) orderby_opt ::= ORDER BY sortlist */
164207 231, /* (134) sortlist ::= sortlist COMMA expr sortorder nulls */ 166293 231, /* (134) sortlist ::= sortlist COMMA expr sortorder nulls */
@@ -164245,8 +166331,8 @@ static const YYCODETYPE yyRuleInfoLhs[] = {
164245 269, /* (172) insert_cmd ::= REPLACE */ 166331 269, /* (172) insert_cmd ::= REPLACE */
164246 270, /* (173) idlist_opt ::= */ 166332 270, /* (173) idlist_opt ::= */
164247 270, /* (174) idlist_opt ::= LP idlist RP */ 166333 270, /* (174) idlist_opt ::= LP idlist RP */
164248 264, /* (175) idlist ::= idlist COMMA nm */ 166334 263, /* (175) idlist ::= idlist COMMA nm */
164249 264, /* (176) idlist ::= nm */ 166335 263, /* (176) idlist ::= nm */
164250 217, /* (177) expr ::= LP expr RP */ 166336 217, /* (177) expr ::= LP expr RP */
164251 217, /* (178) expr ::= ID|INDEXED */ 166337 217, /* (178) expr ::= ID|INDEXED */
164252 217, /* (179) expr ::= JOIN_KW */ 166338 217, /* (179) expr ::= JOIN_KW */
@@ -164279,199 +166365,202 @@ static const YYCODETYPE yyRuleInfoLhs[] = {
164279 217, /* (206) expr ::= expr NOT NULL */ 166365 217, /* (206) expr ::= expr NOT NULL */
164280 217, /* (207) expr ::= expr IS expr */ 166366 217, /* (207) expr ::= expr IS expr */
164281 217, /* (208) expr ::= expr IS NOT expr */ 166367 217, /* (208) expr ::= expr IS NOT expr */
164282 217, /* (209) expr ::= NOT expr */ 166368 217, /* (209) expr ::= expr IS NOT DISTINCT FROM expr */
164283 217, /* (210) expr ::= BITNOT expr */ 166369 217, /* (210) expr ::= expr IS DISTINCT FROM expr */
164284 217, /* (211) expr ::= PLUS|MINUS expr */ 166370 217, /* (211) expr ::= NOT expr */
164285 217, /* (212) expr ::= expr PTR expr */ 166371 217, /* (212) expr ::= BITNOT expr */
164286 275, /* (213) between_op ::= BETWEEN */ 166372 217, /* (213) expr ::= PLUS|MINUS expr */
164287 275, /* (214) between_op ::= NOT BETWEEN */ 166373 217, /* (214) expr ::= expr PTR expr */
164288 217, /* (215) expr ::= expr between_op expr AND expr */ 166374 275, /* (215) between_op ::= BETWEEN */
164289 276, /* (216) in_op ::= IN */ 166375 275, /* (216) between_op ::= NOT BETWEEN */
164290 276, /* (217) in_op ::= NOT IN */ 166376 217, /* (217) expr ::= expr between_op expr AND expr */
164291 217, /* (218) expr ::= expr in_op LP exprlist RP */ 166377 276, /* (218) in_op ::= IN */
164292 217, /* (219) expr ::= LP select RP */ 166378 276, /* (219) in_op ::= NOT IN */
164293 217, /* (220) expr ::= expr in_op LP select RP */ 166379 217, /* (220) expr ::= expr in_op LP exprlist RP */
164294 217, /* (221) expr ::= expr in_op nm dbnm paren_exprlist */ 166380 217, /* (221) expr ::= LP select RP */
164295 217, /* (222) expr ::= EXISTS LP select RP */ 166381 217, /* (222) expr ::= expr in_op LP select RP */
164296 217, /* (223) expr ::= CASE case_operand case_exprlist case_else END */ 166382 217, /* (223) expr ::= expr in_op nm dbnm paren_exprlist */
164297 279, /* (224) case_exprlist ::= case_exprlist WHEN expr THEN expr */ 166383 217, /* (224) expr ::= EXISTS LP select RP */
164298 279, /* (225) case_exprlist ::= WHEN expr THEN expr */ 166384 217, /* (225) expr ::= CASE case_operand case_exprlist case_else END */
164299 280, /* (226) case_else ::= ELSE expr */ 166385 279, /* (226) case_exprlist ::= case_exprlist WHEN expr THEN expr */
164300 280, /* (227) case_else ::= */ 166386 279, /* (227) case_exprlist ::= WHEN expr THEN expr */
164301 278, /* (228) case_operand ::= expr */ 166387 280, /* (228) case_else ::= ELSE expr */
164302 278, /* (229) case_operand ::= */ 166388 280, /* (229) case_else ::= */
164303 262, /* (230) exprlist ::= */ 166389 278, /* (230) case_operand ::= expr */
164304 253, /* (231) nexprlist ::= nexprlist COMMA expr */ 166390 278, /* (231) case_operand ::= */
164305 253, /* (232) nexprlist ::= expr */ 166391 261, /* (232) exprlist ::= */
164306 277, /* (233) paren_exprlist ::= */ 166392 253, /* (233) nexprlist ::= nexprlist COMMA expr */
164307 277, /* (234) paren_exprlist ::= LP exprlist RP */ 166393 253, /* (234) nexprlist ::= expr */
164308 190, /* (235) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */ 166394 277, /* (235) paren_exprlist ::= */
164309 281, /* (236) uniqueflag ::= UNIQUE */ 166395 277, /* (236) paren_exprlist ::= LP exprlist RP */
164310 281, /* (237) uniqueflag ::= */ 166396 190, /* (237) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
164311 221, /* (238) eidlist_opt ::= */ 166397 281, /* (238) uniqueflag ::= UNIQUE */
164312 221, /* (239) eidlist_opt ::= LP eidlist RP */ 166398 281, /* (239) uniqueflag ::= */
164313 232, /* (240) eidlist ::= eidlist COMMA nm collate sortorder */ 166399 221, /* (240) eidlist_opt ::= */
164314 232, /* (241) eidlist ::= nm collate sortorder */ 166400 221, /* (241) eidlist_opt ::= LP eidlist RP */
164315 282, /* (242) collate ::= */ 166401 232, /* (242) eidlist ::= eidlist COMMA nm collate sortorder */
164316 282, /* (243) collate ::= COLLATE ID|STRING */ 166402 232, /* (243) eidlist ::= nm collate sortorder */
164317 190, /* (244) cmd ::= DROP INDEX ifexists fullname */ 166403 282, /* (244) collate ::= */
164318 190, /* (245) cmd ::= VACUUM vinto */ 166404 282, /* (245) collate ::= COLLATE ID|STRING */
164319 190, /* (246) cmd ::= VACUUM nm vinto */ 166405 190, /* (246) cmd ::= DROP INDEX ifexists fullname */
164320 283, /* (247) vinto ::= INTO expr */ 166406 190, /* (247) cmd ::= VACUUM vinto */
164321 283, /* (248) vinto ::= */ 166407 190, /* (248) cmd ::= VACUUM nm vinto */
164322 190, /* (249) cmd ::= PRAGMA nm dbnm */ 166408 283, /* (249) vinto ::= INTO expr */
164323 190, /* (250) cmd ::= PRAGMA nm dbnm EQ nmnum */ 166409 283, /* (250) vinto ::= */
164324 190, /* (251) cmd ::= PRAGMA nm dbnm LP nmnum RP */ 166410 190, /* (251) cmd ::= PRAGMA nm dbnm */
164325 190, /* (252) cmd ::= PRAGMA nm dbnm EQ minus_num */ 166411 190, /* (252) cmd ::= PRAGMA nm dbnm EQ nmnum */
164326 190, /* (253) cmd ::= PRAGMA nm dbnm LP minus_num RP */ 166412 190, /* (253) cmd ::= PRAGMA nm dbnm LP nmnum RP */
164327 211, /* (254) plus_num ::= PLUS INTEGER|FLOAT */ 166413 190, /* (254) cmd ::= PRAGMA nm dbnm EQ minus_num */
164328 212, /* (255) minus_num ::= MINUS INTEGER|FLOAT */ 166414 190, /* (255) cmd ::= PRAGMA nm dbnm LP minus_num RP */
164329 190, /* (256) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */ 166415 211, /* (256) plus_num ::= PLUS INTEGER|FLOAT */
164330 285, /* (257) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ 166416 212, /* (257) minus_num ::= MINUS INTEGER|FLOAT */
164331 287, /* (258) trigger_time ::= BEFORE|AFTER */ 166417 190, /* (258) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
164332 287, /* (259) trigger_time ::= INSTEAD OF */ 166418 285, /* (259) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
164333 287, /* (260) trigger_time ::= */ 166419 287, /* (260) trigger_time ::= BEFORE|AFTER */
164334 288, /* (261) trigger_event ::= DELETE|INSERT */ 166420 287, /* (261) trigger_time ::= INSTEAD OF */
164335 288, /* (262) trigger_event ::= UPDATE */ 166421 287, /* (262) trigger_time ::= */
164336 288, /* (263) trigger_event ::= UPDATE OF idlist */ 166422 288, /* (263) trigger_event ::= DELETE|INSERT */
164337 290, /* (264) when_clause ::= */ 166423 288, /* (264) trigger_event ::= UPDATE */
164338 290, /* (265) when_clause ::= WHEN expr */ 166424 288, /* (265) trigger_event ::= UPDATE OF idlist */
164339 286, /* (266) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ 166425 290, /* (266) when_clause ::= */
164340 286, /* (267) trigger_cmd_list ::= trigger_cmd SEMI */ 166426 290, /* (267) when_clause ::= WHEN expr */
164341 292, /* (268) trnm ::= nm DOT nm */ 166427 286, /* (268) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
164342 293, /* (269) tridxby ::= INDEXED BY nm */ 166428 286, /* (269) trigger_cmd_list ::= trigger_cmd SEMI */
164343 293, /* (270) tridxby ::= NOT INDEXED */ 166429 292, /* (270) trnm ::= nm DOT nm */
164344 291, /* (271) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */ 166430 293, /* (271) tridxby ::= INDEXED BY nm */
164345 291, /* (272) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */ 166431 293, /* (272) tridxby ::= NOT INDEXED */
164346 291, /* (273) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */ 166432 291, /* (273) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
164347 291, /* (274) trigger_cmd ::= scanpt select scanpt */ 166433 291, /* (274) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
164348 217, /* (275) expr ::= RAISE LP IGNORE RP */ 166434 291, /* (275) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
164349 217, /* (276) expr ::= RAISE LP raisetype COMMA nm RP */ 166435 291, /* (276) trigger_cmd ::= scanpt select scanpt */
164350 236, /* (277) raisetype ::= ROLLBACK */ 166436 217, /* (277) expr ::= RAISE LP IGNORE RP */
164351 236, /* (278) raisetype ::= ABORT */ 166437 217, /* (278) expr ::= RAISE LP raisetype COMMA nm RP */
164352 236, /* (279) raisetype ::= FAIL */ 166438 236, /* (279) raisetype ::= ROLLBACK */
164353 190, /* (280) cmd ::= DROP TRIGGER ifexists fullname */ 166439 236, /* (280) raisetype ::= ABORT */
164354 190, /* (281) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ 166440 236, /* (281) raisetype ::= FAIL */
164355 190, /* (282) cmd ::= DETACH database_kw_opt expr */ 166441 190, /* (282) cmd ::= DROP TRIGGER ifexists fullname */
164356 295, /* (283) key_opt ::= */ 166442 190, /* (283) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
164357 295, /* (284) key_opt ::= KEY expr */ 166443 190, /* (284) cmd ::= DETACH database_kw_opt expr */
164358 190, /* (285) cmd ::= REINDEX */ 166444 295, /* (285) key_opt ::= */
164359 190, /* (286) cmd ::= REINDEX nm dbnm */ 166445 295, /* (286) key_opt ::= KEY expr */
164360 190, /* (287) cmd ::= ANALYZE */ 166446 190, /* (287) cmd ::= REINDEX */
164361 190, /* (288) cmd ::= ANALYZE nm dbnm */ 166447 190, /* (288) cmd ::= REINDEX nm dbnm */
164362 190, /* (289) cmd ::= ALTER TABLE fullname RENAME TO nm */ 166448 190, /* (289) cmd ::= ANALYZE */
164363 190, /* (290) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */ 166449 190, /* (290) cmd ::= ANALYZE nm dbnm */
164364 190, /* (291) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */ 166450 190, /* (291) cmd ::= ALTER TABLE fullname RENAME TO nm */
164365 296, /* (292) add_column_fullname ::= fullname */ 166451 190, /* (292) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
164366 190, /* (293) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */ 166452 190, /* (293) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
164367 190, /* (294) cmd ::= create_vtab */ 166453 296, /* (294) add_column_fullname ::= fullname */
164368 190, /* (295) cmd ::= create_vtab LP vtabarglist RP */ 166454 190, /* (295) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
164369 298, /* (296) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */ 166455 190, /* (296) cmd ::= create_vtab */
164370 300, /* (297) vtabarg ::= */ 166456 190, /* (297) cmd ::= create_vtab LP vtabarglist RP */
164371 301, /* (298) vtabargtoken ::= ANY */ 166457 298, /* (298) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
164372 301, /* (299) vtabargtoken ::= lp anylist RP */ 166458 300, /* (299) vtabarg ::= */
164373 302, /* (300) lp ::= LP */ 166459 301, /* (300) vtabargtoken ::= ANY */
164374 266, /* (301) with ::= WITH wqlist */ 166460 301, /* (301) vtabargtoken ::= lp anylist RP */
164375 266, /* (302) with ::= WITH RECURSIVE wqlist */ 166461 302, /* (302) lp ::= LP */
164376 305, /* (303) wqas ::= AS */ 166462 266, /* (303) with ::= WITH wqlist */
164377 305, /* (304) wqas ::= AS MATERIALIZED */ 166463 266, /* (304) with ::= WITH RECURSIVE wqlist */
164378 305, /* (305) wqas ::= AS NOT MATERIALIZED */ 166464 305, /* (305) wqas ::= AS */
164379 304, /* (306) wqitem ::= nm eidlist_opt wqas LP select RP */ 166465 305, /* (306) wqas ::= AS MATERIALIZED */
164380 241, /* (307) wqlist ::= wqitem */ 166466 305, /* (307) wqas ::= AS NOT MATERIALIZED */
164381 241, /* (308) wqlist ::= wqlist COMMA wqitem */ 166467 304, /* (308) wqitem ::= nm eidlist_opt wqas LP select RP */
164382 306, /* (309) windowdefn_list ::= windowdefn */ 166468 241, /* (309) wqlist ::= wqitem */
164383 306, /* (310) windowdefn_list ::= windowdefn_list COMMA windowdefn */ 166469 241, /* (310) wqlist ::= wqlist COMMA wqitem */
164384 307, /* (311) windowdefn ::= nm AS LP window RP */ 166470 306, /* (311) windowdefn_list ::= windowdefn */
164385 308, /* (312) window ::= PARTITION BY nexprlist orderby_opt frame_opt */ 166471 306, /* (312) windowdefn_list ::= windowdefn_list COMMA windowdefn */
164386 308, /* (313) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */ 166472 307, /* (313) windowdefn ::= nm AS LP window RP */
164387 308, /* (314) window ::= ORDER BY sortlist frame_opt */ 166473 308, /* (314) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
164388 308, /* (315) window ::= nm ORDER BY sortlist frame_opt */ 166474 308, /* (315) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
164389 308, /* (316) window ::= frame_opt */ 166475 308, /* (316) window ::= ORDER BY sortlist frame_opt */
164390 308, /* (317) window ::= nm frame_opt */ 166476 308, /* (317) window ::= nm ORDER BY sortlist frame_opt */
164391 309, /* (318) frame_opt ::= */ 166477 308, /* (318) window ::= frame_opt */
164392 309, /* (319) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */ 166478 308, /* (319) window ::= nm frame_opt */
164393 309, /* (320) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */ 166479 309, /* (320) frame_opt ::= */
164394 313, /* (321) range_or_rows ::= RANGE|ROWS|GROUPS */ 166480 309, /* (321) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
164395 315, /* (322) frame_bound_s ::= frame_bound */ 166481 309, /* (322) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
164396 315, /* (323) frame_bound_s ::= UNBOUNDED PRECEDING */ 166482 313, /* (323) range_or_rows ::= RANGE|ROWS|GROUPS */
164397 316, /* (324) frame_bound_e ::= frame_bound */ 166483 315, /* (324) frame_bound_s ::= frame_bound */
164398 316, /* (325) frame_bound_e ::= UNBOUNDED FOLLOWING */ 166484 315, /* (325) frame_bound_s ::= UNBOUNDED PRECEDING */
164399 314, /* (326) frame_bound ::= expr PRECEDING|FOLLOWING */ 166485 316, /* (326) frame_bound_e ::= frame_bound */
164400 314, /* (327) frame_bound ::= CURRENT ROW */ 166486 316, /* (327) frame_bound_e ::= UNBOUNDED FOLLOWING */
164401 317, /* (328) frame_exclude_opt ::= */ 166487 314, /* (328) frame_bound ::= expr PRECEDING|FOLLOWING */
164402 317, /* (329) frame_exclude_opt ::= EXCLUDE frame_exclude */ 166488 314, /* (329) frame_bound ::= CURRENT ROW */
164403 318, /* (330) frame_exclude ::= NO OTHERS */ 166489 317, /* (330) frame_exclude_opt ::= */
164404 318, /* (331) frame_exclude ::= CURRENT ROW */ 166490 317, /* (331) frame_exclude_opt ::= EXCLUDE frame_exclude */
164405 318, /* (332) frame_exclude ::= GROUP|TIES */ 166491 318, /* (332) frame_exclude ::= NO OTHERS */
164406 251, /* (333) window_clause ::= WINDOW windowdefn_list */ 166492 318, /* (333) frame_exclude ::= CURRENT ROW */
164407 273, /* (334) filter_over ::= filter_clause over_clause */ 166493 318, /* (334) frame_exclude ::= GROUP|TIES */
164408 273, /* (335) filter_over ::= over_clause */ 166494 251, /* (335) window_clause ::= WINDOW windowdefn_list */
164409 273, /* (336) filter_over ::= filter_clause */ 166495 273, /* (336) filter_over ::= filter_clause over_clause */
164410 312, /* (337) over_clause ::= OVER LP window RP */ 166496 273, /* (337) filter_over ::= over_clause */
164411 312, /* (338) over_clause ::= OVER nm */ 166497 273, /* (338) filter_over ::= filter_clause */
164412 311, /* (339) filter_clause ::= FILTER LP WHERE expr RP */ 166498 312, /* (339) over_clause ::= OVER LP window RP */
164413 185, /* (340) input ::= cmdlist */ 166499 312, /* (340) over_clause ::= OVER nm */
164414 186, /* (341) cmdlist ::= cmdlist ecmd */ 166500 311, /* (341) filter_clause ::= FILTER LP WHERE expr RP */
164415 186, /* (342) cmdlist ::= ecmd */ 166501 185, /* (342) input ::= cmdlist */
164416 187, /* (343) ecmd ::= SEMI */ 166502 186, /* (343) cmdlist ::= cmdlist ecmd */
164417 187, /* (344) ecmd ::= cmdx SEMI */ 166503 186, /* (344) cmdlist ::= ecmd */
164418 187, /* (345) ecmd ::= explain cmdx SEMI */ 166504 187, /* (345) ecmd ::= SEMI */
164419 192, /* (346) trans_opt ::= */ 166505 187, /* (346) ecmd ::= cmdx SEMI */
164420 192, /* (347) trans_opt ::= TRANSACTION */ 166506 187, /* (347) ecmd ::= explain cmdx SEMI */
164421 192, /* (348) trans_opt ::= TRANSACTION nm */ 166507 192, /* (348) trans_opt ::= */
164422 194, /* (349) savepoint_opt ::= SAVEPOINT */ 166508 192, /* (349) trans_opt ::= TRANSACTION */
164423 194, /* (350) savepoint_opt ::= */ 166509 192, /* (350) trans_opt ::= TRANSACTION nm */
164424 190, /* (351) cmd ::= create_table create_table_args */ 166510 194, /* (351) savepoint_opt ::= SAVEPOINT */
164425 203, /* (352) table_option_set ::= table_option */ 166511 194, /* (352) savepoint_opt ::= */
164426 201, /* (353) columnlist ::= columnlist COMMA columnname carglist */ 166512 190, /* (353) cmd ::= create_table create_table_args */
164427 201, /* (354) columnlist ::= columnname carglist */ 166513 203, /* (354) table_option_set ::= table_option */
164428 193, /* (355) nm ::= ID|INDEXED */ 166514 201, /* (355) columnlist ::= columnlist COMMA columnname carglist */
164429 193, /* (356) nm ::= STRING */ 166515 201, /* (356) columnlist ::= columnname carglist */
164430 193, /* (357) nm ::= JOIN_KW */ 166516 193, /* (357) nm ::= ID|INDEXED */
164431 208, /* (358) typetoken ::= typename */ 166517 193, /* (358) nm ::= STRING */
164432 209, /* (359) typename ::= ID|STRING */ 166518 193, /* (359) nm ::= JOIN_KW */
164433 210, /* (360) signed ::= plus_num */ 166519 208, /* (360) typetoken ::= typename */
164434 210, /* (361) signed ::= minus_num */ 166520 209, /* (361) typename ::= ID|STRING */
164435 207, /* (362) carglist ::= carglist ccons */ 166521 210, /* (362) signed ::= plus_num */
164436 207, /* (363) carglist ::= */ 166522 210, /* (363) signed ::= minus_num */
164437 215, /* (364) ccons ::= NULL onconf */ 166523 207, /* (364) carglist ::= carglist ccons */
164438 215, /* (365) ccons ::= GENERATED ALWAYS AS generated */ 166524 207, /* (365) carglist ::= */
164439 215, /* (366) ccons ::= AS generated */ 166525 215, /* (366) ccons ::= NULL onconf */
164440 202, /* (367) conslist_opt ::= COMMA conslist */ 166526 215, /* (367) ccons ::= GENERATED ALWAYS AS generated */
164441 228, /* (368) conslist ::= conslist tconscomma tcons */ 166527 215, /* (368) ccons ::= AS generated */
164442 228, /* (369) conslist ::= tcons */ 166528 202, /* (369) conslist_opt ::= COMMA conslist */
164443 229, /* (370) tconscomma ::= */ 166529 228, /* (370) conslist ::= conslist tconscomma tcons */
164444 233, /* (371) defer_subclause_opt ::= defer_subclause */ 166530 228, /* (371) conslist ::= tcons */
164445 235, /* (372) resolvetype ::= raisetype */ 166531 229, /* (372) tconscomma ::= */
164446 239, /* (373) selectnowith ::= oneselect */ 166532 233, /* (373) defer_subclause_opt ::= defer_subclause */
164447 240, /* (374) oneselect ::= values */ 166533 235, /* (374) resolvetype ::= raisetype */
164448 254, /* (375) sclp ::= selcollist COMMA */ 166534 239, /* (375) selectnowith ::= oneselect */
164449 255, /* (376) as ::= ID|STRING */ 166535 240, /* (376) oneselect ::= values */
164450 272, /* (377) returning ::= */ 166536 254, /* (377) sclp ::= selcollist COMMA */
164451 217, /* (378) expr ::= term */ 166537 255, /* (378) as ::= ID|STRING */
164452 274, /* (379) likeop ::= LIKE_KW|MATCH */ 166538 264, /* (379) indexed_opt ::= indexed_by */
164453 262, /* (380) exprlist ::= nexprlist */ 166539 272, /* (380) returning ::= */
164454 284, /* (381) nmnum ::= plus_num */ 166540 217, /* (381) expr ::= term */
164455 284, /* (382) nmnum ::= nm */ 166541 274, /* (382) likeop ::= LIKE_KW|MATCH */
164456 284, /* (383) nmnum ::= ON */ 166542 261, /* (383) exprlist ::= nexprlist */
164457 284, /* (384) nmnum ::= DELETE */ 166543 284, /* (384) nmnum ::= plus_num */
164458 284, /* (385) nmnum ::= DEFAULT */ 166544 284, /* (385) nmnum ::= nm */
164459 211, /* (386) plus_num ::= INTEGER|FLOAT */ 166545 284, /* (386) nmnum ::= ON */
164460 289, /* (387) foreach_clause ::= */ 166546 284, /* (387) nmnum ::= DELETE */
164461 289, /* (388) foreach_clause ::= FOR EACH ROW */ 166547 284, /* (388) nmnum ::= DEFAULT */
164462 292, /* (389) trnm ::= nm */ 166548 211, /* (389) plus_num ::= INTEGER|FLOAT */
164463 293, /* (390) tridxby ::= */ 166549 289, /* (390) foreach_clause ::= */
164464 294, /* (391) database_kw_opt ::= DATABASE */ 166550 289, /* (391) foreach_clause ::= FOR EACH ROW */
164465 294, /* (392) database_kw_opt ::= */ 166551 292, /* (392) trnm ::= nm */
164466 297, /* (393) kwcolumn_opt ::= */ 166552 293, /* (393) tridxby ::= */
164467 297, /* (394) kwcolumn_opt ::= COLUMNKW */ 166553 294, /* (394) database_kw_opt ::= DATABASE */
164468 299, /* (395) vtabarglist ::= vtabarg */ 166554 294, /* (395) database_kw_opt ::= */
164469 299, /* (396) vtabarglist ::= vtabarglist COMMA vtabarg */ 166555 297, /* (396) kwcolumn_opt ::= */
164470 300, /* (397) vtabarg ::= vtabarg vtabargtoken */ 166556 297, /* (397) kwcolumn_opt ::= COLUMNKW */
164471 303, /* (398) anylist ::= */ 166557 299, /* (398) vtabarglist ::= vtabarg */
164472 303, /* (399) anylist ::= anylist LP anylist RP */ 166558 299, /* (399) vtabarglist ::= vtabarglist COMMA vtabarg */
164473 303, /* (400) anylist ::= anylist ANY */ 166559 300, /* (400) vtabarg ::= vtabarg vtabargtoken */
164474 266, /* (401) with ::= */ 166560 303, /* (401) anylist ::= */
166561 303, /* (402) anylist ::= anylist LP anylist RP */
166562 303, /* (403) anylist ::= anylist ANY */
166563 266, /* (404) with ::= */
164475}; 166564};
164476 166565
164477/* For rule J, yyRuleInfoNRhs[J] contains the negative of the number 166566/* For rule J, yyRuleInfoNRhs[J] contains the negative of the number
@@ -164586,29 +166675,29 @@ static const signed char yyRuleInfoNRhs[] = {
164586 -2, /* (106) from ::= FROM seltablist */ 166675 -2, /* (106) from ::= FROM seltablist */
164587 -2, /* (107) stl_prefix ::= seltablist joinop */ 166676 -2, /* (107) stl_prefix ::= seltablist joinop */
164588 0, /* (108) stl_prefix ::= */ 166677 0, /* (108) stl_prefix ::= */
164589 -7, /* (109) seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */ 166678 -5, /* (109) seltablist ::= stl_prefix nm dbnm as on_using */
164590 -9, /* (110) seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */ 166679 -6, /* (110) seltablist ::= stl_prefix nm dbnm as indexed_by on_using */
164591 -7, /* (111) seltablist ::= stl_prefix LP select RP as on_opt using_opt */ 166680 -8, /* (111) seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_using */
164592 -7, /* (112) seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */ 166681 -6, /* (112) seltablist ::= stl_prefix LP select RP as on_using */
164593 0, /* (113) dbnm ::= */ 166682 -6, /* (113) seltablist ::= stl_prefix LP seltablist RP as on_using */
164594 -2, /* (114) dbnm ::= DOT nm */ 166683 0, /* (114) dbnm ::= */
164595 -1, /* (115) fullname ::= nm */ 166684 -2, /* (115) dbnm ::= DOT nm */
164596 -3, /* (116) fullname ::= nm DOT nm */ 166685 -1, /* (116) fullname ::= nm */
164597 -1, /* (117) xfullname ::= nm */ 166686 -3, /* (117) fullname ::= nm DOT nm */
164598 -3, /* (118) xfullname ::= nm DOT nm */ 166687 -1, /* (118) xfullname ::= nm */
164599 -5, /* (119) xfullname ::= nm DOT nm AS nm */ 166688 -3, /* (119) xfullname ::= nm DOT nm */
164600 -3, /* (120) xfullname ::= nm AS nm */ 166689 -5, /* (120) xfullname ::= nm DOT nm AS nm */
164601 -1, /* (121) joinop ::= COMMA|JOIN */ 166690 -3, /* (121) xfullname ::= nm AS nm */
164602 -2, /* (122) joinop ::= JOIN_KW JOIN */ 166691 -1, /* (122) joinop ::= COMMA|JOIN */
164603 -3, /* (123) joinop ::= JOIN_KW nm JOIN */ 166692 -2, /* (123) joinop ::= JOIN_KW JOIN */
164604 -4, /* (124) joinop ::= JOIN_KW nm nm JOIN */ 166693 -3, /* (124) joinop ::= JOIN_KW nm JOIN */
164605 -2, /* (125) on_opt ::= ON expr */ 166694 -4, /* (125) joinop ::= JOIN_KW nm nm JOIN */
164606 0, /* (126) on_opt ::= */ 166695 -2, /* (126) on_using ::= ON expr */
164607 0, /* (127) indexed_opt ::= */ 166696 -4, /* (127) on_using ::= USING LP idlist RP */
164608 -3, /* (128) indexed_opt ::= INDEXED BY nm */ 166697 0, /* (128) on_using ::= */
164609 -2, /* (129) indexed_opt ::= NOT INDEXED */ 166698 0, /* (129) indexed_opt ::= */
164610 -4, /* (130) using_opt ::= USING LP idlist RP */ 166699 -3, /* (130) indexed_by ::= INDEXED BY nm */
164611 0, /* (131) using_opt ::= */ 166700 -2, /* (131) indexed_by ::= NOT INDEXED */
164612 0, /* (132) orderby_opt ::= */ 166701 0, /* (132) orderby_opt ::= */
164613 -3, /* (133) orderby_opt ::= ORDER BY sortlist */ 166702 -3, /* (133) orderby_opt ::= ORDER BY sortlist */
164614 -5, /* (134) sortlist ::= sortlist COMMA expr sortorder nulls */ 166703 -5, /* (134) sortlist ::= sortlist COMMA expr sortorder nulls */
@@ -164686,199 +166775,202 @@ static const signed char yyRuleInfoNRhs[] = {
164686 -3, /* (206) expr ::= expr NOT NULL */ 166775 -3, /* (206) expr ::= expr NOT NULL */
164687 -3, /* (207) expr ::= expr IS expr */ 166776 -3, /* (207) expr ::= expr IS expr */
164688 -4, /* (208) expr ::= expr IS NOT expr */ 166777 -4, /* (208) expr ::= expr IS NOT expr */
164689 -2, /* (209) expr ::= NOT expr */ 166778 -6, /* (209) expr ::= expr IS NOT DISTINCT FROM expr */
164690 -2, /* (210) expr ::= BITNOT expr */ 166779 -5, /* (210) expr ::= expr IS DISTINCT FROM expr */
164691 -2, /* (211) expr ::= PLUS|MINUS expr */ 166780 -2, /* (211) expr ::= NOT expr */
164692 -3, /* (212) expr ::= expr PTR expr */ 166781 -2, /* (212) expr ::= BITNOT expr */
164693 -1, /* (213) between_op ::= BETWEEN */ 166782 -2, /* (213) expr ::= PLUS|MINUS expr */
164694 -2, /* (214) between_op ::= NOT BETWEEN */ 166783 -3, /* (214) expr ::= expr PTR expr */
164695 -5, /* (215) expr ::= expr between_op expr AND expr */ 166784 -1, /* (215) between_op ::= BETWEEN */
164696 -1, /* (216) in_op ::= IN */ 166785 -2, /* (216) between_op ::= NOT BETWEEN */
164697 -2, /* (217) in_op ::= NOT IN */ 166786 -5, /* (217) expr ::= expr between_op expr AND expr */
164698 -5, /* (218) expr ::= expr in_op LP exprlist RP */ 166787 -1, /* (218) in_op ::= IN */
164699 -3, /* (219) expr ::= LP select RP */ 166788 -2, /* (219) in_op ::= NOT IN */
164700 -5, /* (220) expr ::= expr in_op LP select RP */ 166789 -5, /* (220) expr ::= expr in_op LP exprlist RP */
164701 -5, /* (221) expr ::= expr in_op nm dbnm paren_exprlist */ 166790 -3, /* (221) expr ::= LP select RP */
164702 -4, /* (222) expr ::= EXISTS LP select RP */ 166791 -5, /* (222) expr ::= expr in_op LP select RP */
164703 -5, /* (223) expr ::= CASE case_operand case_exprlist case_else END */ 166792 -5, /* (223) expr ::= expr in_op nm dbnm paren_exprlist */
164704 -5, /* (224) case_exprlist ::= case_exprlist WHEN expr THEN expr */ 166793 -4, /* (224) expr ::= EXISTS LP select RP */
164705 -4, /* (225) case_exprlist ::= WHEN expr THEN expr */ 166794 -5, /* (225) expr ::= CASE case_operand case_exprlist case_else END */
164706 -2, /* (226) case_else ::= ELSE expr */ 166795 -5, /* (226) case_exprlist ::= case_exprlist WHEN expr THEN expr */
164707 0, /* (227) case_else ::= */ 166796 -4, /* (227) case_exprlist ::= WHEN expr THEN expr */
164708 -1, /* (228) case_operand ::= expr */ 166797 -2, /* (228) case_else ::= ELSE expr */
164709 0, /* (229) case_operand ::= */ 166798 0, /* (229) case_else ::= */
164710 0, /* (230) exprlist ::= */ 166799 -1, /* (230) case_operand ::= expr */
164711 -3, /* (231) nexprlist ::= nexprlist COMMA expr */ 166800 0, /* (231) case_operand ::= */
164712 -1, /* (232) nexprlist ::= expr */ 166801 0, /* (232) exprlist ::= */
164713 0, /* (233) paren_exprlist ::= */ 166802 -3, /* (233) nexprlist ::= nexprlist COMMA expr */
164714 -3, /* (234) paren_exprlist ::= LP exprlist RP */ 166803 -1, /* (234) nexprlist ::= expr */
164715 -12, /* (235) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */ 166804 0, /* (235) paren_exprlist ::= */
164716 -1, /* (236) uniqueflag ::= UNIQUE */ 166805 -3, /* (236) paren_exprlist ::= LP exprlist RP */
164717 0, /* (237) uniqueflag ::= */ 166806 -12, /* (237) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
164718 0, /* (238) eidlist_opt ::= */ 166807 -1, /* (238) uniqueflag ::= UNIQUE */
164719 -3, /* (239) eidlist_opt ::= LP eidlist RP */ 166808 0, /* (239) uniqueflag ::= */
164720 -5, /* (240) eidlist ::= eidlist COMMA nm collate sortorder */ 166809 0, /* (240) eidlist_opt ::= */
164721 -3, /* (241) eidlist ::= nm collate sortorder */ 166810 -3, /* (241) eidlist_opt ::= LP eidlist RP */
164722 0, /* (242) collate ::= */ 166811 -5, /* (242) eidlist ::= eidlist COMMA nm collate sortorder */
164723 -2, /* (243) collate ::= COLLATE ID|STRING */ 166812 -3, /* (243) eidlist ::= nm collate sortorder */
164724 -4, /* (244) cmd ::= DROP INDEX ifexists fullname */ 166813 0, /* (244) collate ::= */
164725 -2, /* (245) cmd ::= VACUUM vinto */ 166814 -2, /* (245) collate ::= COLLATE ID|STRING */
164726 -3, /* (246) cmd ::= VACUUM nm vinto */ 166815 -4, /* (246) cmd ::= DROP INDEX ifexists fullname */
164727 -2, /* (247) vinto ::= INTO expr */ 166816 -2, /* (247) cmd ::= VACUUM vinto */
164728 0, /* (248) vinto ::= */ 166817 -3, /* (248) cmd ::= VACUUM nm vinto */
164729 -3, /* (249) cmd ::= PRAGMA nm dbnm */ 166818 -2, /* (249) vinto ::= INTO expr */
164730 -5, /* (250) cmd ::= PRAGMA nm dbnm EQ nmnum */ 166819 0, /* (250) vinto ::= */
164731 -6, /* (251) cmd ::= PRAGMA nm dbnm LP nmnum RP */ 166820 -3, /* (251) cmd ::= PRAGMA nm dbnm */
164732 -5, /* (252) cmd ::= PRAGMA nm dbnm EQ minus_num */ 166821 -5, /* (252) cmd ::= PRAGMA nm dbnm EQ nmnum */
164733 -6, /* (253) cmd ::= PRAGMA nm dbnm LP minus_num RP */ 166822 -6, /* (253) cmd ::= PRAGMA nm dbnm LP nmnum RP */
164734 -2, /* (254) plus_num ::= PLUS INTEGER|FLOAT */ 166823 -5, /* (254) cmd ::= PRAGMA nm dbnm EQ minus_num */
164735 -2, /* (255) minus_num ::= MINUS INTEGER|FLOAT */ 166824 -6, /* (255) cmd ::= PRAGMA nm dbnm LP minus_num RP */
164736 -5, /* (256) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */ 166825 -2, /* (256) plus_num ::= PLUS INTEGER|FLOAT */
164737 -11, /* (257) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ 166826 -2, /* (257) minus_num ::= MINUS INTEGER|FLOAT */
164738 -1, /* (258) trigger_time ::= BEFORE|AFTER */ 166827 -5, /* (258) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
164739 -2, /* (259) trigger_time ::= INSTEAD OF */ 166828 -11, /* (259) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
164740 0, /* (260) trigger_time ::= */ 166829 -1, /* (260) trigger_time ::= BEFORE|AFTER */
164741 -1, /* (261) trigger_event ::= DELETE|INSERT */ 166830 -2, /* (261) trigger_time ::= INSTEAD OF */
164742 -1, /* (262) trigger_event ::= UPDATE */ 166831 0, /* (262) trigger_time ::= */
164743 -3, /* (263) trigger_event ::= UPDATE OF idlist */ 166832 -1, /* (263) trigger_event ::= DELETE|INSERT */
164744 0, /* (264) when_clause ::= */ 166833 -1, /* (264) trigger_event ::= UPDATE */
164745 -2, /* (265) when_clause ::= WHEN expr */ 166834 -3, /* (265) trigger_event ::= UPDATE OF idlist */
164746 -3, /* (266) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ 166835 0, /* (266) when_clause ::= */
164747 -2, /* (267) trigger_cmd_list ::= trigger_cmd SEMI */ 166836 -2, /* (267) when_clause ::= WHEN expr */
164748 -3, /* (268) trnm ::= nm DOT nm */ 166837 -3, /* (268) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
164749 -3, /* (269) tridxby ::= INDEXED BY nm */ 166838 -2, /* (269) trigger_cmd_list ::= trigger_cmd SEMI */
164750 -2, /* (270) tridxby ::= NOT INDEXED */ 166839 -3, /* (270) trnm ::= nm DOT nm */
164751 -9, /* (271) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */ 166840 -3, /* (271) tridxby ::= INDEXED BY nm */
164752 -8, /* (272) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */ 166841 -2, /* (272) tridxby ::= NOT INDEXED */
164753 -6, /* (273) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */ 166842 -9, /* (273) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
164754 -3, /* (274) trigger_cmd ::= scanpt select scanpt */ 166843 -8, /* (274) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
164755 -4, /* (275) expr ::= RAISE LP IGNORE RP */ 166844 -6, /* (275) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
164756 -6, /* (276) expr ::= RAISE LP raisetype COMMA nm RP */ 166845 -3, /* (276) trigger_cmd ::= scanpt select scanpt */
164757 -1, /* (277) raisetype ::= ROLLBACK */ 166846 -4, /* (277) expr ::= RAISE LP IGNORE RP */
164758 -1, /* (278) raisetype ::= ABORT */ 166847 -6, /* (278) expr ::= RAISE LP raisetype COMMA nm RP */
164759 -1, /* (279) raisetype ::= FAIL */ 166848 -1, /* (279) raisetype ::= ROLLBACK */
164760 -4, /* (280) cmd ::= DROP TRIGGER ifexists fullname */ 166849 -1, /* (280) raisetype ::= ABORT */
164761 -6, /* (281) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ 166850 -1, /* (281) raisetype ::= FAIL */
164762 -3, /* (282) cmd ::= DETACH database_kw_opt expr */ 166851 -4, /* (282) cmd ::= DROP TRIGGER ifexists fullname */
164763 0, /* (283) key_opt ::= */ 166852 -6, /* (283) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
164764 -2, /* (284) key_opt ::= KEY expr */ 166853 -3, /* (284) cmd ::= DETACH database_kw_opt expr */
164765 -1, /* (285) cmd ::= REINDEX */ 166854 0, /* (285) key_opt ::= */
164766 -3, /* (286) cmd ::= REINDEX nm dbnm */ 166855 -2, /* (286) key_opt ::= KEY expr */
164767 -1, /* (287) cmd ::= ANALYZE */ 166856 -1, /* (287) cmd ::= REINDEX */
164768 -3, /* (288) cmd ::= ANALYZE nm dbnm */ 166857 -3, /* (288) cmd ::= REINDEX nm dbnm */
164769 -6, /* (289) cmd ::= ALTER TABLE fullname RENAME TO nm */ 166858 -1, /* (289) cmd ::= ANALYZE */
164770 -7, /* (290) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */ 166859 -3, /* (290) cmd ::= ANALYZE nm dbnm */
164771 -6, /* (291) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */ 166860 -6, /* (291) cmd ::= ALTER TABLE fullname RENAME TO nm */
164772 -1, /* (292) add_column_fullname ::= fullname */ 166861 -7, /* (292) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
164773 -8, /* (293) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */ 166862 -6, /* (293) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
164774 -1, /* (294) cmd ::= create_vtab */ 166863 -1, /* (294) add_column_fullname ::= fullname */
164775 -4, /* (295) cmd ::= create_vtab LP vtabarglist RP */ 166864 -8, /* (295) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
164776 -8, /* (296) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */ 166865 -1, /* (296) cmd ::= create_vtab */
164777 0, /* (297) vtabarg ::= */ 166866 -4, /* (297) cmd ::= create_vtab LP vtabarglist RP */
164778 -1, /* (298) vtabargtoken ::= ANY */ 166867 -8, /* (298) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
164779 -3, /* (299) vtabargtoken ::= lp anylist RP */ 166868 0, /* (299) vtabarg ::= */
164780 -1, /* (300) lp ::= LP */ 166869 -1, /* (300) vtabargtoken ::= ANY */
164781 -2, /* (301) with ::= WITH wqlist */ 166870 -3, /* (301) vtabargtoken ::= lp anylist RP */
164782 -3, /* (302) with ::= WITH RECURSIVE wqlist */ 166871 -1, /* (302) lp ::= LP */
164783 -1, /* (303) wqas ::= AS */ 166872 -2, /* (303) with ::= WITH wqlist */
164784 -2, /* (304) wqas ::= AS MATERIALIZED */ 166873 -3, /* (304) with ::= WITH RECURSIVE wqlist */
164785 -3, /* (305) wqas ::= AS NOT MATERIALIZED */ 166874 -1, /* (305) wqas ::= AS */
164786 -6, /* (306) wqitem ::= nm eidlist_opt wqas LP select RP */ 166875 -2, /* (306) wqas ::= AS MATERIALIZED */
164787 -1, /* (307) wqlist ::= wqitem */ 166876 -3, /* (307) wqas ::= AS NOT MATERIALIZED */
164788 -3, /* (308) wqlist ::= wqlist COMMA wqitem */ 166877 -6, /* (308) wqitem ::= nm eidlist_opt wqas LP select RP */
164789 -1, /* (309) windowdefn_list ::= windowdefn */ 166878 -1, /* (309) wqlist ::= wqitem */
164790 -3, /* (310) windowdefn_list ::= windowdefn_list COMMA windowdefn */ 166879 -3, /* (310) wqlist ::= wqlist COMMA wqitem */
164791 -5, /* (311) windowdefn ::= nm AS LP window RP */ 166880 -1, /* (311) windowdefn_list ::= windowdefn */
164792 -5, /* (312) window ::= PARTITION BY nexprlist orderby_opt frame_opt */ 166881 -3, /* (312) windowdefn_list ::= windowdefn_list COMMA windowdefn */
164793 -6, /* (313) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */ 166882 -5, /* (313) windowdefn ::= nm AS LP window RP */
164794 -4, /* (314) window ::= ORDER BY sortlist frame_opt */ 166883 -5, /* (314) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
164795 -5, /* (315) window ::= nm ORDER BY sortlist frame_opt */ 166884 -6, /* (315) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
164796 -1, /* (316) window ::= frame_opt */ 166885 -4, /* (316) window ::= ORDER BY sortlist frame_opt */
164797 -2, /* (317) window ::= nm frame_opt */ 166886 -5, /* (317) window ::= nm ORDER BY sortlist frame_opt */
164798 0, /* (318) frame_opt ::= */ 166887 -1, /* (318) window ::= frame_opt */
164799 -3, /* (319) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */ 166888 -2, /* (319) window ::= nm frame_opt */
164800 -6, /* (320) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */ 166889 0, /* (320) frame_opt ::= */
164801 -1, /* (321) range_or_rows ::= RANGE|ROWS|GROUPS */ 166890 -3, /* (321) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
164802 -1, /* (322) frame_bound_s ::= frame_bound */ 166891 -6, /* (322) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
164803 -2, /* (323) frame_bound_s ::= UNBOUNDED PRECEDING */ 166892 -1, /* (323) range_or_rows ::= RANGE|ROWS|GROUPS */
164804 -1, /* (324) frame_bound_e ::= frame_bound */ 166893 -1, /* (324) frame_bound_s ::= frame_bound */
164805 -2, /* (325) frame_bound_e ::= UNBOUNDED FOLLOWING */ 166894 -2, /* (325) frame_bound_s ::= UNBOUNDED PRECEDING */
164806 -2, /* (326) frame_bound ::= expr PRECEDING|FOLLOWING */ 166895 -1, /* (326) frame_bound_e ::= frame_bound */
164807 -2, /* (327) frame_bound ::= CURRENT ROW */ 166896 -2, /* (327) frame_bound_e ::= UNBOUNDED FOLLOWING */
164808 0, /* (328) frame_exclude_opt ::= */ 166897 -2, /* (328) frame_bound ::= expr PRECEDING|FOLLOWING */
164809 -2, /* (329) frame_exclude_opt ::= EXCLUDE frame_exclude */ 166898 -2, /* (329) frame_bound ::= CURRENT ROW */
164810 -2, /* (330) frame_exclude ::= NO OTHERS */ 166899 0, /* (330) frame_exclude_opt ::= */
164811 -2, /* (331) frame_exclude ::= CURRENT ROW */ 166900 -2, /* (331) frame_exclude_opt ::= EXCLUDE frame_exclude */
164812 -1, /* (332) frame_exclude ::= GROUP|TIES */ 166901 -2, /* (332) frame_exclude ::= NO OTHERS */
164813 -2, /* (333) window_clause ::= WINDOW windowdefn_list */ 166902 -2, /* (333) frame_exclude ::= CURRENT ROW */
164814 -2, /* (334) filter_over ::= filter_clause over_clause */ 166903 -1, /* (334) frame_exclude ::= GROUP|TIES */
164815 -1, /* (335) filter_over ::= over_clause */ 166904 -2, /* (335) window_clause ::= WINDOW windowdefn_list */
164816 -1, /* (336) filter_over ::= filter_clause */ 166905 -2, /* (336) filter_over ::= filter_clause over_clause */
164817 -4, /* (337) over_clause ::= OVER LP window RP */ 166906 -1, /* (337) filter_over ::= over_clause */
164818 -2, /* (338) over_clause ::= OVER nm */ 166907 -1, /* (338) filter_over ::= filter_clause */
164819 -5, /* (339) filter_clause ::= FILTER LP WHERE expr RP */ 166908 -4, /* (339) over_clause ::= OVER LP window RP */
164820 -1, /* (340) input ::= cmdlist */ 166909 -2, /* (340) over_clause ::= OVER nm */
164821 -2, /* (341) cmdlist ::= cmdlist ecmd */ 166910 -5, /* (341) filter_clause ::= FILTER LP WHERE expr RP */
164822 -1, /* (342) cmdlist ::= ecmd */ 166911 -1, /* (342) input ::= cmdlist */
164823 -1, /* (343) ecmd ::= SEMI */ 166912 -2, /* (343) cmdlist ::= cmdlist ecmd */
164824 -2, /* (344) ecmd ::= cmdx SEMI */ 166913 -1, /* (344) cmdlist ::= ecmd */
164825 -3, /* (345) ecmd ::= explain cmdx SEMI */ 166914 -1, /* (345) ecmd ::= SEMI */
164826 0, /* (346) trans_opt ::= */ 166915 -2, /* (346) ecmd ::= cmdx SEMI */
164827 -1, /* (347) trans_opt ::= TRANSACTION */ 166916 -3, /* (347) ecmd ::= explain cmdx SEMI */
164828 -2, /* (348) trans_opt ::= TRANSACTION nm */ 166917 0, /* (348) trans_opt ::= */
164829 -1, /* (349) savepoint_opt ::= SAVEPOINT */ 166918 -1, /* (349) trans_opt ::= TRANSACTION */
164830 0, /* (350) savepoint_opt ::= */ 166919 -2, /* (350) trans_opt ::= TRANSACTION nm */
164831 -2, /* (351) cmd ::= create_table create_table_args */ 166920 -1, /* (351) savepoint_opt ::= SAVEPOINT */
164832 -1, /* (352) table_option_set ::= table_option */ 166921 0, /* (352) savepoint_opt ::= */
164833 -4, /* (353) columnlist ::= columnlist COMMA columnname carglist */ 166922 -2, /* (353) cmd ::= create_table create_table_args */
164834 -2, /* (354) columnlist ::= columnname carglist */ 166923 -1, /* (354) table_option_set ::= table_option */
164835 -1, /* (355) nm ::= ID|INDEXED */ 166924 -4, /* (355) columnlist ::= columnlist COMMA columnname carglist */
164836 -1, /* (356) nm ::= STRING */ 166925 -2, /* (356) columnlist ::= columnname carglist */
164837 -1, /* (357) nm ::= JOIN_KW */ 166926 -1, /* (357) nm ::= ID|INDEXED */
164838 -1, /* (358) typetoken ::= typename */ 166927 -1, /* (358) nm ::= STRING */
164839 -1, /* (359) typename ::= ID|STRING */ 166928 -1, /* (359) nm ::= JOIN_KW */
164840 -1, /* (360) signed ::= plus_num */ 166929 -1, /* (360) typetoken ::= typename */
164841 -1, /* (361) signed ::= minus_num */ 166930 -1, /* (361) typename ::= ID|STRING */
164842 -2, /* (362) carglist ::= carglist ccons */ 166931 -1, /* (362) signed ::= plus_num */
164843 0, /* (363) carglist ::= */ 166932 -1, /* (363) signed ::= minus_num */
164844 -2, /* (364) ccons ::= NULL onconf */ 166933 -2, /* (364) carglist ::= carglist ccons */
164845 -4, /* (365) ccons ::= GENERATED ALWAYS AS generated */ 166934 0, /* (365) carglist ::= */
164846 -2, /* (366) ccons ::= AS generated */ 166935 -2, /* (366) ccons ::= NULL onconf */
164847 -2, /* (367) conslist_opt ::= COMMA conslist */ 166936 -4, /* (367) ccons ::= GENERATED ALWAYS AS generated */
164848 -3, /* (368) conslist ::= conslist tconscomma tcons */ 166937 -2, /* (368) ccons ::= AS generated */
164849 -1, /* (369) conslist ::= tcons */ 166938 -2, /* (369) conslist_opt ::= COMMA conslist */
164850 0, /* (370) tconscomma ::= */ 166939 -3, /* (370) conslist ::= conslist tconscomma tcons */
164851 -1, /* (371) defer_subclause_opt ::= defer_subclause */ 166940 -1, /* (371) conslist ::= tcons */
164852 -1, /* (372) resolvetype ::= raisetype */ 166941 0, /* (372) tconscomma ::= */
164853 -1, /* (373) selectnowith ::= oneselect */ 166942 -1, /* (373) defer_subclause_opt ::= defer_subclause */
164854 -1, /* (374) oneselect ::= values */ 166943 -1, /* (374) resolvetype ::= raisetype */
164855 -2, /* (375) sclp ::= selcollist COMMA */ 166944 -1, /* (375) selectnowith ::= oneselect */
164856 -1, /* (376) as ::= ID|STRING */ 166945 -1, /* (376) oneselect ::= values */
164857 0, /* (377) returning ::= */ 166946 -2, /* (377) sclp ::= selcollist COMMA */
164858 -1, /* (378) expr ::= term */ 166947 -1, /* (378) as ::= ID|STRING */
164859 -1, /* (379) likeop ::= LIKE_KW|MATCH */ 166948 -1, /* (379) indexed_opt ::= indexed_by */
164860 -1, /* (380) exprlist ::= nexprlist */ 166949 0, /* (380) returning ::= */
164861 -1, /* (381) nmnum ::= plus_num */ 166950 -1, /* (381) expr ::= term */
164862 -1, /* (382) nmnum ::= nm */ 166951 -1, /* (382) likeop ::= LIKE_KW|MATCH */
164863 -1, /* (383) nmnum ::= ON */ 166952 -1, /* (383) exprlist ::= nexprlist */
164864 -1, /* (384) nmnum ::= DELETE */ 166953 -1, /* (384) nmnum ::= plus_num */
164865 -1, /* (385) nmnum ::= DEFAULT */ 166954 -1, /* (385) nmnum ::= nm */
164866 -1, /* (386) plus_num ::= INTEGER|FLOAT */ 166955 -1, /* (386) nmnum ::= ON */
164867 0, /* (387) foreach_clause ::= */ 166956 -1, /* (387) nmnum ::= DELETE */
164868 -3, /* (388) foreach_clause ::= FOR EACH ROW */ 166957 -1, /* (388) nmnum ::= DEFAULT */
164869 -1, /* (389) trnm ::= nm */ 166958 -1, /* (389) plus_num ::= INTEGER|FLOAT */
164870 0, /* (390) tridxby ::= */ 166959 0, /* (390) foreach_clause ::= */
164871 -1, /* (391) database_kw_opt ::= DATABASE */ 166960 -3, /* (391) foreach_clause ::= FOR EACH ROW */
164872 0, /* (392) database_kw_opt ::= */ 166961 -1, /* (392) trnm ::= nm */
164873 0, /* (393) kwcolumn_opt ::= */ 166962 0, /* (393) tridxby ::= */
164874 -1, /* (394) kwcolumn_opt ::= COLUMNKW */ 166963 -1, /* (394) database_kw_opt ::= DATABASE */
164875 -1, /* (395) vtabarglist ::= vtabarg */ 166964 0, /* (395) database_kw_opt ::= */
164876 -3, /* (396) vtabarglist ::= vtabarglist COMMA vtabarg */ 166965 0, /* (396) kwcolumn_opt ::= */
164877 -2, /* (397) vtabarg ::= vtabarg vtabargtoken */ 166966 -1, /* (397) kwcolumn_opt ::= COLUMNKW */
164878 0, /* (398) anylist ::= */ 166967 -1, /* (398) vtabarglist ::= vtabarg */
164879 -4, /* (399) anylist ::= anylist LP anylist RP */ 166968 -3, /* (399) vtabarglist ::= vtabarglist COMMA vtabarg */
164880 -2, /* (400) anylist ::= anylist ANY */ 166969 -2, /* (400) vtabarg ::= vtabarg vtabargtoken */
164881 0, /* (401) with ::= */ 166970 0, /* (401) anylist ::= */
166971 -4, /* (402) anylist ::= anylist LP anylist RP */
166972 -2, /* (403) anylist ::= anylist ANY */
166973 0, /* (404) with ::= */
164882}; 166974};
164883 166975
164884static void yy_accept(yyParser*); /* Forward Declaration */ 166976static void yy_accept(yyParser*); /* Forward Declaration */
@@ -164938,7 +167030,7 @@ static YYACTIONTYPE yy_reduce(
164938 case 5: /* transtype ::= DEFERRED */ 167030 case 5: /* transtype ::= DEFERRED */
164939 case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6); 167031 case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6);
164940 case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7); 167032 case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7);
164941 case 321: /* range_or_rows ::= RANGE|ROWS|GROUPS */ yytestcase(yyruleno==321); 167033 case 323: /* range_or_rows ::= RANGE|ROWS|GROUPS */ yytestcase(yyruleno==323);
164942{yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/} 167034{yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/}
164943 break; 167035 break;
164944 case 8: /* cmd ::= COMMIT|END trans_opt */ 167036 case 8: /* cmd ::= COMMIT|END trans_opt */
@@ -164975,7 +167067,7 @@ static YYACTIONTYPE yy_reduce(
164975 case 72: /* defer_subclause_opt ::= */ yytestcase(yyruleno==72); 167067 case 72: /* defer_subclause_opt ::= */ yytestcase(yyruleno==72);
164976 case 81: /* ifexists ::= */ yytestcase(yyruleno==81); 167068 case 81: /* ifexists ::= */ yytestcase(yyruleno==81);
164977 case 98: /* distinct ::= */ yytestcase(yyruleno==98); 167069 case 98: /* distinct ::= */ yytestcase(yyruleno==98);
164978 case 242: /* collate ::= */ yytestcase(yyruleno==242); 167070 case 244: /* collate ::= */ yytestcase(yyruleno==244);
164979{yymsp[1].minor.yy394 = 0;} 167071{yymsp[1].minor.yy394 = 0;}
164980 break; 167072 break;
164981 case 16: /* ifnotexists ::= IF NOT EXISTS */ 167073 case 16: /* ifnotexists ::= IF NOT EXISTS */
@@ -165159,9 +167251,9 @@ static YYACTIONTYPE yy_reduce(
165159 break; 167251 break;
165160 case 63: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ 167252 case 63: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
165161 case 80: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==80); 167253 case 80: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==80);
165162 case 214: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==214); 167254 case 216: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==216);
165163 case 217: /* in_op ::= NOT IN */ yytestcase(yyruleno==217); 167255 case 219: /* in_op ::= NOT IN */ yytestcase(yyruleno==219);
165164 case 243: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==243); 167256 case 245: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==245);
165165{yymsp[-1].minor.yy394 = 1;} 167257{yymsp[-1].minor.yy394 = 1;}
165166 break; 167258 break;
165167 case 64: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ 167259 case 64: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
@@ -165246,7 +167338,7 @@ static YYACTIONTYPE yy_reduce(
165246 Token x; 167338 Token x;
165247 x.n = 0; 167339 x.n = 0;
165248 parserDoubleLinkSelect(pParse, pRhs); 167340 parserDoubleLinkSelect(pParse, pRhs);
165249 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0); 167341 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0);
165250 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0); 167342 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0);
165251 } 167343 }
165252 if( pRhs ){ 167344 if( pRhs ){
@@ -165311,9 +167403,9 @@ static YYACTIONTYPE yy_reduce(
165311 case 99: /* sclp ::= */ 167403 case 99: /* sclp ::= */
165312 case 132: /* orderby_opt ::= */ yytestcase(yyruleno==132); 167404 case 132: /* orderby_opt ::= */ yytestcase(yyruleno==132);
165313 case 142: /* groupby_opt ::= */ yytestcase(yyruleno==142); 167405 case 142: /* groupby_opt ::= */ yytestcase(yyruleno==142);
165314 case 230: /* exprlist ::= */ yytestcase(yyruleno==230); 167406 case 232: /* exprlist ::= */ yytestcase(yyruleno==232);
165315 case 233: /* paren_exprlist ::= */ yytestcase(yyruleno==233); 167407 case 235: /* paren_exprlist ::= */ yytestcase(yyruleno==235);
165316 case 238: /* eidlist_opt ::= */ yytestcase(yyruleno==238); 167408 case 240: /* eidlist_opt ::= */ yytestcase(yyruleno==240);
165317{yymsp[1].minor.yy322 = 0;} 167409{yymsp[1].minor.yy322 = 0;}
165318 break; 167410 break;
165319 case 100: /* selcollist ::= sclp scanpt expr scanpt as */ 167411 case 100: /* selcollist ::= sclp scanpt expr scanpt as */
@@ -165338,9 +167430,9 @@ static YYACTIONTYPE yy_reduce(
165338} 167430}
165339 break; 167431 break;
165340 case 103: /* as ::= AS nm */ 167432 case 103: /* as ::= AS nm */
165341 case 114: /* dbnm ::= DOT nm */ yytestcase(yyruleno==114); 167433 case 115: /* dbnm ::= DOT nm */ yytestcase(yyruleno==115);
165342 case 254: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==254); 167434 case 256: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==256);
165343 case 255: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==255); 167435 case 257: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==257);
165344{yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;} 167436{yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
165345 break; 167437 break;
165346 case 105: /* from ::= */ 167438 case 105: /* from ::= */
@@ -165350,7 +167442,7 @@ static YYACTIONTYPE yy_reduce(
165350 case 106: /* from ::= FROM seltablist */ 167442 case 106: /* from ::= FROM seltablist */
165351{ 167443{
165352 yymsp[-1].minor.yy131 = yymsp[0].minor.yy131; 167444 yymsp[-1].minor.yy131 = yymsp[0].minor.yy131;
165353 sqlite3SrcListShiftJoinType(yymsp[-1].minor.yy131); 167445 sqlite3SrcListShiftJoinType(pParse,yymsp[-1].minor.yy131);
165354} 167446}
165355 break; 167447 break;
165356 case 107: /* stl_prefix ::= seltablist joinop */ 167448 case 107: /* stl_prefix ::= seltablist joinop */
@@ -165358,35 +167450,43 @@ static YYACTIONTYPE yy_reduce(
165358 if( ALWAYS(yymsp[-1].minor.yy131 && yymsp[-1].minor.yy131->nSrc>0) ) yymsp[-1].minor.yy131->a[yymsp[-1].minor.yy131->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy394; 167450 if( ALWAYS(yymsp[-1].minor.yy131 && yymsp[-1].minor.yy131->nSrc>0) ) yymsp[-1].minor.yy131->a[yymsp[-1].minor.yy131->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy394;
165359} 167451}
165360 break; 167452 break;
165361 case 109: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */ 167453 case 109: /* seltablist ::= stl_prefix nm dbnm as on_using */
167454{
167455 yymsp[-4].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-4].minor.yy131,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0,&yymsp[0].minor.yy561);
167456}
167457 break;
167458 case 110: /* seltablist ::= stl_prefix nm dbnm as indexed_by on_using */
165362{ 167459{
165363 yymsp[-6].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy131,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy528,yymsp[0].minor.yy254); 167460 yymsp[-5].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-5].minor.yy131,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,0,&yymsp[0].minor.yy561);
165364 sqlite3SrcListIndexedBy(pParse, yymsp[-6].minor.yy131, &yymsp[-2].minor.yy0); 167461 sqlite3SrcListIndexedBy(pParse, yymsp[-5].minor.yy131, &yymsp[-1].minor.yy0);
165365} 167462}
165366 break; 167463 break;
165367 case 110: /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */ 167464 case 111: /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_using */
165368{ 167465{
165369 yymsp[-8].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy131,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy528,yymsp[0].minor.yy254); 167466 yymsp[-7].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-7].minor.yy131,&yymsp[-6].minor.yy0,&yymsp[-5].minor.yy0,&yymsp[-1].minor.yy0,0,&yymsp[0].minor.yy561);
165370 sqlite3SrcListFuncArgs(pParse, yymsp[-8].minor.yy131, yymsp[-4].minor.yy322); 167467 sqlite3SrcListFuncArgs(pParse, yymsp[-7].minor.yy131, yymsp[-3].minor.yy322);
165371} 167468}
165372 break; 167469 break;
165373 case 111: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */ 167470 case 112: /* seltablist ::= stl_prefix LP select RP as on_using */
165374{ 167471{
165375 yymsp[-6].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy131,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy47,yymsp[-1].minor.yy528,yymsp[0].minor.yy254); 167472 yymsp[-5].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-5].minor.yy131,0,0,&yymsp[-1].minor.yy0,yymsp[-3].minor.yy47,&yymsp[0].minor.yy561);
165376 } 167473 }
165377 break; 167474 break;
165378 case 112: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */ 167475 case 113: /* seltablist ::= stl_prefix LP seltablist RP as on_using */
165379{ 167476{
165380 if( yymsp[-6].minor.yy131==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy528==0 && yymsp[0].minor.yy254==0 ){ 167477 if( yymsp[-5].minor.yy131==0 && yymsp[-1].minor.yy0.n==0 && yymsp[0].minor.yy561.pOn==0 && yymsp[0].minor.yy561.pUsing==0 ){
165381 yymsp[-6].minor.yy131 = yymsp[-4].minor.yy131; 167478 yymsp[-5].minor.yy131 = yymsp[-3].minor.yy131;
165382 }else if( yymsp[-4].minor.yy131->nSrc==1 ){ 167479 }else if( yymsp[-3].minor.yy131->nSrc==1 ){
165383 yymsp[-6].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy131,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy528,yymsp[0].minor.yy254); 167480 yymsp[-5].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-5].minor.yy131,0,0,&yymsp[-1].minor.yy0,0,&yymsp[0].minor.yy561);
165384 if( yymsp[-6].minor.yy131 ){ 167481 if( yymsp[-5].minor.yy131 ){
165385 SrcItem *pNew = &yymsp[-6].minor.yy131->a[yymsp[-6].minor.yy131->nSrc-1]; 167482 SrcItem *pNew = &yymsp[-5].minor.yy131->a[yymsp[-5].minor.yy131->nSrc-1];
165386 SrcItem *pOld = yymsp[-4].minor.yy131->a; 167483 SrcItem *pOld = yymsp[-3].minor.yy131->a;
165387 pNew->zName = pOld->zName; 167484 pNew->zName = pOld->zName;
165388 pNew->zDatabase = pOld->zDatabase; 167485 pNew->zDatabase = pOld->zDatabase;
165389 pNew->pSelect = pOld->pSelect; 167486 pNew->pSelect = pOld->pSelect;
167487 if( pNew->pSelect && (pNew->pSelect->selFlags & SF_NestedFrom)!=0 ){
167488 pNew->fg.isNestedFrom = 1;
167489 }
165390 if( pOld->fg.isTabFunc ){ 167490 if( pOld->fg.isTabFunc ){
165391 pNew->u1.pFuncArg = pOld->u1.pFuncArg; 167491 pNew->u1.pFuncArg = pOld->u1.pFuncArg;
165392 pOld->u1.pFuncArg = 0; 167492 pOld->u1.pFuncArg = 0;
@@ -165396,94 +167496,78 @@ static YYACTIONTYPE yy_reduce(
165396 pOld->zName = pOld->zDatabase = 0; 167496 pOld->zName = pOld->zDatabase = 0;
165397 pOld->pSelect = 0; 167497 pOld->pSelect = 0;
165398 } 167498 }
165399 sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy131); 167499 sqlite3SrcListDelete(pParse->db, yymsp[-3].minor.yy131);
165400 }else{ 167500 }else{
165401 Select *pSubquery; 167501 Select *pSubquery;
165402 sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy131); 167502 sqlite3SrcListShiftJoinType(pParse,yymsp[-3].minor.yy131);
165403 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy131,0,0,0,0,SF_NestedFrom,0); 167503 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-3].minor.yy131,0,0,0,0,SF_NestedFrom,0);
165404 yymsp[-6].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy131,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy528,yymsp[0].minor.yy254); 167504 yymsp[-5].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-5].minor.yy131,0,0,&yymsp[-1].minor.yy0,pSubquery,&yymsp[0].minor.yy561);
165405 } 167505 }
165406 } 167506 }
165407 break; 167507 break;
165408 case 113: /* dbnm ::= */ 167508 case 114: /* dbnm ::= */
165409 case 127: /* indexed_opt ::= */ yytestcase(yyruleno==127); 167509 case 129: /* indexed_opt ::= */ yytestcase(yyruleno==129);
165410{yymsp[1].minor.yy0.z=0; yymsp[1].minor.yy0.n=0;} 167510{yymsp[1].minor.yy0.z=0; yymsp[1].minor.yy0.n=0;}
165411 break; 167511 break;
165412 case 115: /* fullname ::= nm */ 167512 case 116: /* fullname ::= nm */
165413{ 167513{
165414 yylhsminor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0); 167514 yylhsminor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0);
165415 if( IN_RENAME_OBJECT && yylhsminor.yy131 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy131->a[0].zName, &yymsp[0].minor.yy0); 167515 if( IN_RENAME_OBJECT && yylhsminor.yy131 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy131->a[0].zName, &yymsp[0].minor.yy0);
165416} 167516}
165417 yymsp[0].minor.yy131 = yylhsminor.yy131; 167517 yymsp[0].minor.yy131 = yylhsminor.yy131;
165418 break; 167518 break;
165419 case 116: /* fullname ::= nm DOT nm */ 167519 case 117: /* fullname ::= nm DOT nm */
165420{ 167520{
165421 yylhsminor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); 167521 yylhsminor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
165422 if( IN_RENAME_OBJECT && yylhsminor.yy131 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy131->a[0].zName, &yymsp[0].minor.yy0); 167522 if( IN_RENAME_OBJECT && yylhsminor.yy131 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy131->a[0].zName, &yymsp[0].minor.yy0);
165423} 167523}
165424 yymsp[-2].minor.yy131 = yylhsminor.yy131; 167524 yymsp[-2].minor.yy131 = yylhsminor.yy131;
165425 break; 167525 break;
165426 case 117: /* xfullname ::= nm */ 167526 case 118: /* xfullname ::= nm */
165427{yymsp[0].minor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0); /*A-overwrites-X*/} 167527{yymsp[0].minor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0); /*A-overwrites-X*/}
165428 break; 167528 break;
165429 case 118: /* xfullname ::= nm DOT nm */ 167529 case 119: /* xfullname ::= nm DOT nm */
165430{yymsp[-2].minor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/} 167530{yymsp[-2].minor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/}
165431 break; 167531 break;
165432 case 119: /* xfullname ::= nm DOT nm AS nm */ 167532 case 120: /* xfullname ::= nm DOT nm AS nm */
165433{ 167533{
165434 yymsp[-4].minor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,&yymsp[-2].minor.yy0); /*A-overwrites-X*/ 167534 yymsp[-4].minor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,&yymsp[-2].minor.yy0); /*A-overwrites-X*/
165435 if( yymsp[-4].minor.yy131 ) yymsp[-4].minor.yy131->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0); 167535 if( yymsp[-4].minor.yy131 ) yymsp[-4].minor.yy131->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0);
165436} 167536}
165437 break; 167537 break;
165438 case 120: /* xfullname ::= nm AS nm */ 167538 case 121: /* xfullname ::= nm AS nm */
165439{ 167539{
165440 yymsp[-2].minor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,0); /*A-overwrites-X*/ 167540 yymsp[-2].minor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,0); /*A-overwrites-X*/
165441 if( yymsp[-2].minor.yy131 ) yymsp[-2].minor.yy131->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0); 167541 if( yymsp[-2].minor.yy131 ) yymsp[-2].minor.yy131->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0);
165442} 167542}
165443 break; 167543 break;
165444 case 121: /* joinop ::= COMMA|JOIN */ 167544 case 122: /* joinop ::= COMMA|JOIN */
165445{ yymsp[0].minor.yy394 = JT_INNER; } 167545{ yymsp[0].minor.yy394 = JT_INNER; }
165446 break; 167546 break;
165447 case 122: /* joinop ::= JOIN_KW JOIN */ 167547 case 123: /* joinop ::= JOIN_KW JOIN */
165448{yymsp[-1].minor.yy394 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/} 167548{yymsp[-1].minor.yy394 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/}
165449 break; 167549 break;
165450 case 123: /* joinop ::= JOIN_KW nm JOIN */ 167550 case 124: /* joinop ::= JOIN_KW nm JOIN */
165451{yymsp[-2].minor.yy394 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/} 167551{yymsp[-2].minor.yy394 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/}
165452 break; 167552 break;
165453 case 124: /* joinop ::= JOIN_KW nm nm JOIN */ 167553 case 125: /* joinop ::= JOIN_KW nm nm JOIN */
165454{yymsp[-3].minor.yy394 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/} 167554{yymsp[-3].minor.yy394 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/}
165455 break; 167555 break;
165456 case 125: /* on_opt ::= ON expr */ 167556 case 126: /* on_using ::= ON expr */
165457 case 145: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==145); 167557{yymsp[-1].minor.yy561.pOn = yymsp[0].minor.yy528; yymsp[-1].minor.yy561.pUsing = 0;}
165458 case 152: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==152);
165459 case 154: /* where_opt_ret ::= WHERE expr */ yytestcase(yyruleno==154);
165460 case 226: /* case_else ::= ELSE expr */ yytestcase(yyruleno==226);
165461 case 247: /* vinto ::= INTO expr */ yytestcase(yyruleno==247);
165462{yymsp[-1].minor.yy528 = yymsp[0].minor.yy528;}
165463 break; 167558 break;
165464 case 126: /* on_opt ::= */ 167559 case 127: /* on_using ::= USING LP idlist RP */
165465 case 144: /* having_opt ::= */ yytestcase(yyruleno==144); 167560{yymsp[-3].minor.yy561.pOn = 0; yymsp[-3].minor.yy561.pUsing = yymsp[-1].minor.yy254;}
165466 case 146: /* limit_opt ::= */ yytestcase(yyruleno==146); 167561 break;
165467 case 151: /* where_opt ::= */ yytestcase(yyruleno==151); 167562 case 128: /* on_using ::= */
165468 case 153: /* where_opt_ret ::= */ yytestcase(yyruleno==153); 167563{yymsp[1].minor.yy561.pOn = 0; yymsp[1].minor.yy561.pUsing = 0;}
165469 case 227: /* case_else ::= */ yytestcase(yyruleno==227);
165470 case 229: /* case_operand ::= */ yytestcase(yyruleno==229);
165471 case 248: /* vinto ::= */ yytestcase(yyruleno==248);
165472{yymsp[1].minor.yy528 = 0;}
165473 break; 167564 break;
165474 case 128: /* indexed_opt ::= INDEXED BY nm */ 167565 case 130: /* indexed_by ::= INDEXED BY nm */
165475{yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;} 167566{yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;}
165476 break; 167567 break;
165477 case 129: /* indexed_opt ::= NOT INDEXED */ 167568 case 131: /* indexed_by ::= NOT INDEXED */
165478{yymsp[-1].minor.yy0.z=0; yymsp[-1].minor.yy0.n=1;} 167569{yymsp[-1].minor.yy0.z=0; yymsp[-1].minor.yy0.n=1;}
165479 break; 167570 break;
165480 case 130: /* using_opt ::= USING LP idlist RP */
165481{yymsp[-3].minor.yy254 = yymsp[-1].minor.yy254;}
165482 break;
165483 case 131: /* using_opt ::= */
165484 case 173: /* idlist_opt ::= */ yytestcase(yyruleno==173);
165485{yymsp[1].minor.yy254 = 0;}
165486 break;
165487 case 133: /* orderby_opt ::= ORDER BY sortlist */ 167571 case 133: /* orderby_opt ::= ORDER BY sortlist */
165488 case 143: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==143); 167572 case 143: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==143);
165489{yymsp[-2].minor.yy322 = yymsp[0].minor.yy322;} 167573{yymsp[-2].minor.yy322 = yymsp[0].minor.yy322;}
@@ -165516,6 +167600,22 @@ static YYACTIONTYPE yy_reduce(
165516 case 140: /* nulls ::= NULLS LAST */ 167600 case 140: /* nulls ::= NULLS LAST */
165517{yymsp[-1].minor.yy394 = SQLITE_SO_DESC;} 167601{yymsp[-1].minor.yy394 = SQLITE_SO_DESC;}
165518 break; 167602 break;
167603 case 144: /* having_opt ::= */
167604 case 146: /* limit_opt ::= */ yytestcase(yyruleno==146);
167605 case 151: /* where_opt ::= */ yytestcase(yyruleno==151);
167606 case 153: /* where_opt_ret ::= */ yytestcase(yyruleno==153);
167607 case 229: /* case_else ::= */ yytestcase(yyruleno==229);
167608 case 231: /* case_operand ::= */ yytestcase(yyruleno==231);
167609 case 250: /* vinto ::= */ yytestcase(yyruleno==250);
167610{yymsp[1].minor.yy528 = 0;}
167611 break;
167612 case 145: /* having_opt ::= HAVING expr */
167613 case 152: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==152);
167614 case 154: /* where_opt_ret ::= WHERE expr */ yytestcase(yyruleno==154);
167615 case 228: /* case_else ::= ELSE expr */ yytestcase(yyruleno==228);
167616 case 249: /* vinto ::= INTO expr */ yytestcase(yyruleno==249);
167617{yymsp[-1].minor.yy528 = yymsp[0].minor.yy528;}
167618 break;
165519 case 147: /* limit_opt ::= LIMIT expr */ 167619 case 147: /* limit_opt ::= LIMIT expr */
165520{yymsp[-1].minor.yy528 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy528,0);} 167620{yymsp[-1].minor.yy528 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy528,0);}
165521 break; 167621 break;
@@ -165541,7 +167641,18 @@ static YYACTIONTYPE yy_reduce(
165541{ 167641{
165542 sqlite3SrcListIndexedBy(pParse, yymsp[-5].minor.yy131, &yymsp[-4].minor.yy0); 167642 sqlite3SrcListIndexedBy(pParse, yymsp[-5].minor.yy131, &yymsp[-4].minor.yy0);
165543 sqlite3ExprListCheckLength(pParse,yymsp[-2].minor.yy322,"set list"); 167643 sqlite3ExprListCheckLength(pParse,yymsp[-2].minor.yy322,"set list");
165544 yymsp[-5].minor.yy131 = sqlite3SrcListAppendList(pParse, yymsp[-5].minor.yy131, yymsp[-1].minor.yy131); 167644 if( yymsp[-1].minor.yy131 ){
167645 SrcList *pFromClause = yymsp[-1].minor.yy131;
167646 if( pFromClause->nSrc>1 ){
167647 Select *pSubquery;
167648 Token as;
167649 pSubquery = sqlite3SelectNew(pParse,0,pFromClause,0,0,0,0,SF_NestedFrom,0);
167650 as.n = 0;
167651 as.z = 0;
167652 pFromClause = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&as,pSubquery,0);
167653 }
167654 yymsp[-5].minor.yy131 = sqlite3SrcListAppendList(pParse, yymsp[-5].minor.yy131, pFromClause);
167655 }
165545 sqlite3Update(pParse,yymsp[-5].minor.yy131,yymsp[-2].minor.yy322,yymsp[0].minor.yy528,yymsp[-6].minor.yy394,0,0,0); 167656 sqlite3Update(pParse,yymsp[-5].minor.yy131,yymsp[-2].minor.yy322,yymsp[0].minor.yy528,yymsp[-6].minor.yy394,0,0,0);
165546} 167657}
165547 break; 167658 break;
@@ -165599,6 +167710,9 @@ static YYACTIONTYPE yy_reduce(
165599 case 170: /* returning ::= RETURNING selcollist */ 167710 case 170: /* returning ::= RETURNING selcollist */
165600{sqlite3AddReturning(pParse,yymsp[0].minor.yy322);} 167711{sqlite3AddReturning(pParse,yymsp[0].minor.yy322);}
165601 break; 167712 break;
167713 case 173: /* idlist_opt ::= */
167714{yymsp[1].minor.yy254 = 0;}
167715 break;
165602 case 174: /* idlist_opt ::= LP idlist RP */ 167716 case 174: /* idlist_opt ::= LP idlist RP */
165603{yymsp[-2].minor.yy254 = yymsp[-1].minor.yy254;} 167717{yymsp[-2].minor.yy254 = yymsp[-1].minor.yy254;}
165604 break; 167718 break;
@@ -165784,17 +167898,29 @@ static YYACTIONTYPE yy_reduce(
165784 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy528, yymsp[-3].minor.yy528, TK_NOTNULL); 167898 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy528, yymsp[-3].minor.yy528, TK_NOTNULL);
165785} 167899}
165786 break; 167900 break;
165787 case 209: /* expr ::= NOT expr */ 167901 case 209: /* expr ::= expr IS NOT DISTINCT FROM expr */
165788 case 210: /* expr ::= BITNOT expr */ yytestcase(yyruleno==210); 167902{
167903 yymsp[-5].minor.yy528 = sqlite3PExpr(pParse,TK_IS,yymsp[-5].minor.yy528,yymsp[0].minor.yy528);
167904 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy528, yymsp[-5].minor.yy528, TK_ISNULL);
167905}
167906 break;
167907 case 210: /* expr ::= expr IS DISTINCT FROM expr */
167908{
167909 yymsp[-4].minor.yy528 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-4].minor.yy528,yymsp[0].minor.yy528);
167910 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy528, yymsp[-4].minor.yy528, TK_NOTNULL);
167911}
167912 break;
167913 case 211: /* expr ::= NOT expr */
167914 case 212: /* expr ::= BITNOT expr */ yytestcase(yyruleno==212);
165789{yymsp[-1].minor.yy528 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy528, 0);/*A-overwrites-B*/} 167915{yymsp[-1].minor.yy528 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy528, 0);/*A-overwrites-B*/}
165790 break; 167916 break;
165791 case 211: /* expr ::= PLUS|MINUS expr */ 167917 case 213: /* expr ::= PLUS|MINUS expr */
165792{ 167918{
165793 yymsp[-1].minor.yy528 = sqlite3PExpr(pParse, yymsp[-1].major==TK_PLUS ? TK_UPLUS : TK_UMINUS, yymsp[0].minor.yy528, 0); 167919 yymsp[-1].minor.yy528 = sqlite3PExpr(pParse, yymsp[-1].major==TK_PLUS ? TK_UPLUS : TK_UMINUS, yymsp[0].minor.yy528, 0);
165794 /*A-overwrites-B*/ 167920 /*A-overwrites-B*/
165795} 167921}
165796 break; 167922 break;
165797 case 212: /* expr ::= expr PTR expr */ 167923 case 214: /* expr ::= expr PTR expr */
165798{ 167924{
165799 ExprList *pList = sqlite3ExprListAppend(pParse, 0, yymsp[-2].minor.yy528); 167925 ExprList *pList = sqlite3ExprListAppend(pParse, 0, yymsp[-2].minor.yy528);
165800 pList = sqlite3ExprListAppend(pParse, pList, yymsp[0].minor.yy528); 167926 pList = sqlite3ExprListAppend(pParse, pList, yymsp[0].minor.yy528);
@@ -165802,11 +167928,11 @@ static YYACTIONTYPE yy_reduce(
165802} 167928}
165803 yymsp[-2].minor.yy528 = yylhsminor.yy528; 167929 yymsp[-2].minor.yy528 = yylhsminor.yy528;
165804 break; 167930 break;
165805 case 213: /* between_op ::= BETWEEN */ 167931 case 215: /* between_op ::= BETWEEN */
165806 case 216: /* in_op ::= IN */ yytestcase(yyruleno==216); 167932 case 218: /* in_op ::= IN */ yytestcase(yyruleno==218);
165807{yymsp[0].minor.yy394 = 0;} 167933{yymsp[0].minor.yy394 = 0;}
165808 break; 167934 break;
165809 case 215: /* expr ::= expr between_op expr AND expr */ 167935 case 217: /* expr ::= expr between_op expr AND expr */
165810{ 167936{
165811 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy528); 167937 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy528);
165812 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy528); 167938 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy528);
@@ -165819,7 +167945,7 @@ static YYACTIONTYPE yy_reduce(
165819 if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0); 167945 if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0);
165820} 167946}
165821 break; 167947 break;
165822 case 218: /* expr ::= expr in_op LP exprlist RP */ 167948 case 220: /* expr ::= expr in_op LP exprlist RP */
165823{ 167949{
165824 if( yymsp[-1].minor.yy322==0 ){ 167950 if( yymsp[-1].minor.yy322==0 ){
165825 /* Expressions of the form 167951 /* Expressions of the form
@@ -165831,7 +167957,8 @@ static YYACTIONTYPE yy_reduce(
165831 ** regardless of the value of expr1. 167957 ** regardless of the value of expr1.
165832 */ 167958 */
165833 sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy528); 167959 sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy528);
165834 yymsp[-4].minor.yy528 = sqlite3Expr(pParse->db, TK_INTEGER, yymsp[-3].minor.yy394 ? "1" : "0"); 167960 yymsp[-4].minor.yy528 = sqlite3Expr(pParse->db, TK_STRING, yymsp[-3].minor.yy394 ? "true" : "false");
167961 if( yymsp[-4].minor.yy528 ) sqlite3ExprIdToTrueFalse(yymsp[-4].minor.yy528);
165835 }else{ 167962 }else{
165836 Expr *pRHS = yymsp[-1].minor.yy322->a[0].pExpr; 167963 Expr *pRHS = yymsp[-1].minor.yy322->a[0].pExpr;
165837 if( yymsp[-1].minor.yy322->nExpr==1 && sqlite3ExprIsConstant(pRHS) && yymsp[-4].minor.yy528->op!=TK_VECTOR ){ 167964 if( yymsp[-1].minor.yy322->nExpr==1 && sqlite3ExprIsConstant(pRHS) && yymsp[-4].minor.yy528->op!=TK_VECTOR ){
@@ -165859,20 +167986,20 @@ static YYACTIONTYPE yy_reduce(
165859 } 167986 }
165860 } 167987 }
165861 break; 167988 break;
165862 case 219: /* expr ::= LP select RP */ 167989 case 221: /* expr ::= LP select RP */
165863{ 167990{
165864 yymsp[-2].minor.yy528 = sqlite3PExpr(pParse, TK_SELECT, 0, 0); 167991 yymsp[-2].minor.yy528 = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
165865 sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy528, yymsp[-1].minor.yy47); 167992 sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy528, yymsp[-1].minor.yy47);
165866 } 167993 }
165867 break; 167994 break;
165868 case 220: /* expr ::= expr in_op LP select RP */ 167995 case 222: /* expr ::= expr in_op LP select RP */
165869{ 167996{
165870 yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy528, 0); 167997 yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy528, 0);
165871 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy528, yymsp[-1].minor.yy47); 167998 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy528, yymsp[-1].minor.yy47);
165872 if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0); 167999 if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0);
165873 } 168000 }
165874 break; 168001 break;
165875 case 221: /* expr ::= expr in_op nm dbnm paren_exprlist */ 168002 case 223: /* expr ::= expr in_op nm dbnm paren_exprlist */
165876{ 168003{
165877 SrcList *pSrc = sqlite3SrcListAppend(pParse, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); 168004 SrcList *pSrc = sqlite3SrcListAppend(pParse, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
165878 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0); 168005 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
@@ -165882,14 +168009,14 @@ static YYACTIONTYPE yy_reduce(
165882 if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0); 168009 if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0);
165883 } 168010 }
165884 break; 168011 break;
165885 case 222: /* expr ::= EXISTS LP select RP */ 168012 case 224: /* expr ::= EXISTS LP select RP */
165886{ 168013{
165887 Expr *p; 168014 Expr *p;
165888 p = yymsp[-3].minor.yy528 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0); 168015 p = yymsp[-3].minor.yy528 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
165889 sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy47); 168016 sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy47);
165890 } 168017 }
165891 break; 168018 break;
165892 case 223: /* expr ::= CASE case_operand case_exprlist case_else END */ 168019 case 225: /* expr ::= CASE case_operand case_exprlist case_else END */
165893{ 168020{
165894 yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy528, 0); 168021 yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy528, 0);
165895 if( yymsp[-4].minor.yy528 ){ 168022 if( yymsp[-4].minor.yy528 ){
@@ -165901,32 +168028,32 @@ static YYACTIONTYPE yy_reduce(
165901 } 168028 }
165902} 168029}
165903 break; 168030 break;
165904 case 224: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */ 168031 case 226: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
165905{ 168032{
165906 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[-2].minor.yy528); 168033 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[-2].minor.yy528);
165907 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[0].minor.yy528); 168034 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[0].minor.yy528);
165908} 168035}
165909 break; 168036 break;
165910 case 225: /* case_exprlist ::= WHEN expr THEN expr */ 168037 case 227: /* case_exprlist ::= WHEN expr THEN expr */
165911{ 168038{
165912 yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy528); 168039 yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy528);
165913 yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, yymsp[0].minor.yy528); 168040 yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, yymsp[0].minor.yy528);
165914} 168041}
165915 break; 168042 break;
165916 case 228: /* case_operand ::= expr */ 168043 case 230: /* case_operand ::= expr */
165917{yymsp[0].minor.yy528 = yymsp[0].minor.yy528; /*A-overwrites-X*/} 168044{yymsp[0].minor.yy528 = yymsp[0].minor.yy528; /*A-overwrites-X*/}
165918 break; 168045 break;
165919 case 231: /* nexprlist ::= nexprlist COMMA expr */ 168046 case 233: /* nexprlist ::= nexprlist COMMA expr */
165920{yymsp[-2].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy528);} 168047{yymsp[-2].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy528);}
165921 break; 168048 break;
165922 case 232: /* nexprlist ::= expr */ 168049 case 234: /* nexprlist ::= expr */
165923{yymsp[0].minor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy528); /*A-overwrites-Y*/} 168050{yymsp[0].minor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy528); /*A-overwrites-Y*/}
165924 break; 168051 break;
165925 case 234: /* paren_exprlist ::= LP exprlist RP */ 168052 case 236: /* paren_exprlist ::= LP exprlist RP */
165926 case 239: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==239); 168053 case 241: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==241);
165927{yymsp[-2].minor.yy322 = yymsp[-1].minor.yy322;} 168054{yymsp[-2].minor.yy322 = yymsp[-1].minor.yy322;}
165928 break; 168055 break;
165929 case 235: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */ 168056 case 237: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
165930{ 168057{
165931 sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, 168058 sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
165932 sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy322, yymsp[-10].minor.yy394, 168059 sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy322, yymsp[-10].minor.yy394,
@@ -165936,48 +168063,48 @@ static YYACTIONTYPE yy_reduce(
165936 } 168063 }
165937} 168064}
165938 break; 168065 break;
165939 case 236: /* uniqueflag ::= UNIQUE */ 168066 case 238: /* uniqueflag ::= UNIQUE */
165940 case 278: /* raisetype ::= ABORT */ yytestcase(yyruleno==278); 168067 case 280: /* raisetype ::= ABORT */ yytestcase(yyruleno==280);
165941{yymsp[0].minor.yy394 = OE_Abort;} 168068{yymsp[0].minor.yy394 = OE_Abort;}
165942 break; 168069 break;
165943 case 237: /* uniqueflag ::= */ 168070 case 239: /* uniqueflag ::= */
165944{yymsp[1].minor.yy394 = OE_None;} 168071{yymsp[1].minor.yy394 = OE_None;}
165945 break; 168072 break;
165946 case 240: /* eidlist ::= eidlist COMMA nm collate sortorder */ 168073 case 242: /* eidlist ::= eidlist COMMA nm collate sortorder */
165947{ 168074{
165948 yymsp[-4].minor.yy322 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy322, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394); 168075 yymsp[-4].minor.yy322 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy322, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394);
165949} 168076}
165950 break; 168077 break;
165951 case 241: /* eidlist ::= nm collate sortorder */ 168078 case 243: /* eidlist ::= nm collate sortorder */
165952{ 168079{
165953 yymsp[-2].minor.yy322 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394); /*A-overwrites-Y*/ 168080 yymsp[-2].minor.yy322 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394); /*A-overwrites-Y*/
165954} 168081}
165955 break; 168082 break;
165956 case 244: /* cmd ::= DROP INDEX ifexists fullname */ 168083 case 246: /* cmd ::= DROP INDEX ifexists fullname */
165957{sqlite3DropIndex(pParse, yymsp[0].minor.yy131, yymsp[-1].minor.yy394);} 168084{sqlite3DropIndex(pParse, yymsp[0].minor.yy131, yymsp[-1].minor.yy394);}
165958 break; 168085 break;
165959 case 245: /* cmd ::= VACUUM vinto */ 168086 case 247: /* cmd ::= VACUUM vinto */
165960{sqlite3Vacuum(pParse,0,yymsp[0].minor.yy528);} 168087{sqlite3Vacuum(pParse,0,yymsp[0].minor.yy528);}
165961 break; 168088 break;
165962 case 246: /* cmd ::= VACUUM nm vinto */ 168089 case 248: /* cmd ::= VACUUM nm vinto */
165963{sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy528);} 168090{sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy528);}
165964 break; 168091 break;
165965 case 249: /* cmd ::= PRAGMA nm dbnm */ 168092 case 251: /* cmd ::= PRAGMA nm dbnm */
165966{sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);} 168093{sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
165967 break; 168094 break;
165968 case 250: /* cmd ::= PRAGMA nm dbnm EQ nmnum */ 168095 case 252: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
165969{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);} 168096{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
165970 break; 168097 break;
165971 case 251: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */ 168098 case 253: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
165972{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);} 168099{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
165973 break; 168100 break;
165974 case 252: /* cmd ::= PRAGMA nm dbnm EQ minus_num */ 168101 case 254: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
165975{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);} 168102{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
165976 break; 168103 break;
165977 case 253: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */ 168104 case 255: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
165978{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);} 168105{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
165979 break; 168106 break;
165980 case 256: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */ 168107 case 258: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
165981{ 168108{
165982 Token all; 168109 Token all;
165983 all.z = yymsp[-3].minor.yy0.z; 168110 all.z = yymsp[-3].minor.yy0.z;
@@ -165985,50 +168112,50 @@ static YYACTIONTYPE yy_reduce(
165985 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy33, &all); 168112 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy33, &all);
165986} 168113}
165987 break; 168114 break;
165988 case 257: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ 168115 case 259: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
165989{ 168116{
165990 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy394, yymsp[-4].minor.yy180.a, yymsp[-4].minor.yy180.b, yymsp[-2].minor.yy131, yymsp[0].minor.yy528, yymsp[-10].minor.yy394, yymsp[-8].minor.yy394); 168117 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy394, yymsp[-4].minor.yy180.a, yymsp[-4].minor.yy180.b, yymsp[-2].minor.yy131, yymsp[0].minor.yy528, yymsp[-10].minor.yy394, yymsp[-8].minor.yy394);
165991 yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/ 168118 yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
165992} 168119}
165993 break; 168120 break;
165994 case 258: /* trigger_time ::= BEFORE|AFTER */ 168121 case 260: /* trigger_time ::= BEFORE|AFTER */
165995{ yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/ } 168122{ yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/ }
165996 break; 168123 break;
165997 case 259: /* trigger_time ::= INSTEAD OF */ 168124 case 261: /* trigger_time ::= INSTEAD OF */
165998{ yymsp[-1].minor.yy394 = TK_INSTEAD;} 168125{ yymsp[-1].minor.yy394 = TK_INSTEAD;}
165999 break; 168126 break;
166000 case 260: /* trigger_time ::= */ 168127 case 262: /* trigger_time ::= */
166001{ yymsp[1].minor.yy394 = TK_BEFORE; } 168128{ yymsp[1].minor.yy394 = TK_BEFORE; }
166002 break; 168129 break;
166003 case 261: /* trigger_event ::= DELETE|INSERT */ 168130 case 263: /* trigger_event ::= DELETE|INSERT */
166004 case 262: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==262); 168131 case 264: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==264);
166005{yymsp[0].minor.yy180.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy180.b = 0;} 168132{yymsp[0].minor.yy180.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy180.b = 0;}
166006 break; 168133 break;
166007 case 263: /* trigger_event ::= UPDATE OF idlist */ 168134 case 265: /* trigger_event ::= UPDATE OF idlist */
166008{yymsp[-2].minor.yy180.a = TK_UPDATE; yymsp[-2].minor.yy180.b = yymsp[0].minor.yy254;} 168135{yymsp[-2].minor.yy180.a = TK_UPDATE; yymsp[-2].minor.yy180.b = yymsp[0].minor.yy254;}
166009 break; 168136 break;
166010 case 264: /* when_clause ::= */ 168137 case 266: /* when_clause ::= */
166011 case 283: /* key_opt ::= */ yytestcase(yyruleno==283); 168138 case 285: /* key_opt ::= */ yytestcase(yyruleno==285);
166012{ yymsp[1].minor.yy528 = 0; } 168139{ yymsp[1].minor.yy528 = 0; }
166013 break; 168140 break;
166014 case 265: /* when_clause ::= WHEN expr */ 168141 case 267: /* when_clause ::= WHEN expr */
166015 case 284: /* key_opt ::= KEY expr */ yytestcase(yyruleno==284); 168142 case 286: /* key_opt ::= KEY expr */ yytestcase(yyruleno==286);
166016{ yymsp[-1].minor.yy528 = yymsp[0].minor.yy528; } 168143{ yymsp[-1].minor.yy528 = yymsp[0].minor.yy528; }
166017 break; 168144 break;
166018 case 266: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ 168145 case 268: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
166019{ 168146{
166020 assert( yymsp[-2].minor.yy33!=0 ); 168147 assert( yymsp[-2].minor.yy33!=0 );
166021 yymsp[-2].minor.yy33->pLast->pNext = yymsp[-1].minor.yy33; 168148 yymsp[-2].minor.yy33->pLast->pNext = yymsp[-1].minor.yy33;
166022 yymsp[-2].minor.yy33->pLast = yymsp[-1].minor.yy33; 168149 yymsp[-2].minor.yy33->pLast = yymsp[-1].minor.yy33;
166023} 168150}
166024 break; 168151 break;
166025 case 267: /* trigger_cmd_list ::= trigger_cmd SEMI */ 168152 case 269: /* trigger_cmd_list ::= trigger_cmd SEMI */
166026{ 168153{
166027 assert( yymsp[-1].minor.yy33!=0 ); 168154 assert( yymsp[-1].minor.yy33!=0 );
166028 yymsp[-1].minor.yy33->pLast = yymsp[-1].minor.yy33; 168155 yymsp[-1].minor.yy33->pLast = yymsp[-1].minor.yy33;
166029} 168156}
166030 break; 168157 break;
166031 case 268: /* trnm ::= nm DOT nm */ 168158 case 270: /* trnm ::= nm DOT nm */
166032{ 168159{
166033 yymsp[-2].minor.yy0 = yymsp[0].minor.yy0; 168160 yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
166034 sqlite3ErrorMsg(pParse, 168161 sqlite3ErrorMsg(pParse,
@@ -166036,39 +168163,39 @@ static YYACTIONTYPE yy_reduce(
166036 "statements within triggers"); 168163 "statements within triggers");
166037} 168164}
166038 break; 168165 break;
166039 case 269: /* tridxby ::= INDEXED BY nm */ 168166 case 271: /* tridxby ::= INDEXED BY nm */
166040{ 168167{
166041 sqlite3ErrorMsg(pParse, 168168 sqlite3ErrorMsg(pParse,
166042 "the INDEXED BY clause is not allowed on UPDATE or DELETE statements " 168169 "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
166043 "within triggers"); 168170 "within triggers");
166044} 168171}
166045 break; 168172 break;
166046 case 270: /* tridxby ::= NOT INDEXED */ 168173 case 272: /* tridxby ::= NOT INDEXED */
166047{ 168174{
166048 sqlite3ErrorMsg(pParse, 168175 sqlite3ErrorMsg(pParse,
166049 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements " 168176 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
166050 "within triggers"); 168177 "within triggers");
166051} 168178}
166052 break; 168179 break;
166053 case 271: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */ 168180 case 273: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
166054{yylhsminor.yy33 = sqlite3TriggerUpdateStep(pParse, &yymsp[-6].minor.yy0, yymsp[-2].minor.yy131, yymsp[-3].minor.yy322, yymsp[-1].minor.yy528, yymsp[-7].minor.yy394, yymsp[-8].minor.yy0.z, yymsp[0].minor.yy522);} 168181{yylhsminor.yy33 = sqlite3TriggerUpdateStep(pParse, &yymsp[-6].minor.yy0, yymsp[-2].minor.yy131, yymsp[-3].minor.yy322, yymsp[-1].minor.yy528, yymsp[-7].minor.yy394, yymsp[-8].minor.yy0.z, yymsp[0].minor.yy522);}
166055 yymsp[-8].minor.yy33 = yylhsminor.yy33; 168182 yymsp[-8].minor.yy33 = yylhsminor.yy33;
166056 break; 168183 break;
166057 case 272: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */ 168184 case 274: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
166058{ 168185{
166059 yylhsminor.yy33 = sqlite3TriggerInsertStep(pParse,&yymsp[-4].minor.yy0,yymsp[-3].minor.yy254,yymsp[-2].minor.yy47,yymsp[-6].minor.yy394,yymsp[-1].minor.yy444,yymsp[-7].minor.yy522,yymsp[0].minor.yy522);/*yylhsminor.yy33-overwrites-yymsp[-6].minor.yy394*/ 168186 yylhsminor.yy33 = sqlite3TriggerInsertStep(pParse,&yymsp[-4].minor.yy0,yymsp[-3].minor.yy254,yymsp[-2].minor.yy47,yymsp[-6].minor.yy394,yymsp[-1].minor.yy444,yymsp[-7].minor.yy522,yymsp[0].minor.yy522);/*yylhsminor.yy33-overwrites-yymsp[-6].minor.yy394*/
166060} 168187}
166061 yymsp[-7].minor.yy33 = yylhsminor.yy33; 168188 yymsp[-7].minor.yy33 = yylhsminor.yy33;
166062 break; 168189 break;
166063 case 273: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */ 168190 case 275: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
166064{yylhsminor.yy33 = sqlite3TriggerDeleteStep(pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy528, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy522);} 168191{yylhsminor.yy33 = sqlite3TriggerDeleteStep(pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy528, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy522);}
166065 yymsp[-5].minor.yy33 = yylhsminor.yy33; 168192 yymsp[-5].minor.yy33 = yylhsminor.yy33;
166066 break; 168193 break;
166067 case 274: /* trigger_cmd ::= scanpt select scanpt */ 168194 case 276: /* trigger_cmd ::= scanpt select scanpt */
166068{yylhsminor.yy33 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy47, yymsp[-2].minor.yy522, yymsp[0].minor.yy522); /*yylhsminor.yy33-overwrites-yymsp[-1].minor.yy47*/} 168195{yylhsminor.yy33 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy47, yymsp[-2].minor.yy522, yymsp[0].minor.yy522); /*yylhsminor.yy33-overwrites-yymsp[-1].minor.yy47*/}
166069 yymsp[-2].minor.yy33 = yylhsminor.yy33; 168196 yymsp[-2].minor.yy33 = yylhsminor.yy33;
166070 break; 168197 break;
166071 case 275: /* expr ::= RAISE LP IGNORE RP */ 168198 case 277: /* expr ::= RAISE LP IGNORE RP */
166072{ 168199{
166073 yymsp[-3].minor.yy528 = sqlite3PExpr(pParse, TK_RAISE, 0, 0); 168200 yymsp[-3].minor.yy528 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
166074 if( yymsp[-3].minor.yy528 ){ 168201 if( yymsp[-3].minor.yy528 ){
@@ -166076,7 +168203,7 @@ static YYACTIONTYPE yy_reduce(
166076 } 168203 }
166077} 168204}
166078 break; 168205 break;
166079 case 276: /* expr ::= RAISE LP raisetype COMMA nm RP */ 168206 case 278: /* expr ::= RAISE LP raisetype COMMA nm RP */
166080{ 168207{
166081 yymsp[-5].minor.yy528 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1); 168208 yymsp[-5].minor.yy528 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
166082 if( yymsp[-5].minor.yy528 ) { 168209 if( yymsp[-5].minor.yy528 ) {
@@ -166084,118 +168211,118 @@ static YYACTIONTYPE yy_reduce(
166084 } 168211 }
166085} 168212}
166086 break; 168213 break;
166087 case 277: /* raisetype ::= ROLLBACK */ 168214 case 279: /* raisetype ::= ROLLBACK */
166088{yymsp[0].minor.yy394 = OE_Rollback;} 168215{yymsp[0].minor.yy394 = OE_Rollback;}
166089 break; 168216 break;
166090 case 279: /* raisetype ::= FAIL */ 168217 case 281: /* raisetype ::= FAIL */
166091{yymsp[0].minor.yy394 = OE_Fail;} 168218{yymsp[0].minor.yy394 = OE_Fail;}
166092 break; 168219 break;
166093 case 280: /* cmd ::= DROP TRIGGER ifexists fullname */ 168220 case 282: /* cmd ::= DROP TRIGGER ifexists fullname */
166094{ 168221{
166095 sqlite3DropTrigger(pParse,yymsp[0].minor.yy131,yymsp[-1].minor.yy394); 168222 sqlite3DropTrigger(pParse,yymsp[0].minor.yy131,yymsp[-1].minor.yy394);
166096} 168223}
166097 break; 168224 break;
166098 case 281: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ 168225 case 283: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
166099{ 168226{
166100 sqlite3Attach(pParse, yymsp[-3].minor.yy528, yymsp[-1].minor.yy528, yymsp[0].minor.yy528); 168227 sqlite3Attach(pParse, yymsp[-3].minor.yy528, yymsp[-1].minor.yy528, yymsp[0].minor.yy528);
166101} 168228}
166102 break; 168229 break;
166103 case 282: /* cmd ::= DETACH database_kw_opt expr */ 168230 case 284: /* cmd ::= DETACH database_kw_opt expr */
166104{ 168231{
166105 sqlite3Detach(pParse, yymsp[0].minor.yy528); 168232 sqlite3Detach(pParse, yymsp[0].minor.yy528);
166106} 168233}
166107 break; 168234 break;
166108 case 285: /* cmd ::= REINDEX */ 168235 case 287: /* cmd ::= REINDEX */
166109{sqlite3Reindex(pParse, 0, 0);} 168236{sqlite3Reindex(pParse, 0, 0);}
166110 break; 168237 break;
166111 case 286: /* cmd ::= REINDEX nm dbnm */ 168238 case 288: /* cmd ::= REINDEX nm dbnm */
166112{sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);} 168239{sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
166113 break; 168240 break;
166114 case 287: /* cmd ::= ANALYZE */ 168241 case 289: /* cmd ::= ANALYZE */
166115{sqlite3Analyze(pParse, 0, 0);} 168242{sqlite3Analyze(pParse, 0, 0);}
166116 break; 168243 break;
166117 case 288: /* cmd ::= ANALYZE nm dbnm */ 168244 case 290: /* cmd ::= ANALYZE nm dbnm */
166118{sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);} 168245{sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
166119 break; 168246 break;
166120 case 289: /* cmd ::= ALTER TABLE fullname RENAME TO nm */ 168247 case 291: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
166121{ 168248{
166122 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy131,&yymsp[0].minor.yy0); 168249 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy131,&yymsp[0].minor.yy0);
166123} 168250}
166124 break; 168251 break;
166125 case 290: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */ 168252 case 292: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
166126{ 168253{
166127 yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n; 168254 yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
166128 sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0); 168255 sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0);
166129} 168256}
166130 break; 168257 break;
166131 case 291: /* cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */ 168258 case 293: /* cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
166132{ 168259{
166133 sqlite3AlterDropColumn(pParse, yymsp[-3].minor.yy131, &yymsp[0].minor.yy0); 168260 sqlite3AlterDropColumn(pParse, yymsp[-3].minor.yy131, &yymsp[0].minor.yy0);
166134} 168261}
166135 break; 168262 break;
166136 case 292: /* add_column_fullname ::= fullname */ 168263 case 294: /* add_column_fullname ::= fullname */
166137{ 168264{
166138 disableLookaside(pParse); 168265 disableLookaside(pParse);
166139 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy131); 168266 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy131);
166140} 168267}
166141 break; 168268 break;
166142 case 293: /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */ 168269 case 295: /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
166143{ 168270{
166144 sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy131, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); 168271 sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy131, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
166145} 168272}
166146 break; 168273 break;
166147 case 294: /* cmd ::= create_vtab */ 168274 case 296: /* cmd ::= create_vtab */
166148{sqlite3VtabFinishParse(pParse,0);} 168275{sqlite3VtabFinishParse(pParse,0);}
166149 break; 168276 break;
166150 case 295: /* cmd ::= create_vtab LP vtabarglist RP */ 168277 case 297: /* cmd ::= create_vtab LP vtabarglist RP */
166151{sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);} 168278{sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
166152 break; 168279 break;
166153 case 296: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */ 168280 case 298: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
166154{ 168281{
166155 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy394); 168282 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy394);
166156} 168283}
166157 break; 168284 break;
166158 case 297: /* vtabarg ::= */ 168285 case 299: /* vtabarg ::= */
166159{sqlite3VtabArgInit(pParse);} 168286{sqlite3VtabArgInit(pParse);}
166160 break; 168287 break;
166161 case 298: /* vtabargtoken ::= ANY */ 168288 case 300: /* vtabargtoken ::= ANY */
166162 case 299: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==299); 168289 case 301: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==301);
166163 case 300: /* lp ::= LP */ yytestcase(yyruleno==300); 168290 case 302: /* lp ::= LP */ yytestcase(yyruleno==302);
166164{sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);} 168291{sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
166165 break; 168292 break;
166166 case 301: /* with ::= WITH wqlist */ 168293 case 303: /* with ::= WITH wqlist */
166167 case 302: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==302); 168294 case 304: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==304);
166168{ sqlite3WithPush(pParse, yymsp[0].minor.yy521, 1); } 168295{ sqlite3WithPush(pParse, yymsp[0].minor.yy521, 1); }
166169 break; 168296 break;
166170 case 303: /* wqas ::= AS */ 168297 case 305: /* wqas ::= AS */
166171{yymsp[0].minor.yy516 = M10d_Any;} 168298{yymsp[0].minor.yy516 = M10d_Any;}
166172 break; 168299 break;
166173 case 304: /* wqas ::= AS MATERIALIZED */ 168300 case 306: /* wqas ::= AS MATERIALIZED */
166174{yymsp[-1].minor.yy516 = M10d_Yes;} 168301{yymsp[-1].minor.yy516 = M10d_Yes;}
166175 break; 168302 break;
166176 case 305: /* wqas ::= AS NOT MATERIALIZED */ 168303 case 307: /* wqas ::= AS NOT MATERIALIZED */
166177{yymsp[-2].minor.yy516 = M10d_No;} 168304{yymsp[-2].minor.yy516 = M10d_No;}
166178 break; 168305 break;
166179 case 306: /* wqitem ::= nm eidlist_opt wqas LP select RP */ 168306 case 308: /* wqitem ::= nm eidlist_opt wqas LP select RP */
166180{ 168307{
166181 yymsp[-5].minor.yy385 = sqlite3CteNew(pParse, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy322, yymsp[-1].minor.yy47, yymsp[-3].minor.yy516); /*A-overwrites-X*/ 168308 yymsp[-5].minor.yy385 = sqlite3CteNew(pParse, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy322, yymsp[-1].minor.yy47, yymsp[-3].minor.yy516); /*A-overwrites-X*/
166182} 168309}
166183 break; 168310 break;
166184 case 307: /* wqlist ::= wqitem */ 168311 case 309: /* wqlist ::= wqitem */
166185{ 168312{
166186 yymsp[0].minor.yy521 = sqlite3WithAdd(pParse, 0, yymsp[0].minor.yy385); /*A-overwrites-X*/ 168313 yymsp[0].minor.yy521 = sqlite3WithAdd(pParse, 0, yymsp[0].minor.yy385); /*A-overwrites-X*/
166187} 168314}
166188 break; 168315 break;
166189 case 308: /* wqlist ::= wqlist COMMA wqitem */ 168316 case 310: /* wqlist ::= wqlist COMMA wqitem */
166190{ 168317{
166191 yymsp[-2].minor.yy521 = sqlite3WithAdd(pParse, yymsp[-2].minor.yy521, yymsp[0].minor.yy385); 168318 yymsp[-2].minor.yy521 = sqlite3WithAdd(pParse, yymsp[-2].minor.yy521, yymsp[0].minor.yy385);
166192} 168319}
166193 break; 168320 break;
166194 case 309: /* windowdefn_list ::= windowdefn */ 168321 case 311: /* windowdefn_list ::= windowdefn */
166195{ yylhsminor.yy41 = yymsp[0].minor.yy41; } 168322{ yylhsminor.yy41 = yymsp[0].minor.yy41; }
166196 yymsp[0].minor.yy41 = yylhsminor.yy41; 168323 yymsp[0].minor.yy41 = yylhsminor.yy41;
166197 break; 168324 break;
166198 case 310: /* windowdefn_list ::= windowdefn_list COMMA windowdefn */ 168325 case 312: /* windowdefn_list ::= windowdefn_list COMMA windowdefn */
166199{ 168326{
166200 assert( yymsp[0].minor.yy41!=0 ); 168327 assert( yymsp[0].minor.yy41!=0 );
166201 sqlite3WindowChain(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy41); 168328 sqlite3WindowChain(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy41);
@@ -166204,7 +168331,7 @@ static YYACTIONTYPE yy_reduce(
166204} 168331}
166205 yymsp[-2].minor.yy41 = yylhsminor.yy41; 168332 yymsp[-2].minor.yy41 = yylhsminor.yy41;
166206 break; 168333 break;
166207 case 311: /* windowdefn ::= nm AS LP window RP */ 168334 case 313: /* windowdefn ::= nm AS LP window RP */
166208{ 168335{
166209 if( ALWAYS(yymsp[-1].minor.yy41) ){ 168336 if( ALWAYS(yymsp[-1].minor.yy41) ){
166210 yymsp[-1].minor.yy41->zName = sqlite3DbStrNDup(pParse->db, yymsp[-4].minor.yy0.z, yymsp[-4].minor.yy0.n); 168337 yymsp[-1].minor.yy41->zName = sqlite3DbStrNDup(pParse->db, yymsp[-4].minor.yy0.z, yymsp[-4].minor.yy0.n);
@@ -166213,90 +168340,90 @@ static YYACTIONTYPE yy_reduce(
166213} 168340}
166214 yymsp[-4].minor.yy41 = yylhsminor.yy41; 168341 yymsp[-4].minor.yy41 = yylhsminor.yy41;
166215 break; 168342 break;
166216 case 312: /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */ 168343 case 314: /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */
166217{ 168344{
166218 yymsp[-4].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, 0); 168345 yymsp[-4].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, 0);
166219} 168346}
166220 break; 168347 break;
166221 case 313: /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */ 168348 case 315: /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
166222{ 168349{
166223 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, &yymsp[-5].minor.yy0); 168350 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, &yymsp[-5].minor.yy0);
166224} 168351}
166225 yymsp[-5].minor.yy41 = yylhsminor.yy41; 168352 yymsp[-5].minor.yy41 = yylhsminor.yy41;
166226 break; 168353 break;
166227 case 314: /* window ::= ORDER BY sortlist frame_opt */ 168354 case 316: /* window ::= ORDER BY sortlist frame_opt */
166228{ 168355{
166229 yymsp[-3].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, 0); 168356 yymsp[-3].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, 0);
166230} 168357}
166231 break; 168358 break;
166232 case 315: /* window ::= nm ORDER BY sortlist frame_opt */ 168359 case 317: /* window ::= nm ORDER BY sortlist frame_opt */
166233{ 168360{
166234 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0); 168361 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0);
166235} 168362}
166236 yymsp[-4].minor.yy41 = yylhsminor.yy41; 168363 yymsp[-4].minor.yy41 = yylhsminor.yy41;
166237 break; 168364 break;
166238 case 316: /* window ::= frame_opt */ 168365 case 318: /* window ::= frame_opt */
166239 case 335: /* filter_over ::= over_clause */ yytestcase(yyruleno==335); 168366 case 337: /* filter_over ::= over_clause */ yytestcase(yyruleno==337);
166240{ 168367{
166241 yylhsminor.yy41 = yymsp[0].minor.yy41; 168368 yylhsminor.yy41 = yymsp[0].minor.yy41;
166242} 168369}
166243 yymsp[0].minor.yy41 = yylhsminor.yy41; 168370 yymsp[0].minor.yy41 = yylhsminor.yy41;
166244 break; 168371 break;
166245 case 317: /* window ::= nm frame_opt */ 168372 case 319: /* window ::= nm frame_opt */
166246{ 168373{
166247 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, 0, &yymsp[-1].minor.yy0); 168374 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, 0, &yymsp[-1].minor.yy0);
166248} 168375}
166249 yymsp[-1].minor.yy41 = yylhsminor.yy41; 168376 yymsp[-1].minor.yy41 = yylhsminor.yy41;
166250 break; 168377 break;
166251 case 318: /* frame_opt ::= */ 168378 case 320: /* frame_opt ::= */
166252{ 168379{
166253 yymsp[1].minor.yy41 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0); 168380 yymsp[1].minor.yy41 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0);
166254} 168381}
166255 break; 168382 break;
166256 case 319: /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */ 168383 case 321: /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
166257{ 168384{
166258 yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-2].minor.yy394, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy516); 168385 yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-2].minor.yy394, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy516);
166259} 168386}
166260 yymsp[-2].minor.yy41 = yylhsminor.yy41; 168387 yymsp[-2].minor.yy41 = yylhsminor.yy41;
166261 break; 168388 break;
166262 case 320: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */ 168389 case 322: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
166263{ 168390{
166264 yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-5].minor.yy394, yymsp[-3].minor.yy595.eType, yymsp[-3].minor.yy595.pExpr, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, yymsp[0].minor.yy516); 168391 yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-5].minor.yy394, yymsp[-3].minor.yy595.eType, yymsp[-3].minor.yy595.pExpr, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, yymsp[0].minor.yy516);
166265} 168392}
166266 yymsp[-5].minor.yy41 = yylhsminor.yy41; 168393 yymsp[-5].minor.yy41 = yylhsminor.yy41;
166267 break; 168394 break;
166268 case 322: /* frame_bound_s ::= frame_bound */ 168395 case 324: /* frame_bound_s ::= frame_bound */
166269 case 324: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==324); 168396 case 326: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==326);
166270{yylhsminor.yy595 = yymsp[0].minor.yy595;} 168397{yylhsminor.yy595 = yymsp[0].minor.yy595;}
166271 yymsp[0].minor.yy595 = yylhsminor.yy595; 168398 yymsp[0].minor.yy595 = yylhsminor.yy595;
166272 break; 168399 break;
166273 case 323: /* frame_bound_s ::= UNBOUNDED PRECEDING */ 168400 case 325: /* frame_bound_s ::= UNBOUNDED PRECEDING */
166274 case 325: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==325); 168401 case 327: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==327);
166275 case 327: /* frame_bound ::= CURRENT ROW */ yytestcase(yyruleno==327); 168402 case 329: /* frame_bound ::= CURRENT ROW */ yytestcase(yyruleno==329);
166276{yylhsminor.yy595.eType = yymsp[-1].major; yylhsminor.yy595.pExpr = 0;} 168403{yylhsminor.yy595.eType = yymsp[-1].major; yylhsminor.yy595.pExpr = 0;}
166277 yymsp[-1].minor.yy595 = yylhsminor.yy595; 168404 yymsp[-1].minor.yy595 = yylhsminor.yy595;
166278 break; 168405 break;
166279 case 326: /* frame_bound ::= expr PRECEDING|FOLLOWING */ 168406 case 328: /* frame_bound ::= expr PRECEDING|FOLLOWING */
166280{yylhsminor.yy595.eType = yymsp[0].major; yylhsminor.yy595.pExpr = yymsp[-1].minor.yy528;} 168407{yylhsminor.yy595.eType = yymsp[0].major; yylhsminor.yy595.pExpr = yymsp[-1].minor.yy528;}
166281 yymsp[-1].minor.yy595 = yylhsminor.yy595; 168408 yymsp[-1].minor.yy595 = yylhsminor.yy595;
166282 break; 168409 break;
166283 case 328: /* frame_exclude_opt ::= */ 168410 case 330: /* frame_exclude_opt ::= */
166284{yymsp[1].minor.yy516 = 0;} 168411{yymsp[1].minor.yy516 = 0;}
166285 break; 168412 break;
166286 case 329: /* frame_exclude_opt ::= EXCLUDE frame_exclude */ 168413 case 331: /* frame_exclude_opt ::= EXCLUDE frame_exclude */
166287{yymsp[-1].minor.yy516 = yymsp[0].minor.yy516;} 168414{yymsp[-1].minor.yy516 = yymsp[0].minor.yy516;}
166288 break; 168415 break;
166289 case 330: /* frame_exclude ::= NO OTHERS */ 168416 case 332: /* frame_exclude ::= NO OTHERS */
166290 case 331: /* frame_exclude ::= CURRENT ROW */ yytestcase(yyruleno==331); 168417 case 333: /* frame_exclude ::= CURRENT ROW */ yytestcase(yyruleno==333);
166291{yymsp[-1].minor.yy516 = yymsp[-1].major; /*A-overwrites-X*/} 168418{yymsp[-1].minor.yy516 = yymsp[-1].major; /*A-overwrites-X*/}
166292 break; 168419 break;
166293 case 332: /* frame_exclude ::= GROUP|TIES */ 168420 case 334: /* frame_exclude ::= GROUP|TIES */
166294{yymsp[0].minor.yy516 = yymsp[0].major; /*A-overwrites-X*/} 168421{yymsp[0].minor.yy516 = yymsp[0].major; /*A-overwrites-X*/}
166295 break; 168422 break;
166296 case 333: /* window_clause ::= WINDOW windowdefn_list */ 168423 case 335: /* window_clause ::= WINDOW windowdefn_list */
166297{ yymsp[-1].minor.yy41 = yymsp[0].minor.yy41; } 168424{ yymsp[-1].minor.yy41 = yymsp[0].minor.yy41; }
166298 break; 168425 break;
166299 case 334: /* filter_over ::= filter_clause over_clause */ 168426 case 336: /* filter_over ::= filter_clause over_clause */
166300{ 168427{
166301 if( yymsp[0].minor.yy41 ){ 168428 if( yymsp[0].minor.yy41 ){
166302 yymsp[0].minor.yy41->pFilter = yymsp[-1].minor.yy528; 168429 yymsp[0].minor.yy41->pFilter = yymsp[-1].minor.yy528;
@@ -166307,7 +168434,7 @@ static YYACTIONTYPE yy_reduce(
166307} 168434}
166308 yymsp[-1].minor.yy41 = yylhsminor.yy41; 168435 yymsp[-1].minor.yy41 = yylhsminor.yy41;
166309 break; 168436 break;
166310 case 336: /* filter_over ::= filter_clause */ 168437 case 338: /* filter_over ::= filter_clause */
166311{ 168438{
166312 yylhsminor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window)); 168439 yylhsminor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
166313 if( yylhsminor.yy41 ){ 168440 if( yylhsminor.yy41 ){
@@ -166319,13 +168446,13 @@ static YYACTIONTYPE yy_reduce(
166319} 168446}
166320 yymsp[0].minor.yy41 = yylhsminor.yy41; 168447 yymsp[0].minor.yy41 = yylhsminor.yy41;
166321 break; 168448 break;
166322 case 337: /* over_clause ::= OVER LP window RP */ 168449 case 339: /* over_clause ::= OVER LP window RP */
166323{ 168450{
166324 yymsp[-3].minor.yy41 = yymsp[-1].minor.yy41; 168451 yymsp[-3].minor.yy41 = yymsp[-1].minor.yy41;
166325 assert( yymsp[-3].minor.yy41!=0 ); 168452 assert( yymsp[-3].minor.yy41!=0 );
166326} 168453}
166327 break; 168454 break;
166328 case 338: /* over_clause ::= OVER nm */ 168455 case 340: /* over_clause ::= OVER nm */
166329{ 168456{
166330 yymsp[-1].minor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window)); 168457 yymsp[-1].minor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
166331 if( yymsp[-1].minor.yy41 ){ 168458 if( yymsp[-1].minor.yy41 ){
@@ -166333,72 +168460,73 @@ static YYACTIONTYPE yy_reduce(
166333 } 168460 }
166334} 168461}
166335 break; 168462 break;
166336 case 339: /* filter_clause ::= FILTER LP WHERE expr RP */ 168463 case 341: /* filter_clause ::= FILTER LP WHERE expr RP */
166337{ yymsp[-4].minor.yy528 = yymsp[-1].minor.yy528; } 168464{ yymsp[-4].minor.yy528 = yymsp[-1].minor.yy528; }
166338 break; 168465 break;
166339 default: 168466 default:
166340 /* (340) input ::= cmdlist */ yytestcase(yyruleno==340); 168467 /* (342) input ::= cmdlist */ yytestcase(yyruleno==342);
166341 /* (341) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==341); 168468 /* (343) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==343);
166342 /* (342) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=342); 168469 /* (344) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=344);
166343 /* (343) ecmd ::= SEMI */ yytestcase(yyruleno==343); 168470 /* (345) ecmd ::= SEMI */ yytestcase(yyruleno==345);
166344 /* (344) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==344); 168471 /* (346) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==346);
166345 /* (345) ecmd ::= explain cmdx SEMI (NEVER REDUCES) */ assert(yyruleno!=345); 168472 /* (347) ecmd ::= explain cmdx SEMI (NEVER REDUCES) */ assert(yyruleno!=347);
166346 /* (346) trans_opt ::= */ yytestcase(yyruleno==346); 168473 /* (348) trans_opt ::= */ yytestcase(yyruleno==348);
166347 /* (347) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==347); 168474 /* (349) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==349);
166348 /* (348) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==348); 168475 /* (350) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==350);
166349 /* (349) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==349); 168476 /* (351) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==351);
166350 /* (350) savepoint_opt ::= */ yytestcase(yyruleno==350); 168477 /* (352) savepoint_opt ::= */ yytestcase(yyruleno==352);
166351 /* (351) cmd ::= create_table create_table_args */ yytestcase(yyruleno==351); 168478 /* (353) cmd ::= create_table create_table_args */ yytestcase(yyruleno==353);
166352 /* (352) table_option_set ::= table_option (OPTIMIZED OUT) */ assert(yyruleno!=352); 168479 /* (354) table_option_set ::= table_option (OPTIMIZED OUT) */ assert(yyruleno!=354);
166353 /* (353) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==353); 168480 /* (355) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==355);
166354 /* (354) columnlist ::= columnname carglist */ yytestcase(yyruleno==354); 168481 /* (356) columnlist ::= columnname carglist */ yytestcase(yyruleno==356);
166355 /* (355) nm ::= ID|INDEXED */ yytestcase(yyruleno==355); 168482 /* (357) nm ::= ID|INDEXED */ yytestcase(yyruleno==357);
166356 /* (356) nm ::= STRING */ yytestcase(yyruleno==356); 168483 /* (358) nm ::= STRING */ yytestcase(yyruleno==358);
166357 /* (357) nm ::= JOIN_KW */ yytestcase(yyruleno==357); 168484 /* (359) nm ::= JOIN_KW */ yytestcase(yyruleno==359);
166358 /* (358) typetoken ::= typename */ yytestcase(yyruleno==358); 168485 /* (360) typetoken ::= typename */ yytestcase(yyruleno==360);
166359 /* (359) typename ::= ID|STRING */ yytestcase(yyruleno==359); 168486 /* (361) typename ::= ID|STRING */ yytestcase(yyruleno==361);
166360 /* (360) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=360); 168487 /* (362) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=362);
166361 /* (361) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=361); 168488 /* (363) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=363);
166362 /* (362) carglist ::= carglist ccons */ yytestcase(yyruleno==362); 168489 /* (364) carglist ::= carglist ccons */ yytestcase(yyruleno==364);
166363 /* (363) carglist ::= */ yytestcase(yyruleno==363); 168490 /* (365) carglist ::= */ yytestcase(yyruleno==365);
166364 /* (364) ccons ::= NULL onconf */ yytestcase(yyruleno==364); 168491 /* (366) ccons ::= NULL onconf */ yytestcase(yyruleno==366);
166365 /* (365) ccons ::= GENERATED ALWAYS AS generated */ yytestcase(yyruleno==365); 168492 /* (367) ccons ::= GENERATED ALWAYS AS generated */ yytestcase(yyruleno==367);
166366 /* (366) ccons ::= AS generated */ yytestcase(yyruleno==366); 168493 /* (368) ccons ::= AS generated */ yytestcase(yyruleno==368);
166367 /* (367) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==367); 168494 /* (369) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==369);
166368 /* (368) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==368); 168495 /* (370) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==370);
166369 /* (369) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=369); 168496 /* (371) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=371);
166370 /* (370) tconscomma ::= */ yytestcase(yyruleno==370); 168497 /* (372) tconscomma ::= */ yytestcase(yyruleno==372);
166371 /* (371) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=371); 168498 /* (373) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=373);
166372 /* (372) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=372); 168499 /* (374) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=374);
166373 /* (373) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=373); 168500 /* (375) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=375);
166374 /* (374) oneselect ::= values */ yytestcase(yyruleno==374); 168501 /* (376) oneselect ::= values */ yytestcase(yyruleno==376);
166375 /* (375) sclp ::= selcollist COMMA */ yytestcase(yyruleno==375); 168502 /* (377) sclp ::= selcollist COMMA */ yytestcase(yyruleno==377);
166376 /* (376) as ::= ID|STRING */ yytestcase(yyruleno==376); 168503 /* (378) as ::= ID|STRING */ yytestcase(yyruleno==378);
166377 /* (377) returning ::= */ yytestcase(yyruleno==377); 168504 /* (379) indexed_opt ::= indexed_by (OPTIMIZED OUT) */ assert(yyruleno!=379);
166378 /* (378) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=378); 168505 /* (380) returning ::= */ yytestcase(yyruleno==380);
166379 /* (379) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==379); 168506 /* (381) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=381);
166380 /* (380) exprlist ::= nexprlist */ yytestcase(yyruleno==380); 168507 /* (382) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==382);
166381 /* (381) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=381); 168508 /* (383) exprlist ::= nexprlist */ yytestcase(yyruleno==383);
166382 /* (382) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=382); 168509 /* (384) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=384);
166383 /* (383) nmnum ::= ON */ yytestcase(yyruleno==383); 168510 /* (385) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=385);
166384 /* (384) nmnum ::= DELETE */ yytestcase(yyruleno==384); 168511 /* (386) nmnum ::= ON */ yytestcase(yyruleno==386);
166385 /* (385) nmnum ::= DEFAULT */ yytestcase(yyruleno==385); 168512 /* (387) nmnum ::= DELETE */ yytestcase(yyruleno==387);
166386 /* (386) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==386); 168513 /* (388) nmnum ::= DEFAULT */ yytestcase(yyruleno==388);
166387 /* (387) foreach_clause ::= */ yytestcase(yyruleno==387); 168514 /* (389) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==389);
166388 /* (388) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==388); 168515 /* (390) foreach_clause ::= */ yytestcase(yyruleno==390);
166389 /* (389) trnm ::= nm */ yytestcase(yyruleno==389); 168516 /* (391) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==391);
166390 /* (390) tridxby ::= */ yytestcase(yyruleno==390); 168517 /* (392) trnm ::= nm */ yytestcase(yyruleno==392);
166391 /* (391) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==391); 168518 /* (393) tridxby ::= */ yytestcase(yyruleno==393);
166392 /* (392) database_kw_opt ::= */ yytestcase(yyruleno==392); 168519 /* (394) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==394);
166393 /* (393) kwcolumn_opt ::= */ yytestcase(yyruleno==393); 168520 /* (395) database_kw_opt ::= */ yytestcase(yyruleno==395);
166394 /* (394) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==394); 168521 /* (396) kwcolumn_opt ::= */ yytestcase(yyruleno==396);
166395 /* (395) vtabarglist ::= vtabarg */ yytestcase(yyruleno==395); 168522 /* (397) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==397);
166396 /* (396) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==396); 168523 /* (398) vtabarglist ::= vtabarg */ yytestcase(yyruleno==398);
166397 /* (397) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==397); 168524 /* (399) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==399);
166398 /* (398) anylist ::= */ yytestcase(yyruleno==398); 168525 /* (400) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==400);
166399 /* (399) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==399); 168526 /* (401) anylist ::= */ yytestcase(yyruleno==401);
166400 /* (400) anylist ::= anylist ANY */ yytestcase(yyruleno==400); 168527 /* (402) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==402);
166401 /* (401) with ::= */ yytestcase(yyruleno==401); 168528 /* (403) anylist ::= anylist ANY */ yytestcase(yyruleno==403);
168529 /* (404) with ::= */ yytestcase(yyruleno==404);
166402 break; 168530 break;
166403/********** End reduce actions ************************************************/ 168531/********** End reduce actions ************************************************/
166404 }; 168532 };
@@ -167845,6 +169973,7 @@ SQLITE_PRIVATE int sqlite3RunParser(Parse *pParse, const char *zSql){
167845 mxSqlLen -= n; 169973 mxSqlLen -= n;
167846 if( mxSqlLen<0 ){ 169974 if( mxSqlLen<0 ){
167847 pParse->rc = SQLITE_TOOBIG; 169975 pParse->rc = SQLITE_TOOBIG;
169976 pParse->nErr++;
167848 break; 169977 break;
167849 } 169978 }
167850#ifndef SQLITE_OMIT_WINDOWFUNC 169979#ifndef SQLITE_OMIT_WINDOWFUNC
@@ -167941,7 +170070,7 @@ SQLITE_PRIVATE int sqlite3RunParser(Parse *pParse, const char *zSql){
167941 if( pParse->pNewTrigger && !IN_RENAME_OBJECT ){ 170070 if( pParse->pNewTrigger && !IN_RENAME_OBJECT ){
167942 sqlite3DeleteTrigger(db, pParse->pNewTrigger); 170071 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
167943 } 170072 }
167944 sqlite3DbFree(db, pParse->pVList); 170073 if( pParse->pVList ) sqlite3DbFreeNN(db, pParse->pVList);
167945 db->pParse = pParentParse; 170074 db->pParse = pParentParse;
167946 assert( nErr==0 || pParse->rc!=SQLITE_OK ); 170075 assert( nErr==0 || pParse->rc!=SQLITE_OK );
167947 return nErr; 170076 return nErr;
@@ -172570,6 +174699,28 @@ SQLITE_API int sqlite3_test_control(int op, ...){
172570 volatile int x = 0; 174699 volatile int x = 0;
172571 assert( /*side-effects-ok*/ (x = va_arg(ap,int))!=0 ); 174700 assert( /*side-effects-ok*/ (x = va_arg(ap,int))!=0 );
172572 rc = x; 174701 rc = x;
174702#if defined(SQLITE_DEBUG)
174703 /* Invoke these debugging routines so that the compiler does not
174704 ** issue "defined but not used" warnings. */
174705 if( x==9999 ){
174706 sqlite3ShowExpr(0);
174707 sqlite3ShowExpr(0);
174708 sqlite3ShowExprList(0);
174709 sqlite3ShowIdList(0);
174710 sqlite3ShowSrcList(0);
174711 sqlite3ShowWith(0);
174712 sqlite3ShowUpsert(0);
174713 sqlite3ShowTriggerStep(0);
174714 sqlite3ShowTriggerStepList(0);
174715 sqlite3ShowTrigger(0);
174716 sqlite3ShowTriggerList(0);
174717#ifndef SQLITE_OMIT_WINDOWFUNC
174718 sqlite3ShowWindow(0);
174719 sqlite3ShowWinFunc(0);
174720#endif
174721 sqlite3ShowSelect(0);
174722 }
174723#endif
172573 break; 174724 break;
172574 } 174725 }
172575 174726
@@ -172831,8 +174982,8 @@ SQLITE_API int sqlite3_test_control(int op, ...){
172831 ** 174982 **
172832 ** "ptr" is a pointer to a u32. 174983 ** "ptr" is a pointer to a u32.
172833 ** 174984 **
172834 ** op==0 Store the current sqlite3SelectTrace in *ptr 174985 ** op==0 Store the current sqlite3TreeTrace in *ptr
172835 ** op==1 Set sqlite3SelectTrace to the value *ptr 174986 ** op==1 Set sqlite3TreeTrace to the value *ptr
172836 ** op==3 Store the current sqlite3WhereTrace in *ptr 174987 ** op==3 Store the current sqlite3WhereTrace in *ptr
172837 ** op==3 Set sqlite3WhereTrace to the value *ptr 174988 ** op==3 Set sqlite3WhereTrace to the value *ptr
172838 */ 174989 */
@@ -172840,10 +174991,10 @@ SQLITE_API int sqlite3_test_control(int op, ...){
172840 int opTrace = va_arg(ap, int); 174991 int opTrace = va_arg(ap, int);
172841 u32 *ptr = va_arg(ap, u32*); 174992 u32 *ptr = va_arg(ap, u32*);
172842 switch( opTrace ){ 174993 switch( opTrace ){
172843 case 0: *ptr = sqlite3SelectTrace; break; 174994 case 0: *ptr = sqlite3TreeTrace; break;
172844 case 1: sqlite3SelectTrace = *ptr; break; 174995 case 1: sqlite3TreeTrace = *ptr; break;
172845 case 2: *ptr = sqlite3WhereTrace; break; 174996 case 2: *ptr = sqlite3WhereTrace; break;
172846 case 3: sqlite3WhereTrace = *ptr; break; 174997 case 3: sqlite3WhereTrace = *ptr; break;
172847 } 174998 }
172848 break; 174999 break;
172849 } 175000 }
@@ -172860,10 +175011,12 @@ SQLITE_API int sqlite3_test_control(int op, ...){
172860 case SQLITE_TESTCTRL_LOGEST: { 175011 case SQLITE_TESTCTRL_LOGEST: {
172861 double rIn = va_arg(ap, double); 175012 double rIn = va_arg(ap, double);
172862 LogEst rLogEst = sqlite3LogEstFromDouble(rIn); 175013 LogEst rLogEst = sqlite3LogEstFromDouble(rIn);
172863 u64 iInt = sqlite3LogEstToInt(rLogEst); 175014 int *pI1 = va_arg(ap,int*);
172864 va_arg(ap, int*)[0] = rLogEst; 175015 u64 *pU64 = va_arg(ap,u64*);
172865 va_arg(ap, u64*)[0] = iInt; 175016 int *pI2 = va_arg(ap,int*);
172866 va_arg(ap, int*)[0] = sqlite3LogEst(iInt); 175017 *pI1 = rLogEst;
175018 *pU64 = sqlite3LogEstToInt(rLogEst);
175019 *pI2 = sqlite3LogEst(*pU64);
172867 break; 175020 break;
172868 } 175021 }
172869 175022
@@ -173079,6 +175232,24 @@ SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
173079} 175232}
173080 175233
173081/* 175234/*
175235** Return the name of the N-th database schema. Return NULL if N is out
175236** of range.
175237*/
175238SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N){
175239#ifdef SQLITE_ENABLE_API_ARMOR
175240 if( !sqlite3SafetyCheckOk(db) ){
175241 (void)SQLITE_MISUSE_BKPT;
175242 return 0;
175243 }
175244#endif
175245 if( N<0 || N>=db->nDb ){
175246 return 0;
175247 }else{
175248 return db->aDb[N].zDbSName;
175249 }
175250}
175251
175252/*
173082** Return the filename of the database associated with a database 175253** Return the filename of the database associated with a database
173083** connection. 175254** connection.
173084*/ 175255*/
@@ -178881,8 +181052,7 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
178881 char *aPoslist = 0; /* Position list for deferred tokens */ 181052 char *aPoslist = 0; /* Position list for deferred tokens */
178882 int nPoslist = 0; /* Number of bytes in aPoslist */ 181053 int nPoslist = 0; /* Number of bytes in aPoslist */
178883 int iPrev = -1; /* Token number of previous deferred token */ 181054 int iPrev = -1; /* Token number of previous deferred token */
178884 181055 char *aFree = (pPhrase->doclist.bFreeList ? pPhrase->doclist.pList : 0);
178885 assert( pPhrase->doclist.bFreeList==0 );
178886 181056
178887 for(iToken=0; iToken<pPhrase->nToken; iToken++){ 181057 for(iToken=0; iToken<pPhrase->nToken; iToken++){
178888 Fts3PhraseToken *pToken = &pPhrase->aToken[iToken]; 181058 Fts3PhraseToken *pToken = &pPhrase->aToken[iToken];
@@ -178896,6 +181066,7 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
178896 181066
178897 if( pList==0 ){ 181067 if( pList==0 ){
178898 sqlite3_free(aPoslist); 181068 sqlite3_free(aPoslist);
181069 sqlite3_free(aFree);
178899 pPhrase->doclist.pList = 0; 181070 pPhrase->doclist.pList = 0;
178900 pPhrase->doclist.nList = 0; 181071 pPhrase->doclist.nList = 0;
178901 return SQLITE_OK; 181072 return SQLITE_OK;
@@ -178916,6 +181087,7 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
178916 nPoslist = (int)(aOut - aPoslist); 181087 nPoslist = (int)(aOut - aPoslist);
178917 if( nPoslist==0 ){ 181088 if( nPoslist==0 ){
178918 sqlite3_free(aPoslist); 181089 sqlite3_free(aPoslist);
181090 sqlite3_free(aFree);
178919 pPhrase->doclist.pList = 0; 181091 pPhrase->doclist.pList = 0;
178920 pPhrase->doclist.nList = 0; 181092 pPhrase->doclist.nList = 0;
178921 return SQLITE_OK; 181093 return SQLITE_OK;
@@ -178955,6 +181127,7 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
178955 } 181127 }
178956 181128
178957 pPhrase->doclist.pList = aOut; 181129 pPhrase->doclist.pList = aOut;
181130 assert( p1 && p2 );
178958 if( fts3PoslistPhraseMerge(&aOut, nDistance, 0, 1, &p1, &p2) ){ 181131 if( fts3PoslistPhraseMerge(&aOut, nDistance, 0, 1, &p1, &p2) ){
178959 pPhrase->doclist.bFreeList = 1; 181132 pPhrase->doclist.bFreeList = 1;
178960 pPhrase->doclist.nList = (int)(aOut - pPhrase->doclist.pList); 181133 pPhrase->doclist.nList = (int)(aOut - pPhrase->doclist.pList);
@@ -178967,6 +181140,7 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
178967 } 181140 }
178968 } 181141 }
178969 181142
181143 if( pPhrase->doclist.pList!=aFree ) sqlite3_free(aFree);
178970 return SQLITE_OK; 181144 return SQLITE_OK;
178971} 181145}
178972#endif /* SQLITE_DISABLE_FTS4_DEFERRED */ 181146#endif /* SQLITE_DISABLE_FTS4_DEFERRED */
@@ -180141,11 +182315,10 @@ static int fts3EvalTestExpr(
180141 182315
180142 default: { 182316 default: {
180143#ifndef SQLITE_DISABLE_FTS4_DEFERRED 182317#ifndef SQLITE_DISABLE_FTS4_DEFERRED
180144 if( pCsr->pDeferred 182318 if( pCsr->pDeferred && (pExpr->bDeferred || (
180145 && (pExpr->iDocid==pCsr->iPrevId || pExpr->bDeferred) 182319 pExpr->iDocid==pCsr->iPrevId && pExpr->pPhrase->doclist.pList
180146 ){ 182320 ))){
180147 Fts3Phrase *pPhrase = pExpr->pPhrase; 182321 Fts3Phrase *pPhrase = pExpr->pPhrase;
180148 assert( pExpr->bDeferred || pPhrase->doclist.bFreeList==0 );
180149 if( pExpr->bDeferred ){ 182322 if( pExpr->bDeferred ){
180150 fts3EvalInvalidatePoslist(pPhrase); 182323 fts3EvalInvalidatePoslist(pPhrase);
180151 } 182324 }
@@ -188716,6 +190889,8 @@ static int fts3IncrmergePush(
188716 pBlk->n += sqlite3Fts3PutVarint(&pBlk->a[pBlk->n], nPrefix); 190889 pBlk->n += sqlite3Fts3PutVarint(&pBlk->a[pBlk->n], nPrefix);
188717 } 190890 }
188718 pBlk->n += sqlite3Fts3PutVarint(&pBlk->a[pBlk->n], nSuffix); 190891 pBlk->n += sqlite3Fts3PutVarint(&pBlk->a[pBlk->n], nSuffix);
190892 assert( nPrefix+nSuffix<=nTerm );
190893 assert( nPrefix>=0 );
188719 memcpy(&pBlk->a[pBlk->n], &zTerm[nPrefix], nSuffix); 190894 memcpy(&pBlk->a[pBlk->n], &zTerm[nPrefix], nSuffix);
188720 pBlk->n += nSuffix; 190895 pBlk->n += nSuffix;
188721 190896
@@ -188838,6 +191013,7 @@ static int fts3IncrmergeAppend(
188838 pLeaf = &pWriter->aNodeWriter[0]; 191013 pLeaf = &pWriter->aNodeWriter[0];
188839 nPrefix = fts3PrefixCompress(pLeaf->key.a, pLeaf->key.n, zTerm, nTerm); 191014 nPrefix = fts3PrefixCompress(pLeaf->key.a, pLeaf->key.n, zTerm, nTerm);
188840 nSuffix = nTerm - nPrefix; 191015 nSuffix = nTerm - nPrefix;
191016 if(nSuffix<=0 ) return FTS_CORRUPT_VTAB;
188841 191017
188842 nSpace = sqlite3Fts3VarintLen(nPrefix); 191018 nSpace = sqlite3Fts3VarintLen(nPrefix);
188843 nSpace += sqlite3Fts3VarintLen(nSuffix) + nSuffix; 191019 nSpace += sqlite3Fts3VarintLen(nSuffix) + nSuffix;
@@ -194288,14 +196464,15 @@ static JsonNode *jsonLookupStep(
194288 *pzErr = zPath; 196464 *pzErr = zPath;
194289 return 0; 196465 return 0;
194290 } 196466 }
196467 testcase( nKey==0 );
194291 }else{ 196468 }else{
194292 zKey = zPath; 196469 zKey = zPath;
194293 for(i=0; zPath[i] && zPath[i]!='.' && zPath[i]!='['; i++){} 196470 for(i=0; zPath[i] && zPath[i]!='.' && zPath[i]!='['; i++){}
194294 nKey = i; 196471 nKey = i;
194295 } 196472 if( nKey==0 ){
194296 if( nKey==0 ){ 196473 *pzErr = zPath;
194297 *pzErr = zPath; 196474 return 0;
194298 return 0; 196475 }
194299 } 196476 }
194300 j = 1; 196477 j = 1;
194301 for(;;){ 196478 for(;;){
@@ -194794,7 +196971,7 @@ static JsonNode *jsonMergePatch(
194794 if( pPatch->eType!=JSON_OBJECT ){ 196971 if( pPatch->eType!=JSON_OBJECT ){
194795 return pPatch; 196972 return pPatch;
194796 } 196973 }
194797 assert( iTarget>=0 && iTarget<pParse->nNode ); 196974 assert( iTarget<pParse->nNode );
194798 pTarget = &pParse->aNode[iTarget]; 196975 pTarget = &pParse->aNode[iTarget];
194799 assert( (pPatch->jnFlags & JNODE_APPEND)==0 ); 196976 assert( (pPatch->jnFlags & JNODE_APPEND)==0 );
194800 if( pTarget->eType!=JSON_OBJECT ){ 196977 if( pTarget->eType!=JSON_OBJECT ){
@@ -195443,6 +197620,33 @@ static int jsonEachNext(sqlite3_vtab_cursor *cur){
195443 return SQLITE_OK; 197620 return SQLITE_OK;
195444} 197621}
195445 197622
197623/* Append an object label to the JSON Path being constructed
197624** in pStr.
197625*/
197626static void jsonAppendObjectPathElement(
197627 JsonString *pStr,
197628 JsonNode *pNode
197629){
197630 int jj, nn;
197631 const char *z;
197632 assert( pNode->eType==JSON_STRING );
197633 assert( pNode->jnFlags & JNODE_LABEL );
197634 assert( pNode->eU==1 );
197635 z = pNode->u.zJContent;
197636 nn = pNode->n;
197637 assert( nn>=2 );
197638 assert( z[0]=='"' );
197639 assert( z[nn-1]=='"' );
197640 if( nn>2 && sqlite3Isalpha(z[1]) ){
197641 for(jj=2; jj<nn-1 && sqlite3Isalnum(z[jj]); jj++){}
197642 if( jj==nn-1 ){
197643 z++;
197644 nn -= 2;
197645 }
197646 }
197647 jsonPrintf(nn+2, pStr, ".%.*s", nn, z);
197648}
197649
195446/* Append the name of the path for element i to pStr 197650/* Append the name of the path for element i to pStr
195447*/ 197651*/
195448static void jsonEachComputePath( 197652static void jsonEachComputePath(
@@ -195467,10 +197671,7 @@ static void jsonEachComputePath(
195467 }else{ 197671 }else{
195468 assert( pUp->eType==JSON_OBJECT ); 197672 assert( pUp->eType==JSON_OBJECT );
195469 if( (pNode->jnFlags & JNODE_LABEL)==0 ) pNode--; 197673 if( (pNode->jnFlags & JNODE_LABEL)==0 ) pNode--;
195470 assert( pNode->eType==JSON_STRING ); 197674 jsonAppendObjectPathElement(pStr, pNode);
195471 assert( pNode->jnFlags & JNODE_LABEL );
195472 assert( pNode->eU==1 );
195473 jsonPrintf(pNode->n+1, pStr, ".%.*s", pNode->n-2, pNode->u.zJContent+1);
195474 } 197675 }
195475} 197676}
195476 197677
@@ -195541,8 +197742,7 @@ static int jsonEachColumn(
195541 if( p->eType==JSON_ARRAY ){ 197742 if( p->eType==JSON_ARRAY ){
195542 jsonPrintf(30, &x, "[%d]", p->iRowid); 197743 jsonPrintf(30, &x, "[%d]", p->iRowid);
195543 }else if( p->eType==JSON_OBJECT ){ 197744 }else if( p->eType==JSON_OBJECT ){
195544 assert( pThis->eU==1 ); 197745 jsonAppendObjectPathElement(&x, pThis);
195545 jsonPrintf(pThis->n, &x, ".%.*s", pThis->n-2, pThis->u.zJContent+1);
195546 } 197746 }
195547 } 197747 }
195548 jsonResult(&x); 197748 jsonResult(&x);
@@ -210089,7 +212289,7 @@ static int dbpageBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
210089 ){ 212289 ){
210090 pIdxInfo->orderByConsumed = 1; 212290 pIdxInfo->orderByConsumed = 1;
210091 } 212291 }
210092 sqlite3VtabWriteAll(pIdxInfo); 212292 sqlite3VtabUsesAllSchemas(pIdxInfo);
210093 return SQLITE_OK; 212293 return SQLITE_OK;
210094} 212294}
210095 212295
@@ -210267,7 +212467,7 @@ static int dbpageUpdate(
210267 goto update_fail; 212467 goto update_fail;
210268 } 212468 }
210269 pBt = pTab->db->aDb[iDb].pBt; 212469 pBt = pTab->db->aDb[iDb].pBt;
210270 if( pgno<1 || pBt==0 || pgno>(int)sqlite3BtreeLastPage(pBt) ){ 212470 if( pgno<1 || pBt==0 || pgno>sqlite3BtreeLastPage(pBt) ){
210271 zErr = "bad page number"; 212471 zErr = "bad page number";
210272 goto update_fail; 212472 goto update_fail;
210273 } 212473 }
@@ -222817,6 +225017,9 @@ static Fts5ExprNearset *sqlite3Fts5ParseNearset(
222817 }else{ 225017 }else{
222818 if( pRet->nPhrase>0 ){ 225018 if( pRet->nPhrase>0 ){
222819 Fts5ExprPhrase *pLast = pRet->apPhrase[pRet->nPhrase-1]; 225019 Fts5ExprPhrase *pLast = pRet->apPhrase[pRet->nPhrase-1];
225020 assert( pParse!=0 );
225021 assert( pParse->apPhrase!=0 );
225022 assert( pParse->nPhrase>=2 );
222820 assert( pLast==pParse->apPhrase[pParse->nPhrase-2] ); 225023 assert( pLast==pParse->apPhrase[pParse->nPhrase-2] );
222821 if( pPhrase->nTerm==0 ){ 225024 if( pPhrase->nTerm==0 ){
222822 fts5ExprPhraseFree(pPhrase); 225025 fts5ExprPhraseFree(pPhrase);
@@ -225116,7 +227319,7 @@ struct Fts5Index {
225116 sqlite3_stmt *pWriter; /* "INSERT ... %_data VALUES(?,?)" */ 227319 sqlite3_stmt *pWriter; /* "INSERT ... %_data VALUES(?,?)" */
225117 sqlite3_stmt *pDeleter; /* "DELETE FROM %_data ... id>=? AND id<=?" */ 227320 sqlite3_stmt *pDeleter; /* "DELETE FROM %_data ... id>=? AND id<=?" */
225118 sqlite3_stmt *pIdxWriter; /* "INSERT ... %_idx VALUES(?,?,?,?)" */ 227321 sqlite3_stmt *pIdxWriter; /* "INSERT ... %_idx VALUES(?,?,?,?)" */
225119 sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=? */ 227322 sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=?" */
225120 sqlite3_stmt *pIdxSelect; 227323 sqlite3_stmt *pIdxSelect;
225121 int nRead; /* Total number of blocks read */ 227324 int nRead; /* Total number of blocks read */
225122 227325
@@ -234433,7 +236636,7 @@ static void fts5SourceIdFunc(
234433){ 236636){
234434 assert( nArg==0 ); 236637 assert( nArg==0 );
234435 UNUSED_PARAM2(nArg, apUnused); 236638 UNUSED_PARAM2(nArg, apUnused);
234436 sqlite3_result_text(pCtx, "fts5: 2022-03-26 13:51:10 d33c709cc0af66bc5b6dc6216eba9f1f0b40960b9ae83694c986fbf4c1d6f08f", -1, SQLITE_TRANSIENT); 236639 sqlite3_result_text(pCtx, "fts5: 2022-07-21 15:24:47 698edb77537b67c41adc68f9b892db56bcf9a55e00371a61420f3ddd668e6603", -1, SQLITE_TRANSIENT);
234437} 236640}
234438 236641
234439/* 236642/*
@@ -239104,6 +241307,16 @@ SQLITE_EXTENSION_INIT1
239104 241307
239105#ifndef SQLITE_OMIT_VIRTUALTABLE 241308#ifndef SQLITE_OMIT_VIRTUALTABLE
239106 241309
241310
241311#define STMT_NUM_INTEGER_COLUMN 10
241312typedef struct StmtRow StmtRow;
241313struct StmtRow {
241314 sqlite3_int64 iRowid; /* Rowid value */
241315 char *zSql; /* column "sql" */
241316 int aCol[STMT_NUM_INTEGER_COLUMN+1]; /* all other column values */
241317 StmtRow *pNext; /* Next row to return */
241318};
241319
239107/* stmt_vtab is a subclass of sqlite3_vtab which will 241320/* stmt_vtab is a subclass of sqlite3_vtab which will
239108** serve as the underlying representation of a stmt virtual table 241321** serve as the underlying representation of a stmt virtual table
239109*/ 241322*/
@@ -239121,8 +241334,7 @@ typedef struct stmt_cursor stmt_cursor;
239121struct stmt_cursor { 241334struct stmt_cursor {
239122 sqlite3_vtab_cursor base; /* Base class - must be first */ 241335 sqlite3_vtab_cursor base; /* Base class - must be first */
239123 sqlite3 *db; /* Database connection for this cursor */ 241336 sqlite3 *db; /* Database connection for this cursor */
239124 sqlite3_stmt *pStmt; /* Statement cursor is currently pointing at */ 241337 StmtRow *pRow; /* Current row */
239125 sqlite3_int64 iRowid; /* The rowid */
239126}; 241338};
239127 241339
239128/* 241340/*
@@ -239166,7 +241378,7 @@ static int stmtConnect(
239166 "CREATE TABLE x(sql,ncol,ro,busy,nscan,nsort,naidx,nstep," 241378 "CREATE TABLE x(sql,ncol,ro,busy,nscan,nsort,naidx,nstep,"
239167 "reprep,run,mem)"); 241379 "reprep,run,mem)");
239168 if( rc==SQLITE_OK ){ 241380 if( rc==SQLITE_OK ){
239169 pNew = sqlite3_malloc( sizeof(*pNew) ); 241381 pNew = sqlite3_malloc64( sizeof(*pNew) );
239170 *ppVtab = (sqlite3_vtab*)pNew; 241382 *ppVtab = (sqlite3_vtab*)pNew;
239171 if( pNew==0 ) return SQLITE_NOMEM; 241383 if( pNew==0 ) return SQLITE_NOMEM;
239172 memset(pNew, 0, sizeof(*pNew)); 241384 memset(pNew, 0, sizeof(*pNew));
@@ -239188,7 +241400,7 @@ static int stmtDisconnect(sqlite3_vtab *pVtab){
239188*/ 241400*/
239189static int stmtOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){ 241401static int stmtOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
239190 stmt_cursor *pCur; 241402 stmt_cursor *pCur;
239191 pCur = sqlite3_malloc( sizeof(*pCur) ); 241403 pCur = sqlite3_malloc64( sizeof(*pCur) );
239192 if( pCur==0 ) return SQLITE_NOMEM; 241404 if( pCur==0 ) return SQLITE_NOMEM;
239193 memset(pCur, 0, sizeof(*pCur)); 241405 memset(pCur, 0, sizeof(*pCur));
239194 pCur->db = ((stmt_vtab*)p)->db; 241406 pCur->db = ((stmt_vtab*)p)->db;
@@ -239196,10 +241408,21 @@ static int stmtOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
239196 return SQLITE_OK; 241408 return SQLITE_OK;
239197} 241409}
239198 241410
241411static void stmtCsrReset(stmt_cursor *pCur){
241412 StmtRow *pRow = 0;
241413 StmtRow *pNext = 0;
241414 for(pRow=pCur->pRow; pRow; pRow=pNext){
241415 pNext = pRow->pNext;
241416 sqlite3_free(pRow);
241417 }
241418 pCur->pRow = 0;
241419}
241420
239199/* 241421/*
239200** Destructor for a stmt_cursor. 241422** Destructor for a stmt_cursor.
239201*/ 241423*/
239202static int stmtClose(sqlite3_vtab_cursor *cur){ 241424static int stmtClose(sqlite3_vtab_cursor *cur){
241425 stmtCsrReset((stmt_cursor*)cur);
239203 sqlite3_free(cur); 241426 sqlite3_free(cur);
239204 return SQLITE_OK; 241427 return SQLITE_OK;
239205} 241428}
@@ -239210,8 +241433,9 @@ static int stmtClose(sqlite3_vtab_cursor *cur){
239210*/ 241433*/
239211static int stmtNext(sqlite3_vtab_cursor *cur){ 241434static int stmtNext(sqlite3_vtab_cursor *cur){
239212 stmt_cursor *pCur = (stmt_cursor*)cur; 241435 stmt_cursor *pCur = (stmt_cursor*)cur;
239213 pCur->iRowid++; 241436 StmtRow *pNext = pCur->pRow->pNext;
239214 pCur->pStmt = sqlite3_next_stmt(pCur->db, pCur->pStmt); 241437 sqlite3_free(pCur->pRow);
241438 pCur->pRow = pNext;
239215 return SQLITE_OK; 241439 return SQLITE_OK;
239216} 241440}
239217 241441
@@ -239225,39 +241449,11 @@ static int stmtColumn(
239225 int i /* Which column to return */ 241449 int i /* Which column to return */
239226){ 241450){
239227 stmt_cursor *pCur = (stmt_cursor*)cur; 241451 stmt_cursor *pCur = (stmt_cursor*)cur;
239228 switch( i ){ 241452 StmtRow *pRow = pCur->pRow;
239229 case STMT_COLUMN_SQL: { 241453 if( i==STMT_COLUMN_SQL ){
239230 sqlite3_result_text(ctx, sqlite3_sql(pCur->pStmt), -1, SQLITE_TRANSIENT); 241454 sqlite3_result_text(ctx, pRow->zSql, -1, SQLITE_TRANSIENT);
239231 break; 241455 }else{
239232 } 241456 sqlite3_result_int(ctx, pRow->aCol[i]);
239233 case STMT_COLUMN_NCOL: {
239234 sqlite3_result_int(ctx, sqlite3_column_count(pCur->pStmt));
239235 break;
239236 }
239237 case STMT_COLUMN_RO: {
239238 sqlite3_result_int(ctx, sqlite3_stmt_readonly(pCur->pStmt));
239239 break;
239240 }
239241 case STMT_COLUMN_BUSY: {
239242 sqlite3_result_int(ctx, sqlite3_stmt_busy(pCur->pStmt));
239243 break;
239244 }
239245 default: {
239246 assert( i==STMT_COLUMN_MEM );
239247 i = SQLITE_STMTSTATUS_MEMUSED +
239248 STMT_COLUMN_NSCAN - SQLITE_STMTSTATUS_FULLSCAN_STEP;
239249 /* Fall thru */
239250 }
239251 case STMT_COLUMN_NSCAN:
239252 case STMT_COLUMN_NSORT:
239253 case STMT_COLUMN_NAIDX:
239254 case STMT_COLUMN_NSTEP:
239255 case STMT_COLUMN_REPREP:
239256 case STMT_COLUMN_RUN: {
239257 sqlite3_result_int(ctx, sqlite3_stmt_status(pCur->pStmt,
239258 i-STMT_COLUMN_NSCAN+SQLITE_STMTSTATUS_FULLSCAN_STEP, 0));
239259 break;
239260 }
239261 } 241457 }
239262 return SQLITE_OK; 241458 return SQLITE_OK;
239263} 241459}
@@ -239268,7 +241464,7 @@ static int stmtColumn(
239268*/ 241464*/
239269static int stmtRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){ 241465static int stmtRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
239270 stmt_cursor *pCur = (stmt_cursor*)cur; 241466 stmt_cursor *pCur = (stmt_cursor*)cur;
239271 *pRowid = pCur->iRowid; 241467 *pRowid = pCur->pRow->iRowid;
239272 return SQLITE_OK; 241468 return SQLITE_OK;
239273} 241469}
239274 241470
@@ -239278,7 +241474,7 @@ static int stmtRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
239278*/ 241474*/
239279static int stmtEof(sqlite3_vtab_cursor *cur){ 241475static int stmtEof(sqlite3_vtab_cursor *cur){
239280 stmt_cursor *pCur = (stmt_cursor*)cur; 241476 stmt_cursor *pCur = (stmt_cursor*)cur;
239281 return pCur->pStmt==0; 241477 return pCur->pRow==0;
239282} 241478}
239283 241479
239284/* 241480/*
@@ -239293,9 +241489,53 @@ static int stmtFilter(
239293 int argc, sqlite3_value **argv 241489 int argc, sqlite3_value **argv
239294){ 241490){
239295 stmt_cursor *pCur = (stmt_cursor *)pVtabCursor; 241491 stmt_cursor *pCur = (stmt_cursor *)pVtabCursor;
239296 pCur->pStmt = 0; 241492 sqlite3_stmt *p = 0;
239297 pCur->iRowid = 0; 241493 sqlite3_int64 iRowid = 1;
239298 return stmtNext(pVtabCursor); 241494 StmtRow **ppRow = 0;
241495
241496 stmtCsrReset(pCur);
241497 ppRow = &pCur->pRow;
241498 for(p=sqlite3_next_stmt(pCur->db, 0); p; p=sqlite3_next_stmt(pCur->db, p)){
241499 const char *zSql = sqlite3_sql(p);
241500 sqlite3_int64 nSql = zSql ? strlen(zSql)+1 : 0;
241501 StmtRow *pNew = (StmtRow*)sqlite3_malloc64(sizeof(StmtRow) + nSql);
241502
241503 if( pNew==0 ) return SQLITE_NOMEM;
241504 memset(pNew, 0, sizeof(StmtRow));
241505 if( zSql ){
241506 pNew->zSql = (char*)&pNew[1];
241507 memcpy(pNew->zSql, zSql, nSql);
241508 }
241509 pNew->aCol[STMT_COLUMN_NCOL] = sqlite3_column_count(p);
241510 pNew->aCol[STMT_COLUMN_RO] = sqlite3_stmt_readonly(p);
241511 pNew->aCol[STMT_COLUMN_BUSY] = sqlite3_stmt_busy(p);
241512 pNew->aCol[STMT_COLUMN_NSCAN] = sqlite3_stmt_status(
241513 p, SQLITE_STMTSTATUS_FULLSCAN_STEP, 0
241514 );
241515 pNew->aCol[STMT_COLUMN_NSORT] = sqlite3_stmt_status(
241516 p, SQLITE_STMTSTATUS_SORT, 0
241517 );
241518 pNew->aCol[STMT_COLUMN_NAIDX] = sqlite3_stmt_status(
241519 p, SQLITE_STMTSTATUS_AUTOINDEX, 0
241520 );
241521 pNew->aCol[STMT_COLUMN_NSTEP] = sqlite3_stmt_status(
241522 p, SQLITE_STMTSTATUS_VM_STEP, 0
241523 );
241524 pNew->aCol[STMT_COLUMN_REPREP] = sqlite3_stmt_status(
241525 p, SQLITE_STMTSTATUS_REPREPARE, 0
241526 );
241527 pNew->aCol[STMT_COLUMN_RUN] = sqlite3_stmt_status(
241528 p, SQLITE_STMTSTATUS_RUN, 0
241529 );
241530 pNew->aCol[STMT_COLUMN_MEM] = sqlite3_stmt_status(
241531 p, SQLITE_STMTSTATUS_MEMUSED, 0
241532 );
241533 pNew->iRowid = iRowid++;
241534 *ppRow = pNew;
241535 ppRow = &pNew->pNext;
241536 }
241537
241538 return SQLITE_OK;
239299} 241539}
239300 241540
239301/* 241541/*
diff --git a/c/sqlite3.h b/c/sqlite3.h
index 33dbec2..f0df724 100644
--- a/c/sqlite3.h
+++ b/c/sqlite3.h
@@ -146,9 +146,9 @@ extern "C" {
146** [sqlite3_libversion_number()], [sqlite3_sourceid()], 146** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147** [sqlite_version()] and [sqlite_source_id()]. 147** [sqlite_version()] and [sqlite_source_id()].
148*/ 148*/
149#define SQLITE_VERSION "3.38.2" 149#define SQLITE_VERSION "3.39.2"
150#define SQLITE_VERSION_NUMBER 3038002 150#define SQLITE_VERSION_NUMBER 3039002
151#define SQLITE_SOURCE_ID "2022-03-26 13:51:10 d33c709cc0af66bc5b6dc6216eba9f1f0b40960b9ae83694c986fbf4c1d6f08f" 151#define SQLITE_SOURCE_ID "2022-07-21 15:24:47 698edb77537b67c41adc68f9b892db56bcf9a55e00371a61420f3ddd668e6603"
152 152
153/* 153/*
154** CAPI3REF: Run-Time Library Version Numbers 154** CAPI3REF: Run-Time Library Version Numbers
@@ -5593,7 +5593,8 @@ SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*);
5593** object D and returns a pointer to that copy. ^The [sqlite3_value] returned 5593** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
5594** is a [protected sqlite3_value] object even if the input is not. 5594** is a [protected sqlite3_value] object even if the input is not.
5595** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a 5595** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
5596** memory allocation fails. 5596** memory allocation fails. ^If V is a [pointer value], then the result
5597** of sqlite3_value_dup(V) is a NULL value.
5597** 5598**
5598** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object 5599** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
5599** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer 5600** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer
@@ -6276,6 +6277,28 @@ SQLITE_API int sqlite3_get_autocommit(sqlite3*);
6276SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*); 6277SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
6277 6278
6278/* 6279/*
6280** CAPI3REF: Return The Schema Name For A Database Connection
6281** METHOD: sqlite3
6282**
6283** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
6284** for the N-th database on database connection D, or a NULL pointer of N is
6285** out of range. An N value of 0 means the main database file. An N of 1 is
6286** the "temp" schema. Larger values of N correspond to various ATTACH-ed
6287** databases.
6288**
6289** Space to hold the string that is returned by sqlite3_db_name() is managed
6290** by SQLite itself. The string might be deallocated by any operation that
6291** changes the schema, including [ATTACH] or [DETACH] or calls to
6292** [sqlite3_serialize()] or [sqlite3_deserialize()], even operations that
6293** occur on a different thread. Applications that need to
6294** remember the string long-term should make their own copy. Applications that
6295** are accessing the same database connection simultaneously on multiple
6296** threads should mutex-protect calls to this API and should make their own
6297** private copy of the result prior to releasing the mutex.
6298*/
6299SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N);
6300
6301/*
6279** CAPI3REF: Return The Filename For A Database Connection 6302** CAPI3REF: Return The Filename For A Database Connection
6280** METHOD: sqlite3 6303** METHOD: sqlite3
6281** 6304**
@@ -9554,8 +9577,8 @@ SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_
9554** of a [virtual table] implementation. The result of calling this 9577** of a [virtual table] implementation. The result of calling this
9555** interface from outside of xBestIndex() is undefined and probably harmful. 9578** interface from outside of xBestIndex() is undefined and probably harmful.
9556** 9579**
9557** ^The sqlite3_vtab_distinct() interface returns an integer that is 9580** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and
9558** either 0, 1, or 2. The integer returned by sqlite3_vtab_distinct() 9581** 3. The integer returned by sqlite3_vtab_distinct()
9559** gives the virtual table additional information about how the query 9582** gives the virtual table additional information about how the query
9560** planner wants the output to be ordered. As long as the virtual table 9583** planner wants the output to be ordered. As long as the virtual table
9561** can meet the ordering requirements of the query planner, it may set 9584** can meet the ordering requirements of the query planner, it may set
@@ -9587,6 +9610,13 @@ SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_
9587** that have the same value for all columns identified by "aOrderBy". 9610** that have the same value for all columns identified by "aOrderBy".
9588** ^However omitting the extra rows is optional. 9611** ^However omitting the extra rows is optional.
9589** This mode is used for a DISTINCT query. 9612** This mode is used for a DISTINCT query.
9613** <li value="3"><p>
9614** ^(If the sqlite3_vtab_distinct() interface returns 3, that means
9615** that the query planner needs only distinct rows but it does need the
9616** rows to be sorted.)^ ^The virtual table implementation is free to omit
9617** rows that are identical in all aOrderBy columns, if it wants to, but
9618** it is not required to omit any rows. This mode is used for queries
9619** that have both DISTINCT and ORDER BY clauses.
9590** </ol> 9620** </ol>
9591** 9621**
9592** ^For the purposes of comparing virtual table output values to see if the 9622** ^For the purposes of comparing virtual table output values to see if the