aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-02-06 22:49:42 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-02-06 22:49:42 +0000
commitbb65d51c2e1d9c941eec02edde77d76101fbe848 (patch)
tree862539216936e3d6181cadf5c15ae9b59417bf94 /src
parent122680c51443b66fd9fc8687881ad571248516fa (diff)
downloadpostgresql-bb65d51c2e1d9c941eec02edde77d76101fbe848.tar.gz
postgresql-bb65d51c2e1d9c941eec02edde77d76101fbe848.zip
Fix an error in the original coding of holdable cursors: PersistHoldablePortal
thought that it didn't have to reposition the underlying tuplestore if the portal is atEnd. But this is not so, because tuplestores have separate read and write cursors ... and the read cursor hasn't moved from the start. This mistake explains bug #2970 from William Zhang. Note: the coding here is pretty inefficient, but given that no one has noticed this bug until now, I'd say hardly anyone uses the case where the cursor has been advanced before being persisted. So maybe it's not worth worrying about.
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/portalcmds.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c
index 78d1f7c20bb..f1f0831882d 100644
--- a/src/backend/commands/portalcmds.c
+++ b/src/backend/commands/portalcmds.c
@@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.38.4.1 2005/04/11 15:59:47 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.38.4.2 2007/02/06 22:49:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -389,15 +389,30 @@ PersistHoldablePortal(Portal portal)
/* we do not need AfterTriggerEndQuery() here */
/*
- * Reset the position in the result set: ideally, this could be
- * implemented by just skipping straight to the tuple # that we
- * need to be at, but the tuplestore API doesn't support that. So
- * we start at the beginning of the tuplestore and iterate through
- * it until we reach where we need to be. FIXME someday?
+ * Set the position in the result set: ideally, this could be
+ * implemented by just skipping straight to the tuple # that we need
+ * to be at, but the tuplestore API doesn't support that. So we start
+ * at the beginning of the tuplestore and iterate through it until we
+ * reach where we need to be. FIXME someday? (Fortunately, the
+ * typical case is that we're supposed to be at or near the start
+ * of the result set, so this isn't as bad as it sounds.)
*/
MemoryContextSwitchTo(portal->holdContext);
- if (!portal->atEnd)
+ if (portal->atEnd)
+ {
+ /* we can handle this case even if posOverflow */
+ HeapTuple tup;
+ bool should_free;
+
+ while ((tup = tuplestore_gettuple(portal->holdStore, true,
+ &should_free)) != NULL)
+ {
+ if (should_free)
+ pfree(tup);
+ }
+ }
+ else
{
long store_pos;