Repair bug #2839: the various ExecReScan functions need to reset
authorTom Lane <[email protected]>
Tue, 26 Dec 2006 19:27:10 +0000 (19:27 +0000)
committerTom Lane <[email protected]>
Tue, 26 Dec 2006 19:27:10 +0000 (19:27 +0000)
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.

src/backend/executor/nodeFunctionscan.c
src/backend/executor/nodeIndexscan.c
src/backend/executor/nodeResult.c
src/backend/executor/nodeSeqscan.c
src/backend/executor/nodeSubqueryscan.c
src/backend/executor/nodeTidscan.c

index 6fce25dad0628b52940df5bdcd2fe8bff15db4d4..536846242f810d4841998f909770fb3b15339bac 100644 (file)
@@ -326,6 +326,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.
index b3909a2f9e4fe17b3c910399bdeca1a27901cb1f..5d96a8a1e2fbd2d803549fd77be17874fbf93aa1 100644 (file)
@@ -405,6 +405,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)
        {
                /*
@@ -680,6 +682,8 @@ ExecInitIndexScan(IndexScan *node, EState *estate)
         */
        ExecAssignExprContext(estate, &indexstate->ss.ps);
 
+       indexstate->ss.ps.ps_TupFromTlist = false;
+
        /*
         * initialize child expressions
         *
index 72ba5290ed457d69f05ed63645e4c6d5266943c3..b0faa715bb9506300ea6fa1ff3c3c94702416355 100644 (file)
@@ -194,6 +194,8 @@ ExecInitResult(Result *node, EState *estate)
         */
        ExecAssignExprContext(estate, &resstate->ps);
 
+       resstate->ps.ps_TupFromTlist = false;
+
 #define RESULT_NSLOTS 1
 
        /*
index 2e2975d6e91f4099ffb46cea32423ddc5f192c0b..f55898c553a849cc1bfc384928eabf85ca6eb224 100644 (file)
@@ -319,6 +319,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)
index 0381bbfe817e9f7176112ec9e3f64c4469b07889..c8ab5c3fd700e2be54e2b880748ee6c91661f7c6 100644 (file)
@@ -278,4 +278,5 @@ ExecSubqueryReScan(SubqueryScanState *node, ExprContext *exprCtxt)
        MemoryContextSwitchTo(oldcontext);
 
        node->ss.ss_ScanTupleSlot = NULL;
+       node->ss.ps.ps_TupFromTlist = false;
 }
index 0a1407d9639f343ab9df5ece21d969f84088cf94..3b9fa0dd86f9a1d8a12e90f59856a0307d0950df 100644 (file)
@@ -276,6 +276,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 =
@@ -391,6 +393,8 @@ ExecInitTidScan(TidScan *node, EState *estate)
         */
        ExecAssignExprContext(estate, &tidstate->ss.ps);
 
+       tidstate->ss.ps.ps_TupFromTlist = false;
+
        /*
         * initialize child expressions
         */