[20201116]11g連線謂詞推入push_pred問題.txt
[20201116]11g連線謂詞推入push_pred問題.txt
--//看崔華<基於oracle的sql最佳化>,裡面提到11g連線謂詞推入問題的問題自己重複測試看看.
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.測試環境建立:
--//注書中的例子好像不是scott.emp表,不過應該不影響測試.
create table emp1 as select * from emp ;
create index i_emp1_empno on emp1(empno);
create or replace view emp_view as select emp1.empno as empno1 from emp1;
3.測試:
SCOTT@book> alter session set statistics_level = all;
Session altered.
SCOTT@book> select emp.empno from emp,emp_view where emp.empno=emp_view.empno1 and emp.ename='FORD';
EMPNO
----------
7902
SCOTT@book> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID b7up3a8rsctnz, child number 0
-------------------------------------
select emp.empno from emp,emp_view where emp.empno=emp_view.empno1 and emp.ename='FORD'
Plan hash value: 1061644130
-----------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
-----------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 3 (100)| | 1 |00:00:00.01 | 9 |
| 1 | NESTED LOOPS | | 1 | 1 | 14 | 3 (0)| 00:00:01 | 1 |00:00:00.01 | 9 |
|* 2 | TABLE ACCESS FULL| EMP | 1 | 1 | 10 | 3 (0)| 00:00:01 | 1 |00:00:00.01 | 7 |
|* 3 | INDEX RANGE SCAN | I_EMP1_EMPNO | 1 | 1 | 4 | 0 (0)| | 1 |00:00:00.01 | 2 |
-----------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$F5BB74E1
2 - SEL$F5BB74E1 / EMP@SEL$1
3 - SEL$F5BB74E1 / EMP1@SEL$2
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("EMP"."ENAME"='FORD')
3 - access("EMP"."EMPNO"="EMP1"."EMPNO")
29 rows selected.
--//這裡僅僅簡單檢視合併.可以透過提示merge確定,修改如下:
SCOTT@book> select /*+ merge(emp_view) */ emp.empno from emp,emp_view where emp.empno=emp_view.empno1 and emp.ename='FORD';
EMPNO
----------
7902
SCOTT@book> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 35ybv5cn4vx32, child number 0
-------------------------------------
select /*+ merge(emp_view) */ emp.empno from emp,emp_view where
emp.empno=emp_view.empno1 and emp.ename='FORD'
Plan hash value: 1061644130
-----------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
-----------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 3 (100)| | 1 |00:00:00.01 | 9 |
| 1 | NESTED LOOPS | | 1 | 1 | 14 | 3 (0)| 00:00:01 | 1 |00:00:00.01 | 9 |
|* 2 | TABLE ACCESS FULL| EMP | 1 | 1 | 10 | 3 (0)| 00:00:01 | 1 |00:00:00.01 | 7 |
|* 3 | INDEX RANGE SCAN | I_EMP1_EMPNO | 1 | 1 | 4 | 0 (0)| | 1 |00:00:00.01 | 2 |
-----------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$F5BB74E1
2 - SEL$F5BB74E1 / EMP@SEL$1
3 - SEL$F5BB74E1 / EMP1@SEL$2
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("EMP"."ENAME"='FORD')
3 - access("EMP"."EMPNO"="EMP1"."EMPNO")
4.使用提示no_merge看看:
SCOTT@book> select /*+ no_merge(emp_view)*/ emp.empno from emp,emp_view where emp.empno=emp_view.empno1 and emp.ename='FORD';
EMPNO
----------
7902
SCOTT@book> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 7kghy2nb3bnr9, child number 0
-------------------------------------
select /*+ no_merge(emp_view)*/ emp.empno from emp,emp_view where
emp.empno=emp_view.empno1 and emp.ename='FORD'
Plan hash value: 1565533375
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers | Reads | OMem | 1Mem | Used-Mem |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 6 (100)| | 1 |00:00:00.01 | 6 | 1 | | | |
| 1 | MERGE JOIN | | 1 | 1 | 23 | 6 (17)| 00:00:01 | 1 |00:00:00.01 | 6 | 1 | | | |
|* 2 | TABLE ACCESS BY INDEX ROWID| EMP | 1 | 1 | 10 | 2 (0)| 00:00:01 | 1 |00:00:00.01 | 4 | 1 | | | |
| 3 | INDEX FULL SCAN | PK_EMP | 1 | 14 | | 1 (0)| 00:00:01 | 14 |00:00:00.01 | 2 | 1 | | | |
|* 4 | SORT JOIN | | 1 | 14 | 182 | 4 (25)| 00:00:01 | 1 |00:00:00.01 | 2 | 0 | 2048 | 2048 | 2048 (0)|
| 5 | VIEW | EMP_VIEW | 1 | 14 | 182 | 3 (0)| 00:00:01 | 14 |00:00:00.01 | 2 | 0 | | | |
| 6 | TABLE ACCESS FULL | EMP1 | 1 | 14 | 56 | 3 (0)| 00:00:01 | 14 |00:00:00.01 | 2 | 0 | | | |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / EMP@SEL$1
3 - SEL$1 / EMP@SEL$1
5 - SEL$2 / EMP_VIEW@SEL$1
6 - SEL$2 / EMP1@SEL$2
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("EMP"."ENAME"='FORD')
4 - access("EMP"."EMPNO"="EMP_VIEW"."EMPNO1")
filter("EMP"."EMPNO"="EMP_VIEW"."EMPNO1")
35 rows selected.
--//11g無法實現連線謂詞推入push_pred
--//透過如下提示控制如何呢?
SCOTT@book> select /*+ no_merge(emp_view) use_nl(emp_view) push_pred(emp_view) */ emp.empno from emp,emp_view where emp.empno=emp_view.empno1 and emp.ename='FORD';
EMPNO
----------
7902
SCOTT@book> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID dd885z1b7u4nz, child number 0
-------------------------------------
select /*+ no_merge(emp_view) use_nl(emp_view) push_pred(emp_view) */
emp.empno from emp,emp_view where emp.empno=emp_view.empno1 and
emp.ename='FORD'
Plan hash value: 3774177413
--------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
--------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 6 (100)| | 1 |00:00:00.01 | 10 |
| 1 | NESTED LOOPS | | 1 | 1 | 23 | 6 (0)| 00:00:01 | 1 |00:00:00.01 | 10 |
|* 2 | TABLE ACCESS FULL | EMP | 1 | 1 | 10 | 3 (0)| 00:00:01 | 1 |00:00:00.01 | 7 |
|* 3 | VIEW | EMP_VIEW | 1 | 1 | 13 | 3 (0)| 00:00:01 | 1 |00:00:00.01 | 3 |
| 4 | TABLE ACCESS FULL| EMP1 | 1 | 14 | 56 | 3 (0)| 00:00:01 | 14 |00:00:00.01 | 3 |
--------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / EMP@SEL$1
3 - SEL$2 / EMP_VIEW@SEL$1
4 - SEL$2 / EMP1@SEL$2
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("EMP"."ENAME"='FORD')
3 - filter("EMP"."EMPNO"="EMP_VIEW"."EMPNO1")
32 rows selected.
--//確實像作者介紹那樣,11g這種情況無法實現謂詞推入。也許我哪裡做錯了........
4.繼續測試:
--//12c呢?
SCOTT@test01p> @ ver1
PORT_STRING VERSION BANNER CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0 12.2.0.1.0 Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 0
--//建表以及測試相關檢視略。
SCOTT@test01p> select /*+ no_merge(emp_view) use_nl(emp_view) push_pred(emp_view) */ emp.empno from emp,emp_view where emp.empno=emp_view.empno1 and emp.ename='FORD';
EMPNO
----------
7902
SCOTT@test01p> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID dd885z1b7u4nz, child number 0
-------------------------------------
select /*+ no_merge(emp_view) use_nl(emp_view) push_pred(emp_view) */
emp.empno from emp,emp_view where emp.empno=emp_view.empno1 and
emp.ename='FORD'
Plan hash value: 3352622377
----------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
----------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 4 (100)| | 1 |00:00:00.01 | 10 |
| 1 | NESTED LOOPS | | 1 | 1 | 12 | 4 (0)| 00:00:01 | 1 |00:00:00.01 | 10 |
|* 2 | TABLE ACCESS FULL | EMP | 1 | 1 | 10 | 3 (0)| 00:00:01 | 1 |00:00:00.01 | 8 |
| 3 | VIEW PUSHED PREDICATE | EMP_VIEW | 1 | 1 | 2 | 1 (0)| 00:00:01 | 1 |00:00:00.01 | 2 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|* 4 | INDEX RANGE SCAN | I_EMP1_EMPNO | 1 | 1 | 4 | 1 (0)| 00:00:01 | 1 |00:00:00.01 | 2 |
----------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / EMP@SEL$1
3 - SEL$639F1A6F / EMP_VIEW@SEL$1
4 - SEL$639F1A6F / EMP1@SEL$2
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("EMP"."ENAME"='FORD')
4 - access("EMP1"."EMPNO"="EMP"."EMPNO")
--//很明顯不像作者書中介紹那樣,12c是可以最佳化的.
--//說明一點許多東西會變,oracle也在不斷完善自己,當然bug也越來越多。不能抱著一成不變的觀點看問題,要與時俱進^_^。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2734347/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20201116]測試CURSOR_SPACE_FOR_TIME=false(11g).txtFalse
- [20201126]11g VPD的問題.txt
- [20200711]關於左右連線的問題.txt
- [20201210]11G ACS相關問題.txt
- CodeQL學習筆記(1)-QL語法(邏輯連線詞、量詞、聚合詞、謂詞和類)筆記
- [20181128]toad連線資料庫的問題.txt資料庫
- [20181006]12c使用toad連線問題.txt
- [20201116]bash shell IO重定向.txt
- [20200117]push_pred distinct group by.txt
- [20230306]os認證連線資料庫問題.txt資料庫
- [20180819]關於父子游標問題(11g).txt
- 【大資料】SparkSql連線查詢中的謂詞下推處理(一)大資料SparkSQL
- 【大資料】SparkSql 連線查詢中的謂詞下推處理 (二)大資料SparkSQL
- [20181128]toad連線資料庫的問題(補充).txt資料庫
- C++謂詞C++
- Java 8謂詞鏈Java
- 03-NSPredicate謂詞
- [20190409]pre_page_sga=true與連線緩慢的問題.txt
- MySQL SSL連線問題MySql
- [20181107]低版本toad連線18c資料庫問題.txt資料庫
- java8-謂詞(predicate)Java
- 【問題記錄】—SignalR連線斷線重連SignalR
- [20210126]bash ln建立軟連結問題.txt
- 檢測ftp連線問題FTP
- mysql odbc delphi連線問題MySql
- Github ssh的連線問題Github
- [20220815]奇怪的隱式轉換問題(11g測試補充).txt
- 5.1一階謂詞邏輯
- 原子謂詞公式和合式公式公式
- 熱點:安全問題是否能將DNS推入雲服務DNS
- 【Github】 Github訪問不是私密連線問題Github
- xshell連線不上linux問題Linux
- 關於 Homestead 連線 MySQL 問題MySql
- [20201116]測試CURSOR_SPACE_FOR_TIME(10g)(補充).txt
- 解決代理連線超時問題
- [20230214]資料庫連線訪問asm相關檢視.txt資料庫ASM
- 傳說中的“謂詞越界“場景
- SQL 改寫系列七:謂詞移動SQL