项目上遇到一个郁闷的事,我有一个表 车辆通行 有两个字段 经过时间和记录类型
我为这两个字段都加了索引。
单独以这两个字段为条件的查询都很快 在1秒内
但两个字段联合作为记录时 却要20多秒
我的查询语句是 select count (id) from cltx where jgsj>'2010-11-17' and jgsj<'2010-11-18' and jllx='2'
总数据量不到50万条,这条语句的结果5000+条
按说不应该要20多秒的。
哎。。 高手,小弟先在此拜谢
我为这两个字段都加了索引。
单独以这两个字段为条件的查询都很快 在1秒内
但两个字段联合作为记录时 却要20多秒
我的查询语句是 select count (id) from cltx where jgsj>'2010-11-17' and jgsj<'2010-11-18' and jllx='2'
总数据量不到50万条,这条语句的结果5000+条
按说不应该要20多秒的。
哎。。 高手,小弟先在此拜谢
解决方案 »
- oracle case when 查询
- 如何求得两个周次的天数
- 求Oracle数据库开发之命名规范
- 冷备的数据文件怎么恢复?
- oracle程序员,有没有好用的在线帮助手册?
- ★★★高分请教高手Oracle数据导出到SqlServer2000的数据兼容问题!★★★
- Problem with Arabic language in Oracle
- 问个初级问题,怎么创建包?--求救呀
- 我装了9i,可以在服务器用sqlplus可能连上,但在其它机子就安不上了,我在用jbuilder的连接工具就能连,这是为什么啊,我怎么才能用其它工
- 如何对多行求和,结果只显示在第一行,其它行显示为空
- 关于oracle游标的紧急问题,请高手帮忙!!!
- 游标问题
select count(id) from
(
select * from cltx where jgsj>'2010-11-17' and jgsj<'2010-11-18'
)
where jllx='2'
select count (id) from cltx where jgsj>'2010-11-17' and jgsj<'2010-11-18' and jllx='2'
发现执行速度也是12秒。。而且还有
我执行select count (id) from cltx where jllx='2'的时候,按F5 可以看到执行了jllx的索引
但是执行select count (id) from cltx where jgsj>'2010-11-17' and jgsj<'2010-11-18' and jllx='2'
的时候 只看到执行jgsj的索引
介四为嘛呀~~!!!
建了个索引叫jllx 字段是jllx
还一个是jgsj 字段是jgsj
我现在count(id) count(jgsj) count(jllx)
还有那三个条件的顺序 不论如何
查询结果都是那该死的12秒
where jgsj>'2010-11-17' and jgsj<'2010-11-18' and jllx='2'
哪个条件的记录少些 就优先前面过滤id 是否为主键
--试试下面的看看能
select count(主键) from cltx where jgsj>'2010-11-17' and jgsj<'2010-11-18' and jllx='2'
--or
select count(主键)
from (select 主键 from cltx where jgsj>'2010-11-17' and jgsj<'2010-11-18' and jllx='2'
)
开始是索引A on colum A
B on colum B
现在是C on colum A,B 就好了
建个联合索引试试
create index idx_name on cltx(jgsj,jllx)
,用联合索引,太合适了