[Webinar] Streamline your web hosting managementRegister Today

x
Solved

# Meaning of Cost, Cardinality/Rows,Bytes and time in Explain Plan.

Posted on 2010-04-06
Medium Priority
12,495 Views
What does the following terms in the Explain Plan mean:
1. Cost
2. Cardinality/Rows
3. Bytes
4. Time

SQL> create table t as select * from all_objects;
Table created.

SQL> exec dbms_stats.gather_table_stats( user, 'T', method_opt=>'for all indexed columns');
PL/SQL procedure successfully completed.

SQL> create index t_idx on t(object_id);
Index created.

SQL> exec dbms_stats.gather_index_stats( user, 'T_IDX' );
PL/SQL procedure successfully completed.

SQL> select * from t where object_id = 42;
Execution Plan
----------------------------------------------------------
Plan hash value: 470836197

-------------------------------------------------------------------------------------
| Id  | Operation                                            | Name  | Rows  | Bytes | Cost (%CPU)| Time        |
-------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                          |          |   557     | 52915 |            9   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID   | T        |   557     | 52915 |            9   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN                       | T_IDX |   223     |            |            1   (0)| 00:00:01 |
-------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"=42)

or in 9i
Execution Plan
----------------------------------------------------------
0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=2 Card=482 Bytes=44826)
1    0   TABLE ACCESS (BY INDEX ROWID) OF 'T' (TABLE) (Cost=2 Card=482 Bytes=44826)
2    1     INDEX (RANGE SCAN) OF 'T_IDX' (INDEX) (Cost=1 Card=193)
0
Question by:gram77
• 3
• 2

LVL 78

Expert Comment

ID: 29909767
The docs can probably explain it better than we can (it's a 9.2 doc link but these metrics really haven't changed much):

0

LVL 74

Accepted Solution

sdstuber earned 2000 total points
ID: 29909798
1. Cost   - this is an internal number,  many people mistaken believe lower cost = faster.  Ignore this.

2. Cardinality/Rows - this is an estimate by the optimizer of how many rows a particular operation will return

3. Bytes  - this is an estimate by the optimizer of how many bytes a particular operation will return

4. Time - this is an estimate of how long, in seconds, a particular operation will return
1

LVL 74

Expert Comment

ID: 29910099
if you tkprof a tracefile the row source operations (not the explain plan) will contain the actual values of execution.  Using the EXPLAIN option in tkprof adds little to no value.
0

Author Comment

ID: 29912888
sdstuber:
"many people mistaken believe lower cost = faster.  Ignore this"

If cost is not a proof for faster execution of a query what is a proof of a query tuned in the explain plan?
0

LVL 74

Expert Comment

ID: 29915950
"what is a proof"?

In a certain sense, the plan will never constitute a "proof".

The real "proof" comes from running the query and measuring the actual time and resource consumption (cpu,memory,io, locks, etc)

A plan is always an estimate. It's never guaranteed to be completely accurate. Even if you have perfect stats and constraints that provide 100% information, the plan might be accurate exactly then but as soon as you modify the data the plan is now subject to error. So it will never be a hard "proof"

but, you can generally tell a superior plan by

looking at rows and bytes processed and minimize these.
if two plans appear to do the same io, then look at the number of steps, particularly sorts for memory/cpu consumption.

the best plan is the lazy plan. If plan A does more work than plan B. Then plan B will scale better.
0

Author Closing Comment

ID: 31711330
Short and Simple, Excellent!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
###### Suggested Courses
Course of the Month11 days, 3 hours left to enroll