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

Honor the MATERIALIZED keyword on a common table expression by not flattening

the CTE into an outer query.

FossilOrigin-Name: 8d631a6b9eb06b54b10eda595a4c588ca38f909b4afa653b24d1f720b55d72f7
This commit is contained in:
drh
2022-04-22 16:15:48 +00:00
parent 9b843f0ce0
commit 67f70bea06
7 changed files with 94 additions and 17 deletions

View File

@@ -4153,6 +4153,8 @@ static void renumberCursors(
** (27) The subquery may not contain a FULL or RIGHT JOIN unless it
** is the first element of the parent query.
**
** (28) The subquery is not a MATERIALIZED CTE.
**
**
** 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
@@ -4276,6 +4278,9 @@ static int flattenSubquery(
if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
return 0; /* Restriction (27) */
}
if( pSubitem->fg.isCte && pSubitem->u2.pCteUse->eM10d==M10d_Yes ){
return 0; /* (28) */
}
/* 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