sl@0
|
1 |
# 2001 September 23
|
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 stressing the library by putting large amounts
|
sl@0
|
13 |
# of data in a single row of a table.
|
sl@0
|
14 |
#
|
sl@0
|
15 |
# $Id: bigrow.test,v 1.5 2004/08/07 23:54:48 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 |
# Make a big string that we can use for test data
|
sl@0
|
21 |
#
|
sl@0
|
22 |
do_test bigrow-1.0 {
|
sl@0
|
23 |
set ::bigstr {}
|
sl@0
|
24 |
for {set i 1} {$i<=9999} {incr i} {
|
sl@0
|
25 |
set sep [string index "abcdefghijklmnopqrstuvwxyz" [expr {$i%26}]]
|
sl@0
|
26 |
append ::bigstr "$sep [format %04d $i] "
|
sl@0
|
27 |
}
|
sl@0
|
28 |
string length $::bigstr
|
sl@0
|
29 |
} {69993}
|
sl@0
|
30 |
|
sl@0
|
31 |
# Make a table into which we can insert some but records.
|
sl@0
|
32 |
#
|
sl@0
|
33 |
do_test bigrow-1.1 {
|
sl@0
|
34 |
execsql {
|
sl@0
|
35 |
CREATE TABLE t1(a text, b text, c text);
|
sl@0
|
36 |
SELECT name FROM sqlite_master
|
sl@0
|
37 |
WHERE type='table' OR type='index'
|
sl@0
|
38 |
ORDER BY name
|
sl@0
|
39 |
}
|
sl@0
|
40 |
} {t1}
|
sl@0
|
41 |
|
sl@0
|
42 |
do_test bigrow-1.2 {
|
sl@0
|
43 |
set ::big1 [string range $::bigstr 0 65519]
|
sl@0
|
44 |
set sql "INSERT INTO t1 VALUES('abc',"
|
sl@0
|
45 |
append sql "'$::big1', 'xyz');"
|
sl@0
|
46 |
execsql $sql
|
sl@0
|
47 |
execsql {SELECT a, c FROM t1}
|
sl@0
|
48 |
} {abc xyz}
|
sl@0
|
49 |
do_test bigrow-1.3 {
|
sl@0
|
50 |
execsql {SELECT b FROM t1}
|
sl@0
|
51 |
} [list $::big1]
|
sl@0
|
52 |
do_test bigrow-1.4 {
|
sl@0
|
53 |
set ::big2 [string range $::bigstr 0 65520]
|
sl@0
|
54 |
set sql "INSERT INTO t1 VALUES('abc2',"
|
sl@0
|
55 |
append sql "'$::big2', 'xyz2');"
|
sl@0
|
56 |
set r [catch {execsql $sql} msg]
|
sl@0
|
57 |
lappend r $msg
|
sl@0
|
58 |
} {0 {}}
|
sl@0
|
59 |
do_test bigrow-1.4.1 {
|
sl@0
|
60 |
execsql {SELECT b FROM t1 ORDER BY c}
|
sl@0
|
61 |
} [list $::big1 $::big2]
|
sl@0
|
62 |
do_test bigrow-1.4.2 {
|
sl@0
|
63 |
execsql {SELECT c FROM t1 ORDER BY c}
|
sl@0
|
64 |
} {xyz xyz2}
|
sl@0
|
65 |
do_test bigrow-1.4.3 {
|
sl@0
|
66 |
execsql {DELETE FROM t1 WHERE a='abc2'}
|
sl@0
|
67 |
execsql {SELECT c FROM t1}
|
sl@0
|
68 |
} {xyz}
|
sl@0
|
69 |
|
sl@0
|
70 |
do_test bigrow-1.5 {
|
sl@0
|
71 |
execsql {
|
sl@0
|
72 |
UPDATE t1 SET a=b, b=a;
|
sl@0
|
73 |
SELECT b,c FROM t1
|
sl@0
|
74 |
}
|
sl@0
|
75 |
} {abc xyz}
|
sl@0
|
76 |
do_test bigrow-1.6 {
|
sl@0
|
77 |
execsql {
|
sl@0
|
78 |
SELECT * FROM t1
|
sl@0
|
79 |
}
|
sl@0
|
80 |
} [list $::big1 abc xyz]
|
sl@0
|
81 |
do_test bigrow-1.7 {
|
sl@0
|
82 |
execsql {
|
sl@0
|
83 |
INSERT INTO t1 VALUES('1','2','3');
|
sl@0
|
84 |
INSERT INTO t1 VALUES('A','B','C');
|
sl@0
|
85 |
SELECT b FROM t1 WHERE a=='1';
|
sl@0
|
86 |
}
|
sl@0
|
87 |
} {2}
|
sl@0
|
88 |
do_test bigrow-1.8 {
|
sl@0
|
89 |
execsql "SELECT b FROM t1 WHERE a=='$::big1'"
|
sl@0
|
90 |
} {abc}
|
sl@0
|
91 |
do_test bigrow-1.9 {
|
sl@0
|
92 |
execsql "SELECT b FROM t1 WHERE a!='$::big1' ORDER BY a"
|
sl@0
|
93 |
} {2 B}
|
sl@0
|
94 |
|
sl@0
|
95 |
# Try doing some indexing on big columns
|
sl@0
|
96 |
#
|
sl@0
|
97 |
do_test bigrow-2.1 {
|
sl@0
|
98 |
execsql {
|
sl@0
|
99 |
CREATE INDEX i1 ON t1(a)
|
sl@0
|
100 |
}
|
sl@0
|
101 |
execsql "SELECT b FROM t1 WHERE a=='$::big1'"
|
sl@0
|
102 |
} {abc}
|
sl@0
|
103 |
do_test bigrow-2.2 {
|
sl@0
|
104 |
execsql {
|
sl@0
|
105 |
UPDATE t1 SET a=b, b=a
|
sl@0
|
106 |
}
|
sl@0
|
107 |
execsql "SELECT b FROM t1 WHERE a=='abc'"
|
sl@0
|
108 |
} [list $::big1]
|
sl@0
|
109 |
do_test bigrow-2.3 {
|
sl@0
|
110 |
execsql {
|
sl@0
|
111 |
UPDATE t1 SET a=b, b=a
|
sl@0
|
112 |
}
|
sl@0
|
113 |
execsql "SELECT b FROM t1 WHERE a=='$::big1'"
|
sl@0
|
114 |
} {abc}
|
sl@0
|
115 |
catch {unset ::bigstr}
|
sl@0
|
116 |
catch {unset ::big1}
|
sl@0
|
117 |
catch {unset ::big2}
|
sl@0
|
118 |
|
sl@0
|
119 |
# Mosts of the tests above were created back when rows were limited in
|
sl@0
|
120 |
# size to 64K. Now rows can be much bigger. Test that logic. Also
|
sl@0
|
121 |
# make sure things work correctly at the transition boundries between
|
sl@0
|
122 |
# row sizes of 256 to 257 bytes and from 65536 to 65537 bytes.
|
sl@0
|
123 |
#
|
sl@0
|
124 |
# We begin by testing the 256..257 transition.
|
sl@0
|
125 |
#
|
sl@0
|
126 |
do_test bigrow-3.1 {
|
sl@0
|
127 |
execsql {
|
sl@0
|
128 |
DELETE FROM t1;
|
sl@0
|
129 |
INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
|
sl@0
|
130 |
}
|
sl@0
|
131 |
execsql {SELECT a,length(b),c FROM t1}
|
sl@0
|
132 |
} {one 30 hi}
|
sl@0
|
133 |
do_test bigrow-3.2 {
|
sl@0
|
134 |
execsql {
|
sl@0
|
135 |
UPDATE t1 SET b=b||b;
|
sl@0
|
136 |
UPDATE t1 SET b=b||b;
|
sl@0
|
137 |
UPDATE t1 SET b=b||b;
|
sl@0
|
138 |
}
|
sl@0
|
139 |
execsql {SELECT a,length(b),c FROM t1}
|
sl@0
|
140 |
} {one 240 hi}
|
sl@0
|
141 |
for {set i 1} {$i<10} {incr i} {
|
sl@0
|
142 |
do_test bigrow-3.3.$i {
|
sl@0
|
143 |
execsql "UPDATE t1 SET b=b||'$i'"
|
sl@0
|
144 |
execsql {SELECT a,length(b),c FROM t1}
|
sl@0
|
145 |
} "one [expr {240+$i}] hi"
|
sl@0
|
146 |
}
|
sl@0
|
147 |
|
sl@0
|
148 |
# Now test the 65536..65537 row-size transition.
|
sl@0
|
149 |
#
|
sl@0
|
150 |
do_test bigrow-4.1 {
|
sl@0
|
151 |
execsql {
|
sl@0
|
152 |
DELETE FROM t1;
|
sl@0
|
153 |
INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
|
sl@0
|
154 |
}
|
sl@0
|
155 |
execsql {SELECT a,length(b),c FROM t1}
|
sl@0
|
156 |
} {one 30 hi}
|
sl@0
|
157 |
do_test bigrow-4.2 {
|
sl@0
|
158 |
execsql {
|
sl@0
|
159 |
UPDATE t1 SET b=b||b;
|
sl@0
|
160 |
UPDATE t1 SET b=b||b;
|
sl@0
|
161 |
UPDATE t1 SET b=b||b;
|
sl@0
|
162 |
UPDATE t1 SET b=b||b;
|
sl@0
|
163 |
UPDATE t1 SET b=b||b;
|
sl@0
|
164 |
UPDATE t1 SET b=b||b;
|
sl@0
|
165 |
UPDATE t1 SET b=b||b;
|
sl@0
|
166 |
UPDATE t1 SET b=b||b;
|
sl@0
|
167 |
UPDATE t1 SET b=b||b;
|
sl@0
|
168 |
UPDATE t1 SET b=b||b;
|
sl@0
|
169 |
UPDATE t1 SET b=b||b;
|
sl@0
|
170 |
UPDATE t1 SET b=b||b;
|
sl@0
|
171 |
}
|
sl@0
|
172 |
execsql {SELECT a,length(b),c FROM t1}
|
sl@0
|
173 |
} {one 122880 hi}
|
sl@0
|
174 |
do_test bigrow-4.3 {
|
sl@0
|
175 |
execsql {
|
sl@0
|
176 |
UPDATE t1 SET b=substr(b,1,65515)
|
sl@0
|
177 |
}
|
sl@0
|
178 |
execsql {SELECT a,length(b),c FROM t1}
|
sl@0
|
179 |
} {one 65515 hi}
|
sl@0
|
180 |
for {set i 1} {$i<10} {incr i} {
|
sl@0
|
181 |
do_test bigrow-4.4.$i {
|
sl@0
|
182 |
execsql "UPDATE t1 SET b=b||'$i'"
|
sl@0
|
183 |
execsql {SELECT a,length(b),c FROM t1}
|
sl@0
|
184 |
} "one [expr {65515+$i}] hi"
|
sl@0
|
185 |
}
|
sl@0
|
186 |
|
sl@0
|
187 |
# Check to make sure the library recovers safely if a row contains
|
sl@0
|
188 |
# too much data.
|
sl@0
|
189 |
#
|
sl@0
|
190 |
do_test bigrow-5.1 {
|
sl@0
|
191 |
execsql {
|
sl@0
|
192 |
DELETE FROM t1;
|
sl@0
|
193 |
INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
|
sl@0
|
194 |
}
|
sl@0
|
195 |
execsql {SELECT a,length(b),c FROM t1}
|
sl@0
|
196 |
} {one 30 hi}
|
sl@0
|
197 |
set i 1
|
sl@0
|
198 |
for {set sz 60} {$sz<1048560} {incr sz $sz} {
|
sl@0
|
199 |
do_test bigrow-5.2.$i {
|
sl@0
|
200 |
execsql {
|
sl@0
|
201 |
UPDATE t1 SET b=b||b;
|
sl@0
|
202 |
SELECT a,length(b),c FROM t1;
|
sl@0
|
203 |
}
|
sl@0
|
204 |
} "one $sz hi"
|
sl@0
|
205 |
incr i
|
sl@0
|
206 |
}
|
sl@0
|
207 |
do_test bigrow-5.3 {
|
sl@0
|
208 |
catchsql {UPDATE t1 SET b=b||b}
|
sl@0
|
209 |
} {0 {}}
|
sl@0
|
210 |
do_test bigrow-5.4 {
|
sl@0
|
211 |
execsql {SELECT length(b) FROM t1}
|
sl@0
|
212 |
} 1966080
|
sl@0
|
213 |
do_test bigrow-5.5 {
|
sl@0
|
214 |
catchsql {UPDATE t1 SET b=b||b}
|
sl@0
|
215 |
} {0 {}}
|
sl@0
|
216 |
do_test bigrow-5.6 {
|
sl@0
|
217 |
execsql {SELECT length(b) FROM t1}
|
sl@0
|
218 |
} 3932160
|
sl@0
|
219 |
do_test bigrow-5.99 {
|
sl@0
|
220 |
execsql {DROP TABLE t1}
|
sl@0
|
221 |
} {}
|
sl@0
|
222 |
|
sl@0
|
223 |
finish_test
|