Chapter execution plan optimization SQL

Shenkaoziliao:
This series of blog mainly Cenkaoziliao have CUUG database Rannai Gang teacher teaching notes, "SQL optimization core idea" (Luobing Sen, Huang Chao Zhong Jiao with), "PostgreSQL Inside: query optimization Depth" (Zhang Shujie a), ranking in no particular order.

 

SQL execution plan is the steps, because we write SQL is not necessarily written in accordance with our execution, the database optimizer according to statistical information (statistical information to explain later) be rewritten SQL (SQL rewrite explain later), execution plan, but the following three implementation plan as the basis, to master.

In addition, when the implementation of the general plan get executed at least twice to secure the implementation plan (because they themselves would own evolution optimizer execution plans to achieve performance optimization purposes) and the elimination of physical reads.

Physical read: reading data from disk

Logical Read: read data from the memory

 

1 to obtain real implementation plan

Alter session set statistics_level=all;    

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

example:

Alter session set statistics_level=all;

select * from emp;

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

 

A-Rows (actually returns the number of rows) are unique to this acquisition mode, the reference value is super

E-Rows (the estimated number of rows returned) and A-Rows of comparison process is important, when difference is large, we sometimes have to change the execution plan.

2 set autotrace on/off/traceonly

This is to get the estimated execution plan based on statistics.

set autotrace on;

select * from emp;

Logical reads Total (consistent gets), physical reads Total (physical reads), the number of recursive calls (recursive calls) can be easily seen.

3 EXPLAIN PLAN

When a performance SQL dead, not the results, we can use this, this is definitely the estimated execution plan, but there is no way, we must first refer to this optimization.

EXPLAIN PLAN FOR select * from emp;

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);

超级简单的执行计划,在不出结果时初步参考使用,属于无奈之举。

4 关于执行计划入口选择

执行计划的入口选在很重要,我们要知道执行计划从哪里开始的,执行计划阅读方法请自行网上搜索<光标移动大法>,这是一个比较好用的办法。

Guess you like

Origin blog.csdn.net/songjian1104/article/details/91349922