8.7 Optimizing for MEMORY TablesMEMORY表的优化

Consider using MEMORY tables for noncritical data that is accessed often, and is read-only or rarely updated. 对于非经常访问的非关键数据,并且只读或很少更新,请考虑使用MEMORY表。Benchmark your application against equivalent InnoDB or MyISAM tables under a realistic workload, to confirm that any additional performance is worth the risk of losing data, or the overhead of copying data from a disk-based table at application start.在实际工作负载下,根据等效的InnoDBMyISAM表对应用程序进行基准测试,以确认任何额外的性能都值得冒数据丢失的风险,或在应用程序启动时从基于磁盘的表复制数据的开销。

For best performance with MEMORY tables, examine the kinds of queries against each table, and specify the type to use for each associated index, either a B-tree index or a hash index. 为了获得MEMORY表的最佳性能,请检查针对每个表的查询类型,并指定用于每个关联索引(B树索引或哈希索引)的类型。On the CREATE INDEX statement, use the clause USING BTREE or USING HASH. CREATE INDEX语句中,使用USING BTREEUSING HASH子句。B-tree indexes are fast for queries that do greater-than or less-than comparisons through operators such as > or BETWEEN. 对于通过>BETWEEN等运算符进行大于或小于比较的查询,B树索引速度很快。Hash indexes are only fast for queries that look up single values through the = operator, or a restricted set of values through the IN operator. 哈希索引仅适用于通过=运算符查找单个值或通过IN运算符查找受限值集的查询。For why USING BTREE is often a better choice than the default USING HASH, see Section 8.2.1.23, “Avoiding Full Table Scans”. 有关USING BTREE通常比默认USING HASH更好的原因,请参阅第8.2.1.23节,“避免全表扫描”For implementation details of the different types of MEMORY indexes, see Section 8.3.9, “Comparison of B-Tree and Hash Indexes”.有关不同类型MEMORY索引的实现细节,请参阅第8.3.9节,“B-树索引和哈希索引的比较”