]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Correctly interpret negative "PRAGMA cache_size" values when determining the cache...
authordrh <drh@noemail.net>
Mon, 18 Apr 2016 16:18:13 +0000 (16:18 +0000)
committerdrh <drh@noemail.net>
Mon, 18 Apr 2016 16:18:13 +0000 (16:18 +0000)
FossilOrigin-Name: 39dd67afa508aea8f41387806b263b760512377f

manifest
manifest.uuid
src/vdbesort.c
test/sort5.test

index 211533b3a7e7401de55c7869fdb2906773263b42..fdec0de5f137ff302654b4642799327728780e75 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\sproblem\sin\sthe\scode\sgenerator\sfor\sjoins\son\svirtual\stables\swhere\sthe\nouter\sloop\sof\sthe\sjoin\suses\sthe\sIN\soperator.
-D 2016-04-18T16:12:04.978
+C Correctly\sinterpret\snegative\s"PRAGMA\scache_size"\svalues\swhen\sdetermining\sthe\scache-size\sused\sfor\ssorting\slarge\samounts\sof\sdata\s(i.e.\sthe\sfunctionality\sin\svdbesort.c).
+D 2016-04-18T16:18:13.574
 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc b00bcf0ec7001857aea81ee39fae45d20f5f4e59
@@ -426,7 +426,7 @@ F src/vdbeapi.c 95b1f8e527240a18a9aea41a655b013bf07a7009
 F src/vdbeaux.c c8dd3e4e932bede6363b380519d05c0557ad27ce
 F src/vdbeblob.c 3b570b730109e8f653d9d2081649f6e7015113db
 F src/vdbemem.c fe76c1f866de362d9b8332e59d74aa44f6560d69
-F src/vdbesort.c 307460bfa4de4d1c3901fcd42089159131e34062
+F src/vdbesort.c 0a8f98366ae794442e6d1ef71d9553226d885d19
 F src/vdbetrace.c f75c5455d8cf389ef86a8bfdfd3177e0e3692484
 F src/vtab.c 23b6cdfa996152d43b390504ed4a942c8caf3a00
 F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
@@ -1050,7 +1050,7 @@ F test/sort.test c2adc635c2564241fefec0b3a68391ef6868fd3b
 F test/sort2.test cc23b7c19d684657559e8a55b02f7fcee03851d0
 F test/sort3.test 1480ed7c4c157682542224e05e3b75faf4a149e5
 F test/sort4.test 5c34d9623a4ae5921d956dfa2b70e77ed0fc6e5c
-F test/sort5.test d3041ce3c475aa04142a959ae56ef6593f98a99f
+F test/sort5.test e47ec7a490b9b36787755874175d8f413a3883d9
 F test/sortfault.test d4ccf606a0c77498e2beb542764fd9394acb4d66
 F test/speed1.test f2974a91d79f58507ada01864c0e323093065452
 F test/speed1p.explain d841e650a04728b39e6740296b852dccdca9b2cb
@@ -1459,8 +1459,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 368e86c760477f2e646f71f6135b69d40eeb82e7
-Q +6c56b3a04778bc62ca50307ad838dd301cd91ac2
-R acf6a347f3f839bd74b9fc7a6f34fbf3
+P a2cf49689642c2157288829e96c21c0de83e3a1b
+Q +79147dca87cfd7eb62d57baa3b70fa2a8542232a
+R 104c6fbe1d009b71ad568ed52ec9c95a
 U drh
-Z 542d8ddb7626d61cadebfc7721d64c25
+Z 3cb8bbd587ad296a28a8ae5fa5124a04
index baefd8fce3431baf7a5b73d6375ed56a8b7fc33d..322551a66da6aa82af85a7e73065539bf8092d00 100644 (file)
@@ -1 +1 @@
-a2cf49689642c2157288829e96c21c0de83e3a1b
\ No newline at end of file
+39dd67afa508aea8f41387806b263b760512377f
\ No newline at end of file
index 5913cda6d0643ff98578b84ef490fed14d16af24..7d5146cf0b4d8e6bfb35a367ca58a18ddd5b8741 100644 (file)
@@ -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
index 5b1292bb48ff9e6ba6606332bf6778b60410f4ee..9fb2dff2815f644e824dba64d2c9a398cb915afd 100644 (file)
@@ -41,4 +41,76 @@ do_execsql_test 1.2 {
 
 db close
 tvfs delete
+
+#-------------------------------------------------------------------------
+# Test that the PMA size is determined correctly. The PMA size should be
+# roughly the same amount of memory allocated to the main pager cache, or
+# 250 pages if this is larger.
+#
+testvfs tvfs
+tvfs script tv_callback
+tvfs filter {xOpen xWrite}
+
+proc tv_callback {method args} {
+  global iTemp
+  global F
+  switch $method {
+    xOpen {
+      if {[lindex $args 0]==""} { return "temp[incr iTemp]" }
+      return "SQLITE_OK"
+    }
+
+    xWrite {
+      foreach {filename id off amt} $args {}
+      if {[info exists F($id)]==0 || $F($id)<($off + $amt)} {
+        set F($id) [expr $off+$amt]
+      }
+    }
+  }
+}
+
+catch { db close }
+forcedelete test.db
+sqlite3 db test.db -vfs tvfs
+execsql { CREATE TABLE t1(x) }
+
+# Each iteration of the following loop attempts to sort 10001 records
+# each a bit over 100 bytes in size. In total a little more than 1MiB 
+# of data.
+#
+breakpoint
+foreach {tn pgsz cachesz bTemp} {
+  2 1024   1000  1
+
+  1 4096   1000  0
+  2 1024   1000  1
+
+  3 4096  -1000  1
+  4 1024  -1000  1
+
+  5 4096  -9000  0
+  6 1024  -9000  0
+} {
+  do_execsql_test 2.$tn.0 "
+    PRAGMA page_size = $pgsz;
+    VACUUM;
+    PRAGMA cache_size = $cachesz;
+  "
+
+  do_test 2.$tn.1 {
+    set ::iTemp 0
+    catch { array unset F }
+    execsql {
+      WITH x(i, j) AS (
+        SELECT 1, randomblob(100)
+        UNION ALL
+        SELECT i+1, randomblob(100) FROM x WHERE i<10000
+      )
+      SELECT * FROM x ORDER BY j;
+    }
+    expr {[array names F]!=""}
+  } $bTemp
+}
+
 finish_test
+