diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/select.c | 9 | ||||
-rw-r--r-- | src/where.c | 42 |
2 files changed, 28 insertions, 23 deletions
diff --git a/src/select.c b/src/select.c index 482d7283c..41e42b680 100644 --- a/src/select.c +++ b/src/select.c @@ -4292,7 +4292,8 @@ static int compoundHasDifferentAffinities(Select *p){ ** (27b) the subquery is a compound query and the RIGHT JOIN occurs ** in any arm of the compound query. (See also (17g).) ** -** (28) The subquery is not a MATERIALIZED CTE. +** (28) The subquery is not a MATERIALIZED CTE. (This is handled +** in the caller before ever reaching this routine.) ** ** ** In this routine, the "p" parameter is a pointer to the outer query. @@ -4402,9 +4403,9 @@ static int flattenSubquery( if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){ return 0; /* Restriction (27a) */ } - if( pSubitem->fg.isCte && pSubitem->u2.pCteUse->eM10d==M10d_Yes ){ - return 0; /* (28) */ - } + + /* Condition (28) is blocked by the caller */ + assert( !pSubitem->fg.isCte || pSubitem->u2.pCteUse->eM10d!=M10d_Yes ); /* 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 diff --git a/src/where.c b/src/where.c index 9992b2053..213df4223 100644 --- a/src/where.c +++ b/src/where.c @@ -5759,6 +5759,28 @@ static SQLITE_NOINLINE void whereAddIndexedExpr( } /* +** Set the reverse-scan order mask to one for all tables in the query +** with the exception of MATERIALIZED common table expressions that have +** their own internal ORDER BY clauses. +** +** This implements the PRAGMA reverse_unordered_selects=ON setting. +** (Also SQLITE_DBCONFIG_REVERSE_SCANORDER). +*/ +static SQLITE_NOINLINE void whereReverseScanOrder(WhereInfo *pWInfo){ + int ii; + for(ii=0; ii<pWInfo->pTabList->nSrc; ii++){ + SrcItem *pItem = &pWInfo->pTabList->a[ii]; + if( !pItem->fg.isCte + || pItem->u2.pCteUse->eM10d!=M10d_Yes + || NEVER(pItem->pSelect==0) + || pItem->pSelect->pOrderBy==0 + ){ + pWInfo->revMask |= MASKBIT(ii); + } + } +} + +/* ** Generate the beginning of the loop used for WHERE clause processing. ** The return value is a pointer to an opaque structure that contains ** information needed to terminate the loop. Later, the calling routine @@ -6124,25 +6146,7 @@ WhereInfo *sqlite3WhereBegin( } assert( pWInfo->pTabList!=0 ); if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){ - for(ii=0; ii<pWInfo->pTabList->nSrc; ii++){ - /* The PRAGMA reverse_unordered_selects=ON setting (also accessible - ** using SQLITE_DBCONFIG_REVERSE_SCANORDER) means to reverse the scan - ** order for any table that is part of a query that does not have an - ** ORDER BY clause. - ** - ** Except, do not reverse the output from MATERIALIZED common table - ** expression that has an internal ORDER BY clause, because a - ** MATERIALIZED common table expression is an optimization fence. - */ - SrcItem *pItem = &pWInfo->pTabList->a[ii]; - if( !pItem->fg.isCte - || pItem->u2.pCteUse->eM10d!=M10d_Yes - || NEVER(pItem->pSelect==0) - || pItem->pSelect->pOrderBy==0 - ){ - pWInfo->revMask |= MASKBIT(ii); - } - } + whereReverseScanOrder(pWInfo); } if( pParse->nErr ){ goto whereBeginError; |