10g索引的作用實驗1

1)授權SCOTT DBA權限
grant dba to scott;
2)SCOTT創建測試大表
create table tab_idx_test
as
select * from dba_objects
where owner in('PUBLIC','SCOTT','SYS','SYSTEM');        
3)打開執行計劃
SET AUTOTRACE TRACE EXPLAIN
4)查詢指定條件數據
SQL>SELECT OWNER,OBJECT_NAME FROM TAB_IDX_TEST WHERE OBJECT_NAME='DBA_INDEXES';
Elapsed: 00:00:00.00

Execution Plan
----------------------------------------------------------
Plan hash value: 2925858188

----------------------------------------------------------------------------------
| Id    | Operation                 | Name                 | Rows    | Bytes | Cost (%CPU)| Time         |
----------------------------------------------------------------------------------
|     0 | SELECT STATEMENT    |                            |         7 |     581 |     142     (3)| 00:00:02 |
|*    1 |    TABLE ACCESS FULL| TAB_IDX_TEST |         7 |     581 |     142     (3)| 00:00:02 |
----------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

     1 - filter("OBJECT_NAME"='DBA_INDEXES')

Note
-----
     - dynamic sampling used for this statement

SQL>
5)在object_name上創建索引idx_tab_idx_test
CREATE INDEX    idx_tab_idx_test
on tab_idx_test(object_name);    
6)再次查詢指定條件數據
SQL> SELECT OWNER,OBJECT_NAME FROM TAB_IDX_TEST WHERE OBJECT_NAME='DBA_INDEXES';
Elapsed: 00:00:00.03

Execution Plan
----------------------------------------------------------
Plan hash value: 3112998378

------------------------------------------------------------------------------------------------
| Id    | Operation                                     | Name                         | Rows    | Bytes | Cost (%CPU)| Time         |
------------------------------------------------------------------------------------------------
|     0 | SELECT STATEMENT                        |                                    |         2 |     166 |         2     (0)| 00:00:01 |
|     1 |    TABLE ACCESS BY INDEX ROWID| TAB_IDX_TEST         |         2 |     166 |         2     (0)| 00:00:01 |
|*    2 |     INDEX RANGE SCAN                    | IDX_TAB_IDX_TEST |         2 |             |         1     (0)| 00:00:01 |
------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

     2 - access("OBJECT_NAME"='DBA_INDEXES')

Note
-----
     - dynamic sampling used for this statement

SQL>
分析:
1)從Cost上來看,如果不在OBJECT_NAME創建索引,則
COST爲142,CPU佔用爲3%,Rows爲7,Bytes爲581

2)如果在OBJECT_NAME創建索引,則
COST爲2,CPU佔用爲0%,Rows爲2,Bytes爲166


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章