diff options
Diffstat (limited to 'src/backend/utils/cache/plancache.c')
-rw-r--r-- | src/backend/utils/cache/plancache.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c index b66c112926e..bbfdd888c1c 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.15 2008/01/01 19:45:53 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.15.2.1 2008/09/15 23:37:49 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -602,6 +602,44 @@ ReleaseCachedPlan(CachedPlan *plan, bool useResOwner) } /* + * CachedPlanIsValid: test whether the plan within a CachedPlanSource is + * currently valid (that is, not marked as being in need of revalidation). + * + * This result is only trustworthy (ie, free from race conditions) if + * the caller has acquired locks on all the relations used in the plan. + */ +bool +CachedPlanIsValid(CachedPlanSource *plansource) +{ + CachedPlan *plan; + + /* Validity check that we were given a CachedPlanSource */ + Assert(list_member_ptr(cached_plans_list, plansource)); + + plan = plansource->plan; + if (plan && !plan->dead) + { + /* + * Plan must have positive refcount because it is referenced by + * plansource; so no need to fear it disappears under us here. + */ + Assert(plan->refcount > 0); + + /* + * Although we don't want to acquire locks here, it still seems + * useful to check for expiration of a transient plan. + */ + if (TransactionIdIsValid(plan->saved_xmin) && + !TransactionIdEquals(plan->saved_xmin, TransactionXmin)) + plan->dead = true; + else + return true; + } + + return false; +} + +/* * AcquireExecutorLocks: acquire locks needed for execution of a fully-planned * cached plan; or release them if acquire is false. */ |