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 16if {[file exists skip-big-file]} return 17if {$tcl_platform(os)=="Darwin"} return 18 19set testdir [file dirname $argv0] 20source $testdir/tester.tcl 21set testprefix bigmmap 22 23ifcapable !mmap||!vtab { 24 finish_test 25 return 26} 27 28set mmap_limit 0 29db 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} 35if {$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# 47do_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 54for {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" 57 finish_test 58 return 59 } 60 hexio_write test.db 28 [format %.8x [expr ($i*1024*1024*1024/4096) - 5]] 61 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; 66 " 67} 68 69#------------------------------------------------------------------------- 70# Check that data can be retrieved from the db with a variety of 71# configured mmap size limits. 72# 73for {set i 0} {$i < 9} {incr i} { 74 75 # Configure a memory mapping $i GB in size. 76 # 77 set val [expr $i*1024*1024*1024] 78 execsql "PRAGMA main.mmap_size = $val" 79 do_execsql_test 2.$i.0 { 80 PRAGMA main.mmap_size 81 } $val 82 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; 87 " {100 100} 88 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 ) 92 ORDER BY b, c; 93 " {} 94 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 ) 98 ORDER BY b, c; 99 " [string map {"\n " "\n"} " 100 QUERY PLAN 101 |--SCAN o USING COVERING INDEX sqlite_autoindex_t${t}_1 102 `--CORRELATED SCALAR SUBQUERY xxxxxx 103 `--SEARCH i USING INTEGER PRIMARY KEY (rowid=?) 104 "] 105 } 106} 107 108finish_test 109