Do you have different query plans when you turn on the prompt? My guess is that you are based on your description of the problem.
When you execute a query in Oracle, the database usually does not materialize the entire result set at any given time (obviously, it might be necessary if you specify an ORDER BY that requires all the data to be materialized before the view happens). Oracle does not actually begin to materialize data until the client begins to receive data. It satisfies the requests enough to generate as many rows as the client asked to retrieve (in your case, it looks like 10), returns these results to the client and expects the client to request more data before continuing with the processing of the request.
It appears that when the FIRST_ROWS hint is FIRST_ROWS on, the query plan changes in a way that makes it more expensive. Obviously, this is not the purpose of the FIRST_ROWS hint. The goal is to tell the optimizer to create a plan that makes the selection of the first N rows more efficient, even if it makes the selection of all rows from the query less efficient. This causes the optimizer to prefer things like index scans through table scans, where table scans can be more efficient overall. It seems that in your case, the optimizerโs estimates are incorrect, and in the end he chooses a plan that is usually less effective. This often implies that some statistics for some of the objects referenced by your request are incomplete or incorrect.
source share