I have a mysql database with a particular table with a little over 6 million rows and no indexes. A simple query such as SELECT ... FROM log ORDER BY log_date ASC
will take an unacceptable amount of time. I obviously need to add indexes to the table, but am unsure of the most efficient way to go about this.
1) My first option would be to issue ALTER TABLE log ADD INDEX log_date
, but I'm not sure how long it would take... would it take approximately the same length of time as the previous query? If so, this is unacceptable.
2) My second option would be to export the table, TRUNCATE
the table, issue the ALTER TABLE
statement, and then re-import the table data. I'm not sure how long it would take to re-import the data, and am concerned as to what would happen if the system tries to write rows to the table during the process.
Is anyone able to offer insight into the best way to index a moderately large table in a production system without causing too much grief?