views:

41

answers:

1

I'm trying to optimize my mysql tables (MyISAM) and I changed some column types with phpmyadmin, mostly from int to smallint, medium int, etc. After I did that mysql really bogged down and the server load went really high. I did this on a live site, which I figured was the problem, but even after putting the site into maintenance mode and waiting for the load to drop down, the load still went crazy afterwards. In the end I have to drop the tables and recreate them with their original column types for things to work back smoothly... So is there anything special I should be doing before and after changing column types?

Would joining tables with two different column types also create a problem? I.E. id INT(11) joining with MEDIUMINT(8). I think at one point I did that.

+1  A: 

You said:

"Would joining tables with two different column types also create a problem? I.E. id INT(11) joining with MEDIUMINT(8). I think at one point I did that."

Yes. That could kill performance because when you do a join on 2 columns of different types, the RBDMS has to perform an on the fly type conversion of every single value in one of the columns to match the type in the other column so that it can do the comparison. For this reason, columns that you are joining on should always be of the same type, preferably with a foreign key too (if you're using the InnoDB table type).

Asaph
i would also add: use EXPLAIN right before your mysql query to see how columns are joined (possibly tmp table will be used which is overkill)
dusoft
@dusoft Great point. EXPLAIN will show you what keys are being used, if any full table scans are happening, etc.
Asaph
Alright, I'll make sure to do that. Aside from that I should be able to change all the column types normally? Do you need to do anything like drop and recreate indexes?
Roger
@Roger: Indexes shouldn't need to be recreated, RBDMS should do it for you. But foreign keys will need to be dropped and recreated if data types change.
Asaph