1. 程式人生 > 其它 >mysql ALTER TABLE 併發控制

mysql ALTER TABLE 併發控制

併發控制
Concurrency Control
For ALTER TABLE operations that support it, you can use the LOCK clause to control the level of
concurrent reads and writes on a table while it is being altered. Specifying a non-default value for this
clause enables you to require a certain amount of concurrent access or exclusivity during the alter
operation, and halts the operation if the requested degree of locking is not available. The parameters
for the LOCK clause are:(支援指定LOCK語法的ALTER TABLE語句修改表時,可指定 LOCK 語法控制正在ALTER時對該表的併發讀寫限制,指定的 LOCK 為非預設值可明確限定併發或排他性訪問策略,若指定的 LOCK 不支援,則ALTER TABLE時對錶的訪問被阻塞。)
• LOCK = DEFAULT (預設值,最大程度,特定演算法和ALTER操作下儘可能地支援併發,如(演算法和ALTER操作)支援,允許併發讀寫,如不支援,嘗試支援併發讀,如再不支援,強制排他性訪問)
Maximum level of concurrency for the given ALGORITHM clause (if any) and ALTER TABLE
operation: Permit concurrent reads and writes if supported. If not, permit concurrent reads if
supported. If not, enforce exclusive access.
• LOCK = NONE(指定為NONE值,如特定演算法和ALTER操作支援,允許併發讀寫,否則提示錯誤。)
If supported, permit concurrent reads and writes. Otherwise, an error occurs.
• LOCK = SHARED(指定為SHARED值,如特定演算法和ALTER操作支援,允許併發讀但阻塞寫,儘管支援併發寫,仍阻塞寫,如特定演算法和ALTER操作不支援併發讀,則提示錯誤。)
If supported, permit concurrent reads but block writes. Writes are blocked even if concurrent writes
are supported by the storage engine for the given ALGORITHM clause (if any) and ALTER TABLE
operation. If concurrent reads are not supported, an error occurs.
• LOCK = EXCLUSIVE(指定為EXCLUSIVE值,強制排他性讀寫,儘管儲存引擎支援併發讀寫,仍阻塞。)
Enforce exclusive access. This is done even if concurrent reads/writes are supported by the storage
engine for the given ALGORITHM clause (if any) and ALTER TABLE operation.

ALTER TABLE 實現演算法
ALGORITHM [=] {DEFAULT | INPLACE | COPY}
ALTER TABLE operations are processed using one of the following algorithms:
• COPY: Operations are performed on a copy of the original table, and table data is copied from the
original table to the new table row by row. Concurrent DML is not permitted.(COPY 複製演算法,複製原來表資料結構,再操作新表資料結構,逐行復制,不允許對原表資料結構併發讀寫)
• INPLACE: Operations avoid copying table data but may rebuild the table in place. An exclusive(INPLACE 代替演算法,不復制,重新構建原表資料結構,使用元資料作為鎖,一般對併發DML提供支援)
metadata lock on the table may be taken briefly during preparation and execution phases of the
operation. Typically, concurrent DML is supported.
The ALGORITHM clause is optional. If the ALGORITHM clause is omitted, MySQL uses
ALGORITHM=INPLACE for storage engines and ALTER TABLE clauses that support it. Otherwise,
ALGORITHM=COPY is used.(ALGORITHM 引數可選,非必需,如不指定,MySQL儘可能使用INPLACE演算法,INPLACE演算法不可用時使用COPY演算法。)
Specifying an ALGORITHM clause requires the operation to use the specified algorithm for clauses and
storage engines that support it, or fail with an error otherwise. Specifying ALGORITHM=DEFAULT is the
same as omitting the ALGORITHM clause.