Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 320413 - UPDATE batching on MySQL appears to be broken
Summary: UPDATE batching on MySQL appears to be broken
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard: MySQL
Keywords:
Depends on: 320643
Blocks:
  Show dependency tree
 
Reported: 2010-07-20 12:05 EDT by Adrian Goerler CLA
Modified: 2022-06-09 10:02 EDT (History)
1 user (show)

See Also:


Attachments
proposed patch and regression test (42.81 KB, patch)
2010-07-22 10:58 EDT, Adrian Goerler CLA
no flags Details | Diff
proposed patch (1.73 KB, patch)
2010-07-23 08:33 EDT, Adrian Goerler CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adrian Goerler CLA 2010-07-20 12:05:04 EDT
UPDATE batching on MySQL appears to be broken:

1) In the MySQLPlatform, the method

canBatchWriteWithOptimisticLocking() does not override the method DatabasePlatform.canBatchWriteWithOptimisticLocking(DatabaseCall call).

2) The executeBatch does not seem to be able to properly determine the number of rows changed:

public int executeBatch(Statement statement, boolean isStatementPrepared) throws java.sql.SQLException {
       int[] updateResult = statement.executeBatch();
       int updateCount = 0;
       for (int count : updateResult){
           if (count == Statement.SUCCESS_NO_INFO){
               count = 1;
           }
           updateCount+=count;
       }
       return updateCount;
    }

I assume that rows, for which the optimistic verification fails, will also yield SUCCESS_NO_INFO.
Comment 1 Adrian Goerler CLA 2010-07-22 10:39:39 EDT
An investigation showed that while issue 1) is valid, issue 2) seems not to occur as the updateResult[] does not contain SUCCESS_NO_INFO but non-negative values.
Comment 2 Adrian Goerler CLA 2010-07-22 10:58:02 EDT
Created attachment 174990 [details]
proposed patch and regression test

As a regresssion test, the patch enables JDBC-batching in the eclipselink.jpa.wdf.test testsuite.

The test TestDeleteQuery had to be modified:
if JDBC batching is enabled EclipseLink also batches statements generated by a JPQL delete query. Due to the batching, it is not possible any longer to determine the exact update count. Hence, checking the update count is disabled in the test.

Also, the executeUpdate method of the MySQL Platform needs to be modified for Statement batches: here, the update count is just the number of statements in the batch.
Comment 3 Adrian Goerler CLA 2010-07-23 08:33:51 EDT
Created attachment 175060 [details]
proposed patch

Moved the regression tests to bug 320643.
Comment 4 Adrian Goerler CLA 2010-09-20 08:32:44 EDT
Checked in in trunk at #8217

Reviewed by Gordon
Tests on MySQL (core, jpa, jpa.wdf): OK
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:02:47 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink