Skip to content

possible mitigation for Oracle fetch size issue #9632

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
@@ -8,6 +8,7 @@
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@@ -49,7 +50,7 @@ public class ExtractedDatabaseMetaDataImpl implements ExtractedDatabaseMetaData
private final String url;
private final String driver;
private final boolean jdbcMetadataAccessible;

private final int defaultFetchSize;

//Lazily initialized: loading all sequence information upfront has been
//shown to be too slow in some cases. In this way we only load it
@@ -71,6 +72,7 @@ private ExtractedDatabaseMetaDataImpl(
SQLStateType sqlStateType,
int transactionIsolation,
int defaultTransactionIsolation,
int defaultFetchSize,
String url,
String driver,
boolean jdbcMetadataIsAccessible) {
@@ -88,6 +90,7 @@ private ExtractedDatabaseMetaDataImpl(
this.sqlStateType = sqlStateType;
this.transactionIsolation = transactionIsolation;
this.defaultTransactionIsolation = defaultTransactionIsolation;
this.defaultFetchSize = defaultFetchSize;
this.url = url;
this.driver = driver;
this.jdbcMetadataAccessible = jdbcMetadataIsAccessible;
@@ -168,6 +171,11 @@ public int getDefaultTransactionIsolation() {
return defaultTransactionIsolation;
}

@Override
public int getDefaultFetchSize() {
return defaultFetchSize;
}

@Override
public synchronized List<SequenceInformation> getSequenceInformationList() {
if ( jdbcMetadataAccessible ) {
@@ -211,6 +219,7 @@ public static class Builder {
private String driver;
private int defaultTransactionIsolation;
private int transactionIsolation;
private int defaultFetchSize;

public Builder(JdbcEnvironment jdbcEnvironment, boolean jdbcMetadataIsAccessible, JdbcConnectionAccess connectionAccess) {
this.jdbcEnvironment = jdbcEnvironment;
@@ -233,6 +242,12 @@ public Builder apply(DatabaseMetaData databaseMetaData) throws SQLException {
driver = databaseMetaData.getDriverName();
defaultTransactionIsolation = databaseMetaData.getDefaultTransactionIsolation();
transactionIsolation = databaseMetaData.getConnection().getTransactionIsolation();
try ( Statement statement = databaseMetaData.getConnection().createStatement() ) {
defaultFetchSize = statement.getFetchSize();
}
catch (SQLException sqle) {
defaultFetchSize = -1;
}
return this;
}

@@ -302,6 +317,7 @@ public ExtractedDatabaseMetaDataImpl build() {
sqlStateType,
transactionIsolation,
defaultTransactionIsolation,
defaultFetchSize,
url,
driver,
jdbcMetadataIsAccessible
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
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;
@@ -103,6 +104,8 @@ public JdbcEnvironmentImpl(final ServiceRegistryImplementor serviceRegistry, fin
this.qualifiedObjectNameFormatter = new QualifiedObjectNameFormatterStandardImpl( nameQualifierSupport );

this.lobCreatorBuilder = makeLobCreatorBuilder( dialect );

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

private IdentifierHelperBuilder identifierHelperBuilder(
@@ -312,6 +315,8 @@ public JdbcEnvironmentImpl(
cfgService.getSettings(),
databaseMetaData.getConnection()
);

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

private static IdentifierHelper identifierHelper(
@@ -420,4 +425,14 @@ 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 < 200 ) {
log.warn( "Low default JDBC fetch size: " + defaultFetchSize + " (set hibernate.jdbc.fetch_size)" );
}
else {
log.debug( "Using default JDBC fetch size: " + defaultFetchSize );
}
}
}
}
Original file line number Diff line number Diff line change
@@ -150,6 +150,11 @@ public interface ExtractedDatabaseMetaData {
*/
int getDefaultTransactionIsolation();

/**
* Retrieve the default JDBC {@link java.sql.Statement#getFetchSize fetch size}.
*/
int getDefaultFetchSize();

/**
* Retrieve the list of {@code SequenceInformation} objects which describe the underlying database sequences.
*