Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9bd27b7

Browse files
committed
Extend EXPLAIN to support output in XML or JSON format.
There are probably still some adjustments to be made in the details of the output, but this gets the basic structure in place. Robert Haas
1 parent 18894c4 commit 9bd27b7

File tree

12 files changed

+1150
-361
lines changed

12 files changed

+1150
-361
lines changed

contrib/auto_explain/auto_explain.c

+21-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2008-2009, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.6 2009/07/26 23:34:17 tgl Exp $
9+
* $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.7 2009/08/10 05:46:49 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -22,8 +22,16 @@ PG_MODULE_MAGIC;
2222
static int auto_explain_log_min_duration = -1; /* msec or -1 */
2323
static bool auto_explain_log_analyze = false;
2424
static bool auto_explain_log_verbose = false;
25+
static int auto_explain_log_format = EXPLAIN_FORMAT_TEXT;
2526
static bool auto_explain_log_nested_statements = false;
2627

28+
static const struct config_enum_entry format_options[] = {
29+
{"text", EXPLAIN_FORMAT_TEXT, false},
30+
{"xml", EXPLAIN_FORMAT_XML, false},
31+
{"json", EXPLAIN_FORMAT_JSON, false},
32+
{NULL, 0, false}
33+
};
34+
2735
/* Current nesting depth of ExecutorRun calls */
2836
static int nesting_level = 0;
2937

@@ -84,6 +92,17 @@ _PG_init(void)
8492
NULL,
8593
NULL);
8694

95+
DefineCustomEnumVariable("auto_explain.log_format",
96+
"EXPLAIN format to be used for plan logging.",
97+
NULL,
98+
&auto_explain_log_format,
99+
EXPLAIN_FORMAT_TEXT,
100+
format_options,
101+
PGC_SUSET,
102+
0,
103+
NULL,
104+
NULL);
105+
87106
DefineCustomBoolVariable("auto_explain.log_nested_statements",
88107
"Log nested statements.",
89108
NULL,
@@ -201,6 +220,7 @@ explain_ExecutorEnd(QueryDesc *queryDesc)
201220
ExplainInitState(&es);
202221
es.analyze = (queryDesc->doInstrument && auto_explain_log_analyze);
203222
es.verbose = auto_explain_log_verbose;
223+
es.format = auto_explain_log_format;
204224

205225
ExplainPrintPlan(&es, queryDesc);
206226

doc/src/sgml/auto-explain.sgml

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/auto-explain.sgml,v 1.3 2009/01/02 01:16:02 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/auto-explain.sgml,v 1.4 2009/08/10 05:46:50 tgl Exp $ -->
22

33
<sect1 id="auto-explain">
44
<title>auto_explain</title>
@@ -102,6 +102,24 @@ LOAD 'auto_explain';
102102
</listitem>
103103
</varlistentry>
104104

105+
<varlistentry>
106+
<term>
107+
<varname>auto_explain.log_format</varname> (<type>enum</type>)
108+
</term>
109+
<indexterm>
110+
<primary><varname>auto_explain.log_format</> configuration parameter</primary>
111+
</indexterm>
112+
<listitem>
113+
<para>
114+
<varname>auto_explain.log_format</varname> selects the
115+
<command>EXPLAIN</> output format to be used.
116+
The allowed values are <literal>text</literal>, <literal>xml</literal>,
117+
and <literal>json</literal>. The default is text.
118+
Only superusers can change this setting.
119+
</para>
120+
</listitem>
121+
</varlistentry>
122+
105123
<varlistentry>
106124
<term>
107125
<varname>auto_explain.log_nested_statements</varname> (<type>boolean</type>)

doc/src/sgml/ref/explain.sgml

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/explain.sgml,v 1.45 2009/07/26 23:34:17 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/explain.sgml,v 1.46 2009/08/10 05:46:50 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -31,7 +31,7 @@ PostgreSQL documentation
3131

3232
<refsynopsisdiv>
3333
<synopsis>
34-
EXPLAIN [ ( { ANALYZE <replaceable class="parameter">boolean</replaceable> | VERBOSE <replaceable class="parameter">boolean</replaceable> | COSTS <replaceable class="parameter">boolean</replaceable> } [, ...] ) ] <replaceable class="parameter">statement</replaceable>
34+
EXPLAIN [ ( { ANALYZE <replaceable class="parameter">boolean</replaceable> | VERBOSE <replaceable class="parameter">boolean</replaceable> | COSTS <replaceable class="parameter">boolean</replaceable> | FORMAT { TEXT | XML | JSON } } [, ...] ) ] <replaceable class="parameter">statement</replaceable>
3535
EXPLAIN [ ANALYZE ] [ VERBOSE ] <replaceable class="parameter">statement</replaceable>
3636
</synopsis>
3737
</refsynopsisdiv>
@@ -109,7 +109,7 @@ ROLLBACK;
109109
<listitem>
110110
<para>
111111
Carry out the command and show the actual run times. This
112-
parameter defaults to <command>FALSE</command>.
112+
parameter defaults to <literal>FALSE</literal>.
113113
</para>
114114
</listitem>
115115
</varlistentry>
@@ -118,8 +118,12 @@ ROLLBACK;
118118
<term><literal>VERBOSE</literal></term>
119119
<listitem>
120120
<para>
121-
Include the output column list for each node in the plan tree. This
122-
parameter defaults to <command>FALSE</command>.
121+
Display additional information regarding the plan. Specifically, include
122+
the output column list for each node in the plan tree, schema-qualify
123+
table and function names, always label variables in expressions with
124+
their range table alias, and always print the name of each trigger for
125+
which statistics are displayed. This parameter defaults to
126+
<literal>FALSE</literal>.
123127
</para>
124128
</listitem>
125129
</varlistentry>
@@ -130,7 +134,19 @@ ROLLBACK;
130134
<para>
131135
Include information on the estimated startup and total cost of each
132136
plan node, as well as the estimated number of rows and the estimated
133-
width of each row. This parameter defaults to <command>TRUE</command>.
137+
width of each row. This parameter defaults to <literal>TRUE</literal>.
138+
</para>
139+
</listitem>
140+
</varlistentry>
141+
142+
<varlistentry>
143+
<term><literal>FORMAT</literal></term>
144+
<listitem>
145+
<para>
146+
Specify the output format, which can be TEXT, XML, or JSON.
147+
XML or JSON output contains the same information as the text output
148+
format, but is easier for programs to parse. This parameter defaults to
149+
<literal>TEXT</literal>.
134150
</para>
135151
</listitem>
136152
</varlistentry>

0 commit comments

Comments
 (0)