[20210120]提示加入註解.txt
[20210120]提示加入註解.txt
--//經常做sql語句最佳化,需要手工加入各種提示,但是有時候要取消很麻煩,我個人喜歡直接加入一些11,12之類的字元在提示前.
--//看崔華<基於Oracle的SQL最佳化>,看到許多例子自己根據工作需要自己測試看看.
--//透過例子說明:
1.環境:
SCOTT@book> @ ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
2.測試:
select
/*+
gather_plan_statistics
use_hash(emp)
*/
* from dept,emp where dept.deptno=emp.deptno;
--//執行計劃如下:
Plan hash value: 615168685
------------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 6 (100)| | 14 |00:00:00.01 | 12 | | | |
|* 1 | HASH JOIN | | 1 | 14 | 812 | 6 (0)| 00:00:01 | 14 |00:00:00.01 | 12 | 1321K| 1321K| 1041K (0)|
| 2 | TABLE ACCESS FULL| DEPT | 1 | 4 | 80 | 3 (0)| 00:00:01 | 4 |00:00:00.01 | 6 | | | |
| 3 | TABLE ACCESS FULL| EMP | 1 | 14 | 532 | 3 (0)| 00:00:01 | 14 |00:00:00.01 | 6 | | | |
------------------------------------------------------------------------------------------------------------------------------------------------
select
/*+
comment gather_plan_statistics
use_hash(emp)
*/
* from dept,emp where dept.deptno=emp.deptno;
--//執行計劃如下:
-----------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 812 | 6 (17)| 00:00:01 |
| 1 | MERGE JOIN | | 14 | 812 | 6 (17)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| DEPT | 4 | 80 | 2 (0)| 00:00:01 |
| 3 | INDEX FULL SCAN | PK_DEPT | 4 | | 1 (0)| 00:00:01 |
|* 4 | SORT JOIN | | 14 | 532 | 4 (25)| 00:00:01 |
| 5 | TABLE ACCESS FULL | EMP | 14 | 532 | 3 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
--//加入comment,這個是oracle的關鍵字,而後面的use_hash(emp)也無效了.我感覺有點奇怪.也就是這樣的方式取消整個提示.
--//這個倒是不錯取消整個提示的好方式.
--//也可以簡單地使用,替換comment.
select
/*+
, gather_plan_statistics
use_hash(emp)
*/
* from dept,emp where dept.deptno=emp.deptno;
--//執行計劃如下:
Plan hash value: 844388907
--------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time | OMem | 1Mem | Used-Mem |
--------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 6 (100)| | | | |
| 1 | MERGE JOIN | | 14 | 812 | 6 (17)| 00:00:01 | | | |
| 2 | TABLE ACCESS BY INDEX ROWID| DEPT | 4 | 80 | 2 (0)| 00:00:01 | | | |
| 3 | INDEX FULL SCAN | PK_DEPT | 4 | | 1 (0)| 00:00:01 | | | |
|* 4 | SORT JOIN | | 14 | 532 | 4 (25)| 00:00:01 | 2048 | 2048 | 2048 (0)|
| 5 | TABLE ACCESS FULL | EMP | 14 | 532 | 3 (0)| 00:00:01 | | | |
--------------------------------------------------------------------------------------------------------------------
--//如果想取消某個提示,可以直接在提示前加入--,修改如下:
select
/*+
--gather_plan_statistics
use_hash(emp)
*/
* from dept,emp where dept.deptno=emp.deptno;
--//執行計劃如下:
-------------------------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time | OMem | 1Mem | Used-Mem |
-------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 6 (100)| | | | |
|* 1 | HASH JOIN | | 14 | 812 | 6 (0)| 00:00:01 | 1321K| 1321K| 1074K (0)|
| 2 | TABLE ACCESS FULL| DEPT | 4 | 80 | 3 (0)| 00:00:01 | | | |
| 3 | TABLE ACCESS FULL| EMP | 14 | 532 | 3 (0)| 00:00:01 | | | |
-------------------------------------------------------------------------------------------------------
select
/*+
gather_plan_statistics
--use_hash(emp)
*/
* from dept,emp where dept.deptno=emp.deptno;
--//執行計劃如下:
Plan hash value: 844388907
-------------------------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
-------------------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 6 (100)| | 14 |00:00:00.01 | 8 | | | |
| 1 | MERGE JOIN | | 1 | 14 | 812 | 6 (17)| 00:00:01 | 14 |00:00:00.01 | 8 | | | |
| 2 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 | 4 | 80 | 2 (0)| 00:00:01 | 4 |00:00:00.01 | 2 | | | |
| 3 | INDEX FULL SCAN | PK_DEPT | 1 | 4 | | 1 (0)| 00:00:01 | 4 |00:00:00.01 | 1 | | | |
|* 4 | SORT JOIN | | 4 | 14 | 532 | 4 (25)| 00:00:01 | 14 |00:00:00.01 | 6 | 2048 | 2048 | 2048 (0)|
| 5 | TABLE ACCESS FULL | EMP | 1 | 14 | 532 | 3 (0)| 00:00:01 | 14 |00:00:00.01 | 6 | | | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------
總結:
1.取消整個提示,在最前面加入, 或者comment.
2.另外我個人主張一個提示寫一行,特別在測試與最佳化時.
3.取消單個提示,可以在前面加入--.
4.如果大家做最佳化加入提示有什麼好方法,歡迎加入討論.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2751251/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20210120]in list與繫結變數個數.txt變數
- [20211026]奇怪註解不起作用.txt
- [20240607]PL/SQL中sql語句的註解.txtSQL
- [20211213]提示precompute_subquery.txt
- [20180927]修改sql prompt提示.txtSQL
- [20180503]檢視提示使用索引.txt索引
- [20190502]給顯示輸出加入時間戳.txt時間戳
- [20211215]提示precompute_subquery補充.txt
- [20201130]11g or_expand提示.txt
- [20181220]使用提示OR_EXPAND優化.txt優化
- 解決陌陌註冊新號就提示裝置異常
- vscode 沒有函式註釋提示VSCode函式
- JAVA-註解(2)-自定義註解及反射註解Java反射
- 註解專題(一)Java元註解,內建註解Java
- [20211221]提示precompute_subquery補充2.txt
- Java註解-後設資料、註解分類、內建註解和自定義註解Java
- 【Spring註解】事務註解@TransactionalSpring
- @ResponseBody註解和@RequestBody註解使用
- Win10正式版系統中提示“加入家庭組時遇到錯誤”怎麼解決Win10
- win10系統加入域一直提示找不到網路路徑怎麼解決Win10
- 註解
- Java註解詳解「註解專案實戰」Java
- Java中的註解-自定義註解Java
- [20220517]toad使用gather_plan_statistics提示問題.txt
- [20211115]配置logrotate提示parent directory has insecure permissions.txtlogrotate
- [20210929]sql打補丁使用rule提示問題.txtSQL
- [20191213]toad 12下BIND_AWARE提示無效.txt
- [20190524]使用use_concat or_expand提示優化.txt優化
- 【String註解驅動開發】你瞭解@PostConstruct註解和@PreDestroy註解嗎?Struct
- [20181225]如何清除註冊的線上日誌.txt
- Java註解解析-搭建自己的註解處理器(CLASS註解使用篇)Java
- SwaggerAPI註解詳解,以及註解常用引數配置SwaggerAPI
- Spring 註解程式設計之模式註解Spring程式設計模式
- SpringBoot註解Spring Boot
- 註解 javaJava
- java註解Java
- 註解 & 反射反射
- 註解 @component