1
1
/******************************************************************************
2
2
** This file is an amalgamation of many separate C source files from SQLite
3
- ** version 3.41.1 . By combining all the individual C code files into this
3
+ ** version 3.41.2 . 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.41.1 "
456
- #define SQLITE_VERSION_NUMBER 3041001
457
- #define SQLITE_SOURCE_ID "2023-03-10 12:13:52 20399f3eda5ec249d147ba9e48da6e87f969d7966a9a896764ca437ff7e737ff "
455
+ #define SQLITE_VERSION "3.41.2 "
456
+ #define SQLITE_VERSION_NUMBER 3041002
457
+ #define SQLITE_SOURCE_ID "2023-03-22 11:56:21 0d1fc92f94cb6b76bffe3ec34d69cffde2924203304e8ffc4155597af0c191da "
458
458
459
459
/*
460
460
** CAPI3REF: Run-Time Library Version Numbers
@@ -16592,7 +16592,7 @@ struct PgHdr {
16592
16592
** private to pcache.c and should not be accessed by other modules.
16593
16593
** pCache is grouped with the public elements for efficiency.
16594
16594
*/
16595
- i16 nRef; /* Number of users of this page */
16595
+ i64 nRef; /* Number of users of this page */
16596
16596
PgHdr *pDirtyNext; /* Next element in list of dirty pages */
16597
16597
PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */
16598
16598
/* NB: pDirtyNext and pDirtyPrev are undefined if the
@@ -16673,12 +16673,12 @@ SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *);
16673
16673
SQLITE_PRIVATE void sqlite3PcacheClear(PCache*);
16674
16674
16675
16675
/* Return the total number of outstanding page references */
16676
- SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache*);
16676
+ SQLITE_PRIVATE i64 sqlite3PcacheRefCount(PCache*);
16677
16677
16678
16678
/* Increment the reference count of an existing page */
16679
16679
SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr*);
16680
16680
16681
- SQLITE_PRIVATE int sqlite3PcachePageRefcount(PgHdr*);
16681
+ SQLITE_PRIVATE i64 sqlite3PcachePageRefcount(PgHdr*);
16682
16682
16683
16683
/* Return the total number of pages stored in the cache */
16684
16684
SQLITE_PRIVATE int sqlite3PcachePagecount(PCache*);
@@ -18837,7 +18837,7 @@ struct NameContext {
18837
18837
#define NC_HasAgg 0x000010 /* One or more aggregate functions seen */
18838
18838
#define NC_IdxExpr 0x000020 /* True if resolving columns of CREATE INDEX */
18839
18839
#define NC_SelfRef 0x00002e /* Combo: PartIdx, isCheck, GenCol, and IdxExpr */
18840
- #define NC_VarSelect 0x000040 /* A correlated subquery has been seen */
18840
+ #define NC_Subquery 0x000040 /* A subquery has been seen */
18841
18841
#define NC_UEList 0x000080 /* True if uNC.pEList is used */
18842
18842
#define NC_UAggInfo 0x000100 /* True if uNC.pAggInfo is used */
18843
18843
#define NC_UUpsert 0x000200 /* True if uNC.pUpsert is used */
@@ -19208,6 +19208,9 @@ struct Parse {
19208
19208
u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
19209
19209
#if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
19210
19210
u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
19211
+ #endif
19212
+ #ifdef SQLITE_DEBUG
19213
+ u8 ifNotExists; /* Might be true if IF NOT EXISTS. Assert()s only */
19211
19214
#endif
19212
19215
int nRangeReg; /* Size of the temporary register block */
19213
19216
int iRangeReg; /* First register in temporary register block */
@@ -52654,7 +52657,7 @@ SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int sz, int *aOp){
52654
52657
struct PCache {
52655
52658
PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */
52656
52659
PgHdr *pSynced; /* Last synced page in dirty page list */
52657
- int nRefSum; /* Sum of ref counts over all pages */
52660
+ i64 nRefSum; /* Sum of ref counts over all pages */
52658
52661
int szCache; /* Configured cache size */
52659
52662
int szSpill; /* Size before spilling occurs */
52660
52663
int szPage; /* Size of every page in this cache */
@@ -52684,7 +52687,7 @@ struct PCache {
52684
52687
unsigned char *a;
52685
52688
int j;
52686
52689
pPg = (PgHdr*)pLower->pExtra;
52687
- printf("%3d : nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
52690
+ printf("%3lld : nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
52688
52691
a = (unsigned char *)pLower->pBuf;
52689
52692
for(j=0; j<12; j++) printf("%02x", a[j]);
52690
52693
printf(" ptr %p\n", pPg);
@@ -53428,14 +53431,14 @@ SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
53428
53431
** This is not the total number of pages referenced, but the sum of the
53429
53432
** reference count for all pages.
53430
53433
*/
53431
- SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
53434
+ SQLITE_PRIVATE i64 sqlite3PcacheRefCount(PCache *pCache){
53432
53435
return pCache->nRefSum;
53433
53436
}
53434
53437
53435
53438
/*
53436
53439
** Return the number of references to the page supplied as an argument.
53437
53440
*/
53438
- SQLITE_PRIVATE int sqlite3PcachePageRefcount(PgHdr *p){
53441
+ SQLITE_PRIVATE i64 sqlite3PcachePageRefcount(PgHdr *p){
53439
53442
return p->nRef;
53440
53443
}
53441
53444
@@ -74505,7 +74508,7 @@ static SQLITE_NOINLINE int btreeNext(BtCursor *pCur){
74505
74508
74506
74509
pPage = pCur->pPage;
74507
74510
idx = ++pCur->ix;
74508
- if( NEVER( !pPage->isInit) || sqlite3FaultSim(412) ){
74511
+ if( !pPage->isInit || sqlite3FaultSim(412) ){
74509
74512
return SQLITE_CORRUPT_BKPT;
74510
74513
}
74511
74514
@@ -77634,6 +77637,7 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
77634
77637
assert( szNew==pPage->xCellSize(pPage, newCell) );
77635
77638
assert( szNew <= MX_CELL_SIZE(p->pBt) );
77636
77639
idx = pCur->ix;
77640
+ pCur->info.nSize = 0;
77637
77641
if( loc==0 ){
77638
77642
CellInfo info;
77639
77643
assert( idx>=0 );
@@ -77706,7 +77710,6 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
77706
77710
** larger than the largest existing key, it is possible to insert the
77707
77711
** row without seeking the cursor. This can be a big performance boost.
77708
77712
*/
77709
- pCur->info.nSize = 0;
77710
77713
if( pPage->nOverflow ){
77711
77714
assert( rc==SQLITE_OK );
77712
77715
pCur->curFlags &= ~(BTCF_ValidNKey);
@@ -104800,8 +104803,8 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
104800
104803
assert( pNC->nRef>=nRef );
104801
104804
if( nRef!=pNC->nRef ){
104802
104805
ExprSetProperty(pExpr, EP_VarSelect);
104803
- pNC->ncFlags |= NC_VarSelect;
104804
104806
}
104807
+ pNC->ncFlags |= NC_Subquery;
104805
104808
}
104806
104809
break;
104807
104810
}
@@ -109550,6 +109553,7 @@ SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(
109550
109553
){
109551
109554
int iAddr;
109552
109555
Vdbe *v = pParse->pVdbe;
109556
+ int nErr = pParse->nErr;
109553
109557
assert( v!=0 );
109554
109558
assert( pParse->iSelfTab!=0 );
109555
109559
if( pParse->iSelfTab>0 ){
@@ -109562,6 +109566,7 @@ SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(
109562
109566
sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
109563
109567
}
109564
109568
if( iAddr ) sqlite3VdbeJumpHere(v, iAddr);
109569
+ if( pParse->nErr>nErr ) pParse->db->errByteOffset = -1;
109565
109570
}
109566
109571
#endif /* SQLITE_OMIT_GENERATED_COLUMNS */
109567
109572
@@ -109578,6 +109583,7 @@ SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(
109578
109583
Column *pCol;
109579
109584
assert( v!=0 );
109580
109585
assert( pTab!=0 );
109586
+ assert( iCol!=XN_EXPR );
109581
109587
if( iCol<0 || iCol==pTab->iPKey ){
109582
109588
sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
109583
109589
VdbeComment((v, "%s.rowid", pTab->zName));
@@ -118933,7 +118939,7 @@ SQLITE_PRIVATE void sqlite3AddReturning(Parse *pParse, ExprList *pList){
118933
118939
if( pParse->pNewTrigger ){
118934
118940
sqlite3ErrorMsg(pParse, "cannot use RETURNING in a trigger");
118935
118941
}else{
118936
- assert( pParse->bReturning==0 );
118942
+ assert( pParse->bReturning==0 || pParse->ifNotExists );
118937
118943
}
118938
118944
pParse->bReturning = 1;
118939
118945
pRet = sqlite3DbMallocZero(db, sizeof(*pRet));
@@ -118959,7 +118965,8 @@ SQLITE_PRIVATE void sqlite3AddReturning(Parse *pParse, ExprList *pList){
118959
118965
pRet->retTStep.pTrig = &pRet->retTrig;
118960
118966
pRet->retTStep.pExprList = pList;
118961
118967
pHash = &(db->aDb[1].pSchema->trigHash);
118962
- assert( sqlite3HashFind(pHash, RETURNING_TRIGGER_NAME)==0 || pParse->nErr );
118968
+ assert( sqlite3HashFind(pHash, RETURNING_TRIGGER_NAME)==0
118969
+ || pParse->nErr || pParse->ifNotExists );
118963
118970
if( sqlite3HashInsert(pHash, RETURNING_TRIGGER_NAME, &pRet->retTrig)
118964
118971
==&pRet->retTrig ){
118965
118972
sqlite3OomFault(db);
@@ -124201,7 +124208,7 @@ SQLITE_PRIVATE void sqlite3DeleteFrom(
124201
124208
#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
124202
124209
{
124203
124210
u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK;
124204
- if( sNC.ncFlags & NC_VarSelect ) bComplex = 1;
124211
+ if( sNC.ncFlags & NC_Subquery ) bComplex = 1;
124205
124212
wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
124206
124213
if( HasRowid(pTab) ){
124207
124214
/* For a rowid table, initialize the RowSet to an empty set */
@@ -142131,7 +142138,9 @@ static Expr *substExpr(
142131
142138
sqlite3VectorErrorMsg(pSubst->pParse, pCopy);
142132
142139
}else{
142133
142140
sqlite3 *db = pSubst->pParse->db;
142134
- if( pSubst->isOuterJoin ){
142141
+ if( pSubst->isOuterJoin
142142
+ && (pCopy->op!=TK_COLUMN || pCopy->iTable!=pSubst->iNewTable)
142143
+ ){
142135
142144
memset(&ifNullRow, 0, sizeof(ifNullRow));
142136
142145
ifNullRow.op = TK_IF_NULL_ROW;
142137
142146
ifNullRow.pLeft = pCopy;
@@ -146893,6 +146902,7 @@ SQLITE_PRIVATE void sqlite3BeginTrigger(
146893
146902
}else{
146894
146903
assert( !db->init.busy );
146895
146904
sqlite3CodeVerifySchema(pParse, iDb);
146905
+ VVA_ONLY( pParse->ifNotExists = 1; )
146896
146906
}
146897
146907
goto trigger_cleanup;
146898
146908
}
@@ -148896,12 +148906,22 @@ SQLITE_PRIVATE void sqlite3Update(
148896
148906
/* Begin the database scan.
148897
148907
**
148898
148908
** Do not consider a single-pass strategy for a multi-row update if
148899
- ** there are any triggers or foreign keys to process, or rows may
148900
- ** be deleted as a result of REPLACE conflict handling. Any of these
148901
- ** things might disturb a cursor being used to scan through the table
148902
- ** or index, causing a single-pass approach to malfunction. */
148909
+ ** there is anything that might disrupt the cursor being used to do
148910
+ ** the UPDATE:
148911
+ ** (1) This is a nested UPDATE
148912
+ ** (2) There are triggers
148913
+ ** (3) There are FOREIGN KEY constraints
148914
+ ** (4) There are REPLACE conflict handlers
148915
+ ** (5) There are subqueries in the WHERE clause
148916
+ */
148903
148917
flags = WHERE_ONEPASS_DESIRED;
148904
- if( !pParse->nested && !pTrigger && !hasFK && !chngKey && !bReplace ){
148918
+ if( !pParse->nested
148919
+ && !pTrigger
148920
+ && !hasFK
148921
+ && !chngKey
148922
+ && !bReplace
148923
+ && (sNC.ncFlags & NC_Subquery)==0
148924
+ ){
148905
148925
flags |= WHERE_ONEPASS_MULTIROW;
148906
148926
}
148907
148927
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere,0,0,0,flags,iIdxCur);
@@ -150866,7 +150886,9 @@ static int vtabCallConstructor(
150866
150886
sCtx.pPrior = db->pVtabCtx;
150867
150887
sCtx.bDeclared = 0;
150868
150888
db->pVtabCtx = &sCtx;
150889
+ pTab->nTabRef++;
150869
150890
rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
150891
+ sqlite3DeleteTable(db, pTab);
150870
150892
db->pVtabCtx = sCtx.pPrior;
150871
150893
if( rc==SQLITE_NOMEM ) sqlite3OomFault(db);
150872
150894
assert( sCtx.pTab==pTab );
@@ -158035,6 +158057,10 @@ static SQLITE_NOINLINE void sqlite3ConstructBloomFilter(
158035
158057
Vdbe *v = pParse->pVdbe; /* VDBE under construction */
158036
158058
WhereLoop *pLoop = pLevel->pWLoop; /* The loop being coded */
158037
158059
int iCur; /* Cursor for table getting the filter */
158060
+ IndexedExpr *saved_pIdxEpr; /* saved copy of Parse.pIdxEpr */
158061
+
158062
+ saved_pIdxEpr = pParse->pIdxEpr;
158063
+ pParse->pIdxEpr = 0;
158038
158064
158039
158065
assert( pLoop!=0 );
158040
158066
assert( v!=0 );
@@ -158091,9 +158117,8 @@ static SQLITE_NOINLINE void sqlite3ConstructBloomFilter(
158091
158117
int r1 = sqlite3GetTempRange(pParse, n);
158092
158118
int jj;
158093
158119
for(jj=0; jj<n; jj++){
158094
- int iCol = pIdx->aiColumn[jj];
158095
158120
assert( pIdx->pTable==pItem->pTab );
158096
- sqlite3ExprCodeGetColumnOfTable(v , pIdx->pTable , iCur, iCol, r1+jj);
158121
+ sqlite3ExprCodeLoadIndexColumn(pParse , pIdx, iCur, jj, r1+jj);
158097
158122
}
158098
158123
sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, r1, n);
158099
158124
sqlite3ReleaseTempRange(pParse, r1, n);
@@ -158124,6 +158149,7 @@ static SQLITE_NOINLINE void sqlite3ConstructBloomFilter(
158124
158149
}
158125
158150
}while( iLevel < pWInfo->nLevel );
158126
158151
sqlite3VdbeJumpHere(v, addrOnce);
158152
+ pParse->pIdxEpr = saved_pIdxEpr;
158127
158153
}
158128
158154
158129
158155
@@ -158423,6 +158449,7 @@ static int whereKeyStats(
158423
158449
assert( pIdx->nSample>0 );
158424
158450
assert( pRec->nField>0 );
158425
158451
158452
+
158426
158453
/* Do a binary search to find the first sample greater than or equal
158427
158454
** to pRec. If pRec contains a single field, the set of samples to search
158428
158455
** is simply the aSample[] array. If the samples in aSample[] contain more
@@ -158467,7 +158494,12 @@ static int whereKeyStats(
158467
158494
** it is extended to two fields. The duplicates that this creates do not
158468
158495
** cause any problems.
158469
158496
*/
158470
- nField = MIN(pRec->nField, pIdx->nSample);
158497
+ if( !HasRowid(pIdx->pTable) && IsPrimaryKeyIndex(pIdx) ){
158498
+ nField = pIdx->nKeyCol;
158499
+ }else{
158500
+ nField = pIdx->nColumn;
158501
+ }
158502
+ nField = MIN(pRec->nField, nField);
158471
158503
iCol = 0;
158472
158504
iSample = pIdx->nSample * nField;
158473
158505
do{
@@ -162195,6 +162227,10 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
162195
162227
if( pFrom->isOrdered==pWInfo->pOrderBy->nExpr ){
162196
162228
pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
162197
162229
}
162230
+ if( pWInfo->pSelect->pOrderBy
162231
+ && pWInfo->nOBSat > pWInfo->pSelect->pOrderBy->nExpr ){
162232
+ pWInfo->nOBSat = pWInfo->pSelect->pOrderBy->nExpr;
162233
+ }
162198
162234
}else{
162199
162235
pWInfo->revMask = pFrom->revLoop;
162200
162236
if( pWInfo->nOBSat<=0 ){
@@ -193071,16 +193107,18 @@ static int fts3MsrBufferData(
193071
193107
char *pList,
193072
193108
i64 nList
193073
193109
){
193074
- if( nList>pMsr->nBuffer ){
193110
+ if( ( nList+FTS3_NODE_PADDING) >pMsr->nBuffer ){
193075
193111
char *pNew;
193076
- pMsr->nBuffer = nList*2;
193077
- pNew = (char *)sqlite3_realloc64(pMsr->aBuffer, pMsr->nBuffer );
193112
+ int nNew = nList*2 + FTS3_NODE_PADDING ;
193113
+ pNew = (char *)sqlite3_realloc64(pMsr->aBuffer, nNew );
193078
193114
if( !pNew ) return SQLITE_NOMEM;
193079
193115
pMsr->aBuffer = pNew;
193116
+ pMsr->nBuffer = nNew;
193080
193117
}
193081
193118
193082
193119
assert( nList>0 );
193083
193120
memcpy(pMsr->aBuffer, pList, nList);
193121
+ memset(&pMsr->aBuffer[nList], 0, FTS3_NODE_PADDING);
193084
193122
return SQLITE_OK;
193085
193123
}
193086
193124
@@ -240224,7 +240262,7 @@ static void fts5SourceIdFunc(
240224
240262
){
240225
240263
assert( nArg==0 );
240226
240264
UNUSED_PARAM2(nArg, apUnused);
240227
- sqlite3_result_text(pCtx, "fts5: 2023-03-10 12:13:52 20399f3eda5ec249d147ba9e48da6e87f969d7966a9a896764ca437ff7e737ff ", -1, SQLITE_TRANSIENT);
240265
+ sqlite3_result_text(pCtx, "fts5: 2023-03-22 11:56:21 0d1fc92f94cb6b76bffe3ec34d69cffde2924203304e8ffc4155597af0c191da ", -1, SQLITE_TRANSIENT);
240228
240266
}
240229
240267
240230
240268
/*
0 commit comments