假如 [分區(qū)表] 在字段 [createdate] 上進行分區(qū),每個月為一個分區(qū):
2009年6月為分區(qū)P200906
2009年7月為分區(qū)P200907
2009年8月為分區(qū)P200908
。。。
執(zhí)行SQL 使用分區(qū)鍵檢索:
select*from 分區(qū)表 t where createdate > to_date('2009-07-12','yyyy-mm-dd') and createdate < to_date('2009-08-12','yyyy-mm-dd')
執(zhí)行計劃如下,使用分區(qū)鍵進行索引,會自動在數(shù)據(jù)存在的區(qū)進行檢索。因為開始區(qū)為2,結束區(qū)為3,一目了然。
SELECT STATEMENT, GOAL = ALL_ROWS
PARTITION RANGE ITERATOR Partition start=2 Partition stop=3
TABLE ACCESS FULL Partition start=2 Partition stop=3
執(zhí)行SQL 不使用分區(qū)鍵檢索:
select*from 分區(qū)表 t where sms_report_date > to_date('2009-07-12','yyyy-mm-dd') and sms_report_date < to_date('2009-08-12','yyyy-mm-dd')
執(zhí)行計劃如下:沒有使用分區(qū)鍵進行檢索,那么則會查詢全部的表分區(qū)。因為要查詢的數(shù)據(jù)就在2和3分區(qū)上,其它的分區(qū)數(shù)據(jù)也被讀取了,增大了數(shù)據(jù)庫壓力,效率低下。
SELECT STATEMENT, GOAL = ALL_ROWS
PARTITION RANGE ALL Partition start=1 Partition stop=31
TABLE ACCESS FULL Partition start=1 Partition stop=31
執(zhí)行SQL 指定使用分區(qū):
select*from 分區(qū)表 partition(P200907) t where sms_report_date > to_date('2009-07-12','yyyy-mm-dd') and sms_report_date < to_date('2009-08-12','yyyy-mm-dd')
執(zhí)行計劃如下:
SELECT STATEMENT, GOAL = ALL_ROWS
PARTITION RANGE SINGLE Partition start=2 Partition stop=2
TABLE ACCESS FULL Partition start=2 Partition stop=2