I have query with sort and rownum to get top N record in big table (with more than 21M records). I use order and rownum for select n recent records like below. I defined index on nullable create_date column but the execution time was more than 30s. How can I improve this time?
select * from(
select *
from my_table t
order by t.create_date
)
where rownum<N
Explain Plan:
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost | Time |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 9 | 31446 | 1153573 | 03:50:43 |
| * 1 | COUNT STOPKEY | | | | | |
| 2 | VIEW | | 21335585 | 74546533990 | 1153573 | 03:50:43 |
| * 3 | SORT ORDER BY STOPKEY | | 21335585 | 4544479605 | 1153573 | 03:50:43 |
| 4 | TABLE ACCESS FULL | MY_TABLE | 21335585 | 4544479605 | 165097 | 00:33:02 |
----------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
------------------------------------------
* 1 - filter(ROWNUM<10)
* 3 - filter(ROWNUM<10)
EXPLAIN PLAN FOR your-querythenSELECT * FROM table(DBMS_XPLAN.Display), and copy a result of last query (as a plain text - don't take a printscreen) and append it to the question. - krokodilkoselect * from v$version. - mathguy