有时候 group by 为什么这么慢呢
2011-05-31 20:45
239 查看
假设三个表 t_user , t_user_detail , t_log_info 记录都比较多(5000~1000)。
select count(user_id),a.user_type from t_user ainner join t_user_detail b on a.user_id=b.user_idinner join t_log_info c on b.user_id=c.user_idwhere a.user_type=100
这样会比较慢。
一个小小的改进速度会快很多。 b.user_id 改成 a.user_id
select count(user_id),a.user_type from t_user ainner join t_user_detail b on a.user_id=b.user_idinner join t_log_info c on a.user_id=c.user_idwhere a.user_type=100
个人观点, 表关联时尽量用where过滤后记录比较少的表的字段关联。
select count(user_id),a.user_type from t_user ainner join t_user_detail b on a.user_id=b.user_idinner join t_log_info c on b.user_id=c.user_idwhere a.user_type=100
这样会比较慢。
一个小小的改进速度会快很多。 b.user_id 改成 a.user_id
select count(user_id),a.user_type from t_user ainner join t_user_detail b on a.user_id=b.user_idinner join t_log_info c on a.user_id=c.user_idwhere a.user_type=100
个人观点, 表关联时尽量用where过滤后记录比较少的表的字段关联。
相关文章推荐
- 为什么有时候 进入这么多次,一次是 38次,一次是 114次,
- 为什么 Android Studio 工程文件夹占用空间这么大?
- utf8编码为什么这么普遍,优势在哪里?
- 程序员转行为什么这么难
- 市场竞争这么大 为什么我们不提供免费建站
- 为什么HTTP有时候比HTTPS要好?
- 为什么BAT等互联网公司在校招里这么受追捧?
- 大神节,大神为什么这么拼?
- 为什么成为一名程序员这么难
- 程序员你为什么这么累?
- U3D这么优秀为什么还有那么多手游厂商望而却步
- unity游戏开发为什么工作这么难找
- 程序员你为什么这么累【续】:如何应对需求变更
- 我们为什么这么容易受骗?
- 集合操作的ConcurrentModificationException异常分析,为什么有时候循环remove不会异常?Iterator方式也会异常吗?
- 为什么腾讯后来居上的能力这么强
- Netflix on Linux:如何在Linux上使用Netflix以及为什么在Linux上使用Netflix怎么就这么难
- 服务器为什么这么慢?耗尽了CPU、RAM和磁盘I/O资源
- Docker到底是什么?为什么它这么火!