4、有一个索引,查询语句仍然执行一次全表扫描。 selectcust_Id,cust_name from customers where cust_rating<>'aa'; 把上面的语句改成如下的查询语句,这样,在采用基于规则的优化器而不是基于代价的优化器(更智能)时,将会使用索引。 selectcust_Id,cust_name from customers where cust_rating<'aa'orcust_rating>
6、 如果不使用基于函数的索引,那么在SQL语句的WHERE子句中对存在索引的列使用函数时,会使优化器忽略掉这些索引。 下面的查询不会使用索引(只要它不是基于函数的索引) selectempno,ename,deptno from emp where trunc(hiredate)='01-MAY-81'; 把上面的语句改成下面的语句,这样就可以通过索引进行查找。 selectempno,ename,deptno from emp
7、 where hiredate<(to_date('01-MAY-81')+0.9999); 4.4比较不匹配的数据类型 比较不匹配的数据类型也是比较难于发现的性能问题之一。 注意下面查询的例子,account_number是一个VARCHAR2类型,在account_number字段上有索引。下面的语句将执行全表扫描。 selectbank_name,address,city,state,zip from banks where acco
8、unt_number=990354; Oracle可以自动把where子句变成to_number(account_number)=990354,这样就限制了索引的使用,改成下面的查询就可以使用索引: selectbank_name,address,city,state,zip from banks where account_number='990354'; 特别