[CONJ-1004] `ANALYZE TABLE` query executed by spring-data stopped working in mariadb-java-client 3.0.x Created: 2022-09-01  Updated: 2022-09-02  Resolved: 2022-09-02

Status: Closed
Project: MariaDB Connector/J
Component/s: JDBC 4.2 compatibility
Affects Version/s: 3.0.7
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: MikoĊ‚aj Matejko Assignee: Diego Dupin
Resolution: Not a Bug Votes: 0
Labels: None

Attachments: PNG File statement.png    

 Description   

Hi, we used to have a scheduled job that were executing the ANALYZE TABLE & OPTIMIZE TABLE for several tables.
Queries were coded using spring-data `@Query` annotation, which under the hood was invoking maria-db-client.

@Modifying
@Query(value = "ANALYZE TABLE xyz", nativeQuery = true)
void analyze();

In maria-db-client 2.7.x it worked correctly, however after upgrading to 3.0.5 the query stopped working. Stacktrace pointed us to ServerPreparedStatement#executeLargeUpdate.

Caused by: java.sql.SQLException: (conn=261028) the given SQL statement produces an unexpected ResultSet object
	at org.mariadb.jdbc.export.ExceptionFactory.createException(ExceptionFactory.java:297)
	at org.mariadb.jdbc.export.ExceptionFactory.create(ExceptionFactory.java:345)
	at org.mariadb.jdbc.ServerPreparedStatement.executeLargeUpdate(ServerPreparedStatement.java:470)
	at org.mariadb.jdbc.ServerPreparedStatement.executeUpdate(ServerPreparedStatement.java:442)

So the query itself is correct, however what does not look correct is handling of result in ServerPreparedStatement, because in case of ANALYZE TABLE/OPTIMIZE TABLE the result is CompleteResult type (query succeeded tho), so it goes to the if condition that throws an exception.



 Comments   
Comment by Diego Dupin [ 2022-09-02 ]

3.0 connector version correct wrong 2.x behavior about executeUpdate() :
has stated in JDBC : https://docs.oracle.com/javase/8/docs/api/java/sql/Statement.html#executeUpdate-java.lang.String-
executeUpdate must thrown an exception if

"the given SQL statement produces a ResultSet object"

removing

@Modifying

will probably solve the issue (changing returning 'void' type might have to be changed too)

Generated at Thu Feb 08 03:19:54 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.