Fossil SCM

Update the built-in SQLite to the latest 3.39.0 beta, for testing.

drh 2022-06-15 17:37 trunk
Commit b0f84d8d1742a22d39d2c4cb047d57c10ec625fb1dbc9514b0e1f8f61fcb3119
+10 -1
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -12924,11 +12924,15 @@
1292412924
UNUSED_PARAMETER(zA2);
1292512925
UNUSED_PARAMETER(zA3);
1292612926
UNUSED_PARAMETER(zA4);
1292712927
switch( op ){
1292812928
case SQLITE_ATTACH: {
12929
+#ifndef SQLITE_SHELL_WASM_MODE
12930
+ /* In WASM builds the filesystem is a virtual sandbox, so
12931
+ ** there's no harm in using ATTACH. */
1292912932
failIfSafeMode(p, "cannot run ATTACH in safe mode");
12933
+#endif
1293012934
break;
1293112935
}
1293212936
case SQLITE_FUNCTION: {
1293312937
int i;
1293412938
for(i=0; i<ArraySize(azProhibitedFunctions); i++){
@@ -15379,11 +15383,13 @@
1537915383
".clone NEWDB Clone data into NEWDB from the existing database",
1538015384
#endif
1538115385
".connection [close] [#] Open or close an auxiliary database connection",
1538215386
".databases List names and files of attached databases",
1538315387
".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
15388
+#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
1538415389
".dbinfo ?DB? Show status information about the database",
15390
+#endif
1538515391
".dump ?OBJECTS? Render database content as SQL",
1538615392
" Options:",
1538715393
" --data-only Output only INSERT statements",
1538815394
" --newlines Allow unescaped newline characters in output",
1538915395
" --nosys Omit system tables (ex: \"sqlite_stat1\")",
@@ -16917,10 +16923,11 @@
1691716923
}
1691816924
sqlite3_finalize(pStmt);
1691916925
return res;
1692016926
}
1692116927
16928
+#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
1692216929
/*
1692316930
** Convert a 2-byte or 4-byte big-endian integer into a native integer
1692416931
*/
1692516932
static unsigned int get2byteInt(unsigned char *a){
1692616933
return (a[0]<<8) + a[1];
@@ -17023,10 +17030,12 @@
1702317030
sqlite3_free(zSchemaTab);
1702417031
sqlite3_file_control(p->db, zDb, SQLITE_FCNTL_DATA_VERSION, &iDataVersion);
1702517032
utf8_printf(p->out, "%-20s %u\n", "data version", iDataVersion);
1702617033
return 0;
1702717034
}
17035
+#endif /* !defined(SQLITE_OMIT_VIRTUALTABLE)
17036
+ && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
1702817037
1702917038
/*
1703017039
** Print the current sqlite3_errmsg() value to stderr and return 1.
1703117040
*/
1703217041
static int shellDatabaseError(sqlite3 *db){
@@ -19565,15 +19574,15 @@
1956519574
utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
1956619575
utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
1956719576
}
1956819577
}else
1956919578
19579
+#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
1957019580
if( c=='d' && n>=3 && strncmp(azArg[0], "dbinfo", n)==0 ){
1957119581
rc = shell_dbinfo_command(p, nArg, azArg);
1957219582
}else
1957319583
19574
-#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
1957519584
if( c=='r' && strncmp(azArg[0], "recover", n)==0 ){
1957619585
open_db(p, 0);
1957719586
rc = recoverDatabaseCmd(p, nArg, azArg);
1957819587
}else
1957919588
#endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
1958019589
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -12924,11 +12924,15 @@
12924 UNUSED_PARAMETER(zA2);
12925 UNUSED_PARAMETER(zA3);
12926 UNUSED_PARAMETER(zA4);
12927 switch( op ){
12928 case SQLITE_ATTACH: {
 
 
 
12929 failIfSafeMode(p, "cannot run ATTACH in safe mode");
 
12930 break;
12931 }
12932 case SQLITE_FUNCTION: {
12933 int i;
12934 for(i=0; i<ArraySize(azProhibitedFunctions); i++){
@@ -15379,11 +15383,13 @@
15379 ".clone NEWDB Clone data into NEWDB from the existing database",
15380 #endif
15381 ".connection [close] [#] Open or close an auxiliary database connection",
15382 ".databases List names and files of attached databases",
15383 ".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
 
15384 ".dbinfo ?DB? Show status information about the database",
 
15385 ".dump ?OBJECTS? Render database content as SQL",
15386 " Options:",
15387 " --data-only Output only INSERT statements",
15388 " --newlines Allow unescaped newline characters in output",
15389 " --nosys Omit system tables (ex: \"sqlite_stat1\")",
@@ -16917,10 +16923,11 @@
16917 }
16918 sqlite3_finalize(pStmt);
16919 return res;
16920 }
16921
 
16922 /*
16923 ** Convert a 2-byte or 4-byte big-endian integer into a native integer
16924 */
16925 static unsigned int get2byteInt(unsigned char *a){
16926 return (a[0]<<8) + a[1];
@@ -17023,10 +17030,12 @@
17023 sqlite3_free(zSchemaTab);
17024 sqlite3_file_control(p->db, zDb, SQLITE_FCNTL_DATA_VERSION, &iDataVersion);
17025 utf8_printf(p->out, "%-20s %u\n", "data version", iDataVersion);
17026 return 0;
17027 }
 
 
17028
17029 /*
17030 ** Print the current sqlite3_errmsg() value to stderr and return 1.
17031 */
17032 static int shellDatabaseError(sqlite3 *db){
@@ -19565,15 +19574,15 @@
19565 utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
19566 utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
19567 }
19568 }else
19569
 
19570 if( c=='d' && n>=3 && strncmp(azArg[0], "dbinfo", n)==0 ){
19571 rc = shell_dbinfo_command(p, nArg, azArg);
19572 }else
19573
19574 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
19575 if( c=='r' && strncmp(azArg[0], "recover", n)==0 ){
19576 open_db(p, 0);
19577 rc = recoverDatabaseCmd(p, nArg, azArg);
19578 }else
19579 #endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
19580
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -12924,11 +12924,15 @@
12924 UNUSED_PARAMETER(zA2);
12925 UNUSED_PARAMETER(zA3);
12926 UNUSED_PARAMETER(zA4);
12927 switch( op ){
12928 case SQLITE_ATTACH: {
12929 #ifndef SQLITE_SHELL_WASM_MODE
12930 /* In WASM builds the filesystem is a virtual sandbox, so
12931 ** there's no harm in using ATTACH. */
12932 failIfSafeMode(p, "cannot run ATTACH in safe mode");
12933 #endif
12934 break;
12935 }
12936 case SQLITE_FUNCTION: {
12937 int i;
12938 for(i=0; i<ArraySize(azProhibitedFunctions); i++){
@@ -15379,11 +15383,13 @@
15383 ".clone NEWDB Clone data into NEWDB from the existing database",
15384 #endif
15385 ".connection [close] [#] Open or close an auxiliary database connection",
15386 ".databases List names and files of attached databases",
15387 ".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
15388 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
15389 ".dbinfo ?DB? Show status information about the database",
15390 #endif
15391 ".dump ?OBJECTS? Render database content as SQL",
15392 " Options:",
15393 " --data-only Output only INSERT statements",
15394 " --newlines Allow unescaped newline characters in output",
15395 " --nosys Omit system tables (ex: \"sqlite_stat1\")",
@@ -16917,10 +16923,11 @@
16923 }
16924 sqlite3_finalize(pStmt);
16925 return res;
16926 }
16927
16928 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
16929 /*
16930 ** Convert a 2-byte or 4-byte big-endian integer into a native integer
16931 */
16932 static unsigned int get2byteInt(unsigned char *a){
16933 return (a[0]<<8) + a[1];
@@ -17023,10 +17030,12 @@
17030 sqlite3_free(zSchemaTab);
17031 sqlite3_file_control(p->db, zDb, SQLITE_FCNTL_DATA_VERSION, &iDataVersion);
17032 utf8_printf(p->out, "%-20s %u\n", "data version", iDataVersion);
17033 return 0;
17034 }
17035 #endif /* !defined(SQLITE_OMIT_VIRTUALTABLE)
17036 && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
17037
17038 /*
17039 ** Print the current sqlite3_errmsg() value to stderr and return 1.
17040 */
17041 static int shellDatabaseError(sqlite3 *db){
@@ -19565,15 +19574,15 @@
19574 utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
19575 utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
19576 }
19577 }else
19578
19579 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
19580 if( c=='d' && n>=3 && strncmp(azArg[0], "dbinfo", n)==0 ){
19581 rc = shell_dbinfo_command(p, nArg, azArg);
19582 }else
19583
 
19584 if( c=='r' && strncmp(azArg[0], "recover", n)==0 ){
19585 open_db(p, 0);
19586 rc = recoverDatabaseCmd(p, nArg, azArg);
19587 }else
19588 #endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
19589
+190 -61
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.39.0"
456456
#define SQLITE_VERSION_NUMBER 3039000
457
-#define SQLITE_SOURCE_ID "2022-06-03 14:08:40 d18818afc6021a32989499c26ab38fa442e5a55e662e39bb06e5c0daa9c65e25"
457
+#define SQLITE_SOURCE_ID "2022-06-15 16:26:37 56c60a35ea457f06db58ec3f694a1ae16fd03e6625da1d7879d63d72bbcb1c62"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -15724,17 +15724,18 @@
1572415724
#define OP_VInitIn 174 /* synopsis: r[P2]=ValueList(P1,P3) */
1572515725
#define OP_VColumn 175 /* synopsis: r[P3]=vcolumn(P2) */
1572615726
#define OP_VRename 176
1572715727
#define OP_Pagecount 177
1572815728
#define OP_MaxPgcnt 178
15729
-#define OP_FilterAdd 179 /* synopsis: filter(P1) += key(P3@P4) */
15730
-#define OP_Trace 180
15731
-#define OP_CursorHint 181
15732
-#define OP_ReleaseReg 182 /* synopsis: release r[P1@P2] mask P3 */
15733
-#define OP_Noop 183
15734
-#define OP_Explain 184
15735
-#define OP_Abortable 185
15729
+#define OP_ClrSubtype 179 /* synopsis: r[P1].subtype = 0 */
15730
+#define OP_FilterAdd 180 /* synopsis: filter(P1) += key(P3@P4) */
15731
+#define OP_Trace 181
15732
+#define OP_CursorHint 182
15733
+#define OP_ReleaseReg 183 /* synopsis: release r[P1@P2] mask P3 */
15734
+#define OP_Noop 184
15735
+#define OP_Explain 185
15736
+#define OP_Abortable 186
1573615737
1573715738
/* Properties such as "out2" or "jump" that are specified in
1573815739
** comments following the "case" for each opcode in the vdbe.c
1573915740
** are encoded into bitvectors as follows:
1574015741
*/
@@ -15765,12 +15766,12 @@
1576515766
/* 136 */ 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00,\
1576615767
/* 144 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
1576715768
/* 152 */ 0x00, 0x10, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
1576815769
/* 160 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
1576915770
/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\
15770
-/* 176 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
15771
-/* 184 */ 0x00, 0x00,}
15771
+/* 176 */ 0x00, 0x10, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00,\
15772
+/* 184 */ 0x00, 0x00, 0x00,}
1577215773
1577315774
/* The resolve3P2Values() routine is able to run faster if it knows
1577415775
** the value of the largest JUMP opcode. The smaller the maximum
1577515776
** JUMP opcode the better, so the mkopcodeh.tcl script that
1577615777
** generated this include file strives to group all JUMP opcodes
@@ -18403,10 +18404,11 @@
1840318404
unsigned isRecursive :1; /* True for recursive reference in WITH */
1840418405
unsigned fromDDL :1; /* Comes from sqlite_schema */
1840518406
unsigned isCte :1; /* This is a CTE */
1840618407
unsigned notCte :1; /* This item may not match a CTE */
1840718408
unsigned isUsing :1; /* u3.pUsing is valid */
18409
+ unsigned isOn :1; /* u3.pOn was once valid and non-NULL */
1840818410
unsigned isSynthUsing :1; /* u3.pUsing is synthensized from NATURAL */
1840918411
unsigned isNestedFrom :1; /* pSelect is a SF_NestedFrom subquery */
1841018412
} fg;
1841118413
int iCursor; /* The VDBE cursor number used to access this table */
1841218414
union {
@@ -22254,11 +22256,11 @@
2225422256
u8 wrFlag; /* The wrFlag argument to sqlite3BtreeCursor() */
2225522257
#endif
2225622258
Bool isEphemeral:1; /* True for an ephemeral table */
2225722259
Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */
2225822260
Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
22259
- Bool hasBeenDuped:1; /* This cursor was source or target of OP_OpenDup */
22261
+ Bool noReuse:1; /* OpenEphemeral may not reuse this cursor */
2226022262
u16 seekHit; /* See the OP_SeekHit and OP_IfNoHope opcodes */
2226122263
union { /* pBtx for isEphermeral. pAltMap otherwise */
2226222264
Btree *pBtx; /* Separate file holding temporary table */
2226322265
u32 *aAltMap; /* Mapping from table to index column numbers */
2226422266
} ub;
@@ -31228,10 +31230,13 @@
3122831230
sqlite3_str_appendf(&x, " DDL");
3122931231
}
3123031232
if( pItem->fg.isCte ){
3123131233
sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
3123231234
}
31235
+ if( pItem->fg.isOn || (pItem->fg.isUsing==0 && pItem->u3.pOn!=0) ){
31236
+ sqlite3_str_appendf(&x, " ON");
31237
+ }
3123331238
sqlite3StrAccumFinish(&x);
3123431239
sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
3123531240
n = 0;
3123631241
if( pItem->pSelect ) n++;
3123731242
if( pItem->fg.isTabFunc ) n++;
@@ -35433,17 +35438,18 @@
3543335438
/* 174 */ "VInitIn" OpHelp("r[P2]=ValueList(P1,P3)"),
3543435439
/* 175 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
3543535440
/* 176 */ "VRename" OpHelp(""),
3543635441
/* 177 */ "Pagecount" OpHelp(""),
3543735442
/* 178 */ "MaxPgcnt" OpHelp(""),
35438
- /* 179 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"),
35439
- /* 180 */ "Trace" OpHelp(""),
35440
- /* 181 */ "CursorHint" OpHelp(""),
35441
- /* 182 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
35442
- /* 183 */ "Noop" OpHelp(""),
35443
- /* 184 */ "Explain" OpHelp(""),
35444
- /* 185 */ "Abortable" OpHelp(""),
35443
+ /* 179 */ "ClrSubtype" OpHelp("r[P1].subtype = 0"),
35444
+ /* 180 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"),
35445
+ /* 181 */ "Trace" OpHelp(""),
35446
+ /* 182 */ "CursorHint" OpHelp(""),
35447
+ /* 183 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
35448
+ /* 184 */ "Noop" OpHelp(""),
35449
+ /* 185 */ "Explain" OpHelp(""),
35450
+ /* 186 */ "Abortable" OpHelp(""),
3544535451
};
3544635452
return azName[i];
3544735453
}
3544835454
#endif
3544935455
@@ -56462,10 +56468,11 @@
5646256468
}else if( (currentSize+szPage)<=newSize ){
5646356469
char *pTmp = pPager->pTmpSpace;
5646456470
memset(pTmp, 0, szPage);
5646556471
testcase( (newSize-szPage) == currentSize );
5646656472
testcase( (newSize-szPage) > currentSize );
56473
+ sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_SIZE_HINT, &newSize);
5646756474
rc = sqlite3OsWrite(pPager->fd, pTmp, szPage, newSize-szPage);
5646856475
}
5646956476
if( rc==SQLITE_OK ){
5647056477
pPager->dbFileSize = nPage;
5647156478
}
@@ -70714,16 +70721,21 @@
7071470721
eMode = BTALLOC_LE;
7071570722
iNear = nFin;
7071670723
}
7071770724
do {
7071870725
MemPage *pFreePg;
70726
+ Pgno dbSize = btreePagecount(pBt);
7071970727
rc = allocateBtreePage(pBt, &pFreePg, &iFreePg, iNear, eMode);
7072070728
if( rc!=SQLITE_OK ){
7072170729
releasePage(pLastPg);
7072270730
return rc;
7072370731
}
7072470732
releasePage(pFreePg);
70733
+ if( iFreePg>dbSize ){
70734
+ releasePage(pLastPg);
70735
+ return SQLITE_CORRUPT_BKPT;
70736
+ }
7072570737
}while( bCommit && iFreePg>nFin );
7072670738
assert( iFreePg<iLastPg );
7072770739
7072870740
rc = relocatePage(pBt, pLastPg, eType, iPtrPage, iFreePg, bCommit);
7072970741
releasePage(pLastPg);
@@ -80228,12 +80240,12 @@
8022880240
assert( !ExprHasProperty(pExpr, EP_IntValue) );
8022980241
aff = sqlite3AffinityType(pExpr->u.zToken,0);
8023080242
rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
8023180243
testcase( rc!=SQLITE_OK );
8023280244
if( *ppVal ){
80233
- sqlite3VdbeMemCast(*ppVal, aff, SQLITE_UTF8);
80234
- sqlite3ValueApplyAffinity(*ppVal, affinity, SQLITE_UTF8);
80245
+ sqlite3VdbeMemCast(*ppVal, aff, enc);
80246
+ sqlite3ValueApplyAffinity(*ppVal, affinity, enc);
8023580247
}
8023680248
return rc;
8023780249
}
8023880250
8023980251
/* Handle negative integers in a single step. This is needed in the
@@ -89757,14 +89769,19 @@
8975789769
pOut++;
8975889770
}while( --n );
8975989771
break;
8976089772
}
8976189773
89762
-/* Opcode: Copy P1 P2 P3 * *
89774
+/* Opcode: Copy P1 P2 P3 * P5
8976389775
** Synopsis: r[P2@P3+1]=r[P1@P3+1]
8976489776
**
8976589777
** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
89778
+**
89779
+** If the 0x0002 bit of P5 is set then also clear the MEM_Subtype flag in the
89780
+** destination. The 0x0001 bit of P5 indicates that this Copy opcode cannot
89781
+** be merged. The 0x0001 bit is used by the query planner and does not
89782
+** come into play during query execution.
8976689783
**
8976789784
** This instruction makes a deep copy of the value. A duplicate
8976889785
** is made of any string or blob constant. See also OP_SCopy.
8976989786
*/
8977089787
case OP_Copy: {
@@ -89776,10 +89793,13 @@
8977689793
assert( pOut!=pIn1 );
8977789794
while( 1 ){
8977889795
memAboutToChange(p, pOut);
8977989796
sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
8978089797
Deephemeralize(pOut);
89798
+ if( (pOut->flags & MEM_Subtype)!=0 && (pOp->p5 & 0x0002)!=0 ){
89799
+ pOut->flags &= ~MEM_Subtype;
89800
+ }
8978189801
#ifdef SQLITE_DEBUG
8978289802
pOut->pScopyFrom = 0;
8978389803
#endif
8978489804
REGISTER_TRACE(pOp->p2+pOp->p3-n, pOut);
8978589805
if( (n--)==0 ) break;
@@ -92158,10 +92178,15 @@
9215892178
if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
9215992179
sqlite3ResetOneSchema(db, pOp->p1);
9216092180
}
9216192181
p->expired = 1;
9216292182
rc = SQLITE_SCHEMA;
92183
+
92184
+ /* Set changeCntOn to 0 to prevent the value returned by sqlite3_changes()
92185
+ ** from being modified in sqlite3VdbeHalt(). If this statement is
92186
+ ** reprepared, changeCntOn will be set again. */
92187
+ p->changeCntOn = 0;
9216392188
}
9216492189
if( rc ) goto abort_due_to_error;
9216592190
break;
9216692191
}
9216792192
@@ -92457,12 +92482,12 @@
9245792482
pCx->pKeyInfo = pOrig->pKeyInfo;
9245892483
pCx->isTable = pOrig->isTable;
9245992484
pCx->pgnoRoot = pOrig->pgnoRoot;
9246092485
pCx->isOrdered = pOrig->isOrdered;
9246192486
pCx->ub.pBtx = pOrig->ub.pBtx;
92462
- pCx->hasBeenDuped = 1;
92463
- pOrig->hasBeenDuped = 1;
92487
+ pCx->noReuse = 1;
92488
+ pOrig->noReuse = 1;
9246492489
rc = sqlite3BtreeCursor(pCx->ub.pBtx, pCx->pgnoRoot, BTREE_WRCSR,
9246592490
pCx->pKeyInfo, pCx->uc.pCursor);
9246692491
/* The sqlite3BtreeCursor() routine can only fail for the first cursor
9246792492
** opened for a database. Since there is already an open cursor when this
9246892493
** opcode is run, the sqlite3BtreeCursor() cannot fail */
@@ -92525,11 +92550,11 @@
9252592550
assert( aMem[pOp->p3].flags & MEM_Null );
9252692551
aMem[pOp->p3].n = 0;
9252792552
aMem[pOp->p3].z = "";
9252892553
}
9252992554
pCx = p->apCsr[pOp->p1];
92530
- if( pCx && !pCx->hasBeenDuped && ALWAYS(pOp->p2<=pCx->nField) ){
92555
+ if( pCx && !pCx->noReuse && ALWAYS(pOp->p2<=pCx->nField) ){
9253192556
/* If the ephermeral table is already open and has no duplicates from
9253292557
** OP_OpenDup, then erase all existing content so that the table is
9253392558
** empty again, rather than creating a new table. */
9253492559
assert( pCx->isEphemeral );
9253592560
pCx->seqCount = 0;
@@ -94112,10 +94137,11 @@
9411294137
** pseudo-cursor that always gives null rows. */
9411394138
pC = allocateCursor(p, pOp->p1, 1, CURTYPE_PSEUDO);
9411494139
if( pC==0 ) goto no_mem;
9411594140
pC->seekResult = 0;
9411694141
pC->isTable = 1;
94142
+ pC->noReuse = 1;
9411794143
pC->uc.pCursor = sqlite3BtreeFakeValidCursor();
9411894144
}
9411994145
pC->nullRow = 1;
9412094146
pC->cacheStatus = CACHE_STALE;
9412194147
if( pC->eCurType==CURTYPE_BTREE ){
@@ -96244,18 +96270,18 @@
9624496270
Mem *pDest;
9624596271
sqlite3_context sContext;
9624696272
9624796273
VdbeCursor *pCur = p->apCsr[pOp->p1];
9624896274
assert( pCur!=0 );
96249
- assert( pCur->eCurType==CURTYPE_VTAB );
9625096275
assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
9625196276
pDest = &aMem[pOp->p3];
9625296277
memAboutToChange(p, pDest);
9625396278
if( pCur->nullRow ){
9625496279
sqlite3VdbeMemSetNull(pDest);
9625596280
break;
9625696281
}
96282
+ assert( pCur->eCurType==CURTYPE_VTAB );
9625796283
pVtab = pCur->uc.pVCur->pVtab;
9625896284
pModule = pVtab->pModule;
9625996285
assert( pModule->xColumn );
9626096286
memset(&sContext, 0, sizeof(sContext));
9626196287
sContext.pOut = pDest;
@@ -96578,10 +96604,21 @@
9657896604
9657996605
REGISTER_TRACE(pOp->p3, pOut);
9658096606
UPDATE_MAX_BLOBSIZE(pOut);
9658196607
break;
9658296608
}
96609
+
96610
+/* Opcode: ClrSubtype P1 * * * *
96611
+** Synopsis: r[P1].subtype = 0
96612
+**
96613
+** Clear the subtype from register P1.
96614
+*/
96615
+case OP_ClrSubtype: { /* in1 */
96616
+ pIn1 = &aMem[pOp->p1];
96617
+ pIn1->flags &= ~MEM_Subtype;
96618
+ break;
96619
+}
9658396620
9658496621
/* Opcode: FilterAdd P1 * P3 P4 *
9658596622
** Synopsis: filter(P1) += key(P3@P4)
9658696623
**
9658796624
** Compute a hash on the P4 registers starting with r[P3] and
@@ -108130,13 +108167,29 @@
108130108167
** Z is stored in pExpr->pList->a[1].pExpr.
108131108168
*/
108132108169
case TK_BETWEEN: {
108133108170
exprCodeBetween(pParse, pExpr, target, 0, 0);
108134108171
return target;
108172
+ }
108173
+ case TK_COLLATE: {
108174
+ if( !ExprHasProperty(pExpr, EP_Collate)
108175
+ && ALWAYS(pExpr->pLeft)
108176
+ && pExpr->pLeft->op==TK_FUNCTION
108177
+ ){
108178
+ inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
108179
+ if( inReg!=target ){
108180
+ sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
108181
+ inReg = target;
108182
+ }
108183
+ sqlite3VdbeAddOp1(v, OP_ClrSubtype, inReg);
108184
+ return inReg;
108185
+ }else{
108186
+ pExpr = pExpr->pLeft;
108187
+ goto expr_code_doover; /* 2018-04-28: Prevent deep recursion. */
108188
+ }
108135108189
}
108136108190
case TK_SPAN:
108137
- case TK_COLLATE:
108138108191
case TK_UPLUS: {
108139108192
pExpr = pExpr->pLeft;
108140108193
goto expr_code_doover; /* 2018-04-28: Prevent deep recursion. OSSFuzz. */
108141108194
}
108142108195
@@ -135899,31 +135952,37 @@
135899135952
/* Undo the work of sqlite3SetJoinExpr(). In the expression p, convert every
135900135953
** term that is marked with EP_OuterON and w.iJoin==iTable into
135901135954
** an ordinary term that omits the EP_OuterON mark.
135902135955
**
135903135956
** This happens when a LEFT JOIN is simplified into an ordinary JOIN.
135957
+**
135958
+** If nullable is true, that means that Expr p might evaluate to NULL even
135959
+** if it is a reference to a NOT NULL column. This can happen, for example,
135960
+** if the table that p references is on the left side of a RIGHT JOIN.
135961
+** If nullable is true, then take care to not remove the EP_CanBeNull bit.
135962
+** See forum thread https://sqlite.org/forum/forumpost/b40696f50145d21c
135904135963
*/
135905
-static void unsetJoinExpr(Expr *p, int iTable){
135964
+static void unsetJoinExpr(Expr *p, int iTable, int nullable){
135906135965
while( p ){
135907135966
if( ExprHasProperty(p, EP_OuterON)
135908135967
&& (iTable<0 || p->w.iJoin==iTable) ){
135909135968
ExprClearProperty(p, EP_OuterON);
135910135969
ExprSetProperty(p, EP_InnerON);
135911135970
}
135912
- if( p->op==TK_COLUMN && p->iTable==iTable ){
135971
+ if( p->op==TK_COLUMN && p->iTable==iTable && !nullable ){
135913135972
ExprClearProperty(p, EP_CanBeNull);
135914135973
}
135915135974
if( p->op==TK_FUNCTION ){
135916135975
assert( ExprUseXList(p) );
135917135976
if( p->x.pList ){
135918135977
int i;
135919135978
for(i=0; i<p->x.pList->nExpr; i++){
135920
- unsetJoinExpr(p->x.pList->a[i].pExpr, iTable);
135979
+ unsetJoinExpr(p->x.pList->a[i].pExpr, iTable, nullable);
135921135980
}
135922135981
}
135923135982
}
135924
- unsetJoinExpr(p->pLeft, iTable);
135983
+ unsetJoinExpr(p->pLeft, iTable, nullable);
135925135984
p = p->pRight;
135926135985
}
135927135986
}
135928135987
135929135988
/*
@@ -136080,10 +136139,11 @@
136080136139
*/
136081136140
else if( pRight->u3.pOn ){
136082136141
sqlite3SetJoinExpr(pRight->u3.pOn, pRight->iCursor, joinType);
136083136142
p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->u3.pOn);
136084136143
pRight->u3.pOn = 0;
136144
+ pRight->fg.isOn = 1;
136085136145
}
136086136146
}
136087136147
return 0;
136088136148
}
136089136149
@@ -139233,13 +139293,14 @@
139233139293
static Expr *substExpr(
139234139294
SubstContext *pSubst, /* Description of the substitution */
139235139295
Expr *pExpr /* Expr in which substitution occurs */
139236139296
){
139237139297
if( pExpr==0 ) return 0;
139238
- if( ExprHasProperty(pExpr, EP_OuterON)
139298
+ if( ExprHasProperty(pExpr, EP_OuterON|EP_InnerON)
139239139299
&& pExpr->w.iJoin==pSubst->iTable
139240139300
){
139301
+ testcase( ExprHasProperty(pExpr, EP_InnerON) );
139241139302
pExpr->w.iJoin = pSubst->iNewTable;
139242139303
}
139243139304
if( pExpr->op==TK_COLUMN
139244139305
&& pExpr->iTable==pSubst->iTable
139245139306
&& !ExprHasProperty(pExpr, EP_FixedCol)
@@ -139638,10 +139699,15 @@
139638139699
** (27) The subquery may not contain a FULL or RIGHT JOIN unless it
139639139700
** is the first element of the parent query.
139640139701
**
139641139702
** (28) The subquery is not a MATERIALIZED CTE.
139642139703
**
139704
+** (29) Either the subquery is not the right-hand operand of a join with an
139705
+** ON or USING clause nor the right-hand operand of a NATURAL JOIN, or
139706
+** the right-most table within the FROM clause of the subquery
139707
+** is not part of an outer join.
139708
+**
139643139709
**
139644139710
** In this routine, the "p" parameter is a pointer to the outer query.
139645139711
** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
139646139712
** uses aggregates.
139647139713
**
@@ -139764,10 +139830,39 @@
139764139830
return 0; /* Restriction (27) */
139765139831
}
139766139832
if( pSubitem->fg.isCte && pSubitem->u2.pCteUse->eM10d==M10d_Yes ){
139767139833
return 0; /* (28) */
139768139834
}
139835
+
139836
+ /* Restriction (29):
139837
+ **
139838
+ ** We do not want two constraints on the same term of the flattened
139839
+ ** query where one constraint has EP_InnerON and the other is EP_OuterON.
139840
+ ** To prevent this, one or the other of the following conditions must be
139841
+ ** false:
139842
+ **
139843
+ ** (29a) The right-most entry in the FROM clause of the subquery
139844
+ ** must not be part of an outer join.
139845
+ **
139846
+ ** (29b) The subquery itself must not be the right operand of a
139847
+ ** NATURAL join or a join that as an ON or USING clause.
139848
+ **
139849
+ ** These conditions are sufficient to keep an EP_OuterON from being
139850
+ ** flattened into an EP_InnerON. Restrictions (3a) and (27) prevent
139851
+ ** an EP_InnerON from being flattened into an EP_OuterON.
139852
+ */
139853
+ if( pSubSrc->nSrc>=2
139854
+ && (pSubSrc->a[pSubSrc->nSrc-1].fg.jointype & JT_OUTER)!=0
139855
+ ){
139856
+ if( (pSubitem->fg.jointype & JT_NATURAL)!=0
139857
+ || pSubitem->fg.isUsing
139858
+ || NEVER(pSubitem->u3.pOn!=0) /* ON clause already shifted into WHERE */
139859
+ || pSubitem->fg.isOn
139860
+ ){
139861
+ return 0;
139862
+ }
139863
+ }
139769139864
139770139865
/* Restriction (17): If the sub-query is a compound SELECT, then it must
139771139866
** use only the UNION ALL operator. And none of the simple select queries
139772139867
** that make up the compound SELECT are allowed to be aggregate or distinct
139773139868
** queries.
@@ -140156,11 +140251,15 @@
140156140251
** found, add it to the pConst structure.
140157140252
*/
140158140253
static void findConstInWhere(WhereConst *pConst, Expr *pExpr){
140159140254
Expr *pRight, *pLeft;
140160140255
if( NEVER(pExpr==0) ) return;
140161
- if( ExprHasProperty(pExpr, EP_OuterON) ) return;
140256
+ if( ExprHasProperty(pExpr, EP_OuterON|EP_InnerON) ){
140257
+ testcase( ExprHasProperty(pExpr, EP_OuterON) );
140258
+ testcase( ExprHasProperty(pExpr, EP_InnerON) );
140259
+ return;
140260
+ }
140162140261
if( pExpr->op==TK_AND ){
140163140262
findConstInWhere(pConst, pExpr->pRight);
140164140263
findConstInWhere(pConst, pExpr->pLeft);
140165140264
return;
140166140265
}
@@ -140497,11 +140596,11 @@
140497140596
nChng++;
140498140597
pSubq->selFlags |= SF_PushDown;
140499140598
while( pSubq ){
140500140599
SubstContext x;
140501140600
pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
140502
- unsetJoinExpr(pNew, -1);
140601
+ unsetJoinExpr(pNew, -1, 1);
140503140602
x.pParse = pParse;
140504140603
x.iTable = pSrc->iCursor;
140505140604
x.iNewTable = pSrc->iCursor;
140506140605
x.isOuterJoin = 0;
140507140606
x.pEList = pSubq->pEList;
@@ -142181,11 +142280,12 @@
142181142280
&& OptimizationEnabled(db, SQLITE_SimplifyJoin)
142182142281
){
142183142282
SELECTTRACE(0x100,pParse,p,
142184142283
("LEFT-JOIN simplifies to JOIN on term %d\n",i));
142185142284
pItem->fg.jointype &= ~(JT_LEFT|JT_OUTER);
142186
- unsetJoinExpr(p->pWhere, pItem->iCursor);
142285
+ unsetJoinExpr(p->pWhere, pItem->iCursor,
142286
+ pTabList->a[0].fg.jointype & JT_LTORJ);
142187142287
}
142188142288
142189142289
/* No futher action if this term of the FROM clause is no a subquery */
142190142290
if( pSub==0 ) continue;
142191142291
@@ -145977,11 +146077,11 @@
145977146077
if( pPk ){
145978146078
sqlite3VdbeAddOp4Int(v, OP_NotFound,iDataCur,labelContinue,regKey,nKey);
145979146079
}else{
145980146080
sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue,regOldRowid);
145981146081
}
145982
- VdbeCoverageNeverTaken(v);
146082
+ VdbeCoverage(v);
145983146083
}
145984146084
145985146085
/* Do FK constraint checks. */
145986146086
if( hasFK ){
145987146087
sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngKey);
@@ -154477,10 +154577,11 @@
154477154577
if( pOp->opcode==OP_Column ){
154478154578
pOp->opcode = OP_Copy;
154479154579
pOp->p1 = pOp->p2 + iRegister;
154480154580
pOp->p2 = pOp->p3;
154481154581
pOp->p3 = 0;
154582
+ pOp->p5 = 2; /* Cause the MEM_Subtype flag to be cleared */
154482154583
}else if( pOp->opcode==OP_Rowid ){
154483154584
pOp->opcode = OP_Sequence;
154484154585
pOp->p1 = iAutoidxCur;
154485154586
#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
154486154587
if( iAutoidxCur==0 ){
@@ -154551,18 +154652,21 @@
154551154652
const Bitmask notReady /* Tables in outer loops of the join */
154552154653
){
154553154654
char aff;
154554154655
if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
154555154656
if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0;
154556
- if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
154557
- && !ExprHasProperty(pTerm->pExpr, EP_OuterON)
154558
- && (pTerm->eOperator & WO_IS)
154559
- ){
154560
- /* Cannot use an IS term from the WHERE clause as an index driver for
154561
- ** the RHS of a LEFT JOIN or for the LHS of a RIGHT JOIN. Such a term
154562
- ** can only be used if it is from the ON clause. */
154563
- return 0;
154657
+ assert( (pSrc->fg.jointype & JT_RIGHT)==0 );
154658
+ if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0 ){
154659
+ testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LEFT );
154660
+ testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LTORJ );
154661
+ testcase( ExprHasProperty(pTerm->pExpr, EP_OuterON) )
154662
+ testcase( ExprHasProperty(pTerm->pExpr, EP_InnerON) );
154663
+ if( !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON)
154664
+ || pTerm->pExpr->w.iJoin != pSrc->iCursor
154665
+ ){
154666
+ return 0; /* See tag-20191211-001 */
154667
+ }
154564154668
}
154565154669
if( (pTerm->prereqRight & notReady)!=0 ) return 0;
154566154670
assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
154567154671
if( pTerm->u.x.leftColumn<0 ) return 0;
154568154672
aff = pSrc->pTab->aCol[pTerm->u.x.leftColumn].affinity;
@@ -154972,17 +155076,24 @@
154972155076
assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
154973155077
assert( pTerm->u.x.leftColumn>=XN_ROWID );
154974155078
assert( pTerm->u.x.leftColumn<pTab->nCol );
154975155079
154976155080
/* tag-20191211-002: WHERE-clause constraints are not useful to the
154977
- ** right-hand table of a LEFT JOIN nor to the left-hand table of a
155081
+ ** right-hand table of a LEFT JOIN nor to the either table of a
154978155082
** RIGHT JOIN. See tag-20191211-001 for the
154979155083
** equivalent restriction for ordinary tables. */
154980
- if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
154981
- && !ExprHasProperty(pTerm->pExpr, EP_OuterON)
154982
- ){
154983
- continue;
155084
+ if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0 ){
155085
+ testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LEFT );
155086
+ testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_RIGHT );
155087
+ testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LTORJ );
155088
+ testcase( ExprHasProperty(pTerm->pExpr, EP_OuterON) );
155089
+ testcase( ExprHasProperty(pTerm->pExpr, EP_InnerON) );
155090
+ if( !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON)
155091
+ || pTerm->pExpr->w.iJoin != pSrc->iCursor
155092
+ ){
155093
+ continue;
155094
+ }
154984155095
}
154985155096
nTerm++;
154986155097
pTerm->wtFlags |= TERM_OK;
154987155098
}
154988155099
@@ -156628,16 +156739,32 @@
156628156739
** to mix with a lower range bound from some other source */
156629156740
if( pTerm->wtFlags & TERM_LIKEOPT && pTerm->eOperator==WO_LT ) continue;
156630156741
156631156742
/* tag-20191211-001: Do not allow constraints from the WHERE clause to
156632156743
** be used by the right table of a LEFT JOIN nor by the left table of a
156633
- ** RIGHT JOIN. Only constraints in the
156634
- ** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */
156635
- if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
156636
- && !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON)
156637
- ){
156638
- continue;
156744
+ ** RIGHT JOIN. Only constraints in the ON clause are allowed.
156745
+ ** See tag-20191211-002 for the vtab equivalent.
156746
+ **
156747
+ ** 2022-06-06: See https://sqlite.org/forum/forumpost/206d99a16dd9212f
156748
+ ** for an example of a WHERE clause constraints that may not be used on
156749
+ ** the right table of a RIGHT JOIN because the constraint implies a
156750
+ ** not-NULL condition on the left table of the RIGHT JOIN.
156751
+ **
156752
+ ** 2022-06-10: The same condition applies to termCanDriveIndex() above.
156753
+ ** https://sqlite.org/forum/forumpost/51e6959f61
156754
+ */
156755
+ if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0 ){
156756
+ testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LEFT );
156757
+ testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_RIGHT );
156758
+ testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LTORJ );
156759
+ testcase( ExprHasProperty(pTerm->pExpr, EP_OuterON) )
156760
+ testcase( ExprHasProperty(pTerm->pExpr, EP_InnerON) );
156761
+ if( !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON)
156762
+ || pTerm->pExpr->w.iJoin != pSrc->iCursor
156763
+ ){
156764
+ continue;
156765
+ }
156639156766
}
156640156767
156641156768
if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
156642156769
pBuilder->bldFlags1 |= SQLITE_BLDF1_UNIQUE;
156643156770
}else{
@@ -156985,27 +157112,30 @@
156985157112
/* Check to see if a partial index with pPartIndexWhere can be used
156986157113
** in the current query. Return true if it can be and false if not.
156987157114
*/
156988157115
static int whereUsablePartialIndex(
156989157116
int iTab, /* The table for which we want an index */
156990
- int isLeft, /* True if iTab is the right table of a LEFT JOIN */
157117
+ u8 jointype, /* The JT_* flags on the join */
156991157118
WhereClause *pWC, /* The WHERE clause of the query */
156992157119
Expr *pWhere /* The WHERE clause from the partial index */
156993157120
){
156994157121
int i;
156995157122
WhereTerm *pTerm;
156996
- Parse *pParse = pWC->pWInfo->pParse;
157123
+ Parse *pParse;
157124
+
157125
+ if( jointype & JT_LTORJ ) return 0;
157126
+ pParse = pWC->pWInfo->pParse;
156997157127
while( pWhere->op==TK_AND ){
156998
- if( !whereUsablePartialIndex(iTab,isLeft,pWC,pWhere->pLeft) ) return 0;
157128
+ if( !whereUsablePartialIndex(iTab,jointype,pWC,pWhere->pLeft) ) return 0;
156999157129
pWhere = pWhere->pRight;
157000157130
}
157001157131
if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0;
157002157132
for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
157003157133
Expr *pExpr;
157004157134
pExpr = pTerm->pExpr;
157005157135
if( (!ExprHasProperty(pExpr, EP_OuterON) || pExpr->w.iJoin==iTab)
157006
- && (isLeft==0 || ExprHasProperty(pExpr, EP_OuterON))
157136
+ && ((jointype & JT_OUTER)==0 || ExprHasProperty(pExpr, EP_OuterON))
157007157137
&& sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
157008157138
&& (pTerm->wtFlags & TERM_VNULL)==0
157009157139
){
157010157140
return 1;
157011157141
}
@@ -157167,13 +157297,12 @@
157167157297
/* Loop over all indices. If there was an INDEXED BY clause, then only
157168157298
** consider index pProbe. */
157169157299
for(; rc==SQLITE_OK && pProbe;
157170157300
pProbe=(pSrc->fg.isIndexedBy ? 0 : pProbe->pNext), iSortIdx++
157171157301
){
157172
- int isLeft = (pSrc->fg.jointype & JT_OUTER)!=0;
157173157302
if( pProbe->pPartIdxWhere!=0
157174
- && !whereUsablePartialIndex(pSrc->iCursor, isLeft, pWC,
157303
+ && !whereUsablePartialIndex(pSrc->iCursor, pSrc->fg.jointype, pWC,
157175157304
pProbe->pPartIdxWhere)
157176157305
){
157177157306
testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */
157178157307
continue; /* Partial index inappropriate for this query */
157179157308
}
@@ -236446,11 +236575,11 @@
236446236575
int nArg, /* Number of args */
236447236576
sqlite3_value **apUnused /* Function arguments */
236448236577
){
236449236578
assert( nArg==0 );
236450236579
UNUSED_PARAM2(nArg, apUnused);
236451
- sqlite3_result_text(pCtx, "fts5: 2022-06-03 14:08:40 d18818afc6021a32989499c26ab38fa442e5a55e662e39bb06e5c0daa9c65e25", -1, SQLITE_TRANSIENT);
236580
+ sqlite3_result_text(pCtx, "fts5: 2022-06-15 16:26:37 56c60a35ea457f06db58ec3f694a1ae16fd03e6625da1d7879d63d72bbcb1c62", -1, SQLITE_TRANSIENT);
236452236581
}
236453236582
236454236583
/*
236455236584
** Return true if zName is the extension on one of the shadow tables used
236456236585
** by this module.
236457236586
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.39.0"
456 #define SQLITE_VERSION_NUMBER 3039000
457 #define SQLITE_SOURCE_ID "2022-06-03 14:08:40 d18818afc6021a32989499c26ab38fa442e5a55e662e39bb06e5c0daa9c65e25"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -15724,17 +15724,18 @@
15724 #define OP_VInitIn 174 /* synopsis: r[P2]=ValueList(P1,P3) */
15725 #define OP_VColumn 175 /* synopsis: r[P3]=vcolumn(P2) */
15726 #define OP_VRename 176
15727 #define OP_Pagecount 177
15728 #define OP_MaxPgcnt 178
15729 #define OP_FilterAdd 179 /* synopsis: filter(P1) += key(P3@P4) */
15730 #define OP_Trace 180
15731 #define OP_CursorHint 181
15732 #define OP_ReleaseReg 182 /* synopsis: release r[P1@P2] mask P3 */
15733 #define OP_Noop 183
15734 #define OP_Explain 184
15735 #define OP_Abortable 185
 
15736
15737 /* Properties such as "out2" or "jump" that are specified in
15738 ** comments following the "case" for each opcode in the vdbe.c
15739 ** are encoded into bitvectors as follows:
15740 */
@@ -15765,12 +15766,12 @@
15765 /* 136 */ 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00,\
15766 /* 144 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
15767 /* 152 */ 0x00, 0x10, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
15768 /* 160 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15769 /* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\
15770 /* 176 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
15771 /* 184 */ 0x00, 0x00,}
15772
15773 /* The resolve3P2Values() routine is able to run faster if it knows
15774 ** the value of the largest JUMP opcode. The smaller the maximum
15775 ** JUMP opcode the better, so the mkopcodeh.tcl script that
15776 ** generated this include file strives to group all JUMP opcodes
@@ -18403,10 +18404,11 @@
18403 unsigned isRecursive :1; /* True for recursive reference in WITH */
18404 unsigned fromDDL :1; /* Comes from sqlite_schema */
18405 unsigned isCte :1; /* This is a CTE */
18406 unsigned notCte :1; /* This item may not match a CTE */
18407 unsigned isUsing :1; /* u3.pUsing is valid */
 
18408 unsigned isSynthUsing :1; /* u3.pUsing is synthensized from NATURAL */
18409 unsigned isNestedFrom :1; /* pSelect is a SF_NestedFrom subquery */
18410 } fg;
18411 int iCursor; /* The VDBE cursor number used to access this table */
18412 union {
@@ -22254,11 +22256,11 @@
22254 u8 wrFlag; /* The wrFlag argument to sqlite3BtreeCursor() */
22255 #endif
22256 Bool isEphemeral:1; /* True for an ephemeral table */
22257 Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */
22258 Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
22259 Bool hasBeenDuped:1; /* This cursor was source or target of OP_OpenDup */
22260 u16 seekHit; /* See the OP_SeekHit and OP_IfNoHope opcodes */
22261 union { /* pBtx for isEphermeral. pAltMap otherwise */
22262 Btree *pBtx; /* Separate file holding temporary table */
22263 u32 *aAltMap; /* Mapping from table to index column numbers */
22264 } ub;
@@ -31228,10 +31230,13 @@
31228 sqlite3_str_appendf(&x, " DDL");
31229 }
31230 if( pItem->fg.isCte ){
31231 sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
31232 }
 
 
 
31233 sqlite3StrAccumFinish(&x);
31234 sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
31235 n = 0;
31236 if( pItem->pSelect ) n++;
31237 if( pItem->fg.isTabFunc ) n++;
@@ -35433,17 +35438,18 @@
35433 /* 174 */ "VInitIn" OpHelp("r[P2]=ValueList(P1,P3)"),
35434 /* 175 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
35435 /* 176 */ "VRename" OpHelp(""),
35436 /* 177 */ "Pagecount" OpHelp(""),
35437 /* 178 */ "MaxPgcnt" OpHelp(""),
35438 /* 179 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"),
35439 /* 180 */ "Trace" OpHelp(""),
35440 /* 181 */ "CursorHint" OpHelp(""),
35441 /* 182 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
35442 /* 183 */ "Noop" OpHelp(""),
35443 /* 184 */ "Explain" OpHelp(""),
35444 /* 185 */ "Abortable" OpHelp(""),
 
35445 };
35446 return azName[i];
35447 }
35448 #endif
35449
@@ -56462,10 +56468,11 @@
56462 }else if( (currentSize+szPage)<=newSize ){
56463 char *pTmp = pPager->pTmpSpace;
56464 memset(pTmp, 0, szPage);
56465 testcase( (newSize-szPage) == currentSize );
56466 testcase( (newSize-szPage) > currentSize );
 
56467 rc = sqlite3OsWrite(pPager->fd, pTmp, szPage, newSize-szPage);
56468 }
56469 if( rc==SQLITE_OK ){
56470 pPager->dbFileSize = nPage;
56471 }
@@ -70714,16 +70721,21 @@
70714 eMode = BTALLOC_LE;
70715 iNear = nFin;
70716 }
70717 do {
70718 MemPage *pFreePg;
 
70719 rc = allocateBtreePage(pBt, &pFreePg, &iFreePg, iNear, eMode);
70720 if( rc!=SQLITE_OK ){
70721 releasePage(pLastPg);
70722 return rc;
70723 }
70724 releasePage(pFreePg);
 
 
 
 
70725 }while( bCommit && iFreePg>nFin );
70726 assert( iFreePg<iLastPg );
70727
70728 rc = relocatePage(pBt, pLastPg, eType, iPtrPage, iFreePg, bCommit);
70729 releasePage(pLastPg);
@@ -80228,12 +80240,12 @@
80228 assert( !ExprHasProperty(pExpr, EP_IntValue) );
80229 aff = sqlite3AffinityType(pExpr->u.zToken,0);
80230 rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
80231 testcase( rc!=SQLITE_OK );
80232 if( *ppVal ){
80233 sqlite3VdbeMemCast(*ppVal, aff, SQLITE_UTF8);
80234 sqlite3ValueApplyAffinity(*ppVal, affinity, SQLITE_UTF8);
80235 }
80236 return rc;
80237 }
80238
80239 /* Handle negative integers in a single step. This is needed in the
@@ -89757,14 +89769,19 @@
89757 pOut++;
89758 }while( --n );
89759 break;
89760 }
89761
89762 /* Opcode: Copy P1 P2 P3 * *
89763 ** Synopsis: r[P2@P3+1]=r[P1@P3+1]
89764 **
89765 ** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
 
 
 
 
 
89766 **
89767 ** This instruction makes a deep copy of the value. A duplicate
89768 ** is made of any string or blob constant. See also OP_SCopy.
89769 */
89770 case OP_Copy: {
@@ -89776,10 +89793,13 @@
89776 assert( pOut!=pIn1 );
89777 while( 1 ){
89778 memAboutToChange(p, pOut);
89779 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
89780 Deephemeralize(pOut);
 
 
 
89781 #ifdef SQLITE_DEBUG
89782 pOut->pScopyFrom = 0;
89783 #endif
89784 REGISTER_TRACE(pOp->p2+pOp->p3-n, pOut);
89785 if( (n--)==0 ) break;
@@ -92158,10 +92178,15 @@
92158 if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
92159 sqlite3ResetOneSchema(db, pOp->p1);
92160 }
92161 p->expired = 1;
92162 rc = SQLITE_SCHEMA;
 
 
 
 
 
92163 }
92164 if( rc ) goto abort_due_to_error;
92165 break;
92166 }
92167
@@ -92457,12 +92482,12 @@
92457 pCx->pKeyInfo = pOrig->pKeyInfo;
92458 pCx->isTable = pOrig->isTable;
92459 pCx->pgnoRoot = pOrig->pgnoRoot;
92460 pCx->isOrdered = pOrig->isOrdered;
92461 pCx->ub.pBtx = pOrig->ub.pBtx;
92462 pCx->hasBeenDuped = 1;
92463 pOrig->hasBeenDuped = 1;
92464 rc = sqlite3BtreeCursor(pCx->ub.pBtx, pCx->pgnoRoot, BTREE_WRCSR,
92465 pCx->pKeyInfo, pCx->uc.pCursor);
92466 /* The sqlite3BtreeCursor() routine can only fail for the first cursor
92467 ** opened for a database. Since there is already an open cursor when this
92468 ** opcode is run, the sqlite3BtreeCursor() cannot fail */
@@ -92525,11 +92550,11 @@
92525 assert( aMem[pOp->p3].flags & MEM_Null );
92526 aMem[pOp->p3].n = 0;
92527 aMem[pOp->p3].z = "";
92528 }
92529 pCx = p->apCsr[pOp->p1];
92530 if( pCx && !pCx->hasBeenDuped && ALWAYS(pOp->p2<=pCx->nField) ){
92531 /* If the ephermeral table is already open and has no duplicates from
92532 ** OP_OpenDup, then erase all existing content so that the table is
92533 ** empty again, rather than creating a new table. */
92534 assert( pCx->isEphemeral );
92535 pCx->seqCount = 0;
@@ -94112,10 +94137,11 @@
94112 ** pseudo-cursor that always gives null rows. */
94113 pC = allocateCursor(p, pOp->p1, 1, CURTYPE_PSEUDO);
94114 if( pC==0 ) goto no_mem;
94115 pC->seekResult = 0;
94116 pC->isTable = 1;
 
94117 pC->uc.pCursor = sqlite3BtreeFakeValidCursor();
94118 }
94119 pC->nullRow = 1;
94120 pC->cacheStatus = CACHE_STALE;
94121 if( pC->eCurType==CURTYPE_BTREE ){
@@ -96244,18 +96270,18 @@
96244 Mem *pDest;
96245 sqlite3_context sContext;
96246
96247 VdbeCursor *pCur = p->apCsr[pOp->p1];
96248 assert( pCur!=0 );
96249 assert( pCur->eCurType==CURTYPE_VTAB );
96250 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
96251 pDest = &aMem[pOp->p3];
96252 memAboutToChange(p, pDest);
96253 if( pCur->nullRow ){
96254 sqlite3VdbeMemSetNull(pDest);
96255 break;
96256 }
 
96257 pVtab = pCur->uc.pVCur->pVtab;
96258 pModule = pVtab->pModule;
96259 assert( pModule->xColumn );
96260 memset(&sContext, 0, sizeof(sContext));
96261 sContext.pOut = pDest;
@@ -96578,10 +96604,21 @@
96578
96579 REGISTER_TRACE(pOp->p3, pOut);
96580 UPDATE_MAX_BLOBSIZE(pOut);
96581 break;
96582 }
 
 
 
 
 
 
 
 
 
 
 
96583
96584 /* Opcode: FilterAdd P1 * P3 P4 *
96585 ** Synopsis: filter(P1) += key(P3@P4)
96586 **
96587 ** Compute a hash on the P4 registers starting with r[P3] and
@@ -108130,13 +108167,29 @@
108130 ** Z is stored in pExpr->pList->a[1].pExpr.
108131 */
108132 case TK_BETWEEN: {
108133 exprCodeBetween(pParse, pExpr, target, 0, 0);
108134 return target;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108135 }
108136 case TK_SPAN:
108137 case TK_COLLATE:
108138 case TK_UPLUS: {
108139 pExpr = pExpr->pLeft;
108140 goto expr_code_doover; /* 2018-04-28: Prevent deep recursion. OSSFuzz. */
108141 }
108142
@@ -135899,31 +135952,37 @@
135899 /* Undo the work of sqlite3SetJoinExpr(). In the expression p, convert every
135900 ** term that is marked with EP_OuterON and w.iJoin==iTable into
135901 ** an ordinary term that omits the EP_OuterON mark.
135902 **
135903 ** This happens when a LEFT JOIN is simplified into an ordinary JOIN.
 
 
 
 
 
 
135904 */
135905 static void unsetJoinExpr(Expr *p, int iTable){
135906 while( p ){
135907 if( ExprHasProperty(p, EP_OuterON)
135908 && (iTable<0 || p->w.iJoin==iTable) ){
135909 ExprClearProperty(p, EP_OuterON);
135910 ExprSetProperty(p, EP_InnerON);
135911 }
135912 if( p->op==TK_COLUMN && p->iTable==iTable ){
135913 ExprClearProperty(p, EP_CanBeNull);
135914 }
135915 if( p->op==TK_FUNCTION ){
135916 assert( ExprUseXList(p) );
135917 if( p->x.pList ){
135918 int i;
135919 for(i=0; i<p->x.pList->nExpr; i++){
135920 unsetJoinExpr(p->x.pList->a[i].pExpr, iTable);
135921 }
135922 }
135923 }
135924 unsetJoinExpr(p->pLeft, iTable);
135925 p = p->pRight;
135926 }
135927 }
135928
135929 /*
@@ -136080,10 +136139,11 @@
136080 */
136081 else if( pRight->u3.pOn ){
136082 sqlite3SetJoinExpr(pRight->u3.pOn, pRight->iCursor, joinType);
136083 p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->u3.pOn);
136084 pRight->u3.pOn = 0;
 
136085 }
136086 }
136087 return 0;
136088 }
136089
@@ -139233,13 +139293,14 @@
139233 static Expr *substExpr(
139234 SubstContext *pSubst, /* Description of the substitution */
139235 Expr *pExpr /* Expr in which substitution occurs */
139236 ){
139237 if( pExpr==0 ) return 0;
139238 if( ExprHasProperty(pExpr, EP_OuterON)
139239 && pExpr->w.iJoin==pSubst->iTable
139240 ){
 
139241 pExpr->w.iJoin = pSubst->iNewTable;
139242 }
139243 if( pExpr->op==TK_COLUMN
139244 && pExpr->iTable==pSubst->iTable
139245 && !ExprHasProperty(pExpr, EP_FixedCol)
@@ -139638,10 +139699,15 @@
139638 ** (27) The subquery may not contain a FULL or RIGHT JOIN unless it
139639 ** is the first element of the parent query.
139640 **
139641 ** (28) The subquery is not a MATERIALIZED CTE.
139642 **
 
 
 
 
 
139643 **
139644 ** In this routine, the "p" parameter is a pointer to the outer query.
139645 ** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
139646 ** uses aggregates.
139647 **
@@ -139764,10 +139830,39 @@
139764 return 0; /* Restriction (27) */
139765 }
139766 if( pSubitem->fg.isCte && pSubitem->u2.pCteUse->eM10d==M10d_Yes ){
139767 return 0; /* (28) */
139768 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139769
139770 /* Restriction (17): If the sub-query is a compound SELECT, then it must
139771 ** use only the UNION ALL operator. And none of the simple select queries
139772 ** that make up the compound SELECT are allowed to be aggregate or distinct
139773 ** queries.
@@ -140156,11 +140251,15 @@
140156 ** found, add it to the pConst structure.
140157 */
140158 static void findConstInWhere(WhereConst *pConst, Expr *pExpr){
140159 Expr *pRight, *pLeft;
140160 if( NEVER(pExpr==0) ) return;
140161 if( ExprHasProperty(pExpr, EP_OuterON) ) return;
 
 
 
 
140162 if( pExpr->op==TK_AND ){
140163 findConstInWhere(pConst, pExpr->pRight);
140164 findConstInWhere(pConst, pExpr->pLeft);
140165 return;
140166 }
@@ -140497,11 +140596,11 @@
140497 nChng++;
140498 pSubq->selFlags |= SF_PushDown;
140499 while( pSubq ){
140500 SubstContext x;
140501 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
140502 unsetJoinExpr(pNew, -1);
140503 x.pParse = pParse;
140504 x.iTable = pSrc->iCursor;
140505 x.iNewTable = pSrc->iCursor;
140506 x.isOuterJoin = 0;
140507 x.pEList = pSubq->pEList;
@@ -142181,11 +142280,12 @@
142181 && OptimizationEnabled(db, SQLITE_SimplifyJoin)
142182 ){
142183 SELECTTRACE(0x100,pParse,p,
142184 ("LEFT-JOIN simplifies to JOIN on term %d\n",i));
142185 pItem->fg.jointype &= ~(JT_LEFT|JT_OUTER);
142186 unsetJoinExpr(p->pWhere, pItem->iCursor);
 
142187 }
142188
142189 /* No futher action if this term of the FROM clause is no a subquery */
142190 if( pSub==0 ) continue;
142191
@@ -145977,11 +146077,11 @@
145977 if( pPk ){
145978 sqlite3VdbeAddOp4Int(v, OP_NotFound,iDataCur,labelContinue,regKey,nKey);
145979 }else{
145980 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue,regOldRowid);
145981 }
145982 VdbeCoverageNeverTaken(v);
145983 }
145984
145985 /* Do FK constraint checks. */
145986 if( hasFK ){
145987 sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngKey);
@@ -154477,10 +154577,11 @@
154477 if( pOp->opcode==OP_Column ){
154478 pOp->opcode = OP_Copy;
154479 pOp->p1 = pOp->p2 + iRegister;
154480 pOp->p2 = pOp->p3;
154481 pOp->p3 = 0;
 
154482 }else if( pOp->opcode==OP_Rowid ){
154483 pOp->opcode = OP_Sequence;
154484 pOp->p1 = iAutoidxCur;
154485 #ifdef SQLITE_ALLOW_ROWID_IN_VIEW
154486 if( iAutoidxCur==0 ){
@@ -154551,18 +154652,21 @@
154551 const Bitmask notReady /* Tables in outer loops of the join */
154552 ){
154553 char aff;
154554 if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
154555 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0;
154556 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
154557 && !ExprHasProperty(pTerm->pExpr, EP_OuterON)
154558 && (pTerm->eOperator & WO_IS)
154559 ){
154560 /* Cannot use an IS term from the WHERE clause as an index driver for
154561 ** the RHS of a LEFT JOIN or for the LHS of a RIGHT JOIN. Such a term
154562 ** can only be used if it is from the ON clause. */
154563 return 0;
 
 
 
154564 }
154565 if( (pTerm->prereqRight & notReady)!=0 ) return 0;
154566 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
154567 if( pTerm->u.x.leftColumn<0 ) return 0;
154568 aff = pSrc->pTab->aCol[pTerm->u.x.leftColumn].affinity;
@@ -154972,17 +155076,24 @@
154972 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
154973 assert( pTerm->u.x.leftColumn>=XN_ROWID );
154974 assert( pTerm->u.x.leftColumn<pTab->nCol );
154975
154976 /* tag-20191211-002: WHERE-clause constraints are not useful to the
154977 ** right-hand table of a LEFT JOIN nor to the left-hand table of a
154978 ** RIGHT JOIN. See tag-20191211-001 for the
154979 ** equivalent restriction for ordinary tables. */
154980 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
154981 && !ExprHasProperty(pTerm->pExpr, EP_OuterON)
154982 ){
154983 continue;
 
 
 
 
 
 
 
154984 }
154985 nTerm++;
154986 pTerm->wtFlags |= TERM_OK;
154987 }
154988
@@ -156628,16 +156739,32 @@
156628 ** to mix with a lower range bound from some other source */
156629 if( pTerm->wtFlags & TERM_LIKEOPT && pTerm->eOperator==WO_LT ) continue;
156630
156631 /* tag-20191211-001: Do not allow constraints from the WHERE clause to
156632 ** be used by the right table of a LEFT JOIN nor by the left table of a
156633 ** RIGHT JOIN. Only constraints in the
156634 ** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */
156635 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
156636 && !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON)
156637 ){
156638 continue;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156639 }
156640
156641 if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
156642 pBuilder->bldFlags1 |= SQLITE_BLDF1_UNIQUE;
156643 }else{
@@ -156985,27 +157112,30 @@
156985 /* Check to see if a partial index with pPartIndexWhere can be used
156986 ** in the current query. Return true if it can be and false if not.
156987 */
156988 static int whereUsablePartialIndex(
156989 int iTab, /* The table for which we want an index */
156990 int isLeft, /* True if iTab is the right table of a LEFT JOIN */
156991 WhereClause *pWC, /* The WHERE clause of the query */
156992 Expr *pWhere /* The WHERE clause from the partial index */
156993 ){
156994 int i;
156995 WhereTerm *pTerm;
156996 Parse *pParse = pWC->pWInfo->pParse;
 
 
 
156997 while( pWhere->op==TK_AND ){
156998 if( !whereUsablePartialIndex(iTab,isLeft,pWC,pWhere->pLeft) ) return 0;
156999 pWhere = pWhere->pRight;
157000 }
157001 if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0;
157002 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
157003 Expr *pExpr;
157004 pExpr = pTerm->pExpr;
157005 if( (!ExprHasProperty(pExpr, EP_OuterON) || pExpr->w.iJoin==iTab)
157006 && (isLeft==0 || ExprHasProperty(pExpr, EP_OuterON))
157007 && sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
157008 && (pTerm->wtFlags & TERM_VNULL)==0
157009 ){
157010 return 1;
157011 }
@@ -157167,13 +157297,12 @@
157167 /* Loop over all indices. If there was an INDEXED BY clause, then only
157168 ** consider index pProbe. */
157169 for(; rc==SQLITE_OK && pProbe;
157170 pProbe=(pSrc->fg.isIndexedBy ? 0 : pProbe->pNext), iSortIdx++
157171 ){
157172 int isLeft = (pSrc->fg.jointype & JT_OUTER)!=0;
157173 if( pProbe->pPartIdxWhere!=0
157174 && !whereUsablePartialIndex(pSrc->iCursor, isLeft, pWC,
157175 pProbe->pPartIdxWhere)
157176 ){
157177 testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */
157178 continue; /* Partial index inappropriate for this query */
157179 }
@@ -236446,11 +236575,11 @@
236446 int nArg, /* Number of args */
236447 sqlite3_value **apUnused /* Function arguments */
236448 ){
236449 assert( nArg==0 );
236450 UNUSED_PARAM2(nArg, apUnused);
236451 sqlite3_result_text(pCtx, "fts5: 2022-06-03 14:08:40 d18818afc6021a32989499c26ab38fa442e5a55e662e39bb06e5c0daa9c65e25", -1, SQLITE_TRANSIENT);
236452 }
236453
236454 /*
236455 ** Return true if zName is the extension on one of the shadow tables used
236456 ** by this module.
236457
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.39.0"
456 #define SQLITE_VERSION_NUMBER 3039000
457 #define SQLITE_SOURCE_ID "2022-06-15 16:26:37 56c60a35ea457f06db58ec3f694a1ae16fd03e6625da1d7879d63d72bbcb1c62"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -15724,17 +15724,18 @@
15724 #define OP_VInitIn 174 /* synopsis: r[P2]=ValueList(P1,P3) */
15725 #define OP_VColumn 175 /* synopsis: r[P3]=vcolumn(P2) */
15726 #define OP_VRename 176
15727 #define OP_Pagecount 177
15728 #define OP_MaxPgcnt 178
15729 #define OP_ClrSubtype 179 /* synopsis: r[P1].subtype = 0 */
15730 #define OP_FilterAdd 180 /* synopsis: filter(P1) += key(P3@P4) */
15731 #define OP_Trace 181
15732 #define OP_CursorHint 182
15733 #define OP_ReleaseReg 183 /* synopsis: release r[P1@P2] mask P3 */
15734 #define OP_Noop 184
15735 #define OP_Explain 185
15736 #define OP_Abortable 186
15737
15738 /* Properties such as "out2" or "jump" that are specified in
15739 ** comments following the "case" for each opcode in the vdbe.c
15740 ** are encoded into bitvectors as follows:
15741 */
@@ -15765,12 +15766,12 @@
15766 /* 136 */ 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00,\
15767 /* 144 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
15768 /* 152 */ 0x00, 0x10, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
15769 /* 160 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15770 /* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\
15771 /* 176 */ 0x00, 0x10, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00,\
15772 /* 184 */ 0x00, 0x00, 0x00,}
15773
15774 /* The resolve3P2Values() routine is able to run faster if it knows
15775 ** the value of the largest JUMP opcode. The smaller the maximum
15776 ** JUMP opcode the better, so the mkopcodeh.tcl script that
15777 ** generated this include file strives to group all JUMP opcodes
@@ -18403,10 +18404,11 @@
18404 unsigned isRecursive :1; /* True for recursive reference in WITH */
18405 unsigned fromDDL :1; /* Comes from sqlite_schema */
18406 unsigned isCte :1; /* This is 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 */
18412 } fg;
18413 int iCursor; /* The VDBE cursor number used to access this table */
18414 union {
@@ -22254,11 +22256,11 @@
22256 u8 wrFlag; /* The wrFlag argument to sqlite3BtreeCursor() */
22257 #endif
22258 Bool isEphemeral:1; /* True for an ephemeral table */
22259 Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */
22260 Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
22261 Bool noReuse:1; /* OpenEphemeral may not reuse this cursor */
22262 u16 seekHit; /* See the OP_SeekHit and OP_IfNoHope opcodes */
22263 union { /* pBtx for isEphermeral. pAltMap otherwise */
22264 Btree *pBtx; /* Separate file holding temporary table */
22265 u32 *aAltMap; /* Mapping from table to index column numbers */
22266 } ub;
@@ -31228,10 +31230,13 @@
31230 sqlite3_str_appendf(&x, " DDL");
31231 }
31232 if( pItem->fg.isCte ){
31233 sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
31234 }
31235 if( pItem->fg.isOn || (pItem->fg.isUsing==0 && pItem->u3.pOn!=0) ){
31236 sqlite3_str_appendf(&x, " ON");
31237 }
31238 sqlite3StrAccumFinish(&x);
31239 sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
31240 n = 0;
31241 if( pItem->pSelect ) n++;
31242 if( pItem->fg.isTabFunc ) n++;
@@ -35433,17 +35438,18 @@
35438 /* 174 */ "VInitIn" OpHelp("r[P2]=ValueList(P1,P3)"),
35439 /* 175 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
35440 /* 176 */ "VRename" OpHelp(""),
35441 /* 177 */ "Pagecount" OpHelp(""),
35442 /* 178 */ "MaxPgcnt" OpHelp(""),
35443 /* 179 */ "ClrSubtype" OpHelp("r[P1].subtype = 0"),
35444 /* 180 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"),
35445 /* 181 */ "Trace" OpHelp(""),
35446 /* 182 */ "CursorHint" OpHelp(""),
35447 /* 183 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
35448 /* 184 */ "Noop" OpHelp(""),
35449 /* 185 */ "Explain" OpHelp(""),
35450 /* 186 */ "Abortable" OpHelp(""),
35451 };
35452 return azName[i];
35453 }
35454 #endif
35455
@@ -56462,10 +56468,11 @@
56468 }else if( (currentSize+szPage)<=newSize ){
56469 char *pTmp = pPager->pTmpSpace;
56470 memset(pTmp, 0, szPage);
56471 testcase( (newSize-szPage) == currentSize );
56472 testcase( (newSize-szPage) > currentSize );
56473 sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_SIZE_HINT, &newSize);
56474 rc = sqlite3OsWrite(pPager->fd, pTmp, szPage, newSize-szPage);
56475 }
56476 if( rc==SQLITE_OK ){
56477 pPager->dbFileSize = nPage;
56478 }
@@ -70714,16 +70721,21 @@
70721 eMode = BTALLOC_LE;
70722 iNear = nFin;
70723 }
70724 do {
70725 MemPage *pFreePg;
70726 Pgno dbSize = btreePagecount(pBt);
70727 rc = allocateBtreePage(pBt, &pFreePg, &iFreePg, iNear, eMode);
70728 if( rc!=SQLITE_OK ){
70729 releasePage(pLastPg);
70730 return rc;
70731 }
70732 releasePage(pFreePg);
70733 if( iFreePg>dbSize ){
70734 releasePage(pLastPg);
70735 return SQLITE_CORRUPT_BKPT;
70736 }
70737 }while( bCommit && iFreePg>nFin );
70738 assert( iFreePg<iLastPg );
70739
70740 rc = relocatePage(pBt, pLastPg, eType, iPtrPage, iFreePg, bCommit);
70741 releasePage(pLastPg);
@@ -80228,12 +80240,12 @@
80240 assert( !ExprHasProperty(pExpr, EP_IntValue) );
80241 aff = sqlite3AffinityType(pExpr->u.zToken,0);
80242 rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
80243 testcase( rc!=SQLITE_OK );
80244 if( *ppVal ){
80245 sqlite3VdbeMemCast(*ppVal, aff, enc);
80246 sqlite3ValueApplyAffinity(*ppVal, affinity, enc);
80247 }
80248 return rc;
80249 }
80250
80251 /* Handle negative integers in a single step. This is needed in the
@@ -89757,14 +89769,19 @@
89769 pOut++;
89770 }while( --n );
89771 break;
89772 }
89773
89774 /* Opcode: Copy P1 P2 P3 * P5
89775 ** Synopsis: r[P2@P3+1]=r[P1@P3+1]
89776 **
89777 ** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
89778 **
89779 ** If the 0x0002 bit of P5 is set then also clear the MEM_Subtype flag in the
89780 ** destination. The 0x0001 bit of P5 indicates that this Copy opcode cannot
89781 ** be merged. The 0x0001 bit is used by the query planner and does not
89782 ** come into play during query execution.
89783 **
89784 ** This instruction makes a deep copy of the value. A duplicate
89785 ** is made of any string or blob constant. See also OP_SCopy.
89786 */
89787 case OP_Copy: {
@@ -89776,10 +89793,13 @@
89793 assert( pOut!=pIn1 );
89794 while( 1 ){
89795 memAboutToChange(p, pOut);
89796 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
89797 Deephemeralize(pOut);
89798 if( (pOut->flags & MEM_Subtype)!=0 && (pOp->p5 & 0x0002)!=0 ){
89799 pOut->flags &= ~MEM_Subtype;
89800 }
89801 #ifdef SQLITE_DEBUG
89802 pOut->pScopyFrom = 0;
89803 #endif
89804 REGISTER_TRACE(pOp->p2+pOp->p3-n, pOut);
89805 if( (n--)==0 ) break;
@@ -92158,10 +92178,15 @@
92178 if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
92179 sqlite3ResetOneSchema(db, pOp->p1);
92180 }
92181 p->expired = 1;
92182 rc = SQLITE_SCHEMA;
92183
92184 /* Set changeCntOn to 0 to prevent the value returned by sqlite3_changes()
92185 ** from being modified in sqlite3VdbeHalt(). If this statement is
92186 ** reprepared, changeCntOn will be set again. */
92187 p->changeCntOn = 0;
92188 }
92189 if( rc ) goto abort_due_to_error;
92190 break;
92191 }
92192
@@ -92457,12 +92482,12 @@
92482 pCx->pKeyInfo = pOrig->pKeyInfo;
92483 pCx->isTable = pOrig->isTable;
92484 pCx->pgnoRoot = pOrig->pgnoRoot;
92485 pCx->isOrdered = pOrig->isOrdered;
92486 pCx->ub.pBtx = pOrig->ub.pBtx;
92487 pCx->noReuse = 1;
92488 pOrig->noReuse = 1;
92489 rc = sqlite3BtreeCursor(pCx->ub.pBtx, pCx->pgnoRoot, BTREE_WRCSR,
92490 pCx->pKeyInfo, pCx->uc.pCursor);
92491 /* The sqlite3BtreeCursor() routine can only fail for the first cursor
92492 ** opened for a database. Since there is already an open cursor when this
92493 ** opcode is run, the sqlite3BtreeCursor() cannot fail */
@@ -92525,11 +92550,11 @@
92550 assert( aMem[pOp->p3].flags & MEM_Null );
92551 aMem[pOp->p3].n = 0;
92552 aMem[pOp->p3].z = "";
92553 }
92554 pCx = p->apCsr[pOp->p1];
92555 if( pCx && !pCx->noReuse && ALWAYS(pOp->p2<=pCx->nField) ){
92556 /* If the ephermeral table is already open and has no duplicates from
92557 ** OP_OpenDup, then erase all existing content so that the table is
92558 ** empty again, rather than creating a new table. */
92559 assert( pCx->isEphemeral );
92560 pCx->seqCount = 0;
@@ -94112,10 +94137,11 @@
94137 ** pseudo-cursor that always gives null rows. */
94138 pC = allocateCursor(p, pOp->p1, 1, CURTYPE_PSEUDO);
94139 if( pC==0 ) goto no_mem;
94140 pC->seekResult = 0;
94141 pC->isTable = 1;
94142 pC->noReuse = 1;
94143 pC->uc.pCursor = sqlite3BtreeFakeValidCursor();
94144 }
94145 pC->nullRow = 1;
94146 pC->cacheStatus = CACHE_STALE;
94147 if( pC->eCurType==CURTYPE_BTREE ){
@@ -96244,18 +96270,18 @@
96270 Mem *pDest;
96271 sqlite3_context sContext;
96272
96273 VdbeCursor *pCur = p->apCsr[pOp->p1];
96274 assert( pCur!=0 );
 
96275 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
96276 pDest = &aMem[pOp->p3];
96277 memAboutToChange(p, pDest);
96278 if( pCur->nullRow ){
96279 sqlite3VdbeMemSetNull(pDest);
96280 break;
96281 }
96282 assert( pCur->eCurType==CURTYPE_VTAB );
96283 pVtab = pCur->uc.pVCur->pVtab;
96284 pModule = pVtab->pModule;
96285 assert( pModule->xColumn );
96286 memset(&sContext, 0, sizeof(sContext));
96287 sContext.pOut = pDest;
@@ -96578,10 +96604,21 @@
96604
96605 REGISTER_TRACE(pOp->p3, pOut);
96606 UPDATE_MAX_BLOBSIZE(pOut);
96607 break;
96608 }
96609
96610 /* Opcode: ClrSubtype P1 * * * *
96611 ** Synopsis: r[P1].subtype = 0
96612 **
96613 ** Clear the subtype from register P1.
96614 */
96615 case OP_ClrSubtype: { /* in1 */
96616 pIn1 = &aMem[pOp->p1];
96617 pIn1->flags &= ~MEM_Subtype;
96618 break;
96619 }
96620
96621 /* Opcode: FilterAdd P1 * P3 P4 *
96622 ** Synopsis: filter(P1) += key(P3@P4)
96623 **
96624 ** Compute a hash on the P4 registers starting with r[P3] and
@@ -108130,13 +108167,29 @@
108167 ** Z is stored in pExpr->pList->a[1].pExpr.
108168 */
108169 case TK_BETWEEN: {
108170 exprCodeBetween(pParse, pExpr, target, 0, 0);
108171 return target;
108172 }
108173 case TK_COLLATE: {
108174 if( !ExprHasProperty(pExpr, EP_Collate)
108175 && ALWAYS(pExpr->pLeft)
108176 && pExpr->pLeft->op==TK_FUNCTION
108177 ){
108178 inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
108179 if( inReg!=target ){
108180 sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
108181 inReg = target;
108182 }
108183 sqlite3VdbeAddOp1(v, OP_ClrSubtype, inReg);
108184 return inReg;
108185 }else{
108186 pExpr = pExpr->pLeft;
108187 goto expr_code_doover; /* 2018-04-28: Prevent deep recursion. */
108188 }
108189 }
108190 case TK_SPAN:
 
108191 case TK_UPLUS: {
108192 pExpr = pExpr->pLeft;
108193 goto expr_code_doover; /* 2018-04-28: Prevent deep recursion. OSSFuzz. */
108194 }
108195
@@ -135899,31 +135952,37 @@
135952 /* Undo the work of sqlite3SetJoinExpr(). In the expression p, convert every
135953 ** term that is marked with EP_OuterON and w.iJoin==iTable into
135954 ** an ordinary term that omits the EP_OuterON mark.
135955 **
135956 ** This happens when a LEFT JOIN is simplified into an ordinary JOIN.
135957 **
135958 ** If nullable is true, that means that Expr p might evaluate to NULL even
135959 ** if it is a reference to a NOT NULL column. This can happen, for example,
135960 ** if the table that p references is on the left side of a RIGHT JOIN.
135961 ** If nullable is true, then take care to not remove the EP_CanBeNull bit.
135962 ** See forum thread https://sqlite.org/forum/forumpost/b40696f50145d21c
135963 */
135964 static void unsetJoinExpr(Expr *p, int iTable, int nullable){
135965 while( p ){
135966 if( ExprHasProperty(p, EP_OuterON)
135967 && (iTable<0 || p->w.iJoin==iTable) ){
135968 ExprClearProperty(p, EP_OuterON);
135969 ExprSetProperty(p, EP_InnerON);
135970 }
135971 if( p->op==TK_COLUMN && p->iTable==iTable && !nullable ){
135972 ExprClearProperty(p, EP_CanBeNull);
135973 }
135974 if( p->op==TK_FUNCTION ){
135975 assert( ExprUseXList(p) );
135976 if( p->x.pList ){
135977 int i;
135978 for(i=0; i<p->x.pList->nExpr; i++){
135979 unsetJoinExpr(p->x.pList->a[i].pExpr, iTable, nullable);
135980 }
135981 }
135982 }
135983 unsetJoinExpr(p->pLeft, iTable, nullable);
135984 p = p->pRight;
135985 }
135986 }
135987
135988 /*
@@ -136080,10 +136139,11 @@
136139 */
136140 else if( pRight->u3.pOn ){
136141 sqlite3SetJoinExpr(pRight->u3.pOn, pRight->iCursor, joinType);
136142 p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->u3.pOn);
136143 pRight->u3.pOn = 0;
136144 pRight->fg.isOn = 1;
136145 }
136146 }
136147 return 0;
136148 }
136149
@@ -139233,13 +139293,14 @@
139293 static Expr *substExpr(
139294 SubstContext *pSubst, /* Description of the substitution */
139295 Expr *pExpr /* Expr in which substitution occurs */
139296 ){
139297 if( pExpr==0 ) return 0;
139298 if( ExprHasProperty(pExpr, EP_OuterON|EP_InnerON)
139299 && pExpr->w.iJoin==pSubst->iTable
139300 ){
139301 testcase( ExprHasProperty(pExpr, EP_InnerON) );
139302 pExpr->w.iJoin = pSubst->iNewTable;
139303 }
139304 if( pExpr->op==TK_COLUMN
139305 && pExpr->iTable==pSubst->iTable
139306 && !ExprHasProperty(pExpr, EP_FixedCol)
@@ -139638,10 +139699,15 @@
139699 ** (27) The subquery may not contain a FULL or RIGHT JOIN unless it
139700 ** is the first element of the parent query.
139701 **
139702 ** (28) The subquery is not a MATERIALIZED CTE.
139703 **
139704 ** (29) Either the subquery is not the right-hand operand of a join with an
139705 ** ON or USING clause nor the right-hand operand of a NATURAL JOIN, or
139706 ** the right-most table within the FROM clause of the subquery
139707 ** is not part of an outer join.
139708 **
139709 **
139710 ** In this routine, the "p" parameter is a pointer to the outer query.
139711 ** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
139712 ** uses aggregates.
139713 **
@@ -139764,10 +139830,39 @@
139830 return 0; /* Restriction (27) */
139831 }
139832 if( pSubitem->fg.isCte && pSubitem->u2.pCteUse->eM10d==M10d_Yes ){
139833 return 0; /* (28) */
139834 }
139835
139836 /* Restriction (29):
139837 **
139838 ** We do not want two constraints on the same term of the flattened
139839 ** query where one constraint has EP_InnerON and the other is EP_OuterON.
139840 ** To prevent this, one or the other of the following conditions must be
139841 ** false:
139842 **
139843 ** (29a) The right-most entry in the FROM clause of the subquery
139844 ** must not be part of an outer join.
139845 **
139846 ** (29b) The subquery itself must not be the right operand of a
139847 ** NATURAL join or a join that as an ON or USING clause.
139848 **
139849 ** These conditions are sufficient to keep an EP_OuterON from being
139850 ** flattened into an EP_InnerON. Restrictions (3a) and (27) prevent
139851 ** an EP_InnerON from being flattened into an EP_OuterON.
139852 */
139853 if( pSubSrc->nSrc>=2
139854 && (pSubSrc->a[pSubSrc->nSrc-1].fg.jointype & JT_OUTER)!=0
139855 ){
139856 if( (pSubitem->fg.jointype & JT_NATURAL)!=0
139857 || pSubitem->fg.isUsing
139858 || NEVER(pSubitem->u3.pOn!=0) /* ON clause already shifted into WHERE */
139859 || pSubitem->fg.isOn
139860 ){
139861 return 0;
139862 }
139863 }
139864
139865 /* Restriction (17): If the sub-query is a compound SELECT, then it must
139866 ** use only the UNION ALL operator. And none of the simple select queries
139867 ** that make up the compound SELECT are allowed to be aggregate or distinct
139868 ** queries.
@@ -140156,11 +140251,15 @@
140251 ** found, add it to the pConst structure.
140252 */
140253 static void findConstInWhere(WhereConst *pConst, Expr *pExpr){
140254 Expr *pRight, *pLeft;
140255 if( NEVER(pExpr==0) ) return;
140256 if( ExprHasProperty(pExpr, EP_OuterON|EP_InnerON) ){
140257 testcase( ExprHasProperty(pExpr, EP_OuterON) );
140258 testcase( ExprHasProperty(pExpr, EP_InnerON) );
140259 return;
140260 }
140261 if( pExpr->op==TK_AND ){
140262 findConstInWhere(pConst, pExpr->pRight);
140263 findConstInWhere(pConst, pExpr->pLeft);
140264 return;
140265 }
@@ -140497,11 +140596,11 @@
140596 nChng++;
140597 pSubq->selFlags |= SF_PushDown;
140598 while( pSubq ){
140599 SubstContext x;
140600 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
140601 unsetJoinExpr(pNew, -1, 1);
140602 x.pParse = pParse;
140603 x.iTable = pSrc->iCursor;
140604 x.iNewTable = pSrc->iCursor;
140605 x.isOuterJoin = 0;
140606 x.pEList = pSubq->pEList;
@@ -142181,11 +142280,12 @@
142280 && OptimizationEnabled(db, SQLITE_SimplifyJoin)
142281 ){
142282 SELECTTRACE(0x100,pParse,p,
142283 ("LEFT-JOIN simplifies to JOIN on term %d\n",i));
142284 pItem->fg.jointype &= ~(JT_LEFT|JT_OUTER);
142285 unsetJoinExpr(p->pWhere, pItem->iCursor,
142286 pTabList->a[0].fg.jointype & JT_LTORJ);
142287 }
142288
142289 /* No futher action if this term of the FROM clause is no a subquery */
142290 if( pSub==0 ) continue;
142291
@@ -145977,11 +146077,11 @@
146077 if( pPk ){
146078 sqlite3VdbeAddOp4Int(v, OP_NotFound,iDataCur,labelContinue,regKey,nKey);
146079 }else{
146080 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue,regOldRowid);
146081 }
146082 VdbeCoverage(v);
146083 }
146084
146085 /* Do FK constraint checks. */
146086 if( hasFK ){
146087 sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngKey);
@@ -154477,10 +154577,11 @@
154577 if( pOp->opcode==OP_Column ){
154578 pOp->opcode = OP_Copy;
154579 pOp->p1 = pOp->p2 + iRegister;
154580 pOp->p2 = pOp->p3;
154581 pOp->p3 = 0;
154582 pOp->p5 = 2; /* Cause the MEM_Subtype flag to be cleared */
154583 }else if( pOp->opcode==OP_Rowid ){
154584 pOp->opcode = OP_Sequence;
154585 pOp->p1 = iAutoidxCur;
154586 #ifdef SQLITE_ALLOW_ROWID_IN_VIEW
154587 if( iAutoidxCur==0 ){
@@ -154551,18 +154652,21 @@
154652 const Bitmask notReady /* Tables in outer loops of the join */
154653 ){
154654 char aff;
154655 if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
154656 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0;
154657 assert( (pSrc->fg.jointype & JT_RIGHT)==0 );
154658 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0 ){
154659 testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LEFT );
154660 testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LTORJ );
154661 testcase( ExprHasProperty(pTerm->pExpr, EP_OuterON) )
154662 testcase( ExprHasProperty(pTerm->pExpr, EP_InnerON) );
154663 if( !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON)
154664 || pTerm->pExpr->w.iJoin != pSrc->iCursor
154665 ){
154666 return 0; /* See tag-20191211-001 */
154667 }
154668 }
154669 if( (pTerm->prereqRight & notReady)!=0 ) return 0;
154670 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
154671 if( pTerm->u.x.leftColumn<0 ) return 0;
154672 aff = pSrc->pTab->aCol[pTerm->u.x.leftColumn].affinity;
@@ -154972,17 +155076,24 @@
155076 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
155077 assert( pTerm->u.x.leftColumn>=XN_ROWID );
155078 assert( pTerm->u.x.leftColumn<pTab->nCol );
155079
155080 /* tag-20191211-002: WHERE-clause constraints are not useful to the
155081 ** right-hand table of a LEFT JOIN nor to the either table of a
155082 ** RIGHT JOIN. See tag-20191211-001 for the
155083 ** equivalent restriction for ordinary tables. */
155084 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0 ){
155085 testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LEFT );
155086 testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_RIGHT );
155087 testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LTORJ );
155088 testcase( ExprHasProperty(pTerm->pExpr, EP_OuterON) );
155089 testcase( ExprHasProperty(pTerm->pExpr, EP_InnerON) );
155090 if( !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON)
155091 || pTerm->pExpr->w.iJoin != pSrc->iCursor
155092 ){
155093 continue;
155094 }
155095 }
155096 nTerm++;
155097 pTerm->wtFlags |= TERM_OK;
155098 }
155099
@@ -156628,16 +156739,32 @@
156739 ** to mix with a lower range bound from some other source */
156740 if( pTerm->wtFlags & TERM_LIKEOPT && pTerm->eOperator==WO_LT ) continue;
156741
156742 /* tag-20191211-001: Do not allow constraints from the WHERE clause to
156743 ** be used by the right table of a LEFT JOIN nor by the left table of a
156744 ** RIGHT JOIN. Only constraints in the ON clause are allowed.
156745 ** See tag-20191211-002 for the vtab equivalent.
156746 **
156747 ** 2022-06-06: See https://sqlite.org/forum/forumpost/206d99a16dd9212f
156748 ** for an example of a WHERE clause constraints that may not be used on
156749 ** the right table of a RIGHT JOIN because the constraint implies a
156750 ** not-NULL condition on the left table of the RIGHT JOIN.
156751 **
156752 ** 2022-06-10: The same condition applies to termCanDriveIndex() above.
156753 ** https://sqlite.org/forum/forumpost/51e6959f61
156754 */
156755 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0 ){
156756 testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LEFT );
156757 testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_RIGHT );
156758 testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LTORJ );
156759 testcase( ExprHasProperty(pTerm->pExpr, EP_OuterON) )
156760 testcase( ExprHasProperty(pTerm->pExpr, EP_InnerON) );
156761 if( !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON)
156762 || pTerm->pExpr->w.iJoin != pSrc->iCursor
156763 ){
156764 continue;
156765 }
156766 }
156767
156768 if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
156769 pBuilder->bldFlags1 |= SQLITE_BLDF1_UNIQUE;
156770 }else{
@@ -156985,27 +157112,30 @@
157112 /* Check to see if a partial index with pPartIndexWhere can be used
157113 ** in the current query. Return true if it can be and false if not.
157114 */
157115 static int whereUsablePartialIndex(
157116 int iTab, /* The table for which we want an index */
157117 u8 jointype, /* The JT_* flags on the join */
157118 WhereClause *pWC, /* The WHERE clause of the query */
157119 Expr *pWhere /* The WHERE clause from the partial index */
157120 ){
157121 int i;
157122 WhereTerm *pTerm;
157123 Parse *pParse;
157124
157125 if( jointype & JT_LTORJ ) return 0;
157126 pParse = pWC->pWInfo->pParse;
157127 while( pWhere->op==TK_AND ){
157128 if( !whereUsablePartialIndex(iTab,jointype,pWC,pWhere->pLeft) ) return 0;
157129 pWhere = pWhere->pRight;
157130 }
157131 if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0;
157132 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
157133 Expr *pExpr;
157134 pExpr = pTerm->pExpr;
157135 if( (!ExprHasProperty(pExpr, EP_OuterON) || pExpr->w.iJoin==iTab)
157136 && ((jointype & JT_OUTER)==0 || ExprHasProperty(pExpr, EP_OuterON))
157137 && sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
157138 && (pTerm->wtFlags & TERM_VNULL)==0
157139 ){
157140 return 1;
157141 }
@@ -157167,13 +157297,12 @@
157297 /* Loop over all indices. If there was an INDEXED BY clause, then only
157298 ** consider index pProbe. */
157299 for(; rc==SQLITE_OK && pProbe;
157300 pProbe=(pSrc->fg.isIndexedBy ? 0 : pProbe->pNext), iSortIdx++
157301 ){
 
157302 if( pProbe->pPartIdxWhere!=0
157303 && !whereUsablePartialIndex(pSrc->iCursor, pSrc->fg.jointype, pWC,
157304 pProbe->pPartIdxWhere)
157305 ){
157306 testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */
157307 continue; /* Partial index inappropriate for this query */
157308 }
@@ -236446,11 +236575,11 @@
236575 int nArg, /* Number of args */
236576 sqlite3_value **apUnused /* Function arguments */
236577 ){
236578 assert( nArg==0 );
236579 UNUSED_PARAM2(nArg, apUnused);
236580 sqlite3_result_text(pCtx, "fts5: 2022-06-15 16:26:37 56c60a35ea457f06db58ec3f694a1ae16fd03e6625da1d7879d63d72bbcb1c62", -1, SQLITE_TRANSIENT);
236581 }
236582
236583 /*
236584 ** Return true if zName is the extension on one of the shadow tables used
236585 ** by this module.
236586
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.39.0"
150150
#define SQLITE_VERSION_NUMBER 3039000
151
-#define SQLITE_SOURCE_ID "2022-06-03 14:08:40 d18818afc6021a32989499c26ab38fa442e5a55e662e39bb06e5c0daa9c65e25"
151
+#define SQLITE_SOURCE_ID "2022-06-15 16:26:37 56c60a35ea457f06db58ec3f694a1ae16fd03e6625da1d7879d63d72bbcb1c62"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
157157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.39.0"
150 #define SQLITE_VERSION_NUMBER 3039000
151 #define SQLITE_SOURCE_ID "2022-06-03 14:08:40 d18818afc6021a32989499c26ab38fa442e5a55e662e39bb06e5c0daa9c65e25"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.39.0"
150 #define SQLITE_VERSION_NUMBER 3039000
151 #define SQLITE_SOURCE_ID "2022-06-15 16:26:37 56c60a35ea457f06db58ec3f694a1ae16fd03e6625da1d7879d63d72bbcb1c62"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button