Monday, 1 June 2009

Oracle Explain Plan: Use 'explain plan' to mesure cost of query

Execute query as given below :
explain plan for select * from wireless_nport_message  where requestnumber = '6017809144100804' and correlationid = '5846000245497600000000000000000000000000000000000000000000000821' AND DIRECTION='Out' AND MESSAGETYPE in ('MultiPortRequest','MultiPortResponse','ModifyPortRequest','StoreStatus') ORDER BY MESSAGEKEY;

Execute below query to display plan:
SELECT * FROM   TABLE(DBMS_XPLAN.DISPLAY);

PLAN_TABLE_OUTPUT:

Plan hash value: 2718731310
 
-------------------------------------------------------------------------------------------------------
| Id  | Operation                    | Name                   | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |                        |     1 |   280 |     3  (34)| 00:00:01 |
|   1 |  SORT ORDER BY               |                        |     1 |   280 |     3  (34)| 00:00:01 |
|*  2 |   TABLE ACCESS BY INDEX ROWID| WIRELESS_NPORT_MESSAGE |     1 |   280 |     2   (0)| 00:00:01 |
|*  3 |    INDEX RANGE SCAN          | WNM_REQNO_CORRID_IDX   |     1 |       |     1   (0)| 00:00:01 |
-------------------------------------------------------------------------------------------------------
 
Predicate Information (identified by operation id):
---------------------------------------------------
 
   2 - filter("DIRECTION"='Out' AND ("MESSAGETYPE"='ModifyPortRequest' OR 
              "MESSAGETYPE"='MultiPortRequest' OR "MESSAGETYPE"='MultiPortResponse' OR 
              "MESSAGETYPE"='StoreStatus'))
   3 - access("REQUESTNUMBER"='6017809144100804' AND 
              "CORRELATIONID"='5846000245497600000000000000000000000000000000000000000000000821')