0

As per title, I'm current using JDBC on eclipse to connect to my PostgreSQL.

I have been running EXPLAIN ANALYZE statements to retrieve query plans from postgres itself. However, is it possible to store these query plan in a structure that resemble a tree? e.g main branch and sub branch etc. I read somewhere that it is a good idea to store it into xml document first and manipulate it from there.

Is there an API in Java for me to achieve this? Thanks!

3
  • "is it possible to store these query plan in a structure that resemble a tree?" Yes. --- "Is there an API in Java for me to achieve this?" Which part of it? Creating XML? Yes. Converting EXPLAIN ANALYZE data to XML? No, that's for you to write. --- "I read somewhere that it is a good idea to store it into xml document first and manipulate it from there." Where did you read that? What manipulation would you be doing? Manipulating XML (DOM) may not the best way to do it. Commented Oct 20, 2017 at 18:24
  • 3
    wh not just using format xml?.. eg xplain (analyze, format xml) select * from pg_database join pg_class on true; Commented Oct 20, 2017 at 19:11
  • Thanks for the tip! I didn't know there was such a thing as format xml! was able to achieve what I wanted by using it Commented Oct 21, 2017 at 6:12

1 Answer 1

1

try using format xml eg

t=# explain (analyze, format xml) select * from pg_database join pg_class on true;
                           QUERY PLAN
----------------------------------------------------------------
 <explain xmlns="http://www.postgresql.org/2009/explain">      +
   <Query>                                                     +
     <Plan>                                                    +
       <Node-Type>Nested Loop</Node-Type>                      +
       <Join-Type>Inner</Join-Type>                            +
       <Startup-Cost>0.00</Startup-Cost>                       +
       <Total-Cost>23.66</Total-Cost>                          +
       <Plan-Rows>722</Plan-Rows>                              +
       <Plan-Width>457</Plan-Width>                            +
       <Actual-Startup-Time>0.026</Actual-Startup-Time>        +
       <Actual-Total-Time>3.275</Actual-Total-Time>            +
       <Actual-Rows>5236</Actual-Rows>                         +
       <Actual-Loops>1</Actual-Loops>                          +
       <Plans>                                                 +
         <Plan>                                                +
           <Node-Type>Seq Scan</Node-Type>                     +
           <Parent-Relationship>Outer</Parent-Relationship>    +
     ...and so on
Sign up to request clarification or add additional context in comments.

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.