micronaut-projects / micronaut-data

Ahead of Time Data Repositories
Apache License 2.0
464 stars 195 forks source link

Batch insert for MSSQL #629

Open chrisparton1991 opened 4 years ago

chrisparton1991 commented 4 years ago

This issue doesn't fall into the issue template sorry, so I'll keep it short.

Micronaut Data disables batch insert capability for MSSQL (code).

This is because MSSQL doesn't return generated primary keys for multiple inserts (I can reproduce this in plain JDBC). However, the batch insert functionality itself works fine in JDBC if you don't care about the returned IDs.

Could MSSQL batch inserts be enabled via a config flag like micronaut.data.mssql-batch-inserts: true? This gives users the choice.

I understand if this isn't worth the added complexity. Users can still use Micronaut for JDBC transactions and fall back to plain JDBC + JDBI or similar.

graemerocher commented 4 years ago

Seems reasonable yes

graemerocher commented 4 years ago

Would you like to put together a PR?

chrisparton1991 commented 4 years ago

Sure, I'll have a crack at it when I've got some spare time.

chrisparton1991 commented 1 week ago

I forgot about this issue as it became less of a problem when I moved away from generated integer primary keys.

However, issue #993 doesn't resolve this as it's only for MySql, not SQL Server.

Would it be a case of making the same updates to Dialect and AbstractSqlRepositoryOperations.isSupportsBatchInsert for SQL Server? i.e. allow batch inserts when not using a generated ID?