gpt4 book ai didi

MySQL:优化 300 秒以上的查询?

转载 作者:行者123 更新时间:2023-11-29 11:16:19 25 4
gpt4 key购买 nike

我有一个分类网站,这个月我们有很多新访问者。

该网站简直爆炸了,并开始提供“无法与数据库连接”的信息。我正在使用 codeigniter,这是 Mysql 日志的跟踪:

# Time: 160924 22:50:20
# Thread_id: 1914 Schema: erich33_asd QC_hit: No
# Query_time: 378.515875 Lock_time: 375.061742 Rows_sent: 75 Rows_examined: 152644
SET timestamp=1474771820;
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`, SUBSTR(ads.body, 1, 160) as body, `ads`.`sellfast`, `ads`.`foto1`, `ads`.`foto2`, `ads`.`foto3`, `ads`.`foto4`, `ads`.`foto5`, `ads`.`updated`, `ads`.`created`, `ads`.`hits`, `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` = '22'
AND `recycle_bin` != 1
AND `hidden` =0
ORDER BY `promo_type` DESC, `updated` DESC
LIMIT 833, 75;

如您所见,完成需要378.515875 秒

您将如何优化此查询以减少时间?

最佳答案

问题是数据库模式中的索引配置错误。刚刚在 ads.recycle_bin、ads.hidden 和 ads.subcat_id 中添加了索引

谢谢!

关于MySQL:优化 300 秒以上的查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39682999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com