我有一個購物車,不斷地記錄像這樣的查詢速度慢...mysql的慢查詢優化
# Query_time: 4 Lock_time: 0 Rows_sent: 50 Rows_examined: 454403
SELECT SQL_CALC_FOUND_ROWS products.*,
descr1.product AS product,
Min(prices.price) AS price,
GROUP_CONCAT(IF(products_categories.link_type = 'M',
Concat(products_categories.category_id,
'M'), products_categories.category_id)) AS
category_ids,
cscart_seo_names.name AS seo_name
FROM cscart_products AS products
LEFT JOIN cscart_product_descriptions AS descr1
ON descr1.product_id = products.product_id
AND descr1.lang_code = 'EN'
LEFT JOIN cscart_product_prices AS prices
ON prices.product_id = products.product_id
AND prices.lower_limit = 1
INNER JOIN cscart_products_categories AS products_categories
ON products_categories.product_id = products.product_id
INNER JOIN cscart_categories
ON cscart_categories.category_id = products_categories.category_id
AND (cscart_categories.usergroup_ids = ''
OR Find_in_set(0, cscart_categories.usergroup_ids)
OR Find_in_set(1, cscart_categories.usergroup_ids))
AND cscart_categories.status IN ('A', 'H')
LEFT JOIN cscart_seo_names
ON cscart_seo_names.object_id = products.product_id
AND cscart_seo_names.TYPE = 'p'
AND cscart_seo_names.dispatch = ''
AND cscart_seo_names.lang_code = 'EN'
WHERE 1
AND products.company_id = 0
AND (products.usergroup_ids = ''
OR Find_in_set(0, products.usergroup_ids)
OR Find_in_set(1, products.usergroup_ids))
AND products.status IN ('A')
AND prices.usergroup_id IN (0, 0, 1)
GROUP BY products.product_id
ORDER BY descr1.product ASC
LIMIT 1300, 50;
我似乎無法得到從車公司就如何加快該查詢的任何幫助。也許我需要添加更多索引?我不確定,並希望得到一些幫助,指出我正確解決這個問題的方向。
感謝,
克里斯·愛德華茲
'EXPLAIN'是你最好的朋友 – meze