<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="federated-description">
      </a>
      18.8.1 FEDERATED Storage Engine Overview
     </h3>
    </div>
   </div>
  </div>
  <p>
   When you create a table using one of the standard storage engines
      (such as
   <code class="literal">
    MyISAM
   </code>
   ,
   <code class="literal">
    CSV
   </code>
   or
   <code class="literal">
    InnoDB
   </code>
   ), the table consists of the table
      definition and the associated data. When you create a
   <code class="literal">
    FEDERATED
   </code>
   table, the table definition is the
      same, but the physical storage of the data is handled on a remote
      server.
  </p>
  <p>
   A
   <code class="literal">
    FEDERATED
   </code>
   table consists of two elements:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      A
      <span class="emphasis">
       <em>
        remote server
       </em>
      </span>
      with a database table,
          which in turn consists of the table definition (stored in the
          MySQL data dictionary) and the associated table. The table
          type of the remote table may be any type supported by the
          remote
      <code class="literal">
       mysqld
      </code>
      server, including
      <code class="literal">
       MyISAM
      </code>
      or
      <code class="literal">
       InnoDB
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      A
      <span class="emphasis">
       <em>
        local server
       </em>
      </span>
      with a database table,
          where the table definition matches that of the corresponding
          table on the remote server. The table definition is stored in
          the data dictionary. There is no data file on the local
          server. Instead, the table definition includes a connection
          string that points to the remote table.
     </p>
    </li>
   </ul>
  </div>
  <p>
   When executing queries and statements on a
   <code class="literal">
    FEDERATED
   </code>
   table on the local server, the
      operations that would normally insert, update or delete
      information from a local data file are instead sent to the remote
      server for execution, where they update the data file on the
      remote server or return matching rows from the remote server.
  </p>
  <p>
   The basic structure of a
   <code class="literal">
    FEDERATED
   </code>
   table setup
      is shown in
   <a class="xref" href="federated-description.html#figure-se-federated-structure" title="Figure 18.2 FEDERATED Table Structure">
    Figure 18.2, “FEDERATED Table Structure”
   </a>
   .
  </p>
  <div class="figure">
   <a name="figure-se-federated-structure">
   </a>
   <p class="title">
    <b>
     Figure 18.2 FEDERATED Table Structure
    </b>
   </p>
   <div class="figure-contents">
    <div class="mediaobject">
     <img alt="Content is described in the surrounding text." src="images/se-federated-structure.png" style="width: 100%; max-width: 384px;"/>
    </div>
   </div>
  </div>
  <br class="figure-break"/>
  <p>
   When a client issues an SQL statement that refers to a
   <code class="literal">
    FEDERATED
   </code>
   table, the flow of information
      between the local server (where the SQL statement is executed) and
      the remote server (where the data is physically stored) is as
      follows:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      The storage engine looks through each column that the
      <code class="literal">
       FEDERATED
      </code>
      table has and constructs an
          appropriate SQL statement that refers to the remote table.
     </p>
    </li>
    <li class="listitem">
     <p>
      The statement is sent to the remote server using the MySQL
          client API.
     </p>
    </li>
    <li class="listitem">
     <p>
      The remote server processes the statement and the local server
          retrieves any result that the statement produces (an
          affected-rows count or a result set).
     </p>
    </li>
    <li class="listitem">
     <p>
      If the statement produces a result set, each column is
          converted to internal storage engine format that the
      <code class="literal">
       FEDERATED
      </code>
      engine expects and can use to
          display the result to the client that issued the original
          statement.
     </p>
    </li>
   </ol>
  </div>
  <p>
   The local server communicates with the remote server using MySQL
      client C API functions. It invokes
   <a class="ulink" href="/doc/c-api/8.4/en/mysql-real-query.html" target="_top">
    <code class="literal">
     mysql_real_query()
    </code>
   </a>
   to send the
      statement. To read a result set, it uses
   <a class="ulink" href="/doc/c-api/8.4/en/mysql-store-result.html" target="_top">
    <code class="literal">
     mysql_store_result()
    </code>
   </a>
   and fetches
      rows one at a time using
   <a class="ulink" href="/doc/c-api/8.4/en/mysql-fetch-row.html" target="_top">
    <code class="literal">
     mysql_fetch_row()
    </code>
   </a>
   .
  </p>
 </div>
 <br/>
</div>
