<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="replication-features-row-searches">
      </a>
      19.5.1.27 Replication and Row Searches
     </h4>
    </div>
   </div>
  </div>
  <p>
   When a replica using row-based replication format applies an
   <a class="link" href="update.html" title="15.2.17 UPDATE Statement">
    <code class="literal">
     UPDATE
    </code>
   </a>
   or
   <a class="link" href="delete.html" title="15.2.2 DELETE Statement">
    <code class="literal">
     DELETE
    </code>
   </a>
   operation, it must search
        the relevant table for the matching rows. The algorithm used to
        carry out this process uses one of the table's indexes to carry
        out the search as the first choice, and a hash table if there
        are no suitable indexes.
  </p>
  <p>
   The algorithm first assesses the available indexes in the table
        definition to see if there is any suitable index to use, and if
        there are multiple possibilities, which index is the best fit
        for the operation. The algorithm ignores the following types of
        index:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Fulltext indexes.
     </p>
    </li>
    <li class="listitem">
     <p>
      Hidden indexes.
     </p>
    </li>
    <li class="listitem">
     <p>
      Generated indexes.
     </p>
    </li>
    <li class="listitem">
     <p>
      Multi-valued indexes.
     </p>
    </li>
    <li class="listitem">
     <p>
      Any index where the before-image of the row event does not
            contain all the columns of the index.
     </p>
    </li>
   </ul>
  </div>
  <p>
   If there are no suitable indexes after ruling out these index
        types, the algorithm does not use an index for the search. If
        there are suitable indexes, one index is selected from the
        candidates, in the following priority order:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      A primary key.
     </p>
    </li>
    <li class="listitem">
     <p>
      A unique index where every column in the index has a NOT
            NULL attribute. If more than one such index is available,
            the algorithm chooses the leftmost of these indexes.
     </p>
    </li>
    <li class="listitem">
     <p>
      Any other index. If more than one such index is available,
            the algorithm chooses the leftmost of these indexes.
     </p>
    </li>
   </ol>
  </div>
  <p>
   If the algorithm is able to select a primary key or a unique
        index where every column in the index has a
   <code class="literal">
    NOT
        NULL
   </code>
   attribute, it uses this index to iterate over the
        rows in the
   <a class="link" href="update.html" title="15.2.17 UPDATE Statement">
    <code class="literal">
     UPDATE
    </code>
   </a>
   or
   <a class="link" href="delete.html" title="15.2.2 DELETE Statement">
    <code class="literal">
     DELETE
    </code>
   </a>
   operation. For each row in
        the row event, the algorithm looks up the row in the index to
        locate the table record to update. If no matching record is
        found, it returns the error
   <span class="errortext">
    ER_KEY_NOT_FOUND
   </span>
   and stops the
        replication applier thread.
  </p>
  <p>
   If the algorithm was not able to find a suitable index, or was
        only able to find an index that was non-unique or contained
        nulls, a hash table is used to assist in identifying the table
        records. The algorithm creates a hash table containing the rows
        in the
   <a class="link" href="update.html" title="15.2.17 UPDATE Statement">
    <code class="literal">
     UPDATE
    </code>
   </a>
   or
   <a class="link" href="delete.html" title="15.2.2 DELETE Statement">
    <code class="literal">
     DELETE
    </code>
   </a>
   operation, with the key as
        the full before-image of the row. The algorithm then iterates
        over all the records in the target table, using the selected
        index if it found one, or else performing a full table scan. For
        each record in the target table, it determines whether that row
        exists in the hash table. If the row is found in the hash table,
        the record in the target table is updated, and the row is
        deleted from the hash table. When all the records in the target
        table have been checked, the algorithm verifies whether the hash
        table is now empty. If there are any unmatched rows remaining in
        the hash table, the algorithm returns the error
   <span class="errortext">
    ER_KEY_NOT_FOUND
   </span>
   and stops the
        replication applier thread.
  </p>
 </div>
 <br/>
</div>
