0
我有以下查詢:爲什麼在一個oracle函數中比沒有它的時候比較慢,我該如何提高性能?
select o.a1
from d
inner join c on d.cid = c.cid
inner join o on c.oid = o.oid
inner join l on d.did = l.did
inner join a on l.lid = a.lid
where (case when d.name = 'some name' and d.q > 0 and
((l.p in ('a', 'b', 'c', 'd', 'e')
and a.db != 0) or
(d.m is null or d.m > some_value)) then 1 else 0 end) = 1
此查詢運行200毫秒左右。現在我想在incapsulate這樣一個功能比較邏輯:
function is_that_true
(
a nvarchar2,
b number,
c nvarchar2,
d number,
e date
)
return number result_cache
is
begin
return (case when a = 'some name' and b > 0 and
((c in ('a', 'b', 'c', 'd', 'e')
and d != 0) or
(e is null or e > some_value)) then 1 else 0 end);
end;
當我運行通過更換具有功能比較稱它爲上述查詢運行慢得多(約1分鐘)。這可能是因爲Oracle在後臺進行了一些優化。在這種情況下是否可以使用函數調用並仍然可以獲得可接受的性能?
這並沒有提供問題的答案。要批評或要求作者澄清,在他們的帖子下留下評論 - 你總是可以評論你自己的帖子,一旦你有足夠的[聲譽](http://stackoverflow.com/help/whats-reputation),你會能夠[評論任何帖子](http://stackoverflow.com/help/privileges/comment)。 –
嗨馬蒂亞斯,你能指導我爲什麼我的評論沒有回答這個問題嗎? – Veerender
我現在看到,這是真正的問題的答案。道歉!但話雖如此,如果您能詳細闡述一下,例如展示如何「創建基於函數的索引」。 –