<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="performance-schema-functions">
      </a>
      14.21 Performance Schema Functions
     </h2>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045191704160">
  </a>
  <a class="indexterm" name="idm46045191702672">
  </a>
  <p>
   MySQL includes built-in SQL functions that format or retrieve
      Performance Schema data, and that may be used as equivalents for
      the corresponding
   <code class="literal">
    sys
   </code>
   schema stored functions.
      The built-in functions can be invoked in any schema and require no
      qualifier, unlike the
   <code class="literal">
    sys
   </code>
   functions, which
      require either a
   <code class="literal">
    sys.
   </code>
   schema qualifier or that
   <code class="literal">
    sys
   </code>
   be the current schema.
  </p>
  <div class="table">
   <a name="idm46045191698064">
   </a>
   <p class="title">
    <b>
     Table 14.31 Performance Schema Functions
    </b>
   </p>
   <div class="table-contents">
    <table frame="box" rules="all" summary="A reference that lists Performance Schema functions.">
     <colgroup>
      <col style="width: 28%"/>
      <col style="width: 71%"/>
     </colgroup>
     <thead>
      <tr>
       <th>
        Name
       </th>
       <th>
        Description
       </th>
      </tr>
     </thead>
     <tbody>
      <tr>
       <td>
        <a class="link" href="performance-schema-functions.html#function_format-bytes">
         <code class="literal">
          FORMAT_BYTES()
         </code>
        </a>
       </td>
       <td>
        Convert byte count to value with units
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="performance-schema-functions.html#function_format-pico-time">
         <code class="literal">
          FORMAT_PICO_TIME()
         </code>
        </a>
       </td>
       <td>
        Convert time in picoseconds to value with units
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="performance-schema-functions.html#function_ps-current-thread-id">
         <code class="literal">
          PS_CURRENT_THREAD_ID()
         </code>
        </a>
       </td>
       <td>
        Performance Schema thread ID for current thread
       </td>
      </tr>
      <tr>
       <td>
        <a class="link" href="performance-schema-functions.html#function_ps-thread-id">
         <code class="literal">
          PS_THREAD_ID()
         </code>
        </a>
       </td>
       <td>
        Performance Schema thread ID for given thread
       </td>
      </tr>
     </tbody>
    </table>
   </div>
  </div>
  <br class="table-break"/>
  <p>
   The built-in functions supersede the corresponding
   <code class="literal">
    sys
   </code>
   functions, which are deprecated; expect
      them to be removed in a future version of MySQL. Applications that
      use the
   <code class="literal">
    sys
   </code>
   functions should be adjusted to use
      the built-in functions instead, keeping in mind some minor
      differences between the
   <code class="literal">
    sys
   </code>
   functions and the
      built-in functions. For details about these differences, see the
      function descriptions in this section.
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <a name="function_format-bytes">
     </a>
     <p>
      <a class="link" href="performance-schema-functions.html#function_format-bytes">
       <code class="literal">
        FORMAT_BYTES(
        <em class="replaceable">
         <code>
          count
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045191671424">
     </a>
     <p>
      Given a numeric byte count, converts it to human-readable
          format and returns a string consisting of a value and a units
          indicator. The string contains the number of bytes rounded to
          2 decimal places and a minimum of 3 significant digits.
          Numbers less than 1024 bytes are represented as whole numbers
          and are not rounded. Returns
      <code class="literal">
       NULL
      </code>
      if
      <em class="replaceable">
       <code>
        count
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      The units indicator depends on the size of the byte-count
          argument as shown in the following table.
     </p>
     <div class="informaltable">
      <table summary="Units indicators used by FORMAT_BYTES() function.">
       <colgroup>
        <col style="width: 30%"/>
        <col style="width: 25%"/>
        <col style="width: 45%"/>
       </colgroup>
       <thead>
        <tr>
         <th scope="col">
          Argument Value
         </th>
         <th scope="col">
          Result Units
         </th>
         <th scope="col">
          Result Units Indicator
         </th>
        </tr>
       </thead>
       <tbody>
        <tr>
         <th scope="row">
          Up to 1023
         </th>
         <td>
          bytes
         </td>
         <td>
          bytes
         </td>
        </tr>
        <tr>
         <th scope="row">
          Up to 1024
          <sup>
           2
          </sup>
          − 1
         </th>
         <td>
          kibibytes
         </td>
         <td>
          KiB
         </td>
        </tr>
        <tr>
         <th scope="row">
          Up to 1024
          <sup>
           3
          </sup>
          − 1
         </th>
         <td>
          mebibytes
         </td>
         <td>
          MiB
         </td>
        </tr>
        <tr>
         <th scope="row">
          Up to 1024
          <sup>
           4
          </sup>
          − 1
         </th>
         <td>
          gibibytes
         </td>
         <td>
          GiB
         </td>
        </tr>
        <tr>
         <th scope="row">
          Up to 1024
          <sup>
           5
          </sup>
          − 1
         </th>
         <td>
          tebibytes
         </td>
         <td>
          TiB
         </td>
        </tr>
        <tr>
         <th scope="row">
          Up to 1024
          <sup>
           6
          </sup>
          − 1
         </th>
         <td>
          pebibytes
         </td>
         <td>
          PiB
         </td>
        </tr>
        <tr>
         <th scope="row">
          1024
          <sup>
           6
          </sup>
          and up
         </th>
         <td>
          exbibytes
         </td>
         <td>
          EiB
         </td>
        </tr>
       </tbody>
      </table>
     </div>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa82214424"><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> FORMAT_BYTES<span class="token punctuation">(</span><span class="token number">512</span><span class="token punctuation">)</span><span class="token punctuation">,</span> FORMAT_BYTES<span class="token punctuation">(</span><span class="token number">18446644073709551615</span><span class="token punctuation">)</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>
<span class="token output"><span class="token punctuation">|</span> FORMAT_BYTES(512) <span class="token punctuation">|</span> FORMAT_BYTES(18446644073709551615) <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>
<span class="token output"><span class="token punctuation">|</span>  512 bytes        <span class="token punctuation">|</span> 16.00 EiB                          <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></code></pre>
     </div>
     <p>
      <a class="link" href="performance-schema-functions.html#function_format-bytes">
       <code class="literal">
        FORMAT_BYTES()
       </code>
      </a>
      may be used
          instead of the
      <code class="literal">
       sys
      </code>
      schema
      <a class="link" href="sys-format-bytes.html" title="30.4.5.3 The format_bytes() Function">
       <code class="literal">
        format_bytes()
       </code>
      </a>
      function, keeping
          in mind this difference:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         <a class="link" href="performance-schema-functions.html#function_format-bytes">
          <code class="literal">
           FORMAT_BYTES()
          </code>
         </a>
         uses the
         <code class="literal">
          EiB
         </code>
         units indicator.
         <a class="link" href="sys-format-bytes.html" title="30.4.5.3 The format_bytes() Function">
          <code class="literal">
           sys.format_bytes()
          </code>
         </a>
         does not.
        </p>
       </li>
      </ul>
     </div>
    </li>
    <li class="listitem">
     <a name="function_format-pico-time">
     </a>
     <p>
      <a class="link" href="performance-schema-functions.html#function_format-pico-time">
       <code class="literal">
        FORMAT_PICO_TIME(
        <em class="replaceable">
         <code>
          time_val
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045191617248">
     </a>
     <p>
      Given a numeric Performance Schema latency or wait time in
          picoseconds, converts it to human-readable format and returns
          a string consisting of a value and a units indicator. The
          string contains the decimal time rounded to 2 decimal places
          and a minimum of 3 significant digits. Times under 1
          nanosecond are represented as whole numbers and are not
          rounded.
     </p>
     <p>
      If
      <em class="replaceable">
       <code>
        time_val
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      , this function returns
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      The units indicator depends on the size of the time-value
          argument as shown in the following table.
     </p>
     <div class="informaltable">
      <table summary="Units indicators used by FORMAT_PICO_TIME() function.">
       <colgroup>
        <col style="width: 30%"/>
        <col style="width: 25%"/>
        <col style="width: 45%"/>
       </colgroup>
       <thead>
        <tr>
         <th scope="col">
          Argument Value
         </th>
         <th scope="col">
          Result Units
         </th>
         <th scope="col">
          Result Units Indicator
         </th>
        </tr>
       </thead>
       <tbody>
        <tr>
         <th scope="row">
          Up to 10
          <sup>
           3
          </sup>
          − 1
         </th>
         <td>
          picoseconds
         </td>
         <td>
          ps
         </td>
        </tr>
        <tr>
         <th scope="row">
          Up to 10
          <sup>
           6
          </sup>
          − 1
         </th>
         <td>
          nanoseconds
         </td>
         <td>
          ns
         </td>
        </tr>
        <tr>
         <th scope="row">
          Up to 10
          <sup>
           9
          </sup>
          − 1
         </th>
         <td>
          microseconds
         </td>
         <td>
          us
         </td>
        </tr>
        <tr>
         <th scope="row">
          Up to 10
          <sup>
           12
          </sup>
          − 1
         </th>
         <td>
          milliseconds
         </td>
         <td>
          ms
         </td>
        </tr>
        <tr>
         <th scope="row">
          Up to 60×10
          <sup>
           12
          </sup>
          − 1
         </th>
         <td>
          seconds
         </td>
         <td>
          s
         </td>
        </tr>
        <tr>
         <th scope="row">
          Up to 3.6×10
          <sup>
           15
          </sup>
          − 1
         </th>
         <td>
          minutes
         </td>
         <td>
          min
         </td>
        </tr>
        <tr>
         <th scope="row">
          Up to 8.64×10
          <sup>
           16
          </sup>
          − 1
         </th>
         <td>
          hours
         </td>
         <td>
          h
         </td>
        </tr>
        <tr>
         <th scope="row">
          8.64×10
          <sup>
           16
          </sup>
          and up
         </th>
         <td>
          days
         </td>
         <td>
          d
         </td>
        </tr>
       </tbody>
      </table>
     </div>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa63395209"><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> FORMAT_PICO_TIME<span class="token punctuation">(</span><span class="token number">3501</span><span class="token punctuation">)</span><span class="token punctuation">,</span> FORMAT_PICO_TIME<span class="token punctuation">(</span><span class="token number">188732396662000</span><span class="token punctuation">)</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>
<span class="token output"><span class="token punctuation">|</span> FORMAT_PICO_TIME(3501) <span class="token punctuation">|</span> FORMAT_PICO_TIME(188732396662000) <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>
<span class="token output"><span class="token punctuation">|</span> 3.50 ns                <span class="token punctuation">|</span> 3.15 min                          <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></code></pre>
     </div>
     <p>
      <a class="link" href="performance-schema-functions.html#function_format-pico-time">
       <code class="literal">
        FORMAT_PICO_TIME()
       </code>
      </a>
      may be used
          instead of the
      <code class="literal">
       sys
      </code>
      schema
      <a class="link" href="sys-format-time.html" title="30.4.5.6 The format_time() Function">
       <code class="literal">
        format_time()
       </code>
      </a>
      function, keeping
          in mind these differences:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         To indicate minutes,
         <a class="link" href="sys-format-time.html" title="30.4.5.6 The format_time() Function">
          <code class="literal">
           sys.format_time()
          </code>
         </a>
         uses the
         <code class="literal">
          m
         </code>
         units indicator, whereas
         <a class="link" href="performance-schema-functions.html#function_format-pico-time">
          <code class="literal">
           FORMAT_PICO_TIME()
          </code>
         </a>
         uses
         <code class="literal">
          min
         </code>
         .
        </p>
       </li>
       <li class="listitem">
        <p>
         <a class="link" href="sys-format-time.html" title="30.4.5.6 The format_time() Function">
          <code class="literal">
           sys.format_time()
          </code>
         </a>
         uses the
         <code class="literal">
          w
         </code>
         (weeks) units indicator.
         <a class="link" href="performance-schema-functions.html#function_format-pico-time">
          <code class="literal">
           FORMAT_PICO_TIME()
          </code>
         </a>
         does
              not.
        </p>
       </li>
      </ul>
     </div>
    </li>
    <li class="listitem">
     <a name="function_ps-current-thread-id">
     </a>
     <p>
      <a class="link" href="performance-schema-functions.html#function_ps-current-thread-id">
       <code class="literal">
        PS_CURRENT_THREAD_ID()
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045191554160">
     </a>
     <p>
      Returns a
      <code class="literal">
       BIGINT UNSIGNED
      </code>
      value
          representing the Performance Schema thread ID assigned to the
          current connection.
     </p>
     <p>
      The thread ID return value is a value of the type given in the
      <code class="literal">
       THREAD_ID
      </code>
      column of Performance Schema
          tables.
     </p>
     <p>
      Performance Schema configuration affects
      <a class="link" href="performance-schema-functions.html#function_ps-current-thread-id">
       <code class="literal">
        PS_CURRENT_THREAD_ID()
       </code>
      </a>
      the same
          way as for
      <a class="link" href="performance-schema-functions.html#function_ps-thread-id">
       <code class="literal">
        PS_THREAD_ID()
       </code>
      </a>
      . For
          details, see the description of that function.
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa88746901"><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> PS_CURRENT_THREAD_ID<span class="token punctuation">(</span><span class="token punctuation">)</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>
<span class="token output"><span class="token punctuation">|</span> PS_CURRENT_THREAD_ID() <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>
<span class="token output"><span class="token punctuation">|</span>                     52 <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>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> PS_THREAD_ID<span class="token punctuation">(</span><span class="token function">CONNECTION_ID</span><span class="token punctuation">(</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><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="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> PS_THREAD_ID(CONNECTION_ID()) <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>
<span class="token output"><span class="token punctuation">|</span>                            52 <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></code></pre>
     </div>
     <p>
      <a class="link" href="performance-schema-functions.html#function_ps-current-thread-id">
       <code class="literal">
        PS_CURRENT_THREAD_ID()
       </code>
      </a>
      may be
          used as a shortcut for invoking the
      <code class="literal">
       sys
      </code>
      schema
      <a class="link" href="sys-ps-thread-id.html" title="30.4.5.15 The ps_thread_id() Function">
       <code class="literal">
        ps_thread_id()
       </code>
      </a>
      function
          with an argument of
      <code class="literal">
       NULL
      </code>
      or
      <a class="link" href="information-functions.html#function_connection-id">
       <code class="literal">
        CONNECTION_ID()
       </code>
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <a name="function_ps-thread-id">
     </a>
     <p>
      <a class="link" href="performance-schema-functions.html#function_ps-thread-id">
       <code class="literal">
        PS_THREAD_ID(
        <em class="replaceable">
         <code>
          connection_id
         </code>
        </em>
        )
       </code>
      </a>
     </p>
     <a class="indexterm" name="idm46045191532640">
     </a>
     <p>
      Given a connection ID, returns a
      <code class="literal">
       BIGINT
          UNSIGNED
      </code>
      value representing the Performance Schema
          thread ID assigned to the connection ID, or
      <code class="literal">
       NULL
      </code>
      if no thread ID exists for the
          connection ID. The latter can occur for threads that are not
          instrumented, or if
      <em class="replaceable">
       <code>
        connection_id
       </code>
      </em>
      is
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      The connection ID argument is a value of the type given in the
      <code class="literal">
       PROCESSLIST_ID
      </code>
      column of the Performance
          Schema
      <a class="link" href="performance-schema-threads-table.html" title="29.12.22.8 The threads Table">
       <code class="literal">
        threads
       </code>
      </a>
      table or the
      <code class="literal">
       Id
      </code>
      column of
      <a class="link" href="show-processlist.html" title="15.7.7.31 SHOW PROCESSLIST Statement">
       <code class="literal">
        SHOW
          PROCESSLIST
       </code>
      </a>
      output.
     </p>
     <p>
      The thread ID return value is a value of the type given in the
      <code class="literal">
       THREAD_ID
      </code>
      column of Performance Schema
          tables.
     </p>
     <p>
      Performance Schema configuration affects
      <a class="link" href="performance-schema-functions.html#function_ps-thread-id">
       <code class="literal">
        PS_THREAD_ID()
       </code>
      </a>
      operation as
          follows. (These remarks also apply to
      <a class="link" href="performance-schema-functions.html#function_ps-current-thread-id">
       <code class="literal">
        PS_CURRENT_THREAD_ID()
       </code>
      </a>
      .)
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         Disabling the
         <code class="literal">
          thread_instrumentation
         </code>
         consumer disables statistics from being collected and
              aggregated at the thread level, but has no effect on
         <a class="link" href="performance-schema-functions.html#function_ps-thread-id">
          <code class="literal">
           PS_THREAD_ID()
          </code>
         </a>
         .
        </p>
       </li>
       <li class="listitem">
        <p>
         If
         <a class="link" href="performance-schema-system-variables.html#sysvar_performance_schema_max_thread_instances">
          <code class="literal">
           performance_schema_max_thread_instances
          </code>
         </a>
         is not 0, the Performance Schema allocates memory for
              thread statistics and assigns an internal ID to each
              thread for which instance memory is available. If there
              are threads for which instance memory is not available,
         <a class="link" href="performance-schema-functions.html#function_ps-thread-id">
          <code class="literal">
           PS_THREAD_ID()
          </code>
         </a>
         returns
         <code class="literal">
          NULL
         </code>
         ; in this case,
         <a class="link" href="performance-schema-status-variables.html#statvar_Performance_schema_thread_instances_lost">
          <code class="literal">
           Performance_schema_thread_instances_lost
          </code>
         </a>
         is nonzero.
        </p>
       </li>
       <li class="listitem">
        <p>
         If
         <a class="link" href="performance-schema-system-variables.html#sysvar_performance_schema_max_thread_instances">
          <code class="literal">
           performance_schema_max_thread_instances
          </code>
         </a>
         is 0, the Performance Schema allocates no thread memory
              and
         <a class="link" href="performance-schema-functions.html#function_ps-thread-id">
          <code class="literal">
           PS_THREAD_ID()
          </code>
         </a>
         returns
         <code class="literal">
          NULL
         </code>
         .
        </p>
       </li>
       <li class="listitem">
        <p>
         If the Performance Schema itself is disabled,
         <a class="link" href="performance-schema-functions.html#function_ps-thread-id">
          <code class="literal">
           PS_THREAD_ID()
          </code>
         </a>
         produces an
              error.
        </p>
       </li>
      </ul>
     </div>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa32280947"><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> PS_THREAD_ID<span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">)</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>
<span class="token output"><span class="token punctuation">|</span> PS_THREAD_ID(6) <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>
<span class="token output"><span class="token punctuation">|</span>              45 <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></code></pre>
     </div>
     <p>
      <a class="link" href="performance-schema-functions.html#function_ps-thread-id">
       <code class="literal">
        PS_THREAD_ID()
       </code>
      </a>
      may be used
          instead of the
      <code class="literal">
       sys
      </code>
      schema
      <a class="link" href="sys-ps-thread-id.html" title="30.4.5.15 The ps_thread_id() Function">
       <code class="literal">
        ps_thread_id()
       </code>
      </a>
      function, keeping
          in mind this difference:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         With an argument of
         <code class="literal">
          NULL
         </code>
         ,
         <a class="link" href="sys-ps-thread-id.html" title="30.4.5.15 The ps_thread_id() Function">
          <code class="literal">
           sys.ps_thread_id()
          </code>
         </a>
         returns
              the thread ID for the current connection, whereas
         <a class="link" href="performance-schema-functions.html#function_ps-thread-id">
          <code class="literal">
           PS_THREAD_ID()
          </code>
         </a>
         returns
         <code class="literal">
          NULL
         </code>
         . To obtain the current connection
              thread ID, use
         <a class="link" href="performance-schema-functions.html#function_ps-current-thread-id">
          <code class="literal">
           PS_CURRENT_THREAD_ID()
          </code>
         </a>
         instead.
        </p>
       </li>
      </ul>
     </div>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
