1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-12 15:23:02 +03:00

Repair bug #2839: the various ExecReScan functions need to reset

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.
This commit is contained in:
Tom Lane
2006-12-26 19:27:10 +00:00
parent b328083249
commit cbca48aa24
6 changed files with 20 additions and 6 deletions

View 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.

View 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
*

View 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
/*

View 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)

View 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;
}

View 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
*/