mirror of
https://github.com/postgres/postgres.git
synced 2025-10-19 15:49:24 +03:00
Run pgindent on 9.2 source tree in preparation for first 9.3
commit-fest.
This commit is contained in:
82
src/backend/utils/cache/plancache.c
vendored
82
src/backend/utils/cache/plancache.c
vendored
@@ -11,7 +11,7 @@
|
||||
* The logic for choosing generic or custom plans is in choose_custom_plan,
|
||||
* which see for comments.
|
||||
*
|
||||
* Cache invalidation is driven off sinval events. Any CachedPlanSource
|
||||
* Cache invalidation is driven off sinval events. Any CachedPlanSource
|
||||
* that matches the event is marked invalid, as is its generic CachedPlan
|
||||
* if it has one. When (and if) the next demand for a cached plan occurs,
|
||||
* parse analysis and rewrite is repeated to build a new valid query tree,
|
||||
@@ -77,9 +77,9 @@ static void ReleaseGenericPlan(CachedPlanSource *plansource);
|
||||
static List *RevalidateCachedQuery(CachedPlanSource *plansource);
|
||||
static bool CheckCachedPlan(CachedPlanSource *plansource);
|
||||
static CachedPlan *BuildCachedPlan(CachedPlanSource *plansource, List *qlist,
|
||||
ParamListInfo boundParams);
|
||||
ParamListInfo boundParams);
|
||||
static bool choose_custom_plan(CachedPlanSource *plansource,
|
||||
ParamListInfo boundParams);
|
||||
ParamListInfo boundParams);
|
||||
static double cached_plan_cost(CachedPlan *plan);
|
||||
static void AcquireExecutorLocks(List *stmt_list, bool acquire);
|
||||
static void AcquirePlannerLocks(List *stmt_list, bool acquire);
|
||||
@@ -111,7 +111,7 @@ InitPlanCache(void)
|
||||
* CreateCachedPlan: initially create a plan cache entry.
|
||||
*
|
||||
* Creation of a cached plan is divided into two steps, CreateCachedPlan and
|
||||
* CompleteCachedPlan. CreateCachedPlan should be called after running the
|
||||
* CompleteCachedPlan. CreateCachedPlan should be called after running the
|
||||
* query through raw_parser, but before doing parse analysis and rewrite;
|
||||
* CompleteCachedPlan is called after that. The reason for this arrangement
|
||||
* is that it can save one round of copying of the raw parse tree, since
|
||||
@@ -198,13 +198,13 @@ CreateCachedPlan(Node *raw_parse_tree,
|
||||
* CompleteCachedPlan: second step of creating a plan cache entry.
|
||||
*
|
||||
* Pass in the analyzed-and-rewritten form of the query, as well as the
|
||||
* required subsidiary data about parameters and such. All passed values will
|
||||
* required subsidiary data about parameters and such. All passed values will
|
||||
* be copied into the CachedPlanSource's memory, except as specified below.
|
||||
* After this is called, GetCachedPlan can be called to obtain a plan, and
|
||||
* optionally the CachedPlanSource can be saved using SaveCachedPlan.
|
||||
*
|
||||
* If querytree_context is not NULL, the querytree_list must be stored in that
|
||||
* context (but the other parameters need not be). The querytree_list is not
|
||||
* context (but the other parameters need not be). The querytree_list is not
|
||||
* copied, rather the given context is kept as the initial query_context of
|
||||
* the CachedPlanSource. (It should have been created as a child of the
|
||||
* caller's working memory context, but it will now be reparented to belong
|
||||
@@ -277,8 +277,8 @@ CompleteCachedPlan(CachedPlanSource *plansource,
|
||||
|
||||
/*
|
||||
* Use the planner machinery to extract dependencies. Data is saved in
|
||||
* query_context. (We assume that not a lot of extra cruft is created
|
||||
* by this call.)
|
||||
* query_context. (We assume that not a lot of extra cruft is created by
|
||||
* this call.)
|
||||
*/
|
||||
extract_query_dependencies((Node *) querytree_list,
|
||||
&plansource->relationOids,
|
||||
@@ -327,7 +327,7 @@ CompleteCachedPlan(CachedPlanSource *plansource,
|
||||
*
|
||||
* This is guaranteed not to throw error; callers typically depend on that
|
||||
* since this is called just before or just after adding a pointer to the
|
||||
* CachedPlanSource to some permanent data structure of their own. Up until
|
||||
* CachedPlanSource to some permanent data structure of their own. Up until
|
||||
* this is done, a CachedPlanSource is just transient data that will go away
|
||||
* automatically on transaction abort.
|
||||
*/
|
||||
@@ -341,16 +341,16 @@ SaveCachedPlan(CachedPlanSource *plansource)
|
||||
|
||||
/*
|
||||
* In typical use, this function would be called before generating any
|
||||
* plans from the CachedPlanSource. If there is a generic plan, moving
|
||||
* it into CacheMemoryContext would be pretty risky since it's unclear
|
||||
* plans from the CachedPlanSource. If there is a generic plan, moving it
|
||||
* into CacheMemoryContext would be pretty risky since it's unclear
|
||||
* whether the caller has taken suitable care with making references
|
||||
* long-lived. Best thing to do seems to be to discard the plan.
|
||||
* long-lived. Best thing to do seems to be to discard the plan.
|
||||
*/
|
||||
ReleaseGenericPlan(plansource);
|
||||
|
||||
/*
|
||||
* Reparent the source memory context under CacheMemoryContext so that
|
||||
* it will live indefinitely. The query_context follows along since it's
|
||||
* Reparent the source memory context under CacheMemoryContext so that it
|
||||
* will live indefinitely. The query_context follows along since it's
|
||||
* already a child of the other one.
|
||||
*/
|
||||
MemoryContextSetParent(plansource->context, CacheMemoryContext);
|
||||
@@ -474,8 +474,8 @@ RevalidateCachedQuery(CachedPlanSource *plansource)
|
||||
}
|
||||
|
||||
/*
|
||||
* Discard the no-longer-useful query tree. (Note: we don't want to
|
||||
* do this any earlier, else we'd not have been able to release locks
|
||||
* Discard the no-longer-useful query tree. (Note: we don't want to do
|
||||
* this any earlier, else we'd not have been able to release locks
|
||||
* correctly in the race condition case.)
|
||||
*/
|
||||
plansource->is_valid = false;
|
||||
@@ -484,14 +484,14 @@ RevalidateCachedQuery(CachedPlanSource *plansource)
|
||||
plansource->invalItems = NIL;
|
||||
|
||||
/*
|
||||
* Free the query_context. We don't really expect MemoryContextDelete to
|
||||
* Free the query_context. We don't really expect MemoryContextDelete to
|
||||
* fail, but just in case, make sure the CachedPlanSource is left in a
|
||||
* reasonably sane state. (The generic plan won't get unlinked yet,
|
||||
* but that's acceptable.)
|
||||
* reasonably sane state. (The generic plan won't get unlinked yet, but
|
||||
* that's acceptable.)
|
||||
*/
|
||||
if (plansource->query_context)
|
||||
{
|
||||
MemoryContext qcxt = plansource->query_context;
|
||||
MemoryContext qcxt = plansource->query_context;
|
||||
|
||||
plansource->query_context = NULL;
|
||||
MemoryContextDelete(qcxt);
|
||||
@@ -553,7 +553,7 @@ RevalidateCachedQuery(CachedPlanSource *plansource)
|
||||
PopOverrideSearchPath();
|
||||
|
||||
/*
|
||||
* Check or update the result tupdesc. XXX should we use a weaker
|
||||
* Check or update the result tupdesc. XXX should we use a weaker
|
||||
* condition than equalTupleDescs() here?
|
||||
*
|
||||
* We assume the parameter types didn't change from the first time, so no
|
||||
@@ -596,8 +596,8 @@ RevalidateCachedQuery(CachedPlanSource *plansource)
|
||||
|
||||
/*
|
||||
* Use the planner machinery to extract dependencies. Data is saved in
|
||||
* query_context. (We assume that not a lot of extra cruft is created
|
||||
* by this call.)
|
||||
* query_context. (We assume that not a lot of extra cruft is created by
|
||||
* this call.)
|
||||
*/
|
||||
extract_query_dependencies((Node *) qlist,
|
||||
&plansource->relationOids,
|
||||
@@ -612,12 +612,12 @@ RevalidateCachedQuery(CachedPlanSource *plansource)
|
||||
plansource->query_list = qlist;
|
||||
|
||||
/*
|
||||
* Note: we do not reset generic_cost or total_custom_cost, although
|
||||
* we could choose to do so. If the DDL or statistics change that
|
||||
* prompted the invalidation meant a significant change in the cost
|
||||
* estimates, it would be better to reset those variables and start
|
||||
* fresh; but often it doesn't, and we're better retaining our hard-won
|
||||
* knowledge about the relative costs.
|
||||
* Note: we do not reset generic_cost or total_custom_cost, although we
|
||||
* could choose to do so. If the DDL or statistics change that prompted
|
||||
* the invalidation meant a significant change in the cost estimates, it
|
||||
* would be better to reset those variables and start fresh; but often it
|
||||
* doesn't, and we're better retaining our hard-won knowledge about the
|
||||
* relative costs.
|
||||
*/
|
||||
|
||||
plansource->is_valid = true;
|
||||
@@ -728,7 +728,7 @@ BuildCachedPlan(CachedPlanSource *plansource, List *qlist,
|
||||
* we ought to be holding sufficient locks to prevent any invalidation.
|
||||
* However, if we're building a custom plan after having built and
|
||||
* rejected a generic plan, it's possible to reach here with is_valid
|
||||
* false due to an invalidation while making the generic plan. In theory
|
||||
* false due to an invalidation while making the generic plan. In theory
|
||||
* the invalidation must be a false positive, perhaps a consequence of an
|
||||
* sinval reset event or the CLOBBER_CACHE_ALWAYS debug code. But for
|
||||
* safety, let's treat it as real and redo the RevalidateCachedQuery call.
|
||||
@@ -770,10 +770,10 @@ BuildCachedPlan(CachedPlanSource *plansource, List *qlist,
|
||||
}
|
||||
|
||||
/*
|
||||
* The planner may try to call SPI-using functions, which causes a
|
||||
* problem if we're already inside one. Rather than expect all
|
||||
* SPI-using code to do SPI_push whenever a replan could happen,
|
||||
* it seems best to take care of the case here.
|
||||
* The planner may try to call SPI-using functions, which causes a problem
|
||||
* if we're already inside one. Rather than expect all SPI-using code to
|
||||
* do SPI_push whenever a replan could happen, it seems best to take care
|
||||
* of the case here.
|
||||
*/
|
||||
spi_pushed = SPI_push_conditional();
|
||||
|
||||
@@ -865,8 +865,8 @@ choose_custom_plan(CachedPlanSource *plansource, ParamListInfo boundParams)
|
||||
/*
|
||||
* Prefer generic plan if it's less than 10% more expensive than average
|
||||
* custom plan. This threshold is a bit arbitrary; it'd be better if we
|
||||
* had some means of comparing planning time to the estimated runtime
|
||||
* cost differential.
|
||||
* had some means of comparing planning time to the estimated runtime cost
|
||||
* differential.
|
||||
*
|
||||
* Note that if generic_cost is -1 (indicating we've not yet determined
|
||||
* the generic plan cost), we'll always prefer generic at this point.
|
||||
@@ -966,7 +966,7 @@ GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams,
|
||||
{
|
||||
/* otherwise, it should be a sibling of the plansource */
|
||||
MemoryContextSetParent(plan->context,
|
||||
MemoryContextGetParent(plansource->context));
|
||||
MemoryContextGetParent(plansource->context));
|
||||
}
|
||||
/* Update generic_cost whenever we make a new generic plan */
|
||||
plansource->generic_cost = cached_plan_cost(plan);
|
||||
@@ -984,7 +984,7 @@ GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams,
|
||||
|
||||
/*
|
||||
* If we choose to plan again, we need to re-copy the query_list,
|
||||
* since the planner probably scribbled on it. We can force
|
||||
* since the planner probably scribbled on it. We can force
|
||||
* BuildCachedPlan to do that by passing NIL.
|
||||
*/
|
||||
qlist = NIL;
|
||||
@@ -1089,7 +1089,7 @@ CachedPlanSetParentContext(CachedPlanSource *plansource,
|
||||
*
|
||||
* This is a convenience routine that does the equivalent of
|
||||
* CreateCachedPlan + CompleteCachedPlan, using the data stored in the
|
||||
* input CachedPlanSource. The result is therefore "unsaved" (regardless
|
||||
* input CachedPlanSource. The result is therefore "unsaved" (regardless
|
||||
* of the state of the source), and we don't copy any generic plan either.
|
||||
* The result will be currently valid, or not, the same as the source.
|
||||
*/
|
||||
@@ -1233,7 +1233,7 @@ AcquireExecutorLocks(List *stmt_list, bool acquire)
|
||||
{
|
||||
/*
|
||||
* Ignore utility statements, except those (such as EXPLAIN) that
|
||||
* contain a parsed-but-not-planned query. Note: it's okay to use
|
||||
* contain a parsed-but-not-planned query. Note: it's okay to use
|
||||
* ScanQueryForLocks, even though the query hasn't been through
|
||||
* rule rewriting, because rewriting doesn't change the query
|
||||
* representation.
|
||||
@@ -1429,7 +1429,7 @@ plan_list_is_transient(List *stmt_list)
|
||||
|
||||
/*
|
||||
* PlanCacheComputeResultDesc: given a list of analyzed-and-rewritten Queries,
|
||||
* determine the result tupledesc it will produce. Returns NULL if the
|
||||
* determine the result tupledesc it will produce. Returns NULL if the
|
||||
* execution will not return tuples.
|
||||
*
|
||||
* Note: the result is created or copied into current memory context.
|
||||
|
Reference in New Issue
Block a user