Skip to content
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

Improve batch insertion for entities with auto-increment primary keys. #1191

Merged
merged 3 commits into from
Sep 28, 2024

Conversation

nakamura-to
Copy link
Member

This PR retrieves primary keys using Statement.getGeneratedKeys() after executing Statement.executeBatch(), if supported by the DBMS.

Supported DBMS are as follows:

  • H2
  • MySQL
  • PostgreSQL

Oracle Database and SQL Server do not support the combination of Statement.getGeneratedKeys() and Statement.executeBatch(). Therefore, Doma falls back to a process that repeatedly uses Statement.executeUpdate() for each entity in the batch.

Previously, to speed up batch insertion in PostgreSQL, we used org.seasar.doma.jdbc.id.IdProvider to retrieve IDs from the database in advance. However, since this pull request provides an alternative solution, org.seasar.doma.jdbc.id.IdProvider is now deprecated.

Retrieve primary keys using `Statement.getGeneratedKeys()` after executing `Statement.executeBatch()`, if supported by the DBMS.
@nakamura-to nakamura-to merged commit 3c45ccb into master Sep 28, 2024
10 checks passed
@nakamura-to nakamura-to deleted the refactor/batch-insert branch September 28, 2024 01:08
@nakamura-to
Copy link
Member Author

This pull request makes it possible to batch process operations with DuplicateKeyType.UPDATE and DuplicateKeyType.IGNORE, which previously fell back to inserting records one by one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant