Annotation of embedaddon/sqlite3/test/tkt3757.test, revision 1.1

1.1     ! misho       1: # 2009 March 28
        !             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: # Ticket #3757:  The cost functions on the query optimizer for the
        !            13: # IN operator can be improved.
        !            14: #
        !            15: # $Id: tkt3757.test,v 1.1 2009/03/29 00:13:04 drh Exp $
        !            16: 
        !            17: set testdir [file dirname $argv0]
        !            18: source $testdir/tester.tcl
        !            19: 
        !            20: # Evaluate SQL.  Return the result set followed by the
        !            21: # and the number of full-scan steps.
        !            22: #
        !            23: proc count_steps {sql} {
        !            24:   set r [db eval $sql]
        !            25:   lappend r scan [db status step] sort [db status sort]
        !            26: }
        !            27: 
        !            28: # Construct tables
        !            29: #
        !            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}
        !            41: 
        !            42: # Modify statistics in order to make the optimizer then that:
        !            43: #
        !            44: #   (1)  Table T1 has about 250K entries
        !            45: #   (2)  There are only about 5 distinct values of T1.
        !            46: #
        !            47: # Then run a query with "t1.y IN (SELECT ..)" in the WHERE clause.
        !            48: # Make sure the index is used.
        !            49: #
        !            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}
        !            59: 
        !            60: finish_test

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>