mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-11 01:42:22 +03:00
Add restriction (29) to the query flattener - do not allow flattening that
would leave both EP_InnerON and EP_OuterON constraints on the same join term. FossilOrigin-Name: c585d6a4678b04f4cedc08852d01c44cdf52ae2c8ccd1174c3d5a395088bf528
This commit is contained in:
20
src/select.c
20
src/select.c
@@ -610,6 +610,7 @@ static int sqlite3ProcessJoin(Parse *pParse, Select *p){
|
||||
sqlite3SetJoinExpr(pRight->u3.pOn, pRight->iCursor, joinType);
|
||||
p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->u3.pOn);
|
||||
pRight->u3.pOn = 0;
|
||||
pRight->fg.isOn = 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -4169,6 +4170,11 @@ static void renumberCursors(
|
||||
**
|
||||
** (28) The subquery is not a MATERIALIZED CTE.
|
||||
**
|
||||
** (29) Either the subquery is not the right-hand operand of a join with an
|
||||
** ON or USING clause nor the right-hand operand of a NATURAL JOIN, or
|
||||
** the right-most table within the FROM clause of the subquery
|
||||
** is not part of an outer join.
|
||||
**
|
||||
**
|
||||
** In this routine, the "p" parameter is a pointer to the outer query.
|
||||
** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
|
||||
@@ -4296,6 +4302,20 @@ static int flattenSubquery(
|
||||
return 0; /* (28) */
|
||||
}
|
||||
|
||||
if( pSubSrc->nSrc>=2
|
||||
&& (pSubSrc->a[pSubSrc->nSrc-1].fg.jointype & JT_OUTER)!=0
|
||||
){
|
||||
/* Reach here if the right-most term in the FROM clause of the subquery
|
||||
** is an outer join - the second half of (29) */
|
||||
if( pSubitem->fg.jointype & JT_NATURAL
|
||||
|| pSubitem->fg.isUsing
|
||||
|| pSubitem->u3.pOn!=0
|
||||
|| pSubitem->fg.isOn
|
||||
){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Restriction (17): If the sub-query is a compound SELECT, then it must
|
||||
** use only the UNION ALL operator. And none of the simple select queries
|
||||
** that make up the compound SELECT are allowed to be aggregate or distinct
|
||||
|
||||
Reference in New Issue
Block a user