xref: /sqlite-3.40.0/test/sort2.test (revision be7721d1)
1578e1ca8Sdan# 2014 March 25.
2578e1ca8Sdan#
3578e1ca8Sdan# The author disclaims copyright to this source code.  In place of
4578e1ca8Sdan# a legal notice, here is a blessing:
5578e1ca8Sdan#
6578e1ca8Sdan#    May you do good and not evil.
7578e1ca8Sdan#    May you find forgiveness for yourself and forgive others.
8578e1ca8Sdan#    May you share freely, never taking more than you give.
9578e1ca8Sdan#
10578e1ca8Sdan#***********************************************************************
11578e1ca8Sdan# This file implements regression tests for SQLite library.
12578e1ca8Sdan#
130d51def2Sdan# Specifically, the tests in this file attempt to verify that
140d51def2Sdan# multi-threaded sorting works.
150d51def2Sdan#
16578e1ca8Sdan
17578e1ca8Sdanset testdir [file dirname $argv0]
18578e1ca8Sdansource $testdir/tester.tcl
19578e1ca8Sdanset testprefix sort2
203bd1791dSdrhdb close
213bd1791dSdrhsqlite3_shutdown
223bd1791dSdrhsqlite3_config_pmasz 10
233bd1791dSdrhsqlite3_initialize
243bd1791dSdrhsqlite3 db test.db
25578e1ca8Sdan
264be4c406Sdanforeach {tn script} {
274be4c406Sdan  1 { }
284be4c406Sdan  2 {
294be4c406Sdan    catch { db close }
30578e1ca8Sdan    reset_db
31028696c4Sdrh    catch { db eval {PRAGMA threads=7} }
324be4c406Sdan  }
334be4c406Sdan} {
344be4c406Sdan  eval $script
354be4c406Sdan
364be4c406Sdan  do_execsql_test $tn.1 {
37578e1ca8Sdan    PRAGMA cache_size = 5;
38578e1ca8Sdan    WITH r(x,y) AS (
39578e1ca8Sdan      SELECT 1, randomblob(100)
40578e1ca8Sdan      UNION ALL
41578e1ca8Sdan      SELECT x+1, randomblob(100) FROM r
42578e1ca8Sdan      LIMIT 100000
43578e1ca8Sdan    )
44578e1ca8Sdan    SELECT count(x), length(y) FROM r GROUP BY (x%5)
45578e1ca8Sdan  } {
46578e1ca8Sdan    20000 100 20000 100 20000 100 20000 100 20000 100
47578e1ca8Sdan  }
48578e1ca8Sdan
494be4c406Sdan  do_execsql_test $tn.2.1 {
50fad9f9a8Sdan    CREATE TABLE t1(a, b);
51fad9f9a8Sdan    WITH r(x,y) AS (
52fad9f9a8Sdan      SELECT 1, randomblob(100)
53fad9f9a8Sdan      UNION ALL
54fad9f9a8Sdan      SELECT x+1, randomblob(100) FROM r
55fad9f9a8Sdan      LIMIT 10000
56fad9f9a8Sdan    ) INSERT INTO t1 SELECT * FROM r;
57fad9f9a8Sdan  }
58fad9f9a8Sdan
594be4c406Sdan  do_execsql_test $tn.2.2 {
60fad9f9a8Sdan    CREATE UNIQUE INDEX i1 ON t1(b, a);
61fad9f9a8Sdan  }
62fad9f9a8Sdan
634be4c406Sdan  do_execsql_test $tn.2.3 {
64d30ab3d9Sdan    CREATE UNIQUE INDEX i2 ON t1(a);
65d30ab3d9Sdan  }
66d30ab3d9Sdan
674be4c406Sdan  do_execsql_test $tn.2.4 { PRAGMA integrity_check } {ok}
684be4c406Sdan
69*be7721d1Sdan  # Because it uses so much data, this test can take 12-13 seconds even on
70*be7721d1Sdan  # a modern workstation. So it is omitted from "veryquick" and other
71*be7721d1Sdan  # permutations.test tests.
72*be7721d1Sdan  if {[isquick]==0} {
734be4c406Sdan    do_execsql_test $tn.3 {
744be4c406Sdan      PRAGMA cache_size = 5;
754be4c406Sdan      WITH r(x,y) AS (
764be4c406Sdan          SELECT 1, randomblob(100)
774be4c406Sdan          UNION ALL
784be4c406Sdan          SELECT x+1, randomblob(100) FROM r
794be4c406Sdan          LIMIT 1000000
804be4c406Sdan          )
814be4c406Sdan        SELECT count(x), length(y) FROM r GROUP BY (x%5)
824be4c406Sdan    } {
834be4c406Sdan      200000 100 200000 100 200000 100 200000 100 200000 100
844be4c406Sdan    }
854be4c406Sdan  }
86*be7721d1Sdan}
874be4c406Sdan
88578e1ca8Sdanfinish_test
89