| | @@ -452,11 +452,11 @@ |
| 452 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | 454 | */ |
| 455 | 455 | #define SQLITE_VERSION "3.41.0" |
| 456 | 456 | #define SQLITE_VERSION_NUMBER 3041000 |
| 457 | | -#define SQLITE_SOURCE_ID "2023-02-08 14:49:52 6b41ba2e996ab7b9c3943ab93a19748db5cf37792f5d59d20eec301085282355" |
| 457 | +#define SQLITE_SOURCE_ID "2023-02-13 19:32:40 ecdeef43b27412b0b0b09e09a62ad3a03836a3fc80f2070268090e7ca8f02712" |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| | @@ -14400,19 +14400,13 @@ |
| 14400 | 14400 | */ |
| 14401 | 14401 | #define SQLITE_MAX_U32 ((((u64)1)<<32)-1) |
| 14402 | 14402 | |
| 14403 | 14403 | /* |
| 14404 | 14404 | ** The datatype used to store estimates of the number of rows in a |
| 14405 | | -** table or index. This is an unsigned integer type. For 99.9% of |
| 14406 | | -** the world, a 32-bit integer is sufficient. But a 64-bit integer |
| 14407 | | -** can be used at compile-time if desired. |
| 14405 | +** table or index. |
| 14408 | 14406 | */ |
| 14409 | | -#ifdef SQLITE_64BIT_STATS |
| 14410 | | - typedef u64 tRowcnt; /* 64-bit only if requested at compile-time */ |
| 14411 | | -#else |
| 14412 | | - typedef u32 tRowcnt; /* 32-bit is the default */ |
| 14413 | | -#endif |
| 14407 | +typedef u64 tRowcnt; |
| 14414 | 14408 | |
| 14415 | 14409 | /* |
| 14416 | 14410 | ** Estimated quantities used for query planning are stored as 16-bit |
| 14417 | 14411 | ** logarithms. For quantity X, the value stored is 10*log2(X). This |
| 14418 | 14412 | ** gives a possible range of values of approximately 1.0e986 to 1e-986. |
| | @@ -17116,11 +17110,10 @@ |
| 17116 | 17110 | u8 mTrace; /* zero or more SQLITE_TRACE flags */ |
| 17117 | 17111 | u8 noSharedCache; /* True if no shared-cache backends */ |
| 17118 | 17112 | u8 nSqlExec; /* Number of pending OP_SqlExec opcodes */ |
| 17119 | 17113 | u8 eOpenState; /* Current condition of the connection */ |
| 17120 | 17114 | int nextPagesize; /* Pagesize after VACUUM if >0 */ |
| 17121 | | - i64 txnTime; /* Timestamp for current transaction */ |
| 17122 | 17115 | i64 nChange; /* Value returned by sqlite3_changes() */ |
| 17123 | 17116 | i64 nTotalChange; /* Value returned by sqlite3_total_changes() */ |
| 17124 | 17117 | int aLimit[SQLITE_N_LIMIT]; /* Limits */ |
| 17125 | 17118 | int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */ |
| 17126 | 17119 | struct sqlite3InitInfo { /* Information used during initialization */ |
| | @@ -20836,11 +20829,11 @@ |
| 20836 | 20829 | SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*); |
| 20837 | 20830 | #if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \ |
| 20838 | 20831 | && !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 20839 | 20832 | SQLITE_PRIVATE void sqlite3VtabUsesAllSchemas(sqlite3_index_info*); |
| 20840 | 20833 | #endif |
| 20841 | | -SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*, int); |
| 20834 | +SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*); |
| 20842 | 20835 | SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int); |
| 20843 | 20836 | SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *); |
| 20844 | 20837 | SQLITE_PRIVATE void sqlite3ParseObjectInit(Parse*,sqlite3*); |
| 20845 | 20838 | SQLITE_PRIVATE void sqlite3ParseObjectReset(Parse*); |
| 20846 | 20839 | SQLITE_PRIVATE void *sqlite3ParserAddCleanup(Parse*,void(*)(sqlite3*,void*),void*); |
| | @@ -23824,20 +23817,16 @@ |
| 23824 | 23817 | } |
| 23825 | 23818 | return 0; |
| 23826 | 23819 | } |
| 23827 | 23820 | |
| 23828 | 23821 | /* |
| 23829 | | -** Set the time to the current time reported for the prepared statement |
| 23830 | | -** that is currently executing. The same time is reported for all |
| 23831 | | -** invocations of this routine from within the same call to sqlite3_step(). |
| 23832 | | -** |
| 23833 | | -** Or if bTxn is true, use the transaction time. |
| 23822 | +** Set the time to the current time reported by the VFS. |
| 23834 | 23823 | ** |
| 23835 | 23824 | ** Return the number of errors. |
| 23836 | 23825 | */ |
| 23837 | | -static int setCurrentStmtTime(sqlite3_context *context, DateTime *p, int bTxn){ |
| 23838 | | - p->iJD = sqlite3StmtCurrentTime(context, bTxn); |
| 23826 | +static int setDateTimeToCurrent(sqlite3_context *context, DateTime *p){ |
| 23827 | + p->iJD = sqlite3StmtCurrentTime(context); |
| 23839 | 23828 | if( p->iJD>0 ){ |
| 23840 | 23829 | p->validJD = 1; |
| 23841 | 23830 | return 0; |
| 23842 | 23831 | }else{ |
| 23843 | 23832 | return 1; |
| | @@ -23884,13 +23873,11 @@ |
| 23884 | 23873 | if( parseYyyyMmDd(zDate,p)==0 ){ |
| 23885 | 23874 | return 0; |
| 23886 | 23875 | }else if( parseHhMmSs(zDate, p)==0 ){ |
| 23887 | 23876 | return 0; |
| 23888 | 23877 | }else if( sqlite3StrICmp(zDate,"now")==0 && sqlite3NotPureFunc(context) ){ |
| 23889 | | - return setCurrentStmtTime(context, p, 0); |
| 23890 | | - }else if( sqlite3StrICmp(zDate,"txn")==0 && sqlite3NotPureFunc(context) ){ |
| 23891 | | - return setCurrentStmtTime(context, p, 1); |
| 23878 | + return setDateTimeToCurrent(context, p); |
| 23892 | 23879 | }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8)>0 ){ |
| 23893 | 23880 | setRawDateNumber(p, r); |
| 23894 | 23881 | return 0; |
| 23895 | 23882 | } |
| 23896 | 23883 | return 1; |
| | @@ -24248,11 +24235,11 @@ |
| 24248 | 24235 | else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){ |
| 24249 | 24236 | if( p->tzSet==0 ){ |
| 24250 | 24237 | i64 iOrigJD; /* Original localtime */ |
| 24251 | 24238 | i64 iGuess; /* Guess at the corresponding utc time */ |
| 24252 | 24239 | int cnt = 0; /* Safety to prevent infinite loop */ |
| 24253 | | - int iErr; /* Guess is off by this much */ |
| 24240 | + i64 iErr; /* Guess is off by this much */ |
| 24254 | 24241 | |
| 24255 | 24242 | computeJD(p); |
| 24256 | 24243 | iGuess = iOrigJD = p->iJD; |
| 24257 | 24244 | iErr = 0; |
| 24258 | 24245 | do{ |
| | @@ -24430,15 +24417,12 @@ |
| 24430 | 24417 | ** Process time function arguments. argv[0] is a date-time stamp. |
| 24431 | 24418 | ** argv[1] and following are modifiers. Parse them all and write |
| 24432 | 24419 | ** the resulting time into the DateTime structure p. Return 0 |
| 24433 | 24420 | ** on success and 1 if there are any errors. |
| 24434 | 24421 | ** |
| 24435 | | -** If there are zero parameters (if argc<=0) then assume a default |
| 24436 | | -** value of "now" for argv[0] if argc==0 and "txn" if argc<0. SQL |
| 24437 | | -** functions will always have argc>=0, but the special implementations |
| 24438 | | -** of CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP set argc to -1 |
| 24439 | | -** in order to force the use of 'txn' semantics. |
| 24422 | +** If there are zero parameters (if even argv[0] is undefined) |
| 24423 | +** then assume a default value of "now" for argv[0]. |
| 24440 | 24424 | */ |
| 24441 | 24425 | static int isDate( |
| 24442 | 24426 | sqlite3_context *context, |
| 24443 | 24427 | int argc, |
| 24444 | 24428 | sqlite3_value **argv, |
| | @@ -24446,13 +24430,13 @@ |
| 24446 | 24430 | ){ |
| 24447 | 24431 | int i, n; |
| 24448 | 24432 | const unsigned char *z; |
| 24449 | 24433 | int eType; |
| 24450 | 24434 | memset(p, 0, sizeof(*p)); |
| 24451 | | - if( argc<=0 ){ |
| 24435 | + if( argc==0 ){ |
| 24452 | 24436 | if( !sqlite3NotPureFunc(context) ) return 1; |
| 24453 | | - return setCurrentStmtTime(context, p, argc<0); |
| 24437 | + return setDateTimeToCurrent(context, p); |
| 24454 | 24438 | } |
| 24455 | 24439 | if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT |
| 24456 | 24440 | || eType==SQLITE_INTEGER ){ |
| 24457 | 24441 | setRawDateNumber(p, sqlite3_value_double(argv[0])); |
| 24458 | 24442 | }else{ |
| | @@ -24755,11 +24739,11 @@ |
| 24755 | 24739 | sqlite3_context *context, |
| 24756 | 24740 | int NotUsed, |
| 24757 | 24741 | sqlite3_value **NotUsed2 |
| 24758 | 24742 | ){ |
| 24759 | 24743 | UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 24760 | | - timeFunc(context, -1, 0); |
| 24744 | + timeFunc(context, 0, 0); |
| 24761 | 24745 | } |
| 24762 | 24746 | |
| 24763 | 24747 | /* |
| 24764 | 24748 | ** current_date() |
| 24765 | 24749 | ** |
| | @@ -24769,11 +24753,11 @@ |
| 24769 | 24753 | sqlite3_context *context, |
| 24770 | 24754 | int NotUsed, |
| 24771 | 24755 | sqlite3_value **NotUsed2 |
| 24772 | 24756 | ){ |
| 24773 | 24757 | UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 24774 | | - dateFunc(context, -1, 0); |
| 24758 | + dateFunc(context, 0, 0); |
| 24775 | 24759 | } |
| 24776 | 24760 | |
| 24777 | 24761 | /* |
| 24778 | 24762 | ** current_timestamp() |
| 24779 | 24763 | ** |
| | @@ -24783,11 +24767,11 @@ |
| 24783 | 24767 | sqlite3_context *context, |
| 24784 | 24768 | int NotUsed, |
| 24785 | 24769 | sqlite3_value **NotUsed2 |
| 24786 | 24770 | ){ |
| 24787 | 24771 | UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 24788 | | - datetimeFunc(context, -1, 0); |
| 24772 | + datetimeFunc(context, 0, 0); |
| 24789 | 24773 | } |
| 24790 | 24774 | #endif /* !defined(SQLITE_OMIT_DATETIME_FUNCS) */ |
| 24791 | 24775 | |
| 24792 | 24776 | #ifdef SQLITE_OMIT_DATETIME_FUNCS |
| 24793 | 24777 | /* |
| | @@ -24814,11 +24798,11 @@ |
| 24814 | 24798 | char zBuf[20]; |
| 24815 | 24799 | |
| 24816 | 24800 | UNUSED_PARAMETER(argc); |
| 24817 | 24801 | UNUSED_PARAMETER(argv); |
| 24818 | 24802 | |
| 24819 | | - iT = sqlite3StmtCurrentTime(context, 1); |
| 24803 | + iT = sqlite3StmtCurrentTime(context); |
| 24820 | 24804 | if( iT<=0 ) return; |
| 24821 | 24805 | t = iT/1000 - 10000*(sqlite3_int64)21086676; |
| 24822 | 24806 | #if HAVE_GMTIME_R |
| 24823 | 24807 | pTm = gmtime_r(&t, &sNow); |
| 24824 | 24808 | #else |
| | @@ -59055,11 +59039,10 @@ |
| 59055 | 59039 | ** the xSync primitive is called and is relevant to all platforms. |
| 59056 | 59040 | ** |
| 59057 | 59041 | ** Numeric values associated with these states are OFF==1, NORMAL=2, |
| 59058 | 59042 | ** and FULL=3. |
| 59059 | 59043 | */ |
| 59060 | | -#ifndef SQLITE_OMIT_PAGER_PRAGMAS |
| 59061 | 59044 | SQLITE_PRIVATE void sqlite3PagerSetFlags( |
| 59062 | 59045 | Pager *pPager, /* The pager to set safety level for */ |
| 59063 | 59046 | unsigned pgFlags /* Various flags */ |
| 59064 | 59047 | ){ |
| 59065 | 59048 | unsigned level = pgFlags & PAGER_SYNCHRONOUS_MASK; |
| | @@ -59090,11 +59073,10 @@ |
| 59090 | 59073 | pPager->doNotSpill &= ~SPILLFLAG_OFF; |
| 59091 | 59074 | }else{ |
| 59092 | 59075 | pPager->doNotSpill |= SPILLFLAG_OFF; |
| 59093 | 59076 | } |
| 59094 | 59077 | } |
| 59095 | | -#endif |
| 59096 | 59078 | |
| 59097 | 59079 | /* |
| 59098 | 59080 | ** The following global variable is incremented whenever the library |
| 59099 | 59081 | ** attempts to open a temporary file. This information is used for |
| 59100 | 59082 | ** testing and analysis only. |
| | @@ -60494,22 +60476,11 @@ |
| 60494 | 60476 | pPager->exclusiveMode = (u8)tempFile; |
| 60495 | 60477 | pPager->changeCountDone = pPager->tempFile; |
| 60496 | 60478 | pPager->memDb = (u8)memDb; |
| 60497 | 60479 | pPager->readOnly = (u8)readOnly; |
| 60498 | 60480 | assert( useJournal || pPager->tempFile ); |
| 60499 | | - pPager->noSync = pPager->tempFile; |
| 60500 | | - if( pPager->noSync ){ |
| 60501 | | - assert( pPager->fullSync==0 ); |
| 60502 | | - assert( pPager->extraSync==0 ); |
| 60503 | | - assert( pPager->syncFlags==0 ); |
| 60504 | | - assert( pPager->walSyncFlags==0 ); |
| 60505 | | - }else{ |
| 60506 | | - pPager->fullSync = 1; |
| 60507 | | - pPager->extraSync = 0; |
| 60508 | | - pPager->syncFlags = SQLITE_SYNC_NORMAL; |
| 60509 | | - pPager->walSyncFlags = SQLITE_SYNC_NORMAL | (SQLITE_SYNC_NORMAL<<2); |
| 60510 | | - } |
| 60481 | + sqlite3PagerSetFlags(pPager, (SQLITE_DEFAULT_SYNCHRONOUS+1)|PAGER_CACHESPILL); |
| 60511 | 60482 | /* pPager->pFirst = 0; */ |
| 60512 | 60483 | /* pPager->pFirstSynced = 0; */ |
| 60513 | 60484 | /* pPager->pLast = 0; */ |
| 60514 | 60485 | pPager->nExtra = (u16)nExtra; |
| 60515 | 60486 | pPager->journalSizeLimit = SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT; |
| | @@ -81926,15 +81897,15 @@ |
| 81926 | 81897 | rc = SQLITE_TOOBIG; |
| 81927 | 81898 | pCtx->pParse->nErr++; |
| 81928 | 81899 | } |
| 81929 | 81900 | #endif |
| 81930 | 81901 | } |
| 81931 | | - pCtx->pParse->rc = rc; |
| 81932 | 81902 | |
| 81933 | 81903 | value_from_function_out: |
| 81934 | 81904 | if( rc!=SQLITE_OK ){ |
| 81935 | 81905 | pVal = 0; |
| 81906 | + pCtx->pParse->rc = rc; |
| 81936 | 81907 | } |
| 81937 | 81908 | if( apVal ){ |
| 81938 | 81909 | for(i=0; i<nVal; i++){ |
| 81939 | 81910 | sqlite3ValueFree(apVal[i]); |
| 81940 | 81911 | } |
| | @@ -85785,11 +85756,10 @@ |
| 85785 | 85756 | ** by connection db have now been released. Call sqlite3ConnectionUnlocked() |
| 85786 | 85757 | ** to invoke any required unlock-notify callbacks. |
| 85787 | 85758 | */ |
| 85788 | 85759 | if( db->autoCommit ){ |
| 85789 | 85760 | sqlite3ConnectionUnlocked(db); |
| 85790 | | - db->txnTime = 0; |
| 85791 | 85761 | } |
| 85792 | 85762 | |
| 85793 | 85763 | assert( db->nVdbeActive>0 || db->autoCommit==0 || db->nStatement==0 ); |
| 85794 | 85764 | return (p->rc==SQLITE_BUSY ? SQLITE_BUSY : SQLITE_OK); |
| 85795 | 85765 | } |
| | @@ -88744,31 +88714,22 @@ |
| 88744 | 88714 | ** Return the current time for a statement. If the current time |
| 88745 | 88715 | ** is requested more than once within the same run of a single prepared |
| 88746 | 88716 | ** statement, the exact same time is returned for each invocation regardless |
| 88747 | 88717 | ** of the amount of time that elapses between invocations. In other words, |
| 88748 | 88718 | ** the time returned is always the time of the first call. |
| 88749 | | -** |
| 88750 | | -** Or, if bTxn, return the transaction time. The transaction time is the |
| 88751 | | -** same for all calls within the same transaction. |
| 88752 | | -** |
| 88753 | | -** bTxn is 0 for SQL like datetime('now') and is 1 for datetime('txn'). |
| 88754 | 88719 | */ |
| 88755 | | -SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context *p, int bTxn){ |
| 88720 | +SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context *p){ |
| 88756 | 88721 | int rc; |
| 88757 | 88722 | #ifndef SQLITE_ENABLE_STAT4 |
| 88758 | | - sqlite3_int64 *piTime; |
| 88759 | | - sqlite3 *db = p->pOut->db; |
| 88723 | + sqlite3_int64 *piTime = &p->pVdbe->iCurrentTime; |
| 88760 | 88724 | assert( p->pVdbe!=0 ); |
| 88761 | | - piTime = bTxn ? &db->txnTime : &p->pVdbe->iCurrentTime; |
| 88762 | 88725 | #else |
| 88763 | 88726 | sqlite3_int64 iTime = 0; |
| 88764 | | - sqlite3_int64 *piTime; |
| 88765 | | - sqlite3 *db = p->pOut->db; |
| 88766 | | - piTime = bTxn ? &db->txnTime : p->pVdbe!=0 ? &p->pVdbe->iCurrentTime : &iTime; |
| 88727 | + sqlite3_int64 *piTime = p->pVdbe!=0 ? &p->pVdbe->iCurrentTime : &iTime; |
| 88767 | 88728 | #endif |
| 88768 | 88729 | if( *piTime==0 ){ |
| 88769 | | - rc = sqlite3OsCurrentTimeInt64(db->pVfs, piTime); |
| 88730 | + rc = sqlite3OsCurrentTimeInt64(p->pOut->db->pVfs, piTime); |
| 88770 | 88731 | if( rc ) *piTime = 0; |
| 88771 | 88732 | } |
| 88772 | 88733 | return *piTime; |
| 88773 | 88734 | } |
| 88774 | 88735 | |
| | @@ -109856,14 +109817,17 @@ |
| 109856 | 109817 | case INLINEFUNC_affinity: { |
| 109857 | 109818 | /* The AFFINITY() function evaluates to a string that describes |
| 109858 | 109819 | ** the type affinity of the argument. This is used for testing of |
| 109859 | 109820 | ** the SQLite type logic. |
| 109860 | 109821 | */ |
| 109861 | | - const char *azAff[] = { "blob", "text", "numeric", "integer", "real" }; |
| 109822 | + const char *azAff[] = { "blob", "text", "numeric", "integer", |
| 109823 | + "real", "flexnum" }; |
| 109862 | 109824 | char aff; |
| 109863 | 109825 | assert( nFarg==1 ); |
| 109864 | 109826 | aff = sqlite3ExprAffinity(pFarg->a[0].pExpr); |
| 109827 | + assert( aff<=SQLITE_AFF_NONE |
| 109828 | + || (aff>=SQLITE_AFF_BLOB && aff<=SQLITE_AFF_FLEXNUM) ); |
| 109865 | 109829 | sqlite3VdbeLoadString(v, target, |
| 109866 | 109830 | (aff<=SQLITE_AFF_NONE) ? "none" : azAff[aff-SQLITE_AFF_BLOB]); |
| 109867 | 109831 | break; |
| 109868 | 109832 | } |
| 109869 | 109833 | #endif /* !defined(SQLITE_UNTESTABLE) */ |
| | @@ -152720,72 +152684,79 @@ |
| 152720 | 152684 | int iEq, /* Look at loop terms starting here */ |
| 152721 | 152685 | WhereLoop *pLoop, /* The current loop */ |
| 152722 | 152686 | Expr *pX /* The IN expression to be reduced */ |
| 152723 | 152687 | ){ |
| 152724 | 152688 | sqlite3 *db = pParse->db; |
| 152689 | + Select *pSelect; /* Pointer to the SELECT on the RHS */ |
| 152725 | 152690 | Expr *pNew; |
| 152726 | 152691 | pNew = sqlite3ExprDup(db, pX, 0); |
| 152727 | 152692 | if( db->mallocFailed==0 ){ |
| 152728 | | - ExprList *pOrigRhs; /* Original unmodified RHS */ |
| 152729 | | - ExprList *pOrigLhs; /* Original unmodified LHS */ |
| 152730 | | - ExprList *pRhs = 0; /* New RHS after modifications */ |
| 152731 | | - ExprList *pLhs = 0; /* New LHS after mods */ |
| 152732 | | - int i; /* Loop counter */ |
| 152733 | | - Select *pSelect; /* Pointer to the SELECT on the RHS */ |
| 152734 | | - |
| 152735 | | - assert( ExprUseXSelect(pNew) ); |
| 152736 | | - pOrigRhs = pNew->x.pSelect->pEList; |
| 152737 | | - assert( pNew->pLeft!=0 ); |
| 152738 | | - assert( ExprUseXList(pNew->pLeft) ); |
| 152739 | | - pOrigLhs = pNew->pLeft->x.pList; |
| 152740 | | - for(i=iEq; i<pLoop->nLTerm; i++){ |
| 152741 | | - if( pLoop->aLTerm[i]->pExpr==pX ){ |
| 152742 | | - int iField; |
| 152743 | | - assert( (pLoop->aLTerm[i]->eOperator & (WO_OR|WO_AND))==0 ); |
| 152744 | | - iField = pLoop->aLTerm[i]->u.x.iField - 1; |
| 152745 | | - if( pOrigRhs->a[iField].pExpr==0 ) continue; /* Duplicate PK column */ |
| 152746 | | - pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr); |
| 152747 | | - pOrigRhs->a[iField].pExpr = 0; |
| 152748 | | - assert( pOrigLhs->a[iField].pExpr!=0 ); |
| 152749 | | - pLhs = sqlite3ExprListAppend(pParse, pLhs, pOrigLhs->a[iField].pExpr); |
| 152750 | | - pOrigLhs->a[iField].pExpr = 0; |
| 152751 | | - } |
| 152752 | | - } |
| 152753 | | - sqlite3ExprListDelete(db, pOrigRhs); |
| 152754 | | - sqlite3ExprListDelete(db, pOrigLhs); |
| 152755 | | - pNew->pLeft->x.pList = pLhs; |
| 152756 | | - pNew->x.pSelect->pEList = pRhs; |
| 152757 | | - if( pLhs && pLhs->nExpr==1 ){ |
| 152758 | | - /* Take care here not to generate a TK_VECTOR containing only a |
| 152759 | | - ** single value. Since the parser never creates such a vector, some |
| 152760 | | - ** of the subroutines do not handle this case. */ |
| 152761 | | - Expr *p = pLhs->a[0].pExpr; |
| 152762 | | - pLhs->a[0].pExpr = 0; |
| 152763 | | - sqlite3ExprDelete(db, pNew->pLeft); |
| 152764 | | - pNew->pLeft = p; |
| 152765 | | - } |
| 152766 | | - pSelect = pNew->x.pSelect; |
| 152767 | | - if( pSelect->pOrderBy ){ |
| 152768 | | - /* If the SELECT statement has an ORDER BY clause, zero the |
| 152769 | | - ** iOrderByCol variables. These are set to non-zero when an |
| 152770 | | - ** ORDER BY term exactly matches one of the terms of the |
| 152771 | | - ** result-set. Since the result-set of the SELECT statement may |
| 152772 | | - ** have been modified or reordered, these variables are no longer |
| 152773 | | - ** set correctly. Since setting them is just an optimization, |
| 152774 | | - ** it's easiest just to zero them here. */ |
| 152775 | | - ExprList *pOrderBy = pSelect->pOrderBy; |
| 152776 | | - for(i=0; i<pOrderBy->nExpr; i++){ |
| 152777 | | - pOrderBy->a[i].u.x.iOrderByCol = 0; |
| 152778 | | - } |
| 152779 | | - } |
| 152693 | + for(pSelect=pNew->x.pSelect; pSelect; pSelect=pSelect->pPrior){ |
| 152694 | + ExprList *pOrigRhs; /* Original unmodified RHS */ |
| 152695 | + ExprList *pOrigLhs = 0; /* Original unmodified LHS */ |
| 152696 | + ExprList *pRhs = 0; /* New RHS after modifications */ |
| 152697 | + ExprList *pLhs = 0; /* New LHS after mods */ |
| 152698 | + int i; /* Loop counter */ |
| 152699 | + |
| 152700 | + assert( ExprUseXSelect(pNew) ); |
| 152701 | + pOrigRhs = pSelect->pEList; |
| 152702 | + assert( pNew->pLeft!=0 ); |
| 152703 | + assert( ExprUseXList(pNew->pLeft) ); |
| 152704 | + if( pSelect==pNew->x.pSelect ){ |
| 152705 | + pOrigLhs = pNew->pLeft->x.pList; |
| 152706 | + } |
| 152707 | + for(i=iEq; i<pLoop->nLTerm; i++){ |
| 152708 | + if( pLoop->aLTerm[i]->pExpr==pX ){ |
| 152709 | + int iField; |
| 152710 | + assert( (pLoop->aLTerm[i]->eOperator & (WO_OR|WO_AND))==0 ); |
| 152711 | + iField = pLoop->aLTerm[i]->u.x.iField - 1; |
| 152712 | + if( pOrigRhs->a[iField].pExpr==0 ) continue; /* Duplicate PK column */ |
| 152713 | + pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr); |
| 152714 | + pOrigRhs->a[iField].pExpr = 0; |
| 152715 | + if( pOrigLhs ){ |
| 152716 | + assert( pOrigLhs->a[iField].pExpr!=0 ); |
| 152717 | + pLhs = sqlite3ExprListAppend(pParse,pLhs,pOrigLhs->a[iField].pExpr); |
| 152718 | + pOrigLhs->a[iField].pExpr = 0; |
| 152719 | + } |
| 152720 | + } |
| 152721 | + } |
| 152722 | + sqlite3ExprListDelete(db, pOrigRhs); |
| 152723 | + if( pOrigLhs ){ |
| 152724 | + sqlite3ExprListDelete(db, pOrigLhs); |
| 152725 | + pNew->pLeft->x.pList = pLhs; |
| 152726 | + } |
| 152727 | + pSelect->pEList = pRhs; |
| 152728 | + if( pLhs && pLhs->nExpr==1 ){ |
| 152729 | + /* Take care here not to generate a TK_VECTOR containing only a |
| 152730 | + ** single value. Since the parser never creates such a vector, some |
| 152731 | + ** of the subroutines do not handle this case. */ |
| 152732 | + Expr *p = pLhs->a[0].pExpr; |
| 152733 | + pLhs->a[0].pExpr = 0; |
| 152734 | + sqlite3ExprDelete(db, pNew->pLeft); |
| 152735 | + pNew->pLeft = p; |
| 152736 | + } |
| 152737 | + if( pSelect->pOrderBy ){ |
| 152738 | + /* If the SELECT statement has an ORDER BY clause, zero the |
| 152739 | + ** iOrderByCol variables. These are set to non-zero when an |
| 152740 | + ** ORDER BY term exactly matches one of the terms of the |
| 152741 | + ** result-set. Since the result-set of the SELECT statement may |
| 152742 | + ** have been modified or reordered, these variables are no longer |
| 152743 | + ** set correctly. Since setting them is just an optimization, |
| 152744 | + ** it's easiest just to zero them here. */ |
| 152745 | + ExprList *pOrderBy = pSelect->pOrderBy; |
| 152746 | + for(i=0; i<pOrderBy->nExpr; i++){ |
| 152747 | + pOrderBy->a[i].u.x.iOrderByCol = 0; |
| 152748 | + } |
| 152749 | + } |
| 152780 | 152750 | |
| 152781 | 152751 | #if 0 |
| 152782 | | - printf("For indexing, change the IN expr:\n"); |
| 152783 | | - sqlite3TreeViewExpr(0, pX, 0); |
| 152784 | | - printf("Into:\n"); |
| 152785 | | - sqlite3TreeViewExpr(0, pNew, 0); |
| 152752 | + printf("For indexing, change the IN expr:\n"); |
| 152753 | + sqlite3TreeViewExpr(0, pX, 0); |
| 152754 | + printf("Into:\n"); |
| 152755 | + sqlite3TreeViewExpr(0, pNew, 0); |
| 152786 | 152756 | #endif |
| 152757 | + } |
| 152787 | 152758 | } |
| 152788 | 152759 | return pNew; |
| 152789 | 152760 | } |
| 152790 | 152761 | |
| 152791 | 152762 | |
| | @@ -155993,60 +155964,70 @@ |
| 155993 | 155964 | ** true even if that particular column is not indexed, because the column |
| 155994 | 155965 | ** might be added to an automatic index later. |
| 155995 | 155966 | */ |
| 155996 | 155967 | static SQLITE_NOINLINE int exprMightBeIndexed2( |
| 155997 | 155968 | SrcList *pFrom, /* The FROM clause */ |
| 155998 | | - Bitmask mPrereq, /* Bitmask of FROM clause terms referenced by pExpr */ |
| 155999 | 155969 | int *aiCurCol, /* Write the referenced table cursor and column here */ |
| 156000 | | - Expr *pExpr /* An operand of a comparison operator */ |
| 155970 | + Expr *pExpr, /* An operand of a comparison operator */ |
| 155971 | + int j /* Start looking with the j-th pFrom entry */ |
| 156001 | 155972 | ){ |
| 156002 | 155973 | Index *pIdx; |
| 156003 | 155974 | int i; |
| 156004 | 155975 | int iCur; |
| 156005 | | - for(i=0; mPrereq>1; i++, mPrereq>>=1){} |
| 156006 | | - iCur = pFrom->a[i].iCursor; |
| 156007 | | - for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 156008 | | - if( pIdx->aColExpr==0 ) continue; |
| 156009 | | - for(i=0; i<pIdx->nKeyCol; i++){ |
| 156010 | | - if( pIdx->aiColumn[i]!=XN_EXPR ) continue; |
| 156011 | | - assert( pIdx->bHasExpr ); |
| 156012 | | - if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){ |
| 156013 | | - aiCurCol[0] = iCur; |
| 156014 | | - aiCurCol[1] = XN_EXPR; |
| 156015 | | - return 1; |
| 155976 | + do{ |
| 155977 | + iCur = pFrom->a[j].iCursor; |
| 155978 | + for(pIdx=pFrom->a[j].pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 155979 | + if( pIdx->aColExpr==0 ) continue; |
| 155980 | + for(i=0; i<pIdx->nKeyCol; i++){ |
| 155981 | + if( pIdx->aiColumn[i]!=XN_EXPR ) continue; |
| 155982 | + assert( pIdx->bHasExpr ); |
| 155983 | + if( sqlite3ExprCompareSkip(pExpr,pIdx->aColExpr->a[i].pExpr,iCur)==0 |
| 155984 | + && pExpr->op!=TK_STRING |
| 155985 | + ){ |
| 155986 | + aiCurCol[0] = iCur; |
| 155987 | + aiCurCol[1] = XN_EXPR; |
| 155988 | + return 1; |
| 155989 | + } |
| 156016 | 155990 | } |
| 156017 | 155991 | } |
| 156018 | | - } |
| 155992 | + }while( ++j < pFrom->nSrc ); |
| 156019 | 155993 | return 0; |
| 156020 | 155994 | } |
| 156021 | 155995 | static int exprMightBeIndexed( |
| 156022 | 155996 | SrcList *pFrom, /* The FROM clause */ |
| 156023 | | - Bitmask mPrereq, /* Bitmask of FROM clause terms referenced by pExpr */ |
| 156024 | 155997 | int *aiCurCol, /* Write the referenced table cursor & column here */ |
| 156025 | 155998 | Expr *pExpr, /* An operand of a comparison operator */ |
| 156026 | 155999 | int op /* The specific comparison operator */ |
| 156027 | 156000 | ){ |
| 156001 | + int i; |
| 156002 | + |
| 156028 | 156003 | /* If this expression is a vector to the left or right of a |
| 156029 | 156004 | ** inequality constraint (>, <, >= or <=), perform the processing |
| 156030 | 156005 | ** on the first element of the vector. */ |
| 156031 | 156006 | assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE ); |
| 156032 | 156007 | assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE ); |
| 156033 | 156008 | assert( op<=TK_GE ); |
| 156034 | 156009 | if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){ |
| 156035 | 156010 | assert( ExprUseXList(pExpr) ); |
| 156036 | 156011 | pExpr = pExpr->x.pList->a[0].pExpr; |
| 156037 | | - |
| 156038 | 156012 | } |
| 156039 | 156013 | |
| 156040 | 156014 | if( pExpr->op==TK_COLUMN ){ |
| 156041 | 156015 | aiCurCol[0] = pExpr->iTable; |
| 156042 | 156016 | aiCurCol[1] = pExpr->iColumn; |
| 156043 | 156017 | return 1; |
| 156044 | 156018 | } |
| 156045 | | - if( mPrereq==0 ) return 0; /* No table references */ |
| 156046 | | - if( (mPrereq&(mPrereq-1))!=0 ) return 0; /* Refs more than one table */ |
| 156047 | | - return exprMightBeIndexed2(pFrom,mPrereq,aiCurCol,pExpr); |
| 156019 | + |
| 156020 | + for(i=0; i<pFrom->nSrc; i++){ |
| 156021 | + Index *pIdx; |
| 156022 | + for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 156023 | + if( pIdx->aColExpr ){ |
| 156024 | + return exprMightBeIndexed2(pFrom,aiCurCol,pExpr,i); |
| 156025 | + } |
| 156026 | + } |
| 156027 | + } |
| 156028 | + return 0; |
| 156048 | 156029 | } |
| 156049 | 156030 | |
| 156050 | 156031 | |
| 156051 | 156032 | /* |
| 156052 | 156033 | ** The input to this routine is an WhereTerm structure with only the |
| | @@ -156168,19 +156149,19 @@ |
| 156168 | 156149 | assert( pLeft->op==TK_VECTOR ); |
| 156169 | 156150 | assert( ExprUseXList(pLeft) ); |
| 156170 | 156151 | pLeft = pLeft->x.pList->a[pTerm->u.x.iField-1].pExpr; |
| 156171 | 156152 | } |
| 156172 | 156153 | |
| 156173 | | - if( exprMightBeIndexed(pSrc, prereqLeft, aiCurCol, pLeft, op) ){ |
| 156154 | + if( exprMightBeIndexed(pSrc, aiCurCol, pLeft, op) ){ |
| 156174 | 156155 | pTerm->leftCursor = aiCurCol[0]; |
| 156175 | 156156 | assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 156176 | 156157 | pTerm->u.x.leftColumn = aiCurCol[1]; |
| 156177 | 156158 | pTerm->eOperator = operatorMask(op) & opMask; |
| 156178 | 156159 | } |
| 156179 | 156160 | if( op==TK_IS ) pTerm->wtFlags |= TERM_IS; |
| 156180 | 156161 | if( pRight |
| 156181 | | - && exprMightBeIndexed(pSrc, pTerm->prereqRight, aiCurCol, pRight, op) |
| 156162 | + && exprMightBeIndexed(pSrc, aiCurCol, pRight, op) |
| 156182 | 156163 | && !ExprHasProperty(pRight, EP_FixedCol) |
| 156183 | 156164 | ){ |
| 156184 | 156165 | WhereTerm *pNew; |
| 156185 | 156166 | Expr *pDup; |
| 156186 | 156167 | u16 eExtraOp = 0; /* Extra bits for pNew->eOperator */ |
| | @@ -156387,18 +156368,18 @@ |
| 156387 | 156368 | sqlite3ExprAddCollateString(pParse,pNewExpr1,zCollSeqName), |
| 156388 | 156369 | pStr1); |
| 156389 | 156370 | transferJoinMarkings(pNewExpr1, pExpr); |
| 156390 | 156371 | idxNew1 = whereClauseInsert(pWC, pNewExpr1, wtFlags); |
| 156391 | 156372 | testcase( idxNew1==0 ); |
| 156392 | | - exprAnalyze(pSrc, pWC, idxNew1); |
| 156393 | 156373 | pNewExpr2 = sqlite3ExprDup(db, pLeft, 0); |
| 156394 | 156374 | pNewExpr2 = sqlite3PExpr(pParse, TK_LT, |
| 156395 | 156375 | sqlite3ExprAddCollateString(pParse,pNewExpr2,zCollSeqName), |
| 156396 | 156376 | pStr2); |
| 156397 | 156377 | transferJoinMarkings(pNewExpr2, pExpr); |
| 156398 | 156378 | idxNew2 = whereClauseInsert(pWC, pNewExpr2, wtFlags); |
| 156399 | 156379 | testcase( idxNew2==0 ); |
| 156380 | + exprAnalyze(pSrc, pWC, idxNew1); |
| 156400 | 156381 | exprAnalyze(pSrc, pWC, idxNew2); |
| 156401 | 156382 | pTerm = &pWC->a[idxTerm]; |
| 156402 | 156383 | if( isComplete ){ |
| 156403 | 156384 | markTermAsChild(pWC, idxNew1, idxTerm); |
| 156404 | 156385 | markTermAsChild(pWC, idxNew2, idxTerm); |
| | @@ -156451,11 +156432,11 @@ |
| 156451 | 156432 | */ |
| 156452 | 156433 | else if( pExpr->op==TK_IN |
| 156453 | 156434 | && pTerm->u.x.iField==0 |
| 156454 | 156435 | && pExpr->pLeft->op==TK_VECTOR |
| 156455 | 156436 | && ALWAYS( ExprUseXSelect(pExpr) ) |
| 156456 | | - && pExpr->x.pSelect->pPrior==0 |
| 156437 | + && (pExpr->x.pSelect->pPrior==0 || (pExpr->x.pSelect->selFlags & SF_Values)) |
| 156457 | 156438 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 156458 | 156439 | && pExpr->x.pSelect->pWin==0 |
| 156459 | 156440 | #endif |
| 156460 | 156441 | && pWC->op==TK_AND |
| 156461 | 156442 | ){ |
| | @@ -171278,10 +171259,15 @@ |
| 171278 | 171259 | if( yymsp[-1].minor.yy322->nExpr==1 && sqlite3ExprIsConstant(pRHS) && yymsp[-4].minor.yy528->op!=TK_VECTOR ){ |
| 171279 | 171260 | yymsp[-1].minor.yy322->a[0].pExpr = 0; |
| 171280 | 171261 | sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322); |
| 171281 | 171262 | pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0); |
| 171282 | 171263 | yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_EQ, yymsp[-4].minor.yy528, pRHS); |
| 171264 | + }else if( yymsp[-1].minor.yy322->nExpr==1 && pRHS->op==TK_SELECT ){ |
| 171265 | + yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy528, 0); |
| 171266 | + sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy528, pRHS->x.pSelect); |
| 171267 | + pRHS->x.pSelect = 0; |
| 171268 | + sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322); |
| 171283 | 171269 | }else{ |
| 171284 | 171270 | yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy528, 0); |
| 171285 | 171271 | if( yymsp[-4].minor.yy528==0 ){ |
| 171286 | 171272 | sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322); |
| 171287 | 171273 | }else if( yymsp[-4].minor.yy528->pLeft->op==TK_VECTOR ){ |
| | @@ -227206,10 +227192,23 @@ |
| 227206 | 227192 | |
| 227207 | 227193 | sqlite3_free(sParse.apPhrase); |
| 227208 | 227194 | *pzErr = sParse.zErr; |
| 227209 | 227195 | return sParse.rc; |
| 227210 | 227196 | } |
| 227197 | + |
| 227198 | +/* |
| 227199 | +** Assuming that buffer z is at least nByte bytes in size and contains a |
| 227200 | +** valid utf-8 string, return the number of characters in the string. |
| 227201 | +*/ |
| 227202 | +static int fts5ExprCountChar(const char *z, int nByte){ |
| 227203 | + int nRet = 0; |
| 227204 | + int ii; |
| 227205 | + for(ii=0; ii<nByte; ii++){ |
| 227206 | + if( (z[ii] & 0xC0)!=0x80 ) nRet++; |
| 227207 | + } |
| 227208 | + return nRet; |
| 227209 | +} |
| 227211 | 227210 | |
| 227212 | 227211 | /* |
| 227213 | 227212 | ** This function is only called when using the special 'trigram' tokenizer. |
| 227214 | 227213 | ** Argument zText contains the text of a LIKE or GLOB pattern matched |
| 227215 | 227214 | ** against column iCol. This function creates and compiles an FTS5 MATCH |
| | @@ -227244,11 +227243,12 @@ |
| 227244 | 227243 | |
| 227245 | 227244 | while( i<=nText ){ |
| 227246 | 227245 | if( i==nText |
| 227247 | 227246 | || zText[i]==aSpec[0] || zText[i]==aSpec[1] || zText[i]==aSpec[2] |
| 227248 | 227247 | ){ |
| 227249 | | - if( i-iFirst>=3 ){ |
| 227248 | + |
| 227249 | + if( fts5ExprCountChar(&zText[iFirst], i-iFirst)>=3 ){ |
| 227250 | 227250 | int jj; |
| 227251 | 227251 | zExpr[iOut++] = '"'; |
| 227252 | 227252 | for(jj=iFirst; jj<i; jj++){ |
| 227253 | 227253 | zExpr[iOut++] = zText[jj]; |
| 227254 | 227254 | if( zText[jj]=='"' ) zExpr[iOut++] = '"'; |
| | @@ -235321,14 +235321,14 @@ |
| 235321 | 235321 | pNew = (Fts5Structure*)sqlite3Fts5MallocZero(&p->rc, nByte); |
| 235322 | 235322 | |
| 235323 | 235323 | if( pNew ){ |
| 235324 | 235324 | Fts5StructureLevel *pLvl; |
| 235325 | 235325 | nByte = nSeg * sizeof(Fts5StructureSegment); |
| 235326 | | - pNew->nLevel = pStruct->nLevel+1; |
| 235326 | + pNew->nLevel = MIN(pStruct->nLevel+1, FTS5_MAX_LEVEL); |
| 235327 | 235327 | pNew->nRef = 1; |
| 235328 | 235328 | pNew->nWriteCounter = pStruct->nWriteCounter; |
| 235329 | | - pLvl = &pNew->aLevel[MIN(pStruct->nLevel, FTS5_MAX_LEVEL-1)]; |
| 235329 | + pLvl = &pNew->aLevel[pNew->nLevel-1]; |
| 235330 | 235330 | pLvl->aSeg = (Fts5StructureSegment*)sqlite3Fts5MallocZero(&p->rc, nByte); |
| 235331 | 235331 | if( pLvl->aSeg ){ |
| 235332 | 235332 | int iLvl, iSeg; |
| 235333 | 235333 | int iSegOut = 0; |
| 235334 | 235334 | /* Iterate through all segments, from oldest to newest. Add them to |
| | @@ -240169,11 +240169,11 @@ |
| 240169 | 240169 | int nArg, /* Number of args */ |
| 240170 | 240170 | sqlite3_value **apUnused /* Function arguments */ |
| 240171 | 240171 | ){ |
| 240172 | 240172 | assert( nArg==0 ); |
| 240173 | 240173 | UNUSED_PARAM2(nArg, apUnused); |
| 240174 | | - sqlite3_result_text(pCtx, "fts5: 2023-02-08 14:49:52 6b41ba2e996ab7b9c3943ab93a19748db5cf37792f5d59d20eec301085282355", -1, SQLITE_TRANSIENT); |
| 240174 | + sqlite3_result_text(pCtx, "fts5: 2023-02-13 19:32:40 ecdeef43b27412b0b0b09e09a62ad3a03836a3fc80f2070268090e7ca8f02712", -1, SQLITE_TRANSIENT); |
| 240175 | 240175 | } |
| 240176 | 240176 | |
| 240177 | 240177 | /* |
| 240178 | 240178 | ** Return true if zName is the extension on one of the shadow tables used |
| 240179 | 240179 | ** by this module. |
| 240180 | 240180 | |