简体   繁体   English

为什么 MyISAM 存储引擎不支持行级锁定作为 InnoDB

[英]Why MyISAM storage engine does not support row level locking as InnoDB

I have encountered this problem during an interview with one famous company, the question is:我在采访一家知名公司的时候遇到过这个问题,问题是:

Why MyISAM storage engine does not support row level locking as InnoDB storage engine为什么 MyISAM 存储引擎不支持行级锁定作为 InnoDB 存储引擎

As far as I know the main difference is that InnoDB has clustered index whereas MyISAM does not have.据我所知,主要区别在于 InnoDB 有聚集索引,而 MyISAM 没有。

I found from some blog saying that the reason why is:我从一些博客中发现,原因是:

Since MyISAM only has secondary index, in other words, the data and index are stored separately, it is will hurt the performance when lock the data and secondary index at the same time.由于MyISAM只有二级索引,也就是说数据和索引是分开存储的,同时锁定数据和二级索引会影响性能。

I cannot concur with this hint as I think some InnoDB table also has secondary index.我不同意这个提示,因为我认为一些 InnoDB 表也有二级索引。

MyISAM is an read optimized storage engine, non-MVCC, crash unsafe , storage engine that shouldn't be written to. MyISAM是一个读取优化的存储引擎,非 MVCC, 崩溃不安全,不应该被写入的存储引擎。

Having row locking is excessive to these purposes.拥有行锁定对于这些目的来说是多余的。

The clustering of the PK is not the main difference between the Engines. PK 的聚类并不是引擎之间的主要区别。

MyISAM was a quick-and-dirty Engine that worked fine most of the time. MyISAM 是一个快速而肮脏的引擎,大部分时间都运行良好。 For avoiding conflicts, a simple "table-level" locking mechanism was invented.为了避免冲突,发明了一种简单的“表级”锁定机制。

The main differences (and many of the secondary differences) stem from ACID .主要差异(以及许多次要差异)源于ACID InnoDB adds crash-safe features. InnoDB 添加了崩溃安全功能。 The Question expected you to understand that ne expoind on it.该问题希望您了解它的说明。

Row-level locking allows more concurrency between write operations, while also providing other aspects of ACID.行级锁定允许写入操作之间的更多并发,同时还提供了 ACID 的其他方面。

Atomic: If MyISAM dies in the middle of doing UPDATE t SET x=x+1 , some of the rows have been incremented;原子:如果 MyISAM 在执行UPDATE t SET x=x+1的过程中死掉,一些行已经增加; some have not.有些还没有。 There is no recovery (without reloading the data.) InnoDB stands on its head to guarantee "all or none".没有恢复(无需重新加载数据)。InnoDB 站在它的头上,以保证“全部或全部”。

Etc for Concistency, Isolation, and Durability.一致性、隔离性和耐用性等。

Having the PRIMARY KEY "clustered" with the data is not a requirement, even for an ACID-complient DB.PRIMARY KEY与数据“聚集”不是必需的,即使对于符合 ACID 的数据库也是如此。 (See competing vendors and how they use "row numbers".) With InnoDB, certain queries run faster due to this clustering of the PK. (请参阅竞争供应商以及他们如何使用“行号”。)使用 InnoDB,由于 PK 的这种集群,某些查询运行得更快。

Yes, InnoDB has secondary indexes.是的,InnoDB 有二级索引。 Both the main data and each secondary index is implemented via a B+Tree.主数据和每个二级索引都是通过 B+Tree 实现的。 But for secondary indexes, the key's column(s) plus the PK's column(s) are to be found in the leaf nodes.但是对于二级索引,键的列加上 PK 的列将在叶节点中找到。 There are pros and cons to this design, but it is not required这种设计有利有弊,但不是必须

MyISAM's indexes (PK and secondary are identical) are all in one file ( .MYI ) and contain the key's columns plus a 'pointer' to the data. MyISAM 的索引(PK辅助索引相同)都在一个文件( .MYI )中,并包含键的列以及指向数据的“指针”。 It is in a BTree structure.它采用 BTree 结构。 The Data is stored in a separate file ( .MYD ).数据存储在单独的文件 ( .MYD ) 中。 Rows are 'pointed' to either by a byte offset into the file or by a row number (if only fixed-length columns).行通过文件中的字节偏移量或行号(如果只有固定长度的列)“指向”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM