【产品名称】oceanbase
【产品版本】3.1.1
【问题描述】java 使用insert on duplicate key update 模式导入1万条数据到一个9个普通字段的空表,用了10分钟,而直接insert 1万条数据,只需要1秒,请问是那里的问题呢? 感谢
相关配置以及关键代码
1、jdbc的url: jdbc:mysql://192.168.90.32:2883/test?useSSL=false;useUnicode=true;characterEncoding=UTF-8;rewriteBatchedStatements=true;allowMultiQueries=true;useLocalSessionState=true 2、租户资源: 内存 36G,cpu 2 3、mysql-connector-java版本: 5.1.47 4、关键代码 PreparedStatement pstmt = null; try { // tid是主键, data+code+type是唯一性约束 String sql = "insert into test (tid,date,code,type,type_num,all_num,titime,tutime,tutimestamp) " + "value( ?,?,?,?,?,?,?,?,?) " + “on duplicate key update type_num= ? ,all_num= ? ,titime= ?,tutime= ? ,tutimestamp= ?” ; pstmt = conn.prepareStatement(sql); for (int i = 0; i < args.length; i++) { Object[] curArgs = args[i]; for (int j = 1; j <= curArgs.length; j++) { pstmt.setObject(j, curArgs[j - 1]); } pstmt.addBatch(); } int[] result = pstmt.executeBatch(); return result; } catch (SQLException ex) { throw new JdbcException(ex); } finally { closeStatement(pstmt); }