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

Commit 5b706ba

Browse files
committed
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.
1 parent 09f9553 commit 5b706ba

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/backend/commands/portalcmds.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.59 2007/02/01 19:10:26 momjian Exp $
17+
* $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.60 2007/02/06 22:49:24 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -392,15 +392,23 @@ PersistHoldablePortal(Portal portal)
392392
ExecutorEnd(queryDesc);
393393

394394
/*
395-
* Reset the position in the result set: ideally, this could be
395+
* Set the position in the result set: ideally, this could be
396396
* implemented by just skipping straight to the tuple # that we need
397397
* to be at, but the tuplestore API doesn't support that. So we start
398398
* at the beginning of the tuplestore and iterate through it until we
399-
* reach where we need to be. FIXME someday?
399+
* reach where we need to be. FIXME someday? (Fortunately, the
400+
* typical case is that we're supposed to be at or near the start
401+
* of the result set, so this isn't as bad as it sounds.)
400402
*/
401403
MemoryContextSwitchTo(portal->holdContext);
402404

403-
if (!portal->atEnd)
405+
if (portal->atEnd)
406+
{
407+
/* we can handle this case even if posOverflow */
408+
while (tuplestore_advance(portal->holdStore, true))
409+
/* continue */ ;
410+
}
411+
else
404412
{
405413
long store_pos;
406414

0 commit comments

Comments
 (0)