]> 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:26 +0000 (19:27 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 26 Dec 2006 19:27:26 +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 cf8d74a06f2b93125b3af732478e395206350ced..a5323af692225e48ad5573307340b14d4830aba6 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/executor/nodeFunctionscan.c,v 1.12 2002/09/04 20:31:18 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/executor/nodeFunctionscan.c,v 1.12.2.1 2006/12/26 19:27:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -361,6 +361,7 @@ ExecFunctionReScan(FunctionScan *node, ExprContext *exprCtxt, Plan *parent)
        scanstate = (FunctionScanState *) node->scan.scanstate;
 
        ExecClearTuple(scanstate->csstate.cstate.cs_ResultTupleSlot);
+       scanstate->csstate.cstate.cs_TupFromTlist = false;
 
        /*
         * If we haven't materialized yet, just return.
index 78f5ad0ba26da6d8cee9192519d09528899c7af3..2e8e85958329c8f730ff837678ba02ae27a44c06 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.71 2002/09/04 20:31:18 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.71.2.1 2006/12/26 19:27:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -303,6 +303,8 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
        runtimeKeyInfo = indexstate->iss_RuntimeKeyInfo;
        numScanKeys = indexstate->iss_NumScanKeys;
 
+       node->scan.scanstate->cstate.cs_TupFromTlist = false;
+
        if (econtext)
        {
                /*
@@ -639,6 +641,8 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
         */
        ExecAssignExprContext(estate, &scanstate->cstate);
 
+       scanstate->cstate.cs_TupFromTlist = false;
+
 #define INDEXSCAN_NSLOTS 2
 
        /*
index d9d1608a81df740239236338c07012b19e8f1c43..195fa8c234e1e82c2ad37a0d354c9e3b16cd2255 100644 (file)
@@ -34,7 +34,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/executor/nodeResult.c,v 1.21 2002/06/20 20:29:28 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/executor/nodeResult.c,v 1.21.2.1 2006/12/26 19:27:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -202,6 +202,8 @@ ExecInitResult(Result *node, EState *estate, Plan *parent)
         */
        ExecAssignExprContext(estate, &resstate->cstate);
 
+       resstate->cstate.cs_TupFromTlist = false;
+
 #define RESULT_NSLOTS 1
 
        /*
index 074a52731c0691ea42e69438177569cd24aa3b3d..5d6c3ed28504b09fcb14e62ab5cdb7599bdef8cc 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/executor/nodeSeqscan.c,v 1.37 2002/09/04 20:31:18 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/executor/nodeSeqscan.c,v 1.37.2.1 2006/12/26 19:27:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -318,6 +318,8 @@ ExecSeqReScan(SeqScan *node, ExprContext *exprCtxt, Plan *parent)
        scanstate = node->scanstate;
        estate = node->plan.state;
 
+       scanstate->cstate.cs_TupFromTlist = false;
+
        /* If this is re-scanning of PlanQual ... */
        if (estate->es_evTuple != NULL &&
                estate->es_evTuple[node->scanrelid - 1] != NULL)
index 982dd0236ca32b0b26e7525360307497a023b2d1..9649c5a28f5230c6b6ddf57e641b769af6396030 100644 (file)
@@ -12,7 +12,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.13 2002/06/20 20:29:28 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.13.2.1 2006/12/26 19:27:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -259,4 +259,5 @@ ExecSubqueryReScan(SubqueryScan *node, ExprContext *exprCtxt, Plan *parent)
                ExecReScan(node->subplan, NULL, (Plan *) node);
 
        subquerystate->csstate.css_ScanTupleSlot = NULL;
+       subquerystate->csstate.cstate.cs_TupFromTlist = false;
 }
index f5e477663b57b969cc395bf1f6c20fbbbe7d31e1..18e81adac2f6c4d568797e8a1b1d8bb6ffc3107b 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/executor/nodeTidscan.c,v 1.26 2002/09/04 20:31:18 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/executor/nodeTidscan.c,v 1.26.2.1 2006/12/26 19:27:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -254,6 +254,8 @@ ExecTidReScan(TidScan *node, ExprContext *exprCtxt, Plan *parent)
        tidstate = node->tidstate;
        tidList = tidstate->tss_TidList;
 
+       node->scan.scanstate->cstate.cs_TupFromTlist = false;
+
        /* If we are being passed an outer tuple, save it for runtime key calc */
        if (exprCtxt != NULL)
                node->scan.scanstate->cstate.cs_ExprContext->ecxt_outertuple =
@@ -411,6 +413,8 @@ ExecInitTidScan(TidScan *node, EState *estate, Plan *parent)
         */
        ExecAssignExprContext(estate, &scanstate->cstate);
 
+       scanstate->cstate.cs_TupFromTlist = false;
+
 #define TIDSCAN_NSLOTS 2
 
        /*