<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="optimizing-innodb-ddl-operations">
      </a>
      10.5.7 Optimizing InnoDB DDL Operations
     </h3>
    </div>
   </div>
  </div>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Many DDL operations on tables and indexes
            (
      <code class="literal">
       CREATE
      </code>
      ,
      <code class="literal">
       ALTER
      </code>
      , and
      <code class="literal">
       DROP
      </code>
      statements) can be performed online.
            See
      <a class="xref" href="innodb-online-ddl.html" title="17.12 InnoDB and Online DDL">
       Section 17.12, “InnoDB and Online DDL”
      </a>
      for details.
     </p>
    </li>
    <li class="listitem">
     <p>
      Online DDL support for adding secondary indexes means that
            you can generally speed up the process of creating and
            loading a table and associated indexes by creating the table
            without secondary indexes, then adding secondary indexes
            after the data is loaded.
     </p>
    </li>
    <li class="listitem">
     <p>
      Use
      <a class="link" href="truncate-table.html" title="15.1.37 TRUNCATE TABLE Statement">
       <code class="literal">
        TRUNCATE TABLE
       </code>
      </a>
      to empty a
            table, not
      <code class="literal">
       DELETE FROM
       <em class="replaceable">
        <code>
         tbl_name
        </code>
       </em>
      </code>
      . Foreign key
            constraints can make a
      <code class="literal">
       TRUNCATE
      </code>
      statement
            work like a regular
      <code class="literal">
       DELETE
      </code>
      statement, in
            which case a sequence of commands like
      <a class="link" href="drop-table.html" title="15.1.32 DROP TABLE Statement">
       <code class="literal">
        DROP TABLE
       </code>
      </a>
      and
      <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
       <code class="literal">
        CREATE TABLE
       </code>
      </a>
      might be
            fastest.
     </p>
    </li>
    <li class="listitem">
     <p>
      Because the primary key is integral to the storage layout of
            each
      <code class="literal">
       InnoDB
      </code>
      table, and changing the
            definition of the primary key involves reorganizing the
            whole table, always set up the primary key as part of the
      <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
       <code class="literal">
        CREATE TABLE
       </code>
      </a>
      statement, and
            plan ahead so that you do not need to
      <code class="literal">
       ALTER
      </code>
      or
      <code class="literal">
       DROP
      </code>
      the
            primary key afterward.
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
