8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

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

18.7.1 MERGE 表的优点和缺点18.7.1 MERGE Table Advantages and Disadvantages

MERGE 表可以帮助你解决以下问题:MERGE tables can help you solve the following problems:

  • 轻松管理一组日志表。例如,你可以将不同月份的数据放入不同的表中,用 myisampack 压缩其中一些,然后创建一个 MERGE 表将它们作为一个表来使用。Easily manage a set of log tables. For example, you can put data from different months into separate tables, compress some of them with myisampack, and then create a MERGE table to use them as one.

  • 获得更高速度。你可以根据某些条件拆分一个大型只读表,然后将各个表放在不同的磁盘上。以这种方式构建的 MERGE 表可能比使用单个大表快得多。Obtain more speed. You can split a large read-only table based on some criteria, and then put individual tables on different disks. A MERGE table structured this way could be much faster than using a single large table.

  • 执行更高效的搜索。如果你确切知道自己在寻找什么,你可以在某些查询中仅搜索一个底层表,而在其他查询中使用MERGE表。你甚至可以拥有许多不同的MERGE表,这些表使用重叠的表集合。Perform more efficient searches. If you know exactly what you are looking for, you can search in just one of the underlying tables for some queries and use a MERGE table for others. You can even have many different MERGE tables that use overlapping sets of tables.

  • 执行更高效的修复。修复映射到MERGE表的单个小表比修复单个大表更容易。Perform more efficient repairs. It is easier to repair individual smaller tables that are mapped to a MERGE table than to repair a single large table.

  • 瞬间将多张表映射为一张表。一个 MERGE 表不需要维护自己的索引,因为它使用各个表的索引。因此,MERGE 表集合的创建或重新映射速度非常快。(即使没有创建索引,在创建 MERGE 表时,你仍然必须指定索引定义。)Instantly map many tables as one. A MERGE table need not maintain an index of its own because it uses the indexes of the individual tables. As a result, MERGE table collections are very fast to create or remap. (You must still specify the index definitions when you create a MERGE table, even though no indexes are created.)

  • 如果你有一组表,并且需要按需创建一张大表,你可以改为按需从它们创建一个 MERGE 表。这要快得多,同时节省大量磁盘空间。If you have a set of tables from which you create a large table on demand, you can instead create a MERGE table from them on demand. This is much faster and saves a lot of disk space.

  • 超出操作系统的文件大小限制。每个 MyISAM 表都受此限制约束,但一组 MyISAM 表的集合则不受此限制。Exceed the file size limit for the operating system. Each MyISAM table is bound by this limit, but a collection of MyISAM tables is not.

  • 您可以通过定义一个映射到该单个表的 MERGE 表,为 MyISAM 表创建别名或同义词。这样做几乎不会有明显的性能影响(每次读取只需几次间接调用和 memcpy() 调用)。You can create an alias or synonym for a MyISAM table by defining a MERGE table that maps to that single table. There should be no really notable performance impact from doing this (only a couple of indirect calls and memcpy() calls for each read).

MERGE 表的缺点是:The disadvantages of MERGE tables are:

  • 您只能使用相同的 MyISAM 表来创建 MERGE 表。You can use only identical MyISAM tables for a MERGE table.

  • 某些 MyISAM 功能在 MERGE 表中不可用。例如,您不能在 MERGE 表上创建 FULLTEXT 索引。(您可以在底层的 MyISAM 表上创建 FULLTEXT 索引,但不能使用全文搜索在 MERGE 表中进行搜索。)Some MyISAM features are unavailable in MERGE tables. For example, you cannot create FULLTEXT indexes on MERGE tables. (You can create FULLTEXT indexes on the underlying MyISAM tables, but you cannot search the MERGE table with a full-text search.)

  • 如果 MERGE 表是非临时的,则所有底层 MyISAM 表必须是非临时的。如果 MERGE 表是临时的,则 MyISAM 表可以是任何临时和非临时的混合。If the MERGE table is nontemporary, all underlying MyISAM tables must be nontemporary. If the MERGE table is temporary, the MyISAM tables can be any mix of temporary and nontemporary.

  • MERGE 表使用的文件描述符比 MyISAM 表多。如果 10 个客户端正在使用映射到 10 个表的 MERGE 表,服务器将使用 (10 × 10) + 10 个文件描述符。(每个客户端 10 个数据文件描述符,以及客户端共享的 10 个索引文件描述符。) MERGE tables use more file descriptors than MyISAM tables. If 10 clients are using a MERGE table that maps to 10 tables, the server uses (10 × 10) + 10 file descriptors. (10 data file descriptors for each of the 10 clients, and 10 index file descriptors shared among the clients.)

  • 索引读取较慢。当你读取索引时,MERGE 存储引擎需要对所有底层表执行读取,以检查哪个表最接近给定的索引值。要读取下一个索引值,MERGE 存储引擎需要搜索读取缓冲区以找到下一个值。只有当某个索引缓冲区用完时,存储引擎才需要读取下一个索引块。这使得 MERGE 索引在 eq_ref 查询中速度慢得多,但在 ref 查询中不会慢太多。有关 eq_ref 和 ref 的更多信息,请参见 第 15.8.2 节,“EXPLAIN 语句”。Index reads are slower. When you read an index, the MERGE storage engine needs to issue a read on all underlying tables to check which one most closely matches a given index value. To read the next index value, the MERGE storage engine needs to search the read buffers to find the next value. Only when one index buffer is used up does the storage engine need to read the next index block. This makes MERGE indexes much slower on eq_ref searches, but not much slower on ref searches. For more information about eq_ref and ref, see Section 15.8.2, “EXPLAIN Statement”.