1*3a3b420aSdrh# 2017-02-15 2*3a3b420aSdrh# 3*3a3b420aSdrh# The author disclaims copyright to this source code. In place of 4*3a3b420aSdrh# a legal notice, here is a blessing: 5*3a3b420aSdrh# 6*3a3b420aSdrh# May you do good and not evil. 7*3a3b420aSdrh# May you find forgiveness for yourself and forgive others. 8*3a3b420aSdrh# May you share freely, never taking more than you give. 9*3a3b420aSdrh# 10*3a3b420aSdrh#*********************************************************************** 11*3a3b420aSdrh# 12*3a3b420aSdrh# Test cases to show that a join involving an empty table is very fast. 13*3a3b420aSdrh# 14*3a3b420aSdrh 15*3a3b420aSdrhset testdir [file dirname $argv0] 16*3a3b420aSdrhsource $testdir/tester.tcl 17*3a3b420aSdrh 18*3a3b420aSdrh# Build some test data 19*3a3b420aSdrh# 20*3a3b420aSdrhdo_execsql_test emptytable-100 { 21*3a3b420aSdrh CREATE TABLE t1(a); 22*3a3b420aSdrh WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) 23*3a3b420aSdrh INSERT INTO t1(a) SELECT x FROM c; 24*3a3b420aSdrh CREATE TABLE empty(x); 25*3a3b420aSdrh SELECT count(*) FROM t1; 26*3a3b420aSdrh} {100} 27*3a3b420aSdrh 28*3a3b420aSdrh# Interrupt queries after 1M cycles to prevent burning excess CPU 29*3a3b420aSdrhproc stopDb {args} { 30*3a3b420aSdrh db interrupt 31*3a3b420aSdrh} 32*3a3b420aSdrhdb progress 1000000 {stopDb} 33*3a3b420aSdrh 34*3a3b420aSdrh# Prior to the query planner optimization on 2017-02-15, this query would 35*3a3b420aSdrh# take a ridiculous amount of time. If that optimization stops working, 36*3a3b420aSdrh# the result here will be in interrupt for running too long. 37*3a3b420aSdrh# 38*3a3b420aSdrhdo_catchsql_test emptytable-110 { 39*3a3b420aSdrh SELECT count(*) FROM t1, t1, t1, t1, t1, t1, empty; 40*3a3b420aSdrh} {0 0} 41*3a3b420aSdrh 42*3a3b420aSdrhdo_catchsql_test emptytable-120 { 43*3a3b420aSdrh SELECT count(*) FROM t1, t1 LEFT JOIN empty; 44*3a3b420aSdrh} {0 10000} 45*3a3b420aSdrhdo_catchsql_test emptytable-121 { 46*3a3b420aSdrh SELECT count(*) FROM t1, t1 LEFT JOIN t1, empty; 47*3a3b420aSdrh} {0 0} 48*3a3b420aSdrh 49*3a3b420aSdrh 50*3a3b420aSdrhfinish_test 51