3

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?

4
  • The stuff Hugo Depesz has built is pretty fantastic. I doubt you'll find much else, and certainly nothing better. Can't you just call his modules as a web wervice or so? Commented Nov 10, 2011 at 16:12
  • Note that the XML output was added in 9.0, not 9.1 Commented Nov 10, 2011 at 16:18
  • FWIW there's also support for output in JSON and YAML format. Commented Nov 10, 2011 at 16:28
  • @C.Ramseyer Hubert "Depesz" Lubaczewski Commented Nov 10, 2011 at 22:24

3 Answers 3

4

You've got the right answer right there. For your automated needs use XML or the tools at: https://github.com/depesz/Pg--Explain

For the rest of us, the interactive version is a real gem, and I'm posting it here so people find it: http://explain.depesz.com/

Background on explain itself is at: http://www.postgresql.org/docs/current/static/sql-explain.html But there does not appear to be a reference to a DTD or defined schema for explain.

Sign up to request clarification or add additional context in comments.

1 Comment

This can be helpful also if someone needs to parse depesz site output: github.com/celuk/…
0

I had the same requirement of parsing XML plan output of Explain command. I have used LibXML2 libray. It is easy to use and powerful. Try that.

Comments

0

I have a similar requirement and solved by psql and jq, for example:

psql $PG_URL -P pager=off -Aqt -c 'EXPLAIN (FORMAT JSON) SELECT version()' | jq

You can also pipe to other programming languages you are familiar with, for example:

psql $PG_URL -P pager=off -Aqt -c 'EXPLAIN (FORMAT JSON) SELECT version()' |
  ruby -rjson -e 'pp JSON.parse($stdin.read)'

References

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.