xref: /sqlite-3.40.0/test/vacuum5.test (revision ff02e200)
19ef5e770Sdrh# 2016-08-19
29ef5e770Sdrh#
39ef5e770Sdrh# The author disclaims copyright to this source code.  In place of
49ef5e770Sdrh# a legal notice, here is a blessing:
59ef5e770Sdrh#
69ef5e770Sdrh#    May you do good and not evil.
79ef5e770Sdrh#    May you find forgiveness for yourself and forgive others.
89ef5e770Sdrh#    May you share freely, never taking more than you give.
99ef5e770Sdrh#
109ef5e770Sdrh#***********************************************************************
119ef5e770Sdrh#
129ef5e770Sdrh# This file implements a test for VACUUM on attached databases.
139ef5e770Sdrh#
149ef5e770Sdrh
159ef5e770Sdrhset testdir [file dirname $argv0]
169ef5e770Sdrhsource $testdir/tester.tcl
179ef5e770Sdrh
189ef5e770Sdrh# If the VACUUM statement is disabled in the current build, skip all
199ef5e770Sdrh# the tests in this file.
209ef5e770Sdrh#
219ef5e770Sdrhifcapable !vacuum {
229ef5e770Sdrh  finish_test
239ef5e770Sdrh  return
249ef5e770Sdrh}
259ef5e770Sdrh
269ef5e770Sdrhforcedelete test2.db test3.db
279ef5e770Sdrhdo_execsql_test vacuum5-1.1 {
289ef5e770Sdrh  CREATE TABLE main.t1(a,b);
299ef5e770Sdrh  WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000)
309ef5e770Sdrh    INSERT INTO t1(a,b) SELECT x, randomblob(1000) FROM c;
319ef5e770Sdrh  CREATE TEMP TABLE ttemp(x,y);
329ef5e770Sdrh  INSERT INTO ttemp SELECT * FROM t1;
339ef5e770Sdrh  ATTACH 'test2.db' AS x2;
349ef5e770Sdrh  ATTACH 'test3.db' AS x3;
359ef5e770Sdrh  CREATE TABLE x2.t2(c,d);
369ef5e770Sdrh  INSERT INTO t2 SELECT * FROM t1;
379ef5e770Sdrh  CREATE TABLE x3.t3(e,f);
389ef5e770Sdrh  INSERT INTO t3 SELECT * FROM t1;
399ef5e770Sdrh  DELETE FROM t1 WHERE (rowid%3)!=0;
409ef5e770Sdrh  DELETE FROM t2 WHERE (rowid%4)!=0;
419ef5e770Sdrh  DELETE FROM t3 WHERE (rowid%5)!=0;
429ef5e770Sdrh  PRAGMA main.integrity_check;
439ef5e770Sdrh  PRAGMA x2.integrity_check;
449ef5e770Sdrh  PRAGMA x3.integrity_check;
459ef5e770Sdrh} {ok ok ok}
469ef5e770Sdrhset size1 [file size test.db]
479ef5e770Sdrhset size2 [file size test2.db]
489ef5e770Sdrhset size3 [file size test3.db]
499ef5e770Sdrh
509ef5e770Sdrhdo_execsql_test vacuum5-1.2.1 {
519ef5e770Sdrh  VACUUM main;
529ef5e770Sdrh} {}
539ef5e770Sdrhdo_test vacuum5-1.2.2 {
549ef5e770Sdrh  expr {[file size test.db]<$size1}
559ef5e770Sdrh} {1}
569ef5e770Sdrhdo_test vacuum5-1.2.3 {
579ef5e770Sdrh  file size test2.db
589ef5e770Sdrh} $size2
599ef5e770Sdrhdo_test vacuum5-1.2.4 {
609ef5e770Sdrh  file size test3.db
619ef5e770Sdrh} $size3
629ef5e770Sdrhset size1 [file size test.db]
639ef5e770Sdrhdo_execsql_test vacuum-1.2.5 {
649ef5e770Sdrh  DELETE FROM t1;
659ef5e770Sdrh  PRAGMA main.integrity_check;
669ef5e770Sdrh} {ok}
679ef5e770Sdrh
689ef5e770Sdrhdo_execsql_test vacuum5-1.3.1 {
699ef5e770Sdrh  VACUUM x2;
709ef5e770Sdrh} {}
719ef5e770Sdrhdo_test vacuum5-1.3.2 {
729ef5e770Sdrh  file size test.db
739ef5e770Sdrh} $size1
749ef5e770Sdrhdo_test vacuum5-1.3.3 {
759ef5e770Sdrh  expr {[file size test2.db]<$size2}
769ef5e770Sdrh} 1
779ef5e770Sdrhdo_test vacuum5-1.3.4 {
789ef5e770Sdrh  file size test3.db
799ef5e770Sdrh} $size3
809ef5e770Sdrhset size2 [file size test2.db]
819ef5e770Sdrhdo_execsql_test vacuum-1.3.5 {
829ef5e770Sdrh  DELETE FROM t2;
839ef5e770Sdrh  PRAGMA x2.integrity_check;
849ef5e770Sdrh} {ok}
859ef5e770Sdrh
869ef5e770Sdrhdo_execsql_test vacuum5-1.4.1 {
879ef5e770Sdrh  VACUUM x3;
889ef5e770Sdrh} {}
899ef5e770Sdrhdo_test vacuum5-1.3.2 {
909ef5e770Sdrh  file size test.db
919ef5e770Sdrh} $size1
929ef5e770Sdrhdo_test vacuum5-1.3.3 {
939ef5e770Sdrh  file size test2.db
949ef5e770Sdrh} $size2
959ef5e770Sdrhdo_test vacuum5-1.3.4 {
969ef5e770Sdrh  expr {[file size test3.db]<$size3}
979ef5e770Sdrh} 1
989ef5e770Sdrh
999ef5e770Sdrh# VACUUM is a no-op on the TEMP table
1009ef5e770Sdrh#
1019ef5e770Sdrhset sizeTemp [db one {PRAGMA temp.page_count}]
1029ef5e770Sdrhdo_execsql_test vacuum5-1.4.1 {
1039ef5e770Sdrh  VACUUM temp;
1049ef5e770Sdrh} {}
1059ef5e770Sdrhdo_execsql_test vacuum5-1.4.2 {
1069ef5e770Sdrh  PRAGMA temp.page_count;
1079ef5e770Sdrh} $sizeTemp
1089ef5e770Sdrh
1099ef5e770Sdrhdo_catchsql_test vacuum5-2.0 {
1109ef5e770Sdrh  VACUUM olaf;
1119ef5e770Sdrh} {1 {unknown database olaf}}
112*ff02e200Sdan
113*ff02e200Sdanfinish_test
114