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 # Tests for the optimization which attempts to use a covering index
13 # for a full-table scan (under the theory that the index will be smaller
14 # and require less I/O and hence will run faster.)
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 set testprefix coveridxscan
24 CREATE TABLE t1(a,b,c);
25 INSERT INTO t1 VALUES(5,4,3), (4,8,2), (3,2,1);
26 CREATE INDEX t1ab ON t1(a,b);
27 CREATE INDEX t1b ON t1(b);
30 # covering index used for the scan, hence values are increasing
37 # There is no covering index, hence the values are in rowid order
44 # Choice of two indices: use the one with fewest columns
48 optimization_control db cover-idx-scan 0
49 db eval {SELECT a FROM t1}
50 # With the optimization turned off, output in rowid order
53 db eval {SELECT a, c FROM t1}
56 db eval {SELECT b FROM t1}
65 db eval {SELECT a FROM t1}
66 # With the optimization configured off, output in rowid order
69 db eval {SELECT a, c FROM t1}
72 db eval {SELECT b FROM t1}
80 # The CIS optimization is enabled again. Covering indices are once again
81 # used for all table scans.
83 db eval {SELECT a FROM t1}
86 db eval {SELECT a, c FROM t1}
89 db eval {SELECT b FROM t1}