dlopezgonzalez
dlopezgonzalez

Reputation: 4297

My query takes too much time in hibernate with index

I'm using Hibernate and I have this table:

Table my_entity:

ID_ENTITY        int(10) unsigned PK
ID_ENTITY_TYPE   int(10) unsigned
NAME             varchar(256)
SYNONYM          varchar(32)
KEY `INDEX_synonym` (`SYNONYM`)

I have got 180.000 rows in this table.

When I execute a query, it takes quite a few seconds.

 query = session.createQuery("from Entity c Where synonym = :synonym");
 query.setParameter(":synonym", MYKEY);     
 lst = query.list();  

How can I instruct Hibernate to use the index?

Upvotes: 0

Views: 1402

Answers (1)

JB Nizet
JB Nizet

Reputation: 691755

Hibernate doesn't do anything other than generating a SQL query and executing it. Turn loggin on to see which query it executes. Make sure this query looks like what you want. Use your database to analyze the execution plan and make sure the necessary indices are there.

180,000 rows is nothing for a decent database. Unless your query loads a whole lot of entities with a whole lot of eagerly fetched associations, this query shoud execute in a few milliseconds.

Upvotes: 4

Related Questions