Fossil SCM
Update the built-in SQLite to the latest version from trunk, for SQLite testing.
Commit
e9d8c04c94fd072dcaac4732f9e8053df48c59f057e2f47b99ba2a5340904688
Parent
00b6b2f4dc47fc1…
2 files changed
+95
-35
+1
-1
+95
-35
| --- extsrc/sqlite3.c | ||
| +++ extsrc/sqlite3.c | ||
| @@ -16,11 +16,11 @@ | ||
| 16 | 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | 19 | ** |
| 20 | 20 | ** The content in this amalgamation comes from Fossil check-in |
| 21 | -** 7bf49e2c54c9f6f336416f01c0e76aaf70f1. | |
| 21 | +** 69ec714b2d698acf9e37635256c01b233ce3. | |
| 22 | 22 | */ |
| 23 | 23 | #define SQLITE_CORE 1 |
| 24 | 24 | #define SQLITE_AMALGAMATION 1 |
| 25 | 25 | #ifndef SQLITE_PRIVATE |
| 26 | 26 | # define SQLITE_PRIVATE static |
| @@ -459,11 +459,11 @@ | ||
| 459 | 459 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 460 | 460 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 461 | 461 | */ |
| 462 | 462 | #define SQLITE_VERSION "3.46.0" |
| 463 | 463 | #define SQLITE_VERSION_NUMBER 3046000 |
| 464 | -#define SQLITE_SOURCE_ID "2024-04-04 14:26:42 7bf49e2c54c9f6f336416f01c0e76aaf70f1e2f3fd612232e5a33ae5dabe0900" | |
| 464 | +#define SQLITE_SOURCE_ID "2024-04-08 11:50:07 69ec714b2d698acf9e37635256c01b233ce32f22e8323e226441d5ddd948a940" | |
| 465 | 465 | |
| 466 | 466 | /* |
| 467 | 467 | ** CAPI3REF: Run-Time Library Version Numbers |
| 468 | 468 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 469 | 469 | ** |
| @@ -17832,11 +17832,11 @@ | ||
| 17832 | 17832 | #define SQLITE_OmitNoopJoin 0x00000100 /* Omit unused tables in joins */ |
| 17833 | 17833 | #define SQLITE_CountOfView 0x00000200 /* The count-of-view optimization */ |
| 17834 | 17834 | #define SQLITE_CursorHints 0x00000400 /* Add OP_CursorHint opcodes */ |
| 17835 | 17835 | #define SQLITE_Stat4 0x00000800 /* Use STAT4 data */ |
| 17836 | 17836 | /* TH3 expects this value ^^^^^^^^^^ to be 0x0000800. Don't change it */ |
| 17837 | -#define SQLITE_PushDown 0x00001000 /* The push-down optimization */ | |
| 17837 | +#define SQLITE_PushDown 0x00001000 /* WHERE-clause push-down opt */ | |
| 17838 | 17838 | #define SQLITE_SimplifyJoin 0x00002000 /* Convert LEFT JOIN to JOIN */ |
| 17839 | 17839 | #define SQLITE_SkipScan 0x00004000 /* Skip-scans */ |
| 17840 | 17840 | #define SQLITE_PropagateConst 0x00008000 /* The constant propagation opt */ |
| 17841 | 17841 | #define SQLITE_MinMaxOpt 0x00010000 /* The min/max optimization */ |
| 17842 | 17842 | #define SQLITE_SeekScan 0x00020000 /* The OP_SeekScan optimization */ |
| @@ -19506,15 +19506,16 @@ | ||
| 19506 | 19506 | #define SF_WhereBegin 0x0080000 /* Really a WhereBegin() call. Debug Only */ |
| 19507 | 19507 | #define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */ |
| 19508 | 19508 | #define SF_View 0x0200000 /* SELECT statement is a view */ |
| 19509 | 19509 | #define SF_NoopOrderBy 0x0400000 /* ORDER BY is ignored for this query */ |
| 19510 | 19510 | #define SF_UFSrcCheck 0x0800000 /* Check pSrc as required by UPDATE...FROM */ |
| 19511 | -#define SF_PushDown 0x1000000 /* SELECT has be modified by push-down opt */ | |
| 19511 | +#define SF_PushDown 0x1000000 /* Modified by WHERE-clause push-down opt */ | |
| 19512 | 19512 | #define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */ |
| 19513 | 19513 | #define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */ |
| 19514 | 19514 | #define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */ |
| 19515 | 19515 | #define SF_UpdateFrom 0x10000000 /* Query originates with UPDATE FROM */ |
| 19516 | +#define SF_Correlated 0x20000000 /* True if references the outer context */ | |
| 19516 | 19517 | |
| 19517 | 19518 | /* True if S exists and has SF_NestedFrom */ |
| 19518 | 19519 | #define IsNestedFrom(S) ((S)!=0 && ((S)->selFlags&SF_NestedFrom)!=0) |
| 19519 | 19520 | |
| 19520 | 19521 | /* |
| @@ -21007,12 +21008,11 @@ | ||
| 21007 | 21008 | SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr*); |
| 21008 | 21009 | SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr*); |
| 21009 | 21010 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Parse*,Expr*); |
| 21010 | 21011 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8); |
| 21011 | 21012 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*); |
| 21012 | -SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int); | |
| 21013 | -SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcList*,int); | |
| 21013 | +SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcList*,int,int); | |
| 21014 | 21014 | #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 21015 | 21015 | SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*); |
| 21016 | 21016 | #endif |
| 21017 | 21017 | SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*); |
| 21018 | 21018 | SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); |
| @@ -107284,10 +107284,15 @@ | ||
| 107284 | 107284 | && (pNC->ncFlags & (NC_IdxExpr|NC_GenCol))==0 |
| 107285 | 107285 | && sqlite3IsRowid(zCol) |
| 107286 | 107286 | && ALWAYS(VisibleRowid(pMatch->pTab) || pMatch->fg.isNestedFrom) |
| 107287 | 107287 | ){ |
| 107288 | 107288 | cnt = cntTab; |
| 107289 | +#if SQLITE_ALLOW_ROWID_IN_VIEW+0==2 | |
| 107290 | + if( pMatch->pTab!=0 && IsView(pMatch->pTab) ){ | |
| 107291 | + eNewExprOp = TK_NULL; | |
| 107292 | + } | |
| 107293 | +#endif | |
| 107289 | 107294 | if( pMatch->fg.isNestedFrom==0 ) pExpr->iColumn = -1; |
| 107290 | 107295 | pExpr->affExpr = SQLITE_AFF_INTEGER; |
| 107291 | 107296 | } |
| 107292 | 107297 | |
| 107293 | 107298 | /* |
| @@ -108001,18 +108006,20 @@ | ||
| 108001 | 108006 | int nRef = pNC->nRef; |
| 108002 | 108007 | testcase( pNC->ncFlags & NC_IsCheck ); |
| 108003 | 108008 | testcase( pNC->ncFlags & NC_PartIdx ); |
| 108004 | 108009 | testcase( pNC->ncFlags & NC_IdxExpr ); |
| 108005 | 108010 | testcase( pNC->ncFlags & NC_GenCol ); |
| 108011 | + assert( pExpr->x.pSelect ); | |
| 108006 | 108012 | if( pNC->ncFlags & NC_SelfRef ){ |
| 108007 | 108013 | notValidImpl(pParse, pNC, "subqueries", pExpr, pExpr); |
| 108008 | 108014 | }else{ |
| 108009 | 108015 | sqlite3WalkSelect(pWalker, pExpr->x.pSelect); |
| 108010 | 108016 | } |
| 108011 | 108017 | assert( pNC->nRef>=nRef ); |
| 108012 | 108018 | if( nRef!=pNC->nRef ){ |
| 108013 | 108019 | ExprSetProperty(pExpr, EP_VarSelect); |
| 108020 | + pExpr->x.pSelect->selFlags |= SF_Correlated; | |
| 108014 | 108021 | } |
| 108015 | 108022 | pNC->ncFlags |= NC_Subquery; |
| 108016 | 108023 | } |
| 108017 | 108024 | break; |
| 108018 | 108025 | } |
| @@ -111425,20 +111432,19 @@ | ||
| 111425 | 111432 | testcase( pExpr->op==TK_SELECT ); /* sqlite3SelectWalkFail() disallows */ |
| 111426 | 111433 | testcase( pExpr->op==TK_EXISTS ); /* sqlite3SelectWalkFail() disallows */ |
| 111427 | 111434 | return WRC_Continue; |
| 111428 | 111435 | } |
| 111429 | 111436 | } |
| 111430 | -static int exprIsConst(Parse *pParse, Expr *p, int initFlag, int iCur){ | |
| 111437 | +static int exprIsConst(Parse *pParse, Expr *p, int initFlag){ | |
| 111431 | 111438 | Walker w; |
| 111432 | 111439 | w.eCode = initFlag; |
| 111433 | 111440 | w.pParse = pParse; |
| 111434 | 111441 | w.xExprCallback = exprNodeIsConstant; |
| 111435 | 111442 | w.xSelectCallback = sqlite3SelectWalkFail; |
| 111436 | 111443 | #ifdef SQLITE_DEBUG |
| 111437 | 111444 | w.xSelectCallback2 = sqlite3SelectWalkAssert2; |
| 111438 | 111445 | #endif |
| 111439 | - w.u.iCur = iCur; | |
| 111440 | 111446 | sqlite3WalkExpr(&w, p); |
| 111441 | 111447 | return w.eCode; |
| 111442 | 111448 | } |
| 111443 | 111449 | |
| 111444 | 111450 | /* |
| @@ -111454,11 +111460,11 @@ | ||
| 111454 | 111460 | ** function calls will be considered to be non-constant. If pParse is |
| 111455 | 111461 | ** not NULL, then a function call might be constant, depending on the |
| 111456 | 111462 | ** function and on its parameters. |
| 111457 | 111463 | */ |
| 111458 | 111464 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Parse *pParse, Expr *p){ |
| 111459 | - return exprIsConst(pParse, p, 1, 0); | |
| 111465 | + return exprIsConst(pParse, p, 1); | |
| 111460 | 111466 | } |
| 111461 | 111467 | |
| 111462 | 111468 | /* |
| 111463 | 111469 | ** Walk an expression tree. Return non-zero if |
| 111464 | 111470 | ** |
| @@ -111471,21 +111477,54 @@ | ||
| 111471 | 111477 | ** When this routine returns true, it indicates that the expression |
| 111472 | 111478 | ** can be added to the pParse->pConstExpr list and evaluated once when |
| 111473 | 111479 | ** the prepared statement starts up. See sqlite3ExprCodeRunJustOnce(). |
| 111474 | 111480 | */ |
| 111475 | 111481 | static int sqlite3ExprIsConstantNotJoin(Parse *pParse, Expr *p){ |
| 111476 | - return exprIsConst(pParse, p, 2, 0); | |
| 111482 | + return exprIsConst(pParse, p, 2); | |
| 111483 | +} | |
| 111484 | + | |
| 111485 | +/* | |
| 111486 | +** This routine examines sub-SELECT statements as an expression is being | |
| 111487 | +** walked as part of sqlite3ExprIsTableConstant(). Sub-SELECTs are considered | |
| 111488 | +** constant as long as they are uncorrelated - meaning that they do not | |
| 111489 | +** contain any terms from outer contexts. | |
| 111490 | +*/ | |
| 111491 | +static int exprSelectWalkTableConstant(Walker *pWalker, Select *pSelect){ | |
| 111492 | + assert( pSelect!=0 ); | |
| 111493 | + assert( pWalker->eCode==3 || pWalker->eCode==0 ); | |
| 111494 | + if( (pSelect->selFlags & SF_Correlated)!=0 ){ | |
| 111495 | + pWalker->eCode = 0; | |
| 111496 | + return WRC_Abort; | |
| 111497 | + } | |
| 111498 | + return WRC_Prune; | |
| 111477 | 111499 | } |
| 111478 | 111500 | |
| 111479 | 111501 | /* |
| 111480 | 111502 | ** Walk an expression tree. Return non-zero if the expression is constant |
| 111481 | 111503 | ** for any single row of the table with cursor iCur. In other words, the |
| 111482 | 111504 | ** expression must not refer to any non-deterministic function nor any |
| 111483 | 111505 | ** table other than iCur. |
| 111506 | +** | |
| 111507 | +** Consider uncorrelated subqueries to be constants if the bAllowSubq | |
| 111508 | +** parameter is true. | |
| 111484 | 111509 | */ |
| 111485 | -SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){ | |
| 111486 | - return exprIsConst(0, p, 3, iCur); | |
| 111510 | +static int sqlite3ExprIsTableConstant(Expr *p, int iCur, int bAllowSubq){ | |
| 111511 | + Walker w; | |
| 111512 | + w.eCode = 3; | |
| 111513 | + w.pParse = 0; | |
| 111514 | + w.xExprCallback = exprNodeIsConstant; | |
| 111515 | + if( bAllowSubq ){ | |
| 111516 | + w.xSelectCallback = exprSelectWalkTableConstant; | |
| 111517 | + }else{ | |
| 111518 | + w.xSelectCallback = sqlite3SelectWalkFail; | |
| 111519 | +#ifdef SQLITE_DEBUG | |
| 111520 | + w.xSelectCallback2 = sqlite3SelectWalkAssert2; | |
| 111521 | +#endif | |
| 111522 | + } | |
| 111523 | + w.u.iCur = iCur; | |
| 111524 | + sqlite3WalkExpr(&w, p); | |
| 111525 | + return w.eCode; | |
| 111487 | 111526 | } |
| 111488 | 111527 | |
| 111489 | 111528 | /* |
| 111490 | 111529 | ** Check pExpr to see if it is an constraint on the single data source |
| 111491 | 111530 | ** pSrc = &pSrcList->a[iSrc]. In other words, check to see if pExpr |
| @@ -111499,11 +111538,14 @@ | ||
| 111499 | 111538 | ** |
| 111500 | 111539 | ** To be an single-source constraint, the following must be true: |
| 111501 | 111540 | ** |
| 111502 | 111541 | ** (1) pExpr cannot refer to any table other than pSrc->iCursor. |
| 111503 | 111542 | ** |
| 111504 | -** (2) pExpr cannot use subqueries or non-deterministic functions. | |
| 111543 | +** (2a) pExpr cannot use subqueries unless the bAllowSubq parameter is | |
| 111544 | +** true and the subquery is non-correlated | |
| 111545 | +** | |
| 111546 | +** (2b) pExpr cannot use non-deterministic functions. | |
| 111505 | 111547 | ** |
| 111506 | 111548 | ** (3) pSrc cannot be part of the left operand for a RIGHT JOIN. |
| 111507 | 111549 | ** (Is there some way to relax this constraint?) |
| 111508 | 111550 | ** |
| 111509 | 111551 | ** (4) If pSrc is the right operand of a LEFT JOIN, then... |
| @@ -111528,11 +111570,12 @@ | ||
| 111528 | 111570 | ** on push-down. |
| 111529 | 111571 | */ |
| 111530 | 111572 | SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint( |
| 111531 | 111573 | Expr *pExpr, /* The constraint */ |
| 111532 | 111574 | const SrcList *pSrcList, /* Complete FROM clause */ |
| 111533 | - int iSrc /* Which element of pSrcList to use */ | |
| 111575 | + int iSrc, /* Which element of pSrcList to use */ | |
| 111576 | + int bAllowSubq /* Allow non-correlated subqueries */ | |
| 111534 | 111577 | ){ |
| 111535 | 111578 | const SrcItem *pSrc = &pSrcList->a[iSrc]; |
| 111536 | 111579 | if( pSrc->fg.jointype & JT_LTORJ ){ |
| 111537 | 111580 | return 0; /* rule (3) */ |
| 111538 | 111581 | } |
| @@ -111553,11 +111596,12 @@ | ||
| 111553 | 111596 | } |
| 111554 | 111597 | break; |
| 111555 | 111598 | } |
| 111556 | 111599 | } |
| 111557 | 111600 | } |
| 111558 | - return sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor); /* rules (1), (2) */ | |
| 111601 | + /* Rules (1), (2a), and (2b) handled by the following: */ | |
| 111602 | + return sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor, bAllowSubq); | |
| 111559 | 111603 | } |
| 111560 | 111604 | |
| 111561 | 111605 | |
| 111562 | 111606 | /* |
| 111563 | 111607 | ** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy(). |
| @@ -111638,11 +111682,11 @@ | ||
| 111638 | 111682 | ** is considered a variable but a single-quoted string (ex: 'abc') is |
| 111639 | 111683 | ** a constant. |
| 111640 | 111684 | */ |
| 111641 | 111685 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){ |
| 111642 | 111686 | assert( isInit==0 || isInit==1 ); |
| 111643 | - return exprIsConst(0, p, 4+isInit, 0); | |
| 111687 | + return exprIsConst(0, p, 4+isInit); | |
| 111644 | 111688 | } |
| 111645 | 111689 | |
| 111646 | 111690 | #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 111647 | 111691 | /* |
| 111648 | 111692 | ** Walk an expression tree. Return 1 if the expression contains a |
| @@ -113956,12 +114000,13 @@ | ||
| 113956 | 114000 | } |
| 113957 | 114001 | case TK_COLLATE: { |
| 113958 | 114002 | if( !ExprHasProperty(pExpr, EP_Collate) ){ |
| 113959 | 114003 | /* A TK_COLLATE Expr node without the EP_Collate tag is a so-called |
| 113960 | 114004 | ** "SOFT-COLLATE" that is added to constraints that are pushed down |
| 113961 | - ** from outer queries into sub-queries by the push-down optimization. | |
| 113962 | - ** Clear subtypes as subtypes may not cross a subquery boundary. | |
| 114005 | + ** from outer queries into sub-queries by the WHERE-clause push-down | |
| 114006 | + ** optimization. Clear subtypes as subtypes may not cross a subquery | |
| 114007 | + ** boundary. | |
| 113963 | 114008 | */ |
| 113964 | 114009 | assert( pExpr->pLeft ); |
| 113965 | 114010 | sqlite3ExprCode(pParse, pExpr->pLeft, target); |
| 113966 | 114011 | sqlite3VdbeAddOp1(v, OP_ClrSubtype, target); |
| 113967 | 114012 | return target; |
| @@ -147804,10 +147849,22 @@ | ||
| 147804 | 147849 | ** SELECT * FROM (SELECT a AS x, c-d AS y FROM t1 WHERE a=5 AND c-d=10) |
| 147805 | 147850 | ** WHERE x=5 AND y=10; |
| 147806 | 147851 | ** |
| 147807 | 147852 | ** The hope is that the terms added to the inner query will make it more |
| 147808 | 147853 | ** efficient. |
| 147854 | +** | |
| 147855 | +** NAME AMBIGUITY | |
| 147856 | +** | |
| 147857 | +** This optimization is called the "WHERE-clause push-down optimization". | |
| 147858 | +** | |
| 147859 | +** Do not confuse this optimization with another unrelated optimization | |
| 147860 | +** with a similar name: The "MySQL push-down optimization" causes WHERE | |
| 147861 | +** clause terms that can be evaluated using only the index and without | |
| 147862 | +** reference to the table are run first, so that if they are false, | |
| 147863 | +** unnecessary table seeks are avoided. | |
| 147864 | +** | |
| 147865 | +** RULES | |
| 147809 | 147866 | ** |
| 147810 | 147867 | ** Do not attempt this optimization if: |
| 147811 | 147868 | ** |
| 147812 | 147869 | ** (1) (** This restriction was removed on 2017-09-29. We used to |
| 147813 | 147870 | ** disallow this optimization for aggregate subqueries, but now |
| @@ -147870,14 +147927,14 @@ | ||
| 147870 | 147927 | ** (9b) The subquery is to the right of the ON/USING clause |
| 147871 | 147928 | ** |
| 147872 | 147929 | ** (9c) There is a RIGHT JOIN (or FULL JOIN) in between the ON/USING |
| 147873 | 147930 | ** clause and the subquery. |
| 147874 | 147931 | ** |
| 147875 | -** Without this restriction, the push-down optimization might move | |
| 147876 | -** the ON/USING filter expression from the left side of a RIGHT JOIN | |
| 147877 | -** over to the right side, which leads to incorrect answers. See | |
| 147878 | -** also restriction (6) in sqlite3ExprIsSingleTableConstraint(). | |
| 147932 | +** Without this restriction, the WHERE-clause push-down optimization | |
| 147933 | +** might move the ON/USING filter expression from the left side of a | |
| 147934 | +** RIGHT JOIN over to the right side, which leads to incorrect answers. | |
| 147935 | +** See also restriction (6) in sqlite3ExprIsSingleTableConstraint(). | |
| 147879 | 147936 | ** |
| 147880 | 147937 | ** (10) The inner query is not the right-hand table of a RIGHT JOIN. |
| 147881 | 147938 | ** |
| 147882 | 147939 | ** (11) The subquery is not a VALUES clause |
| 147883 | 147940 | ** |
| @@ -148005,11 +148062,11 @@ | ||
| 148005 | 148062 | return 0; /* Restriction (12) */ |
| 148006 | 148063 | } |
| 148007 | 148064 | } |
| 148008 | 148065 | #endif |
| 148009 | 148066 | |
| 148010 | - if( sqlite3ExprIsSingleTableConstraint(pWhere, pSrcList, iSrc) ){ | |
| 148067 | + if( sqlite3ExprIsSingleTableConstraint(pWhere, pSrcList, iSrc, 1) ){ | |
| 148011 | 148068 | nChng++; |
| 148012 | 148069 | pSubq->selFlags |= SF_PushDown; |
| 148013 | 148070 | while( pSubq ){ |
| 148014 | 148071 | SubstContext x; |
| 148015 | 148072 | pNew = sqlite3ExprDup(pParse->db, pWhere, 0); |
| @@ -150434,11 +150491,11 @@ | ||
| 150434 | 150491 | sqlite3TreeViewSelect(0, p, 0); |
| 150435 | 150492 | } |
| 150436 | 150493 | #endif |
| 150437 | 150494 | assert( pItem->pSelect && (pItem->pSelect->selFlags & SF_PushDown)!=0 ); |
| 150438 | 150495 | }else{ |
| 150439 | - TREETRACE(0x4000,pParse,p,("Push-down not possible\n")); | |
| 150496 | + TREETRACE(0x4000,pParse,p,("WHERE-lcause push-down not possible\n")); | |
| 150440 | 150497 | } |
| 150441 | 150498 | |
| 150442 | 150499 | /* Convert unused result columns of the subquery into simple NULL |
| 150443 | 150500 | ** expressions, to avoid unneeded searching and computation. |
| 150444 | 150501 | */ |
| @@ -153965,10 +154022,13 @@ | ||
| 153965 | 154022 | }else{ |
| 153966 | 154023 | sqlite3VdbeAddOp2(v, OP_Null, 0, k); |
| 153967 | 154024 | } |
| 153968 | 154025 | } |
| 153969 | 154026 | if( chngRowid==0 && pPk==0 ){ |
| 154027 | +#ifdef SQLITE_ALLOW_ROWID_IN_VIEW | |
| 154028 | + if( isView ) sqlite3VdbeAddOp2(v, OP_Null, 0, regOldRowid); | |
| 154029 | +#endif | |
| 153970 | 154030 | sqlite3VdbeAddOp2(v, OP_Copy, regOldRowid, regNewRowid); |
| 153971 | 154031 | } |
| 153972 | 154032 | } |
| 153973 | 154033 | |
| 153974 | 154034 | /* Populate the array of registers beginning at regNew with the new |
| @@ -159650,10 +159710,16 @@ | ||
| 159650 | 159710 | ** iLoop==2: Code remaining expressions that do not contain correlated |
| 159651 | 159711 | ** sub-queries. |
| 159652 | 159712 | ** iLoop==3: Code all remaining expressions. |
| 159653 | 159713 | ** |
| 159654 | 159714 | ** An effort is made to skip unnecessary iterations of the loop. |
| 159715 | + ** | |
| 159716 | + ** This optimization of causing simple query restrictions to occur before | |
| 159717 | + ** more complex one is call the "push-down" optimization in MySQL. Here | |
| 159718 | + ** in SQLite, the name is "MySQL push-down", since there is also another | |
| 159719 | + ** totally unrelated optimization called "WHERE-clause push-down". | |
| 159720 | + ** Sometimes the qualifier is omitted, resulting in an ambiguity, so beware. | |
| 159655 | 159721 | */ |
| 159656 | 159722 | iLoop = (pIdx ? 1 : 2); |
| 159657 | 159723 | do{ |
| 159658 | 159724 | int iNext = 0; /* Next value for iLoop */ |
| 159659 | 159725 | for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){ |
| @@ -162783,11 +162849,11 @@ | ||
| 162783 | 162849 | Expr *pExpr = pTerm->pExpr; |
| 162784 | 162850 | /* Make the automatic index a partial index if there are terms in the |
| 162785 | 162851 | ** WHERE clause (or the ON clause of a LEFT join) that constrain which |
| 162786 | 162852 | ** rows of the target table (pSrc) that can be used. */ |
| 162787 | 162853 | if( (pTerm->wtFlags & TERM_VIRTUAL)==0 |
| 162788 | - && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, pLevel->iFrom) | |
| 162854 | + && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, pLevel->iFrom, 0) | |
| 162789 | 162855 | ){ |
| 162790 | 162856 | pPartial = sqlite3ExprAnd(pParse, pPartial, |
| 162791 | 162857 | sqlite3ExprDup(pParse->db, pExpr, 0)); |
| 162792 | 162858 | } |
| 162793 | 162859 | if( termCanDriveIndex(pTerm, pSrc, notReady) ){ |
| @@ -163052,11 +163118,11 @@ | ||
| 163052 | 163118 | addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v); |
| 163053 | 163119 | pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm]; |
| 163054 | 163120 | for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){ |
| 163055 | 163121 | Expr *pExpr = pTerm->pExpr; |
| 163056 | 163122 | if( (pTerm->wtFlags & TERM_VIRTUAL)==0 |
| 163057 | - && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, iSrc) | |
| 163123 | + && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, iSrc, 0) | |
| 163058 | 163124 | ){ |
| 163059 | 163125 | sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL); |
| 163060 | 163126 | } |
| 163061 | 163127 | } |
| 163062 | 163128 | if( pLoop->wsFlags & WHERE_IPK ){ |
| @@ -167789,20 +167855,14 @@ | ||
| 167789 | 167855 | assert( pIdx->bHasExpr ); |
| 167790 | 167856 | pTab = pIdx->pTable; |
| 167791 | 167857 | for(i=0; i<pIdx->nColumn; i++){ |
| 167792 | 167858 | Expr *pExpr; |
| 167793 | 167859 | int j = pIdx->aiColumn[i]; |
| 167794 | - int bMaybeNullRow; | |
| 167795 | 167860 | if( j==XN_EXPR ){ |
| 167796 | 167861 | pExpr = pIdx->aColExpr->a[i].pExpr; |
| 167797 | - testcase( pTabItem->fg.jointype & JT_LEFT ); | |
| 167798 | - testcase( pTabItem->fg.jointype & JT_RIGHT ); | |
| 167799 | - testcase( pTabItem->fg.jointype & JT_LTORJ ); | |
| 167800 | - bMaybeNullRow = (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0; | |
| 167801 | 167862 | }else if( j>=0 && (pTab->aCol[j].colFlags & COLFLAG_VIRTUAL)!=0 ){ |
| 167802 | 167863 | pExpr = sqlite3ColumnExpr(pTab, &pTab->aCol[j]); |
| 167803 | - bMaybeNullRow = 0; | |
| 167804 | 167864 | }else{ |
| 167805 | 167865 | continue; |
| 167806 | 167866 | } |
| 167807 | 167867 | if( sqlite3ExprIsConstant(0,pExpr) ) continue; |
| 167808 | 167868 | if( pExpr->op==TK_FUNCTION ){ |
| @@ -167830,11 +167890,11 @@ | ||
| 167830 | 167890 | #endif |
| 167831 | 167891 | p->pExpr = sqlite3ExprDup(pParse->db, pExpr, 0); |
| 167832 | 167892 | p->iDataCur = pTabItem->iCursor; |
| 167833 | 167893 | p->iIdxCur = iIdxCur; |
| 167834 | 167894 | p->iIdxCol = i; |
| 167835 | - p->bMaybeNullRow = bMaybeNullRow; | |
| 167895 | + p->bMaybeNullRow = (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0; | |
| 167836 | 167896 | if( sqlite3IndexAffinityStr(pParse->db, pIdx) ){ |
| 167837 | 167897 | p->aff = pIdx->zColAff[i]; |
| 167838 | 167898 | } |
| 167839 | 167899 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 167840 | 167900 | p->zIdxName = pIdx->zName; |
| @@ -216753,11 +216813,11 @@ | ||
| 216753 | 216813 | { "TERTIARY", UCOL_TERTIARY }, |
| 216754 | 216814 | { "DEFAULT", UCOL_DEFAULT_STRENGTH }, |
| 216755 | 216815 | { "QUARTERNARY", UCOL_QUATERNARY }, |
| 216756 | 216816 | { "IDENTICAL", UCOL_IDENTICAL }, |
| 216757 | 216817 | }; |
| 216758 | - int i; | |
| 216818 | + unsigned int i; | |
| 216759 | 216819 | for(i=0; i<sizeof(aStrength)/sizeof(aStrength[0]); i++){ |
| 216760 | 216820 | if( sqlite3_stricmp(zOption,aStrength[i].zName)==0 ){ |
| 216761 | 216821 | ucol_setStrength(pUCollator, aStrength[i].val); |
| 216762 | 216822 | break; |
| 216763 | 216823 | } |
| @@ -252096,11 +252156,11 @@ | ||
| 252096 | 252156 | int nArg, /* Number of args */ |
| 252097 | 252157 | sqlite3_value **apUnused /* Function arguments */ |
| 252098 | 252158 | ){ |
| 252099 | 252159 | assert( nArg==0 ); |
| 252100 | 252160 | UNUSED_PARAM2(nArg, apUnused); |
| 252101 | - sqlite3_result_text(pCtx, "fts5: 2024-04-04 14:26:42 7bf49e2c54c9f6f336416f01c0e76aaf70f1e2f3fd612232e5a33ae5dabe0900", -1, SQLITE_TRANSIENT); | |
| 252161 | + sqlite3_result_text(pCtx, "fts5: 2024-04-08 11:50:07 69ec714b2d698acf9e37635256c01b233ce32f22e8323e226441d5ddd948a940", -1, SQLITE_TRANSIENT); | |
| 252102 | 252162 | } |
| 252103 | 252163 | |
| 252104 | 252164 | /* |
| 252105 | 252165 | ** Return true if zName is the extension on one of the shadow tables used |
| 252106 | 252166 | ** by this module. |
| 252107 | 252167 |
| --- extsrc/sqlite3.c | |
| +++ extsrc/sqlite3.c | |
| @@ -16,11 +16,11 @@ | |
| 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | ** |
| 20 | ** The content in this amalgamation comes from Fossil check-in |
| 21 | ** 7bf49e2c54c9f6f336416f01c0e76aaf70f1. |
| 22 | */ |
| 23 | #define SQLITE_CORE 1 |
| 24 | #define SQLITE_AMALGAMATION 1 |
| 25 | #ifndef SQLITE_PRIVATE |
| 26 | # define SQLITE_PRIVATE static |
| @@ -459,11 +459,11 @@ | |
| 459 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 460 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 461 | */ |
| 462 | #define SQLITE_VERSION "3.46.0" |
| 463 | #define SQLITE_VERSION_NUMBER 3046000 |
| 464 | #define SQLITE_SOURCE_ID "2024-04-04 14:26:42 7bf49e2c54c9f6f336416f01c0e76aaf70f1e2f3fd612232e5a33ae5dabe0900" |
| 465 | |
| 466 | /* |
| 467 | ** CAPI3REF: Run-Time Library Version Numbers |
| 468 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 469 | ** |
| @@ -17832,11 +17832,11 @@ | |
| 17832 | #define SQLITE_OmitNoopJoin 0x00000100 /* Omit unused tables in joins */ |
| 17833 | #define SQLITE_CountOfView 0x00000200 /* The count-of-view optimization */ |
| 17834 | #define SQLITE_CursorHints 0x00000400 /* Add OP_CursorHint opcodes */ |
| 17835 | #define SQLITE_Stat4 0x00000800 /* Use STAT4 data */ |
| 17836 | /* TH3 expects this value ^^^^^^^^^^ to be 0x0000800. Don't change it */ |
| 17837 | #define SQLITE_PushDown 0x00001000 /* The push-down optimization */ |
| 17838 | #define SQLITE_SimplifyJoin 0x00002000 /* Convert LEFT JOIN to JOIN */ |
| 17839 | #define SQLITE_SkipScan 0x00004000 /* Skip-scans */ |
| 17840 | #define SQLITE_PropagateConst 0x00008000 /* The constant propagation opt */ |
| 17841 | #define SQLITE_MinMaxOpt 0x00010000 /* The min/max optimization */ |
| 17842 | #define SQLITE_SeekScan 0x00020000 /* The OP_SeekScan optimization */ |
| @@ -19506,15 +19506,16 @@ | |
| 19506 | #define SF_WhereBegin 0x0080000 /* Really a WhereBegin() call. Debug Only */ |
| 19507 | #define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */ |
| 19508 | #define SF_View 0x0200000 /* SELECT statement is a view */ |
| 19509 | #define SF_NoopOrderBy 0x0400000 /* ORDER BY is ignored for this query */ |
| 19510 | #define SF_UFSrcCheck 0x0800000 /* Check pSrc as required by UPDATE...FROM */ |
| 19511 | #define SF_PushDown 0x1000000 /* SELECT has be modified by push-down opt */ |
| 19512 | #define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */ |
| 19513 | #define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */ |
| 19514 | #define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */ |
| 19515 | #define SF_UpdateFrom 0x10000000 /* Query originates with UPDATE FROM */ |
| 19516 | |
| 19517 | /* True if S exists and has SF_NestedFrom */ |
| 19518 | #define IsNestedFrom(S) ((S)!=0 && ((S)->selFlags&SF_NestedFrom)!=0) |
| 19519 | |
| 19520 | /* |
| @@ -21007,12 +21008,11 @@ | |
| 21007 | SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr*); |
| 21008 | SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr*); |
| 21009 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Parse*,Expr*); |
| 21010 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8); |
| 21011 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*); |
| 21012 | SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int); |
| 21013 | SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcList*,int); |
| 21014 | #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 21015 | SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*); |
| 21016 | #endif |
| 21017 | SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*); |
| 21018 | SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); |
| @@ -107284,10 +107284,15 @@ | |
| 107284 | && (pNC->ncFlags & (NC_IdxExpr|NC_GenCol))==0 |
| 107285 | && sqlite3IsRowid(zCol) |
| 107286 | && ALWAYS(VisibleRowid(pMatch->pTab) || pMatch->fg.isNestedFrom) |
| 107287 | ){ |
| 107288 | cnt = cntTab; |
| 107289 | if( pMatch->fg.isNestedFrom==0 ) pExpr->iColumn = -1; |
| 107290 | pExpr->affExpr = SQLITE_AFF_INTEGER; |
| 107291 | } |
| 107292 | |
| 107293 | /* |
| @@ -108001,18 +108006,20 @@ | |
| 108001 | int nRef = pNC->nRef; |
| 108002 | testcase( pNC->ncFlags & NC_IsCheck ); |
| 108003 | testcase( pNC->ncFlags & NC_PartIdx ); |
| 108004 | testcase( pNC->ncFlags & NC_IdxExpr ); |
| 108005 | testcase( pNC->ncFlags & NC_GenCol ); |
| 108006 | if( pNC->ncFlags & NC_SelfRef ){ |
| 108007 | notValidImpl(pParse, pNC, "subqueries", pExpr, pExpr); |
| 108008 | }else{ |
| 108009 | sqlite3WalkSelect(pWalker, pExpr->x.pSelect); |
| 108010 | } |
| 108011 | assert( pNC->nRef>=nRef ); |
| 108012 | if( nRef!=pNC->nRef ){ |
| 108013 | ExprSetProperty(pExpr, EP_VarSelect); |
| 108014 | } |
| 108015 | pNC->ncFlags |= NC_Subquery; |
| 108016 | } |
| 108017 | break; |
| 108018 | } |
| @@ -111425,20 +111432,19 @@ | |
| 111425 | testcase( pExpr->op==TK_SELECT ); /* sqlite3SelectWalkFail() disallows */ |
| 111426 | testcase( pExpr->op==TK_EXISTS ); /* sqlite3SelectWalkFail() disallows */ |
| 111427 | return WRC_Continue; |
| 111428 | } |
| 111429 | } |
| 111430 | static int exprIsConst(Parse *pParse, Expr *p, int initFlag, int iCur){ |
| 111431 | Walker w; |
| 111432 | w.eCode = initFlag; |
| 111433 | w.pParse = pParse; |
| 111434 | w.xExprCallback = exprNodeIsConstant; |
| 111435 | w.xSelectCallback = sqlite3SelectWalkFail; |
| 111436 | #ifdef SQLITE_DEBUG |
| 111437 | w.xSelectCallback2 = sqlite3SelectWalkAssert2; |
| 111438 | #endif |
| 111439 | w.u.iCur = iCur; |
| 111440 | sqlite3WalkExpr(&w, p); |
| 111441 | return w.eCode; |
| 111442 | } |
| 111443 | |
| 111444 | /* |
| @@ -111454,11 +111460,11 @@ | |
| 111454 | ** function calls will be considered to be non-constant. If pParse is |
| 111455 | ** not NULL, then a function call might be constant, depending on the |
| 111456 | ** function and on its parameters. |
| 111457 | */ |
| 111458 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Parse *pParse, Expr *p){ |
| 111459 | return exprIsConst(pParse, p, 1, 0); |
| 111460 | } |
| 111461 | |
| 111462 | /* |
| 111463 | ** Walk an expression tree. Return non-zero if |
| 111464 | ** |
| @@ -111471,21 +111477,54 @@ | |
| 111471 | ** When this routine returns true, it indicates that the expression |
| 111472 | ** can be added to the pParse->pConstExpr list and evaluated once when |
| 111473 | ** the prepared statement starts up. See sqlite3ExprCodeRunJustOnce(). |
| 111474 | */ |
| 111475 | static int sqlite3ExprIsConstantNotJoin(Parse *pParse, Expr *p){ |
| 111476 | return exprIsConst(pParse, p, 2, 0); |
| 111477 | } |
| 111478 | |
| 111479 | /* |
| 111480 | ** Walk an expression tree. Return non-zero if the expression is constant |
| 111481 | ** for any single row of the table with cursor iCur. In other words, the |
| 111482 | ** expression must not refer to any non-deterministic function nor any |
| 111483 | ** table other than iCur. |
| 111484 | */ |
| 111485 | SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){ |
| 111486 | return exprIsConst(0, p, 3, iCur); |
| 111487 | } |
| 111488 | |
| 111489 | /* |
| 111490 | ** Check pExpr to see if it is an constraint on the single data source |
| 111491 | ** pSrc = &pSrcList->a[iSrc]. In other words, check to see if pExpr |
| @@ -111499,11 +111538,14 @@ | |
| 111499 | ** |
| 111500 | ** To be an single-source constraint, the following must be true: |
| 111501 | ** |
| 111502 | ** (1) pExpr cannot refer to any table other than pSrc->iCursor. |
| 111503 | ** |
| 111504 | ** (2) pExpr cannot use subqueries or non-deterministic functions. |
| 111505 | ** |
| 111506 | ** (3) pSrc cannot be part of the left operand for a RIGHT JOIN. |
| 111507 | ** (Is there some way to relax this constraint?) |
| 111508 | ** |
| 111509 | ** (4) If pSrc is the right operand of a LEFT JOIN, then... |
| @@ -111528,11 +111570,12 @@ | |
| 111528 | ** on push-down. |
| 111529 | */ |
| 111530 | SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint( |
| 111531 | Expr *pExpr, /* The constraint */ |
| 111532 | const SrcList *pSrcList, /* Complete FROM clause */ |
| 111533 | int iSrc /* Which element of pSrcList to use */ |
| 111534 | ){ |
| 111535 | const SrcItem *pSrc = &pSrcList->a[iSrc]; |
| 111536 | if( pSrc->fg.jointype & JT_LTORJ ){ |
| 111537 | return 0; /* rule (3) */ |
| 111538 | } |
| @@ -111553,11 +111596,12 @@ | |
| 111553 | } |
| 111554 | break; |
| 111555 | } |
| 111556 | } |
| 111557 | } |
| 111558 | return sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor); /* rules (1), (2) */ |
| 111559 | } |
| 111560 | |
| 111561 | |
| 111562 | /* |
| 111563 | ** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy(). |
| @@ -111638,11 +111682,11 @@ | |
| 111638 | ** is considered a variable but a single-quoted string (ex: 'abc') is |
| 111639 | ** a constant. |
| 111640 | */ |
| 111641 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){ |
| 111642 | assert( isInit==0 || isInit==1 ); |
| 111643 | return exprIsConst(0, p, 4+isInit, 0); |
| 111644 | } |
| 111645 | |
| 111646 | #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 111647 | /* |
| 111648 | ** Walk an expression tree. Return 1 if the expression contains a |
| @@ -113956,12 +114000,13 @@ | |
| 113956 | } |
| 113957 | case TK_COLLATE: { |
| 113958 | if( !ExprHasProperty(pExpr, EP_Collate) ){ |
| 113959 | /* A TK_COLLATE Expr node without the EP_Collate tag is a so-called |
| 113960 | ** "SOFT-COLLATE" that is added to constraints that are pushed down |
| 113961 | ** from outer queries into sub-queries by the push-down optimization. |
| 113962 | ** Clear subtypes as subtypes may not cross a subquery boundary. |
| 113963 | */ |
| 113964 | assert( pExpr->pLeft ); |
| 113965 | sqlite3ExprCode(pParse, pExpr->pLeft, target); |
| 113966 | sqlite3VdbeAddOp1(v, OP_ClrSubtype, target); |
| 113967 | return target; |
| @@ -147804,10 +147849,22 @@ | |
| 147804 | ** SELECT * FROM (SELECT a AS x, c-d AS y FROM t1 WHERE a=5 AND c-d=10) |
| 147805 | ** WHERE x=5 AND y=10; |
| 147806 | ** |
| 147807 | ** The hope is that the terms added to the inner query will make it more |
| 147808 | ** efficient. |
| 147809 | ** |
| 147810 | ** Do not attempt this optimization if: |
| 147811 | ** |
| 147812 | ** (1) (** This restriction was removed on 2017-09-29. We used to |
| 147813 | ** disallow this optimization for aggregate subqueries, but now |
| @@ -147870,14 +147927,14 @@ | |
| 147870 | ** (9b) The subquery is to the right of the ON/USING clause |
| 147871 | ** |
| 147872 | ** (9c) There is a RIGHT JOIN (or FULL JOIN) in between the ON/USING |
| 147873 | ** clause and the subquery. |
| 147874 | ** |
| 147875 | ** Without this restriction, the push-down optimization might move |
| 147876 | ** the ON/USING filter expression from the left side of a RIGHT JOIN |
| 147877 | ** over to the right side, which leads to incorrect answers. See |
| 147878 | ** also restriction (6) in sqlite3ExprIsSingleTableConstraint(). |
| 147879 | ** |
| 147880 | ** (10) The inner query is not the right-hand table of a RIGHT JOIN. |
| 147881 | ** |
| 147882 | ** (11) The subquery is not a VALUES clause |
| 147883 | ** |
| @@ -148005,11 +148062,11 @@ | |
| 148005 | return 0; /* Restriction (12) */ |
| 148006 | } |
| 148007 | } |
| 148008 | #endif |
| 148009 | |
| 148010 | if( sqlite3ExprIsSingleTableConstraint(pWhere, pSrcList, iSrc) ){ |
| 148011 | nChng++; |
| 148012 | pSubq->selFlags |= SF_PushDown; |
| 148013 | while( pSubq ){ |
| 148014 | SubstContext x; |
| 148015 | pNew = sqlite3ExprDup(pParse->db, pWhere, 0); |
| @@ -150434,11 +150491,11 @@ | |
| 150434 | sqlite3TreeViewSelect(0, p, 0); |
| 150435 | } |
| 150436 | #endif |
| 150437 | assert( pItem->pSelect && (pItem->pSelect->selFlags & SF_PushDown)!=0 ); |
| 150438 | }else{ |
| 150439 | TREETRACE(0x4000,pParse,p,("Push-down not possible\n")); |
| 150440 | } |
| 150441 | |
| 150442 | /* Convert unused result columns of the subquery into simple NULL |
| 150443 | ** expressions, to avoid unneeded searching and computation. |
| 150444 | */ |
| @@ -153965,10 +154022,13 @@ | |
| 153965 | }else{ |
| 153966 | sqlite3VdbeAddOp2(v, OP_Null, 0, k); |
| 153967 | } |
| 153968 | } |
| 153969 | if( chngRowid==0 && pPk==0 ){ |
| 153970 | sqlite3VdbeAddOp2(v, OP_Copy, regOldRowid, regNewRowid); |
| 153971 | } |
| 153972 | } |
| 153973 | |
| 153974 | /* Populate the array of registers beginning at regNew with the new |
| @@ -159650,10 +159710,16 @@ | |
| 159650 | ** iLoop==2: Code remaining expressions that do not contain correlated |
| 159651 | ** sub-queries. |
| 159652 | ** iLoop==3: Code all remaining expressions. |
| 159653 | ** |
| 159654 | ** An effort is made to skip unnecessary iterations of the loop. |
| 159655 | */ |
| 159656 | iLoop = (pIdx ? 1 : 2); |
| 159657 | do{ |
| 159658 | int iNext = 0; /* Next value for iLoop */ |
| 159659 | for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){ |
| @@ -162783,11 +162849,11 @@ | |
| 162783 | Expr *pExpr = pTerm->pExpr; |
| 162784 | /* Make the automatic index a partial index if there are terms in the |
| 162785 | ** WHERE clause (or the ON clause of a LEFT join) that constrain which |
| 162786 | ** rows of the target table (pSrc) that can be used. */ |
| 162787 | if( (pTerm->wtFlags & TERM_VIRTUAL)==0 |
| 162788 | && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, pLevel->iFrom) |
| 162789 | ){ |
| 162790 | pPartial = sqlite3ExprAnd(pParse, pPartial, |
| 162791 | sqlite3ExprDup(pParse->db, pExpr, 0)); |
| 162792 | } |
| 162793 | if( termCanDriveIndex(pTerm, pSrc, notReady) ){ |
| @@ -163052,11 +163118,11 @@ | |
| 163052 | addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v); |
| 163053 | pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm]; |
| 163054 | for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){ |
| 163055 | Expr *pExpr = pTerm->pExpr; |
| 163056 | if( (pTerm->wtFlags & TERM_VIRTUAL)==0 |
| 163057 | && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, iSrc) |
| 163058 | ){ |
| 163059 | sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL); |
| 163060 | } |
| 163061 | } |
| 163062 | if( pLoop->wsFlags & WHERE_IPK ){ |
| @@ -167789,20 +167855,14 @@ | |
| 167789 | assert( pIdx->bHasExpr ); |
| 167790 | pTab = pIdx->pTable; |
| 167791 | for(i=0; i<pIdx->nColumn; i++){ |
| 167792 | Expr *pExpr; |
| 167793 | int j = pIdx->aiColumn[i]; |
| 167794 | int bMaybeNullRow; |
| 167795 | if( j==XN_EXPR ){ |
| 167796 | pExpr = pIdx->aColExpr->a[i].pExpr; |
| 167797 | testcase( pTabItem->fg.jointype & JT_LEFT ); |
| 167798 | testcase( pTabItem->fg.jointype & JT_RIGHT ); |
| 167799 | testcase( pTabItem->fg.jointype & JT_LTORJ ); |
| 167800 | bMaybeNullRow = (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0; |
| 167801 | }else if( j>=0 && (pTab->aCol[j].colFlags & COLFLAG_VIRTUAL)!=0 ){ |
| 167802 | pExpr = sqlite3ColumnExpr(pTab, &pTab->aCol[j]); |
| 167803 | bMaybeNullRow = 0; |
| 167804 | }else{ |
| 167805 | continue; |
| 167806 | } |
| 167807 | if( sqlite3ExprIsConstant(0,pExpr) ) continue; |
| 167808 | if( pExpr->op==TK_FUNCTION ){ |
| @@ -167830,11 +167890,11 @@ | |
| 167830 | #endif |
| 167831 | p->pExpr = sqlite3ExprDup(pParse->db, pExpr, 0); |
| 167832 | p->iDataCur = pTabItem->iCursor; |
| 167833 | p->iIdxCur = iIdxCur; |
| 167834 | p->iIdxCol = i; |
| 167835 | p->bMaybeNullRow = bMaybeNullRow; |
| 167836 | if( sqlite3IndexAffinityStr(pParse->db, pIdx) ){ |
| 167837 | p->aff = pIdx->zColAff[i]; |
| 167838 | } |
| 167839 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 167840 | p->zIdxName = pIdx->zName; |
| @@ -216753,11 +216813,11 @@ | |
| 216753 | { "TERTIARY", UCOL_TERTIARY }, |
| 216754 | { "DEFAULT", UCOL_DEFAULT_STRENGTH }, |
| 216755 | { "QUARTERNARY", UCOL_QUATERNARY }, |
| 216756 | { "IDENTICAL", UCOL_IDENTICAL }, |
| 216757 | }; |
| 216758 | int i; |
| 216759 | for(i=0; i<sizeof(aStrength)/sizeof(aStrength[0]); i++){ |
| 216760 | if( sqlite3_stricmp(zOption,aStrength[i].zName)==0 ){ |
| 216761 | ucol_setStrength(pUCollator, aStrength[i].val); |
| 216762 | break; |
| 216763 | } |
| @@ -252096,11 +252156,11 @@ | |
| 252096 | int nArg, /* Number of args */ |
| 252097 | sqlite3_value **apUnused /* Function arguments */ |
| 252098 | ){ |
| 252099 | assert( nArg==0 ); |
| 252100 | UNUSED_PARAM2(nArg, apUnused); |
| 252101 | sqlite3_result_text(pCtx, "fts5: 2024-04-04 14:26:42 7bf49e2c54c9f6f336416f01c0e76aaf70f1e2f3fd612232e5a33ae5dabe0900", -1, SQLITE_TRANSIENT); |
| 252102 | } |
| 252103 | |
| 252104 | /* |
| 252105 | ** Return true if zName is the extension on one of the shadow tables used |
| 252106 | ** by this module. |
| 252107 |
| --- extsrc/sqlite3.c | |
| +++ extsrc/sqlite3.c | |
| @@ -16,11 +16,11 @@ | |
| 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | ** |
| 20 | ** The content in this amalgamation comes from Fossil check-in |
| 21 | ** 69ec714b2d698acf9e37635256c01b233ce3. |
| 22 | */ |
| 23 | #define SQLITE_CORE 1 |
| 24 | #define SQLITE_AMALGAMATION 1 |
| 25 | #ifndef SQLITE_PRIVATE |
| 26 | # define SQLITE_PRIVATE static |
| @@ -459,11 +459,11 @@ | |
| 459 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 460 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 461 | */ |
| 462 | #define SQLITE_VERSION "3.46.0" |
| 463 | #define SQLITE_VERSION_NUMBER 3046000 |
| 464 | #define SQLITE_SOURCE_ID "2024-04-08 11:50:07 69ec714b2d698acf9e37635256c01b233ce32f22e8323e226441d5ddd948a940" |
| 465 | |
| 466 | /* |
| 467 | ** CAPI3REF: Run-Time Library Version Numbers |
| 468 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 469 | ** |
| @@ -17832,11 +17832,11 @@ | |
| 17832 | #define SQLITE_OmitNoopJoin 0x00000100 /* Omit unused tables in joins */ |
| 17833 | #define SQLITE_CountOfView 0x00000200 /* The count-of-view optimization */ |
| 17834 | #define SQLITE_CursorHints 0x00000400 /* Add OP_CursorHint opcodes */ |
| 17835 | #define SQLITE_Stat4 0x00000800 /* Use STAT4 data */ |
| 17836 | /* TH3 expects this value ^^^^^^^^^^ to be 0x0000800. Don't change it */ |
| 17837 | #define SQLITE_PushDown 0x00001000 /* WHERE-clause push-down opt */ |
| 17838 | #define SQLITE_SimplifyJoin 0x00002000 /* Convert LEFT JOIN to JOIN */ |
| 17839 | #define SQLITE_SkipScan 0x00004000 /* Skip-scans */ |
| 17840 | #define SQLITE_PropagateConst 0x00008000 /* The constant propagation opt */ |
| 17841 | #define SQLITE_MinMaxOpt 0x00010000 /* The min/max optimization */ |
| 17842 | #define SQLITE_SeekScan 0x00020000 /* The OP_SeekScan optimization */ |
| @@ -19506,15 +19506,16 @@ | |
| 19506 | #define SF_WhereBegin 0x0080000 /* Really a WhereBegin() call. Debug Only */ |
| 19507 | #define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */ |
| 19508 | #define SF_View 0x0200000 /* SELECT statement is a view */ |
| 19509 | #define SF_NoopOrderBy 0x0400000 /* ORDER BY is ignored for this query */ |
| 19510 | #define SF_UFSrcCheck 0x0800000 /* Check pSrc as required by UPDATE...FROM */ |
| 19511 | #define SF_PushDown 0x1000000 /* Modified by WHERE-clause push-down opt */ |
| 19512 | #define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */ |
| 19513 | #define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */ |
| 19514 | #define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */ |
| 19515 | #define SF_UpdateFrom 0x10000000 /* Query originates with UPDATE FROM */ |
| 19516 | #define SF_Correlated 0x20000000 /* True if references the outer context */ |
| 19517 | |
| 19518 | /* True if S exists and has SF_NestedFrom */ |
| 19519 | #define IsNestedFrom(S) ((S)!=0 && ((S)->selFlags&SF_NestedFrom)!=0) |
| 19520 | |
| 19521 | /* |
| @@ -21007,12 +21008,11 @@ | |
| 21008 | SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr*); |
| 21009 | SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr*); |
| 21010 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Parse*,Expr*); |
| 21011 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8); |
| 21012 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*); |
| 21013 | SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcList*,int,int); |
| 21014 | #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 21015 | SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*); |
| 21016 | #endif |
| 21017 | SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*); |
| 21018 | SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); |
| @@ -107284,10 +107284,15 @@ | |
| 107284 | && (pNC->ncFlags & (NC_IdxExpr|NC_GenCol))==0 |
| 107285 | && sqlite3IsRowid(zCol) |
| 107286 | && ALWAYS(VisibleRowid(pMatch->pTab) || pMatch->fg.isNestedFrom) |
| 107287 | ){ |
| 107288 | cnt = cntTab; |
| 107289 | #if SQLITE_ALLOW_ROWID_IN_VIEW+0==2 |
| 107290 | if( pMatch->pTab!=0 && IsView(pMatch->pTab) ){ |
| 107291 | eNewExprOp = TK_NULL; |
| 107292 | } |
| 107293 | #endif |
| 107294 | if( pMatch->fg.isNestedFrom==0 ) pExpr->iColumn = -1; |
| 107295 | pExpr->affExpr = SQLITE_AFF_INTEGER; |
| 107296 | } |
| 107297 | |
| 107298 | /* |
| @@ -108001,18 +108006,20 @@ | |
| 108006 | int nRef = pNC->nRef; |
| 108007 | testcase( pNC->ncFlags & NC_IsCheck ); |
| 108008 | testcase( pNC->ncFlags & NC_PartIdx ); |
| 108009 | testcase( pNC->ncFlags & NC_IdxExpr ); |
| 108010 | testcase( pNC->ncFlags & NC_GenCol ); |
| 108011 | assert( pExpr->x.pSelect ); |
| 108012 | if( pNC->ncFlags & NC_SelfRef ){ |
| 108013 | notValidImpl(pParse, pNC, "subqueries", pExpr, pExpr); |
| 108014 | }else{ |
| 108015 | sqlite3WalkSelect(pWalker, pExpr->x.pSelect); |
| 108016 | } |
| 108017 | assert( pNC->nRef>=nRef ); |
| 108018 | if( nRef!=pNC->nRef ){ |
| 108019 | ExprSetProperty(pExpr, EP_VarSelect); |
| 108020 | pExpr->x.pSelect->selFlags |= SF_Correlated; |
| 108021 | } |
| 108022 | pNC->ncFlags |= NC_Subquery; |
| 108023 | } |
| 108024 | break; |
| 108025 | } |
| @@ -111425,20 +111432,19 @@ | |
| 111432 | testcase( pExpr->op==TK_SELECT ); /* sqlite3SelectWalkFail() disallows */ |
| 111433 | testcase( pExpr->op==TK_EXISTS ); /* sqlite3SelectWalkFail() disallows */ |
| 111434 | return WRC_Continue; |
| 111435 | } |
| 111436 | } |
| 111437 | static int exprIsConst(Parse *pParse, Expr *p, int initFlag){ |
| 111438 | Walker w; |
| 111439 | w.eCode = initFlag; |
| 111440 | w.pParse = pParse; |
| 111441 | w.xExprCallback = exprNodeIsConstant; |
| 111442 | w.xSelectCallback = sqlite3SelectWalkFail; |
| 111443 | #ifdef SQLITE_DEBUG |
| 111444 | w.xSelectCallback2 = sqlite3SelectWalkAssert2; |
| 111445 | #endif |
| 111446 | sqlite3WalkExpr(&w, p); |
| 111447 | return w.eCode; |
| 111448 | } |
| 111449 | |
| 111450 | /* |
| @@ -111454,11 +111460,11 @@ | |
| 111460 | ** function calls will be considered to be non-constant. If pParse is |
| 111461 | ** not NULL, then a function call might be constant, depending on the |
| 111462 | ** function and on its parameters. |
| 111463 | */ |
| 111464 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Parse *pParse, Expr *p){ |
| 111465 | return exprIsConst(pParse, p, 1); |
| 111466 | } |
| 111467 | |
| 111468 | /* |
| 111469 | ** Walk an expression tree. Return non-zero if |
| 111470 | ** |
| @@ -111471,21 +111477,54 @@ | |
| 111477 | ** When this routine returns true, it indicates that the expression |
| 111478 | ** can be added to the pParse->pConstExpr list and evaluated once when |
| 111479 | ** the prepared statement starts up. See sqlite3ExprCodeRunJustOnce(). |
| 111480 | */ |
| 111481 | static int sqlite3ExprIsConstantNotJoin(Parse *pParse, Expr *p){ |
| 111482 | return exprIsConst(pParse, p, 2); |
| 111483 | } |
| 111484 | |
| 111485 | /* |
| 111486 | ** This routine examines sub-SELECT statements as an expression is being |
| 111487 | ** walked as part of sqlite3ExprIsTableConstant(). Sub-SELECTs are considered |
| 111488 | ** constant as long as they are uncorrelated - meaning that they do not |
| 111489 | ** contain any terms from outer contexts. |
| 111490 | */ |
| 111491 | static int exprSelectWalkTableConstant(Walker *pWalker, Select *pSelect){ |
| 111492 | assert( pSelect!=0 ); |
| 111493 | assert( pWalker->eCode==3 || pWalker->eCode==0 ); |
| 111494 | if( (pSelect->selFlags & SF_Correlated)!=0 ){ |
| 111495 | pWalker->eCode = 0; |
| 111496 | return WRC_Abort; |
| 111497 | } |
| 111498 | return WRC_Prune; |
| 111499 | } |
| 111500 | |
| 111501 | /* |
| 111502 | ** Walk an expression tree. Return non-zero if the expression is constant |
| 111503 | ** for any single row of the table with cursor iCur. In other words, the |
| 111504 | ** expression must not refer to any non-deterministic function nor any |
| 111505 | ** table other than iCur. |
| 111506 | ** |
| 111507 | ** Consider uncorrelated subqueries to be constants if the bAllowSubq |
| 111508 | ** parameter is true. |
| 111509 | */ |
| 111510 | static int sqlite3ExprIsTableConstant(Expr *p, int iCur, int bAllowSubq){ |
| 111511 | Walker w; |
| 111512 | w.eCode = 3; |
| 111513 | w.pParse = 0; |
| 111514 | w.xExprCallback = exprNodeIsConstant; |
| 111515 | if( bAllowSubq ){ |
| 111516 | w.xSelectCallback = exprSelectWalkTableConstant; |
| 111517 | }else{ |
| 111518 | w.xSelectCallback = sqlite3SelectWalkFail; |
| 111519 | #ifdef SQLITE_DEBUG |
| 111520 | w.xSelectCallback2 = sqlite3SelectWalkAssert2; |
| 111521 | #endif |
| 111522 | } |
| 111523 | w.u.iCur = iCur; |
| 111524 | sqlite3WalkExpr(&w, p); |
| 111525 | return w.eCode; |
| 111526 | } |
| 111527 | |
| 111528 | /* |
| 111529 | ** Check pExpr to see if it is an constraint on the single data source |
| 111530 | ** pSrc = &pSrcList->a[iSrc]. In other words, check to see if pExpr |
| @@ -111499,11 +111538,14 @@ | |
| 111538 | ** |
| 111539 | ** To be an single-source constraint, the following must be true: |
| 111540 | ** |
| 111541 | ** (1) pExpr cannot refer to any table other than pSrc->iCursor. |
| 111542 | ** |
| 111543 | ** (2a) pExpr cannot use subqueries unless the bAllowSubq parameter is |
| 111544 | ** true and the subquery is non-correlated |
| 111545 | ** |
| 111546 | ** (2b) pExpr cannot use non-deterministic functions. |
| 111547 | ** |
| 111548 | ** (3) pSrc cannot be part of the left operand for a RIGHT JOIN. |
| 111549 | ** (Is there some way to relax this constraint?) |
| 111550 | ** |
| 111551 | ** (4) If pSrc is the right operand of a LEFT JOIN, then... |
| @@ -111528,11 +111570,12 @@ | |
| 111570 | ** on push-down. |
| 111571 | */ |
| 111572 | SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint( |
| 111573 | Expr *pExpr, /* The constraint */ |
| 111574 | const SrcList *pSrcList, /* Complete FROM clause */ |
| 111575 | int iSrc, /* Which element of pSrcList to use */ |
| 111576 | int bAllowSubq /* Allow non-correlated subqueries */ |
| 111577 | ){ |
| 111578 | const SrcItem *pSrc = &pSrcList->a[iSrc]; |
| 111579 | if( pSrc->fg.jointype & JT_LTORJ ){ |
| 111580 | return 0; /* rule (3) */ |
| 111581 | } |
| @@ -111553,11 +111596,12 @@ | |
| 111596 | } |
| 111597 | break; |
| 111598 | } |
| 111599 | } |
| 111600 | } |
| 111601 | /* Rules (1), (2a), and (2b) handled by the following: */ |
| 111602 | return sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor, bAllowSubq); |
| 111603 | } |
| 111604 | |
| 111605 | |
| 111606 | /* |
| 111607 | ** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy(). |
| @@ -111638,11 +111682,11 @@ | |
| 111682 | ** is considered a variable but a single-quoted string (ex: 'abc') is |
| 111683 | ** a constant. |
| 111684 | */ |
| 111685 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){ |
| 111686 | assert( isInit==0 || isInit==1 ); |
| 111687 | return exprIsConst(0, p, 4+isInit); |
| 111688 | } |
| 111689 | |
| 111690 | #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 111691 | /* |
| 111692 | ** Walk an expression tree. Return 1 if the expression contains a |
| @@ -113956,12 +114000,13 @@ | |
| 114000 | } |
| 114001 | case TK_COLLATE: { |
| 114002 | if( !ExprHasProperty(pExpr, EP_Collate) ){ |
| 114003 | /* A TK_COLLATE Expr node without the EP_Collate tag is a so-called |
| 114004 | ** "SOFT-COLLATE" that is added to constraints that are pushed down |
| 114005 | ** from outer queries into sub-queries by the WHERE-clause push-down |
| 114006 | ** optimization. Clear subtypes as subtypes may not cross a subquery |
| 114007 | ** boundary. |
| 114008 | */ |
| 114009 | assert( pExpr->pLeft ); |
| 114010 | sqlite3ExprCode(pParse, pExpr->pLeft, target); |
| 114011 | sqlite3VdbeAddOp1(v, OP_ClrSubtype, target); |
| 114012 | return target; |
| @@ -147804,10 +147849,22 @@ | |
| 147849 | ** SELECT * FROM (SELECT a AS x, c-d AS y FROM t1 WHERE a=5 AND c-d=10) |
| 147850 | ** WHERE x=5 AND y=10; |
| 147851 | ** |
| 147852 | ** The hope is that the terms added to the inner query will make it more |
| 147853 | ** efficient. |
| 147854 | ** |
| 147855 | ** NAME AMBIGUITY |
| 147856 | ** |
| 147857 | ** This optimization is called the "WHERE-clause push-down optimization". |
| 147858 | ** |
| 147859 | ** Do not confuse this optimization with another unrelated optimization |
| 147860 | ** with a similar name: The "MySQL push-down optimization" causes WHERE |
| 147861 | ** clause terms that can be evaluated using only the index and without |
| 147862 | ** reference to the table are run first, so that if they are false, |
| 147863 | ** unnecessary table seeks are avoided. |
| 147864 | ** |
| 147865 | ** RULES |
| 147866 | ** |
| 147867 | ** Do not attempt this optimization if: |
| 147868 | ** |
| 147869 | ** (1) (** This restriction was removed on 2017-09-29. We used to |
| 147870 | ** disallow this optimization for aggregate subqueries, but now |
| @@ -147870,14 +147927,14 @@ | |
| 147927 | ** (9b) The subquery is to the right of the ON/USING clause |
| 147928 | ** |
| 147929 | ** (9c) There is a RIGHT JOIN (or FULL JOIN) in between the ON/USING |
| 147930 | ** clause and the subquery. |
| 147931 | ** |
| 147932 | ** Without this restriction, the WHERE-clause push-down optimization |
| 147933 | ** might move the ON/USING filter expression from the left side of a |
| 147934 | ** RIGHT JOIN over to the right side, which leads to incorrect answers. |
| 147935 | ** See also restriction (6) in sqlite3ExprIsSingleTableConstraint(). |
| 147936 | ** |
| 147937 | ** (10) The inner query is not the right-hand table of a RIGHT JOIN. |
| 147938 | ** |
| 147939 | ** (11) The subquery is not a VALUES clause |
| 147940 | ** |
| @@ -148005,11 +148062,11 @@ | |
| 148062 | return 0; /* Restriction (12) */ |
| 148063 | } |
| 148064 | } |
| 148065 | #endif |
| 148066 | |
| 148067 | if( sqlite3ExprIsSingleTableConstraint(pWhere, pSrcList, iSrc, 1) ){ |
| 148068 | nChng++; |
| 148069 | pSubq->selFlags |= SF_PushDown; |
| 148070 | while( pSubq ){ |
| 148071 | SubstContext x; |
| 148072 | pNew = sqlite3ExprDup(pParse->db, pWhere, 0); |
| @@ -150434,11 +150491,11 @@ | |
| 150491 | sqlite3TreeViewSelect(0, p, 0); |
| 150492 | } |
| 150493 | #endif |
| 150494 | assert( pItem->pSelect && (pItem->pSelect->selFlags & SF_PushDown)!=0 ); |
| 150495 | }else{ |
| 150496 | TREETRACE(0x4000,pParse,p,("WHERE-lcause push-down not possible\n")); |
| 150497 | } |
| 150498 | |
| 150499 | /* Convert unused result columns of the subquery into simple NULL |
| 150500 | ** expressions, to avoid unneeded searching and computation. |
| 150501 | */ |
| @@ -153965,10 +154022,13 @@ | |
| 154022 | }else{ |
| 154023 | sqlite3VdbeAddOp2(v, OP_Null, 0, k); |
| 154024 | } |
| 154025 | } |
| 154026 | if( chngRowid==0 && pPk==0 ){ |
| 154027 | #ifdef SQLITE_ALLOW_ROWID_IN_VIEW |
| 154028 | if( isView ) sqlite3VdbeAddOp2(v, OP_Null, 0, regOldRowid); |
| 154029 | #endif |
| 154030 | sqlite3VdbeAddOp2(v, OP_Copy, regOldRowid, regNewRowid); |
| 154031 | } |
| 154032 | } |
| 154033 | |
| 154034 | /* Populate the array of registers beginning at regNew with the new |
| @@ -159650,10 +159710,16 @@ | |
| 159710 | ** iLoop==2: Code remaining expressions that do not contain correlated |
| 159711 | ** sub-queries. |
| 159712 | ** iLoop==3: Code all remaining expressions. |
| 159713 | ** |
| 159714 | ** An effort is made to skip unnecessary iterations of the loop. |
| 159715 | ** |
| 159716 | ** This optimization of causing simple query restrictions to occur before |
| 159717 | ** more complex one is call the "push-down" optimization in MySQL. Here |
| 159718 | ** in SQLite, the name is "MySQL push-down", since there is also another |
| 159719 | ** totally unrelated optimization called "WHERE-clause push-down". |
| 159720 | ** Sometimes the qualifier is omitted, resulting in an ambiguity, so beware. |
| 159721 | */ |
| 159722 | iLoop = (pIdx ? 1 : 2); |
| 159723 | do{ |
| 159724 | int iNext = 0; /* Next value for iLoop */ |
| 159725 | for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){ |
| @@ -162783,11 +162849,11 @@ | |
| 162849 | Expr *pExpr = pTerm->pExpr; |
| 162850 | /* Make the automatic index a partial index if there are terms in the |
| 162851 | ** WHERE clause (or the ON clause of a LEFT join) that constrain which |
| 162852 | ** rows of the target table (pSrc) that can be used. */ |
| 162853 | if( (pTerm->wtFlags & TERM_VIRTUAL)==0 |
| 162854 | && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, pLevel->iFrom, 0) |
| 162855 | ){ |
| 162856 | pPartial = sqlite3ExprAnd(pParse, pPartial, |
| 162857 | sqlite3ExprDup(pParse->db, pExpr, 0)); |
| 162858 | } |
| 162859 | if( termCanDriveIndex(pTerm, pSrc, notReady) ){ |
| @@ -163052,11 +163118,11 @@ | |
| 163118 | addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v); |
| 163119 | pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm]; |
| 163120 | for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){ |
| 163121 | Expr *pExpr = pTerm->pExpr; |
| 163122 | if( (pTerm->wtFlags & TERM_VIRTUAL)==0 |
| 163123 | && sqlite3ExprIsSingleTableConstraint(pExpr, pTabList, iSrc, 0) |
| 163124 | ){ |
| 163125 | sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL); |
| 163126 | } |
| 163127 | } |
| 163128 | if( pLoop->wsFlags & WHERE_IPK ){ |
| @@ -167789,20 +167855,14 @@ | |
| 167855 | assert( pIdx->bHasExpr ); |
| 167856 | pTab = pIdx->pTable; |
| 167857 | for(i=0; i<pIdx->nColumn; i++){ |
| 167858 | Expr *pExpr; |
| 167859 | int j = pIdx->aiColumn[i]; |
| 167860 | if( j==XN_EXPR ){ |
| 167861 | pExpr = pIdx->aColExpr->a[i].pExpr; |
| 167862 | }else if( j>=0 && (pTab->aCol[j].colFlags & COLFLAG_VIRTUAL)!=0 ){ |
| 167863 | pExpr = sqlite3ColumnExpr(pTab, &pTab->aCol[j]); |
| 167864 | }else{ |
| 167865 | continue; |
| 167866 | } |
| 167867 | if( sqlite3ExprIsConstant(0,pExpr) ) continue; |
| 167868 | if( pExpr->op==TK_FUNCTION ){ |
| @@ -167830,11 +167890,11 @@ | |
| 167890 | #endif |
| 167891 | p->pExpr = sqlite3ExprDup(pParse->db, pExpr, 0); |
| 167892 | p->iDataCur = pTabItem->iCursor; |
| 167893 | p->iIdxCur = iIdxCur; |
| 167894 | p->iIdxCol = i; |
| 167895 | p->bMaybeNullRow = (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0; |
| 167896 | if( sqlite3IndexAffinityStr(pParse->db, pIdx) ){ |
| 167897 | p->aff = pIdx->zColAff[i]; |
| 167898 | } |
| 167899 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 167900 | p->zIdxName = pIdx->zName; |
| @@ -216753,11 +216813,11 @@ | |
| 216813 | { "TERTIARY", UCOL_TERTIARY }, |
| 216814 | { "DEFAULT", UCOL_DEFAULT_STRENGTH }, |
| 216815 | { "QUARTERNARY", UCOL_QUATERNARY }, |
| 216816 | { "IDENTICAL", UCOL_IDENTICAL }, |
| 216817 | }; |
| 216818 | unsigned int i; |
| 216819 | for(i=0; i<sizeof(aStrength)/sizeof(aStrength[0]); i++){ |
| 216820 | if( sqlite3_stricmp(zOption,aStrength[i].zName)==0 ){ |
| 216821 | ucol_setStrength(pUCollator, aStrength[i].val); |
| 216822 | break; |
| 216823 | } |
| @@ -252096,11 +252156,11 @@ | |
| 252156 | int nArg, /* Number of args */ |
| 252157 | sqlite3_value **apUnused /* Function arguments */ |
| 252158 | ){ |
| 252159 | assert( nArg==0 ); |
| 252160 | UNUSED_PARAM2(nArg, apUnused); |
| 252161 | sqlite3_result_text(pCtx, "fts5: 2024-04-08 11:50:07 69ec714b2d698acf9e37635256c01b233ce32f22e8323e226441d5ddd948a940", -1, SQLITE_TRANSIENT); |
| 252162 | } |
| 252163 | |
| 252164 | /* |
| 252165 | ** Return true if zName is the extension on one of the shadow tables used |
| 252166 | ** by this module. |
| 252167 |
+1
-1
| --- extsrc/sqlite3.h | ||
| +++ extsrc/sqlite3.h | ||
| @@ -146,11 +146,11 @@ | ||
| 146 | 146 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 147 | 147 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 148 | 148 | */ |
| 149 | 149 | #define SQLITE_VERSION "3.46.0" |
| 150 | 150 | #define SQLITE_VERSION_NUMBER 3046000 |
| 151 | -#define SQLITE_SOURCE_ID "2024-04-04 14:26:42 7bf49e2c54c9f6f336416f01c0e76aaf70f1e2f3fd612232e5a33ae5dabe0900" | |
| 151 | +#define SQLITE_SOURCE_ID "2024-04-08 11:50:07 69ec714b2d698acf9e37635256c01b233ce32f22e8323e226441d5ddd948a940" | |
| 152 | 152 | |
| 153 | 153 | /* |
| 154 | 154 | ** CAPI3REF: Run-Time Library Version Numbers |
| 155 | 155 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 156 | 156 | ** |
| 157 | 157 |
| --- extsrc/sqlite3.h | |
| +++ extsrc/sqlite3.h | |
| @@ -146,11 +146,11 @@ | |
| 146 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 147 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 148 | */ |
| 149 | #define SQLITE_VERSION "3.46.0" |
| 150 | #define SQLITE_VERSION_NUMBER 3046000 |
| 151 | #define SQLITE_SOURCE_ID "2024-04-04 14:26:42 7bf49e2c54c9f6f336416f01c0e76aaf70f1e2f3fd612232e5a33ae5dabe0900" |
| 152 | |
| 153 | /* |
| 154 | ** CAPI3REF: Run-Time Library Version Numbers |
| 155 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 156 | ** |
| 157 |
| --- extsrc/sqlite3.h | |
| +++ extsrc/sqlite3.h | |
| @@ -146,11 +146,11 @@ | |
| 146 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 147 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 148 | */ |
| 149 | #define SQLITE_VERSION "3.46.0" |
| 150 | #define SQLITE_VERSION_NUMBER 3046000 |
| 151 | #define SQLITE_SOURCE_ID "2024-04-08 11:50:07 69ec714b2d698acf9e37635256c01b233ce32f22e8323e226441d5ddd948a940" |
| 152 | |
| 153 | /* |
| 154 | ** CAPI3REF: Run-Time Library Version Numbers |
| 155 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 156 | ** |
| 157 |