Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd8d93bc

Browse files
committed
Avoid fetching from an already-terminated plan.
Some plan node types don't react well to being called again afterthey've already returned NULL. PortalRunSelect() has long dealtwith this by calling the executor with NoMovementScanDirectionif it sees that we've already run the portal to the end. However,commitba2c6d6 overlooked this point, so that persisting analready-fully-fetched cursor would fail if it had such a plan.Per report from Tomas Barton. Back-patch to v11, as the faultycommit was. (I've omitted a test case because the type of planthat causes a problem isn't all that stable.)Discussion:https://postgr.es/m/CAPV2KRjd=ErgVGbvO2Ty20tKTEZZr6cYsYLxgN_W3eAo9pf5sw@mail.gmail.com
1 parent04118de commitd8d93bc

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

‎src/backend/commands/portalcmds.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ PersistHoldablePortal(Portal portal)
364364
savePortalContext=PortalContext;
365365
PG_TRY();
366366
{
367+
ScanDirectiondirection=ForwardScanDirection;
368+
367369
ActivePortal=portal;
368370
if (portal->resowner)
369371
CurrentResourceOwner=portal->resowner;
@@ -386,10 +388,20 @@ PersistHoldablePortal(Portal portal)
386388
}
387389
else
388390
{
389-
/*We must reset the cursor state as though at start of query */
391+
/*Disallow moving backwards from here */
390392
portal->atStart= true;
391-
portal->atEnd= false;
392393
portal->portalPos=0;
394+
395+
/*
396+
* If we already reached end-of-query, set the direction to
397+
* NoMovement to avoid trying to fetch any tuples. (This check
398+
* exists because not all plan node types are robust about being
399+
* called again if they've already returned NULL once.) We'll
400+
* still set up an empty tuplestore, though, to keep this from
401+
* being a special case later.
402+
*/
403+
if (portal->atEnd)
404+
direction=NoMovementScanDirection;
393405
}
394406

395407
/*
@@ -404,7 +416,7 @@ PersistHoldablePortal(Portal portal)
404416
true);
405417

406418
/* Fetch the result set into the tuplestore */
407-
ExecutorRun(queryDesc,ForwardScanDirection,0L, false);
419+
ExecutorRun(queryDesc,direction,0L, false);
408420

409421
queryDesc->dest->rDestroy(queryDesc->dest);
410422
queryDesc->dest=NULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp