]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Extra tests for incremental vacuum. (CVS 3879)
authordanielk1977 <danielk1977@noemail.net>
Fri, 27 Apr 2007 07:55:37 +0000 (07:55 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Fri, 27 Apr 2007 07:55:37 +0000 (07:55 +0000)
FossilOrigin-Name: 40ba6493e9e8ba135552a2a0943ab499713ac001

manifest
manifest.uuid
test/incrvacuum.test

index dc7a65686c23b2411be1de404abff995896dc122..b33caf688f75896f62fa310e5f0c3ec5affa46ed 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Modifications\sto\sbtree\sintegrity\scheck\sso\sthat\sit\scan\sbe\srun\sinside\sa\stransaction\safter\san\sincr\svacuum.\s(CVS\s3878)
-D 2007-04-27T07:05:44
+C Extra\stests\sfor\sincremental\svacuum.\s(CVS\s3879)
+D 2007-04-27T07:55:38
 F Makefile.in 8cab54f7c9f5af8f22fd97ddf1ecfd1e1860de62
 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -238,7 +238,7 @@ F test/fts2m.test 4b30142ead6f3ed076e880a2a464064c5ad58c51
 F test/func.test d66c42af501a77bd9b36c3d675d844b04db04765
 F test/hook.test 7e7645fd9a033f79cce8fdff151e32715e7ec50a
 F test/in.test 369cb2aa1eab02296b4ec470732fe8c131260b1d
-F test/incrvacuum.test 6c14f0492f00437ebf8275eac0a80f97799d99d4
+F test/incrvacuum.test fc5e88ac32095fb65ea11b739bc4e310c4852ef4
 F test/index.test e65df12bed94b2903ee89987115e1578687e9266
 F test/index2.test ee83c6b5e3173a3d7137140d945d9a5d4fdfb9d6
 F test/index3.test f66718cd92ce1216819d47e6a156755e4b2c4ca1
@@ -463,7 +463,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P e6a0c90dd9b4f7efe2153dd0c899b6e3d9846bd8
-R 3e1e2e05e5e9e264674bc6629d08b7ad
+P 4d4180d6474d8d74460fb9333580b9b60c89f353
+R cb55629cd4ed6b5c3bd0582e6bc3a138
 U danielk1977
-Z 1d29f050695ac44aa0f3dcac643e125b
+Z f3e9134088bb4d98704fded975f43270
index 0801a5cba8957ce15375476ff40e0305554c2196..dfc8508b511a3a2ebf5254d42e42776c786f914e 100644 (file)
@@ -1 +1 @@
-4d4180d6474d8d74460fb9333580b9b60c89f353
\ No newline at end of file
+40ba6493e9e8ba135552a2a0943ab499713ac001
\ No newline at end of file
index 63f12ffc2f6ea63e4c95a8e083f838c78993749d..912769858ed0890957205754cb913153c9826725 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the incremental vacuum feature.
 #
-# $Id: incrvacuum.test,v 1.2 2007/04/27 07:05:44 danielk1977 Exp $
+# $Id: incrvacuum.test,v 1.3 2007/04/27 07:55:38 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -226,7 +226,22 @@ do_test incrvacuum-5.2.4 {
     SELECT * FROM tbl2;
   }
 } {{a nice string}}
+do_test incrvacuum-5.2.5 {
+  execsql {
+    DROP TABLE tbl1;
+    DROP TABLE tbl2;
+    INCREMENTAL VACUUM;
+  }
+  expr {[file size test.db] / 1024}
+} {1}
+
 
+# Test cases incrvacuum-5.3.* use the following list as input data.
+# Two new databases are opened, one with incremental vacuum enabled,
+# the other with no auto-vacuum completely disabled. After executing
+# each element of the following list on both databases, test that
+# the integrity-check passes and the contents of each are identical.
+# 
 set TestScriptList [list {
   BEGIN;
   CREATE TABLE t1(a, b);
@@ -252,12 +267,19 @@ set TestScriptList [list {
 } {
   CREATE INDEX t3_i ON t3(a);
   COMMIT;
-}]
-
-file delete -force test1.db test1.db-journal
-file delete -force test2.db test2.db-journal
-
+} {
+  BEGIN;
+  DROP INDEX t3_i;
+  INCREMENTAL VACUUM;
+  INSERT INTO t3 VALUES('hello', 'world');
+  ROLLBACK;
+} {
+  INSERT INTO t3 VALUES('hello', 'world');
+}
+]
 
+# Compare the contents of databases $A and $B.
+#
 proc compare_dbs {A B tname} {
   set tbl_list [execsql {
     SELECT tbl_name FROM sqlite_master WHERE type = 'table'
@@ -280,6 +302,8 @@ proc compare_dbs {A B tname} {
 
 set ::str1 [string repeat abcdefghij 130]
 set ::str2 [string repeat 1234567890 105]
+
+file delete -force test1.db test1.db-journal test2.db test2.db-journal
 sqlite3 db1 test1.db
 sqlite3 db2 test2.db
 execsql { PRAGMA auto_vacuum = 'none' } db1
@@ -291,24 +315,116 @@ foreach sql $::TestScriptList {
   execsql $sql db2
 
   compare_dbs db1 db2 incrvacuum-5.3.${tn}
-  do_test incrvacuum-5.3.${tn}.integrity {
-    execsql {
-      PRAGMA integrity_check;
-    } db2
+  do_test incrvacuum-5.3.${tn}.integrity1 {
+    execsql { PRAGMA integrity_check; } db1
+  } {ok}
+  do_test incrvacuum-5.3.${tn}.integrity2 {
+    execsql { PRAGMA integrity_check; } db2
   } {ok}
   incr tn
 }
-
-
 db1 close
 db2 close
+#
+# End of test cases 5.3.*
 
+#---------------------------------------------------------------------
+# The following tests - incrvacuum-6.* - test running incremental 
+# vacuum while another statement (a read) is being executed.
+#
+for {set jj 0} {$jj < 10} {incr jj} {
+  # Build some test data. Two tables are created in an empty
+  # database. tbl1 data is a contiguous block starting at page 5 (pages
+  # 3 and 4 are the table roots). tbl2 is a contiguous block starting 
+  # right after tbl1.
+  #
+  # Then drop tbl1 so that when an incr vacuum is run the pages
+  # of tbl2 have to be moved to fill the gap.
+  #
+  do_test incrvacuum-6.${jj}.1 {
+    execsql {
+      DROP TABLE IF EXISTS tbl1;
+      DROP TABLE IF EXISTS tbl2;
+      INCREMENTAL VACUUM;
+      CREATE TABLE tbl1(a, b);
+      CREATE TABLE tbl2(a, b);
+      BEGIN;
+    }
+    for {set ii 0} {$ii < 1000} {incr ii} {
+      db eval {INSERT INTO tbl1 VALUES($ii, $ii || $ii)}
+    }
+    execsql {
+      INSERT INTO tbl2 SELECT * FROM tbl1;
+      COMMIT;
+      DROP TABLE tbl1;
+    }
+    expr {[file size test.db] / 1024}
+  } {36}
+
+  # Run a linear scan query on tbl2. After reading ($jj*100) rows, 
+  # run the incremental vacuum to shrink the database.
+  #
+  do_test incrvacuum-6.${jj}.2 {
+    set ::nRow 0
+    db eval {SELECT a FROM tbl2} {} {
+      if {$a == [expr $jj*100]} {
+        db eval {INCREMENTAL VACUUM}
+      }
+      incr ::nRow
+    }
+    list [expr {[file size test.db] / 1024}] $nRow
+  } {19 1000}
+}
 
 #---------------------------------------------------------------------
-# TODO: The following tests - incrvacuum-6.* - test that rolling back 
-# a transaction that contains an incremental vacuum operation 
-# works Ok.
+# This test - incrvacuum-7.* - is to check that the database can be
+# written in the middle of an incremental vacuum.
 #
+set ::iWrite 1
+while 1 {
+  do_test incrvacuum-7.${::iWrite}.1 {
+    execsql {
+      DROP TABLE IF EXISTS tbl1;
+      DROP TABLE IF EXISTS tbl2;
+      INCREMENTAL VACUUM;
+      CREATE TABLE tbl1(a, b);
+      CREATE TABLE tbl2(a, b);
+      BEGIN;
+    }
+    for {set ii 0} {$ii < 1000} {incr ii} {
+      db eval {INSERT INTO tbl1 VALUES($ii, $ii || $ii)}
+    }
+    execsql {
+      INSERT INTO tbl2 SELECT * FROM tbl1;
+      COMMIT;
+      DROP TABLE tbl1;
+    }
+    expr {[file size test.db] / 1024}
+  } {36}
+
+  do_test incrvacuum-7.${::iWrite}.2 {
+    set ::nRow 0
+    db eval {INCREMENTAL VACUUM} {
+      incr ::nRow
+      if {$::nRow == $::iWrite} {
+        db eval {
+          CREATE TABLE tbl1(a, b);
+          INSERT INTO tbl1 VALUES('hello', 'world');
+        }
+      }
+    }
+    list [expr {[file size test.db] / 1024}]
+  } {20}
+
+  do_test incrvacuum-7.${::iWrite}.3 {
+    execsql {
+      SELECT * FROM tbl1;
+    }
+  } {hello world}
+
+  if {$::nRow == $::iWrite} break
+  incr ::iWrite
+}
 
 finish_test