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/tcop/postgres.c | |
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/tcop/postgres.c')
-rw-r--r-- | src/backend/tcop/postgres.c | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index c6d6e1b55d9..242388f2cb0 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.553 2008/05/15 00:17:40 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.554 2008/07/18 20:26:06 tgl Exp $ * * NOTES * this is the "main" module of the postgres backend and @@ -1388,9 +1388,9 @@ exec_bind_message(StringInfo input_message) /* * Report query to various monitoring facilities. */ - debug_query_string = psrc->query_string ? psrc->query_string : "<BIND>"; + debug_query_string = psrc->query_string; - pgstat_report_activity(debug_query_string); + pgstat_report_activity(psrc->query_string); set_ps_display("BIND", false); @@ -1466,10 +1466,8 @@ exec_bind_message(StringInfo input_message) */ oldContext = MemoryContextSwitchTo(PortalGetHeapMemory(portal)); - /* Copy the plan's query string, if available, into the portal */ - query_string = psrc->query_string; - if (query_string) - query_string = pstrdup(query_string); + /* Copy the plan's query string into the portal */ + query_string = pstrdup(psrc->query_string); /* Likewise make a copy of the statement name, unless it's unnamed */ if (stmt_name[0]) @@ -1714,7 +1712,7 @@ exec_bind_message(StringInfo input_message) *stmt_name ? stmt_name : "<unnamed>", *portal_name ? "/" : "", *portal_name ? portal_name : "", - psrc->query_string ? psrc->query_string : "<source not stored>"), + psrc->query_string), errhidestmt(true), errdetail_params(params))); break; @@ -1780,7 +1778,7 @@ exec_execute_message(const char *portal_name, long max_rows) */ if (is_xact_command) { - sourceText = portal->sourceText ? pstrdup(portal->sourceText) : NULL; + sourceText = pstrdup(portal->sourceText); if (portal->prepStmtName) prepStmtName = pstrdup(portal->prepStmtName); else @@ -1805,9 +1803,9 @@ exec_execute_message(const char *portal_name, long max_rows) /* * Report query to various monitoring facilities. */ - debug_query_string = sourceText ? sourceText : "<EXECUTE>"; + debug_query_string = sourceText; - pgstat_report_activity(debug_query_string); + pgstat_report_activity(sourceText); set_ps_display(portal->commandTag, false); @@ -1840,15 +1838,14 @@ exec_execute_message(const char *portal_name, long max_rows) if (check_log_statement(portal->stmts)) { ereport(LOG, - (errmsg("%s %s%s%s%s%s", + (errmsg("%s %s%s%s: %s", execute_is_fetch ? _("execute fetch from") : _("execute"), prepStmtName, *portal_name ? "/" : "", *portal_name ? portal_name : "", - sourceText ? ": " : "", - sourceText ? sourceText : ""), + sourceText), errhidestmt(true), errdetail_params(portalParams))); was_logged = true; @@ -1924,7 +1921,7 @@ exec_execute_message(const char *portal_name, long max_rows) break; case 2: ereport(LOG, - (errmsg("duration: %s ms %s %s%s%s%s%s", + (errmsg("duration: %s ms %s %s%s%s: %s", msec_str, execute_is_fetch ? _("execute fetch from") : @@ -1932,8 +1929,7 @@ exec_execute_message(const char *portal_name, long max_rows) prepStmtName, *portal_name ? "/" : "", *portal_name ? portal_name : "", - sourceText ? ": " : "", - sourceText ? sourceText : ""), + sourceText), errhidestmt(true), errdetail_params(portalParams))); break; @@ -2049,7 +2045,7 @@ errdetail_execute(List *raw_parsetree_list) PreparedStatement *pstmt; pstmt = FetchPreparedStatement(stmt->name, false); - if (pstmt && pstmt->plansource->query_string) + if (pstmt) { errdetail("prepare: %s", pstmt->plansource->query_string); return 0; |