Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
eh?
select * from foo where rownum < 11;
-- at least from 11g. IDK about older ones -
It used to be a lot worse
Select *
From (
Select *
From actual_table
Order by id
)
Where ROWNUM <= 10 -
In the first versions when the fetch first was introduced I've read a blog post that the rownum version had better performance.
-
@coffeeholic
The optimizer didn't really work well for small sets with FETCH FIRST. If you didn't supply a limit, it would run the full table before finding a single id. I can't say if it's better now, but as long as you supply cardinality and row only, it won't be too bad. -
@SortOfTested reminds me of postgresql :D (apparently this subquery-based-approach performs significantly better than a limitation w/o a subquery)
-
@netikras
As long as it's off an indexed field, yes. Otherwise it will likely construct an index as part of the operation.
Related Rants
When you want only 10 rows of query result.
Mysql: Select top 10 * from foo.... 😁
Sql server: select top 10 * from foo.. 😁
PostgreSQL: select * from foo limit 10.. 😁
Oracle: select * from foo FETCH NEXT/FIRST 10 ROWS ONLY. 🌚
Oracle, are you trying to be more expressive/verbose because if that's the case then your understanding of verbosity is fucked up just like your understanding of clean-coding, user experience, open source, productivity...
Etc.
rant
oracle