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 { 28*b6ea12ccSdan PRAGMA auto_vacuum = 0; 299ef5e770Sdrh CREATE TABLE main.t1(a,b); 309ef5e770Sdrh WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000) 319ef5e770Sdrh INSERT INTO t1(a,b) SELECT x, randomblob(1000) FROM c; 329ef5e770Sdrh CREATE TEMP TABLE ttemp(x,y); 339ef5e770Sdrh INSERT INTO ttemp SELECT * FROM t1; 349ef5e770Sdrh ATTACH 'test2.db' AS x2; 359ef5e770Sdrh ATTACH 'test3.db' AS x3; 369ef5e770Sdrh CREATE TABLE x2.t2(c,d); 379ef5e770Sdrh INSERT INTO t2 SELECT * FROM t1; 389ef5e770Sdrh CREATE TABLE x3.t3(e,f); 399ef5e770Sdrh INSERT INTO t3 SELECT * FROM t1; 409ef5e770Sdrh DELETE FROM t1 WHERE (rowid%3)!=0; 419ef5e770Sdrh DELETE FROM t2 WHERE (rowid%4)!=0; 429ef5e770Sdrh DELETE FROM t3 WHERE (rowid%5)!=0; 439ef5e770Sdrh PRAGMA main.integrity_check; 449ef5e770Sdrh PRAGMA x2.integrity_check; 459ef5e770Sdrh PRAGMA x3.integrity_check; 469ef5e770Sdrh} {ok ok ok} 479ef5e770Sdrhset size1 [file size test.db] 489ef5e770Sdrhset size2 [file size test2.db] 499ef5e770Sdrhset size3 [file size test3.db] 509ef5e770Sdrh 519ef5e770Sdrhdo_execsql_test vacuum5-1.2.1 { 529ef5e770Sdrh VACUUM main; 539ef5e770Sdrh} {} 549ef5e770Sdrhdo_test vacuum5-1.2.2 { 559ef5e770Sdrh expr {[file size test.db]<$size1} 569ef5e770Sdrh} {1} 579ef5e770Sdrhdo_test vacuum5-1.2.3 { 589ef5e770Sdrh file size test2.db 599ef5e770Sdrh} $size2 609ef5e770Sdrhdo_test vacuum5-1.2.4 { 619ef5e770Sdrh file size test3.db 629ef5e770Sdrh} $size3 639ef5e770Sdrhset size1 [file size test.db] 649ef5e770Sdrhdo_execsql_test vacuum-1.2.5 { 659ef5e770Sdrh DELETE FROM t1; 669ef5e770Sdrh PRAGMA main.integrity_check; 679ef5e770Sdrh} {ok} 689ef5e770Sdrh 699ef5e770Sdrhdo_execsql_test vacuum5-1.3.1 { 709ef5e770Sdrh VACUUM x2; 719ef5e770Sdrh} {} 729ef5e770Sdrhdo_test vacuum5-1.3.2 { 739ef5e770Sdrh file size test.db 749ef5e770Sdrh} $size1 759ef5e770Sdrhdo_test vacuum5-1.3.3 { 769ef5e770Sdrh expr {[file size test2.db]<$size2} 779ef5e770Sdrh} 1 789ef5e770Sdrhdo_test vacuum5-1.3.4 { 799ef5e770Sdrh file size test3.db 809ef5e770Sdrh} $size3 819ef5e770Sdrhset size2 [file size test2.db] 829ef5e770Sdrhdo_execsql_test vacuum-1.3.5 { 839ef5e770Sdrh DELETE FROM t2; 849ef5e770Sdrh PRAGMA x2.integrity_check; 859ef5e770Sdrh} {ok} 869ef5e770Sdrh 879ef5e770Sdrhdo_execsql_test vacuum5-1.4.1 { 889ef5e770Sdrh VACUUM x3; 899ef5e770Sdrh} {} 909ef5e770Sdrhdo_test vacuum5-1.3.2 { 919ef5e770Sdrh file size test.db 929ef5e770Sdrh} $size1 939ef5e770Sdrhdo_test vacuum5-1.3.3 { 949ef5e770Sdrh file size test2.db 959ef5e770Sdrh} $size2 969ef5e770Sdrhdo_test vacuum5-1.3.4 { 979ef5e770Sdrh expr {[file size test3.db]<$size3} 989ef5e770Sdrh} 1 999ef5e770Sdrh 1009ef5e770Sdrh# VACUUM is a no-op on the TEMP table 1019ef5e770Sdrh# 1029ef5e770Sdrhset sizeTemp [db one {PRAGMA temp.page_count}] 1039ef5e770Sdrhdo_execsql_test vacuum5-1.4.1 { 1049ef5e770Sdrh VACUUM temp; 1059ef5e770Sdrh} {} 1069ef5e770Sdrhdo_execsql_test vacuum5-1.4.2 { 1079ef5e770Sdrh PRAGMA temp.page_count; 1089ef5e770Sdrh} $sizeTemp 1099ef5e770Sdrh 1109ef5e770Sdrhdo_catchsql_test vacuum5-2.0 { 1119ef5e770Sdrh VACUUM olaf; 1129ef5e770Sdrh} {1 {unknown database olaf}} 113ff02e200Sdan 114ff02e200Sdanfinish_test 115