1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-11 01:42:22 +03:00

The fix at [cab9b4cccd13bf0a] was incomplete, as demonstrated by

[forum:/forumpost/57bdf2217d|forum post 57bdf2217d].  This check-in
should complete the fix.

FossilOrigin-Name: fb0a23b6789da8e934562ce9ebd9d58ea13a10fd10dee5cbfc7ac8f394e1aeec
This commit is contained in:
drh
2022-06-20 12:42:28 +00:00
parent 1d49768151
commit ae8776e092
5 changed files with 55 additions and 11 deletions

View File

@@ -4666,6 +4666,8 @@ struct WhereConst {
int nConst; /* Number for COLUMN=CONSTANT terms */
int nChng; /* Number of times a constant is propagated */
int bHasAffBlob; /* At least one column in apExpr[] as affinity BLOB */
u32 mExcludeOn; /* Which ON expressions to exclude from considertion.
** Either EP_OuterON or EP_InnerON|EP_OuterON */
Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */
};
@@ -4728,7 +4730,7 @@ static void constInsert(
static void findConstInWhere(WhereConst *pConst, Expr *pExpr){
Expr *pRight, *pLeft;
if( NEVER(pExpr==0) ) return;
if( ExprHasProperty(pExpr, EP_OuterON|EP_InnerON) ){
if( ExprHasProperty(pExpr, pConst->mExcludeOn) ){
testcase( ExprHasProperty(pExpr, EP_OuterON) );
testcase( ExprHasProperty(pExpr, EP_InnerON) );
return;
@@ -4768,9 +4770,10 @@ static int propagateConstantExprRewriteOne(
int i;
if( pConst->pOomFault[0] ) return WRC_Prune;
if( pExpr->op!=TK_COLUMN ) return WRC_Continue;
if( ExprHasProperty(pExpr, EP_FixedCol|EP_OuterON) ){
if( ExprHasProperty(pExpr, EP_FixedCol|pConst->mExcludeOn) ){
testcase( ExprHasProperty(pExpr, EP_FixedCol) );
testcase( ExprHasProperty(pExpr, EP_OuterON) );
testcase( ExprHasProperty(pExpr, EP_InnerON) );
return WRC_Continue;
}
for(i=0; i<pConst->nConst; i++){
@@ -4894,6 +4897,17 @@ static int propagateConstants(
x.nChng = 0;
x.apExpr = 0;
x.bHasAffBlob = 0;
if( ALWAYS(p->pSrc!=0)
&& p->pSrc->nSrc>0
&& (p->pSrc->a[0].fg.jointype & JT_LTORJ)!=0
){
/* Do not propagate constants on any ON clause if there is a
** RIGHT JOIN anywhere in the query */
x.mExcludeOn = EP_InnerON | EP_OuterON;
}else{
/* Do not propagate constants through the ON clause of a LEFT JOIN */
x.mExcludeOn = EP_OuterON;
}
findConstInWhere(&x, p->pWhere);
if( x.nConst ){
memset(&w, 0, sizeof(w));