Query became very slow [message #660100] |
Wed, 08 February 2017 23:04 |
lotusdeva
Messages: 201 Registered: March 2005
|
Senior Member |
|
|
Hello, we are on Oracle 11.2.0.3 and since today one of our queries started running very slow (went from 71 ms to 3 minutes), which is causing a report to basically crash. Our client added more data to this table and I think the query (I am just pasting the part that is very slow here) would have to be changed.
SELECT distinct a.usr_key, a.actiondate
FROM aging_tracking a
WHERE a.actiondate =
(SELECT MAX(actiondate)
FROM aging_tracking b
WHERE b.usr_key = a.usr_key
AND b.status = 'P'
)
AND a.actiondate BETWEEN sysdate AND sysdate +30
- Ran Explain Plan, which showed that actiondate has an index on it and it is being used. Without this last line of code (BETWEEN dates) the query runs super fast. Is there anything I can do to improve it?
thank you in advance for any input!
|
|
|
|
|
Re: Query became very slow [message #660137 is a reply to message #660105] |
Thu, 09 February 2017 10:56 |
lotusdeva
Messages: 201 Registered: March 2005
|
Senior Member |
|
|
Yes, it is possible for the USR_KEY to have multiple action dates. I re-wrote this part of query as follows:
SELECT usr_key, actiondate
FROM
(SELECT usr_key, actiondate, row_number() OVER(partition by usr_key ORDER BY usr_key DESC) a
FROM aging_tracking
WHERE actiondate BETWEEN sysdate AND (sysdate+30)
AND status = 'P') b
WHERE A=1
I am getting 154 records more though, so not sure at this point what is going on.
thank you!
|
|
|
Re: Query became very slow [message #660138 is a reply to message #660137] |
Thu, 09 February 2017 10:59 |
John Watson
Messages: 8964 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
I didn't ask if a usr_key can have multiple action_dates, but if a usr_key can have the same action_date more than once. ie, is usr_key||action_date unique?
|
|
|
|
|
|
|