From: Tom Lane Date: Tue, 26 Dec 2006 19:27:26 +0000 (+0000) Subject: Repair bug #2839: the various ExecReScan functions need to reset X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=07d410ee4bec013f09ef1086d19e5ff3f94e0f0d;p=users%2Fbernd%2Fpostgres.git Repair bug #2839: the various ExecReScan functions need to reset ps_TupFromTlist in plan nodes that make use of it. This was being done correctly in join nodes and Result nodes but not in any relation-scan nodes. Bug would lead to bogus results if a set-returning function appeared in the targetlist of a subquery that could be rescanned after partial execution, for example a subquery within EXISTS(). Bug has been around forever :-( ... surprising it wasn't reported before. --- diff --git a/src/backend/executor/nodeFunctionscan.c b/src/backend/executor/nodeFunctionscan.c index 8aa7eb44e2..ff37ecfb6b 100644 --- a/src/backend/executor/nodeFunctionscan.c +++ b/src/backend/executor/nodeFunctionscan.c @@ -361,6 +361,7 @@ ExecFunctionReScan(FunctionScan *node, ExprContext *exprCtxt, Plan *parent) scanstate = (FunctionScanState *) node->scan.scanstate; ExecClearTuple(scanstate->csstate.cstate.cs_ResultTupleSlot); + scanstate->csstate.cstate.cs_TupFromTlist = false; /* * If we haven't materialized yet, just return. diff --git a/src/backend/executor/nodeIndexscan.c b/src/backend/executor/nodeIndexscan.c index c1918d9df6..dfc4188f86 100644 --- a/src/backend/executor/nodeIndexscan.c +++ b/src/backend/executor/nodeIndexscan.c @@ -303,6 +303,8 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent) runtimeKeyInfo = indexstate->iss_RuntimeKeyInfo; numScanKeys = indexstate->iss_NumScanKeys; + node->scan.scanstate->cstate.cs_TupFromTlist = false; + if (econtext) { /* @@ -639,6 +641,8 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent) */ ExecAssignExprContext(estate, &scanstate->cstate); + scanstate->cstate.cs_TupFromTlist = false; + #define INDEXSCAN_NSLOTS 2 /* diff --git a/src/backend/executor/nodeResult.c b/src/backend/executor/nodeResult.c index 1cc11a89f3..d292164904 100644 --- a/src/backend/executor/nodeResult.c +++ b/src/backend/executor/nodeResult.c @@ -202,6 +202,8 @@ ExecInitResult(Result *node, EState *estate, Plan *parent) */ ExecAssignExprContext(estate, &resstate->cstate); + resstate->cstate.cs_TupFromTlist = false; + #define RESULT_NSLOTS 1 /* diff --git a/src/backend/executor/nodeSeqscan.c b/src/backend/executor/nodeSeqscan.c index 0e930bb343..ce34d91f4b 100644 --- a/src/backend/executor/nodeSeqscan.c +++ b/src/backend/executor/nodeSeqscan.c @@ -318,6 +318,8 @@ ExecSeqReScan(SeqScan *node, ExprContext *exprCtxt, Plan *parent) scanstate = node->scanstate; estate = node->plan.state; + scanstate->cstate.cs_TupFromTlist = false; + /* If this is re-scanning of PlanQual ... */ if (estate->es_evTuple != NULL && estate->es_evTuple[node->scanrelid - 1] != NULL) diff --git a/src/backend/executor/nodeSubqueryscan.c b/src/backend/executor/nodeSubqueryscan.c index 45c3252f78..56626009a6 100644 --- a/src/backend/executor/nodeSubqueryscan.c +++ b/src/backend/executor/nodeSubqueryscan.c @@ -259,4 +259,5 @@ ExecSubqueryReScan(SubqueryScan *node, ExprContext *exprCtxt, Plan *parent) ExecReScan(node->subplan, NULL, (Plan *) node); subquerystate->csstate.css_ScanTupleSlot = NULL; + subquerystate->csstate.cstate.cs_TupFromTlist = false; } diff --git a/src/backend/executor/nodeTidscan.c b/src/backend/executor/nodeTidscan.c index 8bc3b613e0..f7e74218eb 100644 --- a/src/backend/executor/nodeTidscan.c +++ b/src/backend/executor/nodeTidscan.c @@ -254,6 +254,8 @@ ExecTidReScan(TidScan *node, ExprContext *exprCtxt, Plan *parent) tidstate = node->tidstate; tidList = tidstate->tss_TidList; + node->scan.scanstate->cstate.cs_TupFromTlist = false; + /* If we are being passed an outer tuple, save it for runtime key calc */ if (exprCtxt != NULL) node->scan.scanstate->cstate.cs_ExprContext->ecxt_outertuple = @@ -411,6 +413,8 @@ ExecInitTidScan(TidScan *node, EState *estate, Plan *parent) */ ExecAssignExprContext(estate, &scanstate->cstate); + scanstate->cstate.cs_TupFromTlist = false; + #define TIDSCAN_NSLOTS 2 /*