]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Avoid unnecessarily reseting the pager cache after committing a transaction that...
authordan <dan@noemail.net>
Fri, 26 Apr 2013 18:36:58 +0000 (18:36 +0000)
committerdan <dan@noemail.net>
Fri, 26 Apr 2013 18:36:58 +0000 (18:36 +0000)
FossilOrigin-Name: c47144e98c0a0f9e09780c945de10c57b6a495ea

manifest
manifest.uuid
src/pager.c
test/io.test

index de4051d5666e5de3738a6da51338ee2df572b3c6..c5c2b1f688deeae71288bcc1a91155144737deb0 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Avoid\susing\sposix_fallocate()\sin\sWAL\smode,\sas\sit\sis\snot\ssupported\sby\sall\sfile-systems.
-D 2013-04-26T17:00:52.665
+C Avoid\sunnecessarily\sreseting\sthe\spager\scache\safter\scommitting\sa\stransaction\sthat\stakes\sadvantage\sof\sthe\sSQLITE_IOCAP_ATOMIC\srelated\soptimization.
+D 2013-04-26T18:36:58.055
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in ce81671efd6223d19d4c8c6b88ac2c4134427111
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -179,7 +179,7 @@ F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f
 F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
 F src/os_unix.c f86cd628ffb9ccf3adcc5c15b02c00a64eaf598e
 F src/os_win.c 673b3e3d1fa3040d8d95a7f1f5e0e553aed56cfb
-F src/pager.c 6c3a8a5d665498b0344395a2c9f82d5abc4cc771
+F src/pager.c 4a9160d268977e56ae2df90182050ab30fca715d
 F src/pager.h 5cb78b8e1adfd5451e600be7719f5a99d87ac3b1
 F src/parse.y 5d5e12772845805fdfeb889163516b84fbb9ae95
 F src/pcache.c f8043b433a57aba85384a531e3937a804432a346
@@ -571,7 +571,7 @@ F test/instr.test a34e1d46a9eefb098a7167ef0e730a4a3d82fba0
 F test/intarray.test 066b7d7ac38d25bf96f87f1b017bfc687551cdd4
 F test/interrupt.test dfe9a67a94b0b2d8f70545ba1a6cca10780d71cc
 F test/intpkey.test 7af30f6ae852d8d1c2b70e4bf1551946742e92d8
-F test/io.test a4be25a446a99a0604ceecc039ee7363c56e4185
+F test/io.test b90105d295225a712e2e9cb685876101712058b5
 F test/ioerr.test 40bb2cfcab63fb6aa7424cd97812a84bc16b5fb8
 F test/ioerr2.test 9d71166f8466eda510f1af6137bdabaa82b5408d
 F test/ioerr3.test d3cec5e1a11ad6d27527d0d38573fbff14c71bdd
@@ -1062,7 +1062,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
-P 640eb54ad6aac9bc7109cba167389a9bcec3f21e 9c7523dabf4aee609287732ce787c9b9a9087e7f
-R b4ea9ecffc738493e7005d865dad4b9a
+P 1bbb4be1a25947f75b2b0c6f368199016b6f7de3
+R 50c4e22fb69fce6bfb1bbec0cac61356
 U dan
-Z 8914d43d4bd2278afd40d03ae3982d74
+Z 042ff5429ace151fb0c673232d14fee9
index 86ca24f5f4ea3536deaa13ed11de1edcd5e8d005..58806060f6bbf1d34567eace65e51c2220785d0d 100644 (file)
@@ -1 +1 @@
-1bbb4be1a25947f75b2b0c6f368199016b6f7de3
\ No newline at end of file
+c47144e98c0a0f9e09780c945de10c57b6a495ea
\ No newline at end of file
index 1c8b5df6518b2824de82f771dffe5904280adae4..dffcf602d7bd748b95c0f9ec5de59021603ce0bc 100644 (file)
@@ -5927,6 +5927,11 @@ static int pager_incr_changecounter(Pager *pPager, int isDirectMode){
           pPager->aStat[PAGER_STAT_WRITE]++;
         }
         if( rc==SQLITE_OK ){
+          /* Update the pager's copy of the change-counter. Otherwise, the
+          ** next time a read transaction is opened the cache will be
+          ** flushed (as the change-counter values will not match).  */
+          const void *pCopy = (const void *)&((const char *)zBuf)[24];
+          memcpy(&pPager->dbFileVers, pCopy, sizeof(pPager->dbFileVers));
           pPager->changeCountDone = 1;
         }
       }else{
index bf4d1572759ba8c59c6d1e2e2957d814424edfe6..f9583e0e33553d5cbe93f0c6fa0bf73267f4b4e9 100644 (file)
@@ -38,6 +38,10 @@ sqlite3 db test.db -vfs devsym
 #
 # io-5.* -  Test that the default page size is selected and used 
 #           correctly.
+#
+# io-6.* -  Test that the pager-cache is not being flushed unnecessarily 
+#           after a transaction that uses the special atomic-write path
+#           is committed.
 #           
 
 set ::nWrite 0
@@ -565,5 +569,67 @@ foreach {char                 sectorsize pgsize} {
   } $pgsize
 }
 
+#----------------------------------------------------------------------
+#
+do_test io-6.1 {
+  db close
+  sqlite3_simulate_device -char atomic
+  forcedelete test.db
+  sqlite3 db test.db -vfs devsym
+  execsql {
+    PRAGMA mmap_size = 0;
+    PRAGMA page_size = 1024;
+    CREATE TABLE t1(x);
+    CREATE TABLE t2(x);
+    CREATE TABLE t3(x);
+    CREATE INDEX i3 ON t3(x);
+    INSERT INTO t3 VALUES(randomblob(100));
+    INSERT INTO t3 SELECT randomblob(100) FROM t3;
+    INSERT INTO t3 SELECT randomblob(100) FROM t3;
+    INSERT INTO t3 SELECT randomblob(100) FROM t3;
+    INSERT INTO t3 SELECT randomblob(100) FROM t3;
+    INSERT INTO t3 SELECT randomblob(100) FROM t3;
+    INSERT INTO t3 SELECT randomblob(100) FROM t3;
+    INSERT INTO t3 SELECT randomblob(100) FROM t3;
+    INSERT INTO t3 SELECT randomblob(100) FROM t3;
+    INSERT INTO t3 SELECT randomblob(100) FROM t3;
+    INSERT INTO t3 SELECT randomblob(100) FROM t3;
+    INSERT INTO t3 SELECT randomblob(100) FROM t3;
+  }
+
+  db_save_and_close
+} {}
+
+foreach {tn sql} {
+  1 { BEGIN;
+        INSERT INTO t1 VALUES('123');
+        INSERT INTO t2 VALUES('456');
+      COMMIT;
+  }
+  2 { BEGIN;
+        INSERT INTO t1 VALUES('123');
+      COMMIT;
+  }
+} {
+  db_restore
+  sqlite3 db test.db -vfs devsym
+  execsql {
+    PRAGMA mmap_size = 0;
+    SELECT x FROM t3 ORDER BY rowid;
+    SELECT x FROM t3 ORDER BY x;
+  }
+  do_execsql_test 6.2.$tn.1 { PRAGMA integrity_check } {ok}
+  do_execsql_test 6.2.$tn.2 $sql
+
+  # Corrupt the database file on disk. This should not matter for the
+  # purposes of the following "PRAGMA integrity_check", as the entire
+  # database should be cached in the pager-cache. If corruption is
+  # reported, it indicates that executing $sql caused the pager cache
+  # to be flushed. Which is a bug.
+  hexio_write test.db [expr 1024 * 5] [string repeat 00 2048]
+  do_execsql_test 6.2.$tn.3 { PRAGMA integrity_check } {ok}
+}
+
 sqlite3_simulate_device -char {} -sectorsize 0
 finish_test
+