OLD | NEW |
1 # 2014 March 25. | 1 # 2014 March 25. |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
11 # This file implements regression tests for SQLite library. | 11 # This file implements regression tests for SQLite library. |
12 # | 12 # |
13 # The tests in this file verify that sorting works when the library is | 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 | 14 # configured to use mmap(), but the temporary files generated by the |
15 # sorter are too large to be completely mapped. | 15 # sorter are too large to be completely mapped. |
16 # | 16 # |
17 | 17 |
18 set testdir [file dirname $argv0] | 18 set testdir [file dirname $argv0] |
19 source $testdir/tester.tcl | 19 source $testdir/tester.tcl |
20 set testprefix sort3 | 20 set testprefix sort3 |
21 | 21 |
| 22 #------------------------------------------------------------------------- |
| 23 # Sort some large ( > 4KiB) records. |
| 24 # |
| 25 proc cksum {x} { |
| 26 set i1 1 |
| 27 set i2 2 |
| 28 binary scan $x c* L |
| 29 foreach {a b} $L { |
| 30 set i1 [expr (($i2<<3) + $a) & 0x7FFFFFFF] |
| 31 set i2 [expr (($i1<<3) + $b) & 0x7FFFFFFF] |
| 32 } |
| 33 list $i1 $i2 |
| 34 } |
| 35 db func cksum cksum |
| 36 |
| 37 do_execsql_test 1.0 { |
| 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); |
| 50 } |
| 51 |
| 52 foreach {tn mmap_limit} { |
| 53 1 0 |
| 54 2 1000000 |
| 55 } { |
| 56 do_test 1.$tn { |
| 57 sqlite3_test_control SQLITE_TESTCTRL_SORTER_MMAP db $mmap_limit |
| 58 set prev "" |
| 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"} |
| 62 set prev $b |
| 63 } |
| 64 set {} {} |
| 65 } {} |
| 66 } |
| 67 |
| 68 |
22 # Sort roughly 20MB of data. Once with a mmap limit of 5MB and once without. | 69 # Sort roughly 20MB of data. Once with a mmap limit of 5MB and once without. |
23 # | 70 # |
24 foreach {itest limit} { | 71 foreach {itest limit} { |
25 1 5000000 | 72 1 5000000 |
26 2 0x7FFFFFFF | 73 2 0x7FFFFFFF |
27 } { | 74 } { |
28 sqlite3_test_control SQLITE_TESTCTRL_SORTER_MMAP db $limit | 75 sqlite3_test_control SQLITE_TESTCTRL_SORTER_MMAP db $limit |
29 do_execsql_test 1.$itest { | 76 do_execsql_test 2.$itest { |
30 WITH r(x,y) AS ( | 77 WITH r(x,y) AS ( |
31 SELECT 1, randomblob(1000) | 78 SELECT 1, randomblob(1000) |
32 UNION ALL | 79 UNION ALL |
33 SELECT x+1, randomblob(1000) FROM r | 80 SELECT x+1, randomblob(1000) FROM r |
34 LIMIT 20000 | 81 LIMIT 20000 |
35 ) | 82 ) |
36 SELECT count(*), sum(length(y)) FROM r GROUP BY (x%5); | 83 SELECT count(*), sum(length(y)) FROM r GROUP BY (x%5); |
37 } { | 84 } { |
38 4000 4000000 | 85 4000 4000000 |
39 4000 4000000 | 86 4000 4000000 |
40 4000 4000000 | 87 4000 4000000 |
41 4000 4000000 | 88 4000 4000000 |
42 4000 4000000 | 89 4000 4000000 |
43 } | 90 } |
44 } | 91 } |
45 | 92 |
46 # Sort more than 2GB of data. At one point this was causing a problem. | 93 # Sort more than 2GB of data. At one point this was causing a problem. |
47 # This test might take one minute or more to run. | 94 # This test might take one minute or more to run. |
48 # | 95 # |
49 do_execsql_test 2 { | 96 do_execsql_test 3 { |
50 PRAGMA cache_size = 20000; | 97 PRAGMA cache_size = 20000; |
51 WITH r(x,y) AS ( | 98 WITH r(x,y) AS ( |
52 SELECT 1, randomblob(1000) | 99 SELECT 1, randomblob(1000) |
53 UNION ALL | 100 UNION ALL |
54 SELECT x+1, randomblob(1000) FROM r | 101 SELECT x+1, randomblob(1000) FROM r |
55 LIMIT 2200000 | 102 LIMIT 2200000 |
56 ) | 103 ) |
57 SELECT count(*), sum(length(y)) FROM r GROUP BY (x%5); | 104 SELECT count(*), sum(length(y)) FROM r GROUP BY (x%5); |
58 } { | 105 } { |
59 440000 440000000 | 106 440000 440000000 |
60 440000 440000000 | 107 440000 440000000 |
61 440000 440000000 | 108 440000 440000000 |
62 440000 440000000 | 109 440000 440000000 |
63 440000 440000000 | 110 440000 440000000 |
64 } | 111 } |
65 | 112 |
66 finish_test | 113 finish_test |
67 | |
OLD | NEW |