Bug regarding rewritableAsMultiValues introduced in 8.0.29
Posted by: Gustaf Sörensen
Date: January 26, 2023 08:45AM

After bumping to 8.0.29 and later versions we noticed that batch inserts made by prepared statements took much longer time to execute. After a bit of investigation we found that this only happens on some of our inserts. Namely inserts where we have column names that have the word "value" in them and where the query takes placeholders "?".

We could find no way to work around this so please provide a fix since we can't go above 8.0.28 until this is resolved.

Including is a test verifying the bug:

import static org.junit.jupiter.api.Assertions.assertTrue;

import com.mysql.cj.jdbc.ClientPreparedStatement;
import com.mysql.cj.jdbc.MysqlDataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.junit.jupiter.api.Test;

class TransferDatabaseTest {
@Test
void rewritableAsMultiValuesBug() throws SQLException {
MysqlDataSource dataSource = new MysqlDataSource();
String url = "YOUR CONNECTION STRING GOES HERE :)";
dataSource.setURL(url);
dataSource.setRewriteBatchedStatements(true);
Connection connection = dataSource.getConnection();

//WORKING QUERY
PreparedStatement preparedStatement = connection.prepareStatement(
"INSERT INTO test (a, b) VALUES (?, ?)"
);
ClientPreparedStatement clientPreparedStatement = (ClientPreparedStatement) preparedStatement;
boolean isRewritable = clientPreparedStatement.getQueryInfo()
.isRewritableWithMultiValuesClause();
assertTrue(isRewritable);
connection.close();

//FAILING QUERY
connection = dataSource.getConnection();
PreparedStatement preparedStatementBug = connection.prepareStatement(
"INSERT INTO test (a_value, bvalue) VALUES (?, ?)"
);
ClientPreparedStatement clientPreparedStatementBug = (ClientPreparedStatement) preparedStatementBug;
boolean isRewritableBug = clientPreparedStatementBug.getQueryInfo()
.isRewritableWithMultiValuesClause();
assertTrue(isRewritableBug);

}

}

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.