I have a query (below) that takes forever to run when a customer has a lot of categories. I need to speed it up somehow and I can’t figure out how. Any assistance is greatly appreciated.
SELECT pictures1.*, GROUP_CONCAT(cats_master.categoryName SEPARATOR ';') AS categoryNames
FROM pictures1
LEFT JOIN cats_contacts ON pictures1.id =cats_contacts.contact_id
LEFT JOIN cats_master ON cats_contacts.category_id = cats_master.id
WHERE pictures1.customer_id = (customer id goes here)
GROUP BY pictures1.id
ORDER BY pictures1.l_name ASC
The result of this query is a file that the customer can download – the issue seems to be the category piece.
Having following indexes will greatly speedup the query: