Best practice with mysql innodb to rename huge table when table with same name already exist

Yosef picture Yosef · Oct 12, 2012 · Viewed 7.3k times · Source

I Use Mysql 5.5.. + INNODB and windows server.

The case(make it simple then real case):

I have 2 tables 1GB with name new_car and car table 1GB.

I to replace car table with new_car table every 10 hours not manually(auto by code) - important to do it fast(real website data).

I read(say that drop its problem in innodb) :http://www.mysqlperformanceblog.com/2011/02/03/performance-problem-with-innodb-and-drop-table/

solution1:

DROP TABLE car;
RENAME TABLE new_car TO car;

Solution2(making drop in the end -maybe it not block the table to access that happen during drop):

RENAME TABLE car TO temp_car;
RENAME TABLE new_car TO car;
DROP TABLE temp_car;

Solution3(Truncate delete fast the table and create empty table then maybe drop action after should be very fast):

TRUNCATE TABLE car;
DROP TABLE car;
RENAME TABLE new_car TO car; 

Solution4:

RENAME TABLE car TO temp_car;
RENAME TABLE new_car TO car;
TRUNCATE TABLE temp_car;
DROP TABLE temp_car;

Which solution is the best and why or please write other better solution?

Thanks

Answer

Louis Ricci picture Louis Ricci · Oct 12, 2012

I don't understand why you would DROP the table. You always want those 2 tables and you'd (I'd assume be refilling up the New_Car table...

RENAME TABLE car TO temp_car;
RENAME TABLE new_car TO car;
TRUNCATE TABLE temp_car;
RENAME TABLE temp_car TO new_car;