Improving performance of a query using order by clause [message #240901] |
Sun, 27 May 2007 08:25 |
rolex.mp
Messages: 161 Registered: February 2007
|
Senior Member |
|
|
I wanna to get the top ten tasks from a table based on the execution time of a task
the table
ad_tasks contains columns task_id , exec_time ,tg_id etc
the table ard 7 lakh rows
the query is like this
select task_id from ( select * from ad_tasks where tg_id=1 order by exec_time desc nulls last ) where rownum < 11;
can i tune this query to make its performance better ?
|
|
|
|
|
|
Re: Improving performance of a query using order by clause [message #241005 is a reply to message #240912] |
Mon, 28 May 2007 03:28 |
rleishman
Messages: 3728 Registered: October 2005 Location: Melbourne, Australia
|
Senior Member |
|
|
Disagree: Yes, well... maybe.
If you index (tg_id,exec_time), then Oracle can use it to honour the ORDER BY.
select task_id
from (
select *
from ad_tasks
where tg_id=1
order by exec_time desc
) where rownum < 11
Try with and without the NULLS LAST - I'm not sure you can use it with this technique. I'm not sure whether this will work with the DESC order either, but you can try.
Ross Leishman
|
|
|
|