<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="performance-schema-rwlock-instances-table">
      </a>
      29.12.3.4 The rwlock_instances Table
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045073490960">
  </a>
  <a class="indexterm" name="idm46045073489472">
  </a>
  <p>
   The
   <a class="link" href="performance-schema-rwlock-instances-table.html" title="29.12.3.4 The rwlock_instances Table">
    <code class="literal">
     rwlock_instances
    </code>
   </a>
   table lists
          all the
   <a class="link" href="glossary.html#glos_rw_lock" title="rw-lock">
    rwlock
   </a>
   (read write
          lock) instances seen by the Performance Schema while the
          server executes. An
   <code class="literal">
    rwlock
   </code>
   is a
          synchronization mechanism used in the code to enforce that
          threads at a given time can have access to some common
          resource following certain rules. The resource is said to be
   <span class="quote">
    “
    <span class="quote">
     protected
    </span>
    ”
   </span>
   by the
   <code class="literal">
    rwlock
   </code>
   . The
          access is either shared (many threads can have a read lock at
          the same time), exclusive (only one thread can have a write
          lock at a given time), or shared-exclusive (a thread can have
          a write lock while permitting inconsistent reads by other
          threads). Shared-exclusive access is otherwise known as an
   <code class="literal">
    sxlock
   </code>
   and optimizes concurrency and
          improves scalability for read-write workloads.
  </p>
  <p>
   Depending on how many threads are requesting a lock, and the
          nature of the locks requested, access can be either granted in
          shared mode, exclusive mode, shared-exclusive mode or not
          granted at all, waiting for other threads to finish first.
  </p>
  <p>
   The
   <a class="link" href="performance-schema-rwlock-instances-table.html" title="29.12.3.4 The rwlock_instances Table">
    <code class="literal">
     rwlock_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 lock.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       OBJECT_INSTANCE_BEGIN
      </code>
     </p>
     <p>
      The address in memory of the instrumented lock.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       WRITE_LOCKED_BY_THREAD_ID
      </code>
     </p>
     <p>
      When a thread currently has an
      <code class="literal">
       rwlock
      </code>
      locked in exclusive (write) mode,
      <code class="literal">
       WRITE_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>
    <li class="listitem">
     <p>
      <code class="literal">
       READ_LOCKED_BY_COUNT
      </code>
     </p>
     <p>
      When a thread currently has an
      <code class="literal">
       rwlock
      </code>
      locked in shared (read) mode,
      <code class="literal">
       READ_LOCKED_BY_COUNT
      </code>
      is incremented by
              1. This is a counter only, so it cannot be used directly
              to find which thread holds a read lock, but it can be used
              to see whether there is a read contention on an
      <code class="literal">
       rwlock
      </code>
      , and see how many readers are
              currently active.
     </p>
    </li>
   </ul>
  </div>
  <p>
   The
   <a class="link" href="performance-schema-rwlock-instances-table.html" title="29.12.3.4 The rwlock_instances Table">
    <code class="literal">
     rwlock_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">
       WRITE_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-rwlock-instances-table.html" title="29.12.3.4 The rwlock_instances Table">
    <code class="literal">
     rwlock_instances
    </code>
   </a>
   table.
  </p>
  <p>
   By performing queries on both of the following tables, a
          monitoring application or a DBA may detect some bottlenecks or
          deadlocks between threads that involve locks:
  </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
      <code class="literal">
       rwlock
      </code>
      a thread is waiting for
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="performance-schema-rwlock-instances-table.html" title="29.12.3.4 The rwlock_instances Table">
       <code class="literal">
        rwlock_instances
       </code>
      </a>
      , to see
              which other thread currently owns an
      <code class="literal">
       rwlock
      </code>
     </p>
    </li>
   </ul>
  </div>
  <p>
   There is a limitation: The
   <a class="link" href="performance-schema-rwlock-instances-table.html" title="29.12.3.4 The rwlock_instances Table">
    <code class="literal">
     rwlock_instances
    </code>
   </a>
   can be used only
          to identify the thread holding a write lock, but not the
          threads holding a read lock.
  </p>
 </div>
 <br/>
</div>
