diff options
author | dan <dan@noemail.net> | 2016-04-14 15:44:37 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2016-04-14 15:44:37 +0000 |
commit | fc26f7cfed8e8f3bd54072ced115f9ec1a1542b9 (patch) | |
tree | 63c7cd30bf31f78ebb40488171daf8a76d00267a /src/vdbesort.c | |
parent | 7111c93c408c6c927a4b632c5a6d2eb856a93fbe (diff) | |
download | sqlite-fc26f7cfed8e8f3bd54072ced115f9ec1a1542b9.tar.gz sqlite-fc26f7cfed8e8f3bd54072ced115f9ec1a1542b9.zip |
Correctly interpret negative "PRAGMA cache_size" values when determining the cache-size used for sorting large amounts of data (i.e. the functionality in vdbesort.c).
FossilOrigin-Name: 79147dca87cfd7eb62d57baa3b70fa2a8542232a
Diffstat (limited to 'src/vdbesort.c')
-rw-r--r-- | src/vdbesort.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/vdbesort.c b/src/vdbesort.c index 5913cda6d..7d5146cf0 100644 --- a/src/vdbesort.c +++ b/src/vdbesort.c @@ -931,7 +931,6 @@ int sqlite3VdbeSorterInit( ){ int pgsz; /* Page size of main database */ int i; /* Used to iterate through aTask[] */ - int mxCache; /* Cache size */ VdbeSorter *pSorter; /* The new sorter */ KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */ int szKeyInfo; /* Size of pCsr->pKeyInfo in bytes */ @@ -988,11 +987,20 @@ int sqlite3VdbeSorterInit( } if( !sqlite3TempInMemory(db) ){ + i64 mxCache; /* Cache size in bytes*/ u32 szPma = sqlite3GlobalConfig.szPma; pSorter->mnPmaSize = szPma * pgsz; + mxCache = db->aDb[0].pSchema->cache_size; - if( mxCache<(int)szPma ) mxCache = (int)szPma; - pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_PMASZ); + if( mxCache<0 ){ + /* A negative cache-size value C indicates that the cache is abs(C) + ** KiB in size. */ + mxCache = mxCache * -1024; + }else{ + mxCache = mxCache * pgsz; + } + mxCache = MIN(mxCache, SQLITE_MAX_PMASZ); + pSorter->mxPmaSize = MAX(pSorter->mnPmaSize, (int)mxCache); /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary |