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 aMERGEtable 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. AMERGEtable 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 aMERGEtable for others. You can even have many differentMERGEtables that use overlapping sets of tables.执行更高效的修复。修复映射到
MERGE表的单个小表比修复单个大表更容易。Perform more efficient repairs. It is easier to repair individual smaller tables that are mapped to aMERGEtable than to repair a single large table.瞬间将多张表映射为一张表。一个
MERGE表不需要维护自己的索引,因为它使用各个表的索引。因此,MERGE表集合的创建或重新映射速度非常快。(即使没有创建索引,在创建MERGE表时,你仍然必须指定索引定义。)Instantly map many tables as one. AMERGEtable need not maintain an index of its own because it uses the indexes of the individual tables. As a result,MERGEtable collections are very fast to create or remap. (You must still specify the index definitions when you create aMERGEtable, 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 aMERGEtable 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. EachMyISAMtable is bound by this limit, but a collection ofMyISAMtables is not.您可以通过定义一个映射到该单个表的
MERGE表,为MyISAM表创建别名或同义词。这样做几乎不会有明显的性能影响(每次读取只需几次间接调用和memcpy()调用)。You can create an alias or synonym for aMyISAMtable by defining aMERGEtable that maps to that single table. There should be no really notable performance impact from doing this (only a couple of indirect calls andmemcpy()calls for each read).
MERGE 表的缺点是:The disadvantages of MERGE tables are:
您只能使用相同的
MyISAM表来创建MERGE表。You can use only identicalMyISAMtables for aMERGEtable.某些
MyISAM功能在MERGE表中不可用。例如,您不能在MERGE表上创建FULLTEXT索引。(您可以在底层的MyISAM表上创建FULLTEXT索引,但不能使用全文搜索在MERGE表中进行搜索。)SomeMyISAMfeatures are unavailable inMERGEtables. For example, you cannot createFULLTEXTindexes onMERGEtables. (You can createFULLTEXTindexes on the underlyingMyISAMtables, but you cannot search theMERGEtable with a full-text search.)如果
MERGE表是非临时的,则所有底层MyISAM表必须是非临时的。如果MERGE表是临时的,则MyISAM表可以是任何临时和非临时的混合。If theMERGEtable is nontemporary, all underlyingMyISAMtables must be nontemporary. If theMERGEtable is temporary, theMyISAMtables can be any mix of temporary and nontemporary.MERGE表使用的文件描述符比MyISAM表多。如果 10 个客户端正在使用映射到 10 个表的MERGE表,服务器将使用 (10 × 10) + 10 个文件描述符。(每个客户端 10 个数据文件描述符,以及客户端共享的 10 个索引文件描述符。)MERGEtables use more file descriptors thanMyISAMtables. If 10 clients are using aMERGEtable 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, theMERGEstorage 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, theMERGEstorage 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 makesMERGEindexes much slower oneq_refsearches, but not much slower onrefsearches. For more information abouteq_refandref, see Section 15.8.2, “EXPLAIN Statement”.