MySQL Math —— INTEGER 和 FLOAT 哪个更快?
我正在做一些需要大量连接行的查询,其中一些字段被添加并相乘。
我知道这有点模糊,但我的问题是哪种数字数据类型对于这些类型的操作最快?
由于 DOUBLE 是 8 个字节,而 FLOAT 是 4 个字节,因此 FLOAT 会比 DOUBLE 更快吗?
INT 会比 FLOAT 更快吗(即使它们都是 4 字节)?
DECIMAL 会比 FLOAT 更快吗?
这里有一些更多信息:我正在解决的问题允许我选择将“浮点”数字存储为 BIGINTEGER 的...我可以在插入它们之前将数字乘以 100000。如果 BIGINT 的数学运算比 FLOAT 的运算速度更快,我愿意这样做。
谢谢。
I'm doing some queries that require a lot of joined rows have some of their fields added and multiplied together.
I know it is sort of vague, but my question is which numeric data type is fastest for these types of operations?
Will FLOAT be faster than DOUBLE since DOUBLE is 8 bytes, and FLOAT is 4?
Will INT be faster than FLOAT (even if they are both 4 bytes)?
Will DECIMAL be faster than FLOAT?
Here's some more information: The problem I'm solving allows me the option to store "float" numbers as BIGINTEGER's... I can just multiply the number by 100000 before inserting them. I'd be willing to do this if BIGINT's math was faster than FLOAT's.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
字节大小影响数据检索,而不是基于它的计算。如有必要,索引可以改进这一点,但会减慢 UPDATE/INSERT/DELETE 语句的速度。
我建议选择反映您将要使用的操作的数据类型。如果您根本不需要精度,则没有理由考虑使用 DECIMAL 或 FLOAT。
The byte size impacts data retrieval, not calculation based on it. Indexes can improve this if necessary, but will slow down UPDATE/INSERT/DELETE statements.
I suggest choosing the data type that reflects the operations you're going to be using. If you don't need the precision at all, there's no reason to consider using DECIMAL or FLOAT.
一般来说,整数运算更快(而且更准确)。因为我实际上并没有在 MySQL 中工作,所以我不能肯定地说——但我肯定会打赌整数。
In general, integer operations are quicker (and more accurate). Since I don't actually work in MySQL I can't say for certain--but I'd certainly bet in favor of Integers.