Fossil SCM

Update the built-in SQLite to the latest trunk version for testing. Enable floating-point math functions in SQLite.

drh 2025-01-29 20:28 trunk
Commit 3ce667ae583477af82c6c07c7d685cf5f178154b249cd05561b27a6fa50d818e
+14 -7
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -355,10 +355,15 @@
355355
**
356356
** The default behavior, if neither of the above is defined is to
357357
** use O_U8TEXT when writing to the Windows console (or anything
358358
** else for which _isatty() returns true) and to use O_BINARY or O_TEXT
359359
** for all other output channels.
360
+**
361
+** The SQLITE_USE_W32_FOR_CONSOLE_IO macro is also available. If
362
+** defined, it forces the use of Win32 APIs for all console I/O, both
363
+** input and output. This is necessary for some non-Microsoft run-times
364
+** that implement stdio differently from Microsoft/Visual-Studio.
360365
*/
361366
#if defined(SQLITE_U8TEXT_ONLY)
362367
# define UseWtextForOutput(fd) 1
363368
# define UseWtextForInput(fd) 1
364369
# define IsConsole(fd) _isatty(_fileno(fd))
@@ -457,14 +462,14 @@
457462
** that into UTF-8. Otherwise, non-ASCII characters all get translated
458463
** into '?'.
459464
*/
460465
wchar_t *b1 = sqlite3_malloc( sz*sizeof(wchar_t) );
461466
if( b1==0 ) return 0;
462
-#ifndef SQLITE_USE_STDIO_FOR_CONSOLE
467
+#ifdef SQLITE_USE_W32_FOR_CONSOLE_IO
463468
DWORD nRead = 0;
464469
if( IsConsole(in)
465
- && ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE), b1, sz, &nRead, 0)
470
+ && ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE), b1, sz-1, &nRead, 0)
466471
){
467472
b1[nRead] = 0;
468473
}else
469474
#endif
470475
{
@@ -535,22 +540,23 @@
535540
wchar_t *b1 = sqlite3_malloc( (sz+1)*sizeof(wchar_t) );
536541
if( b1==0 ) return 0;
537542
sz = MultiByteToWideChar(CP_UTF8, 0, z, sz, b1, sz);
538543
b1[sz] = 0;
539544
540
-#ifndef SQLITE_STDIO_FOR_CONSOLE
545
+#ifdef SQLITE_USE_W32_FOR_CONSOLE_IO
541546
DWORD nWr = 0;
542547
if( IsConsole(out)
543548
&& WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE),b1,sz,&nWr,0)
544549
){
545550
/* If writing to the console, then the WriteConsoleW() is all we
546551
** need to do. */
547552
}else
548553
#endif
549554
{
550
- /* For non-console I/O, or if SQLITE_USE_STDIO_FOR_CONSOLE is defined
551
- ** then write using the standard library. */
555
+ /* As long as SQLITE_USE_W32_FOR_CONSOLE_IO is not defined, or for
556
+ ** non-console I/O even if that macro is defined, write using the
557
+ ** standard library. */
552558
_setmode(_fileno(out), _O_U8TEXT);
553559
if( UseBinaryWText(out) ){
554560
piecemealOutput(b1, sz, out);
555561
}else{
556562
fputws(b1, out);
@@ -5312,11 +5318,11 @@
53125318
case 2:
53135319
pOut[1] = (qv>>8) & 0xff;
53145320
deliberate_fall_through; /* FALLTHRU */
53155321
case 1:
53165322
pOut[0] = (qv>>16) & 0xff;
5317
- deliberate_fall_through; /* FALLTHRU */
5323
+ break;
53185324
}
53195325
pOut += nbo;
53205326
}
53215327
return pOut;
53225328
}
@@ -17197,11 +17203,11 @@
1719717203
*/
1719817204
static void vfstraceDlClose(sqlite3_vfs *pVfs, void *pHandle){
1719917205
vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
1720017206
sqlite3_vfs *pRoot = pInfo->pRootVfs;
1720117207
vfstraceOnOff(pInfo, VTR_DLCLOSE);
17202
- vfstrace_printf(pInfo, "%s.xDlOpen()\n", pInfo->zVfsName);
17208
+ vfstrace_printf(pInfo, "%s.xDlClose()\n", pInfo->zVfsName);
1720317209
pRoot->xDlClose(pRoot, pHandle);
1720417210
}
1720517211
1720617212
/*
1720717213
** Populate the buffer pointed to by zBufOut with nByte bytes of
@@ -31633,10 +31639,11 @@
3163331639
{ 0x01000000, 1, "IndexedEXpr" },
3163431640
{ 0x02000000, 1, "Coroutines" },
3163531641
{ 0x04000000, 1, "NullUnusedCols" },
3163631642
{ 0x08000000, 1, "OnePass" },
3163731643
{ 0x10000000, 1, "OrderBySubq" },
31644
+ { 0x20000000, 1, "StarQuery" },
3163831645
{ 0xffffffff, 0, "All" },
3163931646
};
3164031647
unsigned int curOpt;
3164131648
unsigned int newOpt;
3164231649
unsigned int m;
3164331650
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -355,10 +355,15 @@
355 **
356 ** The default behavior, if neither of the above is defined is to
357 ** use O_U8TEXT when writing to the Windows console (or anything
358 ** else for which _isatty() returns true) and to use O_BINARY or O_TEXT
359 ** for all other output channels.
 
 
 
 
 
360 */
361 #if defined(SQLITE_U8TEXT_ONLY)
362 # define UseWtextForOutput(fd) 1
363 # define UseWtextForInput(fd) 1
364 # define IsConsole(fd) _isatty(_fileno(fd))
@@ -457,14 +462,14 @@
457 ** that into UTF-8. Otherwise, non-ASCII characters all get translated
458 ** into '?'.
459 */
460 wchar_t *b1 = sqlite3_malloc( sz*sizeof(wchar_t) );
461 if( b1==0 ) return 0;
462 #ifndef SQLITE_USE_STDIO_FOR_CONSOLE
463 DWORD nRead = 0;
464 if( IsConsole(in)
465 && ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE), b1, sz, &nRead, 0)
466 ){
467 b1[nRead] = 0;
468 }else
469 #endif
470 {
@@ -535,22 +540,23 @@
535 wchar_t *b1 = sqlite3_malloc( (sz+1)*sizeof(wchar_t) );
536 if( b1==0 ) return 0;
537 sz = MultiByteToWideChar(CP_UTF8, 0, z, sz, b1, sz);
538 b1[sz] = 0;
539
540 #ifndef SQLITE_STDIO_FOR_CONSOLE
541 DWORD nWr = 0;
542 if( IsConsole(out)
543 && WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE),b1,sz,&nWr,0)
544 ){
545 /* If writing to the console, then the WriteConsoleW() is all we
546 ** need to do. */
547 }else
548 #endif
549 {
550 /* For non-console I/O, or if SQLITE_USE_STDIO_FOR_CONSOLE is defined
551 ** then write using the standard library. */
 
552 _setmode(_fileno(out), _O_U8TEXT);
553 if( UseBinaryWText(out) ){
554 piecemealOutput(b1, sz, out);
555 }else{
556 fputws(b1, out);
@@ -5312,11 +5318,11 @@
5312 case 2:
5313 pOut[1] = (qv>>8) & 0xff;
5314 deliberate_fall_through; /* FALLTHRU */
5315 case 1:
5316 pOut[0] = (qv>>16) & 0xff;
5317 deliberate_fall_through; /* FALLTHRU */
5318 }
5319 pOut += nbo;
5320 }
5321 return pOut;
5322 }
@@ -17197,11 +17203,11 @@
17197 */
17198 static void vfstraceDlClose(sqlite3_vfs *pVfs, void *pHandle){
17199 vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
17200 sqlite3_vfs *pRoot = pInfo->pRootVfs;
17201 vfstraceOnOff(pInfo, VTR_DLCLOSE);
17202 vfstrace_printf(pInfo, "%s.xDlOpen()\n", pInfo->zVfsName);
17203 pRoot->xDlClose(pRoot, pHandle);
17204 }
17205
17206 /*
17207 ** Populate the buffer pointed to by zBufOut with nByte bytes of
@@ -31633,10 +31639,11 @@
31633 { 0x01000000, 1, "IndexedEXpr" },
31634 { 0x02000000, 1, "Coroutines" },
31635 { 0x04000000, 1, "NullUnusedCols" },
31636 { 0x08000000, 1, "OnePass" },
31637 { 0x10000000, 1, "OrderBySubq" },
 
31638 { 0xffffffff, 0, "All" },
31639 };
31640 unsigned int curOpt;
31641 unsigned int newOpt;
31642 unsigned int m;
31643
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -355,10 +355,15 @@
355 **
356 ** The default behavior, if neither of the above is defined is to
357 ** use O_U8TEXT when writing to the Windows console (or anything
358 ** else for which _isatty() returns true) and to use O_BINARY or O_TEXT
359 ** for all other output channels.
360 **
361 ** The SQLITE_USE_W32_FOR_CONSOLE_IO macro is also available. If
362 ** defined, it forces the use of Win32 APIs for all console I/O, both
363 ** input and output. This is necessary for some non-Microsoft run-times
364 ** that implement stdio differently from Microsoft/Visual-Studio.
365 */
366 #if defined(SQLITE_U8TEXT_ONLY)
367 # define UseWtextForOutput(fd) 1
368 # define UseWtextForInput(fd) 1
369 # define IsConsole(fd) _isatty(_fileno(fd))
@@ -457,14 +462,14 @@
462 ** that into UTF-8. Otherwise, non-ASCII characters all get translated
463 ** into '?'.
464 */
465 wchar_t *b1 = sqlite3_malloc( sz*sizeof(wchar_t) );
466 if( b1==0 ) return 0;
467 #ifdef SQLITE_USE_W32_FOR_CONSOLE_IO
468 DWORD nRead = 0;
469 if( IsConsole(in)
470 && ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE), b1, sz-1, &nRead, 0)
471 ){
472 b1[nRead] = 0;
473 }else
474 #endif
475 {
@@ -535,22 +540,23 @@
540 wchar_t *b1 = sqlite3_malloc( (sz+1)*sizeof(wchar_t) );
541 if( b1==0 ) return 0;
542 sz = MultiByteToWideChar(CP_UTF8, 0, z, sz, b1, sz);
543 b1[sz] = 0;
544
545 #ifdef SQLITE_USE_W32_FOR_CONSOLE_IO
546 DWORD nWr = 0;
547 if( IsConsole(out)
548 && WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE),b1,sz,&nWr,0)
549 ){
550 /* If writing to the console, then the WriteConsoleW() is all we
551 ** need to do. */
552 }else
553 #endif
554 {
555 /* As long as SQLITE_USE_W32_FOR_CONSOLE_IO is not defined, or for
556 ** non-console I/O even if that macro is defined, write using the
557 ** standard library. */
558 _setmode(_fileno(out), _O_U8TEXT);
559 if( UseBinaryWText(out) ){
560 piecemealOutput(b1, sz, out);
561 }else{
562 fputws(b1, out);
@@ -5312,11 +5318,11 @@
5318 case 2:
5319 pOut[1] = (qv>>8) & 0xff;
5320 deliberate_fall_through; /* FALLTHRU */
5321 case 1:
5322 pOut[0] = (qv>>16) & 0xff;
5323 break;
5324 }
5325 pOut += nbo;
5326 }
5327 return pOut;
5328 }
@@ -17197,11 +17203,11 @@
17203 */
17204 static void vfstraceDlClose(sqlite3_vfs *pVfs, void *pHandle){
17205 vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
17206 sqlite3_vfs *pRoot = pInfo->pRootVfs;
17207 vfstraceOnOff(pInfo, VTR_DLCLOSE);
17208 vfstrace_printf(pInfo, "%s.xDlClose()\n", pInfo->zVfsName);
17209 pRoot->xDlClose(pRoot, pHandle);
17210 }
17211
17212 /*
17213 ** Populate the buffer pointed to by zBufOut with nByte bytes of
@@ -31633,10 +31639,11 @@
31639 { 0x01000000, 1, "IndexedEXpr" },
31640 { 0x02000000, 1, "Coroutines" },
31641 { 0x04000000, 1, "NullUnusedCols" },
31642 { 0x08000000, 1, "OnePass" },
31643 { 0x10000000, 1, "OrderBySubq" },
31644 { 0x20000000, 1, "StarQuery" },
31645 { 0xffffffff, 0, "All" },
31646 };
31647 unsigned int curOpt;
31648 unsigned int newOpt;
31649 unsigned int m;
31650
+483 -256
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.48.0. By combining all the individual C code files into this
3
+** version 3.49.0. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -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
-** d2fe6b05f38d9d7cd78c5d252e99ac59f1ae with changes in files:
21
+** d7c07581203a0a88456588e49e51b40a8341 with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -463,13 +463,13 @@
463463
**
464464
** See also: [sqlite3_libversion()],
465465
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466466
** [sqlite_version()] and [sqlite_source_id()].
467467
*/
468
-#define SQLITE_VERSION "3.48.0"
469
-#define SQLITE_VERSION_NUMBER 3048000
470
-#define SQLITE_SOURCE_ID "2025-01-14 11:05:00 d2fe6b05f38d9d7cd78c5d252e99ac59f1aea071d669830c1ffe4e8966e84010"
468
+#define SQLITE_VERSION "3.49.0"
469
+#define SQLITE_VERSION_NUMBER 3049000
470
+#define SQLITE_SOURCE_ID "2025-01-29 18:53:19 d7c07581203a0a88456588e49e51b40a8341b0e7121809f75be0ee882d91650f"
471471
472472
/*
473473
** CAPI3REF: Run-Time Library Version Numbers
474474
** KEYWORDS: sqlite3_version sqlite3_sourceid
475475
**
@@ -11065,12 +11065,13 @@
1106511065
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
1106611066
1106711067
/*
1106811068
** CAPI3REF: Serialize a database
1106911069
**
11070
-** The sqlite3_serialize(D,S,P,F) interface returns a pointer to memory
11071
-** that is a serialization of the S database on [database connection] D.
11070
+** The sqlite3_serialize(D,S,P,F) interface returns a pointer to
11071
+** memory that is a serialization of the S database on
11072
+** [database connection] D. If S is a NULL pointer, the main database is used.
1107211073
** If P is not a NULL pointer, then the size of the database in bytes
1107311074
** is written into *P.
1107411075
**
1107511076
** For an ordinary on-disk database file, the serialization is just a
1107611077
** copy of the disk file. For an in-memory database or a "TEMP" database,
@@ -15127,10 +15128,12 @@
1512715128
** Examples:
1512815129
**
1512915130
** 0.5 -> -10 0.1 -> -33 0.0625 -> -40
1513015131
*/
1513115132
typedef INT16_TYPE LogEst;
15133
+#define LOGEST_MIN (-32768)
15134
+#define LOGEST_MAX (32767)
1513215135
1513315136
/*
1513415137
** Set the SQLITE_PTRSIZE macro to the number of bytes in a pointer
1513515138
*/
1513615139
#ifndef SQLITE_PTRSIZE
@@ -15397,11 +15400,11 @@
1539715400
** 0x-------F High-level debug messages
1539815401
** 0x----FFF- More detail
1539915402
** 0xFFFF---- Low-level debug messages
1540015403
**
1540115404
** 0x00000001 Code generation
15402
-** 0x00000002 Solver
15405
+** 0x00000002 Solver (Use 0x40000 for less detail)
1540315406
** 0x00000004 Solver costs
1540415407
** 0x00000008 WhereLoop inserts
1540515408
**
1540615409
** 0x00000010 Display sqlite3_index_info xBestIndex calls
1540715410
** 0x00000020 Range an equality scan metrics
@@ -15416,10 +15419,12 @@
1541615419
** 0x00004000 Show all WHERE terms at key points
1541715420
** 0x00008000 Show the full SELECT statement at key places
1541815421
**
1541915422
** 0x00010000 Show more detail when printing WHERE terms
1542015423
** 0x00020000 Show WHERE terms returned from whereScanNext()
15424
+** 0x00040000 Solver overview messages
15425
+** 0x00080000 Star-query heuristic
1542115426
*/
1542215427
1542315428
1542415429
/*
1542515430
** An instance of the following structure is used to store the busy-handler
@@ -18097,10 +18102,11 @@
1809718102
#define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
1809818103
#define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
1809918104
#define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
1810018105
#define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
1810118106
#define SQLITE_OrderBySubq 0x10000000 /* ORDER BY in subquery helps outer */
18107
+#define SQLITE_StarQuery 0x20000000 /* Heurists for star queries */
1810218108
#define SQLITE_AllOpts 0xffffffff /* All optimizations */
1810318109
1810418110
/*
1810518111
** Macros for testing whether or not optimizations are enabled or disabled.
1810618112
*/
@@ -19426,17 +19432,12 @@
1942619432
**
1942719433
** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
1942819434
*/
1942919435
struct IdList {
1943019436
int nId; /* Number of identifiers on the list */
19431
- u8 eU4; /* Which element of a.u4 is valid */
1943219437
struct IdList_item {
1943319438
char *zName; /* Name of the identifier */
19434
- union {
19435
- int idx; /* Index in some Table.aCol[] of a column named zName */
19436
- Expr *pExpr; /* Expr to implement a USING variable -- NOT USED */
19437
- } u4;
1943819439
} a[1];
1943919440
};
1944019441
1944119442
/*
1944219443
** Allowed values for IdList.eType, which determines which value of the a.u4
@@ -23579,10 +23580,11 @@
2357923580
char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
2358023581
void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
2358123582
#ifdef SQLITE_DEBUG
2358223583
Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
2358323584
u16 mScopyFlags; /* flags value immediately after the shallow copy */
23585
+ u8 bScopy; /* The pScopyFrom of some other Mem *might* point here */
2358423586
#endif
2358523587
};
2358623588
2358723589
/*
2358823590
** Size of struct Mem not including the Mem.zMalloc member or anything that
@@ -24677,10 +24679,13 @@
2467724679
ms = ms*10.0 + *zDate - '0';
2467824680
rScale *= 10.0;
2467924681
zDate++;
2468024682
}
2468124683
ms /= rScale;
24684
+ /* Truncate to avoid problems with sub-milliseconds
24685
+ ** rounding. https://sqlite.org/forum/forumpost/766a2c9231 */
24686
+ if( ms>0.999 ) ms = 0.999;
2468224687
}
2468324688
}else{
2468424689
s = 0;
2468524690
}
2468624691
p->validJD = 0;
@@ -25884,11 +25889,11 @@
2588425889
sqlite3_str_appendf(&sRes, cf=='d' ? "%02d" : "%2d", x.D);
2588525890
break;
2588625891
}
2588725892
case 'f': { /* Fractional seconds. (Non-standard) */
2588825893
double s = x.s;
25889
- if( s>59.999 ) s = 59.999;
25894
+ if( NEVER(s>59.999) ) s = 59.999;
2589025895
sqlite3_str_appendf(&sRes, "%06.3f", s);
2589125896
break;
2589225897
}
2589325898
case 'F': {
2589425899
sqlite3_str_appendf(&sRes, "%04d-%02d-%02d", x.Y, x.M, x.D);
@@ -33815,25 +33820,11 @@
3381533820
char *zName = pList->a[i].zName;
3381633821
int moreToFollow = i<pList->nId - 1;
3381733822
if( zName==0 ) zName = "(null)";
3381833823
sqlite3TreeViewPush(&pView, moreToFollow);
3381933824
sqlite3TreeViewLine(pView, 0);
33820
- if( pList->eU4==EU4_NONE ){
33821
- fprintf(stdout, "%s\n", zName);
33822
- }else if( pList->eU4==EU4_IDX ){
33823
- fprintf(stdout, "%s (%d)\n", zName, pList->a[i].u4.idx);
33824
- }else{
33825
- assert( pList->eU4==EU4_EXPR );
33826
- if( pList->a[i].u4.pExpr==0 ){
33827
- fprintf(stdout, "%s (pExpr=NULL)\n", zName);
33828
- }else{
33829
- fprintf(stdout, "%s\n", zName);
33830
- sqlite3TreeViewPush(&pView, i<pList->nId-1);
33831
- sqlite3TreeViewExpr(pView, pList->a[i].u4.pExpr, 0);
33832
- sqlite3TreeViewPop(&pView);
33833
- }
33834
- }
33825
+ fprintf(stdout, "%s\n", zName);
3383533826
sqlite3TreeViewPop(&pView);
3383633827
}
3383733828
}
3383833829
}
3383933830
SQLITE_PRIVATE void sqlite3TreeViewIdList(
@@ -40170,11 +40161,11 @@
4017040161
assert( pInode!=0 );
4017140162
assert( sqlite3_mutex_held(pInode->pLockMutex) );
4017240163
if( (pFile->ctrlFlags & (UNIXFILE_EXCL|UNIXFILE_RDONLY))==UNIXFILE_EXCL ){
4017340164
if( pInode->bProcessLock==0 ){
4017440165
struct flock lock;
40175
- assert( pInode->nLock==0 );
40166
+ /* assert( pInode->nLock==0 ); <-- Not true if unix-excl READONLY used */
4017640167
lock.l_whence = SEEK_SET;
4017740168
lock.l_start = SHARED_FIRST;
4017840169
lock.l_len = SHARED_SIZE;
4017940170
lock.l_type = F_WRLCK;
4018040171
rc = osSetPosixAdvisoryLock(pFile->h, &lock, pFile);
@@ -58053,11 +58044,11 @@
5805358044
if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0; /* Failed (3) */
5805458045
#ifndef SQLITE_OMIT_WAL
5805558046
if( pPager->pWal ){
5805658047
u32 iRead = 0;
5805758048
(void)sqlite3WalFindFrame(pPager->pWal, pgno, &iRead);
58058
- return iRead==0; /* Condition (4) */
58049
+ if( iRead ) return 0; /* Case (4) */
5805958050
}
5806058051
#endif
5806158052
assert( pPager->fd->pMethods->xDeviceCharacteristics!=0 );
5806258053
if( (pPager->fd->pMethods->xDeviceCharacteristics(pPager->fd)
5806358054
& SQLITE_IOCAP_SUBPAGE_READ)==0 ){
@@ -84001,31 +83992,34 @@
8400183992
** copies (created by OP_SCopy) are not misused.
8400283993
*/
8400383994
SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){
8400483995
int i;
8400583996
Mem *pX;
84006
- for(i=1, pX=pVdbe->aMem+1; i<pVdbe->nMem; i++, pX++){
84007
- if( pX->pScopyFrom==pMem ){
84008
- u16 mFlags;
84009
- if( pVdbe->db->flags & SQLITE_VdbeTrace ){
84010
- sqlite3DebugPrintf("Invalidate R[%d] due to change in R[%d]\n",
84011
- (int)(pX - pVdbe->aMem), (int)(pMem - pVdbe->aMem));
84012
- }
84013
- /* If pX is marked as a shallow copy of pMem, then try to verify that
84014
- ** no significant changes have been made to pX since the OP_SCopy.
84015
- ** A significant change would indicated a missed call to this
84016
- ** function for pX. Minor changes, such as adding or removing a
84017
- ** dual type, are allowed, as long as the underlying value is the
84018
- ** same. */
84019
- mFlags = pMem->flags & pX->flags & pX->mScopyFlags;
84020
- assert( (mFlags&(MEM_Int|MEM_IntReal))==0 || pMem->u.i==pX->u.i );
84021
-
84022
- /* pMem is the register that is changing. But also mark pX as
84023
- ** undefined so that we can quickly detect the shallow-copy error */
84024
- pX->flags = MEM_Undefined;
84025
- pX->pScopyFrom = 0;
84026
- }
83997
+ if( pMem->bScopy ){
83998
+ for(i=1, pX=pVdbe->aMem+1; i<pVdbe->nMem; i++, pX++){
83999
+ if( pX->pScopyFrom==pMem ){
84000
+ u16 mFlags;
84001
+ if( pVdbe->db->flags & SQLITE_VdbeTrace ){
84002
+ sqlite3DebugPrintf("Invalidate R[%d] due to change in R[%d]\n",
84003
+ (int)(pX - pVdbe->aMem), (int)(pMem - pVdbe->aMem));
84004
+ }
84005
+ /* If pX is marked as a shallow copy of pMem, then try to verify that
84006
+ ** no significant changes have been made to pX since the OP_SCopy.
84007
+ ** A significant change would indicated a missed call to this
84008
+ ** function for pX. Minor changes, such as adding or removing a
84009
+ ** dual type, are allowed, as long as the underlying value is the
84010
+ ** same. */
84011
+ mFlags = pMem->flags & pX->flags & pX->mScopyFlags;
84012
+ assert( (mFlags&(MEM_Int|MEM_IntReal))==0 || pMem->u.i==pX->u.i );
84013
+
84014
+ /* pMem is the register that is changing. But also mark pX as
84015
+ ** undefined so that we can quickly detect the shallow-copy error */
84016
+ pX->flags = MEM_Undefined;
84017
+ pX->pScopyFrom = 0;
84018
+ }
84019
+ }
84020
+ pMem->bScopy = 0;
8402784021
}
8402884022
pMem->pScopyFrom = 0;
8402984023
}
8403084024
#endif /* SQLITE_DEBUG */
8403184025
@@ -87163,10 +87157,11 @@
8716387157
p->flags = flags;
8716487158
p->db = db;
8716587159
p->szMalloc = 0;
8716687160
#ifdef SQLITE_DEBUG
8716787161
p->pScopyFrom = 0;
87162
+ p->bScopy = 0;
8716887163
#endif
8716987164
p++;
8717087165
}while( (--N)>0 );
8717187166
}
8717287167
}
@@ -91348,11 +91343,11 @@
9134891343
if( db->nVdbeActive==0 ){
9134991344
AtomicStore(&db->u1.isInterrupted, 0);
9135091345
}
9135191346
9135291347
assert( db->nVdbeWrite>0 || db->autoCommit==0
91353
- || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
91348
+ || ((db->nDeferredCons + db->nDeferredImmCons)==0)
9135491349
);
9135591350
9135691351
#ifndef SQLITE_OMIT_TRACE
9135791352
if( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0
9135891353
&& !db->init.busy && p->zSql ){
@@ -91859,10 +91854,11 @@
9185991854
/* .zMalloc = */ (char*)0,
9186091855
/* .xDel = */ (void(*)(void*))0,
9186191856
#ifdef SQLITE_DEBUG
9186291857
/* .pScopyFrom = */ (Mem*)0,
9186391858
/* .mScopyFlags= */ 0,
91859
+ /* .bScopy = */ 0,
9186491860
#endif
9186591861
};
9186691862
return &nullMem;
9186791863
}
9186891864
@@ -92741,10 +92737,11 @@
9274192737
*/
9274292738
SQLITE_API int sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
9274392739
PreUpdate *p;
9274492740
Mem *pMem;
9274592741
int rc = SQLITE_OK;
92742
+ int iStore = 0;
9274692743
9274792744
#ifdef SQLITE_ENABLE_API_ARMOR
9274892745
if( db==0 || ppValue==0 ){
9274992746
return SQLITE_MISUSE_BKPT;
9275092747
}
@@ -92755,13 +92752,15 @@
9275592752
if( !p || p->op==SQLITE_INSERT ){
9275692753
rc = SQLITE_MISUSE_BKPT;
9275792754
goto preupdate_old_out;
9275892755
}
9275992756
if( p->pPk ){
92760
- iIdx = sqlite3TableColumnToIndex(p->pPk, iIdx);
92757
+ iStore = sqlite3TableColumnToIndex(p->pPk, iIdx);
92758
+ }else{
92759
+ iStore = sqlite3TableColumnToStorage(p->pTab, iIdx);
9276192760
}
92762
- if( iIdx>=p->pCsr->nField || iIdx<0 ){
92761
+ if( iStore>=p->pCsr->nField || iStore<0 ){
9276392762
rc = SQLITE_RANGE;
9276492763
goto preupdate_old_out;
9276592764
}
9276692765
9276792766
if( iIdx==p->pTab->iPKey ){
@@ -92788,12 +92787,12 @@
9278892787
goto preupdate_old_out;
9278992788
}
9279092789
p->aRecord = aRec;
9279192790
}
9279292791
92793
- pMem = *ppValue = &p->pUnpacked->aMem[iIdx];
92794
- if( iIdx>=p->pUnpacked->nField ){
92792
+ pMem = *ppValue = &p->pUnpacked->aMem[iStore];
92793
+ if( iStore>=p->pUnpacked->nField ){
9279592794
/* This occurs when the table has been extended using ALTER TABLE
9279692795
** ADD COLUMN. The value to return is the default value of the column. */
9279792796
Column *pCol = &p->pTab->aCol[iIdx];
9279892797
if( pCol->iDflt>0 ){
9279992798
if( p->apDflt==0 ){
@@ -92893,10 +92892,11 @@
9289392892
*/
9289492893
SQLITE_API int sqlite3_preupdate_new(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
9289592894
PreUpdate *p;
9289692895
int rc = SQLITE_OK;
9289792896
Mem *pMem;
92897
+ int iStore = 0;
9289892898
9289992899
#ifdef SQLITE_ENABLE_API_ARMOR
9290092900
if( db==0 || ppValue==0 ){
9290192901
return SQLITE_MISUSE_BKPT;
9290292902
}
@@ -92905,13 +92905,16 @@
9290592905
if( !p || p->op==SQLITE_DELETE ){
9290692906
rc = SQLITE_MISUSE_BKPT;
9290792907
goto preupdate_new_out;
9290892908
}
9290992909
if( p->pPk && p->op!=SQLITE_UPDATE ){
92910
- iIdx = sqlite3TableColumnToIndex(p->pPk, iIdx);
92910
+ iStore = sqlite3TableColumnToIndex(p->pPk, iIdx);
92911
+ }else{
92912
+ iStore = sqlite3TableColumnToStorage(p->pTab, iIdx);
9291192913
}
92912
- if( iIdx>=p->pCsr->nField || iIdx<0 ){
92914
+
92915
+ if( iStore>=p->pCsr->nField || iStore<0 ){
9291392916
rc = SQLITE_RANGE;
9291492917
goto preupdate_new_out;
9291592918
}
9291692919
9291792920
if( p->op==SQLITE_INSERT ){
@@ -92927,18 +92930,18 @@
9292792930
rc = SQLITE_NOMEM;
9292892931
goto preupdate_new_out;
9292992932
}
9293092933
p->pNewUnpacked = pUnpack;
9293192934
}
92932
- pMem = &pUnpack->aMem[iIdx];
92935
+ pMem = &pUnpack->aMem[iStore];
9293392936
if( iIdx==p->pTab->iPKey ){
9293492937
sqlite3VdbeMemSetInt64(pMem, p->iKey2);
92935
- }else if( iIdx>=pUnpack->nField ){
92938
+ }else if( iStore>=pUnpack->nField ){
9293692939
pMem = (sqlite3_value *)columnNullValue();
9293792940
}
9293892941
}else{
92939
- /* For an UPDATE, memory cell (p->iNewReg+1+iIdx) contains the required
92942
+ /* For an UPDATE, memory cell (p->iNewReg+1+iStore) contains the required
9294092943
** value. Make a copy of the cell contents and return a pointer to it.
9294192944
** It is not safe to return a pointer to the memory cell itself as the
9294292945
** caller may modify the value text encoding.
9294392946
*/
9294492947
assert( p->op==SQLITE_UPDATE );
@@ -92947,17 +92950,17 @@
9294792950
if( !p->aNew ){
9294892951
rc = SQLITE_NOMEM;
9294992952
goto preupdate_new_out;
9295092953
}
9295192954
}
92952
- assert( iIdx>=0 && iIdx<p->pCsr->nField );
92953
- pMem = &p->aNew[iIdx];
92955
+ assert( iStore>=0 && iStore<p->pCsr->nField );
92956
+ pMem = &p->aNew[iStore];
9295492957
if( pMem->flags==0 ){
9295592958
if( iIdx==p->pTab->iPKey ){
9295692959
sqlite3VdbeMemSetInt64(pMem, p->iKey2);
9295792960
}else{
92958
- rc = sqlite3VdbeMemCopy(pMem, &p->v->aMem[p->iNewReg+1+iIdx]);
92961
+ rc = sqlite3VdbeMemCopy(pMem, &p->v->aMem[p->iNewReg+1+iStore]);
9295992962
if( rc!=SQLITE_OK ) goto preupdate_new_out;
9296092963
}
9296192964
}
9296292965
}
9296392966
*ppValue = pMem;
@@ -94042,10 +94045,11 @@
9404294045
}
9404394046
static void registerTrace(int iReg, Mem *p){
9404494047
printf("R[%d] = ", iReg);
9404594048
memTracePrint(p);
9404694049
if( p->pScopyFrom ){
94050
+ assert( p->pScopyFrom->bScopy );
9404794051
printf(" <== R[%d]", (int)(p->pScopyFrom - &p[-iReg]));
9404894052
}
9404994053
printf("\n");
9405094054
sqlite3VdbeCheckMemInvariants(p);
9405194055
}
@@ -95025,10 +95029,11 @@
9502595029
#ifdef SQLITE_DEBUG
9502695030
pIn1->pScopyFrom = 0;
9502795031
{ int i;
9502895032
for(i=1; i<p->nMem; i++){
9502995033
if( aMem[i].pScopyFrom==pIn1 ){
95034
+ assert( aMem[i].bScopy );
9503095035
aMem[i].pScopyFrom = pOut;
9503195036
}
9503295037
}
9503395038
}
9503495039
#endif
@@ -95097,10 +95102,11 @@
9509795102
assert( pOut!=pIn1 );
9509895103
sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
9509995104
#ifdef SQLITE_DEBUG
9510095105
pOut->pScopyFrom = pIn1;
9510195106
pOut->mScopyFlags = pIn1->flags;
95107
+ pIn1->bScopy = 1;
9510295108
#endif
9510395109
break;
9510495110
}
9510595111
9510695112
/* Opcode: IntCopy P1 P2 * * *
@@ -111360,20 +111366,17 @@
111360111366
SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3 *db, const IdList *p){
111361111367
IdList *pNew;
111362111368
int i;
111363111369
assert( db!=0 );
111364111370
if( p==0 ) return 0;
111365
- assert( p->eU4!=EU4_EXPR );
111366111371
pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew)+(p->nId-1)*sizeof(p->a[0]) );
111367111372
if( pNew==0 ) return 0;
111368111373
pNew->nId = p->nId;
111369
- pNew->eU4 = p->eU4;
111370111374
for(i=0; i<p->nId; i++){
111371111375
struct IdList_item *pNewItem = &pNew->a[i];
111372111376
const struct IdList_item *pOldItem = &p->a[i];
111373111377
pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
111374
- pNewItem->u4 = pOldItem->u4;
111375111378
}
111376111379
return pNew;
111377111380
}
111378111381
SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, const Select *pDup, int flags){
111379111382
Select *pRet = 0;
@@ -126726,11 +126729,10 @@
126726126729
*/
126727126730
SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
126728126731
int i;
126729126732
assert( db!=0 );
126730126733
if( pList==0 ) return;
126731
- assert( pList->eU4!=EU4_EXPR ); /* EU4_EXPR mode is not currently used */
126732126734
for(i=0; i<pList->nId; i++){
126733126735
sqlite3DbFree(db, pList->a[i].zName);
126734126736
}
126735126737
sqlite3DbNNFreeNN(db, pList);
126736126738
}
@@ -128107,16 +128109,22 @@
128107128109
FuncDef *p, /* The function we are evaluating for match quality */
128108128110
int nArg, /* Desired number of arguments. (-1)==any */
128109128111
u8 enc /* Desired text encoding */
128110128112
){
128111128113
int match;
128112
- assert( p->nArg>=-1 );
128114
+ assert( p->nArg>=(-4) && p->nArg!=(-2) );
128115
+ assert( nArg>=(-2) );
128113128116
128114128117
/* Wrong number of arguments means "no match" */
128115128118
if( p->nArg!=nArg ){
128116
- if( nArg==(-2) ) return (p->xSFunc==0) ? 0 : FUNC_PERFECT_MATCH;
128119
+ if( nArg==(-2) ) return p->xSFunc==0 ? 0 : FUNC_PERFECT_MATCH;
128117128120
if( p->nArg>=0 ) return 0;
128121
+ /* Special p->nArg values available to built-in functions only:
128122
+ ** -3 1 or more arguments required
128123
+ ** -4 2 or more arguments required
128124
+ */
128125
+ if( p->nArg<(-2) && nArg<(-2-p->nArg) ) return 0;
128118128126
}
128119128127
128120128128
/* Give a better score to a function with a specific number of arguments
128121128129
** than to function that accepts any number of arguments. */
128122128130
if( p->nArg==nArg ){
@@ -132076,16 +132084,14 @@
132076132084
FUNCTION(ltrim, 2, 1, 0, trimFunc ),
132077132085
FUNCTION(rtrim, 1, 2, 0, trimFunc ),
132078132086
FUNCTION(rtrim, 2, 2, 0, trimFunc ),
132079132087
FUNCTION(trim, 1, 3, 0, trimFunc ),
132080132088
FUNCTION(trim, 2, 3, 0, trimFunc ),
132081
- FUNCTION(min, -1, 0, 1, minmaxFunc ),
132082
- FUNCTION(min, 0, 0, 1, 0 ),
132089
+ FUNCTION(min, -3, 0, 1, minmaxFunc ),
132083132090
WAGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
132084132091
SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ),
132085
- FUNCTION(max, -1, 1, 1, minmaxFunc ),
132086
- FUNCTION(max, 0, 1, 1, 0 ),
132092
+ FUNCTION(max, -3, 1, 1, minmaxFunc ),
132087132093
WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
132088132094
SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ),
132089132095
FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
132090132096
FUNCTION2(subtype, 1, 0, 0, subtypeFunc,
132091132097
SQLITE_FUNC_TYPEOF|SQLITE_SUBTYPE),
@@ -132108,15 +132114,12 @@
132108132114
FUNCTION(upper, 1, 0, 0, upperFunc ),
132109132115
FUNCTION(lower, 1, 0, 0, lowerFunc ),
132110132116
FUNCTION(hex, 1, 0, 0, hexFunc ),
132111132117
FUNCTION(unhex, 1, 0, 0, unhexFunc ),
132112132118
FUNCTION(unhex, 2, 0, 0, unhexFunc ),
132113
- FUNCTION(concat, -1, 0, 0, concatFunc ),
132114
- FUNCTION(concat, 0, 0, 0, 0 ),
132115
- FUNCTION(concat_ws, -1, 0, 0, concatwsFunc ),
132116
- FUNCTION(concat_ws, 0, 0, 0, 0 ),
132117
- FUNCTION(concat_ws, 1, 0, 0, 0 ),
132119
+ FUNCTION(concat, -3, 0, 0, concatFunc ),
132120
+ FUNCTION(concat_ws, -4, 0, 0, concatwsFunc ),
132118132121
INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, 0 ),
132119132122
VFUNCTION(random, 0, 0, 0, randomFunc ),
132120132123
VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
132121132124
FUNCTION(nullif, 2, 0, 1, nullifFunc ),
132122132125
DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
@@ -132156,12 +132159,10 @@
132156132159
LIKEFUNC(like, 3, &likeInfoNorm, SQLITE_FUNC_LIKE),
132157132160
#endif
132158132161
#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
132159132162
FUNCTION(unknown, -1, 0, 0, unknownFunc ),
132160132163
#endif
132161
- FUNCTION(coalesce, 1, 0, 0, 0 ),
132162
- FUNCTION(coalesce, 0, 0, 0, 0 ),
132163132164
#ifdef SQLITE_ENABLE_MATH_FUNCTIONS
132164132165
MFUNCTION(ceil, 1, xCeil, ceilingFunc ),
132165132166
MFUNCTION(ceiling, 1, xCeil, ceilingFunc ),
132166132167
MFUNCTION(floor, 1, xFloor, ceilingFunc ),
132167132168
#if SQLITE_HAVE_C99_MATH_FUNCS
@@ -132195,15 +132196,13 @@
132195132196
MFUNCTION(radians, 1, degToRad, math1Func ),
132196132197
MFUNCTION(degrees, 1, radToDeg, math1Func ),
132197132198
MFUNCTION(pi, 0, 0, piFunc ),
132198132199
#endif /* SQLITE_ENABLE_MATH_FUNCTIONS */
132199132200
FUNCTION(sign, 1, 0, 0, signFunc ),
132200
- INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, 0 ),
132201
- INLINE_FUNC(iif, 2, INLINEFUNC_iif, 0 ),
132202
- INLINE_FUNC(iif, 3, INLINEFUNC_iif, 0 ),
132203
- INLINE_FUNC(if, 2, INLINEFUNC_iif, 0 ),
132204
- INLINE_FUNC(if, 3, INLINEFUNC_iif, 0 ),
132201
+ INLINE_FUNC(coalesce, -4, INLINEFUNC_coalesce, 0 ),
132202
+ INLINE_FUNC(iif, -4, INLINEFUNC_iif, 0 ),
132203
+ INLINE_FUNC(if, -4, INLINEFUNC_iif, 0 ),
132205132204
};
132206132205
#ifndef SQLITE_OMIT_ALTERTABLE
132207132206
sqlite3AlterFunctions();
132208132207
#endif
132209132208
sqlite3WindowFunctions();
@@ -134645,10 +134644,11 @@
134645134644
int regRowCount = 0; /* Memory cell used for the row counter */
134646134645
int regIns; /* Block of regs holding rowid+data being inserted */
134647134646
int regRowid; /* registers holding insert rowid */
134648134647
int regData; /* register holding first column to insert */
134649134648
int *aRegIdx = 0; /* One register allocated to each index */
134649
+ int *aTabColMap = 0; /* Mapping from pTab columns to pCol entries */
134650134650
134651134651
#ifndef SQLITE_OMIT_TRIGGER
134652134652
int isView; /* True if attempting to insert into a view */
134653134653
Trigger *pTrigger; /* List of triggers on pTab, if required */
134654134654
int tmask; /* Mask of trigger times */
@@ -134789,19 +134789,19 @@
134789134789
** columns into storage order. False negatives are harmless,
134790134790
** but false positives will cause database corruption.
134791134791
*/
134792134792
bIdListInOrder = (pTab->tabFlags & (TF_OOOHidden|TF_HasStored))==0;
134793134793
if( pColumn ){
134794
- assert( pColumn->eU4!=EU4_EXPR );
134795
- pColumn->eU4 = EU4_IDX;
134796
- for(i=0; i<pColumn->nId; i++){
134797
- pColumn->a[i].u4.idx = -1;
134798
- }
134799
- for(i=0; i<pColumn->nId; i++){
134800
- for(j=0; j<pTab->nCol; j++){
134801
- if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zCnName)==0 ){
134802
- pColumn->a[i].u4.idx = j;
134794
+ aTabColMap = sqlite3DbMallocZero(db, pTab->nCol*sizeof(int));
134795
+ if( aTabColMap==0 ) goto insert_cleanup;
134796
+ for(i=0; i<pColumn->nId; i++){
134797
+ const char *zCName = pColumn->a[i].zName;
134798
+ u8 hName = sqlite3StrIHash(zCName);
134799
+ for(j=0; j<pTab->nCol; j++){
134800
+ if( pTab->aCol[j].hName!=hName ) continue;
134801
+ if( sqlite3StrICmp(zCName, pTab->aCol[j].zCnName)==0 ){
134802
+ if( aTabColMap[j]==0 ) aTabColMap[j] = i+1;
134803134803
if( i!=j ) bIdListInOrder = 0;
134804134804
if( j==pTab->iPKey ){
134805134805
ipkColumn = i; assert( !withoutRowid );
134806134806
}
134807134807
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
@@ -135119,21 +135119,21 @@
135119135119
iRegStore);
135120135120
continue;
135121135121
}
135122135122
}
135123135123
if( pColumn ){
135124
- assert( pColumn->eU4==EU4_IDX );
135125
- for(j=0; j<pColumn->nId && pColumn->a[j].u4.idx!=i; j++){}
135126
- if( j>=pColumn->nId ){
135124
+ j = aTabColMap[i];
135125
+ assert( j>=0 && j<=pColumn->nId );
135126
+ if( j==0 ){
135127135127
/* A column not named in the insert column list gets its
135128135128
** default value */
135129135129
sqlite3ExprCodeFactorable(pParse,
135130135130
sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
135131135131
iRegStore);
135132135132
continue;
135133135133
}
135134
- k = j;
135134
+ k = j - 1;
135135135135
}else if( nColumn==0 ){
135136135136
/* This is INSERT INTO ... DEFAULT VALUES. Load the default value. */
135137135137
sqlite3ExprCodeFactorable(pParse,
135138135138
sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
135139135139
iRegStore);
@@ -135374,11 +135374,14 @@
135374135374
insert_cleanup:
135375135375
sqlite3SrcListDelete(db, pTabList);
135376135376
sqlite3ExprListDelete(db, pList);
135377135377
sqlite3UpsertDelete(db, pUpsert);
135378135378
sqlite3SelectDelete(db, pSelect);
135379
- sqlite3IdListDelete(db, pColumn);
135379
+ if( pColumn ){
135380
+ sqlite3IdListDelete(db, pColumn);
135381
+ sqlite3DbFree(db, aTabColMap);
135382
+ }
135380135383
if( aRegIdx ) sqlite3DbNNFreeNN(db, aRegIdx);
135381135384
}
135382135385
135383135386
/* Make sure "isView" and other macros defined above are undefined. Otherwise
135384135387
** they may interfere with compilation of other functions in this file
@@ -157961,12 +157964,14 @@
157961157964
u16 nLTerm; /* Number of entries in aLTerm[] */
157962157965
u16 nSkip; /* Number of NULL aLTerm[] entries */
157963157966
/**** whereLoopXfer() copies fields above ***********************/
157964157967
# define WHERE_LOOP_XFER_SZ offsetof(WhereLoop,nLSlot)
157965157968
u16 nLSlot; /* Number of slots allocated for aLTerm[] */
157969
+#ifdef WHERETRACE_ENABLED
157966157970
LogEst rStarDelta; /* Cost delta due to star-schema heuristic. Not
157967
- ** initialized unless pWInfo->nOutStarDelta>0 */
157971
+ ** initialized unless pWInfo->bStarUsed */
157972
+#endif
157968157973
WhereTerm **aLTerm; /* WhereTerms used */
157969157974
WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */
157970157975
WhereTerm *aLTermSpace[3]; /* Initial aLTerm[] space */
157971157976
};
157972157977
@@ -158011,11 +158016,11 @@
158011158016
struct WherePath {
158012158017
Bitmask maskLoop; /* Bitmask of all WhereLoop objects in this path */
158013158018
Bitmask revLoop; /* aLoop[]s that should be reversed for ORDER BY */
158014158019
LogEst nRow; /* Estimated number of rows generated by this path */
158015158020
LogEst rCost; /* Total cost of this path */
158016
- LogEst rUnsorted; /* Total cost of this path ignoring sorting costs */
158021
+ LogEst rUnsort; /* Total cost of this path ignoring sorting costs */
158017158022
i8 isOrdered; /* No. of ORDER BY terms satisfied. -1 for unknown */
158018158023
WhereLoop **aLoop; /* Array of WhereLoop objects implementing this path */
158019158024
};
158020158025
158021158026
/*
@@ -158284,13 +158289,17 @@
158284158289
u8 eOnePass; /* ONEPASS_OFF, or _SINGLE, or _MULTI */
158285158290
u8 eDistinct; /* One of the WHERE_DISTINCT_* values */
158286158291
unsigned bDeferredSeek :1; /* Uses OP_DeferredSeek */
158287158292
unsigned untestedTerms :1; /* Not all WHERE terms resolved by outer loop */
158288158293
unsigned bOrderedInnerLoop:1;/* True if only the inner-most loop is ordered */
158289
- unsigned sorted :1; /* True if really sorted (not just grouped) */
158290
- LogEst nOutStarDelta; /* Artifical nOut reduction for star-query */
158294
+ unsigned sorted :1; /* True if really sorted (not just grouped) */
158295
+ unsigned bStarDone :1; /* True if check for star-query is complete */
158296
+ unsigned bStarUsed :1; /* True if star-query heuristic is used */
158291158297
LogEst nRowOut; /* Estimated number of output rows */
158298
+#ifdef WHERETRACE_ENABLED
158299
+ LogEst rTotalCost; /* Total cost of the solution */
158300
+#endif
158292158301
int iTop; /* The very beginning of the WHERE loop */
158293158302
int iEndWhere; /* End of the WHERE clause itself */
158294158303
WhereLoop *pLoops; /* List of all WhereLoop objects */
158295158304
WhereMemBlock *pMemToFree;/* Memory to free when this object destroyed */
158296158305
Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
@@ -164232,11 +164241,11 @@
164232164241
char *zText = 0;
164233164242
int ii = 0;
164234164243
sqlite3_str *pStr = sqlite3_str_new(pParse->db);
164235164244
sqlite3_str_appendf(pStr,"CREATE AUTOMATIC INDEX ON %s(", pTab->zName);
164236164245
assert( pIdx->nColumn>1 );
164237
- assert( pIdx->aiColumn[pIdx->nColumn-1]==XN_ROWID );
164246
+ assert( pIdx->aiColumn[pIdx->nColumn-1]==XN_ROWID || !HasRowid(pTab) );
164238164247
for(ii=0; ii<(pIdx->nColumn-1); ii++){
164239164248
const char *zName = 0;
164240164249
int iCol = pIdx->aiColumn[ii];
164241164250
164242164251
zName = pTab->aCol[iCol].zCnName;
@@ -164362,10 +164371,23 @@
164362164371
*/
164363164372
if( IsView(pTable) ){
164364164373
extraCols = ALLBITS & ~idxCols;
164365164374
}else{
164366164375
extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));
164376
+ }
164377
+ if( !HasRowid(pTable) ){
164378
+ /* For WITHOUT ROWID tables, ensure that all PRIMARY KEY columns are
164379
+ ** either in the idxCols mask or in the extraCols mask */
164380
+ for(i=0; i<pTable->nCol; i++){
164381
+ if( (pTable->aCol[i].colFlags & COLFLAG_PRIMKEY)==0 ) continue;
164382
+ if( i>=BMS-1 ){
164383
+ extraCols |= MASKBIT(BMS-1);
164384
+ break;
164385
+ }
164386
+ if( idxCols & MASKBIT(i) ) continue;
164387
+ extraCols |= MASKBIT(i);
164388
+ }
164367164389
}
164368164390
mxBitCol = MIN(BMS-1,pTable->nCol);
164369164391
testcase( pTable->nCol==BMS-1 );
164370164392
testcase( pTable->nCol==BMS-2 );
164371164393
for(i=0; i<mxBitCol; i++){
@@ -164374,11 +164396,12 @@
164374164396
if( pSrc->colUsed & MASKBIT(BMS-1) ){
164375164397
nKeyCol += pTable->nCol - BMS + 1;
164376164398
}
164377164399
164378164400
/* Construct the Index object to describe this index */
164379
- pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);
164401
+ pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+HasRowid(pTable),
164402
+ 0, &zNotUsed);
164380164403
if( pIdx==0 ) goto end_auto_index_create;
164381164404
pLoop->u.btree.pIndex = pIdx;
164382164405
pIdx->zName = "auto-index";
164383164406
pIdx->pTable = pTable;
164384164407
n = 0;
@@ -164430,12 +164453,14 @@
164430164453
pIdx->azColl[n] = sqlite3StrBINARY;
164431164454
n++;
164432164455
}
164433164456
}
164434164457
assert( n==nKeyCol );
164435
- pIdx->aiColumn[n] = XN_ROWID;
164436
- pIdx->azColl[n] = sqlite3StrBINARY;
164458
+ if( HasRowid(pTable) ){
164459
+ pIdx->aiColumn[n] = XN_ROWID;
164460
+ pIdx->azColl[n] = sqlite3StrBINARY;
164461
+ }
164437164462
164438164463
/* Create the automatic index */
164439164464
explainAutomaticIndex(pParse, pIdx, pPartial!=0, &addrExp);
164440164465
assert( pLevel->iIdxCur>=0 );
164441164466
pLevel->iIdxCur = pParse->nTab++;
@@ -165698,21 +165723,23 @@
165698165723
** | | | __|__ nEq ---. ___|__ | __|__
165699165724
** | / \ / \ / \ | / \ / \ / \
165700165725
** 1.002.001 t2.t2xy 2 f 010241 N 2 cost 0,56,31
165701165726
*/
165702165727
SQLITE_PRIVATE void sqlite3WhereLoopPrint(const WhereLoop *p, const WhereClause *pWC){
165728
+ WhereInfo *pWInfo;
165703165729
if( pWC ){
165704
- WhereInfo *pWInfo = pWC->pWInfo;
165730
+ pWInfo = pWC->pWInfo;
165705165731
int nb = 1+(pWInfo->pTabList->nSrc+3)/4;
165706165732
SrcItem *pItem = pWInfo->pTabList->a + p->iTab;
165707165733
Table *pTab = pItem->pSTab;
165708165734
Bitmask mAll = (((Bitmask)1)<<(nb*4)) - 1;
165709165735
sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
165710165736
p->iTab, nb, p->maskSelf, nb, p->prereq & mAll);
165711165737
sqlite3DebugPrintf(" %12s",
165712165738
pItem->zAlias ? pItem->zAlias : pTab->zName);
165713165739
}else{
165740
+ pWInfo = 0;
165714165741
sqlite3DebugPrintf("%c%2d.%03llx.%03llx %c%d",
165715165742
p->cId, p->iTab, p->maskSelf, p->prereq & 0xfff, p->cId, p->iTab);
165716165743
}
165717165744
if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
165718165745
const char *zName;
@@ -165740,11 +165767,16 @@
165740165767
if( p->wsFlags & WHERE_SKIPSCAN ){
165741165768
sqlite3DebugPrintf(" f %06x %d-%d", p->wsFlags, p->nLTerm,p->nSkip);
165742165769
}else{
165743165770
sqlite3DebugPrintf(" f %06x N %d", p->wsFlags, p->nLTerm);
165744165771
}
165745
- sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
165772
+ if( pWInfo && pWInfo->bStarUsed && p->rStarDelta!=0 ){
165773
+ sqlite3DebugPrintf(" cost %d,%d,%d delta=%d\n",
165774
+ p->rSetup, p->rRun, p->nOut, p->rStarDelta);
165775
+ }else{
165776
+ sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
165777
+ }
165746165778
if( p->nLTerm && (sqlite3WhereTrace & 0x4000)!=0 ){
165747165779
int i;
165748165780
for(i=0; i<p->nLTerm; i++){
165749165781
sqlite3WhereTermPrint(p->aLTerm[i], i);
165750165782
}
@@ -167206,11 +167238,10 @@
167206167238
if( !pBuilder->pOrSet /* Not part of an OR optimization */
167207167239
&& (pWInfo->wctrlFlags & (WHERE_RIGHT_JOIN|WHERE_OR_SUBCLAUSE))==0
167208167240
&& (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
167209167241
&& !pSrc->fg.isIndexedBy /* Has no INDEXED BY clause */
167210167242
&& !pSrc->fg.notIndexed /* Has no NOT INDEXED clause */
167211
- && HasRowid(pTab) /* Not WITHOUT ROWID table. (FIXME: Why not?) */
167212167243
&& !pSrc->fg.isCorrelated /* Not a correlated subquery */
167213167244
&& !pSrc->fg.isRecursive /* Not a recursive common table expression. */
167214167245
&& (pSrc->fg.jointype & JT_RIGHT)==0 /* Not the right tab of a RIGHT JOIN */
167215167246
){
167216167247
/* Generate auto-index WhereLoops */
@@ -168709,72 +168740,205 @@
168709168740
** The value returned is a tuning parameter. Currently the value is:
168710168741
**
168711168742
** 18 for star queries
168712168743
** 12 otherwise
168713168744
**
168714
-** For the purposes of SQLite, a star-query is defined as a query
168715
-** with a large central table that is joined against four or more
168716
-** smaller tables. The central table is called the "fact" table.
168717
-** The smaller tables that get joined are "dimension tables".
168745
+** For the purposes of this heuristic, a star-query is defined as a query
168746
+** with a large central table that is joined using an INNER JOIN,
168747
+** not CROSS or OUTER JOINs, against four or more smaller tables.
168748
+** The central table is called the "fact" table. The smaller tables
168749
+** that get joined are "dimension tables". Also, any table that is
168750
+** self-joined cannot be a dimension table; we assume that dimension
168751
+** tables may only be joined against fact tables.
168718168752
**
168719168753
** SIDE EFFECT: (and really the whole point of this subroutine)
168720168754
**
168721
-** If pWInfo describes a star-query, then the cost on WhereLoops for the
168722
-** fact table is reduced. This heuristic helps keep fact tables in
168723
-** outer loops. Without this heuristic, paths with fact tables in outer
168724
-** loops tend to get pruned by the mxChoice limit on the number of paths,
168725
-** resulting in poor query plans. The total amount of heuristic cost
168726
-** adjustment is stored in pWInfo->nOutStarDelta and the cost adjustment
168727
-** for each WhereLoop is stored in its rStarDelta field.
168755
+** If pWInfo describes a star-query, then the cost for SCANs of dimension
168756
+** WhereLoops is increased to be slightly larger than the cost of a SCAN
168757
+** in the fact table. Only SCAN costs are increased. SEARCH costs are
168758
+** unchanged. This heuristic helps keep fact tables in outer loops. Without
168759
+** this heuristic, paths with fact tables in outer loops tend to get pruned
168760
+** by the mxChoice limit on the number of paths, resulting in poor query
168761
+** plans. See the starschema1.test test module for examples of queries
168762
+** that need this heuristic to find good query plans.
168763
+**
168764
+** This heuristic can be completely disabled, so that no query is
168765
+** considered a star-query, using SQLITE_TESTCTRL_OPTIMIZATION to
168766
+** disable the SQLITE_StarQuery optimization. In the CLI, the command
168767
+** to do that is: ".testctrl opt -starquery".
168768
+**
168769
+** HISTORICAL NOTES:
168770
+**
168771
+** This optimization was first added on 2024-05-09 by check-in 38db9b5c83d.
168772
+** The original optimization reduced the cost and output size estimate for
168773
+** fact tables to help them move to outer loops. But months later (as people
168774
+** started upgrading) performance regression reports started caming in,
168775
+** including:
168776
+**
168777
+** forum post b18ef983e68d06d1 (2024-12-21)
168778
+** forum post 0025389d0860af82 (2025-01-14)
168779
+** forum post d87570a145599033 (2025-01-17)
168780
+**
168781
+** To address these, the criteria for a star-query was tightened to exclude
168782
+** cases where the fact and dimensions are separated by an outer join, and
168783
+** the affect of star-schema detection was changed to increase the rRun cost
168784
+** on just full table scans of dimension tables, rather than reducing costs
168785
+** in the all access methods of the fact table.
168728168786
*/
168729
-static int computeMxChoice(WhereInfo *pWInfo, LogEst nRowEst){
168787
+static int computeMxChoice(WhereInfo *pWInfo){
168730168788
int nLoop = pWInfo->nLevel; /* Number of terms in the join */
168731
- if( nRowEst==0 && nLoop>=5 ){
168732
- /* Check to see if we are dealing with a star schema and if so, reduce
168733
- ** the cost of fact tables relative to dimension tables, as a heuristic
168734
- ** to help keep the fact tables in outer loops.
168789
+ WhereLoop *pWLoop; /* For looping over WhereLoops */
168790
+
168791
+#ifdef SQLITE_DEBUG
168792
+ /* The star-query detection code below makes use of the following
168793
+ ** properties of the WhereLoop list, so verify them before
168794
+ ** continuing:
168795
+ ** (1) .maskSelf is the bitmask corresponding to .iTab
168796
+ ** (2) The WhereLoop list is in ascending .iTab order
168797
+ */
168798
+ for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
168799
+ assert( pWLoop->maskSelf==MASKBIT(pWLoop->iTab) );
168800
+ assert( pWLoop->pNextLoop==0 || pWLoop->iTab<=pWLoop->pNextLoop->iTab );
168801
+ }
168802
+#endif /* SQLITE_DEBUG */
168803
+
168804
+ if( nLoop>=5
168805
+ && !pWInfo->bStarDone
168806
+ && OptimizationEnabled(pWInfo->pParse->db, SQLITE_StarQuery)
168807
+ ){
168808
+ SrcItem *aFromTabs; /* All terms of the FROM clause */
168809
+ int iFromIdx; /* Term of FROM clause is the candidate fact-table */
168810
+ Bitmask m; /* Bitmask for candidate fact-table */
168811
+ Bitmask mSelfJoin = 0; /* Tables that cannot be dimension tables */
168812
+ WhereLoop *pStart; /* Where to start searching for dimension-tables */
168813
+
168814
+ pWInfo->bStarDone = 1; /* Only do this computation once */
168815
+
168816
+ /* Look for fact tables with four or more dimensions where the
168817
+ ** dimension tables are not separately from the fact tables by an outer
168818
+ ** or cross join. Adjust cost weights if found.
168735168819
*/
168736
- int iLoop; /* Counter over join terms */
168737
- Bitmask m; /* Bitmask for current loop */
168738
- assert( pWInfo->nOutStarDelta==0 );
168739
- for(iLoop=0, m=1; iLoop<nLoop; iLoop++, m<<=1){
168740
- WhereLoop *pWLoop; /* For looping over WhereLoops */
168820
+ assert( !pWInfo->bStarUsed );
168821
+ aFromTabs = pWInfo->pTabList->a;
168822
+ pStart = pWInfo->pLoops;
168823
+ for(iFromIdx=0, m=1; iFromIdx<nLoop; iFromIdx++, m<<=1){
168741168824
int nDep = 0; /* Number of dimension tables */
168742
- LogEst rDelta; /* Heuristic cost adjustment */
168825
+ LogEst mxRun; /* Maximum SCAN cost of a fact table */
168743168826
Bitmask mSeen = 0; /* Mask of dimension tables */
168744
- for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
168745
- if( (pWLoop->prereq & m)!=0 && (pWLoop->maskSelf & mSeen)==0 ){
168746
- nDep++;
168747
- mSeen |= pWLoop->maskSelf;
168827
+ SrcItem *pFactTab; /* The candidate fact table */
168828
+
168829
+ pFactTab = aFromTabs + iFromIdx;
168830
+ if( (pFactTab->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
168831
+ /* If the candidate fact-table is the right table of an outer join
168832
+ ** restrict the search for dimension-tables to be tables to the right
168833
+ ** of the fact-table. */
168834
+ if( iFromIdx+4 > nLoop ) break; /* Impossible to reach nDep>=4 */
168835
+ while( pStart && pStart->iTab<=iFromIdx ){
168836
+ pStart = pStart->pNextLoop;
168837
+ }
168838
+ }
168839
+ for(pWLoop=pStart; pWLoop; pWLoop=pWLoop->pNextLoop){
168840
+ if( (aFromTabs[pWLoop->iTab].fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
168841
+ /* Fact-tables and dimension-tables cannot be separated by an
168842
+ ** outer join (at least for the definition of fact- and dimension-
168843
+ ** used by this heuristic). */
168844
+ break;
168845
+ }
168846
+ if( (pWLoop->prereq & m)!=0 /* pWInfo depends on iFromIdx */
168847
+ && (pWLoop->maskSelf & mSeen)==0 /* pWInfo not already a dependency */
168848
+ && (pWLoop->maskSelf & mSelfJoin)==0 /* Not a self-join */
168849
+ ){
168850
+ if( aFromTabs[pWLoop->iTab].pSTab==pFactTab->pSTab ){
168851
+ mSelfJoin |= m;
168852
+ }else{
168853
+ nDep++;
168854
+ mSeen |= pWLoop->maskSelf;
168855
+ }
168748168856
}
168749168857
}
168750168858
if( nDep<=3 ) continue;
168751
- rDelta = 15*(nDep-3);
168752
-#ifdef WHERETRACE_ENABLED /* 0x4 */
168753
- if( sqlite3WhereTrace&0x4 ){
168754
- SrcItem *pItem = pWInfo->pTabList->a + iLoop;
168755
- sqlite3DebugPrintf("Fact-table %s: %d dimensions, cost reduced %d\n",
168756
- pItem->zAlias ? pItem->zAlias : pItem->pSTab->zName,
168757
- nDep, rDelta);
168758
- }
168759
-#endif
168760
- if( pWInfo->nOutStarDelta==0 ){
168859
+
168860
+ /* If we reach this point, it means that pFactTab is a fact table
168861
+ ** with four or more dimensions connected by inner joins. Proceed
168862
+ ** to make cost adjustments. */
168863
+
168864
+#ifdef WHERETRACE_ENABLED
168865
+ /* Make sure rStarDelta values are initialized */
168866
+ if( !pWInfo->bStarUsed ){
168761168867
for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
168762168868
pWLoop->rStarDelta = 0;
168763168869
}
168764168870
}
168765
- pWInfo->nOutStarDelta += rDelta;
168871
+#endif
168872
+ pWInfo->bStarUsed = 1;
168873
+
168874
+ /* Compute the maximum cost of any WhereLoop for the
168875
+ ** fact table plus one epsilon */
168876
+ mxRun = LOGEST_MIN;
168877
+ for(pWLoop=pStart; pWLoop; pWLoop=pWLoop->pNextLoop){
168878
+ if( pWLoop->iTab<iFromIdx ) continue;
168879
+ if( pWLoop->iTab>iFromIdx ) break;
168880
+ if( pWLoop->rRun>mxRun ) mxRun = pWLoop->rRun;
168881
+ }
168882
+ if( ALWAYS(mxRun<LOGEST_MAX) ) mxRun++;
168883
+
168884
+ /* Increase the cost of table scans for dimension tables to be
168885
+ ** slightly more than the maximum cost of the fact table */
168886
+ for(pWLoop=pStart; pWLoop; pWLoop=pWLoop->pNextLoop){
168887
+ if( (pWLoop->maskSelf & mSeen)==0 ) continue;
168888
+ if( pWLoop->nLTerm ) continue;
168889
+ if( pWLoop->rRun<mxRun ){
168890
+#ifdef WHERETRACE_ENABLED /* 0x80000 */
168891
+ if( sqlite3WhereTrace & 0x80000 ){
168892
+ SrcItem *pDim = aFromTabs + pWLoop->iTab;
168893
+ sqlite3DebugPrintf(
168894
+ "Increase SCAN cost of dimension %s(%d) of fact %s(%d) to %d\n",
168895
+ pDim->zAlias ? pDim->zAlias: pDim->pSTab->zName, pWLoop->iTab,
168896
+ pFactTab->zAlias ? pFactTab->zAlias : pFactTab->pSTab->zName,
168897
+ iFromIdx, mxRun
168898
+ );
168899
+ }
168900
+ pWLoop->rStarDelta = mxRun - pWLoop->rRun;
168901
+#endif /* WHERETRACE_ENABLED */
168902
+ pWLoop->rRun = mxRun;
168903
+ }
168904
+ }
168905
+ }
168906
+#ifdef WHERETRACE_ENABLED /* 0x80000 */
168907
+ if( (sqlite3WhereTrace & 0x80000)!=0 && pWInfo->bStarUsed ){
168908
+ sqlite3DebugPrintf("WhereLoops changed by star-query heuristic:\n");
168766168909
for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
168767
- if( pWLoop->maskSelf==m ){
168768
- pWLoop->rRun -= rDelta;
168769
- pWLoop->nOut -= rDelta;
168770
- pWLoop->rStarDelta = rDelta;
168910
+ if( pWLoop->rStarDelta ){
168911
+ sqlite3WhereLoopPrint(pWLoop, &pWInfo->sWC);
168771168912
}
168772168913
}
168773168914
}
168915
+#endif
168774168916
}
168775
- return pWInfo->nOutStarDelta>0 ? 18 : 12;
168917
+ return pWInfo->bStarUsed ? 18 : 12;
168918
+}
168919
+
168920
+/*
168921
+** Two WhereLoop objects, pCandidate and pBaseline, are known to have the
168922
+** same cost. Look deep into each to see if pCandidate is even slightly
168923
+** better than pBaseline. Return false if it is, if pCandidate is is preferred.
168924
+** Return true if pBaseline is preferred or if we cannot tell the difference.
168925
+**
168926
+** Result Meaning
168927
+** -------- ----------------------------------------------------------
168928
+** true We cannot tell the difference in pCandidate and pBaseline
168929
+** false pCandidate seems like a better choice than pBaseline
168930
+*/
168931
+static SQLITE_NOINLINE int whereLoopIsNoBetter(
168932
+ const WhereLoop *pCandidate,
168933
+ const WhereLoop *pBaseline
168934
+){
168935
+ if( (pCandidate->wsFlags & WHERE_INDEXED)==0 ) return 1;
168936
+ if( (pBaseline->wsFlags & WHERE_INDEXED)==0 ) return 1;
168937
+ if( pCandidate->u.btree.pIndex->szIdxRow <
168938
+ pBaseline->u.btree.pIndex->szIdxRow ) return 0;
168939
+ return 1;
168776168940
}
168777168941
168778168942
/*
168779168943
** Given the list of WhereLoop objects at pWInfo->pLoops, this routine
168780168944
** attempts to find the lowest cost path that visits each WhereLoop
@@ -168794,11 +168958,11 @@
168794168958
int iLoop; /* Loop counter over the terms of the join */
168795168959
int ii, jj; /* Loop counters */
168796168960
int mxI = 0; /* Index of next entry to replace */
168797168961
int nOrderBy; /* Number of ORDER BY clause terms */
168798168962
LogEst mxCost = 0; /* Maximum cost of a set of paths */
168799
- LogEst mxUnsorted = 0; /* Maximum unsorted cost of a set of path */
168963
+ LogEst mxUnsort = 0; /* Maximum unsorted cost of a set of path */
168800168964
int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */
168801168965
WherePath *aFrom; /* All nFrom paths at the previous level */
168802168966
WherePath *aTo; /* The nTo best paths at the current level */
168803168967
WherePath *pFrom; /* An element of aFrom[] that we are working on */
168804168968
WherePath *pTo; /* An element of aTo[] that we are working on */
@@ -168823,12 +168987,14 @@
168823168987
*/
168824168988
if( nLoop<=1 ){
168825168989
mxChoice = 1;
168826168990
}else if( nLoop==2 ){
168827168991
mxChoice = 5;
168992
+ }else if( pParse->nErr ){
168993
+ mxChoice = 1;
168828168994
}else{
168829
- mxChoice = computeMxChoice(pWInfo, nRowEst);
168995
+ mxChoice = computeMxChoice(pWInfo);
168830168996
}
168831168997
assert( nLoop<=pWInfo->pTabList->nSrc );
168832168998
168833168999
/* If nRowEst is zero and there is an ORDER BY clause, ignore it. In this
168834169000
** case the purpose of this call is to estimate the number of rows returned
@@ -168891,11 +169057,11 @@
168891169057
nTo = 0;
168892169058
for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){
168893169059
for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
168894169060
LogEst nOut; /* Rows visited by (pFrom+pWLoop) */
168895169061
LogEst rCost; /* Cost of path (pFrom+pWLoop) */
168896
- LogEst rUnsorted; /* Unsorted cost of (pFrom+pWLoop) */
169062
+ LogEst rUnsort; /* Unsorted cost of (pFrom+pWLoop) */
168897169063
i8 isOrdered; /* isOrdered for (pFrom+pWLoop) */
168898169064
Bitmask maskNew; /* Mask of src visited by (..) */
168899169065
Bitmask revMask; /* Mask of rev-order loops for (..) */
168900169066
168901169067
if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue;
@@ -168909,15 +169075,15 @@
168909169075
continue;
168910169076
}
168911169077
168912169078
/* At this point, pWLoop is a candidate to be the next loop.
168913169079
** Compute its cost */
168914
- rUnsorted = pWLoop->rRun + pFrom->nRow;
169080
+ rUnsort = pWLoop->rRun + pFrom->nRow;
168915169081
if( pWLoop->rSetup ){
168916
- rUnsorted = sqlite3LogEstAdd(pWLoop->rSetup, rUnsorted);
169082
+ rUnsort = sqlite3LogEstAdd(pWLoop->rSetup, rUnsort);
168917169083
}
168918
- rUnsorted = sqlite3LogEstAdd(rUnsorted, pFrom->rUnsorted);
169084
+ rUnsort = sqlite3LogEstAdd(rUnsort, pFrom->rUnsort);
168919169085
nOut = pFrom->nRow + pWLoop->nOut;
168920169086
maskNew = pFrom->maskLoop | pWLoop->maskSelf;
168921169087
isOrdered = pFrom->isOrdered;
168922169088
if( isOrdered<0 ){
168923169089
revMask = 0;
@@ -168935,19 +169101,19 @@
168935169101
}
168936169102
/* TUNING: Add a small extra penalty (3) to sorting as an
168937169103
** extra encouragement to the query planner to select a plan
168938169104
** where the rows emerge in the correct order without any sorting
168939169105
** required. */
168940
- rCost = sqlite3LogEstAdd(rUnsorted, aSortCost[isOrdered]) + 3;
169106
+ rCost = sqlite3LogEstAdd(rUnsort, aSortCost[isOrdered]) + 3;
168941169107
168942169108
WHERETRACE(0x002,
168943169109
("---- sort cost=%-3d (%d/%d) increases cost %3d to %-3d\n",
168944169110
aSortCost[isOrdered], (nOrderBy-isOrdered), nOrderBy,
168945
- rUnsorted, rCost));
169111
+ rUnsort, rCost));
168946169112
}else{
168947
- rCost = rUnsorted;
168948
- rUnsorted -= 2; /* TUNING: Slight bias in favor of no-sort plans */
169113
+ rCost = rUnsort;
169114
+ rUnsort -= 2; /* TUNING: Slight bias in favor of no-sort plans */
168949169115
}
168950169116
168951169117
/* Check to see if pWLoop should be added to the set of
168952169118
** mxChoice best-so-far paths.
168953169119
**
@@ -168969,19 +169135,19 @@
168969169135
}
168970169136
}
168971169137
if( jj>=nTo ){
168972169138
/* None of the existing best-so-far paths match the candidate. */
168973169139
if( nTo>=mxChoice
168974
- && (rCost>mxCost || (rCost==mxCost && rUnsorted>=mxUnsorted))
169140
+ && (rCost>mxCost || (rCost==mxCost && rUnsort>=mxUnsort))
168975169141
){
168976169142
/* The current candidate is no better than any of the mxChoice
168977169143
** paths currently in the best-so-far buffer. So discard
168978169144
** this candidate as not viable. */
168979169145
#ifdef WHERETRACE_ENABLED /* 0x4 */
168980169146
if( sqlite3WhereTrace&0x4 ){
168981169147
sqlite3DebugPrintf("Skip %s cost=%-3d,%3d,%3d order=%c\n",
168982
- wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsorted,
169148
+ wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsort,
168983169149
isOrdered>=0 ? isOrdered+'0' : '?');
168984169150
}
168985169151
#endif
168986169152
continue;
168987169153
}
@@ -168996,11 +169162,11 @@
168996169162
}
168997169163
pTo = &aTo[jj];
168998169164
#ifdef WHERETRACE_ENABLED /* 0x4 */
168999169165
if( sqlite3WhereTrace&0x4 ){
169000169166
sqlite3DebugPrintf("New %s cost=%-3d,%3d,%3d order=%c\n",
169001
- wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsorted,
169167
+ wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsort,
169002169168
isOrdered>=0 ? isOrdered+'0' : '?');
169003169169
}
169004169170
#endif
169005169171
}else{
169006169172
/* Control reaches here if best-so-far path pTo=aTo[jj] covers the
@@ -169007,28 +169173,27 @@
169007169173
** same set of loops and has the same isOrdered setting as the
169008169174
** candidate path. Check to see if the candidate should replace
169009169175
** pTo or if the candidate should be skipped.
169010169176
**
169011169177
** The conditional is an expanded vector comparison equivalent to:
169012
- ** (pTo->rCost,pTo->nRow,pTo->rUnsorted) <= (rCost,nOut,rUnsorted)
169178
+ ** (pTo->rCost,pTo->nRow,pTo->rUnsort) <= (rCost,nOut,rUnsort)
169013169179
*/
169014
- if( pTo->rCost<rCost
169015
- || (pTo->rCost==rCost
169016
- && (pTo->nRow<nOut
169017
- || (pTo->nRow==nOut && pTo->rUnsorted<=rUnsorted)
169018
- )
169019
- )
169180
+ if( (pTo->rCost<rCost)
169181
+ || (pTo->rCost==rCost && pTo->nRow<nOut)
169182
+ || (pTo->rCost==rCost && pTo->nRow==nOut && pTo->rUnsort<rUnsort)
169183
+ || (pTo->rCost==rCost && pTo->nRow==nOut && pTo->rUnsort==rUnsort
169184
+ && whereLoopIsNoBetter(pWLoop, pTo->aLoop[iLoop]) )
169020169185
){
169021169186
#ifdef WHERETRACE_ENABLED /* 0x4 */
169022169187
if( sqlite3WhereTrace&0x4 ){
169023169188
sqlite3DebugPrintf(
169024169189
"Skip %s cost=%-3d,%3d,%3d order=%c",
169025
- wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsorted,
169190
+ wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsort,
169026169191
isOrdered>=0 ? isOrdered+'0' : '?');
169027169192
sqlite3DebugPrintf(" vs %s cost=%-3d,%3d,%3d order=%c\n",
169028169193
wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
169029
- pTo->rUnsorted, pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?');
169194
+ pTo->rUnsort, pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?');
169030169195
}
169031169196
#endif
169032169197
/* Discard the candidate path from further consideration */
169033169198
testcase( pTo->rCost==rCost );
169034169199
continue;
@@ -169038,37 +169203,37 @@
169038169203
** pTo path. Replace pTo with the candidate. */
169039169204
#ifdef WHERETRACE_ENABLED /* 0x4 */
169040169205
if( sqlite3WhereTrace&0x4 ){
169041169206
sqlite3DebugPrintf(
169042169207
"Update %s cost=%-3d,%3d,%3d order=%c",
169043
- wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsorted,
169208
+ wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsort,
169044169209
isOrdered>=0 ? isOrdered+'0' : '?');
169045169210
sqlite3DebugPrintf(" was %s cost=%-3d,%3d,%3d order=%c\n",
169046169211
wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
169047
- pTo->rUnsorted, pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?');
169212
+ pTo->rUnsort, pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?');
169048169213
}
169049169214
#endif
169050169215
}
169051169216
/* pWLoop is a winner. Add it to the set of best so far */
169052169217
pTo->maskLoop = pFrom->maskLoop | pWLoop->maskSelf;
169053169218
pTo->revLoop = revMask;
169054169219
pTo->nRow = nOut;
169055169220
pTo->rCost = rCost;
169056
- pTo->rUnsorted = rUnsorted;
169221
+ pTo->rUnsort = rUnsort;
169057169222
pTo->isOrdered = isOrdered;
169058169223
memcpy(pTo->aLoop, pFrom->aLoop, sizeof(WhereLoop*)*iLoop);
169059169224
pTo->aLoop[iLoop] = pWLoop;
169060169225
if( nTo>=mxChoice ){
169061169226
mxI = 0;
169062169227
mxCost = aTo[0].rCost;
169063
- mxUnsorted = aTo[0].nRow;
169228
+ mxUnsort = aTo[0].nRow;
169064169229
for(jj=1, pTo=&aTo[1]; jj<mxChoice; jj++, pTo++){
169065169230
if( pTo->rCost>mxCost
169066
- || (pTo->rCost==mxCost && pTo->rUnsorted>mxUnsorted)
169231
+ || (pTo->rCost==mxCost && pTo->rUnsort>mxUnsort)
169067169232
){
169068169233
mxCost = pTo->rCost;
169069
- mxUnsorted = pTo->rUnsorted;
169234
+ mxUnsort = pTo->rUnsort;
169070169235
mxI = jj;
169071169236
}
169072169237
}
169073169238
}
169074169239
}
@@ -169076,12 +169241,14 @@
169076169241
169077169242
#ifdef WHERETRACE_ENABLED /* >=2 */
169078169243
if( sqlite3WhereTrace & 0x02 ){
169079169244
LogEst rMin, rFloor = 0;
169080169245
int nDone = 0;
169246
+ int nProgress;
169081169247
sqlite3DebugPrintf("---- after round %d ----\n", iLoop);
169082
- while( nDone<nTo ){
169248
+ do{
169249
+ nProgress = 0;
169083169250
rMin = 0x7fff;
169084169251
for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
169085169252
if( pTo->rCost>rFloor && pTo->rCost<rMin ) rMin = pTo->rCost;
169086169253
}
169087169254
for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
@@ -169093,14 +169260,15 @@
169093169260
sqlite3DebugPrintf(" rev=0x%llx\n", pTo->revLoop);
169094169261
}else{
169095169262
sqlite3DebugPrintf("\n");
169096169263
}
169097169264
nDone++;
169265
+ nProgress++;
169098169266
}
169099169267
}
169100169268
rFloor = rMin;
169101
- }
169269
+ }while( nDone<nTo && nProgress>0 );
169102169270
}
169103169271
#endif
169104169272
169105169273
/* Swap the roles of aFrom and aTo for the next generation */
169106169274
pFrom = aTo;
@@ -169190,11 +169358,14 @@
169190169358
pWInfo->revMask = revMask;
169191169359
}
169192169360
}
169193169361
}
169194169362
169195
- pWInfo->nRowOut = pFrom->nRow + pWInfo->nOutStarDelta;
169363
+ pWInfo->nRowOut = pFrom->nRow;
169364
+#ifdef WHERETRACE_ENABLED
169365
+ pWInfo->rTotalCost = pFrom->rCost;
169366
+#endif
169196169367
169197169368
/* Free temporary memory and return success */
169198169369
sqlite3StackFreeNN(pParse->db, pSpace);
169199169370
return SQLITE_OK;
169200169371
}
@@ -169588,11 +169759,10 @@
169588169759
pLoop->cId, (double)sqlite3LogEstToInt(nSearch), pTab->zName,
169589169760
(double)sqlite3LogEstToInt(pTab->nRowLogEst)));
169590169761
}
169591169762
}
169592169763
nSearch += pLoop->nOut;
169593
- if( pWInfo->nOutStarDelta ) nSearch += pLoop->rStarDelta;
169594169764
}
169595169765
}
169596169766
169597169767
/*
169598169768
** The index pIdx is used by a query and contains one or more expressions.
@@ -170071,11 +170241,12 @@
170071170241
goto whereBeginError;
170072170242
}
170073170243
assert( db->mallocFailed==0 );
170074170244
#ifdef WHERETRACE_ENABLED
170075170245
if( sqlite3WhereTrace ){
170076
- sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
170246
+ sqlite3DebugPrintf("---- Solution cost=%d, nRow=%d",
170247
+ pWInfo->rTotalCost, pWInfo->nRowOut);
170077170248
if( pWInfo->nOBSat>0 ){
170078170249
sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
170079170250
}
170080170251
switch( pWInfo->eDistinct ){
170081170252
case WHERE_DISTINCT_UNIQUE: {
@@ -226574,15 +226745,17 @@
226574226745
** SELECT 1, NULL, 'abc'
226575226746
*/
226576226747
struct SessionTable {
226577226748
SessionTable *pNext;
226578226749
char *zName; /* Local name of table */
226579
- int nCol; /* Number of columns in table zName */
226750
+ int nCol; /* Number of non-hidden columns */
226751
+ int nTotalCol; /* Number of columns including hidden */
226580226752
int bStat1; /* True if this is sqlite_stat1 */
226581226753
int bRowid; /* True if this table uses rowid for PK */
226582226754
const char **azCol; /* Column names */
226583226755
const char **azDflt; /* Default value expressions */
226756
+ int *aiIdx; /* Index to pass to xNew/xOld */
226584226757
u8 *abPK; /* Array of primary key flags */
226585226758
int nEntry; /* Total number of entries in hash table */
226586226759
int nChange; /* Size of apChange[] array */
226587226760
SessionChange **apChange; /* Hash table buckets */
226588226761
sqlite3_stmt *pDfltStmt;
@@ -226981,26 +227154,26 @@
226981227154
int *pbNullPK /* OUT: True if there are NULL values in PK */
226982227155
){
226983227156
unsigned int h = 0; /* Hash value to return */
226984227157
int i; /* Used to iterate through columns */
226985227158
227159
+ assert( pTab->nTotalCol==pSession->hook.xCount(pSession->hook.pCtx) );
226986227160
if( pTab->bRowid ){
226987
- assert( pTab->nCol-1==pSession->hook.xCount(pSession->hook.pCtx) );
226988227161
h = sessionHashAppendI64(h, iRowid);
226989227162
}else{
226990227163
assert( *pbNullPK==0 );
226991
- assert( pTab->nCol==pSession->hook.xCount(pSession->hook.pCtx) );
226992227164
for(i=0; i<pTab->nCol; i++){
226993227165
if( pTab->abPK[i] ){
226994227166
int rc;
226995227167
int eType;
226996227168
sqlite3_value *pVal;
227169
+ int iIdx = pTab->aiIdx[i];
226997227170
226998227171
if( bNew ){
226999
- rc = pSession->hook.xNew(pSession->hook.pCtx, i, &pVal);
227172
+ rc = pSession->hook.xNew(pSession->hook.pCtx, iIdx, &pVal);
227000227173
}else{
227001
- rc = pSession->hook.xOld(pSession->hook.pCtx, i, &pVal);
227174
+ rc = pSession->hook.xOld(pSession->hook.pCtx, iIdx, &pVal);
227002227175
}
227003227176
if( rc!=SQLITE_OK ) return rc;
227004227177
227005227178
eType = sqlite3_value_type(pVal);
227006227179
h = sessionHashAppendType(h, eType);
@@ -227333,22 +227506,23 @@
227333227506
a += sessionSerialLen(a);
227334227507
}else{
227335227508
sqlite3_value *pVal; /* Value returned by preupdate_new/old */
227336227509
int rc; /* Error code from preupdate_new/old */
227337227510
int eType = *a++; /* Type of value from change record */
227511
+ int iIdx = pTab->aiIdx[iCol];
227338227512
227339227513
/* The following calls to preupdate_new() and preupdate_old() can not
227340227514
** fail. This is because they cache their return values, and by the
227341227515
** time control flows to here they have already been called once from
227342227516
** within sessionPreupdateHash(). The first two asserts below verify
227343227517
** this (that the method has already been called). */
227344227518
if( op==SQLITE_INSERT ){
227345227519
/* assert( db->pPreUpdate->pNewUnpacked || db->pPreUpdate->aNew ); */
227346
- rc = pSession->hook.xNew(pSession->hook.pCtx, iCol, &pVal);
227520
+ rc = pSession->hook.xNew(pSession->hook.pCtx, iIdx, &pVal);
227347227521
}else{
227348227522
/* assert( db->pPreUpdate->pUnpacked ); */
227349
- rc = pSession->hook.xOld(pSession->hook.pCtx, iCol, &pVal);
227523
+ rc = pSession->hook.xOld(pSession->hook.pCtx, iIdx, &pVal);
227350227524
}
227351227525
assert( rc==SQLITE_OK );
227352227526
(void)rc; /* Suppress warning about unused variable */
227353227527
if( sqlite3_value_type(pVal)!=eType ) return 0;
227354227528
@@ -227469,13 +227643,15 @@
227469227643
sqlite3_session *pSession, /* For memory accounting. May be NULL */
227470227644
sqlite3 *db, /* Database connection */
227471227645
const char *zDb, /* Name of attached database (e.g. "main") */
227472227646
const char *zThis, /* Table name */
227473227647
int *pnCol, /* OUT: number of columns */
227648
+ int *pnTotalCol, /* OUT: number of hidden columns */
227474227649
const char **pzTab, /* OUT: Copy of zThis */
227475227650
const char ***pazCol, /* OUT: Array of column names for table */
227476227651
const char ***pazDflt, /* OUT: Array of default value expressions */
227652
+ int **paiIdx, /* OUT: Array of xNew/xOld indexes */
227477227653
u8 **pabPK, /* OUT: Array of booleans - true for PK col */
227478227654
int *pbRowid /* OUT: True if only PK is a rowid */
227479227655
){
227480227656
char *zPragma;
227481227657
sqlite3_stmt *pStmt;
@@ -227486,37 +227662,40 @@
227486227662
int i;
227487227663
u8 *pAlloc = 0;
227488227664
char **azCol = 0;
227489227665
char **azDflt = 0;
227490227666
u8 *abPK = 0;
227667
+ int *aiIdx = 0;
227491227668
int bRowid = 0; /* Set to true to use rowid as PK */
227492227669
227493227670
assert( pazCol && pabPK );
227494227671
227495227672
*pazCol = 0;
227496227673
*pabPK = 0;
227497227674
*pnCol = 0;
227675
+ if( pnTotalCol ) *pnTotalCol = 0;
227676
+ if( paiIdx ) *paiIdx = 0;
227498227677
if( pzTab ) *pzTab = 0;
227499227678
if( pazDflt ) *pazDflt = 0;
227500227679
227501227680
nThis = sqlite3Strlen30(zThis);
227502227681
if( nThis==12 && 0==sqlite3_stricmp("sqlite_stat1", zThis) ){
227503227682
rc = sqlite3_table_column_metadata(db, zDb, zThis, 0, 0, 0, 0, 0, 0);
227504227683
if( rc==SQLITE_OK ){
227505227684
/* For sqlite_stat1, pretend that (tbl,idx) is the PRIMARY KEY. */
227506227685
zPragma = sqlite3_mprintf(
227507
- "SELECT 0, 'tbl', '', 0, '', 1 UNION ALL "
227508
- "SELECT 1, 'idx', '', 0, '', 2 UNION ALL "
227509
- "SELECT 2, 'stat', '', 0, '', 0"
227686
+ "SELECT 0, 'tbl', '', 0, '', 1, 0 UNION ALL "
227687
+ "SELECT 1, 'idx', '', 0, '', 2, 0 UNION ALL "
227688
+ "SELECT 2, 'stat', '', 0, '', 0, 0"
227510227689
);
227511227690
}else if( rc==SQLITE_ERROR ){
227512227691
zPragma = sqlite3_mprintf("");
227513227692
}else{
227514227693
return rc;
227515227694
}
227516227695
}else{
227517
- zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis);
227696
+ zPragma = sqlite3_mprintf("PRAGMA '%q'.table_xinfo('%q')", zDb, zThis);
227518227697
}
227519227698
if( !zPragma ){
227520227699
return SQLITE_NOMEM;
227521227700
}
227522227701
@@ -227529,20 +227708,22 @@
227529227708
nByte = nThis + 1;
227530227709
bRowid = (pbRowid!=0);
227531227710
while( SQLITE_ROW==sqlite3_step(pStmt) ){
227532227711
nByte += sqlite3_column_bytes(pStmt, 1); /* name */
227533227712
nByte += sqlite3_column_bytes(pStmt, 4); /* dflt_value */
227534
- nDbCol++;
227713
+ if( sqlite3_column_int(pStmt, 6)==0 ){ /* !hidden */
227714
+ nDbCol++;
227715
+ }
227535227716
if( sqlite3_column_int(pStmt, 5) ) bRowid = 0; /* pk */
227536227717
}
227537227718
if( nDbCol==0 ) bRowid = 0;
227538227719
nDbCol += bRowid;
227539227720
nByte += strlen(SESSIONS_ROWID);
227540227721
rc = sqlite3_reset(pStmt);
227541227722
227542227723
if( rc==SQLITE_OK ){
227543
- nByte += nDbCol * (sizeof(const char *)*2 + sizeof(u8) + 1 + 1);
227724
+ nByte += nDbCol * (sizeof(const char *)*2 +sizeof(int)+sizeof(u8) + 1 + 1);
227544227725
pAlloc = sessionMalloc64(pSession, nByte);
227545227726
if( pAlloc==0 ){
227546227727
rc = SQLITE_NOMEM;
227547227728
}else{
227548227729
memset(pAlloc, 0, nByte);
@@ -227549,12 +227730,12 @@
227549227730
}
227550227731
}
227551227732
if( rc==SQLITE_OK ){
227552227733
azCol = (char **)pAlloc;
227553227734
azDflt = (char**)&azCol[nDbCol];
227554
- pAlloc = (u8 *)&azDflt[nDbCol];
227555
- abPK = (u8 *)pAlloc;
227735
+ aiIdx = (int*)&azDflt[nDbCol];
227736
+ abPK = (u8 *)&aiIdx[nDbCol];
227556227737
pAlloc = &abPK[nDbCol];
227557227738
if( pzTab ){
227558227739
memcpy(pAlloc, zThis, nThis+1);
227559227740
*pzTab = (char *)pAlloc;
227560227741
pAlloc += nThis+1;
@@ -227565,31 +227746,36 @@
227565227746
size_t nName = strlen(SESSIONS_ROWID);
227566227747
memcpy(pAlloc, SESSIONS_ROWID, nName+1);
227567227748
azCol[i] = (char*)pAlloc;
227568227749
pAlloc += nName+1;
227569227750
abPK[i] = 1;
227751
+ aiIdx[i] = -1;
227570227752
i++;
227571227753
}
227572227754
while( SQLITE_ROW==sqlite3_step(pStmt) ){
227573
- int nName = sqlite3_column_bytes(pStmt, 1);
227574
- int nDflt = sqlite3_column_bytes(pStmt, 4);
227575
- const unsigned char *zName = sqlite3_column_text(pStmt, 1);
227576
- const unsigned char *zDflt = sqlite3_column_text(pStmt, 4);
227577
-
227578
- if( zName==0 ) break;
227579
- memcpy(pAlloc, zName, nName+1);
227580
- azCol[i] = (char *)pAlloc;
227581
- pAlloc += nName+1;
227582
- if( zDflt ){
227583
- memcpy(pAlloc, zDflt, nDflt+1);
227584
- azDflt[i] = (char *)pAlloc;
227585
- pAlloc += nDflt+1;
227586
- }else{
227587
- azDflt[i] = 0;
227588
- }
227589
- abPK[i] = sqlite3_column_int(pStmt, 5);
227590
- i++;
227755
+ if( sqlite3_column_int(pStmt, 6)==0 ){ /* !hidden */
227756
+ int nName = sqlite3_column_bytes(pStmt, 1);
227757
+ int nDflt = sqlite3_column_bytes(pStmt, 4);
227758
+ const unsigned char *zName = sqlite3_column_text(pStmt, 1);
227759
+ const unsigned char *zDflt = sqlite3_column_text(pStmt, 4);
227760
+
227761
+ if( zName==0 ) break;
227762
+ memcpy(pAlloc, zName, nName+1);
227763
+ azCol[i] = (char *)pAlloc;
227764
+ pAlloc += nName+1;
227765
+ if( zDflt ){
227766
+ memcpy(pAlloc, zDflt, nDflt+1);
227767
+ azDflt[i] = (char *)pAlloc;
227768
+ pAlloc += nDflt+1;
227769
+ }else{
227770
+ azDflt[i] = 0;
227771
+ }
227772
+ abPK[i] = sqlite3_column_int(pStmt, 5);
227773
+ aiIdx[i] = sqlite3_column_int(pStmt, 0);
227774
+ i++;
227775
+ }
227776
+ if( pnTotalCol ) (*pnTotalCol)++;
227591227777
}
227592227778
rc = sqlite3_reset(pStmt);
227593227779
}
227594227780
227595227781
/* If successful, populate the output variables. Otherwise, zero them and
@@ -227598,10 +227784,11 @@
227598227784
if( rc==SQLITE_OK ){
227599227785
*pazCol = (const char**)azCol;
227600227786
if( pazDflt ) *pazDflt = (const char**)azDflt;
227601227787
*pabPK = abPK;
227602227788
*pnCol = nDbCol;
227789
+ if( paiIdx ) *paiIdx = aiIdx;
227603227790
}else{
227604227791
sessionFree(pSession, azCol);
227605227792
}
227606227793
if( pbRowid ) *pbRowid = bRowid;
227607227794
sqlite3_finalize(pStmt);
@@ -227629,11 +227816,12 @@
227629227816
227630227817
if( pTab->nCol==0 ){
227631227818
u8 *abPK;
227632227819
assert( pTab->azCol==0 || pTab->abPK==0 );
227633227820
rc = sessionTableInfo(pSession, db, zDb,
227634
- pTab->zName, &pTab->nCol, 0, &pTab->azCol, &pTab->azDflt, &abPK,
227821
+ pTab->zName, &pTab->nCol, &pTab->nTotalCol, 0, &pTab->azCol,
227822
+ &pTab->azDflt, &pTab->aiIdx, &abPK,
227635227823
((pSession==0 || pSession->bImplicitPK) ? &pTab->bRowid : 0)
227636227824
);
227637227825
if( rc==SQLITE_OK ){
227638227826
int i;
227639227827
for(i=0; i<pTab->nCol; i++){
@@ -227664,19 +227852,21 @@
227664227852
/*
227665227853
** Re-initialize table object pTab.
227666227854
*/
227667227855
static int sessionReinitTable(sqlite3_session *pSession, SessionTable *pTab){
227668227856
int nCol = 0;
227857
+ int nTotalCol = 0;
227669227858
const char **azCol = 0;
227670227859
const char **azDflt = 0;
227860
+ int *aiIdx = 0;
227671227861
u8 *abPK = 0;
227672227862
int bRowid = 0;
227673227863
227674227864
assert( pSession->rc==SQLITE_OK );
227675227865
227676227866
pSession->rc = sessionTableInfo(pSession, pSession->db, pSession->zDb,
227677
- pTab->zName, &nCol, 0, &azCol, &azDflt, &abPK,
227867
+ pTab->zName, &nCol, &nTotalCol, 0, &azCol, &azDflt, &aiIdx, &abPK,
227678227868
(pSession->bImplicitPK ? &bRowid : 0)
227679227869
);
227680227870
if( pSession->rc==SQLITE_OK ){
227681227871
if( pTab->nCol>nCol || pTab->bRowid!=bRowid ){
227682227872
pSession->rc = SQLITE_SCHEMA;
@@ -227695,12 +227885,14 @@
227695227885
227696227886
if( pSession->rc==SQLITE_OK ){
227697227887
const char **a = pTab->azCol;
227698227888
pTab->azCol = azCol;
227699227889
pTab->nCol = nCol;
227890
+ pTab->nTotalCol = nTotalCol;
227700227891
pTab->azDflt = azDflt;
227701227892
pTab->abPK = abPK;
227893
+ pTab->aiIdx = aiIdx;
227702227894
azCol = a;
227703227895
}
227704227896
if( pSession->bEnableSize ){
227705227897
pSession->nMaxChangesetSize += (nCol - nOldCol);
227706227898
pSession->nMaxChangesetSize += sessionVarintLen(nCol);
@@ -228014,11 +228206,11 @@
228014228206
if( pTab->bRowid ) nNew += 9;
228015228207
if( op!=SQLITE_DELETE ){
228016228208
int ii;
228017228209
for(ii=0; ii<pTab->nCol; ii++){
228018228210
sqlite3_value *p = 0;
228019
- pSession->hook.xNew(pSession->hook.pCtx, ii, &p);
228211
+ pSession->hook.xNew(pSession->hook.pCtx, pTab->aiIdx[ii], &p);
228020228212
sessionSerializeValue(0, p, &nNew);
228021228213
}
228022228214
}
228023228215
}else if( op==SQLITE_DELETE ){
228024228216
nNew += pC->nRecord;
@@ -228034,12 +228226,13 @@
228034228226
}
228035228227
for(ii=pTab->bRowid; ii<pTab->nCol; ii++){
228036228228
int bChanged = 1;
228037228229
int nOld = 0;
228038228230
int eType;
228231
+ int iIdx = pTab->aiIdx[ii];
228039228232
sqlite3_value *p = 0;
228040
- pSession->hook.xNew(pSession->hook.pCtx, ii-pTab->bRowid, &p);
228233
+ pSession->hook.xNew(pSession->hook.pCtx, iIdx, &p);
228041228234
if( p==0 ){
228042228235
return SQLITE_NOMEM;
228043228236
}
228044228237
228045228238
eType = *pCsr++;
@@ -228132,15 +228325,15 @@
228132228325
if( sessionInitTable(pSession, pTab, pSession->db, pSession->zDb) ) return;
228133228326
228134228327
/* Check the number of columns in this xPreUpdate call matches the
228135228328
** number of columns in the table. */
228136228329
nExpect = pSession->hook.xCount(pSession->hook.pCtx);
228137
- if( (pTab->nCol-pTab->bRowid)<nExpect ){
228330
+ if( pTab->nTotalCol<nExpect ){
228138228331
if( sessionReinitTable(pSession, pTab) ) return;
228139228332
if( sessionUpdateChanges(pSession, pTab) ) return;
228140228333
}
228141
- if( (pTab->nCol-pTab->bRowid)!=nExpect ){
228334
+ if( pTab->nTotalCol!=nExpect ){
228142228335
pSession->rc = SQLITE_SCHEMA;
228143228336
return;
228144228337
}
228145228338
228146228339
/* Grow the hash table if required */
@@ -228193,18 +228386,19 @@
228193228386
assert( rc==SQLITE_OK );
228194228387
pTab->nEntry++;
228195228388
228196228389
/* Figure out how large an allocation is required */
228197228390
nByte = sizeof(SessionChange);
228198
- for(i=0; i<(pTab->nCol-pTab->bRowid); i++){
228391
+ for(i=pTab->bRowid; i<pTab->nCol; i++){
228392
+ int iIdx = pTab->aiIdx[i];
228199228393
sqlite3_value *p = 0;
228200228394
if( op!=SQLITE_INSERT ){
228201228395
/* This may fail if the column has a non-NULL default and was added
228202228396
** using ALTER TABLE ADD COLUMN after this record was created. */
228203
- rc = pSession->hook.xOld(pSession->hook.pCtx, i, &p);
228397
+ rc = pSession->hook.xOld(pSession->hook.pCtx, iIdx, &p);
228204228398
}else if( pTab->abPK[i] ){
228205
- TESTONLY(int trc = ) pSession->hook.xNew(pSession->hook.pCtx, i, &p);
228399
+ TESTONLY(int trc = ) pSession->hook.xNew(pSession->hook.pCtx,iIdx,&p);
228206228400
assert( trc==SQLITE_OK );
228207228401
}
228208228402
228209228403
if( rc==SQLITE_OK ){
228210228404
/* This may fail if SQLite value p contains a utf-16 string that must
@@ -228235,16 +228429,17 @@
228235228429
if( pTab->bRowid ){
228236228430
pC->aRecord[0] = SQLITE_INTEGER;
228237228431
sessionPutI64(&pC->aRecord[1], iRowid);
228238228432
nByte = 9;
228239228433
}
228240
- for(i=0; i<(pTab->nCol-pTab->bRowid); i++){
228434
+ for(i=pTab->bRowid; i<pTab->nCol; i++){
228241228435
sqlite3_value *p = 0;
228436
+ int iIdx = pTab->aiIdx[i];
228242228437
if( op!=SQLITE_INSERT ){
228243
- pSession->hook.xOld(pSession->hook.pCtx, i, &p);
228438
+ pSession->hook.xOld(pSession->hook.pCtx, iIdx, &p);
228244228439
}else if( pTab->abPK[i] ){
228245
- pSession->hook.xNew(pSession->hook.pCtx, i, &p);
228440
+ pSession->hook.xNew(pSession->hook.pCtx, iIdx, &p);
228246228441
}
228247228442
sessionSerializeValue(&pC->aRecord[nByte], p, &nByte);
228248228443
}
228249228444
228250228445
/* Add the change to the hash-table */
@@ -228642,11 +228837,12 @@
228642228837
int bMismatch = 0;
228643228838
int nCol; /* Columns in zFrom.zTbl */
228644228839
int bRowid = 0;
228645228840
u8 *abPK;
228646228841
const char **azCol = 0;
228647
- rc = sessionTableInfo(0, db, zFrom, zTbl, &nCol, 0, &azCol, 0, &abPK,
228842
+ rc = sessionTableInfo(0, db, zFrom, zTbl,
228843
+ &nCol, 0, 0, &azCol, 0, 0, &abPK,
228648228844
pSession->bImplicitPK ? &bRowid : 0
228649228845
);
228650228846
if( rc==SQLITE_OK ){
228651228847
if( pTo->nCol!=nCol ){
228652228848
bMismatch = 1;
@@ -229219,14 +229415,14 @@
229219229415
sqlite3_stmt **ppStmt /* OUT: Prepared SELECT statement */
229220229416
){
229221229417
int rc = SQLITE_OK;
229222229418
char *zSql = 0;
229223229419
const char *zSep = "";
229224
- const char *zCols = bRowid ? SESSIONS_ROWID ", *" : "*";
229225229420
int nSql = -1;
229226229421
int i;
229227229422
229423
+ SessionBuffer cols = {0, 0, 0};
229228229424
SessionBuffer nooptest = {0, 0, 0};
229229229425
SessionBuffer pkfield = {0, 0, 0};
229230229426
SessionBuffer pkvar = {0, 0, 0};
229231229427
229232229428
sessionAppendStr(&nooptest, ", 1", &rc);
@@ -229235,13 +229431,20 @@
229235229431
sessionAppendStr(&nooptest, " AND (?6 OR ?3 IS stat)", &rc);
229236229432
sessionAppendStr(&pkfield, "tbl, idx", &rc);
229237229433
sessionAppendStr(&pkvar,
229238229434
"?1, (CASE WHEN ?2=X'' THEN NULL ELSE ?2 END)", &rc
229239229435
);
229240
- zCols = "tbl, ?2, stat";
229436
+ sessionAppendStr(&cols, "tbl, ?2, stat", &rc);
229241229437
}else{
229438
+ #if 0
229439
+ if( bRowid ){
229440
+ sessionAppendStr(&cols, SESSIONS_ROWID, &rc);
229441
+ }
229442
+ #endif
229242229443
for(i=0; i<nCol; i++){
229444
+ if( cols.nBuf ) sessionAppendStr(&cols, ", ", &rc);
229445
+ sessionAppendIdent(&cols, azCol[i], &rc);
229243229446
if( abPK[i] ){
229244229447
sessionAppendStr(&pkfield, zSep, &rc);
229245229448
sessionAppendStr(&pkvar, zSep, &rc);
229246229449
zSep = ", ";
229247229450
sessionAppendIdent(&pkfield, azCol[i], &rc);
@@ -229255,11 +229458,11 @@
229255229458
}
229256229459
229257229460
if( rc==SQLITE_OK ){
229258229461
zSql = sqlite3_mprintf(
229259229462
"SELECT %s%s FROM %Q.%Q WHERE (%s) IS (%s)",
229260
- zCols, (bIgnoreNoop ? (char*)nooptest.aBuf : ""),
229463
+ (char*)cols.aBuf, (bIgnoreNoop ? (char*)nooptest.aBuf : ""),
229261229464
zDb, zTab, (char*)pkfield.aBuf, (char*)pkvar.aBuf
229262229465
);
229263229466
if( zSql==0 ) rc = SQLITE_NOMEM;
229264229467
}
229265229468
@@ -229298,10 +229501,11 @@
229298229501
}
229299229502
sqlite3_free(zSql);
229300229503
sqlite3_free(nooptest.aBuf);
229301229504
sqlite3_free(pkfield.aBuf);
229302229505
sqlite3_free(pkvar.aBuf);
229506
+ sqlite3_free(cols.aBuf);
229303229507
return rc;
229304229508
}
229305229509
229306229510
/*
229307229511
** Bind the PRIMARY KEY values from the change passed in argument pChange
@@ -231638,11 +231842,12 @@
231638231842
int nMinCol = 0;
231639231843
int i;
231640231844
231641231845
sqlite3changeset_pk(pIter, &abPK, 0);
231642231846
rc = sessionTableInfo(0, db, "main", zNew,
231643
- &sApply.nCol, &zTab, &sApply.azCol, 0, &sApply.abPK, &sApply.bRowid
231847
+ &sApply.nCol, 0, &zTab, &sApply.azCol, 0, 0,
231848
+ &sApply.abPK, &sApply.bRowid
231644231849
);
231645231850
if( rc!=SQLITE_OK ) break;
231646231851
for(i=0; i<sApply.nCol; i++){
231647231852
if( sApply.abPK[i] ) nMinCol = i+1;
231648231853
}
@@ -231718,10 +231923,15 @@
231718231923
if( res!=SQLITE_CHANGESET_OMIT ){
231719231924
rc = SQLITE_CONSTRAINT;
231720231925
}
231721231926
}
231722231927
}
231928
+
231929
+ {
231930
+ int rc2 = sqlite3_exec(db, "PRAGMA defer_foreign_keys = 0", 0, 0, 0);
231931
+ if( rc==SQLITE_OK ) rc = rc2;
231932
+ }
231723231933
231724231934
if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){
231725231935
if( rc==SQLITE_OK ){
231726231936
rc = sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0);
231727231937
}
@@ -243230,15 +243440,17 @@
243230243440
}
243231243441
243232243442
/*
243233243443
** Close the read-only blob handle, if it is open.
243234243444
*/
243235
-static void sqlite3Fts5IndexCloseReader(Fts5Index *p){
243445
+static void fts5IndexCloseReader(Fts5Index *p){
243236243446
if( p->pReader ){
243447
+ int rc;
243237243448
sqlite3_blob *pReader = p->pReader;
243238243449
p->pReader = 0;
243239
- sqlite3_blob_close(pReader);
243450
+ rc = sqlite3_blob_close(pReader);
243451
+ if( p->rc==SQLITE_OK ) p->rc = rc;
243240243452
}
243241243453
}
243242243454
243243243455
/*
243244243456
** Retrieve a record from the %_data table.
@@ -243259,11 +243471,11 @@
243259243471
p->pReader = 0;
243260243472
rc = sqlite3_blob_reopen(pBlob, iRowid);
243261243473
assert( p->pReader==0 );
243262243474
p->pReader = pBlob;
243263243475
if( rc!=SQLITE_OK ){
243264
- sqlite3Fts5IndexCloseReader(p);
243476
+ fts5IndexCloseReader(p);
243265243477
}
243266243478
if( rc==SQLITE_ABORT ) rc = SQLITE_OK;
243267243479
}
243268243480
243269243481
/* If the blob handle is not open at this point, open it and seek
@@ -247460,10 +247672,18 @@
247460247672
static int fts5IndexReturn(Fts5Index *p){
247461247673
int rc = p->rc;
247462247674
p->rc = SQLITE_OK;
247463247675
return rc;
247464247676
}
247677
+
247678
+/*
247679
+** Close the read-only blob handle, if it is open.
247680
+*/
247681
+static void sqlite3Fts5IndexCloseReader(Fts5Index *p){
247682
+ fts5IndexCloseReader(p);
247683
+ fts5IndexReturn(p);
247684
+}
247465247685
247466247686
typedef struct Fts5FlushCtx Fts5FlushCtx;
247467247687
struct Fts5FlushCtx {
247468247688
Fts5Index *pIdx;
247469247689
Fts5SegWriter writer;
@@ -249182,11 +249402,11 @@
249182249402
** Commit data to disk.
249183249403
*/
249184249404
static int sqlite3Fts5IndexSync(Fts5Index *p){
249185249405
assert( p->rc==SQLITE_OK );
249186249406
fts5IndexFlush(p);
249187
- sqlite3Fts5IndexCloseReader(p);
249407
+ fts5IndexCloseReader(p);
249188249408
return fts5IndexReturn(p);
249189249409
}
249190249410
249191249411
/*
249192249412
** Discard any data stored in the in-memory hash tables. Do not write it
@@ -249193,15 +249413,14 @@
249193249413
** to the database. Additionally, assume that the contents of the %_data
249194249414
** table may have changed on disk. So any in-memory caches of %_data
249195249415
** records must be invalidated.
249196249416
*/
249197249417
static int sqlite3Fts5IndexRollback(Fts5Index *p){
249198
- sqlite3Fts5IndexCloseReader(p);
249418
+ fts5IndexCloseReader(p);
249199249419
fts5IndexDiscardData(p);
249200249420
fts5StructureInvalidate(p);
249201
- /* assert( p->rc==SQLITE_OK ); */
249202
- return SQLITE_OK;
249421
+ return fts5IndexReturn(p);
249203249422
}
249204249423
249205249424
/*
249206249425
** The %_data table is completely empty when this function is called. This
249207249426
** function populates it with the initial structure objects for each index,
@@ -249397,10 +249616,20 @@
249397249616
*/
249398249617
static void fts5SegIterSetEOF(Fts5SegIter *pSeg){
249399249618
fts5DataRelease(pSeg->pLeaf);
249400249619
pSeg->pLeaf = 0;
249401249620
}
249621
+
249622
+static void fts5IterClose(Fts5IndexIter *pIndexIter){
249623
+ if( pIndexIter ){
249624
+ Fts5Iter *pIter = (Fts5Iter*)pIndexIter;
249625
+ Fts5Index *pIndex = pIter->pIndex;
249626
+ fts5TokendataIterDelete(pIter->pTokenDataIter);
249627
+ fts5MultiIterFree(pIter);
249628
+ fts5IndexCloseReader(pIndex);
249629
+ }
249630
+}
249402249631
249403249632
/*
249404249633
** This function appends iterator pAppend to Fts5TokenDataIter pIn and
249405249634
** returns the result.
249406249635
*/
@@ -249425,11 +249654,11 @@
249425249654
pNew->nIterAlloc = nAlloc;
249426249655
}
249427249656
}
249428249657
}
249429249658
if( p->rc ){
249430
- sqlite3Fts5IterClose((Fts5IndexIter*)pAppend);
249659
+ fts5IterClose((Fts5IndexIter*)pAppend);
249431249660
}else{
249432249661
pRet->apIter[pRet->nIter++] = pAppend;
249433249662
}
249434249663
assert( pRet==0 || pRet->nIter<=pRet->nIterAlloc );
249435249664
@@ -249638,11 +249867,11 @@
249638249867
fts5BufferAppendBlob(&p->rc, &bSeek, 1, (const u8*)"\0");
249639249868
}else{
249640249869
fts5BufferSet(&p->rc, &bSeek, nToken, pToken);
249641249870
}
249642249871
if( p->rc ){
249643
- sqlite3Fts5IterClose((Fts5IndexIter*)pNew);
249872
+ fts5IterClose((Fts5IndexIter*)pNew);
249644249873
break;
249645249874
}
249646249875
249647249876
pNewIter = &pNew->aSeg[0];
249648249877
pPrevIter = (pPrev ? &pPrev->aSeg[0] : 0);
@@ -249703,11 +249932,11 @@
249703249932
249704249933
/* If pSmall is still NULL at this point, then the new iterator does
249705249934
** not point to any terms that match the query. So delete it and break
249706249935
** out of the loop - all required iterators have been collected. */
249707249936
if( pSmall==0 ){
249708
- sqlite3Fts5IterClose((Fts5IndexIter*)pNew);
249937
+ fts5IterClose((Fts5IndexIter*)pNew);
249709249938
break;
249710249939
}
249711249940
249712249941
/* Append this iterator to the set and continue. */
249713249942
pSet = fts5AppendTokendataIter(p, pSet, pNew);
@@ -249832,13 +250061,13 @@
249832250061
}
249833250062
}
249834250063
}
249835250064
249836250065
if( p->rc ){
249837
- sqlite3Fts5IterClose((Fts5IndexIter*)pRet);
250066
+ fts5IterClose((Fts5IndexIter*)pRet);
249838250067
pRet = 0;
249839
- sqlite3Fts5IndexCloseReader(p);
250068
+ fts5IndexCloseReader(p);
249840250069
}
249841250070
249842250071
*ppIter = (Fts5IndexIter*)pRet;
249843250072
sqlite3Fts5BufferFree(&buf);
249844250073
}
@@ -250084,15 +250313,13 @@
250084250313
/*
250085250314
** Close an iterator opened by an earlier call to sqlite3Fts5IndexQuery().
250086250315
*/
250087250316
static void sqlite3Fts5IterClose(Fts5IndexIter *pIndexIter){
250088250317
if( pIndexIter ){
250089
- Fts5Iter *pIter = (Fts5Iter*)pIndexIter;
250090
- Fts5Index *pIndex = pIter->pIndex;
250091
- fts5TokendataIterDelete(pIter->pTokenDataIter);
250092
- fts5MultiIterFree(pIter);
250093
- sqlite3Fts5IndexCloseReader(pIndex);
250318
+ Fts5Index *pIndex = ((Fts5Iter*)pIndexIter)->pIndex;
250319
+ fts5IterClose(pIndexIter);
250320
+ fts5IndexReturn(pIndex);
250094250321
}
250095250322
}
250096250323
250097250324
/*
250098250325
** Read and decode the "averages" record from the database.
@@ -250618,11 +250845,11 @@
250618250845
}
250619250846
if( rc==SQLITE_OK ){
250620250847
rc = sqlite3Fts5IterNext(pIter);
250621250848
}
250622250849
}
250623
- sqlite3Fts5IterClose(pIter);
250850
+ fts5IterClose(pIter);
250624250851
250625250852
*pCksum = cksum;
250626250853
return rc;
250627250854
}
250628250855
@@ -255462,11 +255689,11 @@
255462255689
int nArg, /* Number of args */
255463255690
sqlite3_value **apUnused /* Function arguments */
255464255691
){
255465255692
assert( nArg==0 );
255466255693
UNUSED_PARAM2(nArg, apUnused);
255467
- sqlite3_result_text(pCtx, "fts5: 2025-01-14 11:05:00 d2fe6b05f38d9d7cd78c5d252e99ac59f1aea071d669830c1ffe4e8966e84010", -1, SQLITE_TRANSIENT);
255694
+ sqlite3_result_text(pCtx, "fts5: 2025-01-29 18:53:19 d7c07581203a0a88456588e49e51b40a8341b0e7121809f75be0ee882d91650f", -1, SQLITE_TRANSIENT);
255468255695
}
255469255696
255470255697
/*
255471255698
** Implementation of fts5_locale(LOCALE, TEXT) function.
255472255699
**
255473255700
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.48.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -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 ** d2fe6b05f38d9d7cd78c5d252e99ac59f1ae with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -463,13 +463,13 @@
463 **
464 ** See also: [sqlite3_libversion()],
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
468 #define SQLITE_VERSION "3.48.0"
469 #define SQLITE_VERSION_NUMBER 3048000
470 #define SQLITE_SOURCE_ID "2025-01-14 11:05:00 d2fe6b05f38d9d7cd78c5d252e99ac59f1aea071d669830c1ffe4e8966e84010"
471
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -11065,12 +11065,13 @@
11065 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
11066
11067 /*
11068 ** CAPI3REF: Serialize a database
11069 **
11070 ** The sqlite3_serialize(D,S,P,F) interface returns a pointer to memory
11071 ** that is a serialization of the S database on [database connection] D.
 
11072 ** If P is not a NULL pointer, then the size of the database in bytes
11073 ** is written into *P.
11074 **
11075 ** For an ordinary on-disk database file, the serialization is just a
11076 ** copy of the disk file. For an in-memory database or a "TEMP" database,
@@ -15127,10 +15128,12 @@
15127 ** Examples:
15128 **
15129 ** 0.5 -> -10 0.1 -> -33 0.0625 -> -40
15130 */
15131 typedef INT16_TYPE LogEst;
 
 
15132
15133 /*
15134 ** Set the SQLITE_PTRSIZE macro to the number of bytes in a pointer
15135 */
15136 #ifndef SQLITE_PTRSIZE
@@ -15397,11 +15400,11 @@
15397 ** 0x-------F High-level debug messages
15398 ** 0x----FFF- More detail
15399 ** 0xFFFF---- Low-level debug messages
15400 **
15401 ** 0x00000001 Code generation
15402 ** 0x00000002 Solver
15403 ** 0x00000004 Solver costs
15404 ** 0x00000008 WhereLoop inserts
15405 **
15406 ** 0x00000010 Display sqlite3_index_info xBestIndex calls
15407 ** 0x00000020 Range an equality scan metrics
@@ -15416,10 +15419,12 @@
15416 ** 0x00004000 Show all WHERE terms at key points
15417 ** 0x00008000 Show the full SELECT statement at key places
15418 **
15419 ** 0x00010000 Show more detail when printing WHERE terms
15420 ** 0x00020000 Show WHERE terms returned from whereScanNext()
 
 
15421 */
15422
15423
15424 /*
15425 ** An instance of the following structure is used to store the busy-handler
@@ -18097,10 +18102,11 @@
18097 #define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
18098 #define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
18099 #define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
18100 #define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
18101 #define SQLITE_OrderBySubq 0x10000000 /* ORDER BY in subquery helps outer */
 
18102 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
18103
18104 /*
18105 ** Macros for testing whether or not optimizations are enabled or disabled.
18106 */
@@ -19426,17 +19432,12 @@
19426 **
19427 ** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
19428 */
19429 struct IdList {
19430 int nId; /* Number of identifiers on the list */
19431 u8 eU4; /* Which element of a.u4 is valid */
19432 struct IdList_item {
19433 char *zName; /* Name of the identifier */
19434 union {
19435 int idx; /* Index in some Table.aCol[] of a column named zName */
19436 Expr *pExpr; /* Expr to implement a USING variable -- NOT USED */
19437 } u4;
19438 } a[1];
19439 };
19440
19441 /*
19442 ** Allowed values for IdList.eType, which determines which value of the a.u4
@@ -23579,10 +23580,11 @@
23579 char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
23580 void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
23581 #ifdef SQLITE_DEBUG
23582 Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
23583 u16 mScopyFlags; /* flags value immediately after the shallow copy */
 
23584 #endif
23585 };
23586
23587 /*
23588 ** Size of struct Mem not including the Mem.zMalloc member or anything that
@@ -24677,10 +24679,13 @@
24677 ms = ms*10.0 + *zDate - '0';
24678 rScale *= 10.0;
24679 zDate++;
24680 }
24681 ms /= rScale;
 
 
 
24682 }
24683 }else{
24684 s = 0;
24685 }
24686 p->validJD = 0;
@@ -25884,11 +25889,11 @@
25884 sqlite3_str_appendf(&sRes, cf=='d' ? "%02d" : "%2d", x.D);
25885 break;
25886 }
25887 case 'f': { /* Fractional seconds. (Non-standard) */
25888 double s = x.s;
25889 if( s>59.999 ) s = 59.999;
25890 sqlite3_str_appendf(&sRes, "%06.3f", s);
25891 break;
25892 }
25893 case 'F': {
25894 sqlite3_str_appendf(&sRes, "%04d-%02d-%02d", x.Y, x.M, x.D);
@@ -33815,25 +33820,11 @@
33815 char *zName = pList->a[i].zName;
33816 int moreToFollow = i<pList->nId - 1;
33817 if( zName==0 ) zName = "(null)";
33818 sqlite3TreeViewPush(&pView, moreToFollow);
33819 sqlite3TreeViewLine(pView, 0);
33820 if( pList->eU4==EU4_NONE ){
33821 fprintf(stdout, "%s\n", zName);
33822 }else if( pList->eU4==EU4_IDX ){
33823 fprintf(stdout, "%s (%d)\n", zName, pList->a[i].u4.idx);
33824 }else{
33825 assert( pList->eU4==EU4_EXPR );
33826 if( pList->a[i].u4.pExpr==0 ){
33827 fprintf(stdout, "%s (pExpr=NULL)\n", zName);
33828 }else{
33829 fprintf(stdout, "%s\n", zName);
33830 sqlite3TreeViewPush(&pView, i<pList->nId-1);
33831 sqlite3TreeViewExpr(pView, pList->a[i].u4.pExpr, 0);
33832 sqlite3TreeViewPop(&pView);
33833 }
33834 }
33835 sqlite3TreeViewPop(&pView);
33836 }
33837 }
33838 }
33839 SQLITE_PRIVATE void sqlite3TreeViewIdList(
@@ -40170,11 +40161,11 @@
40170 assert( pInode!=0 );
40171 assert( sqlite3_mutex_held(pInode->pLockMutex) );
40172 if( (pFile->ctrlFlags & (UNIXFILE_EXCL|UNIXFILE_RDONLY))==UNIXFILE_EXCL ){
40173 if( pInode->bProcessLock==0 ){
40174 struct flock lock;
40175 assert( pInode->nLock==0 );
40176 lock.l_whence = SEEK_SET;
40177 lock.l_start = SHARED_FIRST;
40178 lock.l_len = SHARED_SIZE;
40179 lock.l_type = F_WRLCK;
40180 rc = osSetPosixAdvisoryLock(pFile->h, &lock, pFile);
@@ -58053,11 +58044,11 @@
58053 if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0; /* Failed (3) */
58054 #ifndef SQLITE_OMIT_WAL
58055 if( pPager->pWal ){
58056 u32 iRead = 0;
58057 (void)sqlite3WalFindFrame(pPager->pWal, pgno, &iRead);
58058 return iRead==0; /* Condition (4) */
58059 }
58060 #endif
58061 assert( pPager->fd->pMethods->xDeviceCharacteristics!=0 );
58062 if( (pPager->fd->pMethods->xDeviceCharacteristics(pPager->fd)
58063 & SQLITE_IOCAP_SUBPAGE_READ)==0 ){
@@ -84001,31 +83992,34 @@
84001 ** copies (created by OP_SCopy) are not misused.
84002 */
84003 SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){
84004 int i;
84005 Mem *pX;
84006 for(i=1, pX=pVdbe->aMem+1; i<pVdbe->nMem; i++, pX++){
84007 if( pX->pScopyFrom==pMem ){
84008 u16 mFlags;
84009 if( pVdbe->db->flags & SQLITE_VdbeTrace ){
84010 sqlite3DebugPrintf("Invalidate R[%d] due to change in R[%d]\n",
84011 (int)(pX - pVdbe->aMem), (int)(pMem - pVdbe->aMem));
84012 }
84013 /* If pX is marked as a shallow copy of pMem, then try to verify that
84014 ** no significant changes have been made to pX since the OP_SCopy.
84015 ** A significant change would indicated a missed call to this
84016 ** function for pX. Minor changes, such as adding or removing a
84017 ** dual type, are allowed, as long as the underlying value is the
84018 ** same. */
84019 mFlags = pMem->flags & pX->flags & pX->mScopyFlags;
84020 assert( (mFlags&(MEM_Int|MEM_IntReal))==0 || pMem->u.i==pX->u.i );
84021
84022 /* pMem is the register that is changing. But also mark pX as
84023 ** undefined so that we can quickly detect the shallow-copy error */
84024 pX->flags = MEM_Undefined;
84025 pX->pScopyFrom = 0;
84026 }
 
 
 
84027 }
84028 pMem->pScopyFrom = 0;
84029 }
84030 #endif /* SQLITE_DEBUG */
84031
@@ -87163,10 +87157,11 @@
87163 p->flags = flags;
87164 p->db = db;
87165 p->szMalloc = 0;
87166 #ifdef SQLITE_DEBUG
87167 p->pScopyFrom = 0;
 
87168 #endif
87169 p++;
87170 }while( (--N)>0 );
87171 }
87172 }
@@ -91348,11 +91343,11 @@
91348 if( db->nVdbeActive==0 ){
91349 AtomicStore(&db->u1.isInterrupted, 0);
91350 }
91351
91352 assert( db->nVdbeWrite>0 || db->autoCommit==0
91353 || (db->nDeferredCons==0 && db->nDeferredImmCons==0)
91354 );
91355
91356 #ifndef SQLITE_OMIT_TRACE
91357 if( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0
91358 && !db->init.busy && p->zSql ){
@@ -91859,10 +91854,11 @@
91859 /* .zMalloc = */ (char*)0,
91860 /* .xDel = */ (void(*)(void*))0,
91861 #ifdef SQLITE_DEBUG
91862 /* .pScopyFrom = */ (Mem*)0,
91863 /* .mScopyFlags= */ 0,
 
91864 #endif
91865 };
91866 return &nullMem;
91867 }
91868
@@ -92741,10 +92737,11 @@
92741 */
92742 SQLITE_API int sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
92743 PreUpdate *p;
92744 Mem *pMem;
92745 int rc = SQLITE_OK;
 
92746
92747 #ifdef SQLITE_ENABLE_API_ARMOR
92748 if( db==0 || ppValue==0 ){
92749 return SQLITE_MISUSE_BKPT;
92750 }
@@ -92755,13 +92752,15 @@
92755 if( !p || p->op==SQLITE_INSERT ){
92756 rc = SQLITE_MISUSE_BKPT;
92757 goto preupdate_old_out;
92758 }
92759 if( p->pPk ){
92760 iIdx = sqlite3TableColumnToIndex(p->pPk, iIdx);
 
 
92761 }
92762 if( iIdx>=p->pCsr->nField || iIdx<0 ){
92763 rc = SQLITE_RANGE;
92764 goto preupdate_old_out;
92765 }
92766
92767 if( iIdx==p->pTab->iPKey ){
@@ -92788,12 +92787,12 @@
92788 goto preupdate_old_out;
92789 }
92790 p->aRecord = aRec;
92791 }
92792
92793 pMem = *ppValue = &p->pUnpacked->aMem[iIdx];
92794 if( iIdx>=p->pUnpacked->nField ){
92795 /* This occurs when the table has been extended using ALTER TABLE
92796 ** ADD COLUMN. The value to return is the default value of the column. */
92797 Column *pCol = &p->pTab->aCol[iIdx];
92798 if( pCol->iDflt>0 ){
92799 if( p->apDflt==0 ){
@@ -92893,10 +92892,11 @@
92893 */
92894 SQLITE_API int sqlite3_preupdate_new(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
92895 PreUpdate *p;
92896 int rc = SQLITE_OK;
92897 Mem *pMem;
 
92898
92899 #ifdef SQLITE_ENABLE_API_ARMOR
92900 if( db==0 || ppValue==0 ){
92901 return SQLITE_MISUSE_BKPT;
92902 }
@@ -92905,13 +92905,16 @@
92905 if( !p || p->op==SQLITE_DELETE ){
92906 rc = SQLITE_MISUSE_BKPT;
92907 goto preupdate_new_out;
92908 }
92909 if( p->pPk && p->op!=SQLITE_UPDATE ){
92910 iIdx = sqlite3TableColumnToIndex(p->pPk, iIdx);
 
 
92911 }
92912 if( iIdx>=p->pCsr->nField || iIdx<0 ){
 
92913 rc = SQLITE_RANGE;
92914 goto preupdate_new_out;
92915 }
92916
92917 if( p->op==SQLITE_INSERT ){
@@ -92927,18 +92930,18 @@
92927 rc = SQLITE_NOMEM;
92928 goto preupdate_new_out;
92929 }
92930 p->pNewUnpacked = pUnpack;
92931 }
92932 pMem = &pUnpack->aMem[iIdx];
92933 if( iIdx==p->pTab->iPKey ){
92934 sqlite3VdbeMemSetInt64(pMem, p->iKey2);
92935 }else if( iIdx>=pUnpack->nField ){
92936 pMem = (sqlite3_value *)columnNullValue();
92937 }
92938 }else{
92939 /* For an UPDATE, memory cell (p->iNewReg+1+iIdx) contains the required
92940 ** value. Make a copy of the cell contents and return a pointer to it.
92941 ** It is not safe to return a pointer to the memory cell itself as the
92942 ** caller may modify the value text encoding.
92943 */
92944 assert( p->op==SQLITE_UPDATE );
@@ -92947,17 +92950,17 @@
92947 if( !p->aNew ){
92948 rc = SQLITE_NOMEM;
92949 goto preupdate_new_out;
92950 }
92951 }
92952 assert( iIdx>=0 && iIdx<p->pCsr->nField );
92953 pMem = &p->aNew[iIdx];
92954 if( pMem->flags==0 ){
92955 if( iIdx==p->pTab->iPKey ){
92956 sqlite3VdbeMemSetInt64(pMem, p->iKey2);
92957 }else{
92958 rc = sqlite3VdbeMemCopy(pMem, &p->v->aMem[p->iNewReg+1+iIdx]);
92959 if( rc!=SQLITE_OK ) goto preupdate_new_out;
92960 }
92961 }
92962 }
92963 *ppValue = pMem;
@@ -94042,10 +94045,11 @@
94042 }
94043 static void registerTrace(int iReg, Mem *p){
94044 printf("R[%d] = ", iReg);
94045 memTracePrint(p);
94046 if( p->pScopyFrom ){
 
94047 printf(" <== R[%d]", (int)(p->pScopyFrom - &p[-iReg]));
94048 }
94049 printf("\n");
94050 sqlite3VdbeCheckMemInvariants(p);
94051 }
@@ -95025,10 +95029,11 @@
95025 #ifdef SQLITE_DEBUG
95026 pIn1->pScopyFrom = 0;
95027 { int i;
95028 for(i=1; i<p->nMem; i++){
95029 if( aMem[i].pScopyFrom==pIn1 ){
 
95030 aMem[i].pScopyFrom = pOut;
95031 }
95032 }
95033 }
95034 #endif
@@ -95097,10 +95102,11 @@
95097 assert( pOut!=pIn1 );
95098 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
95099 #ifdef SQLITE_DEBUG
95100 pOut->pScopyFrom = pIn1;
95101 pOut->mScopyFlags = pIn1->flags;
 
95102 #endif
95103 break;
95104 }
95105
95106 /* Opcode: IntCopy P1 P2 * * *
@@ -111360,20 +111366,17 @@
111360 SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3 *db, const IdList *p){
111361 IdList *pNew;
111362 int i;
111363 assert( db!=0 );
111364 if( p==0 ) return 0;
111365 assert( p->eU4!=EU4_EXPR );
111366 pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew)+(p->nId-1)*sizeof(p->a[0]) );
111367 if( pNew==0 ) return 0;
111368 pNew->nId = p->nId;
111369 pNew->eU4 = p->eU4;
111370 for(i=0; i<p->nId; i++){
111371 struct IdList_item *pNewItem = &pNew->a[i];
111372 const struct IdList_item *pOldItem = &p->a[i];
111373 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
111374 pNewItem->u4 = pOldItem->u4;
111375 }
111376 return pNew;
111377 }
111378 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, const Select *pDup, int flags){
111379 Select *pRet = 0;
@@ -126726,11 +126729,10 @@
126726 */
126727 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
126728 int i;
126729 assert( db!=0 );
126730 if( pList==0 ) return;
126731 assert( pList->eU4!=EU4_EXPR ); /* EU4_EXPR mode is not currently used */
126732 for(i=0; i<pList->nId; i++){
126733 sqlite3DbFree(db, pList->a[i].zName);
126734 }
126735 sqlite3DbNNFreeNN(db, pList);
126736 }
@@ -128107,16 +128109,22 @@
128107 FuncDef *p, /* The function we are evaluating for match quality */
128108 int nArg, /* Desired number of arguments. (-1)==any */
128109 u8 enc /* Desired text encoding */
128110 ){
128111 int match;
128112 assert( p->nArg>=-1 );
 
128113
128114 /* Wrong number of arguments means "no match" */
128115 if( p->nArg!=nArg ){
128116 if( nArg==(-2) ) return (p->xSFunc==0) ? 0 : FUNC_PERFECT_MATCH;
128117 if( p->nArg>=0 ) return 0;
 
 
 
 
 
128118 }
128119
128120 /* Give a better score to a function with a specific number of arguments
128121 ** than to function that accepts any number of arguments. */
128122 if( p->nArg==nArg ){
@@ -132076,16 +132084,14 @@
132076 FUNCTION(ltrim, 2, 1, 0, trimFunc ),
132077 FUNCTION(rtrim, 1, 2, 0, trimFunc ),
132078 FUNCTION(rtrim, 2, 2, 0, trimFunc ),
132079 FUNCTION(trim, 1, 3, 0, trimFunc ),
132080 FUNCTION(trim, 2, 3, 0, trimFunc ),
132081 FUNCTION(min, -1, 0, 1, minmaxFunc ),
132082 FUNCTION(min, 0, 0, 1, 0 ),
132083 WAGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
132084 SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ),
132085 FUNCTION(max, -1, 1, 1, minmaxFunc ),
132086 FUNCTION(max, 0, 1, 1, 0 ),
132087 WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
132088 SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ),
132089 FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
132090 FUNCTION2(subtype, 1, 0, 0, subtypeFunc,
132091 SQLITE_FUNC_TYPEOF|SQLITE_SUBTYPE),
@@ -132108,15 +132114,12 @@
132108 FUNCTION(upper, 1, 0, 0, upperFunc ),
132109 FUNCTION(lower, 1, 0, 0, lowerFunc ),
132110 FUNCTION(hex, 1, 0, 0, hexFunc ),
132111 FUNCTION(unhex, 1, 0, 0, unhexFunc ),
132112 FUNCTION(unhex, 2, 0, 0, unhexFunc ),
132113 FUNCTION(concat, -1, 0, 0, concatFunc ),
132114 FUNCTION(concat, 0, 0, 0, 0 ),
132115 FUNCTION(concat_ws, -1, 0, 0, concatwsFunc ),
132116 FUNCTION(concat_ws, 0, 0, 0, 0 ),
132117 FUNCTION(concat_ws, 1, 0, 0, 0 ),
132118 INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, 0 ),
132119 VFUNCTION(random, 0, 0, 0, randomFunc ),
132120 VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
132121 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
132122 DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
@@ -132156,12 +132159,10 @@
132156 LIKEFUNC(like, 3, &likeInfoNorm, SQLITE_FUNC_LIKE),
132157 #endif
132158 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
132159 FUNCTION(unknown, -1, 0, 0, unknownFunc ),
132160 #endif
132161 FUNCTION(coalesce, 1, 0, 0, 0 ),
132162 FUNCTION(coalesce, 0, 0, 0, 0 ),
132163 #ifdef SQLITE_ENABLE_MATH_FUNCTIONS
132164 MFUNCTION(ceil, 1, xCeil, ceilingFunc ),
132165 MFUNCTION(ceiling, 1, xCeil, ceilingFunc ),
132166 MFUNCTION(floor, 1, xFloor, ceilingFunc ),
132167 #if SQLITE_HAVE_C99_MATH_FUNCS
@@ -132195,15 +132196,13 @@
132195 MFUNCTION(radians, 1, degToRad, math1Func ),
132196 MFUNCTION(degrees, 1, radToDeg, math1Func ),
132197 MFUNCTION(pi, 0, 0, piFunc ),
132198 #endif /* SQLITE_ENABLE_MATH_FUNCTIONS */
132199 FUNCTION(sign, 1, 0, 0, signFunc ),
132200 INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, 0 ),
132201 INLINE_FUNC(iif, 2, INLINEFUNC_iif, 0 ),
132202 INLINE_FUNC(iif, 3, INLINEFUNC_iif, 0 ),
132203 INLINE_FUNC(if, 2, INLINEFUNC_iif, 0 ),
132204 INLINE_FUNC(if, 3, INLINEFUNC_iif, 0 ),
132205 };
132206 #ifndef SQLITE_OMIT_ALTERTABLE
132207 sqlite3AlterFunctions();
132208 #endif
132209 sqlite3WindowFunctions();
@@ -134645,10 +134644,11 @@
134645 int regRowCount = 0; /* Memory cell used for the row counter */
134646 int regIns; /* Block of regs holding rowid+data being inserted */
134647 int regRowid; /* registers holding insert rowid */
134648 int regData; /* register holding first column to insert */
134649 int *aRegIdx = 0; /* One register allocated to each index */
 
134650
134651 #ifndef SQLITE_OMIT_TRIGGER
134652 int isView; /* True if attempting to insert into a view */
134653 Trigger *pTrigger; /* List of triggers on pTab, if required */
134654 int tmask; /* Mask of trigger times */
@@ -134789,19 +134789,19 @@
134789 ** columns into storage order. False negatives are harmless,
134790 ** but false positives will cause database corruption.
134791 */
134792 bIdListInOrder = (pTab->tabFlags & (TF_OOOHidden|TF_HasStored))==0;
134793 if( pColumn ){
134794 assert( pColumn->eU4!=EU4_EXPR );
134795 pColumn->eU4 = EU4_IDX;
134796 for(i=0; i<pColumn->nId; i++){
134797 pColumn->a[i].u4.idx = -1;
134798 }
134799 for(i=0; i<pColumn->nId; i++){
134800 for(j=0; j<pTab->nCol; j++){
134801 if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zCnName)==0 ){
134802 pColumn->a[i].u4.idx = j;
134803 if( i!=j ) bIdListInOrder = 0;
134804 if( j==pTab->iPKey ){
134805 ipkColumn = i; assert( !withoutRowid );
134806 }
134807 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
@@ -135119,21 +135119,21 @@
135119 iRegStore);
135120 continue;
135121 }
135122 }
135123 if( pColumn ){
135124 assert( pColumn->eU4==EU4_IDX );
135125 for(j=0; j<pColumn->nId && pColumn->a[j].u4.idx!=i; j++){}
135126 if( j>=pColumn->nId ){
135127 /* A column not named in the insert column list gets its
135128 ** default value */
135129 sqlite3ExprCodeFactorable(pParse,
135130 sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
135131 iRegStore);
135132 continue;
135133 }
135134 k = j;
135135 }else if( nColumn==0 ){
135136 /* This is INSERT INTO ... DEFAULT VALUES. Load the default value. */
135137 sqlite3ExprCodeFactorable(pParse,
135138 sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
135139 iRegStore);
@@ -135374,11 +135374,14 @@
135374 insert_cleanup:
135375 sqlite3SrcListDelete(db, pTabList);
135376 sqlite3ExprListDelete(db, pList);
135377 sqlite3UpsertDelete(db, pUpsert);
135378 sqlite3SelectDelete(db, pSelect);
135379 sqlite3IdListDelete(db, pColumn);
 
 
 
135380 if( aRegIdx ) sqlite3DbNNFreeNN(db, aRegIdx);
135381 }
135382
135383 /* Make sure "isView" and other macros defined above are undefined. Otherwise
135384 ** they may interfere with compilation of other functions in this file
@@ -157961,12 +157964,14 @@
157961 u16 nLTerm; /* Number of entries in aLTerm[] */
157962 u16 nSkip; /* Number of NULL aLTerm[] entries */
157963 /**** whereLoopXfer() copies fields above ***********************/
157964 # define WHERE_LOOP_XFER_SZ offsetof(WhereLoop,nLSlot)
157965 u16 nLSlot; /* Number of slots allocated for aLTerm[] */
 
157966 LogEst rStarDelta; /* Cost delta due to star-schema heuristic. Not
157967 ** initialized unless pWInfo->nOutStarDelta>0 */
 
157968 WhereTerm **aLTerm; /* WhereTerms used */
157969 WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */
157970 WhereTerm *aLTermSpace[3]; /* Initial aLTerm[] space */
157971 };
157972
@@ -158011,11 +158016,11 @@
158011 struct WherePath {
158012 Bitmask maskLoop; /* Bitmask of all WhereLoop objects in this path */
158013 Bitmask revLoop; /* aLoop[]s that should be reversed for ORDER BY */
158014 LogEst nRow; /* Estimated number of rows generated by this path */
158015 LogEst rCost; /* Total cost of this path */
158016 LogEst rUnsorted; /* Total cost of this path ignoring sorting costs */
158017 i8 isOrdered; /* No. of ORDER BY terms satisfied. -1 for unknown */
158018 WhereLoop **aLoop; /* Array of WhereLoop objects implementing this path */
158019 };
158020
158021 /*
@@ -158284,13 +158289,17 @@
158284 u8 eOnePass; /* ONEPASS_OFF, or _SINGLE, or _MULTI */
158285 u8 eDistinct; /* One of the WHERE_DISTINCT_* values */
158286 unsigned bDeferredSeek :1; /* Uses OP_DeferredSeek */
158287 unsigned untestedTerms :1; /* Not all WHERE terms resolved by outer loop */
158288 unsigned bOrderedInnerLoop:1;/* True if only the inner-most loop is ordered */
158289 unsigned sorted :1; /* True if really sorted (not just grouped) */
158290 LogEst nOutStarDelta; /* Artifical nOut reduction for star-query */
 
158291 LogEst nRowOut; /* Estimated number of output rows */
 
 
 
158292 int iTop; /* The very beginning of the WHERE loop */
158293 int iEndWhere; /* End of the WHERE clause itself */
158294 WhereLoop *pLoops; /* List of all WhereLoop objects */
158295 WhereMemBlock *pMemToFree;/* Memory to free when this object destroyed */
158296 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
@@ -164232,11 +164241,11 @@
164232 char *zText = 0;
164233 int ii = 0;
164234 sqlite3_str *pStr = sqlite3_str_new(pParse->db);
164235 sqlite3_str_appendf(pStr,"CREATE AUTOMATIC INDEX ON %s(", pTab->zName);
164236 assert( pIdx->nColumn>1 );
164237 assert( pIdx->aiColumn[pIdx->nColumn-1]==XN_ROWID );
164238 for(ii=0; ii<(pIdx->nColumn-1); ii++){
164239 const char *zName = 0;
164240 int iCol = pIdx->aiColumn[ii];
164241
164242 zName = pTab->aCol[iCol].zCnName;
@@ -164362,10 +164371,23 @@
164362 */
164363 if( IsView(pTable) ){
164364 extraCols = ALLBITS & ~idxCols;
164365 }else{
164366 extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));
 
 
 
 
 
 
 
 
 
 
 
 
 
164367 }
164368 mxBitCol = MIN(BMS-1,pTable->nCol);
164369 testcase( pTable->nCol==BMS-1 );
164370 testcase( pTable->nCol==BMS-2 );
164371 for(i=0; i<mxBitCol; i++){
@@ -164374,11 +164396,12 @@
164374 if( pSrc->colUsed & MASKBIT(BMS-1) ){
164375 nKeyCol += pTable->nCol - BMS + 1;
164376 }
164377
164378 /* Construct the Index object to describe this index */
164379 pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);
 
164380 if( pIdx==0 ) goto end_auto_index_create;
164381 pLoop->u.btree.pIndex = pIdx;
164382 pIdx->zName = "auto-index";
164383 pIdx->pTable = pTable;
164384 n = 0;
@@ -164430,12 +164453,14 @@
164430 pIdx->azColl[n] = sqlite3StrBINARY;
164431 n++;
164432 }
164433 }
164434 assert( n==nKeyCol );
164435 pIdx->aiColumn[n] = XN_ROWID;
164436 pIdx->azColl[n] = sqlite3StrBINARY;
 
 
164437
164438 /* Create the automatic index */
164439 explainAutomaticIndex(pParse, pIdx, pPartial!=0, &addrExp);
164440 assert( pLevel->iIdxCur>=0 );
164441 pLevel->iIdxCur = pParse->nTab++;
@@ -165698,21 +165723,23 @@
165698 ** | | | __|__ nEq ---. ___|__ | __|__
165699 ** | / \ / \ / \ | / \ / \ / \
165700 ** 1.002.001 t2.t2xy 2 f 010241 N 2 cost 0,56,31
165701 */
165702 SQLITE_PRIVATE void sqlite3WhereLoopPrint(const WhereLoop *p, const WhereClause *pWC){
 
165703 if( pWC ){
165704 WhereInfo *pWInfo = pWC->pWInfo;
165705 int nb = 1+(pWInfo->pTabList->nSrc+3)/4;
165706 SrcItem *pItem = pWInfo->pTabList->a + p->iTab;
165707 Table *pTab = pItem->pSTab;
165708 Bitmask mAll = (((Bitmask)1)<<(nb*4)) - 1;
165709 sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
165710 p->iTab, nb, p->maskSelf, nb, p->prereq & mAll);
165711 sqlite3DebugPrintf(" %12s",
165712 pItem->zAlias ? pItem->zAlias : pTab->zName);
165713 }else{
 
165714 sqlite3DebugPrintf("%c%2d.%03llx.%03llx %c%d",
165715 p->cId, p->iTab, p->maskSelf, p->prereq & 0xfff, p->cId, p->iTab);
165716 }
165717 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
165718 const char *zName;
@@ -165740,11 +165767,16 @@
165740 if( p->wsFlags & WHERE_SKIPSCAN ){
165741 sqlite3DebugPrintf(" f %06x %d-%d", p->wsFlags, p->nLTerm,p->nSkip);
165742 }else{
165743 sqlite3DebugPrintf(" f %06x N %d", p->wsFlags, p->nLTerm);
165744 }
165745 sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
 
 
 
 
 
165746 if( p->nLTerm && (sqlite3WhereTrace & 0x4000)!=0 ){
165747 int i;
165748 for(i=0; i<p->nLTerm; i++){
165749 sqlite3WhereTermPrint(p->aLTerm[i], i);
165750 }
@@ -167206,11 +167238,10 @@
167206 if( !pBuilder->pOrSet /* Not part of an OR optimization */
167207 && (pWInfo->wctrlFlags & (WHERE_RIGHT_JOIN|WHERE_OR_SUBCLAUSE))==0
167208 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
167209 && !pSrc->fg.isIndexedBy /* Has no INDEXED BY clause */
167210 && !pSrc->fg.notIndexed /* Has no NOT INDEXED clause */
167211 && HasRowid(pTab) /* Not WITHOUT ROWID table. (FIXME: Why not?) */
167212 && !pSrc->fg.isCorrelated /* Not a correlated subquery */
167213 && !pSrc->fg.isRecursive /* Not a recursive common table expression. */
167214 && (pSrc->fg.jointype & JT_RIGHT)==0 /* Not the right tab of a RIGHT JOIN */
167215 ){
167216 /* Generate auto-index WhereLoops */
@@ -168709,72 +168740,205 @@
168709 ** The value returned is a tuning parameter. Currently the value is:
168710 **
168711 ** 18 for star queries
168712 ** 12 otherwise
168713 **
168714 ** For the purposes of SQLite, a star-query is defined as a query
168715 ** with a large central table that is joined against four or more
168716 ** smaller tables. The central table is called the "fact" table.
168717 ** The smaller tables that get joined are "dimension tables".
 
 
 
168718 **
168719 ** SIDE EFFECT: (and really the whole point of this subroutine)
168720 **
168721 ** If pWInfo describes a star-query, then the cost on WhereLoops for the
168722 ** fact table is reduced. This heuristic helps keep fact tables in
168723 ** outer loops. Without this heuristic, paths with fact tables in outer
168724 ** loops tend to get pruned by the mxChoice limit on the number of paths,
168725 ** resulting in poor query plans. The total amount of heuristic cost
168726 ** adjustment is stored in pWInfo->nOutStarDelta and the cost adjustment
168727 ** for each WhereLoop is stored in its rStarDelta field.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168728 */
168729 static int computeMxChoice(WhereInfo *pWInfo, LogEst nRowEst){
168730 int nLoop = pWInfo->nLevel; /* Number of terms in the join */
168731 if( nRowEst==0 && nLoop>=5 ){
168732 /* Check to see if we are dealing with a star schema and if so, reduce
168733 ** the cost of fact tables relative to dimension tables, as a heuristic
168734 ** to help keep the fact tables in outer loops.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168735 */
168736 int iLoop; /* Counter over join terms */
168737 Bitmask m; /* Bitmask for current loop */
168738 assert( pWInfo->nOutStarDelta==0 );
168739 for(iLoop=0, m=1; iLoop<nLoop; iLoop++, m<<=1){
168740 WhereLoop *pWLoop; /* For looping over WhereLoops */
168741 int nDep = 0; /* Number of dimension tables */
168742 LogEst rDelta; /* Heuristic cost adjustment */
168743 Bitmask mSeen = 0; /* Mask of dimension tables */
168744 for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
168745 if( (pWLoop->prereq & m)!=0 && (pWLoop->maskSelf & mSeen)==0 ){
168746 nDep++;
168747 mSeen |= pWLoop->maskSelf;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168748 }
168749 }
168750 if( nDep<=3 ) continue;
168751 rDelta = 15*(nDep-3);
168752 #ifdef WHERETRACE_ENABLED /* 0x4 */
168753 if( sqlite3WhereTrace&0x4 ){
168754 SrcItem *pItem = pWInfo->pTabList->a + iLoop;
168755 sqlite3DebugPrintf("Fact-table %s: %d dimensions, cost reduced %d\n",
168756 pItem->zAlias ? pItem->zAlias : pItem->pSTab->zName,
168757 nDep, rDelta);
168758 }
168759 #endif
168760 if( pWInfo->nOutStarDelta==0 ){
168761 for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
168762 pWLoop->rStarDelta = 0;
168763 }
168764 }
168765 pWInfo->nOutStarDelta += rDelta;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168766 for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
168767 if( pWLoop->maskSelf==m ){
168768 pWLoop->rRun -= rDelta;
168769 pWLoop->nOut -= rDelta;
168770 pWLoop->rStarDelta = rDelta;
168771 }
168772 }
168773 }
 
168774 }
168775 return pWInfo->nOutStarDelta>0 ? 18 : 12;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168776 }
168777
168778 /*
168779 ** Given the list of WhereLoop objects at pWInfo->pLoops, this routine
168780 ** attempts to find the lowest cost path that visits each WhereLoop
@@ -168794,11 +168958,11 @@
168794 int iLoop; /* Loop counter over the terms of the join */
168795 int ii, jj; /* Loop counters */
168796 int mxI = 0; /* Index of next entry to replace */
168797 int nOrderBy; /* Number of ORDER BY clause terms */
168798 LogEst mxCost = 0; /* Maximum cost of a set of paths */
168799 LogEst mxUnsorted = 0; /* Maximum unsorted cost of a set of path */
168800 int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */
168801 WherePath *aFrom; /* All nFrom paths at the previous level */
168802 WherePath *aTo; /* The nTo best paths at the current level */
168803 WherePath *pFrom; /* An element of aFrom[] that we are working on */
168804 WherePath *pTo; /* An element of aTo[] that we are working on */
@@ -168823,12 +168987,14 @@
168823 */
168824 if( nLoop<=1 ){
168825 mxChoice = 1;
168826 }else if( nLoop==2 ){
168827 mxChoice = 5;
 
 
168828 }else{
168829 mxChoice = computeMxChoice(pWInfo, nRowEst);
168830 }
168831 assert( nLoop<=pWInfo->pTabList->nSrc );
168832
168833 /* If nRowEst is zero and there is an ORDER BY clause, ignore it. In this
168834 ** case the purpose of this call is to estimate the number of rows returned
@@ -168891,11 +169057,11 @@
168891 nTo = 0;
168892 for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){
168893 for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
168894 LogEst nOut; /* Rows visited by (pFrom+pWLoop) */
168895 LogEst rCost; /* Cost of path (pFrom+pWLoop) */
168896 LogEst rUnsorted; /* Unsorted cost of (pFrom+pWLoop) */
168897 i8 isOrdered; /* isOrdered for (pFrom+pWLoop) */
168898 Bitmask maskNew; /* Mask of src visited by (..) */
168899 Bitmask revMask; /* Mask of rev-order loops for (..) */
168900
168901 if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue;
@@ -168909,15 +169075,15 @@
168909 continue;
168910 }
168911
168912 /* At this point, pWLoop is a candidate to be the next loop.
168913 ** Compute its cost */
168914 rUnsorted = pWLoop->rRun + pFrom->nRow;
168915 if( pWLoop->rSetup ){
168916 rUnsorted = sqlite3LogEstAdd(pWLoop->rSetup, rUnsorted);
168917 }
168918 rUnsorted = sqlite3LogEstAdd(rUnsorted, pFrom->rUnsorted);
168919 nOut = pFrom->nRow + pWLoop->nOut;
168920 maskNew = pFrom->maskLoop | pWLoop->maskSelf;
168921 isOrdered = pFrom->isOrdered;
168922 if( isOrdered<0 ){
168923 revMask = 0;
@@ -168935,19 +169101,19 @@
168935 }
168936 /* TUNING: Add a small extra penalty (3) to sorting as an
168937 ** extra encouragement to the query planner to select a plan
168938 ** where the rows emerge in the correct order without any sorting
168939 ** required. */
168940 rCost = sqlite3LogEstAdd(rUnsorted, aSortCost[isOrdered]) + 3;
168941
168942 WHERETRACE(0x002,
168943 ("---- sort cost=%-3d (%d/%d) increases cost %3d to %-3d\n",
168944 aSortCost[isOrdered], (nOrderBy-isOrdered), nOrderBy,
168945 rUnsorted, rCost));
168946 }else{
168947 rCost = rUnsorted;
168948 rUnsorted -= 2; /* TUNING: Slight bias in favor of no-sort plans */
168949 }
168950
168951 /* Check to see if pWLoop should be added to the set of
168952 ** mxChoice best-so-far paths.
168953 **
@@ -168969,19 +169135,19 @@
168969 }
168970 }
168971 if( jj>=nTo ){
168972 /* None of the existing best-so-far paths match the candidate. */
168973 if( nTo>=mxChoice
168974 && (rCost>mxCost || (rCost==mxCost && rUnsorted>=mxUnsorted))
168975 ){
168976 /* The current candidate is no better than any of the mxChoice
168977 ** paths currently in the best-so-far buffer. So discard
168978 ** this candidate as not viable. */
168979 #ifdef WHERETRACE_ENABLED /* 0x4 */
168980 if( sqlite3WhereTrace&0x4 ){
168981 sqlite3DebugPrintf("Skip %s cost=%-3d,%3d,%3d order=%c\n",
168982 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsorted,
168983 isOrdered>=0 ? isOrdered+'0' : '?');
168984 }
168985 #endif
168986 continue;
168987 }
@@ -168996,11 +169162,11 @@
168996 }
168997 pTo = &aTo[jj];
168998 #ifdef WHERETRACE_ENABLED /* 0x4 */
168999 if( sqlite3WhereTrace&0x4 ){
169000 sqlite3DebugPrintf("New %s cost=%-3d,%3d,%3d order=%c\n",
169001 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsorted,
169002 isOrdered>=0 ? isOrdered+'0' : '?');
169003 }
169004 #endif
169005 }else{
169006 /* Control reaches here if best-so-far path pTo=aTo[jj] covers the
@@ -169007,28 +169173,27 @@
169007 ** same set of loops and has the same isOrdered setting as the
169008 ** candidate path. Check to see if the candidate should replace
169009 ** pTo or if the candidate should be skipped.
169010 **
169011 ** The conditional is an expanded vector comparison equivalent to:
169012 ** (pTo->rCost,pTo->nRow,pTo->rUnsorted) <= (rCost,nOut,rUnsorted)
169013 */
169014 if( pTo->rCost<rCost
169015 || (pTo->rCost==rCost
169016 && (pTo->nRow<nOut
169017 || (pTo->nRow==nOut && pTo->rUnsorted<=rUnsorted)
169018 )
169019 )
169020 ){
169021 #ifdef WHERETRACE_ENABLED /* 0x4 */
169022 if( sqlite3WhereTrace&0x4 ){
169023 sqlite3DebugPrintf(
169024 "Skip %s cost=%-3d,%3d,%3d order=%c",
169025 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsorted,
169026 isOrdered>=0 ? isOrdered+'0' : '?');
169027 sqlite3DebugPrintf(" vs %s cost=%-3d,%3d,%3d order=%c\n",
169028 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
169029 pTo->rUnsorted, pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?');
169030 }
169031 #endif
169032 /* Discard the candidate path from further consideration */
169033 testcase( pTo->rCost==rCost );
169034 continue;
@@ -169038,37 +169203,37 @@
169038 ** pTo path. Replace pTo with the candidate. */
169039 #ifdef WHERETRACE_ENABLED /* 0x4 */
169040 if( sqlite3WhereTrace&0x4 ){
169041 sqlite3DebugPrintf(
169042 "Update %s cost=%-3d,%3d,%3d order=%c",
169043 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsorted,
169044 isOrdered>=0 ? isOrdered+'0' : '?');
169045 sqlite3DebugPrintf(" was %s cost=%-3d,%3d,%3d order=%c\n",
169046 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
169047 pTo->rUnsorted, pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?');
169048 }
169049 #endif
169050 }
169051 /* pWLoop is a winner. Add it to the set of best so far */
169052 pTo->maskLoop = pFrom->maskLoop | pWLoop->maskSelf;
169053 pTo->revLoop = revMask;
169054 pTo->nRow = nOut;
169055 pTo->rCost = rCost;
169056 pTo->rUnsorted = rUnsorted;
169057 pTo->isOrdered = isOrdered;
169058 memcpy(pTo->aLoop, pFrom->aLoop, sizeof(WhereLoop*)*iLoop);
169059 pTo->aLoop[iLoop] = pWLoop;
169060 if( nTo>=mxChoice ){
169061 mxI = 0;
169062 mxCost = aTo[0].rCost;
169063 mxUnsorted = aTo[0].nRow;
169064 for(jj=1, pTo=&aTo[1]; jj<mxChoice; jj++, pTo++){
169065 if( pTo->rCost>mxCost
169066 || (pTo->rCost==mxCost && pTo->rUnsorted>mxUnsorted)
169067 ){
169068 mxCost = pTo->rCost;
169069 mxUnsorted = pTo->rUnsorted;
169070 mxI = jj;
169071 }
169072 }
169073 }
169074 }
@@ -169076,12 +169241,14 @@
169076
169077 #ifdef WHERETRACE_ENABLED /* >=2 */
169078 if( sqlite3WhereTrace & 0x02 ){
169079 LogEst rMin, rFloor = 0;
169080 int nDone = 0;
 
169081 sqlite3DebugPrintf("---- after round %d ----\n", iLoop);
169082 while( nDone<nTo ){
 
169083 rMin = 0x7fff;
169084 for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
169085 if( pTo->rCost>rFloor && pTo->rCost<rMin ) rMin = pTo->rCost;
169086 }
169087 for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
@@ -169093,14 +169260,15 @@
169093 sqlite3DebugPrintf(" rev=0x%llx\n", pTo->revLoop);
169094 }else{
169095 sqlite3DebugPrintf("\n");
169096 }
169097 nDone++;
 
169098 }
169099 }
169100 rFloor = rMin;
169101 }
169102 }
169103 #endif
169104
169105 /* Swap the roles of aFrom and aTo for the next generation */
169106 pFrom = aTo;
@@ -169190,11 +169358,14 @@
169190 pWInfo->revMask = revMask;
169191 }
169192 }
169193 }
169194
169195 pWInfo->nRowOut = pFrom->nRow + pWInfo->nOutStarDelta;
 
 
 
169196
169197 /* Free temporary memory and return success */
169198 sqlite3StackFreeNN(pParse->db, pSpace);
169199 return SQLITE_OK;
169200 }
@@ -169588,11 +169759,10 @@
169588 pLoop->cId, (double)sqlite3LogEstToInt(nSearch), pTab->zName,
169589 (double)sqlite3LogEstToInt(pTab->nRowLogEst)));
169590 }
169591 }
169592 nSearch += pLoop->nOut;
169593 if( pWInfo->nOutStarDelta ) nSearch += pLoop->rStarDelta;
169594 }
169595 }
169596
169597 /*
169598 ** The index pIdx is used by a query and contains one or more expressions.
@@ -170071,11 +170241,12 @@
170071 goto whereBeginError;
170072 }
170073 assert( db->mallocFailed==0 );
170074 #ifdef WHERETRACE_ENABLED
170075 if( sqlite3WhereTrace ){
170076 sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
 
170077 if( pWInfo->nOBSat>0 ){
170078 sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
170079 }
170080 switch( pWInfo->eDistinct ){
170081 case WHERE_DISTINCT_UNIQUE: {
@@ -226574,15 +226745,17 @@
226574 ** SELECT 1, NULL, 'abc'
226575 */
226576 struct SessionTable {
226577 SessionTable *pNext;
226578 char *zName; /* Local name of table */
226579 int nCol; /* Number of columns in table zName */
 
226580 int bStat1; /* True if this is sqlite_stat1 */
226581 int bRowid; /* True if this table uses rowid for PK */
226582 const char **azCol; /* Column names */
226583 const char **azDflt; /* Default value expressions */
 
226584 u8 *abPK; /* Array of primary key flags */
226585 int nEntry; /* Total number of entries in hash table */
226586 int nChange; /* Size of apChange[] array */
226587 SessionChange **apChange; /* Hash table buckets */
226588 sqlite3_stmt *pDfltStmt;
@@ -226981,26 +227154,26 @@
226981 int *pbNullPK /* OUT: True if there are NULL values in PK */
226982 ){
226983 unsigned int h = 0; /* Hash value to return */
226984 int i; /* Used to iterate through columns */
226985
 
226986 if( pTab->bRowid ){
226987 assert( pTab->nCol-1==pSession->hook.xCount(pSession->hook.pCtx) );
226988 h = sessionHashAppendI64(h, iRowid);
226989 }else{
226990 assert( *pbNullPK==0 );
226991 assert( pTab->nCol==pSession->hook.xCount(pSession->hook.pCtx) );
226992 for(i=0; i<pTab->nCol; i++){
226993 if( pTab->abPK[i] ){
226994 int rc;
226995 int eType;
226996 sqlite3_value *pVal;
 
226997
226998 if( bNew ){
226999 rc = pSession->hook.xNew(pSession->hook.pCtx, i, &pVal);
227000 }else{
227001 rc = pSession->hook.xOld(pSession->hook.pCtx, i, &pVal);
227002 }
227003 if( rc!=SQLITE_OK ) return rc;
227004
227005 eType = sqlite3_value_type(pVal);
227006 h = sessionHashAppendType(h, eType);
@@ -227333,22 +227506,23 @@
227333 a += sessionSerialLen(a);
227334 }else{
227335 sqlite3_value *pVal; /* Value returned by preupdate_new/old */
227336 int rc; /* Error code from preupdate_new/old */
227337 int eType = *a++; /* Type of value from change record */
 
227338
227339 /* The following calls to preupdate_new() and preupdate_old() can not
227340 ** fail. This is because they cache their return values, and by the
227341 ** time control flows to here they have already been called once from
227342 ** within sessionPreupdateHash(). The first two asserts below verify
227343 ** this (that the method has already been called). */
227344 if( op==SQLITE_INSERT ){
227345 /* assert( db->pPreUpdate->pNewUnpacked || db->pPreUpdate->aNew ); */
227346 rc = pSession->hook.xNew(pSession->hook.pCtx, iCol, &pVal);
227347 }else{
227348 /* assert( db->pPreUpdate->pUnpacked ); */
227349 rc = pSession->hook.xOld(pSession->hook.pCtx, iCol, &pVal);
227350 }
227351 assert( rc==SQLITE_OK );
227352 (void)rc; /* Suppress warning about unused variable */
227353 if( sqlite3_value_type(pVal)!=eType ) return 0;
227354
@@ -227469,13 +227643,15 @@
227469 sqlite3_session *pSession, /* For memory accounting. May be NULL */
227470 sqlite3 *db, /* Database connection */
227471 const char *zDb, /* Name of attached database (e.g. "main") */
227472 const char *zThis, /* Table name */
227473 int *pnCol, /* OUT: number of columns */
 
227474 const char **pzTab, /* OUT: Copy of zThis */
227475 const char ***pazCol, /* OUT: Array of column names for table */
227476 const char ***pazDflt, /* OUT: Array of default value expressions */
 
227477 u8 **pabPK, /* OUT: Array of booleans - true for PK col */
227478 int *pbRowid /* OUT: True if only PK is a rowid */
227479 ){
227480 char *zPragma;
227481 sqlite3_stmt *pStmt;
@@ -227486,37 +227662,40 @@
227486 int i;
227487 u8 *pAlloc = 0;
227488 char **azCol = 0;
227489 char **azDflt = 0;
227490 u8 *abPK = 0;
 
227491 int bRowid = 0; /* Set to true to use rowid as PK */
227492
227493 assert( pazCol && pabPK );
227494
227495 *pazCol = 0;
227496 *pabPK = 0;
227497 *pnCol = 0;
 
 
227498 if( pzTab ) *pzTab = 0;
227499 if( pazDflt ) *pazDflt = 0;
227500
227501 nThis = sqlite3Strlen30(zThis);
227502 if( nThis==12 && 0==sqlite3_stricmp("sqlite_stat1", zThis) ){
227503 rc = sqlite3_table_column_metadata(db, zDb, zThis, 0, 0, 0, 0, 0, 0);
227504 if( rc==SQLITE_OK ){
227505 /* For sqlite_stat1, pretend that (tbl,idx) is the PRIMARY KEY. */
227506 zPragma = sqlite3_mprintf(
227507 "SELECT 0, 'tbl', '', 0, '', 1 UNION ALL "
227508 "SELECT 1, 'idx', '', 0, '', 2 UNION ALL "
227509 "SELECT 2, 'stat', '', 0, '', 0"
227510 );
227511 }else if( rc==SQLITE_ERROR ){
227512 zPragma = sqlite3_mprintf("");
227513 }else{
227514 return rc;
227515 }
227516 }else{
227517 zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis);
227518 }
227519 if( !zPragma ){
227520 return SQLITE_NOMEM;
227521 }
227522
@@ -227529,20 +227708,22 @@
227529 nByte = nThis + 1;
227530 bRowid = (pbRowid!=0);
227531 while( SQLITE_ROW==sqlite3_step(pStmt) ){
227532 nByte += sqlite3_column_bytes(pStmt, 1); /* name */
227533 nByte += sqlite3_column_bytes(pStmt, 4); /* dflt_value */
227534 nDbCol++;
 
 
227535 if( sqlite3_column_int(pStmt, 5) ) bRowid = 0; /* pk */
227536 }
227537 if( nDbCol==0 ) bRowid = 0;
227538 nDbCol += bRowid;
227539 nByte += strlen(SESSIONS_ROWID);
227540 rc = sqlite3_reset(pStmt);
227541
227542 if( rc==SQLITE_OK ){
227543 nByte += nDbCol * (sizeof(const char *)*2 + sizeof(u8) + 1 + 1);
227544 pAlloc = sessionMalloc64(pSession, nByte);
227545 if( pAlloc==0 ){
227546 rc = SQLITE_NOMEM;
227547 }else{
227548 memset(pAlloc, 0, nByte);
@@ -227549,12 +227730,12 @@
227549 }
227550 }
227551 if( rc==SQLITE_OK ){
227552 azCol = (char **)pAlloc;
227553 azDflt = (char**)&azCol[nDbCol];
227554 pAlloc = (u8 *)&azDflt[nDbCol];
227555 abPK = (u8 *)pAlloc;
227556 pAlloc = &abPK[nDbCol];
227557 if( pzTab ){
227558 memcpy(pAlloc, zThis, nThis+1);
227559 *pzTab = (char *)pAlloc;
227560 pAlloc += nThis+1;
@@ -227565,31 +227746,36 @@
227565 size_t nName = strlen(SESSIONS_ROWID);
227566 memcpy(pAlloc, SESSIONS_ROWID, nName+1);
227567 azCol[i] = (char*)pAlloc;
227568 pAlloc += nName+1;
227569 abPK[i] = 1;
 
227570 i++;
227571 }
227572 while( SQLITE_ROW==sqlite3_step(pStmt) ){
227573 int nName = sqlite3_column_bytes(pStmt, 1);
227574 int nDflt = sqlite3_column_bytes(pStmt, 4);
227575 const unsigned char *zName = sqlite3_column_text(pStmt, 1);
227576 const unsigned char *zDflt = sqlite3_column_text(pStmt, 4);
227577
227578 if( zName==0 ) break;
227579 memcpy(pAlloc, zName, nName+1);
227580 azCol[i] = (char *)pAlloc;
227581 pAlloc += nName+1;
227582 if( zDflt ){
227583 memcpy(pAlloc, zDflt, nDflt+1);
227584 azDflt[i] = (char *)pAlloc;
227585 pAlloc += nDflt+1;
227586 }else{
227587 azDflt[i] = 0;
227588 }
227589 abPK[i] = sqlite3_column_int(pStmt, 5);
227590 i++;
 
 
 
 
227591 }
227592 rc = sqlite3_reset(pStmt);
227593 }
227594
227595 /* If successful, populate the output variables. Otherwise, zero them and
@@ -227598,10 +227784,11 @@
227598 if( rc==SQLITE_OK ){
227599 *pazCol = (const char**)azCol;
227600 if( pazDflt ) *pazDflt = (const char**)azDflt;
227601 *pabPK = abPK;
227602 *pnCol = nDbCol;
 
227603 }else{
227604 sessionFree(pSession, azCol);
227605 }
227606 if( pbRowid ) *pbRowid = bRowid;
227607 sqlite3_finalize(pStmt);
@@ -227629,11 +227816,12 @@
227629
227630 if( pTab->nCol==0 ){
227631 u8 *abPK;
227632 assert( pTab->azCol==0 || pTab->abPK==0 );
227633 rc = sessionTableInfo(pSession, db, zDb,
227634 pTab->zName, &pTab->nCol, 0, &pTab->azCol, &pTab->azDflt, &abPK,
 
227635 ((pSession==0 || pSession->bImplicitPK) ? &pTab->bRowid : 0)
227636 );
227637 if( rc==SQLITE_OK ){
227638 int i;
227639 for(i=0; i<pTab->nCol; i++){
@@ -227664,19 +227852,21 @@
227664 /*
227665 ** Re-initialize table object pTab.
227666 */
227667 static int sessionReinitTable(sqlite3_session *pSession, SessionTable *pTab){
227668 int nCol = 0;
 
227669 const char **azCol = 0;
227670 const char **azDflt = 0;
 
227671 u8 *abPK = 0;
227672 int bRowid = 0;
227673
227674 assert( pSession->rc==SQLITE_OK );
227675
227676 pSession->rc = sessionTableInfo(pSession, pSession->db, pSession->zDb,
227677 pTab->zName, &nCol, 0, &azCol, &azDflt, &abPK,
227678 (pSession->bImplicitPK ? &bRowid : 0)
227679 );
227680 if( pSession->rc==SQLITE_OK ){
227681 if( pTab->nCol>nCol || pTab->bRowid!=bRowid ){
227682 pSession->rc = SQLITE_SCHEMA;
@@ -227695,12 +227885,14 @@
227695
227696 if( pSession->rc==SQLITE_OK ){
227697 const char **a = pTab->azCol;
227698 pTab->azCol = azCol;
227699 pTab->nCol = nCol;
 
227700 pTab->azDflt = azDflt;
227701 pTab->abPK = abPK;
 
227702 azCol = a;
227703 }
227704 if( pSession->bEnableSize ){
227705 pSession->nMaxChangesetSize += (nCol - nOldCol);
227706 pSession->nMaxChangesetSize += sessionVarintLen(nCol);
@@ -228014,11 +228206,11 @@
228014 if( pTab->bRowid ) nNew += 9;
228015 if( op!=SQLITE_DELETE ){
228016 int ii;
228017 for(ii=0; ii<pTab->nCol; ii++){
228018 sqlite3_value *p = 0;
228019 pSession->hook.xNew(pSession->hook.pCtx, ii, &p);
228020 sessionSerializeValue(0, p, &nNew);
228021 }
228022 }
228023 }else if( op==SQLITE_DELETE ){
228024 nNew += pC->nRecord;
@@ -228034,12 +228226,13 @@
228034 }
228035 for(ii=pTab->bRowid; ii<pTab->nCol; ii++){
228036 int bChanged = 1;
228037 int nOld = 0;
228038 int eType;
 
228039 sqlite3_value *p = 0;
228040 pSession->hook.xNew(pSession->hook.pCtx, ii-pTab->bRowid, &p);
228041 if( p==0 ){
228042 return SQLITE_NOMEM;
228043 }
228044
228045 eType = *pCsr++;
@@ -228132,15 +228325,15 @@
228132 if( sessionInitTable(pSession, pTab, pSession->db, pSession->zDb) ) return;
228133
228134 /* Check the number of columns in this xPreUpdate call matches the
228135 ** number of columns in the table. */
228136 nExpect = pSession->hook.xCount(pSession->hook.pCtx);
228137 if( (pTab->nCol-pTab->bRowid)<nExpect ){
228138 if( sessionReinitTable(pSession, pTab) ) return;
228139 if( sessionUpdateChanges(pSession, pTab) ) return;
228140 }
228141 if( (pTab->nCol-pTab->bRowid)!=nExpect ){
228142 pSession->rc = SQLITE_SCHEMA;
228143 return;
228144 }
228145
228146 /* Grow the hash table if required */
@@ -228193,18 +228386,19 @@
228193 assert( rc==SQLITE_OK );
228194 pTab->nEntry++;
228195
228196 /* Figure out how large an allocation is required */
228197 nByte = sizeof(SessionChange);
228198 for(i=0; i<(pTab->nCol-pTab->bRowid); i++){
 
228199 sqlite3_value *p = 0;
228200 if( op!=SQLITE_INSERT ){
228201 /* This may fail if the column has a non-NULL default and was added
228202 ** using ALTER TABLE ADD COLUMN after this record was created. */
228203 rc = pSession->hook.xOld(pSession->hook.pCtx, i, &p);
228204 }else if( pTab->abPK[i] ){
228205 TESTONLY(int trc = ) pSession->hook.xNew(pSession->hook.pCtx, i, &p);
228206 assert( trc==SQLITE_OK );
228207 }
228208
228209 if( rc==SQLITE_OK ){
228210 /* This may fail if SQLite value p contains a utf-16 string that must
@@ -228235,16 +228429,17 @@
228235 if( pTab->bRowid ){
228236 pC->aRecord[0] = SQLITE_INTEGER;
228237 sessionPutI64(&pC->aRecord[1], iRowid);
228238 nByte = 9;
228239 }
228240 for(i=0; i<(pTab->nCol-pTab->bRowid); i++){
228241 sqlite3_value *p = 0;
 
228242 if( op!=SQLITE_INSERT ){
228243 pSession->hook.xOld(pSession->hook.pCtx, i, &p);
228244 }else if( pTab->abPK[i] ){
228245 pSession->hook.xNew(pSession->hook.pCtx, i, &p);
228246 }
228247 sessionSerializeValue(&pC->aRecord[nByte], p, &nByte);
228248 }
228249
228250 /* Add the change to the hash-table */
@@ -228642,11 +228837,12 @@
228642 int bMismatch = 0;
228643 int nCol; /* Columns in zFrom.zTbl */
228644 int bRowid = 0;
228645 u8 *abPK;
228646 const char **azCol = 0;
228647 rc = sessionTableInfo(0, db, zFrom, zTbl, &nCol, 0, &azCol, 0, &abPK,
 
228648 pSession->bImplicitPK ? &bRowid : 0
228649 );
228650 if( rc==SQLITE_OK ){
228651 if( pTo->nCol!=nCol ){
228652 bMismatch = 1;
@@ -229219,14 +229415,14 @@
229219 sqlite3_stmt **ppStmt /* OUT: Prepared SELECT statement */
229220 ){
229221 int rc = SQLITE_OK;
229222 char *zSql = 0;
229223 const char *zSep = "";
229224 const char *zCols = bRowid ? SESSIONS_ROWID ", *" : "*";
229225 int nSql = -1;
229226 int i;
229227
 
229228 SessionBuffer nooptest = {0, 0, 0};
229229 SessionBuffer pkfield = {0, 0, 0};
229230 SessionBuffer pkvar = {0, 0, 0};
229231
229232 sessionAppendStr(&nooptest, ", 1", &rc);
@@ -229235,13 +229431,20 @@
229235 sessionAppendStr(&nooptest, " AND (?6 OR ?3 IS stat)", &rc);
229236 sessionAppendStr(&pkfield, "tbl, idx", &rc);
229237 sessionAppendStr(&pkvar,
229238 "?1, (CASE WHEN ?2=X'' THEN NULL ELSE ?2 END)", &rc
229239 );
229240 zCols = "tbl, ?2, stat";
229241 }else{
 
 
 
 
 
229242 for(i=0; i<nCol; i++){
 
 
229243 if( abPK[i] ){
229244 sessionAppendStr(&pkfield, zSep, &rc);
229245 sessionAppendStr(&pkvar, zSep, &rc);
229246 zSep = ", ";
229247 sessionAppendIdent(&pkfield, azCol[i], &rc);
@@ -229255,11 +229458,11 @@
229255 }
229256
229257 if( rc==SQLITE_OK ){
229258 zSql = sqlite3_mprintf(
229259 "SELECT %s%s FROM %Q.%Q WHERE (%s) IS (%s)",
229260 zCols, (bIgnoreNoop ? (char*)nooptest.aBuf : ""),
229261 zDb, zTab, (char*)pkfield.aBuf, (char*)pkvar.aBuf
229262 );
229263 if( zSql==0 ) rc = SQLITE_NOMEM;
229264 }
229265
@@ -229298,10 +229501,11 @@
229298 }
229299 sqlite3_free(zSql);
229300 sqlite3_free(nooptest.aBuf);
229301 sqlite3_free(pkfield.aBuf);
229302 sqlite3_free(pkvar.aBuf);
 
229303 return rc;
229304 }
229305
229306 /*
229307 ** Bind the PRIMARY KEY values from the change passed in argument pChange
@@ -231638,11 +231842,12 @@
231638 int nMinCol = 0;
231639 int i;
231640
231641 sqlite3changeset_pk(pIter, &abPK, 0);
231642 rc = sessionTableInfo(0, db, "main", zNew,
231643 &sApply.nCol, &zTab, &sApply.azCol, 0, &sApply.abPK, &sApply.bRowid
 
231644 );
231645 if( rc!=SQLITE_OK ) break;
231646 for(i=0; i<sApply.nCol; i++){
231647 if( sApply.abPK[i] ) nMinCol = i+1;
231648 }
@@ -231718,10 +231923,15 @@
231718 if( res!=SQLITE_CHANGESET_OMIT ){
231719 rc = SQLITE_CONSTRAINT;
231720 }
231721 }
231722 }
 
 
 
 
 
231723
231724 if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){
231725 if( rc==SQLITE_OK ){
231726 rc = sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0);
231727 }
@@ -243230,15 +243440,17 @@
243230 }
243231
243232 /*
243233 ** Close the read-only blob handle, if it is open.
243234 */
243235 static void sqlite3Fts5IndexCloseReader(Fts5Index *p){
243236 if( p->pReader ){
 
243237 sqlite3_blob *pReader = p->pReader;
243238 p->pReader = 0;
243239 sqlite3_blob_close(pReader);
 
243240 }
243241 }
243242
243243 /*
243244 ** Retrieve a record from the %_data table.
@@ -243259,11 +243471,11 @@
243259 p->pReader = 0;
243260 rc = sqlite3_blob_reopen(pBlob, iRowid);
243261 assert( p->pReader==0 );
243262 p->pReader = pBlob;
243263 if( rc!=SQLITE_OK ){
243264 sqlite3Fts5IndexCloseReader(p);
243265 }
243266 if( rc==SQLITE_ABORT ) rc = SQLITE_OK;
243267 }
243268
243269 /* If the blob handle is not open at this point, open it and seek
@@ -247460,10 +247672,18 @@
247460 static int fts5IndexReturn(Fts5Index *p){
247461 int rc = p->rc;
247462 p->rc = SQLITE_OK;
247463 return rc;
247464 }
 
 
 
 
 
 
 
 
247465
247466 typedef struct Fts5FlushCtx Fts5FlushCtx;
247467 struct Fts5FlushCtx {
247468 Fts5Index *pIdx;
247469 Fts5SegWriter writer;
@@ -249182,11 +249402,11 @@
249182 ** Commit data to disk.
249183 */
249184 static int sqlite3Fts5IndexSync(Fts5Index *p){
249185 assert( p->rc==SQLITE_OK );
249186 fts5IndexFlush(p);
249187 sqlite3Fts5IndexCloseReader(p);
249188 return fts5IndexReturn(p);
249189 }
249190
249191 /*
249192 ** Discard any data stored in the in-memory hash tables. Do not write it
@@ -249193,15 +249413,14 @@
249193 ** to the database. Additionally, assume that the contents of the %_data
249194 ** table may have changed on disk. So any in-memory caches of %_data
249195 ** records must be invalidated.
249196 */
249197 static int sqlite3Fts5IndexRollback(Fts5Index *p){
249198 sqlite3Fts5IndexCloseReader(p);
249199 fts5IndexDiscardData(p);
249200 fts5StructureInvalidate(p);
249201 /* assert( p->rc==SQLITE_OK ); */
249202 return SQLITE_OK;
249203 }
249204
249205 /*
249206 ** The %_data table is completely empty when this function is called. This
249207 ** function populates it with the initial structure objects for each index,
@@ -249397,10 +249616,20 @@
249397 */
249398 static void fts5SegIterSetEOF(Fts5SegIter *pSeg){
249399 fts5DataRelease(pSeg->pLeaf);
249400 pSeg->pLeaf = 0;
249401 }
 
 
 
 
 
 
 
 
 
 
249402
249403 /*
249404 ** This function appends iterator pAppend to Fts5TokenDataIter pIn and
249405 ** returns the result.
249406 */
@@ -249425,11 +249654,11 @@
249425 pNew->nIterAlloc = nAlloc;
249426 }
249427 }
249428 }
249429 if( p->rc ){
249430 sqlite3Fts5IterClose((Fts5IndexIter*)pAppend);
249431 }else{
249432 pRet->apIter[pRet->nIter++] = pAppend;
249433 }
249434 assert( pRet==0 || pRet->nIter<=pRet->nIterAlloc );
249435
@@ -249638,11 +249867,11 @@
249638 fts5BufferAppendBlob(&p->rc, &bSeek, 1, (const u8*)"\0");
249639 }else{
249640 fts5BufferSet(&p->rc, &bSeek, nToken, pToken);
249641 }
249642 if( p->rc ){
249643 sqlite3Fts5IterClose((Fts5IndexIter*)pNew);
249644 break;
249645 }
249646
249647 pNewIter = &pNew->aSeg[0];
249648 pPrevIter = (pPrev ? &pPrev->aSeg[0] : 0);
@@ -249703,11 +249932,11 @@
249703
249704 /* If pSmall is still NULL at this point, then the new iterator does
249705 ** not point to any terms that match the query. So delete it and break
249706 ** out of the loop - all required iterators have been collected. */
249707 if( pSmall==0 ){
249708 sqlite3Fts5IterClose((Fts5IndexIter*)pNew);
249709 break;
249710 }
249711
249712 /* Append this iterator to the set and continue. */
249713 pSet = fts5AppendTokendataIter(p, pSet, pNew);
@@ -249832,13 +250061,13 @@
249832 }
249833 }
249834 }
249835
249836 if( p->rc ){
249837 sqlite3Fts5IterClose((Fts5IndexIter*)pRet);
249838 pRet = 0;
249839 sqlite3Fts5IndexCloseReader(p);
249840 }
249841
249842 *ppIter = (Fts5IndexIter*)pRet;
249843 sqlite3Fts5BufferFree(&buf);
249844 }
@@ -250084,15 +250313,13 @@
250084 /*
250085 ** Close an iterator opened by an earlier call to sqlite3Fts5IndexQuery().
250086 */
250087 static void sqlite3Fts5IterClose(Fts5IndexIter *pIndexIter){
250088 if( pIndexIter ){
250089 Fts5Iter *pIter = (Fts5Iter*)pIndexIter;
250090 Fts5Index *pIndex = pIter->pIndex;
250091 fts5TokendataIterDelete(pIter->pTokenDataIter);
250092 fts5MultiIterFree(pIter);
250093 sqlite3Fts5IndexCloseReader(pIndex);
250094 }
250095 }
250096
250097 /*
250098 ** Read and decode the "averages" record from the database.
@@ -250618,11 +250845,11 @@
250618 }
250619 if( rc==SQLITE_OK ){
250620 rc = sqlite3Fts5IterNext(pIter);
250621 }
250622 }
250623 sqlite3Fts5IterClose(pIter);
250624
250625 *pCksum = cksum;
250626 return rc;
250627 }
250628
@@ -255462,11 +255689,11 @@
255462 int nArg, /* Number of args */
255463 sqlite3_value **apUnused /* Function arguments */
255464 ){
255465 assert( nArg==0 );
255466 UNUSED_PARAM2(nArg, apUnused);
255467 sqlite3_result_text(pCtx, "fts5: 2025-01-14 11:05:00 d2fe6b05f38d9d7cd78c5d252e99ac59f1aea071d669830c1ffe4e8966e84010", -1, SQLITE_TRANSIENT);
255468 }
255469
255470 /*
255471 ** Implementation of fts5_locale(LOCALE, TEXT) function.
255472 **
255473
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.49.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -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 ** d7c07581203a0a88456588e49e51b40a8341 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -463,13 +463,13 @@
463 **
464 ** See also: [sqlite3_libversion()],
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
468 #define SQLITE_VERSION "3.49.0"
469 #define SQLITE_VERSION_NUMBER 3049000
470 #define SQLITE_SOURCE_ID "2025-01-29 18:53:19 d7c07581203a0a88456588e49e51b40a8341b0e7121809f75be0ee882d91650f"
471
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -11065,12 +11065,13 @@
11065 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
11066
11067 /*
11068 ** CAPI3REF: Serialize a database
11069 **
11070 ** The sqlite3_serialize(D,S,P,F) interface returns a pointer to
11071 ** memory that is a serialization of the S database on
11072 ** [database connection] D. If S is a NULL pointer, the main database is used.
11073 ** If P is not a NULL pointer, then the size of the database in bytes
11074 ** is written into *P.
11075 **
11076 ** For an ordinary on-disk database file, the serialization is just a
11077 ** copy of the disk file. For an in-memory database or a "TEMP" database,
@@ -15127,10 +15128,12 @@
15128 ** Examples:
15129 **
15130 ** 0.5 -> -10 0.1 -> -33 0.0625 -> -40
15131 */
15132 typedef INT16_TYPE LogEst;
15133 #define LOGEST_MIN (-32768)
15134 #define LOGEST_MAX (32767)
15135
15136 /*
15137 ** Set the SQLITE_PTRSIZE macro to the number of bytes in a pointer
15138 */
15139 #ifndef SQLITE_PTRSIZE
@@ -15397,11 +15400,11 @@
15400 ** 0x-------F High-level debug messages
15401 ** 0x----FFF- More detail
15402 ** 0xFFFF---- Low-level debug messages
15403 **
15404 ** 0x00000001 Code generation
15405 ** 0x00000002 Solver (Use 0x40000 for less detail)
15406 ** 0x00000004 Solver costs
15407 ** 0x00000008 WhereLoop inserts
15408 **
15409 ** 0x00000010 Display sqlite3_index_info xBestIndex calls
15410 ** 0x00000020 Range an equality scan metrics
@@ -15416,10 +15419,12 @@
15419 ** 0x00004000 Show all WHERE terms at key points
15420 ** 0x00008000 Show the full SELECT statement at key places
15421 **
15422 ** 0x00010000 Show more detail when printing WHERE terms
15423 ** 0x00020000 Show WHERE terms returned from whereScanNext()
15424 ** 0x00040000 Solver overview messages
15425 ** 0x00080000 Star-query heuristic
15426 */
15427
15428
15429 /*
15430 ** An instance of the following structure is used to store the busy-handler
@@ -18097,10 +18102,11 @@
18102 #define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
18103 #define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
18104 #define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
18105 #define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
18106 #define SQLITE_OrderBySubq 0x10000000 /* ORDER BY in subquery helps outer */
18107 #define SQLITE_StarQuery 0x20000000 /* Heurists for star queries */
18108 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
18109
18110 /*
18111 ** Macros for testing whether or not optimizations are enabled or disabled.
18112 */
@@ -19426,17 +19432,12 @@
19432 **
19433 ** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
19434 */
19435 struct IdList {
19436 int nId; /* Number of identifiers on the list */
 
19437 struct IdList_item {
19438 char *zName; /* Name of the identifier */
 
 
 
 
19439 } a[1];
19440 };
19441
19442 /*
19443 ** Allowed values for IdList.eType, which determines which value of the a.u4
@@ -23579,10 +23580,11 @@
23580 char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
23581 void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
23582 #ifdef SQLITE_DEBUG
23583 Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
23584 u16 mScopyFlags; /* flags value immediately after the shallow copy */
23585 u8 bScopy; /* The pScopyFrom of some other Mem *might* point here */
23586 #endif
23587 };
23588
23589 /*
23590 ** Size of struct Mem not including the Mem.zMalloc member or anything that
@@ -24677,10 +24679,13 @@
24679 ms = ms*10.0 + *zDate - '0';
24680 rScale *= 10.0;
24681 zDate++;
24682 }
24683 ms /= rScale;
24684 /* Truncate to avoid problems with sub-milliseconds
24685 ** rounding. https://sqlite.org/forum/forumpost/766a2c9231 */
24686 if( ms>0.999 ) ms = 0.999;
24687 }
24688 }else{
24689 s = 0;
24690 }
24691 p->validJD = 0;
@@ -25884,11 +25889,11 @@
25889 sqlite3_str_appendf(&sRes, cf=='d' ? "%02d" : "%2d", x.D);
25890 break;
25891 }
25892 case 'f': { /* Fractional seconds. (Non-standard) */
25893 double s = x.s;
25894 if( NEVER(s>59.999) ) s = 59.999;
25895 sqlite3_str_appendf(&sRes, "%06.3f", s);
25896 break;
25897 }
25898 case 'F': {
25899 sqlite3_str_appendf(&sRes, "%04d-%02d-%02d", x.Y, x.M, x.D);
@@ -33815,25 +33820,11 @@
33820 char *zName = pList->a[i].zName;
33821 int moreToFollow = i<pList->nId - 1;
33822 if( zName==0 ) zName = "(null)";
33823 sqlite3TreeViewPush(&pView, moreToFollow);
33824 sqlite3TreeViewLine(pView, 0);
33825 fprintf(stdout, "%s\n", zName);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33826 sqlite3TreeViewPop(&pView);
33827 }
33828 }
33829 }
33830 SQLITE_PRIVATE void sqlite3TreeViewIdList(
@@ -40170,11 +40161,11 @@
40161 assert( pInode!=0 );
40162 assert( sqlite3_mutex_held(pInode->pLockMutex) );
40163 if( (pFile->ctrlFlags & (UNIXFILE_EXCL|UNIXFILE_RDONLY))==UNIXFILE_EXCL ){
40164 if( pInode->bProcessLock==0 ){
40165 struct flock lock;
40166 /* assert( pInode->nLock==0 ); <-- Not true if unix-excl READONLY used */
40167 lock.l_whence = SEEK_SET;
40168 lock.l_start = SHARED_FIRST;
40169 lock.l_len = SHARED_SIZE;
40170 lock.l_type = F_WRLCK;
40171 rc = osSetPosixAdvisoryLock(pFile->h, &lock, pFile);
@@ -58053,11 +58044,11 @@
58044 if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0; /* Failed (3) */
58045 #ifndef SQLITE_OMIT_WAL
58046 if( pPager->pWal ){
58047 u32 iRead = 0;
58048 (void)sqlite3WalFindFrame(pPager->pWal, pgno, &iRead);
58049 if( iRead ) return 0; /* Case (4) */
58050 }
58051 #endif
58052 assert( pPager->fd->pMethods->xDeviceCharacteristics!=0 );
58053 if( (pPager->fd->pMethods->xDeviceCharacteristics(pPager->fd)
58054 & SQLITE_IOCAP_SUBPAGE_READ)==0 ){
@@ -84001,31 +83992,34 @@
83992 ** copies (created by OP_SCopy) are not misused.
83993 */
83994 SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){
83995 int i;
83996 Mem *pX;
83997 if( pMem->bScopy ){
83998 for(i=1, pX=pVdbe->aMem+1; i<pVdbe->nMem; i++, pX++){
83999 if( pX->pScopyFrom==pMem ){
84000 u16 mFlags;
84001 if( pVdbe->db->flags & SQLITE_VdbeTrace ){
84002 sqlite3DebugPrintf("Invalidate R[%d] due to change in R[%d]\n",
84003 (int)(pX - pVdbe->aMem), (int)(pMem - pVdbe->aMem));
84004 }
84005 /* If pX is marked as a shallow copy of pMem, then try to verify that
84006 ** no significant changes have been made to pX since the OP_SCopy.
84007 ** A significant change would indicated a missed call to this
84008 ** function for pX. Minor changes, such as adding or removing a
84009 ** dual type, are allowed, as long as the underlying value is the
84010 ** same. */
84011 mFlags = pMem->flags & pX->flags & pX->mScopyFlags;
84012 assert( (mFlags&(MEM_Int|MEM_IntReal))==0 || pMem->u.i==pX->u.i );
84013
84014 /* pMem is the register that is changing. But also mark pX as
84015 ** undefined so that we can quickly detect the shallow-copy error */
84016 pX->flags = MEM_Undefined;
84017 pX->pScopyFrom = 0;
84018 }
84019 }
84020 pMem->bScopy = 0;
84021 }
84022 pMem->pScopyFrom = 0;
84023 }
84024 #endif /* SQLITE_DEBUG */
84025
@@ -87163,10 +87157,11 @@
87157 p->flags = flags;
87158 p->db = db;
87159 p->szMalloc = 0;
87160 #ifdef SQLITE_DEBUG
87161 p->pScopyFrom = 0;
87162 p->bScopy = 0;
87163 #endif
87164 p++;
87165 }while( (--N)>0 );
87166 }
87167 }
@@ -91348,11 +91343,11 @@
91343 if( db->nVdbeActive==0 ){
91344 AtomicStore(&db->u1.isInterrupted, 0);
91345 }
91346
91347 assert( db->nVdbeWrite>0 || db->autoCommit==0
91348 || ((db->nDeferredCons + db->nDeferredImmCons)==0)
91349 );
91350
91351 #ifndef SQLITE_OMIT_TRACE
91352 if( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0
91353 && !db->init.busy && p->zSql ){
@@ -91859,10 +91854,11 @@
91854 /* .zMalloc = */ (char*)0,
91855 /* .xDel = */ (void(*)(void*))0,
91856 #ifdef SQLITE_DEBUG
91857 /* .pScopyFrom = */ (Mem*)0,
91858 /* .mScopyFlags= */ 0,
91859 /* .bScopy = */ 0,
91860 #endif
91861 };
91862 return &nullMem;
91863 }
91864
@@ -92741,10 +92737,11 @@
92737 */
92738 SQLITE_API int sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
92739 PreUpdate *p;
92740 Mem *pMem;
92741 int rc = SQLITE_OK;
92742 int iStore = 0;
92743
92744 #ifdef SQLITE_ENABLE_API_ARMOR
92745 if( db==0 || ppValue==0 ){
92746 return SQLITE_MISUSE_BKPT;
92747 }
@@ -92755,13 +92752,15 @@
92752 if( !p || p->op==SQLITE_INSERT ){
92753 rc = SQLITE_MISUSE_BKPT;
92754 goto preupdate_old_out;
92755 }
92756 if( p->pPk ){
92757 iStore = sqlite3TableColumnToIndex(p->pPk, iIdx);
92758 }else{
92759 iStore = sqlite3TableColumnToStorage(p->pTab, iIdx);
92760 }
92761 if( iStore>=p->pCsr->nField || iStore<0 ){
92762 rc = SQLITE_RANGE;
92763 goto preupdate_old_out;
92764 }
92765
92766 if( iIdx==p->pTab->iPKey ){
@@ -92788,12 +92787,12 @@
92787 goto preupdate_old_out;
92788 }
92789 p->aRecord = aRec;
92790 }
92791
92792 pMem = *ppValue = &p->pUnpacked->aMem[iStore];
92793 if( iStore>=p->pUnpacked->nField ){
92794 /* This occurs when the table has been extended using ALTER TABLE
92795 ** ADD COLUMN. The value to return is the default value of the column. */
92796 Column *pCol = &p->pTab->aCol[iIdx];
92797 if( pCol->iDflt>0 ){
92798 if( p->apDflt==0 ){
@@ -92893,10 +92892,11 @@
92892 */
92893 SQLITE_API int sqlite3_preupdate_new(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
92894 PreUpdate *p;
92895 int rc = SQLITE_OK;
92896 Mem *pMem;
92897 int iStore = 0;
92898
92899 #ifdef SQLITE_ENABLE_API_ARMOR
92900 if( db==0 || ppValue==0 ){
92901 return SQLITE_MISUSE_BKPT;
92902 }
@@ -92905,13 +92905,16 @@
92905 if( !p || p->op==SQLITE_DELETE ){
92906 rc = SQLITE_MISUSE_BKPT;
92907 goto preupdate_new_out;
92908 }
92909 if( p->pPk && p->op!=SQLITE_UPDATE ){
92910 iStore = sqlite3TableColumnToIndex(p->pPk, iIdx);
92911 }else{
92912 iStore = sqlite3TableColumnToStorage(p->pTab, iIdx);
92913 }
92914
92915 if( iStore>=p->pCsr->nField || iStore<0 ){
92916 rc = SQLITE_RANGE;
92917 goto preupdate_new_out;
92918 }
92919
92920 if( p->op==SQLITE_INSERT ){
@@ -92927,18 +92930,18 @@
92930 rc = SQLITE_NOMEM;
92931 goto preupdate_new_out;
92932 }
92933 p->pNewUnpacked = pUnpack;
92934 }
92935 pMem = &pUnpack->aMem[iStore];
92936 if( iIdx==p->pTab->iPKey ){
92937 sqlite3VdbeMemSetInt64(pMem, p->iKey2);
92938 }else if( iStore>=pUnpack->nField ){
92939 pMem = (sqlite3_value *)columnNullValue();
92940 }
92941 }else{
92942 /* For an UPDATE, memory cell (p->iNewReg+1+iStore) contains the required
92943 ** value. Make a copy of the cell contents and return a pointer to it.
92944 ** It is not safe to return a pointer to the memory cell itself as the
92945 ** caller may modify the value text encoding.
92946 */
92947 assert( p->op==SQLITE_UPDATE );
@@ -92947,17 +92950,17 @@
92950 if( !p->aNew ){
92951 rc = SQLITE_NOMEM;
92952 goto preupdate_new_out;
92953 }
92954 }
92955 assert( iStore>=0 && iStore<p->pCsr->nField );
92956 pMem = &p->aNew[iStore];
92957 if( pMem->flags==0 ){
92958 if( iIdx==p->pTab->iPKey ){
92959 sqlite3VdbeMemSetInt64(pMem, p->iKey2);
92960 }else{
92961 rc = sqlite3VdbeMemCopy(pMem, &p->v->aMem[p->iNewReg+1+iStore]);
92962 if( rc!=SQLITE_OK ) goto preupdate_new_out;
92963 }
92964 }
92965 }
92966 *ppValue = pMem;
@@ -94042,10 +94045,11 @@
94045 }
94046 static void registerTrace(int iReg, Mem *p){
94047 printf("R[%d] = ", iReg);
94048 memTracePrint(p);
94049 if( p->pScopyFrom ){
94050 assert( p->pScopyFrom->bScopy );
94051 printf(" <== R[%d]", (int)(p->pScopyFrom - &p[-iReg]));
94052 }
94053 printf("\n");
94054 sqlite3VdbeCheckMemInvariants(p);
94055 }
@@ -95025,10 +95029,11 @@
95029 #ifdef SQLITE_DEBUG
95030 pIn1->pScopyFrom = 0;
95031 { int i;
95032 for(i=1; i<p->nMem; i++){
95033 if( aMem[i].pScopyFrom==pIn1 ){
95034 assert( aMem[i].bScopy );
95035 aMem[i].pScopyFrom = pOut;
95036 }
95037 }
95038 }
95039 #endif
@@ -95097,10 +95102,11 @@
95102 assert( pOut!=pIn1 );
95103 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
95104 #ifdef SQLITE_DEBUG
95105 pOut->pScopyFrom = pIn1;
95106 pOut->mScopyFlags = pIn1->flags;
95107 pIn1->bScopy = 1;
95108 #endif
95109 break;
95110 }
95111
95112 /* Opcode: IntCopy P1 P2 * * *
@@ -111360,20 +111366,17 @@
111366 SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3 *db, const IdList *p){
111367 IdList *pNew;
111368 int i;
111369 assert( db!=0 );
111370 if( p==0 ) return 0;
 
111371 pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew)+(p->nId-1)*sizeof(p->a[0]) );
111372 if( pNew==0 ) return 0;
111373 pNew->nId = p->nId;
 
111374 for(i=0; i<p->nId; i++){
111375 struct IdList_item *pNewItem = &pNew->a[i];
111376 const struct IdList_item *pOldItem = &p->a[i];
111377 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
 
111378 }
111379 return pNew;
111380 }
111381 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, const Select *pDup, int flags){
111382 Select *pRet = 0;
@@ -126726,11 +126729,10 @@
126729 */
126730 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
126731 int i;
126732 assert( db!=0 );
126733 if( pList==0 ) return;
 
126734 for(i=0; i<pList->nId; i++){
126735 sqlite3DbFree(db, pList->a[i].zName);
126736 }
126737 sqlite3DbNNFreeNN(db, pList);
126738 }
@@ -128107,16 +128109,22 @@
128109 FuncDef *p, /* The function we are evaluating for match quality */
128110 int nArg, /* Desired number of arguments. (-1)==any */
128111 u8 enc /* Desired text encoding */
128112 ){
128113 int match;
128114 assert( p->nArg>=(-4) && p->nArg!=(-2) );
128115 assert( nArg>=(-2) );
128116
128117 /* Wrong number of arguments means "no match" */
128118 if( p->nArg!=nArg ){
128119 if( nArg==(-2) ) return p->xSFunc==0 ? 0 : FUNC_PERFECT_MATCH;
128120 if( p->nArg>=0 ) return 0;
128121 /* Special p->nArg values available to built-in functions only:
128122 ** -3 1 or more arguments required
128123 ** -4 2 or more arguments required
128124 */
128125 if( p->nArg<(-2) && nArg<(-2-p->nArg) ) return 0;
128126 }
128127
128128 /* Give a better score to a function with a specific number of arguments
128129 ** than to function that accepts any number of arguments. */
128130 if( p->nArg==nArg ){
@@ -132076,16 +132084,14 @@
132084 FUNCTION(ltrim, 2, 1, 0, trimFunc ),
132085 FUNCTION(rtrim, 1, 2, 0, trimFunc ),
132086 FUNCTION(rtrim, 2, 2, 0, trimFunc ),
132087 FUNCTION(trim, 1, 3, 0, trimFunc ),
132088 FUNCTION(trim, 2, 3, 0, trimFunc ),
132089 FUNCTION(min, -3, 0, 1, minmaxFunc ),
 
132090 WAGGREGATE(min, 1, 0, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
132091 SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ),
132092 FUNCTION(max, -3, 1, 1, minmaxFunc ),
 
132093 WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0,
132094 SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ),
132095 FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
132096 FUNCTION2(subtype, 1, 0, 0, subtypeFunc,
132097 SQLITE_FUNC_TYPEOF|SQLITE_SUBTYPE),
@@ -132108,15 +132114,12 @@
132114 FUNCTION(upper, 1, 0, 0, upperFunc ),
132115 FUNCTION(lower, 1, 0, 0, lowerFunc ),
132116 FUNCTION(hex, 1, 0, 0, hexFunc ),
132117 FUNCTION(unhex, 1, 0, 0, unhexFunc ),
132118 FUNCTION(unhex, 2, 0, 0, unhexFunc ),
132119 FUNCTION(concat, -3, 0, 0, concatFunc ),
132120 FUNCTION(concat_ws, -4, 0, 0, concatwsFunc ),
 
 
 
132121 INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, 0 ),
132122 VFUNCTION(random, 0, 0, 0, randomFunc ),
132123 VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
132124 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
132125 DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
@@ -132156,12 +132159,10 @@
132159 LIKEFUNC(like, 3, &likeInfoNorm, SQLITE_FUNC_LIKE),
132160 #endif
132161 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
132162 FUNCTION(unknown, -1, 0, 0, unknownFunc ),
132163 #endif
 
 
132164 #ifdef SQLITE_ENABLE_MATH_FUNCTIONS
132165 MFUNCTION(ceil, 1, xCeil, ceilingFunc ),
132166 MFUNCTION(ceiling, 1, xCeil, ceilingFunc ),
132167 MFUNCTION(floor, 1, xFloor, ceilingFunc ),
132168 #if SQLITE_HAVE_C99_MATH_FUNCS
@@ -132195,15 +132196,13 @@
132196 MFUNCTION(radians, 1, degToRad, math1Func ),
132197 MFUNCTION(degrees, 1, radToDeg, math1Func ),
132198 MFUNCTION(pi, 0, 0, piFunc ),
132199 #endif /* SQLITE_ENABLE_MATH_FUNCTIONS */
132200 FUNCTION(sign, 1, 0, 0, signFunc ),
132201 INLINE_FUNC(coalesce, -4, INLINEFUNC_coalesce, 0 ),
132202 INLINE_FUNC(iif, -4, INLINEFUNC_iif, 0 ),
132203 INLINE_FUNC(if, -4, INLINEFUNC_iif, 0 ),
 
 
132204 };
132205 #ifndef SQLITE_OMIT_ALTERTABLE
132206 sqlite3AlterFunctions();
132207 #endif
132208 sqlite3WindowFunctions();
@@ -134645,10 +134644,11 @@
134644 int regRowCount = 0; /* Memory cell used for the row counter */
134645 int regIns; /* Block of regs holding rowid+data being inserted */
134646 int regRowid; /* registers holding insert rowid */
134647 int regData; /* register holding first column to insert */
134648 int *aRegIdx = 0; /* One register allocated to each index */
134649 int *aTabColMap = 0; /* Mapping from pTab columns to pCol entries */
134650
134651 #ifndef SQLITE_OMIT_TRIGGER
134652 int isView; /* True if attempting to insert into a view */
134653 Trigger *pTrigger; /* List of triggers on pTab, if required */
134654 int tmask; /* Mask of trigger times */
@@ -134789,19 +134789,19 @@
134789 ** columns into storage order. False negatives are harmless,
134790 ** but false positives will cause database corruption.
134791 */
134792 bIdListInOrder = (pTab->tabFlags & (TF_OOOHidden|TF_HasStored))==0;
134793 if( pColumn ){
134794 aTabColMap = sqlite3DbMallocZero(db, pTab->nCol*sizeof(int));
134795 if( aTabColMap==0 ) goto insert_cleanup;
134796 for(i=0; i<pColumn->nId; i++){
134797 const char *zCName = pColumn->a[i].zName;
134798 u8 hName = sqlite3StrIHash(zCName);
134799 for(j=0; j<pTab->nCol; j++){
134800 if( pTab->aCol[j].hName!=hName ) continue;
134801 if( sqlite3StrICmp(zCName, pTab->aCol[j].zCnName)==0 ){
134802 if( aTabColMap[j]==0 ) aTabColMap[j] = i+1;
134803 if( i!=j ) bIdListInOrder = 0;
134804 if( j==pTab->iPKey ){
134805 ipkColumn = i; assert( !withoutRowid );
134806 }
134807 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
@@ -135119,21 +135119,21 @@
135119 iRegStore);
135120 continue;
135121 }
135122 }
135123 if( pColumn ){
135124 j = aTabColMap[i];
135125 assert( j>=0 && j<=pColumn->nId );
135126 if( j==0 ){
135127 /* A column not named in the insert column list gets its
135128 ** default value */
135129 sqlite3ExprCodeFactorable(pParse,
135130 sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
135131 iRegStore);
135132 continue;
135133 }
135134 k = j - 1;
135135 }else if( nColumn==0 ){
135136 /* This is INSERT INTO ... DEFAULT VALUES. Load the default value. */
135137 sqlite3ExprCodeFactorable(pParse,
135138 sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
135139 iRegStore);
@@ -135374,11 +135374,14 @@
135374 insert_cleanup:
135375 sqlite3SrcListDelete(db, pTabList);
135376 sqlite3ExprListDelete(db, pList);
135377 sqlite3UpsertDelete(db, pUpsert);
135378 sqlite3SelectDelete(db, pSelect);
135379 if( pColumn ){
135380 sqlite3IdListDelete(db, pColumn);
135381 sqlite3DbFree(db, aTabColMap);
135382 }
135383 if( aRegIdx ) sqlite3DbNNFreeNN(db, aRegIdx);
135384 }
135385
135386 /* Make sure "isView" and other macros defined above are undefined. Otherwise
135387 ** they may interfere with compilation of other functions in this file
@@ -157961,12 +157964,14 @@
157964 u16 nLTerm; /* Number of entries in aLTerm[] */
157965 u16 nSkip; /* Number of NULL aLTerm[] entries */
157966 /**** whereLoopXfer() copies fields above ***********************/
157967 # define WHERE_LOOP_XFER_SZ offsetof(WhereLoop,nLSlot)
157968 u16 nLSlot; /* Number of slots allocated for aLTerm[] */
157969 #ifdef WHERETRACE_ENABLED
157970 LogEst rStarDelta; /* Cost delta due to star-schema heuristic. Not
157971 ** initialized unless pWInfo->bStarUsed */
157972 #endif
157973 WhereTerm **aLTerm; /* WhereTerms used */
157974 WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */
157975 WhereTerm *aLTermSpace[3]; /* Initial aLTerm[] space */
157976 };
157977
@@ -158011,11 +158016,11 @@
158016 struct WherePath {
158017 Bitmask maskLoop; /* Bitmask of all WhereLoop objects in this path */
158018 Bitmask revLoop; /* aLoop[]s that should be reversed for ORDER BY */
158019 LogEst nRow; /* Estimated number of rows generated by this path */
158020 LogEst rCost; /* Total cost of this path */
158021 LogEst rUnsort; /* Total cost of this path ignoring sorting costs */
158022 i8 isOrdered; /* No. of ORDER BY terms satisfied. -1 for unknown */
158023 WhereLoop **aLoop; /* Array of WhereLoop objects implementing this path */
158024 };
158025
158026 /*
@@ -158284,13 +158289,17 @@
158289 u8 eOnePass; /* ONEPASS_OFF, or _SINGLE, or _MULTI */
158290 u8 eDistinct; /* One of the WHERE_DISTINCT_* values */
158291 unsigned bDeferredSeek :1; /* Uses OP_DeferredSeek */
158292 unsigned untestedTerms :1; /* Not all WHERE terms resolved by outer loop */
158293 unsigned bOrderedInnerLoop:1;/* True if only the inner-most loop is ordered */
158294 unsigned sorted :1; /* True if really sorted (not just grouped) */
158295 unsigned bStarDone :1; /* True if check for star-query is complete */
158296 unsigned bStarUsed :1; /* True if star-query heuristic is used */
158297 LogEst nRowOut; /* Estimated number of output rows */
158298 #ifdef WHERETRACE_ENABLED
158299 LogEst rTotalCost; /* Total cost of the solution */
158300 #endif
158301 int iTop; /* The very beginning of the WHERE loop */
158302 int iEndWhere; /* End of the WHERE clause itself */
158303 WhereLoop *pLoops; /* List of all WhereLoop objects */
158304 WhereMemBlock *pMemToFree;/* Memory to free when this object destroyed */
158305 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
@@ -164232,11 +164241,11 @@
164241 char *zText = 0;
164242 int ii = 0;
164243 sqlite3_str *pStr = sqlite3_str_new(pParse->db);
164244 sqlite3_str_appendf(pStr,"CREATE AUTOMATIC INDEX ON %s(", pTab->zName);
164245 assert( pIdx->nColumn>1 );
164246 assert( pIdx->aiColumn[pIdx->nColumn-1]==XN_ROWID || !HasRowid(pTab) );
164247 for(ii=0; ii<(pIdx->nColumn-1); ii++){
164248 const char *zName = 0;
164249 int iCol = pIdx->aiColumn[ii];
164250
164251 zName = pTab->aCol[iCol].zCnName;
@@ -164362,10 +164371,23 @@
164371 */
164372 if( IsView(pTable) ){
164373 extraCols = ALLBITS & ~idxCols;
164374 }else{
164375 extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));
164376 }
164377 if( !HasRowid(pTable) ){
164378 /* For WITHOUT ROWID tables, ensure that all PRIMARY KEY columns are
164379 ** either in the idxCols mask or in the extraCols mask */
164380 for(i=0; i<pTable->nCol; i++){
164381 if( (pTable->aCol[i].colFlags & COLFLAG_PRIMKEY)==0 ) continue;
164382 if( i>=BMS-1 ){
164383 extraCols |= MASKBIT(BMS-1);
164384 break;
164385 }
164386 if( idxCols & MASKBIT(i) ) continue;
164387 extraCols |= MASKBIT(i);
164388 }
164389 }
164390 mxBitCol = MIN(BMS-1,pTable->nCol);
164391 testcase( pTable->nCol==BMS-1 );
164392 testcase( pTable->nCol==BMS-2 );
164393 for(i=0; i<mxBitCol; i++){
@@ -164374,11 +164396,12 @@
164396 if( pSrc->colUsed & MASKBIT(BMS-1) ){
164397 nKeyCol += pTable->nCol - BMS + 1;
164398 }
164399
164400 /* Construct the Index object to describe this index */
164401 pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+HasRowid(pTable),
164402 0, &zNotUsed);
164403 if( pIdx==0 ) goto end_auto_index_create;
164404 pLoop->u.btree.pIndex = pIdx;
164405 pIdx->zName = "auto-index";
164406 pIdx->pTable = pTable;
164407 n = 0;
@@ -164430,12 +164453,14 @@
164453 pIdx->azColl[n] = sqlite3StrBINARY;
164454 n++;
164455 }
164456 }
164457 assert( n==nKeyCol );
164458 if( HasRowid(pTable) ){
164459 pIdx->aiColumn[n] = XN_ROWID;
164460 pIdx->azColl[n] = sqlite3StrBINARY;
164461 }
164462
164463 /* Create the automatic index */
164464 explainAutomaticIndex(pParse, pIdx, pPartial!=0, &addrExp);
164465 assert( pLevel->iIdxCur>=0 );
164466 pLevel->iIdxCur = pParse->nTab++;
@@ -165698,21 +165723,23 @@
165723 ** | | | __|__ nEq ---. ___|__ | __|__
165724 ** | / \ / \ / \ | / \ / \ / \
165725 ** 1.002.001 t2.t2xy 2 f 010241 N 2 cost 0,56,31
165726 */
165727 SQLITE_PRIVATE void sqlite3WhereLoopPrint(const WhereLoop *p, const WhereClause *pWC){
165728 WhereInfo *pWInfo;
165729 if( pWC ){
165730 pWInfo = pWC->pWInfo;
165731 int nb = 1+(pWInfo->pTabList->nSrc+3)/4;
165732 SrcItem *pItem = pWInfo->pTabList->a + p->iTab;
165733 Table *pTab = pItem->pSTab;
165734 Bitmask mAll = (((Bitmask)1)<<(nb*4)) - 1;
165735 sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
165736 p->iTab, nb, p->maskSelf, nb, p->prereq & mAll);
165737 sqlite3DebugPrintf(" %12s",
165738 pItem->zAlias ? pItem->zAlias : pTab->zName);
165739 }else{
165740 pWInfo = 0;
165741 sqlite3DebugPrintf("%c%2d.%03llx.%03llx %c%d",
165742 p->cId, p->iTab, p->maskSelf, p->prereq & 0xfff, p->cId, p->iTab);
165743 }
165744 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
165745 const char *zName;
@@ -165740,11 +165767,16 @@
165767 if( p->wsFlags & WHERE_SKIPSCAN ){
165768 sqlite3DebugPrintf(" f %06x %d-%d", p->wsFlags, p->nLTerm,p->nSkip);
165769 }else{
165770 sqlite3DebugPrintf(" f %06x N %d", p->wsFlags, p->nLTerm);
165771 }
165772 if( pWInfo && pWInfo->bStarUsed && p->rStarDelta!=0 ){
165773 sqlite3DebugPrintf(" cost %d,%d,%d delta=%d\n",
165774 p->rSetup, p->rRun, p->nOut, p->rStarDelta);
165775 }else{
165776 sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
165777 }
165778 if( p->nLTerm && (sqlite3WhereTrace & 0x4000)!=0 ){
165779 int i;
165780 for(i=0; i<p->nLTerm; i++){
165781 sqlite3WhereTermPrint(p->aLTerm[i], i);
165782 }
@@ -167206,11 +167238,10 @@
167238 if( !pBuilder->pOrSet /* Not part of an OR optimization */
167239 && (pWInfo->wctrlFlags & (WHERE_RIGHT_JOIN|WHERE_OR_SUBCLAUSE))==0
167240 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
167241 && !pSrc->fg.isIndexedBy /* Has no INDEXED BY clause */
167242 && !pSrc->fg.notIndexed /* Has no NOT INDEXED clause */
 
167243 && !pSrc->fg.isCorrelated /* Not a correlated subquery */
167244 && !pSrc->fg.isRecursive /* Not a recursive common table expression. */
167245 && (pSrc->fg.jointype & JT_RIGHT)==0 /* Not the right tab of a RIGHT JOIN */
167246 ){
167247 /* Generate auto-index WhereLoops */
@@ -168709,72 +168740,205 @@
168740 ** The value returned is a tuning parameter. Currently the value is:
168741 **
168742 ** 18 for star queries
168743 ** 12 otherwise
168744 **
168745 ** For the purposes of this heuristic, a star-query is defined as a query
168746 ** with a large central table that is joined using an INNER JOIN,
168747 ** not CROSS or OUTER JOINs, against four or more smaller tables.
168748 ** The central table is called the "fact" table. The smaller tables
168749 ** that get joined are "dimension tables". Also, any table that is
168750 ** self-joined cannot be a dimension table; we assume that dimension
168751 ** tables may only be joined against fact tables.
168752 **
168753 ** SIDE EFFECT: (and really the whole point of this subroutine)
168754 **
168755 ** If pWInfo describes a star-query, then the cost for SCANs of dimension
168756 ** WhereLoops is increased to be slightly larger than the cost of a SCAN
168757 ** in the fact table. Only SCAN costs are increased. SEARCH costs are
168758 ** unchanged. This heuristic helps keep fact tables in outer loops. Without
168759 ** this heuristic, paths with fact tables in outer loops tend to get pruned
168760 ** by the mxChoice limit on the number of paths, resulting in poor query
168761 ** plans. See the starschema1.test test module for examples of queries
168762 ** that need this heuristic to find good query plans.
168763 **
168764 ** This heuristic can be completely disabled, so that no query is
168765 ** considered a star-query, using SQLITE_TESTCTRL_OPTIMIZATION to
168766 ** disable the SQLITE_StarQuery optimization. In the CLI, the command
168767 ** to do that is: ".testctrl opt -starquery".
168768 **
168769 ** HISTORICAL NOTES:
168770 **
168771 ** This optimization was first added on 2024-05-09 by check-in 38db9b5c83d.
168772 ** The original optimization reduced the cost and output size estimate for
168773 ** fact tables to help them move to outer loops. But months later (as people
168774 ** started upgrading) performance regression reports started caming in,
168775 ** including:
168776 **
168777 ** forum post b18ef983e68d06d1 (2024-12-21)
168778 ** forum post 0025389d0860af82 (2025-01-14)
168779 ** forum post d87570a145599033 (2025-01-17)
168780 **
168781 ** To address these, the criteria for a star-query was tightened to exclude
168782 ** cases where the fact and dimensions are separated by an outer join, and
168783 ** the affect of star-schema detection was changed to increase the rRun cost
168784 ** on just full table scans of dimension tables, rather than reducing costs
168785 ** in the all access methods of the fact table.
168786 */
168787 static int computeMxChoice(WhereInfo *pWInfo){
168788 int nLoop = pWInfo->nLevel; /* Number of terms in the join */
168789 WhereLoop *pWLoop; /* For looping over WhereLoops */
168790
168791 #ifdef SQLITE_DEBUG
168792 /* The star-query detection code below makes use of the following
168793 ** properties of the WhereLoop list, so verify them before
168794 ** continuing:
168795 ** (1) .maskSelf is the bitmask corresponding to .iTab
168796 ** (2) The WhereLoop list is in ascending .iTab order
168797 */
168798 for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
168799 assert( pWLoop->maskSelf==MASKBIT(pWLoop->iTab) );
168800 assert( pWLoop->pNextLoop==0 || pWLoop->iTab<=pWLoop->pNextLoop->iTab );
168801 }
168802 #endif /* SQLITE_DEBUG */
168803
168804 if( nLoop>=5
168805 && !pWInfo->bStarDone
168806 && OptimizationEnabled(pWInfo->pParse->db, SQLITE_StarQuery)
168807 ){
168808 SrcItem *aFromTabs; /* All terms of the FROM clause */
168809 int iFromIdx; /* Term of FROM clause is the candidate fact-table */
168810 Bitmask m; /* Bitmask for candidate fact-table */
168811 Bitmask mSelfJoin = 0; /* Tables that cannot be dimension tables */
168812 WhereLoop *pStart; /* Where to start searching for dimension-tables */
168813
168814 pWInfo->bStarDone = 1; /* Only do this computation once */
168815
168816 /* Look for fact tables with four or more dimensions where the
168817 ** dimension tables are not separately from the fact tables by an outer
168818 ** or cross join. Adjust cost weights if found.
168819 */
168820 assert( !pWInfo->bStarUsed );
168821 aFromTabs = pWInfo->pTabList->a;
168822 pStart = pWInfo->pLoops;
168823 for(iFromIdx=0, m=1; iFromIdx<nLoop; iFromIdx++, m<<=1){
 
168824 int nDep = 0; /* Number of dimension tables */
168825 LogEst mxRun; /* Maximum SCAN cost of a fact table */
168826 Bitmask mSeen = 0; /* Mask of dimension tables */
168827 SrcItem *pFactTab; /* The candidate fact table */
168828
168829 pFactTab = aFromTabs + iFromIdx;
168830 if( (pFactTab->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
168831 /* If the candidate fact-table is the right table of an outer join
168832 ** restrict the search for dimension-tables to be tables to the right
168833 ** of the fact-table. */
168834 if( iFromIdx+4 > nLoop ) break; /* Impossible to reach nDep>=4 */
168835 while( pStart && pStart->iTab<=iFromIdx ){
168836 pStart = pStart->pNextLoop;
168837 }
168838 }
168839 for(pWLoop=pStart; pWLoop; pWLoop=pWLoop->pNextLoop){
168840 if( (aFromTabs[pWLoop->iTab].fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
168841 /* Fact-tables and dimension-tables cannot be separated by an
168842 ** outer join (at least for the definition of fact- and dimension-
168843 ** used by this heuristic). */
168844 break;
168845 }
168846 if( (pWLoop->prereq & m)!=0 /* pWInfo depends on iFromIdx */
168847 && (pWLoop->maskSelf & mSeen)==0 /* pWInfo not already a dependency */
168848 && (pWLoop->maskSelf & mSelfJoin)==0 /* Not a self-join */
168849 ){
168850 if( aFromTabs[pWLoop->iTab].pSTab==pFactTab->pSTab ){
168851 mSelfJoin |= m;
168852 }else{
168853 nDep++;
168854 mSeen |= pWLoop->maskSelf;
168855 }
168856 }
168857 }
168858 if( nDep<=3 ) continue;
168859
168860 /* If we reach this point, it means that pFactTab is a fact table
168861 ** with four or more dimensions connected by inner joins. Proceed
168862 ** to make cost adjustments. */
168863
168864 #ifdef WHERETRACE_ENABLED
168865 /* Make sure rStarDelta values are initialized */
168866 if( !pWInfo->bStarUsed ){
 
 
168867 for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
168868 pWLoop->rStarDelta = 0;
168869 }
168870 }
168871 #endif
168872 pWInfo->bStarUsed = 1;
168873
168874 /* Compute the maximum cost of any WhereLoop for the
168875 ** fact table plus one epsilon */
168876 mxRun = LOGEST_MIN;
168877 for(pWLoop=pStart; pWLoop; pWLoop=pWLoop->pNextLoop){
168878 if( pWLoop->iTab<iFromIdx ) continue;
168879 if( pWLoop->iTab>iFromIdx ) break;
168880 if( pWLoop->rRun>mxRun ) mxRun = pWLoop->rRun;
168881 }
168882 if( ALWAYS(mxRun<LOGEST_MAX) ) mxRun++;
168883
168884 /* Increase the cost of table scans for dimension tables to be
168885 ** slightly more than the maximum cost of the fact table */
168886 for(pWLoop=pStart; pWLoop; pWLoop=pWLoop->pNextLoop){
168887 if( (pWLoop->maskSelf & mSeen)==0 ) continue;
168888 if( pWLoop->nLTerm ) continue;
168889 if( pWLoop->rRun<mxRun ){
168890 #ifdef WHERETRACE_ENABLED /* 0x80000 */
168891 if( sqlite3WhereTrace & 0x80000 ){
168892 SrcItem *pDim = aFromTabs + pWLoop->iTab;
168893 sqlite3DebugPrintf(
168894 "Increase SCAN cost of dimension %s(%d) of fact %s(%d) to %d\n",
168895 pDim->zAlias ? pDim->zAlias: pDim->pSTab->zName, pWLoop->iTab,
168896 pFactTab->zAlias ? pFactTab->zAlias : pFactTab->pSTab->zName,
168897 iFromIdx, mxRun
168898 );
168899 }
168900 pWLoop->rStarDelta = mxRun - pWLoop->rRun;
168901 #endif /* WHERETRACE_ENABLED */
168902 pWLoop->rRun = mxRun;
168903 }
168904 }
168905 }
168906 #ifdef WHERETRACE_ENABLED /* 0x80000 */
168907 if( (sqlite3WhereTrace & 0x80000)!=0 && pWInfo->bStarUsed ){
168908 sqlite3DebugPrintf("WhereLoops changed by star-query heuristic:\n");
168909 for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
168910 if( pWLoop->rStarDelta ){
168911 sqlite3WhereLoopPrint(pWLoop, &pWInfo->sWC);
 
 
168912 }
168913 }
168914 }
168915 #endif
168916 }
168917 return pWInfo->bStarUsed ? 18 : 12;
168918 }
168919
168920 /*
168921 ** Two WhereLoop objects, pCandidate and pBaseline, are known to have the
168922 ** same cost. Look deep into each to see if pCandidate is even slightly
168923 ** better than pBaseline. Return false if it is, if pCandidate is is preferred.
168924 ** Return true if pBaseline is preferred or if we cannot tell the difference.
168925 **
168926 ** Result Meaning
168927 ** -------- ----------------------------------------------------------
168928 ** true We cannot tell the difference in pCandidate and pBaseline
168929 ** false pCandidate seems like a better choice than pBaseline
168930 */
168931 static SQLITE_NOINLINE int whereLoopIsNoBetter(
168932 const WhereLoop *pCandidate,
168933 const WhereLoop *pBaseline
168934 ){
168935 if( (pCandidate->wsFlags & WHERE_INDEXED)==0 ) return 1;
168936 if( (pBaseline->wsFlags & WHERE_INDEXED)==0 ) return 1;
168937 if( pCandidate->u.btree.pIndex->szIdxRow <
168938 pBaseline->u.btree.pIndex->szIdxRow ) return 0;
168939 return 1;
168940 }
168941
168942 /*
168943 ** Given the list of WhereLoop objects at pWInfo->pLoops, this routine
168944 ** attempts to find the lowest cost path that visits each WhereLoop
@@ -168794,11 +168958,11 @@
168958 int iLoop; /* Loop counter over the terms of the join */
168959 int ii, jj; /* Loop counters */
168960 int mxI = 0; /* Index of next entry to replace */
168961 int nOrderBy; /* Number of ORDER BY clause terms */
168962 LogEst mxCost = 0; /* Maximum cost of a set of paths */
168963 LogEst mxUnsort = 0; /* Maximum unsorted cost of a set of path */
168964 int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */
168965 WherePath *aFrom; /* All nFrom paths at the previous level */
168966 WherePath *aTo; /* The nTo best paths at the current level */
168967 WherePath *pFrom; /* An element of aFrom[] that we are working on */
168968 WherePath *pTo; /* An element of aTo[] that we are working on */
@@ -168823,12 +168987,14 @@
168987 */
168988 if( nLoop<=1 ){
168989 mxChoice = 1;
168990 }else if( nLoop==2 ){
168991 mxChoice = 5;
168992 }else if( pParse->nErr ){
168993 mxChoice = 1;
168994 }else{
168995 mxChoice = computeMxChoice(pWInfo);
168996 }
168997 assert( nLoop<=pWInfo->pTabList->nSrc );
168998
168999 /* If nRowEst is zero and there is an ORDER BY clause, ignore it. In this
169000 ** case the purpose of this call is to estimate the number of rows returned
@@ -168891,11 +169057,11 @@
169057 nTo = 0;
169058 for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){
169059 for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
169060 LogEst nOut; /* Rows visited by (pFrom+pWLoop) */
169061 LogEst rCost; /* Cost of path (pFrom+pWLoop) */
169062 LogEst rUnsort; /* Unsorted cost of (pFrom+pWLoop) */
169063 i8 isOrdered; /* isOrdered for (pFrom+pWLoop) */
169064 Bitmask maskNew; /* Mask of src visited by (..) */
169065 Bitmask revMask; /* Mask of rev-order loops for (..) */
169066
169067 if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue;
@@ -168909,15 +169075,15 @@
169075 continue;
169076 }
169077
169078 /* At this point, pWLoop is a candidate to be the next loop.
169079 ** Compute its cost */
169080 rUnsort = pWLoop->rRun + pFrom->nRow;
169081 if( pWLoop->rSetup ){
169082 rUnsort = sqlite3LogEstAdd(pWLoop->rSetup, rUnsort);
169083 }
169084 rUnsort = sqlite3LogEstAdd(rUnsort, pFrom->rUnsort);
169085 nOut = pFrom->nRow + pWLoop->nOut;
169086 maskNew = pFrom->maskLoop | pWLoop->maskSelf;
169087 isOrdered = pFrom->isOrdered;
169088 if( isOrdered<0 ){
169089 revMask = 0;
@@ -168935,19 +169101,19 @@
169101 }
169102 /* TUNING: Add a small extra penalty (3) to sorting as an
169103 ** extra encouragement to the query planner to select a plan
169104 ** where the rows emerge in the correct order without any sorting
169105 ** required. */
169106 rCost = sqlite3LogEstAdd(rUnsort, aSortCost[isOrdered]) + 3;
169107
169108 WHERETRACE(0x002,
169109 ("---- sort cost=%-3d (%d/%d) increases cost %3d to %-3d\n",
169110 aSortCost[isOrdered], (nOrderBy-isOrdered), nOrderBy,
169111 rUnsort, rCost));
169112 }else{
169113 rCost = rUnsort;
169114 rUnsort -= 2; /* TUNING: Slight bias in favor of no-sort plans */
169115 }
169116
169117 /* Check to see if pWLoop should be added to the set of
169118 ** mxChoice best-so-far paths.
169119 **
@@ -168969,19 +169135,19 @@
169135 }
169136 }
169137 if( jj>=nTo ){
169138 /* None of the existing best-so-far paths match the candidate. */
169139 if( nTo>=mxChoice
169140 && (rCost>mxCost || (rCost==mxCost && rUnsort>=mxUnsort))
169141 ){
169142 /* The current candidate is no better than any of the mxChoice
169143 ** paths currently in the best-so-far buffer. So discard
169144 ** this candidate as not viable. */
169145 #ifdef WHERETRACE_ENABLED /* 0x4 */
169146 if( sqlite3WhereTrace&0x4 ){
169147 sqlite3DebugPrintf("Skip %s cost=%-3d,%3d,%3d order=%c\n",
169148 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsort,
169149 isOrdered>=0 ? isOrdered+'0' : '?');
169150 }
169151 #endif
169152 continue;
169153 }
@@ -168996,11 +169162,11 @@
169162 }
169163 pTo = &aTo[jj];
169164 #ifdef WHERETRACE_ENABLED /* 0x4 */
169165 if( sqlite3WhereTrace&0x4 ){
169166 sqlite3DebugPrintf("New %s cost=%-3d,%3d,%3d order=%c\n",
169167 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsort,
169168 isOrdered>=0 ? isOrdered+'0' : '?');
169169 }
169170 #endif
169171 }else{
169172 /* Control reaches here if best-so-far path pTo=aTo[jj] covers the
@@ -169007,28 +169173,27 @@
169173 ** same set of loops and has the same isOrdered setting as the
169174 ** candidate path. Check to see if the candidate should replace
169175 ** pTo or if the candidate should be skipped.
169176 **
169177 ** The conditional is an expanded vector comparison equivalent to:
169178 ** (pTo->rCost,pTo->nRow,pTo->rUnsort) <= (rCost,nOut,rUnsort)
169179 */
169180 if( (pTo->rCost<rCost)
169181 || (pTo->rCost==rCost && pTo->nRow<nOut)
169182 || (pTo->rCost==rCost && pTo->nRow==nOut && pTo->rUnsort<rUnsort)
169183 || (pTo->rCost==rCost && pTo->nRow==nOut && pTo->rUnsort==rUnsort
169184 && whereLoopIsNoBetter(pWLoop, pTo->aLoop[iLoop]) )
 
169185 ){
169186 #ifdef WHERETRACE_ENABLED /* 0x4 */
169187 if( sqlite3WhereTrace&0x4 ){
169188 sqlite3DebugPrintf(
169189 "Skip %s cost=%-3d,%3d,%3d order=%c",
169190 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsort,
169191 isOrdered>=0 ? isOrdered+'0' : '?');
169192 sqlite3DebugPrintf(" vs %s cost=%-3d,%3d,%3d order=%c\n",
169193 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
169194 pTo->rUnsort, pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?');
169195 }
169196 #endif
169197 /* Discard the candidate path from further consideration */
169198 testcase( pTo->rCost==rCost );
169199 continue;
@@ -169038,37 +169203,37 @@
169203 ** pTo path. Replace pTo with the candidate. */
169204 #ifdef WHERETRACE_ENABLED /* 0x4 */
169205 if( sqlite3WhereTrace&0x4 ){
169206 sqlite3DebugPrintf(
169207 "Update %s cost=%-3d,%3d,%3d order=%c",
169208 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, rUnsort,
169209 isOrdered>=0 ? isOrdered+'0' : '?');
169210 sqlite3DebugPrintf(" was %s cost=%-3d,%3d,%3d order=%c\n",
169211 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
169212 pTo->rUnsort, pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?');
169213 }
169214 #endif
169215 }
169216 /* pWLoop is a winner. Add it to the set of best so far */
169217 pTo->maskLoop = pFrom->maskLoop | pWLoop->maskSelf;
169218 pTo->revLoop = revMask;
169219 pTo->nRow = nOut;
169220 pTo->rCost = rCost;
169221 pTo->rUnsort = rUnsort;
169222 pTo->isOrdered = isOrdered;
169223 memcpy(pTo->aLoop, pFrom->aLoop, sizeof(WhereLoop*)*iLoop);
169224 pTo->aLoop[iLoop] = pWLoop;
169225 if( nTo>=mxChoice ){
169226 mxI = 0;
169227 mxCost = aTo[0].rCost;
169228 mxUnsort = aTo[0].nRow;
169229 for(jj=1, pTo=&aTo[1]; jj<mxChoice; jj++, pTo++){
169230 if( pTo->rCost>mxCost
169231 || (pTo->rCost==mxCost && pTo->rUnsort>mxUnsort)
169232 ){
169233 mxCost = pTo->rCost;
169234 mxUnsort = pTo->rUnsort;
169235 mxI = jj;
169236 }
169237 }
169238 }
169239 }
@@ -169076,12 +169241,14 @@
169241
169242 #ifdef WHERETRACE_ENABLED /* >=2 */
169243 if( sqlite3WhereTrace & 0x02 ){
169244 LogEst rMin, rFloor = 0;
169245 int nDone = 0;
169246 int nProgress;
169247 sqlite3DebugPrintf("---- after round %d ----\n", iLoop);
169248 do{
169249 nProgress = 0;
169250 rMin = 0x7fff;
169251 for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
169252 if( pTo->rCost>rFloor && pTo->rCost<rMin ) rMin = pTo->rCost;
169253 }
169254 for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
@@ -169093,14 +169260,15 @@
169260 sqlite3DebugPrintf(" rev=0x%llx\n", pTo->revLoop);
169261 }else{
169262 sqlite3DebugPrintf("\n");
169263 }
169264 nDone++;
169265 nProgress++;
169266 }
169267 }
169268 rFloor = rMin;
169269 }while( nDone<nTo && nProgress>0 );
169270 }
169271 #endif
169272
169273 /* Swap the roles of aFrom and aTo for the next generation */
169274 pFrom = aTo;
@@ -169190,11 +169358,14 @@
169358 pWInfo->revMask = revMask;
169359 }
169360 }
169361 }
169362
169363 pWInfo->nRowOut = pFrom->nRow;
169364 #ifdef WHERETRACE_ENABLED
169365 pWInfo->rTotalCost = pFrom->rCost;
169366 #endif
169367
169368 /* Free temporary memory and return success */
169369 sqlite3StackFreeNN(pParse->db, pSpace);
169370 return SQLITE_OK;
169371 }
@@ -169588,11 +169759,10 @@
169759 pLoop->cId, (double)sqlite3LogEstToInt(nSearch), pTab->zName,
169760 (double)sqlite3LogEstToInt(pTab->nRowLogEst)));
169761 }
169762 }
169763 nSearch += pLoop->nOut;
 
169764 }
169765 }
169766
169767 /*
169768 ** The index pIdx is used by a query and contains one or more expressions.
@@ -170071,11 +170241,12 @@
170241 goto whereBeginError;
170242 }
170243 assert( db->mallocFailed==0 );
170244 #ifdef WHERETRACE_ENABLED
170245 if( sqlite3WhereTrace ){
170246 sqlite3DebugPrintf("---- Solution cost=%d, nRow=%d",
170247 pWInfo->rTotalCost, pWInfo->nRowOut);
170248 if( pWInfo->nOBSat>0 ){
170249 sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
170250 }
170251 switch( pWInfo->eDistinct ){
170252 case WHERE_DISTINCT_UNIQUE: {
@@ -226574,15 +226745,17 @@
226745 ** SELECT 1, NULL, 'abc'
226746 */
226747 struct SessionTable {
226748 SessionTable *pNext;
226749 char *zName; /* Local name of table */
226750 int nCol; /* Number of non-hidden columns */
226751 int nTotalCol; /* Number of columns including hidden */
226752 int bStat1; /* True if this is sqlite_stat1 */
226753 int bRowid; /* True if this table uses rowid for PK */
226754 const char **azCol; /* Column names */
226755 const char **azDflt; /* Default value expressions */
226756 int *aiIdx; /* Index to pass to xNew/xOld */
226757 u8 *abPK; /* Array of primary key flags */
226758 int nEntry; /* Total number of entries in hash table */
226759 int nChange; /* Size of apChange[] array */
226760 SessionChange **apChange; /* Hash table buckets */
226761 sqlite3_stmt *pDfltStmt;
@@ -226981,26 +227154,26 @@
227154 int *pbNullPK /* OUT: True if there are NULL values in PK */
227155 ){
227156 unsigned int h = 0; /* Hash value to return */
227157 int i; /* Used to iterate through columns */
227158
227159 assert( pTab->nTotalCol==pSession->hook.xCount(pSession->hook.pCtx) );
227160 if( pTab->bRowid ){
 
227161 h = sessionHashAppendI64(h, iRowid);
227162 }else{
227163 assert( *pbNullPK==0 );
 
227164 for(i=0; i<pTab->nCol; i++){
227165 if( pTab->abPK[i] ){
227166 int rc;
227167 int eType;
227168 sqlite3_value *pVal;
227169 int iIdx = pTab->aiIdx[i];
227170
227171 if( bNew ){
227172 rc = pSession->hook.xNew(pSession->hook.pCtx, iIdx, &pVal);
227173 }else{
227174 rc = pSession->hook.xOld(pSession->hook.pCtx, iIdx, &pVal);
227175 }
227176 if( rc!=SQLITE_OK ) return rc;
227177
227178 eType = sqlite3_value_type(pVal);
227179 h = sessionHashAppendType(h, eType);
@@ -227333,22 +227506,23 @@
227506 a += sessionSerialLen(a);
227507 }else{
227508 sqlite3_value *pVal; /* Value returned by preupdate_new/old */
227509 int rc; /* Error code from preupdate_new/old */
227510 int eType = *a++; /* Type of value from change record */
227511 int iIdx = pTab->aiIdx[iCol];
227512
227513 /* The following calls to preupdate_new() and preupdate_old() can not
227514 ** fail. This is because they cache their return values, and by the
227515 ** time control flows to here they have already been called once from
227516 ** within sessionPreupdateHash(). The first two asserts below verify
227517 ** this (that the method has already been called). */
227518 if( op==SQLITE_INSERT ){
227519 /* assert( db->pPreUpdate->pNewUnpacked || db->pPreUpdate->aNew ); */
227520 rc = pSession->hook.xNew(pSession->hook.pCtx, iIdx, &pVal);
227521 }else{
227522 /* assert( db->pPreUpdate->pUnpacked ); */
227523 rc = pSession->hook.xOld(pSession->hook.pCtx, iIdx, &pVal);
227524 }
227525 assert( rc==SQLITE_OK );
227526 (void)rc; /* Suppress warning about unused variable */
227527 if( sqlite3_value_type(pVal)!=eType ) return 0;
227528
@@ -227469,13 +227643,15 @@
227643 sqlite3_session *pSession, /* For memory accounting. May be NULL */
227644 sqlite3 *db, /* Database connection */
227645 const char *zDb, /* Name of attached database (e.g. "main") */
227646 const char *zThis, /* Table name */
227647 int *pnCol, /* OUT: number of columns */
227648 int *pnTotalCol, /* OUT: number of hidden columns */
227649 const char **pzTab, /* OUT: Copy of zThis */
227650 const char ***pazCol, /* OUT: Array of column names for table */
227651 const char ***pazDflt, /* OUT: Array of default value expressions */
227652 int **paiIdx, /* OUT: Array of xNew/xOld indexes */
227653 u8 **pabPK, /* OUT: Array of booleans - true for PK col */
227654 int *pbRowid /* OUT: True if only PK is a rowid */
227655 ){
227656 char *zPragma;
227657 sqlite3_stmt *pStmt;
@@ -227486,37 +227662,40 @@
227662 int i;
227663 u8 *pAlloc = 0;
227664 char **azCol = 0;
227665 char **azDflt = 0;
227666 u8 *abPK = 0;
227667 int *aiIdx = 0;
227668 int bRowid = 0; /* Set to true to use rowid as PK */
227669
227670 assert( pazCol && pabPK );
227671
227672 *pazCol = 0;
227673 *pabPK = 0;
227674 *pnCol = 0;
227675 if( pnTotalCol ) *pnTotalCol = 0;
227676 if( paiIdx ) *paiIdx = 0;
227677 if( pzTab ) *pzTab = 0;
227678 if( pazDflt ) *pazDflt = 0;
227679
227680 nThis = sqlite3Strlen30(zThis);
227681 if( nThis==12 && 0==sqlite3_stricmp("sqlite_stat1", zThis) ){
227682 rc = sqlite3_table_column_metadata(db, zDb, zThis, 0, 0, 0, 0, 0, 0);
227683 if( rc==SQLITE_OK ){
227684 /* For sqlite_stat1, pretend that (tbl,idx) is the PRIMARY KEY. */
227685 zPragma = sqlite3_mprintf(
227686 "SELECT 0, 'tbl', '', 0, '', 1, 0 UNION ALL "
227687 "SELECT 1, 'idx', '', 0, '', 2, 0 UNION ALL "
227688 "SELECT 2, 'stat', '', 0, '', 0, 0"
227689 );
227690 }else if( rc==SQLITE_ERROR ){
227691 zPragma = sqlite3_mprintf("");
227692 }else{
227693 return rc;
227694 }
227695 }else{
227696 zPragma = sqlite3_mprintf("PRAGMA '%q'.table_xinfo('%q')", zDb, zThis);
227697 }
227698 if( !zPragma ){
227699 return SQLITE_NOMEM;
227700 }
227701
@@ -227529,20 +227708,22 @@
227708 nByte = nThis + 1;
227709 bRowid = (pbRowid!=0);
227710 while( SQLITE_ROW==sqlite3_step(pStmt) ){
227711 nByte += sqlite3_column_bytes(pStmt, 1); /* name */
227712 nByte += sqlite3_column_bytes(pStmt, 4); /* dflt_value */
227713 if( sqlite3_column_int(pStmt, 6)==0 ){ /* !hidden */
227714 nDbCol++;
227715 }
227716 if( sqlite3_column_int(pStmt, 5) ) bRowid = 0; /* pk */
227717 }
227718 if( nDbCol==0 ) bRowid = 0;
227719 nDbCol += bRowid;
227720 nByte += strlen(SESSIONS_ROWID);
227721 rc = sqlite3_reset(pStmt);
227722
227723 if( rc==SQLITE_OK ){
227724 nByte += nDbCol * (sizeof(const char *)*2 +sizeof(int)+sizeof(u8) + 1 + 1);
227725 pAlloc = sessionMalloc64(pSession, nByte);
227726 if( pAlloc==0 ){
227727 rc = SQLITE_NOMEM;
227728 }else{
227729 memset(pAlloc, 0, nByte);
@@ -227549,12 +227730,12 @@
227730 }
227731 }
227732 if( rc==SQLITE_OK ){
227733 azCol = (char **)pAlloc;
227734 azDflt = (char**)&azCol[nDbCol];
227735 aiIdx = (int*)&azDflt[nDbCol];
227736 abPK = (u8 *)&aiIdx[nDbCol];
227737 pAlloc = &abPK[nDbCol];
227738 if( pzTab ){
227739 memcpy(pAlloc, zThis, nThis+1);
227740 *pzTab = (char *)pAlloc;
227741 pAlloc += nThis+1;
@@ -227565,31 +227746,36 @@
227746 size_t nName = strlen(SESSIONS_ROWID);
227747 memcpy(pAlloc, SESSIONS_ROWID, nName+1);
227748 azCol[i] = (char*)pAlloc;
227749 pAlloc += nName+1;
227750 abPK[i] = 1;
227751 aiIdx[i] = -1;
227752 i++;
227753 }
227754 while( SQLITE_ROW==sqlite3_step(pStmt) ){
227755 if( sqlite3_column_int(pStmt, 6)==0 ){ /* !hidden */
227756 int nName = sqlite3_column_bytes(pStmt, 1);
227757 int nDflt = sqlite3_column_bytes(pStmt, 4);
227758 const unsigned char *zName = sqlite3_column_text(pStmt, 1);
227759 const unsigned char *zDflt = sqlite3_column_text(pStmt, 4);
227760
227761 if( zName==0 ) break;
227762 memcpy(pAlloc, zName, nName+1);
227763 azCol[i] = (char *)pAlloc;
227764 pAlloc += nName+1;
227765 if( zDflt ){
227766 memcpy(pAlloc, zDflt, nDflt+1);
227767 azDflt[i] = (char *)pAlloc;
227768 pAlloc += nDflt+1;
227769 }else{
227770 azDflt[i] = 0;
227771 }
227772 abPK[i] = sqlite3_column_int(pStmt, 5);
227773 aiIdx[i] = sqlite3_column_int(pStmt, 0);
227774 i++;
227775 }
227776 if( pnTotalCol ) (*pnTotalCol)++;
227777 }
227778 rc = sqlite3_reset(pStmt);
227779 }
227780
227781 /* If successful, populate the output variables. Otherwise, zero them and
@@ -227598,10 +227784,11 @@
227784 if( rc==SQLITE_OK ){
227785 *pazCol = (const char**)azCol;
227786 if( pazDflt ) *pazDflt = (const char**)azDflt;
227787 *pabPK = abPK;
227788 *pnCol = nDbCol;
227789 if( paiIdx ) *paiIdx = aiIdx;
227790 }else{
227791 sessionFree(pSession, azCol);
227792 }
227793 if( pbRowid ) *pbRowid = bRowid;
227794 sqlite3_finalize(pStmt);
@@ -227629,11 +227816,12 @@
227816
227817 if( pTab->nCol==0 ){
227818 u8 *abPK;
227819 assert( pTab->azCol==0 || pTab->abPK==0 );
227820 rc = sessionTableInfo(pSession, db, zDb,
227821 pTab->zName, &pTab->nCol, &pTab->nTotalCol, 0, &pTab->azCol,
227822 &pTab->azDflt, &pTab->aiIdx, &abPK,
227823 ((pSession==0 || pSession->bImplicitPK) ? &pTab->bRowid : 0)
227824 );
227825 if( rc==SQLITE_OK ){
227826 int i;
227827 for(i=0; i<pTab->nCol; i++){
@@ -227664,19 +227852,21 @@
227852 /*
227853 ** Re-initialize table object pTab.
227854 */
227855 static int sessionReinitTable(sqlite3_session *pSession, SessionTable *pTab){
227856 int nCol = 0;
227857 int nTotalCol = 0;
227858 const char **azCol = 0;
227859 const char **azDflt = 0;
227860 int *aiIdx = 0;
227861 u8 *abPK = 0;
227862 int bRowid = 0;
227863
227864 assert( pSession->rc==SQLITE_OK );
227865
227866 pSession->rc = sessionTableInfo(pSession, pSession->db, pSession->zDb,
227867 pTab->zName, &nCol, &nTotalCol, 0, &azCol, &azDflt, &aiIdx, &abPK,
227868 (pSession->bImplicitPK ? &bRowid : 0)
227869 );
227870 if( pSession->rc==SQLITE_OK ){
227871 if( pTab->nCol>nCol || pTab->bRowid!=bRowid ){
227872 pSession->rc = SQLITE_SCHEMA;
@@ -227695,12 +227885,14 @@
227885
227886 if( pSession->rc==SQLITE_OK ){
227887 const char **a = pTab->azCol;
227888 pTab->azCol = azCol;
227889 pTab->nCol = nCol;
227890 pTab->nTotalCol = nTotalCol;
227891 pTab->azDflt = azDflt;
227892 pTab->abPK = abPK;
227893 pTab->aiIdx = aiIdx;
227894 azCol = a;
227895 }
227896 if( pSession->bEnableSize ){
227897 pSession->nMaxChangesetSize += (nCol - nOldCol);
227898 pSession->nMaxChangesetSize += sessionVarintLen(nCol);
@@ -228014,11 +228206,11 @@
228206 if( pTab->bRowid ) nNew += 9;
228207 if( op!=SQLITE_DELETE ){
228208 int ii;
228209 for(ii=0; ii<pTab->nCol; ii++){
228210 sqlite3_value *p = 0;
228211 pSession->hook.xNew(pSession->hook.pCtx, pTab->aiIdx[ii], &p);
228212 sessionSerializeValue(0, p, &nNew);
228213 }
228214 }
228215 }else if( op==SQLITE_DELETE ){
228216 nNew += pC->nRecord;
@@ -228034,12 +228226,13 @@
228226 }
228227 for(ii=pTab->bRowid; ii<pTab->nCol; ii++){
228228 int bChanged = 1;
228229 int nOld = 0;
228230 int eType;
228231 int iIdx = pTab->aiIdx[ii];
228232 sqlite3_value *p = 0;
228233 pSession->hook.xNew(pSession->hook.pCtx, iIdx, &p);
228234 if( p==0 ){
228235 return SQLITE_NOMEM;
228236 }
228237
228238 eType = *pCsr++;
@@ -228132,15 +228325,15 @@
228325 if( sessionInitTable(pSession, pTab, pSession->db, pSession->zDb) ) return;
228326
228327 /* Check the number of columns in this xPreUpdate call matches the
228328 ** number of columns in the table. */
228329 nExpect = pSession->hook.xCount(pSession->hook.pCtx);
228330 if( pTab->nTotalCol<nExpect ){
228331 if( sessionReinitTable(pSession, pTab) ) return;
228332 if( sessionUpdateChanges(pSession, pTab) ) return;
228333 }
228334 if( pTab->nTotalCol!=nExpect ){
228335 pSession->rc = SQLITE_SCHEMA;
228336 return;
228337 }
228338
228339 /* Grow the hash table if required */
@@ -228193,18 +228386,19 @@
228386 assert( rc==SQLITE_OK );
228387 pTab->nEntry++;
228388
228389 /* Figure out how large an allocation is required */
228390 nByte = sizeof(SessionChange);
228391 for(i=pTab->bRowid; i<pTab->nCol; i++){
228392 int iIdx = pTab->aiIdx[i];
228393 sqlite3_value *p = 0;
228394 if( op!=SQLITE_INSERT ){
228395 /* This may fail if the column has a non-NULL default and was added
228396 ** using ALTER TABLE ADD COLUMN after this record was created. */
228397 rc = pSession->hook.xOld(pSession->hook.pCtx, iIdx, &p);
228398 }else if( pTab->abPK[i] ){
228399 TESTONLY(int trc = ) pSession->hook.xNew(pSession->hook.pCtx,iIdx,&p);
228400 assert( trc==SQLITE_OK );
228401 }
228402
228403 if( rc==SQLITE_OK ){
228404 /* This may fail if SQLite value p contains a utf-16 string that must
@@ -228235,16 +228429,17 @@
228429 if( pTab->bRowid ){
228430 pC->aRecord[0] = SQLITE_INTEGER;
228431 sessionPutI64(&pC->aRecord[1], iRowid);
228432 nByte = 9;
228433 }
228434 for(i=pTab->bRowid; i<pTab->nCol; i++){
228435 sqlite3_value *p = 0;
228436 int iIdx = pTab->aiIdx[i];
228437 if( op!=SQLITE_INSERT ){
228438 pSession->hook.xOld(pSession->hook.pCtx, iIdx, &p);
228439 }else if( pTab->abPK[i] ){
228440 pSession->hook.xNew(pSession->hook.pCtx, iIdx, &p);
228441 }
228442 sessionSerializeValue(&pC->aRecord[nByte], p, &nByte);
228443 }
228444
228445 /* Add the change to the hash-table */
@@ -228642,11 +228837,12 @@
228837 int bMismatch = 0;
228838 int nCol; /* Columns in zFrom.zTbl */
228839 int bRowid = 0;
228840 u8 *abPK;
228841 const char **azCol = 0;
228842 rc = sessionTableInfo(0, db, zFrom, zTbl,
228843 &nCol, 0, 0, &azCol, 0, 0, &abPK,
228844 pSession->bImplicitPK ? &bRowid : 0
228845 );
228846 if( rc==SQLITE_OK ){
228847 if( pTo->nCol!=nCol ){
228848 bMismatch = 1;
@@ -229219,14 +229415,14 @@
229415 sqlite3_stmt **ppStmt /* OUT: Prepared SELECT statement */
229416 ){
229417 int rc = SQLITE_OK;
229418 char *zSql = 0;
229419 const char *zSep = "";
 
229420 int nSql = -1;
229421 int i;
229422
229423 SessionBuffer cols = {0, 0, 0};
229424 SessionBuffer nooptest = {0, 0, 0};
229425 SessionBuffer pkfield = {0, 0, 0};
229426 SessionBuffer pkvar = {0, 0, 0};
229427
229428 sessionAppendStr(&nooptest, ", 1", &rc);
@@ -229235,13 +229431,20 @@
229431 sessionAppendStr(&nooptest, " AND (?6 OR ?3 IS stat)", &rc);
229432 sessionAppendStr(&pkfield, "tbl, idx", &rc);
229433 sessionAppendStr(&pkvar,
229434 "?1, (CASE WHEN ?2=X'' THEN NULL ELSE ?2 END)", &rc
229435 );
229436 sessionAppendStr(&cols, "tbl, ?2, stat", &rc);
229437 }else{
229438 #if 0
229439 if( bRowid ){
229440 sessionAppendStr(&cols, SESSIONS_ROWID, &rc);
229441 }
229442 #endif
229443 for(i=0; i<nCol; i++){
229444 if( cols.nBuf ) sessionAppendStr(&cols, ", ", &rc);
229445 sessionAppendIdent(&cols, azCol[i], &rc);
229446 if( abPK[i] ){
229447 sessionAppendStr(&pkfield, zSep, &rc);
229448 sessionAppendStr(&pkvar, zSep, &rc);
229449 zSep = ", ";
229450 sessionAppendIdent(&pkfield, azCol[i], &rc);
@@ -229255,11 +229458,11 @@
229458 }
229459
229460 if( rc==SQLITE_OK ){
229461 zSql = sqlite3_mprintf(
229462 "SELECT %s%s FROM %Q.%Q WHERE (%s) IS (%s)",
229463 (char*)cols.aBuf, (bIgnoreNoop ? (char*)nooptest.aBuf : ""),
229464 zDb, zTab, (char*)pkfield.aBuf, (char*)pkvar.aBuf
229465 );
229466 if( zSql==0 ) rc = SQLITE_NOMEM;
229467 }
229468
@@ -229298,10 +229501,11 @@
229501 }
229502 sqlite3_free(zSql);
229503 sqlite3_free(nooptest.aBuf);
229504 sqlite3_free(pkfield.aBuf);
229505 sqlite3_free(pkvar.aBuf);
229506 sqlite3_free(cols.aBuf);
229507 return rc;
229508 }
229509
229510 /*
229511 ** Bind the PRIMARY KEY values from the change passed in argument pChange
@@ -231638,11 +231842,12 @@
231842 int nMinCol = 0;
231843 int i;
231844
231845 sqlite3changeset_pk(pIter, &abPK, 0);
231846 rc = sessionTableInfo(0, db, "main", zNew,
231847 &sApply.nCol, 0, &zTab, &sApply.azCol, 0, 0,
231848 &sApply.abPK, &sApply.bRowid
231849 );
231850 if( rc!=SQLITE_OK ) break;
231851 for(i=0; i<sApply.nCol; i++){
231852 if( sApply.abPK[i] ) nMinCol = i+1;
231853 }
@@ -231718,10 +231923,15 @@
231923 if( res!=SQLITE_CHANGESET_OMIT ){
231924 rc = SQLITE_CONSTRAINT;
231925 }
231926 }
231927 }
231928
231929 {
231930 int rc2 = sqlite3_exec(db, "PRAGMA defer_foreign_keys = 0", 0, 0, 0);
231931 if( rc==SQLITE_OK ) rc = rc2;
231932 }
231933
231934 if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){
231935 if( rc==SQLITE_OK ){
231936 rc = sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0);
231937 }
@@ -243230,15 +243440,17 @@
243440 }
243441
243442 /*
243443 ** Close the read-only blob handle, if it is open.
243444 */
243445 static void fts5IndexCloseReader(Fts5Index *p){
243446 if( p->pReader ){
243447 int rc;
243448 sqlite3_blob *pReader = p->pReader;
243449 p->pReader = 0;
243450 rc = sqlite3_blob_close(pReader);
243451 if( p->rc==SQLITE_OK ) p->rc = rc;
243452 }
243453 }
243454
243455 /*
243456 ** Retrieve a record from the %_data table.
@@ -243259,11 +243471,11 @@
243471 p->pReader = 0;
243472 rc = sqlite3_blob_reopen(pBlob, iRowid);
243473 assert( p->pReader==0 );
243474 p->pReader = pBlob;
243475 if( rc!=SQLITE_OK ){
243476 fts5IndexCloseReader(p);
243477 }
243478 if( rc==SQLITE_ABORT ) rc = SQLITE_OK;
243479 }
243480
243481 /* If the blob handle is not open at this point, open it and seek
@@ -247460,10 +247672,18 @@
247672 static int fts5IndexReturn(Fts5Index *p){
247673 int rc = p->rc;
247674 p->rc = SQLITE_OK;
247675 return rc;
247676 }
247677
247678 /*
247679 ** Close the read-only blob handle, if it is open.
247680 */
247681 static void sqlite3Fts5IndexCloseReader(Fts5Index *p){
247682 fts5IndexCloseReader(p);
247683 fts5IndexReturn(p);
247684 }
247685
247686 typedef struct Fts5FlushCtx Fts5FlushCtx;
247687 struct Fts5FlushCtx {
247688 Fts5Index *pIdx;
247689 Fts5SegWriter writer;
@@ -249182,11 +249402,11 @@
249402 ** Commit data to disk.
249403 */
249404 static int sqlite3Fts5IndexSync(Fts5Index *p){
249405 assert( p->rc==SQLITE_OK );
249406 fts5IndexFlush(p);
249407 fts5IndexCloseReader(p);
249408 return fts5IndexReturn(p);
249409 }
249410
249411 /*
249412 ** Discard any data stored in the in-memory hash tables. Do not write it
@@ -249193,15 +249413,14 @@
249413 ** to the database. Additionally, assume that the contents of the %_data
249414 ** table may have changed on disk. So any in-memory caches of %_data
249415 ** records must be invalidated.
249416 */
249417 static int sqlite3Fts5IndexRollback(Fts5Index *p){
249418 fts5IndexCloseReader(p);
249419 fts5IndexDiscardData(p);
249420 fts5StructureInvalidate(p);
249421 return fts5IndexReturn(p);
 
249422 }
249423
249424 /*
249425 ** The %_data table is completely empty when this function is called. This
249426 ** function populates it with the initial structure objects for each index,
@@ -249397,10 +249616,20 @@
249616 */
249617 static void fts5SegIterSetEOF(Fts5SegIter *pSeg){
249618 fts5DataRelease(pSeg->pLeaf);
249619 pSeg->pLeaf = 0;
249620 }
249621
249622 static void fts5IterClose(Fts5IndexIter *pIndexIter){
249623 if( pIndexIter ){
249624 Fts5Iter *pIter = (Fts5Iter*)pIndexIter;
249625 Fts5Index *pIndex = pIter->pIndex;
249626 fts5TokendataIterDelete(pIter->pTokenDataIter);
249627 fts5MultiIterFree(pIter);
249628 fts5IndexCloseReader(pIndex);
249629 }
249630 }
249631
249632 /*
249633 ** This function appends iterator pAppend to Fts5TokenDataIter pIn and
249634 ** returns the result.
249635 */
@@ -249425,11 +249654,11 @@
249654 pNew->nIterAlloc = nAlloc;
249655 }
249656 }
249657 }
249658 if( p->rc ){
249659 fts5IterClose((Fts5IndexIter*)pAppend);
249660 }else{
249661 pRet->apIter[pRet->nIter++] = pAppend;
249662 }
249663 assert( pRet==0 || pRet->nIter<=pRet->nIterAlloc );
249664
@@ -249638,11 +249867,11 @@
249867 fts5BufferAppendBlob(&p->rc, &bSeek, 1, (const u8*)"\0");
249868 }else{
249869 fts5BufferSet(&p->rc, &bSeek, nToken, pToken);
249870 }
249871 if( p->rc ){
249872 fts5IterClose((Fts5IndexIter*)pNew);
249873 break;
249874 }
249875
249876 pNewIter = &pNew->aSeg[0];
249877 pPrevIter = (pPrev ? &pPrev->aSeg[0] : 0);
@@ -249703,11 +249932,11 @@
249932
249933 /* If pSmall is still NULL at this point, then the new iterator does
249934 ** not point to any terms that match the query. So delete it and break
249935 ** out of the loop - all required iterators have been collected. */
249936 if( pSmall==0 ){
249937 fts5IterClose((Fts5IndexIter*)pNew);
249938 break;
249939 }
249940
249941 /* Append this iterator to the set and continue. */
249942 pSet = fts5AppendTokendataIter(p, pSet, pNew);
@@ -249832,13 +250061,13 @@
250061 }
250062 }
250063 }
250064
250065 if( p->rc ){
250066 fts5IterClose((Fts5IndexIter*)pRet);
250067 pRet = 0;
250068 fts5IndexCloseReader(p);
250069 }
250070
250071 *ppIter = (Fts5IndexIter*)pRet;
250072 sqlite3Fts5BufferFree(&buf);
250073 }
@@ -250084,15 +250313,13 @@
250313 /*
250314 ** Close an iterator opened by an earlier call to sqlite3Fts5IndexQuery().
250315 */
250316 static void sqlite3Fts5IterClose(Fts5IndexIter *pIndexIter){
250317 if( pIndexIter ){
250318 Fts5Index *pIndex = ((Fts5Iter*)pIndexIter)->pIndex;
250319 fts5IterClose(pIndexIter);
250320 fts5IndexReturn(pIndex);
 
 
250321 }
250322 }
250323
250324 /*
250325 ** Read and decode the "averages" record from the database.
@@ -250618,11 +250845,11 @@
250845 }
250846 if( rc==SQLITE_OK ){
250847 rc = sqlite3Fts5IterNext(pIter);
250848 }
250849 }
250850 fts5IterClose(pIter);
250851
250852 *pCksum = cksum;
250853 return rc;
250854 }
250855
@@ -255462,11 +255689,11 @@
255689 int nArg, /* Number of args */
255690 sqlite3_value **apUnused /* Function arguments */
255691 ){
255692 assert( nArg==0 );
255693 UNUSED_PARAM2(nArg, apUnused);
255694 sqlite3_result_text(pCtx, "fts5: 2025-01-29 18:53:19 d7c07581203a0a88456588e49e51b40a8341b0e7121809f75be0ee882d91650f", -1, SQLITE_TRANSIENT);
255695 }
255696
255697 /*
255698 ** Implementation of fts5_locale(LOCALE, TEXT) function.
255699 **
255700
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144144
**
145145
** See also: [sqlite3_libversion()],
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149
-#define SQLITE_VERSION "3.48.0"
150
-#define SQLITE_VERSION_NUMBER 3048000
151
-#define SQLITE_SOURCE_ID "2025-01-14 11:05:00 d2fe6b05f38d9d7cd78c5d252e99ac59f1aea071d669830c1ffe4e8966e84010"
149
+#define SQLITE_VERSION "3.49.0"
150
+#define SQLITE_VERSION_NUMBER 3049000
151
+#define SQLITE_SOURCE_ID "2025-01-29 18:53:19 d7c07581203a0a88456588e49e51b40a8341b0e7121809f75be0ee882d91650f"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -10746,12 +10746,13 @@
1074610746
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
1074710747
1074810748
/*
1074910749
** CAPI3REF: Serialize a database
1075010750
**
10751
-** The sqlite3_serialize(D,S,P,F) interface returns a pointer to memory
10752
-** that is a serialization of the S database on [database connection] D.
10751
+** The sqlite3_serialize(D,S,P,F) interface returns a pointer to
10752
+** memory that is a serialization of the S database on
10753
+** [database connection] D. If S is a NULL pointer, the main database is used.
1075310754
** If P is not a NULL pointer, then the size of the database in bytes
1075410755
** is written into *P.
1075510756
**
1075610757
** For an ordinary on-disk database file, the serialization is just a
1075710758
** copy of the disk file. For an in-memory database or a "TEMP" database,
1075810759
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.48.0"
150 #define SQLITE_VERSION_NUMBER 3048000
151 #define SQLITE_SOURCE_ID "2025-01-14 11:05:00 d2fe6b05f38d9d7cd78c5d252e99ac59f1aea071d669830c1ffe4e8966e84010"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -10746,12 +10746,13 @@
10746 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
10747
10748 /*
10749 ** CAPI3REF: Serialize a database
10750 **
10751 ** The sqlite3_serialize(D,S,P,F) interface returns a pointer to memory
10752 ** that is a serialization of the S database on [database connection] D.
 
10753 ** If P is not a NULL pointer, then the size of the database in bytes
10754 ** is written into *P.
10755 **
10756 ** For an ordinary on-disk database file, the serialization is just a
10757 ** copy of the disk file. For an in-memory database or a "TEMP" database,
10758
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.49.0"
150 #define SQLITE_VERSION_NUMBER 3049000
151 #define SQLITE_SOURCE_ID "2025-01-29 18:53:19 d7c07581203a0a88456588e49e51b40a8341b0e7121809f75be0ee882d91650f"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -10746,12 +10746,13 @@
10746 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
10747
10748 /*
10749 ** CAPI3REF: Serialize a database
10750 **
10751 ** The sqlite3_serialize(D,S,P,F) interface returns a pointer to
10752 ** memory that is a serialization of the S database on
10753 ** [database connection] D. If S is a NULL pointer, the main database is used.
10754 ** If P is not a NULL pointer, then the size of the database in bytes
10755 ** is written into *P.
10756 **
10757 ** For an ordinary on-disk database file, the serialization is just a
10758 ** copy of the disk file. For an in-memory database or a "TEMP" database,
10759
+4 -2
--- src/main.mk
+++ src/main.mk
@@ -648,14 +648,15 @@
648648
-DSQLITE_OMIT_SHARED_CACHE \
649649
-DSQLITE_OMIT_LOAD_EXTENSION \
650650
-DSQLITE_MAX_EXPR_DEPTH=0 \
651651
-DSQLITE_ENABLE_LOCKING_STYLE=0 \
652652
-DSQLITE_DEFAULT_FILE_FORMAT=4 \
653
+ -DSQLITE_ENABLE_DBSTAT_VTAB \
653654
-DSQLITE_ENABLE_EXPLAIN_COMMENTS \
654655
-DSQLITE_ENABLE_FTS4 \
655
- -DSQLITE_ENABLE_DBSTAT_VTAB \
656656
-DSQLITE_ENABLE_FTS5 \
657
+ -DSQLITE_ENABLE_MATH_FUNCTIONS \
657658
-DSQLITE_ENABLE_STMTVTAB \
658659
-DSQLITE_HAVE_ZLIB \
659660
-DSQLITE_ENABLE_DBPAGE_VTAB \
660661
-DSQLITE_TRUSTED_SCHEMA=0 \
661662
-DHAVE_USLEEP
@@ -673,14 +674,15 @@
673674
-DSQLITE_OMIT_SHARED_CACHE \
674675
-DSQLITE_OMIT_LOAD_EXTENSION \
675676
-DSQLITE_MAX_EXPR_DEPTH=0 \
676677
-DSQLITE_ENABLE_LOCKING_STYLE=0 \
677678
-DSQLITE_DEFAULT_FILE_FORMAT=4 \
679
+ -DSQLITE_ENABLE_DBSTAT_VTAB \
678680
-DSQLITE_ENABLE_EXPLAIN_COMMENTS \
679681
-DSQLITE_ENABLE_FTS4 \
680
- -DSQLITE_ENABLE_DBSTAT_VTAB \
681682
-DSQLITE_ENABLE_FTS5 \
683
+ -DSQLITE_ENABLE_MATH_FUNCTIONS \
682684
-DSQLITE_ENABLE_STMTVTAB \
683685
-DSQLITE_HAVE_ZLIB \
684686
-DSQLITE_ENABLE_DBPAGE_VTAB \
685687
-DSQLITE_TRUSTED_SCHEMA=0 \
686688
-DHAVE_USLEEP \
687689
--- src/main.mk
+++ src/main.mk
@@ -648,14 +648,15 @@
648 -DSQLITE_OMIT_SHARED_CACHE \
649 -DSQLITE_OMIT_LOAD_EXTENSION \
650 -DSQLITE_MAX_EXPR_DEPTH=0 \
651 -DSQLITE_ENABLE_LOCKING_STYLE=0 \
652 -DSQLITE_DEFAULT_FILE_FORMAT=4 \
 
653 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
654 -DSQLITE_ENABLE_FTS4 \
655 -DSQLITE_ENABLE_DBSTAT_VTAB \
656 -DSQLITE_ENABLE_FTS5 \
 
657 -DSQLITE_ENABLE_STMTVTAB \
658 -DSQLITE_HAVE_ZLIB \
659 -DSQLITE_ENABLE_DBPAGE_VTAB \
660 -DSQLITE_TRUSTED_SCHEMA=0 \
661 -DHAVE_USLEEP
@@ -673,14 +674,15 @@
673 -DSQLITE_OMIT_SHARED_CACHE \
674 -DSQLITE_OMIT_LOAD_EXTENSION \
675 -DSQLITE_MAX_EXPR_DEPTH=0 \
676 -DSQLITE_ENABLE_LOCKING_STYLE=0 \
677 -DSQLITE_DEFAULT_FILE_FORMAT=4 \
 
678 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
679 -DSQLITE_ENABLE_FTS4 \
680 -DSQLITE_ENABLE_DBSTAT_VTAB \
681 -DSQLITE_ENABLE_FTS5 \
 
682 -DSQLITE_ENABLE_STMTVTAB \
683 -DSQLITE_HAVE_ZLIB \
684 -DSQLITE_ENABLE_DBPAGE_VTAB \
685 -DSQLITE_TRUSTED_SCHEMA=0 \
686 -DHAVE_USLEEP \
687
--- src/main.mk
+++ src/main.mk
@@ -648,14 +648,15 @@
648 -DSQLITE_OMIT_SHARED_CACHE \
649 -DSQLITE_OMIT_LOAD_EXTENSION \
650 -DSQLITE_MAX_EXPR_DEPTH=0 \
651 -DSQLITE_ENABLE_LOCKING_STYLE=0 \
652 -DSQLITE_DEFAULT_FILE_FORMAT=4 \
653 -DSQLITE_ENABLE_DBSTAT_VTAB \
654 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
655 -DSQLITE_ENABLE_FTS4 \
 
656 -DSQLITE_ENABLE_FTS5 \
657 -DSQLITE_ENABLE_MATH_FUNCTIONS \
658 -DSQLITE_ENABLE_STMTVTAB \
659 -DSQLITE_HAVE_ZLIB \
660 -DSQLITE_ENABLE_DBPAGE_VTAB \
661 -DSQLITE_TRUSTED_SCHEMA=0 \
662 -DHAVE_USLEEP
@@ -673,14 +674,15 @@
674 -DSQLITE_OMIT_SHARED_CACHE \
675 -DSQLITE_OMIT_LOAD_EXTENSION \
676 -DSQLITE_MAX_EXPR_DEPTH=0 \
677 -DSQLITE_ENABLE_LOCKING_STYLE=0 \
678 -DSQLITE_DEFAULT_FILE_FORMAT=4 \
679 -DSQLITE_ENABLE_DBSTAT_VTAB \
680 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
681 -DSQLITE_ENABLE_FTS4 \
 
682 -DSQLITE_ENABLE_FTS5 \
683 -DSQLITE_ENABLE_MATH_FUNCTIONS \
684 -DSQLITE_ENABLE_STMTVTAB \
685 -DSQLITE_HAVE_ZLIB \
686 -DSQLITE_ENABLE_DBPAGE_VTAB \
687 -DSQLITE_TRUSTED_SCHEMA=0 \
688 -DHAVE_USLEEP \
689
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -240,14 +240,15 @@
240240
-DSQLITE_OMIT_SHARED_CACHE
241241
-DSQLITE_OMIT_LOAD_EXTENSION
242242
-DSQLITE_MAX_EXPR_DEPTH=0
243243
-DSQLITE_ENABLE_LOCKING_STYLE=0
244244
-DSQLITE_DEFAULT_FILE_FORMAT=4
245
+ -DSQLITE_ENABLE_DBSTAT_VTAB
245246
-DSQLITE_ENABLE_EXPLAIN_COMMENTS
246247
-DSQLITE_ENABLE_FTS4
247
- -DSQLITE_ENABLE_DBSTAT_VTAB
248248
-DSQLITE_ENABLE_FTS5
249
+ -DSQLITE_ENABLE_MATH_FUNCTIONS
249250
-DSQLITE_ENABLE_STMTVTAB
250251
-DSQLITE_HAVE_ZLIB
251252
-DSQLITE_ENABLE_DBPAGE_VTAB
252253
-DSQLITE_TRUSTED_SCHEMA=0
253254
-DHAVE_USLEEP
254255
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -240,14 +240,15 @@
240 -DSQLITE_OMIT_SHARED_CACHE
241 -DSQLITE_OMIT_LOAD_EXTENSION
242 -DSQLITE_MAX_EXPR_DEPTH=0
243 -DSQLITE_ENABLE_LOCKING_STYLE=0
244 -DSQLITE_DEFAULT_FILE_FORMAT=4
 
245 -DSQLITE_ENABLE_EXPLAIN_COMMENTS
246 -DSQLITE_ENABLE_FTS4
247 -DSQLITE_ENABLE_DBSTAT_VTAB
248 -DSQLITE_ENABLE_FTS5
 
249 -DSQLITE_ENABLE_STMTVTAB
250 -DSQLITE_HAVE_ZLIB
251 -DSQLITE_ENABLE_DBPAGE_VTAB
252 -DSQLITE_TRUSTED_SCHEMA=0
253 -DHAVE_USLEEP
254
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -240,14 +240,15 @@
240 -DSQLITE_OMIT_SHARED_CACHE
241 -DSQLITE_OMIT_LOAD_EXTENSION
242 -DSQLITE_MAX_EXPR_DEPTH=0
243 -DSQLITE_ENABLE_LOCKING_STYLE=0
244 -DSQLITE_DEFAULT_FILE_FORMAT=4
245 -DSQLITE_ENABLE_DBSTAT_VTAB
246 -DSQLITE_ENABLE_EXPLAIN_COMMENTS
247 -DSQLITE_ENABLE_FTS4
 
248 -DSQLITE_ENABLE_FTS5
249 -DSQLITE_ENABLE_MATH_FUNCTIONS
250 -DSQLITE_ENABLE_STMTVTAB
251 -DSQLITE_HAVE_ZLIB
252 -DSQLITE_ENABLE_DBPAGE_VTAB
253 -DSQLITE_TRUSTED_SCHEMA=0
254 -DHAVE_USLEEP
255
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -26,13 +26,13 @@
2626
CFLAGS = -o
2727
BCC = $(DMDIR)\bin\dmc $(CFLAGS)
2828
TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
2929
LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 dnsapi
3030
31
-SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP
31
+SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP
3232
33
-SHELL_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP -Dmain=sqlite3_shell -DSQLITE_SHELL_IS_UTF8=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=sqlcmd_get_dbname -DSQLITE_SHELL_INIT_PROC=sqlcmd_init_proc -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
33
+SHELL_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP -Dmain=sqlite3_shell -DSQLITE_SHELL_IS_UTF8=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=sqlcmd_get_dbname -DSQLITE_SHELL_INIT_PROC=sqlcmd_init_proc -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
3434
3535
PIKCHR_OPTIONS = -DPIKCHR_TOKEN_LIMIT=10000
3636
3737
SRC = add_.c ajax_.c alerts_.c allrepo_.c attach_.c backlink_.c backoffice_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.c capabilities_.c captcha_.c cgi_.c chat_.c checkin_.c checkout_.c clearsign_.c clone_.c color_.c comformat_.c configure_.c content_.c cookies_.c db_.c delta_.c deltacmd_.c deltafunc_.c descendants_.c diff_.c diffcmd_.c dispatch_.c doc_.c encode_.c etag_.c event_.c export_.c extcgi_.c file_.c fileedit_.c finfo_.c foci_.c forum_.c fshell_.c fusefs_.c fuzz_.c glob_.c graph_.c gzip_.c hname_.c hook_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c interwiki_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c match_.c md5_.c merge_.c merge3_.c moderate_.c name_.c patch_.c path_.c piechart_.c pikchrshow_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c repolist_.c report_.c rss_.c schema_.c search_.c security_audit_.c setup_.c setupuser_.c sha1_.c sha1hard_.c sha3_.c shun_.c sitemap_.c skins_.c smtp_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c terminal_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c unversioned_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c xfer_.c xfersetup_.c zip_.c
3838
3939
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -26,13 +26,13 @@
26 CFLAGS = -o
27 BCC = $(DMDIR)\bin\dmc $(CFLAGS)
28 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
29 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 dnsapi
30
31 SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP
32
33 SHELL_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP -Dmain=sqlite3_shell -DSQLITE_SHELL_IS_UTF8=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=sqlcmd_get_dbname -DSQLITE_SHELL_INIT_PROC=sqlcmd_init_proc -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
34
35 PIKCHR_OPTIONS = -DPIKCHR_TOKEN_LIMIT=10000
36
37 SRC = add_.c ajax_.c alerts_.c allrepo_.c attach_.c backlink_.c backoffice_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.c capabilities_.c captcha_.c cgi_.c chat_.c checkin_.c checkout_.c clearsign_.c clone_.c color_.c comformat_.c configure_.c content_.c cookies_.c db_.c delta_.c deltacmd_.c deltafunc_.c descendants_.c diff_.c diffcmd_.c dispatch_.c doc_.c encode_.c etag_.c event_.c export_.c extcgi_.c file_.c fileedit_.c finfo_.c foci_.c forum_.c fshell_.c fusefs_.c fuzz_.c glob_.c graph_.c gzip_.c hname_.c hook_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c interwiki_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c match_.c md5_.c merge_.c merge3_.c moderate_.c name_.c patch_.c path_.c piechart_.c pikchrshow_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c repolist_.c report_.c rss_.c schema_.c search_.c security_audit_.c setup_.c setupuser_.c sha1_.c sha1hard_.c sha3_.c shun_.c sitemap_.c skins_.c smtp_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c terminal_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c unversioned_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c xfer_.c xfersetup_.c zip_.c
38
39
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -26,13 +26,13 @@
26 CFLAGS = -o
27 BCC = $(DMDIR)\bin\dmc $(CFLAGS)
28 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
29 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 dnsapi
30
31 SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP
32
33 SHELL_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP -Dmain=sqlite3_shell -DSQLITE_SHELL_IS_UTF8=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=sqlcmd_get_dbname -DSQLITE_SHELL_INIT_PROC=sqlcmd_init_proc -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
34
35 PIKCHR_OPTIONS = -DPIKCHR_TOKEN_LIMIT=10000
36
37 SRC = add_.c ajax_.c alerts_.c allrepo_.c attach_.c backlink_.c backoffice_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.c capabilities_.c captcha_.c cgi_.c chat_.c checkin_.c checkout_.c clearsign_.c clone_.c color_.c comformat_.c configure_.c content_.c cookies_.c db_.c delta_.c deltacmd_.c deltafunc_.c descendants_.c diff_.c diffcmd_.c dispatch_.c doc_.c encode_.c etag_.c event_.c export_.c extcgi_.c file_.c fileedit_.c finfo_.c foci_.c forum_.c fshell_.c fusefs_.c fuzz_.c glob_.c graph_.c gzip_.c hname_.c hook_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c interwiki_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c match_.c md5_.c merge_.c merge3_.c moderate_.c name_.c patch_.c path_.c piechart_.c pikchrshow_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c repolist_.c report_.c rss_.c schema_.c search_.c security_audit_.c setup_.c setupuser_.c sha1_.c sha1hard_.c sha3_.c shun_.c sitemap_.c skins_.c smtp_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c terminal_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c unversioned_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c xfer_.c xfersetup_.c zip_.c
38
39
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -2528,14 +2528,15 @@
25282528
-DSQLITE_OMIT_SHARED_CACHE \
25292529
-DSQLITE_OMIT_LOAD_EXTENSION \
25302530
-DSQLITE_MAX_EXPR_DEPTH=0 \
25312531
-DSQLITE_ENABLE_LOCKING_STYLE=0 \
25322532
-DSQLITE_DEFAULT_FILE_FORMAT=4 \
2533
+ -DSQLITE_ENABLE_DBSTAT_VTAB \
25332534
-DSQLITE_ENABLE_EXPLAIN_COMMENTS \
25342535
-DSQLITE_ENABLE_FTS4 \
2535
- -DSQLITE_ENABLE_DBSTAT_VTAB \
25362536
-DSQLITE_ENABLE_FTS5 \
2537
+ -DSQLITE_ENABLE_MATH_FUNCTIONS \
25372538
-DSQLITE_ENABLE_STMTVTAB \
25382539
-DSQLITE_HAVE_ZLIB \
25392540
-DSQLITE_ENABLE_DBPAGE_VTAB \
25402541
-DSQLITE_TRUSTED_SCHEMA=0 \
25412542
-DHAVE_USLEEP \
@@ -2556,14 +2557,15 @@
25562557
-DSQLITE_OMIT_SHARED_CACHE \
25572558
-DSQLITE_OMIT_LOAD_EXTENSION \
25582559
-DSQLITE_MAX_EXPR_DEPTH=0 \
25592560
-DSQLITE_ENABLE_LOCKING_STYLE=0 \
25602561
-DSQLITE_DEFAULT_FILE_FORMAT=4 \
2562
+ -DSQLITE_ENABLE_DBSTAT_VTAB \
25612563
-DSQLITE_ENABLE_EXPLAIN_COMMENTS \
25622564
-DSQLITE_ENABLE_FTS4 \
2563
- -DSQLITE_ENABLE_DBSTAT_VTAB \
25642565
-DSQLITE_ENABLE_FTS5 \
2566
+ -DSQLITE_ENABLE_MATH_FUNCTIONS \
25652567
-DSQLITE_ENABLE_STMTVTAB \
25662568
-DSQLITE_HAVE_ZLIB \
25672569
-DSQLITE_ENABLE_DBPAGE_VTAB \
25682570
-DSQLITE_TRUSTED_SCHEMA=0 \
25692571
-DHAVE_USLEEP \
25702572
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -2528,14 +2528,15 @@
2528 -DSQLITE_OMIT_SHARED_CACHE \
2529 -DSQLITE_OMIT_LOAD_EXTENSION \
2530 -DSQLITE_MAX_EXPR_DEPTH=0 \
2531 -DSQLITE_ENABLE_LOCKING_STYLE=0 \
2532 -DSQLITE_DEFAULT_FILE_FORMAT=4 \
 
2533 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
2534 -DSQLITE_ENABLE_FTS4 \
2535 -DSQLITE_ENABLE_DBSTAT_VTAB \
2536 -DSQLITE_ENABLE_FTS5 \
 
2537 -DSQLITE_ENABLE_STMTVTAB \
2538 -DSQLITE_HAVE_ZLIB \
2539 -DSQLITE_ENABLE_DBPAGE_VTAB \
2540 -DSQLITE_TRUSTED_SCHEMA=0 \
2541 -DHAVE_USLEEP \
@@ -2556,14 +2557,15 @@
2556 -DSQLITE_OMIT_SHARED_CACHE \
2557 -DSQLITE_OMIT_LOAD_EXTENSION \
2558 -DSQLITE_MAX_EXPR_DEPTH=0 \
2559 -DSQLITE_ENABLE_LOCKING_STYLE=0 \
2560 -DSQLITE_DEFAULT_FILE_FORMAT=4 \
 
2561 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
2562 -DSQLITE_ENABLE_FTS4 \
2563 -DSQLITE_ENABLE_DBSTAT_VTAB \
2564 -DSQLITE_ENABLE_FTS5 \
 
2565 -DSQLITE_ENABLE_STMTVTAB \
2566 -DSQLITE_HAVE_ZLIB \
2567 -DSQLITE_ENABLE_DBPAGE_VTAB \
2568 -DSQLITE_TRUSTED_SCHEMA=0 \
2569 -DHAVE_USLEEP \
2570
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -2528,14 +2528,15 @@
2528 -DSQLITE_OMIT_SHARED_CACHE \
2529 -DSQLITE_OMIT_LOAD_EXTENSION \
2530 -DSQLITE_MAX_EXPR_DEPTH=0 \
2531 -DSQLITE_ENABLE_LOCKING_STYLE=0 \
2532 -DSQLITE_DEFAULT_FILE_FORMAT=4 \
2533 -DSQLITE_ENABLE_DBSTAT_VTAB \
2534 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
2535 -DSQLITE_ENABLE_FTS4 \
 
2536 -DSQLITE_ENABLE_FTS5 \
2537 -DSQLITE_ENABLE_MATH_FUNCTIONS \
2538 -DSQLITE_ENABLE_STMTVTAB \
2539 -DSQLITE_HAVE_ZLIB \
2540 -DSQLITE_ENABLE_DBPAGE_VTAB \
2541 -DSQLITE_TRUSTED_SCHEMA=0 \
2542 -DHAVE_USLEEP \
@@ -2556,14 +2557,15 @@
2557 -DSQLITE_OMIT_SHARED_CACHE \
2558 -DSQLITE_OMIT_LOAD_EXTENSION \
2559 -DSQLITE_MAX_EXPR_DEPTH=0 \
2560 -DSQLITE_ENABLE_LOCKING_STYLE=0 \
2561 -DSQLITE_DEFAULT_FILE_FORMAT=4 \
2562 -DSQLITE_ENABLE_DBSTAT_VTAB \
2563 -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
2564 -DSQLITE_ENABLE_FTS4 \
 
2565 -DSQLITE_ENABLE_FTS5 \
2566 -DSQLITE_ENABLE_MATH_FUNCTIONS \
2567 -DSQLITE_ENABLE_STMTVTAB \
2568 -DSQLITE_HAVE_ZLIB \
2569 -DSQLITE_ENABLE_DBPAGE_VTAB \
2570 -DSQLITE_TRUSTED_SCHEMA=0 \
2571 -DHAVE_USLEEP \
2572
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -311,14 +311,15 @@
311311
/DSQLITE_OMIT_SHARED_CACHE \
312312
/DSQLITE_OMIT_LOAD_EXTENSION \
313313
/DSQLITE_MAX_EXPR_DEPTH=0 \
314314
/DSQLITE_ENABLE_LOCKING_STYLE=0 \
315315
/DSQLITE_DEFAULT_FILE_FORMAT=4 \
316
+ /DSQLITE_ENABLE_DBSTAT_VTAB \
316317
/DSQLITE_ENABLE_EXPLAIN_COMMENTS \
317318
/DSQLITE_ENABLE_FTS4 \
318
- /DSQLITE_ENABLE_DBSTAT_VTAB \
319319
/DSQLITE_ENABLE_FTS5 \
320
+ /DSQLITE_ENABLE_MATH_FUNCTIONS \
320321
/DSQLITE_ENABLE_STMTVTAB \
321322
/DSQLITE_HAVE_ZLIB \
322323
/DSQLITE_ENABLE_DBPAGE_VTAB \
323324
/DSQLITE_TRUSTED_SCHEMA=0 \
324325
/DHAVE_USLEEP \
@@ -336,14 +337,15 @@
336337
/DSQLITE_OMIT_SHARED_CACHE \
337338
/DSQLITE_OMIT_LOAD_EXTENSION \
338339
/DSQLITE_MAX_EXPR_DEPTH=0 \
339340
/DSQLITE_ENABLE_LOCKING_STYLE=0 \
340341
/DSQLITE_DEFAULT_FILE_FORMAT=4 \
342
+ /DSQLITE_ENABLE_DBSTAT_VTAB \
341343
/DSQLITE_ENABLE_EXPLAIN_COMMENTS \
342344
/DSQLITE_ENABLE_FTS4 \
343
- /DSQLITE_ENABLE_DBSTAT_VTAB \
344345
/DSQLITE_ENABLE_FTS5 \
346
+ /DSQLITE_ENABLE_MATH_FUNCTIONS \
345347
/DSQLITE_ENABLE_STMTVTAB \
346348
/DSQLITE_HAVE_ZLIB \
347349
/DSQLITE_ENABLE_DBPAGE_VTAB \
348350
/DSQLITE_TRUSTED_SCHEMA=0 \
349351
/DHAVE_USLEEP \
350352
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -311,14 +311,15 @@
311 /DSQLITE_OMIT_SHARED_CACHE \
312 /DSQLITE_OMIT_LOAD_EXTENSION \
313 /DSQLITE_MAX_EXPR_DEPTH=0 \
314 /DSQLITE_ENABLE_LOCKING_STYLE=0 \
315 /DSQLITE_DEFAULT_FILE_FORMAT=4 \
 
316 /DSQLITE_ENABLE_EXPLAIN_COMMENTS \
317 /DSQLITE_ENABLE_FTS4 \
318 /DSQLITE_ENABLE_DBSTAT_VTAB \
319 /DSQLITE_ENABLE_FTS5 \
 
320 /DSQLITE_ENABLE_STMTVTAB \
321 /DSQLITE_HAVE_ZLIB \
322 /DSQLITE_ENABLE_DBPAGE_VTAB \
323 /DSQLITE_TRUSTED_SCHEMA=0 \
324 /DHAVE_USLEEP \
@@ -336,14 +337,15 @@
336 /DSQLITE_OMIT_SHARED_CACHE \
337 /DSQLITE_OMIT_LOAD_EXTENSION \
338 /DSQLITE_MAX_EXPR_DEPTH=0 \
339 /DSQLITE_ENABLE_LOCKING_STYLE=0 \
340 /DSQLITE_DEFAULT_FILE_FORMAT=4 \
 
341 /DSQLITE_ENABLE_EXPLAIN_COMMENTS \
342 /DSQLITE_ENABLE_FTS4 \
343 /DSQLITE_ENABLE_DBSTAT_VTAB \
344 /DSQLITE_ENABLE_FTS5 \
 
345 /DSQLITE_ENABLE_STMTVTAB \
346 /DSQLITE_HAVE_ZLIB \
347 /DSQLITE_ENABLE_DBPAGE_VTAB \
348 /DSQLITE_TRUSTED_SCHEMA=0 \
349 /DHAVE_USLEEP \
350
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -311,14 +311,15 @@
311 /DSQLITE_OMIT_SHARED_CACHE \
312 /DSQLITE_OMIT_LOAD_EXTENSION \
313 /DSQLITE_MAX_EXPR_DEPTH=0 \
314 /DSQLITE_ENABLE_LOCKING_STYLE=0 \
315 /DSQLITE_DEFAULT_FILE_FORMAT=4 \
316 /DSQLITE_ENABLE_DBSTAT_VTAB \
317 /DSQLITE_ENABLE_EXPLAIN_COMMENTS \
318 /DSQLITE_ENABLE_FTS4 \
 
319 /DSQLITE_ENABLE_FTS5 \
320 /DSQLITE_ENABLE_MATH_FUNCTIONS \
321 /DSQLITE_ENABLE_STMTVTAB \
322 /DSQLITE_HAVE_ZLIB \
323 /DSQLITE_ENABLE_DBPAGE_VTAB \
324 /DSQLITE_TRUSTED_SCHEMA=0 \
325 /DHAVE_USLEEP \
@@ -336,14 +337,15 @@
337 /DSQLITE_OMIT_SHARED_CACHE \
338 /DSQLITE_OMIT_LOAD_EXTENSION \
339 /DSQLITE_MAX_EXPR_DEPTH=0 \
340 /DSQLITE_ENABLE_LOCKING_STYLE=0 \
341 /DSQLITE_DEFAULT_FILE_FORMAT=4 \
342 /DSQLITE_ENABLE_DBSTAT_VTAB \
343 /DSQLITE_ENABLE_EXPLAIN_COMMENTS \
344 /DSQLITE_ENABLE_FTS4 \
 
345 /DSQLITE_ENABLE_FTS5 \
346 /DSQLITE_ENABLE_MATH_FUNCTIONS \
347 /DSQLITE_ENABLE_STMTVTAB \
348 /DSQLITE_HAVE_ZLIB \
349 /DSQLITE_ENABLE_DBPAGE_VTAB \
350 /DSQLITE_TRUSTED_SCHEMA=0 \
351 /DHAVE_USLEEP \
352

Keyboard Shortcuts

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