diff options
author | drh <> | 2022-06-06 22:33:44 +0000 |
---|---|---|
committer | drh <> | 2022-06-06 22:33:44 +0000 |
commit | 16828c8c127b8b2db9d5be77fe7b8447cda831b4 (patch) | |
tree | 66dae1705ab1cf82bc019f267034aadc6b05066d /src | |
parent | 93c4087ffe454412caf21ca1dea7ab63f057d0ff (diff) | |
download | sqlite-16828c8c127b8b2db9d5be77fe7b8447cda831b4.tar.gz sqlite-16828c8c127b8b2db9d5be77fe7b8447cda831b4.zip |
More precise determination of when a WHERE/ON clause term can be used as an
indexed join constraint. Testcase macros added to ensure test coverage.
FossilOrigin-Name: f419e98c515e704efa11728192b2594e962cb0e6d2d1837f99a8caf65f4d93cb
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 ){ |