]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
New test case for block-sorting.
authordrh <drh@noemail.net>
Fri, 21 Mar 2014 15:24:07 +0000 (15:24 +0000)
committerdrh <drh@noemail.net>
Fri, 21 Mar 2014 15:24:07 +0000 (15:24 +0000)
FossilOrigin-Name: e70cfa28aa393661ccc742ecd5e672d807bdd0a9

manifest
manifest.uuid
test/orderby6.test [new file with mode: 0644]

index 6bb5c6bb73fd8b287b07dab72177b7f7546ceeff..e0157af62475ce8a3a2ac60c015de6ce501d0be8 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Merge\strunk\sfixes\sfor\s"x\sIN\s(?)"\shandling.
-D 2014-03-20T20:56:49.315
+C New\stest\scase\sfor\sblock-sorting.
+D 2014-03-21T15:24:07.126
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -723,6 +723,7 @@ F test/orderby2.test bc11009f7cd99d96b1b11e57b199b00633eb5b04
 F test/orderby3.test 8619d06a3debdcd80a27c0fdea5c40b468854b99
 F test/orderby4.test 4d39bfbaaa3ae64d026ca2ff166353d2edca4ba4
 F test/orderby5.test 2490183fef54417209d1df253633a605d46bd350
+F test/orderby6.test 8b38138ab0972588240b3fca0985d2e400432859
 F test/oserror.test 50417780d0e0d7cd23cf12a8277bb44024765df3
 F test/pager1.test 1acbdb14c5952a72dd43129cabdbf69aaa3ed1fa
 F test/pager2.test 67b8f40ae98112bcdba1f2b2d03ea83266418c71
@@ -1156,7 +1157,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
-P e4bfffb988283c077778c60696be0d285ad66c3c d5a1530bdc7ace053d05d1a037551110021d3758
-R a45d230e7f98fec92659279ce8b3552c
+P eca35871c34374ca9189c7c9b6d490ac3c30357f
+R f6c9f43506e02e19d33da5c08cba37a5
 U drh
-Z 027a45adb600d40b2564e06474072c41
+Z 983388db59b02f32fb79fe85b7106067
index 8a32b61e54a829d9bab3aed757eef67cb9a24af4..fe6f27d9c88084beebfe34916490e6c8140e081d 100644 (file)
@@ -1 +1 @@
-eca35871c34374ca9189c7c9b6d490ac3c30357f
\ No newline at end of file
+e70cfa28aa393661ccc742ecd5e672d807bdd0a9
\ No newline at end of file
diff --git a/test/orderby6.test b/test/orderby6.test
new file mode 100644 (file)
index 0000000..403250d
--- /dev/null
@@ -0,0 +1,183 @@
+# 2014-03-21
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.  The
+# focus of this file is testing that the block-sort optimization.
+#
+
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set ::testprefix orderby6
+
+# Run all tests twice.  Once with a normal table and a second time
+# with a WITHOUT ROWID table
+#
+foreach {tn rowidclause} {1 {} 2 {WITHOUT ROWID}} {
+
+  # Construct a table with 1000 rows and a split primary key
+  #
+  reset_db
+  do_test $tn.1 {
+    db eval "CREATE TABLE t1(a,b,c,PRIMARY KEY(b,c)) $rowidclause;"
+    db eval {
+      WITH RECURSIVE
+       cnt(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM cnt WHERE x<1000)
+     INSERT INTO t1 SELECT x, x%40, x/40 FROM cnt;
+    }
+  } {}
+
+  # Run various ORDER BY queries that can benefit from block-sort.
+  # Compare the output to the same output using a full-sort enforced
+  # by adding + to each term of the ORDER BY clause.
+  #
+  do_execsql_test $tn.2 {
+    SELECT b,a,c FROM t1 ORDER BY b,a,c;
+  } [db eval {SELECT b,a,c FROM t1 ORDER BY +b,+a,+c}]
+  do_execsql_test $tn.3 {
+    SELECT b,a,c FROM t1 ORDER BY b,c DESC,a;
+  } [db eval {SELECT b,a,c FROM t1 ORDER BY +b,+c DESC,+a}]
+  do_execsql_test $tn.4 {
+    SELECT b,a,c FROM t1 ORDER BY b DESC,c,a;
+  } [db eval {SELECT b,a,c FROM t1 ORDER BY +b DESC,+c,+a}]
+  do_execsql_test $tn.5 {
+    SELECT b,a,c FROM t1 ORDER BY b DESC,a,c;
+  } [db eval {SELECT b,a,c FROM t1 ORDER BY +b DESC,+a,+c}]
+
+  # LIMIT and OFFSET clauses on block-sort queries.
+  #
+  do_execsql_test $tn.11 {
+    SELECT a FROM t1 ORDER BY b, a LIMIT 10 OFFSET 20;
+  } {840 880 920 960 1000 1 41 81 121 161}
+  do_execsql_test $tn.11x {
+    SELECT a FROM t1 ORDER BY +b, a LIMIT 10 OFFSET 20;
+  } {840 880 920 960 1000 1 41 81 121 161}
+
+  do_execsql_test $tn.12 {
+    SELECT a FROM t1 ORDER BY b DESC, a LIMIT 10 OFFSET 20;
+  } {839 879 919 959 999 38 78 118 158 198}
+  do_execsql_test $tn.12 {
+    SELECT a FROM t1 ORDER BY +b DESC, a LIMIT 10 OFFSET 20;
+  } {839 879 919 959 999 38 78 118 158 198}
+
+  do_execsql_test $tn.13 {
+    SELECT a FROM t1 ORDER BY b, a DESC LIMIT 10 OFFSET 45;
+  } {161 121 81 41 1 962 922 882 842 802}
+  do_execsql_test $tn.13x {
+    SELECT a FROM t1 ORDER BY +b, a DESC LIMIT 10 OFFSET 45;
+  } {161 121 81 41 1 962 922 882 842 802}
+
+  do_execsql_test $tn.14 {
+    SELECT a FROM t1 ORDER BY b DESC, a LIMIT 10 OFFSET 45;
+  } {838 878 918 958 998 37 77 117 157 197}
+  do_execsql_test $tn.14x {
+    SELECT a FROM t1 ORDER BY +b DESC, a LIMIT 10 OFFSET 45;
+  } {838 878 918 958 998 37 77 117 157 197}
+
+  # Many test cases where the LIMIT+OFFSET window is in various
+  # alignments with block-sort boundaries.
+  #
+  foreach {tx limit offset orderby} {
+     1  10 24 {+b,+a}
+     2  10 25 {+b,+a}
+     3  10 26 {+b,+a}
+     4  10 39 {+b,+a}
+     5  10 40 {+b,+a}
+     6  10 41 {+b,+a}
+     7  27 24 {+b,+a}
+     8  27 49 {+b,+a}
+     11 10 24 {+b DESC,+a}
+     12 10 25 {+b DESC,+a}
+     13 10 26 {+b DESC,+a}
+     14 10 39 {+b DESC,+a}
+     15 10 40 {+b DESC,+a}
+     16 10 41 {+b DESC,+a}
+     17 27 24 {+b DESC,+a}
+     18 27 49 {+b DESC,+a}
+     21 10 24 {+b,+a DESC}
+     22 10 25 {+b,+a DESC}
+     23 10 26 {+b,+a DESC}
+     24 10 39 {+b,+a DESC}
+     25 10 40 {+b,+a DESC}
+     26 10 41 {+b,+a DESC}
+     27 27 24 {+b,+a DESC}
+     28 27 49 {+b,+a DESC}
+     31 10 24 {+b DESC,+a DESC}
+     32 10 25 {+b DESC,+a DESC}
+     33 10 26 {+b DESC,+a DESC}
+     34 10 39 {+b DESC,+a DESC}
+     35 10 40 {+b DESC,+a DESC}
+     36 10 41 {+b DESC,+a DESC}
+     37 27 24 {+b DESC,+a DESC}
+     38 27 49 {+b DESC,+a DESC}
+  } {
+    set sql1 "SELECT a FROM t1 ORDER BY $orderby LIMIT $limit OFFSET $offset;"
+    set sql2 [string map {+ {}} $sql1]
+    # puts $sql2\n$sql1\n[db eval $sql2]
+    do_test $tn.21.$tx {db eval $::sql2} [db eval $sql1]
+  }
+
+  ########################################################################
+  # A second test table, t2, has many columns open to sorting.
+  do_test $tn.31 {
+    db eval "CREATE TABLE t2(a,b,c,d,e,f,PRIMARY KEY(b,c,d,e,f)) $rowidclause;"
+    db eval {
+      WITH RECURSIVE
+       cnt(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM cnt WHERE x<242)
+     INSERT INTO t2 SELECT x,  x%3, (x/3)%3, (x/9)%3, (x/27)%3, (x/81)%3
+                      FROM cnt;
+    }
+  } {}
+
+  do_execsql_test $tn.32 {
+    SELECT a FROM t2 ORDER BY b,c,d,e,f;
+  } [db eval {SELECT a FROM t2 ORDER BY +b,+c,+d,+e,+f;}]
+  do_execsql_test $tn.33 {
+    SELECT a FROM t2 ORDER BY b,c,d,e,+f;
+  } [db eval {SELECT a FROM t2 ORDER BY +b,+c,+d,+e,+f;}]
+  do_execsql_test $tn.34 {
+    SELECT a FROM t2 ORDER BY b,c,d,+e,+f;
+  } [db eval {SELECT a FROM t2 ORDER BY +b,+c,+d,+e,+f;}]
+  do_execsql_test $tn.35 {
+    SELECT a FROM t2 ORDER BY b,c,+d,+e,+f;
+  } [db eval {SELECT a FROM t2 ORDER BY +b,+c,+d,+e,+f;}]
+  do_execsql_test $tn.36 {
+    SELECT a FROM t2 ORDER BY b,+c,+d,+e,+f;
+  } [db eval {SELECT a FROM t2 ORDER BY +b,+c,+d,+e,+f;}]
+
+  do_execsql_test $tn.37 {
+    SELECT a FROM t2 ORDER BY b,c,d,e,f DESC;
+  } [db eval {SELECT a FROM t2 ORDER BY +b,+c,+d,+e,+f DESC;}]
+  do_execsql_test $tn.38 {
+    SELECT a FROM t2 ORDER BY b,c,d,e DESC,f;
+  } [db eval {SELECT a FROM t2 ORDER BY +b,+c,+d,+e DESC,+f;}]
+  do_execsql_test $tn.39 {
+    SELECT a FROM t2 ORDER BY b,c,d DESC,e,f;
+  } [db eval {SELECT a FROM t2 ORDER BY +b,+c,+d DESC,+e,+f;}]
+  do_execsql_test $tn.40 {
+    SELECT a FROM t2 ORDER BY b,c DESC,d,e,f;
+  } [db eval {SELECT a FROM t2 ORDER BY +b,+c DESC,+d,+e,+f;}]
+  do_execsql_test $tn.41 {
+    SELECT a FROM t2 ORDER BY b DESC,c,d,e,f;
+  } [db eval {SELECT a FROM t2 ORDER BY +b DESC,+c,+d,+e,+f;}]
+
+  do_execsql_test $tn.42 {
+    SELECT a FROM t2 ORDER BY b DESC,c DESC,d,e,f LIMIT 31;
+  } [db eval {SELECT a FROM t2 ORDER BY +b DESC,+c DESC,+d,+e,+f LIMIT 31}]
+  do_execsql_test $tn.43 {
+    SELECT a FROM t2 ORDER BY b,c,d,e,f DESC LIMIT 8 OFFSET 7;
+  } [db eval {SELECT a FROM t2 ORDER BY +b,+c,+d,+e,+f DESC LIMIT 8 OFFSET 7}]
+
+
+}
+
+
+
+finish_test