From 5da9da71c44f27ba48fdad08ef263bf70e43e689 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Mon, 12 May 2008 20:02:02 +0000 Subject: Improve snapshot manager by keeping explicit track of snapshots. There are two ways to track a snapshot: there's the "registered" list, which is used for arbitrary long-lived snapshots; and there's the "active stack", which is used for the snapshot that is considered "active" at any time. This also allows users of snapshots to stop worrying about snapshot memory allocation and freeing, and about using PG_TRY blocks around ActiveSnapshot assignment. This is all done automatically now. As a consequence, this allows us to reset MyProc->xmin when there are no more snapshots registered in the current backend, reducing the impact that long-running transactions have on VACUUM. --- src/backend/commands/copy.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/backend/commands/copy.c') diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 2504bde78ef..69a059631bc 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.298 2008/03/26 18:48:59 alvherre Exp $ + * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.299 2008/05/12 20:01:59 alvherre Exp $ * *------------------------------------------------------------------------- */ @@ -1044,21 +1044,18 @@ DoCopy(const CopyStmt *stmt, const char *queryString) plan = planner(query, 0, NULL); /* - * Update snapshot command ID to ensure this query sees results of any - * previously executed queries. (It's a bit cheesy to modify - * ActiveSnapshot without making a copy, but for the limited ways in - * which COPY can be invoked, I think it's OK, because the active - * snapshot shouldn't be shared with anything else anyway.) + * Use a snapshot with an updated command ID to ensure this query sees + * results of any previously executed queries. */ - ActiveSnapshot->curcid = GetCurrentCommandId(false); + PushUpdatedSnapshot(GetActiveSnapshot()); /* Create dest receiver for COPY OUT */ dest = CreateDestReceiver(DestCopyOut, NULL); ((DR_copy *) dest)->cstate = cstate; /* Create a QueryDesc requesting no output */ - cstate->queryDesc = CreateQueryDesc(plan, - ActiveSnapshot, InvalidSnapshot, + cstate->queryDesc = CreateQueryDesc(plan, GetActiveSnapshot(), + InvalidSnapshot, dest, NULL, false); /* @@ -1161,6 +1158,7 @@ DoCopy(const CopyStmt *stmt, const char *queryString) /* Close down the query and free resources. */ ExecutorEnd(cstate->queryDesc); FreeQueryDesc(cstate->queryDesc); + PopActiveSnapshot(); } /* Clean up storage (probably not really necessary) */ @@ -1390,7 +1388,7 @@ CopyTo(CopyState cstate) values = (Datum *) palloc(num_phys_attrs * sizeof(Datum)); nulls = (bool *) palloc(num_phys_attrs * sizeof(bool)); - scandesc = heap_beginscan(cstate->rel, ActiveSnapshot, 0, NULL); + scandesc = heap_beginscan(cstate->rel, GetActiveSnapshot(), 0, NULL); while ((tuple = heap_getnext(scandesc, ForwardScanDirection)) != NULL) { -- cgit v1.2.3