在上一章裏,重點分享了命令行SQL分析工具的使用方法。在本章將重點分享PL/SQL的SQL分析工具。
1、如何打開PL/SQL執行計劃
開啓PL/SQL這工具,推薦以下方法:
- 點擊文件菜單,選擇新建子菜單,選中解釋計劃窗口
- 鍵盤快捷方法,先按alt,而後按F,接着按N,最後按E
2、設置PL/SQL執行計劃
初次打開「解釋計劃窗口」,只能看到基數、優化器、耗費等基本信息,其實這個能夠在PL/SQL工具裏面設置的。能夠看到不少其它信息,以下所示:
3、看懂執行計劃
執行順序的原則是:由上至下,從右向左。
由上至下:在執行計劃中通常含有多個節點,相關級別(或並列)的節點,靠上的優先執行,靠下的後執行;
從右向左:在某個節點下還存在多個子節點,先從最靠右的子節點開始執行;
在PL/SQL工具中也能夠經過它提供的功能來查看執行順序,以下圖所示:
4、表訪問方式
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頁。
5、總結
市面上充斥着各類各樣的培訓機構,大肆宣揚各類診斷分析工具的使用技巧,彷佛診斷分析工具和腳本自己比真正的性能分析和優化措施還重要。工具是用於解決某些具體問題的,若是工具自己太過複雜,充滿玄機,咱們還須要用它麼?
懂原理,才能作分析!