MySQL优化
我试图加快我的网站速度,主要问题是一个几乎在所有页面上运行的查询(下面的代码)。 LIMIT 更改可以加快速度,但我需要使用 LIMIT 99 :( 24 日速度约为 0.06 秒。 100 ~ 0.105 秒 服务器限制:子查询(SELECT video_names.name...)不能更改为 JOIN
SELECT `videos`.`name`, `videos`.`episodes`, `videos`.`is_ended`, `videos`.`id`, `videos`.`logo`, `videos`.`type`, `user_videos`.`episode`,
(SELECT `video_names`.`name`
FROM (`video_names`)
WHERE `video_names`.`vid_id` = `videos`.`id` LIMIT 1) as alt_name
FROM (`videos`)
JOIN `user_videos` ON `user_videos`.`vid_id` = `videos`.`id`
WHERE `user_videos`.`user_id` = '1'
AND `user_videos`.`status` = '1'
GROUP BY `videos`.`id`
ORDER BY `last_change` desc
LIMIT 24
I trying to speed up my site and main problem on it one query (code below) that runs on almost all pages.
LIMIT changes make speed up, but I need to use LIMIT 99 :(
On 24 speed is ~ 0.06 sec.
On 100 ~ 0.105 sec.
Server restriction: subquery (SELECT video_names.name...) can't be changed to JOIN
SELECT `videos`.`name`, `videos`.`episodes`, `videos`.`is_ended`, `videos`.`id`, `videos`.`logo`, `videos`.`type`, `user_videos`.`episode`,
(SELECT `video_names`.`name`
FROM (`video_names`)
WHERE `video_names`.`vid_id` = `videos`.`id` LIMIT 1) as alt_name
FROM (`videos`)
JOIN `user_videos` ON `user_videos`.`vid_id` = `videos`.`id`
WHERE `user_videos`.`user_id` = '1'
AND `user_videos`.`status` = '1'
GROUP BY `videos`.`id`
ORDER BY `last_change` desc
LIMIT 24
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
那行不通吗?
Couldn't that work ?
试试这个脚本
Try this script
我测试了 StackOverflow 和其他来源的所有变体。最高速度:
sql_big_selects=1
的查询(时间 x4.5)sql_big_selects=1
的查询(时间 x4.5) x5 及更慢)I test all variants from StackOverflow and other sources. Top speed:
sql_big_selects=1
(time x4.5)sql_big_selects=1
(time x5 and slower)