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 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # The tests in this file verify that sorting works when the library is
14 # configured to use mmap(), but the temporary files generated by the
15 # sorter are too large to be completely mapped.
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
22 #-------------------------------------------------------------------------
23 # Sort some large ( > 4KiB) records.
30 set i1 [expr (($i2<<3) + $a) & 0x7FFFFFFF]
31 set i2 [expr (($i1<<3) + $b) & 0x7FFFFFFF]
38 PRAGMA cache_size = 5;
39 CREATE TABLE t11(a, b);
40 INSERT INTO t11 VALUES(randomblob(5000), NULL);
41 INSERT INTO t11 SELECT randomblob(5000), NULL FROM t11; --2
42 INSERT INTO t11 SELECT randomblob(5000), NULL FROM t11; --3
43 INSERT INTO t11 SELECT randomblob(5000), NULL FROM t11; --4
44 INSERT INTO t11 SELECT randomblob(5000), NULL FROM t11; --5
45 INSERT INTO t11 SELECT randomblob(5000), NULL FROM t11; --6
46 INSERT INTO t11 SELECT randomblob(5000), NULL FROM t11; --7
47 INSERT INTO t11 SELECT randomblob(5000), NULL FROM t11; --8
48 INSERT INTO t11 SELECT randomblob(5000), NULL FROM t11; --9
49 UPDATE t11 SET b = cksum(a);
52 foreach {tn mmap_limit} {
57 sqlite3_test_control SQLITE_TESTCTRL_SORTER_MMAP db $mmap_limit
59 db eval { SELECT * FROM t11 ORDER BY b } {
60 if {$b != [cksum $a]} {error "checksum failed"}
61 if {[string compare $b $prev] < 0} {error "sort failed"}
69 # Sort roughly 20MB of data. Once with a mmap limit of 5MB and once without.
71 foreach {itest limit} {
75 sqlite3_test_control SQLITE_TESTCTRL_SORTER_MMAP db $limit
76 do_execsql_test 2.$itest {
78 SELECT 1, randomblob(1000)
80 SELECT x+1, randomblob(1000) FROM r
83 SELECT count(*), sum(length(y)) FROM r GROUP BY (x%5);
93 # Sort more than 2GB of data. At one point this was causing a problem.
94 # This test might take one minute or more to run.
97 PRAGMA cache_size = 20000;
99 SELECT 1, randomblob(1000)
101 SELECT x+1, randomblob(1000) FROM r
104 SELECT count(*), sum(length(y)) FROM r GROUP BY (x%5);