Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to review/optimize a Hibernate query plan?

Is there some facility in Hibernate for viewing the query plan for a query? I can look at the source code and trace the joins and eager fetches and hope that I don't miss any, or I can look at the SQL log and try to match up a SQL statement with its source, but I was wondering if there was a faster way. e.g., I can imagine an object diagram showing the relevant classes or an E-R diagram with some kind of sequencing notation.

like image 734
Larry OBrien Avatar asked Nov 14 '22 23:11

Larry OBrien


1 Answers

Many times the underlying database engine will show you the plan. If you have the SQL queries being produced by Hibernate, you can prepend it with EXPLAIN

EXPLAIN SELECT blah blah blah

I'm using MySql on Linux so I can get this output without having to go through the Hibernate SQL output - I run mytop and hit 'e' when I see the query I'm interested in. I expect most database servers offer similar diagnostics.

like image 169
werkshy Avatar answered Dec 21 '22 16:12

werkshy