SQL explain plan and AWR

DBMS generates an explain plan for each SQL commands.What does explain plan work for?

As is known,it can use ‘full table scan’ or ‘index’ access destinate data.Which method does DBMS choose?What is the reason?

It is based on explain plan.

That’s an example explain plan as below:

 

Execution Plan
----------------------------------------------------------
Plan hash value: 3956160932

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |    14 |   532 |     3   (0)| 00:00:01 |
|   1 |  TABLE ACCESS FULL| EMP  |    14 |   532 |     3   (0)| 00:00:01 |
--------------------------------------------------------------------------

Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
          8  consistent gets
          0  physical reads
          0  redo size
       1630  bytes sent via SQL*Net to client
        524  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
         14  rows processed

The explain plan is divied into 2 parts,execution plan and statistics.

The execution plan shows that DBMS parses the SQL commands.The 1st step is executing SELECT STATEMENT and the 2nd step is access EMP table using ‘FULL TABLE SCAN’.

The statistics shows that historical statistics information of destinate data.It implies that method of getting physical data.For example,”8 consistent gets” means get data from buffer cache,if DBMS gets it from disk,it turns out to be “8 physical reads”.

Thus,we can conclude that DBMS chooses the most effective way automatically to get data by statistics in explain plan.

How to enable displaying explain plan?A:Enable “autotrace”.It is able to be enabled by DBA and needs to be granted relevant privilege to be enabled by common users.

   1: DBA:set autotrace on
   2: COMMON USER:@?/sqlplus/admin/plustrce.sql;
   3:             set autotrace on

You can query execution in this way:

   1: explain for [SQL COMMAND];
   2: select * from table(dbms_xplan.display);

 

 

“last analyzed” and “row_num” are option of a table depending on statistics.

The DBMS has its own rules to gather statistics.That includes schedules,stale_percent and so on.DBA can use “dbms_stats.set_table_prefs” to modify stale_percent.

Oracle gather all the statistics and performance information and store them into a repository called AWR.It is recommended to make a snapshot as an AWR baseline when database is working properly.The DBMS makes AWR snapshots automatically as well.If it occurs some problems in database someday,DBA can compare performance information at that time and AWR baseline to recognize the reason if possible.The comparation can generate an AWR report which is easily to display.

Make AWR snapshots manually:

   1: dbms_workload_repository.create_snapshot();

Make an AWR reports(2 snapshots at least):

   1: @?/rdbms/admin/awrrpt.sql

Note:Parameter “flush_level” specifies the level of detail to gather.The higher level is,more information is gathered and more resources are taken.

 

There is a component to analyze AWR snapshot which is called ADDM.It can give some advices depending on AWR snapshot and stores its results in AWR too.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章