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 99999, MEDIUMINT 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位整数进行所有计算,然后根据需要将结果转换回浮点值。
本文探讨了如何选择最适合的数据库类型以优化存储空间,并讨论了不同数据类型的计算精度问题。介绍了MEDIUMINT UNSIGNED等类型在特定数值范围内的优势,以及DECIMAL类型提供高精度计算的特点。同时,也提到了在速度优先的情况下可以考虑使用DOUBLE类型。

被折叠的 条评论
为什么被折叠?



