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. The
12 # focus of this script testing the ability of SQLite to use mmap
13 # to access files larger than 4GiB.
16 if {[file exists skip-big-file]} return
17 if {$tcl_platform(os)=="Darwin"} return
19 set testdir [file dirname $argv0]
20 source $testdir/tester.tcl
21 set testprefix bigmmap
23 ifcapable !mmap||!vtab {
30 SELECT compile_options AS x FROM pragma_compile_options
31 WHERE x LIKE 'max_mmap_size=%'
33 regexp {MAX_MMAP_SIZE=([0-9]*)} $x -> mmap_limit
35 if {$mmap_limit < [expr 8 * 1<<30]} {
36 puts "Skipping bigmmap.test - requires SQLITE_MAX_MMAP_SIZE >= 8G"
42 #-------------------------------------------------------------------------
43 # Create the database file roughly 8GiB in size. Most pages are unused,
44 # except that there is a table and index clustered around each 1GiB
48 PRAGMA page_size = 4096;
49 CREATE TABLE t0(a INTEGER PRIMARY KEY, b, c, UNIQUE(b, c));
50 WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 100 )
51 INSERT INTO t0 SELECT i, 't0', randomblob(800) FROM s;
54 for {set i 1} {$i < 8} {incr i} {
55 if {[catch {fake_big_file [expr $i*1024] [get_pwd]/test.db}]} {
56 puts "Cannot create ${i}MB sparse file"
60 hexio_write test.db 28 [format %.8x [expr ($i*1024*1024*1024/4096) - 5]]
62 do_execsql_test 1.$i "
63 CREATE TABLE t$i (a INTEGER PRIMARY KEY, b, c, UNIQUE(b, c));
64 WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 100 )
65 INSERT INTO t$i SELECT i, 't$i', randomblob(800) FROM s;
69 #-------------------------------------------------------------------------
70 # Check that data can be retrieved from the db with a variety of
71 # configured mmap size limits.
73 for {set i 0} {$i < 9} {incr i} {
75 # Configure a memory mapping $i GB in size.
77 set val [expr $i*1024*1024*1024]
78 execsql "PRAGMA main.mmap_size = $val"
79 do_execsql_test 2.$i.0 {
83 for {set t 0} {$t < 8} {incr t} {
84 do_execsql_test 2.$i.$t.1 "
85 SELECT count(*) FROM t$t;
86 SELECT count(b || c) FROM t$t GROUP BY b;
89 do_execsql_test 2.$i.$t.2 "
90 SELECT * FROM t$t AS o WHERE
91 NOT EXISTS( SELECT * FROM t$t AS i WHERE a=o.a AND +b=o.b AND +c=o.c )
95 do_eqp_test 2.$i.$t.3 "
96 SELECT * FROM t$t AS o WHERE
97 NOT EXISTS( SELECT * FROM t$t AS i WHERE a=o.a AND +b=o.b AND +c=o.c )
99 " [string map {"\n " "\n"} "
101 |--SCAN o USING COVERING INDEX sqlite_autoindex_t${t}_1
102 `--CORRELATED SCALAR SUBQUERY xxxxxx
103 `--SEARCH i USING INTEGER PRIMARY KEY (rowid=?)