Adding indexes to large tables without locking tables

ALTER TABLE recharge_v2.pers_point_account ADD INDEX idx_create_time (create_time) , ALGORITHM=INPLACE, LOCK=NONE;

ALGORITHM=INPLACE
is a better solution, add an index to the current table, steps:
1. Create an index (secondary index) data dictionary
2. Add a shared table lock, prohibit DML, and allow queries
3. Read the clustered index and construct a new one Index items, sort and insert
new index
4. Wait for all read-only transactions that open the current table to commit
5. End the index creation

ALGORITHM=COPY
creates an index through a temporary table, which requires twice as much storage and more IO. Steps:
1. Create a temporary table with an index (primary key index)
2. Lock the original table, prohibit DML, and allow queries
3. Set Copy the original table data to the temporary table
4. Prohibit reading and writing, perform rename, and upgrade the dictionary lock
5. Complete the index creation operation

LOCK=DEFAULT: By default, MySQL determines which LOCK mode to use by itself, and try not to lock the table
LOCK=NONE: No lock: Allow concurrent read and write operations during Online DDL. If the Online DDL operation
does not support continuous writing to the table, the DDL operation fails and is invalid for table modification
LOCK=SHARED: Shared lock: Blocking writes during the Online DDL operation does not affect reading
LOCK=EXCLUSIVE: Exclusive lock: No operations are allowed on the lock table during Online DDL operations

Guess you like

Origin blog.csdn.net/Fire_Sky_Ho/article/details/125161156