Re: BUG #14411: Issue with using OFFSET

From: Kevin Grittner <kgrittn(at)gmail(dot)com>
To: Jamie Koceniak <jkoceniak(at)mediamath(dot)com>
Cc: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14411: Issue with using OFFSET
Date: 2016-11-04 00:15:04
Message-ID: CACjxUsOzMErEmr2UjKyBG7-gb0fbqCKxVyYvcG=BP2GfS53hWg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Thu, Nov 3, 2016 at 7:05 PM, Jamie Koceniak <jkoceniak(at)mediamath(dot)com> wrote:
> On 11/3/16, 3:52 PM, "Kevin Grittner" <kgrittn(at)gmail(dot)com> wrote:

>> Personally, I never use OFFSET and LIMIT for pagination; there
>> are better ways for most situations.

> I would be interested in hearing about alternate solutions to
> using OFFSET.
> We have explored using btree index approach (ordering by id
> desc), storing last id and then grabbing next set of rows < last
> id. That works great for fetching next group of rows.

That works. If you also save the starting key value, you can use
it to page backward by reversing your ORDER BY.

> However, how would you implement jumping ahead to a specific
> range?

Range (as in database values) or page (as in count of matching rows)?

> I.e. Picture a web site with pages 1 2 3 4 5 … 10 11 and the user
> jumping to page 11.

You can't know what's on page 11 without reading pages 1 to 10.
You can either track that as you move forward, or just return all
the rows on the initial query and write everything to working
storage somewhere, navigating through this result when the user
chooses a new page. Normally when using this technique you set
some overall limit of rows for the query.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Haribabu Kommi 2016-11-04 01:44:45 Re: [BUGS] BUG #14350: VIEW with INSTEAD OF INSERT TRIGGER and COPY. Missing feature or working as designed.
Previous Message Jamie Koceniak 2016-11-04 00:05:42 Re: BUG #14411: Issue with using OFFSET