1
1
/******************************************************************************
2
2
** This file is an amalgamation of many separate C source files from SQLite
3
- ** version 3.38.2 . By combining all the individual C code files into this
3
+ ** version 3.38.3 . By combining all the individual C code files into this
4
4
** single large file, the entire code can be compiled as a single translation
5
5
** unit. This allows many compilers to do optimizations that would not be
6
6
** possible if the files were compiled separately. Performance improvements
@@ -452,9 +452,9 @@ extern "C" {
452
452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453
453
** [sqlite_version()] and [sqlite_source_id()].
454
454
*/
455
- #define SQLITE_VERSION "3.38.2 "
456
- #define SQLITE_VERSION_NUMBER 3038002
457
- #define SQLITE_SOURCE_ID "2022-03-26 13:51:10 d33c709cc0af66bc5b6dc6216eba9f1f0b40960b9ae83694c986fbf4c1d6f08f "
455
+ #define SQLITE_VERSION "3.38.3 "
456
+ #define SQLITE_VERSION_NUMBER 3038003
457
+ #define SQLITE_SOURCE_ID "2022-04-27 12:03:15 9547e2c38a1c6f751a77d4d796894dec4dc5d8f5d79b1cd39e1ffc50df7b3be4 "
458
458
459
459
/*
460
460
** CAPI3REF: Run-Time Library Version Numbers
@@ -19929,6 +19929,7 @@ SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
19929
19929
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
19930
19930
SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
19931
19931
SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
19932
+ SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr*,const SrcItem*);
19932
19933
#ifdef SQLITE_ENABLE_CURSOR_HINTS
19933
19934
SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
19934
19935
#endif
@@ -29337,8 +29338,9 @@ SQLITE_PRIVATE char *sqlite3DbSpanDup(sqlite3 *db, const char *zStart, const cha
29337
29338
** Free any prior content in *pz and replace it with a copy of zNew.
29338
29339
*/
29339
29340
SQLITE_PRIVATE void sqlite3SetString(char **pz, sqlite3 *db, const char *zNew){
29341
+ char *z = sqlite3DbStrDup(db, zNew);
29340
29342
sqlite3DbFree(db, *pz);
29341
- *pz = sqlite3DbStrDup(db, zNew) ;
29343
+ *pz = z ;
29342
29344
}
29343
29345
29344
29346
/*
@@ -67764,6 +67766,8 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
67764
67766
** fragmented bytes within the page. */
67765
67767
memcpy(&aData[iAddr], &aData[pc], 2);
67766
67768
aData[hdr+7] += (u8)x;
67769
+ testcase( pc+x>maxPC );
67770
+ return &aData[pc];
67767
67771
}else if( x+pc > maxPC ){
67768
67772
/* This slot extends off the end of the usable part of the page */
67769
67773
*pRc = SQLITE_CORRUPT_PAGE(pPg);
@@ -71963,7 +71967,7 @@ SQLITE_PRIVATE int sqlite3BtreeIndexMoveto(
71963
71967
assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
71964
71968
assert( pPage->isInit );
71965
71969
if( pPage->leaf ){
71966
- assert( pCur->ix<pCur->pPage->nCell );
71970
+ assert( pCur->ix<pCur->pPage->nCell || CORRUPT_DB );
71967
71971
pCur->ix = (u16)idx;
71968
71972
*pRes = c;
71969
71973
rc = SQLITE_OK;
@@ -74487,7 +74491,7 @@ static int balance_nonroot(
74487
74491
iOvflSpace += sz;
74488
74492
assert( sz<=pBt->maxLocal+23 );
74489
74493
assert( iOvflSpace <= (int)pBt->pageSize );
74490
- for(k=0; b.ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
74494
+ for(k=0; b.ixNx[k]<=j && ALWAYS(k<NB*2); k++){}
74491
74495
pSrcEnd = b.apEnd[k];
74492
74496
if( SQLITE_WITHIN(pSrcEnd, pCell, pCell+sz) ){
74493
74497
rc = SQLITE_CORRUPT_BKPT;
@@ -78052,7 +78056,11 @@ SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){
78052
78056
assert( !sqlite3VdbeMemIsRowSet(pMem) );
78053
78057
assert( desiredEnc==SQLITE_UTF8 || desiredEnc==SQLITE_UTF16LE
78054
78058
|| desiredEnc==SQLITE_UTF16BE );
78055
- if( !(pMem->flags&MEM_Str) || pMem->enc==desiredEnc ){
78059
+ if( !(pMem->flags&MEM_Str) ){
78060
+ pMem->enc = desiredEnc;
78061
+ return SQLITE_OK;
78062
+ }
78063
+ if( pMem->enc==desiredEnc ){
78056
78064
return SQLITE_OK;
78057
78065
}
78058
78066
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
@@ -104759,6 +104767,38 @@ SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
104759
104767
return exprIsConst(p, 3, iCur);
104760
104768
}
104761
104769
104770
+ /*
104771
+ ** Check pExpr to see if it is an invariant constraint on data source pSrc.
104772
+ ** This is an optimization. False negatives will perhaps cause slower
104773
+ ** queries, but false positives will yield incorrect answers. So when in
104774
+ ** double, return 0.
104775
+ **
104776
+ ** To be an invariant constraint, the following must be true:
104777
+ **
104778
+ ** (1) pExpr cannot refer to any table other than pSrc->iCursor.
104779
+ **
104780
+ ** (2) pExpr cannot use subqueries or non-deterministic functions.
104781
+ **
104782
+ ** (*) ** Not applicable to this branch **
104783
+ **
104784
+ ** (4) If pSrc is the right operand of a LEFT JOIN, then...
104785
+ ** (4a) pExpr must come from an ON clause..
104786
+ ** (4b) and specifically the ON clause associated with the LEFT JOIN.
104787
+ **
104788
+ ** (5) If pSrc is not the right operand of a LEFT JOIN or the left
104789
+ ** operand of a RIGHT JOIN, then pExpr must be from the WHERE
104790
+ ** clause, not an ON clause.
104791
+ */
104792
+ SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr *pExpr, const SrcItem *pSrc){
104793
+ if( pSrc->fg.jointype & JT_LEFT ){
104794
+ if( !ExprHasProperty(pExpr, EP_FromJoin) ) return 0; /* rule (4a) */
104795
+ if( pExpr->w.iRightJoinTable!=pSrc->iCursor ) return 0; /* rule (4b) */
104796
+ }else{
104797
+ if( ExprHasProperty(pExpr, EP_FromJoin) ) return 0; /* rule (5) */
104798
+ }
104799
+ return sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor); /* rules (1), (2) */
104800
+ }
104801
+
104762
104802
104763
104803
/*
104764
104804
** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
@@ -139042,8 +139082,7 @@ static int pushDownWhereTerms(
139042
139082
Parse *pParse, /* Parse context (for malloc() and error reporting) */
139043
139083
Select *pSubq, /* The subquery whose WHERE clause is to be augmented */
139044
139084
Expr *pWhere, /* The WHERE clause of the outer query */
139045
- int iCursor, /* Cursor number of the subquery */
139046
- int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */
139085
+ SrcItem *pSrc /* The subquery term of the outer FROM clause */
139047
139086
){
139048
139087
Expr *pNew;
139049
139088
int nChng = 0;
@@ -139078,10 +139117,11 @@ static int pushDownWhereTerms(
139078
139117
return 0; /* restriction (3) */
139079
139118
}
139080
139119
while( pWhere->op==TK_AND ){
139081
- nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight,
139082
- iCursor, isLeftJoin);
139120
+ nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, pSrc);
139083
139121
pWhere = pWhere->pLeft;
139084
139122
}
139123
+
139124
+ #if 0 /* Legacy code. Checks now done by sqlite3ExprIsTableConstraint() */
139085
139125
if( isLeftJoin
139086
139126
&& (ExprHasProperty(pWhere,EP_FromJoin)==0
139087
139127
|| pWhere->w.iRightJoinTable!=iCursor)
@@ -139093,16 +139133,18 @@ static int pushDownWhereTerms(
139093
139133
){
139094
139134
return 0; /* restriction (5) */
139095
139135
}
139096
- if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
139136
+ #endif
139137
+
139138
+ if( sqlite3ExprIsTableConstraint(pWhere, pSrc) ){
139097
139139
nChng++;
139098
139140
pSubq->selFlags |= SF_PushDown;
139099
139141
while( pSubq ){
139100
139142
SubstContext x;
139101
139143
pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
139102
139144
unsetJoinExpr(pNew, -1);
139103
139145
x.pParse = pParse;
139104
- x.iTable = iCursor;
139105
- x.iNewTable = iCursor;
139146
+ x.iTable = pSrc-> iCursor;
139147
+ x.iNewTable = pSrc-> iCursor;
139106
139148
x.isLeftJoin = 0;
139107
139149
x.pEList = pSubq->pEList;
139108
139150
pNew = substExpr(&x, pNew);
@@ -140884,8 +140926,7 @@ SQLITE_PRIVATE int sqlite3Select(
140884
140926
if( OptimizationEnabled(db, SQLITE_PushDown)
140885
140927
&& (pItem->fg.isCte==0
140886
140928
|| (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2))
140887
- && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor,
140888
- (pItem->fg.jointype & JT_OUTER)!=0)
140929
+ && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem)
140889
140930
){
140890
140931
#if SELECTTRACE_ENABLED
140891
140932
if( sqlite3SelectTrace & 0x100 ){
@@ -152810,8 +152851,7 @@ static SQLITE_NOINLINE void constructAutomaticIndex(
152810
152851
** WHERE clause (or the ON clause of a LEFT join) that constrain which
152811
152852
** rows of the target table (pSrc) that can be used. */
152812
152853
if( (pTerm->wtFlags & TERM_VIRTUAL)==0
152813
- && ((pSrc->fg.jointype&JT_LEFT)==0 || ExprHasProperty(pExpr,EP_FromJoin))
152814
- && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor)
152854
+ && sqlite3ExprIsTableConstraint(pExpr, pSrc)
152815
152855
){
152816
152856
pPartial = sqlite3ExprAnd(pParse, pPartial,
152817
152857
sqlite3ExprDup(pParse->db, pExpr, 0));
@@ -153050,7 +153090,7 @@ static SQLITE_NOINLINE void sqlite3ConstructBloomFilter(
153050
153090
for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){
153051
153091
Expr *pExpr = pTerm->pExpr;
153052
153092
if( (pTerm->wtFlags & TERM_VIRTUAL)==0
153053
- && sqlite3ExprIsTableConstant (pExpr, iCur )
153093
+ && sqlite3ExprIsTableConstraint (pExpr, pItem )
153054
153094
){
153055
153095
sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
153056
153096
}
@@ -159970,7 +160010,7 @@ static void windowAggStep(
159970
160010
159971
160011
for(iEnd=sqlite3VdbeCurrentAddr(v); iOp<iEnd; iOp++){
159972
160012
VdbeOp *pOp = sqlite3VdbeGetOp(v, iOp);
159973
- if( pOp->opcode==OP_Column && pOp->p1==pWin ->iEphCsr ){
160013
+ if( pOp->opcode==OP_Column && pOp->p1==pMWin ->iEphCsr ){
159974
160014
pOp->p1 = csr;
159975
160015
}
159976
160016
}
@@ -194288,14 +194328,15 @@ static JsonNode *jsonLookupStep(
194288
194328
*pzErr = zPath;
194289
194329
return 0;
194290
194330
}
194331
+ testcase( nKey==0 );
194291
194332
}else{
194292
194333
zKey = zPath;
194293
194334
for(i=0; zPath[i] && zPath[i]!='.' && zPath[i]!='['; i++){}
194294
194335
nKey = i;
194295
- }
194296
- if( nKey==0 ){
194297
- *pzErr = zPath ;
194298
- return 0;
194336
+ if( nKey==0 ){
194337
+ *pzErr = zPath;
194338
+ return 0 ;
194339
+ }
194299
194340
}
194300
194341
j = 1;
194301
194342
for(;;){
@@ -195443,6 +195484,33 @@ static int jsonEachNext(sqlite3_vtab_cursor *cur){
195443
195484
return SQLITE_OK;
195444
195485
}
195445
195486
195487
+ /* Append an object label to the JSON Path being constructed
195488
+ ** in pStr.
195489
+ */
195490
+ static void jsonAppendObjectPathElement(
195491
+ JsonString *pStr,
195492
+ JsonNode *pNode
195493
+ ){
195494
+ int jj, nn;
195495
+ const char *z;
195496
+ assert( pNode->eType==JSON_STRING );
195497
+ assert( pNode->jnFlags & JNODE_LABEL );
195498
+ assert( pNode->eU==1 );
195499
+ z = pNode->u.zJContent;
195500
+ nn = pNode->n;
195501
+ assert( nn>=2 );
195502
+ assert( z[0]=='"' );
195503
+ assert( z[nn-1]=='"' );
195504
+ if( nn>2 && sqlite3Isalpha(z[1]) ){
195505
+ for(jj=2; jj<nn-1 && sqlite3Isalnum(z[jj]); jj++){}
195506
+ if( jj==nn-1 ){
195507
+ z++;
195508
+ nn -= 2;
195509
+ }
195510
+ }
195511
+ jsonPrintf(nn+2, pStr, ".%.*s", nn, z);
195512
+ }
195513
+
195446
195514
/* Append the name of the path for element i to pStr
195447
195515
*/
195448
195516
static void jsonEachComputePath(
@@ -195467,10 +195535,7 @@ static void jsonEachComputePath(
195467
195535
}else{
195468
195536
assert( pUp->eType==JSON_OBJECT );
195469
195537
if( (pNode->jnFlags & JNODE_LABEL)==0 ) pNode--;
195470
- assert( pNode->eType==JSON_STRING );
195471
- assert( pNode->jnFlags & JNODE_LABEL );
195472
- assert( pNode->eU==1 );
195473
- jsonPrintf(pNode->n+1, pStr, ".%.*s", pNode->n-2, pNode->u.zJContent+1);
195538
+ jsonAppendObjectPathElement(pStr, pNode);
195474
195539
}
195475
195540
}
195476
195541
@@ -195541,8 +195606,7 @@ static int jsonEachColumn(
195541
195606
if( p->eType==JSON_ARRAY ){
195542
195607
jsonPrintf(30, &x, "[%d]", p->iRowid);
195543
195608
}else if( p->eType==JSON_OBJECT ){
195544
- assert( pThis->eU==1 );
195545
- jsonPrintf(pThis->n, &x, ".%.*s", pThis->n-2, pThis->u.zJContent+1);
195609
+ jsonAppendObjectPathElement(&x, pThis);
195546
195610
}
195547
195611
}
195548
195612
jsonResult(&x);
@@ -234433,7 +234497,7 @@ static void fts5SourceIdFunc(
234433
234497
){
234434
234498
assert( nArg==0 );
234435
234499
UNUSED_PARAM2(nArg, apUnused);
234436
- sqlite3_result_text(pCtx, "fts5: 2022-03-26 13:51:10 d33c709cc0af66bc5b6dc6216eba9f1f0b40960b9ae83694c986fbf4c1d6f08f ", -1, SQLITE_TRANSIENT);
234500
+ sqlite3_result_text(pCtx, "fts5: 2022-04-27 12:03:15 9547e2c38a1c6f751a77d4d796894dec4dc5d8f5d79b1cd39e1ffc50df7b3be4 ", -1, SQLITE_TRANSIENT);
234437
234501
}
234438
234502
234439
234503
/*
0 commit comments