reWriteBatchedInserts does not work with PostgreSQL
See original GitHub issueI’m trying to use reWriteBatchedInserts with a PostgreSQL database. According to pgjdbc the rewrite is possible only if no return values are requested.
In InsertStatement.kt
:
override fun prepared(transaction: Transaction, sql: String): PreparedStatementApi = when {
// https://github.com/pgjdbc/pgjdbc/issues/1168
// Column names always escaped/quoted in RETURNING clause
autoIncColumns.isNotEmpty() && currentDialect is PostgreSQLDialect ->
transaction.connection.prepareStatement(sql, true)
autoIncColumns.isNotEmpty() ->
// http://viralpatel.net/blogs/oracle-java-jdbc-get-primary-key-insert-sql/
transaction.connection.prepareStatement(sql, autoIncColumns.map { it.name.inProperCase() }.toTypedArray())
else ->
transaction.connection.prepareStatement(sql, true)
}
So the prepare statement is always call with true
.
In JdbcConnectionImpl
:
override fun prepareStatement(sql: String, returnKeys: Boolean) : PreparedStatementApi {
val generated = if (returnKeys)
PreparedStatement.RETURN_GENERATED_KEYS
else
PreparedStatement.NO_GENERATED_KEYS
return JdbcPreparedStatementImpl(connection.prepareStatement(sql, generated), returnKeys)
}
So every insert requests set returnKeys
to PreparedStatement.RETURN_GENERATED_KEYS
.
The consequence is that the optimization implies by reWriteBatchedInserts
is not done.
Am I missing something?
ps: I’m using batchInsert
and I set reWriteBatchedInserts
to true correctly (I checked it in debug). I also tested some inserts using directly the jdbc api and the rewrite worked (I saw it in postgresql logs).
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top Results From Across the Web
reWriteBatchedInserts=true not working with ON CONFLICT ...
When using the new reWriteBatchedInserts=true feature, this fails when using ON CONFLICT DO UPDATE ... Assume the following table:.
Read more >PostgreSQL reWriteBatchedInserts configuration property
Learn how the PostgreSQL reWriteBatchedInserts JDBC configuration property works and how it generates multi-VALUE INSERT statements.
Read more >How to Write into a Database Using reWriteBatchedInserts ...
In this article, the author explains how to perform batch insert in PostgreSQL to write data into a database quickly.
Read more >Hibernate/Postgresql batch insert no longer working after ...
After the update, the INSERTs are no longer batched (I can tell because the execution time is much faster before the update.) I...
Read more >Vlad Mihalcea on Twitter: "5. Enable the ...
Learn how the PostgreSQL SERIAL column type works and why you don't want to ... Enable the reWriteBatchedInserts JDBC setting to speed up...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Tapac for your information I just tested version 0.25.1 and it works great! Thanks.
Today or tomorrow.