<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="innodb-deadlock-detection">
      </a>
      17.7.5.2 Deadlock Detection
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045163763152">
  </a>
  <a class="indexterm" name="idm46045163761664">
  </a>
  <a class="indexterm" name="idm46045163760592">
  </a>
  <a class="indexterm" name="idm46045163759104">
  </a>
  <a class="indexterm" name="idm46045163757200">
  </a>
  <a class="indexterm" name="idm46045163755712">
  </a>
  <p>
   When
   <a class="link" href="glossary.html#glos_deadlock_detection" title="deadlock detection">
    deadlock
        detection
   </a>
   is enabled (the default),
   <code class="literal">
    InnoDB
   </code>
   automatically detects transaction
   <a class="link" href="glossary.html#glos_deadlock" title="deadlock">
    deadlocks
   </a>
   and rolls back a
        transaction or transactions to break the deadlock.
   <code class="literal">
    InnoDB
   </code>
   tries to pick small transactions to
        roll back, where the size of a transaction is determined by the
        number of rows inserted, updated, or deleted.
  </p>
  <p>
   <code class="literal">
    InnoDB
   </code>
   is aware of table locks if
   <code class="literal">
    innodb_table_locks = 1
   </code>
   (the default) and
   <a class="link" href="server-system-variables.html#sysvar_autocommit">
    <code class="literal">
     autocommit = 0
    </code>
   </a>
   , and the MySQL
        layer above it knows about row-level locks. Otherwise,
   <code class="literal">
    InnoDB
   </code>
   cannot detect deadlocks where a table
        lock set by a MySQL
   <a class="link" href="lock-tables.html" title="15.3.6 LOCK TABLES and UNLOCK TABLES Statements">
    <code class="literal">
     LOCK TABLES
    </code>
   </a>
   statement or a lock set by a storage engine other than
   <code class="literal">
    InnoDB
   </code>
   is involved. Resolve these situations
        by setting the value of the
   <a class="link" href="innodb-parameters.html#sysvar_innodb_lock_wait_timeout">
    <code class="literal">
     innodb_lock_wait_timeout
    </code>
   </a>
   system
        variable.
  </p>
  <p>
   If the
   <code class="literal">
    LATEST DETECTED DEADLOCK
   </code>
   section of
   <code class="literal">
    InnoDB
   </code>
   Monitor output includes a message
        stating
   <span class="errortext">
    TOO DEEP OR LONG SEARCH IN THE LOCK TABLE
        WAITS-FOR GRAPH, WE WILL ROLL BACK FOLLOWING
        TRANSACTION
   </span>
   , this indicates that the number of
        transactions on the wait-for list has reached a limit of 200. A
        wait-for list that exceeds 200 transactions is treated as a
        deadlock and the transaction attempting to check the wait-for
        list is rolled back. The same error may also occur if the
        locking thread must look at more than 1,000,000 locks owned by
        transactions on the wait-for list.
  </p>
  <p>
   For techniques to organize database operations to avoid
        deadlocks, see
   <a class="xref" href="innodb-deadlocks.html" title="17.7.5 Deadlocks in InnoDB">
    Section 17.7.5, “Deadlocks in InnoDB”
   </a>
   .
  </p>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="innodb-disable-deadlock-detection">
       </a>
       Disabling Deadlock Detection
      </h5>
     </div>
    </div>
   </div>
   <p>
    On high concurrency systems, deadlock detection can cause a
          slowdown when numerous threads wait for the same lock. At
          times, it may be more efficient to disable deadlock detection
          and rely on the
    <a class="link" href="innodb-parameters.html#sysvar_innodb_lock_wait_timeout">
     <code class="literal">
      innodb_lock_wait_timeout
     </code>
    </a>
    setting for transaction rollback when a deadlock occurs.
          Deadlock detection can be disabled using the
    <a class="link" href="innodb-parameters.html#sysvar_innodb_deadlock_detect">
     <code class="literal">
      innodb_deadlock_detect
     </code>
    </a>
    variable.
   </p>
  </div>
 </div>
 <br/>
</div>
