Details
-
Task
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
1.2.2, 1.2.3
-
None
-
Windows 7 Professional
MySQL 5.5.34-log Community Server
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
Description
Attached please find a couple of tests, one with MariaDB Connector and another with MySQL Connector. Both do the same, but with the default value of max_allowed_packet the first test fails while the other stands.
As per CONJ-99, batched statements are rewritten. However, the value of max_allowed_packet is only taken into consideration when already rewritten statement is about to be sent. If resulting (rewritten) statement is too big then the whole operation fails.
MySQL Connector, on the other hand, rewrites the statement, splitting the result as needed in order not to exceed the value of max_allowed_packet (see com.mysql.jdbc.PreparedStatement#computeBatchSize).
import org.junit.Before; |
import org.junit.Test; |
|
import java.sql.Connection; |
import java.sql.Driver; |
import java.sql.PreparedStatement; |
import java.sql.SQLException; |
import java.sql.Statement; |
import java.util.Properties; |
|
public class MaxPacketAllowedTest { |
|
private Properties properties; |
|
@Before |
public void setUp() throws Exception { |
properties = new Properties(); |
properties.put("user", "root"); |
properties.put("password", ""); |
}
|
|
@Test |
public void testMariaDbConnector() throws Exception { |
executeBatch(new org.mariadb.jdbc.Driver()); |
}
|
|
@Test |
public void testMySqlDbConnector() throws Exception { |
executeBatch(new com.mysql.jdbc.Driver()); |
}
|
|
private void executeBatch(Driver driver) throws SQLException { |
Connection connection = driver.connect(
|
"jdbc:mysql://localhost:3306/max?rewriteBatchedStatements=true", |
properties);
|
Statement statement = connection.createStatement();
|
statement.execute("DROP TABLE IF EXISTS test"); |
statement.execute("CREATE TABLE test (id INT, text VARCHAR(50))"); |
|
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO test VALUES(?, ?)"); |
|
for (int i = 0; i < 100000; i++) { |
preparedStatement.setInt(1, i); |
preparedStatement.setString(2, "test text"); |
preparedStatement.addBatch();
|
}
|
preparedStatement.executeBatch();
|
}
|
}
|
Attachments
Issue Links
- relates to
-
CONJ-99 Support for batch statements rewrite
- Closed