8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

10.2.7 其他优化技巧10.2.7 Other Optimization Tips

本节列出了一些提高查询处理速度的杂项技巧:This section lists a number of miscellaneous tips for improving query processing speed:

  • 如果您的应用程序为了执行相关的更新而发出多个数据库请求,将这些语句合并到存储例程中可以提高性能。同样,如果您的应用程序基于多个列值或大量数据计算单个结果,将计算合并到可加载函数中也可以提高性能。由此产生的快速数据库操作随后可以被其他查询、应用程序,甚至用不同编程语言编写的代码重用。更多信息请参见第 27.2 节,“使用存储例程”和向 MySQL 添加函数。If your application makes several database requests to perform related updates, combining the statements into a stored routine can help performance. Similarly, if your application computes a single result based on several column values or large volumes of data, combining the computation into a loadable function can help performance. The resulting fast database operations are then available to be reused by other queries, applications, and even code written in different programming languages. See Section 27.2, “Using Stored Routines” and Adding Functions to MySQL for more information.

  • 要修复 ARCHIVE 表发生的任何压缩问题,请使用 OPTIMIZE TABLE。请参阅 第 18.5 节,“ARCHIVE 存储引擎”。To fix any compression issues that occur with ARCHIVE tables, use OPTIMIZE TABLE. See Section 18.5, “The ARCHIVE Storage Engine”.

  • 如果可能,将报告分类为 “实时” 或 “统计”,其中统计报告所需的数据仅从定期从实时数据生成的汇总表中创建。If possible, classify reports as “live” or as “statistical”, where data needed for statistical reports is created only from summary tables that are generated periodically from the live data.

  • 如果你的数据不太适合行列表结构,你可以将数据打包并存储到 BLOB 列中。在这种情况下,你必须在应用程序中提供代码来打包和解包信息,但这可能会节省读取和写入相关值集的 I/O 操作。If you have data that does not conform well to a rows-and-columns table structure, you can pack and store data into a BLOB column. In this case, you must provide code in your application to pack and unpack information, but this might save I/O operations to read and write the sets of related values.

  • 对于 Web 服务器,将图像和其他二进制资源存储为文件,并在数据库中存储路径名称而不是文件本身。大多数 Web 服务器在缓存文件方面比缓存数据库内容更有效,因此使用文件通常更快。(尽管在这种情况下,你必须自己处理备份和存储问题。)With Web servers, store images and other binary assets as files, with the path name stored in the database rather than the file itself. Most Web servers are better at caching files than database contents, so using files is generally faster. (Although you must handle backups and storage issues yourself in this case.)

  • 如果你需要非常高的速度,可以查看低级别的 MySQL 接口。例如,通过直接访问 MySQL InnoDB 或 MyISAM 存储引擎,与使用 SQL 接口相比,你可以获得显著的速度提升。If you need really high speed, look at the low-level MySQL interfaces. For example, by accessing the MySQL InnoDB or MyISAM storage engine directly, you could get a substantial speed increase compared to using the SQL interface.

    类似地,对于使用 NDBCLUSTER 存储引擎的数据库,你可能希望研究 NDB API 的可能用途(请参见 MySQL NDB Cluster API 开发者指南)。Similarly, for databases using the NDBCLUSTER storage engine, you may wish to investigate possible use of the NDB API (see MySQL NDB Cluster API Developer Guide).

  • 复制可以为某些操作提供性能优势。您可以将客户端的检索操作分配到多个副本以分担负载。为了在备份时避免减慢源的速度,您可以使用副本进行备份。请参见第 19 章,复制。Replication can provide a performance benefit for some operations. You can distribute client retrievals among replicas to split up the load. To avoid slowing down the source while making backups, you can make backups using a replica. See Chapter 19, Replication.