drh | 3a3b420 | 2017-02-15 22:36:15 +0000 | [diff] [blame] | 1 | # 2017-02-15 |
| 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 | # Test cases to show that a join involving an empty table is very fast. |
| 13 | # |
| 14 | |
| 15 | set testdir [file dirname $argv0] |
| 16 | source $testdir/tester.tcl |
| 17 | |
| 18 | # Build some test data |
| 19 | # |
| 20 | do_execsql_test emptytable-100 { |
| 21 | CREATE TABLE t1(a); |
| 22 | WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) |
| 23 | INSERT INTO t1(a) SELECT x FROM c; |
| 24 | CREATE TABLE empty(x); |
| 25 | SELECT count(*) FROM t1; |
| 26 | } {100} |
| 27 | |
| 28 | # Interrupt queries after 1M cycles to prevent burning excess CPU |
| 29 | proc stopDb {args} { |
| 30 | db interrupt |
| 31 | } |
| 32 | db progress 1000000 {stopDb} |
| 33 | |
| 34 | # Prior to the query planner optimization on 2017-02-15, this query would |
| 35 | # take a ridiculous amount of time. If that optimization stops working, |
| 36 | # the result here will be in interrupt for running too long. |
| 37 | # |
| 38 | do_catchsql_test emptytable-110 { |
| 39 | SELECT count(*) FROM t1, t1, t1, t1, t1, t1, empty; |
| 40 | } {0 0} |
| 41 | |
| 42 | do_catchsql_test emptytable-120 { |
| 43 | SELECT count(*) FROM t1, t1 LEFT JOIN empty; |
| 44 | } {0 10000} |
| 45 | do_catchsql_test emptytable-121 { |
| 46 | SELECT count(*) FROM t1, t1 LEFT JOIN t1, empty; |
| 47 | } {0 0} |
| 48 | |
| 49 | |
| 50 | finish_test |