使用长整数作为SQL索引的性能影响。

huangapple go评论59阅读模式
英文:

Perfomance impact using long values for SQL index

问题

例如:我有这张表 -

表 User (id (bigint(20) 主键,session_id (bigint(20),key(varchar(24) )

在该表中有一个包括session_id(bigint(20))和key(varchar(24) )列的唯一索引。

如果我将'key'列更改为varchar(255)(在此列上使用长值),系统会受到性能影响吗?

我正在使用Mysql数据库(AWS Aurora)。

英文:

For example: I have the table -

table User (id (bigint(20) primary key, session_id (bigint(20), key(varchar(24) )

There is a unique index in that table including both session_id(bigint(20)) and key(varchar(24) ) columns.

Can there be a performance impact to system if I will change 'key' column to varchar(255) (use long values for this column) , since it is a part of a unique index?

I'm using Mysql database(AWS Aurora).

答案1

得分: 1

短答案:没有明显的性能影响。

长答案:

  • PRIMARY KEY 是一个 UNIQUE 索引;两者都是索引。(也就是说,不要创建多余的索引。)
  • 索引中的 VARCUAR 主要基于实际字符串的平均长度来影响性能。最大长度并不重要(除非达到某些限制,比如3072字节)。
  • 影响性能的最大因素是所涉及的行数。索引有助于最小化这一点。
英文:

Short Answer: No significant performance impact.

Long Answer:

  • The PRIMARY KEY is a UNIQUE index; both are INDEXes. (That is, do not make redundant indexes.)
  • The impact of a VARCUAR in an index is mostly based on the average length of the actual strings. The max length does not matter (unless it hits some limit, such as 3072 bytes).
  • The number of rows touched is the biggest factor in performance. Indexes help minimize that.

huangapple
  • 本文由 发表于 2023年6月19日 20:29:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76506644.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定