对于数据库,选择正确的数据类型是否会影响性能? [英] For databases, does choosing the correct data type affect performance?

查看:325
本文介绍了对于数据库,选择正确的数据类型是否会影响性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果是,为什么?



如果是这样,实际的性能差异是什么?



int

/ code>与 tinyint 不会在速度上产生明显的差异,但它会使数据大小有所不同。假设 tinyint 为1字节,而 int 为4,每行保存3个字节。



现在,如果 int 针对 varchar ,那么会有一点点下降,因为类似的东西在整数值比字符串值要快得多。



如果它是一个可比类型,你不是太紧张的空间,去与更容易和更强大的。


And if so, why? I mean, is a tinyint faster to search than int?

If so, what are the practical differences in performance?

解决方案

Depending on the data types, yes, it does make a difference.

int vs. tinyint wouldn't make a noticeable difference in speed, but it would make a difference in data sizes. Assuming tinyint is 1 byte, versus int being 4, that's 3 bytes saved every row. it adds up after awhile.

Now, if it was int against varchar, then there would be a bit of a drop, as things like sorts would be much faster on integer values than string values.

If it's a comparable type, and you're not very pressed for space, go with the one that's easier and more robust.

这篇关于对于数据库,选择正确的数据类型是否会影响性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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