The functions described in this section are used with GTID-based replication. 本节中描述的功能用于基于GTID的复制。It is important to keep in mind that all of these functions take string representations of GTID sets as arguments. 请务必记住,所有这些函数都将GTID集的字符串表示形式作为参数。As such, the GTID sets must always be quoted when used with them. 因此,与GTID集一起使用时,必须始终引用GTID集。See GTID Sets for more information.有关详细信息,请参见GTID集。
The union of two GTID sets is simply their representations as strings, joined together with an interposed comma. 两个GTID集的并集只是它们作为字符串的表示,用插入的逗号连接在一起。In other words, you can define a very simple function for obtaining the union of two GTID sets, similar to that created here:换句话说,您可以定义一个非常简单的函数来获得两个GTID集的并集,类似于这里创建的:
CREATE FUNCTION GTID_UNION(g1 TEXT, g2 TEXT) RETURNS TEXT DETERMINISTIC RETURN CONCAT(g1,',',g2);
For more information about GTIDs and how these GTID functions are used in practice, see Section 17.1.3, “Replication with Global Transaction Identifiers”.有关GTID以及如何在实践中使用这些GTID函数的更多信息,请参阅第17.1.3节,“使用全局事务标识符的复制”。
Table 12.24 GTID FunctionsGTID函数
GTID_SUBSET() | true ;否则为false 。 | |
---|---|---|
GTID_SUBTRACT() | ||
WAIT_FOR_EXECUTED_GTID_SET() | ||
WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS() | WAIT_FOR_EXECUTED_GTID_SET() .WAIT _FOR _EXECUTED _GTID_SET() 。 | 8.0.18 |
Given two sets of global transaction identifiers 给定两组全局事务标识符set1
and set2
, returns true if all GTIDs in set1
are also in set2
. set1
和set2
,如果set1
中的所有GTID也在set2
中,则返回true
。Returns false otherwise.否则返回false
。
The GTID sets used with this function are represented as strings, as shown in the following examples:与此函数一起使用的GTID集表示为字符串,如以下示例所示:
mysql>SELECT GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562:23',
->'3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57')\G
*************************** 1. row *************************** GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562:23', '3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57'): 1 1 row in set (0.00 sec) mysql>SELECT GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562:23-25',
->'3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57')\G
*************************** 1. row *************************** GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562:23-25', '3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57'): 1 1 row in set (0.00 sec) mysql>SELECT GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562:20-25',
->'3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57')\G
*************************** 1. row *************************** GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562:20-25', '3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57'): 0 1 row in set (0.00 sec)
Given two sets of global transaction identifiers 给定两组全局事务标识符set1
and set2
, returns only those GTIDs from set1
that are not in set2
.set1
和set2
,只返回set1
中不在set2
中的GTID。
All GTID sets used with this function are represented as strings and must be quoted, as shown in these examples:与此函数一起使用的所有GTID集都表示为字符串,并且必须引用,如以下示例所示:
mysql>SELECT GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57',
->'3E11FA47-71CA-11E1-9E33-C80AA9429562:21')\G
*************************** 1. row *************************** GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57', '3E11FA47-71CA-11E1-9E33-C80AA9429562:21'): 3e11fa47-71ca-11e1-9e33-c80aa9429562:22-57 1 row in set (0.00 sec) mysql>SELECT GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57',
->'3E11FA47-71CA-11E1-9E33-C80AA9429562:20-25')\G
*************************** 1. row *************************** GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57', '3E11FA47-71CA-11E1-9E33-C80AA9429562:20-25'): 3e11fa47-71ca-11e1-9e33-c80aa9429562:26-57 1 row in set (0.00 sec) mysql>SELECT GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57',
->'3E11FA47-71CA-11E1-9E33-C80AA9429562:23-24')\G
*************************** 1. row *************************** GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57', '3E11FA47-71CA-11E1-9E33-C80AA9429562:23-24'): 3e11fa47-71ca-11e1-9e33-c80aa9429562:21-22:25-57 1 row in set (0.01 sec)
WAIT_FOR_EXECUTED_GTID_SET(
gtid_set
[, timeout
])
Wait until the server has applied all of the transactions whose global transaction identifiers are contained in 等待服务器应用了gtid_set
; that is, until the condition GTID_SUBSET(gtid_subset
, @@GLOBAL.gtid_executed
) holds. gtid_set
中包含全局事务标识符的所有事务;也就是说,直到条件GTID_SUBSET(
成立。gtid_subset
, @@GLOBAL.gtid_executed
)See Section 17.1.3.1, “GTID Format and Storage” for a definition of GTID sets.有关GTID集的定义,请参阅第17.1.3.1节,“GTID格式和存储”。
If a timeout is specified, and 如果指定了timeout
seconds elapse before all of the transactions in the GTID set have been applied, the function stops waiting. timeout
,并且在应用GTID集中的所有事务之前经过了超时秒,则函数将停止等待。timeout
is optional, and the default timeout is 0 seconds, in which case the function always waits until all of the transactions in the GTID set have been applied.timeout
是可选的,默认的超时时间是0秒,在这种情况下,函数总是等待,直到应用了GTID集中的所有事务。
WAIT_FOR_EXECUTED_GTID_SET()
monitors all the GTIDs that are applied on the server, including transactions that arrive from all replication channels and user clients. WAIT _FOR _EXECUTED_SET()
监视服务器上应用的所有GTID,包括从所有复制通道和用户客户端到达的事务。It does not take into account whether replication channels have been started or stopped.它不考虑复制通道是已启动还是已停止。
For more information, see Section 17.1.3, “Replication with Global Transaction Identifiers”.有关更多信息,请参阅第17.1.3节,“使用全局事务标识符的复制”。
GTID sets used with this function are represented as strings and so must be quoted as shown in the following example:与此函数一起使用的GTID集表示为字符串,因此必须按以下示例所示引用:
mysql> SELECT WAIT_FOR_EXECUTED_GTID_SET('3E11FA47-71CA-11E1-9E33-C80AA9429562:1-5');
-> 0
For a syntax description for GTID sets, see Section 17.1.3.1, “GTID Format and Storage”.有关GTID集的语法说明,请参阅第17.1.3.1节,“GTID格式和存储”。
For 对于WAIT_FOR_EXECUTED_GTID_SET()
, the return value is the state of the query, where 0 represents success, and 1 represents timeout. WAIT_FOR_EXECUTED_GTID_SET()
,返回值是查询的状态,其中0表示成功,1表示超时。Any other failures generate an error.任何其他故障都会产生错误。
当任何客户端正在使用此函数等待应用gtid时,gtid_mode
cannot be changed to OFF while any client is using this function to wait for GTIDs to be applied.gtid_mode
不能更改为OFF
。
WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS(
gtid_set
[, timeout
][,channel
])
WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS()
is deprecated. WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS()
不再建议使用。Use 请改用WAIT_FOR_EXECUTED_GTID_SET()
instead, which works regardless of the replication channel or user client through which the specified transactions arrive on the server.WAIT_FOR_EXECUTED_GTID_SET()
,无论指定的事务通过哪个复制通道或用户客户端到达服务器,它都可以工作。