11/******************************************************************************
22** This file is an amalgamation of many separate C source files from SQLite
3- ** version 3.41.0 . By combining all the individual C code files into this
3+ ** version 3.41.1 . 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.0 "
456- #define SQLITE_VERSION_NUMBER 3041000
457- #define SQLITE_SOURCE_ID "2023-02-21 18:09:37 05941c2a04037fc3ed2ffae11f5d2260706f89431f463518740f72ada350866d "
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 "
458458
459459/*
460460** CAPI3REF: Run-Time Library Version Numbers
@@ -19156,6 +19156,7 @@ struct IndexedExpr {
1915619156 int iIdxCur; /* The index cursor */
1915719157 int iIdxCol; /* The index column that contains value of pExpr */
1915819158 u8 bMaybeNullRow; /* True if we need an OP_IfNullRow check */
19159+ u8 aff; /* Affinity of the pExpr expression */
1915919160 IndexedExpr *pIENext; /* Next in a list of all indexed expressions */
1916019161#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
1916119162 const char *zIdxName; /* Name of index, used only for bytecode comments */
@@ -90915,8 +90916,7 @@ static u64 filterHash(const Mem *aMem, const Op *pOp){
9091590916 }else if( p->flags & MEM_Real ){
9091690917 h += sqlite3VdbeIntValue(p);
9091790918 }else if( p->flags & (MEM_Str|MEM_Blob) ){
90918- h += p->n;
90919- if( p->flags & MEM_Zero ) h += p->u.nZero;
90919+ /* no-op */
9092090920 }
9092190921 }
9092290922 return h;
@@ -104495,14 +104495,10 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
104495104495 if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
104496104496 testcase( ExprHasProperty(pExpr, EP_OuterON) );
104497104497 assert( !ExprHasProperty(pExpr, EP_IntValue) );
104498- if( pExpr->op==TK_NOTNULL ){
104499- pExpr->u.zToken = "true";
104500- ExprSetProperty(pExpr, EP_IsTrue);
104501- }else{
104502- pExpr->u.zToken = "false";
104503- ExprSetProperty(pExpr, EP_IsFalse);
104504- }
104505- pExpr->op = TK_TRUEFALSE;
104498+ pExpr->u.iValue = (pExpr->op==TK_NOTNULL);
104499+ pExpr->flags |= EP_IntValue;
104500+ pExpr->op = TK_INTEGER;
104501+
104506104502 for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
104507104503 p->nRef = anRef[i];
104508104504 }
@@ -109848,13 +109844,24 @@ static SQLITE_NOINLINE int sqlite3IndexedExprLookup(
109848109844 IndexedExpr *p;
109849109845 Vdbe *v;
109850109846 for(p=pParse->pIdxEpr; p; p=p->pIENext){
109847+ u8 exprAff;
109851109848 int iDataCur = p->iDataCur;
109852109849 if( iDataCur<0 ) continue;
109853109850 if( pParse->iSelfTab ){
109854109851 if( p->iDataCur!=pParse->iSelfTab-1 ) continue;
109855109852 iDataCur = -1;
109856109853 }
109857109854 if( sqlite3ExprCompare(0, pExpr, p->pExpr, iDataCur)!=0 ) continue;
109855+ assert( p->aff>=SQLITE_AFF_BLOB && p->aff<=SQLITE_AFF_NUMERIC );
109856+ exprAff = sqlite3ExprAffinity(pExpr);
109857+ if( (exprAff<=SQLITE_AFF_BLOB && p->aff!=SQLITE_AFF_BLOB)
109858+ || (exprAff==SQLITE_AFF_TEXT && p->aff!=SQLITE_AFF_TEXT)
109859+ || (exprAff>=SQLITE_AFF_NUMERIC && p->aff!=SQLITE_AFF_NUMERIC)
109860+ ){
109861+ /* Affinity mismatch on a generated column */
109862+ continue;
109863+ }
109864+
109858109865 v = pParse->pVdbe;
109859109866 assert( v!=0 );
109860109867 if( p->bMaybeNullRow ){
@@ -110434,10 +110441,13 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target)
110434110441 return target;
110435110442 }
110436110443 case TK_COLLATE: {
110437- if( !ExprHasProperty(pExpr, EP_Collate)
110438- && ALWAYS(pExpr->pLeft)
110439- && pExpr->pLeft->op==TK_FUNCTION
110440- ){
110444+ if( !ExprHasProperty(pExpr, EP_Collate) ){
110445+ /* A TK_COLLATE Expr node without the EP_Collate tag is a so-called
110446+ ** "SOFT-COLLATE" that is added to constraints that are pushed down
110447+ ** from outer queries into sub-queries by the push-down optimization.
110448+ ** Clear subtypes as subtypes may not cross a subquery boundary.
110449+ */
110450+ assert( pExpr->pLeft );
110441110451 inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
110442110452 if( inReg!=target ){
110443110453 sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
@@ -110545,16 +110555,22 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target)
110545110555 break;
110546110556 }
110547110557 }
110548- addrINR = sqlite3VdbeAddOp1(v, OP_IfNullRow, pExpr->iTable);
110549- /* Temporarily disable factoring of constant expressions, since
110550- ** even though expressions may appear to be constant, they are not
110551- ** really constant because they originate from the right-hand side
110552- ** of a LEFT JOIN. */
110553- pParse->okConstFactor = 0;
110558+ addrINR = sqlite3VdbeAddOp3(v, OP_IfNullRow, pExpr->iTable, 0, target);
110559+ /* The OP_IfNullRow opcode above can overwrite the result register with
110560+ ** NULL. So we have to ensure that the result register is not a value
110561+ ** that is suppose to be a constant. Two defenses are needed:
110562+ ** (1) Temporarily disable factoring of constant expressions
110563+ ** (2) Make sure the computed value really is stored in register
110564+ ** "target" and not someplace else.
110565+ */
110566+ pParse->okConstFactor = 0; /* note (1) above */
110554110567 inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
110555110568 pParse->okConstFactor = okConstFactor;
110569+ if( inReg!=target ){ /* note (2) above */
110570+ sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
110571+ inReg = target;
110572+ }
110556110573 sqlite3VdbeJumpHere(v, addrINR);
110557- sqlite3VdbeChangeP3(v, addrINR, inReg);
110558110574 break;
110559110575 }
110560110576
@@ -119478,6 +119494,7 @@ SQLITE_PRIVATE void sqlite3AddGenerated(Parse *pParse, Expr *pExpr, Token *pType
119478119494 ** turn it into one by adding a unary "+" operator. */
119479119495 pExpr = sqlite3PExpr(pParse, TK_UPLUS, pExpr, 0);
119480119496 }
119497+ if( pExpr && pExpr->op!=TK_RAISE ) pExpr->affExpr = pCol->affinity;
119481119498 sqlite3ColumnSetExpr(pParse, pTab, pCol, pExpr);
119482119499 pExpr = 0;
119483119500 goto generated_done;
@@ -126881,6 +126898,18 @@ static void ceilingFunc(
126881126898static double xCeil(double x){ return ceil(x); }
126882126899static double xFloor(double x){ return floor(x); }
126883126900
126901+ /*
126902+ ** Some systems do not have log2() and log10() in their standard math
126903+ ** libraries.
126904+ */
126905+ #if defined(HAVE_LOG10) && HAVE_LOG10==0
126906+ # define log10(X) (0.4342944819032517867*log(X))
126907+ #endif
126908+ #if defined(HAVE_LOG2) && HAVE_LOG2==0
126909+ # define log2(X) (1.442695040888963456*log(X))
126910+ #endif
126911+
126912+
126884126913/*
126885126914** Implementation of SQL functions:
126886126915**
@@ -136260,6 +136289,23 @@ SQLITE_PRIVATE void sqlite3Pragma(
136260136289 jmp4 = integrityCheckResultRow(v);
136261136290 sqlite3VdbeJumpHere(v, jmp2);
136262136291
136292+ /* The OP_IdxRowid opcode is an optimized version of OP_Column
136293+ ** that extracts the rowid off the end of the index record.
136294+ ** But it only works correctly if index record does not have
136295+ ** any extra bytes at the end. Verify that this is the case. */
136296+ if( HasRowid(pTab) ){
136297+ int jmp7;
136298+ sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur+j, 3);
136299+ jmp7 = sqlite3VdbeAddOp3(v, OP_Eq, 3, 0, r1+pIdx->nColumn-1);
136300+ VdbeCoverage(v);
136301+ sqlite3VdbeLoadString(v, 3,
136302+ "rowid not at end-of-record for row ");
136303+ sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
136304+ sqlite3VdbeLoadString(v, 4, " of index ");
136305+ sqlite3VdbeGoto(v, jmp5-1);
136306+ sqlite3VdbeJumpHere(v, jmp7);
136307+ }
136308+
136263136309 /* Any indexed columns with non-BINARY collations must still hold
136264136310 ** the exact same text value as the table. */
136265136311 label6 = 0;
@@ -140555,8 +140601,6 @@ SQLITE_PRIVATE void sqlite3SubqueryColumnTypes(
140555140601 pCol->affinity = sqlite3ExprAffinity(p);
140556140602 if( pCol->affinity<=SQLITE_AFF_NONE ){
140557140603 pCol->affinity = aff;
140558- }else if( pCol->affinity>=SQLITE_AFF_NUMERIC && p->op==TK_CAST ){
140559- pCol->affinity = SQLITE_AFF_FLEXNUM;
140560140604 }
140561140605 if( pCol->affinity>=SQLITE_AFF_TEXT && pSelect->pNext ){
140562140606 int m = 0;
@@ -140570,6 +140614,9 @@ SQLITE_PRIVATE void sqlite3SubqueryColumnTypes(
140570140614 if( pCol->affinity>=SQLITE_AFF_NUMERIC && (m&0x02)!=0 ){
140571140615 pCol->affinity = SQLITE_AFF_BLOB;
140572140616 }
140617+ if( pCol->affinity>=SQLITE_AFF_NUMERIC && p->op==TK_CAST ){
140618+ pCol->affinity = SQLITE_AFF_FLEXNUM;
140619+ }
140573140620 }
140574140621 zType = columnType(&sNC, p, 0, 0, 0);
140575140622 if( zType==0 || pCol->affinity!=sqlite3AffinityType(zType, 0) ){
@@ -142084,7 +142131,7 @@ static Expr *substExpr(
142084142131 sqlite3VectorErrorMsg(pSubst->pParse, pCopy);
142085142132 }else{
142086142133 sqlite3 *db = pSubst->pParse->db;
142087- if( pSubst->isOuterJoin && pCopy->op!=TK_COLUMN ){
142134+ if( pSubst->isOuterJoin ){
142088142135 memset(&ifNullRow, 0, sizeof(ifNullRow));
142089142136 ifNullRow.op = TK_IF_NULL_ROW;
142090142137 ifNullRow.pLeft = pCopy;
@@ -144600,10 +144647,12 @@ static void optimizeAggregateUseOfIndexedExpr(
144600144647 NameContext *pNC /* Name context used to resolve agg-func args */
144601144648){
144602144649 assert( pAggInfo->iFirstReg==0 );
144650+ assert( pSelect!=0 );
144651+ assert( pSelect->pGroupBy!=0 );
144603144652 pAggInfo->nColumn = pAggInfo->nAccumulator;
144604144653 if( ALWAYS(pAggInfo->nSortingColumn>0) ){
144605144654 if( pAggInfo->nColumn==0 ){
144606- pAggInfo->nSortingColumn = 0 ;
144655+ pAggInfo->nSortingColumn = pSelect->pGroupBy->nExpr ;
144607144656 }else{
144608144657 pAggInfo->nSortingColumn =
144609144658 pAggInfo->aCol[pAggInfo->nColumn-1].iSorterColumn+1;
@@ -145028,6 +145077,7 @@ static int countOfViewOptimization(Parse *pParse, Select *p){
145028145077 if( p->pEList->nExpr!=1 ) return 0; /* Single result column */
145029145078 if( p->pWhere ) return 0;
145030145079 if( p->pGroupBy ) return 0;
145080+ if( p->pOrderBy ) return 0;
145031145081 pExpr = p->pEList->a[0].pExpr;
145032145082 if( pExpr->op!=TK_AGG_FUNCTION ) return 0; /* Result is an aggregate */
145033145083 assert( ExprUseUToken(pExpr) );
@@ -145038,7 +145088,8 @@ static int countOfViewOptimization(Parse *pParse, Select *p){
145038145088 if( ExprHasProperty(pExpr, EP_WinFunc) ) return 0;/* Not a window function */
145039145089 pSub = p->pSrc->a[0].pSelect;
145040145090 if( pSub==0 ) return 0; /* The FROM is a subquery */
145041- if( pSub->pPrior==0 ) return 0; /* Must be a compound ry */
145091+ if( pSub->pPrior==0 ) return 0; /* Must be a compound */
145092+ if( pSub->selFlags & SF_CopyCte ) return 0; /* Not a CTE */
145042145093 do{
145043145094 if( pSub->op!=TK_ALL && pSub->pPrior ) return 0; /* Must be UNION ALL */
145044145095 if( pSub->pWhere ) return 0; /* No WHERE clause */
@@ -145481,7 +145532,6 @@ SQLITE_PRIVATE int sqlite3Select(
145481145532 && countOfViewOptimization(pParse, p)
145482145533 ){
145483145534 if( db->mallocFailed ) goto select_end;
145484- pEList = p->pEList;
145485145535 pTabList = p->pSrc;
145486145536 }
145487145537#endif
@@ -147624,7 +147674,7 @@ static void codeReturningTrigger(
147624147674 }
147625147675 sqlite3ExprListDelete(db, sSelect.pEList);
147626147676 pNew = sqlite3ExpandReturning(pParse, pReturning->pReturnEL, pTab);
147627- if( !db->mallocFailed ){
147677+ if( pParse->nErr==0 ){
147628147678 NameContext sNC;
147629147679 memset(&sNC, 0, sizeof(sNC));
147630147680 if( pReturning->nRetCol==0 ){
@@ -156848,7 +156898,7 @@ SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(
156848156898 pRhs = sqlite3PExpr(pParse, TK_UPLUS,
156849156899 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
156850156900 pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs);
156851- if( pItem->fg.jointype & (JT_LEFT|JT_LTORJ) ){
156901+ if( pItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT ) ){
156852156902 joinType = EP_OuterON;
156853156903 }else{
156854156904 joinType = EP_InnerON;
@@ -162556,6 +162606,9 @@ static SQLITE_NOINLINE void whereAddIndexedExpr(
162556162606 p->iIdxCur = iIdxCur;
162557162607 p->iIdxCol = i;
162558162608 p->bMaybeNullRow = bMaybeNullRow;
162609+ if( sqlite3IndexAffinityStr(pParse->db, pIdx) ){
162610+ p->aff = pIdx->zColAff[i];
162611+ }
162559162612#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
162560162613 p->zIdxName = pIdx->zName;
162561162614#endif
@@ -240171,7 +240224,7 @@ static void fts5SourceIdFunc(
240171240224){
240172240225 assert( nArg==0 );
240173240226 UNUSED_PARAM2(nArg, apUnused);
240174- sqlite3_result_text(pCtx, "fts5: 2023-02-21 18:09:37 05941c2a04037fc3ed2ffae11f5d2260706f89431f463518740f72ada350866d ", -1, SQLITE_TRANSIENT);
240227+ sqlite3_result_text(pCtx, "fts5: 2023-03-10 12:13:52 20399f3eda5ec249d147ba9e48da6e87f969d7966a9a896764ca437ff7e737ff ", -1, SQLITE_TRANSIENT);
240175240228}
240176240229
240177240230/*
0 commit comments