varchar字段 - 两个更有效率的力量? [英] varchar Fields - Is a Power of Two More Efficient?

查看:98
本文介绍了varchar字段 - 两个更有效率的力量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用两个与另一个数字的幂的varchar字段是否更有效?我在想,不,因为SQL Server的默认值为50.但是,我已经听到(但从来没有确认过),将大小字段设置为2的大小更有效率,因为它们等同于偶数字节,并且计算机处理位数;字节。那么,声明为varchar(32)还是varchar(64)的字段对varchar(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. 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. So, does a field declared as varchar(32) or varchar(64) have any real benefit over varchar(50)?

推荐答案

no。

在某些其他用途中,使用具有两个大小的结构的结构有一些优势,主要是因为您可以适合一个好的(两个数量)的数字这些都在另一个两尺寸的结构中。但是这不适用于DB fieldsize。

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(或TEXT / BLOB)的确切类型在某些SQL方言中):如果小于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)与$ code> 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆