MySQL varchar唯一列varchar(255)与varchar(50) [英] Mysql varchar unique column varchar(255) vs. varchar(50)
问题描述
我将始终在表的特定列中输入20个字符.
I will always be entering things of 20 characters into a particular column in my table.
我需要此列是唯一的.
如果我将此列设置为varchar(255)而不是varchar(20),那么SELECT查询中是否会有速度差异?
Will there be any speed difference in SELECT queries if I set this column to be a varchar(255) instead of varchar(20)?
(输入的数据始终为20个字符)
(data entered will always be 20 characters)
推荐答案
如果输入的数据总是 20个字符,那么为什么不考虑使用 char(20).使用varchar(20)将使用20个字节存储字符,并使用1个字节存储长度.因此,如果有100万条记录,则会浪费100万个字节.
if data entered will always be 20 characters than why not consider using char(20). using varchar(20) will use 20 bytes for storing character and 1 byte for storing length. so if there are 1 million records, 1 million bytes will be wasted.
就varchar(20)和varchar(255)之间的速度而言,那么我认为选择它们之一可能很难,因为它们都将使用21个字节,我看不到任何显着的性能一个人的利益或损失.
as far as speed is concerned between varchar(20) and varchar(255), then I dont think it might be very hard to pick one of them, both of them will be using 21 bytes, I dont see any significant performance benefit or loss of one over other.
这篇关于MySQL varchar唯一列varchar(255)与varchar(50)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!