As you said, -innodb_file_per_table will decide whether one table will be stored in one file or (if partitioned) in many files.
Here are some advantages and disadvantages of each approach (not necessarily a complete list).
Single file per table Multiple files per (partitioned) table
In general, I would not suggest multiple files.
If, however, your workload leads to heavy fragmentation and the optimize table takes too much time, using multiple files will make sense.
Forget about freeing up space
Some people are very worried that tables in InnoDB files always grow and never shrink, which results in empty space if rows are deleted. Then they come up with schemes to restore this space so that there is no free disk space. ( truncate table x ).
This will work much faster with multiple files, however, all this is pointless because the databases almost always grow and (almost) never shrink, so all that fixing the space will spend a lot of time (CPU and IO) during your table will completely locked (reading and writing are not allowed).
Just to find that your 90% full disk (50% after recovery) will be 99% full after adding data in the following months.
However, beware when using ALTER TABLE ...
Consider the following scenario:
- The disk is 60% full.
- the database occupies 50%, other files occupy 10%.
If you make an alter table in any table, you will lose disk space if you have all the tables in one file.
If you have this in several files, you should not have problems (except for an overdose of caffeine from all waiting).
source share