Oracle技术之和分区表相关的一点总结(四)
3.訪問(wèn)全部數(shù)據(jù),我們發(fā)現(xiàn)訪問(wèn)heap表要比訪問(wèn)分區(qū)表是少了一些邏輯讀:
88429<88573,其實(shí)這點(diǎn)差別對(duì)性能來(lái)說(shuō)是無(wú)關(guān)緊要的,重要的是說(shuō)明了一個(gè)問(wèn)題,
那就是盡量讓執(zhí)行的sql少讀、少些,這也是sql調(diào)整的最終目的,相差的這100
多邏輯讀主要發(fā)生在查找metadata上...
SQL> select * from t1 ;
已選擇1260672行。
已用時(shí)間: 00: 00: 26.70
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1482K| 111M| 1064 (3)| 00:00:13 |
| 1 | TABLE ACCESS FULL| T1 | 1482K| 111M| 1064 (3)| 00:00:13 |
--------------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
統(tǒng)計(jì)信息
----------------------------------------------------------
5 recursive calls
0 db block gets
88511 consistent gets
0 physical reads
0 redo size
44940044 bytes sent via SQL*Net to client
924869 bytes received via SQL*Net from client
84046 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1260672 rows processed
SQL> select * from t1 ;
已選擇1260672行。
已用時(shí)間: 00: 00: 24.59
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1482K| 111M| 1064 (3)| 00:00:13 |
| 1 | TABLE ACCESS FULL| T1 | 1482K| 111M| 1064 (3)| 00:00:13 |
--------------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
統(tǒng)計(jì)信息
----------------------------------------------------------
0 recursive calls
0 db block gets
88429 consistent gets
0 physical reads
0 redo size
44940044 bytes sent via SQL*Net to client
924869 bytes received via SQL*Net from client
84046 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1260672 rows processed
SQL> select * from t ;
已選擇1260544行。
已用時(shí)間: 00: 00: 25.71
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 3557914527
--------------------------------------------------------------------------------
------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pst
art| Pstop |
--------------------------------------------------------------------------------
------------
| 0 | SELECT STATEMENT | | 1317K| 37M| 1094 (3)| 00:00:14 |
| |
| 1 | PARTITION RANGE ALL| | 1317K| 37M| 1094 (3)| 00:00:14 |
1 | 5 |
| 2 | TABLE ACCESS FULL | T | 1317K| 37M| 1094 (3)| 00:00:14 |
1 | 5 |
--------------------------------------------------------------------------------
------------
Note
-----
- dynamic sampling used for this statement
統(tǒng)計(jì)信息
----------------------------------------------------------
7 recursive calls
2 db block gets
90275 consistent gets
2133 physical reads
114820 redo size
39895221 bytes sent via SQL*Net to client
924781 bytes received via SQL*Net from client
84038 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1260544 rows processed
SQL> select * from t ;
已選擇1260544行。
已用時(shí)間: 00: 00: 24.90
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 3557914527
--------------------------------------------------------------------------------
------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pst
art| Pstop |
--------------------------------------------------------------------------------
------------
| 0 | SELECT STATEMENT | | 1317K| 37M| 1094 (3)| 00:00:14 |
| |
| 1 | PARTITION RANGE ALL| | 1317K| 37M| 1094 (3)| 00:00:14 |
1 | 5 |
| 2 | TABLE ACCESS FULL | T | 1317K| 37M| 1094 (3)| 00:00:14 |
1 | 5 |
--------------------------------------------------------------------------------
------------
Note
-----
- dynamic sampling used for this statement
統(tǒng)計(jì)信息
----------------------------------------------------------
0 recursive calls
0 db block gets
88573 consistent gets
0 physical reads
0 redo size
39895221 bytes sent via SQL*Net to client
924781 bytes received via SQL*Net from client
84038 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1260544 rows processed
SQL>
--==========================
有index的情況,創(chuàng)建global index:
有index其實(shí)也是一樣的,首先通過(guò)index找到rowid,之后最終通過(guò)rowid
再去訪問(wèn)表,如果訪問(wèn)的數(shù)據(jù)盡可能的可以集中在一些分區(qū)內(nèi),那么訪問(wèn)
分區(qū)表的性能肯定要優(yōu)于heap表
SQL> create index idx_t on t(object_id) tablespace users;
索引已創(chuàng)建。
已用時(shí)間: 00: 00: 10.21
SQL> create index idx_t1 on t1(object_id) tablespace users;
索引已創(chuàng)建。
已用時(shí)間: 00: 00: 06.89
SQL>
SQL> exec dbms_stats.gather_table_stats('SYS','T',CASCADE=>TRUE);
PL/SQL 過(guò)程已成功完成。
已用時(shí)間: 00: 00: 06.00
SQL> exec dbms_stats.gather_table_stats('SYS','T1',CASCADE=>TRUE);
PL/SQL 過(guò)程已成功完成。
已用時(shí)間: 00: 00: 03.21
SQL>
--有g(shù)lobal index跨分區(qū)訪問(wèn)
SQL> select /*+ index(t idx_t) */ * from t where object_id<3000;
已選擇377984行。
已用時(shí)間: 00: 00: 07.75
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 3317799281
--------------------------------------------------------------------------------
----------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)
| Time | Pstart| Pstop |
--------------------------------------------------------------------------------
----------------------------
| 0 | SELECT STATEMENT | | 368K| 7922K| 363K (1)
| 01:12:41 | | |
| 1 | TABLE ACCESS BY GLOBAL INDEX ROWID| T | 368K| 7922K| 363K (1)
| 01:12:41 | ROWID | ROWID |
|* 2 | INDEX RANGE SCAN | IDX_T | 368K| | 986 (1)
| 00:00:12 | | |
--------------------------------------------------------------------------------
----------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"<3000)
統(tǒng)計(jì)信息
----------------------------------------------------------
1 recursive calls
0 db block gets
398707 consistent gets
0 physical reads
0 redo size
12757072 bytes sent via SQL*Net to client
277563 bytes received via SQL*Net from client
25200 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
377984 rows processed
SQL> select /*+ index(t idx_t) */ * from t where object_id<3000;
已選擇377984行。
已用時(shí)間: 00: 00: 09.43
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 3317799281
--------------------------------------------------------------------------------
----------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)
| Time | Pstart| Pstop |
--------------------------------------------------------------------------------
----------------------------
| 0 | SELECT STATEMENT | | 368K| 7922K| 363K (1)
| 01:12:41 | | |
| 1 | TABLE ACCESS BY GLOBAL INDEX ROWID| T | 368K| 7922K| 363K (1)
| 01:12:41 | ROWID | ROWID |
|* 2 | INDEX RANGE SCAN | IDX_T | 368K| | 986 (1)
| 00:00:12 | | |
--------------------------------------------------------------------------------
----------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"<3000)
統(tǒng)計(jì)信息
----------------------------------------------------------
0 recursive calls
0 db block gets
398707 consistent gets
0 physical reads
0 redo size
12757072 bytes sent via SQL*Net to client
277563 bytes received via SQL*Net from client
25200 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
377984 rows processed
SQL>
--======================
--有g(shù)lobal index不垮分區(qū)訪問(wèn):
SQL> select /*+ index(t1 idx_t1) */ * from t1 where object_id<2000;
已選擇249984行。
已用時(shí)間: 00: 00: 05.57
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 50753647
--------------------------------------------------------------------------------
------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
------
| 0 | SELECT STATEMENT | | 245K| 5264K| 245K (1)| 00:4
9:12 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 245K| 5264K| 245K (1)| 00:4
9:12 |
|* 2 | INDEX RANGE SCAN | IDX_T1 | 245K| | 522 (2)| 00:0
0:07 |
--------------------------------------------------------------------------------
------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"<2000)
統(tǒng)計(jì)信息
----------------------------------------------------------
1 recursive calls
0 db block gets
266985 consistent gets
0 physical reads
0 redo size
8439590 bytes sent via SQL*Net to client
183700 bytes received via SQL*Net from client
16667 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
249984 rows processed
SQL> select /*+ index(t1 idx_t1) */ * from t1 where object_id<2000;
已選擇249984行。
已用時(shí)間: 00: 00: 05.42
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 50753647
--------------------------------------------------------------------------------
------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
------
| 0 | SELECT STATEMENT | | 245K| 5264K| 245K (1)| 00:4
9:12 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 245K| 5264K| 245K (1)| 00:4
9:12 |
|* 2 | INDEX RANGE SCAN | IDX_T1 | 245K| | 522 (2)| 00:0
0:07 |
--------------------------------------------------------------------------------
------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"<2000)
統(tǒng)計(jì)信息
----------------------------------------------------------
0 recursive calls
0 db block gets
266985 consistent gets
0 physical reads
0 redo size
8439590 bytes sent via SQL*Net to client
183700 bytes received via SQL*Net from client
16667 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
249984 rows processed
SQL> select /*+ index(t idx_t) */ * from t where object_id<2000;
已選擇249984行。
已用時(shí)間: 00: 00: 04.93
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 2063514567
--------------------------------------------------------------------------------
----------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)
| Time | Pstart| Pstop |
--------------------------------------------------------------------------------
----------------------------
| 0 | SELECT STATEMENT | | 259K| 5073K| 1241K (1)
| 04:08:20 | | |
| 1 | TABLE ACCESS BY GLOBAL INDEX ROWID| T | 259K| 5073K| 1241K (1)
| 04:08:20 | 1 | 1 |
|* 2 | INDEX RANGE SCAN | IDX_T | 1260K| | 3366 (1)
| 00:00:41 | | |
--------------------------------------------------------------------------------
----------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"<2000)
統(tǒng)計(jì)信息
----------------------------------------------------------
44 recursive calls
0 db block gets
262733 consistent gets
0 physical reads
0 redo size
8439590 bytes sent via SQL*Net to client
183700 bytes received via SQL*Net from client
16667 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
249984 rows processed
SQL>
SQL> select /*+ index(t idx_t) */ * from t where object_id<2000;
已選擇249984行。
已用時(shí)間: 00: 00: 04.62
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 2063514567
--------------------------------------------------------------------------------
----------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)
| Time | Pstart| Pstop |
--------------------------------------------------------------------------------
----------------------------
| 0 | SELECT STATEMENT | | 259K| 5073K| 1241K (1)
| 04:08:20 | | |
| 1 | TABLE ACCESS BY GLOBAL INDEX ROWID| T | 259K| 5073K| 1241K (1)
| 04:08:20 | 1 | 1 |
|* 2 | INDEX RANGE SCAN | IDX_T | 1260K| | 3366 (1)
| 00:00:41 | | |
--------------------------------------------------------------------------------
----------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"<2000)
統(tǒng)計(jì)信息
----------------------------------------------------------
0 recursive calls
0 db block gets
262727 consistent gets
0 physical reads
0 redo size
8439590 bytes sent via SQL*Net to client
183700 bytes received via SQL*Net from client
16667 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
249984 rows processed
SQL>
--======================
SQL> exec dbms_stats.gather_table_stats('SYS','T',CASCADE=>TRUE);
PL/SQL 過(guò)程已成功完成。
已用時(shí)間: 00: 00: 05.82
SQL> exec dbms_stats.gather_table_stats('SYS','T1',CASCADE=>TRUE);
PL/SQL 過(guò)程已成功完成。
已用時(shí)間: 00: 00: 03.17
SQL>
--local index:
SQL> select /*+ index(t1 idx_t1) */ * from t1 where object_id<3000;
已選擇377984行。
已用時(shí)間: 00: 00: 09.46
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 50753647
--------------------------------------------------------------------------------
------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
------
| 0 | SELECT STATEMENT | | 370K| 7963K| 371K (1)| 01:1
4:16 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 370K| 7963K| 371K (1)| 01:1
4:16 |
|* 2 | INDEX RANGE SCAN | IDX_T1 | 370K| | 786 (2)| 00:0
0:10 |
--------------------------------------------------------------------------------
------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"<3000)
統(tǒng)計(jì)信息
----------------------------------------------------------
150 recursive calls
0 db block gets
403726 consistent gets
0 physical reads
0 redo size
12757072 bytes sent via SQL*Net to client
277563 bytes received via SQL*Net from client
25200 SQL*Net roundtrips to/from client
3 sorts (memory)
0 sorts (disk)
377984 rows processed
SQL> select /*+ index(t1 idx_t1) */ * from t1 where object_id<3000;
已選擇377984行。
已用時(shí)間: 00: 00: 08.28
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 50753647
--------------------------------------------------------------------------------
------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
------
| 0 | SELECT STATEMENT | | 370K| 7963K| 371K (1)| 01:1
4:16 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 370K| 7963K| 371K (1)| 01:1
4:16 |
|* 2 | INDEX RANGE SCAN | IDX_T1 | 370K| | 786 (2)| 00:0
0:10 |
--------------------------------------------------------------------------------
------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"<3000)
統(tǒng)計(jì)信息
----------------------------------------------------------
0 recursive calls
0 db block gets
403706 consistent gets
0 physical reads
0 redo size
12757072 bytes sent via SQL*Net to client
277563 bytes received via SQL*Net from client
25200 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
377984 rows processed
SQL> select /*+ index(t idx_t) */ * from t where object_id<3000;
已選擇377984行。
已用時(shí)間: 00: 00: 07.17
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 3038871768
--------------------------------------------------------------------------------
----------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)
| Time | Pstart| Pstop |
--------------------------------------------------------------------------------
----------------------------
| 0 | SELECT STATEMENT | | 368K| 7566K| 363K (1)
| 01:12:40 | | |
| 1 | PARTITION RANGE ITERATOR | | 368K| 7566K| 363K (1)
| 01:12:40 | 1 | 2 |
| 2 | TABLE ACCESS BY LOCAL INDEX ROWID| T | 368K| 7566K| 363K (1)
| 01:12:40 | 1 | 2 |
|* 3 | INDEX RANGE SCAN | IDX_T | 368K| | 783 (2)
| 00:00:10 | 1 | 2 |
--------------------------------------------------------------------------------
----------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("OBJECT_ID"<3000)
統(tǒng)計(jì)信息
----------------------------------------------------------
195 recursive calls
0 db block gets
398680 consistent gets
0 physical reads
0 redo size
5145251 bytes sent via SQL*Net to client
277563 bytes received via SQL*Net from client
25200 SQL*Net roundtrips to/from client
6 sorts (memory)
0 sorts (disk)
377984 rows processed
SQL> select /*+ index(t idx_t) */ * from t where object_id<3000;
已選擇377984行。
已用時(shí)間: 00: 00: 07.42
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 3038871768
--------------------------------------------------------------------------------
----------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)
| Time | Pstart| Pstop |
--------------------------------------------------------------------------------
----------------------------
| 0 | SELECT STATEMENT | | 368K| 7566K| 363K (1)
| 01:12:40 | | |
| 1 | PARTITION RANGE ITERATOR | | 368K| 7566K| 363K (1)
| 01:12:40 | 1 | 2 |
| 2 | TABLE ACCESS BY LOCAL INDEX ROWID| T | 368K| 7566K| 363K (1)
| 01:12:40 | 1 | 2 |
|* 3 | INDEX RANGE SCAN | IDX_T | 368K| | 783 (2)
| 00:00:10 | 1 | 2 |
--------------------------------------------------------------------------------
----------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("OBJECT_ID"<3000)
統(tǒng)計(jì)信息
----------------------------------------------------------
0 recursive calls
0 db block gets
398633 consistent gets
0 physical reads
0 redo size
5145251 bytes sent via SQL*Net to client
277563 bytes received via SQL*Net from client
25200 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
377984 rows processed
SQL>
--===============================
有l(wèi)ocal index不垮分區(qū)訪問(wèn):
SQL> select /*+ index(t idx_t) */ * from t where object_id<2000;
已選擇249984行。
已用時(shí)間: 00: 00: 04.93
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 3965956311
--------------------------------------------------------------------------------
----------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)
| Time | Pstart| Pstop |
--------------------------------------------------------------------------------
----------------------------
| 0 | SELECT STATEMENT | | 254K| 4962K| 245K (1)
| 00:49:11 | | |
| 1 | PARTITION RANGE SINGLE | | 254K| 4962K| 245K (1)
| 00:49:11 | 1 | 1 |
| 2 | TABLE ACCESS BY LOCAL INDEX ROWID| T | 254K| 4962K| 245K (1)
| 00:49:11 | 1 | 1 |
|* 3 | INDEX RANGE SCAN | IDX_T | 249K| | 528 (2)
| 00:00:07 | 1 | 1 |
--------------------------------------------------------------------------------
----------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("OBJECT_ID"<2000)
統(tǒng)計(jì)信息
----------------------------------------------------------
24 recursive calls
0 db block gets
262679 consistent gets
0 physical reads
0 redo size
3406055 bytes sent via SQL*Net to client
183700 bytes received via SQL*Net from client
16667 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
249984 rows processed
SQL> select /*+ index(t idx_t) */ * from t where object_id<2000;
已選擇249984行。
已用時(shí)間: 00: 00: 03.48
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 3965956311
--------------------------------------------------------------------------------
----------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)
| Time | Pstart| Pstop |
--------------------------------------------------------------------------------
----------------------------
| 0 | SELECT STATEMENT | | 254K| 4962K| 245K (1)
| 00:49:11 | | |
| 1 | PARTITION RANGE SINGLE | | 254K| 4962K| 245K (1)
| 00:49:11 | 1 | 1 |
| 2 | TABLE ACCESS BY LOCAL INDEX ROWID| T | 254K| 4962K| 245K (1)
| 00:49:11 | 1 | 1 |
|* 3 | INDEX RANGE SCAN | IDX_T | 249K| | 528 (2)
| 00:00:07 | 1 | 1 |
--------------------------------------------------------------------------------
----------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("OBJECT_ID"<2000)
統(tǒng)計(jì)信息
----------------------------------------------------------
0 recursive calls
0 db block gets
262676 consistent gets
0 physical reads
0 redo size
3406055 bytes sent via SQL*Net to client
183700 bytes received via SQL*Net from client
16667 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
249984 rows processed
SQL> select /*+ index(t1 idx_t1) */ * from t1 where object_id<2000;
已選擇249984行。
已用時(shí)間: 00: 00: 05.40
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 50753647
--------------------------------------------------------------------------------
------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
------
| 0 | SELECT STATEMENT | | 247K| 5306K| 247K (1)| 00:4
9:29 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 247K| 5306K| 247K (1)| 00:4
9:29 |
|* 2 | INDEX RANGE SCAN | IDX_T1 | 247K| | 525 (2)| 00:0
0:07 |
--------------------------------------------------------------------------------
------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"<2000)
統(tǒng)計(jì)信息
----------------------------------------------------------
0 recursive calls
0 db block gets
266985 consistent gets
0 physical reads
0 redo size
8439590 bytes sent via SQL*Net to client
183700 bytes received via SQL*Net from client
16667 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
249984 rows processed
SQL> select /*+ index(t1 idx_t1) */ * from t1 where object_id<2000;
已選擇249984行。
已用時(shí)間: 00: 00: 05.70
執(zhí)行計(jì)劃
----------------------------------------------------------
Plan hash value: 50753647
--------------------------------------------------------------------------------
------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
------
| 0 | SELECT STATEMENT | | 247K| 5306K| 247K (1)| 00:4
9:29 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 247K| 5306K| 247K (1)| 00:4
9:29 |
|* 2 | INDEX RANGE SCAN | IDX_T1 | 247K| | 525 (2)| 00:0
0:07 |
--------------------------------------------------------------------------------
------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"<2000)
統(tǒng)計(jì)信息
----------------------------------------------------------
0 recursive calls
0 db block gets
266985 consistent gets
0 physical reads
0 redo size
8439590 bytes sent via SQL*Net to client
183700 bytes received via SQL*Net from client
16667 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
249984 rows processed
SQL>
--=========================
SQL> create index idx_t_name on t(object_name) tablespace users;
索引已創(chuàng)建。
SQL>
--=========================
SQL> select index_name,status from dba_indexes where index_name='IDX_T_NAME';
INDEX_NAME STATUS
------------------------------ --------
IDX_T_NAME VALID
SQL> alter table t truncate partition p4;
表被截?cái)唷?/p>
--在分區(qū)表上創(chuàng)建的global index(注意非分區(qū)),即使我們truncate partition
其實(shí)這個(gè)global index是不會(huì)自動(dòng)維護(hù)的。
SQL> select index_name,status from dba_indexes where index_name='IDX_T_NAME';
INDEX_NAME STATUS
------------------------------ --------
IDX_T_NAME UNUSABLE
SQL> COL OBJECT_NAME FORMAT A20
SQL> select object_name,status from dba_objects where object_name='IDX_T_NAME';
OBJECT_NAME STATUS
-------------------- -------
IDX_T_NAME VALID
SQL>
SQL> select bytes/1024/1024 m from dba_segments where segment_name='IDX_T_NAME';
M
----------
47
SQL> alter index idx_t_name rebuild;
索引已更改。
SQL> select bytes/1024/1024 m from dba_segments where segment_name='IDX_T_NAME';
M
----------
37
SQL> select index_name,status from dba_indexes where index_name='IDX_T_NAME';
INDEX_NAME STATUS
------------------------------ --------
IDX_T_NAME VALID
SQL>
--==========================
驗(yàn)證一下dml對(duì)global index的影響,dml操作oracle會(huì)自動(dòng)update global index(注意:并非global partition index),這個(gè)
比較好理解,也應(yīng)該這樣做...
SQL> select name,del_lf_rows,del_lf_rows_len from index_stats;
NAME DEL_LF_ROWS DEL_LF_ROWS_LEN
------------------------------ ----------- ---------------
IDX_T_NAME 256 10112
SQL>
SQL> delete from t where object_id=5002;
已刪除128行。
SQL> commit;
提交完成。
SQL> analyze index idx_t_name validate structure;
索引已分析
SQL> select name,del_lf_rows,del_lf_rows_len from index_stats;
NAME DEL_LF_ROWS DEL_LF_ROWS_LEN
------------------------------ ----------- ---------------
IDX_T_NAME 384 15616
SQL>
SQL> select index_name,status from dba_indexes where index_name='IDX_T_NAME';
INDEX_NAME STATUS
------------------------------ --------
IDX_T_NAME VALID
--=========================
驗(yàn)證在分區(qū)表上創(chuàng)建主鍵和唯一索引的情況:
SQL> truncate table t ;
表被截?cái)唷?/p>
SQL> alter table t add pk number;
表已更改。
SQL> insert into t(pk,object_id,object_name) select rownum,object_id,object_name
from t1;
已創(chuàng)建1260672行。
SQL> commit;
提交完成。
SQL> alter table t add constraint pk_t primary key (pk);
表已更改。
SQL> alter table t drop constraint pk_t;
表已更改。
SQL> create unique index idx_t_pk on t(pk) tablespace users;
索引已創(chuàng)建。
SQL> create unique index idx_t_pk on t(pk) local tablespace users;
create unique index idx_t_pk on t(pk) local tablespace users
*
第 1 行出現(xiàn)錯(cuò)誤:
ORA-14039: 分區(qū)列必須構(gòu)成 UNIQUE 索引的關(guān)鍵字列子集
SQL> create unique index idx_t_pk on t(pk,object_id) local tablespace users;
索引已創(chuàng)建。
SQL> drop index idx_t_pk;
索引已刪除。
SQL> alter table t add constraint pk_t primary key (pk) using index local;
alter table t add constraint pk_t primary key (pk) using index local
*
第 1 行出現(xiàn)錯(cuò)誤:
ORA-14039: 分區(qū)列必須構(gòu)成 UNIQUE 索引的關(guān)鍵字列子集
SQL> alter table t add constraint pk_t primary key (pk,object_id) using index l
ocal;
表已更改。
SQL> alter table t drop constraint pk_t;
表已更改。
SQL> create index idx_t_pk on t(pk) local tablespace users;
索引已創(chuàng)建。
SQL> drop index idx_t_pk;
索引已刪除。
SQL>
結(jié)論:不管我們?cè)趧?chuàng)建unique index還是添加primary key時(shí),只要我們
想把index創(chuàng)建成local分區(qū)index,那么就應(yīng)該至少包含分區(qū)列...而不是象
網(wǎng)上有些人說(shuō)的在分區(qū)表上創(chuàng)建primary key或者nuique index時(shí)必須包含分區(qū)列。
oracle視頻教程請(qǐng)關(guān)注:http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html
轉(zhuǎn)載于:https://blog.51cto.com/19880614/1254218
總結(jié)
以上是生活随笔為你收集整理的Oracle技术之和分区表相关的一点总结(四)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 一个手机号码剔重的问题
- 下一篇: poj 2480 (欧拉函数应用)