<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="gtid-functions">
      </a>
      14.18.2 Functions Used with Global Transaction Identifiers (GTIDs)
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045193686672">
  </a>
  <a class="indexterm" name="idm46045193685632">
  </a>
  <p>
   The functions described in this section are used with GTID-based
        replication. It is important to keep in mind that all of these
        functions take string representations of GTID sets as arguments.
        As such, the GTID sets must always be quoted when used with
        them. See
   <a class="xref" href="replication-gtids-concepts.html#replication-gtids-concepts-gtid-sets" title="GTID Sets">
    GTID Sets
   </a>
   for more information.
  </p>
  <p>
   The union of two GTID sets is simply their representations as
        strings, joined together with an interposed comma. In other
        words, you can define a very simple function for obtaining the
        union of two GTID sets, similar to that created here:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa16185424"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">CREATE</span> <span class="token keyword">FUNCTION</span> GTID_UNION<span class="token punctuation">(</span>g1 <span class="token datatype">TEXT</span><span class="token punctuation">,</span> g2 <span class="token datatype">TEXT</span><span class="token punctuation">)</span>
    <span class="token keyword">RETURNS</span> <span class="token datatype">TEXT</span> <span class="token keyword">DETERMINISTIC</span>
    <span class="token keyword">RETURN</span> <span class="token function">CONCAT</span><span class="token punctuation">(</span>g1<span class="token punctuation">,</span><span class="token string">','</span><span class="token punctuation">,</span>g2<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   For more information about GTIDs and how these GTID functions
        are used in practice, see
   <a class="xref" href="replication-gtids.html" title="19.1.3 Replication with Global Transaction Identifiers">
    Section 19.1.3, “Replication with Global Transaction Identifiers”
   </a>
   .
  </p>
  <div class="table">
   <a name="idm46045193679664">
   </a>
   <p class="title">
    <b>
     Table 14.26 GTID Functions
    </b>
   </p>
   <div class="table-contents">
    <table frame="box" rules="all" summary="A reference that lists functions used with global transaction identifiers (GTIDs).">
     <colgroup>
      <col style="width: 28%"/>
      <col style="width: 71%"/>
     </colgroup>
     <thead>
      <tr>
       <th>
        Name
       </th>
       <th>
        Description
       </th>
      </tr>
     </thead>
     <tbody>
      <tr>
       <td>
        <a class="link" href="gtid-functions.html#function_wait-for-executed-gtid-set">
         <code class="literal">
          WAIT_FOR_EXECUTED_GTID_SET()
         </code>
        </a>
       </td>
       <td>
        Wait until the given GTIDs have executed on the replica.
       </td>
      </tr>
     </tbody>
    </table>
   </div>
  </div>
  <br class="table-break"/>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <a name="function_gtid-subset">
     </a>
     <p>
      <a class="link" href="gtid-functions.html#function_gtid-subset">
       <code class="literal">
        GTID_SUBSET(
        <em class="replaceable">
         <code>
          set1
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          set2
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045193664448">
     </a>
     <p>
      Given two sets of global transaction identifiers
      <em class="replaceable">
       <code>
        set1
       </code>
      </em>
      and
      <em class="replaceable">
       <code>
        set2
       </code>
      </em>
      , returns true if all GTIDs
            in
      <em class="replaceable">
       <code>
        set1
       </code>
      </em>
      are also in
      <em class="replaceable">
       <code>
        set2
       </code>
      </em>
      . Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        set1
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        set2
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      . Returns false otherwise.
     </p>
     <p>
      The GTID sets used with this function are represented as
            strings, as shown in the following examples:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa85415616"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">GTID_SUBSET</span><span class="token punctuation">(</span><span class="token string">'3E11FA47-71CA-11E1-9E33-C80AA9429562:23'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>     <span class="token string">'3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57'</span><span class="token punctuation">)</span>\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562<span class="token punctuation">:</span>23',
    '3E11FA47-71CA-11E1-9E33-C80AA9429562<span class="token punctuation">:</span>21-57')<span class="token punctuation">:</span> 1
</span><span class="token output">1 row in set (0.00 sec)</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">GTID_SUBSET</span><span class="token punctuation">(</span><span class="token string">'3E11FA47-71CA-11E1-9E33-C80AA9429562:23-25'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>     <span class="token string">'3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57'</span><span class="token punctuation">)</span>\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562<span class="token punctuation">:</span>23-25',
    '3E11FA47-71CA-11E1-9E33-C80AA9429562<span class="token punctuation">:</span>21-57')<span class="token punctuation">:</span> 1
</span><span class="token output">1 row in set (0.00 sec)</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">GTID_SUBSET</span><span class="token punctuation">(</span><span class="token string">'3E11FA47-71CA-11E1-9E33-C80AA9429562:20-25'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>     <span class="token string">'3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57'</span><span class="token punctuation">)</span>\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
GTID_SUBSET('3E11FA47-71CA-11E1-9E33-C80AA9429562<span class="token punctuation">:</span>20-25',
    '3E11FA47-71CA-11E1-9E33-C80AA9429562<span class="token punctuation">:</span>21-57')<span class="token punctuation">:</span> 0
</span><span class="token output">1 row in set (0.00 sec)</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_gtid-subtract">
     </a>
     <p>
      <a class="link" href="gtid-functions.html#function_gtid-subtract">
       <code class="literal">
        GTID_SUBTRACT(
        <em class="replaceable">
         <code>
          set1
         </code>
        </em>
        ,
        <em class="replaceable">
         <code>
          set2
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045193644336">
     </a>
     <p>
      Given two sets of global transaction identifiers
      <em class="replaceable">
       <code>
        set1
       </code>
      </em>
      and
      <em class="replaceable">
       <code>
        set2
       </code>
      </em>
      , returns only those GTIDs
            from
      <em class="replaceable">
       <code>
        set1
       </code>
      </em>
      that are not in
      <em class="replaceable">
       <code>
        set2
       </code>
      </em>
      . Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        set1
       </code>
      </em>
      or
      <em class="replaceable">
       <code>
        set2
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      All GTID sets used with this function are represented as
            strings and must be quoted, as shown in these examples:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa59628683"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">GTID_SUBTRACT</span><span class="token punctuation">(</span><span class="token string">'3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>     <span class="token string">'3E11FA47-71CA-11E1-9E33-C80AA9429562:21'</span><span class="token punctuation">)</span>\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562<span class="token punctuation">:</span>21-57',
    '3E11FA47-71CA-11E1-9E33-C80AA9429562<span class="token punctuation">:</span>21')<span class="token punctuation">:</span> 3e11fa47-71ca-11e1-9e33-c80aa9429562<span class="token punctuation">:</span>22-57
</span><span class="token output">1 row in set (0.00 sec)</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">GTID_SUBTRACT</span><span class="token punctuation">(</span><span class="token string">'3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>     <span class="token string">'3E11FA47-71CA-11E1-9E33-C80AA9429562:20-25'</span><span class="token punctuation">)</span>\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562<span class="token punctuation">:</span>21-57',
    '3E11FA47-71CA-11E1-9E33-C80AA9429562<span class="token punctuation">:</span>20-25')<span class="token punctuation">:</span> 3e11fa47-71ca-11e1-9e33-c80aa9429562<span class="token punctuation">:</span>26-57
</span><span class="token output">1 row in set (0.00 sec)</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">GTID_SUBTRACT</span><span class="token punctuation">(</span><span class="token string">'3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>     <span class="token string">'3E11FA47-71CA-11E1-9E33-C80AA9429562:23-24'</span><span class="token punctuation">)</span>\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562<span class="token punctuation">:</span>21-57',
    '3E11FA47-71CA-11E1-9E33-C80AA9429562<span class="token punctuation">:</span>23-24')<span class="token punctuation">:</span> 3e11fa47-71ca-11e1-9e33-c80aa9429562<span class="token punctuation">:</span>21-22<span class="token punctuation">:</span>25-57
</span><span class="token output">1 row in set (0.01 sec)</span></code></pre>
     </div>
     <p>
      Subtracting a GTID set from itself produces an empty set, as
            shown here:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa59862624"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">GTID_SUBTRACT</span><span class="token punctuation">(</span><span class="token string">'3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57'</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>     <span class="token string">'3E11FA47-71CA-11E1-9E33-C80AA9429562:21-57'</span><span class="token punctuation">)</span>\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
GTID_SUBTRACT('3E11FA47-71CA-11E1-9E33-C80AA9429562<span class="token punctuation">:</span>21-57',
    '3E11FA47-71CA-11E1-9E33-C80AA9429562<span class="token punctuation">:</span>21-57')<span class="token punctuation">:</span> 
</span><span class="token output">1 row in set (0.00 sec)</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <a name="function_wait-for-executed-gtid-set">
     </a>
     <p>
      <a class="link" href="gtid-functions.html#function_wait-for-executed-gtid-set">
       <code class="literal">
        WAIT_FOR_EXECUTED_GTID_SET(
        <em class="replaceable">
         <code>
          gtid_set
         </code>
        </em>
        [,
        <em class="replaceable">
         <code>
          timeout
         </code>
        </em>
        ])
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045193620704">
     </a>
     <p>
      Wait until the server has applied all of the transactions
            whose global transaction identifiers are contained in
      <em class="replaceable">
       <code>
        gtid_set
       </code>
      </em>
      ; that is, until the
            condition
            GTID_SUBSET(
      <em class="replaceable">
       <code>
        gtid_subset
       </code>
      </em>
      ,
      <code class="literal">
       @@GLOBAL.gtid_executed
      </code>
      ) holds. See
      <a class="xref" href="replication-gtids-concepts.html" title="19.1.3.1 GTID Format and Storage">
       Section 19.1.3.1, “GTID Format and Storage”
      </a>
      for a
            definition of GTID sets.
     </p>
     <p>
      If a timeout is specified, and
      <em class="replaceable">
       <code>
        timeout
       </code>
      </em>
      seconds elapse before all
            of the transactions in the GTID set have been applied, the
            function stops waiting.
      <em class="replaceable">
       <code>
        timeout
       </code>
      </em>
      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.
      <em class="replaceable">
       <code>
        timeout
       </code>
      </em>
      must be greater than or
            equal to 0; when running in strict SQL mode, a negative
      <em class="replaceable">
       <code>
        timeout
       </code>
      </em>
      value is immediately
            rejected with an error
            (
      <a class="ulink" href="/doc/mysql-errors/8.4/en/server-error-reference.html#error_er_wrong_arguments" target="_top">
       <code class="literal">
        ER_WRONG_ARGUMENTS
       </code>
      </a>
      );
            otherwise the function returns
      <code class="literal">
       NULL
      </code>
      , and
            raises a warning.
     </p>
     <p>
      <code class="literal">
       WAIT_FOR_EXECUTED_GTID_SET()
      </code>
      monitors all
            the GTIDs that are applied on the server, including
            transactions that arrive from all replication channels and
            user clients. It does not take into account whether
            replication channels have been started or stopped.
     </p>
     <p>
      For more information, see
      <a class="xref" href="replication-gtids.html" title="19.1.3 Replication with Global Transaction Identifiers">
       Section 19.1.3, “Replication with Global Transaction Identifiers”
      </a>
      .
     </p>
     <p>
      GTID sets used with this function are represented as strings
            and so must be quoted as shown in the following example:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa53992553"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token function">WAIT_FOR_EXECUTED_GTID_SET</span><span class="token punctuation">(</span><span class="token string">'3E11FA47-71CA-11E1-9E33-C80AA9429562:1-5'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token prompt">        -&gt;</span> <span class="token number">0</span></code></pre>
     </div>
     <p>
      For a syntax description for GTID sets, see
      <a class="xref" href="replication-gtids-concepts.html" title="19.1.3.1 GTID Format and Storage">
       Section 19.1.3.1, “GTID Format and Storage”
      </a>
      .
     </p>
     <p>
      For
      <code class="literal">
       WAIT_FOR_EXECUTED_GTID_SET()
      </code>
      , the
            return value is the state of the query, where 0 represents
            success, and 1 represents timeout. Any other failures
            generate an error.
     </p>
     <p>
      <a class="link" href="replication-options-gtids.html#sysvar_gtid_mode">
       <code class="literal">
        gtid_mode
       </code>
      </a>
      cannot be changed
            to OFF while any client is using this function to wait for
            GTIDs to be applied.
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
