Let’s say I have a table with 1M rows and I need to add an index on it. What would be the process of doing so? Am I able to do ALTER TABLE table ADD INDEX column (column) directly on production? Or do I need to take other things into account to add the index.
How does one normally go about adding an index on a live production db?
You should first try adding the same index on your test database under similar load conditions and check that it doesn’t cause problems. It’s possible that by creating the index you lock the table for some time and cause other queries to fail.
One million rows is a large table, but it’s not huge. You will probably find that the adding the index completes reasonably quickly. Unless you have real-time constraints it’s unlikely to cause serious issues. It’s definitely worth testing it first though.