I'm using MySQL innoDB for storing data. I needed to restrict the size of a particular table by some value. Soo after inserting data to the table, i will check the (DATA_LENGTH + INDEX_LENGTH) to see if it exceeded the limit. If exceeded i will delete some old data, until (DATA_LENGTH + INDEX_LENGTH) will reach below the limit.
But i'm getting unexpected (DATA_LENGTH + INDEX_LENGTH) value. so im not able to procced. (i have explained the situation below)
Initially i have a table tableTime with (DATA_LENGTH + INDEX_LENGTH) as around 15GB and DATA_FREE as 0GB. It has 2,000,000 rows.
DELETE FROM tableTime
LIMIT 1000000;
i deleted 1,000,000 rows (using above query) then waited for mysqld.exe to complete the disk I/O (manually see through task manager) and rebooted the system also.
ANALYZE TABLE tableTime;
SELECT ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS TABLE_NAME FROM information_schema.TABLES
where TABLE_NAME = 'tableTime';
now i checked (DATA_LENGTH + INDEX_LENGTH) again (using above query) i found it as ~13GB and DATA_FREE as ~2GB.
OPTIMIZE TABLE tableTime;
SELECT ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS TABLE_NAME FROM information_schema.TABLES
where TABLE_NAME = 'tableTime';
then i tried OPTIMIZE and got the expected like 8-9GB (DATA_LENGTH + INDEX_LENGTH).
But since tables are big i cant do OPTIMIZE every time to get table size. why ANALYZE is this much inefficient.