1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-11 20:28:21 +03:00

Extend EXPLAIN to allow generic options to be specified.

The original syntax made it difficult to add options without making them
into reserved words.  This change parenthesizes the options to avoid that
problem, and makes provision for an explicit (and perhaps non-Boolean)
value for each option.  The original syntax is still supported, but only
for the two original options ANALYZE and VERBOSE.

As a test case, add a COSTS option that can suppress the planner cost
estimates.  This may be useful for including EXPLAIN output in the regression
tests, which are otherwise unable to cope with cross-platform variations in
cost estimates.

Robert Haas
This commit is contained in:
Tom Lane
2009-07-26 23:34:18 +00:00
parent a07e5acebb
commit d4382c4ae7
12 changed files with 282 additions and 156 deletions

View File

@ -6,7 +6,7 @@
* Copyright (c) 2008-2009, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.5 2009/06/11 14:48:50 momjian Exp $
* $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.6 2009/07/26 23:34:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -196,16 +196,17 @@ explain_ExecutorEnd(QueryDesc *queryDesc)
msec = queryDesc->totaltime->total * 1000.0;
if (msec >= auto_explain_log_min_duration)
{
StringInfoData buf;
ExplainState es;
initStringInfo(&buf);
ExplainPrintPlan(&buf, queryDesc,
queryDesc->doInstrument && auto_explain_log_analyze,
auto_explain_log_verbose);
ExplainInitState(&es);
es.analyze = (queryDesc->doInstrument && auto_explain_log_analyze);
es.verbose = auto_explain_log_verbose;
ExplainPrintPlan(&es, queryDesc);
/* Remove last line break */
if (buf.len > 0 && buf.data[buf.len - 1] == '\n')
buf.data[--buf.len] = '\0';
if (es.str->len > 0 && es.str->data[es.str->len - 1] == '\n')
es.str->data[--es.str->len] = '\0';
/*
* Note: we rely on the existing logging of context or
@ -215,9 +216,9 @@ explain_ExecutorEnd(QueryDesc *queryDesc)
*/
ereport(LOG,
(errmsg("duration: %.3f ms plan:\n%s",
msec, buf.data)));
msec, es.str->data)));
pfree(buf.data);
pfree(es.str->data);
}
}