select * from ipinfo p where p.startip > ip and p.endip < ip我在 表ipinfo中 将  startip 和 endip 两个字段都 设为 BTree索引,都不起作用...仍然是Table Access Full存储过程的时间都花在这句上面了...........对索引理解有限,谢谢大家。顺便请教 在 pl/sql developer 中 将 两个字段都设在同一个索引内 和 分开设 有区别吗?

解决方案 »

  1.   

    你试试 select * from ipinfo p where ip between p.startip and p.endip  
      

  2.   


    这要看查询条件,如果两个字段经常在一起用作联系查询,如上面的p.startid和p.endip,则最好建组合索引,如果两个字段不在一起做查询条件,而是常单独做查询条件,那么应该为每个字段单独建立一个索引。
      

  3.   

    你的where条件中有两个条件,所以,索引只有一个字段是不会起作用的,做如下工作:sql> create index idx_ipinfo_id on ipinfo(startip, endip);sql> exec dbms_stats.gather_table_stats(user, 'IPINFO', method_opt=>'for all indexed columns', cascade=>true);注:有了这个索引之后,也要看你的返回结果集的数据量占整表的数据量的比较,如果超过15%,oracle的CBO优化器会选择全表检索的,因为大数据量检查全表检查更快