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:
@@ -1527,6 +1527,7 @@ With *sqlite3WithDup(sqlite3 *db, With *p){
|
||||
pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0);
|
||||
pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0);
|
||||
pRet->a[i].zName = sqlite3DbStrDup(db, p->a[i].zName);
|
||||
pRet->a[i].eM10d = p->a[i].eM10d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -115,6 +115,10 @@ void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){
|
||||
}
|
||||
sqlite3_str_appendf(&x, ")");
|
||||
}
|
||||
if( pCte->eM10d!=M10d_Any ){
|
||||
sqlite3_str_appendf(&x, " %sMATERIALIZED",
|
||||
pCte->eM10d==M10d_No ? "NOT " : "");
|
||||
}
|
||||
if( pCte->pUse ){
|
||||
sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse,
|
||||
pCte->pUse->nUse);
|
||||
|
||||
Reference in New Issue
Block a user