Oracle Real query execution plan

What is the real implementation plan

Gets Oracle's implementation plan, there are several ways. (As used herein, Oracle 11g XE version, as well as ordinary user scott login)

  • explain plan for
    two steps:
    • explain plan for ${SQL}
    • select * from table(dbms_xplan.display);

    This method may be performed in a PLSQLDev sql cmd window and the window, while no authorization to the user.
    Example:

  • autotrace
    two steps:
    • set cars is
    • Performing $ {SQL}

    But ordinary users need authorization to perform. Do not understand the authorization process, you know the students can leave a message.
    And can not perform in my PLSQLDev years, you must be SqlPlus to perform.
    Example:

    We can see a few more statistics, but not very intuitive.

However, the above two methods

Use AUTOTRACE or EXPLAIN PLAN FOR obtain the execution plan from PLAN_TABLE. PLAN_TABLE a temporary table is session-level, which the SQL execution plan is not real execution plan, the optimizer estimates it just came out of. The actual execution plan should not be estimated, it should be really executed before. SQL execution plan executed exists in the shared pool, specifically exists in the data dictionary V $ SQL_PLAN, the implementation plan with the A-Time comes from the V $ SQL_PLAN, it is the real execution plan, and by AUTOTRACE, by EXPLAIN PLAN FOR just get the execution plan the optimizer estimates obtained by the execution plan. (Note 1)

Here that the implementation plan with the A-Time, that is referred to herein, the real execution plan.

  • Real Plan of Implementation
    of this approach requires authorization for the average user, the following statement can be used one-time authorization.
grant select any dictionary to scott;

This execution plan results are as follows:

You can see more A-Rows, A-Time fields.

Starts this indicates the number of operations performed
E-Rows optimizer estimates the number of rows, that is, Rows general implementation plan
A-Rows represent the true number of rows
A-Time represents the total accumulated time. And general execution plan is different, general implementation plan Time is false, and A-Time is real.
Buffers represents the accumulated logical reads
Reads represents physical reads accumulated
(Note 2)

Starts, A-Rows, A- Time intuitive these fields, for non-database developers, easily understood.
The real implementation of the plan acquisition mode, the following will be introduced.

It should be noted that the number of rows in the general implementation plan estimated the affected histogram statistics, the optimizer may cause misjudgment to choose execution plans (such as this to go HASH JOIN, the result becomes NESTED LOOPS). Therefore, the histogram statistics should be updated on a regular basis. This work is in our daily DBA.

How to get the real execution plan

Permission must first have access dynamic performance views, using the following statement authorization

grant select any dictionary to scott;

Once you have permission, divided into the following steps to go

All the session SET = STATISTICS_LEVEL 1.alter;
(this step is valid for the current session window, can not do, explained below)

2. Execute the statement;
(if not the last step, you need to add the / in the statement + gather_plan_statistics / example: the SELECT /. + Gather_plan_statistics / * from Dual; but this is too much trouble, each statement should be added, is not recommended )

3. Find the statement is executed SQL ID, for example:
select v.last_active_time, v.* from v$sql v where v.last_active_time > to_date('2019/10/02 17:00:00', 'yyyy/mm/dd hh24:mi:ss') and v.sql_text like 'select * from %' and v.parsing_schema_name = 'SCOTT' order by v.last_active_time desc;

Parameters according to practical situation, the more accurate the better.
Program can be obtained, the SQL ID remove

4. The isolated execution plan SQL ID

select * from table(dbms_xplan.display_cursor('b8x994z12hax9',null,'allstats last'));

Wherein the first parameter is obtained in Step 3 SQL ID. Implementation plan available

Copy paste it into notepad ++

We can see already have information on the actual execution.
This example is relatively simple, you can try the following example.

select d.dname, d.loc, e.empno, e.ename
  from emp e, dept d
 where e.deptno = d.deptno
 order by d.dname, e.empno;

Implementation plan are as follows:

Here there is more information, you can know the specifics of each step of the operation, such as what relevance the like between the two tables.

to sum up

Real implementation plan provides real information SQL implementation, including the A-Time (real time), A-Rows (true implementation of number), Starts (number of executions step), etc., for non-database developers, very easy and intuitive. I would also like to take this work to optimize the 10+ SQL, full harvest -
here to recommend a book, "SQL optimization core idea," Luobing Sen Huang Chao Zhong Jiao forward. All references to the text of this article are taken from the book. I did not fully understand the book, but at work, has been good enough.

Guess you like

Origin www.cnblogs.com/kingsleylam/p/11617890.html