Forums

This topic is locked

Fisically Remove rows in MYSQL

Posted 20 Oct 2009 07:58:21
1
has voted
20 Oct 2009 07:58:21 kandir pare posted:
HI guys

I need to know how to fisically remove rows from a table, I'm working with a MySQL 4.1 database.
Cause I've noticed that after having deleted too many rows from a very large table (with a SQL statement, ex. DELETE FROM tablename),
the size (in GB's) of the database keep being the same , and so the performance of the queries I run on that table.

I need to know if there's any command or tool to pack a table or work with it's rows (deleted or not)
The table type I use is InnoDB.

Replies

Replied 20 Oct 2009 08:09:03
20 Oct 2009 08:09:03 Patrick Julicher replied:
Hi,

Please check this out:

What I think throws some people off is that when this happens, records that are "deleted" are not actually removed from disk. The database knows those records are not to be used anymore, but the disk space is not deallocated, it's just considered "dead" space. This is perfectly harmless. When new records are added to the database, they get written to this "dead" space, so no new disk space needs to be allocated for them. In other words, the space taken up by the "deleted" records is reused by the database to store new records.

The reason most database applications don't physically delete records at the time they're "deleted" is simple--efficiency. The database itself is typically a huge file on disk, and if you want to delete part of it you have to interact with the filesystem to write a new (modified) copy of it and then delete the old one. This takes time and system resources, and your database application would slow to a crawl if it had to do that every time a record was deleted.


If you still want to loose the dead space, there should be an optimize/vacuum option you could use.

Kind regards, Patrick

Reply to this topic