aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/portalcmds.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands/portalcmds.c')
-rw-r--r--src/backend/commands/portalcmds.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c
index 1f50993621f..e7c681ab7f4 100644
--- a/src/backend/commands/portalcmds.c
+++ b/src/backend/commands/portalcmds.c
@@ -389,26 +389,22 @@ PersistHoldablePortal(Portal portal)
FreeQueryDesc(queryDesc);
/*
- * 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.)
+ * Set the position in the result set.
*/
MemoryContextSwitchTo(portal->holdContext);
if (portal->atEnd)
{
- /* we can handle this case even if posOverflow */
- while (tuplestore_advance(portal->holdStore, true))
+ /*
+ * We can handle this case even if posOverflow: just force the
+ * tuplestore forward to its end. The size of the skip request
+ * here is arbitrary.
+ */
+ while (tuplestore_skiptuples(portal->holdStore, 1000000, true))
/* continue */ ;
}
else
{
- long store_pos;
-
if (portal->posOverflow) /* oops, cannot trust portalPos */
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
@@ -416,11 +412,10 @@ PersistHoldablePortal(Portal portal)
tuplestore_rescan(portal->holdStore);
- for (store_pos = 0; store_pos < portal->portalPos; store_pos++)
- {
- if (!tuplestore_advance(portal->holdStore, true))
- elog(ERROR, "unexpected end of tuple stream");
- }
+ if (!tuplestore_skiptuples(portal->holdStore,
+ portal->portalPos,
+ true))
+ elog(ERROR, "unexpected end of tuple stream");
}
}
PG_CATCH();