Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to figure out size of Indexes in MySQL

Tags:

mysql

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.

like image 481
Brian G Avatar asked Apr 23 '09 14:04

Brian G


People also ask

How does MySQL calculate index size?

In MySQL, an index block is usually 1,024 bytes and the data pointer is usually four bytes. For a 500,000-row table with a key value length of three bytes (the size of MEDIUMINT ), the formula indicates log(500,000)/log(1024/3*2/(3+4)) + 1 = 4 seeks.

How do you find the index size?

Query to check index size in Oracleselect sum(bytes)/1024/1024 as "Index Size (MB)" from dba_segments where segment_name='&INDEX_NAME'; select sum(bytes)/1024/1024 as "Index Size (MB)" from user_segments where segment_name='&INDEX_NAME';

How do I determine the size of a MySQL database?

To check the sizes of all of your databases, at the mysql> prompt type the following command: Copy SELECT table_schema AS "Database", ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)" FROM information_schema.

How do I find the indexes on a MySQL table?

You can list a table's indexes with the mysqlshow -k db_name tbl_name command. In MySQL 8.0. 30 and later, SHOW INDEX includes the table's generated invisible key, if it has one, by default.


2 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

like image 67
Josh Warner-Burke Avatar answered Oct 16 '22 05:10

Josh Warner-Burke


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 size_in_mb DESC; 
like image 31
Daniel Zohar Avatar answered Oct 16 '22 06:10

Daniel Zohar