| | @@ -1,8 +1,8 @@ |
| 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 |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| | @@ -450,13 +450,13 @@ |
| 450 | 450 | ** |
| 451 | 451 | ** See also: [sqlite3_libversion()], |
| 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-09 16:04:34 cc8a0ee40cfc83ab42a0ff452de0a53fe17784aefb944ea7ac2cb078a8310730" |
| 455 | +#define SQLITE_VERSION "3.41.2" |
| 456 | +#define SQLITE_VERSION_NUMBER 3041002 |
| 457 | +#define SQLITE_SOURCE_ID "2023-03-17 12:25:10 c5bd0ea3b5b2f3ed8e971c5fd6e85e8f06d8055d74df65612c3794138306e6ba" |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| | @@ -18835,11 +18835,11 @@ |
| 18835 | 18835 | #define NC_IsCheck 0x000004 /* True if resolving a CHECK constraint */ |
| 18836 | 18836 | #define NC_GenCol 0x000008 /* True for a GENERATED ALWAYS AS clause */ |
| 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 */ |
| 18844 | 18844 | #define NC_UBaseReg 0x000400 /* True if uNC.iBaseReg is used */ |
| 18845 | 18845 | #define NC_MinMaxAgg 0x001000 /* min/max aggregates seen. See note above */ |
| | @@ -19207,10 +19207,13 @@ |
| 19207 | 19207 | u8 prepFlags; /* SQLITE_PREPARE_* flags */ |
| 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 | 19211 | #endif |
| 19212 | +#ifdef SQLITE_DEBUG |
| 19213 | + u8 ifNotExists; /* Might be true if IF NOT EXISTS. Assert()s only */ |
| 19214 | +#endif |
| 19212 | 19215 | int nRangeReg; /* Size of the temporary register block */ |
| 19213 | 19216 | int iRangeReg; /* First register in temporary register block */ |
| 19214 | 19217 | int nErr; /* Number of errors seen */ |
| 19215 | 19218 | int nTab; /* Number of previously allocated VDBE cursors */ |
| 19216 | 19219 | int nMem; /* Number of memory cells used so far */ |
| | @@ -74503,11 +74506,11 @@ |
| 74503 | 74506 | } |
| 74504 | 74507 | } |
| 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 | |
| 74512 | 74515 | if( idx>=pPage->nCell ){ |
| 74513 | 74516 | if( !pPage->leaf ){ |
| | @@ -104798,12 +104801,12 @@ |
| 104798 | 104801 | sqlite3WalkSelect(pWalker, pExpr->x.pSelect); |
| 104799 | 104802 | } |
| 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 | } |
| 104808 | 104811 | case TK_VARIABLE: { |
| 104809 | 104812 | testcase( pNC->ncFlags & NC_IsCheck ); |
| | @@ -109576,10 +109579,11 @@ |
| 109576 | 109579 | int regOut /* Extract the value into this register */ |
| 109577 | 109580 | ){ |
| 109578 | 109581 | Column *pCol; |
| 109579 | 109582 | assert( v!=0 ); |
| 109580 | 109583 | assert( pTab!=0 ); |
| 109584 | + assert( iCol!=XN_EXPR ); |
| 109581 | 109585 | if( iCol<0 || iCol==pTab->iPKey ){ |
| 109582 | 109586 | sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut); |
| 109583 | 109587 | VdbeComment((v, "%s.rowid", pTab->zName)); |
| 109584 | 109588 | }else{ |
| 109585 | 109589 | int op; |
| | @@ -118931,11 +118935,11 @@ |
| 118931 | 118935 | Hash *pHash; |
| 118932 | 118936 | sqlite3 *db = pParse->db; |
| 118933 | 118937 | if( pParse->pNewTrigger ){ |
| 118934 | 118938 | sqlite3ErrorMsg(pParse, "cannot use RETURNING in a trigger"); |
| 118935 | 118939 | }else{ |
| 118936 | | - assert( pParse->bReturning==0 ); |
| 118940 | + assert( pParse->bReturning==0 || pParse->ifNotExists ); |
| 118937 | 118941 | } |
| 118938 | 118942 | pParse->bReturning = 1; |
| 118939 | 118943 | pRet = sqlite3DbMallocZero(db, sizeof(*pRet)); |
| 118940 | 118944 | if( pRet==0 ){ |
| 118941 | 118945 | sqlite3ExprListDelete(db, pList); |
| | @@ -118957,11 +118961,12 @@ |
| 118957 | 118961 | pRet->retTrig.step_list = &pRet->retTStep; |
| 118958 | 118962 | pRet->retTStep.op = TK_RETURNING; |
| 118959 | 118963 | pRet->retTStep.pTrig = &pRet->retTrig; |
| 118960 | 118964 | pRet->retTStep.pExprList = pList; |
| 118961 | 118965 | pHash = &(db->aDb[1].pSchema->trigHash); |
| 118962 | | - assert( sqlite3HashFind(pHash, RETURNING_TRIGGER_NAME)==0 || pParse->nErr ); |
| 118966 | + assert( sqlite3HashFind(pHash, RETURNING_TRIGGER_NAME)==0 |
| 118967 | + || pParse->nErr || pParse->ifNotExists ); |
| 118963 | 118968 | if( sqlite3HashInsert(pHash, RETURNING_TRIGGER_NAME, &pRet->retTrig) |
| 118964 | 118969 | ==&pRet->retTrig ){ |
| 118965 | 118970 | sqlite3OomFault(db); |
| 118966 | 118971 | } |
| 118967 | 118972 | } |
| | @@ -124199,11 +124204,11 @@ |
| 124199 | 124204 | } |
| 124200 | 124205 | }else |
| 124201 | 124206 | #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */ |
| 124202 | 124207 | { |
| 124203 | 124208 | u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK; |
| 124204 | | - if( sNC.ncFlags & NC_VarSelect ) bComplex = 1; |
| 124209 | + if( sNC.ncFlags & NC_Subquery ) bComplex = 1; |
| 124205 | 124210 | wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW); |
| 124206 | 124211 | if( HasRowid(pTab) ){ |
| 124207 | 124212 | /* For a rowid table, initialize the RowSet to an empty set */ |
| 124208 | 124213 | pPk = 0; |
| 124209 | 124214 | nPk = 1; |
| | @@ -142129,11 +142134,13 @@ |
| 142129 | 142134 | assert( pExpr->pRight==0 ); |
| 142130 | 142135 | if( sqlite3ExprIsVector(pCopy) ){ |
| 142131 | 142136 | sqlite3VectorErrorMsg(pSubst->pParse, pCopy); |
| 142132 | 142137 | }else{ |
| 142133 | 142138 | sqlite3 *db = pSubst->pParse->db; |
| 142134 | | - if( pSubst->isOuterJoin ){ |
| 142139 | + if( pSubst->isOuterJoin |
| 142140 | + && (pCopy->op!=TK_COLUMN || pCopy->iTable!=pSubst->iNewTable) |
| 142141 | + ){ |
| 142135 | 142142 | memset(&ifNullRow, 0, sizeof(ifNullRow)); |
| 142136 | 142143 | ifNullRow.op = TK_IF_NULL_ROW; |
| 142137 | 142144 | ifNullRow.pLeft = pCopy; |
| 142138 | 142145 | ifNullRow.iTable = pSubst->iNewTable; |
| 142139 | 142146 | ifNullRow.iColumn = -99; |
| | @@ -146891,10 +146898,11 @@ |
| 146891 | 146898 | if( !noErr ){ |
| 146892 | 146899 | sqlite3ErrorMsg(pParse, "trigger %T already exists", pName); |
| 146893 | 146900 | }else{ |
| 146894 | 146901 | assert( !db->init.busy ); |
| 146895 | 146902 | sqlite3CodeVerifySchema(pParse, iDb); |
| 146903 | + VVA_ONLY( pParse->ifNotExists = 1; ) |
| 146896 | 146904 | } |
| 146897 | 146905 | goto trigger_cleanup; |
| 146898 | 146906 | } |
| 146899 | 146907 | } |
| 146900 | 146908 | |
| | @@ -148894,16 +148902,26 @@ |
| 148894 | 148902 | bFinishSeek = 0; |
| 148895 | 148903 | }else{ |
| 148896 | 148904 | /* Begin the database scan. |
| 148897 | 148905 | ** |
| 148898 | 148906 | ** 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. */ |
| 148907 | + ** there is anything that might disrupt the cursor being used to do |
| 148908 | + ** the UPDATE: |
| 148909 | + ** (1) This is a nested UPDATE |
| 148910 | + ** (2) There are triggers |
| 148911 | + ** (3) There are FOREIGN KEY constraints |
| 148912 | + ** (4) There are REPLACE conflict handlers |
| 148913 | + ** (5) There are subqueries in the WHERE clause |
| 148914 | + */ |
| 148903 | 148915 | flags = WHERE_ONEPASS_DESIRED; |
| 148904 | | - if( !pParse->nested && !pTrigger && !hasFK && !chngKey && !bReplace ){ |
| 148916 | + if( !pParse->nested |
| 148917 | + && !pTrigger |
| 148918 | + && !hasFK |
| 148919 | + && !chngKey |
| 148920 | + && !bReplace |
| 148921 | + && (sNC.ncFlags & NC_Subquery)==0 |
| 148922 | + ){ |
| 148905 | 148923 | flags |= WHERE_ONEPASS_MULTIROW; |
| 148906 | 148924 | } |
| 148907 | 148925 | pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere,0,0,0,flags,iIdxCur); |
| 148908 | 148926 | if( pWInfo==0 ) goto update_cleanup; |
| 148909 | 148927 | |
| | @@ -150864,11 +150882,13 @@ |
| 150864 | 150882 | sCtx.pTab = pTab; |
| 150865 | 150883 | sCtx.pVTable = pVTable; |
| 150866 | 150884 | sCtx.pPrior = db->pVtabCtx; |
| 150867 | 150885 | sCtx.bDeclared = 0; |
| 150868 | 150886 | db->pVtabCtx = &sCtx; |
| 150887 | + pTab->nTabRef++; |
| 150869 | 150888 | rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr); |
| 150889 | + sqlite3DeleteTable(db, pTab); |
| 150870 | 150890 | db->pVtabCtx = sCtx.pPrior; |
| 150871 | 150891 | if( rc==SQLITE_NOMEM ) sqlite3OomFault(db); |
| 150872 | 150892 | assert( sCtx.pTab==pTab ); |
| 150873 | 150893 | |
| 150874 | 150894 | if( SQLITE_OK!=rc ){ |
| | @@ -158033,10 +158053,14 @@ |
| 158033 | 158053 | const WhereTerm *pWCEnd; /* Last WHERE clause term */ |
| 158034 | 158054 | Parse *pParse = pWInfo->pParse; /* Parsing context */ |
| 158035 | 158055 | Vdbe *v = pParse->pVdbe; /* VDBE under construction */ |
| 158036 | 158056 | WhereLoop *pLoop = pLevel->pWLoop; /* The loop being coded */ |
| 158037 | 158057 | int iCur; /* Cursor for table getting the filter */ |
| 158058 | + IndexedExpr *saved_pIdxEpr; /* saved copy of Parse.pIdxEpr */ |
| 158059 | + |
| 158060 | + saved_pIdxEpr = pParse->pIdxEpr; |
| 158061 | + pParse->pIdxEpr = 0; |
| 158038 | 158062 | |
| 158039 | 158063 | assert( pLoop!=0 ); |
| 158040 | 158064 | assert( v!=0 ); |
| 158041 | 158065 | assert( pLoop->wsFlags & WHERE_BLOOMFILTER ); |
| 158042 | 158066 | |
| | @@ -158089,13 +158113,12 @@ |
| 158089 | 158113 | Index *pIdx = pLoop->u.btree.pIndex; |
| 158090 | 158114 | int n = pLoop->u.btree.nEq; |
| 158091 | 158115 | int r1 = sqlite3GetTempRange(pParse, n); |
| 158092 | 158116 | int jj; |
| 158093 | 158117 | for(jj=0; jj<n; jj++){ |
| 158094 | | - int iCol = pIdx->aiColumn[jj]; |
| 158095 | 158118 | assert( pIdx->pTable==pItem->pTab ); |
| 158096 | | - sqlite3ExprCodeGetColumnOfTable(v, pIdx->pTable, iCur, iCol,r1+jj); |
| 158119 | + sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iCur, jj, r1+jj); |
| 158097 | 158120 | } |
| 158098 | 158121 | sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, r1, n); |
| 158099 | 158122 | sqlite3ReleaseTempRange(pParse, r1, n); |
| 158100 | 158123 | } |
| 158101 | 158124 | sqlite3VdbeResolveLabel(v, addrCont); |
| | @@ -158122,10 +158145,11 @@ |
| 158122 | 158145 | break; |
| 158123 | 158146 | } |
| 158124 | 158147 | } |
| 158125 | 158148 | }while( iLevel < pWInfo->nLevel ); |
| 158126 | 158149 | sqlite3VdbeJumpHere(v, addrOnce); |
| 158150 | + pParse->pIdxEpr = saved_pIdxEpr; |
| 158127 | 158151 | } |
| 158128 | 158152 | |
| 158129 | 158153 | |
| 158130 | 158154 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 158131 | 158155 | /* |
| | @@ -162193,10 +162217,14 @@ |
| 162193 | 162217 | pWInfo->nOBSat = pFrom->isOrdered; |
| 162194 | 162218 | if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){ |
| 162195 | 162219 | if( pFrom->isOrdered==pWInfo->pOrderBy->nExpr ){ |
| 162196 | 162220 | pWInfo->eDistinct = WHERE_DISTINCT_ORDERED; |
| 162197 | 162221 | } |
| 162222 | + if( pWInfo->pSelect->pOrderBy |
| 162223 | + && pWInfo->nOBSat > pWInfo->pSelect->pOrderBy->nExpr ){ |
| 162224 | + pWInfo->nOBSat = pWInfo->pSelect->pOrderBy->nExpr; |
| 162225 | + } |
| 162198 | 162226 | }else{ |
| 162199 | 162227 | pWInfo->revMask = pFrom->revLoop; |
| 162200 | 162228 | if( pWInfo->nOBSat<=0 ){ |
| 162201 | 162229 | pWInfo->nOBSat = 0; |
| 162202 | 162230 | if( nLoop>0 ){ |
| | @@ -240222,11 +240250,11 @@ |
| 240222 | 240250 | int nArg, /* Number of args */ |
| 240223 | 240251 | sqlite3_value **apUnused /* Function arguments */ |
| 240224 | 240252 | ){ |
| 240225 | 240253 | assert( nArg==0 ); |
| 240226 | 240254 | UNUSED_PARAM2(nArg, apUnused); |
| 240227 | | - sqlite3_result_text(pCtx, "fts5: 2023-03-09 16:04:34 cc8a0ee40cfc83ab42a0ff452de0a53fe17784aefb944ea7ac2cb078a8310730", -1, SQLITE_TRANSIENT); |
| 240255 | + sqlite3_result_text(pCtx, "fts5: 2023-03-17 12:25:10 c5bd0ea3b5b2f3ed8e971c5fd6e85e8f06d8055d74df65612c3794138306e6ba", -1, SQLITE_TRANSIENT); |
| 240228 | 240256 | } |
| 240229 | 240257 | |
| 240230 | 240258 | /* |
| 240231 | 240259 | ** Return true if zName is the extension on one of the shadow tables used |
| 240232 | 240260 | ** by this module. |
| 240233 | 240261 | |