aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/cache
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-09-15 23:37:40 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-09-15 23:37:40 +0000
commit1cd935609fd47c17f60d8c30b745be936f21f4c3 (patch)
treec59926dc010ec23131694e0657909506c459a1a1 /src/backend/utils/cache
parent448950b37b19714d5b4e64ca7b8ea89f50d81974 (diff)
downloadpostgresql-1cd935609fd47c17f60d8c30b745be936f21f4c3.tar.gz
postgresql-1cd935609fd47c17f60d8c30b745be936f21f4c3.zip
Fix caching of foreign-key-checking queries so that when a replan is needed,
we regenerate the SQL query text not merely the plan derived from it. This is needed to handle contingencies such as renaming of a table or column used in an FK. Pre-8.3, such cases worked despite the lack of replanning (because the cached plan needn't actually change), so this is a regression. Per bug #4417 from Benjamin Bihler.
Diffstat (limited to 'src/backend/utils/cache')
-rw-r--r--src/backend/utils/cache/plancache.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c
index bf1adf16ecc..48addf3f539 100644
--- a/src/backend/utils/cache/plancache.c
+++ b/src/backend/utils/cache/plancache.c
@@ -35,7 +35,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.21 2008/09/09 18:58:08 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.22 2008/09/15 23:37:39 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -572,6 +572,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.
*/