<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="myisam-optimization">
      </a>
      9.6.4 MyISAM Table Optimization
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045230482032">
  </a>
  <a class="indexterm" name="idm46045230480576">
  </a>
  <p>
   To coalesce fragmented rows and eliminate wasted space that
        results from deleting or updating rows, run
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   in recovery mode:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa74323940"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal"><span class="token prompt">$&gt; </span><span class="token command">myisamchk</span> <span class="token property">-r</span> <em class="replaceable">tbl_name</em></code></pre>
  </div>
  <p>
   You can optimize a table in the same way by using the
   <a class="link" href="optimize-table.html" title="15.7.3.4 OPTIMIZE TABLE Statement">
    <code class="literal">
     OPTIMIZE TABLE
    </code>
   </a>
   SQL statement.
   <a class="link" href="optimize-table.html" title="15.7.3.4 OPTIMIZE TABLE Statement">
    <code class="literal">
     OPTIMIZE TABLE
    </code>
   </a>
   does a table
        repair and a key analysis, and also sorts the index tree so that
        key lookups are faster. There is also no possibility of unwanted
        interaction between a utility and the server, because the server
        does all the work when you use
   <a class="link" href="optimize-table.html" title="15.7.3.4 OPTIMIZE TABLE Statement">
    <code class="literal">
     OPTIMIZE
        TABLE
    </code>
   </a>
   . See
   <a class="xref" href="optimize-table.html" title="15.7.3.4 OPTIMIZE TABLE Statement">
    Section 15.7.3.4, “OPTIMIZE TABLE Statement”
   </a>
   .
  </p>
  <p>
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   has a number of other options that
        you can use to improve the performance of a table:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="link" href="myisamchk-other-options.html#option_myisamchk_analyze">
       <code class="option">
        --analyze
       </code>
      </a>
      or
      <code class="option">
       -a
      </code>
      : Perform key distribution analysis. This
            improves join performance by enabling the join optimizer to
            better choose the order in which to join the tables and
            which indexes it should use.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="myisamchk-other-options.html#option_myisamchk_sort-index">
       <code class="option">
        --sort-index
       </code>
      </a>
      or
      <code class="option">
       -S
      </code>
      : Sort the index blocks. This optimizes
            seeks and makes table scans that use indexes faster.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="myisamchk-other-options.html#option_myisamchk_sort-records">
       <code class="option">
        --sort-records=
        <em class="replaceable">
         <code>
          index_num
         </code>
        </em>
       </code>
      </a>
      or
      <code class="option">
       -R
       <em class="replaceable">
        <code>
         index_num
        </code>
       </em>
      </code>
      :
            Sort data rows according to a given index. This makes your
            data much more localized and may speed up range-based
      <a class="link" href="select.html" title="15.2.13 SELECT Statement">
       <code class="literal">
        SELECT
       </code>
      </a>
      and
      <code class="literal">
       ORDER
            BY
      </code>
      operations that use this index.
     </p>
    </li>
   </ul>
  </div>
  <p>
   For a full description of all available options, see
   <a class="xref" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    Section 6.6.4, “myisamchk — MyISAM Table-Maintenance Utility”
   </a>
   .
  </p>
 </div>
 <br/>
</div>
