通過對比分區表和普通表,簡單的測試了效能和對分區表存在index時的維護,最後我們不得不說
使用分區表很多時候不一定能提高效能,主要是維護起來方便,如果我們能把訪問的資料集中
在一個或者有限的幾個分區裡,那麼效能肯定比訪問普通的全表要好,還是那句話
讓執行的sql儘可能的少讀、少寫,這樣才是提高sql效能的關鍵,就像anlinew提到的公式:
T=S/V,其實少讀、少寫的目的就是減小S...
--建立2個結構完全相同,資料量幾乎相同的表,只不過是分區表,一個是普通的heap表,然後簡單的做個訪問時的效能對比,從而更好的理解如何合理的使用分區表
SQL> create table t(object_id number,object_name varchar2(30))
2 partition by range(object_id)
3 (
4 partition p1 values less than(2000) tablespace users,
5 partition p2 values less than(4000) tablespace users,
6 partition p3 values less than(6000) tablespace users,
7 partition p4 values less than(8000) tablespace users,
8 partition p5 values less than(maxvalue) tablespace users
9 );
表已建立。
SQL> insert into t select object_id,object_name from dba_objects;
已建立9848行。
SQL> insert into t select * from t;
已建立9848行。
SQL> insert into t select * from t;
已建立19696行。
SQL> insert into t select * from t;
已建立39392行。
SQL> insert into t select * from t;
已建立78784行。
SQL> insert into t select * from t;
已建立157568行。
SQL> insert into t select * from t;
已建立315136行。
SQL> insert into t select * from t;
已建立630272行。
SQL> commit;
提交完成。
SQL> create table t1 tablespace users as select object_id,object_name from dba_o
bjects;
表已建立。
SQL> insert into t1 select *from t1;
已建立9849行。
SQL> insert into t1 select *from t1;
已建立19698行。
SQL> insert into t1 select *from t1;
已建立39396行。
SQL> insert into t1 select *from t1;
已建立78792行。
SQL> insert into t1 select *from t1;
已建立157584行。
SQL> insert into t1 select *from t1;
已建立315168行。
SQL> insert into t1 select *from t1;
已建立630336行。
SQL> commit;
提交完成。
SQL>
1.先來看不垮分區訪問時的效能對比,這裡我們主要關注邏輯度(consistent gets),
由於第一次訪問sql存在解析,因此我們對比時都看第二次訪問時的情況,
下面的實驗對比都是這樣...
注意:目前2個表上都沒有index
SQL> select * from t1 where object_id<2000;
已選擇249984行。
執行計畫
----------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 270K| 20M| 1069 (4)| 00:00:13 |
|* 1 | TABLE ACCESS FULL| T1 | 270K| 20M| 1069 (4)| 00:00:13 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID"<2000)
返回欄目頁:http://www.bianceng.cnhttp://www.bianceng.cn/database/Oracle/