From: drh Date: Thu, 3 Nov 2016 18:36:26 +0000 (+0000) Subject: Fix an issue that was causing the new database image to be assembled entirely X-Git-Tag: version-3.15.1~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e876607623c037b33c6102a67b7cc5f72dd10e1a;p=thirdparty%2Fsqlite.git Fix an issue that was causing the new database image to be assembled entirely in heap memory when VACUUMing a database, even if it should use a temp file. This could cause SQLITE_NOMEM errors when vacuuming very large databases on 32-bit systems. FossilOrigin-Name: 3fae483faea3370785ac44ac65dbd03c21b9f6f2 --- diff --git a/manifest b/manifest index 76d7b42cc0..38a70f6c67 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\sleft-join\smarkings\sare\stransferred\sto\sthe\svirtual\sscalar\nsubexpressions\swhen\sdecomposing\sa\svector\scomparison\sin\sthe\sON\sclause\sof\na\sLEFT\sJOIN.\nFix\sfor\sticket\s[fef4bb4bd9185ec8f]. -D 2016-11-03T18:35:19.014 +C Fix\san\sissue\sthat\swas\scausing\sthe\snew\sdatabase\simage\sto\sbe\sassembled\sentirely\nin\sheap\smemory\swhen\sVACUUMing\sa\sdatabase,\seven\sif\sit\sshould\suse\sa\stemp\sfile.\nThis\scould\scause\sSQLITE_NOMEM\serrors\swhen\svacuuming\svery\slarge\sdatabases\son\n32-bit\ssystems. +D 2016-11-03T18:36:26.648 F Makefile.in 6fd48ffcf7c2deea7499062d1f3747f986c19678 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 5151cc64c4c05f3455f4f692ad11410a810d937f @@ -453,7 +453,7 @@ F src/trigger.c 3419bb9862983d84d70735fb4c94b21b934cd0c5 F src/update.c 8179e699dbd45b92934fd02d3d8e3732e8da8802 F src/utf.c 699001c79f28e48e9bcdf8a463da029ea660540c F src/util.c 3e2da6101888d073e79ecc6af5e0a2f70fa1e498 -F src/vacuum.c 913970b9d86dd6c2b8063ef1af421880f1464ec3 +F src/vacuum.c 33c174b28886b2faf26e503b5a49a1c01a9b1c16 F src/vdbe.c f43aa96f2efe9bc8a06d17115661af527a3318fa F src/vdbe.h c044be7050ac6bf596eecc6ab159f5dbc020a3b7 F src/vdbeInt.h d8a56a491b752dbb5f671963b8c861ec72ea875e @@ -1342,7 +1342,7 @@ F test/vacuum.test ce91c39f7f91a4273bf620efad21086b5aa6ef1d F test/vacuum2.test aa048abee196c16c9ba308465494009057b79f9b F test/vacuum3.test 77ecdd54592b45a0bcb133339f99f1ae0ae94d0d F test/vacuum4.test d3f8ecff345f166911568f397d2432c16d2867d9 -F test/vacuum5.test 0b7ac80c64eed657b4ce2dd6535092c0d6afec6c +F test/vacuum5.test 800b5e881fa3dfdc1be252f2a45f107c75176628 F test/vacuummem.test 7b42abb3208bd82dd23a7536588396f295a314f2 F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 F test/veryquick.test 57ab846bacf7b90cf4e9a672721ea5c5b669b661 @@ -1526,8 +1526,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 54eeddeceb7545c9843d4ddf4ff73a894214c43b -Q +619f5cc71774a37648e185c8502d7af14eb09b7f -R 9b1102c35e4cb06cf53ebb9652488d69 +P aba1e22bbae1cd21f6e1d10773ccbfc4682db52c +Q +3028845329c9b7acdec2ec8b01d00d782347454c +R 066c1719b90bfa8c3894f730ba9a5b9d U drh -Z 4255b479a7cc8a73ed5c42bbcc82c7b0 +Z d5f09b343d4020b2e128c64e1cab952f diff --git a/manifest.uuid b/manifest.uuid index 5543212928..16f0e036b5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -aba1e22bbae1cd21f6e1d10773ccbfc4682db52c \ No newline at end of file +3fae483faea3370785ac44ac65dbd03c21b9f6f2 \ No newline at end of file diff --git a/src/vacuum.c b/src/vacuum.c index 295beb6752..25b1258510 100644 --- a/src/vacuum.c +++ b/src/vacuum.c @@ -191,7 +191,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db, int iDb){ sqlite3BtreeSetCacheSize(pTemp, db->aDb[iDb].pSchema->cache_size); sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0)); - sqlite3BtreeSetPagerFlags(pTemp, PAGER_SYNCHRONOUS_OFF); + sqlite3BtreeSetPagerFlags(pTemp, PAGER_SYNCHRONOUS_OFF|PAGER_CACHESPILL); /* Begin a transaction and take an exclusive lock on the main database ** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below, diff --git a/test/vacuum5.test b/test/vacuum5.test index 16b15b64a1..c44b200964 100644 --- a/test/vacuum5.test +++ b/test/vacuum5.test @@ -14,6 +14,7 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix vacuum5 # If the VACUUM statement is disabled in the current build, skip all # the tests in this file. @@ -111,4 +112,41 @@ do_catchsql_test vacuum5-2.0 { VACUUM olaf; } {1 {unknown database olaf}} +#------------------------------------------------------------------------- +# Test that a temp file is opened as part of VACUUM. +# +if {$::TEMP_STORE<3} { + db close + testvfs tvfs + tvfs filter xOpen + tvfs script open_cb + forcedelete test.db + + set ::openfiles [list] + proc open_cb {method args} { + lappend ::openfiles [file tail [lindex $args 0]] + } + sqlite3 db test.db -vfs tvfs + + do_execsql_test 3.0 { + PRAGMA page_size = 1024; + PRAGMA cache_size = 50; + CREATE TABLE t1(i INTEGER PRIMARY KEY, j UNIQUE); + WITH s(i) AS ( + VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1000 + ) + INSERT INTO t1 SELECT NULL, randomblob(100) FROM s; + } + + do_execsql_test 3.1 { VACUUM } + + db close + tvfs delete + do_test 3.2 { + set ::openfiles + } {test.db test.db-journal test.db-journal {} test.db-journal} +} + + + finish_test