Skip to content
Snippets Groups Projects
Commit f79a40e7 authored by Robert S Lee's avatar Robert S Lee Committed by Sean Busbey
Browse files

[jdbc] support JDBC option to rewrite batch statement to multi-row insert (#1220)

* [jdbc] support JDBC option to rewrite batch statement to multi-row insert

batch statement int[] results = insertStatement.executeBatch() returns 1 for successful completion. when the batch statement is re-written to multi-row insert, SUCCESS_NO_INFO (-2) is returned instead. This change expands allowable results values to be 1 AND -2

* [jdbc] note on rewriting batch insert to multi-row
parent d1a8a694
No related branches found
No related tags found
No related merge requests found
......@@ -106,3 +106,25 @@ db.batchsize=1000 # The number of rows to be batched before commit (
```
Please refer to https://github.com/brianfrankcooper/YCSB/wiki/Core-Properties for all other YCSB core properties.
## JDBC Parameter to Improve Insert Performance
Some JDBC drivers support re-writing batched insert statements into multi-row insert statements. This technique can yield order of magnitude improvement in insert statement performance. To enable this feature:
- **db.batchsize** must be greater than 0. The magniute of the improvement can be adjusted by varying **batchsize**. Start with a small number and increase at small increments until diminishing return in the improvement is observed.
- set **jdbc.batchupdateapi=true** to enable batching.
- set JDBC driver specific connection parameter in **db.url** to enable the rewrite as shown in the examples below:
* MySQL [rewriteBatchedStatements=true](https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-configuration-properties.html)
```
db.url=jdbc:mysql://127.0.0.1:3306/ycsb?rewriteBatchedStatements=true
```
* Postgres [reWriteBatchedInserts=true](https://jdbc.postgresql.org/documentation/head/connect.html#connection-parameters)
```
db.url=jdbc:postgresql://127.0.0.1:5432/ycsb?reWriteBatchedInserts=true
```
......@@ -421,7 +421,8 @@ public class JdbcDBClient extends DB {
if (++numRowsInBatch % batchSize == 0) {
int[] results = insertStatement.executeBatch();
for (int r : results) {
if (r != 1) {
// Acceptable values are 1 and SUCCESS_NO_INFO (-2) from reWriteBatchedInserts=true
if (r != 1 && r != -2) {
return Status.ERROR;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment