Home » Mysql » How to figure out size of Indexes in MySQL

How to figure out size of Indexes in MySQL

Posted by: admin November 1, 2017 Leave a comment

Questions:

I want to determine the size of my indexes, they are primary key indexes. This happens to be on mysql cluster but I don’t think that is significant.

Answers:

I think this is what you’re looking for.

show table status from [dbname]

http://dev.mysql.com/doc/refman/5.1/en/show-table-status.html

Questions:
Answers:

If you are using InnoDB tables, you can get the size for individual indexes from mysql.innodb_index_stats. The ‘size’ stat contains the answer, in pages, so you have to multiply it by the page-size, which is 16K by default.

select database_name, table_name, index_name, stat_value*@@innodb_page_size
from mysql.innodb_index_stats where stat_name='size';

Questions:
Answers:

Extending Vajk Hermecz’s answer.
This is how you can get all of the indexes size, in megabytes, without the PRIMARY (which is the table itself), ordered by size.

SELECT database_name, table_name, index_name, 
round(stat_value*@@innodb_page_size/1024/1024, 2) size_in_mb
FROM mysql.innodb_index_stats
WHERE stat_name = 'size' AND index_name != 'PRIMARY'
ORDER BY 4 DESC;

Questions:
Answers:

On MyISAM, each index block is 4 KB page filled up to fill_factor with index records, each being key length + 4 bytes long.

Fill factor is normally 2/3

As for InnoDB, the table is always clustered on the PRIMARY KEY, there is no separate PRIMARY KEY index

Questions:
Answers:

Unused by me but perhaps MySQL Index Analyzer may be helpful.

Questions:
Answers:

Using phpMyAdmin, when viewing the table structure there is a Details link at the bottom somewhere. Once you click on it it will show you the total size of the indexes you have on the table where it is marked Space Usage.

I don’t think it shows you each index individually though.

Questions:
Answers:

In this article determine how to calculate index size.
http://aadant.com/blog/2014/02/04/how-to-calculate-a-specific-innodb-index-size/