我们假设temp_zhangxb_2015110501a 是千万级的大表,而cust_id中有几个null值,且cust_id 中不会存在'1'的值,那么我们这么做:
create index ind_custid2 on temp_zhangxb_2015110501a(nvl(cust_id,'1'));
select /*+ index(t ind_custid2)*/* from temp_zhangxb_2015110501a t where nvl(t.cust_id,'1') = '1';
你就会在执行计划中看到调用索引ind_custid2的情况
倘若不用ind_custid2索引,就会走全表扫描,为了几条数据,实在不值当啊,有不知情的人也许会问,那在cust_id建个索引不就完了,...因为我们找的是null值,常规索引是不行的,大家要注意