diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-07-18 20:26:06 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-07-18 20:26:06 +0000 |
commit | a1c692358bb9958b7cb67e4284aae6aa3aabf714 (patch) | |
tree | 30e5c80eabbbce990ec44aac20f37ff3d8fd80ca /src/backend/parser | |
parent | 6cc88f0af5b12b22ce1826a26b1a953c434bd165 (diff) | |
download | postgresql-a1c692358bb9958b7cb67e4284aae6aa3aabf714.tar.gz postgresql-a1c692358bb9958b7cb67e4284aae6aa3aabf714.zip |
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
Diffstat (limited to 'src/backend/parser')
-rw-r--r-- | src/backend/parser/analyze.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 831a7899188..520b5037255 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -17,7 +17,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.372 2008/06/19 00:46:04 alvherre Exp $ + * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.373 2008/07/18 20:26:06 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -72,9 +72,6 @@ static bool check_parameter_resolution_walker(Node *node, * parse_analyze * Analyze a raw parse tree and transform it to Query form. * - * If available, pass the source text from which the raw parse tree was - * generated; it's OK to pass NULL if this is not available. - * * Optionally, information about $n parameter types can be supplied. * References to $n indexes not defined by paramTypes[] are disallowed. * @@ -89,6 +86,8 @@ parse_analyze(Node *parseTree, const char *sourceText, ParseState *pstate = make_parsestate(NULL); Query *query; + Assert(sourceText != NULL); /* required as of 8.4 */ + pstate->p_sourcetext = sourceText; pstate->p_paramtypes = paramTypes; pstate->p_numparams = numParams; @@ -115,6 +114,8 @@ parse_analyze_varparams(Node *parseTree, const char *sourceText, ParseState *pstate = make_parsestate(NULL); Query *query; + Assert(sourceText != NULL); /* required as of 8.4 */ + pstate->p_sourcetext = sourceText; pstate->p_paramtypes = *paramTypes; pstate->p_numparams = *numParams; |