magento网站上的MySQL性能问题

时间:2018-10-02 12:35:25

标签: mysql magento

因此,我正在监视服务器进程,并且看到mysql正在占用80%以上的cpu uasge。 我检查了mysql中的进程列表,发现有很多查询导致mysql每秒钟执行一次“正在复制到tmp表”状态,同时至少有2个这样的查询。

这些是我的服务器规格: CPU 6核,RAM 10GB

这是查询,其他查询当然相同,但是where子句的值不同

SELECT `e`.*, IF(at_name.value_id > 0, at_name.value, at_name_default.value) AS `name`, `at_price`.`value` AS `price`, IF(at_small_image.value_id > 0, at_small_image.value, at_small_image_default.value) AS `small_image`, `at_special_price`.`value` AS `special_price`, IF(at_special_from_date.value_id > 0, at_special_from_date.value, at_special_from_date_default.value) AS `special_from_date`, IF(at_special_to_date.value_id > 0, at_special_to_date.value, at_special_to_date_default.value) AS `special_to_date`, `cat_index`.`position` AS `cat_index_position` FROM `catalog_product_entity` AS `e`
 LEFT JOIN `catalog_product_entity_varchar` AS `at_name_default` ON (`at_name_default`.`entity_id` = `e`.`entity_id`) AND (`at_name_default`.`attribute_id` = '71') AND `at_name_default`.`store_id` = 0
 LEFT JOIN `catalog_product_entity_varchar` AS `at_name` ON (`at_name`.`entity_id` = `e`.`entity_id`) AND (`at_name`.`attribute_id` = '71') AND (`at_name`.`store_id` = 2)
 LEFT JOIN `catalog_product_entity_decimal` AS `at_price` ON (`at_price`.`entity_id` = `e`.`entity_id`) AND (`at_price`.`attribute_id` = '75') AND (`at_price`.`store_id` = 0)
 LEFT JOIN `catalog_product_entity_varchar` AS `at_small_image_default` ON (`at_small_image_default`.`entity_id` = `e`.`entity_id`) AND (`at_small_image_default`.`attribute_id` = '86') AND `at_small_image_default`.`store_id` = 0
 LEFT JOIN `catalog_product_entity_varchar` AS `at_small_image` ON (`at_small_image`.`entity_id` = `e`.`entity_id`) AND (`at_small_image`.`attribute_id` = '86') AND (`at_small_image`.`store_id` = 2)
 LEFT JOIN `catalog_product_entity_decimal` AS `at_special_price` ON (`at_special_price`.`entity_id` = `e`.`entity_id`) AND (`at_special_price`.`attribute_id` = '76') AND (`at_special_price`.`store_id` = 0)
 LEFT JOIN `catalog_product_entity_datetime` AS `at_special_from_date_default` ON (`at_special_from_date_default`.`entity_id` = `e`.`entity_id`) AND (`at_special_from_date_default`.`attribute_id` = '77') AND `at_special_from_date_default`.`store_id` = 0
 LEFT JOIN `catalog_product_entity_datetime` AS `at_special_from_date` ON (`at_special_from_date`.`entity_id` = `e`.`entity_id`) AND (`at_special_from_date`.`attribute_id` = '77') AND (`at_special_from_date`.`store_id` = 2)
 LEFT JOIN `catalog_product_entity_datetime` AS `at_special_to_date_default` ON (`at_special_to_date_default`.`entity_id` = `e`.`entity_id`) AND (`at_special_to_date_default`.`attribute_id` = '78') AND `at_special_to_date_default`.`store_id` = 0
 LEFT JOIN `catalog_product_entity_datetime` AS `at_special_to_date` ON (`at_special_to_date`.`entity_id` = `e`.`entity_id`) AND (`at_special_to_date`.`attribute_id` = '78') AND (`at_special_to_date`.`store_id` = 2)
 INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=2 AND cat_index.visibility IN(2, 4) AND cat_index.category_id = '2' WHERE (IF(at_special_to_date.value_id > 0, at_special_to_date.value, at_special_to_date_default.value) >= '2018-10-02 11:48:59') ORDER BY `at_special_price`.`value` asc

This is the query explain:

+----+-------------+------------------------------+--------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------+---------+----------------------------------------------+--------+---------------------------------+
| id | select_type | table                        | type   | possible_keys                                                                                                                                                                               | key                                             | key_len | ref                                          | rows   | Extra                           |
+----+-------------+------------------------------+--------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------+---------+----------------------------------------------+--------+---------------------------------+
|  1 | SIMPLE      | e                            | ALL    | PRIMARY                                                                                                                                                                                     | NULL                                            | NULL    | NULL                                         | 129392 | Using temporary; Using filesort |
|  1 | SIMPLE      | at_name_default              | eq_ref | UNQ_CAT_PRD_ENTT_VCHR_ENTT_ID_ATTR_ID_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_VARCHAR_ATTRIBUTE_ID,IDX_CATALOG_PRODUCT_ENTITY_VARCHAR_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_VARCHAR_ENTITY_ID     | UNQ_CAT_PRD_ENTT_VCHR_ENTT_ID_ATTR_ID_STORE_ID  | 8       | marketplace.e.entity_id,const,const          |      1 |                                 |
|  1 | SIMPLE      | at_name                      | eq_ref | UNQ_CAT_PRD_ENTT_VCHR_ENTT_ID_ATTR_ID_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_VARCHAR_ATTRIBUTE_ID,IDX_CATALOG_PRODUCT_ENTITY_VARCHAR_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_VARCHAR_ENTITY_ID     | UNQ_CAT_PRD_ENTT_VCHR_ENTT_ID_ATTR_ID_STORE_ID  | 8       | marketplace.e.entity_id,const,const          |      1 |                                 |
|  1 | SIMPLE      | cat_index                    | eq_ref | PRIMARY,IDX_CAT_CTGR_PRD_IDX_PRD_ID_STORE_ID_CTGR_ID_VISIBILITY,15D3C269665C74C2219037D534F4B0DC                                                                                            | PRIMARY                                         | 10      | const,marketplace.e.entity_id,const          |      1 | Using where                     |
|  1 | SIMPLE      | at_price                     | eq_ref | UNQ_CAT_PRD_ENTT_DEC_ENTT_ID_ATTR_ID_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_DECIMAL_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_DECIMAL_ENTITY_ID,IDX_CATALOG_PRODUCT_ENTITY_DECIMAL_ATTRIBUTE_ID      | UNQ_CAT_PRD_ENTT_DEC_ENTT_ID_ATTR_ID_STORE_ID   | 8       | marketplace.e.entity_id,const,const          |      1 |                                 |
|  1 | SIMPLE      | at_small_image_default       | eq_ref | UNQ_CAT_PRD_ENTT_VCHR_ENTT_ID_ATTR_ID_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_VARCHAR_ATTRIBUTE_ID,IDX_CATALOG_PRODUCT_ENTITY_VARCHAR_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_VARCHAR_ENTITY_ID     | UNQ_CAT_PRD_ENTT_VCHR_ENTT_ID_ATTR_ID_STORE_ID  | 8       | marketplace.cat_index.product_id,const,const |      1 |                                 |
|  1 | SIMPLE      | at_small_image               | eq_ref | UNQ_CAT_PRD_ENTT_VCHR_ENTT_ID_ATTR_ID_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_VARCHAR_ATTRIBUTE_ID,IDX_CATALOG_PRODUCT_ENTITY_VARCHAR_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_VARCHAR_ENTITY_ID     | UNQ_CAT_PRD_ENTT_VCHR_ENTT_ID_ATTR_ID_STORE_ID  | 8       | marketplace.cat_index.product_id,const,const |      1 |                                 |
|  1 | SIMPLE      | at_special_price             | eq_ref | UNQ_CAT_PRD_ENTT_DEC_ENTT_ID_ATTR_ID_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_DECIMAL_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_DECIMAL_ENTITY_ID,IDX_CATALOG_PRODUCT_ENTITY_DECIMAL_ATTRIBUTE_ID      | UNQ_CAT_PRD_ENTT_DEC_ENTT_ID_ATTR_ID_STORE_ID   | 8       | marketplace.e.entity_id,const,const          |      1 |                                 |
|  1 | SIMPLE      | at_special_from_date_default | eq_ref | UNQ_CAT_PRD_ENTT_DTIME_ENTT_ID_ATTR_ID_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_DATETIME_ATTRIBUTE_ID,IDX_CATALOG_PRODUCT_ENTITY_DATETIME_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_DATETIME_ENTITY_ID | UNQ_CAT_PRD_ENTT_DTIME_ENTT_ID_ATTR_ID_STORE_ID | 8       | marketplace.cat_index.product_id,const,const |      1 |                                 |
|  1 | SIMPLE      | at_special_from_date         | eq_ref | UNQ_CAT_PRD_ENTT_DTIME_ENTT_ID_ATTR_ID_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_DATETIME_ATTRIBUTE_ID,IDX_CATALOG_PRODUCT_ENTITY_DATETIME_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_DATETIME_ENTITY_ID | UNQ_CAT_PRD_ENTT_DTIME_ENTT_ID_ATTR_ID_STORE_ID | 8       | marketplace.e.entity_id,const,const          |      1 |                                 |
|  1 | SIMPLE      | at_special_to_date_default   | eq_ref | UNQ_CAT_PRD_ENTT_DTIME_ENTT_ID_ATTR_ID_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_DATETIME_ATTRIBUTE_ID,IDX_CATALOG_PRODUCT_ENTITY_DATETIME_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_DATETIME_ENTITY_ID | UNQ_CAT_PRD_ENTT_DTIME_ENTT_ID_ATTR_ID_STORE_ID | 8       | marketplace.cat_index.product_id,const,const |      1 |                                 |
|  1 | SIMPLE      | at_special_to_date           | eq_ref | UNQ_CAT_PRD_ENTT_DTIME_ENTT_ID_ATTR_ID_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_DATETIME_ATTRIBUTE_ID,IDX_CATALOG_PRODUCT_ENTITY_DATETIME_STORE_ID,IDX_CATALOG_PRODUCT_ENTITY_DATETIME_ENTITY_ID | UNQ_CAT_PRD_ENTT_DTIME_ENTT_ID_ATTR_ID_STORE_ID | 8       | marketplace.e.entity_id,const,const          |      1 | Using where                     |
+----+-------------+------------------------------+--------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------+---------+----------------------------------------------+--------+---------------------------------+

请告诉我是否需要提供更多信息。

0 个答案:

没有答案