Smallint 与 int 的性能比较
如果我知道列的值应始终在smallint数据类型允许的范围内,那么从数据完整性维护的角度来看,我似乎应该将数据存储在smallint列而不是int列中。
但是我想知道是否可以通过使用更少的字节来支付任何性能损失?
If I know that the value of a column should always be in teh range allowed by the smallint data type, from a data integrity maintenance point of view, it would seem to behoove me to store the data in a smallint column rather than an int column.
However I am wondering whether there are any performance hits that may be paid by using less bytes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
较小的类型=较少的磁盘存储空间,这会带来更高效的索引。然而,除非处理大量数据,否则这些性能提升将是微乎其微的;此外,为了避免隐式转换(这可能会抵消您看到的任何性能提升),您需要确保每次引用该列时都使用正确的类型(包括与参数的比较等)。
可能无论哪种方式都要洗。
Smaller types = less storage on disk, which leads to more efficient indexes. However, those performance gains will be minimal unless dealing with a large volume of data; furthermore, in order to avoid implicit conversions (which may offset any performance gains you see), you'll need to be sure that any time you reference that column that you use the correct type (including comparisons to parameters, etc).
Probably a wash either way.
正如斯图尔特提到的,我预计性能和存储差异可以忽略不计。
还值得考虑您想要使用给定类型建模的“域”。如果 Smallint 更准确地对数据域进行建模,那么就值得将其明确化,即使它不会给您带来明显的性能改进。
As Stuart mentions, I expect the performance and storage differences are quite negligible.
It is also worth considering the "domain" you want to model with the given type. If smallint more accurately models the domain for the data, then its worth making it explicit, even if it doesn't give you a noticeable performance improvement.