Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-206

Take max_allowed_packet into consideration when rewriting statements

    XMLWordPrintable

Details

    • Task
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 1.2.2, 1.2.3
    • 1.3.0
    • Other
    • 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

          Activity

            People

              diego dupin Diego Dupin
              andrewani Andrei Anishchenko
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.