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