I am executing this query to get the number of products for each category on my website
SELECT COUNT(DISTINCT p.product_id) AS total
FROM category_path cp
LEFT JOIN product_to_category p2c ON (cp.category_id = p2c.category_id)
LEFT JOIN product p ON (p2c.product_id = p.product_id)
LEFT JOIN product_description pd ON (p.product_id = pd.product_id)
LEFT JOIN product_to_store p2s ON (p.product_id = p2s.product_id)
WHERE pd.language_id = '1'
AND p.status = '1'
AND p.date_available <= NOW()
AND p2s.store_id = '0'
AND cp.path_id = '20'
AND p.is_family ='1';
On my local machine it works fine and returns the result within .02
+-------+
| total |
+-------+
| 392 |
+-------+
1 row in set (0.02 sec)`
but when I execute the same query on my server's DB it takes a lot
+-------+
| total |
+-------+
| 412 |
+-------+
1 row in set (0.78 sec)
I searched for any possible solution but I didn't find, If anyone can help me to find the reason I will appreciate that.