潦草白纸

品味性能之道<六>:图形化SQL分析工具

     在上一章里,重点分享了命令行SQL分析工具的使用方法。在本章将重点分享PL/SQL的SQL分析工具。
一、如何打开PL/SQL执行计划
     开启PL/SQL这工具,推荐如下方法:
  • 点击文件菜单,选择新建子菜单,选中解释计划窗口
  • 键盘快捷方法,先按alt,然后按F,接着按N,最后按E

二、设置PL/SQL执行计划
     初次打开“解释计划窗口”,只能看到基数、优化器、耗费等基本信息,其实这个可以在PL/SQL工具里面设置的。可以看到很多其它信息,如下所示
     

三、看懂执行计划
     执行顺序的原则是:由上至下,从右向左。
     由上至下:在执行计划中一般含有多个节点,相关级别(或并列)的节点,靠上的优先执行,靠下的后执行;
     从右向左:在某个节点下还存在多个子节点,先从最靠右的子节点开始执行;
     
     在PL/SQL工具中也可以通过它提供的功能来查看执行顺序,如下图所示:
     

四、表访问方式 
     Full Table Scan (FTS) --全表扫描
     Index Lookup --索引扫描
     Index unique scan --索引唯一扫描,通过唯一索引查找一个数值经常返回单个ROWID,如果存在UNIQUE或PRIMARY KEY约束(它保证了语句只存取单行的话),ORACLE经常实现唯一性扫描
     Index range scan --索引局部扫描,使用一个索引存取多行数据,在唯一索引上使用索引范围扫描的典型情况是在谓词(WHERE 限制条件)中使用了范围操作符号(如>, < <>, >=, <=,BWTEEN) 
     Index full scan --索引全局扫描,Full index scans are only available in the CBO as otherwise we are unable to determine whether a full scan would be a good idea or not. We choose an index Full Scan when we have statistics that indicate that it is going to be more efficient than a Full table scan and a sort. For example we may do a Full index scan when we do an unbounded scan of an index and want the data to be ordered in the index order. (直接抄书了,别怪我!)
     Fast Full Index Scans --快速全局索引扫描,不带order by情况下常常发生。Fast full index scans are an alternative to a full table scan when the index contains all the columns that are needed for the query, and at least one column in the index key has the NOT NULL constraint. A fast full scan accesses the data in the index itself,without accessing the table. The database cannot use this scan to eliminate a sort operation because the data is not ordered by the index key.
     Rowid Scans --物理ID扫描,最快的访问数据方式。This is the quickest access method available.Oracle retrieves the specified block and extracts the rows it is interested in.
     Index skip scan --索引跳跃扫描,where条件列是非索引的前提情况下常发生。Index skip scan finds rows even if the column is not the leading column of a concatenated index. It skips the first column(s) during the search. 
     关于表访问方式的详细介绍,请见Oracle联机文档 Oracle Database Performance Tuning Guide 11g Release 2(11.2)的第11章287页。

五、总结
     市面上充斥着各种各样的培训机构,大肆宣扬各种诊断分析工具的使用技巧,似乎诊断分析工具和脚本本身比真正的性能分析和优化措施还重要。工具是用于解决某些具体问题的,如果工具本身太过复杂,充满玄机,我们还需要用它么?
     懂原理,才能做分析!
 
 

posted on 2013-12-06 18:58  潦草白纸  阅读(2036)  评论(0编辑  收藏  举报

导航