pagination: Spring Data JPA Page vs Slice vs keyset Window scrolling, with the SQL and REST shapes
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b4bLvQVbZweAqqf54x
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
# offset paging, third page of 10: PageRequest.of(2, 10, Sort.by("id"))
|
||||
select p1_0.id,p1_0.category,p1_0.name,p1_0.price from product p1_0 where p1_0.category=? order by p1_0.id offset ? rows fetch first ? rows only
|
||||
|
||||
# keyset scrolling, first window: ScrollPosition.keyset()
|
||||
select p1_0.id,p1_0.category,p1_0.name,p1_0.price from product p1_0 where p1_0.category=? order by p1_0.id fetch first ? rows only
|
||||
rows: 10, hasNext: true, position of the last row: KeysetScrollPosition [FORWARD, {id=10}]
|
||||
|
||||
# keyset scrolling, second window: the position from the first window
|
||||
select p1_0.id,p1_0.category,p1_0.name,p1_0.price from product p1_0 where (p1_0.category=?) and (p1_0.id>?) order by p1_0.id fetch first ? rows only
|
||||
rows: 10 (book-11 .. book-20), hasNext: true
|
||||
|
||||
# third window: 5 rows (book-21 .. book-25), hasNext: false
|
||||
|
||||
# WindowIterator over all 25 books, windows of 10
|
||||
rows visited: 25, statements: 3
|
||||
|
||||
# Query by Example: findBy(example, q -> q.sortBy(Sort.by("id")).limit(5).scroll(ScrollPosition.keyset()))
|
||||
select p1_0.id,p1_0.category,p1_0.name,p1_0.price from product p1_0 where p1_0.category=? order by p1_0.id fetch first ? rows only
|
||||
rows: 5, hasNext: true
|
||||
|
||||
# offset scrolling: ScrollPosition.offset(0) is a position, so the result starts AFTER it
|
||||
select p1_0.id,p1_0.category,p1_0.name,p1_0.price from product p1_0 where p1_0.category=? order by p1_0.id offset ? rows fetch first ? rows only
|
||||
first row returned: book-2
|
||||
Reference in New Issue
Block a user