search

Home  >  Q&A  >  body text

mysql optimization - how to explain the problem that mysql primary key is too long and causes secondary indexes to use more space. For example, using uuid as the primary key causes this problem

I thought of this after reading Meituan’s article: http://tech.meituan.com/MT_Le... but I don’t quite understand

mysql official original words are:

If the primary key is long, the secondary indexes use more space, so it is advantageous to have a short primary key

For example, if uuid is used as the primary key, the primary key space becomes larger. Why does it cause the secondary indexes space to also occupy a large space? I don’t understand

过去多啦不再A梦过去多啦不再A梦2833 days ago880

reply all(1)I'll reply

  • 習慣沉默

    習慣沉默2017-05-18 10:55:33

    All indexes other than the clustered index are known as secondary indexes. In InnoDB, each record in a secondary index contains the primary key columns for the row, as well as the columns specified for the secondary index. InnoDB uses this primary key value to search for the row in the clustered index.

    This is from the official document, which means that the secondary index will also include the primary, so the larger your primary key, the larger the space occupied by the secondary indexes

    Reference: https://dev.mysql.com/doc/ref...

    reply
    0
  • Cancelreply