Fossil SCM

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

drh 2023-05-12 12:26 trunk
Commit b2a29bf41f70478d57c576e44504f7cb3df3e93bcb82b6a079642208e07b2b12
+15 -5
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -20665,15 +20665,25 @@
2066520665
}
2066620666
globalDb = p->db;
2066720667
if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
2066820668
utf8_printf(stderr,"Error: unable to open database \"%s\": %s\n",
2066920669
zDbFilename, sqlite3_errmsg(p->db));
20670
- if( openFlags & OPEN_DB_KEEPALIVE ){
20671
- sqlite3_open(":memory:", &p->db);
20672
- return;
20670
+ if( (openFlags & OPEN_DB_KEEPALIVE)==0 ){
20671
+ exit(1);
2067320672
}
20674
- exit(1);
20673
+ sqlite3_close(p->db);
20674
+ sqlite3_open(":memory:", &p->db);
20675
+ if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
20676
+ utf8_printf(stderr,
20677
+ "Also: unable to open substitute in-memory database.\n"
20678
+ );
20679
+ exit(1);
20680
+ }else{
20681
+ utf8_printf(stderr,
20682
+ "Notice: using substitute in-memory database instead of \"%s\"\n",
20683
+ zDbFilename);
20684
+ }
2067520685
}
2067620686
sqlite3_db_config(p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, (int)0, (int*)0);
2067720687
2067820688
/* Reflect the use or absence of --unsafe-testing invocation. */
2067920689
{
@@ -21415,11 +21425,11 @@
2141521425
}
2141621426
while( sqlite3_step(pQuery)==SQLITE_ROW ){
2141721427
zName = sqlite3_column_text(pQuery, 0);
2141821428
zSql = sqlite3_column_text(pQuery, 1);
2141921429
if( zName==0 || zSql==0 ) continue;
21420
- if( sqlite3_stricmp((char*)zName, "sqlite_sequence")!=0 ) continue;
21430
+ if( sqlite3_stricmp((char*)zName, "sqlite_sequence")==0 ) continue;
2142121431
printf("%s... ", zName); fflush(stdout);
2142221432
sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg);
2142321433
if( zErrMsg ){
2142421434
utf8_printf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
2142521435
sqlite3_free(zErrMsg);
2142621436
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -20665,15 +20665,25 @@
20665 }
20666 globalDb = p->db;
20667 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
20668 utf8_printf(stderr,"Error: unable to open database \"%s\": %s\n",
20669 zDbFilename, sqlite3_errmsg(p->db));
20670 if( openFlags & OPEN_DB_KEEPALIVE ){
20671 sqlite3_open(":memory:", &p->db);
20672 return;
20673 }
20674 exit(1);
 
 
 
 
 
 
 
 
 
 
 
20675 }
20676 sqlite3_db_config(p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, (int)0, (int*)0);
20677
20678 /* Reflect the use or absence of --unsafe-testing invocation. */
20679 {
@@ -21415,11 +21425,11 @@
21415 }
21416 while( sqlite3_step(pQuery)==SQLITE_ROW ){
21417 zName = sqlite3_column_text(pQuery, 0);
21418 zSql = sqlite3_column_text(pQuery, 1);
21419 if( zName==0 || zSql==0 ) continue;
21420 if( sqlite3_stricmp((char*)zName, "sqlite_sequence")!=0 ) continue;
21421 printf("%s... ", zName); fflush(stdout);
21422 sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg);
21423 if( zErrMsg ){
21424 utf8_printf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
21425 sqlite3_free(zErrMsg);
21426
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -20665,15 +20665,25 @@
20665 }
20666 globalDb = p->db;
20667 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
20668 utf8_printf(stderr,"Error: unable to open database \"%s\": %s\n",
20669 zDbFilename, sqlite3_errmsg(p->db));
20670 if( (openFlags & OPEN_DB_KEEPALIVE)==0 ){
20671 exit(1);
 
20672 }
20673 sqlite3_close(p->db);
20674 sqlite3_open(":memory:", &p->db);
20675 if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){
20676 utf8_printf(stderr,
20677 "Also: unable to open substitute in-memory database.\n"
20678 );
20679 exit(1);
20680 }else{
20681 utf8_printf(stderr,
20682 "Notice: using substitute in-memory database instead of \"%s\"\n",
20683 zDbFilename);
20684 }
20685 }
20686 sqlite3_db_config(p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, (int)0, (int*)0);
20687
20688 /* Reflect the use or absence of --unsafe-testing invocation. */
20689 {
@@ -21415,11 +21425,11 @@
21425 }
21426 while( sqlite3_step(pQuery)==SQLITE_ROW ){
21427 zName = sqlite3_column_text(pQuery, 0);
21428 zSql = sqlite3_column_text(pQuery, 1);
21429 if( zName==0 || zSql==0 ) continue;
21430 if( sqlite3_stricmp((char*)zName, "sqlite_sequence")==0 ) continue;
21431 printf("%s... ", zName); fflush(stdout);
21432 sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg);
21433 if( zErrMsg ){
21434 utf8_printf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
21435 sqlite3_free(zErrMsg);
21436
+101 -29
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -456,11 +456,11 @@
456456
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
457457
** [sqlite_version()] and [sqlite_source_id()].
458458
*/
459459
#define SQLITE_VERSION "3.42.0"
460460
#define SQLITE_VERSION_NUMBER 3042000
461
-#define SQLITE_SOURCE_ID "2023-05-05 14:16:31 fece588b186c4f9f76d626313e35336fd5681e966e9bd0fa1053b147c4e3c315"
461
+#define SQLITE_SOURCE_ID "2023-05-12 10:52:12 469718f106e1cfa7f8f4714a9e743108c361af81e0258061c2b76880a7c352ae"
462462
463463
/*
464464
** CAPI3REF: Run-Time Library Version Numbers
465465
** KEYWORDS: sqlite3_version sqlite3_sourceid
466466
**
@@ -20506,11 +20506,11 @@
2050620506
SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
2050720507
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
2050820508
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
2050920509
SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
2051020510
SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
20511
-SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr*,const SrcItem*);
20511
+SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcItem*);
2051220512
#ifdef SQLITE_ENABLE_CURSOR_HINTS
2051320513
SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
2051420514
#endif
2051520515
SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*);
2051620516
SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
@@ -30763,11 +30763,11 @@
3076330763
nsd = 16 + flag_altform2*10;
3076430764
bufpt = buf;
3076530765
{
3076630766
i64 szBufNeeded; /* Size of a temporary buffer needed */
3076730767
szBufNeeded = MAX(e2,0)+(i64)precision+(i64)width+15;
30768
- if( cThousand ) szBufNeeded += (e2+2)/3;
30768
+ if( cThousand && e2>0 ) szBufNeeded += (e2+2)/3;
3076930769
if( szBufNeeded > etBUFSIZE ){
3077030770
bufpt = zExtra = printfTempBuf(pAccum, szBufNeeded);
3077130771
if( bufpt==0 ) return;
3077230772
}
3077330773
}
@@ -63217,17 +63217,19 @@
6321763217
** Attempt to take an exclusive lock on the database file. If a PENDING lock
6321863218
** is obtained instead, immediately release it.
6321963219
*/
6322063220
static int pagerExclusiveLock(Pager *pPager){
6322163221
int rc; /* Return code */
63222
+ u8 eOrigLock; /* Original lock */
6322263223
63223
- assert( pPager->eLock==SHARED_LOCK || pPager->eLock==EXCLUSIVE_LOCK );
63224
+ assert( pPager->eLock>=SHARED_LOCK );
63225
+ eOrigLock = pPager->eLock;
6322463226
rc = pagerLockDb(pPager, EXCLUSIVE_LOCK);
6322563227
if( rc!=SQLITE_OK ){
6322663228
/* If the attempt to grab the exclusive lock failed, release the
6322763229
** pending lock that may have been obtained instead. */
63228
- pagerUnlockDb(pPager, SHARED_LOCK);
63230
+ pagerUnlockDb(pPager, eOrigLock);
6322963231
}
6323063232
6323163233
return rc;
6323263234
}
6323363235
@@ -76408,11 +76410,11 @@
7640876410
int nTail = pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray);
7640976411
assert( nCell>=nTail );
7641076412
nCell -= nTail;
7641176413
}
7641276414
76413
- pData = &aData[get2byteNotZero(&aData[hdr+5])];
76415
+ pData = &aData[get2byte(&aData[hdr+5])];
7641476416
if( pData<pBegin ) goto editpage_fail;
7641576417
if( NEVER(pData>pPg->aDataEnd) ) goto editpage_fail;
7641676418
7641776419
/* Add cells to the start of the page */
7641876420
if( iNew<iOld ){
@@ -93137,11 +93139,11 @@
9313793139
}
9313893140
9313993141
/* Opcode: Jump P1 P2 P3 * *
9314093142
**
9314193143
** Jump to the instruction at address P1, P2, or P3 depending on whether
93142
-** in the most recent OP_Compare instruction the P1 vector was less than
93144
+** in the most recent OP_Compare instruction the P1 vector was less than,
9314393145
** equal to, or greater than the P2 vector, respectively.
9314493146
**
9314593147
** This opcode must immediately follow an OP_Compare opcode.
9314693148
*/
9314793149
case OP_Jump: { /* jump */
@@ -99991,11 +99993,11 @@
9999199993
*ppBlob = (sqlite3_blob *)pBlob;
9999299994
}else{
9999399995
if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
9999499996
sqlite3DbFree(db, pBlob);
9999599997
}
99996
- sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
99998
+ sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : (char*)0), zErr);
9999799999
sqlite3DbFree(db, zErr);
99998100000
sqlite3ParseObjectReset(&sParse);
99999100001
rc = sqlite3ApiExit(db, rc);
100000100002
sqlite3_mutex_leave(db->mutex);
100001100003
return rc;
@@ -100150,11 +100152,11 @@
100150100152
}else{
100151100153
char *zErr;
100152100154
((Vdbe*)p->pStmt)->rc = SQLITE_OK;
100153100155
rc = blobSeekToRow(p, iRow, &zErr);
100154100156
if( rc!=SQLITE_OK ){
100155
- sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
100157
+ sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : (char*)0), zErr);
100156100158
sqlite3DbFree(db, zErr);
100157100159
}
100158100160
assert( rc!=SQLITE_SCHEMA );
100159100161
}
100160100162
@@ -108613,16 +108615,20 @@
108613108615
SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
108614108616
return exprIsConst(p, 3, iCur);
108615108617
}
108616108618
108617108619
/*
108618
-** Check pExpr to see if it is an invariant constraint on data source pSrc.
108620
+** Check pExpr to see if it is an constraint on the single data source pSrc.
108621
+** In other words, check to see if pExpr constrains pSrc but does not depend
108622
+** on any other tables or data sources anywhere else in the query. Return
108623
+** true (non-zero) if pExpr is a constraint on pSrc only.
108624
+**
108619108625
** This is an optimization. False negatives will perhaps cause slower
108620108626
** queries, but false positives will yield incorrect answers. So when in
108621108627
** doubt, return 0.
108622108628
**
108623
-** To be an invariant constraint, the following must be true:
108629
+** To be an single-source constraint, the following must be true:
108624108630
**
108625108631
** (1) pExpr cannot refer to any table other than pSrc->iCursor.
108626108632
**
108627108633
** (2) pExpr cannot use subqueries or non-deterministic functions.
108628108634
**
@@ -108635,11 +108641,11 @@
108635108641
**
108636108642
** (5) If pSrc is not the right operand of a LEFT JOIN or the left
108637108643
** operand of a RIGHT JOIN, then pExpr must be from the WHERE
108638108644
** clause, not an ON clause.
108639108645
*/
108640
-SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr *pExpr, const SrcItem *pSrc){
108646
+SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint(Expr *pExpr, const SrcItem *pSrc){
108641108647
if( pSrc->fg.jointype & JT_LTORJ ){
108642108648
return 0; /* rule (3) */
108643108649
}
108644108650
if( pSrc->fg.jointype & JT_LEFT ){
108645108651
if( !ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (4a) */
@@ -124015,10 +124021,11 @@
124015124021
db->enc = enc;
124016124022
/* EVIDENCE-OF: R-08308-17224 The default collating function for all
124017124023
** strings is BINARY.
124018124024
*/
124019124025
db->pDfltColl = sqlite3FindCollSeq(db, enc, sqlite3StrBINARY, 0);
124026
+ sqlite3ExpirePreparedStatements(db, 1);
124020124027
}
124021124028
124022124029
/*
124023124030
** This function is responsible for invoking the collation factory callback
124024124031
** or substituting a collation sequence of a different encoding when the
@@ -144061,25 +144068,49 @@
144061144068
**
144062144069
** (8) If the subquery is a compound that uses UNION, INTERSECT,
144063144070
** or EXCEPT, then all of the result set columns for all arms of
144064144071
** the compound must use the BINARY collating sequence.
144065144072
**
144073
+** (9) All three of the following are true:
144074
+**
144075
+** (9a) The WHERE clause expression originates in the ON or USING clause
144076
+** of a join (either an INNER or an OUTER join), and
144077
+**
144078
+** (9b) The subquery is to the right of the ON/USING clause
144079
+**
144080
+** (9c) There is a RIGHT JOIN (or FULL JOIN) in between the ON/USING
144081
+** clause and the subquery.
144082
+**
144083
+** Without this restriction, the push-down optimization might move
144084
+** the ON/USING filter expression from the left side of a RIGHT JOIN
144085
+** over to the right side, which leads to incorrect answers.
144086
+**
144087
+** (10) The inner query is not the right-hand table of a RIGHT JOIN.
144088
+**
144089
+** (11) The subquery is not a VALUES clause
144066144090
**
144067144091
** Return 0 if no changes are made and non-zero if one or more WHERE clause
144068144092
** terms are duplicated into the subquery.
144069144093
*/
144070144094
static int pushDownWhereTerms(
144071144095
Parse *pParse, /* Parse context (for malloc() and error reporting) */
144072144096
Select *pSubq, /* The subquery whose WHERE clause is to be augmented */
144073144097
Expr *pWhere, /* The WHERE clause of the outer query */
144074
- SrcItem *pSrc /* The subquery term of the outer FROM clause */
144098
+ SrcList *pSrcList, /* The complete from clause of the outer query */
144099
+ int iSrc /* Which FROM clause term to try to push into */
144075144100
){
144076144101
Expr *pNew;
144102
+ SrcItem *pSrc; /* The subquery FROM term into which WHERE is pushed */
144077144103
int nChng = 0;
144104
+ pSrc = &pSrcList->a[iSrc];
144078144105
if( pWhere==0 ) return 0;
144079
- if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ) return 0;
144080
- if( pSrc->fg.jointype & (JT_LTORJ|JT_RIGHT) ) return 0;
144106
+ if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ){
144107
+ return 0; /* restrictions (2) and (11) */
144108
+ }
144109
+ if( pSrc->fg.jointype & (JT_LTORJ|JT_RIGHT) ){
144110
+ return 0; /* restrictions (10) */
144111
+ }
144081144112
144082144113
if( pSubq->pPrior ){
144083144114
Select *pSel;
144084144115
int notUnionAll = 0;
144085144116
for(pSel=pSubq; pSel; pSel=pSel->pPrior){
@@ -144130,15 +144161,33 @@
144130144161
144131144162
if( pSubq->pLimit!=0 ){
144132144163
return 0; /* restriction (3) */
144133144164
}
144134144165
while( pWhere->op==TK_AND ){
144135
- nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, pSrc);
144166
+ nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, pSrcList, iSrc);
144136144167
pWhere = pWhere->pLeft;
144137144168
}
144138144169
144139
-#if 0 /* Legacy code. Checks now done by sqlite3ExprIsTableConstraint() */
144170
+ if( ExprHasProperty(pWhere, EP_OuterON|EP_InnerON) /* (9a) */
144171
+ && (pSrcList->a[0].fg.jointype & JT_LTORJ)!=0 /* Fast pre-test of (9c) */
144172
+ ){
144173
+ int jj;
144174
+ for(jj=0; jj<iSrc; jj++){
144175
+ if( pWhere->w.iJoin==pSrcList->a[jj].iCursor ){
144176
+ /* If we reach this point, both (9a) and (9b) are satisfied.
144177
+ ** The following loop checks (9c):
144178
+ */
144179
+ for(jj++; jj<iSrc; jj++){
144180
+ if( (pSrcList->a[jj].fg.jointype & JT_RIGHT)!=0 ){
144181
+ return 0; /* restriction (9) */
144182
+ }
144183
+ }
144184
+ }
144185
+ }
144186
+ }
144187
+
144188
+#if 0 /* These checks now done by sqlite3ExprIsSingleTableConstraint() */
144140144189
if( isLeftJoin
144141144190
&& (ExprHasProperty(pWhere,EP_OuterON)==0
144142144191
|| pWhere->w.iJoin!=iCursor)
144143144192
){
144144144193
return 0; /* restriction (4) */
@@ -144148,11 +144197,11 @@
144148144197
){
144149144198
return 0; /* restriction (5) */
144150144199
}
144151144200
#endif
144152144201
144153
- if( sqlite3ExprIsTableConstraint(pWhere, pSrc) ){
144202
+ if( sqlite3ExprIsSingleTableConstraint(pWhere, pSrc) ){
144154144203
nChng++;
144155144204
pSubq->selFlags |= SF_PushDown;
144156144205
while( pSubq ){
144157144206
SubstContext x;
144158144207
pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
@@ -146146,11 +146195,11 @@
146146146195
assert( pItem->iCursor>=0 );
146147146196
unsetJoinExpr(p->pWhere, pItem->iCursor,
146148146197
pTabList->a[0].fg.jointype & JT_LTORJ);
146149146198
}
146150146199
146151
- /* No futher action if this term of the FROM clause is no a subquery */
146200
+ /* No futher action if this term of the FROM clause is not a subquery */
146152146201
if( pSub==0 ) continue;
146153146202
146154146203
/* Catch mismatch in the declared columns of a view and the number of
146155146204
** columns in the SELECT on the RHS */
146156146205
if( pTab->nCol!=pSub->pEList->nExpr ){
@@ -146343,11 +146392,11 @@
146343146392
** inside the subquery. This can help the subquery to run more efficiently.
146344146393
*/
146345146394
if( OptimizationEnabled(db, SQLITE_PushDown)
146346146395
&& (pItem->fg.isCte==0
146347146396
|| (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2))
146348
- && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem)
146397
+ && pushDownWhereTerms(pParse, pSub, p->pWhere, pTabList, i)
146349146398
){
146350146399
#if TREETRACE_ENABLED
146351146400
if( sqlite3TreeTrace & 0x4000 ){
146352146401
TREETRACE(0x4000,pParse,p,
146353146402
("After WHERE-clause push-down into subquery %d:\n", pSub->selId));
@@ -158620,11 +158669,11 @@
158620158669
Expr *pExpr = pTerm->pExpr;
158621158670
/* Make the automatic index a partial index if there are terms in the
158622158671
** WHERE clause (or the ON clause of a LEFT join) that constrain which
158623158672
** rows of the target table (pSrc) that can be used. */
158624158673
if( (pTerm->wtFlags & TERM_VIRTUAL)==0
158625
- && sqlite3ExprIsTableConstraint(pExpr, pSrc)
158674
+ && sqlite3ExprIsSingleTableConstraint(pExpr, pSrc)
158626158675
){
158627158676
pPartial = sqlite3ExprAnd(pParse, pPartial,
158628158677
sqlite3ExprDup(pParse->db, pExpr, 0));
158629158678
}
158630158679
if( termCanDriveIndex(pTerm, pSrc, notReady) ){
@@ -158881,11 +158930,11 @@
158881158930
addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v);
158882158931
pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm];
158883158932
for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){
158884158933
Expr *pExpr = pTerm->pExpr;
158885158934
if( (pTerm->wtFlags & TERM_VIRTUAL)==0
158886
- && sqlite3ExprIsTableConstraint(pExpr, pItem)
158935
+ && sqlite3ExprIsSingleTableConstraint(pExpr, pItem)
158887158936
){
158888158937
sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
158889158938
}
158890158939
}
158891158940
if( pLoop->wsFlags & WHERE_IPK ){
@@ -163220,10 +163269,17 @@
163220163269
** 3) Either the query must be DISTINCT, or else the ON or USING clause
163221163270
** must contain a constraint that limits the scan of the table to
163222163271
** at most a single row.
163223163272
** 4) The table must not be referenced by any part of the query apart
163224163273
** from its own USING or ON clause.
163274
+** 5) The table must not have an inner-join ON or USING clause if there is
163275
+** a RIGHT JOIN anywhere in the query. Otherwise the ON/USING clause
163276
+** might move from the right side to the left side of the RIGHT JOIN.
163277
+** Note: Due to (2), this condition can only arise if the table is
163278
+** the right-most table of a subquery that was flattened into the
163279
+** main query and that subquery was the right-hand operand of an
163280
+** inner join that held an ON or USING clause.
163225163281
**
163226163282
** For example, given:
163227163283
**
163228163284
** CREATE TABLE t1(ipk INTEGER PRIMARY KEY, v1);
163229163285
** CREATE TABLE t2(ipk INTEGER PRIMARY KEY, v2);
@@ -163245,10 +163301,11 @@
163245163301
WhereInfo *pWInfo,
163246163302
Bitmask notReady
163247163303
){
163248163304
int i;
163249163305
Bitmask tabUsed;
163306
+ int hasRightJoin;
163250163307
163251163308
/* Preconditions checked by the caller */
163252163309
assert( pWInfo->nLevel>=2 );
163253163310
assert( OptimizationEnabled(pWInfo->pParse->db, SQLITE_OmitNoopJoin) );
163254163311
@@ -163259,10 +163316,11 @@
163259163316
163260163317
tabUsed = sqlite3WhereExprListUsage(&pWInfo->sMaskSet, pWInfo->pResultSet);
163261163318
if( pWInfo->pOrderBy ){
163262163319
tabUsed |= sqlite3WhereExprListUsage(&pWInfo->sMaskSet, pWInfo->pOrderBy);
163263163320
}
163321
+ hasRightJoin = (pWInfo->pTabList->a[0].fg.jointype & JT_LTORJ)!=0;
163264163322
for(i=pWInfo->nLevel-1; i>=1; i--){
163265163323
WhereTerm *pTerm, *pEnd;
163266163324
SrcItem *pItem;
163267163325
WhereLoop *pLoop;
163268163326
pLoop = pWInfo->a[i].pWLoop;
@@ -163281,10 +163339,16 @@
163281163339
|| pTerm->pExpr->w.iJoin!=pItem->iCursor
163282163340
){
163283163341
break;
163284163342
}
163285163343
}
163344
+ if( hasRightJoin
163345
+ && ExprHasProperty(pTerm->pExpr, EP_InnerON)
163346
+ && pTerm->pExpr->w.iJoin==pItem->iCursor
163347
+ ){
163348
+ break; /* restriction (5) */
163349
+ }
163286163350
}
163287163351
if( pTerm<pEnd ) continue;
163288163352
WHERETRACE(0xffffffff, ("-> drop loop %c not used\n", pLoop->cId));
163289163353
notReady &= ~pLoop->maskSelf;
163290163354
for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){
@@ -199762,14 +199826,14 @@
199762199826
199763199827
/*
199764199828
** Maximum nesting depth of JSON for this implementation.
199765199829
**
199766199830
** This limit is needed to avoid a stack overflow in the recursive
199767
-** descent parser. A depth of 2000 is far deeper than any sane JSON
199768
-** should go.
199831
+** descent parser. A depth of 1000 is far deeper than any sane JSON
199832
+** should go. Historical note: This limit was 2000 prior to version 3.42.0
199769199833
*/
199770
-#define JSON_MAX_DEPTH 2000
199834
+#define JSON_MAX_DEPTH 1000
199771199835
199772199836
/**************************************************************************
199773199837
** Utility routines for dealing with JsonString objects
199774199838
**************************************************************************/
199775199839
@@ -200703,10 +200767,11 @@
200703200767
if( ++pParse->iDepth > JSON_MAX_DEPTH ){
200704200768
pParse->iErr = i;
200705200769
return -1;
200706200770
}
200707200771
for(j=i+1;;j++){
200772
+ u32 nNode = pParse->nNode;
200708200773
x = jsonParseValue(pParse, j);
200709200774
if( x<=0 ){
200710200775
if( x==(-2) ){
200711200776
j = pParse->iErr;
200712200777
if( pParse->nNode!=(u32)iThis+1 ) pParse->hasNonstd = 1;
@@ -200729,11 +200794,11 @@
200729200794
if( x!=-1 ) pParse->iErr = j;
200730200795
return -1;
200731200796
}
200732200797
}
200733200798
if( pParse->oom ) return -1;
200734
- pNode = &pParse->aNode[pParse->nNode-1];
200799
+ pNode = &pParse->aNode[nNode];
200735200800
if( pNode->eType!=JSON_STRING ){
200736200801
pParse->iErr = j;
200737200802
return -1;
200738200803
}
200739200804
pNode->jnFlags |= JNODE_LABEL;
@@ -214042,15 +214107,22 @@
214042214107
static int rbuLockDatabase(sqlite3 *db){
214043214108
int rc = SQLITE_OK;
214044214109
sqlite3_file *fd = 0;
214045214110
214046214111
sqlite3_file_control(db, "main", RBU_ZIPVFS_CTRL_FILE_POINTER, &fd);
214047
- if( fd==0 ){
214112
+ if( fd ){
214113
+ sqlite3_file_control(db, "main", SQLITE_FCNTL_FILE_POINTER, &fd);
214114
+ rc = fd->pMethods->xLock(fd, SQLITE_LOCK_SHARED);
214115
+ if( rc==SQLITE_OK ){
214116
+ rc = fd->pMethods->xUnlock(fd, SQLITE_LOCK_NONE);
214117
+ }
214118
+ sqlite3_file_control(db, "main", RBU_ZIPVFS_CTRL_FILE_POINTER, &fd);
214119
+ }else{
214048214120
sqlite3_file_control(db, "main", SQLITE_FCNTL_FILE_POINTER, &fd);
214049214121
}
214050214122
214051
- if( fd->pMethods ){
214123
+ if( rc==SQLITE_OK && fd->pMethods ){
214052214124
rc = fd->pMethods->xLock(fd, SQLITE_LOCK_SHARED);
214053214125
if( rc==SQLITE_OK ){
214054214126
rc = fd->pMethods->xLock(fd, SQLITE_LOCK_EXCLUSIVE);
214055214127
}
214056214128
}
@@ -242473,11 +242545,11 @@
242473242545
int nArg, /* Number of args */
242474242546
sqlite3_value **apUnused /* Function arguments */
242475242547
){
242476242548
assert( nArg==0 );
242477242549
UNUSED_PARAM2(nArg, apUnused);
242478
- sqlite3_result_text(pCtx, "fts5: 2023-05-05 14:16:31 fece588b186c4f9f76d626313e35336fd5681e966e9bd0fa1053b147c4e3c315", -1, SQLITE_TRANSIENT);
242550
+ sqlite3_result_text(pCtx, "fts5: 2023-05-11 21:15:55 3e9c9bbdb59b9d500ff218db538c047c83da7ac18ebb95c3ee7629ab15e0b43a", -1, SQLITE_TRANSIENT);
242479242551
}
242480242552
242481242553
/*
242482242554
** Return true if zName is the extension on one of the shadow tables used
242483242555
** by this module.
242484242556
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -456,11 +456,11 @@
456 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
457 ** [sqlite_version()] and [sqlite_source_id()].
458 */
459 #define SQLITE_VERSION "3.42.0"
460 #define SQLITE_VERSION_NUMBER 3042000
461 #define SQLITE_SOURCE_ID "2023-05-05 14:16:31 fece588b186c4f9f76d626313e35336fd5681e966e9bd0fa1053b147c4e3c315"
462
463 /*
464 ** CAPI3REF: Run-Time Library Version Numbers
465 ** KEYWORDS: sqlite3_version sqlite3_sourceid
466 **
@@ -20506,11 +20506,11 @@
20506 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
20507 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
20508 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
20509 SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
20510 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
20511 SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr*,const SrcItem*);
20512 #ifdef SQLITE_ENABLE_CURSOR_HINTS
20513 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
20514 #endif
20515 SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*);
20516 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
@@ -30763,11 +30763,11 @@
30763 nsd = 16 + flag_altform2*10;
30764 bufpt = buf;
30765 {
30766 i64 szBufNeeded; /* Size of a temporary buffer needed */
30767 szBufNeeded = MAX(e2,0)+(i64)precision+(i64)width+15;
30768 if( cThousand ) szBufNeeded += (e2+2)/3;
30769 if( szBufNeeded > etBUFSIZE ){
30770 bufpt = zExtra = printfTempBuf(pAccum, szBufNeeded);
30771 if( bufpt==0 ) return;
30772 }
30773 }
@@ -63217,17 +63217,19 @@
63217 ** Attempt to take an exclusive lock on the database file. If a PENDING lock
63218 ** is obtained instead, immediately release it.
63219 */
63220 static int pagerExclusiveLock(Pager *pPager){
63221 int rc; /* Return code */
 
63222
63223 assert( pPager->eLock==SHARED_LOCK || pPager->eLock==EXCLUSIVE_LOCK );
 
63224 rc = pagerLockDb(pPager, EXCLUSIVE_LOCK);
63225 if( rc!=SQLITE_OK ){
63226 /* If the attempt to grab the exclusive lock failed, release the
63227 ** pending lock that may have been obtained instead. */
63228 pagerUnlockDb(pPager, SHARED_LOCK);
63229 }
63230
63231 return rc;
63232 }
63233
@@ -76408,11 +76410,11 @@
76408 int nTail = pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray);
76409 assert( nCell>=nTail );
76410 nCell -= nTail;
76411 }
76412
76413 pData = &aData[get2byteNotZero(&aData[hdr+5])];
76414 if( pData<pBegin ) goto editpage_fail;
76415 if( NEVER(pData>pPg->aDataEnd) ) goto editpage_fail;
76416
76417 /* Add cells to the start of the page */
76418 if( iNew<iOld ){
@@ -93137,11 +93139,11 @@
93137 }
93138
93139 /* Opcode: Jump P1 P2 P3 * *
93140 **
93141 ** Jump to the instruction at address P1, P2, or P3 depending on whether
93142 ** in the most recent OP_Compare instruction the P1 vector was less than
93143 ** equal to, or greater than the P2 vector, respectively.
93144 **
93145 ** This opcode must immediately follow an OP_Compare opcode.
93146 */
93147 case OP_Jump: { /* jump */
@@ -99991,11 +99993,11 @@
99991 *ppBlob = (sqlite3_blob *)pBlob;
99992 }else{
99993 if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
99994 sqlite3DbFree(db, pBlob);
99995 }
99996 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
99997 sqlite3DbFree(db, zErr);
99998 sqlite3ParseObjectReset(&sParse);
99999 rc = sqlite3ApiExit(db, rc);
100000 sqlite3_mutex_leave(db->mutex);
100001 return rc;
@@ -100150,11 +100152,11 @@
100150 }else{
100151 char *zErr;
100152 ((Vdbe*)p->pStmt)->rc = SQLITE_OK;
100153 rc = blobSeekToRow(p, iRow, &zErr);
100154 if( rc!=SQLITE_OK ){
100155 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
100156 sqlite3DbFree(db, zErr);
100157 }
100158 assert( rc!=SQLITE_SCHEMA );
100159 }
100160
@@ -108613,16 +108615,20 @@
108613 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
108614 return exprIsConst(p, 3, iCur);
108615 }
108616
108617 /*
108618 ** Check pExpr to see if it is an invariant constraint on data source pSrc.
 
 
 
 
108619 ** This is an optimization. False negatives will perhaps cause slower
108620 ** queries, but false positives will yield incorrect answers. So when in
108621 ** doubt, return 0.
108622 **
108623 ** To be an invariant constraint, the following must be true:
108624 **
108625 ** (1) pExpr cannot refer to any table other than pSrc->iCursor.
108626 **
108627 ** (2) pExpr cannot use subqueries or non-deterministic functions.
108628 **
@@ -108635,11 +108641,11 @@
108635 **
108636 ** (5) If pSrc is not the right operand of a LEFT JOIN or the left
108637 ** operand of a RIGHT JOIN, then pExpr must be from the WHERE
108638 ** clause, not an ON clause.
108639 */
108640 SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr *pExpr, const SrcItem *pSrc){
108641 if( pSrc->fg.jointype & JT_LTORJ ){
108642 return 0; /* rule (3) */
108643 }
108644 if( pSrc->fg.jointype & JT_LEFT ){
108645 if( !ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (4a) */
@@ -124015,10 +124021,11 @@
124015 db->enc = enc;
124016 /* EVIDENCE-OF: R-08308-17224 The default collating function for all
124017 ** strings is BINARY.
124018 */
124019 db->pDfltColl = sqlite3FindCollSeq(db, enc, sqlite3StrBINARY, 0);
 
124020 }
124021
124022 /*
124023 ** This function is responsible for invoking the collation factory callback
124024 ** or substituting a collation sequence of a different encoding when the
@@ -144061,25 +144068,49 @@
144061 **
144062 ** (8) If the subquery is a compound that uses UNION, INTERSECT,
144063 ** or EXCEPT, then all of the result set columns for all arms of
144064 ** the compound must use the BINARY collating sequence.
144065 **
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144066 **
144067 ** Return 0 if no changes are made and non-zero if one or more WHERE clause
144068 ** terms are duplicated into the subquery.
144069 */
144070 static int pushDownWhereTerms(
144071 Parse *pParse, /* Parse context (for malloc() and error reporting) */
144072 Select *pSubq, /* The subquery whose WHERE clause is to be augmented */
144073 Expr *pWhere, /* The WHERE clause of the outer query */
144074 SrcItem *pSrc /* The subquery term of the outer FROM clause */
 
144075 ){
144076 Expr *pNew;
 
144077 int nChng = 0;
 
144078 if( pWhere==0 ) return 0;
144079 if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ) return 0;
144080 if( pSrc->fg.jointype & (JT_LTORJ|JT_RIGHT) ) return 0;
 
 
 
 
144081
144082 if( pSubq->pPrior ){
144083 Select *pSel;
144084 int notUnionAll = 0;
144085 for(pSel=pSubq; pSel; pSel=pSel->pPrior){
@@ -144130,15 +144161,33 @@
144130
144131 if( pSubq->pLimit!=0 ){
144132 return 0; /* restriction (3) */
144133 }
144134 while( pWhere->op==TK_AND ){
144135 nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, pSrc);
144136 pWhere = pWhere->pLeft;
144137 }
144138
144139 #if 0 /* Legacy code. Checks now done by sqlite3ExprIsTableConstraint() */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144140 if( isLeftJoin
144141 && (ExprHasProperty(pWhere,EP_OuterON)==0
144142 || pWhere->w.iJoin!=iCursor)
144143 ){
144144 return 0; /* restriction (4) */
@@ -144148,11 +144197,11 @@
144148 ){
144149 return 0; /* restriction (5) */
144150 }
144151 #endif
144152
144153 if( sqlite3ExprIsTableConstraint(pWhere, pSrc) ){
144154 nChng++;
144155 pSubq->selFlags |= SF_PushDown;
144156 while( pSubq ){
144157 SubstContext x;
144158 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
@@ -146146,11 +146195,11 @@
146146 assert( pItem->iCursor>=0 );
146147 unsetJoinExpr(p->pWhere, pItem->iCursor,
146148 pTabList->a[0].fg.jointype & JT_LTORJ);
146149 }
146150
146151 /* No futher action if this term of the FROM clause is no a subquery */
146152 if( pSub==0 ) continue;
146153
146154 /* Catch mismatch in the declared columns of a view and the number of
146155 ** columns in the SELECT on the RHS */
146156 if( pTab->nCol!=pSub->pEList->nExpr ){
@@ -146343,11 +146392,11 @@
146343 ** inside the subquery. This can help the subquery to run more efficiently.
146344 */
146345 if( OptimizationEnabled(db, SQLITE_PushDown)
146346 && (pItem->fg.isCte==0
146347 || (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2))
146348 && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem)
146349 ){
146350 #if TREETRACE_ENABLED
146351 if( sqlite3TreeTrace & 0x4000 ){
146352 TREETRACE(0x4000,pParse,p,
146353 ("After WHERE-clause push-down into subquery %d:\n", pSub->selId));
@@ -158620,11 +158669,11 @@
158620 Expr *pExpr = pTerm->pExpr;
158621 /* Make the automatic index a partial index if there are terms in the
158622 ** WHERE clause (or the ON clause of a LEFT join) that constrain which
158623 ** rows of the target table (pSrc) that can be used. */
158624 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
158625 && sqlite3ExprIsTableConstraint(pExpr, pSrc)
158626 ){
158627 pPartial = sqlite3ExprAnd(pParse, pPartial,
158628 sqlite3ExprDup(pParse->db, pExpr, 0));
158629 }
158630 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
@@ -158881,11 +158930,11 @@
158881 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v);
158882 pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm];
158883 for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){
158884 Expr *pExpr = pTerm->pExpr;
158885 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
158886 && sqlite3ExprIsTableConstraint(pExpr, pItem)
158887 ){
158888 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
158889 }
158890 }
158891 if( pLoop->wsFlags & WHERE_IPK ){
@@ -163220,10 +163269,17 @@
163220 ** 3) Either the query must be DISTINCT, or else the ON or USING clause
163221 ** must contain a constraint that limits the scan of the table to
163222 ** at most a single row.
163223 ** 4) The table must not be referenced by any part of the query apart
163224 ** from its own USING or ON clause.
 
 
 
 
 
 
 
163225 **
163226 ** For example, given:
163227 **
163228 ** CREATE TABLE t1(ipk INTEGER PRIMARY KEY, v1);
163229 ** CREATE TABLE t2(ipk INTEGER PRIMARY KEY, v2);
@@ -163245,10 +163301,11 @@
163245 WhereInfo *pWInfo,
163246 Bitmask notReady
163247 ){
163248 int i;
163249 Bitmask tabUsed;
 
163250
163251 /* Preconditions checked by the caller */
163252 assert( pWInfo->nLevel>=2 );
163253 assert( OptimizationEnabled(pWInfo->pParse->db, SQLITE_OmitNoopJoin) );
163254
@@ -163259,10 +163316,11 @@
163259
163260 tabUsed = sqlite3WhereExprListUsage(&pWInfo->sMaskSet, pWInfo->pResultSet);
163261 if( pWInfo->pOrderBy ){
163262 tabUsed |= sqlite3WhereExprListUsage(&pWInfo->sMaskSet, pWInfo->pOrderBy);
163263 }
 
163264 for(i=pWInfo->nLevel-1; i>=1; i--){
163265 WhereTerm *pTerm, *pEnd;
163266 SrcItem *pItem;
163267 WhereLoop *pLoop;
163268 pLoop = pWInfo->a[i].pWLoop;
@@ -163281,10 +163339,16 @@
163281 || pTerm->pExpr->w.iJoin!=pItem->iCursor
163282 ){
163283 break;
163284 }
163285 }
 
 
 
 
 
 
163286 }
163287 if( pTerm<pEnd ) continue;
163288 WHERETRACE(0xffffffff, ("-> drop loop %c not used\n", pLoop->cId));
163289 notReady &= ~pLoop->maskSelf;
163290 for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){
@@ -199762,14 +199826,14 @@
199762
199763 /*
199764 ** Maximum nesting depth of JSON for this implementation.
199765 **
199766 ** This limit is needed to avoid a stack overflow in the recursive
199767 ** descent parser. A depth of 2000 is far deeper than any sane JSON
199768 ** should go.
199769 */
199770 #define JSON_MAX_DEPTH 2000
199771
199772 /**************************************************************************
199773 ** Utility routines for dealing with JsonString objects
199774 **************************************************************************/
199775
@@ -200703,10 +200767,11 @@
200703 if( ++pParse->iDepth > JSON_MAX_DEPTH ){
200704 pParse->iErr = i;
200705 return -1;
200706 }
200707 for(j=i+1;;j++){
 
200708 x = jsonParseValue(pParse, j);
200709 if( x<=0 ){
200710 if( x==(-2) ){
200711 j = pParse->iErr;
200712 if( pParse->nNode!=(u32)iThis+1 ) pParse->hasNonstd = 1;
@@ -200729,11 +200794,11 @@
200729 if( x!=-1 ) pParse->iErr = j;
200730 return -1;
200731 }
200732 }
200733 if( pParse->oom ) return -1;
200734 pNode = &pParse->aNode[pParse->nNode-1];
200735 if( pNode->eType!=JSON_STRING ){
200736 pParse->iErr = j;
200737 return -1;
200738 }
200739 pNode->jnFlags |= JNODE_LABEL;
@@ -214042,15 +214107,22 @@
214042 static int rbuLockDatabase(sqlite3 *db){
214043 int rc = SQLITE_OK;
214044 sqlite3_file *fd = 0;
214045
214046 sqlite3_file_control(db, "main", RBU_ZIPVFS_CTRL_FILE_POINTER, &fd);
214047 if( fd==0 ){
 
 
 
 
 
 
 
214048 sqlite3_file_control(db, "main", SQLITE_FCNTL_FILE_POINTER, &fd);
214049 }
214050
214051 if( fd->pMethods ){
214052 rc = fd->pMethods->xLock(fd, SQLITE_LOCK_SHARED);
214053 if( rc==SQLITE_OK ){
214054 rc = fd->pMethods->xLock(fd, SQLITE_LOCK_EXCLUSIVE);
214055 }
214056 }
@@ -242473,11 +242545,11 @@
242473 int nArg, /* Number of args */
242474 sqlite3_value **apUnused /* Function arguments */
242475 ){
242476 assert( nArg==0 );
242477 UNUSED_PARAM2(nArg, apUnused);
242478 sqlite3_result_text(pCtx, "fts5: 2023-05-05 14:16:31 fece588b186c4f9f76d626313e35336fd5681e966e9bd0fa1053b147c4e3c315", -1, SQLITE_TRANSIENT);
242479 }
242480
242481 /*
242482 ** Return true if zName is the extension on one of the shadow tables used
242483 ** by this module.
242484
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -456,11 +456,11 @@
456 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
457 ** [sqlite_version()] and [sqlite_source_id()].
458 */
459 #define SQLITE_VERSION "3.42.0"
460 #define SQLITE_VERSION_NUMBER 3042000
461 #define SQLITE_SOURCE_ID "2023-05-12 10:52:12 469718f106e1cfa7f8f4714a9e743108c361af81e0258061c2b76880a7c352ae"
462
463 /*
464 ** CAPI3REF: Run-Time Library Version Numbers
465 ** KEYWORDS: sqlite3_version sqlite3_sourceid
466 **
@@ -20506,11 +20506,11 @@
20506 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
20507 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
20508 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
20509 SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
20510 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
20511 SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcItem*);
20512 #ifdef SQLITE_ENABLE_CURSOR_HINTS
20513 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
20514 #endif
20515 SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*);
20516 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
@@ -30763,11 +30763,11 @@
30763 nsd = 16 + flag_altform2*10;
30764 bufpt = buf;
30765 {
30766 i64 szBufNeeded; /* Size of a temporary buffer needed */
30767 szBufNeeded = MAX(e2,0)+(i64)precision+(i64)width+15;
30768 if( cThousand && e2>0 ) szBufNeeded += (e2+2)/3;
30769 if( szBufNeeded > etBUFSIZE ){
30770 bufpt = zExtra = printfTempBuf(pAccum, szBufNeeded);
30771 if( bufpt==0 ) return;
30772 }
30773 }
@@ -63217,17 +63217,19 @@
63217 ** Attempt to take an exclusive lock on the database file. If a PENDING lock
63218 ** is obtained instead, immediately release it.
63219 */
63220 static int pagerExclusiveLock(Pager *pPager){
63221 int rc; /* Return code */
63222 u8 eOrigLock; /* Original lock */
63223
63224 assert( pPager->eLock>=SHARED_LOCK );
63225 eOrigLock = pPager->eLock;
63226 rc = pagerLockDb(pPager, EXCLUSIVE_LOCK);
63227 if( rc!=SQLITE_OK ){
63228 /* If the attempt to grab the exclusive lock failed, release the
63229 ** pending lock that may have been obtained instead. */
63230 pagerUnlockDb(pPager, eOrigLock);
63231 }
63232
63233 return rc;
63234 }
63235
@@ -76408,11 +76410,11 @@
76410 int nTail = pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray);
76411 assert( nCell>=nTail );
76412 nCell -= nTail;
76413 }
76414
76415 pData = &aData[get2byte(&aData[hdr+5])];
76416 if( pData<pBegin ) goto editpage_fail;
76417 if( NEVER(pData>pPg->aDataEnd) ) goto editpage_fail;
76418
76419 /* Add cells to the start of the page */
76420 if( iNew<iOld ){
@@ -93137,11 +93139,11 @@
93139 }
93140
93141 /* Opcode: Jump P1 P2 P3 * *
93142 **
93143 ** Jump to the instruction at address P1, P2, or P3 depending on whether
93144 ** in the most recent OP_Compare instruction the P1 vector was less than,
93145 ** equal to, or greater than the P2 vector, respectively.
93146 **
93147 ** This opcode must immediately follow an OP_Compare opcode.
93148 */
93149 case OP_Jump: { /* jump */
@@ -99991,11 +99993,11 @@
99993 *ppBlob = (sqlite3_blob *)pBlob;
99994 }else{
99995 if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
99996 sqlite3DbFree(db, pBlob);
99997 }
99998 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : (char*)0), zErr);
99999 sqlite3DbFree(db, zErr);
100000 sqlite3ParseObjectReset(&sParse);
100001 rc = sqlite3ApiExit(db, rc);
100002 sqlite3_mutex_leave(db->mutex);
100003 return rc;
@@ -100150,11 +100152,11 @@
100152 }else{
100153 char *zErr;
100154 ((Vdbe*)p->pStmt)->rc = SQLITE_OK;
100155 rc = blobSeekToRow(p, iRow, &zErr);
100156 if( rc!=SQLITE_OK ){
100157 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : (char*)0), zErr);
100158 sqlite3DbFree(db, zErr);
100159 }
100160 assert( rc!=SQLITE_SCHEMA );
100161 }
100162
@@ -108613,16 +108615,20 @@
108615 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
108616 return exprIsConst(p, 3, iCur);
108617 }
108618
108619 /*
108620 ** Check pExpr to see if it is an constraint on the single data source pSrc.
108621 ** In other words, check to see if pExpr constrains pSrc but does not depend
108622 ** on any other tables or data sources anywhere else in the query. Return
108623 ** true (non-zero) if pExpr is a constraint on pSrc only.
108624 **
108625 ** This is an optimization. False negatives will perhaps cause slower
108626 ** queries, but false positives will yield incorrect answers. So when in
108627 ** doubt, return 0.
108628 **
108629 ** To be an single-source constraint, the following must be true:
108630 **
108631 ** (1) pExpr cannot refer to any table other than pSrc->iCursor.
108632 **
108633 ** (2) pExpr cannot use subqueries or non-deterministic functions.
108634 **
@@ -108635,11 +108641,11 @@
108641 **
108642 ** (5) If pSrc is not the right operand of a LEFT JOIN or the left
108643 ** operand of a RIGHT JOIN, then pExpr must be from the WHERE
108644 ** clause, not an ON clause.
108645 */
108646 SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint(Expr *pExpr, const SrcItem *pSrc){
108647 if( pSrc->fg.jointype & JT_LTORJ ){
108648 return 0; /* rule (3) */
108649 }
108650 if( pSrc->fg.jointype & JT_LEFT ){
108651 if( !ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (4a) */
@@ -124015,10 +124021,11 @@
124021 db->enc = enc;
124022 /* EVIDENCE-OF: R-08308-17224 The default collating function for all
124023 ** strings is BINARY.
124024 */
124025 db->pDfltColl = sqlite3FindCollSeq(db, enc, sqlite3StrBINARY, 0);
124026 sqlite3ExpirePreparedStatements(db, 1);
124027 }
124028
124029 /*
124030 ** This function is responsible for invoking the collation factory callback
124031 ** or substituting a collation sequence of a different encoding when the
@@ -144061,25 +144068,49 @@
144068 **
144069 ** (8) If the subquery is a compound that uses UNION, INTERSECT,
144070 ** or EXCEPT, then all of the result set columns for all arms of
144071 ** the compound must use the BINARY collating sequence.
144072 **
144073 ** (9) All three of the following are true:
144074 **
144075 ** (9a) The WHERE clause expression originates in the ON or USING clause
144076 ** of a join (either an INNER or an OUTER join), and
144077 **
144078 ** (9b) The subquery is to the right of the ON/USING clause
144079 **
144080 ** (9c) There is a RIGHT JOIN (or FULL JOIN) in between the ON/USING
144081 ** clause and the subquery.
144082 **
144083 ** Without this restriction, the push-down optimization might move
144084 ** the ON/USING filter expression from the left side of a RIGHT JOIN
144085 ** over to the right side, which leads to incorrect answers.
144086 **
144087 ** (10) The inner query is not the right-hand table of a RIGHT JOIN.
144088 **
144089 ** (11) The subquery is not a VALUES clause
144090 **
144091 ** Return 0 if no changes are made and non-zero if one or more WHERE clause
144092 ** terms are duplicated into the subquery.
144093 */
144094 static int pushDownWhereTerms(
144095 Parse *pParse, /* Parse context (for malloc() and error reporting) */
144096 Select *pSubq, /* The subquery whose WHERE clause is to be augmented */
144097 Expr *pWhere, /* The WHERE clause of the outer query */
144098 SrcList *pSrcList, /* The complete from clause of the outer query */
144099 int iSrc /* Which FROM clause term to try to push into */
144100 ){
144101 Expr *pNew;
144102 SrcItem *pSrc; /* The subquery FROM term into which WHERE is pushed */
144103 int nChng = 0;
144104 pSrc = &pSrcList->a[iSrc];
144105 if( pWhere==0 ) return 0;
144106 if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ){
144107 return 0; /* restrictions (2) and (11) */
144108 }
144109 if( pSrc->fg.jointype & (JT_LTORJ|JT_RIGHT) ){
144110 return 0; /* restrictions (10) */
144111 }
144112
144113 if( pSubq->pPrior ){
144114 Select *pSel;
144115 int notUnionAll = 0;
144116 for(pSel=pSubq; pSel; pSel=pSel->pPrior){
@@ -144130,15 +144161,33 @@
144161
144162 if( pSubq->pLimit!=0 ){
144163 return 0; /* restriction (3) */
144164 }
144165 while( pWhere->op==TK_AND ){
144166 nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, pSrcList, iSrc);
144167 pWhere = pWhere->pLeft;
144168 }
144169
144170 if( ExprHasProperty(pWhere, EP_OuterON|EP_InnerON) /* (9a) */
144171 && (pSrcList->a[0].fg.jointype & JT_LTORJ)!=0 /* Fast pre-test of (9c) */
144172 ){
144173 int jj;
144174 for(jj=0; jj<iSrc; jj++){
144175 if( pWhere->w.iJoin==pSrcList->a[jj].iCursor ){
144176 /* If we reach this point, both (9a) and (9b) are satisfied.
144177 ** The following loop checks (9c):
144178 */
144179 for(jj++; jj<iSrc; jj++){
144180 if( (pSrcList->a[jj].fg.jointype & JT_RIGHT)!=0 ){
144181 return 0; /* restriction (9) */
144182 }
144183 }
144184 }
144185 }
144186 }
144187
144188 #if 0 /* These checks now done by sqlite3ExprIsSingleTableConstraint() */
144189 if( isLeftJoin
144190 && (ExprHasProperty(pWhere,EP_OuterON)==0
144191 || pWhere->w.iJoin!=iCursor)
144192 ){
144193 return 0; /* restriction (4) */
@@ -144148,11 +144197,11 @@
144197 ){
144198 return 0; /* restriction (5) */
144199 }
144200 #endif
144201
144202 if( sqlite3ExprIsSingleTableConstraint(pWhere, pSrc) ){
144203 nChng++;
144204 pSubq->selFlags |= SF_PushDown;
144205 while( pSubq ){
144206 SubstContext x;
144207 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
@@ -146146,11 +146195,11 @@
146195 assert( pItem->iCursor>=0 );
146196 unsetJoinExpr(p->pWhere, pItem->iCursor,
146197 pTabList->a[0].fg.jointype & JT_LTORJ);
146198 }
146199
146200 /* No futher action if this term of the FROM clause is not a subquery */
146201 if( pSub==0 ) continue;
146202
146203 /* Catch mismatch in the declared columns of a view and the number of
146204 ** columns in the SELECT on the RHS */
146205 if( pTab->nCol!=pSub->pEList->nExpr ){
@@ -146343,11 +146392,11 @@
146392 ** inside the subquery. This can help the subquery to run more efficiently.
146393 */
146394 if( OptimizationEnabled(db, SQLITE_PushDown)
146395 && (pItem->fg.isCte==0
146396 || (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2))
146397 && pushDownWhereTerms(pParse, pSub, p->pWhere, pTabList, i)
146398 ){
146399 #if TREETRACE_ENABLED
146400 if( sqlite3TreeTrace & 0x4000 ){
146401 TREETRACE(0x4000,pParse,p,
146402 ("After WHERE-clause push-down into subquery %d:\n", pSub->selId));
@@ -158620,11 +158669,11 @@
158669 Expr *pExpr = pTerm->pExpr;
158670 /* Make the automatic index a partial index if there are terms in the
158671 ** WHERE clause (or the ON clause of a LEFT join) that constrain which
158672 ** rows of the target table (pSrc) that can be used. */
158673 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
158674 && sqlite3ExprIsSingleTableConstraint(pExpr, pSrc)
158675 ){
158676 pPartial = sqlite3ExprAnd(pParse, pPartial,
158677 sqlite3ExprDup(pParse->db, pExpr, 0));
158678 }
158679 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
@@ -158881,11 +158930,11 @@
158930 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v);
158931 pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm];
158932 for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){
158933 Expr *pExpr = pTerm->pExpr;
158934 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
158935 && sqlite3ExprIsSingleTableConstraint(pExpr, pItem)
158936 ){
158937 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
158938 }
158939 }
158940 if( pLoop->wsFlags & WHERE_IPK ){
@@ -163220,10 +163269,17 @@
163269 ** 3) Either the query must be DISTINCT, or else the ON or USING clause
163270 ** must contain a constraint that limits the scan of the table to
163271 ** at most a single row.
163272 ** 4) The table must not be referenced by any part of the query apart
163273 ** from its own USING or ON clause.
163274 ** 5) The table must not have an inner-join ON or USING clause if there is
163275 ** a RIGHT JOIN anywhere in the query. Otherwise the ON/USING clause
163276 ** might move from the right side to the left side of the RIGHT JOIN.
163277 ** Note: Due to (2), this condition can only arise if the table is
163278 ** the right-most table of a subquery that was flattened into the
163279 ** main query and that subquery was the right-hand operand of an
163280 ** inner join that held an ON or USING clause.
163281 **
163282 ** For example, given:
163283 **
163284 ** CREATE TABLE t1(ipk INTEGER PRIMARY KEY, v1);
163285 ** CREATE TABLE t2(ipk INTEGER PRIMARY KEY, v2);
@@ -163245,10 +163301,11 @@
163301 WhereInfo *pWInfo,
163302 Bitmask notReady
163303 ){
163304 int i;
163305 Bitmask tabUsed;
163306 int hasRightJoin;
163307
163308 /* Preconditions checked by the caller */
163309 assert( pWInfo->nLevel>=2 );
163310 assert( OptimizationEnabled(pWInfo->pParse->db, SQLITE_OmitNoopJoin) );
163311
@@ -163259,10 +163316,11 @@
163316
163317 tabUsed = sqlite3WhereExprListUsage(&pWInfo->sMaskSet, pWInfo->pResultSet);
163318 if( pWInfo->pOrderBy ){
163319 tabUsed |= sqlite3WhereExprListUsage(&pWInfo->sMaskSet, pWInfo->pOrderBy);
163320 }
163321 hasRightJoin = (pWInfo->pTabList->a[0].fg.jointype & JT_LTORJ)!=0;
163322 for(i=pWInfo->nLevel-1; i>=1; i--){
163323 WhereTerm *pTerm, *pEnd;
163324 SrcItem *pItem;
163325 WhereLoop *pLoop;
163326 pLoop = pWInfo->a[i].pWLoop;
@@ -163281,10 +163339,16 @@
163339 || pTerm->pExpr->w.iJoin!=pItem->iCursor
163340 ){
163341 break;
163342 }
163343 }
163344 if( hasRightJoin
163345 && ExprHasProperty(pTerm->pExpr, EP_InnerON)
163346 && pTerm->pExpr->w.iJoin==pItem->iCursor
163347 ){
163348 break; /* restriction (5) */
163349 }
163350 }
163351 if( pTerm<pEnd ) continue;
163352 WHERETRACE(0xffffffff, ("-> drop loop %c not used\n", pLoop->cId));
163353 notReady &= ~pLoop->maskSelf;
163354 for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){
@@ -199762,14 +199826,14 @@
199826
199827 /*
199828 ** Maximum nesting depth of JSON for this implementation.
199829 **
199830 ** This limit is needed to avoid a stack overflow in the recursive
199831 ** descent parser. A depth of 1000 is far deeper than any sane JSON
199832 ** should go. Historical note: This limit was 2000 prior to version 3.42.0
199833 */
199834 #define JSON_MAX_DEPTH 1000
199835
199836 /**************************************************************************
199837 ** Utility routines for dealing with JsonString objects
199838 **************************************************************************/
199839
@@ -200703,10 +200767,11 @@
200767 if( ++pParse->iDepth > JSON_MAX_DEPTH ){
200768 pParse->iErr = i;
200769 return -1;
200770 }
200771 for(j=i+1;;j++){
200772 u32 nNode = pParse->nNode;
200773 x = jsonParseValue(pParse, j);
200774 if( x<=0 ){
200775 if( x==(-2) ){
200776 j = pParse->iErr;
200777 if( pParse->nNode!=(u32)iThis+1 ) pParse->hasNonstd = 1;
@@ -200729,11 +200794,11 @@
200794 if( x!=-1 ) pParse->iErr = j;
200795 return -1;
200796 }
200797 }
200798 if( pParse->oom ) return -1;
200799 pNode = &pParse->aNode[nNode];
200800 if( pNode->eType!=JSON_STRING ){
200801 pParse->iErr = j;
200802 return -1;
200803 }
200804 pNode->jnFlags |= JNODE_LABEL;
@@ -214042,15 +214107,22 @@
214107 static int rbuLockDatabase(sqlite3 *db){
214108 int rc = SQLITE_OK;
214109 sqlite3_file *fd = 0;
214110
214111 sqlite3_file_control(db, "main", RBU_ZIPVFS_CTRL_FILE_POINTER, &fd);
214112 if( fd ){
214113 sqlite3_file_control(db, "main", SQLITE_FCNTL_FILE_POINTER, &fd);
214114 rc = fd->pMethods->xLock(fd, SQLITE_LOCK_SHARED);
214115 if( rc==SQLITE_OK ){
214116 rc = fd->pMethods->xUnlock(fd, SQLITE_LOCK_NONE);
214117 }
214118 sqlite3_file_control(db, "main", RBU_ZIPVFS_CTRL_FILE_POINTER, &fd);
214119 }else{
214120 sqlite3_file_control(db, "main", SQLITE_FCNTL_FILE_POINTER, &fd);
214121 }
214122
214123 if( rc==SQLITE_OK && fd->pMethods ){
214124 rc = fd->pMethods->xLock(fd, SQLITE_LOCK_SHARED);
214125 if( rc==SQLITE_OK ){
214126 rc = fd->pMethods->xLock(fd, SQLITE_LOCK_EXCLUSIVE);
214127 }
214128 }
@@ -242473,11 +242545,11 @@
242545 int nArg, /* Number of args */
242546 sqlite3_value **apUnused /* Function arguments */
242547 ){
242548 assert( nArg==0 );
242549 UNUSED_PARAM2(nArg, apUnused);
242550 sqlite3_result_text(pCtx, "fts5: 2023-05-11 21:15:55 3e9c9bbdb59b9d500ff218db538c047c83da7ac18ebb95c3ee7629ab15e0b43a", -1, SQLITE_TRANSIENT);
242551 }
242552
242553 /*
242554 ** Return true if zName is the extension on one of the shadow tables used
242555 ** by this module.
242556
--- 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.42.0"
150150
#define SQLITE_VERSION_NUMBER 3042000
151
-#define SQLITE_SOURCE_ID "2023-05-05 14:16:31 fece588b186c4f9f76d626313e35336fd5681e966e9bd0fa1053b147c4e3c315"
151
+#define SQLITE_SOURCE_ID "2023-05-12 10:52:12 469718f106e1cfa7f8f4714a9e743108c361af81e0258061c2b76880a7c352ae"
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.42.0"
150 #define SQLITE_VERSION_NUMBER 3042000
151 #define SQLITE_SOURCE_ID "2023-05-05 14:16:31 fece588b186c4f9f76d626313e35336fd5681e966e9bd0fa1053b147c4e3c315"
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.42.0"
150 #define SQLITE_VERSION_NUMBER 3042000
151 #define SQLITE_SOURCE_ID "2023-05-12 10:52:12 469718f106e1cfa7f8f4714a9e743108c361af81e0258061c2b76880a7c352ae"
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