From 115d663c05758e5d32a5c5123c1d7b4b5460ae7c Mon Sep 17 00:00:00 2001 From: numist Date: Thu, 12 Dec 2019 02:50:07 +0000 Subject: [PATCH 01/11] More efficient implementation of a lookaside allocator that supports mini (in this case, harcoded to 128B) slots. FossilOrigin-Name: b02fdc09c838f355d9efce57f817d6a86153153b4a1f2b763914f4aaa34cb76e --- manifest | 23 +++++++++++++---------- manifest.uuid | 2 +- src/main.c | 22 +++++++++++++++++++++- src/malloc.c | 36 +++++++++++++++++++++++++++++++++--- src/sqliteInt.h | 5 +++++ src/status.c | 13 +++++++++++++ 6 files changed, 86 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index 804a68c4d3..ca38c913ca 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sgoofy\sstring\sformatting\sin\slemon.c\sthat\sdates\sfrom\sthe\sK&R-C\sdays. -D 2019-12-12T00:20:40.700 +C More\sefficient\simplementation\sof\sa\slookaside\sallocator\sthat\ssupports\smini\s(in\sthis\scase,\sharcoded\sto\s128B)\sslots. +D 2019-12-12T02:50:07.468 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -491,8 +491,8 @@ F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 5de3fd62bd1a692353c8f9c7bbde658f0b579f195620ca3cde1948a53015dddd F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c d74f5e7bd51f3c9d283442473eb65aef359664efd6513591c03f01881c4ae2da -F src/main.c 868ae7db7a54fe859bf2ca8b7a4f24e9fa03a6134abfb7c9801d08411ef5dacb -F src/malloc.c 550021fcae36f0ffe9f8563d83e6385f9df307a854d55d7d0abb7241ee8dbcc6 +F src/main.c dc4fe09174ef0c11204ca90ed46323471c127c9d18266ec97ee1bca871200e99 +F src/malloc.c 350d345ab12aa089f3dbd30b4db9b57e486c9dd920d275d1775aa5b6899199ff F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 @@ -532,9 +532,9 @@ F src/shell.c.in 4a3a9e1c11847b1904f2b01d087af1c052f660902755abab457cab1756817de F src/sqlite.h.in 2a23e8161775253d9cf383c2c6aa559005dc787d350dcb0be67a6c4cc3bd1d19 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 72af51aa4e912e14cd495fb6e7fac65f0940db80ed950d90911aff292cc47ce2 -F src/sqliteInt.h 1ac4dfde728b9d5812d1223d668d5e1f43c6fe4f469d6a7a482f298a10a03210 +F src/sqliteInt.h 7965727cc420b5e9ab79f4ba8bda8e806ba315c6e9f489e83f0202f3397fb522 F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b -F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e +F src/status.c 0fe55b92810509eac821ded2e177e1da944a78cdcdfec7813ad1d6b36d6d667e F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 F src/tclsqlite.c 8cd2600e8de23dff6cdf84d39f46ca57139b061b28f6f80b166bace17d52ab1c F src/test1.c c654981c1d86ebc90dd23fcc0969e6c85e28112f0acc2e2224a97a2a33e7c42f @@ -1852,7 +1852,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4d6d2fc046d586a1e5989bbb2757f13d0371fbfad0acf45a0e2fd77dffd8d8f9 -R 5e026b3cfa5e818c2e50f705eaa7c6b6 -U drh -Z d2668f11b5269bc264b434444e0b4796 +P 48ba5e5a2227257cebafacbb09e9dd91d9b89ab2d52a8b4e4113c1d017d95f41 +R 7ee7a134ba45ae790f475dbb2e983799 +T *branch * mini-lookaside-take-2 +T *sym-mini-lookaside-take-2 * +T -sym-trunk * +U numist +Z aef044ee81b705b7df5a6b1d29e511a6 diff --git a/manifest.uuid b/manifest.uuid index 433b215c3e..c14893ca2e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -48ba5e5a2227257cebafacbb09e9dd91d9b89ab2d52a8b4e4113c1d017d95f41 \ No newline at end of file +b02fdc09c838f355d9efce57f817d6a86153153b4a1f2b763914f4aaa34cb76e \ No newline at end of file diff --git a/src/main.c b/src/main.c index 1afeee0bdb..96234bfe4a 100644 --- a/src/main.c +++ b/src/main.c @@ -683,6 +683,7 @@ int sqlite3_config(int op, ...){ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ #ifndef SQLITE_OMIT_LOOKASIDE void *pStart; + sqlite3_int64 szAlloc = sz*(sqlite3_int64)cnt; if( sqlite3LookasideUsed(db,0)>0 ){ return SQLITE_BUSY; @@ -705,7 +706,7 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ pStart = 0; }else if( pBuf==0 ){ sqlite3BeginBenignMalloc(); - pStart = sqlite3Malloc( sz*(sqlite3_int64)cnt ); /* IMP: R-61949-35727 */ + pStart = sqlite3Malloc( szAlloc ); /* IMP: R-61949-35727 */ sqlite3EndBenignMalloc(); if( pStart ) cnt = sqlite3MallocSize(pStart)/sz; }else{ @@ -714,6 +715,15 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ db->lookaside.pStart = pStart; db->lookaside.pInit = 0; db->lookaside.pFree = 0; +#ifndef SQLITE_OMIT_MINI_LOOKASIDE + db->lookaside.pMiniInit = 0; + db->lookaside.pMiniFree = 0; + /* The arithmetic below causes the number of large lookaside slots to be 1/3 + ** the number of mini slots, based on the observation that 75% of allocations + ** are <=128B. + */ + cnt = szAlloc/(3*128+sz); +#endif db->lookaside.sz = (u16)sz; db->lookaside.szTrue = (u16)sz; if( pStart ){ @@ -727,6 +737,16 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ db->lookaside.pInit = p; p = (LookasideSlot*)&((u8*)p)[sz]; } +#ifndef SQLITE_OMIT_MINI_LOOKASIDE + db->lookaside.pMiddle = p; + /* Fill the remainder of the buffer with mini slots */ + while(p<=(LookasideSlot*)&((u8*)pStart)[szAlloc-128]){ + p->pNext = db->lookaside.pMiniInit; + db->lookaside.pMiniInit = p; + db->lookaside.nSlot++; + p = (LookasideSlot*)&((u8*)p)[128]; + } +#endif db->lookaside.pEnd = p; db->lookaside.bDisable = 0; db->lookaside.bMalloced = pBuf==0 ?1:0; diff --git a/src/malloc.c b/src/malloc.c index 131ed6039a..9241b97c73 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -332,6 +332,13 @@ int sqlite3MallocSize(void *p){ assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); return sqlite3GlobalConfig.m.xSize(p); } +static int lookasideMallocSize(sqlite3 *db, void *p){ +#ifndef SQLITE_OMIT_MINI_LOOKASIDE + return plookaside.pMiddle ? db->lookaside.szTrue : 128; +#else + return db->lookaside.szTrue; +#endif +} int sqlite3DbMallocSize(sqlite3 *db, void *p){ assert( p!=0 ); if( db==0 || !isLookaside(db,p) ){ @@ -347,7 +354,7 @@ int sqlite3DbMallocSize(sqlite3 *db, void *p){ return sqlite3GlobalConfig.m.xSize(p); }else{ assert( sqlite3_mutex_held(db->mutex) ); - return db->lookaside.szTrue; + return lookasideMallocSize(db, p); } } sqlite3_uint64 sqlite3_msize(void *p){ @@ -397,6 +404,17 @@ void sqlite3DbFreeNN(sqlite3 *db, void *p){ } if( isLookaside(db, p) ){ LookasideSlot *pBuf = (LookasideSlot*)p; +#ifndef SQLITE_OMIT_MINI_LOOKASIDE + if( p>=db->lookaside.pMiddle ){ +# ifdef SQLITE_DEBUG + /* Trash all content in the buffer being freed */ + memset(p, 0xaa, 128); +# endif + pBuf->pNext = db->lookaside.pMiniFree; + db->lookaside.pMiniFree = pBuf; + return; + } +#endif #ifdef SQLITE_DEBUG /* Trash all content in the buffer being freed */ memset(p, 0xaa, db->lookaside.szTrue); @@ -564,6 +582,18 @@ void *sqlite3DbMallocRawNN(sqlite3 *db, u64 n){ return db->mallocFailed ? 0 : dbMallocRawFinish(db, n); } db->lookaside.anStat[1]++; +# ifndef SQLITE_OMIT_MINI_LOOKASIDE + }else if( n<=128 ){ + if( (pBuf = db->lookaside.pMiniFree)!=0 ){ + db->lookaside.pMiniFree = pBuf->pNext; + db->lookaside.anStat[0]++; + return (void*)pBuf; + }else if( (pBuf = db->lookaside.pMiniInit)!=0 ){ + db->lookaside.pMiniInit = pBuf->pNext; + db->lookaside.anStat[0]++; + return (void*)pBuf; + } +# endif }else if( (pBuf = db->lookaside.pFree)!=0 ){ db->lookaside.pFree = pBuf->pNext; db->lookaside.anStat[0]++; @@ -597,7 +627,7 @@ void *sqlite3DbRealloc(sqlite3 *db, void *p, u64 n){ assert( db!=0 ); if( p==0 ) return sqlite3DbMallocRawNN(db, n); assert( sqlite3_mutex_held(db->mutex) ); - if( isLookaside(db,p) && n<=db->lookaside.szTrue ) return p; + if( isLookaside(db,p) && nlookaside.szTrue); + memcpy(pNew, p, lookasideMallocSize(db, p)); sqlite3DbFree(db, p); } }else{ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 2aca2abfa9..5280923378 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1287,6 +1287,11 @@ struct Lookaside { u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */ LookasideSlot *pInit; /* List of buffers not previously used */ LookasideSlot *pFree; /* List of available buffers */ +#ifndef SQLITE_OMIT_MINI_LOOKASIDE + LookasideSlot *pMiniInit; /* List of mini buffers not prediously used */ + LookasideSlot *pMiniFree; /* List of available mini buffers */ + void *pMiddle; /* An address between the fullsize and mini buffers */ +#endif void *pStart; /* First byte of available memory space */ void *pEnd; /* First byte past end of available space */ }; diff --git a/src/status.c b/src/status.c index a5a39f4c18..d7ffe99ede 100644 --- a/src/status.c +++ b/src/status.c @@ -188,6 +188,10 @@ static u32 countLookasideSlots(LookasideSlot *p){ int sqlite3LookasideUsed(sqlite3 *db, int *pHighwater){ u32 nInit = countLookasideSlots(db->lookaside.pInit); u32 nFree = countLookasideSlots(db->lookaside.pFree); +#ifndef SQLITE_OMIT_MINI_LOOKASIDE + nInit += countLookasideSlots(db->lookaside.pMiniInit); + nFree += countLookasideSlots(db->lookaside.pMiniFree); +#endif if( pHighwater ) *pHighwater = db->lookaside.nSlot - nInit; return db->lookaside.nSlot - (nInit+nFree); } @@ -220,6 +224,15 @@ int sqlite3_db_status( db->lookaside.pInit = db->lookaside.pFree; db->lookaside.pFree = 0; } +#ifndef SQLITE_OMIT_MINI_LOOKASIDE + p = db->lookaside.pMiniFree; + if( p ){ + while( p->pNext ) p = p->pNext; + p->pNext = db->lookaside.pMiniInit; + db->lookaside.pMiniInit = db->lookaside.pMiniFree; + db->lookaside.pMiniFree = 0; + } +#endif } break; } From 0225d819c4ca87cd29cd6f58d50c75bcee6213bc Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 12 Dec 2019 17:17:24 +0000 Subject: [PATCH 02/11] Change the size of a mini-lookaside allocation to a macro (MINI_SZ) rather than a magic number (128). FossilOrigin-Name: 5e1949bca998f3c8c23a8ebf01c7a2e7a2af1fdad43886271e1fe0f25411551d --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/main.c | 8 ++++---- src/malloc.c | 6 +++--- src/sqliteInt.h | 3 +++ 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index 146060627c..2120e5d6cd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\senhancements\sfrom\strunk. -D 2019-12-12T16:49:10.371 +C Change\sthe\ssize\sof\sa\smini-lookaside\sallocation\sto\sa\smacro\s(MINI_SZ)\srather\nthan\sa\smagic\snumber\s(128). +D 2019-12-12T17:17:24.501 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -491,8 +491,8 @@ F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 5de3fd62bd1a692353c8f9c7bbde658f0b579f195620ca3cde1948a53015dddd F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c d74f5e7bd51f3c9d283442473eb65aef359664efd6513591c03f01881c4ae2da -F src/main.c dc4fe09174ef0c11204ca90ed46323471c127c9d18266ec97ee1bca871200e99 -F src/malloc.c 350d345ab12aa089f3dbd30b4db9b57e486c9dd920d275d1775aa5b6899199ff +F src/main.c 94bf8b6a283914cc8fa8743b3db5350206a4be5cccfd9c84d53409ca5d8bd1c1 +F src/malloc.c 8a907f9e802ff517acb5e9edc13798428fd7668136456d9432a884a7fe5680f5 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 @@ -532,7 +532,7 @@ F src/shell.c.in 4a3a9e1c11847b1904f2b01d087af1c052f660902755abab457cab1756817de F src/sqlite.h.in 2a23e8161775253d9cf383c2c6aa559005dc787d350dcb0be67a6c4cc3bd1d19 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 72af51aa4e912e14cd495fb6e7fac65f0940db80ed950d90911aff292cc47ce2 -F src/sqliteInt.h 7965727cc420b5e9ab79f4ba8bda8e806ba315c6e9f489e83f0202f3397fb522 +F src/sqliteInt.h fad2ac9bc3957bd090ca979e012b744caa60529411a6ab6d379b902983f84134 F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c 0fe55b92810509eac821ded2e177e1da944a78cdcdfec7813ad1d6b36d6d667e F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 @@ -1852,7 +1852,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b02fdc09c838f355d9efce57f817d6a86153153b4a1f2b763914f4aaa34cb76e c6af9f655b73200ecc0c4189698e421af6ca584babdc76e73a36d468b2eea1f9 -R acd8cbaefaeedad19b6643abb0f66a70 +P 6cb053f99b5be2ecc30e0733d8f1e4f2a89f642656d3883fc0c867b10a87ba6b +R 795bb9e2b806be9ab8e7aa8c719a5a17 U drh -Z 68e3e8eeb067499423bb6b0f8443d732 +Z 49d95eecb36c694ed8db26c3a8686826 diff --git a/manifest.uuid b/manifest.uuid index 1583d58553..8da8683c68 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6cb053f99b5be2ecc30e0733d8f1e4f2a89f642656d3883fc0c867b10a87ba6b \ No newline at end of file +5e1949bca998f3c8c23a8ebf01c7a2e7a2af1fdad43886271e1fe0f25411551d \ No newline at end of file diff --git a/src/main.c b/src/main.c index 96234bfe4a..5b70273af2 100644 --- a/src/main.c +++ b/src/main.c @@ -720,9 +720,9 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ db->lookaside.pMiniFree = 0; /* The arithmetic below causes the number of large lookaside slots to be 1/3 ** the number of mini slots, based on the observation that 75% of allocations - ** are <=128B. + ** are <= MINI_SZ bytes. */ - cnt = szAlloc/(3*128+sz); + cnt = szAlloc/(3*MINI_SZ+sz); #endif db->lookaside.sz = (u16)sz; db->lookaside.szTrue = (u16)sz; @@ -740,11 +740,11 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ #ifndef SQLITE_OMIT_MINI_LOOKASIDE db->lookaside.pMiddle = p; /* Fill the remainder of the buffer with mini slots */ - while(p<=(LookasideSlot*)&((u8*)pStart)[szAlloc-128]){ + while(p<=(LookasideSlot*)&((u8*)pStart)[szAlloc-MINI_SZ]){ p->pNext = db->lookaside.pMiniInit; db->lookaside.pMiniInit = p; db->lookaside.nSlot++; - p = (LookasideSlot*)&((u8*)p)[128]; + p = (LookasideSlot*)&((u8*)p)[MINI_SZ]; } #endif db->lookaside.pEnd = p; diff --git a/src/malloc.c b/src/malloc.c index 9241b97c73..8f77c96438 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -334,7 +334,7 @@ int sqlite3MallocSize(void *p){ } static int lookasideMallocSize(sqlite3 *db, void *p){ #ifndef SQLITE_OMIT_MINI_LOOKASIDE - return plookaside.pMiddle ? db->lookaside.szTrue : 128; + return plookaside.pMiddle ? db->lookaside.szTrue : MINI_SZ; #else return db->lookaside.szTrue; #endif @@ -408,7 +408,7 @@ void sqlite3DbFreeNN(sqlite3 *db, void *p){ if( p>=db->lookaside.pMiddle ){ # ifdef SQLITE_DEBUG /* Trash all content in the buffer being freed */ - memset(p, 0xaa, 128); + memset(p, 0xaa, MINI_SZ); # endif pBuf->pNext = db->lookaside.pMiniFree; db->lookaside.pMiniFree = pBuf; @@ -583,7 +583,7 @@ void *sqlite3DbMallocRawNN(sqlite3 *db, u64 n){ } db->lookaside.anStat[1]++; # ifndef SQLITE_OMIT_MINI_LOOKASIDE - }else if( n<=128 ){ + }else if( n<=MINI_SZ ){ if( (pBuf = db->lookaside.pMiniFree)!=0 ){ db->lookaside.pMiniFree = pBuf->pNext; db->lookaside.anStat[0]++; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 5280923378..d01c8128b8 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1303,6 +1303,9 @@ struct LookasideSlot { #define EnableLookaside db->lookaside.bDisable--;\ db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue +/* Size of the MINI lookside allocation */ +#define MINI_SZ 128 + /* ** A hash table for built-in function definitions. (Application-defined ** functions use a regular table table from hash.h.) From 41cee66848afe40aba1e4d4a83bd50b6c33aaff0 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 12 Dec 2019 20:22:34 +0000 Subject: [PATCH 03/11] Change the name of the Expr.a.zName field to zEName, so that it has a name that is distinct from other fields and variables and is hence easier to grep for. FossilOrigin-Name: d3783357f8fa76c42a86f12b214522f0388c37773c36ab8c5ce0623abbc4436a --- manifest | 30 +++++++++++++++--------------- manifest.uuid | 2 +- src/alter.c | 8 ++++---- src/build.c | 14 +++++++------- src/expr.c | 20 ++++++++++---------- src/insert.c | 2 +- src/resolve.c | 4 ++-- src/select.c | 14 +++++++------- src/sqliteInt.h | 2 +- src/treeview.c | 4 ++-- src/trigger.c | 2 +- src/update.c | 6 +++--- 12 files changed, 54 insertions(+), 54 deletions(-) diff --git a/manifest b/manifest index 2120e5d6cd..d0515a9c87 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\ssize\sof\sa\smini-lookaside\sallocation\sto\sa\smacro\s(MINI_SZ)\srather\nthan\sa\smagic\snumber\s(128). -D 2019-12-12T17:17:24.501 +C Change\sthe\sname\sof\sthe\sExpr.a.zName\sfield\sto\szEName,\sso\sthat\sit\shas\sa\sname\nthat\sis\sdistinct\sfrom\sother\sfields\sand\svariables\sand\sis\shence\seasier\sto\ngrep\sfor. +D 2019-12-12T20:22:34.557 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -461,7 +461,7 @@ F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a -F src/alter.c 9b3d6f8d3437f0bec3f9a4ebfa9fa4e7e3b34730631611b6d30f6ae1027bf3db +F src/alter.c 27aaf1045f52876320b431f4b45d9c1e5786899de41cec2bea39620095ab9aa7 F src/analyze.c b3ceec3fc052df8a96ca8a8c858d455dc5029ba681b4be98bb5c5a9162cfa58c F src/attach.c b30c44333d55a68c0a12920b5b9d40b254cbd3d4509bda77417209eeed8b3d80 F src/auth.c a3d5bfdba83d25abed1013a8c7a5f204e2e29b0c25242a56bc02bb0c07bf1e06 @@ -471,7 +471,7 @@ F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 F src/btree.c d22498af716953400e314d2d98d1dac3ea5c3b01e0fd243ef9e9b132c74114ec F src/btree.h f27a33c49280209a93385e218306c4ee5f46ba8d7649d2f81a7166b282232484 F src/btreeInt.h 91806f01fd1145a9a86ba3042f25c38d8faf6002701bf5e780742cf88bcff437 -F src/build.c 7c277ccc24c249b84f29ba829b0ed377e78487c93d17d999798641be0c20fad5 +F src/build.c ec3332b5ff5871a5e134889392e7d9340a2c274b292b1674b595a7835c4908ad F src/callback.c 88615dfc0a82167b65b452b4b305dbf86be77200b3343c6ffc6d03e92a01d181 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 1b0724e66f95f33b160b1af85caaf9cceb325d22abf39bd24df4f54a73982251 @@ -479,7 +479,7 @@ F src/date.c e1d8ac7102f3f283e63e13867acb0efa33861cf34f0faf4cdbaf9fa7a1eb7041 F src/dbpage.c 135eb3b5e74f9ef74bde5cec2571192c90c86984fa534c88bf4a055076fa19b7 F src/dbstat.c 6c407e549406c10fde9ac3987f6d734459205239ad370369bc5fcd683084a4fa F src/delete.c a5c59b9c0251cf7682bc52af0d64f09b1aefc6781a63592c8f1136f7b73c66e4 -F src/expr.c 947911a1826673add2311e8650aeaf9c2809706dfaa45fc2445a5ff32f70693d +F src/expr.c eefc9abca2d8bb8b2cad063dd65c764e5264f1d80c83268a9debcfff2f7a32bb F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 92a248ec0fa4ed8ab60c98d9b188ce173aaf218f32e7737ba77deb2a684f9847 F src/func.c ed33e38cd642058182a31a3f518f2e34f4bbe53aa483335705c153c4d3e50b12 @@ -488,7 +488,7 @@ F src/hash.c 8d7dda241d0ebdafb6ffdeda3149a412d7df75102cecfc1021c98d6219823b19 F src/hash.h 9d56a9079d523b648774c1784b74b89bd93fac7b365210157482e4319a468f38 F src/hwtime.h cb1d7e3e1ed94b7aa6fde95ae2c2daccc3df826be26fc9ed7fd90d1750ae6144 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 -F src/insert.c 5de3fd62bd1a692353c8f9c7bbde658f0b579f195620ca3cde1948a53015dddd +F src/insert.c 276463aa7a26ee73958b9f4bcbef4eaec516f22bf6b8d7d2428f39c8dea90840 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c d74f5e7bd51f3c9d283442473eb65aef359664efd6513591c03f01881c4ae2da F src/main.c 94bf8b6a283914cc8fa8743b3db5350206a4be5cccfd9c84d53409ca5d8bd1c1 @@ -525,14 +525,14 @@ F src/pragma.h ec3b31eac9b1df040f1cc8cb3d89bc06605c3b4cb3d76f833de8d6d6c3f77f04 F src/prepare.c 6049beb71385f017af6fc320d2c75a4e50b75e280c54232442b785fbb83df057 F src/printf.c 9be6945837c839ba57837b4bc3af349eba630920fa5532aa518816defe42a7d4 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 -F src/resolve.c acc54d97e7e867a76e4e0fe407589be9a390f579e6a6a36fe4a0f62f7678d4e4 +F src/resolve.c d703803412770e100be0d79adc4d0b52a99c49715ba8d4a736e503ee5526d473 F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93 -F src/select.c 0fe10579de20eb8dc04ec9ed29659fa782bee2bcc85a35734637f3e2cabc2762 +F src/select.c 39a9e180a2fdf738f3a02977684bc4cad3f5ff8d9f949f2aa48eef2ce5ff29aa F src/shell.c.in 4a3a9e1c11847b1904f2b01d087af1c052f660902755abab457cab1756817ded F src/sqlite.h.in 2a23e8161775253d9cf383c2c6aa559005dc787d350dcb0be67a6c4cc3bd1d19 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 72af51aa4e912e14cd495fb6e7fac65f0940db80ed950d90911aff292cc47ce2 -F src/sqliteInt.h fad2ac9bc3957bd090ca979e012b744caa60529411a6ab6d379b902983f84134 +F src/sqliteInt.h ebb8c7e6439dc4cd6abad9fed0d01751160115328c8670b733505d7c5c6b12a4 F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c 0fe55b92810509eac821ded2e177e1da944a78cdcdfec7813ad1d6b36d6d667e F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 @@ -592,9 +592,9 @@ F src/test_window.c cdae419fdcea5bad6dcd9368c685abdad6deb59e9fc8b84b153de513d394 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c F src/tokenize.c 7b17f6e2f20f6cbcb0b215025a86b7457c38451fc7622f705e553d7a488c572d -F src/treeview.c 41d928f04d65931b15f629b4938e9f2c7dc259f02eef34cb2cc6e293f5af813f -F src/trigger.c 681ccdb910a87243940d63f99b26190d9c5d2534c2ded3c0825b7c0e315a342e -F src/update.c 07a50767f7d3e26d4c887c31cd66448d700d3215caea6023acf7269336097df7 +F src/treeview.c b36e832d4d17ba1abe7739a7a91f1432012c5ada762fb47bfec6fc9ab969af60 +F src/trigger.c a40d50e88bd3355f1d2a73f0a3b2d6b42eae26ca4219001b82ef0d064439badc +F src/update.c c66576a821d4821eda6b40c6aabc646cac5c9eb80f4987cc901db8657549c782 F src/upsert.c b445315c8958d8f17ec3297d06842e61dacaad0633ccaec1e4e160de7e562212 F src/utf.c 2f0fac345c7660d5c5bd3df9e9d8d33d4c27f366bcfb09e07443064d751a0507 F src/util.c 66b22af7b359ce6493c34fef28c87d5c2d1765f212d6e4cd5e08d99ac30b89bb @@ -1852,7 +1852,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 6cb053f99b5be2ecc30e0733d8f1e4f2a89f642656d3883fc0c867b10a87ba6b -R 795bb9e2b806be9ab8e7aa8c719a5a17 +P 5e1949bca998f3c8c23a8ebf01c7a2e7a2af1fdad43886271e1fe0f25411551d +R 251e88e80ae4e78253d2ec11ee9fa128 U drh -Z 49d95eecb36c694ed8db26c3a8686826 +Z c4130ee4f36c72a8f85ea58dbfd139dc diff --git a/manifest.uuid b/manifest.uuid index 8da8683c68..17e6a5e49d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5e1949bca998f3c8c23a8ebf01c7a2e7a2af1fdad43886271e1fe0f25411551d \ No newline at end of file +d3783357f8fa76c42a86f12b214522f0388c37773c36ab8c5ce0623abbc4436a \ No newline at end of file diff --git a/src/alter.c b/src/alter.c index 0fe41bd2f1..f3467fa09e 100644 --- a/src/alter.c +++ b/src/alter.c @@ -764,8 +764,8 @@ static int renameUnmapSelectCb(Walker *pWalker, Select *p){ if( ALWAYS(p->pEList) ){ ExprList *pList = p->pEList; for(i=0; inExpr; i++){ - if( pList->a[i].zName ){ - sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zName); + if( pList->a[i].zEName ){ + sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName); } } } @@ -808,7 +808,7 @@ void sqlite3RenameExprlistUnmap(Parse *pParse, ExprList *pEList){ sWalker.xExprCallback = renameUnmapExprCb; sqlite3WalkExprList(&sWalker, pEList); for(i=0; inExpr; i++){ - sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zName); + sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName); } } } @@ -946,7 +946,7 @@ static void renameColumnElistNames( if( pEList ){ int i; for(i=0; inExpr; i++){ - char *zName = pEList->a[i].zName; + char *zName = pEList->a[i].zEName; if( 0==sqlite3_stricmp(zName, zOld) ){ renameTokenFind(pParse, pCtx, (void*)zName); } diff --git a/src/build.c b/src/build.c index 171cc68cf4..196b35acff 100644 --- a/src/build.c +++ b/src/build.c @@ -3091,7 +3091,7 @@ void sqlite3CreateForeignKey( nByte = sizeof(*pFKey) + (nCol-1)*sizeof(pFKey->aCol[0]) + pTo->n + 1; if( pToCol ){ for(i=0; inExpr; i++){ - nByte += sqlite3Strlen30(pToCol->a[i].zName) + 1; + nByte += sqlite3Strlen30(pToCol->a[i].zEName) + 1; } } pFKey = sqlite3DbMallocZero(db, nByte ); @@ -3116,7 +3116,7 @@ void sqlite3CreateForeignKey( for(i=0; inCol; j++){ - if( sqlite3StrICmp(p->aCol[j].zName, pFromCol->a[i].zName)==0 ){ + if( sqlite3StrICmp(p->aCol[j].zName, pFromCol->a[i].zEName)==0 ){ pFKey->aCol[i].iFrom = j; break; } @@ -3124,22 +3124,22 @@ void sqlite3CreateForeignKey( if( j>=p->nCol ){ sqlite3ErrorMsg(pParse, "unknown column \"%s\" in foreign key definition", - pFromCol->a[i].zName); + pFromCol->a[i].zEName); goto fk_end; } if( IN_RENAME_OBJECT ){ - sqlite3RenameTokenRemap(pParse, &pFKey->aCol[i], pFromCol->a[i].zName); + sqlite3RenameTokenRemap(pParse, &pFKey->aCol[i], pFromCol->a[i].zEName); } } } if( pToCol ){ for(i=0; ia[i].zName); + int n = sqlite3Strlen30(pToCol->a[i].zEName); pFKey->aCol[i].zCol = z; if( IN_RENAME_OBJECT ){ - sqlite3RenameTokenRemap(pParse, z, pToCol->a[i].zName); + sqlite3RenameTokenRemap(pParse, z, pToCol->a[i].zEName); } - memcpy(z, pToCol->a[i].zName, n); + memcpy(z, pToCol->a[i].zEName, n); z[n] = 0; z += n+1; } diff --git a/src/expr.c b/src/expr.c index 3b2b513b6d..f9c57baa9c 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1436,7 +1436,7 @@ ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){ pNewExpr->pLeft = pPriorSelectCol; } } - pItem->zName = sqlite3DbStrDup(db, pOldItem->zName); + pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName); pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan); pItem->sortFlags = pOldItem->sortFlags; pItem->done = 0; @@ -1608,9 +1608,9 @@ ExprList *sqlite3ExprListAppend( pList = pNew; } pItem = &pList->a[pList->nExpr++]; - assert( offsetof(struct ExprList_item,zName)==sizeof(pItem->pExpr) ); + assert( offsetof(struct ExprList_item,zEName)==sizeof(pItem->pExpr) ); assert( offsetof(struct ExprList_item,pExpr)==0 ); - memset(&pItem->zName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zName)); + memset(&pItem->zEName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zEName)); pItem->pExpr = pExpr; return pList; @@ -1667,7 +1667,7 @@ ExprList *sqlite3ExprListAppendVector( pList = sqlite3ExprListAppend(pParse, pList, pSubExpr); if( pList ){ assert( pList->nExpr==iFirst+i+1 ); - pList->a[pList->nExpr-1].zName = pColumns->a[i].zName; + pList->a[pList->nExpr-1].zEName = pColumns->a[i].zName; pColumns->a[i].zName = 0; } } @@ -1727,7 +1727,7 @@ void sqlite3ExprListSetSortOrder(ExprList *p, int iSortOrder, int eNulls){ } /* -** Set the ExprList.a[].zName element of the most recently added item +** Set the ExprList.a[].zEName element of the most recently added item ** on the expression list. ** ** pList might be NULL following an OOM error. But pName should never be @@ -1745,11 +1745,11 @@ void sqlite3ExprListSetName( struct ExprList_item *pItem; assert( pList->nExpr>0 ); pItem = &pList->a[pList->nExpr-1]; - assert( pItem->zName==0 ); - pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n); - if( dequote ) sqlite3Dequote(pItem->zName); + assert( pItem->zEName==0 ); + pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n); + if( dequote ) sqlite3Dequote(pItem->zEName); if( IN_RENAME_OBJECT ){ - sqlite3RenameTokenMap(pParse, (void*)pItem->zName, pName); + sqlite3RenameTokenMap(pParse, (void*)pItem->zEName, pName); } } } @@ -1804,7 +1804,7 @@ static SQLITE_NOINLINE void exprListDeleteNN(sqlite3 *db, ExprList *pList){ assert( pList->nExpr>0 ); do{ sqlite3ExprDelete(db, pItem->pExpr); - sqlite3DbFree(db, pItem->zName); + sqlite3DbFree(db, pItem->zEName); sqlite3DbFree(db, pItem->zSpan); pItem++; }while( --i>0 ); diff --git a/src/insert.c b/src/insert.c index 5915f4fa95..75db131774 100644 --- a/src/insert.c +++ b/src/insert.c @@ -1635,7 +1635,7 @@ void sqlite3GenerateConstraintChecks( if( onError==OE_Ignore ){ sqlite3VdbeGoto(v, ignoreDest); }else{ - char *zName = pCheck->a[i].zName; + char *zName = pCheck->a[i].zEName; if( zName==0 ) zName = pTab->zName; if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-26383-51744 */ sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_CHECK, diff --git a/src/resolve.c b/src/resolve.c index 85db915cf1..b3c331535e 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -448,7 +448,7 @@ static int lookupName( pEList = pNC->uNC.pEList; assert( pEList!=0 ); for(j=0; jnExpr; j++){ - char *zAs = pEList->a[j].zName; + char *zAs = pEList->a[j].zEName; if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){ Expr *pOrig; assert( pExpr->pLeft==0 && pExpr->pRight==0 ); @@ -1115,7 +1115,7 @@ static int resolveAsName( if( pE->op==TK_ID ){ char *zCol = pE->u.zToken; for(i=0; inExpr; i++){ - char *zAs = pEList->a[i].zName; + char *zAs = pEList->a[i].zEName; if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){ return i+1; } diff --git a/src/select.c b/src/select.c index 26c72d6dad..b99b1459be 100644 --- a/src/select.c +++ b/src/select.c @@ -918,7 +918,7 @@ static void selectInnerLoop( if( srcTab>=0 ){ for(i=0; ipEList->a[i].zName)); + VdbeComment((v, "%s", p->pEList->a[i].zEName)); } }else if( eDest!=SRT_Exists ){ #ifdef SQLITE_ENABLE_SORTER_REFERENCES @@ -1539,7 +1539,7 @@ static void generateSortTail( iRead = iCol--; } sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iRead, regRow+i); - VdbeComment((v, "%s", aOutEx[i].zName?aOutEx[i].zName : aOutEx[i].zSpan)); + VdbeComment((v, "%s", aOutEx[i].zEName?aOutEx[i].zEName:aOutEx[i].zSpan)); } } switch( eDest ){ @@ -1873,9 +1873,9 @@ static void generateColumnNames( assert( p!=0 ); assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */ assert( p->op!=TK_COLUMN || p->y.pTab!=0 ); /* Covering idx not yet coded */ - if( pEList->a[i].zName ){ + if( pEList->a[i].zEName ){ /* An AS clause always takes first priority */ - char *zName = pEList->a[i].zName; + char *zName = pEList->a[i].zEName; sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT); }else if( srcName && p->op==TK_COLUMN ){ char *zCol; @@ -1959,7 +1959,7 @@ int sqlite3ColumnsFromExprList( for(i=0, pCol=aCol; imallocFailed; i++, pCol++){ /* Get an appropriate name for the column */ - if( (zName = pEList->a[i].zName)!=0 ){ + if( (zName = pEList->a[i].zEName)!=0 ){ /* If the column contains an "AS " phrase, use as the name */ }else{ Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr); @@ -5003,9 +5003,9 @@ static int selectExpander(Walker *pWalker, Select *p){ */ pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr); if( pNew ){ - pNew->a[pNew->nExpr-1].zName = a[k].zName; + pNew->a[pNew->nExpr-1].zEName = a[k].zEName; pNew->a[pNew->nExpr-1].zSpan = a[k].zSpan; - a[k].zName = 0; + a[k].zEName = 0; a[k].zSpan = 0; } a[k].pExpr = 0; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index d01c8128b8..3de659f791 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2662,7 +2662,7 @@ struct ExprList { int nExpr; /* Number of expressions on the list */ struct ExprList_item { /* For each expression in the list */ Expr *pExpr; /* The parse tree for this expression */ - char *zName; /* Token associated with this expression */ + char *zEName; /* Token associated with this expression */ char *zSpan; /* Original text of the expression */ u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */ unsigned done :1; /* A flag to indicate when processing is finished */ diff --git a/src/treeview.c b/src/treeview.c index 5b9e064540..ac0e92a08f 100644 --- a/src/treeview.c +++ b/src/treeview.c @@ -106,7 +106,7 @@ void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){ char cSep = '('; int j; for(j=0; jpCols->nExpr; j++){ - sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zName); + sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zEName); cSep = ','; } sqlite3_str_appendf(&x, ")"); @@ -727,7 +727,7 @@ void sqlite3TreeViewBareExprList( sqlite3TreeViewLine(pView, "%s", zLabel); for(i=0; inExpr; i++){ int j = pList->a[i].u.x.iOrderByCol; - char *zName = pList->a[i].zName; + char *zName = pList->a[i].zEName; int moreToFollow = inExpr - 1; if( j || zName ){ sqlite3TreeViewPush(pView, moreToFollow); diff --git a/src/trigger.c b/src/trigger.c index 5586995e32..458aa2996c 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -688,7 +688,7 @@ static int checkColumnOverlap(IdList *pIdList, ExprList *pEList){ int e; if( pIdList==0 || NEVER(pEList==0) ) return 1; for(e=0; enExpr; e++){ - if( sqlite3IdListIndex(pIdList, pEList->a[e].zName)>=0 ) return 1; + if( sqlite3IdListIndex(pIdList, pEList->a[e].zEName)>=0 ) return 1; } return 0; } diff --git a/src/update.c b/src/update.c index 935e1d9377..f4e8f696d2 100644 --- a/src/update.c +++ b/src/update.c @@ -305,7 +305,7 @@ void sqlite3Update( goto update_cleanup; } for(j=0; jnCol; j++){ - if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){ + if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zEName)==0 ){ if( j==pTab->iPKey ){ chngRowid = 1; pRowidExpr = pChanges->a[i].pExpr; @@ -327,12 +327,12 @@ void sqlite3Update( } } if( j>=pTab->nCol ){ - if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zName) ){ + if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zEName) ){ j = -1; chngRowid = 1; pRowidExpr = pChanges->a[i].pExpr; }else{ - sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName); + sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zEName); pParse->checkSchema = 1; goto update_cleanup; } From c947d6a4dcdfe6f0185a22464cf97153cabb8052 Mon Sep 17 00:00:00 2001 From: numist Date: Thu, 12 Dec 2019 20:39:47 +0000 Subject: [PATCH 04/11] Fix an issue where malloc could be used to fulfill a small allocation when a large lookaside slot could have beeen used instead. FossilOrigin-Name: 611020e3378f4c81c277cccd84807ae51a816bbab6c3d887c91c5e5af3b5225f --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/malloc.c | 7 +++++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index d0515a9c87..5f8fb620c5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\sname\sof\sthe\sExpr.a.zName\sfield\sto\szEName,\sso\sthat\sit\shas\sa\sname\nthat\sis\sdistinct\sfrom\sother\sfields\sand\svariables\sand\sis\shence\seasier\sto\ngrep\sfor. -D 2019-12-12T20:22:34.557 +C Fix\san\sissue\swhere\smalloc\scould\sbe\sused\sto\sfulfill\sa\ssmall\sallocation\swhen\sa\slarge\slookaside\sslot\scould\shave\sbeeen\sused\sinstead. +D 2019-12-12T20:39:47.705 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -492,7 +492,7 @@ F src/insert.c 276463aa7a26ee73958b9f4bcbef4eaec516f22bf6b8d7d2428f39c8dea90840 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c d74f5e7bd51f3c9d283442473eb65aef359664efd6513591c03f01881c4ae2da F src/main.c 94bf8b6a283914cc8fa8743b3db5350206a4be5cccfd9c84d53409ca5d8bd1c1 -F src/malloc.c 8a907f9e802ff517acb5e9edc13798428fd7668136456d9432a884a7fe5680f5 +F src/malloc.c cae32705aad5549e46687b48f8e5c6f8d045dfeec95b0ad30c295be4773b7c7c F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 @@ -1852,7 +1852,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5e1949bca998f3c8c23a8ebf01c7a2e7a2af1fdad43886271e1fe0f25411551d -R 251e88e80ae4e78253d2ec11ee9fa128 -U drh -Z c4130ee4f36c72a8f85ea58dbfd139dc +P d3783357f8fa76c42a86f12b214522f0388c37773c36ab8c5ce0623abbc4436a +R 419a6defa175975b0c1f1ba26db0be60 +U numist +Z c7e98609c62b97e8952867680421d71f diff --git a/manifest.uuid b/manifest.uuid index 17e6a5e49d..50a02db889 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d3783357f8fa76c42a86f12b214522f0388c37773c36ab8c5ce0623abbc4436a \ No newline at end of file +611020e3378f4c81c277cccd84807ae51a816bbab6c3d887c91c5e5af3b5225f \ No newline at end of file diff --git a/src/malloc.c b/src/malloc.c index 8f77c96438..79cdcbcb21 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -582,8 +582,10 @@ void *sqlite3DbMallocRawNN(sqlite3 *db, u64 n){ return db->mallocFailed ? 0 : dbMallocRawFinish(db, n); } db->lookaside.anStat[1]++; + return dbMallocRawFinish(db, n); + } # ifndef SQLITE_OMIT_MINI_LOOKASIDE - }else if( n<=MINI_SZ ){ + if( n<=MINI_SZ ){ if( (pBuf = db->lookaside.pMiniFree)!=0 ){ db->lookaside.pMiniFree = pBuf->pNext; db->lookaside.anStat[0]++; @@ -593,8 +595,9 @@ void *sqlite3DbMallocRawNN(sqlite3 *db, u64 n){ db->lookaside.anStat[0]++; return (void*)pBuf; } + } # endif - }else if( (pBuf = db->lookaside.pFree)!=0 ){ + if( (pBuf = db->lookaside.pFree)!=0 ){ db->lookaside.pFree = pBuf->pNext; db->lookaside.anStat[0]++; return (void*)pBuf; From 1b47c9c98e9e00bc24d11e6c6cad2c754b05dd02 Mon Sep 17 00:00:00 2001 From: numist Date: Thu, 12 Dec 2019 20:58:32 +0000 Subject: [PATCH 05/11] Reduce the number of call sites to dbMallocRawFinish in the case where n > lookaside.sz FossilOrigin-Name: e392e7f22861ce4b66e4bf84b59c8fd38568fc241a699e001f47fd82011f4d28 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/malloc.c | 7 ++++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 5f8fb620c5..5576b7e323 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sissue\swhere\smalloc\scould\sbe\sused\sto\sfulfill\sa\ssmall\sallocation\swhen\sa\slarge\slookaside\sslot\scould\shave\sbeeen\sused\sinstead. -D 2019-12-12T20:39:47.705 +C Reduce\sthe\snumber\sof\scall\ssites\sto\sdbMallocRawFinish\sin\sthe\scase\swhere\sn\s>\slookaside.sz +D 2019-12-12T20:58:32.965 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -492,7 +492,7 @@ F src/insert.c 276463aa7a26ee73958b9f4bcbef4eaec516f22bf6b8d7d2428f39c8dea90840 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c d74f5e7bd51f3c9d283442473eb65aef359664efd6513591c03f01881c4ae2da F src/main.c 94bf8b6a283914cc8fa8743b3db5350206a4be5cccfd9c84d53409ca5d8bd1c1 -F src/malloc.c cae32705aad5549e46687b48f8e5c6f8d045dfeec95b0ad30c295be4773b7c7c +F src/malloc.c 02235d039c72102d4bddf203a493c2613164487c70ec84bab679fc30daa883f0 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 @@ -1852,7 +1852,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d3783357f8fa76c42a86f12b214522f0388c37773c36ab8c5ce0623abbc4436a -R 419a6defa175975b0c1f1ba26db0be60 +P 611020e3378f4c81c277cccd84807ae51a816bbab6c3d887c91c5e5af3b5225f +R ad47704ebb6417a0219438b5b1af0ca2 U numist -Z c7e98609c62b97e8952867680421d71f +Z 7cabc14d06c02da6aca77386b2ebbfdc diff --git a/manifest.uuid b/manifest.uuid index 50a02db889..a46bfa5958 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -611020e3378f4c81c277cccd84807ae51a816bbab6c3d887c91c5e5af3b5225f \ No newline at end of file +e392e7f22861ce4b66e4bf84b59c8fd38568fc241a699e001f47fd82011f4d28 \ No newline at end of file diff --git a/src/malloc.c b/src/malloc.c index 79cdcbcb21..26a258b347 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -578,10 +578,11 @@ void *sqlite3DbMallocRawNN(sqlite3 *db, u64 n){ assert( sqlite3_mutex_held(db->mutex) ); assert( db->pnBytesFreed==0 ); if( n>db->lookaside.sz ){ - if( db->lookaside.bDisable ){ - return db->mallocFailed ? 0 : dbMallocRawFinish(db, n); + if( !db->lookaside.bDisable ){ + db->lookaside.anStat[1]++; + }else if( db->mallocFailed ){ + return 0; } - db->lookaside.anStat[1]++; return dbMallocRawFinish(db, n); } # ifndef SQLITE_OMIT_MINI_LOOKASIDE From cbb9da337e7f8dc4e6bea59399a0394ec390f1f2 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 12 Dec 2019 22:11:33 +0000 Subject: [PATCH 06/11] Work toward reducing the incremental size of an ExprList object to 24-byte per entry, from 32-bytes (on a 64-bit machine). This helps the new mini-lookaside allocator to run better by avoiding excessive reallocs. The current change mostly works, but still has a few loose ends to tie up. This check-in is merely a snapshot to save my work. FossilOrigin-Name: fdda76cfb01bf2b19522ac4558b443634d28a69b0828677c42682b645eae1f3b --- manifest | 23 +++++++++++++---------- manifest.uuid | 2 +- src/expr.c | 10 +++++----- src/resolve.c | 2 +- src/select.c | 26 +++++++++++++------------- src/sqliteInt.h | 30 +++++++++++++++++++++--------- 6 files changed, 54 insertions(+), 39 deletions(-) diff --git a/manifest b/manifest index 5f8fb620c5..e886d85f40 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sissue\swhere\smalloc\scould\sbe\sused\sto\sfulfill\sa\ssmall\sallocation\swhen\sa\slarge\slookaside\sslot\scould\shave\sbeeen\sused\sinstead. -D 2019-12-12T20:39:47.705 +C Work\stoward\sreducing\sthe\sincremental\ssize\sof\san\sExprList\sobject\sto\s24-byte\nper\sentry,\sfrom\s32-bytes\s(on\sa\s64-bit\smachine).\s\sThis\shelps\sthe\snew\nmini-lookaside\sallocator\sto\srun\sbetter\sby\savoiding\sexcessive\sreallocs.\nThe\scurrent\schange\smostly\sworks,\sbut\sstill\shas\sa\sfew\sloose\sends\sto\stie\sup.\nThis\scheck-in\sis\smerely\sa\ssnapshot\sto\ssave\smy\swork. +D 2019-12-12T22:11:33.445 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -479,7 +479,7 @@ F src/date.c e1d8ac7102f3f283e63e13867acb0efa33861cf34f0faf4cdbaf9fa7a1eb7041 F src/dbpage.c 135eb3b5e74f9ef74bde5cec2571192c90c86984fa534c88bf4a055076fa19b7 F src/dbstat.c 6c407e549406c10fde9ac3987f6d734459205239ad370369bc5fcd683084a4fa F src/delete.c a5c59b9c0251cf7682bc52af0d64f09b1aefc6781a63592c8f1136f7b73c66e4 -F src/expr.c eefc9abca2d8bb8b2cad063dd65c764e5264f1d80c83268a9debcfff2f7a32bb +F src/expr.c 828bc6ae0c15e60a5b0a5fb17ddf98fb3f9a52752fb34cbbdc15ea4868afcf90 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 92a248ec0fa4ed8ab60c98d9b188ce173aaf218f32e7737ba77deb2a684f9847 F src/func.c ed33e38cd642058182a31a3f518f2e34f4bbe53aa483335705c153c4d3e50b12 @@ -525,14 +525,14 @@ F src/pragma.h ec3b31eac9b1df040f1cc8cb3d89bc06605c3b4cb3d76f833de8d6d6c3f77f04 F src/prepare.c 6049beb71385f017af6fc320d2c75a4e50b75e280c54232442b785fbb83df057 F src/printf.c 9be6945837c839ba57837b4bc3af349eba630920fa5532aa518816defe42a7d4 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 -F src/resolve.c d703803412770e100be0d79adc4d0b52a99c49715ba8d4a736e503ee5526d473 +F src/resolve.c fc7bed8f23355db3af73859b4af42af4ee2f7cf3467aa5e242321575203e2896 F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93 -F src/select.c 39a9e180a2fdf738f3a02977684bc4cad3f5ff8d9f949f2aa48eef2ce5ff29aa +F src/select.c b5702ca6b2f215bb8bee27f591d72dfd52250a680b5fa11871a1a7be69dff758 F src/shell.c.in 4a3a9e1c11847b1904f2b01d087af1c052f660902755abab457cab1756817ded F src/sqlite.h.in 2a23e8161775253d9cf383c2c6aa559005dc787d350dcb0be67a6c4cc3bd1d19 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 72af51aa4e912e14cd495fb6e7fac65f0940db80ed950d90911aff292cc47ce2 -F src/sqliteInt.h ebb8c7e6439dc4cd6abad9fed0d01751160115328c8670b733505d7c5c6b12a4 +F src/sqliteInt.h 5be56f6523e0980b4ab66d6420e11dbe66c060c7b2e20aa28344fd67457cbe32 F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c 0fe55b92810509eac821ded2e177e1da944a78cdcdfec7813ad1d6b36d6d667e F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 @@ -1852,7 +1852,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d3783357f8fa76c42a86f12b214522f0388c37773c36ab8c5ce0623abbc4436a -R 419a6defa175975b0c1f1ba26db0be60 -U numist -Z c7e98609c62b97e8952867680421d71f +P 611020e3378f4c81c277cccd84807ae51a816bbab6c3d887c91c5e5af3b5225f +R 162199bc809f1616aa82013813cc7e3c +T *branch * exprlist-size-reduction +T *sym-exprlist-size-reduction * +T -sym-mini-lookaside-take-2 * +U drh +Z 2404f597cd0a4292958003b4ec4cbb04 diff --git a/manifest.uuid b/manifest.uuid index 50a02db889..fe20eceadf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -611020e3378f4c81c277cccd84807ae51a816bbab6c3d887c91c5e5af3b5225f \ No newline at end of file +fdda76cfb01bf2b19522ac4558b443634d28a69b0828677c42682b645eae1f3b \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index f9c57baa9c..0ca1d04077 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1437,11 +1437,10 @@ ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){ } } pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName); - pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan); pItem->sortFlags = pOldItem->sortFlags; + pItem->eEName = pOldItem->eEName; pItem->done = 0; pItem->bNulls = pOldItem->bNulls; - pItem->bSpanIsTab = pOldItem->bSpanIsTab; pItem->bSorterRef = pOldItem->bSorterRef; pItem->u = pOldItem->u; } @@ -1773,8 +1772,10 @@ void sqlite3ExprListSetSpan( if( pList ){ struct ExprList_item *pItem = &pList->a[pList->nExpr-1]; assert( pList->nExpr>0 ); - sqlite3DbFree(db, pItem->zSpan); - pItem->zSpan = sqlite3DbSpanDup(db, zStart, zEnd); + if( pItem->zEName==0 ){ + pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd); + pItem->eEName = ENAME_SPAN; + } } } @@ -1805,7 +1806,6 @@ static SQLITE_NOINLINE void exprListDeleteNN(sqlite3 *db, ExprList *pList){ do{ sqlite3ExprDelete(db, pItem->pExpr); sqlite3DbFree(db, pItem->zEName); - sqlite3DbFree(db, pItem->zSpan); pItem++; }while( --i>0 ); sqlite3DbFreeNN(db, pList); diff --git a/src/resolve.c b/src/resolve.c index b3c331535e..cce9210313 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -267,7 +267,7 @@ static int lookupName( int hit = 0; pEList = pItem->pSelect->pEList; for(j=0; jnExpr; j++){ - if( sqlite3MatchSpanName(pEList->a[j].zSpan, zCol, zTab, zDb) ){ + if( sqlite3MatchSpanName(pEList->a[j].zEName, zCol, zTab, zDb) ){ cnt++; cntTab = 2; pMatch = pItem; diff --git a/src/select.c b/src/select.c index b99b1459be..57bf685ede 100644 --- a/src/select.c +++ b/src/select.c @@ -1539,7 +1539,7 @@ static void generateSortTail( iRead = iCol--; } sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iRead, regRow+i); - VdbeComment((v, "%s", aOutEx[i].zEName?aOutEx[i].zEName:aOutEx[i].zSpan)); + VdbeComment((v, "%s", aOutEx[i].zEName)); } } switch( eDest ){ @@ -1873,7 +1873,7 @@ static void generateColumnNames( assert( p!=0 ); assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */ assert( p->op!=TK_COLUMN || p->y.pTab!=0 ); /* Covering idx not yet coded */ - if( pEList->a[i].zEName ){ + if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){ /* An AS clause always takes first priority */ char *zName = pEList->a[i].zEName; sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT); @@ -1897,7 +1897,7 @@ static void generateColumnNames( sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, SQLITE_TRANSIENT); } }else{ - const char *z = pEList->a[i].zSpan; + const char *z = pEList->a[i].zEName; z = z==0 ? sqlite3MPrintf(db, "column%d", i+1) : sqlite3DbStrDup(db, z); sqlite3VdbeSetColName(v, i, COLNAME_NAME, z, SQLITE_DYNAMIC); } @@ -1959,7 +1959,7 @@ int sqlite3ColumnsFromExprList( for(i=0, pCol=aCol; imallocFailed; i++, pCol++){ /* Get an appropriate name for the column */ - if( (zName = pEList->a[i].zEName)!=0 ){ + if( (zName = pEList->a[i].zEName)!=0 && pEList->a[i].eEName==ENAME_NAME ){ /* If the column contains an "AS " phrase, use as the name */ }else{ Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr); @@ -1979,7 +1979,7 @@ int sqlite3ColumnsFromExprList( zName = pColExpr->u.zToken; }else{ /* Use the original text of the column expression as its name */ - zName = pEList->a[i].zSpan; + zName = pEList->a[i].zEName; } } if( zName ){ @@ -5004,9 +5004,8 @@ static int selectExpander(Walker *pWalker, Select *p){ pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr); if( pNew ){ pNew->a[pNew->nExpr-1].zEName = a[k].zEName; - pNew->a[pNew->nExpr-1].zSpan = a[k].zSpan; + pNew->a[pNew->nExpr-1].eEName = a[k].eEName; a[k].zEName = 0; - a[k].zSpan = 0; } a[k].pExpr = 0; }else{ @@ -5045,7 +5044,7 @@ static int selectExpander(Walker *pWalker, Select *p){ assert( zName ); if( zTName && pSub - && sqlite3MatchSpanName(pSub->pEList->a[j].zSpan, 0, zTName, 0)==0 + && sqlite3MatchSpanName(pSub->pEList->a[j].zEName, 0, zTName, 0)==0 ){ continue; } @@ -5098,15 +5097,16 @@ static int selectExpander(Walker *pWalker, Select *p){ sqlite3ExprListSetName(pParse, pNew, &sColname, 0); if( pNew && (p->selFlags & SF_NestedFrom)!=0 ){ struct ExprList_item *pX = &pNew->a[pNew->nExpr-1]; + sqlite3DbFree(db, pX->zEName); if( pSub ){ - pX->zSpan = sqlite3DbStrDup(db, pSub->pEList->a[j].zSpan); - testcase( pX->zSpan==0 ); + pX->zEName = sqlite3DbStrDup(db, pSub->pEList->a[j].zEName); + testcase( pX->zEName==0 ); }else{ - pX->zSpan = sqlite3MPrintf(db, "%s.%s.%s", + pX->zEName = sqlite3MPrintf(db, "%s.%s.%s", zSchemaName, zTabName, zColname); - testcase( pX->zSpan==0 ); + testcase( pX->zEName==0 ); } - pX->bSpanIsTab = 1; + pX->eEName = ENAME_TAB; } sqlite3DbFree(db, zToFree); } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 3de659f791..7425b29887 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2650,23 +2650,28 @@ struct Expr { ** also be used as the argument to a function, in which case the a.zName ** field is not used. ** -** By default the Expr.zSpan field holds a human-readable description of -** the expression that is used in the generation of error messages and -** column labels. In this case, Expr.zSpan is typically the text of a -** column expression as it exists in a SELECT statement. However, if -** the bSpanIsTab flag is set, then zSpan is overloaded to mean the name -** of the result column in the form: DATABASE.TABLE.COLUMN. This later -** form is used for name resolution with nested FROM clauses. +** In order to try to keep memory usage down, the Expr.a.zEName field +** is used for multiple purposes: +** +** bNameIsTab bNameIsSpan Usage +** ---------- ----------- ------------------------- +** false false (1) the AS of result set column +** (2) COLUMN= of an UPDATE +** +** true false DB.TABLE.NAME used to resolve names +** of subqueries +** +** false true Text of the original result set +** expression. */ struct ExprList { int nExpr; /* Number of expressions on the list */ struct ExprList_item { /* For each expression in the list */ Expr *pExpr; /* The parse tree for this expression */ char *zEName; /* Token associated with this expression */ - char *zSpan; /* Original text of the expression */ u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */ + unsigned eEName :2; /* Meaning of zEName */ unsigned done :1; /* A flag to indicate when processing is finished */ - unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */ unsigned reusable :1; /* Constant expression is reusable */ unsigned bSorterRef :1; /* Defer evaluation until after sorting */ unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */ @@ -2680,6 +2685,13 @@ struct ExprList { } a[1]; /* One slot for each expression in the list */ }; +/* +** Allowed values for Expr.a.eEName +*/ +#define ENAME_NAME 0 /* The AS clause of a result set */ +#define ENAME_SPAN 1 /* Complete text of the result set expression */ +#define ENAME_TAB 2 /* "DB.TABLE.NAME" for the result set */ + /* ** An instance of this structure can hold a simple list of identifiers, ** such as the list "a,b,c" in the following statements: From c4938ea2ba17cdba4bd03a23b2f3cfd783f79c0a Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 13 Dec 2019 00:49:42 +0000 Subject: [PATCH 07/11] Tie up the loose ends in the ExprList size reduction. FossilOrigin-Name: 59d0f3afe5249a2a6453fe7bc810c2c7beb896d3800174c7c90f9304c0b1ad88 --- manifest | 23 ++++++++++------------- manifest.uuid | 2 +- src/alter.c | 10 +++++++--- src/expr.c | 1 + src/resolve.c | 21 +++++++++++++++------ src/select.c | 2 +- src/sqliteInt.h | 23 ++++++++++++++--------- 7 files changed, 49 insertions(+), 33 deletions(-) diff --git a/manifest b/manifest index e886d85f40..e65f7b1b68 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Work\stoward\sreducing\sthe\sincremental\ssize\sof\san\sExprList\sobject\sto\s24-byte\nper\sentry,\sfrom\s32-bytes\s(on\sa\s64-bit\smachine).\s\sThis\shelps\sthe\snew\nmini-lookaside\sallocator\sto\srun\sbetter\sby\savoiding\sexcessive\sreallocs.\nThe\scurrent\schange\smostly\sworks,\sbut\sstill\shas\sa\sfew\sloose\sends\sto\stie\sup.\nThis\scheck-in\sis\smerely\sa\ssnapshot\sto\ssave\smy\swork. -D 2019-12-12T22:11:33.445 +C Tie\sup\sthe\sloose\sends\sin\sthe\sExprList\ssize\sreduction. +D 2019-12-13T00:49:42.494 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -461,7 +461,7 @@ F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a -F src/alter.c 27aaf1045f52876320b431f4b45d9c1e5786899de41cec2bea39620095ab9aa7 +F src/alter.c accee2f80a2db2cb0ca253a62704ab9fad0e8355b0e4b372f0d3bfdf7737a8e3 F src/analyze.c b3ceec3fc052df8a96ca8a8c858d455dc5029ba681b4be98bb5c5a9162cfa58c F src/attach.c b30c44333d55a68c0a12920b5b9d40b254cbd3d4509bda77417209eeed8b3d80 F src/auth.c a3d5bfdba83d25abed1013a8c7a5f204e2e29b0c25242a56bc02bb0c07bf1e06 @@ -479,7 +479,7 @@ F src/date.c e1d8ac7102f3f283e63e13867acb0efa33861cf34f0faf4cdbaf9fa7a1eb7041 F src/dbpage.c 135eb3b5e74f9ef74bde5cec2571192c90c86984fa534c88bf4a055076fa19b7 F src/dbstat.c 6c407e549406c10fde9ac3987f6d734459205239ad370369bc5fcd683084a4fa F src/delete.c a5c59b9c0251cf7682bc52af0d64f09b1aefc6781a63592c8f1136f7b73c66e4 -F src/expr.c 828bc6ae0c15e60a5b0a5fb17ddf98fb3f9a52752fb34cbbdc15ea4868afcf90 +F src/expr.c a4c16d4eed1508377bb8aba71471f3f023edb2ebd79fb7ba3bf379b1e54a6cb7 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 92a248ec0fa4ed8ab60c98d9b188ce173aaf218f32e7737ba77deb2a684f9847 F src/func.c ed33e38cd642058182a31a3f518f2e34f4bbe53aa483335705c153c4d3e50b12 @@ -525,14 +525,14 @@ F src/pragma.h ec3b31eac9b1df040f1cc8cb3d89bc06605c3b4cb3d76f833de8d6d6c3f77f04 F src/prepare.c 6049beb71385f017af6fc320d2c75a4e50b75e280c54232442b785fbb83df057 F src/printf.c 9be6945837c839ba57837b4bc3af349eba630920fa5532aa518816defe42a7d4 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 -F src/resolve.c fc7bed8f23355db3af73859b4af42af4ee2f7cf3467aa5e242321575203e2896 +F src/resolve.c 347c0624f83451803530668055665f770afa851a35a09cb429a7a4749c61706f F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93 -F src/select.c b5702ca6b2f215bb8bee27f591d72dfd52250a680b5fa11871a1a7be69dff758 +F src/select.c 3590f0641817f0d3af4211315ff91abd197f7c03ba8d20129388af8dcdb707f3 F src/shell.c.in 4a3a9e1c11847b1904f2b01d087af1c052f660902755abab457cab1756817ded F src/sqlite.h.in 2a23e8161775253d9cf383c2c6aa559005dc787d350dcb0be67a6c4cc3bd1d19 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 72af51aa4e912e14cd495fb6e7fac65f0940db80ed950d90911aff292cc47ce2 -F src/sqliteInt.h 5be56f6523e0980b4ab66d6420e11dbe66c060c7b2e20aa28344fd67457cbe32 +F src/sqliteInt.h 344e090acc6491b86c4e4368dbac3b679ecf169be0675f567c6e72e71895cadf F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c 0fe55b92810509eac821ded2e177e1da944a78cdcdfec7813ad1d6b36d6d667e F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 @@ -1852,10 +1852,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 611020e3378f4c81c277cccd84807ae51a816bbab6c3d887c91c5e5af3b5225f -R 162199bc809f1616aa82013813cc7e3c -T *branch * exprlist-size-reduction -T *sym-exprlist-size-reduction * -T -sym-mini-lookaside-take-2 * +P fdda76cfb01bf2b19522ac4558b443634d28a69b0828677c42682b645eae1f3b +R 1f0ba04ae14155cebfb37c7f11e00a7b U drh -Z 2404f597cd0a4292958003b4ec4cbb04 +Z 64cc739752f0df56bd4f170960481f66 diff --git a/manifest.uuid b/manifest.uuid index fe20eceadf..c0090acd67 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fdda76cfb01bf2b19522ac4558b443634d28a69b0828677c42682b645eae1f3b \ No newline at end of file +59d0f3afe5249a2a6453fe7bc810c2c7beb896d3800174c7c90f9304c0b1ad88 \ No newline at end of file diff --git a/src/alter.c b/src/alter.c index f3467fa09e..3bc779a1e9 100644 --- a/src/alter.c +++ b/src/alter.c @@ -764,7 +764,7 @@ static int renameUnmapSelectCb(Walker *pWalker, Select *p){ if( ALWAYS(p->pEList) ){ ExprList *pList = p->pEList; for(i=0; inExpr; i++){ - if( pList->a[i].zEName ){ + if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){ sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName); } } @@ -808,7 +808,9 @@ void sqlite3RenameExprlistUnmap(Parse *pParse, ExprList *pEList){ sWalker.xExprCallback = renameUnmapExprCb; sqlite3WalkExprList(&sWalker, pEList); for(i=0; inExpr; i++){ - sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName); + if( pEList->a[i].eEName==ENAME_NAME ){ + sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName); + } } } } @@ -947,7 +949,9 @@ static void renameColumnElistNames( int i; for(i=0; inExpr; i++){ char *zName = pEList->a[i].zEName; - if( 0==sqlite3_stricmp(zName, zOld) ){ + if( pEList->a[i].eEName==ENAME_NAME + && 0==sqlite3_stricmp(zName, zOld) + ){ renameTokenFind(pParse, pCtx, (void*)zName); } } diff --git a/src/expr.c b/src/expr.c index 0ca1d04077..150e34a2c1 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1745,6 +1745,7 @@ void sqlite3ExprListSetName( assert( pList->nExpr>0 ); pItem = &pList->a[pList->nExpr-1]; assert( pItem->zEName==0 ); + assert( pItem->eEName==ENAME_NAME ); pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n); if( dequote ) sqlite3Dequote(pItem->zEName); if( IN_RENAME_OBJECT ){ diff --git a/src/resolve.c b/src/resolve.c index cce9210313..572e0a9f3c 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -132,13 +132,16 @@ static int nameInUsingClause(IdList *pUsing, const char *zCol){ ** and zCol. If any of zDb, zTab, and zCol are NULL then those fields will ** match anything. */ -int sqlite3MatchSpanName( - const char *zSpan, +int sqlite3MatchEName( + const struct ExprList_item *pItem, const char *zCol, const char *zTab, const char *zDb ){ int n; + const char *zSpan; + if( pItem->eEName!=ENAME_TAB ) return 0; + zSpan = pItem->zEName; for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){} if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){ return 0; @@ -267,7 +270,7 @@ static int lookupName( int hit = 0; pEList = pItem->pSelect->pEList; for(j=0; jnExpr; j++){ - if( sqlite3MatchSpanName(pEList->a[j].zEName, zCol, zTab, zDb) ){ + if( sqlite3MatchEName(&pEList->a[j], zCol, zTab, zDb) ){ cnt++; cntTab = 2; pMatch = pItem; @@ -448,8 +451,11 @@ static int lookupName( pEList = pNC->uNC.pEList; assert( pEList!=0 ); for(j=0; jnExpr; j++){ - char *zAs = pEList->a[j].zEName; - if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){ + char *zAs; + if( pEList->a[j].eEName==ENAME_NAME + && (zAs = pEList->a[j].zEName)!=0 + && sqlite3StrICmp(zAs, zCol)==0 + ){ Expr *pOrig; assert( pExpr->pLeft==0 && pExpr->pRight==0 ); assert( pExpr->x.pList==0 ); @@ -1116,7 +1122,10 @@ static int resolveAsName( char *zCol = pE->u.zToken; for(i=0; inExpr; i++){ char *zAs = pEList->a[i].zEName; - if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){ + if( pEList->a[i].eEName==ENAME_NAME + && (zAs = pEList->a[i].zEName)!=0 + && sqlite3StrICmp(zAs, zCol)==0 + ){ return i+1; } } diff --git a/src/select.c b/src/select.c index 57bf685ede..11c25e7876 100644 --- a/src/select.c +++ b/src/select.c @@ -5044,7 +5044,7 @@ static int selectExpander(Walker *pWalker, Select *p){ assert( zName ); if( zTName && pSub - && sqlite3MatchSpanName(pSub->pEList->a[j].zEName, 0, zTName, 0)==0 + && sqlite3MatchEName(&pSub->pEList->a[j], 0, zTName, 0)==0 ){ continue; } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 7425b29887..d022436d38 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2653,16 +2653,16 @@ struct Expr { ** In order to try to keep memory usage down, the Expr.a.zEName field ** is used for multiple purposes: ** -** bNameIsTab bNameIsSpan Usage -** ---------- ----------- ------------------------- -** false false (1) the AS of result set column -** (2) COLUMN= of an UPDATE +** eEName Usage +** ---------- ------------------------- +** ENAME_NAME (1) the AS of result set column +** (2) COLUMN= of an UPDATE ** -** true false DB.TABLE.NAME used to resolve names -** of subqueries +** ENAME_TAB DB.TABLE.NAME used to resolve names +** of subqueries ** -** false true Text of the original result set -** expression. +** ENAME_SPAN Text of the original result set +** expression. */ struct ExprList { int nExpr; /* Number of expressions on the list */ @@ -4430,7 +4430,12 @@ void sqlite3CodeRhsOfIN(Parse*, Expr*, int); int sqlite3CodeSubselect(Parse*, Expr*); void sqlite3SelectPrep(Parse*, Select*, NameContext*); void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p); -int sqlite3MatchSpanName(const char*, const char*, const char*, const char*); +int sqlite3MatchEName( + const struct ExprList_item*, + const char*, + const char*, + const char* +); int sqlite3ResolveExprNames(NameContext*, Expr*); int sqlite3ResolveExprListNames(NameContext*, ExprList*); void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*); From e6068027ca584a1263d2d659f48eded07fc4a297 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 13 Dec 2019 15:48:21 +0000 Subject: [PATCH 08/11] Cleanup and performance enhancements for mini-lookaside. FossilOrigin-Name: 74805668430051032ae9b256c84e252755ee03075fc08293c948675ed40ec280 --- manifest | 18 +++++++------- manifest.uuid | 2 +- src/main.c | 47 +++++++++++++++++++++++------------ src/malloc.c | 65 ++++++++++++++++++++++++++++++++----------------- src/sqliteInt.h | 30 ++++++++++++++++++++--- src/status.c | 2 +- 6 files changed, 112 insertions(+), 52 deletions(-) diff --git a/manifest b/manifest index 448d34a0ee..6425c9f1a0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\sfixes\sfrom\strunk. -D 2019-12-13T12:14:23.880 +C Cleanup\sand\sperformance\senhancements\sfor\smini-lookaside. +D 2019-12-13T15:48:21.644 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -491,8 +491,8 @@ F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 276463aa7a26ee73958b9f4bcbef4eaec516f22bf6b8d7d2428f39c8dea90840 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c d74f5e7bd51f3c9d283442473eb65aef359664efd6513591c03f01881c4ae2da -F src/main.c 94bf8b6a283914cc8fa8743b3db5350206a4be5cccfd9c84d53409ca5d8bd1c1 -F src/malloc.c 02235d039c72102d4bddf203a493c2613164487c70ec84bab679fc30daa883f0 +F src/main.c 34d73303ac76015d3c8961f16d49ab44a56cbc998f178b27ca07847db4cf9273 +F src/malloc.c d74d986f91ebd6a4a9b2995467f4c13a1fdb57ac87df5bb0a7fa3afe1db72d1d F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 @@ -532,9 +532,9 @@ F src/shell.c.in 4a3a9e1c11847b1904f2b01d087af1c052f660902755abab457cab1756817de F src/sqlite.h.in 2a23e8161775253d9cf383c2c6aa559005dc787d350dcb0be67a6c4cc3bd1d19 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 72af51aa4e912e14cd495fb6e7fac65f0940db80ed950d90911aff292cc47ce2 -F src/sqliteInt.h a036ca4ee94ac0dea82c90b2c902dc84bce187adf75e68284e890bc0c4cd3d95 +F src/sqliteInt.h 4948c2046c921461d2021e52ac8cec5b65cd56ab0c58aa7150313abace90153c F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b -F src/status.c 0fe55b92810509eac821ded2e177e1da944a78cdcdfec7813ad1d6b36d6d667e +F src/status.c baf38f521ac079be616dab1ff13f60c6ce0703c7f0429a65238c695197a56935 F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 F src/tclsqlite.c 8cd2600e8de23dff6cdf84d39f46ca57139b061b28f6f80b166bace17d52ab1c F src/test1.c c654981c1d86ebc90dd23fcc0969e6c85e28112f0acc2e2224a97a2a33e7c42f @@ -1852,7 +1852,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P bda92d92bf69a73bc6dd498f92578ad6e81111a3f97bc8724d1720e7283a83b6 c1014e80b26131200a115beb86929a8f0ded2dd65b075e47373346c0f170576a -R b2be5daabe2de4420861c8338271e7de +P 9c471195f6d3e4b00e2d0f909b306a4036352082dca5f016a8eece226e82163d +R 40d26fbfedcb39151f8726a7fa468e8a U drh -Z 5e37344191b5a16624379099587382f5 +Z 7742eaad4b11604e1540b9f51bda9209 diff --git a/manifest.uuid b/manifest.uuid index 69d04cf3ef..4e1f2b833d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9c471195f6d3e4b00e2d0f909b306a4036352082dca5f016a8eece226e82163d \ No newline at end of file +74805668430051032ae9b256c84e252755ee03075fc08293c948675ed40ec280 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 5b70273af2..9f541ff0d0 100644 --- a/src/main.c +++ b/src/main.c @@ -684,6 +684,8 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ #ifndef SQLITE_OMIT_LOOKASIDE void *pStart; sqlite3_int64 szAlloc = sz*(sqlite3_int64)cnt; + int nBig; /* Number of full-size slots */ + int nSm; /* Number smaller mini-slots */ if( sqlite3LookasideUsed(db,0)>0 ){ return SQLITE_BUSY; @@ -708,56 +710,69 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ sqlite3BeginBenignMalloc(); pStart = sqlite3Malloc( szAlloc ); /* IMP: R-61949-35727 */ sqlite3EndBenignMalloc(); - if( pStart ) cnt = sqlite3MallocSize(pStart)/sz; + if( pStart ) szAlloc = sqlite3MallocSize(pStart); }else{ pStart = pBuf; } +#ifndef SQLITE_OMIT_MINI_LOOKASIDE + if( sz>=MINI_SZ*3 ){ + nBig = szAlloc/(3*MINI_SZ+sz); + nSm = (szAlloc - sz*nBig)/MINI_SZ; + }else if( sz>=MINI_SZ*2 ){ + nBig = szAlloc/(MINI_SZ+sz); + nSm = (szAlloc - sz*nBig)/MINI_SZ; + }else +#endif /* SQLITE_OMIT_MINI_LOOKASIDE */ + if( sz>0 ){ + nBig = szAlloc/sz; + nSm = 0; + }else{ + nBig = nSm = 0; + } db->lookaside.pStart = pStart; db->lookaside.pInit = 0; db->lookaside.pFree = 0; -#ifndef SQLITE_OMIT_MINI_LOOKASIDE - db->lookaside.pMiniInit = 0; - db->lookaside.pMiniFree = 0; - /* The arithmetic below causes the number of large lookaside slots to be 1/3 - ** the number of mini slots, based on the observation that 75% of allocations - ** are <= MINI_SZ bytes. - */ - cnt = szAlloc/(3*MINI_SZ+sz); -#endif db->lookaside.sz = (u16)sz; db->lookaside.szTrue = (u16)sz; if( pStart ){ int i; LookasideSlot *p; assert( sz > (int)sizeof(LookasideSlot*) ); - db->lookaside.nSlot = cnt; p = (LookasideSlot*)pStart; - for(i=cnt-1; i>=0; i--){ + for(i=0; ipNext = db->lookaside.pInit; db->lookaside.pInit = p; p = (LookasideSlot*)&((u8*)p)[sz]; } #ifndef SQLITE_OMIT_MINI_LOOKASIDE + db->lookaside.pMiniInit = 0; + db->lookaside.pMiniFree = 0; db->lookaside.pMiddle = p; - /* Fill the remainder of the buffer with mini slots */ - while(p<=(LookasideSlot*)&((u8*)pStart)[szAlloc-MINI_SZ]){ + for(i=0; ipNext = db->lookaside.pMiniInit; db->lookaside.pMiniInit = p; - db->lookaside.nSlot++; p = (LookasideSlot*)&((u8*)p)[MINI_SZ]; } -#endif +#endif /* SQLITE_OMIT_MINI_LOOKASIDE */ + assert( ((uptr)p)<=szAlloc + (uptr)pStart ); db->lookaside.pEnd = p; db->lookaside.bDisable = 0; db->lookaside.bMalloced = pBuf==0 ?1:0; + db->lookaside.nSlot = nBig+nSm; }else{ db->lookaside.pStart = db; +#ifndef SQLITE_OMIT_MINI_LOOKASIDE + db->lookaside.pMiniInit = 0; + db->lookaside.pMiniFree = 0; + db->lookaside.pMiddle = db; +#endif /* SQLITE_OMIT_MINI_LOOKASIDE */ db->lookaside.pEnd = db; db->lookaside.bDisable = 1; db->lookaside.sz = 0; db->lookaside.bMalloced = 0; db->lookaside.nSlot = 0; } + assert( sqlite3LookasideUsed(db,0)==0 ); #endif /* SQLITE_OMIT_LOOKASIDE */ return SQLITE_OK; } diff --git a/src/malloc.c b/src/malloc.c index 26a258b347..1074156eec 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -341,8 +341,8 @@ static int lookasideMallocSize(sqlite3 *db, void *p){ } int sqlite3DbMallocSize(sqlite3 *db, void *p){ assert( p!=0 ); - if( db==0 || !isLookaside(db,p) ){ #ifdef SQLITE_DEBUG + if( db==0 || !isLookaside(db,p) ){ if( db==0 ){ assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); @@ -350,12 +350,23 @@ int sqlite3DbMallocSize(sqlite3 *db, void *p){ assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); } -#endif - return sqlite3GlobalConfig.m.xSize(p); - }else{ - assert( sqlite3_mutex_held(db->mutex) ); - return lookasideMallocSize(db, p); } +#endif + if( db ){ + if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){ +#ifndef SQLITE_OMIT_MINI_LOOKASIDE + if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){ + assert( sqlite3_mutex_held(db->mutex) ); + return MINI_SZ; + } +#endif + if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){ + assert( sqlite3_mutex_held(db->mutex) ); + return db->lookaside.szTrue; + } + } + } + return sqlite3GlobalConfig.m.xSize(p); } sqlite3_uint64 sqlite3_msize(void *p){ assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); @@ -402,26 +413,27 @@ void sqlite3DbFreeNN(sqlite3 *db, void *p){ measureAllocationSize(db, p); return; } - if( isLookaside(db, p) ){ - LookasideSlot *pBuf = (LookasideSlot*)p; + if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){ #ifndef SQLITE_OMIT_MINI_LOOKASIDE - if( p>=db->lookaside.pMiddle ){ -# ifdef SQLITE_DEBUG - /* Trash all content in the buffer being freed */ - memset(p, 0xaa, MINI_SZ); -# endif + if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){ + LookasideSlot *pBuf = (LookasideSlot*)p; +#ifdef SQLITE_DEBUG + memset(p, 0xaa, MINI_SZ); /* Trash freed content */ +#endif pBuf->pNext = db->lookaside.pMiniFree; db->lookaside.pMiniFree = pBuf; return; } -#endif +#endif /* SQLITE_OMIT_MINI_LOOKASIDE */ + if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){ + LookasideSlot *pBuf = (LookasideSlot*)p; #ifdef SQLITE_DEBUG - /* Trash all content in the buffer being freed */ - memset(p, 0xaa, db->lookaside.szTrue); + memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */ #endif - pBuf->pNext = db->lookaside.pFree; - db->lookaside.pFree = pBuf; - return; + pBuf->pNext = db->lookaside.pFree; + db->lookaside.pFree = pBuf; + return; + } } } assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); @@ -585,7 +597,7 @@ void *sqlite3DbMallocRawNN(sqlite3 *db, u64 n){ } return dbMallocRawFinish(db, n); } -# ifndef SQLITE_OMIT_MINI_LOOKASIDE +#ifndef SQLITE_OMIT_MINI_LOOKASIDE if( n<=MINI_SZ ){ if( (pBuf = db->lookaside.pMiniFree)!=0 ){ db->lookaside.pMiniFree = pBuf->pNext; @@ -597,7 +609,7 @@ void *sqlite3DbMallocRawNN(sqlite3 *db, u64 n){ return (void*)pBuf; } } -# endif +#endif if( (pBuf = db->lookaside.pFree)!=0 ){ db->lookaside.pFree = pBuf->pNext; db->lookaside.anStat[0]++; @@ -631,7 +643,16 @@ void *sqlite3DbRealloc(sqlite3 *db, void *p, u64 n){ assert( db!=0 ); if( p==0 ) return sqlite3DbMallocRawNN(db, n); assert( sqlite3_mutex_held(db->mutex) ); - if( isLookaside(db,p) && nlookaside.pEnd ){ +#ifndef SQLITE_OMIT_MINI_LOOKASIDE + if( ((uptr)p)>=(uptr)db->lookaside.pMiddle ){ + if( n<=MINI_SZ ) return p; + }else +#endif + if( ((uptr)p)>=(uptr)db->lookaside.pStart ){ + if( n<=db->lookaside.szTrue ) return p; + } + } return dbReallocFinish(db, p, n); } static SQLITE_NOINLINE void *dbReallocFinish(sqlite3 *db, void *p, u64 n){ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index da9a7ff811..b18f05c85e 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1277,6 +1277,25 @@ struct Schema { ** disables lookaside without adding a new test for the bDisable flag ** in a performance-critical path. sz should be set by to szTrue whenever ** bDisable changes back to zero. +** +** Lookaside buffers are initially held on the pInit list. As they are +** used and freed, they are added back to the pFree list. New allocations +** come off of pFree first, then pInit as a fallback. This dual-list +** allows use to compute a high-water mark - the maximum number of allocations +** outstanding at any point in the past - by subtracting the number of +** allocations on the pInit list from the total number of allocations. +** +** Enhancement on 2019-12-12: Mini-lookaside +** The default lookaside configuration is 100 slots of 1200 bytes each. +** The larger slot sizes are important for performance, but they waste +** a lot of space, as most lookaside allocations are less than 128 bytes. +** The mini-lookaside enhancement breaks up the lookaside allocation into +** two pools: One of 128-byte slots and the other of the default size +** (1200-byte) slots. Allocations are filled from the mini-pool first, +** failing over to the full-size pool if that does not work. Thus more +** lookaside slots are available while also using less memory. +** This enhancement can be omitted by compiling with +** SQLITE_OMIT_MINI_LOOKASIDE. */ struct Lookaside { u32 bDisable; /* Only operate the lookaside when zero */ @@ -1290,8 +1309,9 @@ struct Lookaside { #ifndef SQLITE_OMIT_MINI_LOOKASIDE LookasideSlot *pMiniInit; /* List of mini buffers not prediously used */ LookasideSlot *pMiniFree; /* List of available mini buffers */ - void *pMiddle; /* An address between the fullsize and mini buffers */ -#endif + void *pMiddle; /* First byte past end of full-size buffers and + ** the first byte of mini-buffers */ +#endif /* SQLITE_OMIT_MINI_LOOKASIDE */ void *pStart; /* First byte of available memory space */ void *pEnd; /* First byte past end of available space */ }; @@ -1304,7 +1324,11 @@ struct LookasideSlot { db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue /* Size of the MINI lookside allocation */ -#define MINI_SZ 128 +#ifdef SQLITE_OMIT_MINI_LOOKASIDE +# define MINI_SZ 0 +#else +# define MINI_SZ 128 +#endif /* ** A hash table for built-in function definitions. (Application-defined diff --git a/src/status.c b/src/status.c index d7ffe99ede..977457f8e3 100644 --- a/src/status.c +++ b/src/status.c @@ -191,7 +191,7 @@ int sqlite3LookasideUsed(sqlite3 *db, int *pHighwater){ #ifndef SQLITE_OMIT_MINI_LOOKASIDE nInit += countLookasideSlots(db->lookaside.pMiniInit); nFree += countLookasideSlots(db->lookaside.pMiniFree); -#endif +#endif /* SQLITE_OMIT_MINI_LOOKASIDE */ if( pHighwater ) *pHighwater = db->lookaside.nSlot - nInit; return db->lookaside.nSlot - (nInit+nFree); } From d335bc40a6576d8759466d8efaaaf82b04667aaa Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 13 Dec 2019 16:04:52 +0000 Subject: [PATCH 09/11] Change the default lookaside configuration to 40 slots of 1200-bytes each. This actually works out to 30 big slots and 93 small slots using the mini-lookaside allocator. We get the same (or better) lookaside coverage but with 72KB less memory per connection. FossilOrigin-Name: 47b71a84d1262c4bf6ad4f4a91820fd63593f08ae9efa144199d44972225e073 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/global.c | 11 ++++++++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 6425c9f1a0..16e83f5bd7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Cleanup\sand\sperformance\senhancements\sfor\smini-lookaside. -D 2019-12-13T15:48:21.644 +C Change\sthe\sdefault\slookaside\sconfiguration\sto\s40\sslots\sof\s1200-bytes\seach.\nThis\sactually\sworks\sout\sto\s30\sbig\sslots\sand\s93\ssmall\sslots\susing\sthe\s\nmini-lookaside\sallocator.\s\sWe\sget\sthe\ssame\s(or\sbetter)\slookaside\scoverage\nbut\swith\s72KB\sless\smemory\sper\sconnection. +D 2019-12-13T16:04:52.502 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -483,7 +483,7 @@ F src/expr.c a4c16d4eed1508377bb8aba71471f3f023edb2ebd79fb7ba3bf379b1e54a6cb7 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 92a248ec0fa4ed8ab60c98d9b188ce173aaf218f32e7737ba77deb2a684f9847 F src/func.c ed33e38cd642058182a31a3f518f2e34f4bbe53aa483335705c153c4d3e50b12 -F src/global.c a1a8d698762ddd9a1543aac26c1e0029b20fcc3fcb56bfa41ec8cea2368f2798 +F src/global.c 76da82a621fed40105172969f1a4af93bdab107fa07426f532502c498cf81eb8 F src/hash.c 8d7dda241d0ebdafb6ffdeda3149a412d7df75102cecfc1021c98d6219823b19 F src/hash.h 9d56a9079d523b648774c1784b74b89bd93fac7b365210157482e4319a468f38 F src/hwtime.h cb1d7e3e1ed94b7aa6fde95ae2c2daccc3df826be26fc9ed7fd90d1750ae6144 @@ -1852,7 +1852,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 9c471195f6d3e4b00e2d0f909b306a4036352082dca5f016a8eece226e82163d -R 40d26fbfedcb39151f8726a7fa468e8a +P 74805668430051032ae9b256c84e252755ee03075fc08293c948675ed40ec280 +R be744340ad93a72a39e7a253bc678105 U drh -Z 7742eaad4b11604e1540b9f51bda9209 +Z cd1e4565dc6a4c9271072cb91752ff19 diff --git a/manifest.uuid b/manifest.uuid index 4e1f2b833d..5fd4b18240 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -74805668430051032ae9b256c84e252755ee03075fc08293c948675ed40ec280 \ No newline at end of file +47b71a84d1262c4bf6ad4f4a91820fd63593f08ae9efa144199d44972225e073 \ No newline at end of file diff --git a/src/global.c b/src/global.c index 4689e94bb4..570002be4d 100644 --- a/src/global.c +++ b/src/global.c @@ -190,9 +190,18 @@ const unsigned char sqlite3CtypeMap[256] = { ** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE) ** or at run-time for an individual database connection using ** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE); +** +** With the mini-lookaside enhancement, must less lookaside is required. +** The default configuration of 1200,40 actually proves 30 1200-byte slots +** and 93 128-byte slots, which is more lookaside slots that are available +** using the older 1200,100 configuration without mini-lookaside. */ #ifndef SQLITE_DEFAULT_LOOKASIDE -# define SQLITE_DEFAULT_LOOKASIDE 1200,100 +# ifdef SQLITE_OMIT_MINI_LOOKASIDE +# define SQLITE_DEFAULT_LOOKASIDE 1200,100 /* 120KB of memory */ +# else +# define SQLITE_DEFAULT_LOOKASIDE 1200,40 /* 48KB of memory */ +# endif #endif From cf014f6cbd2452abb29b3bef2b3b4e63e59c09f8 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 31 Dec 2019 15:12:34 +0000 Subject: [PATCH 10/11] Refactor names. Use "small" instead of "mini" to describe the smaller of the two lookaside memory allocation sizes. FossilOrigin-Name: 88d244983854cdc1a369c5df09ae00f1098784db768ba4e17b963d187dcb1009 --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/global.c | 10 +++++----- src/main.c | 40 ++++++++++++++++++++-------------------- src/malloc.c | 34 +++++++++++++++++----------------- src/sqliteInt.h | 28 ++++++++++++++-------------- src/status.c | 18 +++++++++--------- 7 files changed, 76 insertions(+), 76 deletions(-) diff --git a/manifest b/manifest index d7ccb2fbc8..afb4de68b3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\srecent\senhancements\sfrom\strunk. -D 2019-12-31T14:49:10.816 +C Refactor\snames.\s\sUse\s"small"\sinstead\sof\s"mini"\sto\sdescribe\sthe\ssmaller\nof\sthe\stwo\slookaside\smemory\sallocation\ssizes. +D 2019-12-31T15:12:34.090 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -484,7 +484,7 @@ F src/expr.c 8d4b6ac02f69e60b185cba0e38a76ba3f6f2122ee767e7de0f933fddec423e4a F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 92a248ec0fa4ed8ab60c98d9b188ce173aaf218f32e7737ba77deb2a684f9847 F src/func.c ed33e38cd642058182a31a3f518f2e34f4bbe53aa483335705c153c4d3e50b12 -F src/global.c 76da82a621fed40105172969f1a4af93bdab107fa07426f532502c498cf81eb8 +F src/global.c 89e36838a355f99cf86b118c3d4078fc3fc95cc9f992cbd70b422da8bfdf1789 F src/hash.c 8d7dda241d0ebdafb6ffdeda3149a412d7df75102cecfc1021c98d6219823b19 F src/hash.h 9d56a9079d523b648774c1784b74b89bd93fac7b365210157482e4319a468f38 F src/hwtime.h cb1d7e3e1ed94b7aa6fde95ae2c2daccc3df826be26fc9ed7fd90d1750ae6144 @@ -492,8 +492,8 @@ F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c e43c6475b302d094ffa01d76b784c719001c9cf24c0b5af96b78e5b25dc54b83 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c d74f5e7bd51f3c9d283442473eb65aef359664efd6513591c03f01881c4ae2da -F src/main.c 34d73303ac76015d3c8961f16d49ab44a56cbc998f178b27ca07847db4cf9273 -F src/malloc.c d74d986f91ebd6a4a9b2995467f4c13a1fdb57ac87df5bb0a7fa3afe1db72d1d +F src/main.c e9e8da06e089933c3151951be34ac7212212dd8d1551f1d84a2f4416e7af56e0 +F src/malloc.c eaa4dc9602ce28b077f7de2eb275db2be270c5cc56d7fec5466301bd9b80e2f5 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3 @@ -533,9 +533,9 @@ F src/shell.c.in 4a3a9e1c11847b1904f2b01d087af1c052f660902755abab457cab1756817de F src/sqlite.h.in 51f69c62ba3e980aca1e39badcaf9ad13f008774fe1bb8e7f57e3e456c656670 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 72af51aa4e912e14cd495fb6e7fac65f0940db80ed950d90911aff292cc47ce2 -F src/sqliteInt.h b5784a17e5ad158a759b2ed0a0d2ded1e1c3e9cf4cf51e4da21783790b9d0567 +F src/sqliteInt.h edc69ef8684086e8c195f969e47173ad960a0eb3f6298222b635e2ad3e0c1f98 F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b -F src/status.c baf38f521ac079be616dab1ff13f60c6ce0703c7f0429a65238c695197a56935 +F src/status.c 9ff2210207c6c3b4d9631a8241a7d45ab1b26a0e9c84cb07a9b5ce2de9a3b278 F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 F src/tclsqlite.c 8cd2600e8de23dff6cdf84d39f46ca57139b061b28f6f80b166bace17d52ab1c F src/test1.c c654981c1d86ebc90dd23fcc0969e6c85e28112f0acc2e2224a97a2a33e7c42f @@ -1853,7 +1853,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 47b71a84d1262c4bf6ad4f4a91820fd63593f08ae9efa144199d44972225e073 1dc83c5d54ca2890112e735e336c209adb8d067d2f647e9f8ae5d58f84a52461 -R 8dbc460e590e85bbe19d4191ea7ea91a +P 39d55579376906f212271ce9b2d367e3ad029fb173f22c7253312b467970208a +R c6267a3dfb8286b9a7bf015a7e8fc93b U drh -Z ac3eece56ae65a72ceccf8b58e31752f +Z 457f22be9b5a945c48c466bed56b269c diff --git a/manifest.uuid b/manifest.uuid index 47ee9f350b..2ca43abc99 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -39d55579376906f212271ce9b2d367e3ad029fb173f22c7253312b467970208a \ No newline at end of file +88d244983854cdc1a369c5df09ae00f1098784db768ba4e17b963d187dcb1009 \ No newline at end of file diff --git a/src/global.c b/src/global.c index 570002be4d..4072fa0d07 100644 --- a/src/global.c +++ b/src/global.c @@ -191,13 +191,13 @@ const unsigned char sqlite3CtypeMap[256] = { ** or at run-time for an individual database connection using ** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE); ** -** With the mini-lookaside enhancement, must less lookaside is required. -** The default configuration of 1200,40 actually proves 30 1200-byte slots -** and 93 128-byte slots, which is more lookaside slots that are available -** using the older 1200,100 configuration without mini-lookaside. +** With the two-size-lookaside enhancement, less lookaside is required. +** The default configuration of 1200,40 actually provides 30 1200-byte slots +** and 93 128-byte slots, which is more lookaside than is available +** using the older 1200,100 configuration without two-size-lookaside. */ #ifndef SQLITE_DEFAULT_LOOKASIDE -# ifdef SQLITE_OMIT_MINI_LOOKASIDE +# ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE # define SQLITE_DEFAULT_LOOKASIDE 1200,100 /* 120KB of memory */ # else # define SQLITE_DEFAULT_LOOKASIDE 1200,40 /* 48KB of memory */ diff --git a/src/main.c b/src/main.c index 9f541ff0d0..35741ab9f9 100644 --- a/src/main.c +++ b/src/main.c @@ -685,7 +685,7 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ void *pStart; sqlite3_int64 szAlloc = sz*(sqlite3_int64)cnt; int nBig; /* Number of full-size slots */ - int nSm; /* Number smaller mini-slots */ + int nSm; /* Number smaller LOOKASIDE_SMALL-byte slots */ if( sqlite3LookasideUsed(db,0)>0 ){ return SQLITE_BUSY; @@ -714,15 +714,15 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ }else{ pStart = pBuf; } -#ifndef SQLITE_OMIT_MINI_LOOKASIDE - if( sz>=MINI_SZ*3 ){ - nBig = szAlloc/(3*MINI_SZ+sz); - nSm = (szAlloc - sz*nBig)/MINI_SZ; - }else if( sz>=MINI_SZ*2 ){ - nBig = szAlloc/(MINI_SZ+sz); - nSm = (szAlloc - sz*nBig)/MINI_SZ; +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE + if( sz>=LOOKASIDE_SMALL*3 ){ + nBig = szAlloc/(3*LOOKASIDE_SMALL+sz); + nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL; + }else if( sz>=LOOKASIDE_SMALL*2 ){ + nBig = szAlloc/(LOOKASIDE_SMALL+sz); + nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL; }else -#endif /* SQLITE_OMIT_MINI_LOOKASIDE */ +#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */ if( sz>0 ){ nBig = szAlloc/sz; nSm = 0; @@ -744,16 +744,16 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ db->lookaside.pInit = p; p = (LookasideSlot*)&((u8*)p)[sz]; } -#ifndef SQLITE_OMIT_MINI_LOOKASIDE - db->lookaside.pMiniInit = 0; - db->lookaside.pMiniFree = 0; +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE + db->lookaside.pSmallInit = 0; + db->lookaside.pSmallFree = 0; db->lookaside.pMiddle = p; for(i=0; ipNext = db->lookaside.pMiniInit; - db->lookaside.pMiniInit = p; - p = (LookasideSlot*)&((u8*)p)[MINI_SZ]; + p->pNext = db->lookaside.pSmallInit; + db->lookaside.pSmallInit = p; + p = (LookasideSlot*)&((u8*)p)[LOOKASIDE_SMALL]; } -#endif /* SQLITE_OMIT_MINI_LOOKASIDE */ +#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */ assert( ((uptr)p)<=szAlloc + (uptr)pStart ); db->lookaside.pEnd = p; db->lookaside.bDisable = 0; @@ -761,11 +761,11 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ db->lookaside.nSlot = nBig+nSm; }else{ db->lookaside.pStart = db; -#ifndef SQLITE_OMIT_MINI_LOOKASIDE - db->lookaside.pMiniInit = 0; - db->lookaside.pMiniFree = 0; +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE + db->lookaside.pSmallInit = 0; + db->lookaside.pSmallFree = 0; db->lookaside.pMiddle = db; -#endif /* SQLITE_OMIT_MINI_LOOKASIDE */ +#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */ db->lookaside.pEnd = db; db->lookaside.bDisable = 1; db->lookaside.sz = 0; diff --git a/src/malloc.c b/src/malloc.c index 1074156eec..9dd400a3ba 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -333,8 +333,8 @@ int sqlite3MallocSize(void *p){ return sqlite3GlobalConfig.m.xSize(p); } static int lookasideMallocSize(sqlite3 *db, void *p){ -#ifndef SQLITE_OMIT_MINI_LOOKASIDE - return plookaside.pMiddle ? db->lookaside.szTrue : MINI_SZ; +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE + return plookaside.pMiddle ? db->lookaside.szTrue : LOOKASIDE_SMALL; #else return db->lookaside.szTrue; #endif @@ -354,10 +354,10 @@ int sqlite3DbMallocSize(sqlite3 *db, void *p){ #endif if( db ){ if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){ -#ifndef SQLITE_OMIT_MINI_LOOKASIDE +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){ assert( sqlite3_mutex_held(db->mutex) ); - return MINI_SZ; + return LOOKASIDE_SMALL; } #endif if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){ @@ -414,17 +414,17 @@ void sqlite3DbFreeNN(sqlite3 *db, void *p){ return; } if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){ -#ifndef SQLITE_OMIT_MINI_LOOKASIDE +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){ LookasideSlot *pBuf = (LookasideSlot*)p; #ifdef SQLITE_DEBUG - memset(p, 0xaa, MINI_SZ); /* Trash freed content */ + memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */ #endif - pBuf->pNext = db->lookaside.pMiniFree; - db->lookaside.pMiniFree = pBuf; + pBuf->pNext = db->lookaside.pSmallFree; + db->lookaside.pSmallFree = pBuf; return; } -#endif /* SQLITE_OMIT_MINI_LOOKASIDE */ +#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */ if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){ LookasideSlot *pBuf = (LookasideSlot*)p; #ifdef SQLITE_DEBUG @@ -597,14 +597,14 @@ void *sqlite3DbMallocRawNN(sqlite3 *db, u64 n){ } return dbMallocRawFinish(db, n); } -#ifndef SQLITE_OMIT_MINI_LOOKASIDE - if( n<=MINI_SZ ){ - if( (pBuf = db->lookaside.pMiniFree)!=0 ){ - db->lookaside.pMiniFree = pBuf->pNext; +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE + if( n<=LOOKASIDE_SMALL ){ + if( (pBuf = db->lookaside.pSmallFree)!=0 ){ + db->lookaside.pSmallFree = pBuf->pNext; db->lookaside.anStat[0]++; return (void*)pBuf; - }else if( (pBuf = db->lookaside.pMiniInit)!=0 ){ - db->lookaside.pMiniInit = pBuf->pNext; + }else if( (pBuf = db->lookaside.pSmallInit)!=0 ){ + db->lookaside.pSmallInit = pBuf->pNext; db->lookaside.anStat[0]++; return (void*)pBuf; } @@ -644,9 +644,9 @@ void *sqlite3DbRealloc(sqlite3 *db, void *p, u64 n){ if( p==0 ) return sqlite3DbMallocRawNN(db, n); assert( sqlite3_mutex_held(db->mutex) ); if( ((uptr)p)<(uptr)db->lookaside.pEnd ){ -#ifndef SQLITE_OMIT_MINI_LOOKASIDE +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE if( ((uptr)p)>=(uptr)db->lookaside.pMiddle ){ - if( n<=MINI_SZ ) return p; + if( n<=LOOKASIDE_SMALL ) return p; }else #endif if( ((uptr)p)>=(uptr)db->lookaside.pStart ){ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 463cfcefc5..1ed789eb7f 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1305,17 +1305,17 @@ struct Schema { ** outstanding at any point in the past - by subtracting the number of ** allocations on the pInit list from the total number of allocations. ** -** Enhancement on 2019-12-12: Mini-lookaside +** Enhancement on 2019-12-12: Two-size-lookaside ** The default lookaside configuration is 100 slots of 1200 bytes each. ** The larger slot sizes are important for performance, but they waste ** a lot of space, as most lookaside allocations are less than 128 bytes. -** The mini-lookaside enhancement breaks up the lookaside allocation into -** two pools: One of 128-byte slots and the other of the default size -** (1200-byte) slots. Allocations are filled from the mini-pool first, +** The two-size-lookaside enhancement breaks up the lookaside allocation +** into two pools: One of 128-byte slots and the other of the default size +** (1200-byte) slots. Allocations are filled from the small-pool first, ** failing over to the full-size pool if that does not work. Thus more ** lookaside slots are available while also using less memory. ** This enhancement can be omitted by compiling with -** SQLITE_OMIT_MINI_LOOKASIDE. +** SQLITE_OMIT_TWOSIZE_LOOKASIDE. */ struct Lookaside { u32 bDisable; /* Only operate the lookaside when zero */ @@ -1326,12 +1326,12 @@ struct Lookaside { u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */ LookasideSlot *pInit; /* List of buffers not previously used */ LookasideSlot *pFree; /* List of available buffers */ -#ifndef SQLITE_OMIT_MINI_LOOKASIDE - LookasideSlot *pMiniInit; /* List of mini buffers not prediously used */ - LookasideSlot *pMiniFree; /* List of available mini buffers */ +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE + LookasideSlot *pSmallInit; /* List of small buffers not prediously used */ + LookasideSlot *pSmallFree; /* List of available small buffers */ void *pMiddle; /* First byte past end of full-size buffers and - ** the first byte of mini-buffers */ -#endif /* SQLITE_OMIT_MINI_LOOKASIDE */ + ** the first byte of LOOKASIDE_SMALL buffers */ +#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */ void *pStart; /* First byte of available memory space */ void *pEnd; /* First byte past end of available space */ }; @@ -1343,11 +1343,11 @@ struct LookasideSlot { #define EnableLookaside db->lookaside.bDisable--;\ db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue -/* Size of the MINI lookside allocation */ -#ifdef SQLITE_OMIT_MINI_LOOKASIDE -# define MINI_SZ 0 +/* Size of the smaller allocations in two-size lookside */ +#ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE +# define LOOKASIDE_SMALL 0 #else -# define MINI_SZ 128 +# define LOOKASIDE_SMALL 128 #endif /* diff --git a/src/status.c b/src/status.c index 977457f8e3..c42bcc2856 100644 --- a/src/status.c +++ b/src/status.c @@ -188,10 +188,10 @@ static u32 countLookasideSlots(LookasideSlot *p){ int sqlite3LookasideUsed(sqlite3 *db, int *pHighwater){ u32 nInit = countLookasideSlots(db->lookaside.pInit); u32 nFree = countLookasideSlots(db->lookaside.pFree); -#ifndef SQLITE_OMIT_MINI_LOOKASIDE - nInit += countLookasideSlots(db->lookaside.pMiniInit); - nFree += countLookasideSlots(db->lookaside.pMiniFree); -#endif /* SQLITE_OMIT_MINI_LOOKASIDE */ +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE + nInit += countLookasideSlots(db->lookaside.pSmallInit); + nFree += countLookasideSlots(db->lookaside.pSmallFree); +#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */ if( pHighwater ) *pHighwater = db->lookaside.nSlot - nInit; return db->lookaside.nSlot - (nInit+nFree); } @@ -224,13 +224,13 @@ int sqlite3_db_status( db->lookaside.pInit = db->lookaside.pFree; db->lookaside.pFree = 0; } -#ifndef SQLITE_OMIT_MINI_LOOKASIDE - p = db->lookaside.pMiniFree; +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE + p = db->lookaside.pSmallFree; if( p ){ while( p->pNext ) p = p->pNext; - p->pNext = db->lookaside.pMiniInit; - db->lookaside.pMiniInit = db->lookaside.pMiniFree; - db->lookaside.pMiniFree = 0; + p->pNext = db->lookaside.pSmallInit; + db->lookaside.pSmallInit = db->lookaside.pSmallFree; + db->lookaside.pSmallFree = 0; } #endif } From 9fc1b9af36e54c7863a9404a9611abfb4b682374 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 2 Jan 2020 22:23:01 +0000 Subject: [PATCH 11/11] NEVER() and ALWAYS() macros tagging unreachable branches. FossilOrigin-Name: 34b877742ef78e9bb3f16815180f4ad9cd722beb1d610f713400a3b25d68aa9b --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/alter.c | 5 +++-- src/resolve.c | 8 ++++---- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 752a4f3e35..7cfd44f858 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\sthe\slatest\senhancements\sfrom\strunk. -D 2020-01-02T21:41:59.033 +C NEVER()\sand\sALWAYS()\smacros\stagging\sunreachable\sbranches. +D 2020-01-02T22:23:01.861 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -462,7 +462,7 @@ F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a -F src/alter.c 92604dd52bd73dbc4f0cc4f4a1b1fdd366e53cb0503494291e5798524beb74ec +F src/alter.c f48a4423c8f198d7f1ae4940f74b606707d05384ac79fb219be8e3323af2a2de F src/analyze.c b3ceec3fc052df8a96ca8a8c858d455dc5029ba681b4be98bb5c5a9162cfa58c F src/attach.c b30c44333d55a68c0a12920b5b9d40b254cbd3d4509bda77417209eeed8b3d80 F src/auth.c a3d5bfdba83d25abed1013a8c7a5f204e2e29b0c25242a56bc02bb0c07bf1e06 @@ -526,7 +526,7 @@ F src/pragma.h ec3b31eac9b1df040f1cc8cb3d89bc06605c3b4cb3d76f833de8d6d6c3f77f04 F src/prepare.c 6049beb71385f017af6fc320d2c75a4e50b75e280c54232442b785fbb83df057 F src/printf.c 9be6945837c839ba57837b4bc3af349eba630920fa5532aa518816defe42a7d4 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 -F src/resolve.c 6cc3ce3d674b027b437e5b3c4f0c29be7995dc8abf27f1ee8b16e3d070e19d2f +F src/resolve.c 938295261d556dc173e7c4b85c921b565b25c38656b924bdf03c3ff8f37e24ab F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93 F src/select.c 8791103f21df458fdaba16c7d6452f92b00363f222f0f242661654f12455ea0a F src/shell.c.in 90b002bf0054399cbbfac62dd752a9b05770427ba141bcba75eefbb0098f4280 @@ -1853,7 +1853,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 88d244983854cdc1a369c5df09ae00f1098784db768ba4e17b963d187dcb1009 7405e982257611803792617f5d8142c54f9831b4a030f4de8607888c525e6289 -R efdd5d9177183f4cebb9b751b044f27a +P bd57e6d923d3b04f0a07aaf18bf389d2b2b7efc7c57e8cb37e6ef910662d8397 +R 896a86b40586a93b7de7ff4de391d81d U drh -Z dc1b72a94a902754e9baf3ba10a5a0b3 +Z b012354b66730a3de909478223de72aa diff --git a/manifest.uuid b/manifest.uuid index d9e19f60fe..266bf3350f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bd57e6d923d3b04f0a07aaf18bf389d2b2b7efc7c57e8cb37e6ef910662d8397 \ No newline at end of file +34b877742ef78e9bb3f16815180f4ad9cd722beb1d610f713400a3b25d68aa9b \ No newline at end of file diff --git a/src/alter.c b/src/alter.c index f3caba4c18..ee193d18bf 100644 --- a/src/alter.c +++ b/src/alter.c @@ -811,7 +811,7 @@ void sqlite3RenameExprlistUnmap(Parse *pParse, ExprList *pEList){ sWalker.xExprCallback = renameUnmapExprCb; sqlite3WalkExprList(&sWalker, pEList); for(i=0; inExpr; i++){ - if( pEList->a[i].eEName==ENAME_NAME ){ + if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) ){ sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName); } } @@ -952,7 +952,8 @@ static void renameColumnElistNames( int i; for(i=0; inExpr; i++){ char *zName = pEList->a[i].zEName; - if( pEList->a[i].eEName==ENAME_NAME + if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) + && ALWAYS(zName!=0) && 0==sqlite3_stricmp(zName, zOld) ){ renameTokenFind(pParse, pCtx, (void*)zName); diff --git a/src/resolve.c b/src/resolve.c index 607cfd5df0..f69f9ef311 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -140,7 +140,7 @@ int sqlite3MatchEName( ){ int n; const char *zSpan; - if( pItem->eEName!=ENAME_TAB ) return 0; + if( NEVER(pItem->eEName!=ENAME_TAB) ) return 0; zSpan = pItem->zEName; for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){} if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){ @@ -451,9 +451,9 @@ static int lookupName( pEList = pNC->uNC.pEList; assert( pEList!=0 ); for(j=0; jnExpr; j++){ - char *zAs; + char *zAs = pEList->a[j].zEName; if( pEList->a[j].eEName==ENAME_NAME - && (zAs = pEList->a[j].zEName)!=0 + && ALWAYS(zAs!=0) && sqlite3StrICmp(zAs, zCol)==0 ){ Expr *pOrig; @@ -1125,7 +1125,7 @@ static int resolveAsName( for(i=0; inExpr; i++){ char *zAs = pEList->a[i].zEName; if( pEList->a[i].eEName==ENAME_NAME - && (zAs = pEList->a[i].zEName)!=0 + && ALWAYS(zAs!=0) && sqlite3StrICmp(zAs, zCol)==0 ){ return i+1;