diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-09-15 23:37:40 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-09-15 23:37:40 +0000 |
commit | 1cd935609fd47c17f60d8c30b745be936f21f4c3 (patch) | |
tree | c59926dc010ec23131694e0657909506c459a1a1 /src/backend/executor/spi.c | |
parent | 448950b37b19714d5b4e64ca7b8ea89f50d81974 (diff) | |
download | postgresql-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/executor/spi.c')
-rw-r--r-- | src/backend/executor/spi.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index 443ee57e682..302109f24f2 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.197 2008/07/18 20:26:06 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.198 2008/09/15 23:37:39 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1368,6 +1368,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 |