Thread: Parsing output of EXPLAIN command in PostgreSQL

Parsing output of EXPLAIN command in PostgreSQL

From
Αναστάσιος Αρβανίτης
Date:
I'm developing an application that requires parsing of
execution plans (those produced as output by issuing an EXPLAIN [query]
command). Are you aware of any Java library that I could use for this
purpose? I found https://github.com/depesz/Pg--Explain but it is built in Perl.


Also another option I am considering is to use EXPLAIN [query] FORMAT XML which is available in PostgreSQL 9.1.
However,in that case it  
would better to have the XML Schema of the generated plans available.

Is there any other solution I am not aware of?


Thank you



Re: Parsing output of EXPLAIN command in PostgreSQL

From
Andreas Karlsson
Date:
On 2011-11-10 17:23, Αναστάσιος Αρβανίτης wrote:
> Also another option I am considering is to use EXPLAIN [query] FORMAT XML which is available in PostgreSQL 9.1.
However,in that case it
 
> would better to have the XML Schema of the generated plans available.
>
> Is there any other solution I am not aware of?

Hi,

I recommend using the XML, JSON or YAML version of the plan, whichever 
is easiest in your programming language to parse. I do not think anyone 
has written a formal schema yet for the XML but it still should be much 
easier to parse than rolling your own parser for the human readable format.

But if you insist on parsing the human readable format, e.g. to support 
versions before 9.1, I recommend that you take a look at 
http://explain.depesz.com/ which supports parsing text plans in addition 
to XML and JSON. The site is open source and written in Perl.

The source code can be found at:

https://github.com/depesz/Pg--Explain

Best regards,
Andreas

-- 
Andreas Karlsson


Re: Parsing output of EXPLAIN command in PostgreSQL

From
Andreas Karlsson
Date:
On 2011-11-10 23:42, Andreas Karlsson wrote:
> Hi,
>
> I recommend using the XML, JSON or YAML version of the plan, whichever
> is easiest in your programming language to parse. I do not think anyone
> has written a formal schema yet for the XML but it still should be much
> easier to parse than rolling your own parser for the human readable format.
>
> But if you insist on parsing the human readable format, e.g. to support
> versions before 9.1, I recommend that you take a look at
> http://explain.depesz.com/ which supports parsing text plans in addition
> to XML and JSON. The site is open source and written in Perl.
>
> The source code can be found at:
>
> https://github.com/depesz/Pg--Explain

Sorry, I did not see the other thread about the same thing. Let's keep 
all discussion there.

-- 
Andreas Karlsson