求2表连查好友发帖的sql优化
时间:2011-06-15
来源:互联网
et_content 内容表 数据300w
content_id user_id
文章id 用户id\
et_friend 用户好友表 数据50w
fid_fasong fid_jieshou
我的id 我加的好友id
目的查询出我的好友的发帖
现在2种方式都不是很理想
a:
SELECT * FROM et_friend where fid_fasong=$user[user_id];
出来(id,id,id,id,id,id,id,id,id,id)可能出来500个
SELECT * FROM et_content where user_id in (id,id,id,id,id,id,id,id,id,id) and conttype != 'reply' c.content_id>1000000;
由于in里的好友可能比较多 比如有500个
慢日志里有很多记录
b:
SELECT * FROM et_content AS c LEFT JOIN et_friend AS f ON c.user_id=f.fid_jieshou WHERE c.content_id>1000000 and f.fid_fasong='$user[user_id]' and conttype != 'reply' ORDER BY c.content_id DESC LIMIT $start,10"
2表left join
经常出错误 Incorrect key file for table '/tmp/#sql_192a_0.MYI'; try to repair it
估计是内存等不够
求大家给个好的优化思路,谢谢
content_id user_id
文章id 用户id\
et_friend 用户好友表 数据50w
fid_fasong fid_jieshou
我的id 我加的好友id
目的查询出我的好友的发帖
现在2种方式都不是很理想
a:
SELECT * FROM et_friend where fid_fasong=$user[user_id];
出来(id,id,id,id,id,id,id,id,id,id)可能出来500个
SELECT * FROM et_content where user_id in (id,id,id,id,id,id,id,id,id,id) and conttype != 'reply' c.content_id>1000000;
由于in里的好友可能比较多 比如有500个
慢日志里有很多记录
b:
SELECT * FROM et_content AS c LEFT JOIN et_friend AS f ON c.user_id=f.fid_jieshou WHERE c.content_id>1000000 and f.fid_fasong='$user[user_id]' and conttype != 'reply' ORDER BY c.content_id DESC LIMIT $start,10"
2表left join
经常出错误 Incorrect key file for table '/tmp/#sql_192a_0.MYI'; try to repair it
估计是内存等不够
求大家给个好的优化思路,谢谢
作者: dongdongmo 发布时间: 2011-06-15
索引情况如何
user_id上建立索引没有
B:
建立索引试试
et_content :content_id、conttype
et_friend:id_fasong
user_id上建立索引没有
B:
建立索引试试
et_content :content_id、conttype
et_friend:id_fasong
作者: wwwwb 发布时间: 2011-06-15
LEFT JOIN ?不应该是 inner join 么?
left join 把数据少的表 放在前面。
或者 SELECT * FROM et_content where user_id in(Select fid_jieshou * from et_friend Where fid_fasong='$user[user_id]' ****) and ****
left join 把数据少的表 放在前面。
或者 SELECT * FROM et_content where user_id in(Select fid_jieshou * from et_friend Where fid_fasong='$user[user_id]' ****) and ****
作者: jastby 发布时间: 2011-06-15
引用 1 楼 wwwwb 的回复:
索引情况如何
user_id上建立索引没有
B:
建立索引试试
et_content :content_id、conttype
et_friend:id_fasong
索引情况如何
user_id上建立索引没有
B:
建立索引试试
et_content :content_id、conttype
et_friend:id_fasong
都加了
作者: dongdongmo 发布时间: 2011-06-15
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28