Skip to content

HHH-19656 force the default JDBC fetch size to 128 if it is smaller #10636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import static org.hibernate.cfg.QuerySettings.PORTABLE_INTEGER_DIVISION;
import static org.hibernate.cfg.QuerySettings.XML_FUNCTIONS_ENABLED;
import static org.hibernate.engine.config.spi.StandardConverters.BOOLEAN;
import static org.hibernate.engine.jdbc.JdbcLogging.JDBC_MESSAGE_LOGGER;
import static org.hibernate.internal.CoreLogging.messageLogger;
import static org.hibernate.internal.LockOptionsHelper.applyPropertiesToLockOptions;
import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
Expand Down Expand Up @@ -133,6 +134,13 @@
public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
private static final CoreMessageLogger log = messageLogger( SessionFactoryOptionsBuilder.class );

/**
* A lower bound on the {@link java.sql.Statement#getFetchSize JDBC fetch size}.
*
* @see org.hibernate.cfg.JdbcSettings#STATEMENT_FETCH_SIZE
*/
public static final int MIN_FETCH_SIZE = 128;

private final String uuid = LocalObjectUuidHelper.generateLocalObjectUuid();
private final StandardServiceRegistry serviceRegistry;

Expand Down Expand Up @@ -490,6 +498,16 @@ public SessionFactoryOptionsBuilder(StandardServiceRegistry serviceRegistry, Boo
getBoolean( USE_GET_GENERATED_KEYS, settings, meta.supportsGetGeneratedKeys() );

jdbcFetchSize = getInteger( STATEMENT_FETCH_SIZE, settings );
if ( jdbcFetchSize == null ) {
final int defaultFetchSize = meta.getDefaultFetchSize();
if ( defaultFetchSize > 0 && defaultFetchSize < MIN_FETCH_SIZE ) {
JDBC_MESSAGE_LOGGER.forcingFetchSize( defaultFetchSize, MIN_FETCH_SIZE );
jdbcFetchSize = MIN_FETCH_SIZE;
}
else {
JDBC_MESSAGE_LOGGER.usingFetchSize( defaultFetchSize );
}
}

connectionHandlingMode = interpretConnectionHandlingMode( settings, serviceRegistry );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ public interface JdbcLogging extends BasicLogger {
@Message(value = "Using default JDBC fetch size: %s", id = 100122)
void usingFetchSize(int fetchSize);

@LogMessage(level = WARN)
@Message(value = "Low default JDBC fetch size: %s (consider setting 'hibernate.jdbc.fetch_size')", id = 100123)
void warnLowFetchSize(int fetchSize);
@LogMessage(level = INFO)
@Message(value = "Low default JDBC fetch size: %s, forcing to: %s (consider setting 'hibernate.jdbc.fetch_size')", id = 100123)
void forcingFetchSize(int defaultFetchSize, int forcedFetchSize);

@LogMessage(level = TRACE)
@Message(value = "JDBC fetch size: %s", id = 100124)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.JdbcSettings;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.config.spi.StandardConverters;
Expand Down Expand Up @@ -39,7 +38,6 @@
import static org.hibernate.cfg.MappingSettings.DEFAULT_CATALOG;
import static org.hibernate.cfg.MappingSettings.DEFAULT_SCHEMA;
import static org.hibernate.engine.config.spi.StandardConverters.STRING;
import static org.hibernate.engine.jdbc.JdbcLogging.JDBC_MESSAGE_LOGGER;
import static org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl.makeLobCreatorBuilder;

/**
Expand Down Expand Up @@ -107,8 +105,6 @@ public JdbcEnvironmentImpl(final ServiceRegistryImplementor serviceRegistry, fin
new QualifiedObjectNameFormatterStandardImpl( nameQualifierSupport, dialect.getCatalogSeparator() );

lobCreatorBuilder = makeLobCreatorBuilder( dialect );

logJdbcFetchSize( extractedMetaDataSupport.getDefaultFetchSize(), cfgService );
}

private static ConfigurationService configurationService(ServiceRegistryImplementor serviceRegistry) {
Expand Down Expand Up @@ -321,8 +317,6 @@ public JdbcEnvironmentImpl(
new QualifiedObjectNameFormatterStandardImpl( nameQualifierSupport, databaseMetaData );

lobCreatorBuilder = makeLobCreatorBuilder( dialect, cfgService.getSettings(), databaseMetaData.getConnection() );

logJdbcFetchSize( extractedMetaDataSupport.getDefaultFetchSize(), cfgService );
}

private static IdentifierHelper identifierHelper(
Expand Down Expand Up @@ -425,15 +419,4 @@ public SqlExceptionHelper getSqlExceptionHelper() {
public LobCreatorBuilder getLobCreatorBuilder() {
return lobCreatorBuilder;
}

private static void logJdbcFetchSize(int defaultFetchSize, ConfigurationService cfgService) {
if ( !cfgService.getSettings().containsKey( JdbcSettings.STATEMENT_FETCH_SIZE ) ) {
if ( defaultFetchSize > 0 && defaultFetchSize < 100 ) {
JDBC_MESSAGE_LOGGER.warnLowFetchSize( defaultFetchSize );
}
else {
JDBC_MESSAGE_LOGGER.usingFetchSize( defaultFetchSize );
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.checkerframework.checker.nullness.qual.Nullable;

import static org.hibernate.boot.internal.SessionFactoryOptionsBuilder.MIN_FETCH_SIZE;
import static org.hibernate.engine.jdbc.JdbcLogging.JDBC_MESSAGE_LOGGER;

/**
Expand Down Expand Up @@ -234,7 +235,7 @@ private void setStatementFetchSize(PreparedStatement statement) throws SQLExcept
else {
if ( JDBC_MESSAGE_LOGGER.isDebugEnabled() ) {
final int defaultFetchSize = statement.getFetchSize();
if ( defaultFetchSize > 0 && defaultFetchSize < 100 ) {
if ( defaultFetchSize > 0 && defaultFetchSize < MIN_FETCH_SIZE ) {
JDBC_MESSAGE_LOGGER.lowFetchSize( defaultFetchSize );
}
}
Expand Down
Loading