aboutsummaryrefslogtreecommitdiff
path: root/src/select.c
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2023-02-06 22:25:18 +0000
committerstephan <stephan@noemail.net>2023-02-06 22:25:18 +0000
commitf8c73aed6716f911d8a19511586751e5b9aa1e9f (patch)
tree8d35e728901da3454cbff9c600fd0bc1602b2ce8 /src/select.c
parent87ce1ff7f72621cb8a8a99dc93141d253899eba0 (diff)
parent9f29998d2a8890d58b52d13605324193703525c3 (diff)
downloadsqlite-f8c73aed6716f911d8a19511586751e5b9aa1e9f.tar.gz
sqlite-f8c73aed6716f911d8a19511586751e5b9aa1e9f.zip
Merge trunk into wasi-patches branch.
FossilOrigin-Name: 656d36f50f630da68262469087bad1ac71b10325e233a7963103c8cbc232f61a
Diffstat (limited to 'src/select.c')
-rw-r--r--src/select.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/select.c b/src/select.c
index d27bed026..b0e303066 100644
--- a/src/select.c
+++ b/src/select.c
@@ -5626,9 +5626,6 @@ static int resolveFromTermToCte(
pFrom->fg.isCte = 1;
pFrom->u2.pCteUse = pCteUse;
pCteUse->nUse++;
- if( pCteUse->nUse>=2 && pCteUse->eM10d==M10d_Any ){
- pCteUse->eM10d = M10d_Yes;
- }
/* Check if this is a recursive CTE. */
pRecTerm = pSel = pFrom->pSelect;
@@ -6911,8 +6908,10 @@ static int sameSrcAlias(SrcItem *p0, SrcList *pSrc){
** being used as the outer loop if the sqlite3WhereBegin()
** routine nominates it to that position.
** (iii) The query is not a UPDATE ... FROM
-** (2) The subquery is not a CTE that should be materialized because of
-** the AS MATERIALIZED keywords
+** (2) The subquery is not a CTE that should be materialized because
+** (a) the AS MATERIALIZED keyword is used, or
+** (b) the CTE is used multiple times and does not have the
+** NOT MATERIALIZED keyword
** (3) The subquery is not part of a left operand for a RIGHT JOIN
** (4) The SQLITE_Coroutine optimization disable flag is not set
** (5) The subquery is not self-joined
@@ -6924,9 +6923,13 @@ static int fromClauseTermCanBeCoroutine(
int selFlags /* Flags on the SELECT statement */
){
SrcItem *pItem = &pTabList->a[i];
- if( pItem->fg.isCte && pItem->u2.pCteUse->eM10d==M10d_Yes ) return 0;/* (2) */
- if( pTabList->a[0].fg.jointype & JT_LTORJ ) return 0; /* (3) */
- if( OptimizationDisabled(pParse->db, SQLITE_Coroutines) ) return 0; /* (4) */
+ if( pItem->fg.isCte ){
+ const CteUse *pCteUse = pItem->u2.pCteUse;
+ if( pCteUse->eM10d==M10d_Yes ) return 0; /* (2a) */
+ if( pCteUse->nUse>=2 && pCteUse->eM10d!=M10d_No ) return 0; /* (2b) */
+ }
+ if( pTabList->a[0].fg.jointype & JT_LTORJ ) return 0; /* (3) */
+ if( OptimizationDisabled(pParse->db, SQLITE_Coroutines) ) return 0; /* (4) */
if( isSelfJoinView(pTabList, pItem, i+1, pTabList->nSrc)!=0 ){
return 0; /* (5) */
}