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