Add n-plus-one-guard module: detecting N+1 with Hibernate Statistics vs datasource-proxy, five fixes with statement counts, and a JUnit 6 @MaxSelects guard (Hibernate 7.4.16.Final, datasource-proxy 1.11.1)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6R1spapM7nBteaqeo
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
eab5461d86
commit
0db721805b
@@ -0,0 +1,36 @@
|
||||
# Five ways to load 10 authors with their books
|
||||
# Hibernate ORM 7.4.16.Final, datasource-proxy 1.11.1, H2, JDK 25
|
||||
|
||||
== naive loop (lazy collection per author)
|
||||
sql> select a1_0.id,a1_0.name from Author a1_0
|
||||
sql> select b1_0.author_id,b1_0.id,b1_0.title from Book b1_0 where b1_0.author_id=?
|
||||
sql> select b1_0.author_id,b1_0.id,b1_0.title from Book b1_0 where b1_0.author_id=?
|
||||
sql> select b1_0.author_id,b1_0.id,b1_0.title from Book b1_0 where b1_0.author_id=?
|
||||
sql> select b1_0.author_id,b1_0.id,b1_0.title from Book b1_0 where b1_0.author_id=?
|
||||
sql> select b1_0.author_id,b1_0.id,b1_0.title from Book b1_0 where b1_0.author_id=?
|
||||
sql> select b1_0.author_id,b1_0.id,b1_0.title from Book b1_0 where b1_0.author_id=?
|
||||
sql> select b1_0.author_id,b1_0.id,b1_0.title from Book b1_0 where b1_0.author_id=?
|
||||
sql> select b1_0.author_id,b1_0.id,b1_0.title from Book b1_0 where b1_0.author_id=?
|
||||
sql> select b1_0.author_id,b1_0.id,b1_0.title from Book b1_0 where b1_0.author_id=?
|
||||
sql> select b1_0.author_id,b1_0.id,b1_0.title from Book b1_0 where b1_0.author_id=?
|
||||
|
||||
== join fetch
|
||||
sql> select a1_0.id,b1_0.author_id,b1_0.id,b1_0.title,a1_0.name from Author a1_0 join Book b1_0 on a1_0.id=b1_0.author_id
|
||||
|
||||
== entity graph (Author.withBooks)
|
||||
sql> select a1_0.id,b1_0.author_id,b1_0.id,b1_0.title,a1_0.name from Author a1_0 left join Book b1_0 on a1_0.id=b1_0.author_id
|
||||
|
||||
== batch fetching, size 5 (session.setFetchBatchSize)
|
||||
sql> select a1_0.id,a1_0.name from Author a1_0
|
||||
sql> select b1_0.author_id,b1_0.id,b1_0.title from Book b1_0 where b1_0.author_id in (?,?,?,?,?)
|
||||
sql> select b1_0.author_id,b1_0.id,b1_0.title from Book b1_0 where b1_0.author_id in (?,?,?,?,?)
|
||||
|
||||
== DTO projection (no entities)
|
||||
sql> select count(b1_0.id) from Book b1_0 group by b1_0.author_id
|
||||
|
||||
== SELECT statements for 10 authors x 3 books, same result every time (30 books)
|
||||
naive loop (lazy collection per author) 11
|
||||
join fetch 1
|
||||
entity graph (Author.withBooks) 1
|
||||
batch fetching, size 5 (session.setFetchBatchSize) 3
|
||||
DTO projection (no entities) 1
|
||||
Reference in New Issue
Block a user