On 02/11/2012 03:22 PM, Tom Lane wrote:
Andrew Dunstan<and...@dunslane.net>  writes:
But ExplainBeginOutput says:
            /* top-level structure is an array of plans */
            appendStringInfoChar(es->str, '[');
Now that's not true in the auto-explain case, which prints one query +
one plan.
What about queries that expand to multiple plans because of rules?

... and the answer is it logs them in separate pieces of JSON.

Since this is an exposed API, I don't think we can just change it. We
probably need a new API that does the right thing for beginning and
ending auto_explain output. (ExplainBeginLabeledOutput?)
I'm inclined to think that this is auto_explain's error, not that of
the core code, ie we should be changing the output.


Well, maybe this is more to your taste, although it strikes me as more than something of a kludge. At least it's short :-)



*** a/contrib/auto_explain/auto_explain.c
--- b/contrib/auto_explain/auto_explain.c
*** 299,304 **** explain_ExecutorEnd(QueryDesc *queryDesc)
--- 299,311 ----
  			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] = '}';
+ 			}
  			 * Note: we rely on the existing logging of context or
  			 * debug_query_string to identify just which statement is being
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:

Reply via email to