<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="performance-schema-mutex-instances-table">
      </a>
      29.12.3.3 The mutex_instances Table
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045073552144">
  </a>
  <a class="indexterm" name="idm46045073550656">
  </a>
  <p>
   The
   <a class="link" href="performance-schema-mutex-instances-table.html" title="29.12.3.3 The mutex_instances Table">
    <code class="literal">
     mutex_instances
    </code>
   </a>
   table lists
          all the mutexes seen by the Performance Schema while the
          server executes. A mutex is a synchronization mechanism used
          in the code to enforce that only one thread at a given time
          can have access to some common resource. The resource is said
          to be
   <span class="quote">
    “
    <span class="quote">
     protected
    </span>
    ”
   </span>
   by the mutex.
  </p>
  <p>
   When two threads executing in the server (for example, two
          user sessions executing a query simultaneously) do need to
          access the same resource (a file, a buffer, or some piece of
          data), these two threads compete against each other, so that
          the first query to obtain a lock on the mutex causes the other
          query to wait until the first is done and unlocks the mutex.
  </p>
  <p>
   The work performed while holding a mutex is said to be in a
   <span class="quote">
    “
    <span class="quote">
     critical section,
    </span>
    ”
   </span>
   and multiple queries do
          execute this critical section in a serialized way (one at a
          time), which is a potential bottleneck.
  </p>
  <p>
   The
   <a class="link" href="performance-schema-mutex-instances-table.html" title="29.12.3.3 The mutex_instances Table">
    <code class="literal">
     mutex_instances
    </code>
   </a>
   table has
          these columns:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <code class="literal">
       NAME
      </code>
     </p>
     <p>
      The instrument name associated with the mutex.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       OBJECT_INSTANCE_BEGIN
      </code>
     </p>
     <p>
      The address in memory of the instrumented mutex.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       LOCKED_BY_THREAD_ID
      </code>
     </p>
     <p>
      When a thread currently has a mutex locked,
      <code class="literal">
       LOCKED_BY_THREAD_ID
      </code>
      is the
      <code class="literal">
       THREAD_ID
      </code>
      of the locking thread,
              otherwise it is
      <code class="literal">
       NULL
      </code>
      .
     </p>
    </li>
   </ul>
  </div>
  <p>
   The
   <a class="link" href="performance-schema-mutex-instances-table.html" title="29.12.3.3 The mutex_instances Table">
    <code class="literal">
     mutex_instances
    </code>
   </a>
   table has
          these indexes:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Primary key on (
      <code class="literal">
       OBJECT_INSTANCE_BEGIN
      </code>
      )
     </p>
    </li>
    <li class="listitem">
     <p>
      Index on (
      <code class="literal">
       NAME
      </code>
      )
     </p>
    </li>
    <li class="listitem">
     <p>
      Index on (
      <code class="literal">
       LOCKED_BY_THREAD_ID
      </code>
      )
     </p>
    </li>
   </ul>
  </div>
  <p>
   <a class="link" href="truncate-table.html" title="15.1.37 TRUNCATE TABLE Statement">
    <code class="literal">
     TRUNCATE TABLE
    </code>
   </a>
   is not permitted
          for the
   <a class="link" href="performance-schema-mutex-instances-table.html" title="29.12.3.3 The mutex_instances Table">
    <code class="literal">
     mutex_instances
    </code>
   </a>
   table.
  </p>
  <p>
   For every mutex instrumented in the code, the Performance
          Schema provides the following information.
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      The
      <a class="link" href="performance-schema-setup-instruments-table.html" title="29.12.2.3 The setup_instruments Table">
       <code class="literal">
        setup_instruments
       </code>
      </a>
      table
              lists the name of the instrumentation point, with the
              prefix
      <code class="literal">
       wait/synch/mutex/
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      When some code creates a mutex, a row is added to the
      <a class="link" href="performance-schema-mutex-instances-table.html" title="29.12.3.3 The mutex_instances Table">
       <code class="literal">
        mutex_instances
       </code>
      </a>
      table. The
      <code class="literal">
       OBJECT_INSTANCE_BEGIN
      </code>
      column is a
              property that uniquely identifies the mutex.
     </p>
    </li>
    <li class="listitem">
     <p>
      When a thread attempts to lock a mutex, the
      <a class="link" href="performance-schema-events-waits-current-table.html" title="29.12.4.1 The events_waits_current Table">
       <code class="literal">
        events_waits_current
       </code>
      </a>
      table
              shows a row for that thread, indicating that it is waiting
              on a mutex (in the
      <code class="literal">
       EVENT_NAME
      </code>
      column),
              and indicating which mutex is waited on (in the
      <code class="literal">
       OBJECT_INSTANCE_BEGIN
      </code>
      column).
     </p>
    </li>
    <li class="listitem">
     <p>
      When a thread succeeds in locking a mutex:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         <a class="link" href="performance-schema-events-waits-current-table.html" title="29.12.4.1 The events_waits_current Table">
          <code class="literal">
           events_waits_current
          </code>
         </a>
         shows that the wait on the mutex is completed (in the
         <code class="literal">
          TIMER_END
         </code>
         and
         <code class="literal">
          TIMER_WAIT
         </code>
         columns)
        </p>
       </li>
       <li class="listitem">
        <p>
         The completed wait event is added to the
         <a class="link" href="performance-schema-events-waits-history-table.html" title="29.12.4.2 The events_waits_history Table">
          <code class="literal">
           events_waits_history
          </code>
         </a>
         and
         <a class="link" href="performance-schema-events-waits-history-long-table.html" title="29.12.4.3 The events_waits_history_long Table">
          <code class="literal">
           events_waits_history_long
          </code>
         </a>
         tables
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="performance-schema-mutex-instances-table.html" title="29.12.3.3 The mutex_instances Table">
          <code class="literal">
           mutex_instances
          </code>
         </a>
         shows
                  that the mutex is now owned by the thread (in the
         <code class="literal">
          THREAD_ID
         </code>
         column).
        </p>
       </li>
      </ul>
     </div>
    </li>
    <li class="listitem">
     <p>
      When a thread unlocks a mutex,
      <a class="link" href="performance-schema-mutex-instances-table.html" title="29.12.3.3 The mutex_instances Table">
       <code class="literal">
        mutex_instances
       </code>
      </a>
      shows that
              the mutex now has no owner (the
      <code class="literal">
       THREAD_ID
      </code>
      column is
      <code class="literal">
       NULL
      </code>
      ).
     </p>
    </li>
    <li class="listitem">
     <p>
      When a mutex object is destroyed, the corresponding row is
              removed from
      <a class="link" href="performance-schema-mutex-instances-table.html" title="29.12.3.3 The mutex_instances Table">
       <code class="literal">
        mutex_instances
       </code>
      </a>
      .
     </p>
    </li>
   </ul>
  </div>
  <p>
   By performing queries on both of the following tables, a
          monitoring application or a DBA can detect bottlenecks or
          deadlocks between threads that involve mutexes:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="link" href="performance-schema-events-waits-current-table.html" title="29.12.4.1 The events_waits_current Table">
       <code class="literal">
        events_waits_current
       </code>
      </a>
      , to see
              what mutex a thread is waiting for
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="performance-schema-mutex-instances-table.html" title="29.12.3.3 The mutex_instances Table">
       <code class="literal">
        mutex_instances
       </code>
      </a>
      , to see which
              other thread currently owns a mutex
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
