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

sql command ending with semicolon and trailing space are not using bulk

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • 3.4.0, 3.4.1, 3.5.0
    • 3.5.1
    • batch, performance
    • None

    Description

      We are often using Java text blocks to write SQL statements.

      String insertQuery = """
      	INSERT INTO
      		test.table
      		(id, text)
      	VALUES
      		(?, ?);
      	""";
       
      PreparedStatement stmt = conn.prepareStatement(insertQuery);
       
      for (int i = 0; i < 20; i++) {
      	stmt.setInteger(1, i);
      	stmt.setString(2, "text");
      	stmt.addBatch();
      }
       
      stmt.executeBatch();
      

      With version 3.3.3, this sample statement was executed with `executeBatchBulk`. Since 3.4.0, it is only executed one-by-one with `executeBatchStd` with a dramatically worse performance.

      The reason is the query is considered a multi-query, because the semicolon is not very last character in the string:

          // multi contains ";" not finishing statement.
          boolean isMulti = multiQueryIdx != -1 && multiQueryIdx < queryLength - 1;
      

      https://github.com/mariadb-corporation/mariadb-connector-j/blob/2eacf8a0b88f6316a412e552b7fc3edd3671bbba/src/main/java/org/mariadb/jdbc/util/ClientParser.java#L197

      Attachments

        Issue Links

          Activity

            People

              diego dupin Diego Dupin
              Christopher Christopher Wilke
              Votes:
              0 Vote for this issue
              Watchers:
              1 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.