1*f3f69ac9Sdrh# 2014-08-20 2*f3f69ac9Sdrh# 3*f3f69ac9Sdrh# The author disclaims copyright to this source code. In place of 4*f3f69ac9Sdrh# a legal notice, here is a blessing: 5*f3f69ac9Sdrh# 6*f3f69ac9Sdrh# May you do good and not evil. 7*f3f69ac9Sdrh# May you find forgiveness for yourself and forgive others. 8*f3f69ac9Sdrh# May you share freely, never taking more than you give. 9*f3f69ac9Sdrh# 10*f3f69ac9Sdrh#*********************************************************************** 11*f3f69ac9Sdrh# 12*f3f69ac9Sdrh# This file implements tests of the "skip-scan" query strategy. 13*f3f69ac9Sdrh# In particular, this file looks at skipping intermediate terms 14*f3f69ac9Sdrh# in an index. For example, if (a,b,c) are indexed, and we have 15*f3f69ac9Sdrh# "WHERE a=?1 AND c=?2" - verify that skip-scan can still be used. 16*f3f69ac9Sdrh# 17*f3f69ac9Sdrh 18*f3f69ac9Sdrhset testdir [file dirname $argv0] 19*f3f69ac9Sdrhsource $testdir/tester.tcl 20*f3f69ac9Sdrh 21*f3f69ac9Sdrhdo_execsql_test skipscan3-1.1 { 22*f3f69ac9Sdrh CREATE TABLE t1(a,b,c,d,PRIMARY KEY(a,b,c)); 23*f3f69ac9Sdrh WITH RECURSIVE 24*f3f69ac9Sdrh c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000) 25*f3f69ac9Sdrh INSERT INTO t1(a,b,c,d) 26*f3f69ac9Sdrh SELECT 1, 1, x, printf('x%04d',x) FROM c; 27*f3f69ac9Sdrh ANALYZE; 28*f3f69ac9Sdrh} {} 29*f3f69ac9Sdrh 30*f3f69ac9Sdrh# This version has long used skip-scan because of the "+a" 31*f3f69ac9Sdrh# 32*f3f69ac9Sdrhdo_execsql_test skipscan3-1.2eqp { 33*f3f69ac9Sdrh EXPLAIN QUERY PLAN SELECT d FROM t1 WHERE +a=1 AND c=32; 34*f3f69ac9Sdrh} {/*ANY(a) AND ANY(b)*/} 35*f3f69ac9Sdrhdo_execsql_test skipscan3-1.2 { 36*f3f69ac9Sdrh SELECT d FROM t1 WHERE +a=1 AND c=32; 37*f3f69ac9Sdrh} {x0032} 38*f3f69ac9Sdrh 39*f3f69ac9Sdrh# This version (with "a" instead of "+a") should use skip-scan but 40*f3f69ac9Sdrh# did not prior to changes implemented on 2014-08-20 41*f3f69ac9Sdrh# 42*f3f69ac9Sdrhdo_execsql_test skipscan3-1.3eqp { 43*f3f69ac9Sdrh EXPLAIN QUERY PLAN SELECT d FROM t1 WHERE a=1 AND c=32; 44*f3f69ac9Sdrh} {/*ANY(a) AND ANY(b)*/} 45*f3f69ac9Sdrhdo_execsql_test skipscan3-1.3 { 46*f3f69ac9Sdrh SELECT d FROM t1 WHERE a=1 AND c=32; 47*f3f69ac9Sdrh} {x0032} 48*f3f69ac9Sdrh 49*f3f69ac9Sdrh# Repeat the test on a WITHOUT ROWID table 50*f3f69ac9Sdrh# 51*f3f69ac9Sdrhdo_execsql_test skipscan3-2.1 { 52*f3f69ac9Sdrh CREATE TABLE t2(a,b,c,d,PRIMARY KEY(a,b,c)) WITHOUT ROWID; 53*f3f69ac9Sdrh WITH RECURSIVE 54*f3f69ac9Sdrh c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000) 55*f3f69ac9Sdrh INSERT INTO t2(a,b,c,d) 56*f3f69ac9Sdrh SELECT 1, 1, x, printf('x%04d',x) FROM c; 57*f3f69ac9Sdrh ANALYZE; 58*f3f69ac9Sdrh} {} 59*f3f69ac9Sdrhdo_execsql_test skipscan3-2.2eqp { 60*f3f69ac9Sdrh EXPLAIN QUERY PLAN SELECT d FROM t2 WHERE +a=1 AND c=32; 61*f3f69ac9Sdrh} {/*ANY(a) AND ANY(b)*/} 62*f3f69ac9Sdrhdo_execsql_test skipscan3-2.2 { 63*f3f69ac9Sdrh SELECT d FROM t2 WHERE +a=1 AND c=32; 64*f3f69ac9Sdrh} {x0032} 65*f3f69ac9Sdrhdo_execsql_test skipscan3-2.3eqp { 66*f3f69ac9Sdrh EXPLAIN QUERY PLAN SELECT d FROM t2 WHERE a=1 AND c=32; 67*f3f69ac9Sdrh} {/*ANY(a) AND ANY(b)*/} 68*f3f69ac9Sdrhdo_execsql_test skipscan3-2.3 { 69*f3f69ac9Sdrh SELECT d FROM t2 WHERE a=1 AND c=32; 70*f3f69ac9Sdrh} {x0032} 71*f3f69ac9Sdrh 72*f3f69ac9Sdrh 73*f3f69ac9Sdrhfinish_test 74