Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6899646

Browse files
committed
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.
1 parent fccf99f commit 6899646

8 files changed

+27
-8
lines changed

src/backend/executor/nodeBitmapHeapscan.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
*
2323
* IDENTIFICATION
24-
* $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.14 2006/10/04 00:29:52 momjian Exp $
24+
* $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.15 2006/12/26 19:26:45 tgl Exp $
2525
*
2626
*-------------------------------------------------------------------------
2727
*/
@@ -364,6 +364,8 @@ ExecBitmapHeapReScan(BitmapHeapScanState *node, ExprContext *exprCtxt)
364364
estate = node->ss.ps.state;
365365
scanrelid = ((BitmapHeapScan *) node->ss.ps.plan)->scan.scanrelid;
366366

367+
node->ss.ps.ps_TupFromTlist = false;
368+
367369
/*
368370
* If we are being passed an outer tuple, link it into the "regular"
369371
* per-tuple econtext for possible qual eval.
@@ -488,6 +490,8 @@ ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate, int eflags)
488490
*/
489491
ExecAssignExprContext(estate, &scanstate->ss.ps);
490492

493+
scanstate->ss.ps.ps_TupFromTlist = false;
494+
491495
/*
492496
* initialize child expressions
493497
*/

src/backend/executor/nodeFunctionscan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/nodeFunctionscan.c,v 1.40 2006/06/27 02:51:39 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/nodeFunctionscan.c,v 1.41 2006/12/26 19:26:45 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -317,6 +317,7 @@ void
317317
ExecFunctionReScan(FunctionScanState *node, ExprContext *exprCtxt)
318318
{
319319
ExecClearTuple(node->ss.ps.ps_ResultTupleSlot);
320+
node->ss.ps.ps_TupFromTlist = false;
320321

321322
/*
322323
* If we haven't materialized yet, just return.

src/backend/executor/nodeIndexscan.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.118 2006/12/23 00:43:09 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.119 2006/12/26 19:26:45 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -168,6 +168,8 @@ ExecIndexReScan(IndexScanState *node, ExprContext *exprCtxt)
168168
econtext = node->iss_RuntimeContext; /* context for runtime keys */
169169
scanrelid = ((IndexScan *) node->ss.ps.plan)->scan.scanrelid;
170170

171+
node->ss.ps.ps_TupFromTlist = false;
172+
171173
if (econtext)
172174
{
173175
/*
@@ -476,6 +478,8 @@ ExecInitIndexScan(IndexScan *node, EState *estate, int eflags)
476478
*/
477479
ExecAssignExprContext(estate, &indexstate->ss.ps);
478480

481+
indexstate->ss.ps.ps_TupFromTlist = false;
482+
479483
/*
480484
* initialize child expressions
481485
*

src/backend/executor/nodeResult.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
4040
* IDENTIFICATION
41-
* $PostgreSQL: pgsql/src/backend/executor/nodeResult.c,v 1.34 2006/03/05 15:58:26 momjian Exp $
41+
* $PostgreSQL: pgsql/src/backend/executor/nodeResult.c,v 1.35 2006/12/26 19:26:45 tgl Exp $
4242
*
4343
*-------------------------------------------------------------------------
4444
*/
@@ -200,6 +200,8 @@ ExecInitResult(Result *node, EState *estate, int eflags)
200200
*/
201201
ExecAssignExprContext(estate, &resstate->ps);
202202

203+
resstate->ps.ps_TupFromTlist = false;
204+
203205
#define RESULT_NSLOTS 1
204206

205207
/*

src/backend/executor/nodeSeqscan.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/nodeSeqscan.c,v 1.61 2006/10/04 00:29:52 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/nodeSeqscan.c,v 1.62 2006/12/26 19:26:46 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -295,6 +295,8 @@ ExecSeqReScan(SeqScanState *node, ExprContext *exprCtxt)
295295
estate = node->ps.state;
296296
scanrelid = ((SeqScan *) node->ps.plan)->scanrelid;
297297

298+
node->ps.ps_TupFromTlist = false;
299+
298300
/* If this is re-scanning of PlanQual ... */
299301
if (estate->es_evTuple != NULL &&
300302
estate->es_evTuple[scanrelid - 1] != NULL)

src/backend/executor/nodeSubqueryscan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.32 2006/10/04 00:29:53 momjian Exp $
15+
* $PostgreSQL: pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.33 2006/12/26 19:26:46 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -294,4 +294,5 @@ ExecSubqueryReScan(SubqueryScanState *node, ExprContext *exprCtxt)
294294
MemoryContextSwitchTo(oldcontext);
295295

296296
node->ss.ss_ScanTupleSlot = NULL;
297+
node->ss.ps.ps_TupFromTlist = false;
297298
}

src/backend/executor/nodeTidscan.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.51 2006/10/04 00:29:53 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.52 2006/12/26 19:26:46 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -376,6 +376,8 @@ ExecTidReScan(TidScanState *node, ExprContext *exprCtxt)
376376
estate = node->ss.ps.state;
377377
scanrelid = ((TidScan *) node->ss.ps.plan)->scan.scanrelid;
378378

379+
node->ss.ps.ps_TupFromTlist = false;
380+
379381
/* If we are being passed an outer tuple, save it for runtime key calc */
380382
if (exprCtxt != NULL)
381383
node->ss.ps.ps_ExprContext->ecxt_outertuple =
@@ -482,6 +484,8 @@ ExecInitTidScan(TidScan *node, EState *estate, int eflags)
482484
*/
483485
ExecAssignExprContext(estate, &tidstate->ss.ps);
484486

487+
tidstate->ss.ps.ps_TupFromTlist = false;
488+
485489
/*
486490
* initialize child expressions
487491
*/

src/backend/executor/nodeValuesscan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/executor/nodeValuesscan.c,v 1.3 2006/10/04 00:29:53 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/executor/nodeValuesscan.c,v 1.4 2006/12/26 19:26:46 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -334,6 +334,7 @@ void
334334
ExecValuesReScan(ValuesScanState *node, ExprContext *exprCtxt)
335335
{
336336
ExecClearTuple(node->ss.ps.ps_ResultTupleSlot);
337+
node->ss.ps.ps_TupFromTlist = false;
337338

338339
node->curr_idx = -1;
339340
}

0 commit comments

Comments
 (0)