3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # This file contains test cases for b-tree logic.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 set testprefix btree01
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.
23 do_execsql_test btree01-1.1 {
24 PRAGMA page_size=65536;
25 CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB);
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;
34 # 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.
38 for {set i 1} {$i<=30} {incr i} {
39 do_test btree01-1.2.$i {
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;
51 for {set i 1} {$i<=30} {incr i} {
52 do_test btree01-1.3.$i {
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;
64 for {set i 1} {$i<=30} {incr i} {
65 do_test btree01-1.4.$i {
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;
79 for {set i 1} {$i<=30} {incr i} {
80 do_test btree01-1.5.$i {
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;
92 for {set i 1} {$i<=30} {incr i} {
93 do_test btree01-1.6.$i {
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;
105 for {set i 1} {$i<=30} {incr i} {
106 do_test btree01-1.7.$i {
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;
118 for {set i 1} {$i<=31} {incr i} {
119 do_test btree01-1.8.$i {
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;