使用 FEDERATED 存储引擎时,应注意以下几点:You should be aware of the following points when using the
FEDERATED storage engine:
FEDERATED表可以被复制到其他副本,但您必须确保副本服务器能够使用在CONNECTION字符串(或mysql.servers表中的行)中定义的用户名/密码组合连接到远程服务器。FEDERATEDtables 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 theCONNECTIONstring (or the row in themysql.serverstable) 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 aFEDERATEDtable points to must exist before you try to access the table through theFEDERATEDtable.一个
FEDERATED表可以指向另一个表,但您必须小心不要创建循环。It is possible for oneFEDERATEDtable to point to another, but you must be careful not to create a loop.FEDERATED表不支持通常意义上的索引;因为对表数据的访问是远程处理的,实际上使用索引的是远程表。这意味着,对于无法使用任何索引而需要进行全表扫描的查询,服务器会从远程表中获取所有行并在本地进行过滤。无论与此SELECT语句一起使用的WHERE或LIMIT是什么,这些子句都是在返回的行上本地应用的。AFEDERATEDtable 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 anyWHEREorLIMITused with thisSELECTstatement; 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 aFEDERATEDtable since the index definition from an equivalentMyISAMor other table may not be supported. For example, creating aFEDERATEDtable fails if the table uses an index prefix on anyVARCHAR,TEXTorBLOBcolumns. The following definition usingMyISAMis valid:CREATE TABLE `T1`( `A` VARCHAR(100), UNIQUE KEY(`A`(30)) ) ENGINE=MYISAM;此示例中的键前缀与
FEDERATED引擎不兼容,并且等效语句会失败:The key prefix in this example is incompatible with theFEDERATEDengine, 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 usesSELECT,INSERT,UPDATE, andDELETE, but notHANDLER.FEDERATED存储引擎支持SELECT、INSERT、UPDATE、DELETE、TRUNCATE TABLE和索引。它不支持ALTER TABLE,或任何直接影响表结构的数据定义语言语句,除了DROP TABLE。当前实现不使用预处理语句。TheFEDERATEDstorage engine supportsSELECT,INSERT,UPDATE,DELETE,TRUNCATE TABLE, and indexes. It does not supportALTER TABLE, or any Data Definition Language statements that directly affect the structure of the table, other thanDROP TABLE. The current implementation does not use prepared statements.FEDERATED支持INSERT ... ON DUPLICATE KEY UPDATE语句,但如果发生重复键冲突,该语句会失败并报错。FEDERATEDacceptsINSERT ... ON DUPLICATE KEY UPDATEstatements, but if a duplicate-key violation occurs, the statement fails with an error.不支持事务。Transactions are not supported.
FEDERATED执行批量插入处理,将多行数据作为一个批次发送到远程表,从而提高性能。此外,如果远程表是事务性的,它允许远程存储引擎在发生错误时正确执行语句回滚。此功能有以下限制:FEDERATEDperforms 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 forINSERT ... ON DUPLICATE KEY UPDATE.
FEDERATED引擎无法知道远程表是否已更改。原因是该表必须像数据文件一样工作,除数据库系统外,任何其他对象都不会向其写入数据。如果远程数据库发生任何更改,本地表中的数据完整性可能会受到破坏。There is no way for theFEDERATEDengine 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 aCONNECTIONstring, you cannot use an '@' character in the password. You can get round this limitation by using theCREATE SERVERstatement to create a server connection.insert_id和timestamp选项不会传递给数据提供者。Theinsert_idandtimestampoptions are not propagated to the data provider.对
FEDERATED表发出的任何DROP TABLE语句只会删除本地表,而不会删除远程表。AnyDROP TABLEstatement issued against aFEDERATEDtable drops only the local table, not the remote table.不支持
FEDERATED表的用户定义分区。User-defined partitioning is not supported forFEDERATEDtables.