How to improve efficiency of batch insert ?
My version : Sharding-JDBC 4.1.1
sql like this: insert into pressure(userid,orderid) values(?, ?),(?,?),... insert data size is 5000, and i've used prepare statement.
when NOT using sharding, time consumes about 40ms, but sharding takes about 400ms.
Sharding tables configuration:

Analysis by arthas, I can see that time mostly cost on function org.apache.shardingsphere.sharding.rewrite.token.generator.impl.keygen.GeneratedKeyInsertValuesTokenGenerator:isToAddDerivedLiteralExpression. See below:

Is there anything I can do to improve efficiency?
It seems isToAddDerivedLiteralExpression method will call getGroupedParameters for an empty check every time. So we can make two improvement choices:
- cache the GroupedParameters for one sql and will called 5000 times in multiple values
- add a new check empty method and avoid new/merge parameters
private boolean isToAddDerivedLiteralExpression(final InsertStatementContext insertStatementContext, final int insertValueCount) {
return insertStatementContext.getGroupedParameters().get(insertValueCount).isEmpty();
}
public List<List<Object>> getGroupedParameters() {
List<List<Object>> result = new LinkedList<>();
for (InsertValueContext each : insertValueContexts) {
result.add(each.getParameters());
}
if (null != insertSelectContext) {
result.add(insertSelectContext.getParameters());
}
return result;
}
there has been fixed in master branch, can you try it with master branch 5.0.0. https://github.com/apache/shardingsphere/pull/7816
there has been fixed in master branch, can you try it with master branch 5.0.0. #7816
sure!