diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-04-11 19:51:32 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-04-11 19:51:32 +0000 |
commit | fa57fd1c0a4b9dee0bbd932c20d773d56a88a78f (patch) | |
tree | 0be076c1a21005086da1bda3b958f7c46af29f82 /src/backend/access/transam/xact.c | |
parent | add2c3f4d6b137b35c097354438779aacde2f1d9 (diff) | |
download | postgresql-fa57fd1c0a4b9dee0bbd932c20d773d56a88a78f.tar.gz postgresql-fa57fd1c0a4b9dee0bbd932c20d773d56a88a78f.zip |
Fix interaction between materializing holdable cursors and firing
deferred triggers: either one can create more work for the other,
so we have to loop till it's all gone. Per example from andrew@supernews.
Add a regression test to help spot trouble in this area in future.
Diffstat (limited to 'src/backend/access/transam/xact.c')
-rw-r--r-- | src/backend/access/transam/xact.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index ec040d8a96f..dd5c4ea64bd 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.195 2004/12/31 21:59:29 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.195.4.1 2005/04/11 19:51:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1440,16 +1440,32 @@ CommitTransaction(void) /* * Do pre-commit processing (most of this stuff requires database * access, and in fact could still cause an error...) + * + * It is possible for CommitHoldablePortals to invoke functions that + * queue deferred triggers, and it's also possible that triggers create + * holdable cursors. So we have to loop until there's nothing left to + * do. */ + for (;;) + { + /* + * Fire all currently pending deferred triggers. + */ + AfterTriggerFireDeferred(); - /* - * Tell the trigger manager that this transaction is about to be - * committed. He'll invoke all trigger deferred until XACT before we - * really start on committing the transaction. - */ - AfterTriggerEndXact(); + /* + * Convert any open holdable cursors into static portals. If there + * weren't any, we are done ... otherwise loop back to check if they + * queued deferred triggers. Lather, rinse, repeat. + */ + if (!CommitHoldablePortals()) + break; + } + + /* Now we can shut down the deferred-trigger manager */ + AfterTriggerEndXact(true); - /* Close open cursors */ + /* Close any open regular cursors */ AtCommit_Portals(); /* @@ -1650,7 +1666,7 @@ AbortTransaction(void) /* * do abort processing */ - AfterTriggerAbortXact(); + AfterTriggerEndXact(false); AtAbort_Portals(); AtEOXact_LargeObject(false); /* 'false' means it's abort */ AtAbort_Notify(); |