Index: third_party/sqlite/src/test/select9.test |
diff --git a/third_party/sqlite/src/test/select9.test b/third_party/sqlite/src/test/select9.test |
index 085dee0bd1e2991c5fb53feaf8be7d4a3885ccc6..4c42236dc873e30bd9e504bb4fb17d4447f49874 100644 |
--- a/third_party/sqlite/src/test/select9.test |
+++ b/third_party/sqlite/src/test/select9.test |
@@ -415,5 +415,58 @@ do_test select9-4.X { |
} |
} {} |
+# Testing to make sure that queries involving a view of a compound select |
+# are planned efficiently. This detects a problem reported on the mailing |
+# list on 2012-04-26. See |
+# |
+# http://www.mail-archive.com/sqlite-users%40sqlite.org/msg69746.html |
+# |
+# For additional information. |
+# |
+do_test select9-5.1 { |
+ db eval { |
+ CREATE TABLE t51(x, y); |
+ CREATE TABLE t52(x, y); |
+ CREATE VIEW v5 as |
+ SELECT x, y FROM t51 |
+ UNION ALL |
+ SELECT x, y FROM t52; |
+ CREATE INDEX t51x ON t51(x); |
+ CREATE INDEX t52x ON t52(x); |
+ EXPLAIN QUERY PLAN |
+ SELECT * FROM v5 WHERE x='12345' ORDER BY y; |
+ } |
+} {~/SCAN TABLE/} ;# Uses indices with "*" |
+do_test select9-5.2 { |
+ db eval { |
+ EXPLAIN QUERY PLAN |
+ SELECT x, y FROM v5 WHERE x='12345' ORDER BY y; |
+ } |
+} {~/SCAN TABLE/} ;# Uses indices with "x, y" |
+do_test select9-5.3 { |
+ db eval { |
+ EXPLAIN QUERY PLAN |
+ SELECT x, y FROM v5 WHERE +x='12345' ORDER BY y; |
+ } |
+} {/SCAN TABLE/} ;# Full table scan if the "+x" prevents index usage. |
+ |
+# 2013-07-09: Ticket [490a4b7235624298]: |
+# "WHERE 0" on the first element of a UNION causes an assertion fault |
+# |
+do_execsql_test select9-6.1 { |
+ CREATE TABLE t61(a); |
+ CREATE TABLE t62(b); |
+ INSERT INTO t61 VALUES(111); |
+ INSERT INTO t62 VALUES(222); |
+ SELECT a FROM t61 WHERE 0 UNION SELECT b FROM t62; |
+} {222} |
+do_execsql_test select9-6.2 { |
+ SELECT a FROM t61 WHERE 0 UNION ALL SELECT b FROM t62; |
+} {222} |
+do_execsql_test select9-6.3 { |
+ SELECT a FROM t61 UNION SELECT b FROM t62 WHERE 0; |
+} {111} |
+ |
+ |
finish_test |