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

Make saveAll use batch inserts #3193

Open
ritratt opened this issue Oct 24, 2024 · 1 comment
Open

Make saveAll use batch inserts #3193

ritratt opened this issue Oct 24, 2024 · 1 comment

Comments

@ritratt
Copy link

ritratt commented Oct 24, 2024

Feature description

Using Micronaut-Data 4.6.x. I'm trying to persist multiple rows to my table.

@JdbcRepository(dialect = Dialect.POSTGRES)
public interface MyRepository extends PageableRepository<Foo, Long> {
}

// And then I call the `saveAll` to save multiple rows from somewhere else
public void saveData(List<Foo> lostOfData) {
  myRepository.saveAll(lotsOfData);
}

I expected Micronaut to do a batch insert using a single connection+transaction. However, it turns out it not only does one insert per element of Foo but it also uses an individual DB connection. This results in performance issues as well as a starved connection pool.

I checked the docs and couldn't find a way to do this without writing my own queries, but then that defeats the purpose of using out of the box features that Micronaut Data provides.

@graemerocher
Copy link
Contributor

this should be the case, batch inserts are supported https://github.com/micronaut-projects/micronaut-data/blob/4.10.x/data-jdbc/src/main/java/io/micronaut/data/jdbc/operations/DefaultJdbcRepositoryOperations.java#L1296

Note that some databases don't support returning the ID for a batch insert.

Can you provide an example that reproduces the issue?

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

No branches or pull requests

2 participants