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