1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
# 2016-08-19
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file implements a test for VACUUM on attached databases.
#
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.
#
ifcapable !vacuum {
finish_test
return
}
forcedelete test2.db test3.db
do_execsql_test vacuum5-1.1 {
PRAGMA auto_vacuum = 0;
CREATE TABLE main.t1(a,b);
WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000)
INSERT INTO t1(a,b) SELECT x, randomblob(1000) FROM c;
CREATE TEMP TABLE ttemp(x,y);
INSERT INTO ttemp SELECT * FROM t1;
ATTACH 'test2.db' AS x2;
ATTACH 'test3.db' AS x3;
CREATE TABLE x2.t2(c,d);
INSERT INTO t2 SELECT * FROM t1;
CREATE TABLE x3.t3(e,f);
INSERT INTO t3 SELECT * FROM t1;
DELETE FROM t1 WHERE (rowid%3)!=0;
DELETE FROM t2 WHERE (rowid%4)!=0;
DELETE FROM t3 WHERE (rowid%5)!=0;
PRAGMA main.integrity_check;
PRAGMA x2.integrity_check;
PRAGMA x3.integrity_check;
} {ok ok ok}
set size1 [file size test.db]
set size2 [file size test2.db]
set size3 [file size test3.db]
do_execsql_test vacuum5-1.2.1 {
VACUUM main;
} {}
do_test vacuum5-1.2.2 {
expr {[file size test.db]<$size1}
} {1}
do_test vacuum5-1.2.3 {
file size test2.db
} $size2
do_test vacuum5-1.2.4 {
file size test3.db
} $size3
set size1 [file size test.db]
do_execsql_test vacuum-1.2.5 {
DELETE FROM t1;
PRAGMA main.integrity_check;
} {ok}
do_execsql_test vacuum5-1.3.1 {
VACUUM x2;
} {}
do_test vacuum5-1.3.2 {
file size test.db
} $size1
do_test vacuum5-1.3.3 {
expr {[file size test2.db]<$size2}
} 1
do_test vacuum5-1.3.4 {
file size test3.db
} $size3
set size2 [file size test2.db]
do_execsql_test vacuum-1.3.5 {
DELETE FROM t2;
PRAGMA x2.integrity_check;
} {ok}
do_execsql_test vacuum5-1.4.1 {
VACUUM x3;
} {}
do_test vacuum5-1.3.2 {
file size test.db
} $size1
do_test vacuum5-1.3.3 {
file size test2.db
} $size2
do_test vacuum5-1.3.4 {
expr {[file size test3.db]<$size3}
} 1
# VACUUM is a no-op on the TEMP table
#
set sizeTemp [db one {PRAGMA temp.page_count}]
do_execsql_test vacuum5-1.4.1 {
VACUUM temp;
} {}
do_execsql_test vacuum5-1.4.2 {
PRAGMA temp.page_count;
} $sizeTemp
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 && [permutation]!="inmemory_journal"} {
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 temp_store = file;
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
if {[atomic_batch_write test.db]==0} {
do_test 3.2 {
lrange $::openfiles 0 4
} {test.db test.db-journal test.db-journal {} test.db-journal}
}
}
finish_test
|