summaryrefslogtreecommitdiff
path: root/test/autoindex3.test
diff options
context:
space:
mode:
authorHans-Christoph Steiner <hans@eds.org>2014-10-16 22:51:43 -0400
committerHans-Christoph Steiner <hans@eds.org>2014-10-16 22:51:43 -0400
commit9f67c0520ea0d5f11a190197cdf746c512db4ce4 (patch)
treec88a33f01f20a3d13a09594f114fffacebd0d1a4 /test/autoindex3.test
parentee20336e9c78d2e3782c8d096b9ab4f6ca8ce95f (diff)
parent569c6676a6ddb0ff73821d7693b5e18ddef809b9 (diff)
Merge tag 'upstream/3.2.0'
Upstream version 3.2.0 # gpg: Signature made Thu 16 Oct 2014 10:51:39 PM EDT using RSA key ID 374BBE81 # gpg: Good signature from "Hans-Christoph Steiner <hans@guardianproject.info>" # gpg: aka "Hans-Christoph Steiner <hans@eds.org>" # gpg: aka "Hans-Christoph Steiner <hans@at.or.at>" # gpg: aka "[jpeg image of size 5408]"
Diffstat (limited to 'test/autoindex3.test')
-rw-r--r--test/autoindex3.test58
1 files changed, 58 insertions, 0 deletions
diff --git a/test/autoindex3.test b/test/autoindex3.test
new file mode 100644
index 0000000..33053bb
--- /dev/null
+++ b/test/autoindex3.test
@@ -0,0 +1,58 @@
+# 2014-06-17
+#
+# 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 script is testing automatic index creation logic,
+# and specifically that an automatic index will not be created that
+# shadows a declared index.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# The t1b and t2d indexes are not very selective. It used to be that
+# the autoindex mechanism would create automatic indexes on t1(b) or
+# t2(d), make assumptions that they were reasonably selective, and use
+# them instead of t1b or t2d. But that would be cheating, because the
+# automatic index cannot be any more selective than the real index.
+#
+# This test verifies that the cheat is no longer allowed.
+#
+do_execsql_test autoindex3-100 {
+ CREATE TABLE t1(a,b,x);
+ CREATE TABLE t2(c,d,y);
+ CREATE INDEX t1b ON t1(b);
+ CREATE INDEX t2d ON t2(d);
+ ANALYZE sqlite_master;
+ INSERT INTO sqlite_stat1 VALUES('t1','t1b','10000 500');
+ INSERT INTO sqlite_stat1 VALUES('t2','t2d','10000 500');
+ ANALYZE sqlite_master;
+ EXPLAIN QUERY PLAN SELECT * FROM t1, t2 WHERE d=b;
+} {~/AUTO/}
+
+# Automatic indexes can still be used if existing indexes do not
+# participate in == constraints.
+#
+do_execsql_test autoindex3-110 {
+ EXPLAIN QUERY PLAN SELECT * FROM t1, t2 WHERE d>b AND x=y;
+} {/AUTO/}
+do_execsql_test autoindex3-120 {
+ EXPLAIN QUERY PLAN SELECT * FROM t1, t2 WHERE d<b AND x=y;
+} {/AUTO/}
+do_execsql_test autoindex3-130 {
+ EXPLAIN QUERY PLAN SELECT * FROM t1, t2 WHERE d IS NULL AND x=y;
+} {/AUTO/}
+do_execsql_test autoindex3-140 {
+ EXPLAIN QUERY PLAN SELECT * FROM t1, t2 WHERE d IN (5,b) AND x=y;
+} {/AUTO/}
+
+
+finish_test