Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Parsing Oracle Explain Plan

I wonder if there is any library that allows for parsing oracle's explain plan into a data structure.

Given the following query:

 select prod_category, avg(amount_sold)
 from sales s, products p
 where p.prod_id = s.prod_id
 group by prod_category;

explain plan may look something like the following:

 ------------------------------------------
  Id   Operation              Name   
 ------------------------------------------
    0  SELECT STATEMENT              
    1   HASH GROUP BY                
    2    HASH JOIN                   
    3     TABLE ACCESS FULL   PRODUCTS
    4     PARTITION RANGE ALL        
    5      TABLE ACCESS FULL  SALES  
 ------------------------------------------

I want a parser that parses the plan into a data structure that allows visualizing and analyzing the plan like the following:

  SELECT STATEMENT
        |
     GROUP BY
        |
       JOIN
   _____|______
  |            |
 ACCESS     ACCESS
 (PRODUCTS) (SALES)

I have noticed that Oracle's SQLDeveloper visualizes the plan. I am reluctant to manually parse the text, so I wonder if there is any library that would help with parsing the plan.

like image 725
nemo Avatar asked Aug 08 '26 19:08

nemo


1 Answers

Plan is already stored as hierarchical structure for easy visualization:

  select 
    id, 
    parent_id, 
    lpad(' ', 2*(level-1), ' ')||operation||' '||object_name as desc
  from your_plan_table
  start with parent_id is null 
  connect by prior id = parent_id

How this structure can be even more convenient?

like image 196
Egor Skriptunoff Avatar answered Aug 11 '26 09:08

Egor Skriptunoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!