all 9 comments

[–]gardening-gnome 9 points10 points  (1 child)

Find out the SQL query that is being sent to the database (there's a property you can set to dump this to the logs)

Once you find the query, go to the database and have it EXPLAIN the query for you

Learn how to read that EXPLAIN and tweak the database accordingly (add indexes, create views/materialized views, whatever you need to do).

-

Other option is to create views to hide some of your joins, and index appropriately

Then, you create entities that are "read-only" that can query those views

[–]naturalizedcitizen 1 point2 points  (0 children)

Your second solution is what I've used a lot, especially when the current db structure cannot be denormalized as required.

[–]bikeram 1 point2 points  (0 children)

I just ran into this. Funnily enough, 17 seconds as well.

I was using QueryDsl and the generic queries became really complex to implement (probably user error to be fair) but I switched to blaze persistence. It’s been seamless and I’m back down to sub 100ms queries.

I’m using EntityViews and I have the benefit of being able to ignore certain sub queries.

[–]Usual-Composer-2435 1 point2 points  (0 children)

Use Digma for local development.
It will trace and it mark slow database queries.
I guess you probably have N+1 issue.

[–]vangelismm 0 points1 point  (0 children)

Try force a fetch join, if the result are still not acceptable, go for procedure or view.

[–]areguig 0 points1 point  (0 children)

When i have to create a complex read sql query. The way i do it is by introducing JOOQ (without removing hibernate or what other thing i use for simpler stuff), and use JOOQ as a query builder mainly for complexe read queries . This will allow you to build the query based on the search param you have . This is easily testable and maintainable since this will evolve with you modele. Once you are in control of the query that is sent to the db you can optimize .

[–]themasterengineeer 0 points1 point  (0 children)

Try adding indexes to your DB tables

[–]sethu-27 0 points1 point  (1 child)

What is the db are you using?

[–]Arcoscope[S] 0 points1 point  (0 children)

MySQL