MySQL 8.0-11.8 Choosing the Right Type for a Column

本文探讨了如何选择最适合的数据库类型以优化存储空间,并讨论了不同数据类型的计算精度问题。介绍了MEDIUMINT UNSIGNED等类型在特定数值范围内的优势,以及DECIMAL类型提供高精度计算的特点。同时,也提到了在速度优先的情况下可以考虑使用DOUBLE类型。

For optimum storage, you should try to use the most precise type in all cases. For example, if an integer column is used for values in the range from 1 to 99999MEDIUMINT UNSIGNED is the best type. Of the types that represent all the required values, this type uses the least amount of storage.

为了获得最佳的存储效果,您应该在所有情况下尝试使用最精确的类型。例如,如果整数列用于范围从1到99999的值,则MEDIUMINT UNSIGNED是最好的类型。在表示所有所需值的类型中,这种类型使用的存储空间最少。

All basic calculations (+-*, and /) with DECIMAL columns are done with precision of 65 decimal (base 10) digits. See Section 11.1.1, “Numeric Data Type Syntax”.

所有使用DECIMAL列的基本计算(+、-、*和/)都以65位小数(以10为基数)的精度完成。请参见11.1.1节“数字数据类型语法”。

If accuracy is not too important or if speed is the highest priority, the DOUBLE type may be good enough. For high precision, you can always convert to a fixed-point type stored in a BIGINT. This enables you to do all calculations with 64-bit integers and then convert results back to floating-point values as necessary.

如果精度不是太重要,或者速度是最重要的,DOUBLE型可能已经足够好了。对于高精度,您可以始终转换为存储在BIGINT中的定点类型。这使您能够使用64位整数进行所有计算,然后根据需要将结果转换回浮点值。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值