限制索引

一、不等于操作符(<>、!=)

表customers表的cust_rating列有一个索引,但下面的查询语句仍然全表扫描

select cust_id,cust_name from customers where cust_rating <> 'aa';

将上面语句改成如下查询语句,采用基于规则的优化器时,会使用索。

select cust_id,cust_name from customers where cust_rating<'aa' or cust_rating >'aa';

二、IS NULL或IS NOT NULL

三、使用函数

  select * from emp where trunc(hsdate)='01-sep-10';

上面的语句就不会使用索引,下列语句会使用索引

select * from emp where hsdate<(to_date('01-sep-10')+0.9999);

四、比较不匹配的数据类型

account_number varchar2(18);

select * from banks where account_number = 123456

oracle会自动把where子句改成:to_number(account_number)=123456;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章