Allow an automatic index on a WHERE constraint where the RHS is does not

reference another table as long as the RHS is not a constant.

FossilOrigin-Name: 58acc2a8b38c5f13175c191697b4d2b663db1872
This commit is contained in:
drh 2014-06-17 09:00:54 +00:00
parent 9978e6a680
commit 6b7ff748a1
5 changed files with 27 additions and 16 deletions

View File

@ -92,12 +92,18 @@ do_eqp_test rtree6.2.3 {
0 1 1 {SEARCH TABLE t2 USING INTEGER PRIMARY KEY (rowid=?)}
}
do_eqp_test rtree6.2.4 {
SELECT * FROM t1,t2 WHERE v=10 and x1<10 and x2>10
do_eqp_test rtree6.2.4.1 {
SELECT * FROM t1,t2 WHERE v=+ii and x1<10 and x2>10
} {
0 0 0 {SCAN TABLE t1 VIRTUAL TABLE INDEX 2:C0E1}
0 1 1 {SEARCH TABLE t2 USING AUTOMATIC COVERING INDEX (v=?)}
}
do_eqp_test rtree6.2.4.2 {
SELECT * FROM t1,t2 WHERE v=10 and x1<10 and x2>10
} {
0 0 0 {SCAN TABLE t1 VIRTUAL TABLE INDEX 2:C0E1}
0 1 1 {SCAN TABLE t2}
}
do_eqp_test rtree6.2.5 {
SELECT * FROM t1,t2 WHERE k=ii AND x1<v

View File

@ -1,5 +1,5 @@
C Do\snot\sattempt\sto\screate\san\sautomatic\sindex\son\sa\sconstant\sconstraint,\sas\ndoing\sso\sis\spointless.
D 2014-06-17T02:46:55.317
C Allow\san\sautomatic\sindex\son\sa\sWHERE\sconstraint\swhere\sthe\sRHS\sis\sdoes\snot\nreference\sanother\stable\sas\slong\sas\sthe\sRHS\sis\snot\sa\sconstant.
D 2014-06-17T09:00:54.229
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in ed5e4aae4799f724699d5509fac2977786414dbb
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -129,7 +129,7 @@ F ext/rtree/rtree2.test acbb3a4ce0f4fbc2c304d2b4b784cfa161856bba
F ext/rtree/rtree3.test a494da55c30ee0bc9b01a91c80c81b387b22d2dc
F ext/rtree/rtree4.test c8fe384f60ebd49540a5fecc990041bf452eb6e0
F ext/rtree/rtree5.test 6a510494f12454bf57ef28f45bc7764ea279431e
F ext/rtree/rtree6.test 756585abc51727fec97c77852476445c10c0ee95
F ext/rtree/rtree6.test 83a997caf27eeca990291f66277e5a136428479a
F ext/rtree/rtree7.test 1fa710b9e6bf997a0c1a537b81be7bb6fded1971
F ext/rtree/rtree8.test db79c812f9e4a11f9b1f3f9934007884610a713a
F ext/rtree/rtree9.test d86ebf08ff6328895613ed577dd8a2a37c472c34
@ -296,7 +296,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd
F src/wal.c 264df50a1b33124130b23180ded2e2c5663c652a
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45
F src/where.c 46e94a513fa783a950889e924b253339e498d600
F src/where.c d6a284abd9a1b4c1e617e5208e695cd6f0616ae1
F src/whereInt.h 929c1349b5355fd44f22cee5c14d72b3329c58a6
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
@ -1009,7 +1009,7 @@ F test/tkt3992.test f3e7d548ac26f763b47bc0f750da3d03c81071da
F test/tkt3997.test a335fa41ca3985660a139df7b734a26ef53284bd
F test/tkt4018.test 7c2c9ba4df489c676a0a7a0e809a1fb9b2185bd1
F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7
F test/tpch01.test 8f4ac52f62f3e9f6bce0889105aecdf0275e331b
F test/tpch01.test 04adbf8d8300fa60a222f28d901abd76e7be6dd4
F test/trace.test 4b36a41a3e9c7842151af6da5998f5080cdad9e5
F test/trace2.test 93b47ca6996c66b47f57224cfb146f34e07df382
F test/trans.test 6e1b4c6a42dba31bd65f8fa5e61a2708e08ddde6
@ -1177,10 +1177,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P fc918f7d332b8f7cabc79a0f1586bd6760d14d40
R c05b0f400c5eb501cd2d5ddbdc6430c7
T *branch * autoindex-improvements
T *sym-autoindex-improvements *
T -sym-trunk *
P d6883e960f61365729f279a3c1f2c050beb49a55
R e7b366f668336ead2394408b5846caa4
U drh
Z 93418c6f90150cfc0b0ae16a3328fb2a
Z ded0b7f99669cd2fc0f45c3d542cb907

View File

@ -1 +1 @@
d6883e960f61365729f279a3c1f2c050beb49a55
58acc2a8b38c5f13175c191697b4d2b663db1872

View File

@ -4529,7 +4529,10 @@ static int whereLoopAddBtree(
WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
if( pTerm->prereqRight & pNew->maskSelf ) continue;
if( pTerm->prereqRight==0 ) continue;
if( pTerm->prereqRight==0
&& sqlite3ExprIsConstant(pTerm->pExpr->pRight) ){
continue;
}
if( termCanDriveIndex(pTerm, pSrc, 0) ){
pNew->u.btree.nEq = 1;
pNew->u.btree.nSkip = 0;

View File

@ -168,7 +168,10 @@ do_test tpch01-1.1 {
} {/0 0 0 {SEARCH TABLE part USING INDEX bootleg_pti .P_TYPE=..} 0 1 2 {SEARCH TABLE lineitem USING INDEX lpki2 .L_PARTKEY=..}.*/}
do_test tpch01-1.1b {
set ::eqpres
} {/.* customer .* nation AS n1 .* nation AS n2 .*/}
} {/.* customer .* nation AS n1 .*/}
do_test tpch01-1.1c {
set ::eqpres
} {/.* supplier .* nation AS n2 .*/}
do_eqp_test tpch01-1.2 {
select
@ -185,3 +188,5 @@ group by
order by
revenue desc;
} {0 0 1 {SEARCH TABLE orders USING INDEX odi (O_ORDERDATE>? AND O_ORDERDATE<?)} 0 1 0 {SEARCH TABLE customer USING INDEX cpki (C_CUSTKEY=?)} 0 2 3 {SEARCH TABLE nation USING INDEX npki (N_NATIONKEY=?)} 0 3 2 {SEARCH TABLE lineitem USING INDEX lpki (L_ORDERKEY=?)} 0 0 0 {USE TEMP B-TREE FOR GROUP BY} 0 0 0 {USE TEMP B-TREE FOR ORDER BY}}
finish_test