blob: 25f2c6897b95dae1052095eb00409ad62babcc18 [file] [log] [blame]
drh5ab63772014-11-27 03:46:04 +00001# 2014-11-27
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
6# May you do good and not evil.
7# May you find forgiveness for yourself and forgive others.
8# May you share freely, never taking more than you give.
9#
10#***********************************************************************
11#
12# This file contains test cases for b-tree logic.
13#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17set testprefix btree01
18
19# The refactoring on the b-tree balance() routine in check-in
20# http://www.sqlite.org/src/info/face33bea1ba3a (2014-10-27)
21# caused the integrity_check on the following SQL to fail.
22#
23do_execsql_test btree01-1.1 {
24 PRAGMA page_size=65536;
25 CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB);
26 WITH RECURSIVE
27 c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30)
28 INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c;
29 UPDATE t1 SET b=zeroblob(3000);
30 UPDATE t1 SET b=zeroblob(64000) WHERE a=2;
31 PRAGMA integrity_check;
32} {ok}
33
drh3f2d22e2014-11-27 04:23:19 +000034# The previous test is sufficient to prevent a regression. But we
35# add a number of additional tests to stress the balancer in similar
36# ways, looking for related problems.
37#
38for {set i 1} {$i<=30} {incr i} {
39 do_test btree01-1.2.$i {
40 db eval {
41 DELETE FROM t1;
42 WITH RECURSIVE
43 c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30)
44 INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c;
45 UPDATE t1 SET b=zeroblob(3000);
46 UPDATE t1 SET b=zeroblob(64000) WHERE a=$::i;
47 PRAGMA integrity_check;
48 }
49 } {ok}
50}
51for {set i 1} {$i<=30} {incr i} {
52 do_test btree01-1.3.$i {
53 db eval {
54 DELETE FROM t1;
55 WITH RECURSIVE
56 c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30)
57 INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c;
58 UPDATE t1 SET b=zeroblob(2000);
59 UPDATE t1 SET b=zeroblob(64000) WHERE a=$::i;
60 PRAGMA integrity_check;
61 }
62 } {ok}
63}
64for {set i 1} {$i<=30} {incr i} {
65 do_test btree01-1.4.$i {
66 db eval {
67 DELETE FROM t1;
68 WITH RECURSIVE
69 c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30)
70 INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c;
71 UPDATE t1 SET b=zeroblob(6499) WHERE (a%3)==0;
72 UPDATE t1 SET b=zeroblob(6499) WHERE (a%3)==1;
73 UPDATE t1 SET b=zeroblob(6499) WHERE (a%3)==2;
74 UPDATE t1 SET b=zeroblob(64000) WHERE a=$::i;
75 PRAGMA integrity_check;
76 }
77 } {ok}
78}
79for {set i 1} {$i<=30} {incr i} {
80 do_test btree01-1.5.$i {
81 db eval {
82 DELETE FROM t1;
83 WITH RECURSIVE
84 c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30)
85 INSERT INTO t1(a,b) SELECT i, zeroblob(6542) FROM c;
86 UPDATE t1 SET b=zeroblob(2331);
87 UPDATE t1 SET b=zeroblob(65496) WHERE a=$::i;
88 PRAGMA integrity_check;
89 }
90 } {ok}
91}
92for {set i 1} {$i<=30} {incr i} {
93 do_test btree01-1.6.$i {
94 db eval {
95 DELETE FROM t1;
96 WITH RECURSIVE
97 c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30)
98 INSERT INTO t1(a,b) SELECT i, zeroblob(6542) FROM c;
99 UPDATE t1 SET b=zeroblob(2332);
100 UPDATE t1 SET b=zeroblob(65496) WHERE a=$::i;
101 PRAGMA integrity_check;
102 }
103 } {ok}
104}
105for {set i 1} {$i<=30} {incr i} {
106 do_test btree01-1.7.$i {
107 db eval {
108 DELETE FROM t1;
109 WITH RECURSIVE
110 c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30)
111 INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c;
112 UPDATE t1 SET b=zeroblob(1);
113 UPDATE t1 SET b=zeroblob(65000) WHERE a=$::i;
114 PRAGMA integrity_check;
115 }
116 } {ok}
117}
118for {set i 1} {$i<=31} {incr i} {
119 do_test btree01-1.8.$i {
120 db eval {
121 DELETE FROM t1;
122 WITH RECURSIVE
123 c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<31)
124 INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c;
125 UPDATE t1 SET b=zeroblob(4000);
126 UPDATE t1 SET b=zeroblob(65000) WHERE a=$::i;
127 PRAGMA integrity_check;
128 }
129 } {ok}
130}
131
drh5ab63772014-11-27 03:46:04 +0000132finish_test