Small performance optimization in sqlite3VdbeRecordCompareWithSkip() for
[sqlite.git] / test / emptytable.test
blob79cd16e9133d4bd1bd9e4e76ed3b982789201e6e
1 # 2017-02-15
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # Test cases to show that a join involving an empty table is very fast.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
18 # Build some test data
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}
28 # Interrupt queries after 1M cycles to prevent burning excess CPU
29 proc stopDb {args} {
30   db interrupt
32 db progress 1000000 {stopDb}
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.
38 do_catchsql_test emptytable-110 {
39   SELECT count(*) FROM t1, t1, t1, t1, t1, t1, empty;
40 } {0 0}
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}
50 finish_test