diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-04-11 19:51:16 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-04-11 19:51:16 +0000 |
| commit | c3294f1cbfe02293b4a7c6b2e58ca4c09a7e541f (patch) | |
| tree | d4d422b08f15bce2b32867ae3cc8e722e08e9df2 /src/backend/access/transam | |
| parent | 0c400f1bbc3231ed75e11d3ab0ec7a4a9d3c8486 (diff) | |
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')
| -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 b5bb3d5b1fc..4d896ef551d 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.198 2005/03/28 01:50:33 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.199 2005/04/11 19:51:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1439,16 +1439,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(); /* @@ -1649,7 +1665,7 @@ AbortTransaction(void) /* * do abort processing */ - AfterTriggerAbortXact(); + AfterTriggerEndXact(false); AtAbort_Portals(); AtEOXact_LargeObject(false); /* 'false' means it's abort */ AtAbort_Notify(); |
