8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / 13 种数据类型 / 13.8 为列选择正确的类型
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

13.8 为列选择合适的类型13.8 Choosing the Right Type for a Column

为了获得最佳存储效果,你应该尽量在所有情况下使用最精确的类型。例如,如果一个整数列用于存储范围从 1 到 99999 的值,MEDIUMINT UNSIGNED 是最合适的类型。在能够表示所需所有值的类型中,该类型使用的存储空间最少。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.

所有使用 DECIMAL 列进行的基本计算(+、-、* 和 /)都具有 65 位十进制数字的精度。请参见 第 13.1.1 节,“数值数据类型语法”。All basic calculations (+, -, *, and /) with DECIMAL columns are done with precision of 65 decimal (base 10) digits. See Section 13.1.1, “Numeric Data Type Syntax”.

如果精确度不是特别重要,或者速度是最优先考虑的,DOUBLE类型可能已经足够。对于高精度,你总是可以转换为存储在BIGINT中的定点类型。这样你就可以用 64 位整数进行所有计算,然后在必要时将结果转换回浮点值。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.