[20190430]注意sql hint寫法.txt
[20190430]注意sql hint寫法.txt
--//連結:
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
SCOTT@book> @ sqlhint cache
old 1: select * from V$SQL_HINT where name like upper('%&1%')
new 1: select * from V$SQL_HINT where name like upper('%cache%')
NAME SQL_FEATURE CLASS INVERSE TARGET_LEVEL PROPERTY VERSION VERSION_OUTLINE
---------------- --------------- ------------ --------------- ------------ ---------- -------- ----------------
CACHE_CB QKSFM_CBO CACHE_CB NOCACHE 4 256 8.1.5
CACHE QKSFM_EXECUTION CACHE NOCACHE 4 256 8.1.0
NOCACHE QKSFM_EXECUTION CACHE CACHE 4 256 8.1.0
CACHE_TEMP_TABLE QKSFM_ALL CACHE NOCACHE 4 256 8.1.5
RESULT_CACHE QKSFM_EXECUTION RESULT_CACHE NO_RESULT_CACHE 2 0 11.1.0.6
NO_RESULT_CACHE QKSFM_EXECUTION RESULT_CACHE RESULT_CACHE 2 0 11.1.0.6
6 rows selected.
SCOTT@book> select /*+ result cache */ * from dept ;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
--//注意中間沒有"_".
SCOTT@book> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 5sm6uuf1wtunm, child number 0
-------------------------------------
select /*+ result cache */ * from dept
Plan hash value: 3383998547
---------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 3 (100)| |
| 1 | TABLE ACCESS FULL| DEPT | 4 | 80 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / DEPT@SEL$1
SCOTT@book> select /*+ result_cache */ * from dept ;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SCOTT@book> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID dh09kah6tkdjy, child number 0
-------------------------------------
select /*+ result_cache */ * from dept
Plan hash value: 3383998547
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
--------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 3 (100)| |
| 1 | RESULT CACHE | gsg6g7y8rvxaydjyjh2g2yr21r | | | | |
| 2 | TABLE ACCESS FULL| DEPT | 4 | 80 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / DEPT@SEL$1
--//連結:也提到一種情況:
--//我沒有19c.
SCOTT@book> select /*+ use_nl(emp dept) */ * from dept ,emp where dept.deptno=emp.deptno;
...
SCOTT@book> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID gk5d852xxj4b5, child number 0
-------------------------------------
select /*+ use_nl(emp dept) */ * from dept ,emp where
dept.deptno=emp.deptno
Plan hash value: 4192419542
----------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 10 (100)| |
| 1 | NESTED LOOPS | | 14 | 812 | 10 (0)| 00:00:01 |
| 2 | TABLE ACCESS FULL| DEPT | 4 | 80 | 3 (0)| 00:00:01 |
|* 3 | TABLE ACCESS FULL| EMP | 4 | 152 | 2 (0)| 00:00:01 |
----------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / DEPT@SEL$1
3 - SEL$1 / EMP@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter("DEPT"."DEPTNO"="EMP"."DEPTNO")
--//注意看執行計劃,實際上主驅動dept表.只有寫成如下:
SCOTT@book> select /*+ use_nl(emp ) */ * from dept ,emp where dept.deptno=emp.deptno;
..
Plan hash value: 1123238657
-------------------------------------------------------------------------------------------------------
| 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 | 1048K| 1048K| 662K (0)|
| 2 | TABLE ACCESS FULL| EMP | 14 | 532 | 3 (0)| 00:00:01 | | | |
| 3 | TABLE ACCESS FULL| DEPT | 4 | 80 | 3 (0)| 00:00:01 | | | |
-------------------------------------------------------------------------------------------------------
--//這樣emp才能作為驅動表.
--//最後一種情況是我經常犯的錯誤..
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2642961/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20200718]注意sql hint寫法2.txtSQL
- [20200801]sql hint衝突.txtSQL
- Oracle中的sql hintOracleSQL
- openGauss 支援SQL-hintSQL
- GreatSQL 在SQL中使用 HINT 語法修改會話變數SQL會話變數
- [20211229]toad下優化sql語句注意的問題.txt優化SQL
- [20220329]是否開發寫錯sql語句.txtSQL
- [20220330]編寫sql打補丁的指令碼.txtSQL指令碼
- SQL語句規範的寫法SQL
- Mysql 分組排序的sql寫法MySql排序
- 個人線段樹寫法 & 注意逝項
- [20190917]oracle跟蹤事件簡單寫法.txtOracle事件
- [20220104]in list 幾種寫法效能測試.txt
- SQL Server 2008連線字串寫法大全SQLServer字串
- [20231207]開發不應該這樣寫sql4.txtSQL
- [20220124]開發不應該這樣寫sql3.txtSQL
- [20220109]開發不應該這樣寫SQL語句.txtSQL
- [20220121]開發不應該這樣寫sql2.txtSQL
- [20181123]快速提升scn注意.txt
- [20220121]windows使用grep注意.txtWindows
- [20210408]使用linux find注意.txtLinux
- 第39期:MySQL 時間類分割槽寫 SQL 注意事項MySql
- 精讀《手寫 SQL 編譯器 - 詞法分析》SQL編譯詞法分析
- 精讀《手寫 SQL 編譯器 - 語法樹》SQL編譯
- 資料庫規範之SQL規範寫法資料庫SQL
- 精讀《手寫 SQL 編譯器 - 語法分析》SQL編譯語法分析
- 請求引數為物件,mybatis的sql寫法物件MyBatisSQL
- 精讀《手寫 SQL 編譯器 – 詞法分析》SQL編譯詞法分析
- django | 常見 SQL 及其對應的 ORM 寫法DjangoSQLORM
- MySQL與SQL的觸發器的不同寫法MySql觸發器
- SQL WHERE IN引數化編譯寫法簡單示例SQL編譯
- 神奇的 SQL 之別樣的寫法 → 行行比較SQL
- SQL 抽象語法樹及改寫場景應用SQL抽象語法樹
- SQL抽象語法樹及改寫場景應用SQL抽象語法樹
- [2020528]寫sql語句不要忘記給欄位加上表別名.txtSQL
- [20190314]使用strace注意的問題.txt
- [20190221]sql patch 問題.txtSQL
- [20180927]修改sql prompt提示.txtSQL