From 25bf7f8b9b3ce0f04b498988bb98d9d5cf9bad67 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 27 Mar 2009 18:30:21 +0000 Subject: Fix possible failures when a tuplestore switches from in-memory to on-disk mode while callers hold pointers to in-memory tuples. I reported this for the case of nodeWindowAgg's primary scan tuple, but inspection of the code shows that all of the calls in nodeWindowAgg and nodeCtescan are at risk. For the moment, fix it with a rather brute-force approach of copying whenever one of the at-risk callers requests a tuple. Later we might think of some sort of reference-count approach to reduce tuple copying. --- src/backend/executor/nodeWorktablescan.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/backend/executor/nodeWorktablescan.c') diff --git a/src/backend/executor/nodeWorktablescan.c b/src/backend/executor/nodeWorktablescan.c index aaac9d19a8c..24fd2c5f736 100644 --- a/src/backend/executor/nodeWorktablescan.c +++ b/src/backend/executor/nodeWorktablescan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeWorktablescan.c,v 1.5 2009/01/01 17:23:42 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeWorktablescan.c,v 1.6 2009/03/27 18:30:21 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -43,6 +43,10 @@ WorkTableScanNext(WorkTableScanState *node) * worktable plan node, since it cannot appear high enough in the plan * tree of a scrollable cursor to be exposed to a backward-scan * requirement. So it's not worth expending effort to support it. + * + * Note: we are also assuming that this node is the only reader of the + * worktable. Therefore, we don't need a private read pointer for the + * tuplestore, nor do we need to tell tuplestore_gettupleslot to copy. */ estate = node->ss.ps.state; Assert(ScanDirectionIsForward(estate->es_direction)); @@ -53,7 +57,7 @@ WorkTableScanNext(WorkTableScanState *node) * Get the next tuple from tuplestore. Return NULL if no more tuples. */ slot = node->ss.ss_ScanTupleSlot; - (void) tuplestore_gettupleslot(tuplestorestate, true, slot); + (void) tuplestore_gettupleslot(tuplestorestate, true, false, slot); return slot; } -- cgit v1.2.3