mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-24 22:22:08 +03:00
Avoid constantly freeing and reallocing small internal buffers associated with
LSM cursors. Instead, allow them to persist for the lifetime of the cursor if they are LSM_SEGMENTPTR_FREE_THRESHOLD (default 1024) bytes or smaller. FossilOrigin-Name: bacfe8cb3e4d3be736c6789b2ce55ef5603e5c7a289b05b37cae2203cd7f2290
This commit is contained in:
@ -98,6 +98,11 @@
|
||||
#define PGFTR_SKIP_NEXT_FLAG 0x0002
|
||||
#define PGFTR_SKIP_THIS_FLAG 0x0004
|
||||
|
||||
|
||||
#ifndef LSM_SEGMENTPTR_FREE_THRESHOLD
|
||||
# define LSM_SEGMENTPTR_FREE_THRESHOLD 1024
|
||||
#endif
|
||||
|
||||
typedef struct SegmentPtr SegmentPtr;
|
||||
typedef struct Blob Blob;
|
||||
|
||||
@ -1148,7 +1153,11 @@ static void sortedSplitkey(lsm_db *pDb, Level *pLevel, int *pRc){
|
||||
*pRc = rc;
|
||||
}
|
||||
|
||||
static void segmentPtrReset(SegmentPtr *pPtr){
|
||||
/*
|
||||
** Reset a segment cursor. Also free its buffers if they are nThreshold
|
||||
** bytes or larger in size.
|
||||
*/
|
||||
static void segmentPtrReset(SegmentPtr *pPtr, int nThreshold){
|
||||
lsmFsPageRelease(pPtr->pPg);
|
||||
pPtr->pPg = 0;
|
||||
pPtr->nCell = 0;
|
||||
@ -1158,8 +1167,8 @@ static void segmentPtrReset(SegmentPtr *pPtr){
|
||||
pPtr->nVal = 0;
|
||||
pPtr->eType = 0;
|
||||
pPtr->iCell = 0;
|
||||
sortedBlobFree(&pPtr->blob1);
|
||||
sortedBlobFree(&pPtr->blob2);
|
||||
if( pPtr->blob1.nAlloc>=nThreshold ) sortedBlobFree(&pPtr->blob1);
|
||||
if( pPtr->blob2.nAlloc>=nThreshold ) sortedBlobFree(&pPtr->blob2);
|
||||
}
|
||||
|
||||
static int segmentPtrIgnoreSeparators(MultiCursor *pCsr, SegmentPtr *pPtr){
|
||||
@ -1206,7 +1215,7 @@ static int segmentPtrAdvance(
|
||||
rtTopic(pPtr->eType), pPtr->pKey, pPtr->nKey,
|
||||
pLvl->iSplitTopic, pLvl->pSplitKey, pLvl->nSplitKey
|
||||
);
|
||||
if( res<0 ) segmentPtrReset(pPtr);
|
||||
if( res<0 ) segmentPtrReset(pPtr, LSM_SEGMENTPTR_FREE_THRESHOLD);
|
||||
}
|
||||
|
||||
if( pPtr->pPg==0 && (svFlags & LSM_END_DELETE) ){
|
||||
@ -1275,7 +1284,7 @@ static int segmentPtrEnd(MultiCursor *pCsr, SegmentPtr *pPtr, int bLast){
|
||||
rtTopic(pPtr->eType), pPtr->pKey, pPtr->nKey,
|
||||
pLvl->iSplitTopic, pLvl->pSplitKey, pLvl->nSplitKey
|
||||
);
|
||||
if( res<0 ) segmentPtrReset(pPtr);
|
||||
if( res<0 ) segmentPtrReset(pPtr, LSM_SEGMENTPTR_FREE_THRESHOLD);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1611,7 +1620,7 @@ static int segmentPtrFwdPointer(
|
||||
rc = ptrFwdPointer(ptr.pPg, ptr.iCell, ptr.pSeg, &iOut, &bFound);
|
||||
ptr.pPg = 0;
|
||||
}
|
||||
segmentPtrReset(&ptr);
|
||||
segmentPtrReset(&ptr, 0);
|
||||
}
|
||||
|
||||
*piPtr = iOut;
|
||||
@ -1658,7 +1667,7 @@ static int segmentPtrSeek(
|
||||
|| lsmFsDbPageIsLast(pPtr->pSeg, pPtr->pPg)
|
||||
);
|
||||
if( pPtr->nCell==0 ){
|
||||
segmentPtrReset(pPtr);
|
||||
segmentPtrReset(pPtr, LSM_SEGMENTPTR_FREE_THRESHOLD);
|
||||
}else{
|
||||
iMin = 0;
|
||||
iMax = pPtr->nCell-1;
|
||||
@ -1716,7 +1725,7 @@ static int segmentPtrSeek(
|
||||
}
|
||||
pCsr->flags |= CURSOR_SEEK_EQ;
|
||||
}
|
||||
segmentPtrReset(pPtr);
|
||||
segmentPtrReset(pPtr, LSM_SEGMENTPTR_FREE_THRESHOLD);
|
||||
break;
|
||||
}
|
||||
case LSM_SEEK_LE:
|
||||
@ -1943,7 +1952,7 @@ static int seekInLevel(
|
||||
rtTopic(pPtr->eType), pPtr->pKey, pPtr->nKey,
|
||||
pLvl->iSplitTopic, pLvl->pSplitKey, pLvl->nSplitKey
|
||||
);
|
||||
if( res<0 ) segmentPtrReset(pPtr);
|
||||
if( res<0 ) segmentPtrReset(pPtr, LSM_SEGMENTPTR_FREE_THRESHOLD);
|
||||
}
|
||||
|
||||
if( aPtr[i].pKey ) bHit = 1;
|
||||
@ -2219,7 +2228,7 @@ static void mcursorFreeComponents(MultiCursor *pCsr){
|
||||
|
||||
/* Reset the segment pointers */
|
||||
for(i=0; i<pCsr->nPtr; i++){
|
||||
segmentPtrReset(&pCsr->aPtr[i]);
|
||||
segmentPtrReset(&pCsr->aPtr[i], 0);
|
||||
}
|
||||
|
||||
/* And the b-tree cursor, if any */
|
||||
@ -2874,7 +2883,7 @@ static int multiCursorEnd(MultiCursor *pCsr, int bLast){
|
||||
if( bHit==0 && rc==LSM_OK ){
|
||||
rc = segmentPtrEnd(pCsr, pPtr, 1);
|
||||
}else{
|
||||
segmentPtrReset(pPtr);
|
||||
segmentPtrReset(pPtr, LSM_SEGMENTPTR_FREE_THRESHOLD);
|
||||
}
|
||||
}else{
|
||||
int bLhs = (pPtr->pSeg==&pLvl->lhs);
|
||||
@ -2886,7 +2895,7 @@ static int multiCursorEnd(MultiCursor *pCsr, int bLast){
|
||||
}
|
||||
for(iRhs=0; iRhs<pLvl->nRight && rc==LSM_OK; iRhs++){
|
||||
if( bHit ){
|
||||
segmentPtrReset(&pPtr[iRhs+1]);
|
||||
segmentPtrReset(&pPtr[iRhs+1], LSM_SEGMENTPTR_FREE_THRESHOLD);
|
||||
}else{
|
||||
rc = sortedRhsFirst(pCsr, pLvl, &pPtr[iRhs+bLhs]);
|
||||
}
|
||||
@ -2969,7 +2978,7 @@ void lsmMCursorReset(MultiCursor *pCsr){
|
||||
lsmTreeCursorReset(pCsr->apTreeCsr[0]);
|
||||
lsmTreeCursorReset(pCsr->apTreeCsr[1]);
|
||||
for(i=0; i<pCsr->nPtr; i++){
|
||||
segmentPtrReset(&pCsr->aPtr[i]);
|
||||
segmentPtrReset(&pCsr->aPtr[i], LSM_SEGMENTPTR_FREE_THRESHOLD);
|
||||
}
|
||||
pCsr->key.nData = 0;
|
||||
}
|
||||
@ -6079,8 +6088,8 @@ static int assertPointersOk(
|
||||
}
|
||||
}
|
||||
|
||||
segmentPtrReset(&ptr1);
|
||||
segmentPtrReset(&ptr2);
|
||||
segmentPtrReset(&ptr1, 0);
|
||||
segmentPtrReset(&ptr2, 0);
|
||||
return LSM_OK;
|
||||
}
|
||||
|
||||
|
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
||||
C In\sthe\scommand-line\sshell,\sadd\sthe\s-quote\soption\sto\sstart\sup\sin\squote\smode.\nEnhance\sthe\s".mode"\scommand\sso\sthat\sit\sreports\sthe\scurrent\soutput\smode\sif\ngiven\sno\sarguments.
|
||||
D 2017-06-29T21:33:25.847
|
||||
C Avoid\sconstantly\sfreeing\sand\sreallocing\ssmall\sinternal\sbuffers\sassociated\swith\nLSM\scursors.\sInstead,\sallow\sthem\sto\spersist\sfor\sthe\slifetime\sof\sthe\scursor\sif\nthey\sare\sLSM_SEGMENTPTR_FREE_THRESHOLD\s(default\s1024)\sbytes\sor\ssmaller.
|
||||
D 2017-06-30T11:44:11.712
|
||||
F Makefile.in 081e48dfe7f995d57ce1a88ddf4d2917b4349158648a6cd45b42beae30de3a12
|
||||
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
|
||||
F Makefile.msc 4ebb1d257cac7fb1bcb4ba59278416d410ff1c4bf59447a9c37a415f3516056a
|
||||
@ -244,7 +244,7 @@ F ext/lsm1/lsm_main.c f52eada2910f8a57bd4cafcee39c6c375f6b7ed8
|
||||
F ext/lsm1/lsm_mem.c 4c51ea9fa285ee6e35301b33491642d071740a0a
|
||||
F ext/lsm1/lsm_mutex.c 378edf0a2b142b4f7640ee982df06d50b98788ea
|
||||
F ext/lsm1/lsm_shared.c 54cc3a5157c6abd77f7d3ae60708b9f7bf022b3c
|
||||
F ext/lsm1/lsm_sorted.c 4a9e3ffecda87b379ed757b59c9cbcd84a80b55c
|
||||
F ext/lsm1/lsm_sorted.c 62cc605a66cf8e0e6ab3593281c2476a787fc4b2013c618dd17568d18c730070
|
||||
F ext/lsm1/lsm_str.c 77ebdd5040ddf267a6f724d4c83132d2dce8a226
|
||||
F ext/lsm1/lsm_tree.c 5d9fb2bc58a1a70c75126bd8d7198f7b627e165b
|
||||
F ext/lsm1/lsm_unix.c 14aaebdd7a7e9abb57cc16890c8444b241de272bfc2303b68f6e6b984040dc1e
|
||||
@ -1628,7 +1628,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 7782c04e9b2c0e95b5ac2a38876c1a233becfd892140bc6844790d62aeaff4f7
|
||||
R fdaec3a4a9930118ae9822ddeb4d3259
|
||||
U drh
|
||||
Z c0bf63d58bf1bc98c2ecc9c2e3c0756c
|
||||
P 5e3f9ea5c4fad35fe02a12d59114e94ee00e0a09c1840c88908a4c282e2f4625
|
||||
R e4ed1fd49ca170fbcc3ace94e802f0dd
|
||||
U dan
|
||||
Z 88693dceee9c2741baead710728f55cc
|
||||
|
@ -1 +1 @@
|
||||
5e3f9ea5c4fad35fe02a12d59114e94ee00e0a09c1840c88908a4c282e2f4625
|
||||
bacfe8cb3e4d3be736c6789b2ce55ef5603e5c7a289b05b37cae2203cd7f2290
|
Reference in New Issue
Block a user