The attached tiny patch sets the <explain> root element for auto-explain
XML output, so it looks something like this:
<explain xmlns="http://www.postgresql.org/2009/explain">
<Plan>
<Node-Type>Result</Node-Type>
<Startup-Cost>0.00</Startup-Cost>
<Total-Cost>0.01</Total-Cost>
<Plan-Rows>1</Plan-Rows>
<Plan-Width>0</Plan-Width>
</Plan>
</explain>
The JSON output looks like this:
[
"Plan": {
"Node Type": "Result",
"Startup Cost": 0.00,
"Total Cost": 0.01,
"Plan Rows": 1,
"Plan Width": 0
}
]
This is worth doing in itself in the XML case for reasons previously
explained, but it also makes it relatively easy to add a Query-Text node
or some such to the structured output, which is very much worth having,
and would be my next proposed step.
cheers
andrew
Index: contrib/auto_explain/auto_explain.c
===================================================================
RCS file: /cvsroot/pgsql/contrib/auto_explain/auto_explain.c,v
retrieving revision 1.7
diff -c -r1.7 auto_explain.c
*** contrib/auto_explain/auto_explain.c 10 Aug 2009 05:46:49 -0000 1.7
--- contrib/auto_explain/auto_explain.c 17 Aug 2009 21:19:08 -0000
***************
*** 222,228 ****
--- 222,230 ----
es.verbose = auto_explain_log_verbose;
es.format = auto_explain_log_format;
+ ExplainBeginOutput(&es);
ExplainPrintPlan(&es, queryDesc);
+ ExplainEndOutput(&es);
/* Remove last line break */
if (es.str->len > 0 && es.str->data[es.str->len - 1] == '\n')
Index: src/backend/commands/explain.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/commands/explain.c,v
retrieving revision 1.189
diff -c -r1.189 explain.c
*** src/backend/commands/explain.c 10 Aug 2009 05:46:50 -0000 1.189
--- src/backend/commands/explain.c 17 Aug 2009 21:19:09 -0000
***************
*** 91,98 ****
bool labeled, ExplainState *es);
static void ExplainDummyGroup(const char *objtype, const char *labelname,
ExplainState *es);
- static void ExplainBeginOutput(ExplainState *es);
- static void ExplainEndOutput(ExplainState *es);
static void ExplainXMLTag(const char *tagname, int flags, ExplainState *es);
static void ExplainJSONLineEnding(ExplainState *es);
static void escape_json(StringInfo buf, const char *str);
--- 91,96 ----
***************
*** 1712,1718 ****
* This is just enough different from processing a subgroup that we need
* a separate pair of subroutines.
*/
! static void
ExplainBeginOutput(ExplainState *es)
{
switch (es->format)
--- 1710,1716 ----
* This is just enough different from processing a subgroup that we need
* a separate pair of subroutines.
*/
! void
ExplainBeginOutput(ExplainState *es)
{
switch (es->format)
***************
*** 1739,1745 ****
/*
* Emit the end-of-output boilerplate.
*/
! static void
ExplainEndOutput(ExplainState *es)
{
switch (es->format)
--- 1737,1743 ----
/*
* Emit the end-of-output boilerplate.
*/
! void
ExplainEndOutput(ExplainState *es)
{
switch (es->format)
Index: src/include/commands/explain.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/commands/explain.h,v
retrieving revision 1.41
diff -c -r1.41 explain.h
*** src/include/commands/explain.h 10 Aug 2009 05:46:50 -0000 1.41
--- src/include/commands/explain.h 17 Aug 2009 21:19:09 -0000
***************
*** 54,59 ****
--- 54,63 ----
extern void ExplainInitState(ExplainState *es);
+ extern void ExplainBeginOutput(ExplainState *es);
+
+ extern void ExplainEndOutput(ExplainState *es);
+
extern TupleDesc ExplainResultDesc(ExplainStmt *stmt);
extern void ExplainOneUtility(Node *utilityStmt, ExplainState *es,
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers