summaryrefslogtreecommitdiff
path: root/src/backend/executor/spi.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-09-15 23:37:49 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-09-15 23:37:49 +0000
commite4aea74e1924195d73c79dd68fb88eb7914dbd77 (patch)
tree5e219ab0efdce0b7298d1670d0d92318a69b7c35 /src/backend/executor/spi.c
parente5b1eed7c916bbe747ee86da815ebe4ea8bdd643 (diff)
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/executor/spi.c')
-rw-r--r--src/backend/executor/spi.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index f79868630f6..0b404228d80 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.188.2.1 2008/04/02 18:32:00 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.188.2.2 2008/09/15 23:37:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1230,6 +1230,36 @@ SPI_is_cursor_plan(SPIPlanPtr plan)
}
/*
+ * SPI_plan_is_valid --- test whether a SPI plan is currently valid
+ * (that is, not marked as being in need of revalidation).
+ *
+ * See notes for CachedPlanIsValid before using this.
+ */
+bool
+SPI_plan_is_valid(SPIPlanPtr plan)
+{
+ Assert(plan->magic == _SPI_PLAN_MAGIC);
+ if (plan->saved)
+ {
+ ListCell *lc;
+
+ foreach(lc, plan->plancache_list)
+ {
+ CachedPlanSource *plansource = (CachedPlanSource *) lfirst(lc);
+
+ if (!CachedPlanIsValid(plansource))
+ return false;
+ }
+ return true;
+ }
+ else
+ {
+ /* An unsaved plan is assumed valid for its (short) lifetime */
+ return true;
+ }
+}
+
+/*
* SPI_result_code_string --- convert any SPI return code to a string
*
* This is often useful in error messages. Most callers will probably