AryaWu/sqlite
0
1# 2014 September 15.2#3# The author disclaims copyright to this source code. In place of4# 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. 12#13 14set testdir [file dirname $argv0]15source $testdir/tester.tcl16set testprefix sort517 18 19#-------------------------------------------------------------------------20# Verify that sorting works with a version 1 sqlite3_io_methods structure.21#22testvfs tvfs -iversion 1 -default true23reset_db24do_execsql_test 1.0 {25 PRAGMA mmap_size = 10000000;26 PRAGMA cache_size = 10;27 CREATE TABLE t1(a, b);28} {0}29 30do_test 1.1 {31 execsql BEGIN32 for {set i 0} {$i < 2000} {incr i} {33 execsql { INSERT INTO t1 VALUES($i, randomblob(2000)) }34 }35 execsql COMMIT36} {}37 38do_execsql_test 1.2 {39 CREATE INDEX i1 ON t1(b);40}41 42db close43tvfs delete44 45#-------------------------------------------------------------------------46# Test that the PMA size is determined correctly. The PMA size should be47# roughly the same amount of memory allocated to the main pager cache, or48# 250 pages if this is larger.49#50testvfs tvfs51tvfs script tv_callback52tvfs filter {xOpen xWrite}53 54proc tv_callback {method args} {55 global iTemp56 global F57 switch $method {58 xOpen {59 if {[lindex $args 0]==""} { return "temp[incr iTemp]" }60 return "SQLITE_OK"61 }62 63 xWrite {64 foreach {filename id off amt} $args {}65 if {[info exists F($id)]==0 || $F($id)<($off + $amt)} {66 set F($id) [expr $off+$amt]67 }68 }69 }70}71 72catch { db close }73forcedelete test.db74sqlite3 db test.db -vfs tvfs75execsql { CREATE TABLE t1(x) }76execsql { PRAGMA temp_store = 1 }77 78# Each iteration of the following loop attempts to sort 10001 records79# each a bit over 100 bytes in size. In total a little more than 1MiB 80# of data.81#82foreach {tn pgsz cachesz bTemp} {83 1 4096 1000 084 2 1024 1000 185 86 3 4096 -1000 187 4 1024 -1000 188 89 5 4096 -9000 090 6 1024 -9000 091} {92 if {$::TEMP_STORE>2} {93 set bTemp 094 }95 do_execsql_test 2.$tn.0 "96 PRAGMA page_size = $pgsz;97 VACUUM;98 PRAGMA cache_size = $cachesz;99 "100 101 if {[db one {PRAGMA page_size}]!=$pgsz} {102 # SEE is not able to change page sizes and that messes up the103 # results that follow.104 continue105 }106 107 do_test 2.$tn.1 {108 set ::iTemp 0109 catch { array unset F }110 execsql {111 WITH x(i, j) AS (112 SELECT 1, randomblob(100)113 UNION ALL114 SELECT i+1, randomblob(100) FROM x WHERE i<10000115 )116 SELECT * FROM x ORDER BY j;117 }118 expr {[array names F]!=""}119 } $bTemp120}121 122finish_test123 