From: Tom Lane Date: Tue, 26 Dec 2006 19:27:20 +0000 (+0000) Subject: Repair bug #2839: the various ExecReScan functions need to reset X-Git-Url: http://waps.l3s.uni-hannover.de/gitweb/?a=commitdiff_plain;h=07330bccad6e319c21173560163522c0dc7a3ec2;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 20f15004be..ca17c8bb8b 100644 --- a/src/backend/executor/nodeFunctionscan.c +++ b/src/backend/executor/nodeFunctionscan.c @@ -341,6 +341,7 @@ void ExecFunctionReScan(FunctionScanState *node, ExprContext *exprCtxt) { ExecClearTuple(node->ss.ps.ps_ResultTupleSlot); + node->ss.ps.ps_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 f14b447703..5c0315dc7c 100644 --- a/src/backend/executor/nodeIndexscan.c +++ b/src/backend/executor/nodeIndexscan.c @@ -375,6 +375,8 @@ ExecIndexReScan(IndexScanState *node, ExprContext *exprCtxt) numScanKeys = node->iss_NumScanKeys; scanrelid = ((IndexScan *) node->ss.ps.plan)->scan.scanrelid; + node->ss.ps.ps_TupFromTlist = false; + if (econtext) { /* @@ -647,6 +649,8 @@ ExecInitIndexScan(IndexScan *node, EState *estate) */ ExecAssignExprContext(estate, &indexstate->ss.ps); + indexstate->ss.ps.ps_TupFromTlist = false; + /* * initialize child expressions */ diff --git a/src/backend/executor/nodeResult.c b/src/backend/executor/nodeResult.c index 2fd410dd04..4eeeeaae5c 100644 --- a/src/backend/executor/nodeResult.c +++ b/src/backend/executor/nodeResult.c @@ -194,6 +194,8 @@ ExecInitResult(Result *node, EState *estate) */ ExecAssignExprContext(estate, &resstate->ps); + resstate->ps.ps_TupFromTlist = false; + #define RESULT_NSLOTS 1 /* diff --git a/src/backend/executor/nodeSeqscan.c b/src/backend/executor/nodeSeqscan.c index 7d270f6eb2..caee68a807 100644 --- a/src/backend/executor/nodeSeqscan.c +++ b/src/backend/executor/nodeSeqscan.c @@ -311,6 +311,8 @@ ExecSeqReScan(SeqScanState *node, ExprContext *exprCtxt) estate = node->ps.state; scanrelid = ((SeqScan *) node->ps.plan)->scanrelid; + node->ps.ps_TupFromTlist = false; + /* If this is re-scanning of PlanQual ... */ if (estate->es_evTuple != NULL && estate->es_evTuple[scanrelid - 1] != NULL) diff --git a/src/backend/executor/nodeSubqueryscan.c b/src/backend/executor/nodeSubqueryscan.c index d832eda30e..5c2ca5af1b 100644 --- a/src/backend/executor/nodeSubqueryscan.c +++ b/src/backend/executor/nodeSubqueryscan.c @@ -278,4 +278,5 @@ ExecSubqueryReScan(SubqueryScanState *node, ExprContext *exprCtxt) MemoryContextSwitchTo(oldcontext); node->ss.ss_ScanTupleSlot = NULL; + node->ss.ps.ps_TupFromTlist = false; } diff --git a/src/backend/executor/nodeTidscan.c b/src/backend/executor/nodeTidscan.c index 442a9d6fc4..4faa510dac 100644 --- a/src/backend/executor/nodeTidscan.c +++ b/src/backend/executor/nodeTidscan.c @@ -270,6 +270,8 @@ ExecTidReScan(TidScanState *node, ExprContext *exprCtxt) estate = node->ss.ps.state; scanrelid = ((TidScan *) node->ss.ps.plan)->scan.scanrelid; + node->ss.ps.ps_TupFromTlist = false; + /* If we are being passed an outer tuple, save it for runtime key calc */ if (exprCtxt != NULL) node->ss.ps.ps_ExprContext->ecxt_outertuple = @@ -385,6 +387,8 @@ ExecInitTidScan(TidScan *node, EState *estate) */ ExecAssignExprContext(estate, &tidstate->ss.ps); + tidstate->ss.ps.ps_TupFromTlist = false; + /* * initialize child expressions */