Smallint 与 int 的性能比较

发布于 2024-12-12 07:34:22 字数 121 浏览 0 评论 0原文

如果我知道列的值应始终在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷默言语 2024-12-19 07:34:22

较小的类型=较少的磁盘存储空间,这会带来更高效的索引。然而,除非处理大量数据,否则这些性能提升将是微乎其微的;此外,为了避免隐式转换(这可能会抵消您看到的任何性能提升),您需要确保每次引用该列时都使用正确的类型(包括与参数的比较等)。

可能无论哪种方式都要洗。

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.

泼猴你往哪里跑 2024-12-19 07:34:22

正如斯图尔特提到的,我预计性能和存储差异可以忽略不计。

还值得考虑您想要使用给定类型建模的“域”。如果 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文