我有一个不包含任何GROUP_CONCAT()调用的批量更新函数;
UPDATE
product
SET
viewed = ?
WHERE
product_id = ?
如您所见,这是一个准备好的声明。我正在设置其值,然后使用 addBatch() 方法为每一行添加它。当我的计数达到定义的限制 (1000) 时,我正在调用 executeBatch() 以进行数据库修改。如您所见,在我的批处理更新过程中没有 group_concat() 调用,但 mysql jdbc 抛出此异常。与批量更新和group_concat()的隐藏关系是什么,为什么?我该怎么做才能解决这个问题?降低批次限制还是增加 group_concat() 限制?
我的堆栈跟踪是;
java.sql.BatchUpdateException: Row 276751 was cut by GROUP_CONCAT()
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2054)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1467)
at datasource.DB.execPreparedStatement(DB.java:480)
at datasource.DB.addBatch(DB.java:467)
at cj.reportsummarydaily.ProductViewed.executeJob(ProductViewed.java:24)
at job.Job.executeCore(Job.java:101)
at job.Job.execute(Job.java:77)
at cj.reportsummarydaily.Main.executeJobMeta(Main.java:35)
at job.JobMeta.execute(JobMeta.java:32)
at cronjob.CronJob.main(CronJob.java:66)
Caused by: java.sql.SQLException: Row 276751 was cut by GROUP_CONCAT()
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2006)
... 9 more
我发现并解决了这个问题。我们的一位前程序员在表产品上编写了一个错误的更新前触发器。因此,当我更新产品表时,触发器在某些特定记录上引发了该异常。我正确重新编程了触发器,并在代码下方添加了group_concat以增加限制;
SET group_concat_max_len=1024 * 10;