xref: /sqlite-3.40.0/test/bigrow.test (revision 1d64fc1a)
1afa4a020Sdrh# 2001 September 23
2afa4a020Sdrh#
3afa4a020Sdrh# The author disclaims copyright to this source code.  In place of
4afa4a020Sdrh# a legal notice, here is a blessing:
5afa4a020Sdrh#
6afa4a020Sdrh#    May you do good and not evil.
7afa4a020Sdrh#    May you find forgiveness for yourself and forgive others.
8afa4a020Sdrh#    May you share freely, never taking more than you give.
9afa4a020Sdrh#
10afa4a020Sdrh#***********************************************************************
11afa4a020Sdrh# This file implements regression tests for SQLite library.  The
12afa4a020Sdrh# focus of this file is stressing the library by putting large amounts
13afa4a020Sdrh# of data in a single row of a table.
14afa4a020Sdrh#
15*1d64fc1aSdrh# $Id: bigrow.test,v 1.5 2004/08/07 23:54:48 drh Exp $
16afa4a020Sdrh
17afa4a020Sdrhset testdir [file dirname $argv0]
18afa4a020Sdrhsource $testdir/tester.tcl
19afa4a020Sdrh
20afa4a020Sdrh# Make a big string that we can use for test data
21afa4a020Sdrh#
22afa4a020Sdrhdo_test bigrow-1.0 {
23afa4a020Sdrh  set ::bigstr {}
24afa4a020Sdrh  for {set i 1} {$i<=9999} {incr i} {
25afa4a020Sdrh    set sep [string index "abcdefghijklmnopqrstuvwxyz" [expr {$i%26}]]
26afa4a020Sdrh    append ::bigstr "$sep [format %04d $i] "
27afa4a020Sdrh  }
28afa4a020Sdrh  string length $::bigstr
29afa4a020Sdrh} {69993}
30afa4a020Sdrh
31afa4a020Sdrh# Make a table into which we can insert some but records.
32afa4a020Sdrh#
33afa4a020Sdrhdo_test bigrow-1.1 {
34afa4a020Sdrh  execsql {
35afa4a020Sdrh    CREATE TABLE t1(a text, b text, c text);
36afa4a020Sdrh    SELECT name FROM sqlite_master
37afa4a020Sdrh      WHERE type='table' OR type='index'
38afa4a020Sdrh      ORDER BY name
39afa4a020Sdrh  }
40afa4a020Sdrh} {t1}
41afa4a020Sdrh
42afa4a020Sdrhdo_test bigrow-1.2 {
43afa4a020Sdrh  set ::big1 [string range $::bigstr 0 65519]
44afa4a020Sdrh  set sql "INSERT INTO t1 VALUES('abc',"
45afa4a020Sdrh  append sql "'$::big1', 'xyz');"
46afa4a020Sdrh  execsql $sql
47afa4a020Sdrh  execsql {SELECT a, c FROM t1}
48afa4a020Sdrh} {abc xyz}
49afa4a020Sdrhdo_test bigrow-1.3 {
50afa4a020Sdrh  execsql {SELECT b FROM t1}
51afa4a020Sdrh} [list $::big1]
52afa4a020Sdrhdo_test bigrow-1.4 {
5380ff32f5Sdrh  set ::big2 [string range $::bigstr 0 65520]
5480ff32f5Sdrh  set sql "INSERT INTO t1 VALUES('abc2',"
5580ff32f5Sdrh  append sql "'$::big2', 'xyz2');"
56afa4a020Sdrh  set r [catch {execsql $sql} msg]
57afa4a020Sdrh  lappend r $msg
5880ff32f5Sdrh} {0 {}}
5980ff32f5Sdrhdo_test bigrow-1.4.1 {
6080ff32f5Sdrh  execsql {SELECT b FROM t1 ORDER BY c}
6180ff32f5Sdrh} [list $::big1 $::big2]
6280ff32f5Sdrhdo_test bigrow-1.4.2 {
6380ff32f5Sdrh  execsql {SELECT c FROM t1 ORDER BY c}
6480ff32f5Sdrh} {xyz xyz2}
6580ff32f5Sdrhdo_test bigrow-1.4.3 {
6680ff32f5Sdrh  execsql {DELETE FROM t1 WHERE a='abc2'}
6780ff32f5Sdrh  execsql {SELECT c FROM t1}
6880ff32f5Sdrh} {xyz}
69afa4a020Sdrh
70afa4a020Sdrhdo_test bigrow-1.5 {
71afa4a020Sdrh  execsql {
72afa4a020Sdrh    UPDATE t1 SET a=b, b=a;
73afa4a020Sdrh    SELECT b,c FROM t1
74afa4a020Sdrh  }
75afa4a020Sdrh} {abc xyz}
76afa4a020Sdrhdo_test bigrow-1.6 {
77afa4a020Sdrh  execsql {
78afa4a020Sdrh    SELECT * FROM t1
79afa4a020Sdrh  }
80afa4a020Sdrh} [list $::big1 abc xyz]
81afa4a020Sdrhdo_test bigrow-1.7 {
82afa4a020Sdrh  execsql {
83afa4a020Sdrh    INSERT INTO t1 VALUES('1','2','3');
84afa4a020Sdrh    INSERT INTO t1 VALUES('A','B','C');
85afa4a020Sdrh    SELECT b FROM t1 WHERE a=='1';
86afa4a020Sdrh  }
87afa4a020Sdrh} {2}
88afa4a020Sdrhdo_test bigrow-1.8 {
89afa4a020Sdrh  execsql "SELECT b FROM t1 WHERE a=='$::big1'"
90afa4a020Sdrh} {abc}
91afa4a020Sdrhdo_test bigrow-1.9 {
92afa4a020Sdrh  execsql "SELECT b FROM t1 WHERE a!='$::big1' ORDER BY a"
937a7c7390Sdrh} {2 B}
94afa4a020Sdrh
95afa4a020Sdrh# Try doing some indexing on big columns
96afa4a020Sdrh#
97afa4a020Sdrhdo_test bigrow-2.1 {
98afa4a020Sdrh  execsql {
99afa4a020Sdrh    CREATE INDEX i1 ON t1(a)
100afa4a020Sdrh  }
101afa4a020Sdrh  execsql "SELECT b FROM t1 WHERE a=='$::big1'"
102afa4a020Sdrh} {abc}
103afa4a020Sdrhdo_test bigrow-2.2 {
104afa4a020Sdrh  execsql {
105afa4a020Sdrh    UPDATE t1 SET a=b, b=a
106afa4a020Sdrh  }
107afa4a020Sdrh  execsql "SELECT b FROM t1 WHERE a=='abc'"
108afa4a020Sdrh} [list $::big1]
109afa4a020Sdrhdo_test bigrow-2.3 {
110afa4a020Sdrh  execsql {
111afa4a020Sdrh    UPDATE t1 SET a=b, b=a
112afa4a020Sdrh  }
113afa4a020Sdrh  execsql "SELECT b FROM t1 WHERE a=='$::big1'"
114afa4a020Sdrh} {abc}
11580ff32f5Sdrhcatch {unset ::bigstr}
11680ff32f5Sdrhcatch {unset ::big1}
11780ff32f5Sdrhcatch {unset ::big2}
11880ff32f5Sdrh
11980ff32f5Sdrh# Mosts of the tests above were created back when rows were limited in
12080ff32f5Sdrh# size to 64K.  Now rows can be much bigger.  Test that logic.  Also
12180ff32f5Sdrh# make sure things work correctly at the transition boundries between
12280ff32f5Sdrh# row sizes of 256 to 257 bytes and from 65536 to 65537 bytes.
12380ff32f5Sdrh#
12480ff32f5Sdrh# We begin by testing the 256..257 transition.
12580ff32f5Sdrh#
12680ff32f5Sdrhdo_test bigrow-3.1 {
12780ff32f5Sdrh  execsql {
12880ff32f5Sdrh    DELETE FROM t1;
12980ff32f5Sdrh    INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
13080ff32f5Sdrh  }
13180ff32f5Sdrh  execsql {SELECT a,length(b),c FROM t1}
13280ff32f5Sdrh} {one 30 hi}
13380ff32f5Sdrhdo_test bigrow-3.2 {
13480ff32f5Sdrh  execsql {
13580ff32f5Sdrh    UPDATE t1 SET b=b||b;
13680ff32f5Sdrh    UPDATE t1 SET b=b||b;
13780ff32f5Sdrh    UPDATE t1 SET b=b||b;
13880ff32f5Sdrh  }
13980ff32f5Sdrh  execsql {SELECT a,length(b),c FROM t1}
14080ff32f5Sdrh} {one 240 hi}
14180ff32f5Sdrhfor {set i 1} {$i<10} {incr i} {
14280ff32f5Sdrh  do_test bigrow-3.3.$i {
14380ff32f5Sdrh    execsql "UPDATE t1 SET b=b||'$i'"
14480ff32f5Sdrh    execsql {SELECT a,length(b),c FROM t1}
14580ff32f5Sdrh  } "one [expr {240+$i}] hi"
14680ff32f5Sdrh}
14780ff32f5Sdrh
14880ff32f5Sdrh# Now test the 65536..65537 row-size transition.
14980ff32f5Sdrh#
15080ff32f5Sdrhdo_test bigrow-4.1 {
15180ff32f5Sdrh  execsql {
15280ff32f5Sdrh    DELETE FROM t1;
15380ff32f5Sdrh    INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
15480ff32f5Sdrh  }
15580ff32f5Sdrh  execsql {SELECT a,length(b),c FROM t1}
15680ff32f5Sdrh} {one 30 hi}
15780ff32f5Sdrhdo_test bigrow-4.2 {
15880ff32f5Sdrh  execsql {
15980ff32f5Sdrh    UPDATE t1 SET b=b||b;
16080ff32f5Sdrh    UPDATE t1 SET b=b||b;
16180ff32f5Sdrh    UPDATE t1 SET b=b||b;
16280ff32f5Sdrh    UPDATE t1 SET b=b||b;
16380ff32f5Sdrh    UPDATE t1 SET b=b||b;
16480ff32f5Sdrh    UPDATE t1 SET b=b||b;
16580ff32f5Sdrh    UPDATE t1 SET b=b||b;
16680ff32f5Sdrh    UPDATE t1 SET b=b||b;
16780ff32f5Sdrh    UPDATE t1 SET b=b||b;
16880ff32f5Sdrh    UPDATE t1 SET b=b||b;
16980ff32f5Sdrh    UPDATE t1 SET b=b||b;
17080ff32f5Sdrh    UPDATE t1 SET b=b||b;
17180ff32f5Sdrh  }
17280ff32f5Sdrh  execsql {SELECT a,length(b),c FROM t1}
17380ff32f5Sdrh} {one 122880 hi}
17480ff32f5Sdrhdo_test bigrow-4.3 {
17580ff32f5Sdrh  execsql {
17684e6b7b5Sdrh    UPDATE t1 SET b=substr(b,1,65515)
17780ff32f5Sdrh  }
17880ff32f5Sdrh  execsql {SELECT a,length(b),c FROM t1}
17980ff32f5Sdrh} {one 65515 hi}
18080ff32f5Sdrhfor {set i 1} {$i<10} {incr i} {
18180ff32f5Sdrh  do_test bigrow-4.4.$i {
18280ff32f5Sdrh    execsql "UPDATE t1 SET b=b||'$i'"
18380ff32f5Sdrh    execsql {SELECT a,length(b),c FROM t1}
18480ff32f5Sdrh  } "one [expr {65515+$i}] hi"
18580ff32f5Sdrh}
18680ff32f5Sdrh
18780ff32f5Sdrh# Check to make sure the library recovers safely if a row contains
18880ff32f5Sdrh# too much data.
18980ff32f5Sdrh#
19080ff32f5Sdrhdo_test bigrow-5.1 {
19180ff32f5Sdrh  execsql {
19280ff32f5Sdrh    DELETE FROM t1;
19380ff32f5Sdrh    INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
19480ff32f5Sdrh  }
19580ff32f5Sdrh  execsql {SELECT a,length(b),c FROM t1}
19680ff32f5Sdrh} {one 30 hi}
19780ff32f5Sdrhset i 1
19880ff32f5Sdrhfor {set sz 60} {$sz<1048560} {incr sz $sz} {
19980ff32f5Sdrh  do_test bigrow-5.2.$i {
20080ff32f5Sdrh    execsql {
20180ff32f5Sdrh      UPDATE t1 SET b=b||b;
20280ff32f5Sdrh      SELECT a,length(b),c FROM t1;
20380ff32f5Sdrh    }
20480ff32f5Sdrh  } "one $sz hi"
20580ff32f5Sdrh  incr i
20680ff32f5Sdrh}
20780ff32f5Sdrhdo_test bigrow-5.3 {
208*1d64fc1aSdrh  catchsql {UPDATE t1 SET b=b||b}
209*1d64fc1aSdrh} {0 {}}
21080ff32f5Sdrhdo_test bigrow-5.4 {
211*1d64fc1aSdrh  execsql {SELECT length(b) FROM t1}
212*1d64fc1aSdrh} 1966080
213*1d64fc1aSdrhdo_test bigrow-5.5 {
214*1d64fc1aSdrh  catchsql {UPDATE t1 SET b=b||b}
215*1d64fc1aSdrh} {0 {}}
216*1d64fc1aSdrhdo_test bigrow-5.6 {
217*1d64fc1aSdrh  execsql {SELECT length(b) FROM t1}
218*1d64fc1aSdrh} 3932160
219*1d64fc1aSdrhdo_test bigrow-5.99 {
22080ff32f5Sdrh  execsql {DROP TABLE t1}
22180ff32f5Sdrh} {}
222afa4a020Sdrh
223afa4a020Sdrhfinish_test
224