Perfomance impact using long values for SQL index

56 views Asked by At

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

There are 1 answers

0
Rick James On

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.