I have two applications : the first one inserts data in the table MyTable. The second one reads the rows of the table MyTable in chunks : let’s say 1000 rows per read. This second app must read the data in chronological order, and use a query similar to :
SELECT
C1,
C2
FROM
(
SELECT
rownum AS RowNumber,
C1,
C2
FROM
MyTable
WHERE
C3 = :C3
AND IsProcessed = 0
ORDER BY
Timestamp
) temp
WHERE
temp.RowNumber <= 1000
The query works, but it is slow (more than one minute, usually it takes only a few seconds to execute) when a lot of not processed rows (for example 10 millions) are waiting in the table MyTable. I suppose this is normal, because Oracle must first sort all the concerned rows in the chronological order…
So my question is : is there a better way to write this query ?

From your execution plan, I’m guessing that your predicate
C3 = :C3is quite costly. You should try to optimise that by avoidingRAWtypes. There are several options:SUBCONTRACTIDNVL(BUSINESSTRANSACTIONID, HEXTORAW('00'))BUSINESSTRANSACTIONIDand query that usingIS NULL, rather thanNVL(...)ORDER BY timestampclause and process records in arbitrary order.Apart from that, your query seems fine.
Also, try applying a
/*+FIRST_ROWS(1000)*/hint, as it seems that this isn’t done automatically for some reason in your query, even withROWNUMfiltering