aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2021-03-19 13:53:34 +0000
committerdrh <>2021-03-19 13:53:34 +0000
commitd685dd6be6c3a2ff8ef6836db22632aa0e4ac99b (patch)
tree0bba9707f2764b159f6434d49012e9dd2de6745b /src
parent080fe6dec98fe0aca355e6d6a30092fe9b989a50 (diff)
downloadsqlite-d685dd6be6c3a2ff8ef6836db22632aa0e4ac99b.tar.gz
sqlite-d685dd6be6c3a2ff8ef6836db22632aa0e4ac99b.zip
Correlated CTEs should not generate a materialization subroutine. If they
need to be materialized, each use case must be materialized separately. dbsqlfuzz 01b8355086998f0a452cb31208e80b9d29ca739a. FossilOrigin-Name: d72d865d3e8503a545603038eb26044bee42e4e8725522be678059ce6517fc8d
Diffstat (limited to 'src')
-rw-r--r--src/select.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/select.c b/src/select.c
index 0c0bd84f2..e2fa051e5 100644
--- a/src/select.c
+++ b/src/select.c
@@ -6386,7 +6386,9 @@ int sqlite3Select(
sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pPrior->iCursor);
pSub->nSelectRow = pPrior->pSelect->nSelectRow;
}else{
- /* Generate a subroutine that will materialize the view. */
+ /* Materalize the view. If the view is not correlated, generate a
+ ** subroutine to do the materialization so that subsequent uses of
+ ** the same view can reuse the materialization. */
int topAddr;
int onceAddr = 0;
int retAddr;
@@ -6413,7 +6415,7 @@ int sqlite3Select(
VdbeComment((v, "end %s", pItem->pTab->zName));
sqlite3VdbeChangeP1(v, topAddr, retAddr);
sqlite3ClearTempRegCache(pParse);
- if( pItem->fg.isCte ){
+ if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){
CteUse *pCteUse = pItem->u2.pCteUse;
pCteUse->addrM9e = pItem->addrFillSub;
pCteUse->regRtn = pItem->regReturn;