標籤:全表掃描 format 訪問 顯示 test 做了 情境 keep others
These two terms in the Predicate Information section indicate when the data source is reduced. Simply, access means only retrieve those records meeting the condition and ignore others. Filter means
after you already got the data, go through them all and keep those meeting the condition and throw away the others.
1 access: 直接擷取那些滿足條件的資料,拋棄其他不滿足的資料
2 filter: 你已經有了一些資料,對這些已經有的資料應用filter,得到滿足filter的資料。
很多部落格論壇都有如下結論:
access表示這個謂詞條件的值將會影響資料的訪問路徑(表or索引),而filter表示謂詞條件的值並不會影響資料訪問路徑,只起到過濾的作用。
但是這個結論很是含糊,而且容易歧義。很多人一看顯示filter 就認為oracle沒有訪問索引路徑的選擇,肯定走全表掃描進行資料擇取。真的是這樣嗎?
可以類比如下情境:
create table test(aa int ,bb int ) as select rownum,rownum from dba_objects;(10w資料量)
create index .... 在aa上建立索引
select count(aa) from test where aa<500 ----access,index range scan
select count(aa) from test where aa<50000 ----- filter,index fast full scan
select count(bb) from test where aa<50000 ----filter ,table full scan
select aa,bb from test where aa<500 and bb=5
1 -- filter (bb=5)
2 --access(aa<500)
當然如果bb上建立了索引,那麼filter,access的位置可能就會發生變化
明顯access與filter跟是否走索引還是全表掃描無關。
上面access走索引範圍掃描原因在於我只掃描到aa<500的index block我就返回結果了,而走索引快速掃描是對整個index做了掃描,相當於就是對10W條aa值對應的index block都進行掃描。那麼這樣區別就很明顯了,filter其實可以認為在資料擇取的過程中可能做了一些無用功,最終拋棄自己不需要的資料來擇取最終需要的資料,而access 在資料擇取方面更有針對性。也就是說access只是更傾向走索引(前提是索引存在而且合理的情況下)。
oracle 執行計畫 access和filter的區別