xref: /sqlite-3.40.0/test/sort2.test (revision be7721d1)
1# 2014 March 25.
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.
12#
13# Specifically, the tests in this file attempt to verify that
14# multi-threaded sorting works.
15#
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19set testprefix sort2
20db close
21sqlite3_shutdown
22sqlite3_config_pmasz 10
23sqlite3_initialize
24sqlite3 db test.db
25
26foreach {tn script} {
27  1 { }
28  2 {
29    catch { db close }
30    reset_db
31    catch { db eval {PRAGMA threads=7} }
32  }
33} {
34  eval $script
35
36  do_execsql_test $tn.1 {
37    PRAGMA cache_size = 5;
38    WITH r(x,y) AS (
39      SELECT 1, randomblob(100)
40      UNION ALL
41      SELECT x+1, randomblob(100) FROM r
42      LIMIT 100000
43    )
44    SELECT count(x), length(y) FROM r GROUP BY (x%5)
45  } {
46    20000 100 20000 100 20000 100 20000 100 20000 100
47  }
48
49  do_execsql_test $tn.2.1 {
50    CREATE TABLE t1(a, b);
51    WITH r(x,y) AS (
52      SELECT 1, randomblob(100)
53      UNION ALL
54      SELECT x+1, randomblob(100) FROM r
55      LIMIT 10000
56    ) INSERT INTO t1 SELECT * FROM r;
57  }
58
59  do_execsql_test $tn.2.2 {
60    CREATE UNIQUE INDEX i1 ON t1(b, a);
61  }
62
63  do_execsql_test $tn.2.3 {
64    CREATE UNIQUE INDEX i2 ON t1(a);
65  }
66
67  do_execsql_test $tn.2.4 { PRAGMA integrity_check } {ok}
68
69  # Because it uses so much data, this test can take 12-13 seconds even on
70  # a modern workstation. So it is omitted from "veryquick" and other
71  # permutations.test tests.
72  if {[isquick]==0} {
73    do_execsql_test $tn.3 {
74      PRAGMA cache_size = 5;
75      WITH r(x,y) AS (
76          SELECT 1, randomblob(100)
77          UNION ALL
78          SELECT x+1, randomblob(100) FROM r
79          LIMIT 1000000
80          )
81        SELECT count(x), length(y) FROM r GROUP BY (x%5)
82    } {
83      200000 100 200000 100 200000 100 200000 100 200000 100
84    }
85  }
86}
87
88finish_test
89