3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
12 # This file implements a test for VACUUM on attached databases.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 set testprefix vacuum5
19 # If the VACUUM statement is disabled in the current build, skip all
20 # the tests in this file.
27 forcedelete test2.db test3.db
28 do_execsql_test vacuum5-1.1 {
29 PRAGMA auto_vacuum = 0;
30 CREATE TABLE main.t1(a,b);
31 WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000)
32 INSERT INTO t1(a,b) SELECT x, randomblob(1000) FROM c;
33 CREATE TEMP TABLE ttemp(x,y);
34 INSERT INTO ttemp SELECT * FROM t1;
35 ATTACH 'test2.db' AS x2;
36 ATTACH 'test3.db' AS x3;
37 CREATE TABLE x2.t2(c,d);
38 INSERT INTO t2 SELECT * FROM t1;
39 CREATE TABLE x3.t3(e,f);
40 INSERT INTO t3 SELECT * FROM t1;
41 DELETE FROM t1 WHERE (rowid%3)!=0;
42 DELETE FROM t2 WHERE (rowid%4)!=0;
43 DELETE FROM t3 WHERE (rowid%5)!=0;
44 PRAGMA main.integrity_check;
45 PRAGMA x2.integrity_check;
46 PRAGMA x3.integrity_check;
48 set size1 [file size test.db]
49 set size2 [file size test2.db]
50 set size3 [file size test3.db]
52 do_execsql_test vacuum5-1.2.1 {
55 do_test vacuum5-1.2.2 {
56 expr {[file size test.db]<$size1}
58 do_test vacuum5-1.2.3 {
61 do_test vacuum5-1.2.4 {
64 set size1 [file size test.db]
65 do_execsql_test vacuum-1.2.5 {
67 PRAGMA main.integrity_check;
70 do_execsql_test vacuum5-1.3.1 {
73 do_test vacuum5-1.3.2 {
76 do_test vacuum5-1.3.3 {
77 expr {[file size test2.db]<$size2}
79 do_test vacuum5-1.3.4 {
82 set size2 [file size test2.db]
83 do_execsql_test vacuum-1.3.5 {
85 PRAGMA x2.integrity_check;
88 do_execsql_test vacuum5-1.4.1 {
91 do_test vacuum5-1.3.2 {
94 do_test vacuum5-1.3.3 {
97 do_test vacuum5-1.3.4 {
98 expr {[file size test3.db]<$size3}
101 # VACUUM is a no-op on the TEMP table
103 set sizeTemp [db one {PRAGMA temp.page_count}]
104 do_execsql_test vacuum5-1.4.1 {
107 do_execsql_test vacuum5-1.4.2 {
108 PRAGMA temp.page_count;
111 do_catchsql_test vacuum5-2.0 {
113 } {1 {unknown database olaf}}
115 #-------------------------------------------------------------------------
116 # Test that a temp file is opened as part of VACUUM.
118 if {$::TEMP_STORE<3 && [permutation]!="inmemory_journal"} {
125 set ::openfiles [list]
126 proc open_cb {method args} {
127 lappend ::openfiles [file tail [lindex $args 0]]
129 sqlite3 db test.db -vfs tvfs
131 do_execsql_test 3.0 {
132 PRAGMA temp_store = file;
133 PRAGMA page_size = 1024;
134 PRAGMA cache_size = 50;
135 CREATE TABLE t1(i INTEGER PRIMARY KEY, j UNIQUE);
137 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1000
139 INSERT INTO t1 SELECT NULL, randomblob(100) FROM s;
142 do_execsql_test 3.1 { VACUUM }
146 if {[atomic_batch_write test.db]==0} {
148 lrange $::openfiles 0 4
149 } {test.db test.db-journal test.db-journal {} test.db-journal}