document performance implications of id batching i.e. BatchSize

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-10-26 10:30:51 +02:00
parent 10c83d8370
commit 9828ad7b33
3 changed files with 33 additions and 1 deletions

View File

@ -23,6 +23,17 @@ import java.util.List;
* If an explicit batch size is set manually, care should be taken * If an explicit batch size is set manually, care should be taken
* to not exceed the capabilities of the underlying database. * to not exceed the capabilities of the underlying database.
* <p> * <p>
* The performance impact of setting a batch size depends on whether
* a SQL array may be used to pass the list of identifiers to the
* database:
* <ul>
* <li>for databases which support standard SQL arrays, a smaller
* batch size might be extremely inefficient compared to a very
* large batch size or no batching at all, but
* <li>on the other hand, for databases with no SQL array type, a
* large batch size results in long SQL statements with many JDBC
* parameters.
* <p>
* A batch size is considered a hint. This option has no effect * A batch size is considered a hint. This option has no effect
* on {@link Session#find(Class, Object, FindOption...)}. * on {@link Session#find(Class, Object, FindOption...)}.
* *

View File

@ -133,6 +133,18 @@ public interface MultiIdentifierLoadAccess<T> {
* If an explicit batch size is set manually, care should be taken * If an explicit batch size is set manually, care should be taken
* to not exceed the capabilities of the underlying database. * to not exceed the capabilities of the underlying database.
* <p> * <p>
* The performance impact of setting a batch size depends on whether
* a SQL array may be used to pass the list of identifiers to the
* database:
* <ul>
* <li>for databases which support standard SQL arrays, a smaller
* batch size might be extremely inefficient compared to a very
* large batch size or no batching at all, but
* <li>on the other hand, for databases with no SQL array type, a
* large batch size results in long SQL statements with many JDBC
* parameters.
* </ul>
* <p>
* A batch size is considered a hint. * A batch size is considered a hint.
* *
* @param batchSize The batch size * @param batchSize The batch size

View File

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