diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2008-05-12 20:02:02 +0000 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2008-05-12 20:02:02 +0000 |
commit | 5da9da71c44f27ba48fdad08ef263bf70e43e689 (patch) | |
tree | d8afb52acd9386a59c1862a265d4f8e6d2fdbaba /src/backend/utils/cache/plancache.c | |
parent | aa82790fcab98b8d3d4eca2e2f6f7bfce57870bc (diff) | |
download | postgresql-5da9da71c44f27ba48fdad08ef263bf70e43e689.tar.gz postgresql-5da9da71c44f27ba48fdad08ef263bf70e43e689.zip |
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.
Diffstat (limited to 'src/backend/utils/cache/plancache.c')
-rw-r--r-- | src/backend/utils/cache/plancache.c | 57 |
1 files changed, 10 insertions, 47 deletions
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c index 728b6262110..dbe889cb6ce 100644 --- a/src/backend/utils/cache/plancache.c +++ b/src/backend/utils/cache/plancache.c @@ -33,7 +33,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.17 2008/03/26 18:48:59 alvherre Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.18 2008/05/12 20:02:02 alvherre Exp $ * *------------------------------------------------------------------------- */ @@ -71,7 +71,6 @@ static List *cached_plans_list = NIL; static void StoreCachedPlan(CachedPlanSource *plansource, List *stmt_list, MemoryContext plan_context); -static List *do_planning(List *querytrees, int cursorOptions); static void AcquireExecutorLocks(List *stmt_list, bool acquire); static void AcquirePlannerLocks(List *stmt_list, bool acquire); static void LockRelid(Oid relid, LOCKMODE lockmode, void *arg); @@ -481,8 +480,15 @@ RevalidateCachedPlan(CachedPlanSource *plansource, bool useResOwner) if (plansource->fully_planned) { - /* Generate plans for queries */ - slist = do_planning(slist, plansource->cursor_options); + /* + * Generate plans for queries. + * + * If a snapshot is already set (the normal case), we can just use + * that for planning. But if it isn't, we have to tell + * pg_plan_queries to make a snap if it needs one. + */ + slist = pg_plan_queries(slist, plansource->cursor_options, + NULL, !ActiveSnapshotSet()); } /* @@ -538,49 +544,6 @@ RevalidateCachedPlan(CachedPlanSource *plansource, bool useResOwner) } /* - * Invoke the planner on some rewritten queries. This is broken out of - * RevalidateCachedPlan just to avoid plastering "volatile" all over that - * function's variables. - */ -static List * -do_planning(List *querytrees, int cursorOptions) -{ - List *stmt_list; - - /* - * If a snapshot is already set (the normal case), we can just use that - * for planning. But if it isn't, we have to tell pg_plan_queries to make - * a snap if it needs one. In that case we should arrange to reset - * ActiveSnapshot afterward, to ensure that RevalidateCachedPlan has no - * caller-visible effects on the snapshot. Having to replan is an unusual - * case, and it seems a really bad idea for RevalidateCachedPlan to affect - * the snapshot only in unusual cases. (Besides, the snap might have been - * created in a short-lived context.) - */ - if (ActiveSnapshot != NULL) - stmt_list = pg_plan_queries(querytrees, cursorOptions, NULL, false); - else - { - PG_TRY(); - { - stmt_list = pg_plan_queries(querytrees, cursorOptions, NULL, true); - } - PG_CATCH(); - { - /* Restore global vars and propagate error */ - ActiveSnapshot = NULL; - PG_RE_THROW(); - } - PG_END_TRY(); - - ActiveSnapshot = NULL; - } - - return stmt_list; -} - - -/* * ReleaseCachedPlan: release active use of a cached plan. * * This decrements the reference count, and frees the plan if the count |