views:

406

answers:

2

This is pretty trivial, but I noticed on SO that instead of an offset they are using page numbers. I know the difference is minor (multiply the page number by rows on a page or divide offset by rows on a page), but I'm wondering if one is recommended over the other.

Some sites, like Google, of course use a more complicated system because they need to track your actual search. But I'm thinking for a simple site where this doesn't matter.

What is the recommended technique?

+2  A: 

Use offsets. If you choose to allow variable (or user-defined) number of results per page, the coding is easy.

Stefan Mai
+2  A: 

Offsets are also useful for optimization when the result set you are paginating is very large.

This is because in some cases it allows you to do a

WHERE my_sortorder >= (some offset)
LIMIT 10

rather than a

LIMIT 10 OFFSET 880

which is less efficient. An index can let you go straight to all rows matching my_sortoder >= some offset, but when you use OFFSET with LIMIT, it needs to find and scan through all 880 preceding rows first.

thomasrutter