Skip to content

Instantly share code, notes, and snippets.

@fdv
Created February 19, 2020 14:26
Show Gist options
  • Save fdv/19e98eef5c0b0e3e5dc83bda67e3639d to your computer and use it in GitHub Desktop.
Save fdv/19e98eef5c0b0e3e5dc83bda67e3639d to your computer and use it in GitHub Desktop.
MySQL breakdown of table size between data and index
SELECT
ROUND(SUM(DAT) /1024/1024/1024, 2),
ROUND(SUM(NDX) /1024/1024/1024, 2),
TBL
FROM
(
SELECT TBLN, DAT,NDX,TBL,IF(px>4,4,px) pw1,IF(py>4,4,py) pw2,IF(pz>4,4,pz) pw3
FROM
(
SELECT table_name TBLN, data_length DAT,index_length NDX,data_length+index_length TBL,
FLOOR(LOG(IF(data_length=0,1,data_length))/LOG(1024)) px,
FLOOR(LOG(IF(index_length=0,1,index_length))/LOG(1024)) py,
FLOOR(LOG(data_length+index_length)/LOG(1024)) pz
FROM information_schema.tables
WHERE table_schema='mydb'
GROUP BY table_name
) AA
) A,(SELECT 'B KBMBGBTB' units) B;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment