首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

问一个带索引的查询有关问题

2012-01-12 
问一个带索引的查询问题。表day_subtotal有两个索引day_number,user_id,def_id使用查询select*fromday_subt

问一个带索引的查询问题。
表day_subtotal有两个索引day_number,user_id,def_id
使用查询select   *   from   day_subtotal   where   user_id=****   and   def_id=**速度很快。
但加上day_number字段的判断,就速度非常的慢。
请问这是怎么回事,该怎么调优呢?
谢谢。

[解决办法]
你在PLSQL Developer分别用F5看看,两句话用到的索引有什么区别。。。
[解决办法]
再在day_number上创建个索引吧

[解决办法]
ORACLE采用自下而上的顺序解析WHERE子句
你可以把day_number放在前面,如

select * from day_subtotal where day_number=xxx and user_id=**** and def_id=**
这样速度应该没什么影响。
另外还要注意day_number这个字段的类型,如果day_number是varchar型的
你却这样写
select * from day_subtotal where day_number=123;
这样的话将会很慢。
正确写法是要类型匹配
select * from day_subtotal where day_number= '123 '
[解决办法]
看看查询计划。。进行分析

热点排行