我正在查看慢查询日志,我发现以下查询效率低下。鉴于查询,我如何将其追溯到Magento源代码(理想情况下是文件)?:
SELECT count(DISTINCT e.entity_id) FROM `sales_flat_order_item` AS `order_items`
INNER JOIN `sales_flat_order` AS `order` ON `order`.entity_id = order_items.order_id AND `order`.state <> 'canceled' AND (`order`.created_at BETWEEN '2012-08-22 04:17:19' AND '2013-08-22 04:17:19')
LEFT JOIN `catalog_product_entity` AS `e` ON (e.type_id NOT IN ('grouped', 'configurable', 'bundle')) AND e.entity_id = order_items.product_id AND e.entity_type_id = 4
INNER JOIN `catalog_product_entity_int` AS `at_visibility_default` ON (`at_visibility_default`.`entity_id` = `e`.`entity_id`) AND (`at_visibility_default`.`attribute_id` = '102') AND `at_visibility_default`.`store_id` = 0
LEFT JOIN `catalog_product_entity_int` AS `at_visibility` ON (`at_visibility`.`entity_id` = `e`.`entity_id`) AND (`at_visibility`.`attribute_id` = '102') AND (`at_visibility`.`store_id` = 1)
INNER JOIN `catalog_product_entity_int` AS `at_status_default` ON (`at_status_default`.`entity_id` = `e`.`entity_id`) AND (`at_status_default`.`attribute_id` = '96') AND `at_status_default`.`store_id` = 0
LEFT JOIN `catalog_product_entity_int` AS `at_status` ON (`at_status`.`entity_id` = `e`.`entity_id`) AND (`at_status`.`attribute_id` = '96') AND (`at_status`.`store_id` = 1) WHERE (parent_item_id IS NULL) AND (IF(at_visibility.value_id > 0, at_visibility.value, at_visibility_default.value) IN(2, 4)) AND (IF(at_status.value_id > 0, at_status.value, at_status_default.value) = '1')\G
答案 0 :(得分:1)
打开lib/Varien/Db/Adapter/Pdo/Mysql.php
,您会看到如下:
/**
* Write SQL debug data to file
*
* @var bool
*/
protected $_debug = false;
/**
* Log all queries (ignored minimum query duration time)
*
* @var bool
*/
protected $_logAllQueries = false;
/**
* Add to log call stack data (backtrace)
*
* @var bool
*/
protected $_logCallStack = false;
因此,如果您将$_logCallStack
设置为true
,您将在日志文件中看到所需的一切。