<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="optimizing-memory-tables">
      </a>
      10.7 Optimizing for MEMORY Tables
     </h2>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045225633552">
  </a>
  <p>
   Consider using
   <code class="literal">
    MEMORY
   </code>
   tables for noncritical
      data that is accessed often, and is read-only or rarely updated.
      Benchmark your application against equivalent
   <code class="literal">
    InnoDB
   </code>
   or
   <code class="literal">
    MyISAM
   </code>
   tables
      under a realistic workload, to confirm that any additional
      performance is worth the risk of losing data, or the overhead of
      copying data from a disk-based table at application start.
  </p>
  <p>
   For best performance with
   <code class="literal">
    MEMORY
   </code>
   tables,
      examine the kinds of queries against each table, and specify the
      type to use for each associated index, either a B-tree index or a
      hash index. On the
   <a class="link" href="create-index.html" title="15.1.15 CREATE INDEX Statement">
    <code class="literal">
     CREATE INDEX
    </code>
   </a>
   statement, use the clause
   <code class="literal">
    USING BTREE
   </code>
   or
   <code class="literal">
    USING HASH
   </code>
   . B-tree indexes are fast for queries
      that do greater-than or less-than comparisons through operators
      such as
   <code class="literal">
    &gt;
   </code>
   or
   <code class="literal">
    BETWEEN
   </code>
   .
      Hash indexes are only fast for queries that look up single values
      through the
   <code class="literal">
    =
   </code>
   operator, or a restricted set of
      values through the
   <code class="literal">
    IN
   </code>
   operator. For why
   <code class="literal">
    USING BTREE
   </code>
   is often a better choice than the
      default
   <code class="literal">
    USING HASH
   </code>
   , see
   <a class="xref" href="table-scan-avoidance.html" title="10.2.1.23 Avoiding Full Table Scans">
    Section 10.2.1.23, “Avoiding Full Table Scans”
   </a>
   . For implementation details
      of the different types of
   <code class="literal">
    MEMORY
   </code>
   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>
