今天发现一个奇怪的问题,找了大量资料没有找到原因只有在这求助了
在一张user表里有个整型字段importance,在上面我建立了索引
select * from user where importance = 1
索引生效select * from user where importance >=1 and importance <=1 索引不起作用希望各位老大赐教
在一张user表里有个整型字段importance,在上面我建立了索引
select * from user where importance = 1
索引生效select * from user where importance >=1 and importance <=1 索引不起作用希望各位老大赐教
analyze table table_name(索引基表) delete statistics;
TABLE ACCESS BY INDEX ROWID Object owner=SYSTEM Object name=TBEMP
INDEX RANGE SCAN Object owner=SYSTEM Object name=IX_TBEMPCODE 查询速度test: DECLARE
i integer ;
sex char(2) ;
vname varchar(2000) ;
d1 date ;
d2 date ;
begin
d1 := sysdate ;
SELECT name into vname FROM TBEMP WHERE code>=1111111 and code<=1111111 ;
d2:=sysdate ;
dbms_output.put_line(vname) ;
dbms_output.put_line('用时:'||((d2-d1)*3600*24)||'秒') ;
end ; 用时0.014秒
是直接通过索引找到=1的记录select * from user where importance >=1 and importance <=1
不仅要找到=1地记录,而且还要全表找到满足〉1,<1地记录
相当于全表扫描了嘛,索引应该是不起作用的啊~~~
我测试了是起作用的,指定索引试试
select /*+index(t,idx_importance)*/
* from user t
where importance >=1 and importance <=1