Skip to content

Commit 9828ad7

Browse files
committed
document performance implications of id batching i.e. BatchSize
Signed-off-by: Gavin King <[email protected]>
1 parent 10c83d8 commit 9828ad7

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

hibernate-core/src/main/java/org/hibernate/BatchSize.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@
2323
* If an explicit batch size is set manually, care should be taken
2424
* to not exceed the capabilities of the underlying database.
2525
* <p>
26+
* The performance impact of setting a batch size depends on whether
27+
* a SQL array may be used to pass the list of identifiers to the
28+
* database:
29+
* <ul>
30+
* <li>for databases which support standard SQL arrays, a smaller
31+
* batch size might be extremely inefficient compared to a very
32+
* large batch size or no batching at all, but
33+
* <li>on the other hand, for databases with no SQL array type, a
34+
* large batch size results in long SQL statements with many JDBC
35+
* parameters.
36+
* <p>
2637
* A batch size is considered a hint. This option has no effect
2738
* on {@link Session#find(Class, Object, FindOption...)}.
2839
*

hibernate-core/src/main/java/org/hibernate/MultiIdentifierLoadAccess.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ default MultiIdentifierLoadAccess<T> with(RootGraph<T> graph) {
133133
* If an explicit batch size is set manually, care should be taken
134134
* to not exceed the capabilities of the underlying database.
135135
* <p>
136+
* The performance impact of setting a batch size depends on whether
137+
* a SQL array may be used to pass the list of identifiers to the
138+
* database:
139+
* <ul>
140+
* <li>for databases which support standard SQL arrays, a smaller
141+
* batch size might be extremely inefficient compared to a very
142+
* large batch size or no batching at all, but
143+
* <li>on the other hand, for databases with no SQL array type, a
144+
* large batch size results in long SQL statements with many JDBC
145+
* parameters.
146+
* </ul>
147+
* <p>
136148
* A batch size is considered a hint.
137149
*
138150
* @param batchSize The batch size

hibernate-core/src/main/java/org/hibernate/Session.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,16 @@ public interface Session extends SharedSessionContract, EntityManager {
562562
* given entity class, or a fully-fetched proxy object.
563563
* <p>
564564
* This method accepts {@link BatchSize} as an option, allowing control over the number of
565-
* records retrieved in a single database request.
565+
* records retrieved in a single database request. The performance impact of setting a batch
566+
* size depends on whether a SQL array may be used to pass the list of identifiers to the
567+
* database:
568+
* <ul>
569+
* <li>for databases which {@linkplain org.hibernate.dialect.Dialect#supportsStandardArrays
570+
* support standard SQL arrays}, a smaller batch size might be extremely inefficient
571+
* compared to a very large batch size or no batching at all, but
572+
* <li>on the other hand, for databases with no SQL array type, a large batch size results
573+
* in long SQL statements with many JDBC parameters.
574+
* </ul>
566575
* <p>
567576
* For more advanced cases, use {@link #byMultipleIds(Class)}, which returns an instance of
568577
* {@link MultiIdentifierLoadAccess}.

0 commit comments

Comments
 (0)