mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
Adjust things so that the query_string of a cached plan and the sourceText of
a portal are never NULL, but reliably provide the source text of the query. It turns out that there was only one place that was really taking a short-cut, which was the 'EXECUTE' utility statement. That doesn't seem like a sufficiently critical performance hotspot to justify not offering a guarantee of validity of the portal source text. Fix it to copy the source text over from the cached plan. Add Asserts in the places that set up cached plans and portals to reject null source strings, and simplify a bunch of places that formerly needed to guard against nulls. There may be a few places that cons up statements for execution without having any source text at all; I found one such in ConvertTriggerToFK(). It seems sufficient to inject a phony source string in such a case, for instance ProcessUtility((Node *) atstmt, "(generated ALTER TABLE ADD FOREIGN KEY command)", NULL, false, None_Receiver, NULL); We should take a second look at the usage of debug_query_string, particularly the recently added current_query() SQL function. ITAGAKI Takahiro and Tom Lane
This commit is contained in:
11
src/backend/utils/cache/plancache.c
vendored
11
src/backend/utils/cache/plancache.c
vendored
@ -33,7 +33,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.18 2008/05/12 20:02:02 alvherre Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.19 2008/07/18 20:26:06 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -104,8 +104,7 @@ InitPlanCache(void)
|
||||
* about all that we do here is copy it into permanent storage.
|
||||
*
|
||||
* raw_parse_tree: output of raw_parser()
|
||||
* query_string: original query text (can be NULL if not available, but
|
||||
* that is discouraged because it degrades error message quality)
|
||||
* query_string: original query text (as of PG 8.4, must not be NULL)
|
||||
* commandTag: compile-time-constant tag for query, or NULL if empty query
|
||||
* param_types: array of parameter type OIDs, or NULL if none
|
||||
* num_params: number of parameters
|
||||
@ -130,6 +129,8 @@ CreateCachedPlan(Node *raw_parse_tree,
|
||||
MemoryContext source_context;
|
||||
MemoryContext oldcxt;
|
||||
|
||||
Assert(query_string != NULL); /* required as of 8.4 */
|
||||
|
||||
/*
|
||||
* Make a dedicated memory context for the CachedPlanSource and its
|
||||
* subsidiary data. We expect it can be pretty small.
|
||||
@ -152,7 +153,7 @@ CreateCachedPlan(Node *raw_parse_tree,
|
||||
oldcxt = MemoryContextSwitchTo(source_context);
|
||||
plansource = (CachedPlanSource *) palloc(sizeof(CachedPlanSource));
|
||||
plansource->raw_parse_tree = copyObject(raw_parse_tree);
|
||||
plansource->query_string = query_string ? pstrdup(query_string) : NULL;
|
||||
plansource->query_string = pstrdup(query_string);
|
||||
plansource->commandTag = commandTag; /* no copying needed */
|
||||
if (num_params > 0)
|
||||
{
|
||||
@ -228,6 +229,8 @@ FastCreateCachedPlan(Node *raw_parse_tree,
|
||||
OverrideSearchPath *search_path;
|
||||
MemoryContext oldcxt;
|
||||
|
||||
Assert(query_string != NULL); /* required as of 8.4 */
|
||||
|
||||
/*
|
||||
* Fetch current search_path into given context, but do any recalculation
|
||||
* work required in caller's context.
|
||||
|
Reference in New Issue
Block a user