MySQL慢查询不会使用索引

时间:2014-04-18 06:47:40

标签: mysql

无法理解为什么此查询不会使用表提供程序可用的索引之一。这里的任何帮助非常感谢。

SELECT SQL_CALC_FOUND_ROWS 
  provider.id, 
  provider.account_id, 
  provider.title,
  provider.email,
  provider.url,
  provider.phone,

(3959 * acos( cos( radians(151.273824) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(151.273824) ) + sin( radians(-33.766629) ) * sin( radians( latitude ) ) ) * 1.609344) AS distance, 

(SELECT email FROM contact WHERE account_id = provider.account_id) AS account_email 

FROM    
    provider
LEFT JOIN 
    provider_to_category 
ON 
    provider_to_category.provider_id = provider.id 
WHERE  
    provider_to_category.category_id = 467 
AND 
    provider.status = 'A' 
AND  
   ((POW((69.1 * (151.273824 - longitude ) * cos(-33.766629/57.3)),2) + POW( (69.1 * (-33.766629 - latitude)),2) ) < (30)) 
ORDER BY 
    distance DESC
LIMIT 0, 30;

id | select_type        | table                 | type    | possible_keys   | key       | key_len    | ref                    | rows    | filtered  | Extra
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1  | PRIMARY            | provider              | ALL     | PRIMARY,status  | (null)    | (null)    | (null)                  | 353687  | 99.99  |  Using where; Using filesort
1  | PRIMARY            | provider_to_category  | ref     | Index 1         | Index 1   | 8         | db1.provider.id,const   | 1       | 100.00 |  Using where; Using index
2  | DEPENDENT SUBQUERY | contact               | eq_ref  | PRIMARY         | PRIMARY   | 4         | db1.provider.account_id | 1       | 100.00 |  


CREATE TABLE `provider_to_category` (
  `provider_id` INT(11) NOT NULL DEFAULT '0',
  `category_id` INT(11) NOT NULL DEFAULT '0',
  INDEX `Index 1` (`provider_id`, `category_id`)
)
COLLATE='utf8_general_ci'
ENGINE=MyISAM;

0 个答案:

没有答案