Repair bug #2839: the various ExecReScan functions need to reset
authorTom Lane <[email protected]>
Tue, 26 Dec 2006 19:26:56 +0000 (19:26 +0000)
committerTom Lane <[email protected]>
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 820a386153dc0e21f312b72bc37a1d45d8d16036..233d65032a16a71a6295b3bf761891e160cef376 100644 (file)
@@ -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 40e48bf631d31745c0ff5b8e6268c01c5261ecd5..718934df21a1be3e1d5997607bfe4f3d4a4fcd87 100644 (file)
@@ -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 85e61b915a073c82d0e0b06580d6f211417bcdd8..1b831ac8b50213a5debb9665bd72070aa4c567ee 100644 (file)
@@ -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 90b07a7269ffb6055de2fde2e076ca53f23d530a..b60486370c0e3a9d0f13af15bf3c1f15fc1106c5 100644 (file)
@@ -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 34567af4774ac120f40656ea78863800a365195e..e238aca3c499bf50bf2553c8f290d71119bf4c6f 100644 (file)
@@ -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 e9083fbbbd3084e7e08f129969fd0a6a0360ae25..3213f7ca4beb7e539e7ead431232659bbed78c20 100644 (file)
@@ -294,4 +294,5 @@ ExecSubqueryReScan(SubqueryScanState *node, ExprContext *exprCtxt)
        MemoryContextSwitchTo(oldcontext);
 
        node->ss.ss_ScanTupleSlot = NULL;
+       node->ss.ps.ps_TupFromTlist = false;
 }
index b80ff11dc9b9072857e19f3595469f97a1f14354..bcb0c48fb0d43728263d59dacbed04fa8f46d3fc 100644 (file)
@@ -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 5611fbcd52c077da7091e5fd59290bcd26b0ba96..e8f63ce79654b132143fa3337903859e64741419 100644 (file)
@@ -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;
 }