【eygle】Oracle的分割槽表和Local索引建立與維護
Oracle的分割槽技術在某些條件下可以極大的提高查詢的效能,所以被廣泛採用。
從產品上說,分割槽技術是Oracle企業版中獨立收費的一個元件。
以下是對於分割槽及本地索引的一個示例。
首先根據字典表建立一個測試分割槽表:
建立一個Local索引,注意這裡可以將不同分割槽的索引指定建立到不同的表空間:
我們可以通過查詢來對比一下分割槽表和非分割槽表的查詢效能差異:
對於非分割槽表的測試:
當增加表分割槽時,LOCAL索引被自動維護:
-The End-
http://www.eygle.com/archives/2008/04/partition_local_index.html
從產品上說,分割槽技術是Oracle企業版中獨立收費的一個元件。
以下是對於分割槽及本地索引的一個示例。
首先根據字典表建立一個測試分割槽表:
SQL> connect eygle/eygle
Connected.
SQL> CREATE TABLE dbobjs
2 (OBJECT_ID NUMBER NOT NULL,
3 OBJECT_NAME varchar2(128),
4 CREATED DATE NOT NULL
5 )
6 PARTITION BY RANGE (CREATED)
7 (PARTITION dbobjs_06 VALUES LESS THAN (TO_DATE('01/01/2007', 'DD/MM/YYYY')),
8 PARTITION dbobjs_07 VALUES LESS THAN (TO_DATE('01/01/2008', 'DD/MM/YYYY')));
Table created.
SQL> COL segment_name for a20
SQL> COL PARTITION_NAME for a20
SQL> SELECT segment_name, partition_name, tablespace_name
2 FROM dba_segments
3 WHERE segment_name = 'DBOBJS';
SEGMENT_NAME PARTITION_NAME TABLESPACE_NAME
-------------------- -------------------- ------------------------------
DBOBJS DBOBJS_06 EYGLE
DBOBJS DBOBJS_07 EYGLE
建立一個Local索引,注意這裡可以將不同分割槽的索引指定建立到不同的表空間:
SQL> CREATE INDEX dbobjs_idx ON dbobjs (created) LOCAL這個子句可以進一步調整為類似:
2 (PARTITION dbobjs_06 TABLESPACE users,
3 PARTITION dbobjs_07 TABLESPACE users
4 );
Index created.
CREATE INDEX dbobjs_idx ON dbobjs (created) LOCAL通過統一的tablespace子句為索引指定表空間。
(PARTITION dbobjs_06 TABLESPACE users,
PARTITION dbobjs_07 TABLESPACE users
) TABLESPACE users;
SQL> COL segment_name for a20
SQL> COL PARTITION_NAME for a20
SQL> SELECT segment_name, partition_name, tablespace_name
2 FROM dba_segments
3 WHERE segment_name = 'DBOBJS_IDX';
SEGMENT_NAME PARTITION_NAME TABLESPACE_NAME
-------------------- -------------------- ------------------------------
DBOBJS_IDX DBOBJS_06 USERS
DBOBJS_IDX DBOBJS_07 USERS
SQL> insert into dbobjs
2 select object_id,object_name,created
3 from dba_objects where created
6227 rows created.
SQL> commit;
Commit complete.
SQL> select count(*) from dbobjs partition (DBOBJS_06);
COUNT(*)
----------
6154
SQL> select count(*) from dbobjs partition (dbobjs_07);
COUNT(*)
----------
73
我們可以通過查詢來對比一下分割槽表和非分割槽表的查詢效能差異:
SQL> set autotrace on
SQL> select count(*) from dbobjs where created < to_date('01/01/2008','dd/mm/yyyy');
COUNT(*)
----------
6227
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT ptimizer=CHOOSE (Cost=1 Card=1 Bytes=9)
1 0 SORT (AGGREGATE)
2 1 PARTITION RANGE (ALL)
3 2 INDEX (RANGE SCAN) OF 'DBOBJS_IDX' (NON-UNIQUE) (Cost=2 Card=8 Bytes=72)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
25 consistent gets
0 physical reads
0 redo size
380 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> select count(*) from dbobjs where created < to_date('01/01/2007','dd/mm/yyyy');
COUNT(*)
----------
6154
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT ptimizer=CHOOSE (Cost=1 Card=1 Bytes=9)
1 0 SORT (AGGREGATE)
2 1 INDEX (RANGE SCAN) OF 'DBOBJS_IDX' (NON-UNIQUE) (Cost=2 Card=4 Bytes=36)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
24 consistent gets
0 physical reads
0 redo size
380 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> select count(distinct(object_name)) from dbobjs where created < to_date('01/01/2007','dd/mm/yyyy');
COUNT(DISTINCT(OBJECT_NAME))
----------------------------
4753
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT ptimizer=CHOOSE (Cost=1 Card=1 Bytes=75)
1 0 SORT (GROUP BY)
2 1 TABLE ACCESS (BY LOCAL INDEX ROWID) OF 'DBOBJS' (Cost=1 Card=4 Bytes=300)
3 2 INDEX (RANGE SCAN) OF 'DBOBJS_IDX' (NON-UNIQUE) (Cost=2 Card=1)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
101 consistent gets
0 physical reads
0 redo size
400 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1 rows processed
對於非分割槽表的測試:
SQL> CREATE TABLE dbobjs2
2 (object_id NUMBER NOT NULL,
3 object_name VARCHAR2(128),
4 created DATE NOT NULL
5 );
Table created.
SQL> CREATE INDEX dbobjs_idx2 ON dbobjs2 (created);
Index created.
SQL> insert into dbobjs2
2 select object_id,object_name,created
3 from dba_objects where created
6227 rows created.
SQL> commit;
Commit complete.
SQL> select count(distinct(object_name)) from dbobjs2 where created < to_date('01/01/2007','dd/mm/yyyy');
COUNT(DISTINCT(OBJECT_NAME))
----------------------------
4753
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT ptimizer=CHOOSE
1 0 SORT (GROUP BY)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'DBOBJS2'
3 2 INDEX (RANGE SCAN) OF 'DBOBJS_IDX2' (NON-UNIQUE)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
2670 consistent gets
0 physical reads
1332 redo size
400 bytes sent via SQL*Net to client
503 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1 rows processed
當增加表分割槽時,LOCAL索引被自動維護:
SQL> ALTER TABLE dbobjs
2 ADD PARTITION dbobjs_08 VALUES LESS THAN (TO_DATE('01/01/2009', 'DD/MM/YYYY'));
Table altered.
SQL> set autotrace off
SQL> COL segment_name for a20
SQL> COL PARTITION_NAME for a20
SQL> SELECT segment_name, partition_name, tablespace_name
2 FROM dba_segments
3 WHERE segment_name = 'DBOBJS_IDX';
SEGMENT_NAME PARTITION_NAME TABLESPACE_NAME
-------------------- -------------------- ------------------------------
DBOBJS_IDX DBOBJS_06 USERS
DBOBJS_IDX DBOBJS_07 USERS
DBOBJS_IDX DBOBJS_08 EYGLE
SQL> SELECT segment_name, partition_name, tablespace_name
2 FROM dba_segments
3 WHERE segment_name = 'DBOBJS';
SEGMENT_NAME PARTITION_NAME TABLESPACE_NAME
-------------------- -------------------- ------------------------------
DBOBJS DBOBJS_06 EYGLE
DBOBJS DBOBJS_07 EYGLE
DBOBJS DBOBJS_08 EYGLE
-The End-
http://www.eygle.com/archives/2008/04/partition_local_index.html
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/1384/viewspace-342939/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 關於 Oracle 分割槽索引的建立和維護Oracle索引
- oracle分割槽表的維護Oracle
- 【轉】Oracle分割槽表維護Oracle
- Oracle分割槽表基礎運維-06分割槽表索引Oracle運維索引
- 操作分割槽表對global和local索引的影響索引
- 分割槽表及分割槽索引建立示例索引
- oracle分割槽及分割槽索引partition_partition index_維護(一)Oracle索引Index
- oracle分割槽及分割槽索引partition_partition index_維護(二)Oracle索引Index
- oracle分割槽及分割槽索引partition_partition index_維護(三)Oracle索引Index
- oracle分割槽及分割槽索引partition_partition index_維護(四)Oracle索引Index
- Oracle分割槽表及分割槽索引Oracle索引
- 分割槽索引維護(add partition)索引
- oracle 建立所有分割槽索引Oracle索引
- 簡單ORACLE分割槽表、分割槽索引Oracle索引
- 轉個分割槽表Local索引Rebuild的總結索引Rebuild
- Oracle 分割槽表的建立Oracle
- 分割槽表並行建立索引並行索引
- 在範圍分割槽表上分割槽維護操作對索引狀態的影響索引
- oracle分割槽及分割槽索引partition_partition index_維護(五)_快捷方法Oracle索引Index
- ORACLE分割槽表梳理系列(二)- 分割槽表日常維護及注意事項Oracle
- 主鍵local索引、unique local索引、分割槽索引順序的理解索引
- Oracle 建立分割槽表Oracle
- Oracle分割槽之五:建立分割槽索引總結Oracle索引
- 在範圍分割槽表上分割槽維護操作對索引狀態的影響(1)索引
- 【學習筆記】分割槽表和分割槽索引——管理索引分割槽(四)筆記索引
- 有關Oracle表分割槽進行(DML)維護後對索引的影響的分析Oracle索引
- 深入學習Oracle分割槽表及分割槽索引Oracle索引
- 全面認識oracle分割槽表及分割槽索引Oracle索引
- oracle分割槽表和分割槽表exchangeOracle
- 分割槽表、分割槽索引和全域性索引部分總結索引
- 學習筆記】分割槽表和分割槽索引——新增表分割槽(二)筆記索引
- 分割槽索引之本地(local index)索引和全域性索引(global index)索引Index
- 【學習筆記】分割槽表和分割槽索引——分割槽表的其他管理(三)筆記索引
- 海量資料處理_表分割槽(分割槽自動維護與歷史分割槽歸檔)
- rebuild分割槽表分割槽索引的方法Rebuild索引
- 測試oracle子分割槽維護Oracle
- oracle分割槽表和非分割槽表exchangeOracle
- 全面學習分割槽表及分割槽索引(16)--增加和刪除索引分割槽索引