Hi hackers,

I am trying to figure out current cursors/portals management and life cycle in Postgres. There are two if conditions for autoHeld portals:

- 'if (portal->autoHeld)' inside AtAbort_Portals at portalmem.c:802;
- '|| portal->autoHeld' inside AtCleanup_Portals at portalmem.c:871.

Their removal does not seem to affect anything, make check-world is passed. I have tried configure --with-perl/--with-python, which should be a case for autoHeld portals, but nothing changed.

For me it seems to be expectable, since autoHeld flag is always set along with createSubid=InvalidSubTransactionId inside HoldPinnedPortals, so the only one check 'createSubid == InvalidSubTransactionId' should be enough. However, comment sections are rather misleading:

(1) portal.h:126 confirms my guess 'If the portal is held over from a previous transaction, both subxids are InvalidSubTransactionId';

(2) while portalmem.c:797 states 'This is similar to the case of a cursor from a previous transaction, but it could also be that the cursor was auto-held in this transaction, so it wants to live on'.

I have tried, but could not build an example of valid query for the case described in (2), and it is definitely absent in regression tests.

Am I missing something?

Added Peter to cc, since he is a commiter of 056a5a3, where autoHeld has been introduced. Maybe it will be easier for him to recall the context. Anyway, sorry for disturb if this question is actually trivial.


Regards

--
Alexey Kondratov

Postgres Professional https://www.postgrespro.com
Russian Postgres Company

diff --git a/src/backend/utils/mmgr/portalmem.c b/src/backend/utils/mmgr/portalmem.c
index a92b4541bd..841d88df76 100644
--- a/src/backend/utils/mmgr/portalmem.c
+++ b/src/backend/utils/mmgr/portalmem.c
@@ -798,8 +798,6 @@ AtAbort_Portals(void)
 		 * cursor from a previous transaction, but it could also be that the
 		 * cursor was auto-held in this transaction, so it wants to live on.
 		 */
-		if (portal->autoHeld)
-			continue;
 
 		/*
 		 * If it was created in the current transaction, we can't do normal
@@ -868,7 +866,7 @@ AtCleanup_Portals(void)
 		 * Do nothing to cursors held over from a previous transaction or
 		 * auto-held ones.
 		 */
-		if (portal->createSubid == InvalidSubTransactionId || portal->autoHeld)
+		if (portal->createSubid == InvalidSubTransactionId)
 		{
 			Assert(portal->status != PORTAL_ACTIVE);
 			Assert(portal->resowner == NULL);

Reply via email to