1
1
/******************************************************************************
2
2
** 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
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.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 "
458
458
459
459
/*
460
460
** CAPI3REF: Run-Time Library Version Numbers
@@ -19156,6 +19156,7 @@ struct IndexedExpr {
19156
19156
int iIdxCur; /* The index cursor */
19157
19157
int iIdxCol; /* The index column that contains value of pExpr */
19158
19158
u8 bMaybeNullRow; /* True if we need an OP_IfNullRow check */
19159
+ u8 aff; /* Affinity of the pExpr expression */
19159
19160
IndexedExpr *pIENext; /* Next in a list of all indexed expressions */
19160
19161
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
19161
19162
const char *zIdxName; /* Name of index, used only for bytecode comments */
@@ -90915,8 +90916,7 @@ static u64 filterHash(const Mem *aMem, const Op *pOp){
90915
90916
}else if( p->flags & MEM_Real ){
90916
90917
h += sqlite3VdbeIntValue(p);
90917
90918
}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 */
90920
90920
}
90921
90921
}
90922
90922
return h;
@@ -104495,14 +104495,10 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
104495
104495
if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
104496
104496
testcase( ExprHasProperty(pExpr, EP_OuterON) );
104497
104497
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
+
104506
104502
for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
104507
104503
p->nRef = anRef[i];
104508
104504
}
@@ -109848,13 +109844,24 @@ static SQLITE_NOINLINE int sqlite3IndexedExprLookup(
109848
109844
IndexedExpr *p;
109849
109845
Vdbe *v;
109850
109846
for(p=pParse->pIdxEpr; p; p=p->pIENext){
109847
+ u8 exprAff;
109851
109848
int iDataCur = p->iDataCur;
109852
109849
if( iDataCur<0 ) continue;
109853
109850
if( pParse->iSelfTab ){
109854
109851
if( p->iDataCur!=pParse->iSelfTab-1 ) continue;
109855
109852
iDataCur = -1;
109856
109853
}
109857
109854
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
+
109858
109865
v = pParse->pVdbe;
109859
109866
assert( v!=0 );
109860
109867
if( p->bMaybeNullRow ){
@@ -110434,10 +110441,13 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target)
110434
110441
return target;
110435
110442
}
110436
110443
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 );
110441
110451
inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
110442
110452
if( inReg!=target ){
110443
110453
sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
@@ -110545,16 +110555,22 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target)
110545
110555
break;
110546
110556
}
110547
110557
}
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 */
110554
110567
inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
110555
110568
pParse->okConstFactor = okConstFactor;
110569
+ if( inReg!=target ){ /* note (2) above */
110570
+ sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
110571
+ inReg = target;
110572
+ }
110556
110573
sqlite3VdbeJumpHere(v, addrINR);
110557
- sqlite3VdbeChangeP3(v, addrINR, inReg);
110558
110574
break;
110559
110575
}
110560
110576
@@ -119478,6 +119494,7 @@ SQLITE_PRIVATE void sqlite3AddGenerated(Parse *pParse, Expr *pExpr, Token *pType
119478
119494
** turn it into one by adding a unary "+" operator. */
119479
119495
pExpr = sqlite3PExpr(pParse, TK_UPLUS, pExpr, 0);
119480
119496
}
119497
+ if( pExpr && pExpr->op!=TK_RAISE ) pExpr->affExpr = pCol->affinity;
119481
119498
sqlite3ColumnSetExpr(pParse, pTab, pCol, pExpr);
119482
119499
pExpr = 0;
119483
119500
goto generated_done;
@@ -126881,6 +126898,18 @@ static void ceilingFunc(
126881
126898
static double xCeil(double x){ return ceil(x); }
126882
126899
static double xFloor(double x){ return floor(x); }
126883
126900
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
+
126884
126913
/*
126885
126914
** Implementation of SQL functions:
126886
126915
**
@@ -136260,6 +136289,23 @@ SQLITE_PRIVATE void sqlite3Pragma(
136260
136289
jmp4 = integrityCheckResultRow(v);
136261
136290
sqlite3VdbeJumpHere(v, jmp2);
136262
136291
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
+
136263
136309
/* Any indexed columns with non-BINARY collations must still hold
136264
136310
** the exact same text value as the table. */
136265
136311
label6 = 0;
@@ -140555,8 +140601,6 @@ SQLITE_PRIVATE void sqlite3SubqueryColumnTypes(
140555
140601
pCol->affinity = sqlite3ExprAffinity(p);
140556
140602
if( pCol->affinity<=SQLITE_AFF_NONE ){
140557
140603
pCol->affinity = aff;
140558
- }else if( pCol->affinity>=SQLITE_AFF_NUMERIC && p->op==TK_CAST ){
140559
- pCol->affinity = SQLITE_AFF_FLEXNUM;
140560
140604
}
140561
140605
if( pCol->affinity>=SQLITE_AFF_TEXT && pSelect->pNext ){
140562
140606
int m = 0;
@@ -140570,6 +140614,9 @@ SQLITE_PRIVATE void sqlite3SubqueryColumnTypes(
140570
140614
if( pCol->affinity>=SQLITE_AFF_NUMERIC && (m&0x02)!=0 ){
140571
140615
pCol->affinity = SQLITE_AFF_BLOB;
140572
140616
}
140617
+ if( pCol->affinity>=SQLITE_AFF_NUMERIC && p->op==TK_CAST ){
140618
+ pCol->affinity = SQLITE_AFF_FLEXNUM;
140619
+ }
140573
140620
}
140574
140621
zType = columnType(&sNC, p, 0, 0, 0);
140575
140622
if( zType==0 || pCol->affinity!=sqlite3AffinityType(zType, 0) ){
@@ -142084,7 +142131,7 @@ static Expr *substExpr(
142084
142131
sqlite3VectorErrorMsg(pSubst->pParse, pCopy);
142085
142132
}else{
142086
142133
sqlite3 *db = pSubst->pParse->db;
142087
- if( pSubst->isOuterJoin && pCopy->op!=TK_COLUMN ){
142134
+ if( pSubst->isOuterJoin ){
142088
142135
memset(&ifNullRow, 0, sizeof(ifNullRow));
142089
142136
ifNullRow.op = TK_IF_NULL_ROW;
142090
142137
ifNullRow.pLeft = pCopy;
@@ -144600,10 +144647,12 @@ static void optimizeAggregateUseOfIndexedExpr(
144600
144647
NameContext *pNC /* Name context used to resolve agg-func args */
144601
144648
){
144602
144649
assert( pAggInfo->iFirstReg==0 );
144650
+ assert( pSelect!=0 );
144651
+ assert( pSelect->pGroupBy!=0 );
144603
144652
pAggInfo->nColumn = pAggInfo->nAccumulator;
144604
144653
if( ALWAYS(pAggInfo->nSortingColumn>0) ){
144605
144654
if( pAggInfo->nColumn==0 ){
144606
- pAggInfo->nSortingColumn = 0 ;
144655
+ pAggInfo->nSortingColumn = pSelect->pGroupBy->nExpr ;
144607
144656
}else{
144608
144657
pAggInfo->nSortingColumn =
144609
144658
pAggInfo->aCol[pAggInfo->nColumn-1].iSorterColumn+1;
@@ -145028,6 +145077,7 @@ static int countOfViewOptimization(Parse *pParse, Select *p){
145028
145077
if( p->pEList->nExpr!=1 ) return 0; /* Single result column */
145029
145078
if( p->pWhere ) return 0;
145030
145079
if( p->pGroupBy ) return 0;
145080
+ if( p->pOrderBy ) return 0;
145031
145081
pExpr = p->pEList->a[0].pExpr;
145032
145082
if( pExpr->op!=TK_AGG_FUNCTION ) return 0; /* Result is an aggregate */
145033
145083
assert( ExprUseUToken(pExpr) );
@@ -145038,7 +145088,8 @@ static int countOfViewOptimization(Parse *pParse, Select *p){
145038
145088
if( ExprHasProperty(pExpr, EP_WinFunc) ) return 0;/* Not a window function */
145039
145089
pSub = p->pSrc->a[0].pSelect;
145040
145090
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 */
145042
145093
do{
145043
145094
if( pSub->op!=TK_ALL && pSub->pPrior ) return 0; /* Must be UNION ALL */
145044
145095
if( pSub->pWhere ) return 0; /* No WHERE clause */
@@ -145481,7 +145532,6 @@ SQLITE_PRIVATE int sqlite3Select(
145481
145532
&& countOfViewOptimization(pParse, p)
145482
145533
){
145483
145534
if( db->mallocFailed ) goto select_end;
145484
- pEList = p->pEList;
145485
145535
pTabList = p->pSrc;
145486
145536
}
145487
145537
#endif
@@ -147624,7 +147674,7 @@ static void codeReturningTrigger(
147624
147674
}
147625
147675
sqlite3ExprListDelete(db, sSelect.pEList);
147626
147676
pNew = sqlite3ExpandReturning(pParse, pReturning->pReturnEL, pTab);
147627
- if( !db->mallocFailed ){
147677
+ if( pParse->nErr==0 ){
147628
147678
NameContext sNC;
147629
147679
memset(&sNC, 0, sizeof(sNC));
147630
147680
if( pReturning->nRetCol==0 ){
@@ -156848,7 +156898,7 @@ SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(
156848
156898
pRhs = sqlite3PExpr(pParse, TK_UPLUS,
156849
156899
sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
156850
156900
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 ) ){
156852
156902
joinType = EP_OuterON;
156853
156903
}else{
156854
156904
joinType = EP_InnerON;
@@ -162556,6 +162606,9 @@ static SQLITE_NOINLINE void whereAddIndexedExpr(
162556
162606
p->iIdxCur = iIdxCur;
162557
162607
p->iIdxCol = i;
162558
162608
p->bMaybeNullRow = bMaybeNullRow;
162609
+ if( sqlite3IndexAffinityStr(pParse->db, pIdx) ){
162610
+ p->aff = pIdx->zColAff[i];
162611
+ }
162559
162612
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
162560
162613
p->zIdxName = pIdx->zName;
162561
162614
#endif
@@ -240171,7 +240224,7 @@ static void fts5SourceIdFunc(
240171
240224
){
240172
240225
assert( nArg==0 );
240173
240226
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);
240175
240228
}
240176
240229
240177
240230
/*
0 commit comments