blob: 0e7a80df216d9ef41537ba2c4e3d5dc790f9dc5a [file] [log] [blame]
drh059b2d52014-10-24 19:28:09 +00001# 2014-10-24
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
6# May you do good and not evil.
7# May you find forgiveness for yourself and forgive others.
8# May you share freely, never taking more than you give.
9#
10#*************************************************************************
11#
12# This file implements regression tests for SQLite library. The
13# focus of this script is testing automatic index creation logic,
14# and specifically creation of automatic partial indexes.
15#
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20do_execsql_test autoindex4-1.0 {
21 CREATE TABLE t1(a,b);
22 INSERT INTO t1 VALUES(123,'abc'),(234,'def'),(234,'ghi'),(345,'jkl');
23 CREATE TABLE t2(x,y);
24 INSERT INTO t2 VALUES(987,'zyx'),(654,'wvu'),(987,'rqp');
25
26 SELECT *, '|' FROM t1, t2 WHERE a=234 AND x=987 ORDER BY +b;
27} {234 def 987 rqp | 234 def 987 zyx | 234 ghi 987 rqp | 234 ghi 987 zyx |}
28do_execsql_test autoindex4-1.1 {
29 SELECT *, '|' FROM t1, t2 WHERE a=234 AND x=555;
30} {}
31
32do_execsql_test autoindex4-1.2 {
33 SELECT *, '|' FROM t1 LEFT JOIN t2 ON a=234 AND x=555;
34} {123 abc {} {} | 234 def {} {} | 234 ghi {} {} | 345 jkl {} {} |}
35do_execsql_test autoindex4-1.3 {
36 SELECT *, '|' FROM t1 LEFT JOIN t2 ON x=555 WHERE a=234;
37} {234 def {} {} | 234 ghi {} {} |}
38do_execsql_test autoindex4-1.4 {
39 SELECT *, '|' FROM t1 LEFT JOIN t2 WHERE a=234 AND x=555;
40} {}
41
42
43do_execsql_test autoindex4-2.0 {
44 CREATE TABLE t3(e,f);
45 INSERT INTO t3 VALUES(123,654),(555,444),(234,987);
46
47 SELECT (SELECT count(*) FROM t1, t2 WHERE a=e AND x=f), e, f, '|'
48 FROM t3
49 ORDER BY rowid;
50} {1 123 654 | 0 555 444 | 4 234 987 |}
51
drh36f65ba2015-02-24 16:05:54 +000052# Ticket [2326c258d02ead33d]
53# Two joins, one with and the other without an ORDER BY clause.
54# The one without ORDER BY correctly returns two rows of result.
55# The one with ORDER BY returns no rows.
56#
57do_execsql_test autoindex4-3.0 {
58 CREATE TABLE A(Name text);
59 CREATE TABLE Items(ItemName text , Name text);
60 INSERT INTO Items VALUES('Item1','Parent');
61 INSERT INTO Items VALUES('Item2','Parent');
62 CREATE TABLE B(Name text);
63
64 SELECT Items.ItemName
65 FROM Items
66 LEFT JOIN A ON (A.Name = Items.ItemName and Items.ItemName = 'dummy')
67 LEFT JOIN B ON (B.Name = Items.ItemName)
68 WHERE Items.Name = 'Parent'
69 ORDER BY Items.ItemName;
70} {Item1 Item2}
drh077f06e2015-02-24 16:48:59 +000071do_execsql_test autoindex4-3.1 {
72 CREATE INDEX Items_x1 ON Items(ItemName,Name) WHERE ItemName = 'dummy';
73
74 SELECT Items.ItemName
75 FROM Items
76 LEFT JOIN A ON (A.Name = Items.ItemName and Items.ItemName = 'dummy')
77 LEFT JOIN B ON (B.Name = Items.ItemName)
78 WHERE Items.Name = 'Parent'
79 ORDER BY Items.ItemName;
80} {Item1 Item2}
drh36f65ba2015-02-24 16:05:54 +000081
82
drh059b2d52014-10-24 19:28:09 +000083finish_test