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 52*36f65bafSdrh# Ticket [2326c258d02ead33d] 53*36f65bafSdrh# Two joins, one with and the other without an ORDER BY clause. 54*36f65bafSdrh# The one without ORDER BY correctly returns two rows of result. 55*36f65bafSdrh# The one with ORDER BY returns no rows. 56*36f65bafSdrh# 57*36f65bafSdrhdo_execsql_test autoindex4-3.0 { 58*36f65bafSdrh CREATE TABLE A(Name text); 59*36f65bafSdrh CREATE TABLE Items(ItemName text , Name text); 60*36f65bafSdrh INSERT INTO Items VALUES('Item1','Parent'); 61*36f65bafSdrh INSERT INTO Items VALUES('Item2','Parent'); 62*36f65bafSdrh CREATE TABLE B(Name text); 63*36f65bafSdrh 64*36f65bafSdrh SELECT Items.ItemName 65*36f65bafSdrh FROM Items 66*36f65bafSdrh LEFT JOIN A ON (A.Name = Items.ItemName and Items.ItemName = 'dummy') 67*36f65bafSdrh LEFT JOIN B ON (B.Name = Items.ItemName) 68*36f65bafSdrh WHERE Items.Name = 'Parent' 69*36f65bafSdrh ORDER BY Items.ItemName; 70*36f65bafSdrh} {Item1 Item2} 71*36f65bafSdrh 72*36f65bafSdrh 73059b2d50Sdrhfinish_test 74