Skip to content

Instantly share code, notes, and snippets.

@pcarranza
Last active August 29, 2015 14:12
Show Gist options
  • Save pcarranza/d1fe0a8d99bf409a19f7 to your computer and use it in GitHub Desktop.
Save pcarranza/d1fe0a8d99bf409a19f7 to your computer and use it in GitHub Desktop.
MySQL Index Sizes
SELECT sum(T.DATA_LENGTH) as DATA_SIZE_IN_BYTES,
CONCAT(format(sum(T.DATA_LENGTH)/pow(2,20), 2), 'mb') as DATA_SIZE_HR,
sum(T.INDEX_LENGTH) as INDEXES_SIZE_IN_BYTES,
CONCAT(format(sum(T.INDEX_LENGTH)/pow(2,20), 2), 'mb') as INDEX_SIZE_HR,
M.MEMORY_SIZE as MEMORY_SIZE_IN_BYTES,
CONCAT(format((M.MEMORY_SIZE)/pow(2,20), 2),'mb') AS AVAILABLE_MEMORY_HR,
CONCAT(format((sum(T.INDEX_LENGTH)/sum(T.DATA_LENGTH)) * 100, 2), '%') AS INDEX_TO_DATA_RATIO,
CONCAT(format((sum(T.INDEX_LENGTH)/M.MEMORY_SIZE) * 100, 2), '%') as USED_MEMORY_RATIO
FROM information_schema.tables as T,
(select VARIABLE_VALUE AS MEMORY_SIZE
from information_schema.GLOBAL_VARIABLES
where VARIABLE_NAME LIKE 'INNODB_BUFFER_POOL_SIZE') as M
WHERE table_schema = 'datasite' AND ENGINE = 'InnoDB'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment