Bug #40561 rewriteBatchedStatements no longer works with replace statements
Submitted: 6 Nov 2008 20:00 Modified: 20 Jul 2015 17:29
Reporter: Ryan Albarelli Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.7 OS:Any
Assigned to: Filipe Silva CPU Architecture:Any
Tags: rewriteBatchedStatements replace batch

[6 Nov 2008 20:00] Ryan Albarelli
Description:
It appears the ability to rewrite batched REPLACE statements was inadvertently dropped on the check-in listed below. The log comment seems to imply that REPLACE statements are still supported, but the code change removes it.

http://lists.mysql.com/commits/29897?f=plain

Thanks.

How to repeat:
PreparedStatement stmt = conn.prepareStatement( "REPLACE INTO test( test_id, test_val ) VALUES ( ?, ? )", Statement.RETURN_GENERATED_KEYS );

// Add a new value with auto-generated key
stmt.setNull( 1, java.sql.Types.INTEGER );
stmt.setInt( 2, 71 );
stmt.addBatch();
            
Replace an old value with key=1
stmt.setInt( 1, 1 );
stmt.setInt( 2, 72 );
stmt.addBatch();

stmt.executeBatch();

The statements are not rewritten even though the syntax is the same for INSERT and REPLACE. Two statements are executed instead of one.

Suggested fix:
Revert the logic condition to support REPLACE statements, or indicate that the support was intentionally dropped.
[6 Nov 2008 20:01] Ryan Albarelli
The function in question is canRewriteAsMultivalueInsertStatement() in PreparedStatement.java
[7 Nov 2008 8:24] Tonci Grgin
Hi Ryan and thanks for your report.

Verified as described by looking into latest sources. I am sure Mark had good reason for doing this (maybe Bug#39352) so I'll wait for his explanation leaving report without triage until then.
[20 Jul 2015 17:29] Filipe Silva
Duplicate of Bug#77681. Please follow progress in Bug#77681 report.