diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2015-01-15 13:39:33 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2015-01-15 13:39:33 -0500 |
commit | 8e166e164c7c4531d7eb150d836aa2357989237a (patch) | |
tree | 1cf5abe76f86c4a4bee68e714b03aeebbe0dafa8 /contrib/auto_explain/auto_explain.c | |
parent | a5cd70dcbc268381e13cb0b2973b5732856d186f (diff) | |
download | postgresql-8e166e164c7c4531d7eb150d836aa2357989237a.tar.gz postgresql-8e166e164c7c4531d7eb150d836aa2357989237a.zip |
Rearrange explain.c's API so callers need not embed sizeof(ExplainState).
The folly of the previous arrangement was just demonstrated: there's no
convenient way to add fields to ExplainState without breaking ABI, even
if callers have no need to touch those fields. Since we might well need
to do that again someday in back branches, let's change things so that
only explain.c has to have sizeof(ExplainState) compiled into it. This
costs one extra palloc() per EXPLAIN operation, which is surely pretty
negligible.
Diffstat (limited to 'contrib/auto_explain/auto_explain.c')
-rw-r--r-- | contrib/auto_explain/auto_explain.c | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/contrib/auto_explain/auto_explain.c b/contrib/auto_explain/auto_explain.c index 179b33a7938..2a184ed886f 100644 --- a/contrib/auto_explain/auto_explain.c +++ b/contrib/auto_explain/auto_explain.c @@ -294,32 +294,31 @@ explain_ExecutorEnd(QueryDesc *queryDesc) msec = queryDesc->totaltime->total * 1000.0; if (msec >= auto_explain_log_min_duration) { - ExplainState es; - - ExplainInitState(&es); - es.analyze = (queryDesc->instrument_options && auto_explain_log_analyze); - es.verbose = auto_explain_log_verbose; - es.buffers = (es.analyze && auto_explain_log_buffers); - es.timing = (es.analyze && auto_explain_log_timing); - es.summary = es.analyze; - es.format = auto_explain_log_format; - - ExplainBeginOutput(&es); - ExplainQueryText(&es, queryDesc); - ExplainPrintPlan(&es, queryDesc); - if (es.analyze && auto_explain_log_triggers) - ExplainPrintTriggers(&es, queryDesc); - ExplainEndOutput(&es); + ExplainState *es = NewExplainState(); + + es->analyze = (queryDesc->instrument_options && auto_explain_log_analyze); + es->verbose = auto_explain_log_verbose; + es->buffers = (es->analyze && auto_explain_log_buffers); + es->timing = (es->analyze && auto_explain_log_timing); + es->summary = es->analyze; + es->format = auto_explain_log_format; + + ExplainBeginOutput(es); + ExplainQueryText(es, queryDesc); + ExplainPrintPlan(es, queryDesc); + if (es->analyze && auto_explain_log_triggers) + ExplainPrintTriggers(es, queryDesc); + ExplainEndOutput(es); /* Remove last line break */ - if (es.str->len > 0 && es.str->data[es.str->len - 1] == '\n') - es.str->data[--es.str->len] = '\0'; + if (es->str->len > 0 && es->str->data[es->str->len - 1] == '\n') + es->str->data[--es->str->len] = '\0'; /* Fix JSON to output an object */ if (auto_explain_log_format == EXPLAIN_FORMAT_JSON) { - es.str->data[0] = '{'; - es.str->data[es.str->len - 1] = '}'; + es->str->data[0] = '{'; + es->str->data[es->str->len - 1] = '}'; } /* @@ -330,10 +329,10 @@ explain_ExecutorEnd(QueryDesc *queryDesc) */ ereport(LOG, (errmsg("duration: %.3f ms plan:\n%s", - msec, es.str->data), + msec, es->str->data), errhidestmt(true))); - pfree(es.str->data); + pfree(es->str->data); } } |