I am using MySql Engine=InnoDB for my application. There is a table which collects Search data from different location and save it for processing. After a particular interval of time we remove this data using scheduler. Problem happens when we delete large number of rows, it doesn't free up the disk space. We have already set innodb_file_per_table ON. One solution is to run a query:
Optimize Table <TableName>
But this cause other Select operation fails on that particular table, telling:
Caused by: java.sql.SQLException: Table definition has changed, please retry transaction at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:545) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:513) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:115) at com.mysql.cj.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:1983) at com.mysql.cj.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1826) at com.mysql.cj.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1923) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:353) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:60) ... 154 common frames omitted
I need a solution to reclaim/reuse table space. I am using Spring-boot, so this solution should be handled from the application. Even if partition needs to be used, it should be configurable from application.