using sysdate from dual takes longer time [message #666150] |
Tue, 17 October 2017 13:12 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](//www.gravatar.com/avatar/37e14c3d1a0963d82d34d478217718c5?s=64&d=mm&r=g) |
manikandan23
Messages: 34 Registered: February 2017
|
Member |
|
|
Hi,
I have 2 queries. It is yielding the same results. But one query is having cost of 85k and the other one is just 2. Can anyone explain how the difference is and how can I improve the first one?
1. Slow running:
select nvl(pos.qty,0) nqty,pos.*,
sysdate as current_timestamp
from custdata.pos_data pos
where 1=1 and create_date >= (select sysdate-1 from dual)
and src = 'WAL852'
and feed_type ='INV'
and (qty >= 0 or qty is not null);
2. Fast running:
select nvl(pos.qty,0) nqty,pos.*,
sysdate as current_timestamp
from custdata.pos_data pos
where 1=1 and create_date >= (sysdate-1)
and src = 'WAL852'
and feed_type ='INV'
and (qty >= 0 or qty is not null);
|
|
|
|
Re: using sysdate from dual takes longer time [message #666154 is a reply to message #666153] |
Tue, 17 October 2017 13:21 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](//www.gravatar.com/avatar/37e14c3d1a0963d82d34d478217718c5?s=64&d=mm&r=g) |
manikandan23
Messages: 34 Registered: February 2017
|
Member |
|
|
Explain Plan:
1. First Query:
Plan
SELECT STATEMENT CHOOSECost: 81,128 Bytes: 158,842,332 Cardinality: 2,406,702
3 TABLE ACCESS BY INDEX ROWID TABLE CUSTDATA.POS_DATA Cost: 81,126 Bytes: 158,842,332 Cardinality: 2,406,702
1 INDEX RANGE SCAN INDEX CUSTDATA.IDX_POS_DATA_SRC Cost: 15,249 Cardinality: 83,389,963
2 FAST DUAL Cost: 2 Cardinality: 1
2nd query:
Plan
SELECT STATEMENT CHOOSECost: 1 Bytes: 462 Cardinality: 7
2 TABLE ACCESS BY INDEX ROWID TABLE CUSTDATA.POS_DATA Cost: 1 Bytes: 462 Cardinality: 7
1 INDEX RANGE SCAN INDEX CUSTDATA.IDX_POS_DATA_CRT_DT Cost: 1 Cardinality: 96
[mod-edit: code tags added by bb]
[Updated on: Tue, 17 October 2017 21:44] by Moderator Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Re: using sysdate from dual takes longer time [message #666179 is a reply to message #666169] |
Wed, 18 October 2017 09:42 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) |
![](//www.gravatar.com/avatar/37e14c3d1a0963d82d34d478217718c5?s=64&d=mm&r=g) |
manikandan23
Messages: 34 Registered: February 2017
|
Member |
|
|
Thank you All. We decided to use the Index Hint to force the optimizer to use the index associated with the create_date column which resolved the performance issue.
It looks like the long running version of the query used the other index that was created on SRC column which was costlier compared to the create_date index.
Thank you Again!
|
|
|