spring-data-commons icon indicating copy to clipboard operation
spring-data-commons copied to clipboard

Add support for keyset-based pagination [DATACMNS-1729]

Open spring-projects-issues opened this issue 4 years ago • 10 comments

Jens Schauder opened DATACMNS-1729 and commented

Value based pagination basically uses queries of the form: select n rows after the one with id value :id

On relational databases these kind of queries show better performance than the typical: select n rows after the first m especially when m is large.

It is likely that other stores benefit as well


No further details from DATACMNS-1729

spring-projects-issues avatar May 18 '20 11:05 spring-projects-issues

Junho, Kim commented

Is there any update?

spring-projects-issues avatar Dec 03 '20 07:12 spring-projects-issues

wow, I found this 6 years old article asking for this kind of feature and stating that it is not very well known in the field, guess it is true

https://use-the-index-luke.com/no-offset

terence-sk avatar Jan 05 '21 09:01 terence-sk

@terence-sk same here... this link was referenced today in a hackernews thread :)

It would be amazing to have this in spring-data.

About a year ago in our company project, we imported a lot of data into our database, and then all paginated queries were suffering. Going through pages was extremely slow, and after some page, requests were timing-out at 30sec.

We had to move paginated queries to elasticsearch in order to avoid offset paging that is used in spring-data (we duplicate most of our sql data in elasticsearch anyway for full-text-search support). It's a bit ugly code and architecture, but it runs in constant time (~150ms) regardless of which page you're on or the sorting criteria.

Kidlike avatar Jan 27 '21 08:01 Kidlike

Any thoughts on when keyset-based pagination will become available?

yinchenlan avatar Sep 05 '21 15:09 yinchenlan

@mp911de I know that you are pretty busy with other stuff, but any plans to implement that soon and integrated in spring-data-jdbc?

petromir avatar Jan 26 '22 19:01 petromir

I have no idea. We're currently busy with other topics that are required for Spring Data 3.0. If someone is interested in picking up this theme and crafting a pull request along with an implementation for JPA, Mongo, or Spring Data JDBC, we'd be happy to provide additional guidance.

mp911de avatar Jan 27 '22 07:01 mp911de

@mp911de I would like to help with this, but:

  1. The implementation could take more than a month
  2. I could handle only spring-data-commons and spring-data-jdbc

Is this ok for you?

petromir avatar Jan 28 '22 06:01 petromir

Any kind of progress is appreciated. You might want to explore existing keyset pagination implementations to collect some ideas.

mp911de avatar Jan 28 '22 08:01 mp911de

@mp911de Could you please point me to specific code. Any other guidance will be highly appreciated.

petromir avatar Jan 28 '22 19:01 petromir

Hi! I'd also be interested in collaborating, but have no real clue how to! Any kind of support would be really helpful!

germanflighel avatar Aug 03 '22 19:08 germanflighel

Keyset pagination is not pagination in the sense of page number and page size but rather an approach to resume cursor consumption where we've left off the last time.

Taking a step back, keyset cursoring introduces the concept of consumption windows of data. We should make this concept explicit instead of squeezing cursoring into pagination. Another aspect of this is that we can provide means for index/offset-based cursoring and we can retrofit Pageable to become usable with the new Cursor API as page number, page size and a stable sort are ideal to compute a cursor offset.

mp911de avatar Feb 27 '23 11:02 mp911de

closed by: #2787

christophstrobl avatar Mar 16 '23 12:03 christophstrobl