mirror of
https://github.com/postgres/postgres.git
synced 2025-07-14 08:21:07 +03:00
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.
This commit is contained in:
@ -181,11 +181,6 @@ ProcessQuery(PlannedStmt *plan,
|
||||
GetActiveSnapshot(), InvalidSnapshot,
|
||||
dest, params, 0);
|
||||
|
||||
/*
|
||||
* Set up to collect AFTER triggers
|
||||
*/
|
||||
AfterTriggerBeginQuery();
|
||||
|
||||
/*
|
||||
* Call ExecutorStart to prepare the plan for execution
|
||||
*/
|
||||
@ -231,17 +226,15 @@ ProcessQuery(PlannedStmt *plan,
|
||||
}
|
||||
}
|
||||
|
||||
/* Now take care of any queued AFTER triggers */
|
||||
AfterTriggerEndQuery(queryDesc->estate);
|
||||
|
||||
PopActiveSnapshot();
|
||||
|
||||
/*
|
||||
* Now, we close down all the scans and free allocated resources.
|
||||
*/
|
||||
ExecutorFinish(queryDesc);
|
||||
ExecutorEnd(queryDesc);
|
||||
|
||||
FreeQueryDesc(queryDesc);
|
||||
|
||||
PopActiveSnapshot();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -530,13 +523,6 @@ PortalStart(Portal portal, ParamListInfo params, Snapshot snapshot)
|
||||
params,
|
||||
0);
|
||||
|
||||
/*
|
||||
* We do *not* call AfterTriggerBeginQuery() here. We assume
|
||||
* that a SELECT cannot queue any triggers. It would be messy
|
||||
* to support triggers since the execution of the portal may
|
||||
* be interleaved with other queries.
|
||||
*/
|
||||
|
||||
/*
|
||||
* If it's a scrollable cursor, executor needs to support
|
||||
* REWIND and backwards scan.
|
||||
|
Reference in New Issue
Block a user