<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="performance-schema-statement-tables">
      </a>
      29.12.6 Performance Schema Statement Event Tables
     </h3>
    </div>
   </div>
  </div>
  <div class="toc">
   <dl class="toc">
    <dt>
     <span class="section">
      <a href="performance-schema-events-statements-current-table.html">
       29.12.6.1 The events_statements_current Table
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="performance-schema-events-statements-history-table.html">
       29.12.6.2 The events_statements_history Table
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="performance-schema-events-statements-history-long-table.html">
       29.12.6.3 The events_statements_history_long Table
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="performance-schema-prepared-statements-instances-table.html">
       29.12.6.4 The prepared_statements_instances Table
      </a>
     </span>
    </dt>
   </dl>
  </div>
  <p>
   The Performance Schema instruments statement execution.
        Statement events occur at a high level of the event hierarchy.
        Within the event hierarchy, wait events nest within stage
        events, which nest within statement events, which nest within
        transaction events.
  </p>
  <p>
   These tables store statement events:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="link" href="performance-schema-events-statements-current-table.html" title="29.12.6.1 The events_statements_current Table">
       <code class="literal">
        events_statements_current
       </code>
      </a>
      : The
            current statement event for each thread.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="performance-schema-events-statements-history-table.html" title="29.12.6.2 The events_statements_history Table">
       <code class="literal">
        events_statements_history
       </code>
      </a>
      : The
            most recent statement events that have ended per thread.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="performance-schema-events-statements-history-long-table.html" title="29.12.6.3 The events_statements_history_long Table">
       <code class="literal">
        events_statements_history_long
       </code>
      </a>
      :
            The most recent statement events that have ended globally
            (across all threads).
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="performance-schema-prepared-statements-instances-table.html" title="29.12.6.4 The prepared_statements_instances Table">
       <code class="literal">
        prepared_statements_instances
       </code>
      </a>
      :
            Prepared statement instances and statistics
     </p>
    </li>
   </ul>
  </div>
  <p>
   The following sections describe the statement event tables.
        There are also summary tables that aggregate information about
        statement events; see
   <a class="xref" href="performance-schema-statement-summary-tables.html" title="29.12.20.3 Statement Summary Tables">
    Section 29.12.20.3, “Statement Summary Tables”
   </a>
   .
  </p>
  <p>
   For more information about the relationship between the three
   <code class="literal">
    events_statements_
    <em class="replaceable">
     <code>
      xxx
     </code>
    </em>
   </code>
   event tables, see
   <a class="xref" href="performance-schema-event-tables.html" title="29.9 Performance Schema Tables for Current and Historical Events">
    Section 29.9, “Performance Schema Tables for Current and Historical Events”
   </a>
   .
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="xref" href="performance-schema-statement-tables.html#performance-schema-statement-tables-configuration" title="Configuring Statement Event Collection">
       Configuring Statement Event Collection
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="performance-schema-statement-tables.html#performance-schema-statement-tables-monitoring" title="Statement Monitoring">
       Statement Monitoring
      </a>
     </p>
    </li>
   </ul>
  </div>
  <h4>
   <a name="performance-schema-statement-tables-configuration">
   </a>
   Configuring Statement Event Collection
  </h4>
  <p>
   To control whether to collect statement events, set the state of
        the relevant instruments and consumers:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      The
      <a class="link" href="performance-schema-setup-instruments-table.html" title="29.12.2.3 The setup_instruments Table">
       <code class="literal">
        setup_instruments
       </code>
      </a>
      table
            contains instruments with names that begin with
      <code class="literal">
       statement
      </code>
      . Use these instruments to
            enable or disable collection of individual statement event
            classes.
     </p>
    </li>
    <li class="listitem">
     <p>
      The
      <a class="link" href="performance-schema-setup-consumers-table.html" title="29.12.2.2 The setup_consumers Table">
       <code class="literal">
        setup_consumers
       </code>
      </a>
      table
            contains consumer values with names corresponding to the
            current and historical statement event table names, and the
            statement digest consumer. Use these consumers to filter
            collection of statement events and statement digesting.
     </p>
    </li>
   </ul>
  </div>
  <p>
   The statement instruments are enabled by default, and the
   <code class="literal">
    events_statements_current
   </code>
   ,
   <code class="literal">
    events_statements_history
   </code>
   , and
   <code class="literal">
    statements_digest
   </code>
   statement consumers are
        enabled by default:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa85406825"><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-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token keyword">NAME</span><span class="token punctuation">,</span> ENABLED<span class="token punctuation">,</span> TIMED
       <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>setup_instruments
       <span class="token keyword">WHERE</span> <span class="token keyword">NAME</span> <span class="token operator">LIKE</span> <span class="token string">'statement/%'</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> NAME                                        <span class="token punctuation">|</span> ENABLED <span class="token punctuation">|</span> TIMED <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> statement/sql/select                        <span class="token punctuation">|</span> YES     <span class="token punctuation">|</span> YES   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> statement/sql/create_table                  <span class="token punctuation">|</span> YES     <span class="token punctuation">|</span> YES   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> statement/sql/create_index                  <span class="token punctuation">|</span> YES     <span class="token punctuation">|</span> YES   <span class="token punctuation">|</span></span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token output"><span class="token punctuation">|</span> statement/sp/stmt                           <span class="token punctuation">|</span> YES     <span class="token punctuation">|</span> YES   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> statement/sp/set                            <span class="token punctuation">|</span> YES     <span class="token punctuation">|</span> YES   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> statement/sp/set_trigger_field              <span class="token punctuation">|</span> YES     <span class="token punctuation">|</span> YES   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> statement/scheduler/event                   <span class="token punctuation">|</span> YES     <span class="token punctuation">|</span> YES   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> statement/com/Sleep                         <span class="token punctuation">|</span> YES     <span class="token punctuation">|</span> YES   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> statement/com/Quit                          <span class="token punctuation">|</span> YES     <span class="token punctuation">|</span> YES   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> statement/com/Init DB                       <span class="token punctuation">|</span> YES     <span class="token punctuation">|</span> YES   <span class="token punctuation">|</span></span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token output"><span class="token punctuation">|</span> statement/abstract/Query                    <span class="token punctuation">|</span> YES     <span class="token punctuation">|</span> YES   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> statement/abstract/new_packet               <span class="token punctuation">|</span> YES     <span class="token punctuation">|</span> YES   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> statement/abstract/relay_log                <span class="token punctuation">|</span> YES     <span class="token punctuation">|</span> YES   <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
  </div>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa6597527"><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-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span>
       <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>setup_consumers
       <span class="token keyword">WHERE</span> <span class="token keyword">NAME</span> <span class="token operator">LIKE</span> <span class="token string">'%statements%'</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> NAME                           <span class="token punctuation">|</span> ENABLED <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> events_statements_current      <span class="token punctuation">|</span> YES     <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> events_statements_history      <span class="token punctuation">|</span> YES     <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> events_statements_history_long <span class="token punctuation">|</span> NO      <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> statements_digest              <span class="token punctuation">|</span> YES     <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
  </div>
  <p>
   To control statement event collection at server startup, use
        lines like these in your
   <code class="filename">
    my.cnf
   </code>
   file:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Enable:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa15549469"><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-ini"><span class="token selector">[mysqld]</span>
<span class="token constant">performance-schema-instrument</span><span class="token attr-value"><span class="token punctuation">=</span>'statement/%=ON'</span>
<span class="token constant">performance-schema-consumer-events-statements-current</span><span class="token attr-value"><span class="token punctuation">=</span>ON</span>
<span class="token constant">performance-schema-consumer-events-statements-history</span><span class="token attr-value"><span class="token punctuation">=</span>ON</span>
<span class="token constant">performance-schema-consumer-events-statements-history-long</span><span class="token attr-value"><span class="token punctuation">=</span>ON</span>
<span class="token constant">performance-schema-consumer-statements-digest</span><span class="token attr-value"><span class="token punctuation">=</span>ON</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      Disable:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa64807089"><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-ini"><span class="token selector">[mysqld]</span>
<span class="token constant">performance-schema-instrument</span><span class="token attr-value"><span class="token punctuation">=</span>'statement/%=OFF'</span>
<span class="token constant">performance-schema-consumer-events-statements-current</span><span class="token attr-value"><span class="token punctuation">=</span>OFF</span>
<span class="token constant">performance-schema-consumer-events-statements-history</span><span class="token attr-value"><span class="token punctuation">=</span>OFF</span>
<span class="token constant">performance-schema-consumer-events-statements-history-long</span><span class="token attr-value"><span class="token punctuation">=</span>OFF</span>
<span class="token constant">performance-schema-consumer-statements-digest</span><span class="token attr-value"><span class="token punctuation">=</span>OFF</span></code></pre>
     </div>
    </li>
   </ul>
  </div>
  <p>
   To control statement event collection at runtime, update the
   <a class="link" href="performance-schema-setup-instruments-table.html" title="29.12.2.3 The setup_instruments Table">
    <code class="literal">
     setup_instruments
    </code>
   </a>
   and
   <a class="link" href="performance-schema-setup-consumers-table.html" title="29.12.2.2 The setup_consumers Table">
    <code class="literal">
     setup_consumers
    </code>
   </a>
   tables:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Enable:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa91103702"><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-sql"><span class="token keyword">UPDATE</span> performance_schema<span class="token punctuation">.</span>setup_instruments
<span class="token keyword">SET</span> ENABLED <span class="token operator">=</span> <span class="token string">'YES'</span><span class="token punctuation">,</span> TIMED <span class="token operator">=</span> <span class="token string">'YES'</span>
<span class="token keyword">WHERE</span> <span class="token keyword">NAME</span> <span class="token operator">LIKE</span> <span class="token string">'statement/%'</span><span class="token punctuation">;</span>

<span class="token keyword">UPDATE</span> performance_schema<span class="token punctuation">.</span>setup_consumers
<span class="token keyword">SET</span> ENABLED <span class="token operator">=</span> <span class="token string">'YES'</span>
<span class="token keyword">WHERE</span> <span class="token keyword">NAME</span> <span class="token operator">LIKE</span> <span class="token string">'%statements%'</span><span class="token punctuation">;</span></code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      Disable:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa41402211"><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-sql"><span class="token keyword">UPDATE</span> performance_schema<span class="token punctuation">.</span>setup_instruments
<span class="token keyword">SET</span> ENABLED <span class="token operator">=</span> <span class="token string">'NO'</span><span class="token punctuation">,</span> TIMED <span class="token operator">=</span> <span class="token string">'NO'</span>
<span class="token keyword">WHERE</span> <span class="token keyword">NAME</span> <span class="token operator">LIKE</span> <span class="token string">'statement/%'</span><span class="token punctuation">;</span>

<span class="token keyword">UPDATE</span> performance_schema<span class="token punctuation">.</span>setup_consumers
<span class="token keyword">SET</span> ENABLED <span class="token operator">=</span> <span class="token string">'NO'</span>
<span class="token keyword">WHERE</span> <span class="token keyword">NAME</span> <span class="token operator">LIKE</span> <span class="token string">'%statements%'</span><span class="token punctuation">;</span></code></pre>
     </div>
    </li>
   </ul>
  </div>
  <p>
   To collect only specific statement events, enable only the
        corresponding statement instruments. To collect statement events
        only for specific statement event tables, enable the statement
        instruments but only the statement consumers corresponding to
        the desired tables.
  </p>
  <p>
   For additional information about configuring event collection,
        see
   <a class="xref" href="performance-schema-startup-configuration.html" title="29.3 Performance Schema Startup Configuration">
    Section 29.3, “Performance Schema Startup Configuration”
   </a>
   ,
        and
   <a class="xref" href="performance-schema-runtime-configuration.html" title="29.4 Performance Schema Runtime Configuration">
    Section 29.4, “Performance Schema Runtime Configuration”
   </a>
   .
  </p>
  <h4>
   <a name="performance-schema-statement-tables-monitoring">
   </a>
   Statement Monitoring
  </h4>
  <p>
   Statement monitoring begins from the moment the server sees that
        activity is requested on a thread, to the moment when all
        activity has ceased. Typically, this means from the time the
        server gets the first packet from the client to the time the
        server has finished sending the response. Statements within
        stored programs are monitored like other statements.
  </p>
  <p>
   When the Performance Schema instruments a request (server
        command or SQL statement), it uses instrument names that proceed
        in stages from more general (or
   <span class="quote">
    “
    <span class="quote">
     abstract
    </span>
    ”
   </span>
   ) to more
        specific until it arrives at a final instrument name.
  </p>
  <p>
   Final instrument names correspond to server commands and SQL
        statements:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Server commands correspond to the
      <code class="literal">
       COM_
       <em class="replaceable">
        <code>
         xxx
        </code>
       </em>
       codes
      </code>
      defined in the
      <code class="filename">
       mysql_com.h
      </code>
      header file
            and processed in
      <code class="filename">
       sql/sql_parse.cc
      </code>
      .
            Examples are
      <code class="literal">
       COM_PING
      </code>
      and
      <code class="literal">
       COM_QUIT
      </code>
      . Instruments for commands have
            names that begin with
      <code class="literal">
       statement/com
      </code>
      , such
            as
      <code class="literal">
       statement/com/Ping
      </code>
      and
      <code class="literal">
       statement/com/Quit
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      SQL statements are expressed as text, such as
      <code class="literal">
       DELETE FROM t1
      </code>
      or
      <code class="literal">
       SELECT * FROM
            t2
      </code>
      . Instruments for SQL statements have names that
            begin with
      <code class="literal">
       statement/sql
      </code>
      , such as
      <code class="literal">
       statement/sql/delete
      </code>
      and
      <code class="literal">
       statement/sql/select
      </code>
      .
     </p>
    </li>
   </ul>
  </div>
  <p>
   Some final instrument names are specific to error handling:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <code class="literal">
       statement/com/Error
      </code>
      accounts for messages
            received by the server that are out of band. It can be used
            to detect commands sent by clients that the server does not
            understand. This may be helpful for purposes such as
            identifying clients that are misconfigured or using a
            version of MySQL more recent than that of the server, or
            clients that are attempting to attack the server.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       statement/sql/error
      </code>
      accounts for SQL
            statements that fail to parse. It can be used to detect
            malformed queries sent by clients. A query that fails to
            parse differs from a query that parses but fails due to an
            error during execution. For example,
      <code class="literal">
       SELECT *
            FROM
      </code>
      is malformed, and the
      <code class="literal">
       statement/sql/error
      </code>
      instrument is used.
            By contrast,
      <code class="literal">
       SELECT *
      </code>
      parses but fails
            with a
      <code class="literal">
       No tables used
      </code>
      error. In this
            case,
      <code class="literal">
       statement/sql/select
      </code>
      is used and
            the statement event contains information to indicate the
            nature of the error.
     </p>
    </li>
   </ul>
  </div>
  <p>
   A request can be obtained from any of these sources:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      As a command or statement request from a client, which sends
            the request as packets
     </p>
    </li>
    <li class="listitem">
     <p>
      As a statement string read from the relay log on a replica
     </p>
    </li>
    <li class="listitem">
     <p>
      As an event from the Event Scheduler
     </p>
    </li>
   </ul>
  </div>
  <p>
   The details for a request are not initially known and the
        Performance Schema proceeds from abstract to specific instrument
        names in a sequence that depends on the source of the request.
  </p>
  <p>
   For a request received from a client:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      When the server detects a new packet at the socket level, a
            new statement is started with an abstract instrument name of
      <code class="literal">
       statement/abstract/new_packet
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      When the server reads the packet number, it knows more about
            the type of request received, and the Performance Schema
            refines the instrument name. For example, if the request is
            a
      <code class="literal">
       COM_PING
      </code>
      packet, the instrument name
            becomes
      <code class="literal">
       statement/com/Ping
      </code>
      and that is
            the final name. If the request is a
      <code class="literal">
       COM_QUERY
      </code>
      packet, it is known to
            correspond to an SQL statement but not the particular type
            of statement. In this case, the instrument changes from one
            abstract name to a more specific but still abstract name,
      <code class="literal">
       statement/abstract/Query
      </code>
      , and the request
            requires further classification.
     </p>
    </li>
    <li class="listitem">
     <p>
      If the request is a statement, the statement text is read
            and given to the parser. After parsing, the exact statement
            type is known. If the request is, for example, an
      <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
       <code class="literal">
        INSERT
       </code>
      </a>
      statement, the
            Performance Schema refines the instrument name from
      <code class="literal">
       statement/abstract/Query
      </code>
      to
      <code class="literal">
       statement/sql/insert
      </code>
      , which is the final
            name.
     </p>
    </li>
   </ol>
  </div>
  <p>
   For a request read as a statement from the relay log on a
        replica:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      Statements in the relay log are stored as text and are read
            as such. There is no network protocol, so the
      <code class="literal">
       statement/abstract/new_packet
      </code>
      instrument
            is not used. Instead, the initial instrument is
      <code class="literal">
       statement/abstract/relay_log
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      When the statement is parsed, the exact statement type is
            known. If the request is, for example, an
      <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
       <code class="literal">
        INSERT
       </code>
      </a>
      statement, the
            Performance Schema refines the instrument name from
      <code class="literal">
       statement/abstract/Query
      </code>
      to
      <code class="literal">
       statement/sql/insert
      </code>
      , which is the final
            name.
     </p>
    </li>
   </ol>
  </div>
  <p>
   The preceding description applies only for statement-based
        replication. For row-based replication, table I/O done on the
        replica as it processes row changes can be instrumented, but row
        events in the relay log do not appear as discrete statements.
  </p>
  <p>
   For a request received from the Event Scheduler:
  </p>
  <p>
   The event execution is instrumented using the name
   <code class="literal">
    statement/scheduler/event
   </code>
   . This is the final
        name.
  </p>
  <p>
   Statements executed within the event body are instrumented using
   <code class="literal">
    statement/sql/*
   </code>
   names, without use of any
        preceding abstract instrument. An event is a stored program, and
        stored programs are precompiled in memory before execution.
        Consequently, there is no parsing at runtime and the type of
        each statement is known by the time it executes.
  </p>
  <p>
   Statements executed within the event body are child statements.
        For example, if an event executes an
   <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
    <code class="literal">
     INSERT
    </code>
   </a>
   statement, execution of
        the event itself is the parent, instrumented using
   <code class="literal">
    statement/scheduler/event
   </code>
   , and the
   <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
    <code class="literal">
     INSERT
    </code>
   </a>
   is the child, instrumented
        using
   <code class="literal">
    statement/sql/insert
   </code>
   . The parent/child
        relationship holds
   <span class="emphasis">
    <em>
     between
    </em>
   </span>
   separate
        instrumented operations. This differs from the sequence of
        refinement that occurs
   <span class="emphasis">
    <em>
     within
    </em>
   </span>
   a single
        instrumented operation, from abstract to final instrument names.
  </p>
  <p>
   For statistics to be collected for statements, it is not
        sufficient to enable only the final
   <code class="literal">
    statement/sql/*
   </code>
   instruments used for
        individual statement types. The abstract
   <code class="literal">
    statement/abstract/*
   </code>
   instruments must be
        enabled as well. This should not normally be an issue because
        all statement instruments are enabled by default. However, an
        application that enables or disables statement instruments
        selectively must take into account that disabling abstract
        instruments also disables statistics collection for the
        individual statement instruments. For example, to collect
        statistics for
   <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
    <code class="literal">
     INSERT
    </code>
   </a>
   statements,
   <code class="literal">
    statement/sql/insert
   </code>
   must be enabled, but
        also
   <code class="literal">
    statement/abstract/new_packet
   </code>
   and
   <code class="literal">
    statement/abstract/Query
   </code>
   . Similarly, for
        replicated statements to be instrumented,
   <code class="literal">
    statement/abstract/relay_log
   </code>
   must be enabled.
  </p>
  <p>
   No statistics are aggregated for abstract instruments such as
   <code class="literal">
    statement/abstract/Query
   </code>
   because no statement
        is ever classified with an abstract instrument as the final
        statement name.
  </p>
 </div>
 <br/>
</div>
