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/explain.c | |
parent | 67a5e727c8655496013b007d2fb6137fcc244b18 (diff) | |
download | postgresql-a874fe7b4c890d1fe3455215a83ca777867beadd.tar.gz postgresql-a874fe7b4c890d1fe3455215a83ca777867beadd.zip |
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/explain.c')
-rw-r--r-- | src/backend/commands/explain.c | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index ccae1f9d84c..23819a0fdb7 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -360,6 +360,8 @@ ExplainOnePlan(PlannedStmt *plannedstmt, ExplainState *es, if (es->buffers) instrument_option |= INSTRUMENT_BUFFERS; + INSTR_TIME_SET_CURRENT(starttime); + /* * Use a snapshot with an updated command ID to ensure this query sees * results of any previously executed queries. @@ -371,12 +373,6 @@ ExplainOnePlan(PlannedStmt *plannedstmt, ExplainState *es, GetActiveSnapshot(), InvalidSnapshot, None_Receiver, params, instrument_option); - INSTR_TIME_SET_CURRENT(starttime); - - /* If analyzing, we need to cope with queued triggers */ - if (es->analyze) - AfterTriggerBeginQuery(); - /* Select execution options */ if (es->analyze) eflags = 0; /* default run-to-completion flags */ @@ -392,7 +388,10 @@ ExplainOnePlan(PlannedStmt *plannedstmt, ExplainState *es, /* run the plan */ ExecutorRun(queryDesc, ForwardScanDirection, 0L); - /* We can't clean up 'till we're done printing the stats... */ + /* run cleanup too */ + ExecutorFinish(queryDesc); + + /* We can't run ExecutorEnd 'till we're done printing the stats... */ totaltime += elapsed_time(&starttime); } @@ -401,18 +400,6 @@ ExplainOnePlan(PlannedStmt *plannedstmt, ExplainState *es, /* Create textual dump of plan tree */ ExplainPrintPlan(es, queryDesc); - /* - * If we ran the command, run any AFTER triggers it queued. (Note this - * will not include DEFERRED triggers; since those don't run until end of - * transaction, we can't measure them.) Include into total runtime. - */ - if (es->analyze) - { - INSTR_TIME_SET_CURRENT(starttime); - AfterTriggerEndQuery(queryDesc->estate); - totaltime += elapsed_time(&starttime); - } - /* Print info about runtime of triggers */ if (es->analyze) { |