|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set testdir [file dirname $argv0] |
|
|
source $testdir/tester.tcl |
|
|
|
|
|
ifcapable !stat4 { |
|
|
finish_test |
|
|
return |
|
|
} |
|
|
|
|
|
set testprefix analyze8 |
|
|
|
|
|
proc eqp {sql {db db}} { |
|
|
uplevel execsql [list "EXPLAIN QUERY PLAN $sql"] $db |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
do_test 1.0 { |
|
|
db eval { |
|
|
CREATE TABLE t1(a,b,c,d); |
|
|
CREATE INDEX t1a ON t1(a); |
|
|
CREATE INDEX t1b ON t1(b); |
|
|
CREATE INDEX t1c ON t1(c); |
|
|
} |
|
|
for {set i 0} {$i<1000} {incr i} { |
|
|
if {$i%2==0} {set a $i} {set a [expr {($i%8)*100}]} |
|
|
set b [expr {$i/10}] |
|
|
set c [expr {$i/8}] |
|
|
set c [expr {$c*$c*$c}] |
|
|
db eval {INSERT INTO t1 VALUES($a,$b,$c,$i)} |
|
|
} |
|
|
db eval {ANALYZE} |
|
|
} {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
do_test 1.1 { |
|
|
eqp {SELECT * FROM t1 WHERE a=100 AND b=55} |
|
|
} {/*SEARCH t1 USING INDEX t1b (b=?)*/} |
|
|
do_test 1.2 { |
|
|
eqp {SELECT * FROM t1 WHERE a=99 AND b=55} |
|
|
} {/*SEARCH t1 USING INDEX t1a (a=?)*/} |
|
|
do_test 1.3 { |
|
|
eqp {SELECT * FROM t1 WHERE a=101 AND b=55} |
|
|
} {/*SEARCH t1 USING INDEX t1a (a=?)*/} |
|
|
do_test 1.4 { |
|
|
eqp {SELECT * FROM t1 WHERE a=100 AND b=56} |
|
|
} {/*SEARCH t1 USING INDEX t1b (b=?)*/} |
|
|
do_test 1.5 { |
|
|
eqp {SELECT * FROM t1 WHERE a=99 AND b=56} |
|
|
} {/*SEARCH t1 USING INDEX t1a (a=?)*/} |
|
|
do_test 1.6 { |
|
|
eqp {SELECT * FROM t1 WHERE a=101 AND b=56} |
|
|
} {/*SEARCH t1 USING INDEX t1a (a=?)*/} |
|
|
do_test 2.1 { |
|
|
eqp {SELECT * FROM t1 WHERE a=100 AND b BETWEEN 50 AND 54} |
|
|
} {/*SEARCH t1 USING INDEX t1b (b>? AND b<?)*/} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
do_execsql_test 3.0 { |
|
|
SELECT count(*) FROM t1 WHERE b BETWEEN 30 AND 34; |
|
|
SELECT count(*) FROM t1 WHERE c BETWEEN 0 AND 100000; |
|
|
SELECT count(*) FROM t1 WHERE c BETWEEN 800000 AND 900000; |
|
|
} {50 376 32} |
|
|
do_test 3.1 { |
|
|
eqp {SELECT * FROM t1 WHERE b BETWEEN 30 AND 34 AND c BETWEEN 0 AND 100000} |
|
|
} {/*SEARCH t1 USING INDEX t1b (b>? AND b<?)*/} |
|
|
do_test 3.2 { |
|
|
eqp {SELECT * FROM t1 |
|
|
WHERE b BETWEEN 30 AND 34 AND c BETWEEN 800000 AND 900000} |
|
|
} {/*SEARCH t1 USING INDEX t1c (c>? AND c<?)*/} |
|
|
do_test 3.3 { |
|
|
eqp {SELECT * FROM t1 WHERE a=100 AND c BETWEEN 0 AND 100000} |
|
|
} {/*SEARCH t1 USING INDEX t1a (a=?)*/} |
|
|
do_test 3.4 { |
|
|
eqp {SELECT * FROM t1 |
|
|
WHERE a=100 AND c BETWEEN 800000 AND 900000} |
|
|
} {/*SEARCH t1 USING INDEX t1c (c>? AND c<?)*/} |
|
|
|
|
|
finish_test |
|
|
|