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

When a query is inside an AS MATERIALIZED CTE, do not attempt the

omit-ORDER-BY optimization.  If the developer specifies MATERIALIZED,
that means he wants the sort to actually happen.

FossilOrigin-Name: aa769ee7477171f26a091cadff98aa4f48da7752ade20b405a95c4525456f62e
This commit is contained in:
drh
2023-08-02 00:09:15 +00:00
parent cbaef88980
commit 4178849736
3 changed files with 12 additions and 7 deletions

View File

@@ -7314,12 +7314,14 @@ int sqlite3Select(
** (a) The outer query has a different ORDER BY clause
** (b) The subquery is part of a join
** See forum post 062d576715d277c8
** (6) The subquery is really a MATERIALIZED CTE
*/
if( pSub->pOrderBy!=0
&& (p->pOrderBy!=0 || pTabList->nSrc>1) /* Condition (5) */
&& pSub->pLimit==0 /* Condition (1) */
&& (pSub->selFlags & SF_OrderByReqd)==0 /* Condition (2) */
&& (p->selFlags & SF_OrderByReqd)==0 /* Condition (3) and (4) */
&& (pItem->fg.isCte==0 || pItem->u2.pCteUse->eM10d!=M10d_Yes) /* (6) */
&& OptimizationEnabled(db, SQLITE_OmitOrderBy)
){
TREETRACE(0x800,pParse,p,