diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-02-27 13:43:29 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-02-27 13:44:12 -0500 |
commit | a874fe7b4c890d1fe3455215a83ca777867beadd (patch) | |
tree | 04b7870100a76bb79470abaf0f971550043590d7 /src/backend/commands/portalcmds.c | |
parent | 67a5e727c8655496013b007d2fb6137fcc244b18 (diff) |
Refactor the executor's API to support data-modifying CTEs better.
The originally committed patch for modifying CTEs didn't interact well
with EXPLAIN, as noted by myself, and also had corner-case problems with
triggers, as noted by Dean Rasheed. Those problems show it is really not
practical for ExecutorEnd to call any user-defined code; so split the
cleanup duties out into a new function ExecutorFinish, which must be called
between the last ExecutorRun call and ExecutorEnd. Some Asserts have been
added to these functions to help verify correct usage.
It is no longer necessary for callers of the executor to call
AfterTriggerBeginQuery/AfterTriggerEndQuery for themselves, as this is now
done by ExecutorStart/ExecutorFinish respectively. If you really need to
suppress that and do it for yourself, pass EXEC_FLAG_SKIP_TRIGGERS to
ExecutorStart.
Also, refactor portal commit processing to allow for the possibility that
PortalDrop will invoke user-defined code. I think this is not actually
necessary just yet, since the portal-execution-strategy logic forces any
non-pure-SELECT query to be run to completion before we will consider
committing. But it seems like good future-proofing.
Diffstat (limited to 'src/backend/commands/portalcmds.c')
-rw-r--r-- | src/backend/commands/portalcmds.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c index dda592c03a3..60aca3ce8ec 100644 --- a/src/backend/commands/portalcmds.c +++ b/src/backend/commands/portalcmds.c @@ -254,7 +254,14 @@ PortalCleanup(Portal portal) queryDesc = PortalGetQueryDesc(portal); if (queryDesc) { + /* + * Reset the queryDesc before anything else. This prevents us + * from trying to shut down the executor twice, in case of an + * error below. The transaction abort mechanisms will take care + * of resource cleanup in such a case. + */ portal->queryDesc = NULL; + if (portal->status != PORTAL_FAILED) { ResourceOwner saveResourceOwner; @@ -264,7 +271,7 @@ PortalCleanup(Portal portal) PG_TRY(); { CurrentResourceOwner = portal->resowner; - /* we do not need AfterTriggerEndQuery() here */ + ExecutorFinish(queryDesc); ExecutorEnd(queryDesc); FreeQueryDesc(queryDesc); } @@ -371,7 +378,7 @@ PersistHoldablePortal(Portal portal) * Now shut down the inner executor. */ portal->queryDesc = NULL; /* prevent double shutdown */ - /* we do not need AfterTriggerEndQuery() here */ + ExecutorFinish(queryDesc); ExecutorEnd(queryDesc); FreeQueryDesc(queryDesc); |