databasepaginationrdbms-agnostic

What performance gains can I expect from database paging?


Say I have a table X with 100 records in it and that running a select * from X takes 100 seconds.

How long should I expect the query select top 10 * from X to take?

I'd expect that the relationship is more or less linear so 10 seconds. Is this correct, or is the relationship non-linear in some way?


Solution

  • Your performance cost is in two different areas:

    Often, a query will be fast, but returning results will be slow, since it's I/O-bound. If this is the case, then you will see an approximately linear speedup by returning fewer results.

    However, if the query itself is complicated, things are different. If it's not just select * from X, but select * from X where [complicated-expression], then results may vary widely between database implementations. In that case, your performance might be dominated by query complexity, in which case you won't see as much benefit by merely returning fewer results.