Fossil SCM

Update the built-in SQLite to the latest trunk version for testing.

drh 2024-07-04 00:05 trunk
Commit cd508204105a40aa7823f91d385c9b03f952b31b340c81bc4ea040ed72c77616
+22 -14
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -20627,11 +20627,11 @@
2062720627
}
2062820628
case MODE_ScanExp:
2062920629
case MODE_Explain: {
2063020630
static const int aExplainWidth[] = {4, 13, 4, 4, 4, 13, 2, 13};
2063120631
static const int aExplainMap[] = {0, 1, 2, 3, 4, 5, 6, 7 };
20632
- static const int aScanExpWidth[] = {4, 6, 6, 13, 4, 4, 4, 13, 2, 13};
20632
+ static const int aScanExpWidth[] = {4, 15, 6, 13, 4, 4, 4, 13, 2, 13};
2063320633
static const int aScanExpMap[] = {0, 9, 8, 1, 2, 3, 4, 5, 6, 7 };
2063420634
2063520635
const int *aWidth = aExplainWidth;
2063620636
const int *aMap = aExplainMap;
2063720637
int nWidth = ArraySize(aExplainWidth);
@@ -21637,11 +21637,17 @@
2163721637
UNUSED_PARAMETER(pArg);
2163821638
#else
2163921639
if( pArg->scanstatsOn==3 ){
2164021640
const char *zSql =
2164121641
" SELECT addr, opcode, p1, p2, p3, p4, p5, comment, nexec,"
21642
- " round(ncycle*100.0 / (sum(ncycle) OVER ()), 2)||'%' AS cycles"
21642
+ " format('% 6s (%.2f%%)',"
21643
+ " CASE WHEN ncycle<100_000 THEN ncycle || ' '"
21644
+ " WHEN ncycle<100_000_000 THEN (ncycle/1_000) || 'K'"
21645
+ " WHEN ncycle<100_000_000_000 THEN (ncycle/1_000_000) || 'M'"
21646
+ " ELSE (ncycle/1000_000_000) || 'G' END,"
21647
+ " ncycle*100.0/(sum(ncycle) OVER ())"
21648
+ " ) AS cycles"
2164321649
" FROM bytecode(?)";
2164421650
2164521651
int rc = SQLITE_OK;
2164621652
sqlite3_stmt *pStmt = 0;
2164721653
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
@@ -30175,31 +30181,33 @@
3017530181
}
3017630182
3017730183
/*
3017830184
** On non-Windows platforms, look for $XDG_CONFIG_HOME.
3017930185
** If ${XDG_CONFIG_HOME}/sqlite3/sqliterc is found, return
30180
-** the path to it, else return 0. The result is cached for
30181
-** subsequent calls.
30186
+** the path to it. If there is no $(XDG_CONFIG_HOME) then
30187
+** look for $(HOME)/.config/sqlite3/sqliterc and if found
30188
+** return that. If none of these are found, return 0.
30189
+**
30190
+** The string returned is obtained from sqlite3_malloc() and
30191
+** should be freed by the caller.
3018230192
*/
30183
-static const char *find_xdg_config(void){
30193
+static char *find_xdg_config(void){
3018430194
#if defined(_WIN32) || defined(WIN32) || defined(_WIN32_WCE) \
3018530195
|| defined(__RTP__) || defined(_WRS_KERNEL)
3018630196
return 0;
3018730197
#else
30188
- static int alreadyTried = 0;
30189
- static char *zConfig = 0;
30198
+ char *zConfig = 0;
3019030199
const char *zXdgHome;
3019130200
30192
- if( alreadyTried!=0 ){
30193
- return zConfig;
30194
- }
30195
- alreadyTried = 1;
3019630201
zXdgHome = getenv("XDG_CONFIG_HOME");
3019730202
if( zXdgHome==0 ){
30198
- return 0;
30203
+ const char *zHome = getenv("HOME");
30204
+ if( zHome==0 ) return 0;
30205
+ zConfig = sqlite3_mprintf("%s/.config/sqlite3/sqliterc", zHome);
30206
+ }else{
30207
+ zConfig = sqlite3_mprintf("%s/sqlite3/sqliterc", zXdgHome);
3019930208
}
30200
- zConfig = sqlite3_mprintf("%s/sqlite3/sqliterc", zXdgHome);
3020130209
shell_check_oom(zConfig);
3020230210
if( access(zConfig,0)!=0 ){
3020330211
sqlite3_free(zConfig);
3020430212
zConfig = 0;
3020530213
}
@@ -30223,11 +30231,11 @@
3022330231
char *zBuf = 0;
3022430232
FILE *inSaved = p->in;
3022530233
int savedLineno = p->lineno;
3022630234
3022730235
if( sqliterc == NULL ){
30228
- sqliterc = find_xdg_config();
30236
+ sqliterc = zBuf = find_xdg_config();
3022930237
}
3023030238
if( sqliterc == NULL ){
3023130239
home_dir = find_home_dir(0);
3023230240
if( home_dir==0 ){
3023330241
eputz("-- warning: cannot find home directory;"
3023430242
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -20627,11 +20627,11 @@
20627 }
20628 case MODE_ScanExp:
20629 case MODE_Explain: {
20630 static const int aExplainWidth[] = {4, 13, 4, 4, 4, 13, 2, 13};
20631 static const int aExplainMap[] = {0, 1, 2, 3, 4, 5, 6, 7 };
20632 static const int aScanExpWidth[] = {4, 6, 6, 13, 4, 4, 4, 13, 2, 13};
20633 static const int aScanExpMap[] = {0, 9, 8, 1, 2, 3, 4, 5, 6, 7 };
20634
20635 const int *aWidth = aExplainWidth;
20636 const int *aMap = aExplainMap;
20637 int nWidth = ArraySize(aExplainWidth);
@@ -21637,11 +21637,17 @@
21637 UNUSED_PARAMETER(pArg);
21638 #else
21639 if( pArg->scanstatsOn==3 ){
21640 const char *zSql =
21641 " SELECT addr, opcode, p1, p2, p3, p4, p5, comment, nexec,"
21642 " round(ncycle*100.0 / (sum(ncycle) OVER ()), 2)||'%' AS cycles"
 
 
 
 
 
 
21643 " FROM bytecode(?)";
21644
21645 int rc = SQLITE_OK;
21646 sqlite3_stmt *pStmt = 0;
21647 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
@@ -30175,31 +30181,33 @@
30175 }
30176
30177 /*
30178 ** On non-Windows platforms, look for $XDG_CONFIG_HOME.
30179 ** If ${XDG_CONFIG_HOME}/sqlite3/sqliterc is found, return
30180 ** the path to it, else return 0. The result is cached for
30181 ** subsequent calls.
 
 
 
 
30182 */
30183 static const char *find_xdg_config(void){
30184 #if defined(_WIN32) || defined(WIN32) || defined(_WIN32_WCE) \
30185 || defined(__RTP__) || defined(_WRS_KERNEL)
30186 return 0;
30187 #else
30188 static int alreadyTried = 0;
30189 static char *zConfig = 0;
30190 const char *zXdgHome;
30191
30192 if( alreadyTried!=0 ){
30193 return zConfig;
30194 }
30195 alreadyTried = 1;
30196 zXdgHome = getenv("XDG_CONFIG_HOME");
30197 if( zXdgHome==0 ){
30198 return 0;
 
 
 
 
30199 }
30200 zConfig = sqlite3_mprintf("%s/sqlite3/sqliterc", zXdgHome);
30201 shell_check_oom(zConfig);
30202 if( access(zConfig,0)!=0 ){
30203 sqlite3_free(zConfig);
30204 zConfig = 0;
30205 }
@@ -30223,11 +30231,11 @@
30223 char *zBuf = 0;
30224 FILE *inSaved = p->in;
30225 int savedLineno = p->lineno;
30226
30227 if( sqliterc == NULL ){
30228 sqliterc = find_xdg_config();
30229 }
30230 if( sqliterc == NULL ){
30231 home_dir = find_home_dir(0);
30232 if( home_dir==0 ){
30233 eputz("-- warning: cannot find home directory;"
30234
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -20627,11 +20627,11 @@
20627 }
20628 case MODE_ScanExp:
20629 case MODE_Explain: {
20630 static const int aExplainWidth[] = {4, 13, 4, 4, 4, 13, 2, 13};
20631 static const int aExplainMap[] = {0, 1, 2, 3, 4, 5, 6, 7 };
20632 static const int aScanExpWidth[] = {4, 15, 6, 13, 4, 4, 4, 13, 2, 13};
20633 static const int aScanExpMap[] = {0, 9, 8, 1, 2, 3, 4, 5, 6, 7 };
20634
20635 const int *aWidth = aExplainWidth;
20636 const int *aMap = aExplainMap;
20637 int nWidth = ArraySize(aExplainWidth);
@@ -21637,11 +21637,17 @@
21637 UNUSED_PARAMETER(pArg);
21638 #else
21639 if( pArg->scanstatsOn==3 ){
21640 const char *zSql =
21641 " SELECT addr, opcode, p1, p2, p3, p4, p5, comment, nexec,"
21642 " format('% 6s (%.2f%%)',"
21643 " CASE WHEN ncycle<100_000 THEN ncycle || ' '"
21644 " WHEN ncycle<100_000_000 THEN (ncycle/1_000) || 'K'"
21645 " WHEN ncycle<100_000_000_000 THEN (ncycle/1_000_000) || 'M'"
21646 " ELSE (ncycle/1000_000_000) || 'G' END,"
21647 " ncycle*100.0/(sum(ncycle) OVER ())"
21648 " ) AS cycles"
21649 " FROM bytecode(?)";
21650
21651 int rc = SQLITE_OK;
21652 sqlite3_stmt *pStmt = 0;
21653 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
@@ -30175,31 +30181,33 @@
30181 }
30182
30183 /*
30184 ** On non-Windows platforms, look for $XDG_CONFIG_HOME.
30185 ** If ${XDG_CONFIG_HOME}/sqlite3/sqliterc is found, return
30186 ** the path to it. If there is no $(XDG_CONFIG_HOME) then
30187 ** look for $(HOME)/.config/sqlite3/sqliterc and if found
30188 ** return that. If none of these are found, return 0.
30189 **
30190 ** The string returned is obtained from sqlite3_malloc() and
30191 ** should be freed by the caller.
30192 */
30193 static char *find_xdg_config(void){
30194 #if defined(_WIN32) || defined(WIN32) || defined(_WIN32_WCE) \
30195 || defined(__RTP__) || defined(_WRS_KERNEL)
30196 return 0;
30197 #else
30198 char *zConfig = 0;
 
30199 const char *zXdgHome;
30200
 
 
 
 
30201 zXdgHome = getenv("XDG_CONFIG_HOME");
30202 if( zXdgHome==0 ){
30203 const char *zHome = getenv("HOME");
30204 if( zHome==0 ) return 0;
30205 zConfig = sqlite3_mprintf("%s/.config/sqlite3/sqliterc", zHome);
30206 }else{
30207 zConfig = sqlite3_mprintf("%s/sqlite3/sqliterc", zXdgHome);
30208 }
 
30209 shell_check_oom(zConfig);
30210 if( access(zConfig,0)!=0 ){
30211 sqlite3_free(zConfig);
30212 zConfig = 0;
30213 }
@@ -30223,11 +30231,11 @@
30231 char *zBuf = 0;
30232 FILE *inSaved = p->in;
30233 int savedLineno = p->lineno;
30234
30235 if( sqliterc == NULL ){
30236 sqliterc = zBuf = find_xdg_config();
30237 }
30238 if( sqliterc == NULL ){
30239 home_dir = find_home_dir(0);
30240 if( home_dir==0 ){
30241 eputz("-- warning: cannot find home directory;"
30242
+119 -222
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** 33a3f327855b427ae6ba0057218d043a1417.
21
+** baa83b460c677c210c7fa3f20314d7e05f30.
2222
*/
2323
#define SQLITE_CORE 1
2424
#define SQLITE_AMALGAMATION 1
2525
#ifndef SQLITE_PRIVATE
2626
# define SQLITE_PRIVATE static
@@ -254,14 +254,17 @@
254254
#endif
255255
256256
/*
257257
** Macro to disable warnings about missing "break" at the end of a "case".
258258
*/
259
-#if GCC_VERSION>=7000000
260
-# define deliberate_fall_through __attribute__((fallthrough));
261
-#else
262
-# define deliberate_fall_through
259
+#if defined(__has_attribute)
260
+# if __has_attribute(fallthrough)
261
+# define deliberate_fall_through __attribute__((fallthrough));
262
+# endif
263
+#endif
264
+#if !defined(deliberate_fall_through)
265
+# define deliberate_fall_through
263266
#endif
264267
265268
/*
266269
** For MinGW, check to see if we can include the header file containing its
267270
** version information, among other things. Normally, this internal MinGW
@@ -459,11 +462,11 @@
459462
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
460463
** [sqlite_version()] and [sqlite_source_id()].
461464
*/
462465
#define SQLITE_VERSION "3.47.0"
463466
#define SQLITE_VERSION_NUMBER 3047000
464
-#define SQLITE_SOURCE_ID "2024-06-11 18:22:48 33a3f327855b427ae6ba0057218d043a1417bc9d780728f47f23acdd836e1686"
467
+#define SQLITE_SOURCE_ID "2024-07-03 20:19:33 baa83b460c677c210c7fa3f20314d7e05f305aed8a69026bc5fa106a3de4ea38"
465468
466469
/*
467470
** CAPI3REF: Run-Time Library Version Numbers
468471
** KEYWORDS: sqlite3_version sqlite3_sourceid
469472
**
@@ -1083,12 +1086,12 @@
10831086
** xUnlock() downgrades the database file lock to either SHARED or NONE.
10841087
** If the lock is already at or below the requested lock state, then the call
10851088
** to xUnlock() is a no-op.
10861089
** The xCheckReservedLock() method checks whether any database connection,
10871090
** either in this process or in some other process, is holding a RESERVED,
1088
-** PENDING, or EXCLUSIVE lock on the file. It returns true
1089
-** if such a lock exists and false otherwise.
1091
+** PENDING, or EXCLUSIVE lock on the file. It returns, via its output
1092
+** pointer parameter, true if such a lock exists and false otherwise.
10901093
**
10911094
** The xFileControl() method is a generic interface that allows custom
10921095
** VFS implementations to directly control an open file using the
10931096
** [sqlite3_file_control()] interface. The second "op" argument is an
10941097
** integer opcode. The third argument is a generic pointer intended to
@@ -13345,10 +13348,14 @@
1334513348
** "detail=none" or "detail=column" option. If the FTS5 table is created
1334613349
** with either "detail=none" or "detail=column" and "content=" option
1334713350
** (i.e. if it is a contentless table), then this API always iterates
1334813351
** through an empty set (all calls to xPhraseFirst() set iCol to -1).
1334913352
**
13353
+** In all cases, matches are visited in (column ASC, offset ASC) order.
13354
+** i.e. all those in column 0, sorted by offset, followed by those in
13355
+** column 1, etc.
13356
+**
1335013357
** xPhraseNext()
1335113358
** See xPhraseFirst above.
1335213359
**
1335313360
** xPhraseFirstColumn()
1335413361
** This function and xPhraseNextColumn() are similar to the xPhraseFirst()
@@ -15167,11 +15174,10 @@
1516715174
** 0x00008000 After all FROM-clause analysis
1516815175
** 0x00010000 Beginning of DELETE/INSERT/UPDATE processing
1516915176
** 0x00020000 Transform DISTINCT into GROUP BY
1517015177
** 0x00040000 SELECT tree dump after all code has been generated
1517115178
** 0x00080000 NOT NULL strength reduction
15172
-** 0x00100000 EXISTS-to-JOIN optimization
1517315179
*/
1517415180
1517515181
/*
1517615182
** Macros for "wheretrace"
1517715183
*/
@@ -17894,11 +17900,10 @@
1789417900
/* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
1789517901
#define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
1789617902
#define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
1789717903
#define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
1789817904
#define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
17899
-#define SQLITE_ExistsToJoin 0x10000000 /* The EXISTS-to-JOIN optimization */
1790017905
#define SQLITE_AllOpts 0xffffffff /* All optimizations */
1790117906
1790217907
/*
1790317908
** Macros for testing whether or not optimizations are enabled or disabled.
1790417909
*/
@@ -19590,11 +19595,15 @@
1959019595
** of the query. This destination implies "LIMIT 1".
1959119596
**
1959219597
** SRT_Set The result must be a single column. Store each
1959319598
** row of result as the key in table pDest->iSDParm.
1959419599
** Apply the affinity pDest->affSdst before storing
19595
-** results. Used to implement "IN (SELECT ...)".
19600
+** results. if pDest->iSDParm2 is positive, then it is
19601
+** a regsiter holding a Bloom filter for the IN operator
19602
+** that should be populated in addition to the
19603
+** pDest->iSDParm table. This SRT is used to
19604
+** implement "IN (SELECT ...)".
1959619605
**
1959719606
** SRT_EphemTab Create an temporary table pDest->iSDParm and store
1959819607
** the result there. The cursor is left open after
1959919608
** returning. This is like SRT_Table except that
1960019609
** this destination uses OP_OpenEphemeral to create
@@ -19798,11 +19807,10 @@
1979819807
u8 okConstFactor; /* OK to factor out constants */
1979919808
u8 disableLookaside; /* Number of times lookaside has been disabled */
1980019809
u8 prepFlags; /* SQLITE_PREPARE_* flags */
1980119810
u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
1980219811
u8 bHasWith; /* True if statement contains WITH */
19803
- u8 bHasExists; /* Has a correlated "EXISTS (SELECT ....)" expression */
1980419812
#if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
1980519813
u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
1980619814
#endif
1980719815
#ifdef SQLITE_DEBUG
1980819816
u8 ifNotExists; /* Might be true if IF NOT EXISTS. Assert()s only */
@@ -20094,11 +20102,11 @@
2009420102
int iRetReg; /* Register array for holding a row of RETURNING */
2009520103
char zName[40]; /* Name of trigger: "sqlite_returning_%p" */
2009620104
};
2009720105
2009820106
/*
20099
-** An objected used to accumulate the text of a string where we
20107
+** An object used to accumulate the text of a string where we
2010020108
** do not necessarily know how big the string will be in the end.
2010120109
*/
2010220110
struct sqlite3_str {
2010320111
sqlite3 *db; /* Optional database for lookaside. Can be NULL */
2010420112
char *zText; /* The string collected so far */
@@ -20108,11 +20116,11 @@
2010820116
u8 accError; /* SQLITE_NOMEM or SQLITE_TOOBIG */
2010920117
u8 printfFlags; /* SQLITE_PRINTF flags below */
2011020118
};
2011120119
#define SQLITE_PRINTF_INTERNAL 0x01 /* Internal-use-only converters allowed */
2011220120
#define SQLITE_PRINTF_SQLFUNC 0x02 /* SQL function arguments to VXPrintf */
20113
-#define SQLITE_PRINTF_MALLOCED 0x04 /* True if xText is allocated space */
20121
+#define SQLITE_PRINTF_MALLOCED 0x04 /* True if zText is allocated space */
2011420122
2011520123
#define isMalloced(X) (((X)->printfFlags & SQLITE_PRINTF_MALLOCED)!=0)
2011620124
2011720125
/*
2011820126
** The following object is the header for an "RCStr" or "reference-counted
@@ -33485,13 +33493,14 @@
3348533493
}else{
3348633494
int i;
3348733495
sqlite3TreeViewLine(pView, "%s", zLabel);
3348833496
for(i=0; i<pList->nExpr; i++){
3348933497
int j = pList->a[i].u.x.iOrderByCol;
33498
+ u8 sortFlags = pList->a[i].fg.sortFlags;
3349033499
char *zName = pList->a[i].zEName;
3349133500
int moreToFollow = i<pList->nExpr - 1;
33492
- if( j || zName ){
33501
+ if( j || zName || sortFlags ){
3349333502
sqlite3TreeViewPush(&pView, moreToFollow);
3349433503
moreToFollow = 0;
3349533504
sqlite3TreeViewLine(pView, 0);
3349633505
if( zName ){
3349733506
switch( pList->a[i].fg.eEName ){
@@ -33508,17 +33517,22 @@
3350833517
fprintf(stdout, "SPAN(\"%s\") ", zName);
3350933518
break;
3351033519
}
3351133520
}
3351233521
if( j ){
33513
- fprintf(stdout, "iOrderByCol=%d", j);
33522
+ fprintf(stdout, "iOrderByCol=%d ", j);
33523
+ }
33524
+ if( sortFlags & KEYINFO_ORDER_DESC ){
33525
+ fprintf(stdout, "DESC ");
33526
+ }else if( sortFlags & KEYINFO_ORDER_BIGNULL ){
33527
+ fprintf(stdout, "NULLS-LAST");
3351433528
}
3351533529
fprintf(stdout, "\n");
3351633530
fflush(stdout);
3351733531
}
3351833532
sqlite3TreeViewExpr(pView, pList->a[i].pExpr, moreToFollow);
33519
- if( j || zName ){
33533
+ if( j || zName || sortFlags ){
3352033534
sqlite3TreeViewPop(&pView);
3352133535
}
3352233536
}
3352333537
}
3352433538
}
@@ -40643,30 +40657,26 @@
4064340657
*/
4064440658
#define DOTLOCK_SUFFIX ".lock"
4064540659
4064640660
/*
4064740661
** This routine checks if there is a RESERVED lock held on the specified
40648
-** file by this or any other process. If such a lock is held, set *pResOut
40649
-** to a non-zero value otherwise *pResOut is set to zero. The return value
40650
-** is set to SQLITE_OK unless an I/O error occurs during lock checking.
40651
-**
40652
-** In dotfile locking, either a lock exists or it does not. So in this
40653
-** variation of CheckReservedLock(), *pResOut is set to true if any lock
40654
-** is held on the file and false if the file is unlocked.
40662
+** file by this or any other process. If the caller holds a SHARED
40663
+** or greater lock when it is called, then it is assumed that no other
40664
+** client may hold RESERVED. Or, if the caller holds no lock, then it
40665
+** is assumed another client holds RESERVED if the lock-file exists.
4065540666
*/
4065640667
static int dotlockCheckReservedLock(sqlite3_file *id, int *pResOut) {
40657
- int rc = SQLITE_OK;
40658
- int reserved = 0;
4065940668
unixFile *pFile = (unixFile*)id;
40660
-
4066140669
SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
4066240670
40663
- assert( pFile );
40664
- reserved = osAccess((const char*)pFile->lockingContext, 0)==0;
40665
- OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, rc, reserved));
40666
- *pResOut = reserved;
40667
- return rc;
40671
+ if( pFile->eFileLock>=SHARED_LOCK ){
40672
+ *pResOut = 0;
40673
+ }else{
40674
+ *pResOut = osAccess((const char*)pFile->lockingContext, 0)==0;
40675
+ }
40676
+ OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, 0, *pResOut));
40677
+ return SQLITE_OK;
4066840678
}
4066940679
4067040680
/*
4067140681
** Lock the file with the lock specified by parameter eFileLock - one
4067240682
** of the following:
@@ -98433,10 +98443,11 @@
9843398443
if( r.nField>0 ){
9843498444
/* Key values in an array of registers */
9843598445
r.pKeyInfo = pC->pKeyInfo;
9843698446
r.default_rc = 0;
9843798447
#ifdef SQLITE_DEBUG
98448
+ (void)sqlite3FaultSim(50); /* For use by --counter in TH3 */
9843898449
for(ii=0; ii<r.nField; ii++){
9843998450
assert( memIsValid(&r.aMem[ii]) );
9844098451
assert( (r.aMem[ii].flags & MEM_Zero)==0 || r.aMem[ii].n==0 );
9844198452
if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
9844298453
}
@@ -108130,11 +108141,10 @@
108130108141
}
108131108142
assert( pNC->nRef>=nRef );
108132108143
if( nRef!=pNC->nRef ){
108133108144
ExprSetProperty(pExpr, EP_VarSelect);
108134108145
pExpr->x.pSelect->selFlags |= SF_Correlated;
108135
- if( pExpr->op==TK_EXISTS ) pParse->bHasExists = 1;
108136108146
}
108137108147
pNC->ncFlags |= NC_Subquery;
108138108148
}
108139108149
break;
108140108150
}
@@ -109133,11 +109143,13 @@
109133109143
|| (pExpr->op==TK_REGISTER && pExpr->op2==TK_IF_NULL_ROW) );
109134109144
pExpr = pExpr->pLeft;
109135109145
op = pExpr->op;
109136109146
continue;
109137109147
}
109138
- if( op!=TK_REGISTER || (op = pExpr->op2)==TK_REGISTER ) break;
109148
+ if( op!=TK_REGISTER ) break;
109149
+ op = pExpr->op2;
109150
+ if( NEVER( op==TK_REGISTER ) ) break;
109139109151
}
109140109152
return pExpr->affExpr;
109141109153
}
109142109154
109143109155
/*
@@ -112582,19 +112594,34 @@
112582112594
if( ALWAYS(pEList->nExpr==nVal) ){
112583112595
Select *pCopy;
112584112596
SelectDest dest;
112585112597
int i;
112586112598
int rc;
112599
+ int addrBloom = 0;
112587112600
sqlite3SelectDestInit(&dest, SRT_Set, iTab);
112588112601
dest.zAffSdst = exprINAffinity(pParse, pExpr);
112589112602
pSelect->iLimit = 0;
112603
+ if( addrOnce && OptimizationEnabled(pParse->db, SQLITE_BloomFilter) ){
112604
+ int regBloom = ++pParse->nMem;
112605
+ addrBloom = sqlite3VdbeAddOp2(v, OP_Blob, 10000, regBloom);
112606
+ VdbeComment((v, "Bloom filter"));
112607
+ dest.iSDParm2 = regBloom;
112608
+ }
112590112609
testcase( pSelect->selFlags & SF_Distinct );
112591112610
testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
112592112611
pCopy = sqlite3SelectDup(pParse->db, pSelect, 0);
112593112612
rc = pParse->db->mallocFailed ? 1 :sqlite3Select(pParse, pCopy, &dest);
112594112613
sqlite3SelectDelete(pParse->db, pCopy);
112595112614
sqlite3DbFree(pParse->db, dest.zAffSdst);
112615
+ if( addrBloom ){
112616
+ sqlite3VdbeGetOp(v, addrOnce)->p3 = dest.iSDParm2;
112617
+ if( dest.iSDParm2==0 ){
112618
+ sqlite3VdbeChangeToNoop(v, addrBloom);
112619
+ }else{
112620
+ sqlite3VdbeGetOp(v, addrOnce)->p3 = dest.iSDParm2;
112621
+ }
112622
+ }
112596112623
if( rc ){
112597112624
sqlite3KeyInfoUnref(pKeyInfo);
112598112625
return;
112599112626
}
112600112627
assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
@@ -113033,10 +113060,19 @@
113033113060
addrTruthOp = sqlite3VdbeAddOp0(v, OP_Goto); /* Return True */
113034113061
}else{
113035113062
sqlite3VdbeAddOp4(v, OP_Affinity, rLhs, nVector, 0, zAff, nVector);
113036113063
if( destIfFalse==destIfNull ){
113037113064
/* Combine Step 3 and Step 5 into a single opcode */
113065
+ if( ExprHasProperty(pExpr, EP_Subrtn) ){
113066
+ const VdbeOp *pOp = sqlite3VdbeGetOp(v, pExpr->y.sub.iAddr);
113067
+ assert( pOp->opcode==OP_Once || pParse->nErr );
113068
+ if( pOp->opcode==OP_Once && pOp->p3>0 ){
113069
+ assert( OptimizationEnabled(pParse->db, SQLITE_BloomFilter) );
113070
+ sqlite3VdbeAddOp4Int(v, OP_Filter, pOp->p3, destIfFalse,
113071
+ rLhs, nVector); VdbeCoverage(v);
113072
+ }
113073
+ }
113038113074
sqlite3VdbeAddOp4Int(v, OP_NotFound, iTab, destIfFalse,
113039113075
rLhs, nVector); VdbeCoverage(v);
113040113076
goto sqlite3ExprCodeIN_finished;
113041113077
}
113042113078
/* Ordinary Step 3, for the case where FALSE and NULL are distinct */
@@ -113318,14 +113354,18 @@
113318113354
** the correct value for the expression.
113319113355
*/
113320113356
SQLITE_PRIVATE void sqlite3ExprToRegister(Expr *pExpr, int iReg){
113321113357
Expr *p = sqlite3ExprSkipCollateAndLikely(pExpr);
113322113358
if( NEVER(p==0) ) return;
113323
- p->op2 = p->op;
113324
- p->op = TK_REGISTER;
113325
- p->iTable = iReg;
113326
- ExprClearProperty(p, EP_Skip);
113359
+ if( p->op==TK_REGISTER ){
113360
+ assert( p->iTable==iReg );
113361
+ }else{
113362
+ p->op2 = p->op;
113363
+ p->op = TK_REGISTER;
113364
+ p->iTable = iReg;
113365
+ ExprClearProperty(p, EP_Skip);
113366
+ }
113327113367
}
113328113368
113329113369
/*
113330113370
** Evaluate an expression (either a vector or a scalar expression) and store
113331113371
** the result in contiguous temporary registers. Return the index of
@@ -126476,21 +126516,18 @@
126476126516
** Append the contents of SrcList p2 to SrcList p1 and return the resulting
126477126517
** SrcList. Or, if an error occurs, return NULL. In all cases, p1 and p2
126478126518
** are deleted by this function.
126479126519
*/
126480126520
SQLITE_PRIVATE SrcList *sqlite3SrcListAppendList(Parse *pParse, SrcList *p1, SrcList *p2){
126481
- assert( p1 );
126521
+ assert( p1 && p1->nSrc==1 );
126482126522
if( p2 ){
126483
- int nOld = p1->nSrc;
126484
- SrcList *pNew = sqlite3SrcListEnlarge(pParse, p1, p2->nSrc, nOld);
126523
+ SrcList *pNew = sqlite3SrcListEnlarge(pParse, p1, p2->nSrc, 1);
126485126524
if( pNew==0 ){
126486126525
sqlite3SrcListDelete(pParse->db, p2);
126487126526
}else{
126488126527
p1 = pNew;
126489
- memcpy(&p1->a[nOld], p2->a, p2->nSrc*sizeof(SrcItem));
126490
- assert( nOld==1 || (p2->nSrc==1 && (p2->a[0].fg.jointype&JT_LTORJ)==0) );
126491
- assert( p1->nSrc>=2 );
126528
+ memcpy(&p1->a[1], p2->a, p2->nSrc*sizeof(SrcItem));
126492126529
sqlite3DbFree(pParse->db, p2);
126493126530
p1->a[0].fg.jointype |= (JT_LTORJ & p1->a[1].fg.jointype);
126494126531
}
126495126532
}
126496126533
return p1;
@@ -144332,16 +144369,22 @@
144332144369
** ORDER BY in this case since the order of entries in the set
144333144370
** does not matter. But there might be a LIMIT clause, in which
144334144371
** case the order does matter */
144335144372
pushOntoSorter(
144336144373
pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg);
144374
+ pDest->iSDParm2 = 0; /* Signal that any Bloom filter is unpopulated */
144337144375
}else{
144338144376
int r1 = sqlite3GetTempReg(pParse);
144339144377
assert( sqlite3Strlen30(pDest->zAffSdst)==nResultCol );
144340144378
sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult, nResultCol,
144341144379
r1, pDest->zAffSdst, nResultCol);
144342144380
sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, nResultCol);
144381
+ if( pDest->iSDParm2 ){
144382
+ sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pDest->iSDParm2, 0,
144383
+ regResult, nResultCol);
144384
+ ExplainQueryPlan((pParse, 0, "CREATE BLOOM FILTER"));
144385
+ }
144343144386
sqlite3ReleaseTempReg(pParse, r1);
144344144387
}
144345144388
break;
144346144389
}
144347144390
@@ -146271,10 +146314,15 @@
146271146314
r1 = sqlite3GetTempReg(pParse);
146272146315
sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, pIn->nSdst,
146273146316
r1, pDest->zAffSdst, pIn->nSdst);
146274146317
sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pDest->iSDParm, r1,
146275146318
pIn->iSdst, pIn->nSdst);
146319
+ if( pDest->iSDParm2>0 ){
146320
+ sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pDest->iSDParm2, 0,
146321
+ pIn->iSdst, pIn->nSdst);
146322
+ ExplainQueryPlan((pParse, 0, "CREATE BLOOM FILTER"));
146323
+ }
146276146324
sqlite3ReleaseTempReg(pParse, r1);
146277146325
break;
146278146326
}
146279146327
146280146328
/* If this is a scalar select that is part of an expression, then
@@ -150238,162 +150286,10 @@
150238150286
if( pItem->pSelect!=0 ) return 0; /* (1c-i) */
150239150287
}
150240150288
return 1;
150241150289
}
150242150290
150243
-/*
150244
-** sqlite3WalkExpr() callback used by exprReferencesTable().
150245
-*/
150246
-static int exprReferencesTableExprCb(Walker *pWalker, Expr *pExpr){
150247
- if( pExpr->op==TK_COLUMN && pExpr->iTable==pWalker->u.iCur ){
150248
- pWalker->eCode = 1;
150249
- }
150250
- return WRC_Continue;
150251
-}
150252
-
150253
-/*
150254
-** Return true if the expression passed as the first argument refers
150255
-** to cursor number iCur. Otherwise return false.
150256
-*/
150257
-static int exprReferencesTable(Expr *pExpr, int iCur){
150258
- Walker w;
150259
- memset(&w, 0, sizeof(w));
150260
- w.u.iCur = iCur;
150261
- w.xExprCallback = exprReferencesTableExprCb;
150262
- w.xSelectCallback = sqlite3SelectWalkNoop;
150263
- sqlite3WalkExpr(&w, pExpr);
150264
- return w.eCode;
150265
-}
150266
-
150267
-/*
150268
-** Index pIdx is a UNIQUE index on the table accessed by cursor number
150269
-** iCsr. This function returns a mask of the index columns that are
150270
-** constrained to match a single, non-NULL value by the WHERE clause
150271
-** passed as the 4th argument. For example, if the index is:
150272
-**
150273
-** CREATE UNIQUE INDEX idx ON tbl(a, b, c);
150274
-**
150275
-** and pWhere:
150276
-**
150277
-** WHERE a=? AND c=?
150278
-**
150279
-** then this function returns 5.
150280
-*/
150281
-static u64 findConstIdxTerms(
150282
- Parse *pParse,
150283
- int iCsr,
150284
- Index *pIdx,
150285
- Expr *pWhere
150286
-){
150287
- u64 m = 0;
150288
- if( pWhere->op==TK_AND ){
150289
- m = findConstIdxTerms(pParse, iCsr, pIdx, pWhere->pLeft);
150290
- m |= findConstIdxTerms(pParse, iCsr, pIdx, pWhere->pRight);
150291
- }else if( pWhere->op==TK_EQ ){
150292
- Expr *pLeft = sqlite3ExprSkipCollateAndLikely(pWhere->pLeft);
150293
- Expr *pRight = sqlite3ExprSkipCollateAndLikely(pWhere->pRight);
150294
- if( pRight->op==TK_COLUMN && pRight->iTable==iCsr ){
150295
- SWAP(Expr*, pLeft, pRight);
150296
- }
150297
- if( pLeft->op==TK_COLUMN
150298
- && pLeft->iTable==iCsr
150299
- && exprReferencesTable(pRight, iCsr)==0
150300
- ){
150301
- if( pIdx ){
150302
- int ii;
150303
- for(ii=0; ii<pIdx->nKeyCol; ii++){
150304
- assert( pIdx->azColl[ii] );
150305
- if( pLeft->iColumn==pIdx->aiColumn[ii] ){
150306
- CollSeq *pColl = sqlite3ExprCompareCollSeq(pParse, pWhere);
150307
- if( pColl && sqlite3StrICmp(pColl->zName, pIdx->azColl[ii])==0 ){
150308
- m |= ((u64)1 << ii);
150309
- break;
150310
- }
150311
- }
150312
- }
150313
- }else{
150314
- if( pLeft->iColumn<0 ) m = 1;
150315
- }
150316
- }
150317
- }
150318
- return m;
150319
-}
150320
-
150321
-/*
150322
-** Argument pWhere is the WHERE clause belonging to SELECT statement p. This
150323
-** function attempts to transform expressions of the form:
150324
-**
150325
-** EXISTS (SELECT ...)
150326
-**
150327
-** into joins. For example, given
150328
-**
150329
-** CREATE TABLE sailors(sid INTEGER PRIMARY KEY, name TEXT);
150330
-** CREATE TABLE reserves(sid INT, day DATE, PRIMARY KEY(sid, day));
150331
-**
150332
-** SELECT name FROM sailors AS S WHERE EXISTS (
150333
-** SELECT * FROM reserves AS R WHERE S.sid = R.sid AND R.day = '2022-10-25'
150334
-** );
150335
-**
150336
-** the SELECT statement may be transformed as follows:
150337
-**
150338
-** SELECT name FROM sailors AS S, reserves AS R
150339
-** WHERE S.sid = R.sid AND R.day = '2022-10-25';
150340
-*/
150341
-static void existsToJoin(Parse *pParse, Select *p, Expr *pWhere){
150342
- if( pWhere && p->pSrc->nSrc>0 && pParse->db->mallocFailed==0 ){
150343
- if( pWhere->op==TK_AND ){
150344
- Expr *pRight = pWhere->pRight;
150345
- existsToJoin(pParse, p, pWhere->pLeft);
150346
- existsToJoin(pParse, p, pRight);
150347
- }
150348
- else if( pWhere->op==TK_EXISTS ){
150349
- Select *pSub = pWhere->x.pSelect;
150350
- if( pSub->pSrc->nSrc==1
150351
- && (pSub->selFlags & (SF_Aggregate|SF_Correlated))==SF_Correlated
150352
- && pSub->pWhere
150353
- ){
150354
- int bTransform = 0; /* True if EXISTS can be made into join */
150355
- Table *pTab = pSub->pSrc->a[0].pTab;
150356
- int iCsr = pSub->pSrc->a[0].iCursor;
150357
- Index *pIdx;
150358
- if( HasRowid(pTab) && findConstIdxTerms(pParse, iCsr, 0,pSub->pWhere) ){
150359
- bTransform = 1;
150360
- }
150361
- for(pIdx=pTab->pIndex; pIdx && bTransform==0; pIdx=pIdx->pNext){
150362
- if( pIdx->onError && pIdx->nKeyCol<=63 ){
150363
- u64 c = findConstIdxTerms(pParse, iCsr, pIdx, pSub->pWhere);
150364
- if( c==((u64)1 << pIdx->nKeyCol)-1 ){
150365
- bTransform = 1;
150366
- }
150367
- }
150368
- }
150369
- if( bTransform ){
150370
- memset(pWhere, 0, sizeof(*pWhere));
150371
- pWhere->op = TK_INTEGER;
150372
- pWhere->u.iValue = 1;
150373
- ExprSetProperty(pWhere, EP_IntValue);
150374
-
150375
- assert( p->pWhere!=0 );
150376
- p->pSrc = sqlite3SrcListAppendList(pParse, p->pSrc, pSub->pSrc);
150377
- p->pWhere = sqlite3PExpr(pParse, TK_AND, p->pWhere, pSub->pWhere);
150378
-
150379
- pSub->pWhere = 0;
150380
- pSub->pSrc = 0;
150381
- sqlite3ParserAddCleanup(pParse, sqlite3SelectDeleteGeneric, pSub);
150382
-#if TREETRACE_ENABLED
150383
- if( sqlite3TreeTrace & 0x100000 ){
150384
- TREETRACE(0x100000,pParse,p,
150385
- ("After EXISTS-to-JOIN optimization:\n"));
150386
- sqlite3TreeViewSelect(0, p, 0);
150387
- }
150388
-#endif
150389
- }
150390
- }
150391
- }
150392
- }
150393
-}
150394
-
150395150291
/*
150396150292
** Generate code for the SELECT statement given in the p argument.
150397150293
**
150398150294
** The results are returned according to the SelectDest structure.
150399150295
** See comments in sqliteInt.h for further information.
@@ -150642,17 +150538,20 @@
150642150538
** (5) The ORDER BY isn't going to accomplish anything because
150643150539
** one of:
150644150540
** (a) The outer query has a different ORDER BY clause
150645150541
** (b) The subquery is part of a join
150646150542
** See forum post 062d576715d277c8
150543
+ ** (6) The subquery is not a recursive CTE. ORDER BY has a different
150544
+ ** meaning for recursive CTEs and this optimization does not
150545
+ ** apply.
150647150546
**
150648150547
** Also retain the ORDER BY if the OmitOrderBy optimization is disabled.
150649150548
*/
150650150549
if( pSub->pOrderBy!=0
150651150550
&& (p->pOrderBy!=0 || pTabList->nSrc>1) /* Condition (5) */
150652150551
&& pSub->pLimit==0 /* Condition (1) */
150653
- && (pSub->selFlags & SF_OrderByReqd)==0 /* Condition (2) */
150552
+ && (pSub->selFlags & (SF_OrderByReqd|SF_Recursive))==0 /* (2) and (6) */
150654150553
&& (p->selFlags & SF_OrderByReqd)==0 /* Condition (3) and (4) */
150655150554
&& OptimizationEnabled(db, SQLITE_OmitOrderBy)
150656150555
){
150657150556
TREETRACE(0x800,pParse,p,
150658150557
("omit superfluous ORDER BY on %r FROM-clause subquery\n",i+1));
@@ -150716,17 +150615,10 @@
150716150615
if( p->pNext==0 ) ExplainQueryPlanPop(pParse);
150717150616
return rc;
150718150617
}
150719150618
#endif
150720150619
150721
- /* If there may be an "EXISTS (SELECT ...)" in the WHERE clause, attempt
150722
- ** to change it into a join. */
150723
- if( pParse->bHasExists && OptimizationEnabled(db,SQLITE_ExistsToJoin) ){
150724
- existsToJoin(pParse, p, p->pWhere);
150725
- pTabList = p->pSrc;
150726
- }
150727
-
150728150620
/* Do the WHERE-clause constant propagation optimization if this is
150729150621
** a join. No need to speed time on this operation for non-join queries
150730150622
** as the equivalent optimization will be handled by query planner in
150731150623
** sqlite3WhereBegin().
150732150624
*/
@@ -151447,11 +151339,14 @@
151447151339
}
151448151340
151449151341
if( iOrderByCol ){
151450151342
Expr *pX = p->pEList->a[iOrderByCol-1].pExpr;
151451151343
Expr *pBase = sqlite3ExprSkipCollateAndLikely(pX);
151452
- if( ALWAYS(pBase!=0) && pBase->op!=TK_AGG_COLUMN ){
151344
+ if( ALWAYS(pBase!=0)
151345
+ && pBase->op!=TK_AGG_COLUMN
151346
+ && pBase->op!=TK_REGISTER
151347
+ ){
151453151348
sqlite3ExprToRegister(pX, iAMem+j);
151454151349
}
151455151350
}
151456151351
}
151457151352
sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
@@ -167412,11 +167307,11 @@
167412167307
nColumn = pIndex->nColumn;
167413167308
assert( nColumn==nKeyCol+1 || !HasRowid(pIndex->pTable) );
167414167309
assert( pIndex->aiColumn[nColumn-1]==XN_ROWID
167415167310
|| !HasRowid(pIndex->pTable));
167416167311
/* All relevant terms of the index must also be non-NULL in order
167417
- ** for isOrderDistinct to be true. So the isOrderDistint value
167312
+ ** for isOrderDistinct to be true. So the isOrderDistinct value
167418167313
** computed here might be a false positive. Corrections will be
167419167314
** made at tag-20210426-1 below */
167420167315
isOrderDistinct = IsUniqueIndex(pIndex)
167421167316
&& (pLoop->wsFlags & WHERE_SKIPSCAN)==0;
167422167317
}
@@ -232187,10 +232082,14 @@
232187232082
** "detail=none" or "detail=column" option. If the FTS5 table is created
232188232083
** with either "detail=none" or "detail=column" and "content=" option
232189232084
** (i.e. if it is a contentless table), then this API always iterates
232190232085
** through an empty set (all calls to xPhraseFirst() set iCol to -1).
232191232086
**
232087
+** In all cases, matches are visited in (column ASC, offset ASC) order.
232088
+** i.e. all those in column 0, sorted by offset, followed by those in
232089
+** column 1, etc.
232090
+**
232192232091
** xPhraseNext()
232193232092
** See xPhraseFirst above.
232194232093
**
232195232094
** xPhraseFirstColumn()
232196232095
** This function and xPhraseNextColumn() are similar to the xPhraseFirst()
@@ -239066,10 +238965,11 @@
239066238965
** no token characters at all. (e.g ... MATCH '""'). */
239067238966
sCtx.pPhrase = sqlite3Fts5MallocZero(&pParse->rc, sizeof(Fts5ExprPhrase));
239068238967
}else if( sCtx.pPhrase->nTerm ){
239069238968
sCtx.pPhrase->aTerm[sCtx.pPhrase->nTerm-1].bPrefix = (u8)bPrefix;
239070238969
}
238970
+ assert( pParse->apPhrase!=0 );
239071238971
pParse->apPhrase[pParse->nPhrase-1] = sCtx.pPhrase;
239072238972
}
239073238973
239074238974
return sCtx.pPhrase;
239075238975
}
@@ -239085,11 +238985,11 @@
239085238985
){
239086238986
int rc = SQLITE_OK; /* Return code */
239087238987
Fts5ExprPhrase *pOrig = 0; /* The phrase extracted from pExpr */
239088238988
Fts5Expr *pNew = 0; /* Expression to return via *ppNew */
239089238989
TokenCtx sCtx = {0,0,0}; /* Context object for fts5ParseTokenize */
239090
- if( iPhrase<0 || iPhrase>=pExpr->nPhrase ){
238990
+ if( !pExpr || iPhrase<0 || iPhrase>=pExpr->nPhrase ){
239091238991
rc = SQLITE_RANGE;
239092238992
}else{
239093238993
pOrig = pExpr->apExprPhrase[iPhrase];
239094238994
pNew = (Fts5Expr*)sqlite3Fts5MallocZero(&rc, sizeof(Fts5Expr));
239095238995
}
@@ -239660,10 +239560,12 @@
239660239560
|| pPrev->eType==FTS5_TERM
239661239561
|| pPrev->eType==FTS5_EOF
239662239562
);
239663239563
239664239564
if( pRight->eType==FTS5_EOF ){
239565
+ assert( pParse->apPhrase!=0 );
239566
+ assert( pParse->nPhrase>0 );
239665239567
assert( pParse->apPhrase[pParse->nPhrase-1]==pRight->pNear->apPhrase[0] );
239666239568
sqlite3Fts5ParseNodeFree(pRight);
239667239569
pRet = pLeft;
239668239570
pParse->nPhrase--;
239669239571
}
@@ -251077,10 +250979,11 @@
251077250979
"%s", sqlite3_errmsg(pConfig->db)
251078250980
);
251079250981
}
251080250982
}else{
251081250983
rc = SQLITE_OK;
250984
+ CsrFlagSet(pCsr, FTS5CSR_REQUIRE_DOCSIZE);
251082250985
}
251083250986
break;
251084250987
}
251085250988
}
251086250989
}
@@ -251550,13 +251453,17 @@
251550251453
*/
251551251454
static i64 fts5CursorRowid(Fts5Cursor *pCsr){
251552251455
assert( pCsr->ePlan==FTS5_PLAN_MATCH
251553251456
|| pCsr->ePlan==FTS5_PLAN_SORTED_MATCH
251554251457
|| pCsr->ePlan==FTS5_PLAN_SOURCE
251458
+ || pCsr->ePlan==FTS5_PLAN_SCAN
251459
+ || pCsr->ePlan==FTS5_PLAN_ROWID
251555251460
);
251556251461
if( pCsr->pSorter ){
251557251462
return pCsr->pSorter->iRowid;
251463
+ }else if( pCsr->ePlan>=FTS5_PLAN_SCAN ){
251464
+ return sqlite3_column_int64(pCsr->pStmt, 0);
251558251465
}else{
251559251466
return sqlite3Fts5ExprRowid(pCsr->pExpr);
251560251467
}
251561251468
}
251562251469
@@ -251569,24 +251476,14 @@
251569251476
static int fts5RowidMethod(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
251570251477
Fts5Cursor *pCsr = (Fts5Cursor*)pCursor;
251571251478
int ePlan = pCsr->ePlan;
251572251479
251573251480
assert( CsrFlagTest(pCsr, FTS5CSR_EOF)==0 );
251574
- switch( ePlan ){
251575
- case FTS5_PLAN_SPECIAL:
251576
- *pRowid = 0;
251577
- break;
251578
-
251579
- case FTS5_PLAN_SOURCE:
251580
- case FTS5_PLAN_MATCH:
251581
- case FTS5_PLAN_SORTED_MATCH:
251582
- *pRowid = fts5CursorRowid(pCsr);
251583
- break;
251584
-
251585
- default:
251586
- *pRowid = sqlite3_column_int64(pCsr->pStmt, 0);
251587
- break;
251481
+ if( ePlan==FTS5_PLAN_SPECIAL ){
251482
+ *pRowid = 0;
251483
+ }else{
251484
+ *pRowid = fts5CursorRowid(pCsr);
251588251485
}
251589251486
251590251487
return SQLITE_OK;
251591251488
}
251592251489
@@ -253071,11 +252968,11 @@
253071252968
int nArg, /* Number of args */
253072252969
sqlite3_value **apUnused /* Function arguments */
253073252970
){
253074252971
assert( nArg==0 );
253075252972
UNUSED_PARAM2(nArg, apUnused);
253076
- sqlite3_result_text(pCtx, "fts5: 2024-06-11 17:37:36 5f25a9518a675efbd0525cc2f5595ee7bc7122be7cfecdf6b20c909185dea370", -1, SQLITE_TRANSIENT);
252973
+ sqlite3_result_text(pCtx, "fts5: 2024-07-03 20:19:33 baa83b460c677c210c7fa3f20314d7e05f305aed8a69026bc5fa106a3de4ea38", -1, SQLITE_TRANSIENT);
253077252974
}
253078252975
253079252976
/*
253080252977
** Return true if zName is the extension on one of the shadow tables used
253081252978
** by this module.
253082252979
--- 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 ** 33a3f327855b427ae6ba0057218d043a1417.
22 */
23 #define SQLITE_CORE 1
24 #define SQLITE_AMALGAMATION 1
25 #ifndef SQLITE_PRIVATE
26 # define SQLITE_PRIVATE static
@@ -254,14 +254,17 @@
254 #endif
255
256 /*
257 ** Macro to disable warnings about missing "break" at the end of a "case".
258 */
259 #if GCC_VERSION>=7000000
260 # define deliberate_fall_through __attribute__((fallthrough));
261 #else
262 # define deliberate_fall_through
 
 
 
263 #endif
264
265 /*
266 ** For MinGW, check to see if we can include the header file containing its
267 ** version information, among other things. Normally, this internal MinGW
@@ -459,11 +462,11 @@
459 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
460 ** [sqlite_version()] and [sqlite_source_id()].
461 */
462 #define SQLITE_VERSION "3.47.0"
463 #define SQLITE_VERSION_NUMBER 3047000
464 #define SQLITE_SOURCE_ID "2024-06-11 18:22:48 33a3f327855b427ae6ba0057218d043a1417bc9d780728f47f23acdd836e1686"
465
466 /*
467 ** CAPI3REF: Run-Time Library Version Numbers
468 ** KEYWORDS: sqlite3_version sqlite3_sourceid
469 **
@@ -1083,12 +1086,12 @@
1083 ** xUnlock() downgrades the database file lock to either SHARED or NONE.
1084 ** If the lock is already at or below the requested lock state, then the call
1085 ** to xUnlock() is a no-op.
1086 ** The xCheckReservedLock() method checks whether any database connection,
1087 ** either in this process or in some other process, is holding a RESERVED,
1088 ** PENDING, or EXCLUSIVE lock on the file. It returns true
1089 ** if such a lock exists and false otherwise.
1090 **
1091 ** The xFileControl() method is a generic interface that allows custom
1092 ** VFS implementations to directly control an open file using the
1093 ** [sqlite3_file_control()] interface. The second "op" argument is an
1094 ** integer opcode. The third argument is a generic pointer intended to
@@ -13345,10 +13348,14 @@
13345 ** "detail=none" or "detail=column" option. If the FTS5 table is created
13346 ** with either "detail=none" or "detail=column" and "content=" option
13347 ** (i.e. if it is a contentless table), then this API always iterates
13348 ** through an empty set (all calls to xPhraseFirst() set iCol to -1).
13349 **
 
 
 
 
13350 ** xPhraseNext()
13351 ** See xPhraseFirst above.
13352 **
13353 ** xPhraseFirstColumn()
13354 ** This function and xPhraseNextColumn() are similar to the xPhraseFirst()
@@ -15167,11 +15174,10 @@
15167 ** 0x00008000 After all FROM-clause analysis
15168 ** 0x00010000 Beginning of DELETE/INSERT/UPDATE processing
15169 ** 0x00020000 Transform DISTINCT into GROUP BY
15170 ** 0x00040000 SELECT tree dump after all code has been generated
15171 ** 0x00080000 NOT NULL strength reduction
15172 ** 0x00100000 EXISTS-to-JOIN optimization
15173 */
15174
15175 /*
15176 ** Macros for "wheretrace"
15177 */
@@ -17894,11 +17900,10 @@
17894 /* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
17895 #define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
17896 #define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
17897 #define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
17898 #define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
17899 #define SQLITE_ExistsToJoin 0x10000000 /* The EXISTS-to-JOIN optimization */
17900 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
17901
17902 /*
17903 ** Macros for testing whether or not optimizations are enabled or disabled.
17904 */
@@ -19590,11 +19595,15 @@
19590 ** of the query. This destination implies "LIMIT 1".
19591 **
19592 ** SRT_Set The result must be a single column. Store each
19593 ** row of result as the key in table pDest->iSDParm.
19594 ** Apply the affinity pDest->affSdst before storing
19595 ** results. Used to implement "IN (SELECT ...)".
 
 
 
 
19596 **
19597 ** SRT_EphemTab Create an temporary table pDest->iSDParm and store
19598 ** the result there. The cursor is left open after
19599 ** returning. This is like SRT_Table except that
19600 ** this destination uses OP_OpenEphemeral to create
@@ -19798,11 +19807,10 @@
19798 u8 okConstFactor; /* OK to factor out constants */
19799 u8 disableLookaside; /* Number of times lookaside has been disabled */
19800 u8 prepFlags; /* SQLITE_PREPARE_* flags */
19801 u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
19802 u8 bHasWith; /* True if statement contains WITH */
19803 u8 bHasExists; /* Has a correlated "EXISTS (SELECT ....)" expression */
19804 #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
19805 u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
19806 #endif
19807 #ifdef SQLITE_DEBUG
19808 u8 ifNotExists; /* Might be true if IF NOT EXISTS. Assert()s only */
@@ -20094,11 +20102,11 @@
20094 int iRetReg; /* Register array for holding a row of RETURNING */
20095 char zName[40]; /* Name of trigger: "sqlite_returning_%p" */
20096 };
20097
20098 /*
20099 ** An objected used to accumulate the text of a string where we
20100 ** do not necessarily know how big the string will be in the end.
20101 */
20102 struct sqlite3_str {
20103 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
20104 char *zText; /* The string collected so far */
@@ -20108,11 +20116,11 @@
20108 u8 accError; /* SQLITE_NOMEM or SQLITE_TOOBIG */
20109 u8 printfFlags; /* SQLITE_PRINTF flags below */
20110 };
20111 #define SQLITE_PRINTF_INTERNAL 0x01 /* Internal-use-only converters allowed */
20112 #define SQLITE_PRINTF_SQLFUNC 0x02 /* SQL function arguments to VXPrintf */
20113 #define SQLITE_PRINTF_MALLOCED 0x04 /* True if xText is allocated space */
20114
20115 #define isMalloced(X) (((X)->printfFlags & SQLITE_PRINTF_MALLOCED)!=0)
20116
20117 /*
20118 ** The following object is the header for an "RCStr" or "reference-counted
@@ -33485,13 +33493,14 @@
33485 }else{
33486 int i;
33487 sqlite3TreeViewLine(pView, "%s", zLabel);
33488 for(i=0; i<pList->nExpr; i++){
33489 int j = pList->a[i].u.x.iOrderByCol;
 
33490 char *zName = pList->a[i].zEName;
33491 int moreToFollow = i<pList->nExpr - 1;
33492 if( j || zName ){
33493 sqlite3TreeViewPush(&pView, moreToFollow);
33494 moreToFollow = 0;
33495 sqlite3TreeViewLine(pView, 0);
33496 if( zName ){
33497 switch( pList->a[i].fg.eEName ){
@@ -33508,17 +33517,22 @@
33508 fprintf(stdout, "SPAN(\"%s\") ", zName);
33509 break;
33510 }
33511 }
33512 if( j ){
33513 fprintf(stdout, "iOrderByCol=%d", j);
 
 
 
 
 
33514 }
33515 fprintf(stdout, "\n");
33516 fflush(stdout);
33517 }
33518 sqlite3TreeViewExpr(pView, pList->a[i].pExpr, moreToFollow);
33519 if( j || zName ){
33520 sqlite3TreeViewPop(&pView);
33521 }
33522 }
33523 }
33524 }
@@ -40643,30 +40657,26 @@
40643 */
40644 #define DOTLOCK_SUFFIX ".lock"
40645
40646 /*
40647 ** This routine checks if there is a RESERVED lock held on the specified
40648 ** file by this or any other process. If such a lock is held, set *pResOut
40649 ** to a non-zero value otherwise *pResOut is set to zero. The return value
40650 ** is set to SQLITE_OK unless an I/O error occurs during lock checking.
40651 **
40652 ** In dotfile locking, either a lock exists or it does not. So in this
40653 ** variation of CheckReservedLock(), *pResOut is set to true if any lock
40654 ** is held on the file and false if the file is unlocked.
40655 */
40656 static int dotlockCheckReservedLock(sqlite3_file *id, int *pResOut) {
40657 int rc = SQLITE_OK;
40658 int reserved = 0;
40659 unixFile *pFile = (unixFile*)id;
40660
40661 SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
40662
40663 assert( pFile );
40664 reserved = osAccess((const char*)pFile->lockingContext, 0)==0;
40665 OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, rc, reserved));
40666 *pResOut = reserved;
40667 return rc;
 
 
40668 }
40669
40670 /*
40671 ** Lock the file with the lock specified by parameter eFileLock - one
40672 ** of the following:
@@ -98433,10 +98443,11 @@
98433 if( r.nField>0 ){
98434 /* Key values in an array of registers */
98435 r.pKeyInfo = pC->pKeyInfo;
98436 r.default_rc = 0;
98437 #ifdef SQLITE_DEBUG
 
98438 for(ii=0; ii<r.nField; ii++){
98439 assert( memIsValid(&r.aMem[ii]) );
98440 assert( (r.aMem[ii].flags & MEM_Zero)==0 || r.aMem[ii].n==0 );
98441 if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
98442 }
@@ -108130,11 +108141,10 @@
108130 }
108131 assert( pNC->nRef>=nRef );
108132 if( nRef!=pNC->nRef ){
108133 ExprSetProperty(pExpr, EP_VarSelect);
108134 pExpr->x.pSelect->selFlags |= SF_Correlated;
108135 if( pExpr->op==TK_EXISTS ) pParse->bHasExists = 1;
108136 }
108137 pNC->ncFlags |= NC_Subquery;
108138 }
108139 break;
108140 }
@@ -109133,11 +109143,13 @@
109133 || (pExpr->op==TK_REGISTER && pExpr->op2==TK_IF_NULL_ROW) );
109134 pExpr = pExpr->pLeft;
109135 op = pExpr->op;
109136 continue;
109137 }
109138 if( op!=TK_REGISTER || (op = pExpr->op2)==TK_REGISTER ) break;
 
 
109139 }
109140 return pExpr->affExpr;
109141 }
109142
109143 /*
@@ -112582,19 +112594,34 @@
112582 if( ALWAYS(pEList->nExpr==nVal) ){
112583 Select *pCopy;
112584 SelectDest dest;
112585 int i;
112586 int rc;
 
112587 sqlite3SelectDestInit(&dest, SRT_Set, iTab);
112588 dest.zAffSdst = exprINAffinity(pParse, pExpr);
112589 pSelect->iLimit = 0;
 
 
 
 
 
 
112590 testcase( pSelect->selFlags & SF_Distinct );
112591 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
112592 pCopy = sqlite3SelectDup(pParse->db, pSelect, 0);
112593 rc = pParse->db->mallocFailed ? 1 :sqlite3Select(pParse, pCopy, &dest);
112594 sqlite3SelectDelete(pParse->db, pCopy);
112595 sqlite3DbFree(pParse->db, dest.zAffSdst);
 
 
 
 
 
 
 
 
112596 if( rc ){
112597 sqlite3KeyInfoUnref(pKeyInfo);
112598 return;
112599 }
112600 assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
@@ -113033,10 +113060,19 @@
113033 addrTruthOp = sqlite3VdbeAddOp0(v, OP_Goto); /* Return True */
113034 }else{
113035 sqlite3VdbeAddOp4(v, OP_Affinity, rLhs, nVector, 0, zAff, nVector);
113036 if( destIfFalse==destIfNull ){
113037 /* Combine Step 3 and Step 5 into a single opcode */
 
 
 
 
 
 
 
 
 
113038 sqlite3VdbeAddOp4Int(v, OP_NotFound, iTab, destIfFalse,
113039 rLhs, nVector); VdbeCoverage(v);
113040 goto sqlite3ExprCodeIN_finished;
113041 }
113042 /* Ordinary Step 3, for the case where FALSE and NULL are distinct */
@@ -113318,14 +113354,18 @@
113318 ** the correct value for the expression.
113319 */
113320 SQLITE_PRIVATE void sqlite3ExprToRegister(Expr *pExpr, int iReg){
113321 Expr *p = sqlite3ExprSkipCollateAndLikely(pExpr);
113322 if( NEVER(p==0) ) return;
113323 p->op2 = p->op;
113324 p->op = TK_REGISTER;
113325 p->iTable = iReg;
113326 ExprClearProperty(p, EP_Skip);
 
 
 
 
113327 }
113328
113329 /*
113330 ** Evaluate an expression (either a vector or a scalar expression) and store
113331 ** the result in contiguous temporary registers. Return the index of
@@ -126476,21 +126516,18 @@
126476 ** Append the contents of SrcList p2 to SrcList p1 and return the resulting
126477 ** SrcList. Or, if an error occurs, return NULL. In all cases, p1 and p2
126478 ** are deleted by this function.
126479 */
126480 SQLITE_PRIVATE SrcList *sqlite3SrcListAppendList(Parse *pParse, SrcList *p1, SrcList *p2){
126481 assert( p1 );
126482 if( p2 ){
126483 int nOld = p1->nSrc;
126484 SrcList *pNew = sqlite3SrcListEnlarge(pParse, p1, p2->nSrc, nOld);
126485 if( pNew==0 ){
126486 sqlite3SrcListDelete(pParse->db, p2);
126487 }else{
126488 p1 = pNew;
126489 memcpy(&p1->a[nOld], p2->a, p2->nSrc*sizeof(SrcItem));
126490 assert( nOld==1 || (p2->nSrc==1 && (p2->a[0].fg.jointype&JT_LTORJ)==0) );
126491 assert( p1->nSrc>=2 );
126492 sqlite3DbFree(pParse->db, p2);
126493 p1->a[0].fg.jointype |= (JT_LTORJ & p1->a[1].fg.jointype);
126494 }
126495 }
126496 return p1;
@@ -144332,16 +144369,22 @@
144332 ** ORDER BY in this case since the order of entries in the set
144333 ** does not matter. But there might be a LIMIT clause, in which
144334 ** case the order does matter */
144335 pushOntoSorter(
144336 pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg);
 
144337 }else{
144338 int r1 = sqlite3GetTempReg(pParse);
144339 assert( sqlite3Strlen30(pDest->zAffSdst)==nResultCol );
144340 sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult, nResultCol,
144341 r1, pDest->zAffSdst, nResultCol);
144342 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, nResultCol);
 
 
 
 
 
144343 sqlite3ReleaseTempReg(pParse, r1);
144344 }
144345 break;
144346 }
144347
@@ -146271,10 +146314,15 @@
146271 r1 = sqlite3GetTempReg(pParse);
146272 sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, pIn->nSdst,
146273 r1, pDest->zAffSdst, pIn->nSdst);
146274 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pDest->iSDParm, r1,
146275 pIn->iSdst, pIn->nSdst);
 
 
 
 
 
146276 sqlite3ReleaseTempReg(pParse, r1);
146277 break;
146278 }
146279
146280 /* If this is a scalar select that is part of an expression, then
@@ -150238,162 +150286,10 @@
150238 if( pItem->pSelect!=0 ) return 0; /* (1c-i) */
150239 }
150240 return 1;
150241 }
150242
150243 /*
150244 ** sqlite3WalkExpr() callback used by exprReferencesTable().
150245 */
150246 static int exprReferencesTableExprCb(Walker *pWalker, Expr *pExpr){
150247 if( pExpr->op==TK_COLUMN && pExpr->iTable==pWalker->u.iCur ){
150248 pWalker->eCode = 1;
150249 }
150250 return WRC_Continue;
150251 }
150252
150253 /*
150254 ** Return true if the expression passed as the first argument refers
150255 ** to cursor number iCur. Otherwise return false.
150256 */
150257 static int exprReferencesTable(Expr *pExpr, int iCur){
150258 Walker w;
150259 memset(&w, 0, sizeof(w));
150260 w.u.iCur = iCur;
150261 w.xExprCallback = exprReferencesTableExprCb;
150262 w.xSelectCallback = sqlite3SelectWalkNoop;
150263 sqlite3WalkExpr(&w, pExpr);
150264 return w.eCode;
150265 }
150266
150267 /*
150268 ** Index pIdx is a UNIQUE index on the table accessed by cursor number
150269 ** iCsr. This function returns a mask of the index columns that are
150270 ** constrained to match a single, non-NULL value by the WHERE clause
150271 ** passed as the 4th argument. For example, if the index is:
150272 **
150273 ** CREATE UNIQUE INDEX idx ON tbl(a, b, c);
150274 **
150275 ** and pWhere:
150276 **
150277 ** WHERE a=? AND c=?
150278 **
150279 ** then this function returns 5.
150280 */
150281 static u64 findConstIdxTerms(
150282 Parse *pParse,
150283 int iCsr,
150284 Index *pIdx,
150285 Expr *pWhere
150286 ){
150287 u64 m = 0;
150288 if( pWhere->op==TK_AND ){
150289 m = findConstIdxTerms(pParse, iCsr, pIdx, pWhere->pLeft);
150290 m |= findConstIdxTerms(pParse, iCsr, pIdx, pWhere->pRight);
150291 }else if( pWhere->op==TK_EQ ){
150292 Expr *pLeft = sqlite3ExprSkipCollateAndLikely(pWhere->pLeft);
150293 Expr *pRight = sqlite3ExprSkipCollateAndLikely(pWhere->pRight);
150294 if( pRight->op==TK_COLUMN && pRight->iTable==iCsr ){
150295 SWAP(Expr*, pLeft, pRight);
150296 }
150297 if( pLeft->op==TK_COLUMN
150298 && pLeft->iTable==iCsr
150299 && exprReferencesTable(pRight, iCsr)==0
150300 ){
150301 if( pIdx ){
150302 int ii;
150303 for(ii=0; ii<pIdx->nKeyCol; ii++){
150304 assert( pIdx->azColl[ii] );
150305 if( pLeft->iColumn==pIdx->aiColumn[ii] ){
150306 CollSeq *pColl = sqlite3ExprCompareCollSeq(pParse, pWhere);
150307 if( pColl && sqlite3StrICmp(pColl->zName, pIdx->azColl[ii])==0 ){
150308 m |= ((u64)1 << ii);
150309 break;
150310 }
150311 }
150312 }
150313 }else{
150314 if( pLeft->iColumn<0 ) m = 1;
150315 }
150316 }
150317 }
150318 return m;
150319 }
150320
150321 /*
150322 ** Argument pWhere is the WHERE clause belonging to SELECT statement p. This
150323 ** function attempts to transform expressions of the form:
150324 **
150325 ** EXISTS (SELECT ...)
150326 **
150327 ** into joins. For example, given
150328 **
150329 ** CREATE TABLE sailors(sid INTEGER PRIMARY KEY, name TEXT);
150330 ** CREATE TABLE reserves(sid INT, day DATE, PRIMARY KEY(sid, day));
150331 **
150332 ** SELECT name FROM sailors AS S WHERE EXISTS (
150333 ** SELECT * FROM reserves AS R WHERE S.sid = R.sid AND R.day = '2022-10-25'
150334 ** );
150335 **
150336 ** the SELECT statement may be transformed as follows:
150337 **
150338 ** SELECT name FROM sailors AS S, reserves AS R
150339 ** WHERE S.sid = R.sid AND R.day = '2022-10-25';
150340 */
150341 static void existsToJoin(Parse *pParse, Select *p, Expr *pWhere){
150342 if( pWhere && p->pSrc->nSrc>0 && pParse->db->mallocFailed==0 ){
150343 if( pWhere->op==TK_AND ){
150344 Expr *pRight = pWhere->pRight;
150345 existsToJoin(pParse, p, pWhere->pLeft);
150346 existsToJoin(pParse, p, pRight);
150347 }
150348 else if( pWhere->op==TK_EXISTS ){
150349 Select *pSub = pWhere->x.pSelect;
150350 if( pSub->pSrc->nSrc==1
150351 && (pSub->selFlags & (SF_Aggregate|SF_Correlated))==SF_Correlated
150352 && pSub->pWhere
150353 ){
150354 int bTransform = 0; /* True if EXISTS can be made into join */
150355 Table *pTab = pSub->pSrc->a[0].pTab;
150356 int iCsr = pSub->pSrc->a[0].iCursor;
150357 Index *pIdx;
150358 if( HasRowid(pTab) && findConstIdxTerms(pParse, iCsr, 0,pSub->pWhere) ){
150359 bTransform = 1;
150360 }
150361 for(pIdx=pTab->pIndex; pIdx && bTransform==0; pIdx=pIdx->pNext){
150362 if( pIdx->onError && pIdx->nKeyCol<=63 ){
150363 u64 c = findConstIdxTerms(pParse, iCsr, pIdx, pSub->pWhere);
150364 if( c==((u64)1 << pIdx->nKeyCol)-1 ){
150365 bTransform = 1;
150366 }
150367 }
150368 }
150369 if( bTransform ){
150370 memset(pWhere, 0, sizeof(*pWhere));
150371 pWhere->op = TK_INTEGER;
150372 pWhere->u.iValue = 1;
150373 ExprSetProperty(pWhere, EP_IntValue);
150374
150375 assert( p->pWhere!=0 );
150376 p->pSrc = sqlite3SrcListAppendList(pParse, p->pSrc, pSub->pSrc);
150377 p->pWhere = sqlite3PExpr(pParse, TK_AND, p->pWhere, pSub->pWhere);
150378
150379 pSub->pWhere = 0;
150380 pSub->pSrc = 0;
150381 sqlite3ParserAddCleanup(pParse, sqlite3SelectDeleteGeneric, pSub);
150382 #if TREETRACE_ENABLED
150383 if( sqlite3TreeTrace & 0x100000 ){
150384 TREETRACE(0x100000,pParse,p,
150385 ("After EXISTS-to-JOIN optimization:\n"));
150386 sqlite3TreeViewSelect(0, p, 0);
150387 }
150388 #endif
150389 }
150390 }
150391 }
150392 }
150393 }
150394
150395 /*
150396 ** Generate code for the SELECT statement given in the p argument.
150397 **
150398 ** The results are returned according to the SelectDest structure.
150399 ** See comments in sqliteInt.h for further information.
@@ -150642,17 +150538,20 @@
150642 ** (5) The ORDER BY isn't going to accomplish anything because
150643 ** one of:
150644 ** (a) The outer query has a different ORDER BY clause
150645 ** (b) The subquery is part of a join
150646 ** See forum post 062d576715d277c8
 
 
 
150647 **
150648 ** Also retain the ORDER BY if the OmitOrderBy optimization is disabled.
150649 */
150650 if( pSub->pOrderBy!=0
150651 && (p->pOrderBy!=0 || pTabList->nSrc>1) /* Condition (5) */
150652 && pSub->pLimit==0 /* Condition (1) */
150653 && (pSub->selFlags & SF_OrderByReqd)==0 /* Condition (2) */
150654 && (p->selFlags & SF_OrderByReqd)==0 /* Condition (3) and (4) */
150655 && OptimizationEnabled(db, SQLITE_OmitOrderBy)
150656 ){
150657 TREETRACE(0x800,pParse,p,
150658 ("omit superfluous ORDER BY on %r FROM-clause subquery\n",i+1));
@@ -150716,17 +150615,10 @@
150716 if( p->pNext==0 ) ExplainQueryPlanPop(pParse);
150717 return rc;
150718 }
150719 #endif
150720
150721 /* If there may be an "EXISTS (SELECT ...)" in the WHERE clause, attempt
150722 ** to change it into a join. */
150723 if( pParse->bHasExists && OptimizationEnabled(db,SQLITE_ExistsToJoin) ){
150724 existsToJoin(pParse, p, p->pWhere);
150725 pTabList = p->pSrc;
150726 }
150727
150728 /* Do the WHERE-clause constant propagation optimization if this is
150729 ** a join. No need to speed time on this operation for non-join queries
150730 ** as the equivalent optimization will be handled by query planner in
150731 ** sqlite3WhereBegin().
150732 */
@@ -151447,11 +151339,14 @@
151447 }
151448
151449 if( iOrderByCol ){
151450 Expr *pX = p->pEList->a[iOrderByCol-1].pExpr;
151451 Expr *pBase = sqlite3ExprSkipCollateAndLikely(pX);
151452 if( ALWAYS(pBase!=0) && pBase->op!=TK_AGG_COLUMN ){
 
 
 
151453 sqlite3ExprToRegister(pX, iAMem+j);
151454 }
151455 }
151456 }
151457 sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
@@ -167412,11 +167307,11 @@
167412 nColumn = pIndex->nColumn;
167413 assert( nColumn==nKeyCol+1 || !HasRowid(pIndex->pTable) );
167414 assert( pIndex->aiColumn[nColumn-1]==XN_ROWID
167415 || !HasRowid(pIndex->pTable));
167416 /* All relevant terms of the index must also be non-NULL in order
167417 ** for isOrderDistinct to be true. So the isOrderDistint value
167418 ** computed here might be a false positive. Corrections will be
167419 ** made at tag-20210426-1 below */
167420 isOrderDistinct = IsUniqueIndex(pIndex)
167421 && (pLoop->wsFlags & WHERE_SKIPSCAN)==0;
167422 }
@@ -232187,10 +232082,14 @@
232187 ** "detail=none" or "detail=column" option. If the FTS5 table is created
232188 ** with either "detail=none" or "detail=column" and "content=" option
232189 ** (i.e. if it is a contentless table), then this API always iterates
232190 ** through an empty set (all calls to xPhraseFirst() set iCol to -1).
232191 **
 
 
 
 
232192 ** xPhraseNext()
232193 ** See xPhraseFirst above.
232194 **
232195 ** xPhraseFirstColumn()
232196 ** This function and xPhraseNextColumn() are similar to the xPhraseFirst()
@@ -239066,10 +238965,11 @@
239066 ** no token characters at all. (e.g ... MATCH '""'). */
239067 sCtx.pPhrase = sqlite3Fts5MallocZero(&pParse->rc, sizeof(Fts5ExprPhrase));
239068 }else if( sCtx.pPhrase->nTerm ){
239069 sCtx.pPhrase->aTerm[sCtx.pPhrase->nTerm-1].bPrefix = (u8)bPrefix;
239070 }
 
239071 pParse->apPhrase[pParse->nPhrase-1] = sCtx.pPhrase;
239072 }
239073
239074 return sCtx.pPhrase;
239075 }
@@ -239085,11 +238985,11 @@
239085 ){
239086 int rc = SQLITE_OK; /* Return code */
239087 Fts5ExprPhrase *pOrig = 0; /* The phrase extracted from pExpr */
239088 Fts5Expr *pNew = 0; /* Expression to return via *ppNew */
239089 TokenCtx sCtx = {0,0,0}; /* Context object for fts5ParseTokenize */
239090 if( iPhrase<0 || iPhrase>=pExpr->nPhrase ){
239091 rc = SQLITE_RANGE;
239092 }else{
239093 pOrig = pExpr->apExprPhrase[iPhrase];
239094 pNew = (Fts5Expr*)sqlite3Fts5MallocZero(&rc, sizeof(Fts5Expr));
239095 }
@@ -239660,10 +239560,12 @@
239660 || pPrev->eType==FTS5_TERM
239661 || pPrev->eType==FTS5_EOF
239662 );
239663
239664 if( pRight->eType==FTS5_EOF ){
 
 
239665 assert( pParse->apPhrase[pParse->nPhrase-1]==pRight->pNear->apPhrase[0] );
239666 sqlite3Fts5ParseNodeFree(pRight);
239667 pRet = pLeft;
239668 pParse->nPhrase--;
239669 }
@@ -251077,10 +250979,11 @@
251077 "%s", sqlite3_errmsg(pConfig->db)
251078 );
251079 }
251080 }else{
251081 rc = SQLITE_OK;
 
251082 }
251083 break;
251084 }
251085 }
251086 }
@@ -251550,13 +251453,17 @@
251550 */
251551 static i64 fts5CursorRowid(Fts5Cursor *pCsr){
251552 assert( pCsr->ePlan==FTS5_PLAN_MATCH
251553 || pCsr->ePlan==FTS5_PLAN_SORTED_MATCH
251554 || pCsr->ePlan==FTS5_PLAN_SOURCE
 
 
251555 );
251556 if( pCsr->pSorter ){
251557 return pCsr->pSorter->iRowid;
 
 
251558 }else{
251559 return sqlite3Fts5ExprRowid(pCsr->pExpr);
251560 }
251561 }
251562
@@ -251569,24 +251476,14 @@
251569 static int fts5RowidMethod(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
251570 Fts5Cursor *pCsr = (Fts5Cursor*)pCursor;
251571 int ePlan = pCsr->ePlan;
251572
251573 assert( CsrFlagTest(pCsr, FTS5CSR_EOF)==0 );
251574 switch( ePlan ){
251575 case FTS5_PLAN_SPECIAL:
251576 *pRowid = 0;
251577 break;
251578
251579 case FTS5_PLAN_SOURCE:
251580 case FTS5_PLAN_MATCH:
251581 case FTS5_PLAN_SORTED_MATCH:
251582 *pRowid = fts5CursorRowid(pCsr);
251583 break;
251584
251585 default:
251586 *pRowid = sqlite3_column_int64(pCsr->pStmt, 0);
251587 break;
251588 }
251589
251590 return SQLITE_OK;
251591 }
251592
@@ -253071,11 +252968,11 @@
253071 int nArg, /* Number of args */
253072 sqlite3_value **apUnused /* Function arguments */
253073 ){
253074 assert( nArg==0 );
253075 UNUSED_PARAM2(nArg, apUnused);
253076 sqlite3_result_text(pCtx, "fts5: 2024-06-11 17:37:36 5f25a9518a675efbd0525cc2f5595ee7bc7122be7cfecdf6b20c909185dea370", -1, SQLITE_TRANSIENT);
253077 }
253078
253079 /*
253080 ** Return true if zName is the extension on one of the shadow tables used
253081 ** by this module.
253082
--- 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 ** baa83b460c677c210c7fa3f20314d7e05f30.
22 */
23 #define SQLITE_CORE 1
24 #define SQLITE_AMALGAMATION 1
25 #ifndef SQLITE_PRIVATE
26 # define SQLITE_PRIVATE static
@@ -254,14 +254,17 @@
254 #endif
255
256 /*
257 ** Macro to disable warnings about missing "break" at the end of a "case".
258 */
259 #if defined(__has_attribute)
260 # if __has_attribute(fallthrough)
261 # define deliberate_fall_through __attribute__((fallthrough));
262 # endif
263 #endif
264 #if !defined(deliberate_fall_through)
265 # define deliberate_fall_through
266 #endif
267
268 /*
269 ** For MinGW, check to see if we can include the header file containing its
270 ** version information, among other things. Normally, this internal MinGW
@@ -459,11 +462,11 @@
462 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
463 ** [sqlite_version()] and [sqlite_source_id()].
464 */
465 #define SQLITE_VERSION "3.47.0"
466 #define SQLITE_VERSION_NUMBER 3047000
467 #define SQLITE_SOURCE_ID "2024-07-03 20:19:33 baa83b460c677c210c7fa3f20314d7e05f305aed8a69026bc5fa106a3de4ea38"
468
469 /*
470 ** CAPI3REF: Run-Time Library Version Numbers
471 ** KEYWORDS: sqlite3_version sqlite3_sourceid
472 **
@@ -1083,12 +1086,12 @@
1086 ** xUnlock() downgrades the database file lock to either SHARED or NONE.
1087 ** If the lock is already at or below the requested lock state, then the call
1088 ** to xUnlock() is a no-op.
1089 ** The xCheckReservedLock() method checks whether any database connection,
1090 ** either in this process or in some other process, is holding a RESERVED,
1091 ** PENDING, or EXCLUSIVE lock on the file. It returns, via its output
1092 ** pointer parameter, true if such a lock exists and false otherwise.
1093 **
1094 ** The xFileControl() method is a generic interface that allows custom
1095 ** VFS implementations to directly control an open file using the
1096 ** [sqlite3_file_control()] interface. The second "op" argument is an
1097 ** integer opcode. The third argument is a generic pointer intended to
@@ -13345,10 +13348,14 @@
13348 ** "detail=none" or "detail=column" option. If the FTS5 table is created
13349 ** with either "detail=none" or "detail=column" and "content=" option
13350 ** (i.e. if it is a contentless table), then this API always iterates
13351 ** through an empty set (all calls to xPhraseFirst() set iCol to -1).
13352 **
13353 ** In all cases, matches are visited in (column ASC, offset ASC) order.
13354 ** i.e. all those in column 0, sorted by offset, followed by those in
13355 ** column 1, etc.
13356 **
13357 ** xPhraseNext()
13358 ** See xPhraseFirst above.
13359 **
13360 ** xPhraseFirstColumn()
13361 ** This function and xPhraseNextColumn() are similar to the xPhraseFirst()
@@ -15167,11 +15174,10 @@
15174 ** 0x00008000 After all FROM-clause analysis
15175 ** 0x00010000 Beginning of DELETE/INSERT/UPDATE processing
15176 ** 0x00020000 Transform DISTINCT into GROUP BY
15177 ** 0x00040000 SELECT tree dump after all code has been generated
15178 ** 0x00080000 NOT NULL strength reduction
 
15179 */
15180
15181 /*
15182 ** Macros for "wheretrace"
15183 */
@@ -17894,11 +17900,10 @@
17900 /* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
17901 #define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
17902 #define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
17903 #define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
17904 #define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
 
17905 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
17906
17907 /*
17908 ** Macros for testing whether or not optimizations are enabled or disabled.
17909 */
@@ -19590,11 +19595,15 @@
19595 ** of the query. This destination implies "LIMIT 1".
19596 **
19597 ** SRT_Set The result must be a single column. Store each
19598 ** row of result as the key in table pDest->iSDParm.
19599 ** Apply the affinity pDest->affSdst before storing
19600 ** results. if pDest->iSDParm2 is positive, then it is
19601 ** a regsiter holding a Bloom filter for the IN operator
19602 ** that should be populated in addition to the
19603 ** pDest->iSDParm table. This SRT is used to
19604 ** implement "IN (SELECT ...)".
19605 **
19606 ** SRT_EphemTab Create an temporary table pDest->iSDParm and store
19607 ** the result there. The cursor is left open after
19608 ** returning. This is like SRT_Table except that
19609 ** this destination uses OP_OpenEphemeral to create
@@ -19798,11 +19807,10 @@
19807 u8 okConstFactor; /* OK to factor out constants */
19808 u8 disableLookaside; /* Number of times lookaside has been disabled */
19809 u8 prepFlags; /* SQLITE_PREPARE_* flags */
19810 u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
19811 u8 bHasWith; /* True if statement contains WITH */
 
19812 #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
19813 u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
19814 #endif
19815 #ifdef SQLITE_DEBUG
19816 u8 ifNotExists; /* Might be true if IF NOT EXISTS. Assert()s only */
@@ -20094,11 +20102,11 @@
20102 int iRetReg; /* Register array for holding a row of RETURNING */
20103 char zName[40]; /* Name of trigger: "sqlite_returning_%p" */
20104 };
20105
20106 /*
20107 ** An object used to accumulate the text of a string where we
20108 ** do not necessarily know how big the string will be in the end.
20109 */
20110 struct sqlite3_str {
20111 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
20112 char *zText; /* The string collected so far */
@@ -20108,11 +20116,11 @@
20116 u8 accError; /* SQLITE_NOMEM or SQLITE_TOOBIG */
20117 u8 printfFlags; /* SQLITE_PRINTF flags below */
20118 };
20119 #define SQLITE_PRINTF_INTERNAL 0x01 /* Internal-use-only converters allowed */
20120 #define SQLITE_PRINTF_SQLFUNC 0x02 /* SQL function arguments to VXPrintf */
20121 #define SQLITE_PRINTF_MALLOCED 0x04 /* True if zText is allocated space */
20122
20123 #define isMalloced(X) (((X)->printfFlags & SQLITE_PRINTF_MALLOCED)!=0)
20124
20125 /*
20126 ** The following object is the header for an "RCStr" or "reference-counted
@@ -33485,13 +33493,14 @@
33493 }else{
33494 int i;
33495 sqlite3TreeViewLine(pView, "%s", zLabel);
33496 for(i=0; i<pList->nExpr; i++){
33497 int j = pList->a[i].u.x.iOrderByCol;
33498 u8 sortFlags = pList->a[i].fg.sortFlags;
33499 char *zName = pList->a[i].zEName;
33500 int moreToFollow = i<pList->nExpr - 1;
33501 if( j || zName || sortFlags ){
33502 sqlite3TreeViewPush(&pView, moreToFollow);
33503 moreToFollow = 0;
33504 sqlite3TreeViewLine(pView, 0);
33505 if( zName ){
33506 switch( pList->a[i].fg.eEName ){
@@ -33508,17 +33517,22 @@
33517 fprintf(stdout, "SPAN(\"%s\") ", zName);
33518 break;
33519 }
33520 }
33521 if( j ){
33522 fprintf(stdout, "iOrderByCol=%d ", j);
33523 }
33524 if( sortFlags & KEYINFO_ORDER_DESC ){
33525 fprintf(stdout, "DESC ");
33526 }else if( sortFlags & KEYINFO_ORDER_BIGNULL ){
33527 fprintf(stdout, "NULLS-LAST");
33528 }
33529 fprintf(stdout, "\n");
33530 fflush(stdout);
33531 }
33532 sqlite3TreeViewExpr(pView, pList->a[i].pExpr, moreToFollow);
33533 if( j || zName || sortFlags ){
33534 sqlite3TreeViewPop(&pView);
33535 }
33536 }
33537 }
33538 }
@@ -40643,30 +40657,26 @@
40657 */
40658 #define DOTLOCK_SUFFIX ".lock"
40659
40660 /*
40661 ** This routine checks if there is a RESERVED lock held on the specified
40662 ** file by this or any other process. If the caller holds a SHARED
40663 ** or greater lock when it is called, then it is assumed that no other
40664 ** client may hold RESERVED. Or, if the caller holds no lock, then it
40665 ** is assumed another client holds RESERVED if the lock-file exists.
 
 
 
40666 */
40667 static int dotlockCheckReservedLock(sqlite3_file *id, int *pResOut) {
 
 
40668 unixFile *pFile = (unixFile*)id;
 
40669 SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
40670
40671 if( pFile->eFileLock>=SHARED_LOCK ){
40672 *pResOut = 0;
40673 }else{
40674 *pResOut = osAccess((const char*)pFile->lockingContext, 0)==0;
40675 }
40676 OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, 0, *pResOut));
40677 return SQLITE_OK;
40678 }
40679
40680 /*
40681 ** Lock the file with the lock specified by parameter eFileLock - one
40682 ** of the following:
@@ -98433,10 +98443,11 @@
98443 if( r.nField>0 ){
98444 /* Key values in an array of registers */
98445 r.pKeyInfo = pC->pKeyInfo;
98446 r.default_rc = 0;
98447 #ifdef SQLITE_DEBUG
98448 (void)sqlite3FaultSim(50); /* For use by --counter in TH3 */
98449 for(ii=0; ii<r.nField; ii++){
98450 assert( memIsValid(&r.aMem[ii]) );
98451 assert( (r.aMem[ii].flags & MEM_Zero)==0 || r.aMem[ii].n==0 );
98452 if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
98453 }
@@ -108130,11 +108141,10 @@
108141 }
108142 assert( pNC->nRef>=nRef );
108143 if( nRef!=pNC->nRef ){
108144 ExprSetProperty(pExpr, EP_VarSelect);
108145 pExpr->x.pSelect->selFlags |= SF_Correlated;
 
108146 }
108147 pNC->ncFlags |= NC_Subquery;
108148 }
108149 break;
108150 }
@@ -109133,11 +109143,13 @@
109143 || (pExpr->op==TK_REGISTER && pExpr->op2==TK_IF_NULL_ROW) );
109144 pExpr = pExpr->pLeft;
109145 op = pExpr->op;
109146 continue;
109147 }
109148 if( op!=TK_REGISTER ) break;
109149 op = pExpr->op2;
109150 if( NEVER( op==TK_REGISTER ) ) break;
109151 }
109152 return pExpr->affExpr;
109153 }
109154
109155 /*
@@ -112582,19 +112594,34 @@
112594 if( ALWAYS(pEList->nExpr==nVal) ){
112595 Select *pCopy;
112596 SelectDest dest;
112597 int i;
112598 int rc;
112599 int addrBloom = 0;
112600 sqlite3SelectDestInit(&dest, SRT_Set, iTab);
112601 dest.zAffSdst = exprINAffinity(pParse, pExpr);
112602 pSelect->iLimit = 0;
112603 if( addrOnce && OptimizationEnabled(pParse->db, SQLITE_BloomFilter) ){
112604 int regBloom = ++pParse->nMem;
112605 addrBloom = sqlite3VdbeAddOp2(v, OP_Blob, 10000, regBloom);
112606 VdbeComment((v, "Bloom filter"));
112607 dest.iSDParm2 = regBloom;
112608 }
112609 testcase( pSelect->selFlags & SF_Distinct );
112610 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
112611 pCopy = sqlite3SelectDup(pParse->db, pSelect, 0);
112612 rc = pParse->db->mallocFailed ? 1 :sqlite3Select(pParse, pCopy, &dest);
112613 sqlite3SelectDelete(pParse->db, pCopy);
112614 sqlite3DbFree(pParse->db, dest.zAffSdst);
112615 if( addrBloom ){
112616 sqlite3VdbeGetOp(v, addrOnce)->p3 = dest.iSDParm2;
112617 if( dest.iSDParm2==0 ){
112618 sqlite3VdbeChangeToNoop(v, addrBloom);
112619 }else{
112620 sqlite3VdbeGetOp(v, addrOnce)->p3 = dest.iSDParm2;
112621 }
112622 }
112623 if( rc ){
112624 sqlite3KeyInfoUnref(pKeyInfo);
112625 return;
112626 }
112627 assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
@@ -113033,10 +113060,19 @@
113060 addrTruthOp = sqlite3VdbeAddOp0(v, OP_Goto); /* Return True */
113061 }else{
113062 sqlite3VdbeAddOp4(v, OP_Affinity, rLhs, nVector, 0, zAff, nVector);
113063 if( destIfFalse==destIfNull ){
113064 /* Combine Step 3 and Step 5 into a single opcode */
113065 if( ExprHasProperty(pExpr, EP_Subrtn) ){
113066 const VdbeOp *pOp = sqlite3VdbeGetOp(v, pExpr->y.sub.iAddr);
113067 assert( pOp->opcode==OP_Once || pParse->nErr );
113068 if( pOp->opcode==OP_Once && pOp->p3>0 ){
113069 assert( OptimizationEnabled(pParse->db, SQLITE_BloomFilter) );
113070 sqlite3VdbeAddOp4Int(v, OP_Filter, pOp->p3, destIfFalse,
113071 rLhs, nVector); VdbeCoverage(v);
113072 }
113073 }
113074 sqlite3VdbeAddOp4Int(v, OP_NotFound, iTab, destIfFalse,
113075 rLhs, nVector); VdbeCoverage(v);
113076 goto sqlite3ExprCodeIN_finished;
113077 }
113078 /* Ordinary Step 3, for the case where FALSE and NULL are distinct */
@@ -113318,14 +113354,18 @@
113354 ** the correct value for the expression.
113355 */
113356 SQLITE_PRIVATE void sqlite3ExprToRegister(Expr *pExpr, int iReg){
113357 Expr *p = sqlite3ExprSkipCollateAndLikely(pExpr);
113358 if( NEVER(p==0) ) return;
113359 if( p->op==TK_REGISTER ){
113360 assert( p->iTable==iReg );
113361 }else{
113362 p->op2 = p->op;
113363 p->op = TK_REGISTER;
113364 p->iTable = iReg;
113365 ExprClearProperty(p, EP_Skip);
113366 }
113367 }
113368
113369 /*
113370 ** Evaluate an expression (either a vector or a scalar expression) and store
113371 ** the result in contiguous temporary registers. Return the index of
@@ -126476,21 +126516,18 @@
126516 ** Append the contents of SrcList p2 to SrcList p1 and return the resulting
126517 ** SrcList. Or, if an error occurs, return NULL. In all cases, p1 and p2
126518 ** are deleted by this function.
126519 */
126520 SQLITE_PRIVATE SrcList *sqlite3SrcListAppendList(Parse *pParse, SrcList *p1, SrcList *p2){
126521 assert( p1 && p1->nSrc==1 );
126522 if( p2 ){
126523 SrcList *pNew = sqlite3SrcListEnlarge(pParse, p1, p2->nSrc, 1);
 
126524 if( pNew==0 ){
126525 sqlite3SrcListDelete(pParse->db, p2);
126526 }else{
126527 p1 = pNew;
126528 memcpy(&p1->a[1], p2->a, p2->nSrc*sizeof(SrcItem));
 
 
126529 sqlite3DbFree(pParse->db, p2);
126530 p1->a[0].fg.jointype |= (JT_LTORJ & p1->a[1].fg.jointype);
126531 }
126532 }
126533 return p1;
@@ -144332,16 +144369,22 @@
144369 ** ORDER BY in this case since the order of entries in the set
144370 ** does not matter. But there might be a LIMIT clause, in which
144371 ** case the order does matter */
144372 pushOntoSorter(
144373 pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg);
144374 pDest->iSDParm2 = 0; /* Signal that any Bloom filter is unpopulated */
144375 }else{
144376 int r1 = sqlite3GetTempReg(pParse);
144377 assert( sqlite3Strlen30(pDest->zAffSdst)==nResultCol );
144378 sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult, nResultCol,
144379 r1, pDest->zAffSdst, nResultCol);
144380 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, nResultCol);
144381 if( pDest->iSDParm2 ){
144382 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pDest->iSDParm2, 0,
144383 regResult, nResultCol);
144384 ExplainQueryPlan((pParse, 0, "CREATE BLOOM FILTER"));
144385 }
144386 sqlite3ReleaseTempReg(pParse, r1);
144387 }
144388 break;
144389 }
144390
@@ -146271,10 +146314,15 @@
146314 r1 = sqlite3GetTempReg(pParse);
146315 sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, pIn->nSdst,
146316 r1, pDest->zAffSdst, pIn->nSdst);
146317 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pDest->iSDParm, r1,
146318 pIn->iSdst, pIn->nSdst);
146319 if( pDest->iSDParm2>0 ){
146320 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pDest->iSDParm2, 0,
146321 pIn->iSdst, pIn->nSdst);
146322 ExplainQueryPlan((pParse, 0, "CREATE BLOOM FILTER"));
146323 }
146324 sqlite3ReleaseTempReg(pParse, r1);
146325 break;
146326 }
146327
146328 /* If this is a scalar select that is part of an expression, then
@@ -150238,162 +150286,10 @@
150286 if( pItem->pSelect!=0 ) return 0; /* (1c-i) */
150287 }
150288 return 1;
150289 }
150290
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150291 /*
150292 ** Generate code for the SELECT statement given in the p argument.
150293 **
150294 ** The results are returned according to the SelectDest structure.
150295 ** See comments in sqliteInt.h for further information.
@@ -150642,17 +150538,20 @@
150538 ** (5) The ORDER BY isn't going to accomplish anything because
150539 ** one of:
150540 ** (a) The outer query has a different ORDER BY clause
150541 ** (b) The subquery is part of a join
150542 ** See forum post 062d576715d277c8
150543 ** (6) The subquery is not a recursive CTE. ORDER BY has a different
150544 ** meaning for recursive CTEs and this optimization does not
150545 ** apply.
150546 **
150547 ** Also retain the ORDER BY if the OmitOrderBy optimization is disabled.
150548 */
150549 if( pSub->pOrderBy!=0
150550 && (p->pOrderBy!=0 || pTabList->nSrc>1) /* Condition (5) */
150551 && pSub->pLimit==0 /* Condition (1) */
150552 && (pSub->selFlags & (SF_OrderByReqd|SF_Recursive))==0 /* (2) and (6) */
150553 && (p->selFlags & SF_OrderByReqd)==0 /* Condition (3) and (4) */
150554 && OptimizationEnabled(db, SQLITE_OmitOrderBy)
150555 ){
150556 TREETRACE(0x800,pParse,p,
150557 ("omit superfluous ORDER BY on %r FROM-clause subquery\n",i+1));
@@ -150716,17 +150615,10 @@
150615 if( p->pNext==0 ) ExplainQueryPlanPop(pParse);
150616 return rc;
150617 }
150618 #endif
150619
 
 
 
 
 
 
 
150620 /* Do the WHERE-clause constant propagation optimization if this is
150621 ** a join. No need to speed time on this operation for non-join queries
150622 ** as the equivalent optimization will be handled by query planner in
150623 ** sqlite3WhereBegin().
150624 */
@@ -151447,11 +151339,14 @@
151339 }
151340
151341 if( iOrderByCol ){
151342 Expr *pX = p->pEList->a[iOrderByCol-1].pExpr;
151343 Expr *pBase = sqlite3ExprSkipCollateAndLikely(pX);
151344 if( ALWAYS(pBase!=0)
151345 && pBase->op!=TK_AGG_COLUMN
151346 && pBase->op!=TK_REGISTER
151347 ){
151348 sqlite3ExprToRegister(pX, iAMem+j);
151349 }
151350 }
151351 }
151352 sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
@@ -167412,11 +167307,11 @@
167307 nColumn = pIndex->nColumn;
167308 assert( nColumn==nKeyCol+1 || !HasRowid(pIndex->pTable) );
167309 assert( pIndex->aiColumn[nColumn-1]==XN_ROWID
167310 || !HasRowid(pIndex->pTable));
167311 /* All relevant terms of the index must also be non-NULL in order
167312 ** for isOrderDistinct to be true. So the isOrderDistinct value
167313 ** computed here might be a false positive. Corrections will be
167314 ** made at tag-20210426-1 below */
167315 isOrderDistinct = IsUniqueIndex(pIndex)
167316 && (pLoop->wsFlags & WHERE_SKIPSCAN)==0;
167317 }
@@ -232187,10 +232082,14 @@
232082 ** "detail=none" or "detail=column" option. If the FTS5 table is created
232083 ** with either "detail=none" or "detail=column" and "content=" option
232084 ** (i.e. if it is a contentless table), then this API always iterates
232085 ** through an empty set (all calls to xPhraseFirst() set iCol to -1).
232086 **
232087 ** In all cases, matches are visited in (column ASC, offset ASC) order.
232088 ** i.e. all those in column 0, sorted by offset, followed by those in
232089 ** column 1, etc.
232090 **
232091 ** xPhraseNext()
232092 ** See xPhraseFirst above.
232093 **
232094 ** xPhraseFirstColumn()
232095 ** This function and xPhraseNextColumn() are similar to the xPhraseFirst()
@@ -239066,10 +238965,11 @@
238965 ** no token characters at all. (e.g ... MATCH '""'). */
238966 sCtx.pPhrase = sqlite3Fts5MallocZero(&pParse->rc, sizeof(Fts5ExprPhrase));
238967 }else if( sCtx.pPhrase->nTerm ){
238968 sCtx.pPhrase->aTerm[sCtx.pPhrase->nTerm-1].bPrefix = (u8)bPrefix;
238969 }
238970 assert( pParse->apPhrase!=0 );
238971 pParse->apPhrase[pParse->nPhrase-1] = sCtx.pPhrase;
238972 }
238973
238974 return sCtx.pPhrase;
238975 }
@@ -239085,11 +238985,11 @@
238985 ){
238986 int rc = SQLITE_OK; /* Return code */
238987 Fts5ExprPhrase *pOrig = 0; /* The phrase extracted from pExpr */
238988 Fts5Expr *pNew = 0; /* Expression to return via *ppNew */
238989 TokenCtx sCtx = {0,0,0}; /* Context object for fts5ParseTokenize */
238990 if( !pExpr || iPhrase<0 || iPhrase>=pExpr->nPhrase ){
238991 rc = SQLITE_RANGE;
238992 }else{
238993 pOrig = pExpr->apExprPhrase[iPhrase];
238994 pNew = (Fts5Expr*)sqlite3Fts5MallocZero(&rc, sizeof(Fts5Expr));
238995 }
@@ -239660,10 +239560,12 @@
239560 || pPrev->eType==FTS5_TERM
239561 || pPrev->eType==FTS5_EOF
239562 );
239563
239564 if( pRight->eType==FTS5_EOF ){
239565 assert( pParse->apPhrase!=0 );
239566 assert( pParse->nPhrase>0 );
239567 assert( pParse->apPhrase[pParse->nPhrase-1]==pRight->pNear->apPhrase[0] );
239568 sqlite3Fts5ParseNodeFree(pRight);
239569 pRet = pLeft;
239570 pParse->nPhrase--;
239571 }
@@ -251077,10 +250979,11 @@
250979 "%s", sqlite3_errmsg(pConfig->db)
250980 );
250981 }
250982 }else{
250983 rc = SQLITE_OK;
250984 CsrFlagSet(pCsr, FTS5CSR_REQUIRE_DOCSIZE);
250985 }
250986 break;
250987 }
250988 }
250989 }
@@ -251550,13 +251453,17 @@
251453 */
251454 static i64 fts5CursorRowid(Fts5Cursor *pCsr){
251455 assert( pCsr->ePlan==FTS5_PLAN_MATCH
251456 || pCsr->ePlan==FTS5_PLAN_SORTED_MATCH
251457 || pCsr->ePlan==FTS5_PLAN_SOURCE
251458 || pCsr->ePlan==FTS5_PLAN_SCAN
251459 || pCsr->ePlan==FTS5_PLAN_ROWID
251460 );
251461 if( pCsr->pSorter ){
251462 return pCsr->pSorter->iRowid;
251463 }else if( pCsr->ePlan>=FTS5_PLAN_SCAN ){
251464 return sqlite3_column_int64(pCsr->pStmt, 0);
251465 }else{
251466 return sqlite3Fts5ExprRowid(pCsr->pExpr);
251467 }
251468 }
251469
@@ -251569,24 +251476,14 @@
251476 static int fts5RowidMethod(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
251477 Fts5Cursor *pCsr = (Fts5Cursor*)pCursor;
251478 int ePlan = pCsr->ePlan;
251479
251480 assert( CsrFlagTest(pCsr, FTS5CSR_EOF)==0 );
251481 if( ePlan==FTS5_PLAN_SPECIAL ){
251482 *pRowid = 0;
251483 }else{
251484 *pRowid = fts5CursorRowid(pCsr);
 
 
 
 
 
 
 
 
 
 
251485 }
251486
251487 return SQLITE_OK;
251488 }
251489
@@ -253071,11 +252968,11 @@
252968 int nArg, /* Number of args */
252969 sqlite3_value **apUnused /* Function arguments */
252970 ){
252971 assert( nArg==0 );
252972 UNUSED_PARAM2(nArg, apUnused);
252973 sqlite3_result_text(pCtx, "fts5: 2024-07-03 20:19:33 baa83b460c677c210c7fa3f20314d7e05f305aed8a69026bc5fa106a3de4ea38", -1, SQLITE_TRANSIENT);
252974 }
252975
252976 /*
252977 ** Return true if zName is the extension on one of the shadow tables used
252978 ** by this module.
252979
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.47.0"
150150
#define SQLITE_VERSION_NUMBER 3047000
151
-#define SQLITE_SOURCE_ID "2024-06-11 18:22:48 33a3f327855b427ae6ba0057218d043a1417bc9d780728f47f23acdd836e1686"
151
+#define SQLITE_SOURCE_ID "2024-07-03 20:19:33 baa83b460c677c210c7fa3f20314d7e05f305aed8a69026bc5fa106a3de4ea38"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -770,12 +770,12 @@
770770
** xUnlock() downgrades the database file lock to either SHARED or NONE.
771771
** If the lock is already at or below the requested lock state, then the call
772772
** to xUnlock() is a no-op.
773773
** The xCheckReservedLock() method checks whether any database connection,
774774
** either in this process or in some other process, is holding a RESERVED,
775
-** PENDING, or EXCLUSIVE lock on the file. It returns true
776
-** if such a lock exists and false otherwise.
775
+** PENDING, or EXCLUSIVE lock on the file. It returns, via its output
776
+** pointer parameter, true if such a lock exists and false otherwise.
777777
**
778778
** The xFileControl() method is a generic interface that allows custom
779779
** VFS implementations to directly control an open file using the
780780
** [sqlite3_file_control()] interface. The second "op" argument is an
781781
** integer opcode. The third argument is a generic pointer intended to
@@ -13031,10 +13031,14 @@
1303113031
** This API can be quite slow if used with an FTS5 table created with the
1303213032
** "detail=none" or "detail=column" option. If the FTS5 table is created
1303313033
** with either "detail=none" or "detail=column" and "content=" option
1303413034
** (i.e. if it is a contentless table), then this API always iterates
1303513035
** through an empty set (all calls to xPhraseFirst() set iCol to -1).
13036
+**
13037
+** In all cases, matches are visited in (column ASC, offset ASC) order.
13038
+** i.e. all those in column 0, sorted by offset, followed by those in
13039
+** column 1, etc.
1303613040
**
1303713041
** xPhraseNext()
1303813042
** See xPhraseFirst above.
1303913043
**
1304013044
** xPhraseFirstColumn()
1304113045
--- 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.47.0"
150 #define SQLITE_VERSION_NUMBER 3047000
151 #define SQLITE_SOURCE_ID "2024-06-11 18:22:48 33a3f327855b427ae6ba0057218d043a1417bc9d780728f47f23acdd836e1686"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -770,12 +770,12 @@
770 ** xUnlock() downgrades the database file lock to either SHARED or NONE.
771 ** If the lock is already at or below the requested lock state, then the call
772 ** to xUnlock() is a no-op.
773 ** The xCheckReservedLock() method checks whether any database connection,
774 ** either in this process or in some other process, is holding a RESERVED,
775 ** PENDING, or EXCLUSIVE lock on the file. It returns true
776 ** if such a lock exists and false otherwise.
777 **
778 ** The xFileControl() method is a generic interface that allows custom
779 ** VFS implementations to directly control an open file using the
780 ** [sqlite3_file_control()] interface. The second "op" argument is an
781 ** integer opcode. The third argument is a generic pointer intended to
@@ -13031,10 +13031,14 @@
13031 ** This API can be quite slow if used with an FTS5 table created with the
13032 ** "detail=none" or "detail=column" option. If the FTS5 table is created
13033 ** with either "detail=none" or "detail=column" and "content=" option
13034 ** (i.e. if it is a contentless table), then this API always iterates
13035 ** through an empty set (all calls to xPhraseFirst() set iCol to -1).
 
 
 
 
13036 **
13037 ** xPhraseNext()
13038 ** See xPhraseFirst above.
13039 **
13040 ** xPhraseFirstColumn()
13041
--- 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.47.0"
150 #define SQLITE_VERSION_NUMBER 3047000
151 #define SQLITE_SOURCE_ID "2024-07-03 20:19:33 baa83b460c677c210c7fa3f20314d7e05f305aed8a69026bc5fa106a3de4ea38"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -770,12 +770,12 @@
770 ** xUnlock() downgrades the database file lock to either SHARED or NONE.
771 ** If the lock is already at or below the requested lock state, then the call
772 ** to xUnlock() is a no-op.
773 ** The xCheckReservedLock() method checks whether any database connection,
774 ** either in this process or in some other process, is holding a RESERVED,
775 ** PENDING, or EXCLUSIVE lock on the file. It returns, via its output
776 ** pointer parameter, true if such a lock exists and false otherwise.
777 **
778 ** The xFileControl() method is a generic interface that allows custom
779 ** VFS implementations to directly control an open file using the
780 ** [sqlite3_file_control()] interface. The second "op" argument is an
781 ** integer opcode. The third argument is a generic pointer intended to
@@ -13031,10 +13031,14 @@
13031 ** This API can be quite slow if used with an FTS5 table created with the
13032 ** "detail=none" or "detail=column" option. If the FTS5 table is created
13033 ** with either "detail=none" or "detail=column" and "content=" option
13034 ** (i.e. if it is a contentless table), then this API always iterates
13035 ** through an empty set (all calls to xPhraseFirst() set iCol to -1).
13036 **
13037 ** In all cases, matches are visited in (column ASC, offset ASC) order.
13038 ** i.e. all those in column 0, sorted by offset, followed by those in
13039 ** column 1, etc.
13040 **
13041 ** xPhraseNext()
13042 ** See xPhraseFirst above.
13043 **
13044 ** xPhraseFirstColumn()
13045

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button