views:

194

answers:

4

I'm performing some MySQL table maintenance that will mean removing some redundant columns and adding some new ones.

Some of the columns to drop are of the same type as ones to add. Would the procedure be faster if I took advantage of this and reused some of the existing columns?

My rationale is that changing column names should be a simple table metadata change, whereas removing and adding columns means either finding room at the end of the file (fragmenting data) or rebuilding every row with the correct columns so that they're at the same place on the disk.

The engine in question is MyISAM and I'm not up to scratch on how exactly it'll treat this so I'd like to hear from anyone who has been in the same situation before!

+1  A: 

Unless you have a serious issue with performance, I wouldn't take the renaming approach - because of all the dirty data you're going to leave lying around.

Also, by dropping the table, you will cause any indexes to get re-built - which is a good idea every once in a while...

Martin

Martin
Thankfully the columns aren't being used. Is this the only concern? I'm more worried I'm making assumptions about how MySQL works!As for performance, you raise a good point but it's a live site so no down time would be preferable to a down time of 20 minutes if it could be avoided.
jond
A: 

I would drop the columns. You will have fragmentation either way. That should be handled in your regular maintenance plans. You could accelerate those after a large number of modification operations.

Cade Roux
A: 

If you don't know, in Myisam table, every ALTER TABLE operation will do a copy of entire table, thus the table will be locked for the time your server needs to copy the table.

lg
A: 

I've used that same logic, and got stung because even with changes that are supposed to not require rewriting the table (i.e. a table rename), a MySQL bug caused it to think it was a change that required rewriting the table.

If the fields you are dealing with are date, datetime or timestamp fields, you are likely to be hit by this, which means that you should just assume it has to do a full rewrite and plan that way.

Kevin Peterson