Why is MySQL's data_free larger than data and indexes combined?

前端 未结 1 517
悲&欢浪女
悲&欢浪女 2021-01-13 07:20

I have troubles interpreting the following stats from a MySql 5.5database.

Maybe relevant side info: some tables contain TEXT<

相关标签:
1条回答
  • 2021-01-13 08:15

    I assume you are using InnoDB, because it's the default storage engine in MySQL 5.5.

    InnoDB tablespaces grow as you insert data, but the files do not shrink when you delete data. So for example if you insert 1 million rows, and then delete them, the file will have a lot of space that is physically allocated, but no longer used. InnoDB will re-use that space if it can before growing the tablespace file again.

    Also, even if you don't delete, there can be some "wasted" space because when tablespace files are increased in size, they are expanded by a big chunk of pages, determined by the config option innodb_autoextend_increment in megabytes. Until those pages are filled by data, they are free space.

    Data_free reported by InnoDB is the amount of space "wasted" in empty pages in the central tablespace file. It has nothing to do with NULL values, it has to do with data pages that don't have rows in them.

    Further, in MySQL 5.5, the default is for all tables to share one central tablespace called ibdata. The data_Free for all tables in this tablespace will report the same figure, which is the amount of space in free pages in the whole tablespace, not just for one table.

    You can also allocate a separate tablespace per table (innodb_file_per_table=1), and for tables in separate tablespaces, you will see a different value per table for data_free.

    Data_free only reports space left by totally empty extents (an extent is a block of pages equal to 1MB). You'll notice that data_free is always a multiple of 1MB. Smaller blocks of free pages are not counted in data_free, nor are partially-filled pages. So the "wasted" space is probably a lot greater, but we have no way of knowing it.

    0 讨论(0)
提交回复
热议问题