I am working on a project which involves MySQL database which has billions of rows and building a Java based application on top of it. I am using Hibernate as ORM. While I execute a complex query on MySQL it is taking about 2.5 secs to execute where as in Hibernate the same query is taking about 8.9 secs. Are there any settings I need to change to reduce the execution time in Hibernate?
1 Answer
Hibernate is a bit slower than native - that's to be expected... Have you defined the indexes properly? Are you using lazy loading (you should be). What query is hibernate spitting out to fetch your data compared to the native (use hibernate.show_sql=true)
1 Comment
Venu Chitta
The query I am using is:
SELECT start_date, X, 'USER_[[:digit:]]+' AS Y, SUM(Z) FROM table_name WHERE ( Y REGEXP 'USER_[[:digit:]]+') AND X IN ("AAAA", "BBB" ) AND start_date >= "XXX" AND start_date < " YYY" GROUP BY X, startDate ORDER BY X} The database has a single table but not joins. I am using session.createSQLQuery to send the data to MySql. I used an index for X and start_date.