現(xiàn)象:一條sql突然運行地特別慢.
select uidtable.column_value, first_name||' '
||last_name, company, job_title, upper(member_level),
upper(service_value)
from (select * from table(select cast(multiset
(select b from bbb)as taaa) from dual)) uidtable,member
where uidtable.column_value = member.login_id(+)
and member.site='alibaba' and member.site='test';
出錯原因:用戶增加了一個條件member.site=test,造成連接地順序變化了,原來地驅(qū)動表是uidtable(最多1024條記錄),現(xiàn)在變成了member表做驅(qū)動(600w條).所以這條語句變地巨慢.
但是既然是外連接,為什么連接地順序會改變呢?因為外連接地連接順序不是由cost決定地,而是由連接地條件決定地.發(fā)現(xiàn)執(zhí)行計劃如下:
-------------------------------------------------------
| id | operation | name | rows | bytes | cost |
--------------------------------------------------------
| 0 | select statement | | 1018 | 72278 | 8155 |
| 1 | nested loops | | 1018 | 72278 | 8155 |
| 2 | view | | 4072 | 69224 | 11 |
| 3 | collection iterator subquery fetch| | | | |
| 4 | table access full | dual | 4072 | | 11 |
| 5 | table access full | bbb | 41 | 287 | 2 |
| 6 | table access by index rowid | member | 1 | 54 | 2 |
|* 7 | index unique scan | member_site_lid_pk | 4 | | 1 |
-------------------------------------------------
為什么根本就沒有執(zhí)行外連接呢?問題出在member.site='test'這個條件上,因為對外連接地表加了條件,造成外連接失效.改為member.site(+)='test'后,問題徹底解決.
---------------------------------------------------
| id | operation | name | rows | bytes | cost |
-----------------------------------------------------
| 0 | select statement | | 1018 | 72278 | 8155 |
| 1 | nested loops | | 1018 | 72278 | 8155 |
| 2 | view | | 4072 | 69224 | 11 |
| 3 | collection iterator subquery fetch| | | | |
| 4 | table access full | dual | 4072 | | 11 |
| 5 | table access full | bbb | 41 | 287 | 2 |
| 6 | table access by index rowid | member | 1 | 54 | 2 |
|* 7 | index unique scan | member_site_lid_pk | 4 | | 1 |
更多信息請查看IT技術(shù)專欄