MySQL ALTER TABLE on very large table - is it safe to run it?

Posted by Timothy Mifsud on Stack Overflow See other posts from Stack Overflow or by Timothy Mifsud
Published on 2009-08-31T19:47:55Z Indexed on 2010/04/12 23:43 UTC
Read the original article Hit count: 281

Filed under:
|
|
|
|

I have a MySQL database with one particular MyISAM table of above 4 million rows. I update this table about once a week with about 2000 new rows. After updating, I then perform the following statement:

ALTER TABLE x ORDER BY PK DESC

i.e. I order the table in question by the primary key field in descending order. This has not given me any problems on my development machine (Windows with 3GB memory), but, even though 3 times I have tried it successfully on the production Linux server (with 512MB RAM - and achieving the resulted sorted table in about 6 minutes each time), the last time I tried it I had to stop the query after about 30 minutes and rebuild the database from a backup.

I have started to wonder whether a 512MB server can cope with that statement (on such a large table) as I have read that a temporary table is created to perform the ALTER TABLE command?! And, if it can be safely run, what should be the expected time for the alteration of the table?

Thanks in advance, Tim

© Stack Overflow or respective owner

Related posts about mysql

Related posts about alter