varchar 字段 - 两个的幂是否更有效? [英] varchar Fields - Is a Power of Two More Efficient?
问题描述
使用大小为 2 的幂的 varchar
字段比另一个数字更有效吗?我想不是,因为对于 SQL Server,默认值为 50.
Is it more efficient to use a varchar
field sized as a power of two vs. another number? I'm thinking no, because for SQL Server the default is 50.
但是,我听说(但从未证实)将字段大小设置为 2 的幂更有效,因为它们等同于偶数字节,并且计算机以位为单位进行处理字节.
However, I've heard (but never confirmed) that sizing fields as a power of 2 is more efficient because they equate to even bytes, and computers process in bits & bytes.
那么,声明为 varchar(32)
或 varchar(64)
的字段是否比 varchar(50)
有任何真正的好处?
So, does a field declared as varchar(32)
or varchar(64)
have any real benefit over varchar(50)
?
推荐答案
没有
在其他一些用途中,使用具有 2 次幂大小的结构有一些优势,主要是因为您可以将这些(2 的幂)的数量放入另一个大小为 2 的幂的结构中.但这不适用于 DB 字段大小.
In some other uses, there are some advantages to use structures with a power of two size, mostly because you can fit a nice (power of two) number of these inside another power-of-two-sized structure. But this doesn't apply to a DB fieldsize.
与 VARCHAR 相关的唯一二次幂大小是关于 varchar 的确切类型(或某些 SQL 方言中的 TEXT/BLOB):如果它小于 256,它可以使用单个字节来表示长度.如果小于65536(64KB),两个字节就够了,三个字节到16777216(16MB),四个字节到4294967296(4GB).
The only power-of-two-sizing related to VARCHARs is about the exact type of varchar (or TEXT/BLOB in some SQL dialects): if it's less than 256, it can use a single byte to indicate length. if it's less than 65536 (64KB), two bytes are enough, three bytes work up to 16777216 (16MB), four bytes go to 4294967296 (4GB).
此外,可以说 VARCHAR(50)
与 VARCHAR(255)
一样昂贵,因为两者都需要 n+1 字节的存储空间.
Also, it can be argued that VARCHAR(50)
is just as expensive as VARCHAR(255)
, since both will need n+1 bytes of storage.
当然那是在考虑 Unicode 之前...
Of course that's before thinking of Unicode...
这篇关于varchar 字段 - 两个的幂是否更有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!