11/******************************************************************************
22** 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
44** single large file, the entire code can be compiled as a single translation
55** unit. This allows many compilers to do optimizations that would not be
66** possible if the files were compiled separately. Performance improvements
@@ -452,9 +452,9 @@ extern "C" {
452452** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453** [sqlite_version()] and [sqlite_source_id()].
454454*/
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 "
458458
459459/*
460460** CAPI3REF: Run-Time Library Version Numbers
@@ -16592,7 +16592,7 @@ struct PgHdr {
1659216592 ** private to pcache.c and should not be accessed by other modules.
1659316593 ** pCache is grouped with the public elements for efficiency.
1659416594 */
16595- i16 nRef; /* Number of users of this page */
16595+ i64 nRef; /* Number of users of this page */
1659616596 PgHdr *pDirtyNext; /* Next element in list of dirty pages */
1659716597 PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */
1659816598 /* NB: pDirtyNext and pDirtyPrev are undefined if the
@@ -16673,12 +16673,12 @@ SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *);
1667316673SQLITE_PRIVATE void sqlite3PcacheClear(PCache*);
1667416674
1667516675/* Return the total number of outstanding page references */
16676- SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache*);
16676+ SQLITE_PRIVATE i64 sqlite3PcacheRefCount(PCache*);
1667716677
1667816678/* Increment the reference count of an existing page */
1667916679SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr*);
1668016680
16681- SQLITE_PRIVATE int sqlite3PcachePageRefcount(PgHdr*);
16681+ SQLITE_PRIVATE i64 sqlite3PcachePageRefcount(PgHdr*);
1668216682
1668316683/* Return the total number of pages stored in the cache */
1668416684SQLITE_PRIVATE int sqlite3PcachePagecount(PCache*);
@@ -18837,7 +18837,7 @@ struct NameContext {
1883718837#define NC_HasAgg 0x000010 /* One or more aggregate functions seen */
1883818838#define NC_IdxExpr 0x000020 /* True if resolving columns of CREATE INDEX */
1883918839#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 */
1884118841#define NC_UEList 0x000080 /* True if uNC.pEList is used */
1884218842#define NC_UAggInfo 0x000100 /* True if uNC.pAggInfo is used */
1884318843#define NC_UUpsert 0x000200 /* True if uNC.pUpsert is used */
@@ -19208,6 +19208,9 @@ struct Parse {
1920819208 u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
1920919209#if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
1921019210 u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
19211+ #endif
19212+ #ifdef SQLITE_DEBUG
19213+ u8 ifNotExists; /* Might be true if IF NOT EXISTS. Assert()s only */
1921119214#endif
1921219215 int nRangeReg; /* Size of the temporary register block */
1921319216 int iRangeReg; /* First register in temporary register block */
@@ -52654,7 +52657,7 @@ SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int sz, int *aOp){
5265452657struct PCache {
5265552658 PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */
5265652659 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 */
5265852661 int szCache; /* Configured cache size */
5265952662 int szSpill; /* Size before spilling occurs */
5266052663 int szPage; /* Size of every page in this cache */
@@ -52684,7 +52687,7 @@ struct PCache {
5268452687 unsigned char *a;
5268552688 int j;
5268652689 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);
5268852691 a = (unsigned char *)pLower->pBuf;
5268952692 for(j=0; j<12; j++) printf("%02x", a[j]);
5269052693 printf(" ptr %p\n", pPg);
@@ -53428,14 +53431,14 @@ SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
5342853431** This is not the total number of pages referenced, but the sum of the
5342953432** reference count for all pages.
5343053433*/
53431- SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
53434+ SQLITE_PRIVATE i64 sqlite3PcacheRefCount(PCache *pCache){
5343253435 return pCache->nRefSum;
5343353436}
5343453437
5343553438/*
5343653439** Return the number of references to the page supplied as an argument.
5343753440*/
53438- SQLITE_PRIVATE int sqlite3PcachePageRefcount(PgHdr *p){
53441+ SQLITE_PRIVATE i64 sqlite3PcachePageRefcount(PgHdr *p){
5343953442 return p->nRef;
5344053443}
5344153444
@@ -74505,7 +74508,7 @@ static SQLITE_NOINLINE int btreeNext(BtCursor *pCur){
7450574508
7450674509 pPage = pCur->pPage;
7450774510 idx = ++pCur->ix;
74508- if( NEVER( !pPage->isInit) || sqlite3FaultSim(412) ){
74511+ if( !pPage->isInit || sqlite3FaultSim(412) ){
7450974512 return SQLITE_CORRUPT_BKPT;
7451074513 }
7451174514
@@ -77634,6 +77637,7 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
7763477637 assert( szNew==pPage->xCellSize(pPage, newCell) );
7763577638 assert( szNew <= MX_CELL_SIZE(p->pBt) );
7763677639 idx = pCur->ix;
77640+ pCur->info.nSize = 0;
7763777641 if( loc==0 ){
7763877642 CellInfo info;
7763977643 assert( idx>=0 );
@@ -77706,7 +77710,6 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
7770677710 ** larger than the largest existing key, it is possible to insert the
7770777711 ** row without seeking the cursor. This can be a big performance boost.
7770877712 */
77709- pCur->info.nSize = 0;
7771077713 if( pPage->nOverflow ){
7771177714 assert( rc==SQLITE_OK );
7771277715 pCur->curFlags &= ~(BTCF_ValidNKey);
@@ -104800,8 +104803,8 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
104800104803 assert( pNC->nRef>=nRef );
104801104804 if( nRef!=pNC->nRef ){
104802104805 ExprSetProperty(pExpr, EP_VarSelect);
104803- pNC->ncFlags |= NC_VarSelect;
104804104806 }
104807+ pNC->ncFlags |= NC_Subquery;
104805104808 }
104806104809 break;
104807104810 }
@@ -109550,6 +109553,7 @@ SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(
109550109553){
109551109554 int iAddr;
109552109555 Vdbe *v = pParse->pVdbe;
109556+ int nErr = pParse->nErr;
109553109557 assert( v!=0 );
109554109558 assert( pParse->iSelfTab!=0 );
109555109559 if( pParse->iSelfTab>0 ){
@@ -109562,6 +109566,7 @@ SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(
109562109566 sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
109563109567 }
109564109568 if( iAddr ) sqlite3VdbeJumpHere(v, iAddr);
109569+ if( pParse->nErr>nErr ) pParse->db->errByteOffset = -1;
109565109570}
109566109571#endif /* SQLITE_OMIT_GENERATED_COLUMNS */
109567109572
@@ -109578,6 +109583,7 @@ SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(
109578109583 Column *pCol;
109579109584 assert( v!=0 );
109580109585 assert( pTab!=0 );
109586+ assert( iCol!=XN_EXPR );
109581109587 if( iCol<0 || iCol==pTab->iPKey ){
109582109588 sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
109583109589 VdbeComment((v, "%s.rowid", pTab->zName));
@@ -118933,7 +118939,7 @@ SQLITE_PRIVATE void sqlite3AddReturning(Parse *pParse, ExprList *pList){
118933118939 if( pParse->pNewTrigger ){
118934118940 sqlite3ErrorMsg(pParse, "cannot use RETURNING in a trigger");
118935118941 }else{
118936- assert( pParse->bReturning==0 );
118942+ assert( pParse->bReturning==0 || pParse->ifNotExists );
118937118943 }
118938118944 pParse->bReturning = 1;
118939118945 pRet = sqlite3DbMallocZero(db, sizeof(*pRet));
@@ -118959,7 +118965,8 @@ SQLITE_PRIVATE void sqlite3AddReturning(Parse *pParse, ExprList *pList){
118959118965 pRet->retTStep.pTrig = &pRet->retTrig;
118960118966 pRet->retTStep.pExprList = pList;
118961118967 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 );
118963118970 if( sqlite3HashInsert(pHash, RETURNING_TRIGGER_NAME, &pRet->retTrig)
118964118971 ==&pRet->retTrig ){
118965118972 sqlite3OomFault(db);
@@ -124201,7 +124208,7 @@ SQLITE_PRIVATE void sqlite3DeleteFrom(
124201124208#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
124202124209 {
124203124210 u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK;
124204- if( sNC.ncFlags & NC_VarSelect ) bComplex = 1;
124211+ if( sNC.ncFlags & NC_Subquery ) bComplex = 1;
124205124212 wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
124206124213 if( HasRowid(pTab) ){
124207124214 /* For a rowid table, initialize the RowSet to an empty set */
@@ -142131,7 +142138,9 @@ static Expr *substExpr(
142131142138 sqlite3VectorErrorMsg(pSubst->pParse, pCopy);
142132142139 }else{
142133142140 sqlite3 *db = pSubst->pParse->db;
142134- if( pSubst->isOuterJoin ){
142141+ if( pSubst->isOuterJoin
142142+ && (pCopy->op!=TK_COLUMN || pCopy->iTable!=pSubst->iNewTable)
142143+ ){
142135142144 memset(&ifNullRow, 0, sizeof(ifNullRow));
142136142145 ifNullRow.op = TK_IF_NULL_ROW;
142137142146 ifNullRow.pLeft = pCopy;
@@ -146893,6 +146902,7 @@ SQLITE_PRIVATE void sqlite3BeginTrigger(
146893146902 }else{
146894146903 assert( !db->init.busy );
146895146904 sqlite3CodeVerifySchema(pParse, iDb);
146905+ VVA_ONLY( pParse->ifNotExists = 1; )
146896146906 }
146897146907 goto trigger_cleanup;
146898146908 }
@@ -148896,12 +148906,22 @@ SQLITE_PRIVATE void sqlite3Update(
148896148906 /* Begin the database scan.
148897148907 **
148898148908 ** 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+ */
148903148917 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+ ){
148905148925 flags |= WHERE_ONEPASS_MULTIROW;
148906148926 }
148907148927 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere,0,0,0,flags,iIdxCur);
@@ -150866,7 +150886,9 @@ static int vtabCallConstructor(
150866150886 sCtx.pPrior = db->pVtabCtx;
150867150887 sCtx.bDeclared = 0;
150868150888 db->pVtabCtx = &sCtx;
150889+ pTab->nTabRef++;
150869150890 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
150891+ sqlite3DeleteTable(db, pTab);
150870150892 db->pVtabCtx = sCtx.pPrior;
150871150893 if( rc==SQLITE_NOMEM ) sqlite3OomFault(db);
150872150894 assert( sCtx.pTab==pTab );
@@ -158035,6 +158057,10 @@ static SQLITE_NOINLINE void sqlite3ConstructBloomFilter(
158035158057 Vdbe *v = pParse->pVdbe; /* VDBE under construction */
158036158058 WhereLoop *pLoop = pLevel->pWLoop; /* The loop being coded */
158037158059 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;
158038158064
158039158065 assert( pLoop!=0 );
158040158066 assert( v!=0 );
@@ -158091,9 +158117,8 @@ static SQLITE_NOINLINE void sqlite3ConstructBloomFilter(
158091158117 int r1 = sqlite3GetTempRange(pParse, n);
158092158118 int jj;
158093158119 for(jj=0; jj<n; jj++){
158094- int iCol = pIdx->aiColumn[jj];
158095158120 assert( pIdx->pTable==pItem->pTab );
158096- sqlite3ExprCodeGetColumnOfTable(v , pIdx->pTable , iCur, iCol, r1+jj);
158121+ sqlite3ExprCodeLoadIndexColumn(pParse , pIdx, iCur, jj, r1+jj);
158097158122 }
158098158123 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, r1, n);
158099158124 sqlite3ReleaseTempRange(pParse, r1, n);
@@ -158124,6 +158149,7 @@ static SQLITE_NOINLINE void sqlite3ConstructBloomFilter(
158124158149 }
158125158150 }while( iLevel < pWInfo->nLevel );
158126158151 sqlite3VdbeJumpHere(v, addrOnce);
158152+ pParse->pIdxEpr = saved_pIdxEpr;
158127158153}
158128158154
158129158155
@@ -158423,6 +158449,7 @@ static int whereKeyStats(
158423158449 assert( pIdx->nSample>0 );
158424158450 assert( pRec->nField>0 );
158425158451
158452+
158426158453 /* Do a binary search to find the first sample greater than or equal
158427158454 ** to pRec. If pRec contains a single field, the set of samples to search
158428158455 ** is simply the aSample[] array. If the samples in aSample[] contain more
@@ -158467,7 +158494,12 @@ static int whereKeyStats(
158467158494 ** it is extended to two fields. The duplicates that this creates do not
158468158495 ** cause any problems.
158469158496 */
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);
158471158503 iCol = 0;
158472158504 iSample = pIdx->nSample * nField;
158473158505 do{
@@ -162195,6 +162227,10 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
162195162227 if( pFrom->isOrdered==pWInfo->pOrderBy->nExpr ){
162196162228 pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
162197162229 }
162230+ if( pWInfo->pSelect->pOrderBy
162231+ && pWInfo->nOBSat > pWInfo->pSelect->pOrderBy->nExpr ){
162232+ pWInfo->nOBSat = pWInfo->pSelect->pOrderBy->nExpr;
162233+ }
162198162234 }else{
162199162235 pWInfo->revMask = pFrom->revLoop;
162200162236 if( pWInfo->nOBSat<=0 ){
@@ -193071,16 +193107,18 @@ static int fts3MsrBufferData(
193071193107 char *pList,
193072193108 i64 nList
193073193109){
193074- if( nList>pMsr->nBuffer ){
193110+ if( ( nList+FTS3_NODE_PADDING) >pMsr->nBuffer ){
193075193111 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 );
193078193114 if( !pNew ) return SQLITE_NOMEM;
193079193115 pMsr->aBuffer = pNew;
193116+ pMsr->nBuffer = nNew;
193080193117 }
193081193118
193082193119 assert( nList>0 );
193083193120 memcpy(pMsr->aBuffer, pList, nList);
193121+ memset(&pMsr->aBuffer[nList], 0, FTS3_NODE_PADDING);
193084193122 return SQLITE_OK;
193085193123}
193086193124
@@ -240224,7 +240262,7 @@ static void fts5SourceIdFunc(
240224240262){
240225240263 assert( nArg==0 );
240226240264 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);
240228240266}
240229240267
240230240268/*
0 commit comments