0

Using MySql and innodb with innodb_file_per_table flag ON.

  • We have a table with a size of ~100GB. We delete the data and insert fresh data (approx same size) every day (the delete is in chunks by a key, when this key task is fetch fresh data).

  • We see that there is no reuse, the table size is increasing with ~100GB every day.

  • As far as we know mysql should reuse deleted space (same table).

  • We do not want to reclaim the space, just to have the reuse on the same table working...

What could cause this behavior? We cannot optimize the table every single day.

(similar to Does mysql use deleted rows space in a table?)

asked Jul 11, 2024 at 13:03
3
  • 1
    We delete all the data and insert fresh data (approx same size) every day. How do you delete rows? Use TRUNCATE. Commented Jul 11, 2024 at 16:30
  • @Akina We use DELETE because we delete and insert for each account when each account data is ready, so we cannot just truncate... Commented Jul 14, 2024 at 6:23
  • ?? In the question you tell that We delete all the data. Now you tell that you delete the data partially (may be finally all, but in progress by chunks). Please edit the question if its facts are not correct. Commented Jul 14, 2024 at 9:08

1 Answer 1

0

If you are deleting all the data of a table, it is best to create and populate another table, then use RENAME TABLE to swap it in place.

If you are deleting most of a table, it is best to create a new table, then insert the rows to keep into it. Then swap.

It may make sense to PARTITION the table, then delete one hour's worth each hour. More discussion:

(I would rather that you change your process before discussing "reuse" of space. Most of my suggestions are good at not bloating the disk, not locking the table too long, etc. So, come back when you have change the processing.)

answered Jul 18, 2024 at 1:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.