<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="innodb-adaptive-hash">
      </a>
      17.5.3 Adaptive Hash Index
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045166905424">
  </a>
  <a class="indexterm" name="idm46045166903936">
  </a>
  <p>
   The adaptive hash index enables
   <code class="literal">
    InnoDB
   </code>
   to
      perform more like an in-memory database on systems with
      appropriate combinations of workload and sufficient memory for the
      buffer pool without sacrificing transactional features or
      reliability. The adaptive hash index is disabled by the
   <a class="link" href="innodb-parameters.html#sysvar_innodb_adaptive_hash_index">
    <code class="literal">
     innodb_adaptive_hash_index
    </code>
   </a>
   variable, or turned on at server startup by
   <code class="literal">
    --innodb-adaptive-hash-index
   </code>
   .
  </p>
  <p>
   Based on the observed pattern of searches, a hash index is built
      using a prefix of the index key. The prefix can be any length, and
      it may be that only some values in the B-tree appear in the hash
      index. Hash indexes are built on demand for the pages of the index
      that are accessed often.
  </p>
  <p>
   If a table fits almost entirely in main memory, a hash index
      speeds up queries by enabling direct lookup of any element,
      turning the index value into a sort of pointer.
   <code class="literal">
    InnoDB
   </code>
   has a mechanism that monitors index
      searches. If
   <code class="literal">
    InnoDB
   </code>
   notices that queries could
      benefit from building a hash index, it does so automatically.
  </p>
  <p>
   With some workloads, the speedup from hash index lookups greatly
      outweighs the extra work to monitor index lookups and maintain the
      hash index structure. Access to the adaptive hash index can
      sometimes become a source of contention under heavy workloads,
      such as multiple concurrent joins. Queries with
   <code class="literal">
    LIKE
   </code>
   operators and
   <code class="literal">
    %
   </code>
   wildcards also tend not to benefit. For workloads that do not
      benefit from the adaptive hash index, turning it off reduces
      unnecessary performance overhead. Because it is difficult to
      predict in advance whether the adaptive hash index is appropriate
      for a particular system and workload, consider running benchmarks
      with it enabled and disabled.
  </p>
  <p>
   The adaptive hash index feature is partitioned. Each index is
      bound to a specific partition, and each partition is protected by
      a separate latch. Partitioning is controlled by the
   <a class="link" href="innodb-parameters.html#sysvar_innodb_adaptive_hash_index_parts">
    <code class="literal">
     innodb_adaptive_hash_index_parts
    </code>
   </a>
   variable. The
   <a class="link" href="innodb-parameters.html#sysvar_innodb_adaptive_hash_index_parts">
    <code class="literal">
     innodb_adaptive_hash_index_parts
    </code>
   </a>
   variable is set to 8 by default. The maximum setting is 512.
  </p>
  <p>
   You can monitor adaptive hash index use and contention in the
   <code class="literal">
    SEMAPHORES
   </code>
   section of
   <a class="link" href="show-engine.html" title="15.7.7.16 SHOW ENGINE Statement">
    <code class="literal">
     SHOW ENGINE INNODB
      STATUS
    </code>
   </a>
   output. If there are numerous threads waiting on
      rw-latches created in
   <code class="filename">
    btr0sea.c
   </code>
   , consider
      increasing the number of adaptive hash index partitions or
      disabling the adaptive hash index.
  </p>
  <p>
   For information about the performance characteristics of hash
      indexes, see
   <a class="xref" href="index-btree-hash.html" title="10.3.9 Comparison of B-Tree and Hash Indexes">
    Section 10.3.9, “Comparison of B-Tree and Hash Indexes”
   </a>
   .
  </p>
 </div>
 <br/>
</div>
