diff options
author | drh <> | 2022-05-13 17:45:52 +0000 |
---|---|---|
committer | drh <> | 2022-05-13 17:45:52 +0000 |
commit | 767bc8de8e3859777eab42a32e034ef807759f8a (patch) | |
tree | e9b7cbfa5a396341711345b8f9edb4cc2bef5f81 | |
parent | a6e8ee12e2bbb353ae4548e38083d1855f7b86aa (diff) | |
download | sqlite-767bc8de8e3859777eab42a32e034ef807759f8a.tar.gz sqlite-767bc8de8e3859777eab42a32e034ef807759f8a.zip |
Defer generating WHERE clause constraints for a RIGHT JOIN until after the
ON-clause processing for the RIGHT JOIN has done its own row elimination.
This fixes and incorrect output from some RIGHT JOINs that was identified
by [forum:/forumpost/41cc3851d864c5e6|forum post 41cc3851d864c5e6].
FossilOrigin-Name: 238d9c247cf69cc77fdb1af9d42ebe258610a533ac4204e2ddf8af17f24d18c4
-rw-r--r-- | manifest | 12 | ||||
-rw-r--r-- | manifest.uuid | 2 | ||||
-rw-r--r-- | src/wherecode.c | 38 |
3 files changed, 32 insertions, 20 deletions
@@ -1,5 +1,5 @@ -C Redefine\sthe\sacccess\srules\sfor\sthe\sExpr.w\sunion\sso\sthat\sthe\sExpr.w.iJoin\nmember\sis\saccessible\son\seither\sEP_OuterON\sor\sEP_InnerON. -D 2022-05-13T16:38:40.228 +C Defer\sgenerating\sWHERE\sclause\sconstraints\sfor\sa\sRIGHT\sJOIN\suntil\safter\sthe\nON-clause\sprocessing\sfor\sthe\sRIGHT\sJOIN\shas\sdone\sits\sown\srow\selimination.\nThis\sfixes\sand\sincorrect\soutput\sfrom\ssome\sRIGHT\sJOINs\sthat\swas\sidentified\nby\s[forum:/forumpost/41cc3851d864c5e6|forum\spost\s41cc3851d864c5e6]. +D 2022-05-13T17:45:52.976 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -642,7 +642,7 @@ F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b F src/where.c d4d543f06b09ff8bac05072b015a2181f9c48561b1a146158aaaf09e40817567 F src/whereInt.h 8da918f392bf202ccc0ee61291455b33ad171d209445f1ff3eaf62e0b6f6b363 -F src/wherecode.c 51aba5a09657c0400f76453e221aebe2abf488f6ef6345ae89c32468e36a0639 +F src/wherecode.c 4ffa652982b8233b028bed36a4cb6d9293484e75b80f236772ff3c1a91816eca F src/whereexpr.c efed370c684dce04eab949202c5452bbde993efb198de43c7a88f59411ad2a2c F src/window.c fff1b51757438c664e471d5184634e48dcdf8ea34b640f3b1b0810b1e06de18c F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 @@ -1954,8 +1954,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 2f4456f67f64f131fc852ad9a7420eb43b57b879a9bec7e4b295f1dc0d7bfa56 -R 9b69af380ecbac169382f655ff732cd6 +P 6f741d6cfb8831a3ac966257ac4519bcc8156293447bf50323c2d9b170125974 +R bc3436cf9c17c2665a43b91d0b429cda U drh -Z e0160850b64686ab8a3060154919b222 +Z 7f18b62d8d1b8431770b8960ee426eac # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index fa8f72004..b0fc81ce2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6f741d6cfb8831a3ac966257ac4519bcc8156293447bf50323c2d9b170125974
\ No newline at end of file +238d9c247cf69cc77fdb1af9d42ebe258610a533ac4204e2ddf8af17f24d18c4
\ No newline at end of file diff --git a/src/wherecode.c b/src/wherecode.c index 2d7602ae3..e079b944e 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -2620,10 +2620,12 @@ Bitmask sqlite3WhereCodeOneLoopStart( } pE = pTerm->pExpr; assert( pE!=0 ); - if( (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ)) + if( (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT)) && (!ExprHasProperty(pE,EP_OuterON|EP_InnerON) || pE->w.iJoin!=pTabItem->iCursor) ){ + /* Defer processing WHERE clause constraints until after outer + ** join processing. tag-20220513a */ continue; } @@ -2764,18 +2766,8 @@ Bitmask sqlite3WhereCodeOneLoopStart( pLevel->addrFirst = sqlite3VdbeCurrentAddr(v); sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin); VdbeComment((v, "record LEFT JOIN hit")); - for(pTerm=pWC->a, j=0; j<pWC->nBase; j++, pTerm++){ - testcase( pTerm->wtFlags & TERM_VIRTUAL ); - testcase( pTerm->wtFlags & TERM_CODED ); - if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue; - if( (pTerm->prereqAll & pLevel->notReady)!=0 ){ - assert( pWInfo->untestedTerms ); - continue; - } - if( pTabItem->fg.jointype & JT_LTORJ ) continue; - assert( pTerm->pExpr ); - sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL); - pTerm->wtFlags |= TERM_CODED; + if( pLevel->pRJ==0 ){ + goto code_outer_join_constraints; /* WHERE clause constraints */ } } @@ -2791,6 +2783,26 @@ Bitmask sqlite3WhereCodeOneLoopStart( pRJ->addrSubrtn = sqlite3VdbeCurrentAddr(v); assert( pParse->withinRJSubrtn < 255 ); pParse->withinRJSubrtn++; + + /* WHERE clause constraints must be deferred until after outer join + ** row elimination has completed, since WHERE clause constraints apply + ** to the results of the OUTER JOIN. The following loop generates the + ** appropriate WHERE clause constraint checks. tag-20220513a. + */ + code_outer_join_constraints: + for(pTerm=pWC->a, j=0; j<pWC->nBase; j++, pTerm++){ + testcase( pTerm->wtFlags & TERM_VIRTUAL ); + testcase( pTerm->wtFlags & TERM_CODED ); + if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue; + if( (pTerm->prereqAll & pLevel->notReady)!=0 ){ + assert( pWInfo->untestedTerms ); + continue; + } + if( pTabItem->fg.jointype & JT_LTORJ ) continue; + assert( pTerm->pExpr ); + sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL); + pTerm->wtFlags |= TERM_CODED; + } } #if WHERETRACE_ENABLED /* 0x20800 */ |