docs/guides/choose-right.md
Pagination just means retrieving a (potentially big) collection of items in small sequential chunks (pages).
Pagy offers four different pagination techniques, each implementing different types of paginators. Choose the right one to ensure the best performance and workflow.
:icon-move-to-end: OFFSET {#offset}
The most common pagination technique is counting the collection items (COUNT DB query), using the count to calculate where the specific pages start (i.e., OFFSET) and retrieving only the LIMIT items for that page (OFFSET+LIMIT DB query).
It is straightforward to understand and set up and very versatile for the UI, but it also has a few shortcomings.
==- Shortcomings
!!!tip For better DB performance with OFFSET...
==- Paginators [!badge variant="contrast" size="xs" corners="pill" text="3"] {#offset-paginators}
{.list-icon}
{.list-icon}
:offset, but far better performance than :offset (memoizes the total count):offset, the count may become stale (likely a negligible side effect){.list-icon}
:offset, the count is always nil, UI support with a few limitations===
:icon-key: KEYSET {#keyset}
The KEYSET pagination technique allows the fastest and lighter DB performance. It does not count the (ordered) collection (which makes it faster), nor calculates any numeric page pointers in advance (which avoids the data-shift during browsing). It just uses the values in the last record of the page to retrieve the next page.
==- Shortcomings
!!!tip For UI support with KEYSET pagination... Use the :keynav_js paginator. !!!
==- Paginators [!badge variant="contrast" size="xs" corners="pill" text="2"] {#keyset-paginators}
{.list-icon}
{.list-icon}
:keyset+:countless, numeric pages:countless, requires JavaScript Support (or it falls back to the :countless paginator)===
:icon-calendar: TIME-RANGE {#time-range}
This hybrid technique filters by a specific time period (Year, Month, Day, etc.) and applies the offset paginator within that period.
==- Paginator [!badge variant="contrast" size="xs" corners="pill" text="1"]
{.list-icon}
===
:icon-search: SEARCH {#search}
Pagy supports ElasticsearchRails, Meilisearch, Searchkick, and TypesenseRails.
The search paginators get the count, limit and results provided by the search platform. Pagy acts as an interface to these underlying gems, using the OFFSET technique, without its shortcomings.
==- Paginators [!badge variant="contrast" size="xs" corners="pill" text="4"]
{.list-icon}
===