diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-02-28 23:27:18 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-02-28 23:28:06 -0500 |
commit | c0b00760365c74308e9e0719c993eadfbcd090c2 (patch) | |
tree | 28226f24ffb13c5788e1e29606b56bad4d672b72 /src/backend/utils/time/snapmgr.c | |
parent | 57e9bda5ec6a032e1e6d51dad5e534a11669c6bf (diff) | |
download | postgresql-c0b00760365c74308e9e0719c993eadfbcd090c2.tar.gz |
Rearrange snapshot handling to make rule expansion more consistent.
With this patch, portals, SQL functions, and SPI all agree that there
should be only a CommandCounterIncrement between the queries that are
generated from a single SQL command by rule expansion. Fetching a whole
new snapshot now happens only between original queries. This is equivalent
to the existing behavior of EXPLAIN ANALYZE, and it was judged to be the
best choice since it eliminates one source of concurrency hazards for
rules. The patch should also make things marginally faster by reducing the
number of snapshot push/pop operations.
The patch removes pg_parse_and_rewrite(), which is no longer used anywhere.
There was considerable discussion about more aggressive refactoring of the
query-processing functions exported by postgres.c, but for the moment
nothing more has been done there.
I also took the opportunity to refactor snapmgr.c's API slightly: the
former PushUpdatedSnapshot() has been split into two functions.
Marko Tiikkaja, reviewed by Steve Singer and Tom Lane
Diffstat (limited to 'src/backend/utils/time/snapmgr.c')
-rw-r--r-- | src/backend/utils/time/snapmgr.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c index c2ff5e542b..9100c818f8 100644 --- a/src/backend/utils/time/snapmgr.c +++ b/src/backend/utils/time/snapmgr.c @@ -299,22 +299,33 @@ PushActiveSnapshot(Snapshot snap) } /* - * PushUpdatedSnapshot - * As above, except we set the snapshot's CID to the current CID. + * PushCopiedSnapshot + * As above, except forcibly copy the presented snapshot. + * + * This should be used when the ActiveSnapshot has to be modifiable, for + * example if the caller intends to call UpdateActiveSnapshotCommandId. + * The new snapshot will be released when popped from the stack. */ void -PushUpdatedSnapshot(Snapshot snapshot) +PushCopiedSnapshot(Snapshot snapshot) { - Snapshot newsnap; + PushActiveSnapshot(CopySnapshot(snapshot)); +} - /* - * We cannot risk modifying a snapshot that's possibly already used - * elsewhere, so make a new copy to scribble on. - */ - newsnap = CopySnapshot(snapshot); - newsnap->curcid = GetCurrentCommandId(false); +/* + * UpdateActiveSnapshotCommandId + * + * Update the current CID of the active snapshot. This can only be applied + * to a snapshot that is not referenced elsewhere. + */ +void +UpdateActiveSnapshotCommandId(void) +{ + Assert(ActiveSnapshot != NULL); + Assert(ActiveSnapshot->as_snap->active_count == 1); + Assert(ActiveSnapshot->as_snap->regd_count == 0); - PushActiveSnapshot(newsnap); + ActiveSnapshot->as_snap->curcid = GetCurrentCommandId(false); } /* |