Fossil SCM

Update the built-in SQLite to the 3.8.11 alpha that includes the pcache1 preallocation enhancement.

drh 2015-07-08 16:25 trunk
Commit 8fb4269a3180e374744ab0dd219b49a0a46f6016
2 files changed +233 -92 +4 -1
+233 -92
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -325,11 +325,11 @@
325325
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
326326
** [sqlite_version()] and [sqlite_source_id()].
327327
*/
328328
#define SQLITE_VERSION "3.8.11"
329329
#define SQLITE_VERSION_NUMBER 3008011
330
-#define SQLITE_SOURCE_ID "2015-07-03 17:54:49 030f60a7ba171650ce8c0ac32dc166eab80aca32"
330
+#define SQLITE_SOURCE_ID "2015-07-08 16:22:42 5348ffc3fda5168c1e9e14aa88b0c6aedbda7c94"
331331
332332
/*
333333
** CAPI3REF: Run-Time Library Version Numbers
334334
** KEYWORDS: sqlite3_version, sqlite3_sourceid
335335
**
@@ -6503,10 +6503,13 @@
65036503
#define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
65046504
#define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
65056505
#define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */
65066506
#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
65076507
#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6508
+#define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */
6509
+#define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */
6510
+#define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */
65086511
65096512
/*
65106513
** CAPI3REF: Retrieve the mutex for a database connection
65116514
** METHOD: sqlite3
65126515
**
@@ -8941,10 +8944,20 @@
89418944
#if SQLITE_DEFAULT_WORKER_THREADS>SQLITE_MAX_WORKER_THREADS
89428945
# undef SQLITE_MAX_WORKER_THREADS
89438946
# define SQLITE_MAX_WORKER_THREADS SQLITE_DEFAULT_WORKER_THREADS
89448947
#endif
89458948
8949
+/*
8950
+** The default initial allocation for the pagecache when using separate
8951
+** pagecaches for each database connection. A positive number is the
8952
+** number of pages. A negative number N translations means that a buffer
8953
+** of -1024*N bytes is allocated and used for as many pages as it will hold.
8954
+*/
8955
+#ifndef SQLITE_DEFAULT_PCACHE_INITSZ
8956
+# define SQLITE_DEFAULT_PCACHE_INITSZ 100
8957
+#endif
8958
+
89468959
89478960
/*
89488961
** GCC does not define the offsetof() macro so we'll have to do it
89498962
** ourselves.
89508963
*/
@@ -14043,11 +14056,11 @@
1404314056
(void*)0, /* pScratch */
1404414057
0, /* szScratch */
1404514058
0, /* nScratch */
1404614059
(void*)0, /* pPage */
1404714060
0, /* szPage */
14048
- 0, /* nPage */
14061
+ SQLITE_DEFAULT_PCACHE_INITSZ, /* nPage */
1404914062
0, /* mxParserStack */
1405014063
0, /* sharedCacheEnabled */
1405114064
SQLITE_SORTER_PMASZ, /* szPma */
1405214065
/* All the rest should always be initialized to zero */
1405314066
0, /* isInit */
@@ -19454,11 +19467,11 @@
1945419467
** The sqlite3_mutex_alloc() routine allocates a new
1945519468
** mutex and returns a pointer to it. If it returns NULL
1945619469
** that means that a mutex could not be allocated.
1945719470
*/
1945819471
static sqlite3_mutex *debugMutexAlloc(int id){
19459
- static sqlite3_debug_mutex aStatic[SQLITE_MUTEX_STATIC_APP3 - 1];
19472
+ static sqlite3_debug_mutex aStatic[SQLITE_MUTEX_STATIC_VFS3 - 1];
1946019473
sqlite3_debug_mutex *pNew = 0;
1946119474
switch( id ){
1946219475
case SQLITE_MUTEX_FAST:
1946319476
case SQLITE_MUTEX_RECURSIVE: {
1946419477
pNew = sqlite3Malloc(sizeof(*pNew));
@@ -19669,10 +19682,13 @@
1966919682
** <li> SQLITE_MUTEX_STATIC_LRU
1967019683
** <li> SQLITE_MUTEX_STATIC_PMEM
1967119684
** <li> SQLITE_MUTEX_STATIC_APP1
1967219685
** <li> SQLITE_MUTEX_STATIC_APP2
1967319686
** <li> SQLITE_MUTEX_STATIC_APP3
19687
+** <li> SQLITE_MUTEX_STATIC_VFS1
19688
+** <li> SQLITE_MUTEX_STATIC_VFS2
19689
+** <li> SQLITE_MUTEX_STATIC_VFS3
1967419690
** </ul>
1967519691
**
1967619692
** The first two constants cause sqlite3_mutex_alloc() to create
1967719693
** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
1967819694
** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
@@ -19697,10 +19713,13 @@
1969719713
** mutex types, the same mutex is returned on every call that has
1969819714
** the same type number.
1969919715
*/
1970019716
static sqlite3_mutex *pthreadMutexAlloc(int iType){
1970119717
static sqlite3_mutex staticMutexes[] = {
19718
+ SQLITE3_MUTEX_INITIALIZER,
19719
+ SQLITE3_MUTEX_INITIALIZER,
19720
+ SQLITE3_MUTEX_INITIALIZER,
1970219721
SQLITE3_MUTEX_INITIALIZER,
1970319722
SQLITE3_MUTEX_INITIALIZER,
1970419723
SQLITE3_MUTEX_INITIALIZER,
1970519724
SQLITE3_MUTEX_INITIALIZER,
1970619725
SQLITE3_MUTEX_INITIALIZER,
@@ -20311,10 +20330,13 @@
2031120330
SQLITE3_MUTEX_INITIALIZER,
2031220331
SQLITE3_MUTEX_INITIALIZER,
2031320332
SQLITE3_MUTEX_INITIALIZER,
2031420333
SQLITE3_MUTEX_INITIALIZER,
2031520334
SQLITE3_MUTEX_INITIALIZER,
20335
+ SQLITE3_MUTEX_INITIALIZER,
20336
+ SQLITE3_MUTEX_INITIALIZER,
20337
+ SQLITE3_MUTEX_INITIALIZER,
2031620338
SQLITE3_MUTEX_INITIALIZER
2031720339
};
2031820340
2031920341
static int winMutex_isInit = 0;
2032020342
static int winMutex_isNt = -1; /* <0 means "need to query" */
@@ -20382,10 +20404,13 @@
2038220404
** <li> SQLITE_MUTEX_STATIC_LRU
2038320405
** <li> SQLITE_MUTEX_STATIC_PMEM
2038420406
** <li> SQLITE_MUTEX_STATIC_APP1
2038520407
** <li> SQLITE_MUTEX_STATIC_APP2
2038620408
** <li> SQLITE_MUTEX_STATIC_APP3
20409
+** <li> SQLITE_MUTEX_STATIC_VFS1
20410
+** <li> SQLITE_MUTEX_STATIC_VFS2
20411
+** <li> SQLITE_MUTEX_STATIC_VFS3
2038720412
** </ul>
2038820413
**
2038920414
** The first two constants cause sqlite3_mutex_alloc() to create
2039020415
** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
2039120416
** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
@@ -20793,14 +20818,13 @@
2079320818
sqlite3GlobalConfig.pScratch = 0;
2079420819
sqlite3GlobalConfig.szScratch = 0;
2079520820
sqlite3GlobalConfig.nScratch = 0;
2079620821
}
2079720822
if( sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.szPage<512
20798
- || sqlite3GlobalConfig.nPage<1 ){
20823
+ || sqlite3GlobalConfig.nPage<=0 ){
2079920824
sqlite3GlobalConfig.pPage = 0;
2080020825
sqlite3GlobalConfig.szPage = 0;
20801
- sqlite3GlobalConfig.nPage = 0;
2080220826
}
2080320827
rc = sqlite3GlobalConfig.m.xInit(sqlite3GlobalConfig.m.pAppData);
2080420828
if( rc!=SQLITE_OK ) memset(&mem0, 0, sizeof(mem0));
2080520829
return rc;
2080620830
}
@@ -26522,18 +26546,18 @@
2652226546
** unixEnterMutex()
2652326547
** assert( unixMutexHeld() );
2652426548
** unixEnterLeave()
2652526549
*/
2652626550
static void unixEnterMutex(void){
26527
- sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
26551
+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1));
2652826552
}
2652926553
static void unixLeaveMutex(void){
26530
- sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
26554
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1));
2653126555
}
2653226556
#ifdef SQLITE_DEBUG
2653326557
static int unixMutexHeld(void) {
26534
- return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
26558
+ return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1));
2653526559
}
2653626560
#endif
2653726561
2653826562
2653926563
#ifdef SQLITE_HAVE_OS_TRACE
@@ -37047,18 +37071,18 @@
3704737071
** winShmEnterMutex()
3704837072
** assert( winShmMutexHeld() );
3704937073
** winShmLeaveMutex()
3705037074
*/
3705137075
static void winShmEnterMutex(void){
37052
- sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
37076
+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1));
3705337077
}
3705437078
static void winShmLeaveMutex(void){
37055
- sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
37079
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1));
3705637080
}
3705737081
#ifndef NDEBUG
3705837082
static int winShmMutexHeld(void) {
37059
- return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
37083
+ return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1));
3706037084
}
3706137085
#endif
3706237086
3706337087
/*
3706437088
** Object used to represent a single file opened and mmapped to provide
@@ -40399,12 +40423,75 @@
4039940423
** This file implements the default page cache implementation (the
4040040424
** sqlite3_pcache interface). It also contains part of the implementation
4040140425
** of the SQLITE_CONFIG_PAGECACHE and sqlite3_release_memory() features.
4040240426
** If the default page cache implementation is overridden, then neither of
4040340427
** these two features are available.
40428
+**
40429
+** A Page cache line looks like this:
40430
+**
40431
+** -------------------------------------------------------------
40432
+** | database page content | PgHdr1 | MemPage | PgHdr |
40433
+** -------------------------------------------------------------
40434
+**
40435
+** The database page content is up front (so that buffer overreads tend to
40436
+** flow harmlessly into the PgHdr1, MemPage, and PgHdr extensions). MemPage
40437
+** is the extension added by the btree.c module containing information such
40438
+** as the database page number and how that database page is used. PgHdr
40439
+** is added by the pcache.c layer and contains information used to keep track
40440
+** of which pages are "dirty". PgHdr1 is an extension added by this
40441
+** module (pcache1.c). The PgHdr1 header is a subclass of sqlite3_pcache_page.
40442
+** PgHdr1 contains information needed to look up a page by its page number.
40443
+** The superclass sqlite3_pcache_page.pBuf points to the start of the
40444
+** database page content and sqlite3_pcache_page.pExtra points to PgHdr.
40445
+**
40446
+** The size of the extension (MemPage+PgHdr+PgHdr1) can be determined at
40447
+** runtime using sqlite3_config(SQLITE_CONFIG_PCACHE_HDRSZ, &size). The
40448
+** sizes of the extensions sum to 272 bytes on x64 for 3.8.10, but this
40449
+** size can vary according to architecture, compile-time options, and
40450
+** SQLite library version number.
40451
+**
40452
+** If SQLITE_PCACHE_SEPARATE_HEADER is defined, then the extension is obtained
40453
+** using a separate memory allocation from the database page content. This
40454
+** seeks to overcome the "clownshoe" problem (also called "internal
40455
+** fragmentation" in academic literature) of allocating a few bytes more
40456
+** than a power of two with the memory allocator rounding up to the next
40457
+** power of two, and leaving the rounded-up space unused.
40458
+**
40459
+** This module tracks pointers to PgHdr1 objects. Only pcache.c communicates
40460
+** with this module. Information is passed back and forth as PgHdr1 pointers.
40461
+**
40462
+** The pcache.c and pager.c modules deal pointers to PgHdr objects.
40463
+** The btree.c module deals with pointers to MemPage objects.
40464
+**
40465
+** SOURCE OF PAGE CACHE MEMORY:
40466
+**
40467
+** Memory for a page might come from any of three sources:
40468
+**
40469
+** (1) The general-purpose memory allocator - sqlite3Malloc()
40470
+** (2) Global page-cache memory provided using sqlite3_config() with
40471
+** SQLITE_CONFIG_PAGECACHE.
40472
+** (3) PCache-local bulk allocation.
40473
+**
40474
+** The third case is a chunk of heap memory (defaulting to 100 pages worth)
40475
+** that is allocated when the page cache is created. The size of the local
40476
+** bulk allocation can be adjusted using
40477
+**
40478
+** sqlite3_config(SQLITE_CONFIG_PCACHE, 0, 0, N).
40479
+**
40480
+** If N is positive, then N pages worth of memory are allocated using a single
40481
+** sqlite3Malloc() call and that memory is used for the first N pages allocated.
40482
+** Or if N is negative, then -1024*N bytes of memory are allocated and used
40483
+** for as many pages as can be accomodated.
40484
+**
40485
+** Only one of (2) or (3) can be used. Once the memory available to (2) or
40486
+** (3) is exhausted, subsequent allocations fail over to the general-purpose
40487
+** memory allocator (1).
40488
+**
40489
+** Earlier versions of SQLite used only methods (1) and (2). But experiments
40490
+** show that method (3) with N==100 provides about a 5% performance boost for
40491
+** common workloads.
4040440492
*/
40405
-
4040640493
4040740494
typedef struct PCache1 PCache1;
4040840495
typedef struct PgHdr1 PgHdr1;
4040940496
typedef struct PgFreeslot PgFreeslot;
4041040497
typedef struct PGroup PGroup;
@@ -40453,12 +40540,13 @@
4045340540
** flag (bPurgeable) are set when the cache is created. nMax may be
4045440541
** modified at any time by a call to the pcache1Cachesize() method.
4045540542
** The PGroup mutex must be held when accessing nMax.
4045640543
*/
4045740544
PGroup *pGroup; /* PGroup this cache belongs to */
40458
- int szPage; /* Size of allocated pages in bytes */
40459
- int szExtra; /* Size of extra space in bytes */
40545
+ int szPage; /* Size of database content section */
40546
+ int szExtra; /* sizeof(MemPage)+sizeof(PgHdr) */
40547
+ int szAlloc; /* Total size of one pcache line */
4046040548
int bPurgeable; /* True if cache is purgeable */
4046140549
unsigned int nMin; /* Minimum number of pages reserved */
4046240550
unsigned int nMax; /* Configured "cache_size" value */
4046340551
unsigned int n90pct; /* nMax*9/10 */
4046440552
unsigned int iMaxKey; /* Largest key seen since xTruncate() */
@@ -40468,10 +40556,12 @@
4046840556
*/
4046940557
unsigned int nRecyclable; /* Number of pages in the LRU list */
4047040558
unsigned int nPage; /* Total number of pages in apHash */
4047140559
unsigned int nHash; /* Number of slots in apHash[] */
4047240560
PgHdr1 **apHash; /* Hash table for fast lookup by key */
40561
+ PgHdr1 *pFree; /* List of unused pcache-local pages */
40562
+ void *pBulk; /* Bulk memory used by pcache-local */
4047340563
};
4047440564
4047540565
/*
4047640566
** Each cache entry is represented by an instance of the following
4047740567
** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
@@ -40480,19 +40570,20 @@
4048040570
*/
4048140571
struct PgHdr1 {
4048240572
sqlite3_pcache_page page;
4048340573
unsigned int iKey; /* Key value (page number) */
4048440574
u8 isPinned; /* Page in use, not on the LRU list */
40575
+ u8 isBulkLocal; /* This page from bulk local storage */
4048540576
PgHdr1 *pNext; /* Next in hash table chain */
4048640577
PCache1 *pCache; /* Cache that currently owns this page */
4048740578
PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
4048840579
PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
4048940580
};
4049040581
4049140582
/*
40492
-** Free slots in the allocator used to divide up the buffer provided using
40493
-** the SQLITE_CONFIG_PAGECACHE mechanism.
40583
+** Free slots in the allocator used to divide up the global page cache
40584
+** buffer provided using the SQLITE_CONFIG_PAGECACHE mechanism.
4049440585
*/
4049540586
struct PgFreeslot {
4049640587
PgFreeslot *pNext; /* Next free slot */
4049740588
};
4049840589
@@ -40506,14 +40597,15 @@
4050640597
** szSlot, nSlot, pStart, pEnd, nReserve, and isInit values are all
4050740598
** fixed at sqlite3_initialize() time and do not require mutex protection.
4050840599
** The nFreeSlot and pFree values do require mutex protection.
4050940600
*/
4051040601
int isInit; /* True if initialized */
40602
+ int separateCache; /* Use a new PGroup for each PCache */
4051140603
int szSlot; /* Size of each free slot */
4051240604
int nSlot; /* The number of pcache slots */
4051340605
int nReserve; /* Try to keep nFreeSlot above this */
40514
- void *pStart, *pEnd; /* Bounds of pagecache malloc range */
40606
+ void *pStart, *pEnd; /* Bounds of global page cache memory */
4051540607
/* Above requires no mutex. Use mutex below for variable that follow. */
4051640608
sqlite3_mutex *mutex; /* Mutex for accessing the following: */
4051740609
PgFreeslot *pFree; /* Free page blocks */
4051840610
int nFreeSlot; /* Number of unused pcache slots */
4051940611
/* The following value requires a mutex to change. We skip the mutex on
@@ -40556,10 +40648,11 @@
4055640648
** to be serialized already. There is no need for further mutexing.
4055740649
*/
4055840650
SQLITE_PRIVATE void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){
4055940651
if( pcache1.isInit ){
4056040652
PgFreeslot *p;
40653
+ if( pBuf==0 ) sz = n = 0;
4056140654
sz = ROUNDDOWN8(sz);
4056240655
pcache1.szSlot = sz;
4056340656
pcache1.nSlot = pcache1.nFreeSlot = n;
4056440657
pcache1.nReserve = n>90 ? 10 : (n/10 + 1);
4056540658
pcache1.pStart = pBuf;
@@ -40620,13 +40713,13 @@
4062040713
}
4062140714
4062240715
/*
4062340716
** Free an allocated buffer obtained from pcache1Alloc().
4062440717
*/
40625
-static int pcache1Free(void *p){
40718
+static void pcache1Free(void *p){
4062640719
int nFreed = 0;
40627
- if( p==0 ) return 0;
40720
+ if( p==0 ) return;
4062840721
if( p>=pcache1.pStart && p<pcache1.pEnd ){
4062940722
PgFreeslot *pSlot;
4063040723
sqlite3_mutex_enter(pcache1.mutex);
4063140724
sqlite3StatusDown(SQLITE_STATUS_PAGECACHE_USED, 1);
4063240725
pSlot = (PgFreeslot*)p;
@@ -40637,19 +40730,18 @@
4063740730
assert( pcache1.nFreeSlot<=pcache1.nSlot );
4063840731
sqlite3_mutex_leave(pcache1.mutex);
4063940732
}else{
4064040733
assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
4064140734
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
40642
- nFreed = sqlite3MallocSize(p);
4064340735
#ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
40736
+ nFreed = sqlite3MallocSize(p);
4064440737
sqlite3_mutex_enter(pcache1.mutex);
4064540738
sqlite3StatusDown(SQLITE_STATUS_PAGECACHE_OVERFLOW, nFreed);
4064640739
sqlite3_mutex_leave(pcache1.mutex);
4064740740
#endif
4064840741
sqlite3_free(p);
4064940742
}
40650
- return nFreed;
4065140743
}
4065240744
4065340745
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
4065440746
/*
4065540747
** Return the size of a pcache allocation
@@ -40673,58 +40765,69 @@
4067340765
*/
4067440766
static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
4067540767
PgHdr1 *p = 0;
4067640768
void *pPg;
4067740769
40678
- /* The group mutex must be released before pcache1Alloc() is called. This
40679
- ** is because it may call sqlite3_release_memory(), which assumes that
40680
- ** this mutex is not held. */
4068140770
assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
40682
- pcache1LeaveMutex(pCache->pGroup);
40771
+ if( pCache->pFree ){
40772
+ p = pCache->pFree;
40773
+ pCache->pFree = p->pNext;
40774
+ p->pNext = 0;
40775
+ }else{
40776
+#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40777
+ /* The group mutex must be released before pcache1Alloc() is called. This
40778
+ ** is because it might call sqlite3_release_memory(), which assumes that
40779
+ ** this mutex is not held. */
40780
+ assert( pcache1.separateCache==0 );
40781
+ assert( pCache->pGroup==&pcache1.grp );
40782
+ pcache1LeaveMutex(pCache->pGroup);
40783
+#endif
4068340784
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
40684
- pPg = pcache1Alloc(pCache->szPage);
40685
- p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
40686
- if( !pPg || !p ){
40687
- pcache1Free(pPg);
40688
- sqlite3_free(p);
40689
- pPg = 0;
40690
- }
40785
+ pPg = pcache1Alloc(pCache->szPage);
40786
+ p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
40787
+ if( !pPg || !p ){
40788
+ pcache1Free(pPg);
40789
+ sqlite3_free(p);
40790
+ pPg = 0;
40791
+ }
4069140792
#else
40692
- pPg = pcache1Alloc(ROUND8(sizeof(PgHdr1)) + pCache->szPage + pCache->szExtra);
40693
- p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
40793
+ pPg = pcache1Alloc(pCache->szAlloc);
40794
+ p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
4069440795
#endif
40695
- pcache1EnterMutex(pCache->pGroup);
40696
-
40697
- if( pPg ){
40796
+#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40797
+ pcache1EnterMutex(pCache->pGroup);
40798
+#endif
40799
+ if( pPg==0 ) return 0;
4069840800
p->page.pBuf = pPg;
4069940801
p->page.pExtra = &p[1];
40700
- if( pCache->bPurgeable ){
40701
- pCache->pGroup->nCurrentPage++;
40702
- }
40703
- return p;
40802
+ p->isBulkLocal = 0;
4070440803
}
40705
- return 0;
40804
+ if( pCache->bPurgeable ){
40805
+ pCache->pGroup->nCurrentPage++;
40806
+ }
40807
+ return p;
4070640808
}
4070740809
4070840810
/*
4070940811
** Free a page object allocated by pcache1AllocPage().
40710
-**
40711
-** The pointer is allowed to be NULL, which is prudent. But it turns out
40712
-** that the current implementation happens to never call this routine
40713
-** with a NULL pointer, so we mark the NULL test with ALWAYS().
4071440812
*/
4071540813
static void pcache1FreePage(PgHdr1 *p){
40716
- if( ALWAYS(p) ){
40717
- PCache1 *pCache = p->pCache;
40718
- assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
40814
+ PCache1 *pCache;
40815
+ assert( p!=0 );
40816
+ pCache = p->pCache;
40817
+ assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
40818
+ if( p->isBulkLocal ){
40819
+ p->pNext = pCache->pFree;
40820
+ pCache->pFree = p;
40821
+ }else{
4071940822
pcache1Free(p->page.pBuf);
4072040823
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
4072140824
sqlite3_free(p);
4072240825
#endif
40723
- if( pCache->bPurgeable ){
40724
- pCache->pGroup->nCurrentPage--;
40725
- }
40826
+ }
40827
+ if( pCache->bPurgeable ){
40828
+ pCache->pGroup->nCurrentPage--;
4072640829
}
4072740830
}
4072840831
4072940832
/*
4073040833
** Malloc function used by SQLite to obtain space from the buffer configured
@@ -40920,10 +41023,35 @@
4092041023
*/
4092141024
static int pcache1Init(void *NotUsed){
4092241025
UNUSED_PARAMETER(NotUsed);
4092341026
assert( pcache1.isInit==0 );
4092441027
memset(&pcache1, 0, sizeof(pcache1));
41028
+
41029
+
41030
+ /*
41031
+ ** The pcache1.separateCache variable is true if each PCache has its own
41032
+ ** private PGroup (mode-1). pcache1.separateCache is false if the single
41033
+ ** PGroup in pcache1.grp is used for all page caches (mode-2).
41034
+ **
41035
+ ** * Always use a unified cache (mode-2) if ENABLE_MEMORY_MANAGEMENT
41036
+ **
41037
+ ** * Use a unified cache in single-threaded applications that have
41038
+ ** configured a start-time buffer for use as page-cache memory using
41039
+ ** sqlite3_config(SQLITE_CONFIG_PAGECACHE, pBuf, sz, N) with non-NULL
41040
+ ** pBuf argument.
41041
+ **
41042
+ ** * Otherwise use separate caches (mode-1)
41043
+ */
41044
+#if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT)
41045
+ pcache1.separateCache = 0;
41046
+#elif SQLITE_THREADSAFE
41047
+ pcache1.separateCache = sqlite3GlobalConfig.pPage==0
41048
+ || sqlite3GlobalConfig.bCoreMutex>0;
41049
+#else
41050
+ pcache1.separateCache = sqlite3GlobalConfig.pPage==0;
41051
+#endif
41052
+
4092541053
#if SQLITE_THREADSAFE
4092641054
if( sqlite3GlobalConfig.bCoreMutex ){
4092741055
pcache1.grp.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU);
4092841056
pcache1.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PMEM);
4092941057
}
@@ -40955,52 +41083,65 @@
4095541083
static sqlite3_pcache *pcache1Create(int szPage, int szExtra, int bPurgeable){
4095641084
PCache1 *pCache; /* The newly created page cache */
4095741085
PGroup *pGroup; /* The group the new page cache will belong to */
4095841086
int sz; /* Bytes of memory required to allocate the new cache */
4095941087
40960
- /*
40961
- ** The separateCache variable is true if each PCache has its own private
40962
- ** PGroup. In other words, separateCache is true for mode (1) where no
40963
- ** mutexing is required.
40964
- **
40965
- ** * Always use a unified cache (mode-2) if ENABLE_MEMORY_MANAGEMENT
40966
- **
40967
- ** * Always use a unified cache in single-threaded applications
40968
- **
40969
- ** * Otherwise (if multi-threaded and ENABLE_MEMORY_MANAGEMENT is off)
40970
- ** use separate caches (mode-1)
40971
- */
40972
-#if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) || SQLITE_THREADSAFE==0
40973
- const int separateCache = 0;
40974
-#else
40975
- int separateCache = sqlite3GlobalConfig.bCoreMutex>0;
40976
-#endif
40977
-
4097841088
assert( (szPage & (szPage-1))==0 && szPage>=512 && szPage<=65536 );
4097941089
assert( szExtra < 300 );
4098041090
40981
- sz = sizeof(PCache1) + sizeof(PGroup)*separateCache;
41091
+ sz = sizeof(PCache1) + sizeof(PGroup)*pcache1.separateCache;
4098241092
pCache = (PCache1 *)sqlite3MallocZero(sz);
4098341093
if( pCache ){
40984
- if( separateCache ){
41094
+ if( pcache1.separateCache ){
4098541095
pGroup = (PGroup*)&pCache[1];
4098641096
pGroup->mxPinned = 10;
4098741097
}else{
4098841098
pGroup = &pcache1.grp;
4098941099
}
4099041100
pCache->pGroup = pGroup;
4099141101
pCache->szPage = szPage;
4099241102
pCache->szExtra = szExtra;
41103
+ pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1));
4099341104
pCache->bPurgeable = (bPurgeable ? 1 : 0);
4099441105
pcache1EnterMutex(pGroup);
4099541106
pcache1ResizeHash(pCache);
4099641107
if( bPurgeable ){
4099741108
pCache->nMin = 10;
4099841109
pGroup->nMinPage += pCache->nMin;
4099941110
pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
4100041111
}
4100141112
pcache1LeaveMutex(pGroup);
41113
+ /* Try to initialize the local bulk pagecache line allocation if using
41114
+ ** separate caches and if nPage!=0 */
41115
+ if( pcache1.separateCache
41116
+ && sqlite3GlobalConfig.nPage!=0
41117
+ && sqlite3GlobalConfig.pPage==0
41118
+ ){
41119
+ int szBulk;
41120
+ char *zBulk;
41121
+ sqlite3BeginBenignMalloc();
41122
+ if( sqlite3GlobalConfig.nPage>0 ){
41123
+ szBulk = pCache->szAlloc * sqlite3GlobalConfig.nPage;
41124
+ }else{
41125
+ szBulk = -1024*sqlite3GlobalConfig.nPage;
41126
+ }
41127
+ zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
41128
+ sqlite3EndBenignMalloc();
41129
+ if( zBulk ){
41130
+ int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
41131
+ int i;
41132
+ for(i=0; i<nBulk; i++){
41133
+ PgHdr1 *pX = (PgHdr1*)&zBulk[szPage];
41134
+ pX->page.pBuf = zBulk;
41135
+ pX->page.pExtra = &pX[1];
41136
+ pX->isBulkLocal = 1;
41137
+ pX->pNext = pCache->pFree;
41138
+ pCache->pFree = pX;
41139
+ zBulk += pCache->szAlloc;
41140
+ }
41141
+ }
41142
+ }
4100241143
if( pCache->nHash==0 ){
4100341144
pcache1Destroy((sqlite3_pcache*)pCache);
4100441145
pCache = 0;
4100541146
}
4100641147
}
@@ -41090,30 +41231,21 @@
4109041231
4109141232
if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
4109241233
assert( pCache->nHash>0 && pCache->apHash );
4109341234
4109441235
/* Step 4. Try to recycle a page. */
41095
- if( pCache->bPurgeable && pGroup->pLruTail && (
41096
- (pCache->nPage+1>=pCache->nMax)
41097
- || pGroup->nCurrentPage>=pGroup->nMaxPage
41098
- || pcache1UnderMemoryPressure(pCache)
41099
- )){
41236
+ if( pCache->bPurgeable
41237
+ && pGroup->pLruTail
41238
+ && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
41239
+ ){
4110041240
PCache1 *pOther;
4110141241
pPage = pGroup->pLruTail;
4110241242
assert( pPage->isPinned==0 );
4110341243
pcache1RemoveFromHash(pPage, 0);
4110441244
pcache1PinPage(pPage);
4110541245
pOther = pPage->pCache;
41106
-
41107
- /* We want to verify that szPage and szExtra are the same for pOther
41108
- ** and pCache. Assert that we can verify this by comparing sums. */
41109
- assert( (pCache->szPage & (pCache->szPage-1))==0 && pCache->szPage>=512 );
41110
- assert( pCache->szExtra<512 );
41111
- assert( (pOther->szPage & (pOther->szPage-1))==0 && pOther->szPage>=512 );
41112
- assert( pOther->szExtra<512 );
41113
-
41114
- if( pOther->szPage+pOther->szExtra != pCache->szPage+pCache->szExtra ){
41246
+ if( pOther->szAlloc != pCache->szAlloc ){
4111541247
pcache1FreePage(pPage);
4111641248
pPage = 0;
4111741249
}else{
4111841250
pGroup->nCurrentPage -= (pOther->bPurgeable - pCache->bPurgeable);
4111941251
}
@@ -41385,10 +41517,11 @@
4138541517
assert( pGroup->nMinPage >= pCache->nMin );
4138641518
pGroup->nMinPage -= pCache->nMin;
4138741519
pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
4138841520
pcache1EnforceMaxPage(pGroup);
4138941521
pcache1LeaveMutex(pGroup);
41522
+ sqlite3_free(pCache->pBulk);
4139041523
sqlite3_free(pCache->apHash);
4139141524
sqlite3_free(pCache);
4139241525
}
4139341526
4139441527
/*
@@ -41440,11 +41573,11 @@
4144041573
*/
4144141574
SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
4144241575
int nFree = 0;
4144341576
assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
4144441577
assert( sqlite3_mutex_notheld(pcache1.mutex) );
41445
- if( pcache1.pStart==0 ){
41578
+ if( sqlite3GlobalConfig.nPage==0 ){
4144641579
PgHdr1 *p;
4144741580
pcache1EnterMutex(&pcache1.grp);
4144841581
while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){
4144941582
nFree += pcache1MemSize(p->page.pBuf);
4145041583
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
@@ -62542,10 +62675,11 @@
6254262675
u32 *heap = 0; /* Min-heap used for checking cell coverage */
6254362676
u32 x, prev = 0; /* Next and previous entry on the min-heap */
6254462677
const char *saved_zPfx = pCheck->zPfx;
6254562678
int saved_v1 = pCheck->v1;
6254662679
int saved_v2 = pCheck->v2;
62680
+ u8 savedIsInit;
6254762681
6254862682
/* Check that the page exists
6254962683
*/
6255062684
pBt = pCheck->pBt;
6255162685
usableSize = pBt->usableSize;
@@ -62559,10 +62693,11 @@
6255962693
goto end_of_check;
6256062694
}
6256162695
6256262696
/* Clear MemPage.isInit to make sure the corruption detection code in
6256362697
** btreeInitPage() is executed. */
62698
+ savedIsInit = pPage->isInit;
6256462699
pPage->isInit = 0;
6256562700
if( (rc = btreeInitPage(pPage))!=0 ){
6256662701
assert( rc==SQLITE_CORRUPT ); /* The only possible error from InitPage */
6256762702
checkAppendMsg(pCheck,
6256862703
"btreeInitPage() returns error code %d", rc);
@@ -62700,11 +62835,11 @@
6270062835
while( i>0 ){
6270162836
int size, j;
6270262837
assert( (u32)i<=usableSize-4 ); /* Enforced by btreeInitPage() */
6270362838
size = get2byte(&data[i+2]);
6270462839
assert( (u32)(i+size)<=usableSize ); /* Enforced by btreeInitPage() */
62705
- btreeHeapInsert(heap, (i<<16)|(i+size-1));
62840
+ btreeHeapInsert(heap, (((u32)i)<<16)|(i+size-1));
6270662841
/* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
6270762842
** big-endian integer which is the offset in the b-tree page of the next
6270862843
** freeblock in the chain, or zero if the freeblock is the last on the
6270962844
** chain. */
6271062845
j = get2byte(&data[i]);
@@ -62751,10 +62886,11 @@
6275162886
nFrag, data[hdr+7], iPage);
6275262887
}
6275362888
}
6275462889
6275562890
end_of_check:
62891
+ if( !doCoverageCheck ) pPage->isInit = savedIsInit;
6275662892
releasePage(pPage);
6275762893
pCheck->zPfx = saved_zPfx;
6275862894
pCheck->v1 = saved_v1;
6275962895
pCheck->v2 = saved_v2;
6276062896
return depth+1;
@@ -69020,10 +69156,11 @@
6902069156
** to ignore the compiler warnings and leave this variable uninitialized.
6902169157
*/
6902269158
/* mem1.u.i = 0; // not needed, here to silence compiler warning */
6902369159
6902469160
idx1 = getVarint32(aKey1, szHdr1);
69161
+ if( szHdr1>98307 ) return SQLITE_CORRUPT;
6902569162
d1 = szHdr1;
6902669163
assert( pKeyInfo->nField+pKeyInfo->nXField>=pPKey2->nField || CORRUPT_DB );
6902769164
assert( pKeyInfo->aSortOrder!=0 );
6902869165
assert( pKeyInfo->nField>0 );
6902969166
assert( idx1<=szHdr1 || CORRUPT_DB );
@@ -109379,14 +109516,18 @@
109379109516
sqlite3VdbeResolveLabel(v, addrCont);
109380109517
109381109518
/* Execute the recursive SELECT taking the single row in Current as
109382109519
** the value for the recursive-table. Store the results in the Queue.
109383109520
*/
109384
- p->pPrior = 0;
109385
- sqlite3Select(pParse, p, &destQueue);
109386
- assert( p->pPrior==0 );
109387
- p->pPrior = pSetup;
109521
+ if( p->selFlags & SF_Aggregate ){
109522
+ sqlite3ErrorMsg(pParse, "recursive aggregate queries not supported");
109523
+ }else{
109524
+ p->pPrior = 0;
109525
+ sqlite3Select(pParse, p, &destQueue);
109526
+ assert( p->pPrior==0 );
109527
+ p->pPrior = pSetup;
109528
+ }
109388109529
109389109530
/* Keep running the loop until the Queue is empty */
109390109531
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
109391109532
sqlite3VdbeResolveLabel(v, addrBreak);
109392109533
109393109534
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -325,11 +325,11 @@
325 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
326 ** [sqlite_version()] and [sqlite_source_id()].
327 */
328 #define SQLITE_VERSION "3.8.11"
329 #define SQLITE_VERSION_NUMBER 3008011
330 #define SQLITE_SOURCE_ID "2015-07-03 17:54:49 030f60a7ba171650ce8c0ac32dc166eab80aca32"
331
332 /*
333 ** CAPI3REF: Run-Time Library Version Numbers
334 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
335 **
@@ -6503,10 +6503,13 @@
6503 #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
6504 #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
6505 #define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */
6506 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6507 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
 
 
 
6508
6509 /*
6510 ** CAPI3REF: Retrieve the mutex for a database connection
6511 ** METHOD: sqlite3
6512 **
@@ -8941,10 +8944,20 @@
8941 #if SQLITE_DEFAULT_WORKER_THREADS>SQLITE_MAX_WORKER_THREADS
8942 # undef SQLITE_MAX_WORKER_THREADS
8943 # define SQLITE_MAX_WORKER_THREADS SQLITE_DEFAULT_WORKER_THREADS
8944 #endif
8945
 
 
 
 
 
 
 
 
 
 
8946
8947 /*
8948 ** GCC does not define the offsetof() macro so we'll have to do it
8949 ** ourselves.
8950 */
@@ -14043,11 +14056,11 @@
14043 (void*)0, /* pScratch */
14044 0, /* szScratch */
14045 0, /* nScratch */
14046 (void*)0, /* pPage */
14047 0, /* szPage */
14048 0, /* nPage */
14049 0, /* mxParserStack */
14050 0, /* sharedCacheEnabled */
14051 SQLITE_SORTER_PMASZ, /* szPma */
14052 /* All the rest should always be initialized to zero */
14053 0, /* isInit */
@@ -19454,11 +19467,11 @@
19454 ** The sqlite3_mutex_alloc() routine allocates a new
19455 ** mutex and returns a pointer to it. If it returns NULL
19456 ** that means that a mutex could not be allocated.
19457 */
19458 static sqlite3_mutex *debugMutexAlloc(int id){
19459 static sqlite3_debug_mutex aStatic[SQLITE_MUTEX_STATIC_APP3 - 1];
19460 sqlite3_debug_mutex *pNew = 0;
19461 switch( id ){
19462 case SQLITE_MUTEX_FAST:
19463 case SQLITE_MUTEX_RECURSIVE: {
19464 pNew = sqlite3Malloc(sizeof(*pNew));
@@ -19669,10 +19682,13 @@
19669 ** <li> SQLITE_MUTEX_STATIC_LRU
19670 ** <li> SQLITE_MUTEX_STATIC_PMEM
19671 ** <li> SQLITE_MUTEX_STATIC_APP1
19672 ** <li> SQLITE_MUTEX_STATIC_APP2
19673 ** <li> SQLITE_MUTEX_STATIC_APP3
 
 
 
19674 ** </ul>
19675 **
19676 ** The first two constants cause sqlite3_mutex_alloc() to create
19677 ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
19678 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
@@ -19697,10 +19713,13 @@
19697 ** mutex types, the same mutex is returned on every call that has
19698 ** the same type number.
19699 */
19700 static sqlite3_mutex *pthreadMutexAlloc(int iType){
19701 static sqlite3_mutex staticMutexes[] = {
 
 
 
19702 SQLITE3_MUTEX_INITIALIZER,
19703 SQLITE3_MUTEX_INITIALIZER,
19704 SQLITE3_MUTEX_INITIALIZER,
19705 SQLITE3_MUTEX_INITIALIZER,
19706 SQLITE3_MUTEX_INITIALIZER,
@@ -20311,10 +20330,13 @@
20311 SQLITE3_MUTEX_INITIALIZER,
20312 SQLITE3_MUTEX_INITIALIZER,
20313 SQLITE3_MUTEX_INITIALIZER,
20314 SQLITE3_MUTEX_INITIALIZER,
20315 SQLITE3_MUTEX_INITIALIZER,
 
 
 
20316 SQLITE3_MUTEX_INITIALIZER
20317 };
20318
20319 static int winMutex_isInit = 0;
20320 static int winMutex_isNt = -1; /* <0 means "need to query" */
@@ -20382,10 +20404,13 @@
20382 ** <li> SQLITE_MUTEX_STATIC_LRU
20383 ** <li> SQLITE_MUTEX_STATIC_PMEM
20384 ** <li> SQLITE_MUTEX_STATIC_APP1
20385 ** <li> SQLITE_MUTEX_STATIC_APP2
20386 ** <li> SQLITE_MUTEX_STATIC_APP3
 
 
 
20387 ** </ul>
20388 **
20389 ** The first two constants cause sqlite3_mutex_alloc() to create
20390 ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
20391 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
@@ -20793,14 +20818,13 @@
20793 sqlite3GlobalConfig.pScratch = 0;
20794 sqlite3GlobalConfig.szScratch = 0;
20795 sqlite3GlobalConfig.nScratch = 0;
20796 }
20797 if( sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.szPage<512
20798 || sqlite3GlobalConfig.nPage<1 ){
20799 sqlite3GlobalConfig.pPage = 0;
20800 sqlite3GlobalConfig.szPage = 0;
20801 sqlite3GlobalConfig.nPage = 0;
20802 }
20803 rc = sqlite3GlobalConfig.m.xInit(sqlite3GlobalConfig.m.pAppData);
20804 if( rc!=SQLITE_OK ) memset(&mem0, 0, sizeof(mem0));
20805 return rc;
20806 }
@@ -26522,18 +26546,18 @@
26522 ** unixEnterMutex()
26523 ** assert( unixMutexHeld() );
26524 ** unixEnterLeave()
26525 */
26526 static void unixEnterMutex(void){
26527 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
26528 }
26529 static void unixLeaveMutex(void){
26530 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
26531 }
26532 #ifdef SQLITE_DEBUG
26533 static int unixMutexHeld(void) {
26534 return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
26535 }
26536 #endif
26537
26538
26539 #ifdef SQLITE_HAVE_OS_TRACE
@@ -37047,18 +37071,18 @@
37047 ** winShmEnterMutex()
37048 ** assert( winShmMutexHeld() );
37049 ** winShmLeaveMutex()
37050 */
37051 static void winShmEnterMutex(void){
37052 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
37053 }
37054 static void winShmLeaveMutex(void){
37055 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
37056 }
37057 #ifndef NDEBUG
37058 static int winShmMutexHeld(void) {
37059 return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
37060 }
37061 #endif
37062
37063 /*
37064 ** Object used to represent a single file opened and mmapped to provide
@@ -40399,12 +40423,75 @@
40399 ** This file implements the default page cache implementation (the
40400 ** sqlite3_pcache interface). It also contains part of the implementation
40401 ** of the SQLITE_CONFIG_PAGECACHE and sqlite3_release_memory() features.
40402 ** If the default page cache implementation is overridden, then neither of
40403 ** these two features are available.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40404 */
40405
40406
40407 typedef struct PCache1 PCache1;
40408 typedef struct PgHdr1 PgHdr1;
40409 typedef struct PgFreeslot PgFreeslot;
40410 typedef struct PGroup PGroup;
@@ -40453,12 +40540,13 @@
40453 ** flag (bPurgeable) are set when the cache is created. nMax may be
40454 ** modified at any time by a call to the pcache1Cachesize() method.
40455 ** The PGroup mutex must be held when accessing nMax.
40456 */
40457 PGroup *pGroup; /* PGroup this cache belongs to */
40458 int szPage; /* Size of allocated pages in bytes */
40459 int szExtra; /* Size of extra space in bytes */
 
40460 int bPurgeable; /* True if cache is purgeable */
40461 unsigned int nMin; /* Minimum number of pages reserved */
40462 unsigned int nMax; /* Configured "cache_size" value */
40463 unsigned int n90pct; /* nMax*9/10 */
40464 unsigned int iMaxKey; /* Largest key seen since xTruncate() */
@@ -40468,10 +40556,12 @@
40468 */
40469 unsigned int nRecyclable; /* Number of pages in the LRU list */
40470 unsigned int nPage; /* Total number of pages in apHash */
40471 unsigned int nHash; /* Number of slots in apHash[] */
40472 PgHdr1 **apHash; /* Hash table for fast lookup by key */
 
 
40473 };
40474
40475 /*
40476 ** Each cache entry is represented by an instance of the following
40477 ** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
@@ -40480,19 +40570,20 @@
40480 */
40481 struct PgHdr1 {
40482 sqlite3_pcache_page page;
40483 unsigned int iKey; /* Key value (page number) */
40484 u8 isPinned; /* Page in use, not on the LRU list */
 
40485 PgHdr1 *pNext; /* Next in hash table chain */
40486 PCache1 *pCache; /* Cache that currently owns this page */
40487 PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
40488 PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
40489 };
40490
40491 /*
40492 ** Free slots in the allocator used to divide up the buffer provided using
40493 ** the SQLITE_CONFIG_PAGECACHE mechanism.
40494 */
40495 struct PgFreeslot {
40496 PgFreeslot *pNext; /* Next free slot */
40497 };
40498
@@ -40506,14 +40597,15 @@
40506 ** szSlot, nSlot, pStart, pEnd, nReserve, and isInit values are all
40507 ** fixed at sqlite3_initialize() time and do not require mutex protection.
40508 ** The nFreeSlot and pFree values do require mutex protection.
40509 */
40510 int isInit; /* True if initialized */
 
40511 int szSlot; /* Size of each free slot */
40512 int nSlot; /* The number of pcache slots */
40513 int nReserve; /* Try to keep nFreeSlot above this */
40514 void *pStart, *pEnd; /* Bounds of pagecache malloc range */
40515 /* Above requires no mutex. Use mutex below for variable that follow. */
40516 sqlite3_mutex *mutex; /* Mutex for accessing the following: */
40517 PgFreeslot *pFree; /* Free page blocks */
40518 int nFreeSlot; /* Number of unused pcache slots */
40519 /* The following value requires a mutex to change. We skip the mutex on
@@ -40556,10 +40648,11 @@
40556 ** to be serialized already. There is no need for further mutexing.
40557 */
40558 SQLITE_PRIVATE void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){
40559 if( pcache1.isInit ){
40560 PgFreeslot *p;
 
40561 sz = ROUNDDOWN8(sz);
40562 pcache1.szSlot = sz;
40563 pcache1.nSlot = pcache1.nFreeSlot = n;
40564 pcache1.nReserve = n>90 ? 10 : (n/10 + 1);
40565 pcache1.pStart = pBuf;
@@ -40620,13 +40713,13 @@
40620 }
40621
40622 /*
40623 ** Free an allocated buffer obtained from pcache1Alloc().
40624 */
40625 static int pcache1Free(void *p){
40626 int nFreed = 0;
40627 if( p==0 ) return 0;
40628 if( p>=pcache1.pStart && p<pcache1.pEnd ){
40629 PgFreeslot *pSlot;
40630 sqlite3_mutex_enter(pcache1.mutex);
40631 sqlite3StatusDown(SQLITE_STATUS_PAGECACHE_USED, 1);
40632 pSlot = (PgFreeslot*)p;
@@ -40637,19 +40730,18 @@
40637 assert( pcache1.nFreeSlot<=pcache1.nSlot );
40638 sqlite3_mutex_leave(pcache1.mutex);
40639 }else{
40640 assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
40641 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
40642 nFreed = sqlite3MallocSize(p);
40643 #ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
 
40644 sqlite3_mutex_enter(pcache1.mutex);
40645 sqlite3StatusDown(SQLITE_STATUS_PAGECACHE_OVERFLOW, nFreed);
40646 sqlite3_mutex_leave(pcache1.mutex);
40647 #endif
40648 sqlite3_free(p);
40649 }
40650 return nFreed;
40651 }
40652
40653 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40654 /*
40655 ** Return the size of a pcache allocation
@@ -40673,58 +40765,69 @@
40673 */
40674 static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
40675 PgHdr1 *p = 0;
40676 void *pPg;
40677
40678 /* The group mutex must be released before pcache1Alloc() is called. This
40679 ** is because it may call sqlite3_release_memory(), which assumes that
40680 ** this mutex is not held. */
40681 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
40682 pcache1LeaveMutex(pCache->pGroup);
 
 
 
 
 
 
 
 
 
 
 
 
40683 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
40684 pPg = pcache1Alloc(pCache->szPage);
40685 p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
40686 if( !pPg || !p ){
40687 pcache1Free(pPg);
40688 sqlite3_free(p);
40689 pPg = 0;
40690 }
40691 #else
40692 pPg = pcache1Alloc(ROUND8(sizeof(PgHdr1)) + pCache->szPage + pCache->szExtra);
40693 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
40694 #endif
40695 pcache1EnterMutex(pCache->pGroup);
40696
40697 if( pPg ){
 
40698 p->page.pBuf = pPg;
40699 p->page.pExtra = &p[1];
40700 if( pCache->bPurgeable ){
40701 pCache->pGroup->nCurrentPage++;
40702 }
40703 return p;
40704 }
40705 return 0;
 
 
 
40706 }
40707
40708 /*
40709 ** Free a page object allocated by pcache1AllocPage().
40710 **
40711 ** The pointer is allowed to be NULL, which is prudent. But it turns out
40712 ** that the current implementation happens to never call this routine
40713 ** with a NULL pointer, so we mark the NULL test with ALWAYS().
40714 */
40715 static void pcache1FreePage(PgHdr1 *p){
40716 if( ALWAYS(p) ){
40717 PCache1 *pCache = p->pCache;
40718 assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
 
 
 
 
 
40719 pcache1Free(p->page.pBuf);
40720 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
40721 sqlite3_free(p);
40722 #endif
40723 if( pCache->bPurgeable ){
40724 pCache->pGroup->nCurrentPage--;
40725 }
40726 }
40727 }
40728
40729 /*
40730 ** Malloc function used by SQLite to obtain space from the buffer configured
@@ -40920,10 +41023,35 @@
40920 */
40921 static int pcache1Init(void *NotUsed){
40922 UNUSED_PARAMETER(NotUsed);
40923 assert( pcache1.isInit==0 );
40924 memset(&pcache1, 0, sizeof(pcache1));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40925 #if SQLITE_THREADSAFE
40926 if( sqlite3GlobalConfig.bCoreMutex ){
40927 pcache1.grp.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU);
40928 pcache1.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PMEM);
40929 }
@@ -40955,52 +41083,65 @@
40955 static sqlite3_pcache *pcache1Create(int szPage, int szExtra, int bPurgeable){
40956 PCache1 *pCache; /* The newly created page cache */
40957 PGroup *pGroup; /* The group the new page cache will belong to */
40958 int sz; /* Bytes of memory required to allocate the new cache */
40959
40960 /*
40961 ** The separateCache variable is true if each PCache has its own private
40962 ** PGroup. In other words, separateCache is true for mode (1) where no
40963 ** mutexing is required.
40964 **
40965 ** * Always use a unified cache (mode-2) if ENABLE_MEMORY_MANAGEMENT
40966 **
40967 ** * Always use a unified cache in single-threaded applications
40968 **
40969 ** * Otherwise (if multi-threaded and ENABLE_MEMORY_MANAGEMENT is off)
40970 ** use separate caches (mode-1)
40971 */
40972 #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) || SQLITE_THREADSAFE==0
40973 const int separateCache = 0;
40974 #else
40975 int separateCache = sqlite3GlobalConfig.bCoreMutex>0;
40976 #endif
40977
40978 assert( (szPage & (szPage-1))==0 && szPage>=512 && szPage<=65536 );
40979 assert( szExtra < 300 );
40980
40981 sz = sizeof(PCache1) + sizeof(PGroup)*separateCache;
40982 pCache = (PCache1 *)sqlite3MallocZero(sz);
40983 if( pCache ){
40984 if( separateCache ){
40985 pGroup = (PGroup*)&pCache[1];
40986 pGroup->mxPinned = 10;
40987 }else{
40988 pGroup = &pcache1.grp;
40989 }
40990 pCache->pGroup = pGroup;
40991 pCache->szPage = szPage;
40992 pCache->szExtra = szExtra;
 
40993 pCache->bPurgeable = (bPurgeable ? 1 : 0);
40994 pcache1EnterMutex(pGroup);
40995 pcache1ResizeHash(pCache);
40996 if( bPurgeable ){
40997 pCache->nMin = 10;
40998 pGroup->nMinPage += pCache->nMin;
40999 pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
41000 }
41001 pcache1LeaveMutex(pGroup);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41002 if( pCache->nHash==0 ){
41003 pcache1Destroy((sqlite3_pcache*)pCache);
41004 pCache = 0;
41005 }
41006 }
@@ -41090,30 +41231,21 @@
41090
41091 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
41092 assert( pCache->nHash>0 && pCache->apHash );
41093
41094 /* Step 4. Try to recycle a page. */
41095 if( pCache->bPurgeable && pGroup->pLruTail && (
41096 (pCache->nPage+1>=pCache->nMax)
41097 || pGroup->nCurrentPage>=pGroup->nMaxPage
41098 || pcache1UnderMemoryPressure(pCache)
41099 )){
41100 PCache1 *pOther;
41101 pPage = pGroup->pLruTail;
41102 assert( pPage->isPinned==0 );
41103 pcache1RemoveFromHash(pPage, 0);
41104 pcache1PinPage(pPage);
41105 pOther = pPage->pCache;
41106
41107 /* We want to verify that szPage and szExtra are the same for pOther
41108 ** and pCache. Assert that we can verify this by comparing sums. */
41109 assert( (pCache->szPage & (pCache->szPage-1))==0 && pCache->szPage>=512 );
41110 assert( pCache->szExtra<512 );
41111 assert( (pOther->szPage & (pOther->szPage-1))==0 && pOther->szPage>=512 );
41112 assert( pOther->szExtra<512 );
41113
41114 if( pOther->szPage+pOther->szExtra != pCache->szPage+pCache->szExtra ){
41115 pcache1FreePage(pPage);
41116 pPage = 0;
41117 }else{
41118 pGroup->nCurrentPage -= (pOther->bPurgeable - pCache->bPurgeable);
41119 }
@@ -41385,10 +41517,11 @@
41385 assert( pGroup->nMinPage >= pCache->nMin );
41386 pGroup->nMinPage -= pCache->nMin;
41387 pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
41388 pcache1EnforceMaxPage(pGroup);
41389 pcache1LeaveMutex(pGroup);
 
41390 sqlite3_free(pCache->apHash);
41391 sqlite3_free(pCache);
41392 }
41393
41394 /*
@@ -41440,11 +41573,11 @@
41440 */
41441 SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
41442 int nFree = 0;
41443 assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
41444 assert( sqlite3_mutex_notheld(pcache1.mutex) );
41445 if( pcache1.pStart==0 ){
41446 PgHdr1 *p;
41447 pcache1EnterMutex(&pcache1.grp);
41448 while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){
41449 nFree += pcache1MemSize(p->page.pBuf);
41450 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
@@ -62542,10 +62675,11 @@
62542 u32 *heap = 0; /* Min-heap used for checking cell coverage */
62543 u32 x, prev = 0; /* Next and previous entry on the min-heap */
62544 const char *saved_zPfx = pCheck->zPfx;
62545 int saved_v1 = pCheck->v1;
62546 int saved_v2 = pCheck->v2;
 
62547
62548 /* Check that the page exists
62549 */
62550 pBt = pCheck->pBt;
62551 usableSize = pBt->usableSize;
@@ -62559,10 +62693,11 @@
62559 goto end_of_check;
62560 }
62561
62562 /* Clear MemPage.isInit to make sure the corruption detection code in
62563 ** btreeInitPage() is executed. */
 
62564 pPage->isInit = 0;
62565 if( (rc = btreeInitPage(pPage))!=0 ){
62566 assert( rc==SQLITE_CORRUPT ); /* The only possible error from InitPage */
62567 checkAppendMsg(pCheck,
62568 "btreeInitPage() returns error code %d", rc);
@@ -62700,11 +62835,11 @@
62700 while( i>0 ){
62701 int size, j;
62702 assert( (u32)i<=usableSize-4 ); /* Enforced by btreeInitPage() */
62703 size = get2byte(&data[i+2]);
62704 assert( (u32)(i+size)<=usableSize ); /* Enforced by btreeInitPage() */
62705 btreeHeapInsert(heap, (i<<16)|(i+size-1));
62706 /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
62707 ** big-endian integer which is the offset in the b-tree page of the next
62708 ** freeblock in the chain, or zero if the freeblock is the last on the
62709 ** chain. */
62710 j = get2byte(&data[i]);
@@ -62751,10 +62886,11 @@
62751 nFrag, data[hdr+7], iPage);
62752 }
62753 }
62754
62755 end_of_check:
 
62756 releasePage(pPage);
62757 pCheck->zPfx = saved_zPfx;
62758 pCheck->v1 = saved_v1;
62759 pCheck->v2 = saved_v2;
62760 return depth+1;
@@ -69020,10 +69156,11 @@
69020 ** to ignore the compiler warnings and leave this variable uninitialized.
69021 */
69022 /* mem1.u.i = 0; // not needed, here to silence compiler warning */
69023
69024 idx1 = getVarint32(aKey1, szHdr1);
 
69025 d1 = szHdr1;
69026 assert( pKeyInfo->nField+pKeyInfo->nXField>=pPKey2->nField || CORRUPT_DB );
69027 assert( pKeyInfo->aSortOrder!=0 );
69028 assert( pKeyInfo->nField>0 );
69029 assert( idx1<=szHdr1 || CORRUPT_DB );
@@ -109379,14 +109516,18 @@
109379 sqlite3VdbeResolveLabel(v, addrCont);
109380
109381 /* Execute the recursive SELECT taking the single row in Current as
109382 ** the value for the recursive-table. Store the results in the Queue.
109383 */
109384 p->pPrior = 0;
109385 sqlite3Select(pParse, p, &destQueue);
109386 assert( p->pPrior==0 );
109387 p->pPrior = pSetup;
 
 
 
 
109388
109389 /* Keep running the loop until the Queue is empty */
109390 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
109391 sqlite3VdbeResolveLabel(v, addrBreak);
109392
109393
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -325,11 +325,11 @@
325 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
326 ** [sqlite_version()] and [sqlite_source_id()].
327 */
328 #define SQLITE_VERSION "3.8.11"
329 #define SQLITE_VERSION_NUMBER 3008011
330 #define SQLITE_SOURCE_ID "2015-07-08 16:22:42 5348ffc3fda5168c1e9e14aa88b0c6aedbda7c94"
331
332 /*
333 ** CAPI3REF: Run-Time Library Version Numbers
334 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
335 **
@@ -6503,10 +6503,13 @@
6503 #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
6504 #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
6505 #define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */
6506 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6507 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6508 #define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */
6509 #define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */
6510 #define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */
6511
6512 /*
6513 ** CAPI3REF: Retrieve the mutex for a database connection
6514 ** METHOD: sqlite3
6515 **
@@ -8941,10 +8944,20 @@
8944 #if SQLITE_DEFAULT_WORKER_THREADS>SQLITE_MAX_WORKER_THREADS
8945 # undef SQLITE_MAX_WORKER_THREADS
8946 # define SQLITE_MAX_WORKER_THREADS SQLITE_DEFAULT_WORKER_THREADS
8947 #endif
8948
8949 /*
8950 ** The default initial allocation for the pagecache when using separate
8951 ** pagecaches for each database connection. A positive number is the
8952 ** number of pages. A negative number N translations means that a buffer
8953 ** of -1024*N bytes is allocated and used for as many pages as it will hold.
8954 */
8955 #ifndef SQLITE_DEFAULT_PCACHE_INITSZ
8956 # define SQLITE_DEFAULT_PCACHE_INITSZ 100
8957 #endif
8958
8959
8960 /*
8961 ** GCC does not define the offsetof() macro so we'll have to do it
8962 ** ourselves.
8963 */
@@ -14043,11 +14056,11 @@
14056 (void*)0, /* pScratch */
14057 0, /* szScratch */
14058 0, /* nScratch */
14059 (void*)0, /* pPage */
14060 0, /* szPage */
14061 SQLITE_DEFAULT_PCACHE_INITSZ, /* nPage */
14062 0, /* mxParserStack */
14063 0, /* sharedCacheEnabled */
14064 SQLITE_SORTER_PMASZ, /* szPma */
14065 /* All the rest should always be initialized to zero */
14066 0, /* isInit */
@@ -19454,11 +19467,11 @@
19467 ** The sqlite3_mutex_alloc() routine allocates a new
19468 ** mutex and returns a pointer to it. If it returns NULL
19469 ** that means that a mutex could not be allocated.
19470 */
19471 static sqlite3_mutex *debugMutexAlloc(int id){
19472 static sqlite3_debug_mutex aStatic[SQLITE_MUTEX_STATIC_VFS3 - 1];
19473 sqlite3_debug_mutex *pNew = 0;
19474 switch( id ){
19475 case SQLITE_MUTEX_FAST:
19476 case SQLITE_MUTEX_RECURSIVE: {
19477 pNew = sqlite3Malloc(sizeof(*pNew));
@@ -19669,10 +19682,13 @@
19682 ** <li> SQLITE_MUTEX_STATIC_LRU
19683 ** <li> SQLITE_MUTEX_STATIC_PMEM
19684 ** <li> SQLITE_MUTEX_STATIC_APP1
19685 ** <li> SQLITE_MUTEX_STATIC_APP2
19686 ** <li> SQLITE_MUTEX_STATIC_APP3
19687 ** <li> SQLITE_MUTEX_STATIC_VFS1
19688 ** <li> SQLITE_MUTEX_STATIC_VFS2
19689 ** <li> SQLITE_MUTEX_STATIC_VFS3
19690 ** </ul>
19691 **
19692 ** The first two constants cause sqlite3_mutex_alloc() to create
19693 ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
19694 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
@@ -19697,10 +19713,13 @@
19713 ** mutex types, the same mutex is returned on every call that has
19714 ** the same type number.
19715 */
19716 static sqlite3_mutex *pthreadMutexAlloc(int iType){
19717 static sqlite3_mutex staticMutexes[] = {
19718 SQLITE3_MUTEX_INITIALIZER,
19719 SQLITE3_MUTEX_INITIALIZER,
19720 SQLITE3_MUTEX_INITIALIZER,
19721 SQLITE3_MUTEX_INITIALIZER,
19722 SQLITE3_MUTEX_INITIALIZER,
19723 SQLITE3_MUTEX_INITIALIZER,
19724 SQLITE3_MUTEX_INITIALIZER,
19725 SQLITE3_MUTEX_INITIALIZER,
@@ -20311,10 +20330,13 @@
20330 SQLITE3_MUTEX_INITIALIZER,
20331 SQLITE3_MUTEX_INITIALIZER,
20332 SQLITE3_MUTEX_INITIALIZER,
20333 SQLITE3_MUTEX_INITIALIZER,
20334 SQLITE3_MUTEX_INITIALIZER,
20335 SQLITE3_MUTEX_INITIALIZER,
20336 SQLITE3_MUTEX_INITIALIZER,
20337 SQLITE3_MUTEX_INITIALIZER,
20338 SQLITE3_MUTEX_INITIALIZER
20339 };
20340
20341 static int winMutex_isInit = 0;
20342 static int winMutex_isNt = -1; /* <0 means "need to query" */
@@ -20382,10 +20404,13 @@
20404 ** <li> SQLITE_MUTEX_STATIC_LRU
20405 ** <li> SQLITE_MUTEX_STATIC_PMEM
20406 ** <li> SQLITE_MUTEX_STATIC_APP1
20407 ** <li> SQLITE_MUTEX_STATIC_APP2
20408 ** <li> SQLITE_MUTEX_STATIC_APP3
20409 ** <li> SQLITE_MUTEX_STATIC_VFS1
20410 ** <li> SQLITE_MUTEX_STATIC_VFS2
20411 ** <li> SQLITE_MUTEX_STATIC_VFS3
20412 ** </ul>
20413 **
20414 ** The first two constants cause sqlite3_mutex_alloc() to create
20415 ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
20416 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
@@ -20793,14 +20818,13 @@
20818 sqlite3GlobalConfig.pScratch = 0;
20819 sqlite3GlobalConfig.szScratch = 0;
20820 sqlite3GlobalConfig.nScratch = 0;
20821 }
20822 if( sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.szPage<512
20823 || sqlite3GlobalConfig.nPage<=0 ){
20824 sqlite3GlobalConfig.pPage = 0;
20825 sqlite3GlobalConfig.szPage = 0;
 
20826 }
20827 rc = sqlite3GlobalConfig.m.xInit(sqlite3GlobalConfig.m.pAppData);
20828 if( rc!=SQLITE_OK ) memset(&mem0, 0, sizeof(mem0));
20829 return rc;
20830 }
@@ -26522,18 +26546,18 @@
26546 ** unixEnterMutex()
26547 ** assert( unixMutexHeld() );
26548 ** unixEnterLeave()
26549 */
26550 static void unixEnterMutex(void){
26551 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1));
26552 }
26553 static void unixLeaveMutex(void){
26554 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1));
26555 }
26556 #ifdef SQLITE_DEBUG
26557 static int unixMutexHeld(void) {
26558 return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1));
26559 }
26560 #endif
26561
26562
26563 #ifdef SQLITE_HAVE_OS_TRACE
@@ -37047,18 +37071,18 @@
37071 ** winShmEnterMutex()
37072 ** assert( winShmMutexHeld() );
37073 ** winShmLeaveMutex()
37074 */
37075 static void winShmEnterMutex(void){
37076 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1));
37077 }
37078 static void winShmLeaveMutex(void){
37079 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1));
37080 }
37081 #ifndef NDEBUG
37082 static int winShmMutexHeld(void) {
37083 return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1));
37084 }
37085 #endif
37086
37087 /*
37088 ** Object used to represent a single file opened and mmapped to provide
@@ -40399,12 +40423,75 @@
40423 ** This file implements the default page cache implementation (the
40424 ** sqlite3_pcache interface). It also contains part of the implementation
40425 ** of the SQLITE_CONFIG_PAGECACHE and sqlite3_release_memory() features.
40426 ** If the default page cache implementation is overridden, then neither of
40427 ** these two features are available.
40428 **
40429 ** A Page cache line looks like this:
40430 **
40431 ** -------------------------------------------------------------
40432 ** | database page content | PgHdr1 | MemPage | PgHdr |
40433 ** -------------------------------------------------------------
40434 **
40435 ** The database page content is up front (so that buffer overreads tend to
40436 ** flow harmlessly into the PgHdr1, MemPage, and PgHdr extensions). MemPage
40437 ** is the extension added by the btree.c module containing information such
40438 ** as the database page number and how that database page is used. PgHdr
40439 ** is added by the pcache.c layer and contains information used to keep track
40440 ** of which pages are "dirty". PgHdr1 is an extension added by this
40441 ** module (pcache1.c). The PgHdr1 header is a subclass of sqlite3_pcache_page.
40442 ** PgHdr1 contains information needed to look up a page by its page number.
40443 ** The superclass sqlite3_pcache_page.pBuf points to the start of the
40444 ** database page content and sqlite3_pcache_page.pExtra points to PgHdr.
40445 **
40446 ** The size of the extension (MemPage+PgHdr+PgHdr1) can be determined at
40447 ** runtime using sqlite3_config(SQLITE_CONFIG_PCACHE_HDRSZ, &size). The
40448 ** sizes of the extensions sum to 272 bytes on x64 for 3.8.10, but this
40449 ** size can vary according to architecture, compile-time options, and
40450 ** SQLite library version number.
40451 **
40452 ** If SQLITE_PCACHE_SEPARATE_HEADER is defined, then the extension is obtained
40453 ** using a separate memory allocation from the database page content. This
40454 ** seeks to overcome the "clownshoe" problem (also called "internal
40455 ** fragmentation" in academic literature) of allocating a few bytes more
40456 ** than a power of two with the memory allocator rounding up to the next
40457 ** power of two, and leaving the rounded-up space unused.
40458 **
40459 ** This module tracks pointers to PgHdr1 objects. Only pcache.c communicates
40460 ** with this module. Information is passed back and forth as PgHdr1 pointers.
40461 **
40462 ** The pcache.c and pager.c modules deal pointers to PgHdr objects.
40463 ** The btree.c module deals with pointers to MemPage objects.
40464 **
40465 ** SOURCE OF PAGE CACHE MEMORY:
40466 **
40467 ** Memory for a page might come from any of three sources:
40468 **
40469 ** (1) The general-purpose memory allocator - sqlite3Malloc()
40470 ** (2) Global page-cache memory provided using sqlite3_config() with
40471 ** SQLITE_CONFIG_PAGECACHE.
40472 ** (3) PCache-local bulk allocation.
40473 **
40474 ** The third case is a chunk of heap memory (defaulting to 100 pages worth)
40475 ** that is allocated when the page cache is created. The size of the local
40476 ** bulk allocation can be adjusted using
40477 **
40478 ** sqlite3_config(SQLITE_CONFIG_PCACHE, 0, 0, N).
40479 **
40480 ** If N is positive, then N pages worth of memory are allocated using a single
40481 ** sqlite3Malloc() call and that memory is used for the first N pages allocated.
40482 ** Or if N is negative, then -1024*N bytes of memory are allocated and used
40483 ** for as many pages as can be accomodated.
40484 **
40485 ** Only one of (2) or (3) can be used. Once the memory available to (2) or
40486 ** (3) is exhausted, subsequent allocations fail over to the general-purpose
40487 ** memory allocator (1).
40488 **
40489 ** Earlier versions of SQLite used only methods (1) and (2). But experiments
40490 ** show that method (3) with N==100 provides about a 5% performance boost for
40491 ** common workloads.
40492 */
 
40493
40494 typedef struct PCache1 PCache1;
40495 typedef struct PgHdr1 PgHdr1;
40496 typedef struct PgFreeslot PgFreeslot;
40497 typedef struct PGroup PGroup;
@@ -40453,12 +40540,13 @@
40540 ** flag (bPurgeable) are set when the cache is created. nMax may be
40541 ** modified at any time by a call to the pcache1Cachesize() method.
40542 ** The PGroup mutex must be held when accessing nMax.
40543 */
40544 PGroup *pGroup; /* PGroup this cache belongs to */
40545 int szPage; /* Size of database content section */
40546 int szExtra; /* sizeof(MemPage)+sizeof(PgHdr) */
40547 int szAlloc; /* Total size of one pcache line */
40548 int bPurgeable; /* True if cache is purgeable */
40549 unsigned int nMin; /* Minimum number of pages reserved */
40550 unsigned int nMax; /* Configured "cache_size" value */
40551 unsigned int n90pct; /* nMax*9/10 */
40552 unsigned int iMaxKey; /* Largest key seen since xTruncate() */
@@ -40468,10 +40556,12 @@
40556 */
40557 unsigned int nRecyclable; /* Number of pages in the LRU list */
40558 unsigned int nPage; /* Total number of pages in apHash */
40559 unsigned int nHash; /* Number of slots in apHash[] */
40560 PgHdr1 **apHash; /* Hash table for fast lookup by key */
40561 PgHdr1 *pFree; /* List of unused pcache-local pages */
40562 void *pBulk; /* Bulk memory used by pcache-local */
40563 };
40564
40565 /*
40566 ** Each cache entry is represented by an instance of the following
40567 ** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
@@ -40480,19 +40570,20 @@
40570 */
40571 struct PgHdr1 {
40572 sqlite3_pcache_page page;
40573 unsigned int iKey; /* Key value (page number) */
40574 u8 isPinned; /* Page in use, not on the LRU list */
40575 u8 isBulkLocal; /* This page from bulk local storage */
40576 PgHdr1 *pNext; /* Next in hash table chain */
40577 PCache1 *pCache; /* Cache that currently owns this page */
40578 PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
40579 PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
40580 };
40581
40582 /*
40583 ** Free slots in the allocator used to divide up the global page cache
40584 ** buffer provided using the SQLITE_CONFIG_PAGECACHE mechanism.
40585 */
40586 struct PgFreeslot {
40587 PgFreeslot *pNext; /* Next free slot */
40588 };
40589
@@ -40506,14 +40597,15 @@
40597 ** szSlot, nSlot, pStart, pEnd, nReserve, and isInit values are all
40598 ** fixed at sqlite3_initialize() time and do not require mutex protection.
40599 ** The nFreeSlot and pFree values do require mutex protection.
40600 */
40601 int isInit; /* True if initialized */
40602 int separateCache; /* Use a new PGroup for each PCache */
40603 int szSlot; /* Size of each free slot */
40604 int nSlot; /* The number of pcache slots */
40605 int nReserve; /* Try to keep nFreeSlot above this */
40606 void *pStart, *pEnd; /* Bounds of global page cache memory */
40607 /* Above requires no mutex. Use mutex below for variable that follow. */
40608 sqlite3_mutex *mutex; /* Mutex for accessing the following: */
40609 PgFreeslot *pFree; /* Free page blocks */
40610 int nFreeSlot; /* Number of unused pcache slots */
40611 /* The following value requires a mutex to change. We skip the mutex on
@@ -40556,10 +40648,11 @@
40648 ** to be serialized already. There is no need for further mutexing.
40649 */
40650 SQLITE_PRIVATE void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){
40651 if( pcache1.isInit ){
40652 PgFreeslot *p;
40653 if( pBuf==0 ) sz = n = 0;
40654 sz = ROUNDDOWN8(sz);
40655 pcache1.szSlot = sz;
40656 pcache1.nSlot = pcache1.nFreeSlot = n;
40657 pcache1.nReserve = n>90 ? 10 : (n/10 + 1);
40658 pcache1.pStart = pBuf;
@@ -40620,13 +40713,13 @@
40713 }
40714
40715 /*
40716 ** Free an allocated buffer obtained from pcache1Alloc().
40717 */
40718 static void pcache1Free(void *p){
40719 int nFreed = 0;
40720 if( p==0 ) return;
40721 if( p>=pcache1.pStart && p<pcache1.pEnd ){
40722 PgFreeslot *pSlot;
40723 sqlite3_mutex_enter(pcache1.mutex);
40724 sqlite3StatusDown(SQLITE_STATUS_PAGECACHE_USED, 1);
40725 pSlot = (PgFreeslot*)p;
@@ -40637,19 +40730,18 @@
40730 assert( pcache1.nFreeSlot<=pcache1.nSlot );
40731 sqlite3_mutex_leave(pcache1.mutex);
40732 }else{
40733 assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
40734 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
 
40735 #ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
40736 nFreed = sqlite3MallocSize(p);
40737 sqlite3_mutex_enter(pcache1.mutex);
40738 sqlite3StatusDown(SQLITE_STATUS_PAGECACHE_OVERFLOW, nFreed);
40739 sqlite3_mutex_leave(pcache1.mutex);
40740 #endif
40741 sqlite3_free(p);
40742 }
 
40743 }
40744
40745 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40746 /*
40747 ** Return the size of a pcache allocation
@@ -40673,58 +40765,69 @@
40765 */
40766 static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
40767 PgHdr1 *p = 0;
40768 void *pPg;
40769
 
 
 
40770 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
40771 if( pCache->pFree ){
40772 p = pCache->pFree;
40773 pCache->pFree = p->pNext;
40774 p->pNext = 0;
40775 }else{
40776 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40777 /* The group mutex must be released before pcache1Alloc() is called. This
40778 ** is because it might call sqlite3_release_memory(), which assumes that
40779 ** this mutex is not held. */
40780 assert( pcache1.separateCache==0 );
40781 assert( pCache->pGroup==&pcache1.grp );
40782 pcache1LeaveMutex(pCache->pGroup);
40783 #endif
40784 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
40785 pPg = pcache1Alloc(pCache->szPage);
40786 p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
40787 if( !pPg || !p ){
40788 pcache1Free(pPg);
40789 sqlite3_free(p);
40790 pPg = 0;
40791 }
40792 #else
40793 pPg = pcache1Alloc(pCache->szAlloc);
40794 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
40795 #endif
40796 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40797 pcache1EnterMutex(pCache->pGroup);
40798 #endif
40799 if( pPg==0 ) return 0;
40800 p->page.pBuf = pPg;
40801 p->page.pExtra = &p[1];
40802 p->isBulkLocal = 0;
 
 
 
40803 }
40804 if( pCache->bPurgeable ){
40805 pCache->pGroup->nCurrentPage++;
40806 }
40807 return p;
40808 }
40809
40810 /*
40811 ** Free a page object allocated by pcache1AllocPage().
 
 
 
 
40812 */
40813 static void pcache1FreePage(PgHdr1 *p){
40814 PCache1 *pCache;
40815 assert( p!=0 );
40816 pCache = p->pCache;
40817 assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
40818 if( p->isBulkLocal ){
40819 p->pNext = pCache->pFree;
40820 pCache->pFree = p;
40821 }else{
40822 pcache1Free(p->page.pBuf);
40823 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
40824 sqlite3_free(p);
40825 #endif
40826 }
40827 if( pCache->bPurgeable ){
40828 pCache->pGroup->nCurrentPage--;
40829 }
40830 }
40831
40832 /*
40833 ** Malloc function used by SQLite to obtain space from the buffer configured
@@ -40920,10 +41023,35 @@
41023 */
41024 static int pcache1Init(void *NotUsed){
41025 UNUSED_PARAMETER(NotUsed);
41026 assert( pcache1.isInit==0 );
41027 memset(&pcache1, 0, sizeof(pcache1));
41028
41029
41030 /*
41031 ** The pcache1.separateCache variable is true if each PCache has its own
41032 ** private PGroup (mode-1). pcache1.separateCache is false if the single
41033 ** PGroup in pcache1.grp is used for all page caches (mode-2).
41034 **
41035 ** * Always use a unified cache (mode-2) if ENABLE_MEMORY_MANAGEMENT
41036 **
41037 ** * Use a unified cache in single-threaded applications that have
41038 ** configured a start-time buffer for use as page-cache memory using
41039 ** sqlite3_config(SQLITE_CONFIG_PAGECACHE, pBuf, sz, N) with non-NULL
41040 ** pBuf argument.
41041 **
41042 ** * Otherwise use separate caches (mode-1)
41043 */
41044 #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT)
41045 pcache1.separateCache = 0;
41046 #elif SQLITE_THREADSAFE
41047 pcache1.separateCache = sqlite3GlobalConfig.pPage==0
41048 || sqlite3GlobalConfig.bCoreMutex>0;
41049 #else
41050 pcache1.separateCache = sqlite3GlobalConfig.pPage==0;
41051 #endif
41052
41053 #if SQLITE_THREADSAFE
41054 if( sqlite3GlobalConfig.bCoreMutex ){
41055 pcache1.grp.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU);
41056 pcache1.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PMEM);
41057 }
@@ -40955,52 +41083,65 @@
41083 static sqlite3_pcache *pcache1Create(int szPage, int szExtra, int bPurgeable){
41084 PCache1 *pCache; /* The newly created page cache */
41085 PGroup *pGroup; /* The group the new page cache will belong to */
41086 int sz; /* Bytes of memory required to allocate the new cache */
41087
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41088 assert( (szPage & (szPage-1))==0 && szPage>=512 && szPage<=65536 );
41089 assert( szExtra < 300 );
41090
41091 sz = sizeof(PCache1) + sizeof(PGroup)*pcache1.separateCache;
41092 pCache = (PCache1 *)sqlite3MallocZero(sz);
41093 if( pCache ){
41094 if( pcache1.separateCache ){
41095 pGroup = (PGroup*)&pCache[1];
41096 pGroup->mxPinned = 10;
41097 }else{
41098 pGroup = &pcache1.grp;
41099 }
41100 pCache->pGroup = pGroup;
41101 pCache->szPage = szPage;
41102 pCache->szExtra = szExtra;
41103 pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1));
41104 pCache->bPurgeable = (bPurgeable ? 1 : 0);
41105 pcache1EnterMutex(pGroup);
41106 pcache1ResizeHash(pCache);
41107 if( bPurgeable ){
41108 pCache->nMin = 10;
41109 pGroup->nMinPage += pCache->nMin;
41110 pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
41111 }
41112 pcache1LeaveMutex(pGroup);
41113 /* Try to initialize the local bulk pagecache line allocation if using
41114 ** separate caches and if nPage!=0 */
41115 if( pcache1.separateCache
41116 && sqlite3GlobalConfig.nPage!=0
41117 && sqlite3GlobalConfig.pPage==0
41118 ){
41119 int szBulk;
41120 char *zBulk;
41121 sqlite3BeginBenignMalloc();
41122 if( sqlite3GlobalConfig.nPage>0 ){
41123 szBulk = pCache->szAlloc * sqlite3GlobalConfig.nPage;
41124 }else{
41125 szBulk = -1024*sqlite3GlobalConfig.nPage;
41126 }
41127 zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
41128 sqlite3EndBenignMalloc();
41129 if( zBulk ){
41130 int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
41131 int i;
41132 for(i=0; i<nBulk; i++){
41133 PgHdr1 *pX = (PgHdr1*)&zBulk[szPage];
41134 pX->page.pBuf = zBulk;
41135 pX->page.pExtra = &pX[1];
41136 pX->isBulkLocal = 1;
41137 pX->pNext = pCache->pFree;
41138 pCache->pFree = pX;
41139 zBulk += pCache->szAlloc;
41140 }
41141 }
41142 }
41143 if( pCache->nHash==0 ){
41144 pcache1Destroy((sqlite3_pcache*)pCache);
41145 pCache = 0;
41146 }
41147 }
@@ -41090,30 +41231,21 @@
41231
41232 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
41233 assert( pCache->nHash>0 && pCache->apHash );
41234
41235 /* Step 4. Try to recycle a page. */
41236 if( pCache->bPurgeable
41237 && pGroup->pLruTail
41238 && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
41239 ){
 
41240 PCache1 *pOther;
41241 pPage = pGroup->pLruTail;
41242 assert( pPage->isPinned==0 );
41243 pcache1RemoveFromHash(pPage, 0);
41244 pcache1PinPage(pPage);
41245 pOther = pPage->pCache;
41246 if( pOther->szAlloc != pCache->szAlloc ){
 
 
 
 
 
 
 
 
41247 pcache1FreePage(pPage);
41248 pPage = 0;
41249 }else{
41250 pGroup->nCurrentPage -= (pOther->bPurgeable - pCache->bPurgeable);
41251 }
@@ -41385,10 +41517,11 @@
41517 assert( pGroup->nMinPage >= pCache->nMin );
41518 pGroup->nMinPage -= pCache->nMin;
41519 pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
41520 pcache1EnforceMaxPage(pGroup);
41521 pcache1LeaveMutex(pGroup);
41522 sqlite3_free(pCache->pBulk);
41523 sqlite3_free(pCache->apHash);
41524 sqlite3_free(pCache);
41525 }
41526
41527 /*
@@ -41440,11 +41573,11 @@
41573 */
41574 SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
41575 int nFree = 0;
41576 assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
41577 assert( sqlite3_mutex_notheld(pcache1.mutex) );
41578 if( sqlite3GlobalConfig.nPage==0 ){
41579 PgHdr1 *p;
41580 pcache1EnterMutex(&pcache1.grp);
41581 while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){
41582 nFree += pcache1MemSize(p->page.pBuf);
41583 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
@@ -62542,10 +62675,11 @@
62675 u32 *heap = 0; /* Min-heap used for checking cell coverage */
62676 u32 x, prev = 0; /* Next and previous entry on the min-heap */
62677 const char *saved_zPfx = pCheck->zPfx;
62678 int saved_v1 = pCheck->v1;
62679 int saved_v2 = pCheck->v2;
62680 u8 savedIsInit;
62681
62682 /* Check that the page exists
62683 */
62684 pBt = pCheck->pBt;
62685 usableSize = pBt->usableSize;
@@ -62559,10 +62693,11 @@
62693 goto end_of_check;
62694 }
62695
62696 /* Clear MemPage.isInit to make sure the corruption detection code in
62697 ** btreeInitPage() is executed. */
62698 savedIsInit = pPage->isInit;
62699 pPage->isInit = 0;
62700 if( (rc = btreeInitPage(pPage))!=0 ){
62701 assert( rc==SQLITE_CORRUPT ); /* The only possible error from InitPage */
62702 checkAppendMsg(pCheck,
62703 "btreeInitPage() returns error code %d", rc);
@@ -62700,11 +62835,11 @@
62835 while( i>0 ){
62836 int size, j;
62837 assert( (u32)i<=usableSize-4 ); /* Enforced by btreeInitPage() */
62838 size = get2byte(&data[i+2]);
62839 assert( (u32)(i+size)<=usableSize ); /* Enforced by btreeInitPage() */
62840 btreeHeapInsert(heap, (((u32)i)<<16)|(i+size-1));
62841 /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
62842 ** big-endian integer which is the offset in the b-tree page of the next
62843 ** freeblock in the chain, or zero if the freeblock is the last on the
62844 ** chain. */
62845 j = get2byte(&data[i]);
@@ -62751,10 +62886,11 @@
62886 nFrag, data[hdr+7], iPage);
62887 }
62888 }
62889
62890 end_of_check:
62891 if( !doCoverageCheck ) pPage->isInit = savedIsInit;
62892 releasePage(pPage);
62893 pCheck->zPfx = saved_zPfx;
62894 pCheck->v1 = saved_v1;
62895 pCheck->v2 = saved_v2;
62896 return depth+1;
@@ -69020,10 +69156,11 @@
69156 ** to ignore the compiler warnings and leave this variable uninitialized.
69157 */
69158 /* mem1.u.i = 0; // not needed, here to silence compiler warning */
69159
69160 idx1 = getVarint32(aKey1, szHdr1);
69161 if( szHdr1>98307 ) return SQLITE_CORRUPT;
69162 d1 = szHdr1;
69163 assert( pKeyInfo->nField+pKeyInfo->nXField>=pPKey2->nField || CORRUPT_DB );
69164 assert( pKeyInfo->aSortOrder!=0 );
69165 assert( pKeyInfo->nField>0 );
69166 assert( idx1<=szHdr1 || CORRUPT_DB );
@@ -109379,14 +109516,18 @@
109516 sqlite3VdbeResolveLabel(v, addrCont);
109517
109518 /* Execute the recursive SELECT taking the single row in Current as
109519 ** the value for the recursive-table. Store the results in the Queue.
109520 */
109521 if( p->selFlags & SF_Aggregate ){
109522 sqlite3ErrorMsg(pParse, "recursive aggregate queries not supported");
109523 }else{
109524 p->pPrior = 0;
109525 sqlite3Select(pParse, p, &destQueue);
109526 assert( p->pPrior==0 );
109527 p->pPrior = pSetup;
109528 }
109529
109530 /* Keep running the loop until the Queue is empty */
109531 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
109532 sqlite3VdbeResolveLabel(v, addrBreak);
109533
109534
+4 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111111
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112112
** [sqlite_version()] and [sqlite_source_id()].
113113
*/
114114
#define SQLITE_VERSION "3.8.11"
115115
#define SQLITE_VERSION_NUMBER 3008011
116
-#define SQLITE_SOURCE_ID "2015-07-03 17:54:49 030f60a7ba171650ce8c0ac32dc166eab80aca32"
116
+#define SQLITE_SOURCE_ID "2015-07-08 16:22:42 5348ffc3fda5168c1e9e14aa88b0c6aedbda7c94"
117117
118118
/*
119119
** CAPI3REF: Run-Time Library Version Numbers
120120
** KEYWORDS: sqlite3_version, sqlite3_sourceid
121121
**
@@ -6289,10 +6289,13 @@
62896289
#define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
62906290
#define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
62916291
#define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */
62926292
#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
62936293
#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6294
+#define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */
6295
+#define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */
6296
+#define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */
62946297
62956298
/*
62966299
** CAPI3REF: Retrieve the mutex for a database connection
62976300
** METHOD: sqlite3
62986301
**
62996302
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.8.11"
115 #define SQLITE_VERSION_NUMBER 3008011
116 #define SQLITE_SOURCE_ID "2015-07-03 17:54:49 030f60a7ba171650ce8c0ac32dc166eab80aca32"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
@@ -6289,10 +6289,13 @@
6289 #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
6290 #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
6291 #define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */
6292 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6293 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
 
 
 
6294
6295 /*
6296 ** CAPI3REF: Retrieve the mutex for a database connection
6297 ** METHOD: sqlite3
6298 **
6299
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.8.11"
115 #define SQLITE_VERSION_NUMBER 3008011
116 #define SQLITE_SOURCE_ID "2015-07-08 16:22:42 5348ffc3fda5168c1e9e14aa88b0c6aedbda7c94"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
@@ -6289,10 +6289,13 @@
6289 #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
6290 #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
6291 #define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */
6292 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6293 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
6294 #define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */
6295 #define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */
6296 #define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */
6297
6298 /*
6299 ** CAPI3REF: Retrieve the mutex for a database connection
6300 ** METHOD: sqlite3
6301 **
6302

Keyboard Shortcuts

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