Database `ORDER BY` speeds as more entries are added
<p>I'm not very knowledgeable about databases. I would want to retrieve, say the "newest" 10 rows with owner ID matching something, and then perhaps paginate to retrieve the next "newest" 10 rows with that owner, and so on. But say I'm adding more and more rows into a database table -- at some point, would such a query become unbearably slow, or are databases generally good enough that this won't be a worry?</p>

<p>I imagine it would be an issue because to get the "newest" 10 rows you'd have to order by date, which is <code>O(n log n)</code>. With this assumption, I sought a possible solution from <a href="https://stackoverflow.com/questions/4193705/sql-server-select-last-n-rows">SQL Server SELECT LAST N Rows</a>.
It pointed me to <a href="http://www.sqlservercurry.com/2009/02/retrieve-last-n-rows-based-on-condition.html" rel="nofollow">http://www.sqlservercurry.com/2009/02/retrieve-last-n-rows-based-on-condition.html</a> where I found that there is a <code>PARTITION BY</code> option for a query. I imagine this means first selecting all the rows that match the owner ID, and THEN ordering them, which would be significantly faster, and fast enough to not worry about for most applications. Is this the correct understanding?</p>

<p>Otherwise, is there some better way to get the "newest" N rows (  seems to suggest it is)?</p>

<p>I'm developing the app in Django if anyone knows a convenient way, but otherwise Django also allows raw database queries.</p>