This figure illustrates how query rewrites works:
First, you enter a query.
Then, Oracle generates the plan for your query.
Then, Oracle rewrites the statement.
Then, Oracle compares the cost of the two statements.
Oracle chooses the best result.