1059b2d50Sdrh# 2014-10-24 2059b2d50Sdrh# 3059b2d50Sdrh# The author disclaims copyright to this source code. In place of 4059b2d50Sdrh# a legal notice, here is a blessing: 5059b2d50Sdrh# 6059b2d50Sdrh# May you do good and not evil. 7059b2d50Sdrh# May you find forgiveness for yourself and forgive others. 8059b2d50Sdrh# May you share freely, never taking more than you give. 9059b2d50Sdrh# 10059b2d50Sdrh#************************************************************************* 11059b2d50Sdrh# 12059b2d50Sdrh# This file implements regression tests for SQLite library. The 13059b2d50Sdrh# focus of this script is testing automatic index creation logic, 14059b2d50Sdrh# and specifically creation of automatic partial indexes. 15059b2d50Sdrh# 16059b2d50Sdrh 17059b2d50Sdrhset testdir [file dirname $argv0] 18059b2d50Sdrhsource $testdir/tester.tcl 19059b2d50Sdrh 20059b2d50Sdrhdo_execsql_test autoindex4-1.0 { 21059b2d50Sdrh CREATE TABLE t1(a,b); 22059b2d50Sdrh INSERT INTO t1 VALUES(123,'abc'),(234,'def'),(234,'ghi'),(345,'jkl'); 23059b2d50Sdrh CREATE TABLE t2(x,y); 24059b2d50Sdrh INSERT INTO t2 VALUES(987,'zyx'),(654,'wvu'),(987,'rqp'); 25059b2d50Sdrh 26059b2d50Sdrh SELECT *, '|' FROM t1, t2 WHERE a=234 AND x=987 ORDER BY +b; 27059b2d50Sdrh} {234 def 987 rqp | 234 def 987 zyx | 234 ghi 987 rqp | 234 ghi 987 zyx |} 28059b2d50Sdrhdo_execsql_test autoindex4-1.1 { 29059b2d50Sdrh SELECT *, '|' FROM t1, t2 WHERE a=234 AND x=555; 30059b2d50Sdrh} {} 31059b2d50Sdrh 32059b2d50Sdrhdo_execsql_test autoindex4-1.2 { 33059b2d50Sdrh SELECT *, '|' FROM t1 LEFT JOIN t2 ON a=234 AND x=555; 34059b2d50Sdrh} {123 abc {} {} | 234 def {} {} | 234 ghi {} {} | 345 jkl {} {} |} 35059b2d50Sdrhdo_execsql_test autoindex4-1.3 { 36059b2d50Sdrh SELECT *, '|' FROM t1 LEFT JOIN t2 ON x=555 WHERE a=234; 37059b2d50Sdrh} {234 def {} {} | 234 ghi {} {} |} 38059b2d50Sdrhdo_execsql_test autoindex4-1.4 { 39059b2d50Sdrh SELECT *, '|' FROM t1 LEFT JOIN t2 WHERE a=234 AND x=555; 40059b2d50Sdrh} {} 41059b2d50Sdrh 42059b2d50Sdrh 43059b2d50Sdrhdo_execsql_test autoindex4-2.0 { 44059b2d50Sdrh CREATE TABLE t3(e,f); 45059b2d50Sdrh INSERT INTO t3 VALUES(123,654),(555,444),(234,987); 46059b2d50Sdrh 47059b2d50Sdrh SELECT (SELECT count(*) FROM t1, t2 WHERE a=e AND x=f), e, f, '|' 48059b2d50Sdrh FROM t3 49059b2d50Sdrh ORDER BY rowid; 50059b2d50Sdrh} {1 123 654 | 0 555 444 | 4 234 987 |} 51059b2d50Sdrh 5236f65bafSdrh# Ticket [2326c258d02ead33d] 5336f65bafSdrh# Two joins, one with and the other without an ORDER BY clause. 5436f65bafSdrh# The one without ORDER BY correctly returns two rows of result. 5536f65bafSdrh# The one with ORDER BY returns no rows. 5636f65bafSdrh# 5736f65bafSdrhdo_execsql_test autoindex4-3.0 { 5836f65bafSdrh CREATE TABLE A(Name text); 5936f65bafSdrh CREATE TABLE Items(ItemName text , Name text); 6036f65bafSdrh INSERT INTO Items VALUES('Item1','Parent'); 6136f65bafSdrh INSERT INTO Items VALUES('Item2','Parent'); 6236f65bafSdrh CREATE TABLE B(Name text); 6336f65bafSdrh 6436f65bafSdrh SELECT Items.ItemName 6536f65bafSdrh FROM Items 6636f65bafSdrh LEFT JOIN A ON (A.Name = Items.ItemName and Items.ItemName = 'dummy') 6736f65bafSdrh LEFT JOIN B ON (B.Name = Items.ItemName) 6836f65bafSdrh WHERE Items.Name = 'Parent' 6936f65bafSdrh ORDER BY Items.ItemName; 7036f65bafSdrh} {Item1 Item2} 71*077f06edSdrhdo_execsql_test autoindex4-3.1 { 72*077f06edSdrh CREATE INDEX Items_x1 ON Items(ItemName,Name) WHERE ItemName = 'dummy'; 73*077f06edSdrh 74*077f06edSdrh SELECT Items.ItemName 75*077f06edSdrh FROM Items 76*077f06edSdrh LEFT JOIN A ON (A.Name = Items.ItemName and Items.ItemName = 'dummy') 77*077f06edSdrh LEFT JOIN B ON (B.Name = Items.ItemName) 78*077f06edSdrh WHERE Items.Name = 'Parent' 79*077f06edSdrh ORDER BY Items.ItemName; 80*077f06edSdrh} {Item1 Item2} 8136f65bafSdrh 8236f65bafSdrh 83059b2d50Sdrhfinish_test 84