xref: /sqlite-3.40.0/test/vacuum5.test (revision 9ef5e770)
1*9ef5e770Sdrh# 2016-08-19
2*9ef5e770Sdrh#
3*9ef5e770Sdrh# The author disclaims copyright to this source code.  In place of
4*9ef5e770Sdrh# a legal notice, here is a blessing:
5*9ef5e770Sdrh#
6*9ef5e770Sdrh#    May you do good and not evil.
7*9ef5e770Sdrh#    May you find forgiveness for yourself and forgive others.
8*9ef5e770Sdrh#    May you share freely, never taking more than you give.
9*9ef5e770Sdrh#
10*9ef5e770Sdrh#***********************************************************************
11*9ef5e770Sdrh#
12*9ef5e770Sdrh# This file implements a test for VACUUM on attached databases.
13*9ef5e770Sdrh#
14*9ef5e770Sdrh
15*9ef5e770Sdrhset testdir [file dirname $argv0]
16*9ef5e770Sdrhsource $testdir/tester.tcl
17*9ef5e770Sdrh
18*9ef5e770Sdrh# If the VACUUM statement is disabled in the current build, skip all
19*9ef5e770Sdrh# the tests in this file.
20*9ef5e770Sdrh#
21*9ef5e770Sdrhifcapable !vacuum {
22*9ef5e770Sdrh  finish_test
23*9ef5e770Sdrh  return
24*9ef5e770Sdrh}
25*9ef5e770Sdrh
26*9ef5e770Sdrhforcedelete test2.db test3.db
27*9ef5e770Sdrhdo_execsql_test vacuum5-1.1 {
28*9ef5e770Sdrh  CREATE TABLE main.t1(a,b);
29*9ef5e770Sdrh  WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000)
30*9ef5e770Sdrh    INSERT INTO t1(a,b) SELECT x, randomblob(1000) FROM c;
31*9ef5e770Sdrh  CREATE TEMP TABLE ttemp(x,y);
32*9ef5e770Sdrh  INSERT INTO ttemp SELECT * FROM t1;
33*9ef5e770Sdrh  ATTACH 'test2.db' AS x2;
34*9ef5e770Sdrh  ATTACH 'test3.db' AS x3;
35*9ef5e770Sdrh  CREATE TABLE x2.t2(c,d);
36*9ef5e770Sdrh  INSERT INTO t2 SELECT * FROM t1;
37*9ef5e770Sdrh  CREATE TABLE x3.t3(e,f);
38*9ef5e770Sdrh  INSERT INTO t3 SELECT * FROM t1;
39*9ef5e770Sdrh  DELETE FROM t1 WHERE (rowid%3)!=0;
40*9ef5e770Sdrh  DELETE FROM t2 WHERE (rowid%4)!=0;
41*9ef5e770Sdrh  DELETE FROM t3 WHERE (rowid%5)!=0;
42*9ef5e770Sdrh  PRAGMA main.integrity_check;
43*9ef5e770Sdrh  PRAGMA x2.integrity_check;
44*9ef5e770Sdrh  PRAGMA x3.integrity_check;
45*9ef5e770Sdrh} {ok ok ok}
46*9ef5e770Sdrhset size1 [file size test.db]
47*9ef5e770Sdrhset size2 [file size test2.db]
48*9ef5e770Sdrhset size3 [file size test3.db]
49*9ef5e770Sdrh
50*9ef5e770Sdrhdo_execsql_test vacuum5-1.2.1 {
51*9ef5e770Sdrh  VACUUM main;
52*9ef5e770Sdrh} {}
53*9ef5e770Sdrhdo_test vacuum5-1.2.2 {
54*9ef5e770Sdrh  expr {[file size test.db]<$size1}
55*9ef5e770Sdrh} {1}
56*9ef5e770Sdrhdo_test vacuum5-1.2.3 {
57*9ef5e770Sdrh  file size test2.db
58*9ef5e770Sdrh} $size2
59*9ef5e770Sdrhdo_test vacuum5-1.2.4 {
60*9ef5e770Sdrh  file size test3.db
61*9ef5e770Sdrh} $size3
62*9ef5e770Sdrhset size1 [file size test.db]
63*9ef5e770Sdrhdo_execsql_test vacuum-1.2.5 {
64*9ef5e770Sdrh  DELETE FROM t1;
65*9ef5e770Sdrh  PRAGMA main.integrity_check;
66*9ef5e770Sdrh} {ok}
67*9ef5e770Sdrh
68*9ef5e770Sdrhdo_execsql_test vacuum5-1.3.1 {
69*9ef5e770Sdrh  VACUUM x2;
70*9ef5e770Sdrh} {}
71*9ef5e770Sdrhdo_test vacuum5-1.3.2 {
72*9ef5e770Sdrh  file size test.db
73*9ef5e770Sdrh} $size1
74*9ef5e770Sdrhdo_test vacuum5-1.3.3 {
75*9ef5e770Sdrh  expr {[file size test2.db]<$size2}
76*9ef5e770Sdrh} 1
77*9ef5e770Sdrhdo_test vacuum5-1.3.4 {
78*9ef5e770Sdrh  file size test3.db
79*9ef5e770Sdrh} $size3
80*9ef5e770Sdrhset size2 [file size test2.db]
81*9ef5e770Sdrhdo_execsql_test vacuum-1.3.5 {
82*9ef5e770Sdrh  DELETE FROM t2;
83*9ef5e770Sdrh  PRAGMA x2.integrity_check;
84*9ef5e770Sdrh} {ok}
85*9ef5e770Sdrh
86*9ef5e770Sdrhdo_execsql_test vacuum5-1.4.1 {
87*9ef5e770Sdrh  VACUUM x3;
88*9ef5e770Sdrh} {}
89*9ef5e770Sdrhdo_test vacuum5-1.3.2 {
90*9ef5e770Sdrh  file size test.db
91*9ef5e770Sdrh} $size1
92*9ef5e770Sdrhdo_test vacuum5-1.3.3 {
93*9ef5e770Sdrh  file size test2.db
94*9ef5e770Sdrh} $size2
95*9ef5e770Sdrhdo_test vacuum5-1.3.4 {
96*9ef5e770Sdrh  expr {[file size test3.db]<$size3}
97*9ef5e770Sdrh} 1
98*9ef5e770Sdrh
99*9ef5e770Sdrh# VACUUM is a no-op on the TEMP table
100*9ef5e770Sdrh#
101*9ef5e770Sdrhset sizeTemp [db one {PRAGMA temp.page_count}]
102*9ef5e770Sdrhdo_execsql_test vacuum5-1.4.1 {
103*9ef5e770Sdrh  VACUUM temp;
104*9ef5e770Sdrh} {}
105*9ef5e770Sdrhdo_execsql_test vacuum5-1.4.2 {
106*9ef5e770Sdrh  PRAGMA temp.page_count;
107*9ef5e770Sdrh} $sizeTemp
108*9ef5e770Sdrh
109*9ef5e770Sdrhdo_catchsql_test vacuum5-2.0 {
110*9ef5e770Sdrh  VACUUM olaf;
111*9ef5e770Sdrh} {1 {unknown database olaf}}
112