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,25 @@
|
||||
Hibernate ORM: 7.3.13.Final
|
||||
# 25 books, 6 of them with 2 reviews each (12 joined rows). Page of 2 products, join fetch p.reviews.
|
||||
|
||||
## method 8: @Query("select p from Product p join fetch p.reviews where ...")
|
||||
select p1_0.id,p1_0.category,p1_0.name,p1_0.price,r1_0.product_id,r1_0.id,r1_0.rating from product p1_0 join review r1_0 on p1_0.id=r1_0.product_id where p1_0.category=? order by p1_0.id
|
||||
select count(*) from product p1_0 join review r1_0 on p1_0.id=r1_0.product_id where p1_0.category=?
|
||||
products on the page: [book-1, book-2], reviews loaded on them: 4
|
||||
entities held by the persistence context: 18
|
||||
HHH90003004 (applying in memory) logged: true
|
||||
totalElements reported: 12 (products that actually have reviews: 6)
|
||||
|
||||
## method 8b: the same query with countQuery = "select count(distinct p) ..."
|
||||
select count(distinct p1_0.id) from product p1_0 join review r1_0 on p1_0.id=r1_0.product_id where p1_0.category=?
|
||||
totalElements reported: 6, totalPages: 3
|
||||
|
||||
## method 8c: @EntityGraph(attributePaths = "reviews") on a derived query, page of 4
|
||||
select p1_0.id,p1_0.category,p1_0.name,p1_0.price,r1_0.product_id,r1_0.id,r1_0.rating from product p1_0 left join review r1_0 on p1_0.id=r1_0.product_id where p1_0.category=? order by p1_0.id
|
||||
select count(*) from product p1_0 where p1_0.category=?
|
||||
rows: 4, totalElements: 25, entities held by the persistence context: 37
|
||||
|
||||
## methods 9a + 9b: page the ids, then fetch the reviews for exactly those ids
|
||||
select p1_0.id from product p1_0 where p1_0.category=? order by p1_0.id fetch first ? rows only
|
||||
select count(*) from product p1_0 where p1_0.category=?
|
||||
select distinct p1_0.id,p1_0.category,p1_0.name,p1_0.price,r1_0.product_id,r1_0.id,r1_0.rating from product p1_0 join review r1_0 on p1_0.id=r1_0.product_id where p1_0.id in (?,?) order by p1_0.id
|
||||
ids on the page: [1, 2], products fetched: 2, reviews fetched: 4
|
||||
Reference in New Issue
Block a user