8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

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

18.8.1 FEDERATED 存储引擎概述18.8.1 FEDERATED Storage Engine Overview

当您使用标准存储引擎(例如 MyISAM、CSV 或 InnoDB)创建表时,表由表定义和相关数据组成。创建 FEDERATED 表时,表定义相同,但数据的物理存储由远程服务器处理。When you create a table using one of the standard storage engines (such as MyISAM, CSV or InnoDB), the table consists of the table definition and the associated data. When you create a FEDERATED table, the table definition is the same, but the physical storage of the data is handled on a remote server.

FEDERATED 表由两个部分组成:A FEDERATED table consists of two elements:

  • 一个带有表的 远程服务器,该表 wiederum 包含表定义(存储在 MySQL 数据字典中)和相关表。远程表的表类型可以是远程 mysqld 服务器支持的任何类型,包括 MyISAM 或 InnoDB。A remote server with a database table, which in turn consists of the table definition (stored in the MySQL data dictionary) and the associated table. The table type of the remote table may be any type supported by the remote mysqld server, including MyISAM or InnoDB.

  • 一个本地服务器,具有一个表,该表的定义与远程服务器上相应表的定义相匹配。表定义存储在数据字典中。本地服务器上没有数据文件。相反,表定义包括指向远程表的连接字符串。A local server with a database table, where the table definition matches that of the corresponding table on the remote server. The table definition is stored in the data dictionary. There is no data file on the local server. Instead, the table definition includes a connection string that points to the remote table.

当在本地服务器上的FEDERATED表上执行查询和语句时,那些通常会从本地数据文件插入、更新或删除信息的操作会被发送到远程服务器执行,在那里它们会更新远程服务器上的数据文件或返回远程服务器中匹配的行。When executing queries and statements on a FEDERATED table on the local server, the operations that would normally insert, update or delete information from a local data file are instead sent to the remote server for execution, where they update the data file on the remote server or return matching rows from the remote server.

FEDERATED 表的基本结构如 图 18.2,“FEDERATED 表结构” 所示。The basic structure of a FEDERATED table setup is shown in Figure 18.2, “FEDERATED Table Structure”.

图 18.2 FEDERATED 表结构Figure 18.2 FEDERATED Table Structure

Content is described in the surrounding text.

当客户端执行引用 FEDERATED 表的 SQL 语句时,本地服务器(执行 SQL 语句的服务器)与远程服务器(数据实际存储的服务器)之间的信息流如下:When a client issues an SQL statement that refers to a FEDERATED table, the flow of information between the local server (where the SQL statement is executed) and the remote server (where the data is physically stored) is as follows:

  1. 存储引擎会查看 FEDERATED 表的每一列,并构建引用远程表的相应 SQL 语句。The storage engine looks through each column that the FEDERATED table has and constructs an appropriate SQL statement that refers to the remote table.

  2. 该语句通过 MySQL 客户端 API 发送到远程服务器。The statement is sent to the remote server using the MySQL client API.

  3. 远程服务器处理该语句,本地服务器检索该语句产生的任何结果(受影响的行数或结果集)。The remote server processes the statement and the local server retrieves any result that the statement produces (an affected-rows count or a result set).

  4. 如果该语句产生结果集,每一列将被转换为 FEDERATED 引擎所期望的内部存储引擎格式,并可用于向发出原始语句的客户端显示结果。If the statement produces a result set, each column is converted to internal storage engine format that the FEDERATED engine expects and can use to display the result to the client that issued the original statement.

本地服务器使用 MySQL 客户端 C API 函数与远程服务器通信。它调用 mysql_real_query() 来发送语句。为了读取结果集,它使用 mysql_store_result(),并使用 mysql_fetch_row() 一次获取一行。The local server communicates with the remote server using MySQL client C API functions. It invokes mysql_real_query() to send the statement. To read a result set, it uses mysql_store_result() and fetches rows one at a time using mysql_fetch_row().