任何加快价格指数的方法

时间:2012-06-13 09:53:28

标签: php magento

在一家商店,我们维持在价格指数最新之前需要很长时间。在分析过程的过程中,我注意到捆绑价格索引器正在使用一个需要40秒才能执行的查询,如果你问我,这个时间太长了。此查询将重复大约8次,因此难怪为什么索引问题如此缓慢。

我能做些什么吗?如果通过Explain分析查询,并且没有给出可以进行的优化。还有其他选择吗?我很乐意听到他们的声音。

查询如下所示:

SELECT `e`.`entity_id`, 
       `cg`.`customer_group_id`, 
       `cw`.`website_id`, 
       IF(IF(Ifnull(tas_tax_class_id.value_id, -1) > 0, tas_tax_class_id.value, 
             tad_tax_class_id.value) IS NOT NULL, IF( 
       Ifnull(tas_tax_class_id.value_id, -1) > 0, tas_tax_class_id.value, 
                                                  tad_tax_class_id.value), 0) 
       AS
       `tax_class_id`, 
       1 
       AS `price_type`, 
       IF(IF(ta_special_from_date.value IS NULL, 1, IF( 
             ta_special_from_date.value <= cwd.website_date, 1, 0)) > 0 
          AND IF(ta_special_to_date.value IS NULL, 1, IF( 
                  ta_special_to_date.value >= cwd.website_date, 1, 0)) > 0 
          AND IF(Ifnull(tas_special_price.value_id, -1) > 0, 
              tas_special_price.value, 
                  tad_special_price.value) > 0 
          AND IF(Ifnull(tas_special_price.value_id, -1) > 0, 
              tas_special_price.value, 
                  tad_special_price.value) < 100, IF( 
       Ifnull(tas_special_price.value_id, -1) > 0, tas_special_price.value, 
                                                  tad_special_price.value), 0) 
       AS
       `special_price`, 
       tp.min_price 
       AS `tier_percent`, 
       IF(IF(Ifnull(tas_price.value_id, -1) > 0, tas_price.value, 
          tad_price.value) IS
          NULL, 0, IF(Ifnull(tas_price.value_id, -1) > 0, tas_price.value, 
                   tad_price.value)) 
       AS `orig_price`, 
       IF(IF(IF(ta_special_from_date.value IS NULL, 1, IF( 
                   ta_special_from_date.value <= cwd.website_date, 1, 0)) > 0 
             AND IF(ta_special_to_date.value IS NULL, 1, IF( 
                     ta_special_to_date.value >= cwd.website_date, 1, 0)) > 0 
             AND IF(Ifnull(tas_special_price.value_id, -1) > 0, 
                 tas_special_price.value, 
                     tad_special_price.value) > 0 
             AND IF(Ifnull(tas_special_price.value_id, -1) > 0, 
                 tas_special_price.value, 
                     tad_special_price.value) < 100, 
          IF( 
             Ifnull(tas_special_price.value_id, -1) > 0, 
          tas_special_price.value, 
                                                     tad_special_price.value), 0 
          ) > 0, 
       Round( 
       IF(Ifnull(tas_price.value_id, -1) > 0, tas_price.value, tad_price.value) 
       * ( IF( 
       IF 
       (ta_special_from_date.value IS NULL, 1, IF( 
             ta_special_from_date.value <= 
             cwd.website_date, 1, 0)) > 0 
             AND IF(ta_special_to_date.value IS NULL, 1, IF( 
                     ta_special_to_date.value >= cwd.website_date, 1, 0)) > 0 
             AND IF(Ifnull(tas_special_price.value_id, -1) > 0, 
                 tas_special_price.value, 
                     tad_special_price.value) > 0 
             AND IF(Ifnull(tas_special_price.value_id, -1) > 0, 
                 tas_special_price.value, 
                     tad_special_price.value) < 100, 
           IF( 
             Ifnull(tas_special_price.value_id, -1) > 0, 
           tas_special_price.value, 
                                                     tad_special_price.value), 0 
           ) / 100 
       ), 4), IF(Ifnull(tas_price.value_id, -1) > 0, tas_price.value, 
              tad_price.value)) 
                       AS `price`, 
       IF(IF(IF(ta_special_from_date.value IS NULL, 1, IF( 
                   ta_special_from_date.value <= cwd.website_date, 1, 0)) > 0 
             AND IF(ta_special_to_date.value IS NULL, 1, IF( 
                     ta_special_to_date.value >= cwd.website_date, 1, 0)) > 0 
             AND IF(Ifnull(tas_special_price.value_id, -1) > 0, 
                 tas_special_price.value, 
                     tad_special_price.value) > 0 
             AND IF(Ifnull(tas_special_price.value_id, -1) > 0, 
                 tas_special_price.value, 
                     tad_special_price.value) < 100, 
          IF( 
             Ifnull(tas_special_price.value_id, -1) > 0, 
          tas_special_price.value, 
                                                     tad_special_price.value), 0 
          ) > 0, 
       Round( 
       IF(Ifnull(tas_price.value_id, -1) > 0, tas_price.value, tad_price.value) 
       * ( IF( 
       IF 
       (ta_special_from_date.value IS NULL, 1, IF( 
             ta_special_from_date.value <= 
             cwd.website_date, 1, 0)) > 0 
             AND IF(ta_special_to_date.value IS NULL, 1, IF( 
                     ta_special_to_date.value >= cwd.website_date, 1, 0)) > 0 
             AND IF(Ifnull(tas_special_price.value_id, -1) > 0, 
                 tas_special_price.value, 
                     tad_special_price.value) > 0 
             AND IF(Ifnull(tas_special_price.value_id, -1) > 0, 
                 tas_special_price.value, 
                     tad_special_price.value) < 100, 
           IF( 
             Ifnull(tas_special_price.value_id, -1) > 0, 
           tas_special_price.value, 
                                                     tad_special_price.value), 0 
           ) / 100 
       ), 4), IF(Ifnull(tas_price.value_id, -1) > 0, tas_price.value, 
              tad_price.value)) 
                       AS `min_price`, 
       IF(IF(IF(ta_special_from_date.value IS NULL, 1, IF( 
                   ta_special_from_date.value <= cwd.website_date, 1, 0)) > 0 
             AND IF(ta_special_to_date.value IS NULL, 1, IF( 
                     ta_special_to_date.value >= cwd.website_date, 1, 0)) > 0 
             AND IF(Ifnull(tas_special_price.value_id, -1) > 0, 
                 tas_special_price.value, 
                     tad_special_price.value) > 0 
             AND IF(Ifnull(tas_special_price.value_id, -1) > 0, 
                 tas_special_price.value, 
                     tad_special_price.value) < 100, 
          IF( 
             Ifnull(tas_special_price.value_id, -1) > 0, 
          tas_special_price.value, 
                                                     tad_special_price.value), 0 
          ) > 0, 
       Round( 
       IF(Ifnull(tas_price.value_id, -1) > 0, tas_price.value, tad_price.value) 
       * ( IF( 
       IF 
       (ta_special_from_date.value IS NULL, 1, IF( 
             ta_special_from_date.value <= 
             cwd.website_date, 1, 0)) > 0 
             AND IF(ta_special_to_date.value IS NULL, 1, IF( 
                     ta_special_to_date.value >= cwd.website_date, 1, 0)) > 0 
             AND IF(Ifnull(tas_special_price.value_id, -1) > 0, 
                 tas_special_price.value, 
                     tad_special_price.value) > 0 
             AND IF(Ifnull(tas_special_price.value_id, -1) > 0, 
                 tas_special_price.value, 
                     tad_special_price.value) < 100, 
           IF( 
             Ifnull(tas_special_price.value_id, -1) > 0, 
           tas_special_price.value, 
                                                     tad_special_price.value), 0 
           ) / 100 
       ), 4), IF(Ifnull(tas_price.value_id, -1) > 0, tas_price.value, 
              tad_price.value)) 
                       AS `max_price`, 
       IF(tp.min_price IS NOT NULL, Round(IF(Ifnull(tas_price.value_id, -1) > 0, 
                                          tas_price.value, tad_price.value) 
                                                                       - ( 
                                          IF(Ifnull(tas_price.value_id, -1) > 0, 
                                          tas_price.value, tad_price.value) * ( 
                                          tp.min_price / 100 ) ), 4), NULL) 
       AS
       `tier_price`, 
       IF(tp.min_price IS NOT NULL, Round(IF(Ifnull(tas_price.value_id, -1) > 0, 
                                          tas_price.value, tad_price.value) 
                                                                       - ( 
                                          IF(Ifnull(tas_price.value_id, -1) > 0, 
                                          tas_price.value, tad_price.value) * ( 
                                          tp.min_price / 100 ) ), 4), NULL) 
       AS
       `base_tier` 
FROM   `catalog_product_entity` AS `e` 
       CROSS JOIN `customer_group` AS `cg` 
       CROSS JOIN `core_website` AS `cw` 
       INNER JOIN `core_store_group` AS `csg` 
               ON csg.group_id = cw.default_group_id 
       INNER JOIN `core_store` AS `cs` 
               ON cs.store_id = csg.default_store_id 
       INNER JOIN `catalog_product_website` AS `pw` 
               ON pw.product_id = e.entity_id 
                  AND pw.website_id = cw.website_id 
       INNER JOIN `catalog_product_index_website` AS `cwd` 
               ON cw.website_id = cwd.website_id 
       LEFT JOIN `catalog_product_index_tier_price` AS `tp` 
              ON tp.entity_id = e.entity_id 
                 AND tp.website_id = cw.website_id 
                 AND tp.customer_group_id = cg.customer_group_id 
       INNER JOIN `catalog_product_entity_int` AS `tad_status` 
               ON tad_status.entity_id = e.entity_id 
                  AND tad_status.attribute_id = 80 
                  AND tad_status.store_id = 0 
       LEFT JOIN `catalog_product_entity_int` AS `tas_status` 
              ON tas_status.entity_id = e.entity_id 
                 AND tas_status.attribute_id = 80 
                 AND tas_status.store_id = cs.store_id 
       LEFT JOIN `catalog_product_entity_int` AS `tad_tax_class_id` 
              ON tad_tax_class_id.entity_id = e.entity_id 
                 AND tad_tax_class_id.attribute_id = 81 
                 AND tad_tax_class_id.store_id = 0 
       LEFT JOIN `catalog_product_entity_int` AS `tas_tax_class_id` 
              ON tas_tax_class_id.entity_id = e.entity_id 
                 AND tas_tax_class_id.attribute_id = 81 
                 AND tas_tax_class_id.store_id = cs.store_id 
       INNER JOIN `catalog_product_entity_int` AS `ta_price_type` 
               ON ta_price_type.entity_id = e.entity_id 
                  AND ta_price_type.attribute_id = 470 
                  AND ta_price_type.store_id = 0 
       LEFT JOIN `catalog_product_entity_decimal` AS `tad_price` 
              ON tad_price.entity_id = e.entity_id 
                 AND tad_price.attribute_id = 60 
                 AND tad_price.store_id = 0 
       LEFT JOIN `catalog_product_entity_decimal` AS `tas_price` 
              ON tas_price.entity_id = e.entity_id 
                 AND tas_price.attribute_id = 60 
                 AND tas_price.store_id = cs.store_id 
       LEFT JOIN `catalog_product_entity_decimal` AS `tad_special_price` 
              ON tad_special_price.entity_id = e.entity_id 
                 AND tad_special_price.attribute_id = 61 
                 AND tad_special_price.store_id = 0 
       LEFT JOIN `catalog_product_entity_decimal` AS `tas_special_price` 
              ON tas_special_price.entity_id = e.entity_id 
                 AND tas_special_price.attribute_id = 61 
                 AND tas_special_price.store_id = cs.store_id 
       LEFT JOIN `catalog_product_entity_datetime` AS `ta_special_from_date` 
              ON ta_special_from_date.entity_id = e.entity_id 
                 AND ta_special_from_date.attribute_id = 62 
                 AND ta_special_from_date.store_id = 0 
       LEFT JOIN `catalog_product_entity_datetime` AS `ta_special_to_date` 
              ON ta_special_to_date.entity_id = e.entity_id 
                 AND ta_special_to_date.attribute_id = 63 
                 AND ta_special_to_date.store_id = 0 
       INNER JOIN `cataloginventory_stock_status` AS `ciss` 
               ON ciss.product_id = e.entity_id 
                  AND ciss.website_id = cw.website_id 
WHERE  ( e.type_id = 'bundle' ) 
       AND ( IF(Ifnull(tas_status.value_id, -1) > 0, tas_status.value, 
             tad_status.value) = 1 ) 
       AND ( ta_price_type.value = 1 ) 
       AND ( e.entity_id IN( 99, 228, 248, 249, 
                             251, 252, 257, 263, 275 ) ) 
       AND ( ciss.stock_status = 1 )

1 个答案:

答案 0 :(得分:0)

这是一个解释如何减少特定查询的线程。我没有花时间尝试自己,当我这样做时,我会把修复程序作为模块,但更快的方法是将文件的副本放在'code / local'文件夹中。

http://www.magentocommerce.com/boards/viewthread/38818/P90/#t367525