mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
Do not allow query flattening nor the push-down optimization on the
right operand of a RIGHT JOIN. FossilOrigin-Name: 5aa0c9ea9cf53c13bf266278b479b2e7af3aa5c6b144bd49ff155a4eb3c23c96
This commit is contained in:
16
src/select.c
16
src/select.c
@@ -3975,6 +3975,7 @@ static void renumberCursors(
|
||||
** table and
|
||||
** (3c) the outer query may not be an aggregate.
|
||||
** (3d) the outer query may not be DISTINCT.
|
||||
** See also (26) for restrictions on RIGHT JOIN.
|
||||
**
|
||||
** (4) The subquery can not be DISTINCT.
|
||||
**
|
||||
@@ -4073,6 +4074,9 @@ static void renumberCursors(
|
||||
** function in the select list or ORDER BY clause, flattening
|
||||
** is not attempted.
|
||||
**
|
||||
** (26) The subquery may not be the right operand of a RIGHT JOIN.
|
||||
** See also (3) for restrictions on LEFT 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
|
||||
@@ -4172,14 +4176,15 @@ static int flattenSubquery(
|
||||
** See also tickets #306, #350, and #3300.
|
||||
*/
|
||||
if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
|
||||
isLeftJoin = 1;
|
||||
if( pSubSrc->nSrc>1 /* (3a) */
|
||||
|| isAgg /* (3b) */
|
||||
|| IsVirtual(pSubSrc->a[0].pTab) /* (3c) */
|
||||
|| (p->selFlags & SF_Distinct)!=0 /* (3d) */
|
||||
if( pSubSrc->nSrc>1 /* (3a) */
|
||||
|| isAgg /* (3b) */
|
||||
|| IsVirtual(pSubSrc->a[0].pTab) /* (3c) */
|
||||
|| (p->selFlags & SF_Distinct)!=0 /* (3d) */
|
||||
|| (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
|
||||
){
|
||||
return 0;
|
||||
}
|
||||
isLeftJoin = 1;
|
||||
}
|
||||
#ifdef SQLITE_EXTRA_IFNULLROW
|
||||
else if( iFrom>0 && !isAgg ){
|
||||
@@ -6707,6 +6712,7 @@ int sqlite3Select(
|
||||
if( OptimizationEnabled(db, SQLITE_PushDown)
|
||||
&& (pItem->fg.isCte==0
|
||||
|| (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2))
|
||||
&& (pItem->fg.jointype & JT_RIGHT)==0
|
||||
&& pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor,
|
||||
(pItem->fg.jointype & JT_OUTER)!=0)
|
||||
){
|
||||
|
||||
Reference in New Issue
Block a user