ALTER TABLE without locking the table?

后端 未结 19 1998
梦毁少年i
梦毁少年i 2020-11-30 17:41

When doing an ALTER TABLE statement in MySQL, the whole table is read-locked (allowing concurrent reads, but prohibiting concurrent writes) for the duration of the statement

19条回答
  •  攒了一身酷
    2020-11-30 18:03

    Dummy columns are a good idea if you can predict their type (and make them nullable). Check how your storage engine handles nulls.

    MyISAM will lock everything if you even mention a table name in passing, on the phone, at the airport. It just does that...

    That being said, locks aren't really that big a deal; as long as you are not trying to add a default value for the new column to every row, but let it sit as null, and your storage engine is smart enough not to go writing it, you should be ok with a lock that is only held long enough to update the metadata. If you do try to write a new value, well, you are toast.

提交回复
热议问题