From: drh Date: Thu, 7 Apr 2016 23:18:44 +0000 (+0000) Subject: Enhance the query planner so that IS and IS NULL operators are able to drive X-Git-Tag: version-3.12.1~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=32291526a2700b3ae89ff43c25365d5e43bf2729;p=thirdparty%2Fsqlite.git Enhance the query planner so that IS and IS NULL operators are able to drive an index on a LEFT OUTER JOIN. FossilOrigin-Name: 84d2a09eab28b65ab7015e89c2057851c7894842 --- diff --git a/manifest b/manifest index d150efacf1..dbc8d05fdd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sthe\sversion\snumber\sto\s3.12.1.\s\sThis\sis\sthe\sfirst\srelease\scandidate. -D 2016-04-07T21:29:56.281 +C Enhance\sthe\squery\splanner\sso\sthat\sIS\sand\sIS\sNULL\soperators\sare\sable\sto\sdrive\nan\sindex\son\sa\sLEFT\sOUTER\sJOIN. +D 2016-04-07T23:18:44.800 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc b00bcf0ec7001857aea81ee39fae45d20f5f4e59 @@ -433,7 +433,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 10deb6b43887662691e5f53d10b3c171c401169b F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 -F src/where.c fe7925faafbe9a458972035c0bb4753d672f04ed +F src/where.c 99cc6270fc3915201e2a90bbac3768f007a89c44 F src/whereInt.h 93297d56edd137b7ea004490690fb6e2ce028a34 F src/wherecode.c 863aedf086131743763c1960637fde904eadc442 F src/whereexpr.c fb87944b1254234e5bba671aaf6dee476241506a @@ -1459,7 +1459,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3360ab098a374d2eea433ca2a8278ca866957326 -R bdce6efd0bd6b8391dd3f11f99281b9e +P 300f1b61a0a1e486bdd63ab14b8a06574d4b3fc9 +Q +c648539b52ca28c0b2cb61208e2c32b1d29626a1 +R 53ca277f27cb21538c9d98930a79d380 U drh -Z 903e5b0a3bbef42c4103adda07b920c0 +Z 0e0ae1cbd0507466230e7807074e834c diff --git a/manifest.uuid b/manifest.uuid index 273ed69bc5..7b24e92699 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -300f1b61a0a1e486bdd63ab14b8a06574d4b3fc9 \ No newline at end of file +84d2a09eab28b65ab7015e89c2057851c7894842 \ No newline at end of file diff --git a/src/where.c b/src/where.c index cf23aa62a4..4f7ee66ff7 100644 --- a/src/where.c +++ b/src/where.c @@ -2201,8 +2201,6 @@ static int whereLoopAddBtreeIndex( assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 ); if( pNew->wsFlags & WHERE_BTM_LIMIT ){ opMask = WO_LT|WO_LE; - }else if( /*pProbe->tnum<=0 ||*/ (pSrc->fg.jointype & JT_LEFT)!=0 ){ - opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE; }else{ opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE|WO_ISNULL|WO_IS; } @@ -2240,6 +2238,18 @@ static int whereLoopAddBtreeIndex( ** to mix with a lower range bound from some other source */ if( pTerm->wtFlags & TERM_LIKEOPT && pTerm->eOperator==WO_LT ) continue; + /* Do not allow IS constraints from the WHERE clause to be used by the + ** right table of a LEFT JOIN. Only constraints in the ON clause are + ** allowed */ + if( (pSrc->fg.jointype & JT_LEFT)!=0 + && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) + && (eOp & (WO_IS|WO_ISNULL))!=0 + ){ + testcase( eOp & WO_IS ); + testcase( eOp & WO_ISNULL ); + continue; + } + pNew->wsFlags = saved_wsFlags; pNew->u.btree.nEq = saved_nEq; pNew->nLTerm = saved_nLTerm;