InnoDB复合索引顺序和INSERT性能

编程入门 行业动态 更新时间:2024-10-28 18:36:31
本文介绍了InnoDB复合索引顺序和INSERT性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个包含3列的MySQL表,我想在该表上使用多列索引.列A为TINYINT,B为SMALLINT,C为VARBINARY(16).我是否应该将索引用作A,B,C,因为A的粒度低于B,B的粒度低于C,以实现最大的INSERT速度?

I have a MySQL table with 3 columns on which I'd like to use a multi-column index. Column A is TINYINT, B is SMALLINT and C is VARBINARY (16). Should I use the index as A, B, C, because A has lower granularity than B and B lower than C to achieve maximum INSERT speed?

推荐答案

(注意:此答案澄清或不同意已经写过的一些评论.)

(Note: This answer clarifies or disagrees with some of the comments already written.)

DELETEs由于删除索引条目而减慢了速度. UPDATEs 可能会变慢-这取决于是否更改了索引列.

DELETEs are slowed down because of deleting the index entries. UPDATEs may be slowed down -- it depends on whether an indexed column is changed.

SELECTs,UPDATEs和DELETEs,但不是INSERTs,需要查找该行;为此,索引可能会有所帮助.

SELECTs, UPDATEs, and DELETEs, but not INSERTs, need to find the row(s); for this, an index may help a lot.

如果要检查UNIQUE索引,则INSERT会受到额外的伤害.

An INSERT is hurt an extra amount if there is a UNIQUE index to check.

次要密钥(在InnoDB中),UNIQUE密钥的除外,在延迟"中被更新(通常是由于INSERT和DELETE,但可能是由于UPDATE)通过称为更改缓冲区"的方式.这有效地推迟了更新索引的时间,但仍保持索引完全可用.

Secondary keys (in InnoDB), except for UNIQUE keys, are updated (usually due to INSERT and DELETE, but possibly due to UPDATE) in a 'delayed' way via what is called the "Change Buffer". This effectively puts off updating the index, but still keeps the index fully usable.

所有这些都不受索引中列顺序的影响.但是,如果索引大于可在RAM中缓存的索引,则缓存"将起作用,并且可能会或可能不会涉及I/O.但这是另一个话题.

None of this is impacted by the order of the columns in an index. However, if an index is bigger than can be cached in RAM, "caching" comes into play, and I/O may or may not be involved. But that is another topic.

通常,用于读取的索引中的好处远胜于写入操作的速度.

In general the benefit from an index for reading far outweighs the slowdown for write operations.

更多推荐

InnoDB复合索引顺序和INSERT性能

本文发布于:2023-10-23 03:36:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519642.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:顺序   索引   性能   InnoDB   INSERT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!