Larry OBrien
Larry OBrien

Reputation: 8606

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.

Upvotes: 6

Views: 4094

Answers (1)

werkshy
werkshy

Reputation: 1665

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.

Upvotes: 1

Related Questions