Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql table index length not reducing after drop them

Tags:

indexing

mysql

I created few indexes on a table that has 1M records and the index_length was increased then dropped the indexes which I created but the index_length is not reducing back. Using the below query to see the details

SELECT  TABLE_NAME, table_rows, data_length, index_length,
        round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB"
    FROM  information_schema.TABLES
    WHERE  table_schema = "dbname"
    ORDER BY  (data_length + index_length) DESC;

Any inputs on this much appreciated. TIA

like image 514
Ramjith Ap Avatar asked Oct 15 '25 03:10

Ramjith Ap


1 Answers

In general MySQL InnoDB does not release disk space after deleting data rows from the table. It keeps the space to reuse it later.

OPTIMIZE TABLE reorganizes the physical storage of table data and associated index data, to reduce storage space and improve I/O efficiency when accessing the table. The exact changes made to each table depending on the storage engine used by that table.

Look MySQL Documentation for more information

like image 66
Slava Rozhnev Avatar answered Oct 18 '25 03:10

Slava Rozhnev