I am running magento community edition and its db performance is horrible. I have the following query:
SELECT `width_idx`.`value`, COUNT(DISTINCT width_idx.entity_id) AS `count` FROM `mage_catalog_product_flat_1` AS `e`
INNER JOIN `mage_catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.visibility IN(2, 4) AND cat_index.category_id='2'
INNER JOIN `mage_catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.
website_id = '1' AND price_index.customer_group_id = 0
INNER JOIN `mage_catalog_product_index_eav` AS `gender_idx` ON gender_idx.entity_id = e.entity_id AND gender_idx.attribute_id = '154' AND gender_idx.store_id = 1 AND gender_idx.value IN('70')
LEFT JOIN `mage_review_entity_summary` AS `at_rating_summary` ON (at_rating_summary.`entity_pk_value`=e.entity_id) AND
(at_rating_summary.entity_type = '1') AND (at_rating_summary.store_id = '1')
INNER JOIN `mage_catalog_product_index_eav` AS `width_idx` ON width_idx.entity_id = e.entity_id AND width_idx.attribute_id = '153' AND width_idx.store_id = '1' GROUP BY `width_idx`.`value`;
The table *mage_catalog_product_flat_1* has 211931 rows in it. Here is EXPLAIN output:
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: width_idx
type: ref
possible_keys: PRIMARY,IDX_MAGE_CATALOG_PRODUCT_INDEX_EAV_ENTITY_ID,IDX_MAGE_CATALOG_PRODUCT_IN
_MAGE_CATALOG_PRODUCT_INDEX_EAV_STORE_ID
key: IDX_MAGE_CATALOG_PRODUCT_INDEX_EAV_ATTRIBUTE_ID
key_len: 2
ref: const
rows: 18746
Extra: Using where; Using index; Using filesort
*************************** 2. row ***************************
id: 1
select_type: SIMPLE
table: cat_index
type: eq_ref
possible_keys: PRIMARY,IDX_MAGE_CAT_CTGR_PRD_IDX_PRD_ID_STORE_ID_CTGR_ID_VISIBILITY,18A130F8AA1
key: PRIMARY
key_len: 10
ref: const,shoestore_stg.width_idx.entity_id,const
rows: 1
Extra: Using where
*************************** 3. row ***************************
id: 1
select_type: SIMPLE
table: e
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: shoestore_stg.cat_index.product_id
rows: 1
Extra: Using where; Using index
*************************** 4. row ***************************
id: 1
select_type: SIMPLE
table: at_rating_summary
type: ref
possible_keys: IDX_MAGE_REVIEW_ENTITY_SUMMARY_STORE_ID
key: IDX_MAGE_REVIEW_ENTITY_SUMMARY_STORE_ID
key_len: 2
ref: const
rows: 603
Extra:
*************************** 5. row ***************************
id: 1
select_type: SIMPLE
table: gender_idx
type: eq_ref
possible_keys: PRIMARY,IDX_MAGE_CATALOG_PRODUCT_INDEX_EAV_ENTITY_ID,IDX_MAGE_CATALOG_PRODUCT_INDEX_EAV_ATTRIBUTE_ID,IDX
_MAGE_CATALOG_PRODUCT_INDEX_EAV_STORE_ID,IDX_MAGE_CATALOG_PRODUCT_INDEX_EAV_VALUE
key: PRIMARY
key_len: 12
ref: shoestore_stg.e.entity_id,const,const,const
rows: 1
Extra: Using where; Using index
*************************** 6. row ***************************
id: 1
select_type: SIMPLE
table: price_index
type: eq_ref
possible_keys: PRIMARY,IDX_MAGE_CATALOG_PRODUCT_INDEX_PRICE_CUSTOMER_GROUP_ID,IDX_MAGE_CATALOG_PRODUCT_INDEX_PRICE_WEBS
ITE_ID,IDX_MAGE_CAT_PRD_IDX_PRICE_WS_ID_CSTR_GROUP_ID_MIN_PRICE
key: PRIMARY
key_len: 8
ref: shoestore_stg.width_idx.entity_id,const,const
rows: 1
Extra: Using index
The slow query log has this query running over a minute:
# Query_time: 66.226261 Lock_time: 0.000433 Rows_sent: 44 Rows_examined: 34271886
How can I speed this query up ?