]> granicus.if.org Git - postgresql/commitdiff
Repair bug #2839: the various ExecReScan functions need to reset
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 26 Dec 2006 19:26:56 +0000 (19:26 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 26 Dec 2006 19:26:56 +0000 (19:26 +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
src/backend/executor/nodeValuesscan.c

index e1e006226908d7025115419fad3c94bd2e707017..69171a6145f4e1569d8507cf8fc9792bbf583f09 100644 (file)
@@ -21,7 +21,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.14 2006/10/04 00:29:52 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.14.2.1 2006/12/26 19:26:56 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -364,6 +364,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.
@@ -488,6 +490,8 @@ ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate, int eflags)
         */
        ExecAssignExprContext(estate, &scanstate->ss.ps);
 
+       scanstate->ss.ps.ps_TupFromTlist = false;
+
        /*
         * initialize child expressions
         */
index 90ab018874329b6788e061ac3a2e2dd288709aec..3ab193cb14ab892d81836fa563d869fa40e69c6a 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeFunctionscan.c,v 1.40 2006/06/27 02:51:39 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeFunctionscan.c,v 1.40.2.1 2006/12/26 19:26:56 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -317,6 +317,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 9773f2341ec78eda88b6fceb7a09c0ea1fe6fbe0..10ea65c5ec72e1fd2eb08843f5b07a01f6dcbda7 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.117 2006/10/04 00:29:52 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.117.2.1 2006/12/26 19:26:56 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -168,6 +168,8 @@ ExecIndexReScan(IndexScanState *node, ExprContext *exprCtxt)
        econtext = node->iss_RuntimeContext;            /* context for runtime keys */
        scanrelid = ((IndexScan *) node->ss.ps.plan)->scan.scanrelid;
 
+       node->ss.ps.ps_TupFromTlist = false;
+
        if (econtext)
        {
                /*
@@ -476,6 +478,8 @@ ExecInitIndexScan(IndexScan *node, EState *estate, int eflags)
         */
        ExecAssignExprContext(estate, &indexstate->ss.ps);
 
+       indexstate->ss.ps.ps_TupFromTlist = false;
+
        /*
         * initialize child expressions
         *
index e58d6ece5067c95f1320e2494aa56c3c531db32f..2deef985f4d3f70b21dcda76333c882048a162c6 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.34 2006/03/05 15:58:26 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeResult.c,v 1.34.2.1 2006/12/26 19:26:56 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -200,6 +200,8 @@ ExecInitResult(Result *node, EState *estate, int eflags)
         */
        ExecAssignExprContext(estate, &resstate->ps);
 
+       resstate->ps.ps_TupFromTlist = false;
+
 #define RESULT_NSLOTS 1
 
        /*
index a6287793d44b8d8f4ab644fdc8e2a5038c8be3b6..d01cad4be7186be815d2ffda796856c8a0f671e9 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeSeqscan.c,v 1.61 2006/10/04 00:29:52 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeSeqscan.c,v 1.61.2.1 2006/12/26 19:26:56 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -295,6 +295,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 22e148ec6c9a2b32a3130532a14ab9eb5df2bf69..f14f8b77658a3302dfe7d13c18b4d44551fe1e5e 100644 (file)
@@ -12,7 +12,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.32 2006/10/04 00:29:53 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.32.2.1 2006/12/26 19:26:56 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -294,4 +294,5 @@ ExecSubqueryReScan(SubqueryScanState *node, ExprContext *exprCtxt)
        MemoryContextSwitchTo(oldcontext);
 
        node->ss.ss_ScanTupleSlot = NULL;
+       node->ss.ps.ps_TupFromTlist = false;
 }
index 52d92904577397b49e5c5383328f41234baaf49f..d6bbe970e0f66f02fa79f0c15bde470a0ab398f5 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.51 2006/10/04 00:29:53 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.51.2.1 2006/12/26 19:26:56 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -376,6 +376,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 =
@@ -482,6 +484,8 @@ ExecInitTidScan(TidScan *node, EState *estate, int eflags)
         */
        ExecAssignExprContext(estate, &tidstate->ss.ps);
 
+       tidstate->ss.ps.ps_TupFromTlist = false;
+
        /*
         * initialize child expressions
         */
index c6a1a940389ce562ea5219bae43bf4be5fcb624b..5b7b635f7ed58f9ccc036d9d7142bb22c03bd8e4 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeValuesscan.c,v 1.3 2006/10/04 00:29:53 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeValuesscan.c,v 1.3.2.1 2006/12/26 19:26:56 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -334,6 +334,7 @@ void
 ExecValuesReScan(ValuesScanState *node, ExprContext *exprCtxt)
 {
        ExecClearTuple(node->ss.ps.ps_ResultTupleSlot);
+       node->ss.ps.ps_TupFromTlist = false;
 
        node->curr_idx = -1;
 }