MySql教程

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.

这篇关于mysql ALTER TABLE 并发控制的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!