Common methods for viewing SQL execution plans

Source: Internet
Author: User
Tags dba

Whether you are developing a DBA or maintaining a DBA, you are always more or less encountering SQL execution efficiencies or SQL tuning issues, and it is necessary to view the execution plan. Generally we can view in 3 ways:

First, explain plan for

Examples are enough to illustrate their use.

sys@ORCL> explain plan for
2 select sysdate from dual;
Explained.
sys@ORCL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
--------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
--------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | |
| 1 | TABLE ACCESS FULL | DUAL | | | |
--------------------------------------------------------------------
Note: rule based optimization
9 rows selected.

Ii. Use of tkprof tools

Tkprof is an executable tool for parsing Oracle trace files and generating a clearer and more reasonable output. If a system performs less efficiently, a better approach is to track the user's session and format the output using the Tkprof tool's sorting function to find the problematic SQL statement.

The options behind the tkprof command and the meaning of each column in the output file are not described here in detail. Google will have a lot of information.

The following is a brief description of the use of the Tkprof tool:

1. Set Sql_trace=true at session level

sys@ORCL> alter session set sql_trace=true;
Session altered.

If you want to set the session level to true in Pl/sql, you can use the Dbms_system package:

sys@ORCL> exec dbms_system.set_sql_trace_in_session(sid,serial#,true);

2, specify the generated trace file name, easy to find:

sys@ORCL> alter session set tracefile_identifier='yourname';

3, execute the SQL statement.

4, using the TKPROF tool format the output of the trace file:

[oracle@q1test01 ~] $ tkprof /oracle/admin/orcl/udump/orcl_ora_10266_yourname.trc /oracle/yourname.txt explain=user/pwd aggregate=yes sys=no waits=yes sort=fchela

5, view the generated files and set Sql_trace=false:

sys@ORCL> alter session set sql_trace=false;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.