8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

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

18.7.2 MERGE 表问题18.7.2 MERGE Table Problems

以下是已知的 MERGE 表问题:The following are known problems with MERGE tables:

  • MERGE 子表通过父表被锁定。如果父表是临时表,它不会被锁定,因此子表也不会被锁定;这意味着并行使用底层的 MyISAM 表会导致它们损坏。MERGE child tables are locked through the parent table. If the parent is a temporary table, it is not locked, and thus the child tables are also not locked; this means that parallel use of the underlying MyISAM tables corrupts them.

  • 如果你使用 ALTER TABLE 将一个 MERGE 表更改为另一种存储引擎,则与底层表的映射将丢失。相反,底层 MyISAM 表中的行会被复制到修改后的表中,然后该表使用指定的存储引擎。If you use ALTER TABLE to change a MERGE table to another storage engine, the mapping to the underlying tables is lost. Instead, the rows from the underlying MyISAM tables are copied into the altered table, which then uses the specified storage engine.

  • MERGE 表的 INSERT_METHOD 表选项指示用于向 MERGE 表插入数据的底层 MyISAM 表。然而,在至少向该 MyISAM 表直接插入一行之前,为该 MyISAM 表使用的 AUTO_INCREMENT 表选项对向 MERGE 表的插入没有影响。The INSERT_METHOD table option for a MERGE table indicates which underlying MyISAM table to use for inserts into the MERGE table. However, use of the AUTO_INCREMENT table option for that MyISAM table has no effect for inserts into the MERGE table until at least one row has been inserted directly into the MyISAM table.

  • MERGE 表无法在整个表上维护唯一性约束。当你执行 INSERT 操作时,数据会进入第一个或最后一个 MyISAM 表(由 INSERT_METHOD 选项决定)。MySQL 确保唯一键值在该 MyISAM 表内保持唯一,但在集合中的所有底层表中并不保证唯一。A MERGE table cannot maintain uniqueness constraints over the entire table. When you perform an INSERT, the data goes into the first or last MyISAM table (as determined by the INSERT_METHOD option). MySQL ensures that unique key values remain unique within that MyISAM table, but not over all the underlying tables in the collection.

  • 由于 MERGE 引擎无法对底层表集合强制唯一性约束,REPLACE 不能按预期工作。两个关键事实是:Because the MERGE engine cannot enforce uniqueness over the set of underlying tables, REPLACE does not work as expected. The two key facts are:

    • REPLACE 只能检测其将要写入的基础表中的唯一键冲突(由 INSERT_METHOD 选项决定)。这与 MERGE 表本身中的冲突不同。REPLACE can detect unique key violations only in the underlying table to which it is going to write (which is determined by the INSERT_METHOD option). This differs from violations in the MERGE table itself.

    • 如果 REPLACE 检测到唯一键冲突,它只会更改它正在写入的基础表中的相应行;也就是说,依据 INSERT_METHOD 选项确定的第一个或最后一个表。If REPLACE detects a unique key violation, it changes only the corresponding row in the underlying table it is writing to; that is, the first or last table, as determined by the INSERT_METHOD option.

    类似的考虑也适用于 INSERT ... ON DUPLICATE KEY UPDATE。Similar considerations apply for INSERT ... ON DUPLICATE KEY UPDATE.

  • MERGE 表不支持分区。也就是说,你不能对 MERGE 表进行分区,也不能对 MERGE 表的任何底层 MyISAM 表进行分区。MERGE tables do not support partitioning. That is, you cannot partition a MERGE table, nor can any of a MERGE table's underlying MyISAM tables be partitioned.

  • 你不应该对任何映射到开放的 MERGE 表的表使用 ANALYZE TABLE、REPAIR TABLE、OPTIMIZE TABLE、ALTER TABLE、DROP TABLE、DELETE(没有 WHERE 子句),或 TRUNCATE TABLE。如果这样做,MERGE 表可能仍然引用原始表,并产生意外结果。为了解决这个问题,请确保在执行上述操作之前,通过执行 FLUSH TABLES 语句关闭所有 MERGE 表。You should not use ANALYZE TABLE, REPAIR TABLE, OPTIMIZE TABLE, ALTER TABLE, DROP TABLE, DELETE without a WHERE clause, or TRUNCATE TABLE on any of the tables that are mapped into an open MERGE table. If you do so, the MERGE table may still refer to the original table and yield unexpected results. To work around this problem, ensure that no MERGE tables remain open by issuing a FLUSH TABLES statement prior to performing any of the named operations.

    意外的结果包括在 MERGE 表上操作时可能报告表损坏。如果在对基础 MyISAM 表执行命名操作之后发生这种情况,损坏消息是虚假的。为了解决这个问题,在修改 MyISAM 表之后发出 FLUSH TABLES 语句。The unexpected results include the possibility that the operation on the MERGE table reports table corruption. If this occurs after one of the named operations on the underlying MyISAM tables, the corruption message is spurious. To deal with this, issue a FLUSH TABLES statement after modifying the MyISAM tables.

  • DROP TABLE 对正在被 MERGE 表使用的表在 Windows 上无法工作,因为 MERGE 存储引擎的表映射对 MySQL 的上层是隐藏的。Windows 不允许删除打开的文件,因此您必须先刷新所有 MERGE 表(使用 FLUSH TABLES)或在删除表之前删除 MERGE 表。DROP TABLE on a table that is in use by a MERGE table does not work on Windows because the MERGE storage engine's table mapping is hidden from the upper layer of MySQL. Windows does not permit open files to be deleted, so you first must flush all MERGE tables (with FLUSH TABLES) or drop the MERGE table before dropping the table.

  • 在访问表时(例如,作为 SELECT 或 INSERT 语句的一部分),会检查 MyISAM 表和 MERGE 表的定义。这些检查通过比较列顺序、类型、大小以及相关索引,确保表的定义与父 MERGE 表的定义匹配。如果表之间存在差异,将返回错误并导致语句失败。由于这些检查在打开表时进行,对单个表的任何定义更改,包括列更改、列顺序调整和存储引擎修改,都将导致语句失败。The definition of the MyISAM tables and the MERGE table are checked when the tables are accessed (for example, as part of a SELECT or INSERT statement). The checks ensure that the definitions of the tables and the parent MERGE table definition match by comparing column order, types, sizes and associated indexes. If there is a difference between the tables, an error is returned and the statement fails. Because these checks take place when the tables are opened, any changes to the definition of a single table, including column changes, column ordering, and engine alterations cause the statement to fail.

  • MERGE 表及其底层表中索引的顺序应当一致。如果您使用 ALTER TABLE 向用于 MERGE 表的表添加 UNIQUE 索引,然后再使用 ALTER TABLE 向 MERGE 表添加非唯一索引,如果底层表中已有非唯一索引,则表的索引顺序将不同。(这是因为 ALTER TABLE 会将 UNIQUE 索引放在非唯一索引前,以便快速检测重复键。)因此,对具有此类索引的表执行查询可能返回意外结果。The order of indexes in the MERGE table and its underlying tables should be the same. If you use ALTER TABLE to add a UNIQUE index to a table used in a MERGE table, and then use ALTER TABLE to add a nonunique index on the MERGE table, the index ordering is different for the tables if there was already a nonunique index in the underlying table. (This happens because ALTER TABLE puts UNIQUE indexes before nonunique indexes to facilitate rapid detection of duplicate keys.) Consequently, queries on tables with such indexes may return unexpected results.

  • 如果你遇到类似于 ERROR 1017 (HY000):找不到文件:'tbl_name.MRG' (errno: 2) 的错误信息,这通常表示某些底层表没有使用 MyISAM 存储引擎。请确认所有这些表都是 MyISAM。If you encounter an error message similar to ERROR 1017 (HY000): Can't find file: 'tbl_name.MRG' (errno: 2), it generally indicates that some of the underlying tables do not use the MyISAM storage engine. Confirm that all of these tables are MyISAM.

  • MERGE 表的最大行数是 264(约 1.844E19;与 MyISAM 表相同)。无法将多个 MyISAM 表合并成一个行数超过此数量的 MERGE 表。The maximum number of rows in a MERGE table is 264 (~1.844E+19; the same as for a MyISAM table). It is not possible to merge multiple MyISAM tables into a single MERGE table that would have more than this number of rows.

  • 当前已知使用具有不同行格式的底层 MyISAM 表与父 MERGE 表时会失败。请参见 Bug #32364。Use of underlying MyISAM tables of differing row formats with a parent MERGE table is currently known to fail. See Bug #32364.

  • 当 MERGE 生效时,你不能更改非临时 LOCK TABLES 表的并集列表。以下操作 不起作用:You cannot change the union list of a nontemporary MERGE table when LOCK TABLES is in effect. The following does not work:

    CREATE TABLE m1 ... ENGINE=MRG_MYISAM ...;
    LOCK TABLES t1 WRITE, t2 WRITE, m1 WRITE;
    ALTER TABLE m1 ... UNION=(t1,t2) ...;
    

    但是,你可以在临时 MERGE 表上执行此操作。However, you can do this with a temporary MERGE table.

  • 你不能使用 CREATE ... SELECT 创建 MERGE 表,无论是临时 MERGE 表还是非临时 MERGE 表。例如:You cannot create a MERGE table with CREATE ... SELECT, neither as a temporary MERGE table, nor as a nontemporary MERGE table. For example:

    CREATE TABLE m1 ... ENGINE=MRG_MYISAM ... SELECT ...;

    尝试这样做会导致错误:tbl_name 不是 BASE TABLE。Attempts to do this result in an error: tbl_name is not BASE TABLE.

  • 在某些情况下,如果底层表包含 CHAR 或 BINARY 列,MERGE 表与底层表之间 PACK_KEYS 表选项值不同,可能会导致意外结果。作为解决方法,请使用 ALTER TABLE 确保所有相关表具有相同的 PACK_KEYS 值。(错误 #50646)In some cases, differing PACK_KEYS table option values among the MERGE and underlying tables cause unexpected results if the underlying tables contain CHAR or BINARY columns. As a workaround, use ALTER TABLE to ensure that all involved tables have the same PACK_KEYS value. (Bug #50646)