Monday, October 12, 2009

Using explain plan to show the use of a new index

With no Index on the WHERE column, we can see no index
is being used.



SQL> select object_id, object_name from tim_objects
where object_id = 5368;


OBJECT_ID OBJECT_NAME
---------- ----------------------------------------
5368 TTS_OBJ_VIEW

1 row selected.


Execution Plan
---------------------------------------------------
Plan hash value: 816050672


-----------------------------------------
| Id | Operation | Name |
-----------------------------------------
| 0 | SELECT STATEMENT | |
|* 1 | TABLE ACCESS FULL| TIM_OBJECTS |
-----------------------------------------


Now if we add an index we can look at the explain plan again to see if its being used.



SQL> create index tim_object_id on tim_objects(object_id);


SQL> select object_id, object_name from tim_objects
where object_id = 5368;


OBJECT_ID OBJECT_NAME
---------- ---------------------------------------
5368 TTS_OBJ_VIEW

1 row selected.



Execution Plan
---------------------------------------------------
Plan hash value: 3022239600


-----------------------------------------------------
| Id | Operation | Name |
-----------------------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | TABLE ACCESS BY INDEX ROWID| TIM_OBJECTS |
|* 2 | INDEX RANGE SCAN | TIM_OBJECT_ID |
-----------------------------------------------------



******************************************
keywords: index explain plan
******************************************
rdbms version:
******************************************

No comments: