mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
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.
This commit is contained in:
28
src/backend/utils/cache/plancache.c
vendored
28
src/backend/utils/cache/plancache.c
vendored
@ -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;
|
||||
|
||||
@ -133,6 +135,12 @@ CreateCachedPlan(Node *raw_parse_tree,
|
||||
ALLOCSET_SMALL_INITSIZE,
|
||||
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.
|
||||
*/
|
||||
@ -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,8 +218,15 @@ 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.
|
||||
*/
|
||||
@ -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;
|
||||
@ -420,6 +437,12 @@ RevalidateCachedPlan(CachedPlanSource *plansource, bool useResOwner)
|
||||
List *slist;
|
||||
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
|
||||
@ -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.
|
||||
|
Reference in New Issue
Block a user