标题:救助,关于union语句的优化
只看楼主
球球
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:1146
专家分:265
注 册:2005-11-28
结帖率:100%
 问题点数:0 回复次数:2 
救助,关于union语句的优化
请问,下面的这条语句该怎么优化?
Select Count(*) as usercount from (

SELECT UserID FROM IPTV_COOK_PROGRESS where RowTime between '08-08-01' and '08-08-31'

UNION SELECT UserID FROM IPTV_FISH_HISTORY where RowTime between '08-08-01' and '08-08-31'

UNION SELECT UserID FROM IPTV_FIND_HISTORY where RowTime between '08-08-01' and '08-08-31'

UNION SELECT UserID FROM IPTV_QUIZ_HISTORY where RowTime between '08-08-01' and '08-08-31') a
搜索更多相关主题的帖子: union 语句 救助 
2008-09-02 11:28
bb3852
Rank: 1
等 级:新手上路
帖 子:82
专家分:0
注 册:2008-4-21
得分:0 
1 * 改为1
2 union 改为union all
3 between and 改为>= <=
4 RowTime建立索引

http://hi.baidu.com/bb3852
数据库开发有兴趣的朋友们,里面有很多原创代码
qq:184882759
2008-09-02 13:13
球球
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:1146
专家分:265
注 册:2005-11-28
得分:0 
谢谢。我分别在RowTime_UserID,RowTime,UserID上面创建了索引,查询百万条数据,从1万6毫秒提高到2百毫秒以内。

好累
2008-09-05 02:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-230972-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.412293 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved