【发布时间】:2018-01-13 04:55:20
【问题描述】:
当我在数据库中检查 SHOW PROCESSLIST; 时,我得到了以下查询。它大量使用 CPU(超过 100%),完成查询需要 80 秒。我们有一个单独的数据库服务器(64GB RAM)。
INSERT INTO `search_tmp_598075de5c7e67_73335919`
SELECT `main_select`.`entity_id`, MAX(score) AS `relevance`
FROM (SELECT `search_index`.`entity_id`, (((0)) * 1) AS score
FROM `catalogsearch_fulltext_scope1` AS `search_index`
LEFT JOIN `catalog_eav_attribute` AS `cea`
ON search_index.attribute_id = cea.attribute_id
LEFT JOIN `catalog_category_product_index` AS `category_ids_index`
ON search_index.entity_id = category_ids_index.product_id
LEFT JOIN `review_entity_summary` AS `rating`
ON `rating`.`entity_pk_value`=`search_index`.entity_id
AND `rating`.entity_type = 1
AND `rating`.store_id = 1
WHERE (category_ids_index.category_id = 2299)
) AS `main_select`
GROUP BY `entity_id`
ORDER BY `relevance` DESC
LIMIT 10000
为什么这个查询会占用我全部的 CPU 资源?
【问题讨论】:
-
在 SELECT 部分中出现错误或没有索引,也许我们需要查看 select 部分的说明。
-
你的表的主键是什么?
-
这是一个查询不应该是什么样子的示例。
-
请阅读meta.stackoverflow.com/a/271056,尤其是关于查询性能的部分。那么请edit你的问题。
-
此查询不是我们创建的,这是用于索引的默认 Magento 查询。有没有什么mysql配置设置可以解决这个问题?
标签: mysql magento mariadb query-performance