machine-readable explain output - Mailing list pgsql-hackers

From Robert Haas
Subject machine-readable explain output
Date
Msg-id 603c8f070906112215qf2939d0mcf8497167f825b86@mail.gmail.com
Whole thread Raw
Responses Re: machine-readable explain output
Re: machine-readable explain output
Re: machine-readable explain output
List pgsql-hackers
Here we go, XML and JSON output.

You will need to apply explain_refactor-v4.patch and
explain_options-v2.patch first, then apply the two patches attached to
this message.

http://archives.postgresql.org/pgsql-hackers/2009-06/msg00865.php
http://archives.postgresql.org/pgsql-hackers/2009-06/msg00866.php

The infrastructure patch applies first and is separated only for ease
of reviewing.  If the infrastructure patch applied by itself changes
any user-visible behavior, it's a bug.  The main patch does all the
heavy lifting.  The syntax is:

explain (format xml) ...
explain (format json, analyze) ...
explain (format text) ...   -- same as just plain old explain

If you don't like the syntax, please argue about that on the "generic
explain options v2" thread.  Let's try to use this thread to discuss
the output format, about which I spent a good deal of time agonizing.
I felt that it was important to keep the XML and JSON output as
similar to each other as possible.  This has the fairly obvious
advantage of reducing code complexity and the somewhat less obvious
advantage of avoiding expressing information in ways that are overly
tied to the syntax of XML.  I think the latter is actually a pretty
important point; it's hard to know that you've done something that's
actually generic unless you actually go through the exercise of making
it apply to two different cases.  This code is obviously not
completely generic; I did consider the idea that Greg Stark proposed
of having some kind of ephemeral internal format with multiple output
converters, but I couldn't figure out a way to make it work.  Still,
I've made a fairly determined effort to minimize the number of places
where we switch on the output format.  It's still larger than I'd
like, but I don't have any good ideas for trimming it down further.

There is an argument to be made that machine-readable output formats
shouldn't be afraid to print information that isn't displayed in the
regular output, but I haven't gone very far down that road in this
patch.  I lean toward the view that any additional information that
someone wants to have in the machine-readable format should also be an
available option for the text format, because I think the question of
WHAT you want to display and HOW you want to display it are largely
orthogonal (hence options are a separate patch, and this patch just
uses that infrastructure to implement an option for format).  But
there may be some exceptions.  At any rate, if it's possible, I would
like to get at least some of this work committed before I go too much
further with it, since this patch stack is already four layers deep
and my head may explode if it gets too much deeper.

If it's helpful to have any of these patches further decomposed for
reviewing purposes, see here, where they are broken out into
individual commits:

http://git.postgresql.org/gitweb?p=postgresql-rhaas.git;a=shortlog;h=refs/heads/explain_format

(It's probably a bad idea to clone this repository as I am updating
the patch set by rebasing, but it's useful for browsing.)

Comments appreciated...

...Robert

Attachment

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: generic explain options v2
Next
From: "suylivar"
Date:
Subject: PostgreSQL installation