diff options
author | drh <> | 2022-06-06 23:22:06 +0000 |
---|---|---|
committer | drh <> | 2022-06-06 23:22:06 +0000 |
commit | 6fdac751277981a8fa4db8eda339b9c140140bd7 (patch) | |
tree | 63d646e57eeddf30693f1da49c774cfc6e6cd49a /src | |
parent | c18fc6134ef811cffbcd2a308ef6570b8d22fc55 (diff) | |
parent | 16828c8c127b8b2db9d5be77fe7b8447cda831b4 (diff) | |
download | sqlite-6fdac751277981a8fa4db8eda339b9c140140bd7.tar.gz sqlite-6fdac751277981a8fa4db8eda339b9c140140bd7.zip |
More precise determination of when a WHERE clause can be used to drive an
index on an outer join.
FossilOrigin-Name: 318543a91108c6fd0764d7ee7beee49838f54d44c54dae3dc9d4cb8336d52fe1
Diffstat (limited to 'src')
-rw-r--r-- | src/where.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/where.c b/src/where.c index b77fa78e0..58aec128e 100644 --- a/src/where.c +++ b/src/where.c @@ -1180,10 +1180,17 @@ static sqlite3_index_info *allocateIndexInfo( ** right-hand table of a LEFT JOIN nor to the either table of a ** RIGHT JOIN. See tag-20191211-001 for the ** equivalent restriction for ordinary tables. */ - if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0 - && !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON) - ){ - continue; + if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0 ){ + testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LEFT ); + testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_RIGHT ); + testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LTORJ ); + testcase( ExprHasProperty(pTerm->pExpr, EP_OuterON) ); + testcase( ExprHasProperty(pTerm->pExpr, EP_InnerON) ); + if( !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON) + || pTerm->pExpr->w.iJoin != pSrc->iCursor + ){ + continue; + } } nTerm++; pTerm->wtFlags |= TERM_OK; @@ -2841,10 +2848,17 @@ static int whereLoopAddBtreeIndex( ** the right table of a RIGHT JOIN because the constraint implies a ** not-NULL condition on the left table of the RIGHT JOIN. */ - if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0 - && !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON) - ){ - continue; + if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0 ){ + testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LEFT ); + testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_RIGHT ); + testcase( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))==JT_LTORJ ); + testcase( ExprHasProperty(pTerm->pExpr, EP_OuterON) ) + testcase( ExprHasProperty(pTerm->pExpr, EP_InnerON) ); + if( !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON) + || pTerm->pExpr->w.iJoin != pSrc->iCursor + ){ + continue; + } } if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){ |