1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-18 17:41:14 +03:00

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.
This commit is contained in:
Tom Lane 2007-02-06 22:49:48 +00:00
parent f0083ccfde
commit dec65c9421

View File

@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.24.2.1 2004/11/28 22:16:49 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.24.2.2 2007/02/06 22:49:48 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -363,7 +363,20 @@ PersistHoldablePortal(Portal portal)
*/
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;