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

[jdbc] support JDBC option to rewrite batch statement to multi-row in… #1220

Merged
merged 2 commits into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions jdbc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```





3 changes: 2 additions & 1 deletion jdbc/src/main/java/com/yahoo/ycsb/db/JdbcDBClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ public Status insert(String tableName, String key, Map<String, ByteIterator> val
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;
}
}
Expand Down