1

We are using MySQL 5.6 InnoDB storage engine and innodb_file_per_table is ON. We have some huge tables (> 100GB) with hundreds of millions of rows. For some huge tables, index space accounts for more than half of the table space. We found some indexes are redundant (thanks to Percona Toolkit). Could we simply drop the redundant indexes to release the disk space used by the index without OPTIMIZE TABLE?

  • Show us the SHOW CREATE TABLE, plus the important indexes. We may have advice on what other indexes to drop and/or datatype shrinkage. You may as well do all these things at once. – Rick James Dec 4 '20 at 2:13
1

I tested this:

CREATE TABLE `mytable` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `t` text,
  PRIMARY KEY (`id`),
  KEY `t` (`t`(768))
) ENGINE=InnoDB 

I filled it with some thousands of rows of random data.

mysql> show table status like 'mytable'\G
*************************** 1. row ***************************
           Name: mytable
         Engine: InnoDB
        Version: 10
     Row_format: Dynamic
           Rows: 95030
 Avg_row_length: 5660
    Data_length: 537903104
Max_data_length: 0
   Index_length: 190742528
      Data_free: 5242880

Dropped the index on the text column:

mysql> alter table mytable drop index t;

Refreshed information_schema statistics:

mysql> analyze table mytable;

And checked the table status:

mysql> show table status like 'mytable'\G
*************************** 1. row ***************************
           Name: mytable
         Engine: InnoDB
        Version: 10
     Row_format: Dynamic
           Rows: 95030
 Avg_row_length: 5660
    Data_length: 537903104
Max_data_length: 0
   Index_length: 0
      Data_free: 195035136

The space that used to be taken by the index is now in data_free. The file size has not shrunk.

This is consistent with other behavior of InnoDB, that a tablespace file never shrinks, the only thing that gives you back more disk space is if you copy the data to a new tablespace file. That requires enough free disk space to hold both the old and the new tablespace, temporarily.

So if you don't have enough free disk space to do this, your only recourse is to make the whole storage volume larger using a virtual disk, or else move the whole MySQL datadir to another server that already has a larger disk.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.