Divergence between amount of data from rows and storage usage

Hello all.

We have a customer that uses MySQL 8.0 with Cloud SQL. They brought us an interesting question. They ran this query, to try to reckon the amount of data on the database

mysql> SELECT table_schema AS 'Schema',ROUND(SUM(data_length) / (1024 * 1024 * 1024), 2) AS 'Data (GB)',ROUND(SUM(index_length) / (1024 * 1024 * 1024), 2) AS 'Index (GB)',ROUND(SUM(data_free) / (1024 * 1024 * 1024), 2) AS 'Free/Fragmented (GB)',ROUND((SUM(data_length) + SUM(index_length) + SUM(data_free)) / (1024 * 1024 * 1024), 2) AS 'Total Estimated Disk Usage (GB)' FROM information_schema.tables WHERE table_type = 'BASE TABLE' GROUP BY table_schema;
+--------------------+-----------+------------+----------------------+---------------------------------+
| Schema | Data (GB) | Index (GB) | Free/Fragmented (GB) | Total Estimated Disk Usage (GB) |
+--------------------+-----------+------------+----------------------+---------------------------------+
| lportal | 124.88 | 76.10 | 2.82 | 203.81 |
| performance_schema | 0.00 | 0.00 | 0.00 | 0.00 |
+--------------------+-----------+------------+----------------------+---------------------------------+
2 rows in set (3.58 sec)

Nonetheless, the “Storage usage” shows that the service is using more than 240 GB, which is above the ~200 GB the query gave us.

I imagine there is a lot of extra data necessary to keep the database up and running, but a difference of almost 40 GB is considerable.

What could be causing the difference? I have checked everything (bin log, audit log, undo log etc.) and none seems to affect it.

Thanks in advance!

Hello @Adam_Brandizzi,

Note that your SQL query is using GB (Gigabyte) while GCP uses GiB (Gibibyte).

240 GiB ~= 250 GB. So it’s even more! :eyes:

As written in the metrics documentation, Bytes Used and Bytes Used By Data Type are Disk Metrics.

Your query returns the logical disk usage, which may be smaller because it does not include reserved but unused space. From a physical perspective, the disk considers this space as used since it has been allocated by MySQL.

I have found some nice Stack Overflow threads to help you better understand what’s happening: