8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 18 个替代存储引擎 / 18.8 联邦存储引擎 / 18.8.3 联邦存储引擎注释和技巧
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

18.8.3 FEDERATED 存储引擎说明和提示18.8.3 FEDERATED Storage Engine Notes and Tips

使用 FEDERATED 存储引擎时,应注意以下几点:You should be aware of the following points when using the FEDERATED storage engine:

  • FEDERATED 表可以被复制到其他副本,但您必须确保副本服务器能够使用在 CONNECTION 字符串(或 mysql.servers 表中的行)中定义的用户名/密码组合连接到远程服务器。FEDERATED tables may be replicated to other replicas, but you must ensure that the replica servers are able to use the user/password combination that is defined in the CONNECTION string (or the row in the mysql.servers table) to connect to the remote server.

下面列出的是 FEDERATED 存储引擎支持和不支持的功能:The following items indicate features that the FEDERATED storage engine does and does not support:

  • 远程服务器必须是 MySQL 服务器。The remote server must be a MySQL server.

  • FEDERATED 表所指向的远程表 必须 在您尝试通过 FEDERATED 表访问该表之前存在。The remote table that a FEDERATED table points to must exist before you try to access the table through the FEDERATED table.

  • 一个 FEDERATED 表可以指向另一个表,但您必须小心不要创建循环。It is possible for one FEDERATED table to point to another, but you must be careful not to create a loop.

  • FEDERATED 表不支持通常意义上的索引;因为对表数据的访问是远程处理的,实际上使用索引的是远程表。这意味着,对于无法使用任何索引而需要进行全表扫描的查询,服务器会从远程表中获取所有行并在本地进行过滤。无论与此 SELECT 语句一起使用的 WHERE 或 LIMIT 是什么,这些子句都是在返回的行上本地应用的。A FEDERATED table does not support indexes in the usual sense; because access to the table data is handled remotely, it is actually the remote table that makes use of indexes. This means that, for a query that cannot use any indexes and so requires a full table scan, the server fetches all rows from the remote table and filters them locally. This occurs regardless of any WHERE or LIMIT used with this SELECT statement; these clauses are applied locally to the returned rows.

    因此,未能使用索引的查询可能导致性能下降和网络过载。此外,由于返回的行必须存储在内存中,这种查询还可能导致本地服务器出现交换甚至卡死。Queries that fail to use indexes can thus cause poor performance and network overload. In addition, since returned rows must be stored in memory, such a query can also lead to the local server swapping, or even hanging.

  • 在创建 FEDERATED 表时应小心,因为等效的 MyISAM 或其他表的索引定义可能不被支持。例如,如果表在任何 VARCHAR、TEXT 或 BLOB 列上使用索引前缀,则创建 FEDERATED 表会失败。以下使用 MyISAM 的定义是有效的:Care should be taken when creating a FEDERATED table since the index definition from an equivalent MyISAM or other table may not be supported. For example, creating a FEDERATED table fails if the table uses an index prefix on any VARCHAR, TEXT or BLOB columns. The following definition using MyISAM is valid:

    CREATE TABLE `T1`(
        `A` VARCHAR(100),
        UNIQUE KEY(`A`(30))
    ) ENGINE=MYISAM;
    

    此示例中的键前缀与 FEDERATED 引擎不兼容,并且等效语句会失败:The key prefix in this example is incompatible with the FEDERATED engine, and the equivalent statement fails:

    CREATE TABLE `T1`(
        `A` VARCHAR(100),
        UNIQUE KEY(`A`(30))
    ) ENGINE=FEDERATED
      CONNECTION='MYSQL://127.0.0.1:3306/TEST/T1';
    

    如果可能的话,在远程服务器和本地服务器上创建表时,你应该尝试将列定义和索引定义分开,以避免这些索引问题。If possible, you should try to separate the column and index definition when creating tables on both the remote server and the local server to avoid these index issues.

  • 在内部实现中使用了 SELECT、INSERT、UPDATE 和 DELETE,但不使用 HANDLER。Internally, the implementation uses SELECT, INSERT, UPDATE, and DELETE, but not HANDLER.

  • FEDERATED 存储引擎支持 SELECT、INSERT、UPDATE、DELETE、TRUNCATE TABLE 和索引。它不支持 ALTER TABLE,或任何直接影响表结构的数据定义语言语句,除了 DROP TABLE。当前实现不使用预处理语句。The FEDERATED storage engine supports SELECT, INSERT, UPDATE, DELETE, TRUNCATE TABLE, and indexes. It does not support ALTER TABLE, or any Data Definition Language statements that directly affect the structure of the table, other than DROP TABLE. The current implementation does not use prepared statements.

  • FEDERATED 支持 INSERT ... ON DUPLICATE KEY UPDATE 语句,但如果发生重复键冲突,该语句会失败并报错。FEDERATED accepts INSERT ... ON DUPLICATE KEY UPDATE statements, but if a duplicate-key violation occurs, the statement fails with an error.

  • 不支持事务。Transactions are not supported.

  • FEDERATED 执行批量插入处理,将多行数据作为一个批次发送到远程表,从而提高性能。此外,如果远程表是事务性的,它允许远程存储引擎在发生错误时正确执行语句回滚。此功能有以下限制:FEDERATED performs bulk-insert handling such that multiple rows are sent to the remote table in a batch, which improves performance. Also, if the remote table is transactional, it enables the remote storage engine to perform statement rollback properly should an error occur. This capability has the following limitations:

    • 插入数据的大小不能超过服务器之间的最大数据包大小。如果插入超出此大小,它会被分成多个数据包,可能会导致回滚问题。The size of the insert cannot exceed the maximum packet size between servers. If the insert exceeds this size, it is broken into multiple packets and the rollback problem can occur.

    • 批量插入处理不会针对 INSERT ... ON DUPLICATE KEY UPDATE 发生。Bulk-insert handling does not occur for INSERT ... ON DUPLICATE KEY UPDATE.

  • FEDERATED 引擎无法知道远程表是否已更改。原因是该表必须像数据文件一样工作,除数据库系统外,任何其他对象都不会向其写入数据。如果远程数据库发生任何更改,本地表中的数据完整性可能会受到破坏。There is no way for the FEDERATED engine to know if the remote table has changed. The reason for this is that this table must work like a data file that would never be written to by anything other than the database system. The integrity of the data in the local table could be breached if there was any change to the remote database.

  • 使用 CONNECTION 字符串时,密码中不能使用 '@' 字符。你可以通过使用 CREATE SERVER 语句来创建服务器连接,从而解决此限制。When using a CONNECTION string, you cannot use an '@' character in the password. You can get round this limitation by using the CREATE SERVER statement to create a server connection.

  • insert_id 和 timestamp 选项不会传递给数据提供者。The insert_id and timestamp options are not propagated to the data provider.

  • 对 FEDERATED 表发出的任何 DROP TABLE 语句只会删除本地表,而不会删除远程表。Any DROP TABLE statement issued against a FEDERATED table drops only the local table, not the remote table.

  • 不支持 FEDERATED 表的用户定义分区。User-defined partitioning is not supported for FEDERATED tables.