Showing posts with label Oracle. Show all posts
Showing posts with label Oracle. Show all posts

Sunday, February 7, 2010

Explain plan basics

In recent times I've been writing sql queries frequently.Sometime adding a constrain or adding a join between the tables based on index would return the results much faster.But this is based on my knowledge in Siebel schema but was wondering how would a DBA analyze an executed sql stament to optmize performance. Then came across a powerful SQL command explain plan. I think going forward I'd use this command to optmize the sql..Here is what I did to start with Explain plan command

> Created a table for explain plan ( you can find the sql statement below $oracle_home\rdbms\admin\utlxplan)

create table PLAN_TABLE (
statement_id varchar2(30),
plan_id number,
timestamp date,
remarks varchar2(4000),
operation varchar2(30),
options varchar2(255),
object_node varchar2(128),
object_owner varchar2(30),
object_name varchar2(30),
object_alias varchar2(65),
object_instance numeric,
object_type varchar2(30),
optimizer varchar2(255),
search_columns number,
id numeric,
parent_id numeric,
depth numeric,
position numeric,
cost numeric,
cardinality numeric,
bytes numeric,
other_tag varchar2(255),
partition_start varchar2(255),
partition_stop varchar2(255),
partition_id numeric,
other long,
distribution varchar2(30),
cpu_cost numeric,
io_cost numeric,
temp_space numeric,
access_predicates varchar2(4000),
filter_predicates varchar2(4000),
projection varchar2(4000),
time numeric,
qblock_name varchar2(30),
other_xml clob
);

> Commit the above change
>Executed a simple sql statment on Siebel tables with explain plan command

explain plan for select * from siebel.s_org_ext accnt,
siebel.s_accnt_postn sap,siebel.s_postn postn
where sap.ou_ext_id = accnt.row_id
and sap.position_id = postn.row_id

> Next step is to see the result in the plan table and Oracle has a sample sql statment to view the plan_table @ $oracle_root\RDBMS\ADMIN\utlxpls

select plan_table_output from table(dbms_xplan.display('plan_table',null,'serial'));

Hurray I could see the results in the plan_table ..Now I just need to learn how to read the plan_table and optmize sql queries. To be Continued... :-)