From: Tom Lane Date: Tue, 26 Dec 2006 19:27:04 +0000 (+0000) Subject: Repair bug #2839: the various ExecReScan functions need to reset X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=d4ca45484ad18a89741fbdffc64917acfb4a73ed;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/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c index c33f41d55f..2e4c76b699 100644 --- a/src/backend/executor/nodeBitmapHeapscan.c +++ b/src/backend/executor/nodeBitmapHeapscan.c @@ -306,6 +306,8 @@ ExecBitmapHeapReScan(BitmapHeapScanState *node, ExprContext *exprCtxt) estate = node->ss.ps.state; scanrelid = ((BitmapHeapScan *) node->ss.ps.plan)->scan.scanrelid; + node->ss.ps.ps_TupFromTlist = false; + /* * If we are being passed an outer tuple, link it into the "regular" * per-tuple econtext for possible qual eval. @@ -429,6 +431,8 @@ ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate) */ ExecAssignExprContext(estate, &scanstate->ss.ps); + scanstate->ss.ps.ps_TupFromTlist = false; + /* * initialize child expressions */ diff --git a/src/backend/executor/nodeFunctionscan.c b/src/backend/executor/nodeFunctionscan.c index e60189db3b..8d85e8ac99 100644 --- a/src/backend/executor/nodeFunctionscan.c +++ b/src/backend/executor/nodeFunctionscan.c @@ -320,6 +320,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 acb2de4cda..2263753a8b 100644 --- a/src/backend/executor/nodeIndexscan.c +++ b/src/backend/executor/nodeIndexscan.c @@ -183,6 +183,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) { /* @@ -384,6 +386,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 d671c6a2d8..a672b10c22 100644 --- a/src/backend/executor/nodeResult.c +++ b/src/backend/executor/nodeResult.c @@ -196,6 +196,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 073a16b7ec..581791abc8 100644 --- a/src/backend/executor/nodeSeqscan.c +++ b/src/backend/executor/nodeSeqscan.c @@ -317,6 +317,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 14b05479f3..49073d2db5 100644 --- a/src/backend/executor/nodeSubqueryscan.c +++ b/src/backend/executor/nodeSubqueryscan.c @@ -293,4 +293,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 4dc02e43e1..1ca8ee3d01 100644 --- a/src/backend/executor/nodeTidscan.c +++ b/src/backend/executor/nodeTidscan.c @@ -275,6 +275,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 = @@ -389,6 +391,8 @@ ExecInitTidScan(TidScan *node, EState *estate) */ ExecAssignExprContext(estate, &tidstate->ss.ps); + tidstate->ss.ps.ps_TupFromTlist = false; + /* * initialize child expressions */