]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Repair bug #2839: the various ExecReScan functions need to reset
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 26 Dec 2006 19:27:10 +0000 (19:27 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
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 4cf77dac930fabc54691aa498cbc9e8a7f82830c..4f95692fe0d0f30d233c681edd46a805404ddf7b 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeFunctionscan.c,v 1.29 2004/12/31 21:59:45 pgsql Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeFunctionscan.c,v 1.29.4.1 2006/12/26 19:27:10 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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 afe3a8effa39e5b4e6125ac8abf352806747e17a..e3c97fe572e0bd06d6949ef75a7abee5e451f0bb 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.99.4.1 2006/05/19 16:30:50 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.99.4.2 2006/12/26 19:27:10 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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 abc94a2cf12ece9e82f8601a49198129abeb8347..d2ec0deded33f70bcec9c43466d6686c675b0ff0 100644 (file)
@@ -34,7 +34,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeResult.c,v 1.29 2004/12/31 21:59:45 pgsql Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeResult.c,v 1.29.4.1 2006/12/26 19:27:10 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -194,6 +194,8 @@ ExecInitResult(Result *node, EState *estate)
         */
        ExecAssignExprContext(estate, &resstate->ps);
 
+       resstate->ps.ps_TupFromTlist = false;
+
 #define RESULT_NSLOTS 1
 
        /*
index 621911652a9fd2d6bfdd9906a2f2d69693d8b59d..0a53ce0caacf9a2df8113ff4b5eb14de181d1f37 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeSeqscan.c,v 1.51 2004/12/31 21:59:45 pgsql Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeSeqscan.c,v 1.51.4.1 2006/12/26 19:27:10 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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 9bc5a6294d0e6a52b50120bdd09d5435b10e1ef9..dbdd7c05465ce90d57fbd82010e5aa02325fd341 100644 (file)
@@ -12,7 +12,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.25 2004/12/31 21:59:45 pgsql Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.25.4.1 2006/12/26 19:27:10 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -278,4 +278,5 @@ ExecSubqueryReScan(SubqueryScanState *node, ExprContext *exprCtxt)
        MemoryContextSwitchTo(oldcontext);
 
        node->ss.ss_ScanTupleSlot = NULL;
+       node->ss.ps.ps_TupFromTlist = false;
 }
index a1eb4351dbb4933d742edea3f14e0d8a87c92e72..1cc361cfe5a6dd47cc6322cf32442627939bc5a2 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.41 2004/12/31 21:59:45 pgsql Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.41.4.1 2006/12/26 19:27:10 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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
         */