Skip to content

Conversation

@brfrn169
Copy link
Collaborator

@brfrn169 brfrn169 commented Jun 20, 2025

Description

When benchmarking the new release, I observed some performance degradation with the JDBC adapter for MySQL. After investigating the issue, I found the following:

  • Using Connection.setReadOnly(true) causes performance degradation.
  • Enabling cursor fetch mode in MySQL also results in performance degradation.

To address these issues, this PR introduces optimizations to the JDBC adapter for MySQL.

Related issues and/or PRs

N/A

Changes made

Added some inline comments. Please take a look for the details.

Checklist

The following is a best-effort checklist. If any items in this checklist are not applicable to this PR or are dependent on other, unmerged PRs, please still mark the checkboxes after you have read and understood each item.

  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation to reflect the changes.
  • I have considered whether similar issues could occur in other products, components, or modules if this PR is for bug fixes.
  • Any remaining open issues linked to this PR are documented and up-to-date (Jira, GitHub, etc.).
  • Tests (unit, integration, etc.) have been added for the changes.
  • My changes generate no new warnings.
  • Any dependent changes in other PRs have been merged and published.

Additional notes (optional)

N/A

Release notes

N/A

@brfrn169 brfrn169 requested a review from Copilot June 20, 2025 01:53
@brfrn169 brfrn169 self-assigned this Jun 20, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR aims to optimize the JDBC adapter for MySQL by refining connection property management and disabling performance-degrading configurations such as setting MySQL connections to read-only mode. Key changes include:

  • Refactoring the getConnectionProperties API to accept a configuration parameter in multiple RdbEngine implementations.
  • Disabling setting the read-only flag on MySQL connections to address performance degradation.
  • Adjusting test cases to reflect changes in error handling and connection property configurations.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
core/src/test/java/com/scalar/db/transaction/jdbc/JdbcTransactionManagerTest.java Changed RdbEngine strategy from MYSQL to POSTGRESQL and updated SQL error handling.
core/src/test/java/com/scalar/db/storage/jdbc/JdbcUtilsTest.java Updated getConnectionProperties method signature usage in tests.
core/src/test/java/com/scalar/db/storage/jdbc/JdbcDatabaseTest.java Changed RdbEngine strategy from MYSQL to POSTGRESQL and updated SQL error handling.
core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTest.java Adjusted read-only verification conditions to accommodate MySQL performance optimization.
core/src/main/java/com/scalar/db/storage/jdbc/RdbEngineStrategy.java, RdbEngineSqlServer.java, RdbEngineMysql.java, RdbEngineMariaDB.java, RdbEngineDb2.java Modified getConnectionProperties signatures to include JdbcConfig and introduced setConnectionToReadOnly for MySQL.
core/src/main/java/com/scalar/db/storage/jdbc/JdbcUtils.java Updated loops to iterate using the new API signature.
core/src/main/java/com/scalar/db/storage/jdbc/JdbcConfig.java Added a field and accessor for DatabaseConfig to support new API usage.
Comments suppressed due to low confidence (2)

core/src/test/java/com/scalar/db/transaction/jdbc/JdbcTransactionManagerTest.java:82

  • The test case now uses the POSTGRESQL engine instead of MYSQL, which might not accurately test the MySQL optimizations addressed by this PR. Please verify if this change is intentional.
            RdbEngine.createRdbEngineStrategy(RdbEngine.POSTGRESQL),

core/src/test/java/com/scalar/db/storage/jdbc/JdbcDatabaseTest.java:65

  • Switching from MYSQL to POSTGRESQL in this test case could lead to inconsistencies when validating the MySQL-specific performance improvements. Please confirm if this change aligns with the intended testing scenarios for MySQL optimizations.
            RdbEngine.createRdbEngineStrategy(RdbEngine.POSTGRESQL),

Comment on lines +462 to +466
@Override
public void setConnectionToReadOnly(Connection connection, boolean readOnly) throws SQLException {
// Observed performance degradation when using read-only connections in MySQL. So we do not
// set the read-only mode for MySQL connections.
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't call Connection.setReadOnly(true) for MySQL.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question. We don't know the reason for the behavior?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we don't know the exact reason. We just observed performance degradation when we call Connection.setReadOnly(true) with MySQL.

Comment on lines +452 to 460
public Map<String, String> getConnectionProperties(JdbcConfig config) {
if (config.getDatabaseConfig().getScanFetchSize() == Integer.MIN_VALUE) {
// If the scan fetch size is set to Integer.MIN_VALUE, use the streaming mode.
return Collections.emptyMap();
}

// Otherwise, use the cursor fetch mode.
return Collections.singletonMap("useCursorFetch", "true");
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user sets scalar.db.scan_fetch_size to Integer.MIN_VALUE, the streaming mode is used in MySQL. In that case, we should not set the connection property useCursorFetch=true.

Copy link
Contributor

@Torch3333 Torch3333 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

Comment on lines +462 to +466
@Override
public void setConnectionToReadOnly(Connection connection, boolean readOnly) throws SQLException {
// Observed performance degradation when using read-only connections in MySQL. So we do not
// set the read-only mode for MySQL connections.
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question. We don't know the reason for the behavior?

public Map<String, String> getConnectionProperties() {
public Map<String, String> getConnectionProperties(JdbcConfig config) {
if (config.getDatabaseConfig().getScanFetchSize() == Integer.MIN_VALUE) {
// If the scan fetch size is set to Integer.MIN_VALUE, use the streaming mode.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[question] Is this behavior only for MySQL?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to add an integration test using scalar.db.scan_fetch_size = Integer.MIN_VALUE just in case ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, let me do that.

Copy link
Collaborator Author

@brfrn169 brfrn169 Jun 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added integration tests for it in bdb1309. Thanks!

@brfrn169 brfrn169 requested a review from komamitsu June 20, 2025 03:08
@brfrn169 brfrn169 force-pushed the optimize-jdbc-adopter-for-mysql branch from 0292941 to bdb1309 Compare June 20, 2025 03:26
Copy link
Contributor

@komamitsu komamitsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@brfrn169 brfrn169 merged commit f3969d9 into master Jun 20, 2025
56 checks passed
@brfrn169 brfrn169 deleted the optimize-jdbc-adopter-for-mysql branch June 20, 2025 04:52
brfrn169 added a commit that referenced this pull request Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants