Skip to content
Advertisement

How can I optimise COUNT with GROUPBY mysql query?

I have 5M records in eus table and 121 records in es table. I am doing a left join but the COUNT query is making my query very slow. How can I optimize this?

Raw query with Explain:

Output of Explain:

enter image description here

Explain Visual View:

enter image description here

This full table scan of count is making the problem.

Note: All JOINs and necessary columns fields are having proper indexes.

Advertisement

Answer

A correlated subquery can be a fast method:

For performance, you want an index on eb_evaluation_user_symptom(eb_evaluation_symptom_id).

An index on eb_evaluation_symptom won’t be of much help, because that table is so small.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement