Very slow SQL query with GROUP BY

时间:2018-03-22 23:35:34

标签: mysql optimization query-optimization greatest-n-per-group groupwise-maximum

I have a database with 61,000 rows. My website has a very low Google PageSpeed score due to slow server response time, so while investigating I found this SQL query takes over 1200ms to return a result:

SELECT * FROM shop_tshirts 
    WHERE categorie != '174868' AND shop_id = '266497' AND online='1' 
    GROUP BY design_id 
    ORDER BY tshirt_sales DESC LIMIT 0, 54

If I remove the "GROUP BY" part, the query is executed in less than 150ms

I have already added index and optimized table. What else can I do to optimise this query? Table index: http://prntscr.com/iv2nel

0 个答案:

没有答案