Enhance the command-line completion extension to return the names of
[sqlite.git] / test / tkt3757.test
blob011beb5c8b79f8f1a1b46832dab5bdfce88ea10d
1 # 2009 March 28
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 # Ticket #3757:  The cost functions on the query optimizer for the
13 # IN operator can be improved.
15 # $Id: tkt3757.test,v 1.1 2009/03/29 00:13:04 drh Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 # Evaluate SQL.  Return the result set followed by the
21 # and the number of full-scan steps.
23 proc count_steps {sql} {
24   set r [db eval $sql]
25   lappend r scan [db status step] sort [db status sort]
28 # Construct tables
30 do_test tkt3757-1.1 {
31   db eval {
32      CREATE TABLE t1(x INTEGER, y INTEGER, z TEXT);
33      CREATE INDEX t1i1 ON t1(y,z);
34      INSERT INTO t1 VALUES(1,2,'three');
35      CREATE TABLE t2(a INTEGER, b TEXT);
36      INSERT INTO t2 VALUES(2, 'two');
37      ANALYZE;
38      SELECT * FROM sqlite_stat1 ORDER BY 1, 2;
39   }
40 } {t1 t1i1 {1 1 1} t2 {} 1}
42 # Modify statistics in order to make the optimizer then that:
44 #   (1)  Table T1 has about 250K entries
45 #   (2)  There are only about 5 distinct values of T1.
47 # Then run a query with "t1.y IN (SELECT ..)" in the WHERE clause.
48 # Make sure the index is used.
50 do_test tkt3757-1.2 {
51   db eval {
52     DELETE FROM sqlite_stat1;
53     INSERT INTO sqlite_stat1 VALUES('t1','t1i1','250000 50000 30');
54   }
55   count_steps {
56     SELECT * FROM t1 WHERE y IN (SELECT a FROM t2)
57   }
58 } {1 2 three scan 0 sort 0}
60 finish_test