From: dan Date: Tue, 24 Feb 2015 20:10:49 +0000 (+0000) Subject: Prevent partial indexes on the table on the left hand side of a LEFT JOIN from being... X-Git-Tag: version-3.8.9~118 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2a45cb5c0ecfba41c673fc8184337543ea8d475f;p=thirdparty%2Fsqlite.git Prevent partial indexes on the table on the left hand side of a LEFT JOIN from being incorrectly qualified by a constraint in the ON clause of the join. This relaxes the rule introduced by the previous commit (as the partial indexes on the table on the rhs of the LEFT JOIN may now be qualified by terms within the ON clause). FossilOrigin-Name: 1d6fb43a576d335d2717e94d28385178c23c81a1 --- diff --git a/manifest b/manifest index 1f4acd3fec..c6a94d0d59 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\spartial\sindexes\sare\snot\squalified\sincorrectly\sby\sa\sconstraint\sthat\nis\sinside\sthe\sON\sclause\sof\sa\sLEFT\sJOIN.\s\sFix\sfor\sticket\s[2326c258d02ead33]. -D 2015-02-24T20:04:59.149 +C Prevent\spartial\sindexes\son\sthe\stable\son\sthe\sleft\shand\sside\sof\sa\sLEFT\sJOIN\sfrom\sbeing\sincorrectly\squalified\sby\sa\sconstraint\sin\sthe\sON\sclause\sof\sthe\sjoin.\sThis\srelaxes\sthe\srule\sintroduced\sby\sthe\sprevious\scommit\s(as\sthe\spartial\sindexes\son\sthe\stable\son\sthe\srhs\sof\sthe\sLEFT\sJOIN\smay\snow\sbe\squalified\sby\sterms\swithin\sthe\sON\sclause). +D 2015-02-24T20:10:49.082 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -306,7 +306,7 @@ F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01 F src/wal.c 39303f2c9db02a4e422cd8eb2c8760420c6a51fe F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c 88509f19a64a36e1c22a1dbdac74ee1a62d99dc3 +F src/where.c 294423cf9a3c46377c3e246338ff2a38365ad922 F src/whereInt.h d3633e9b592103241b74b0ec76185f3e5b8b62e0 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -652,7 +652,7 @@ F test/index2.test ee83c6b5e3173a3d7137140d945d9a5d4fdfb9d6 F test/index3.test 55a90cff99834305e8141df7afaef39674b57062 F test/index4.test ab92e736d5946840236cd61ac3191f91a7856bf6 F test/index5.test 25b0b451aceed4ac5f7d49f856f6de7257470b3e -F test/index6.test c56852451b574ad5b2a1789e566e62e6ab244f42 +F test/index6.test 3ae54e53c53f2adcacda269237d8e52bdb05a481 F test/index7.test 917cf1e1c7439bb155abbeabec511b28945e157b F test/indexedby.test b2f22f3e693a53813aa3f50b812eb609ba6df1ec F test/indexfault.test 31d4ab9a7d2f6e9616933eb079722362a883eb1d @@ -1239,8 +1239,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 f8917ba4d917bc762b3b252466ab72a8a70dc0d8 c6399958a17e8b7c1798a9240fb06bffc774b332 -R 65a9e61b66b400145ad4b4adbab491c4 -T +closed c6399958a17e8b7c1798a9240fb06bffc774b332 -U drh -Z 128fd4816e28956dbfeb54d3b3932fdf +P 491cfe9b3f87f5fcc579f953745012cea8d64db7 +R ca86a79194d1da36938ef90c0f8f3a89 +U dan +Z 37d3633be74b06dd46fb3d2721885844 diff --git a/manifest.uuid b/manifest.uuid index af369a2ac7..cd9fd72c3a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -491cfe9b3f87f5fcc579f953745012cea8d64db7 \ No newline at end of file +1d6fb43a576d335d2717e94d28385178c23c81a1 \ No newline at end of file diff --git a/src/where.c b/src/where.c index f45da74794..f40b051a56 100644 --- a/src/where.c +++ b/src/where.c @@ -1614,7 +1614,8 @@ static void constructAutomaticIndex( for(pTerm=pWC->a; pTermprereq==0 && (pTerm->wtFlags & TERM_VIRTUAL)==0 - && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) + && (!ExprHasProperty(pTerm->pExpr, EP_FromJoin) + || pTerm->pExpr->iRightJoinTable==pSrc->iCursor) && sqlite3ExprIsTableConstant(pTerm->pExpr, pSrc->iCursor) ){ pPartial = sqlite3ExprAnd(pParse->db, pPartial, sqlite3ExprDup(pParse->db, pTerm->pExpr, 0)); @@ -4695,8 +4696,9 @@ static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){ int i; WhereTerm *pTerm; for(i=0, pTerm=pWC->a; inTerm; i++, pTerm++){ - if( sqlite3ExprImpliesExpr(pTerm->pExpr, pWhere, iTab) - && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) + Expr *pExpr = pTerm->pExpr; + if( sqlite3ExprImpliesExpr(pExpr, pWhere, iTab) + && (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab) ){ return 1; } diff --git a/test/index6.test b/test/index6.test index 8414b11baa..69fae49feb 100644 --- a/test/index6.test +++ b/test/index6.test @@ -296,4 +296,35 @@ do_execsql_test index6-7.4 { SELECT * FROM t7a JOIN t7b ON (x=99) ORDER BY x; } {/USING COVERING INDEX t7ax/} + +do_execsql_test index6-8.0 { + CREATE TABLE t8a(a,b); + CREATE TABLE t8b(x,y); + CREATE INDEX i8c ON t8b(y) WHERE x = 'value'; + + INSERT INTO t8a VALUES(1, 'one'); + INSERT INTO t8a VALUES(2, 'two'); + INSERT INTO t8a VALUES(3, 'three'); + + INSERT INTO t8b VALUES('value', 1); + INSERT INTO t8b VALUES('dummy', 2); + INSERT INTO t8b VALUES('value', 3); + INSERT INTO t8b VALUES('dummy', 4); +} {} + +do_eqp_test index6-8.1 { + SELECT * FROM t8a LEFT JOIN t8b ON (x = 'value' AND y = a) +} { + 0 0 0 {SCAN TABLE t8a} + 0 1 1 {SEARCH TABLE t8b USING INDEX i8c (y=?)} +} + +do_execsql_test index6-8.2 { + SELECT * FROM t8a LEFT JOIN t8b ON (x = 'value' AND y = a) +} { + 1 one value 1 + 2 two {} {} + 3 three value 3 +} + finish_test