我开发了一个大约有20万个广告的分类广告网站。 当用户访问特定类别时,我会多次运行此查询。
# Time: 171129 21:04:05
# User@Host: erich33_bache4[erich33_bache4] @ localhost []
# Thread_id: 11596 Schema: erich33_bache3 QC_hit: No
# Query_time: 0.629711 Lock_time: 0.000252 Rows_sent: 75 Rows_examined: 12717
use erich33_bache3;
SET timestamp=1512007445;
SELECT `category`.`id` as `category_id`, `category`.`subcat` as `category_name`, `category`.`desc` as `category_desc`, `category`.`name` as `category_pretty_name`, `ads`.`id`, `ads`.`header`, `ads`.`price`, `ads`.`oldprice`, `ads`.`sellfast`, `ads`.`hash`, `ads`.`foto1`, `ads`.`foto2`, `ads`.`foto3`, `ads`.`foto4`, `ads`.`foto5`, `ads`.`user_id`, SUBSTR(ads.body, 1, 160) as body, `ads`.`subcat_id`, `ads`.`updated`, `ads`.`created`, `ads`.`email`, `ads`.`name`, `ads`.`phone`, `ads`.`hits`, `ads`.`hidden`, `promo`.`promotype` as `promo_type`, `provinces`.`prov_name`, `supercategory`.`name` as `supercategory_name`, `supercategory`.`id` as `supercategory_id`
FROM `ads`
JOIN `category` ON `category`.`id` = `ads`.`subcat_id`
JOIN `supercategory` ON `supercategory`.`id` = `category`.`cat`
JOIN `provinces` ON `provinces`.`id` = `ads`.`province_id`
LEFT OUTER JOIN `promo` ON `promo`.`ads_id` = `ads`.`id`
WHERE `ads`.`subcat_id` = '54'
AND `recycle_bin` != 1
AND `hidden` =0
ORDER BY `promo_type` DESC, `updated` DESC
LIMIT 75;
我的问题是,作为MySQL的专业知识,如何优化外表以获得更好的Query_time: 0.629711
这是EXPLAIN结果。我是MySQL的新手和菜鸟但是我想,可能会有一些优化。