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 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this file is changing the database page size using a
15 # $Id: vacuum3.test,v 1.9 2008/08/26 21:07:27 drh Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 # If the VACUUM statement is disabled in the current build, skip all
21 # the tests in this file.
29 #-------------------------------------------------------------------
30 # Test cases vacuum3-1.* convert a simple 2-page database between a
31 # few different page sizes.
35 PRAGMA auto_vacuum=OFF;
36 PRAGMA page_size = 1024;
37 CREATE TABLE t1(a, b, c);
38 INSERT INTO t1 VALUES(1, 2, 3);
42 execsql { PRAGMA page_size }
49 foreach {request actual database} [list \
58 do_test vacuum3-1.$I.1 {
60 PRAGMA page_size = $request;
63 execsql { PRAGMA page_size }
65 do_test vacuum3-1.$I.2 {
68 do_test vacuum3-1.$I.3 {
69 execsql { SELECT * FROM t1 }
71 integrity_check vacuum3-1.$I.4
76 #-------------------------------------------------------------------
77 # Test cases vacuum3-2.* convert a simple 3-page database between a
78 # few different page sizes.
82 PRAGMA page_size = 1024;
85 ifcapable altertable {
86 execsql { ALTER TABLE t1 ADD COLUMN d; }
90 CREATE TABLE t1(a, b, c, d);
91 INSERT INTO t1 VALUES(1, 2, 3, NULL);
95 UPDATE t1 SET d = randomblob(1000);
100 execsql { PRAGMA page_size }
102 do_test vacuum3-2.3 {
103 set blob [db one {select d from t1}]
108 foreach {request actual database} [list \
117 do_test vacuum3-2.$I.1 {
119 PRAGMA page_size = $request;
122 execsql { PRAGMA page_size }
124 do_test vacuum3-2.$I.2 {
127 do_test vacuum3-2.$I.3 {
128 execsql { SELECT * FROM t1 }
130 integrity_check vacuum3-1.$I.4
135 #-------------------------------------------------------------------
136 # Test cases vacuum3-3.* converts a database large enough to include
137 # the locking page (in a test environment) between few different
141 return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}]
143 do_test vacuum3-3.1 {
145 PRAGMA page_size = 1024;
147 CREATE TABLE abc(a PRIMARY KEY, b, c);
148 INSERT INTO abc VALUES(randomblob(100), randomblob(200), randomblob(1000));
150 SELECT randomblob(1000), randomblob(200), randomblob(100)
153 SELECT randomblob(100), randomblob(200), randomblob(1000)
156 SELECT randomblob(100), randomblob(200), randomblob(1000)
159 SELECT randomblob(100), randomblob(200), randomblob(1000)
162 SELECT randomblob(100), randomblob(200), randomblob(1000)
165 SELECT randomblob(25), randomblob(45), randomblob(9456)
168 SELECT randomblob(100), randomblob(200), randomblob(1000)
171 SELECT randomblob(25), randomblob(45), randomblob(9456)
176 do_test vacuum3-3.2 {
177 execsql { PRAGMA page_size }
180 set ::sig [signature]
183 foreach {request actual} [list \
192 do_test vacuum3-3.$I.1 {
194 PRAGMA page_size = $request;
197 execsql { PRAGMA page_size }
199 do_test vacuum3-3.$I.2 {
202 integrity_check vacuum3-3.$I.3
207 do_test vacuum3-4.1 {
212 PRAGMA page_size=1024;
213 CREATE TABLE abc(a, b, c);
214 INSERT INTO abc VALUES(1, 2, 3);
215 INSERT INTO abc VALUES(4, 5, 6);
217 execsql { SELECT * FROM abc }
219 do_test vacuum3-4.2 {
221 execsql { SELECT * FROM abc } db2
223 do_test vacuum3-4.3 {
225 PRAGMA page_size = 2048;
228 execsql { SELECT * FROM abc }
230 do_test vacuum3-4.4 {
231 execsql { SELECT * FROM abc } db2
233 do_test vacuum3-4.5 {
235 PRAGMA page_size=16384;
238 execsql { SELECT * FROM abc } db2
240 do_test vacuum3-4.6 {
242 PRAGMA page_size=1024;
245 execsql { SELECT * FROM abc } db2
248 # Unable to change the page-size of an in-memory using vacuum.
251 do_test vacuum3-5.1 {
254 INSERT INTO t1 VALUES(1234);
255 PRAGMA page_size=4096;
260 do_test vacuum3-5.2 {
266 set create_database_sql {
268 CREATE TABLE t1(a, b, c);
269 INSERT INTO t1 VALUES(1, randstr(50,50), randstr(50,50));
270 INSERT INTO t1 SELECT a+2, b||'-'||rowid, c||'-'||rowid FROM t1;
271 INSERT INTO t1 SELECT a+4, b||'-'||rowid, c||'-'||rowid FROM t1;
272 INSERT INTO t1 SELECT a+8, b||'-'||rowid, c||'-'||rowid FROM t1;
273 INSERT INTO t1 SELECT a+16, b||'-'||rowid, c||'-'||rowid FROM t1;
274 INSERT INTO t1 SELECT a+32, b||'-'||rowid, c||'-'||rowid FROM t1;
275 INSERT INTO t1 SELECT a+64, b||'-'||rowid, c||'-'||rowid FROM t1;
276 INSERT INTO t1 SELECT a+128, b||'-'||rowid, c||'-'||rowid FROM t1;
277 INSERT INTO t1 VALUES(1, randstr(600,600), randstr(600,600));
278 CREATE TABLE t2 AS SELECT * FROM t1;
279 CREATE TABLE t3 AS SELECT * FROM t1;
284 do_ioerr_test vacuum3-ioerr-1 -cksum true -sqlprep "
285 PRAGMA page_size = 1024;
288 PRAGMA page_size = 4096;
291 do_ioerr_test vacuum3-ioerr-2 -cksum true -sqlprep "
292 PRAGMA page_size = 2048;
295 PRAGMA page_size = 512;
299 ifcapable autovacuum {
300 do_ioerr_test vacuum3-ioerr-3 -cksum true -sqlprep "
301 PRAGMA auto_vacuum = 0;
304 PRAGMA auto_vacuum = 1;
307 do_ioerr_test vacuum3-ioerr-4 -cksum true -sqlprep "
308 PRAGMA auto_vacuum = 1;
311 PRAGMA auto_vacuum = 0;
316 source $testdir/malloc_common.tcl
318 do_malloc_test vacuum3-malloc-1 -sqlprep {
319 PRAGMA page_size = 2048;
321 CREATE TABLE t1(a, b, c);
322 INSERT INTO t1 VALUES(1, randstr(50,50), randstr(50,50));
323 INSERT INTO t1 SELECT a+2, b||'-'||rowid, c||'-'||rowid FROM t1;
324 INSERT INTO t1 SELECT a+4, b||'-'||rowid, c||'-'||rowid FROM t1;
325 INSERT INTO t1 SELECT a+8, b||'-'||rowid, c||'-'||rowid FROM t1;
326 INSERT INTO t1 SELECT a+16, b||'-'||rowid, c||'-'||rowid FROM t1;
327 INSERT INTO t1 SELECT a+32, b||'-'||rowid, c||'-'||rowid FROM t1;
328 INSERT INTO t1 SELECT a+64, b||'-'||rowid, c||'-'||rowid FROM t1;
329 INSERT INTO t1 SELECT a+128, b||'-'||rowid, c||'-'||rowid FROM t1;
330 INSERT INTO t1 VALUES(1, randstr(600,600), randstr(600,600));
331 CREATE TABLE t2 AS SELECT * FROM t1;
332 CREATE TABLE t3 AS SELECT * FROM t1;
336 PRAGMA page_size = 512;
339 do_malloc_test vacuum3-malloc-2 -sqlprep {
340 PRAGMA encoding=UTF16;
341 CREATE TABLE t1(a, b, c);
342 INSERT INTO t1 VALUES(1, 2, 3);
343 CREATE TABLE t2(x,y,z);
344 INSERT INTO t2 SELECT * FROM t1;