<p>It's one of those things that seems to have an odd curve where the more I think about it, the more it makes sense.  To a certain extent, of course.  And then it doesn't make sense to me at all.</p>

<p>Care to enlighten me?</p>

[{'answer_id': 29588, 'author': 'lubos hasko', 'author_id': 275, 'author_profile': 'https://Stackoverflow.com/users/275', 'pm_score': 5, 'selected': True, 'text': '<p>Because in most cases you\'ve got to sort your results first. For example, when you search on Google, <a href="http://www.google.com.au/search?hl=en&amp;safe=off&amp;q=google&amp;start=1000&amp;sa=N" rel="noreferrer">you can view only up to 100 pages of results</a>. They don\'t bother sorting by page-rank beyond 1000 websites for given keyword (or combination of keywords).</p>\n\n<p><strong>Pagination is fast. Sorting is slow.</strong></p>\n'}, {'answer_id': 29589, 'author': 'Ryan Doherty', 'author_id': 956, 'author_profile': 'https://Stackoverflow.com/users/956', 'pm_score': 2, 'selected': False, 'text': "<p>This is a really vague question. We'd need a concrete example to get a better idea of the problem.</p>\n"}, {'answer_id': 29601, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 2, 'selected': False, 'text': '<p><a href="https://stackoverflow.com/questions/29580/why-is-pagination-so-resource-expensive#29588">Lubos</a> is right, the problem is not the fact that you are paging (which takes a HUGE amount of data off the wire), but that you need to figure out what is actually going on the page..</p>\n\n<p>The fact that you need to page implies there is a lot of data. A lot of data takes a long time to sort :)</p>\n'}, {'answer_id': 29627, 'author': 'Josh', 'author_id': 3166, 'author_profile': 'https://Stackoverflow.com/users/3166', 'pm_score': 1, 'selected': False, 'text': '<p>I thought you meant <a href="http://en.wikipedia.org/wiki/Pagination" rel="nofollow noreferrer">pagination of the printed page</a> - that\'s where I cut my teeth.  I was going to enter a great monologue about collecting all the content for the page, positioning (a vast number of rules here, constrait engines are quite helpful) and justification... but apparently you were talking about the process of organizing information on webpages.  </p>\n\n<p>For that, I\'d guess database hits.  Disk access is slow.  Once you\'ve got it in memory, sorting is cheap.</p>\n'}, {'answer_id': 289682, 'author': 'Stein G. Strindhaug', 'author_id': 26115, 'author_profile': 'https://Stackoverflow.com/users/26115', 'pm_score': 0, 'selected': False, 'text': "<p>Of course sorting on a random query takes some time, but if you're having problems with the same paginated query being used regulary, there's either something wrong with the database setup (improperly indexing/none at all, too little memory etc. I'm not a db-manager) or you're doing pagination seriously wrong: </p>\n\n<p>Terribly wrong: e.g. doing <code>select * from hugetable where somecondition;</code> into an array getting the page count with the array.length pick the relevant indexes and dicard the array - then repeating this for each page... That's what I call seriously wrong. </p>\n\n<p>The better solution two queries: one getting just the count then another getting results using <code>limit</code> and <code>offset</code>. (Some proprietary, nonstandard-sql server might have a one query option, I dunno)</p>\n\n<p>The bad solution might actually work quite okay in on small tables (in fact it's not unthinkable that it's faster on very small tables, because the overhead of making two queries is bigger than getting all rows in one query. I'm not saying it <em>is</em> so...) but as soon as the database begins to grow the problems become obvious.</p>\n"}, {'answer_id': 374980, 'author': 'JoeBloggs', 'author_id': 34097, 'author_profile': 'https://Stackoverflow.com/users/34097', 'pm_score': 2, 'selected': False, 'text': "<p>This question seems pretty well covered, but I'll add a little something MySQL specific as it catches out a lot of people:</p>\n\n<p>Avoid using <code>SQL_CALC_FOUND_ROWS</code>. Unless the dataset is trivial, counting matches and retrieving x amount of matches in two separate queries is going to be a lot quicker. (If it <em>is</em> trivial, you'll barely notice a difference either way.)</p>\n"}]
['https://Stackoverflow.com/questions/29580', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2293/']