xref: /sqlite-3.40.0/test/sort5.test (revision 22f60b84)
1ed7bcba7Sdan# 2014 September 15.
2ed7bcba7Sdan#
3ed7bcba7Sdan# The author disclaims copyright to this source code.  In place of
4ed7bcba7Sdan# a legal notice, here is a blessing:
5ed7bcba7Sdan#
6ed7bcba7Sdan#    May you do good and not evil.
7ed7bcba7Sdan#    May you find forgiveness for yourself and forgive others.
8ed7bcba7Sdan#    May you share freely, never taking more than you give.
9ed7bcba7Sdan#
10ed7bcba7Sdan#***********************************************************************
11ed7bcba7Sdan# This file implements regression tests for SQLite library.
12ed7bcba7Sdan#
13ed7bcba7Sdan
14ed7bcba7Sdanset testdir [file dirname $argv0]
15ed7bcba7Sdansource $testdir/tester.tcl
16ed7bcba7Sdanset testprefix sort5
17ed7bcba7Sdan
18ed7bcba7Sdan
19ed7bcba7Sdan#-------------------------------------------------------------------------
20ed7bcba7Sdan# Verify that sorting works with a version 1 sqlite3_io_methods structure.
21ed7bcba7Sdan#
22ed7bcba7Sdantestvfs tvfs -iversion 1 -default true
23ed7bcba7Sdanreset_db
24ed7bcba7Sdando_execsql_test 1.0 {
25ed7bcba7Sdan  PRAGMA mmap_size = 10000000;
26ed7bcba7Sdan  PRAGMA cache_size = 10;
27ed7bcba7Sdan  CREATE TABLE t1(a, b);
28ed7bcba7Sdan} {0}
29ed7bcba7Sdan
30ed7bcba7Sdando_test 1.1 {
31ed7bcba7Sdan  execsql BEGIN
32ed7bcba7Sdan  for {set i 0} {$i < 2000} {incr i} {
33ed7bcba7Sdan    execsql { INSERT INTO t1 VALUES($i, randomblob(2000)) }
34ed7bcba7Sdan  }
35ed7bcba7Sdan  execsql COMMIT
36ed7bcba7Sdan} {}
37ed7bcba7Sdan
38ed7bcba7Sdando_execsql_test 1.2 {
39ed7bcba7Sdan  CREATE INDEX i1 ON t1(b);
40ed7bcba7Sdan}
41ed7bcba7Sdan
42ed7bcba7Sdandb close
43ed7bcba7Sdantvfs delete
44fc26f7cfSdan
45fc26f7cfSdan#-------------------------------------------------------------------------
46fc26f7cfSdan# Test that the PMA size is determined correctly. The PMA size should be
47fc26f7cfSdan# roughly the same amount of memory allocated to the main pager cache, or
48fc26f7cfSdan# 250 pages if this is larger.
49fc26f7cfSdan#
50fc26f7cfSdantestvfs tvfs
51fc26f7cfSdantvfs script tv_callback
52fc26f7cfSdantvfs filter {xOpen xWrite}
53fc26f7cfSdan
54fc26f7cfSdanproc tv_callback {method args} {
55fc26f7cfSdan  global iTemp
56fc26f7cfSdan  global F
57fc26f7cfSdan  switch $method {
58fc26f7cfSdan    xOpen {
59fc26f7cfSdan      if {[lindex $args 0]==""} { return "temp[incr iTemp]" }
60fc26f7cfSdan      return "SQLITE_OK"
61fc26f7cfSdan    }
62fc26f7cfSdan
63fc26f7cfSdan    xWrite {
64fc26f7cfSdan      foreach {filename id off amt} $args {}
65fc26f7cfSdan      if {[info exists F($id)]==0 || $F($id)<($off + $amt)} {
66fc26f7cfSdan        set F($id) [expr $off+$amt]
67fc26f7cfSdan      }
68fc26f7cfSdan    }
69fc26f7cfSdan  }
70fc26f7cfSdan}
71fc26f7cfSdan
72fc26f7cfSdancatch { db close }
73fc26f7cfSdanforcedelete test.db
74fc26f7cfSdansqlite3 db test.db -vfs tvfs
75fc26f7cfSdanexecsql { CREATE TABLE t1(x) }
76*22f60b84Sdanexecsql { PRAGMA temp_store = 1 }
77fc26f7cfSdan
78fc26f7cfSdan# Each iteration of the following loop attempts to sort 10001 records
79fc26f7cfSdan# each a bit over 100 bytes in size. In total a little more than 1MiB
80fc26f7cfSdan# of data.
81fc26f7cfSdan#
82fc26f7cfSdanforeach {tn pgsz cachesz bTemp} {
83fc26f7cfSdan  1 4096   1000  0
84fc26f7cfSdan  2 1024   1000  1
85fc26f7cfSdan
86fc26f7cfSdan  3 4096  -1000  1
87fc26f7cfSdan  4 1024  -1000  1
88fc26f7cfSdan
89fc26f7cfSdan  5 4096  -9000  0
90fc26f7cfSdan  6 1024  -9000  0
91fc26f7cfSdan} {
92*22f60b84Sdan  if {$::TEMP_STORE>2} {
93*22f60b84Sdan    set bTemp 0
94*22f60b84Sdan  }
95fc26f7cfSdan  do_execsql_test 2.$tn.0 "
96fc26f7cfSdan    PRAGMA page_size = $pgsz;
97fc26f7cfSdan    VACUUM;
98fc26f7cfSdan    PRAGMA cache_size = $cachesz;
99fc26f7cfSdan  "
100fc26f7cfSdan
10183561932Sdrh  if {[db one {PRAGMA page_size}]!=$pgsz} {
10283561932Sdrh    # SEE is not able to change page sizes and that messes up the
10383561932Sdrh    # results that follow.
10483561932Sdrh    continue
10583561932Sdrh  }
10683561932Sdrh
107fc26f7cfSdan  do_test 2.$tn.1 {
108fc26f7cfSdan    set ::iTemp 0
109fc26f7cfSdan    catch { array unset F }
110fc26f7cfSdan    execsql {
111fc26f7cfSdan      WITH x(i, j) AS (
112fc26f7cfSdan        SELECT 1, randomblob(100)
113fc26f7cfSdan        UNION ALL
114fc26f7cfSdan        SELECT i+1, randomblob(100) FROM x WHERE i<10000
115fc26f7cfSdan      )
116fc26f7cfSdan      SELECT * FROM x ORDER BY j;
117fc26f7cfSdan    }
118fc26f7cfSdan    expr {[array names F]!=""}
119fc26f7cfSdan  } $bTemp
120fc26f7cfSdan}
121fc26f7cfSdan
122ed7bcba7Sdanfinish_test
123