sl@0
|
1 |
# 2007 March 19
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
# This file implements regression tests for SQLite library. The
|
sl@0
|
12 |
# focus of this file is changing the database page size using a
|
sl@0
|
13 |
# VACUUM statement.
|
sl@0
|
14 |
#
|
sl@0
|
15 |
# $Id: vacuum3.test,v 1.9 2008/08/26 21:07:27 drh Exp $
|
sl@0
|
16 |
|
sl@0
|
17 |
set testdir [file dirname $argv0]
|
sl@0
|
18 |
source $testdir/tester.tcl
|
sl@0
|
19 |
|
sl@0
|
20 |
# If the VACUUM statement is disabled in the current build, skip all
|
sl@0
|
21 |
# the tests in this file.
|
sl@0
|
22 |
#
|
sl@0
|
23 |
ifcapable !vacuum {
|
sl@0
|
24 |
finish_test
|
sl@0
|
25 |
return
|
sl@0
|
26 |
}
|
sl@0
|
27 |
|
sl@0
|
28 |
|
sl@0
|
29 |
#-------------------------------------------------------------------
|
sl@0
|
30 |
# Test cases vacuum3-1.* convert a simple 2-page database between a
|
sl@0
|
31 |
# few different page sizes.
|
sl@0
|
32 |
#
|
sl@0
|
33 |
do_test vacuum3-1.1 {
|
sl@0
|
34 |
execsql {
|
sl@0
|
35 |
PRAGMA auto_vacuum=OFF;
|
sl@0
|
36 |
PRAGMA page_size = 1024;
|
sl@0
|
37 |
CREATE TABLE t1(a, b, c);
|
sl@0
|
38 |
INSERT INTO t1 VALUES(1, 2, 3);
|
sl@0
|
39 |
}
|
sl@0
|
40 |
} {}
|
sl@0
|
41 |
do_test vacuum3-1.2 {
|
sl@0
|
42 |
execsql { PRAGMA page_size }
|
sl@0
|
43 |
} {1024}
|
sl@0
|
44 |
do_test vacuum3-1.3 {
|
sl@0
|
45 |
file size test.db
|
sl@0
|
46 |
} {2048}
|
sl@0
|
47 |
|
sl@0
|
48 |
set I 4
|
sl@0
|
49 |
foreach {request actual database} [list \
|
sl@0
|
50 |
2048 2048 4096 \
|
sl@0
|
51 |
1024 1024 2048 \
|
sl@0
|
52 |
1170 1024 2048 \
|
sl@0
|
53 |
256 1024 2048 \
|
sl@0
|
54 |
512 512 1024 \
|
sl@0
|
55 |
4096 4096 8192 \
|
sl@0
|
56 |
1024 1024 2048 \
|
sl@0
|
57 |
] {
|
sl@0
|
58 |
do_test vacuum3-1.$I.1 {
|
sl@0
|
59 |
execsql "
|
sl@0
|
60 |
PRAGMA page_size = $request;
|
sl@0
|
61 |
VACUUM;
|
sl@0
|
62 |
"
|
sl@0
|
63 |
execsql { PRAGMA page_size }
|
sl@0
|
64 |
} $actual
|
sl@0
|
65 |
do_test vacuum3-1.$I.2 {
|
sl@0
|
66 |
file size test.db
|
sl@0
|
67 |
} $database
|
sl@0
|
68 |
do_test vacuum3-1.$I.3 {
|
sl@0
|
69 |
execsql { SELECT * FROM t1 }
|
sl@0
|
70 |
} {1 2 3}
|
sl@0
|
71 |
integrity_check vacuum3-1.$I.4
|
sl@0
|
72 |
|
sl@0
|
73 |
incr I
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
#-------------------------------------------------------------------
|
sl@0
|
77 |
# Test cases vacuum3-2.* convert a simple 3-page database between a
|
sl@0
|
78 |
# few different page sizes.
|
sl@0
|
79 |
#
|
sl@0
|
80 |
do_test vacuum3-2.1 {
|
sl@0
|
81 |
execsql {
|
sl@0
|
82 |
PRAGMA page_size = 1024;
|
sl@0
|
83 |
VACUUM;
|
sl@0
|
84 |
ALTER TABLE t1 ADD COLUMN d;
|
sl@0
|
85 |
UPDATE t1 SET d = randomblob(1000);
|
sl@0
|
86 |
}
|
sl@0
|
87 |
file size test.db
|
sl@0
|
88 |
} {3072}
|
sl@0
|
89 |
do_test vacuum3-2.2 {
|
sl@0
|
90 |
execsql { PRAGMA page_size }
|
sl@0
|
91 |
} {1024}
|
sl@0
|
92 |
do_test vacuum3-2.3 {
|
sl@0
|
93 |
set blob [db one {select d from t1}]
|
sl@0
|
94 |
string length $blob
|
sl@0
|
95 |
} {1000}
|
sl@0
|
96 |
|
sl@0
|
97 |
set I 4
|
sl@0
|
98 |
foreach {request actual database} [list \
|
sl@0
|
99 |
2048 2048 4096 \
|
sl@0
|
100 |
1024 1024 3072 \
|
sl@0
|
101 |
1170 1024 3072 \
|
sl@0
|
102 |
256 1024 3072 \
|
sl@0
|
103 |
512 512 2048 \
|
sl@0
|
104 |
4096 4096 8192 \
|
sl@0
|
105 |
1024 1024 3072 \
|
sl@0
|
106 |
] {
|
sl@0
|
107 |
do_test vacuum3-2.$I.1 {
|
sl@0
|
108 |
execsql "
|
sl@0
|
109 |
PRAGMA page_size = $request;
|
sl@0
|
110 |
VACUUM;
|
sl@0
|
111 |
"
|
sl@0
|
112 |
execsql { PRAGMA page_size }
|
sl@0
|
113 |
} $actual
|
sl@0
|
114 |
do_test vacuum3-2.$I.2 {
|
sl@0
|
115 |
file size test.db
|
sl@0
|
116 |
} $database
|
sl@0
|
117 |
do_test vacuum3-2.$I.3 {
|
sl@0
|
118 |
execsql { SELECT * FROM t1 }
|
sl@0
|
119 |
} [list 1 2 3 $blob]
|
sl@0
|
120 |
integrity_check vacuum3-1.$I.4
|
sl@0
|
121 |
|
sl@0
|
122 |
incr I
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@0
|
125 |
#-------------------------------------------------------------------
|
sl@0
|
126 |
# Test cases vacuum3-3.* converts a database large enough to include
|
sl@0
|
127 |
# the locking page (in a test environment) between few different
|
sl@0
|
128 |
# page sizes.
|
sl@0
|
129 |
#
|
sl@0
|
130 |
proc signature {} {
|
sl@0
|
131 |
return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}]
|
sl@0
|
132 |
}
|
sl@0
|
133 |
do_test vacuum3-3.1 {
|
sl@0
|
134 |
execsql "
|
sl@0
|
135 |
PRAGMA page_size = 1024;
|
sl@0
|
136 |
BEGIN;
|
sl@0
|
137 |
CREATE TABLE abc(a PRIMARY KEY, b, c);
|
sl@0
|
138 |
INSERT INTO abc VALUES(randomblob(100), randomblob(200), randomblob(1000));
|
sl@0
|
139 |
INSERT INTO abc
|
sl@0
|
140 |
SELECT randomblob(1000), randomblob(200), randomblob(100)
|
sl@0
|
141 |
FROM abc;
|
sl@0
|
142 |
INSERT INTO abc
|
sl@0
|
143 |
SELECT randomblob(100), randomblob(200), randomblob(1000)
|
sl@0
|
144 |
FROM abc;
|
sl@0
|
145 |
INSERT INTO abc
|
sl@0
|
146 |
SELECT randomblob(100), randomblob(200), randomblob(1000)
|
sl@0
|
147 |
FROM abc;
|
sl@0
|
148 |
INSERT INTO abc
|
sl@0
|
149 |
SELECT randomblob(100), randomblob(200), randomblob(1000)
|
sl@0
|
150 |
FROM abc;
|
sl@0
|
151 |
INSERT INTO abc
|
sl@0
|
152 |
SELECT randomblob(100), randomblob(200), randomblob(1000)
|
sl@0
|
153 |
FROM abc;
|
sl@0
|
154 |
INSERT INTO abc
|
sl@0
|
155 |
SELECT randomblob(25), randomblob(45), randomblob(9456)
|
sl@0
|
156 |
FROM abc;
|
sl@0
|
157 |
INSERT INTO abc
|
sl@0
|
158 |
SELECT randomblob(100), randomblob(200), randomblob(1000)
|
sl@0
|
159 |
FROM abc;
|
sl@0
|
160 |
INSERT INTO abc
|
sl@0
|
161 |
SELECT randomblob(25), randomblob(45), randomblob(9456)
|
sl@0
|
162 |
FROM abc;
|
sl@0
|
163 |
COMMIT;
|
sl@0
|
164 |
"
|
sl@0
|
165 |
} {}
|
sl@0
|
166 |
do_test vacuum3-3.2 {
|
sl@0
|
167 |
execsql { PRAGMA page_size }
|
sl@0
|
168 |
} {1024}
|
sl@0
|
169 |
|
sl@0
|
170 |
set ::sig [signature]
|
sl@0
|
171 |
|
sl@0
|
172 |
set I 3
|
sl@0
|
173 |
foreach {request actual} [list \
|
sl@0
|
174 |
2048 2048 \
|
sl@0
|
175 |
1024 1024 \
|
sl@0
|
176 |
1170 1024 \
|
sl@0
|
177 |
256 1024 \
|
sl@0
|
178 |
512 512 \
|
sl@0
|
179 |
4096 4096 \
|
sl@0
|
180 |
1024 1024 \
|
sl@0
|
181 |
] {
|
sl@0
|
182 |
do_test vacuum3-3.$I.1 {
|
sl@0
|
183 |
execsql "
|
sl@0
|
184 |
PRAGMA page_size = $request;
|
sl@0
|
185 |
VACUUM;
|
sl@0
|
186 |
"
|
sl@0
|
187 |
execsql { PRAGMA page_size }
|
sl@0
|
188 |
} $actual
|
sl@0
|
189 |
do_test vacuum3-3.$I.2 {
|
sl@0
|
190 |
signature
|
sl@0
|
191 |
} $::sig
|
sl@0
|
192 |
integrity_check vacuum3-3.$I.3
|
sl@0
|
193 |
|
sl@0
|
194 |
incr I
|
sl@0
|
195 |
}
|
sl@0
|
196 |
|
sl@0
|
197 |
do_test vacuum3-4.1 {
|
sl@0
|
198 |
db close
|
sl@0
|
199 |
file delete test.db
|
sl@0
|
200 |
sqlite3 db test.db
|
sl@0
|
201 |
execsql {
|
sl@0
|
202 |
PRAGMA page_size=1024;
|
sl@0
|
203 |
CREATE TABLE abc(a, b, c);
|
sl@0
|
204 |
INSERT INTO abc VALUES(1, 2, 3);
|
sl@0
|
205 |
INSERT INTO abc VALUES(4, 5, 6);
|
sl@0
|
206 |
}
|
sl@0
|
207 |
execsql { SELECT * FROM abc }
|
sl@0
|
208 |
} {1 2 3 4 5 6}
|
sl@0
|
209 |
do_test vacuum3-4.2 {
|
sl@0
|
210 |
sqlite3 db2 test.db
|
sl@0
|
211 |
execsql { SELECT * FROM abc } db2
|
sl@0
|
212 |
} {1 2 3 4 5 6}
|
sl@0
|
213 |
do_test vacuum3-4.3 {
|
sl@0
|
214 |
execsql {
|
sl@0
|
215 |
PRAGMA page_size = 2048;
|
sl@0
|
216 |
VACUUM;
|
sl@0
|
217 |
}
|
sl@0
|
218 |
execsql { SELECT * FROM abc }
|
sl@0
|
219 |
} {1 2 3 4 5 6}
|
sl@0
|
220 |
do_test vacuum3-4.4 {
|
sl@0
|
221 |
execsql { SELECT * FROM abc } db2
|
sl@0
|
222 |
} {1 2 3 4 5 6}
|
sl@0
|
223 |
do_test vacuum3-4.5 {
|
sl@0
|
224 |
execsql {
|
sl@0
|
225 |
PRAGMA page_size=16384;
|
sl@0
|
226 |
VACUUM;
|
sl@0
|
227 |
} db2
|
sl@0
|
228 |
execsql { SELECT * FROM abc } db2
|
sl@0
|
229 |
} {1 2 3 4 5 6}
|
sl@0
|
230 |
do_test vacuum3-4.6 {
|
sl@0
|
231 |
execsql {
|
sl@0
|
232 |
PRAGMA page_size=1024;
|
sl@0
|
233 |
VACUUM;
|
sl@0
|
234 |
}
|
sl@0
|
235 |
execsql { SELECT * FROM abc } db2
|
sl@0
|
236 |
} {1 2 3 4 5 6}
|
sl@0
|
237 |
|
sl@0
|
238 |
# Unable to change the page-size of an in-memory using vacuum.
|
sl@0
|
239 |
db2 close
|
sl@0
|
240 |
sqlite3 db2 :memory:
|
sl@0
|
241 |
do_test vacuum3-5.1 {
|
sl@0
|
242 |
db2 eval {
|
sl@0
|
243 |
CREATE TABLE t1(x);
|
sl@0
|
244 |
INSERT INTO t1 VALUES(1234);
|
sl@0
|
245 |
PRAGMA page_size=4096;
|
sl@0
|
246 |
VACUUM;
|
sl@0
|
247 |
SELECT * FROM t1;
|
sl@0
|
248 |
}
|
sl@0
|
249 |
} {1234}
|
sl@0
|
250 |
do_test vacuum3-5.2 {
|
sl@0
|
251 |
db2 eval {
|
sl@0
|
252 |
PRAGMA page_size
|
sl@0
|
253 |
}
|
sl@0
|
254 |
} {1024}
|
sl@0
|
255 |
|
sl@0
|
256 |
set create_database_sql {
|
sl@0
|
257 |
BEGIN;
|
sl@0
|
258 |
CREATE TABLE t1(a, b, c);
|
sl@0
|
259 |
INSERT INTO t1 VALUES(1, randstr(50,50), randstr(50,50));
|
sl@0
|
260 |
INSERT INTO t1 SELECT a+2, b||'-'||rowid, c||'-'||rowid FROM t1;
|
sl@0
|
261 |
INSERT INTO t1 SELECT a+4, b||'-'||rowid, c||'-'||rowid FROM t1;
|
sl@0
|
262 |
INSERT INTO t1 SELECT a+8, b||'-'||rowid, c||'-'||rowid FROM t1;
|
sl@0
|
263 |
INSERT INTO t1 SELECT a+16, b||'-'||rowid, c||'-'||rowid FROM t1;
|
sl@0
|
264 |
INSERT INTO t1 SELECT a+32, b||'-'||rowid, c||'-'||rowid FROM t1;
|
sl@0
|
265 |
INSERT INTO t1 SELECT a+64, b||'-'||rowid, c||'-'||rowid FROM t1;
|
sl@0
|
266 |
INSERT INTO t1 SELECT a+128, b||'-'||rowid, c||'-'||rowid FROM t1;
|
sl@0
|
267 |
INSERT INTO t1 VALUES(1, randstr(600,600), randstr(600,600));
|
sl@0
|
268 |
CREATE TABLE t2 AS SELECT * FROM t1;
|
sl@0
|
269 |
CREATE TABLE t3 AS SELECT * FROM t1;
|
sl@0
|
270 |
COMMIT;
|
sl@0
|
271 |
DROP TABLE t2;
|
sl@0
|
272 |
}
|
sl@0
|
273 |
|
sl@0
|
274 |
do_ioerr_test vacuum3-ioerr-1 -cksum true -sqlprep "
|
sl@0
|
275 |
PRAGMA page_size = 1024;
|
sl@0
|
276 |
$create_database_sql
|
sl@0
|
277 |
" -sqlbody {
|
sl@0
|
278 |
PRAGMA page_size = 4096;
|
sl@0
|
279 |
VACUUM;
|
sl@0
|
280 |
}
|
sl@0
|
281 |
do_ioerr_test vacuum3-ioerr-2 -cksum true -sqlprep "
|
sl@0
|
282 |
PRAGMA page_size = 2048;
|
sl@0
|
283 |
$create_database_sql
|
sl@0
|
284 |
" -sqlbody {
|
sl@0
|
285 |
PRAGMA page_size = 512;
|
sl@0
|
286 |
VACUUM;
|
sl@0
|
287 |
}
|
sl@0
|
288 |
|
sl@0
|
289 |
ifcapable autovacuum {
|
sl@0
|
290 |
do_ioerr_test vacuum3-ioerr-3 -cksum true -sqlprep "
|
sl@0
|
291 |
PRAGMA auto_vacuum = 0;
|
sl@0
|
292 |
$create_database_sql
|
sl@0
|
293 |
" -sqlbody {
|
sl@0
|
294 |
PRAGMA auto_vacuum = 1;
|
sl@0
|
295 |
VACUUM;
|
sl@0
|
296 |
}
|
sl@0
|
297 |
do_ioerr_test vacuum3-ioerr-4 -cksum true -sqlprep "
|
sl@0
|
298 |
PRAGMA auto_vacuum = 1;
|
sl@0
|
299 |
$create_database_sql
|
sl@0
|
300 |
" -sqlbody {
|
sl@0
|
301 |
PRAGMA auto_vacuum = 0;
|
sl@0
|
302 |
VACUUM;
|
sl@0
|
303 |
}
|
sl@0
|
304 |
}
|
sl@0
|
305 |
|
sl@0
|
306 |
source $testdir/malloc_common.tcl
|
sl@0
|
307 |
if {$MEMDEBUG} {
|
sl@0
|
308 |
do_malloc_test vacuum3-malloc-1 -sqlprep {
|
sl@0
|
309 |
PRAGMA page_size = 2048;
|
sl@0
|
310 |
BEGIN;
|
sl@0
|
311 |
CREATE TABLE t1(a, b, c);
|
sl@0
|
312 |
INSERT INTO t1 VALUES(1, randstr(50,50), randstr(50,50));
|
sl@0
|
313 |
INSERT INTO t1 SELECT a+2, b||'-'||rowid, c||'-'||rowid FROM t1;
|
sl@0
|
314 |
INSERT INTO t1 SELECT a+4, b||'-'||rowid, c||'-'||rowid FROM t1;
|
sl@0
|
315 |
INSERT INTO t1 SELECT a+8, b||'-'||rowid, c||'-'||rowid FROM t1;
|
sl@0
|
316 |
INSERT INTO t1 SELECT a+16, b||'-'||rowid, c||'-'||rowid FROM t1;
|
sl@0
|
317 |
INSERT INTO t1 SELECT a+32, b||'-'||rowid, c||'-'||rowid FROM t1;
|
sl@0
|
318 |
INSERT INTO t1 SELECT a+64, b||'-'||rowid, c||'-'||rowid FROM t1;
|
sl@0
|
319 |
INSERT INTO t1 SELECT a+128, b||'-'||rowid, c||'-'||rowid FROM t1;
|
sl@0
|
320 |
INSERT INTO t1 VALUES(1, randstr(600,600), randstr(600,600));
|
sl@0
|
321 |
CREATE TABLE t2 AS SELECT * FROM t1;
|
sl@0
|
322 |
CREATE TABLE t3 AS SELECT * FROM t1;
|
sl@0
|
323 |
COMMIT;
|
sl@0
|
324 |
DROP TABLE t2;
|
sl@0
|
325 |
} -sqlbody {
|
sl@0
|
326 |
PRAGMA page_size = 512;
|
sl@0
|
327 |
VACUUM;
|
sl@0
|
328 |
}
|
sl@0
|
329 |
do_malloc_test vacuum3-malloc-2 -sqlprep {
|
sl@0
|
330 |
PRAGMA encoding=UTF16;
|
sl@0
|
331 |
CREATE TABLE t1(a, b, c);
|
sl@0
|
332 |
INSERT INTO t1 VALUES(1, 2, 3);
|
sl@0
|
333 |
CREATE TABLE t2(x,y,z);
|
sl@0
|
334 |
INSERT INTO t2 SELECT * FROM t1;
|
sl@0
|
335 |
} -sqlbody {
|
sl@0
|
336 |
VACUUM;
|
sl@0
|
337 |
}
|
sl@0
|
338 |
}
|
sl@0
|
339 |
|
sl@0
|
340 |
finish_test
|