aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2009-04-02 16:59:47 +0000
committerdrh <drh@noemail.net>2009-04-02 16:59:47 +0000
commite8902a70fe07fcbc3929ed1b44f46fd6dea418b8 (patch)
tree8c5f2f4800130474b1c03d7d42f9d53429e18b9f /test
parent3034e3d3649c71770a11de94d38412d4abd4ef98 (diff)
downloadsqlite-e8902a70fe07fcbc3929ed1b44f46fd6dea418b8.tar.gz
sqlite-e8902a70fe07fcbc3929ed1b44f46fd6dea418b8.zip
Disable the query flattening optimization when the subquery is a compound
query with an ORDER BY clause. Ticket #3773 shows why that combination does not work. (CVS 6437) FossilOrigin-Name: 23f90d50737a36ebd17152dd4667948ce7049967
Diffstat (limited to 'test')
-rw-r--r--test/selectB.test60
-rw-r--r--test/tkt3773.test38
2 files changed, 69 insertions, 29 deletions
diff --git a/test/selectB.test b/test/selectB.test
index 9f5261e91..3fdf85c0f 100644
--- a/test/selectB.test
+++ b/test/selectB.test
@@ -10,7 +10,7 @@
#***********************************************************************
# This file implements regression tests for SQLite library.
#
-# $Id: selectB.test,v 1.9 2008/08/04 03:51:24 danielk1977 Exp $
+# $Id: selectB.test,v 1.10 2009/04/02 16:59:47 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -122,7 +122,7 @@ for {set ii 1} {$ii <= 2} {incr ii} {
} {
SELECT a FROM t1 UNION ALL SELECT d FROM t2 ORDER BY 1 LIMIT 2 OFFSET 3
} {12 14}
-
+
test_transform selectB-$ii.9 {
SELECT * FROM (
SELECT a FROM t1 UNION ALL SELECT d FROM t2 UNION ALL SELECT c FROM t1
@@ -156,33 +156,35 @@ for {set ii 1} {$ii <= 2} {incr ii} {
SELECT a FROM t1 UNION ALL SELECT d FROM t2 LIMIT 2
} {2 8}
- test_transform selectB-$ii.13 {
- SELECT * FROM (SELECT a FROM t1 UNION ALL SELECT d FROM t2 ORDER BY a ASC)
- } {
- SELECT a FROM t1 UNION ALL SELECT d FROM t2 ORDER BY 1 ASC
- } {2 3 8 12 14 21}
-
- test_transform selectB-$ii.14 {
- SELECT * FROM (SELECT a FROM t1 UNION ALL SELECT d FROM t2 ORDER BY a DESC)
- } {
- SELECT a FROM t1 UNION ALL SELECT d FROM t2 ORDER BY 1 DESC
- } {21 14 12 8 3 2}
-
- test_transform selectB-$ii.14 {
- SELECT * FROM (
- SELECT a FROM t1 UNION ALL SELECT d FROM t2 ORDER BY a DESC
- ) LIMIT 2 OFFSET 2
- } {
- SELECT a FROM t1 UNION ALL SELECT d FROM t2 ORDER BY 1 DESC LIMIT 2 OFFSET 2
- } {12 8}
-
- test_transform selectB-$ii.15 {
- SELECT * FROM (
- SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 ORDER BY a ASC, e DESC
- )
- } {
- SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 ORDER BY a ASC, e DESC
- } {2 4 3 6 8 10 12 15 14 16 21 24}
+ # An ORDER BY in a compound subqueries defeats flattening. Ticket #3773
+ # test_transform selectB-$ii.13 {
+ # SELECT * FROM (SELECT a FROM t1 UNION ALL SELECT d FROM t2 ORDER BY a ASC)
+ # } {
+ # SELECT a FROM t1 UNION ALL SELECT d FROM t2 ORDER BY 1 ASC
+ # } {2 3 8 12 14 21}
+ #
+ # test_transform selectB-$ii.14 {
+ # SELECT * FROM (SELECT a FROM t1 UNION ALL SELECT d FROM t2 ORDER BY a DESC)
+ # } {
+ # SELECT a FROM t1 UNION ALL SELECT d FROM t2 ORDER BY 1 DESC
+ # } {21 14 12 8 3 2}
+ #
+ # test_transform selectB-$ii.14 {
+ # SELECT * FROM (
+ # SELECT a FROM t1 UNION ALL SELECT d FROM t2 ORDER BY a DESC
+ # ) LIMIT 2 OFFSET 2
+ # } {
+ # SELECT a FROM t1 UNION ALL SELECT d FROM t2 ORDER BY 1 DESC
+ # LIMIT 2 OFFSET 2
+ # } {12 8}
+ #
+ # test_transform selectB-$ii.15 {
+ # SELECT * FROM (
+ # SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 ORDER BY a ASC, e DESC
+ # )
+ # } {
+ # SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 ORDER BY a ASC, e DESC
+ # } {2 4 3 6 8 10 12 15 14 16 21 24}
}
do_test selectB-3.0 {
diff --git a/test/tkt3773.test b/test/tkt3773.test
new file mode 100644
index 000000000..0dc414e50
--- /dev/null
+++ b/test/tkt3773.test
@@ -0,0 +1,38 @@
+# 2009 April 2
+#
+# 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.
+#
+#***********************************************************************
+#
+# Ticket #3773: Be careful not to over-optimize when a compound
+# subquery contains an ORDER BY clause.
+#
+#
+# $Id: tkt3773.test,v 1.1 2009/04/02 16:59:47 drh Exp $
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_test tkt3773-1.1 {
+ db eval {
+ CREATE TABLE t1(a,b);
+ INSERT INTO t1 VALUES(2,1);
+ INSERT INTO t1 VALUES(33,3);
+ CREATE TABLE t2(x,y);
+ INSERT INTO t2 VALUES(123,2);
+ INSERT INTO t2 VALUES(4,4);
+ SELECT a FROM (
+ SELECT a, b FROM t1
+ UNION ALL
+ SELECT x, y FROM t2
+ ORDER BY 2
+ );
+ }
+} {2 123 33 4}
+
+finish_test