This section lists a number of miscellaneous tips for improving query processing speed:本节列出了一些提高查询处理速度的其他技巧:
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 25.2, “Using Stored Routines” and Adding Functions to MySQL for more information.有关更多信息,请参阅第25.2节,“使用存储例程”和向MySQL添加函数。
To fix any compression issues that occur with 若要修复ARCHIVE
tables, use OPTIMIZE TABLE
. ARCHIVE
表中出现的任何压缩问题,请使用OPTIMIZE TABLE
。See Section 16.5, “The ARCHIVE Storage Engine”.请参阅第16.5节,“ARCHIVE存储引擎”。
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.如果可能,将报告分类为“实时”或“统计”,其中统计报告所需的数据仅从实时数据定期生成的汇总表中创建。
If you have data that does not conform well to a rows-and-columns table structure, you can pack and store data into a 如果您的数据不符合rows和columns表结构,则可以将数据打包并存储到BLOB
column. BLOB
列中。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.在这种情况下,您必须在应用程序中提供代码来打包和解包信息,但这可能会节省读取和写入相关值集的I/O操作。
With Web servers, store images and other binary assets as files, with the path name stored in the database rather than the file itself. 对于Web服务器,将图像和其他二进制资产存储为文件,路径名存储在数据库中,而不是文件本身。Most Web servers are better at caching files than database contents, so using files is generally faster. 大多数Web服务器在缓存文件方面比数据库内容更好,因此使用文件通常更快。(Although you must handle backups and storage issues yourself in this case.)(尽管在这种情况下,您必须自己处理备份和存储问题。)
If you need really high speed, look at the low-level MySQL interfaces. 如果您需要非常高的速度,请查看底层MySQL接口。For example, by accessing the MySQL 例如,通过直接访问MySQL InnoDB
or MyISAM
storage engine directly, you could get a substantial speed increase compared to using the SQL interface.InnoDB
或MyISAM
存储引擎,与使用SQL接口相比,您可以获得显著的速度提升。
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).NDBCLUSTER
存储引擎的数据库,您可能希望调查NDB API的可能使用(请参阅MySQL NDB Cluster API开发者指南)。
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 17, Replication.请参阅第17章,“复制”。