# 2013-11-13 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # # This file implements tests of the "skip-scan" query strategy. In # particular it tests that stat4 data can be used by a range query # that uses the skip-scan approach. # set testdir [file dirname $argv0] source $testdir/tester.tcl set testprefix skipscan5 ifcapable !stat4 { finish_test return } do_execsql_test 1.1 { CREATE TABLE t1(a INT, b INT, c INT); CREATE INDEX i1 ON t1(a, b); } {} expr srand(4) do_test 1.2 { for {set i 0} {$i < 1000} {incr i} { set a [expr int(rand()*4.0) + 1] set b [expr int(rand()*20.0) + 1] execsql { INSERT INTO t1 VALUES($a, $b, NULL) } } execsql ANALYZE } {} foreach {tn q res} { 1 "b = 5" {/*ANY(a) AND b=?*/} 2 "b > 12 AND b < 16" {/*ANY(a) AND b>? AND b 2 AND b < 16" {/*SCAN TABLE t1*/} 4 "b > 18 AND b < 25" {/*ANY(a) AND b>? AND b 16" {/*ANY(a) AND b>?*/} 6 "b > 5" {/*SCAN TABLE t1*/} 7 "b < 15" {/*SCAN TABLE t1*/} 8 "b < 5" {/*ANY(a) AND b b" {/*ANY(a) AND b '12' AND b < '16'" {/*ANY(a) AND b>? AND b '2' AND b < '16'" {/*SCAN TABLE t1*/} 13 "b > '18' AND b < '25'" {/*ANY(a) AND b>? AND b '16'" {/*ANY(a) AND b>?*/} 15 "b > '5'" {/*SCAN TABLE t1*/} 16 "b < '15'" {/*SCAN TABLE t1*/} 17 "b < '5'" {/*ANY(a) AND b b" {/*ANY(a) AND b? AND c 'q' } {/*ANY(a) AND ANY(b) AND c>?*/} 4 { c > 'e' } {/*SCAN TABLE t2*/} 5 { c < 'q' } {/*SCAN TABLE t2*/} 6 { c < 'b' } {/*ANY(a) AND ANY(b) AND c? AND b X'5555'" {/*ANY(a) AND b>?*/} 5 "b > 'zzz'" {/*ANY(a) AND b>?*/} 6 "b < 'zzz'" {/*SCAN TABLE t3*/} } { set sql "EXPLAIN QUERY PLAN SELECT * FROM t3 WHERE $q" do_execsql_test 3.3.$tn $sql $res } finish_test