Oracle的又一巨型bug
關於exist中條件為true時的執行計劃問題,同事發現的,還真沒留意到:
SQL> with tmp as(
2 select 1 a from dual union all
3 select 2 a from dual union all
4 select 3 a from dual union all
5 select 4 a from dual),
6 notext as(
7 select 2 a from dual union all
8 select 3 a from dual)
9 select * from tmp a where exists(select 1 from notext b where b.a = decode(1,1,b.a,a.a))
10 /
A
----------
1
2
3
4
1
2
3
4
8 rows selected
執行計劃(紅色部分明顯錯了):
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 24 | 13 (8)| 00:00:01 |
| 1 | MERGE JOIN CARTESIAN| | 4 | 24 | 13 (8)| 00:00:01 |
|* 2 | VIEW | | 2 | 6 | 4 (0)| 00:00:01 |
| 3 | HASH UNIQUE | | 2 | | 4 (50)| 00:00:01 |
| 4 | UNION-ALL | | | | | |
| 5 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 6 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 7 | BUFFER SORT | | 4 | 12 | 13 (8)| 00:00:01 |
| 8 | VIEW | | 4 | 12 | 8 (0)| 00:00:01 |
| 9 | UNION-ALL | | | | | |
| 10 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 11 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 12 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 13 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
-----------------------------------------------------------------------------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("B"."A"="B"."A")
25 rows selected
正確的結果(加了紅色部分):
with tmp as(
select 1 a from dual union all
select 2 a from dual union all
select 3 a from dual union all
select 4 a from dual),
notext as(
select 2 a from dual union all
select 3 a from dual)
select * from tmp a where exists(select 1 from notext b where b.a = decode(1,1,b.a,a.a) and rownum <= 1e100)
執行計劃(透過rownum約束了謂詞推進,這次對了):
-------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 | 12 (0)| 00:00:01 |
|* 1 | FILTER | | | | | |
| 2 | VIEW | | 4 | 12 | 8 (0)| 00:00:01 |
| 3 | UNION-ALL | | | | | |
| 4 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 5 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 6 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 7 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
|* 8 | COUNT STOPKEY | | | | | |
| 9 | VIEW | | 2 | 6 | 4 (0)| 00:00:01 |
| 10 | UNION-ALL | | | | | |
| 11 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 12 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
-------------------------------------------------------------------------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter( EXISTS (SELECT /*+ */ 0 FROM ( (SELECT /*+ */ 2 "A"
FROM "SYS"."DUAL" "DUAL") UNION ALL (SELECT /*+ */ 3 "A" FROM
"SYS"."DUAL" "DUAL")) "B" WHERE ROWNUM<=1e100))
8 - filter(ROWNUM<=1e100)
bell6248給的另一個解決辦法:
with tmp as(
select 1 a from dual union all
select 2 a from dual union all
select 3 a from dual union all
select 4 a from dual),
notext as(
select 2 a from dual union all
select 3 a from dual)
select rownum from tmp a where exists(select 1 from notext b where b.a = decode(1,1,b.a,a.a))
需要說明的是,以證明在11g裡面該bug已經修復。10201bug太多了,什麼時候發個心把版本升了。
SQL> with tmp as(
2 select 1 a from dual union all
3 select 2 a from dual union all
4 select 3 a from dual union all
5 select 4 a from dual),
6 notext as(
7 select 2 a from dual union all
8 select 3 a from dual)
9 select * from tmp a where exists(select 1 from notext b where b.a = decode(1,1,b.a,a.a))
10 /
A
----------
1
2
3
4
1
2
3
4
8 rows selected
執行計劃(紅色部分明顯錯了):
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 24 | 13 (8)| 00:00:01 |
| 1 | MERGE JOIN CARTESIAN| | 4 | 24 | 13 (8)| 00:00:01 |
|* 2 | VIEW | | 2 | 6 | 4 (0)| 00:00:01 |
| 3 | HASH UNIQUE | | 2 | | 4 (50)| 00:00:01 |
| 4 | UNION-ALL | | | | | |
| 5 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 6 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 7 | BUFFER SORT | | 4 | 12 | 13 (8)| 00:00:01 |
| 8 | VIEW | | 4 | 12 | 8 (0)| 00:00:01 |
| 9 | UNION-ALL | | | | | |
| 10 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 11 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 12 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 13 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
-----------------------------------------------------------------------------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("B"."A"="B"."A")
25 rows selected
正確的結果(加了紅色部分):
with tmp as(
select 1 a from dual union all
select 2 a from dual union all
select 3 a from dual union all
select 4 a from dual),
notext as(
select 2 a from dual union all
select 3 a from dual)
select * from tmp a where exists(select 1 from notext b where b.a = decode(1,1,b.a,a.a) and rownum <= 1e100)
執行計劃(透過rownum約束了謂詞推進,這次對了):
-------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 | 12 (0)| 00:00:01 |
|* 1 | FILTER | | | | | |
| 2 | VIEW | | 4 | 12 | 8 (0)| 00:00:01 |
| 3 | UNION-ALL | | | | | |
| 4 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 5 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 6 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 7 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
|* 8 | COUNT STOPKEY | | | | | |
| 9 | VIEW | | 2 | 6 | 4 (0)| 00:00:01 |
| 10 | UNION-ALL | | | | | |
| 11 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 12 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
-------------------------------------------------------------------------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter( EXISTS (SELECT /*+ */ 0 FROM ( (SELECT /*+ */ 2 "A"
FROM "SYS"."DUAL" "DUAL") UNION ALL (SELECT /*+ */ 3 "A" FROM
"SYS"."DUAL" "DUAL")) "B" WHERE ROWNUM<=1e100))
8 - filter(ROWNUM<=1e100)
bell6248給的另一個解決辦法:
with tmp as(
select 1 a from dual union all
select 2 a from dual union all
select 3 a from dual union all
select 4 a from dual),
notext as(
select 2 a from dual union all
select 3 a from dual)
select rownum from tmp a where exists(select 1 from notext b where b.a = decode(1,1,b.a,a.a))
需要說明的是,以證明在11g裡面該bug已經修復。10201bug太多了,什麼時候發個心把版本升了。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12932950/viewspace-718193/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle groupby的bugOracle
- oracle bugOracle
- oracle的一個bugOracle
- Oracle srvctl的小bugOracle
- oracle的兩個bugOracle
- 2015:巨型 JavaScript 框架的末日JavaScript框架
- Oracle Debug ---- oradebugOracle
- 巨型專案如何選擇合適的框架?框架
- Oracle bug的手工修復Oracle
- oracle ucm 的嚴重bugOracle
- Oracle10.2.0.1的bugOracle
- oracle interval日期函式的bug!Oracle函式
- oracle interval日期函式的bugOracle函式
- oracle 10.2.0.2.0的一個BUGOracle
- ORACLE 9I not exists的bugOracle
- oracle串物件相關的bugOracle物件
- oracle之BUG 7497640Oracle
- ADBUG發現中國巨型作弊網路「紅眼」,廣告主每天損失超2000萬
- Oracle關於nvl的一個BugOracle
- 一個oracle查詢引起的bugOracle
- 由drop datafile導致的oracle bugOracle
- oracle10.1.0.4.0bugOracle
- ORACLE EVENT && ORADEBUGOracle
- Oracle oradebug命令Oracle
- 從《Skelittle 巨型派對》看輕度聚會遊戲的困境遊戲
- powerbuilder 11的又一怪事UI
- [轉帖]深度探究Linux核心透明巨型頁Linux
- 一個oracle bug的簡單驗證Oracle
- kewastUnPackStats(): oracle 11.2.0.1的bug解決方法ASTOracle
- Oracle 9201下connect by的bugOracle
- oradebug分析oracle hangOracle
- (轉)Oracle EVENT && ORADEBUGOracle
- ORACLE 自定義函式BUG?Oracle函式
- oracle 9i index bug?OracleIndex
- ORACLE 10.2.0.4 RAC BUG IN HPOracle
- 又一個有趣的面試題面試題
- MMORPG聯動&巨型BOSS設計經驗分享
- OpenAI CEO表示巨型AI模型時代已經結束OpenAI模型