假设我有一个 1M 行的表,我需要在其上添加一个索引。这样做的过程是什么?我可以ALTER TABLE table ADD INDEX column (column)
直接在生产上做吗?或者我是否需要考虑其他因素来添加索引。
通常如何在实时生产数据库上添加索引?
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.
就我个人而言,我会等到事情平静下来,但您不必使数据库脱机。用户可能会看到延迟,但不应超时。(如果确实如此,则有其他问题。)
请注意,添加索引不会使 dbms 复制整个表(就像添加列一样)。