Hi all,
I have a question regarding an interesting ASA performance problem I have discovered at a customer (ASA 11.0.1.2558). This is the query customer has:
SELECT R.Direction_IO,
C.Arrival_time,
C.Meaning,
R.Text
FROM Calls_history C,
Reasons R
WHERE C.Reason_ref=R.Reason_def And
C.Call_entity_type=2 And
C.Call_entity_ref=91075 And
C.Arrival_time>='2012-11-07 00:00:00'
C.Arrival_time<='2012-11-20 00:00:00'
ORDER BY C.Arrival_time DESC
As you can see the where clause has a date condition between Nov 11th and “today” (20th Nov). The query is taking many seconds.
Exactly the same result set can be obtained removing "today" (20th Nov) clause (the date range is exactly the same):
SELECT R.Direction_IO,
C.Arrival_time,
C.Meaning,
R.Text
FROM Calls_history C,
Reasons R
WHERE C.Reason_ref=R.Reason_def And
C.Call_entity_type=2 And
C.Call_entity_ref=91075 And
C.Arrival_time>='2012-11-07 00:00:00'
ORDER BY C.Arrival_time DESC
And in this case the query takes less than 1 second.
I am attaching table definitions, query plan for query 1 and also for query 2 (in text format becuase I cannot upload saplan files here). What I understand is happening is:
- In plan 1 index CHIST_ARRIVALTIME (index in date column) is being when accessing to table C, as they are ordering by that datetime field the sort is avoided.
- In plan 2 index CHIST_ENTTYPE_ENTREF is being used when accessing table C I suppose becase it is more selective, in this case it has to order later but it takes much less than plan 1.
My question is, is this a optimizer problem in ASA ? or this is an expected behavior ?, any way to avoid this situation ?, customer has serveral queries like this and most of the times he has the end date the problem happens (sql code cannot be changed).
If anyone can help and give me any ideas I will appreciate, if you need saplan files I can send them by email
Thanks in advance and regards.
Javier.