]> 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:04 +0000 (19:27 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 26 Dec 2006 19:27:04 +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/nodeBitmapHeapscan.c
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 38288ec659e1a2537c05e675b2039cfef9e095d0..4ea557c0efd02e416dec0c03e64091f088a6d270 100644 (file)
@@ -21,7 +21,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.4.2.1 2005/12/02 01:30:26 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.4.2.2 2006/12/26 19:27:03 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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
         */
index a0178e8fa17f59acd8b21b18449df30b37fc2714..bb1dcba127028facfb8167a760a7461ce76ffe99 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeFunctionscan.c,v 1.35 2005/10/15 02:49:17 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeFunctionscan.c,v 1.35.2.1 2006/12/26 19:27:03 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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.
index 009aba997f6410aa77372645542501ee8a89a0be..63a6073f77945068e38d2d25c7c26886ebd79250 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.104.2.1 2005/11/22 18:23:09 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.104.2.2 2006/12/26 19:27:03 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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
         *
index 013c4e99794a48b341c8c28aaa1218cfe16690f0..952745783b30cf60d4e5844c7542468eb9505533 100644 (file)
@@ -38,7 +38,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeResult.c,v 1.32 2005/10/15 02:49:17 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeResult.c,v 1.32.2.1 2006/12/26 19:27:04 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -196,6 +196,8 @@ ExecInitResult(Result *node, EState *estate)
         */
        ExecAssignExprContext(estate, &resstate->ps);
 
+       resstate->ps.ps_TupFromTlist = false;
+
 #define RESULT_NSLOTS 1
 
        /*
index 91e0c81e036890a5f22fb1ef04e8cb2be102a42c..7eec46d9a323a7645423fe17baa773a09f32ede7 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeSeqscan.c,v 1.54 2005/10/15 02:49:17 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeSeqscan.c,v 1.54.2.1 2006/12/26 19:27:04 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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)
index 9b1bd25143505c5114f56ed7b9fd625c46b2f16e..851a1f66edb7604d56fed2fda4a04c6ac5011d5e 100644 (file)
@@ -12,7 +12,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.27 2005/10/15 02:49:17 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.27.2.1 2006/12/26 19:27:04 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -293,4 +293,5 @@ ExecSubqueryReScan(SubqueryScanState *node, ExprContext *exprCtxt)
        MemoryContextSwitchTo(oldcontext);
 
        node->ss.ss_ScanTupleSlot = NULL;
+       node->ss.ps.ps_TupFromTlist = false;
 }
index c8708f583110e2c492be92e0db94bb39754216d5..43aa23917a40473c894903cbb10b0300f0afa868 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.43 2005/10/15 02:49:17 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.43.2.1 2006/12/26 19:27:04 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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
         */