有一个表a(fsn varchar2(32),fflag varchar2(16)),里面数据15w左右,fsn上有惟一索引,fflag有2个值,0和1,其中fflag=1大约7w,fflag=0大约10w,上面建有位图索引BTMP,执行
select fflag,fsn from a where fflag='1';为什么不走位图索引,而走全表扫描,
而select fflag from a where fflag='1'和select count(*) from a where fflag='1' 却走位图索引,
select fflag,fsn from a where fflag='1';为什么不走位图索引,而走全表扫描,
而select fflag from a where fflag='1'和select count(*) from a where fflag='1' 却走位图索引,
select fflag,fsn from a where fflag='1';为什么不走位图索引,而走全表扫描
而select fflag from a where fflag='1'和select count(*) from a where fflag='1' 都不需要所有数据,所以走位图索引
是所有的索引 在一次取数据占表所有数据的1/10时候 ,oracle 就会采用全表扫描,因为这个时候用索引取反而更慢
真强大,那应该把optimizer_mode参数设置成什么呢
这个说话不完全对,关键是,你可以查看执行计划,上面两个查询通过扫描位图索引而不需要访问表就得到结果,而选择了fsn字段后,扫描索引+扫描表的成本大于直接扫描表的成本,所以采用全表扫描。