Using MySQL Index for foreign Keys with Hibernate
Our current database (MySQL) already has Indexes for its foreign keys since these use InnoDB, which (afaik) automatically ge开发者_如何学运维nerates IndexTables for foreign keys. Hibernate wasnt used to create these tables. So my question is: Is MySQL using Indexes for their foreign keys automatically, when I use Hibernate to fetch Data from its tables? Or do I have to configure Hibernate to use these Indexes?
Thank you, ymene
Yes, the query optimizer decides to use or not to use an index. Use EXPLAIN on your SELECT statements to see what it uses. There is no difference in a query created by Hibernate or a hardcoded query.
Is MySQL using Indexes for their foreign keys automatically, when I use Hibernate to fetch Data from its tables? Or do I have to configure Hibernate to use these Indexes?
There is nothing to configure in Hibernate to make the SQL backend use indices for joins. Let Hibernate perform its queries and if the optimizer decides that using an index is appropriate, it will use it.
PS: I'm not talking about Index Hints syntax here, see HHH-2736 - support for native/SQL query hints in HQL/Criteria (Oracle SELECT hints for example), this is something different.
精彩评论