diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-03-23 19:53:52 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-03-23 19:53:52 +0000 |
commit | 547b6e537aa8bbae83a8a4c4d0d7f216390bdb9c (patch) | |
tree | 0a8e84561de60017cdbcb2080aa444706c1af404 /src/backend/utils/cache | |
parent | 4c35ec53a9e8e9c5496b2e33c6b568c0cfbdb7e3 (diff) | |
download | postgresql-547b6e537aa8bbae83a8a4c4d0d7f216390bdb9c.tar.gz postgresql-547b6e537aa8bbae83a8a4c4d0d7f216390bdb9c.zip |
Fix plancache so that any required replanning is done with the same
search_path that was active when the plan was first made. To do this,
improve namespace.c to support a stack of "override" search path settings
(we must have a stack since nested replan events are entirely possible).
This facility replaces the "special namespace" hack formerly used by
CREATE SCHEMA, and should be able to support per-function search path
settings as well.
Diffstat (limited to 'src/backend/utils/cache')
-rw-r--r-- | src/backend/utils/cache/plancache.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c index 4648b05803e..4ff2f745c31 100644 --- a/src/backend/utils/cache/plancache.c +++ b/src/backend/utils/cache/plancache.c @@ -33,13 +33,14 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.3 2007/03/19 23:38:29 wieck Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.4 2007/03/23 19:53:51 tgl Exp $ * *------------------------------------------------------------------------- */ #include "postgres.h" #include "utils/plancache.h" +#include "catalog/namespace.h" #include "executor/executor.h" #include "optimizer/clauses.h" #include "storage/lmgr.h" @@ -120,6 +121,7 @@ CreateCachedPlan(Node *raw_parse_tree, bool fixed_result) { CachedPlanSource *plansource; + OverrideSearchPath *search_path; MemoryContext source_context; MemoryContext oldcxt; @@ -134,6 +136,12 @@ CreateCachedPlan(Node *raw_parse_tree, ALLOCSET_SMALL_MAXSIZE); /* + * Fetch current search_path into new context, but do any recalculation + * work required in caller's context. + */ + search_path = GetOverrideSearchPath(source_context); + + /* * Create and fill the CachedPlanSource struct within the new context. */ oldcxt = MemoryContextSwitchTo(source_context); @@ -151,6 +159,7 @@ CreateCachedPlan(Node *raw_parse_tree, plansource->num_params = num_params; plansource->fully_planned = fully_planned; plansource->fixed_result = fixed_result; + plansource->search_path = search_path; plansource->generation = 0; /* StoreCachedPlan will increment */ plansource->resultDesc = PlanCacheComputeResultDesc(stmt_list); plansource->plan = NULL; @@ -209,9 +218,16 @@ FastCreateCachedPlan(Node *raw_parse_tree, MemoryContext context) { CachedPlanSource *plansource; + OverrideSearchPath *search_path; MemoryContext oldcxt; /* + * Fetch current search_path into given context, but do any recalculation + * work required in caller's context. + */ + search_path = GetOverrideSearchPath(context); + + /* * Create and fill the CachedPlanSource struct within the given context. */ oldcxt = MemoryContextSwitchTo(context); @@ -223,6 +239,7 @@ FastCreateCachedPlan(Node *raw_parse_tree, plansource->num_params = num_params; plansource->fully_planned = fully_planned; plansource->fixed_result = fixed_result; + plansource->search_path = search_path; plansource->generation = 0; /* StoreCachedPlan will increment */ plansource->resultDesc = PlanCacheComputeResultDesc(stmt_list); plansource->plan = NULL; @@ -421,6 +438,12 @@ RevalidateCachedPlan(CachedPlanSource *plansource, bool useResOwner) TupleDesc resultDesc; /* + * Restore the search_path that was in use when the plan was made. + * (XXX is there anything else we really need to restore?) + */ + PushOverrideSearchPath(plansource->search_path); + + /* * Run parse analysis and rule rewriting. The parser tends to * scribble on its input, so we must copy the raw parse tree to * prevent corruption of the cache. Note that we do not use @@ -469,6 +492,9 @@ RevalidateCachedPlan(CachedPlanSource *plansource, bool useResOwner) MemoryContextSwitchTo(oldcxt); } + /* Now we can restore current search path */ + PopOverrideSearchPath(); + /* * Store the plans into the plancache entry, advancing the generation * count. |