xref: /sqlite-3.40.0/test/sort2.test (revision 0d51def2)
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
20
21foreach {tn script} {
22  1 { }
23  2 {
24    catch { db close }
25    sqlite3_shutdown
26    sqlite3_config_worker_threads 7
27    reset_db
28  }
29} {
30
31  eval $script
32
33  do_execsql_test $tn.1 {
34    PRAGMA cache_size = 5;
35    WITH r(x,y) AS (
36      SELECT 1, randomblob(100)
37      UNION ALL
38      SELECT x+1, randomblob(100) FROM r
39      LIMIT 100000
40    )
41    SELECT count(x), length(y) FROM r GROUP BY (x%5)
42  } {
43    20000 100 20000 100 20000 100 20000 100 20000 100
44  }
45
46  do_execsql_test $tn.2.1 {
47    CREATE TABLE t1(a, b);
48    WITH r(x,y) AS (
49      SELECT 1, randomblob(100)
50      UNION ALL
51      SELECT x+1, randomblob(100) FROM r
52      LIMIT 10000
53    ) INSERT INTO t1 SELECT * FROM r;
54  }
55
56  do_execsql_test $tn.2.2 {
57    CREATE UNIQUE INDEX i1 ON t1(b, a);
58  }
59
60  do_execsql_test $tn.2.3 {
61    CREATE UNIQUE INDEX i2 ON t1(a);
62  }
63
64  do_execsql_test $tn.2.4 { PRAGMA integrity_check } {ok}
65
66  breakpoint
67  do_execsql_test $tn.3 {
68    PRAGMA cache_size = 5;
69    WITH r(x,y) AS (
70      SELECT 1, randomblob(100)
71      UNION ALL
72      SELECT x+1, randomblob(100) FROM r
73      LIMIT 1000000
74    )
75    SELECT count(x), length(y) FROM r GROUP BY (x%5)
76  } {
77    200000 100 200000 100 200000 100 200000 100 200000 100
78  }
79
80  db close
81  sqlite3_shutdown
82  sqlite3_config_worker_threads 0
83  sqlite3_initialize
84
85}
86
87finish_test
88
89