For character and string columns, follow these guidelines:对于字符和字符串列,请遵循以下准则:
Use binary collation order for fast comparison and sort operations, when you do not need language-specific collation features. 当您不需要特定于语言的排序功能时,请使用二进制排序顺序进行快速比较和排序操作。You can use the 可以使用BINARY
operator to use binary collation within a particular query.BINARY
运算符在特定查询中使用二进制排序规则。
When comparing values from different columns, declare those columns with the same character set and collation wherever possible, to avoid string conversions while running the query.在比较不同列的值时,尽可能使用相同的字符集和排序规则声明这些列,以避免在运行查询时进行字符串转换。
For column values less than 8KB in size, use binary 对于大小小于8KB的列值,请使用二进制VARCHAR
instead of BLOB
. VARCHAR
而不是BLOB
。The GROUP BY
and ORDER BY
clauses can generate temporary tables, and these temporary tables can use the MEMORY
storage engine if the original table does not contain any BLOB
columns.GROUP BY
和ORDER BY
子句可以生成临时表,如果原始表不包含任何BLOB列,则这些临时表可以使用内存存储引擎。
If a table contains string columns such as name and address, but many queries do not retrieve those columns, consider splitting the string columns into a separate table and using join queries with a foreign key when necessary. 如果表包含字符串列(如名称和地址),但许多查询不检索这些列,则考虑将字符串列拆分为单独的表,并在必要时使用具有外键的联接查询。When MySQL retrieves any value from a row, it reads a data block containing all the columns of that row (and possibly other adjacent rows). 当MySQL从一行中检索任何值时,它会读取一个包含该行(可能还有其他相邻行)所有列的数据块。Keeping each row small, with only the most frequently used columns, allows more rows to fit in each data block. Such compact tables reduce disk I/O and memory usage for common queries.保持每一行较小,只使用最常用的列,允许在每个数据块中容纳更多的行。这样的紧凑表减少了常见查询的磁盘I/O和内存使用。
When you use a randomly generated value as a primary key in an 在InnoDB
table, prefix it with an ascending value such as the current date and time if possible. InnoDB
表中使用随机生成的值作为主键时,如果可能,请使用升序值(如当前日期和时间)作为前缀。When consecutive primary values are physically stored near each other, 当连续的主值彼此物理存储在一起时,InnoDB
can insert and retrieve them faster.InnoDB
可以更快地插入和检索它们。
See Section 8.4.2.1, “Optimizing for Numeric Data” for reasons why a numeric column is usually preferable to an equivalent string column.有关数字列通常优于等效字符串列的原因,请参阅第8.4.2.1节,“优化数字数据”。