即使在处理“select”时,myisam 也会在表上放置表锁。询问?
我正在阅读《高性能MySQL》一书,它提到:
performing one query per table uses table locks more efficiently: the queries
will lock the tables invididually and relatively briefly, instead of locking
them all for a longer time.
即使在选择
某些内容时,MyISAM 也会放置表锁?有人可以解释一下吗?
i am reading the book High Performance MySQL
, it mentions:
performing one query per table uses table locks more efficiently: the queries
will lock the tables invididually and relatively briefly, instead of locking
them all for a longer time.
MyISAM places table-lock even when selecting
something? can someone explain a little bit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MyISAM 有不同类型的锁。
SELECT
操作会在表上放置一个READ LOCK。只要没有活动的写锁,在任何给定时间都可以有多个活动的读锁。修改表的操作,例如。INSERT
、UPDATE
、DELETE
或ALTER TABLE
在表上放置一个WRITE LOCK 。只有当没有活动的读锁时,才能对表放置写锁;如果存在活动的读锁,MyISAM 会将写锁排队,以便在所有活动的读锁到期后立即激活。同样,当存在活动的写锁时,尝试在表上放置读锁将使锁(以及关联的查询)排队,直到表上的写锁过期。
最终,这一切都意味着:
有关详细信息,请参阅:http://dev.mysql.com/doc/refman/5.5/en/internal-locking.html< /a>
MyISAM has different kinds of locks. A
SELECT
operation places a READ LOCK on the table. There can be multiple active read locks at any given time, as long as there are no active WRITE LOCKS. Operations that modify the table, eg.INSERT
,UPDATE
,DELETE
orALTER TABLE
place a WRITE LOCK on the table. Write lock can only be placed on a table when there are no active read locks; If there are active read locks, MyISAM queues the write lock to be activated as soon as all active read locks are expired.Likewise when there's an active write lock, attempting to place a read lock on a table will queue the lock (and the associated query) until write locks have expired on the table.
Ultimately this all means that:
For more information see: http://dev.mysql.com/doc/refman/5.5/en/internal-locking.html
reko_t 提供了一个很好的答案,我将尝试详细说明:
是的。
从本质上讲,MyISAM 的并发性很差。你可以尝试假装它,但无论你怎么看,它都是不好的。 MySQL / Oracle 最近没有尝试改进它(查看源代码,我并不感到惊讶 - 他们只会引入错误)。
如果您的工作负载包含大量检索大量行的“大”SELECT,或者在某些方面很难,它们可能经常重叠,这看起来可能没问题。但是单行更新或删除将阻止全部行。
reko_t provided a good answer, I will try to elaborate on it:
Yes.
Essentially, MyISAM has poor concurrency. You can try to fake it, but it's bad whichever way you look at it. MySQL / Oracle has made no attempts to improve it recently (looking at the source code, I'm not surprised - they'd only introduce bugs).
If you have a workload with lots of "big" SELECTs which retrieve lots of rows, or are hard in some way, they may often overlap, this may seem ok. But a single row update or delete will block the whole lot of them.