gitlab.com/CoiaPrant/sqlite3@v1.19.1/testdata/tcl/bigmmap.test (about) 1 # 2017 August 07 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 # 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. 14 # 15 16 if {[file exists skip-big-file]} return 17 if {$tcl_platform(os)=="Darwin"} return 18 19 set testdir [file dirname $argv0] 20 source $testdir/tester.tcl 21 set testprefix bigmmap 22 23 ifcapable !mmap||!vtab { 24 finish_test 25 return 26 } 27 28 set mmap_limit 0 29 db eval { 30 SELECT compile_options AS x FROM pragma_compile_options 31 WHERE x LIKE 'max_mmap_size=%' 32 } { 33 regexp {MAX_MMAP_SIZE=([0-9]*)} $x -> mmap_limit 34 } 35 if {$mmap_limit < [expr 8 * 1<<30]} { 36 puts "Skipping bigmmap.test - requires SQLITE_MAX_MMAP_SIZE >= 8G" 37 finish_test 38 return 39 } 40 41 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 45 # boundary. 46 # 47 do_execsql_test 1.0 { 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; 52 } 53 54 for {set i 1} {$i < 8} {incr i} { 55 fake_big_file [expr $i*1024] [get_pwd]/test.db 56 hexio_write test.db 28 [format %.8x [expr ($i*1024*1024*1024/4096) - 5]] 57 58 do_execsql_test 1.$i " 59 CREATE TABLE t$i (a INTEGER PRIMARY KEY, b, c, UNIQUE(b, c)); 60 WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 100 ) 61 INSERT INTO t$i SELECT i, 't$i', randomblob(800) FROM s; 62 " 63 } 64 65 #------------------------------------------------------------------------- 66 # Check that data can be retrieved from the db with a variety of 67 # configured mmap size limits. 68 # 69 for {set i 0} {$i < 9} {incr i} { 70 71 # Configure a memory mapping $i GB in size. 72 # 73 set val [expr $i*1024*1024*1024] 74 execsql "PRAGMA main.mmap_size = $val" 75 do_execsql_test 2.$i.0 { 76 PRAGMA main.mmap_size 77 } $val 78 79 for {set t 0} {$t < 8} {incr t} { 80 do_execsql_test 2.$i.$t.1 " 81 SELECT count(*) FROM t$t; 82 SELECT count(b || c) FROM t$t GROUP BY b; 83 " {100 100} 84 85 do_execsql_test 2.$i.$t.2 " 86 SELECT * FROM t$t AS o WHERE 87 NOT EXISTS( SELECT * FROM t$t AS i WHERE a=o.a AND +b=o.b AND +c=o.c ) 88 ORDER BY b, c; 89 " {} 90 91 do_eqp_test 2.$i.$t.3 " 92 SELECT * FROM t$t AS o WHERE 93 NOT EXISTS( SELECT * FROM t$t AS i WHERE a=o.a AND +b=o.b AND +c=o.c ) 94 ORDER BY b, c; 95 " [string map {"\n " "\n"} " 96 QUERY PLAN 97 |--SCAN o USING COVERING INDEX sqlite_autoindex_t${t}_1 98 `--CORRELATED SCALAR SUBQUERY xxxxxx 99 `--SEARCH i USING INTEGER PRIMARY KEY (rowid=?) 100 "] 101 } 102 } 103 104 finish_test