程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> oracle10g下范圍分區掃描的幾種方式

oracle10g下范圍分區掃描的幾種方式

編輯:Oracle教程

oracle 10g下有幾種掃描方式,注意最後一種掃描方式,當對分區的列進行計算時,會不走分區,這跟對索引列進行計算會導致無法用索引一樣。

--掃描單個分區 PARTITION RANGE SINGLE
--連續掃描多個分區 PARTITION RANGE ITERATOR
--不連續掃描多個分區 PARTITION RANGE INLIST
--掃描全分區 PARTITION RANGE ALL

SQL> drop table t_range purge;

SQL> create table t_range (id number not null PRIMARY KEY, test_date date) partition by range (test_date)
(
partition p_1 values less than (to_date('2013-12-01', 'yyyy-mm-dd')),
partition p_2 values less than (to_date('2014-02-01', 'yyyy-mm-dd')),
partition p_3 values less than (to_date('2014-03-01', 'yyyy-mm-dd')),
partition p_4 values less than (to_date('2014-04-01', 'yyyy-mm-dd')),
partition p_5 values less than (to_date('2014-05-01', 'yyyy-mm-dd')),
partition p_6 values less than (to_date('2014-06-01', 'yyyy-mm-dd')),
partition p_max values less than (MAXVALUE)
) nologging;
SQL> insert /*+append */ into t_range select rownum,
to_date(to_char(sysdate - 140, 'J') +
trunc(dbms_random.value(0, 80)),
'J')
from dual
connect by rownum <= 100000;
SQL> commit;
SQL> exec dbms_stats.gather_table_stats(user,'T_RANGE');
SQL> select to_char(t.test_date,'yyyy-MM'),count(1) from t_range t
group by to_char(t.test_date,'yyyy-MM');
TO_CHAR COUNT(1)
------- ----------
2014-01 38803
2014-03 11242
2013-12 15107
2014-02 34848

SQL> set autotrace traceonly
--掃描單個分區
SQL> select * from t_range where test_date = to_date('2014-04-28', 'yyyy-mm-dd');
執行計劃
----------------------------------------------------------
Plan hash value: 3010141842
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
--------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 22 | 2 (0)| 00:00:01 | | |
| 1 | PARTITION RANGE SINGLE| | 1 | 22 | 2 (0)| 00:00:01 | 5 | 5 |
|* 2 | TABLE ACCESS FULL | T_RANGE | 1 | 22 | 2 (0)| 00:00:01 | 5 | 5 |
--------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("TEST_DATE"=TO_DATE('2014-04-28 00:00:00', 'yyyy-mm-dd hh24:mi:ss'))
統計信息
----------------------------------------------------------
1 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
327 bytes sent via SQL*Net to client
374 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed

--連續掃描多個分區
SQL> select * from t_range
where test_date <= to_date('2014-04-28', 'yyyy-mm-dd')
and test_date >= to_date('2014-02-28', 'yyyy-mm-dd');
執行計劃
----------------------------------------------------------
Plan hash value: 1921532398
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 12556 | 147K| 28 (0)| 00:00:01 | | |
| 1 | PARTITION RANGE ITERATOR| | 12556 | 147K| 28 (0)| 00:00:01 | 3 | 5 |
|* 2 | TABLE ACCESS FULL | T_RANGE | 12556 | 147K| 28 (0)| 00:00:01 | 3 | 5 |
----------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("TEST_DATE">=TO_DATE('2014-02-28 00:00:00', 'yyyy-mm-dd hh24:mi:ss') AND
"TEST_DATE"<=TO_DATE('2014-04-28 00:00:00', 'yyyy-mm-dd hh24:mi:ss'))
統計信息
----------------------------------------------------------
1 recursive calls
0 db block gets
956 consistent gets
0 physical reads
0 redo size
309138 bytes sent via SQL*Net to client
9515 bytes received via SQL*Net from client
832 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
12453 rows processed

--不連續掃描多個分區
SQL> select * from t_range
where test_date = to_date('2014-04-28', 'yyyy-mm-dd')
or test_date = to_date('2014-02-28', 'yyyy-mm-dd');
執行計劃
----------------------------------------------------------
Plan hash value: 2021067984
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
--------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1678 | 20136 | 21 (0)| 00:00:01 | | |
| 1 | PARTITION RANGE INLIST| | 1678 | 20136 | 21 (0)| 00:00:01 |KEY(I) |KEY(I) |
|* 2 | TABLE ACCESS FULL | T_RANGE | 1678 | 20136 | 21 (0)| 00:00:01 |KEY(I) |KEY(I) |
--------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("TEST_DATE"=TO_DATE('2014-02-28 00:00:00', 'yyyy-mm-dd hh24:mi:ss') OR
"TEST_DATE"=TO_DATE('2014-04-28 00:00:00', 'yyyy-mm-dd hh24:mi:ss'))
統計信息
----------------------------------------------------------
1 recursive calls
0 db block gets
175 consistent gets
0 physical reads
0 redo size
22646 bytes sent via SQL*Net to client
1265 bytes received via SQL*Net from client
82 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1211 rows processed


--掃描全分區
SQL> select * from t_range where to_char(test_date,'yyyy-MM-dd')='2014-04-01';
執行計劃
----------------------------------------------------------
Plan hash value: 2128486036
-----------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 994 | 11928 | 59 (4)| 00:00:01 | | |
| 1 | PARTITION RANGE ALL| | 994 | 11928 | 59 (4)| 00:00:01 | 1 | 7 |
|* 2 | TABLE ACCESS FULL | T_RANGE | 994 | 11928 | 59 (4)| 00:00:01 | 1 | 7 |
-----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter(TO_CHAR(INTERNAL_FUNCTION("TEST_DATE"),'yyyy-MM-dd')='2014-04-01')
統計信息
----------------------------------------------------------
1 recursive calls
0 db block gets
272 consistent gets
0 physical reads
0 redo size
327 bytes sent via SQL*Net to client
374 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved