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;
84 ALTER TABLE t1 ADD COLUMN d;
85 UPDATE t1 SET d = randomblob(1000);
90 execsql { PRAGMA page_size }
93 set blob [db one {select d from t1}]
98 foreach {request actual database} [list \
107 do_test vacuum3-2.$I.1 {
109 PRAGMA page_size = $request;
112 execsql { PRAGMA page_size }
114 do_test vacuum3-2.$I.2 {
117 do_test vacuum3-2.$I.3 {
118 execsql { SELECT * FROM t1 }
120 integrity_check vacuum3-1.$I.4
125 #-------------------------------------------------------------------
126 # Test cases vacuum3-3.* converts a database large enough to include
127 # the locking page (in a test environment) between few different
131 return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}]
133 do_test vacuum3-3.1 {
135 PRAGMA page_size = 1024;
137 CREATE TABLE abc(a PRIMARY KEY, b, c);
138 INSERT INTO abc VALUES(randomblob(100), randomblob(200), randomblob(1000));
140 SELECT randomblob(1000), randomblob(200), randomblob(100)
143 SELECT randomblob(100), randomblob(200), randomblob(1000)
146 SELECT randomblob(100), randomblob(200), randomblob(1000)
149 SELECT randomblob(100), randomblob(200), randomblob(1000)
152 SELECT randomblob(100), randomblob(200), randomblob(1000)
155 SELECT randomblob(25), randomblob(45), randomblob(9456)
158 SELECT randomblob(100), randomblob(200), randomblob(1000)
161 SELECT randomblob(25), randomblob(45), randomblob(9456)
166 do_test vacuum3-3.2 {
167 execsql { PRAGMA page_size }
170 set ::sig [signature]
173 foreach {request actual} [list \
182 do_test vacuum3-3.$I.1 {
184 PRAGMA page_size = $request;
187 execsql { PRAGMA page_size }
189 do_test vacuum3-3.$I.2 {
192 integrity_check vacuum3-3.$I.3
197 do_test vacuum3-4.1 {
202 PRAGMA page_size=1024;
203 CREATE TABLE abc(a, b, c);
204 INSERT INTO abc VALUES(1, 2, 3);
205 INSERT INTO abc VALUES(4, 5, 6);
207 execsql { SELECT * FROM abc }
209 do_test vacuum3-4.2 {
211 execsql { SELECT * FROM abc } db2
213 do_test vacuum3-4.3 {
215 PRAGMA page_size = 2048;
218 execsql { SELECT * FROM abc }
220 do_test vacuum3-4.4 {
221 execsql { SELECT * FROM abc } db2
223 do_test vacuum3-4.5 {
225 PRAGMA page_size=16384;
228 execsql { SELECT * FROM abc } db2
230 do_test vacuum3-4.6 {
232 PRAGMA page_size=1024;
235 execsql { SELECT * FROM abc } db2
238 # Unable to change the page-size of an in-memory using vacuum.
241 do_test vacuum3-5.1 {
244 INSERT INTO t1 VALUES(1234);
245 PRAGMA page_size=4096;
250 do_test vacuum3-5.2 {
256 set create_database_sql {
258 CREATE TABLE t1(a, b, c);
259 INSERT INTO t1 VALUES(1, randstr(50,50), randstr(50,50));
260 INSERT INTO t1 SELECT a+2, b||'-'||rowid, c||'-'||rowid FROM t1;
261 INSERT INTO t1 SELECT a+4, b||'-'||rowid, c||'-'||rowid FROM t1;
262 INSERT INTO t1 SELECT a+8, b||'-'||rowid, c||'-'||rowid FROM t1;
263 INSERT INTO t1 SELECT a+16, b||'-'||rowid, c||'-'||rowid FROM t1;
264 INSERT INTO t1 SELECT a+32, b||'-'||rowid, c||'-'||rowid FROM t1;
265 INSERT INTO t1 SELECT a+64, b||'-'||rowid, c||'-'||rowid FROM t1;
266 INSERT INTO t1 SELECT a+128, b||'-'||rowid, c||'-'||rowid FROM t1;
267 INSERT INTO t1 VALUES(1, randstr(600,600), randstr(600,600));
268 CREATE TABLE t2 AS SELECT * FROM t1;
269 CREATE TABLE t3 AS SELECT * FROM t1;
274 do_ioerr_test vacuum3-ioerr-1 -cksum true -sqlprep "
275 PRAGMA page_size = 1024;
278 PRAGMA page_size = 4096;
281 do_ioerr_test vacuum3-ioerr-2 -cksum true -sqlprep "
282 PRAGMA page_size = 2048;
285 PRAGMA page_size = 512;
289 ifcapable autovacuum {
290 do_ioerr_test vacuum3-ioerr-3 -cksum true -sqlprep "
291 PRAGMA auto_vacuum = 0;
294 PRAGMA auto_vacuum = 1;
297 do_ioerr_test vacuum3-ioerr-4 -cksum true -sqlprep "
298 PRAGMA auto_vacuum = 1;
301 PRAGMA auto_vacuum = 0;
306 source $testdir/malloc_common.tcl
308 do_malloc_test vacuum3-malloc-1 -sqlprep {
309 PRAGMA page_size = 2048;
311 CREATE TABLE t1(a, b, c);
312 INSERT INTO t1 VALUES(1, randstr(50,50), randstr(50,50));
313 INSERT INTO t1 SELECT a+2, b||'-'||rowid, c||'-'||rowid FROM t1;
314 INSERT INTO t1 SELECT a+4, b||'-'||rowid, c||'-'||rowid FROM t1;
315 INSERT INTO t1 SELECT a+8, b||'-'||rowid, c||'-'||rowid FROM t1;
316 INSERT INTO t1 SELECT a+16, b||'-'||rowid, c||'-'||rowid FROM t1;
317 INSERT INTO t1 SELECT a+32, b||'-'||rowid, c||'-'||rowid FROM t1;
318 INSERT INTO t1 SELECT a+64, b||'-'||rowid, c||'-'||rowid FROM t1;
319 INSERT INTO t1 SELECT a+128, b||'-'||rowid, c||'-'||rowid FROM t1;
320 INSERT INTO t1 VALUES(1, randstr(600,600), randstr(600,600));
321 CREATE TABLE t2 AS SELECT * FROM t1;
322 CREATE TABLE t3 AS SELECT * FROM t1;
326 PRAGMA page_size = 512;
329 do_malloc_test vacuum3-malloc-2 -sqlprep {
330 PRAGMA encoding=UTF16;
331 CREATE TABLE t1(a, b, c);
332 INSERT INTO t1 VALUES(1, 2, 3);
333 CREATE TABLE t2(x,y,z);
334 INSERT INTO t2 SELECT * FROM t1;