[英]Inserting performance for UUID primary_key index
I have read that the insert performance for UUID as a primary_key depends on how many records exists in the database.我读到 UUID 作为 primary_key 的插入性能取决于数据库中存在的记录数。 With the greater number of records the more time it taking to insert records
记录数量越多,插入记录所需的时间就越多
https://kccoder.com/mysql/uuid-vs-int-insert-performance/ https://kccoder.com/mysql/uuid-vs-int-insert-performance/
The author for the above article has run experiments, he thinks its because there are greater number of reads for UUID primary_key insert than other auto incremented integers.上面文章的作者进行了实验,他认为这是因为 UUID primary_key insert 的读取次数比其他自增整数要多。
I wanted to ask whether databases automatically create an index for the the chosen primary_key If the UUID primary_key index is the problem, would the insert problem be solved by using an integer as the primary_key index while still keeping the UUID field, then switching the primary keys to UUID, the problem then is would the foreign key references to integer ID propagate to the UUID field upon the switching?我想问一下数据库是否自动为选择的primary_key创建索引如果UUID的primary_key索引有问题,插入问题是否可以通过使用整数作为primary_key索引同时保留UUID字段,然后切换主键来解决到 UUID,那么问题是对整数 ID 的外键引用是否会在切换时传播到 UUID 字段?
whether databases automatically create an index for the the chosen primary_key
数据库是否自动为选定的 primary_key 创建索引
Yes.是的。 Primary keys are always indexed.
主键总是被索引。 In some databases, the index is a clustered index (meaning that the data on the data pages is actually sorted by the key).
在某些数据库中,索引是聚集索引(意味着数据页上的数据实际上是按键排序的)。 In other databases, the index is to enforce the uniqueness constraint.
在其他数据库中,索引是强制执行唯一性约束的。
The issue with UUIDs and indexes is that new values are not necessarily larger than older values. UUID 和索引的问题在于新值不一定大于旧值。 That means that an insert is typically going "between" two existing records.
这意味着插入通常在两个现有记录之间进行。 When this happens you have fragmentation -- that is, existing data pages need to make room for new records and sometimes even split into two pages.
发生这种情况时,您会产生碎片——也就是说,现有数据页需要为新记录腾出空间,有时甚至分成两页。
An auto-incremented integer does not have this problem.自增整数没有这个问题。 It to is indexed (and clustered in MySQL).
它被索引(并在 MySQL 中聚集)。 However, the newer values are bigger than any existing value -- the definition of auto-incrementing.
但是,较新的值比任何现有值都大——自动递增的定义。 So, new values go at the end.
所以,新的价值会在最后。 Fragmentation is only an issue when rows are deleted or if you manually set the value.
碎片仅在行被删除或手动设置值时才会出现。
I would recommend that you use auto-incremented primary keys unless you have a specific reason for UUIDs.我建议您使用自动递增的主键,除非您有使用 UUID 的特定原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.