<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="create-table-secondary-indexes">
      </a>
      15.1.20.9 Secondary Indexes and Generated Columns
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045184698016">
  </a>
  <p>
   <code class="literal">
    InnoDB
   </code>
   supports secondary indexes on virtual
        generated columns. Other index types are not supported. A
        secondary index defined on a virtual column is sometimes
        referred to as a
   <span class="quote">
    “
    <span class="quote">
     virtual index
    </span>
    ”
   </span>
   .
  </p>
  <p>
   A secondary index may be created on one or more virtual columns
        or on a combination of virtual columns and regular columns or
        stored generated columns. Secondary indexes that include virtual
        columns may be defined as
   <code class="literal">
    UNIQUE
   </code>
   .
  </p>
  <p>
   When a secondary index is created on a virtual generated column,
        generated column values are materialized in the records of the
        index. If the index is a
   <a class="link" href="glossary.html#glos_covering_index" title="covering index">
    covering index
   </a>
   (one
        that includes all the columns retrieved by a query), generated
        column values are retrieved from materialized values in the
        index structure instead of computed
   <span class="quote">
    “
    <span class="quote">
     on the fly
    </span>
    ”
   </span>
   .
  </p>
  <p>
   There are additional write costs to consider when using a
        secondary index on a virtual column due to computation performed
        when materializing virtual column values in secondary index
        records during
   <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
    <code class="literal">
     INSERT
    </code>
   </a>
   and
   <a class="link" href="update.html" title="15.2.17 UPDATE Statement">
    <code class="literal">
     UPDATE
    </code>
   </a>
   operations. Even with
        additional write costs, secondary indexes on virtual columns may
        be preferable to generated
   <span class="emphasis">
    <em>
     stored
    </em>
   </span>
   columns,
        which are materialized in the clustered index, resulting in
        larger tables that require more disk space and memory. If a
        secondary index is not defined on a virtual column, there are
        additional costs for reads, as virtual column values must be
        computed each time the column's row is examined.
  </p>
  <p>
   Values of an indexed virtual column are MVCC-logged to avoid
        unnecessary recomputation of generated column values during
        rollback or during a purge operation. The data length of logged
        values is limited by the index key limit of 767 bytes for
   <code class="literal">
    COMPACT
   </code>
   and
   <code class="literal">
    REDUNDANT
   </code>
   row
        formats, and 3072 bytes for
   <code class="literal">
    DYNAMIC
   </code>
   and
   <code class="literal">
    COMPRESSED
   </code>
   row formats.
  </p>
  <p>
   Adding or dropping a secondary index on a virtual column is an
        in-place operation.
  </p>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="json-column-indirect-index">
       </a>
       Indexing a Generated Column to Provide a JSON Column Index
      </h5>
     </div>
    </div>
   </div>
   <p>
    As noted elsewhere,
    <a class="link" href="json.html" title="13.5 The JSON Data Type">
     <code class="literal">
      JSON
     </code>
    </a>
    columns cannot be indexed directly. To create an index that
          references such a column indirectly, you can define a
          generated column that extracts the information that should be
          indexed, then create an index on the generated column, as
          shown in this example:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa52640304"><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">CREATE</span> <span class="token keyword">TABLE</span> jemp <span class="token punctuation">(</span>
<span class="token prompt">    -&gt;</span>     c <span class="token datatype">JSON</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>     g <span class="token datatype">INT</span> <span class="token keyword">GENERATED</span> <span class="token keyword">ALWAYS</span> <span class="token keyword">AS</span> <span class="token punctuation">(</span>c<span class="token operator">-</span><span class="token operator">&gt;</span><span class="token string">"$.id"</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token prompt">    -&gt;</span>     <span class="token keyword">INDEX</span> i <span class="token punctuation">(</span>g<span class="token punctuation">)</span>
<span class="token prompt">    -&gt;</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 0 rows affected (0.28 sec)</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> jemp <span class="token punctuation">(</span>c<span class="token punctuation">)</span> <span class="token keyword">VALUES</span>
     <span class="token operator">&gt;</span>   <span class="token punctuation">(</span><span class="token string">'{"id": "1", "name": "Fred"}'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">'{"id": "2", "name": "Wilma"}'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
     <span class="token operator">&gt;</span>   <span class="token punctuation">(</span><span class="token string">'{"id": "3", "name": "Barney"}'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">'{"id": "4", "name": "Betty"}'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 4 rows affected (0.04 sec)</span>
<span class="token output">Records: 4  Duplicates: 0  Warnings: 0</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> c<span class="token operator">-</span><span class="token operator">&gt;&gt;</span><span class="token string">"$.name"</span> <span class="token keyword">AS</span> <span class="token keyword">name</span>
     <span class="token operator">&gt;</span>     <span class="token keyword">FROM</span> jemp <span class="token keyword">WHERE</span> g <span class="token operator">&gt;</span> <span class="token number">2</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>
<span class="token output"><span class="token punctuation">|</span> name   <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>
<span class="token output"><span class="token punctuation">|</span> Barney <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> Betty  <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>
<span class="token output">2 rows in set (0.00 sec)</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">EXPLAIN</span> <span class="token keyword">SELECT</span> c<span class="token operator">-</span><span class="token operator">&gt;&gt;</span><span class="token string">"$.name"</span> <span class="token keyword">AS</span> <span class="token keyword">name</span>
     <span class="token operator">&gt;</span>    <span class="token keyword">FROM</span> jemp <span class="token keyword">WHERE</span> g <span class="token operator">&gt;</span> <span class="token number">2</span>\G
<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> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
           id<span class="token punctuation">:</span> 1
  select_type<span class="token punctuation">:</span> SIMPLE
        table<span class="token punctuation">:</span> jemp
   partitions<span class="token punctuation">:</span> NULL
         type<span class="token punctuation">:</span> range
possible_keys<span class="token punctuation">:</span> i
          key<span class="token punctuation">:</span> i
      key_len<span class="token punctuation">:</span> 5
          ref<span class="token punctuation">:</span> NULL
         rows<span class="token punctuation">:</span> 2
     filtered<span class="token punctuation">:</span> 100.00
        Extra<span class="token punctuation">:</span> Using where
</span><span class="token output">1 row in set, 1 warning (0.00 sec)</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">WARNINGS</span>\G
<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> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
  Level<span class="token punctuation">:</span> Note
   Code<span class="token punctuation">:</span> 1003
Message<span class="token punctuation">:</span> /<span class="token punctuation">*</span> select#1 <span class="token punctuation">*</span>/ select json_unquote(json_extract(`test`.`jemp`.`c`,'$.name'))
AS `name` from `test`.`jemp` where (`test`.`jemp`.`g` &gt; 2)
</span><span class="token output">1 row in set (0.00 sec)</span></code></pre>
   </div>
   <p>
    (We have wrapped the output from the last statement in this
          example to fit the viewing area.)
   </p>
   <p>
    When you use
    <a class="link" href="explain.html" title="15.8.2 EXPLAIN Statement">
     <code class="literal">
      EXPLAIN
     </code>
    </a>
    on a
    <a class="link" href="select.html" title="15.2.13 SELECT Statement">
     <code class="literal">
      SELECT
     </code>
    </a>
    or other SQL statement
          containing one or more expressions that use the
    <code class="literal">
     -&gt;
    </code>
    or
    <code class="literal">
     -&gt;&gt;
    </code>
    operator, these expressions are translated into their
          equivalents using
    <code class="literal">
     JSON_EXTRACT()
    </code>
    and (if
          needed)
    <code class="literal">
     JSON_UNQUOTE()
    </code>
    instead, as shown
          here in the output from
    <a class="link" href="show-warnings.html" title="15.7.7.42 SHOW WARNINGS Statement">
     <code class="literal">
      SHOW
          WARNINGS
     </code>
    </a>
    immediately following this
    <code class="literal">
     EXPLAIN
    </code>
    statement:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa5265950"><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">EXPLAIN</span> <span class="token keyword">SELECT</span> c<span class="token operator">-</span><span class="token operator">&gt;&gt;</span><span class="token string">"$.name"</span>
     <span class="token operator">&gt;</span> <span class="token keyword">FROM</span> jemp <span class="token keyword">WHERE</span> g <span class="token operator">&gt;</span> <span class="token number">2</span> <span class="token keyword">ORDER</span> <span class="token keyword">BY</span> c<span class="token operator">-</span><span class="token operator">&gt;</span><span class="token string">"$.name"</span>\G
<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> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
           id<span class="token punctuation">:</span> 1
  select_type<span class="token punctuation">:</span> SIMPLE
        table<span class="token punctuation">:</span> jemp
   partitions<span class="token punctuation">:</span> NULL
         type<span class="token punctuation">:</span> range
possible_keys<span class="token punctuation">:</span> i
          key<span class="token punctuation">:</span> i
      key_len<span class="token punctuation">:</span> 5
          ref<span class="token punctuation">:</span> NULL
         rows<span class="token punctuation">:</span> 2
     filtered<span class="token punctuation">:</span> 100.00
        Extra<span class="token punctuation">:</span> Using where; Using filesort
</span><span class="token output">1 row in set, 1 warning (0.00 sec)</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">WARNINGS</span>\G
<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> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
  Level<span class="token punctuation">:</span> Note
   Code<span class="token punctuation">:</span> 1003
Message<span class="token punctuation">:</span> /<span class="token punctuation">*</span> select#1 <span class="token punctuation">*</span>/ select json_unquote(json_extract(`test`.`jemp`.`c`,'$.name')) AS
`c-&gt;&gt;"$.name"` from `test`.`jemp` where (`test`.`jemp`.`g` &gt; 2) order by
json_extract(`test`.`jemp`.`c`,'$.name')
</span><span class="token output">1 row in set (0.00 sec)</span></code></pre>
   </div>
   <p>
    See the descriptions of the
    <a class="link" href="json-search-functions.html#operator_json-column-path">
     <code class="literal">
      -&gt;
     </code>
    </a>
    and
    <a class="link" href="json-search-functions.html#operator_json-inline-path">
     <code class="literal">
      -&gt;&gt;
     </code>
    </a>
    operators, as well as those of the
    <a class="link" href="json-search-functions.html#function_json-extract">
     <code class="literal">
      JSON_EXTRACT()
     </code>
    </a>
    and
    <a class="link" href="json-modification-functions.html#function_json-unquote">
     <code class="literal">
      JSON_UNQUOTE()
     </code>
    </a>
    functions, for
          additional information and examples.
   </p>
   <p>
    This technique also can be used to provide indexes that
          indirectly reference columns of other types that cannot be
          indexed directly, such as
    <code class="literal">
     GEOMETRY
    </code>
    columns.
   </p>
   <p>
    It is also possible to create an index on a
    <a class="link" href="json.html" title="13.5 The JSON Data Type">
     <code class="literal">
      JSON
     </code>
    </a>
    column using the
    <a class="link" href="json-search-functions.html#function_json-value">
     <code class="literal">
      JSON_VALUE()
     </code>
    </a>
    function with an
          expression that can be used to optimize queries employing the
          expression. See the description of that function for more
          information and examples.
   </p>
   <h6>
    <a name="json-column-indirect-index-mysql-cluster">
    </a>
    JSON columns and indirect indexing in NDB Cluster
   </h6>
   <p>
    <a class="indexterm" name="idm46045184643920">
    </a>
    <a class="indexterm" name="idm46045184642432">
    </a>
    <a class="indexterm" name="idm46045184640944">
    </a>
    <a class="indexterm" name="idm46045184639456">
    </a>
    It is also possible to use indirect indexing of JSON columns
          in MySQL NDB Cluster, subject to the following conditions:
   </p>
   <div class="orderedlist">
    <ol class="orderedlist" type="1">
     <li class="listitem">
      <p>
       <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4">
        <code class="literal">
         NDB
        </code>
       </a>
       handles a
       <a class="link" href="json.html" title="13.5 The JSON Data Type">
        <code class="literal">
         JSON
        </code>
       </a>
       column value
              internally as a
       <a class="link" href="blob.html" title="13.3.4 The BLOB and TEXT Types">
        <code class="literal">
         BLOB
        </code>
       </a>
       . This
              means that any
       <code class="literal">
        NDB
       </code>
       table having one or
              more JSON columns must have a primary key, else it cannot
              be recorded in the binary log.
      </p>
     </li>
     <li class="listitem">
      <p>
       The
       <a class="link" href="mysql-cluster.html" title="Chapter 25 MySQL NDB Cluster 8.4">
        <code class="literal">
         NDB
        </code>
       </a>
       storage engine does
              not support indexing of virtual columns. Since the default
              for generated columns is
       <code class="literal">
        VIRTUAL
       </code>
       , you
              must specify explicitly the generated column to which to
              apply the indirect index as
       <code class="literal">
        STORED
       </code>
       .
      </p>
     </li>
    </ol>
   </div>
   <p>
    The
    <strong class="userinput">
     <code>
      CREATE TABLE
     </code>
    </strong>
    statement
          used to create the table
    <code class="literal">
     jempn
    </code>
    shown here
          is a version of the
    <code class="literal">
     jemp
    </code>
    table shown
          previously, with modifications making it compatible with
    <code class="literal">
     NDB
    </code>
    :
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa1195068"><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">CREATE</span> <span class="token keyword">TABLE</span> jempn <span class="token punctuation">(</span>
  a <span class="token datatype">BIGINT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span><span class="token punctuation">,</span>
  c <span class="token datatype">JSON</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
  g <span class="token datatype">INT</span> <span class="token keyword">GENERATED</span> <span class="token keyword">ALWAYS</span> <span class="token keyword">AS</span> <span class="token punctuation">(</span>c<span class="token operator">-</span><span class="token operator">&gt;</span><span class="token string">"$.id"</span><span class="token punctuation">)</span> <span class="token keyword">STORED</span><span class="token punctuation">,</span>
  <span class="token keyword">INDEX</span> i <span class="token punctuation">(</span>g<span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span><span class="token keyword">NDB</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    We can populate this table using the following
    <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
     <code class="literal">
      INSERT
     </code>
    </a>
    statement:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa83736311"><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">INSERT</span> <span class="token keyword">INTO</span> jempn <span class="token punctuation">(</span>c<span class="token punctuation">)</span> <span class="token keyword">VALUES</span>
  <span class="token punctuation">(</span><span class="token string">'{"id": "1", "name": "Fred"}'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token punctuation">(</span><span class="token string">'{"id": "2", "name": "Wilma"}'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token punctuation">(</span><span class="token string">'{"id": "3", "name": "Barney"}'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token punctuation">(</span><span class="token string">'{"id": "4", "name": "Betty"}'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    Now
    <code class="literal">
     NDB
    </code>
    can use index
    <code class="literal">
     i
    </code>
    ,
          as shown here:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa70937543"><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">EXPLAIN</span> <span class="token keyword">SELECT</span> c<span class="token operator">-</span><span class="token operator">&gt;&gt;</span><span class="token string">"$.name"</span> <span class="token keyword">AS</span> <span class="token keyword">name</span>
<span class="token prompt">    -&gt;</span>           <span class="token keyword">FROM</span> jempn <span class="token keyword">WHERE</span> g <span class="token operator">&gt;</span> <span class="token number">2</span>\G
<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> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
           id<span class="token punctuation">:</span> 1
  select_type<span class="token punctuation">:</span> SIMPLE
        table<span class="token punctuation">:</span> jempn
   partitions<span class="token punctuation">:</span> p0,p1,p2,p3
         type<span class="token punctuation">:</span> range
possible_keys<span class="token punctuation">:</span> i
          key<span class="token punctuation">:</span> i
      key_len<span class="token punctuation">:</span> 5
          ref<span class="token punctuation">:</span> NULL
         rows<span class="token punctuation">:</span> 3
     filtered<span class="token punctuation">:</span> 100.00
        Extra<span class="token punctuation">:</span> Using pushed condition (`test`.`jempn`.`g` &gt; 2)
</span><span class="token output">1 row in set, 1 warning (0.01 sec)</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">WARNINGS</span>\G
<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> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
  Level<span class="token punctuation">:</span> Note
   Code<span class="token punctuation">:</span> 1003
Message<span class="token punctuation">:</span> /<span class="token punctuation">*</span> select#1 <span class="token punctuation">*</span>/ select
json_unquote(json_extract(`test`.`jempn`.`c`,'$.name')) AS `name` from
`test`.`jempn` where (`test`.`jempn`.`g` &gt; 2)   
</span><span class="token output">1 row in set (0.00 sec)</span></code></pre>
   </div>
   <p>
    You should keep in mind that a stored generated column, as
          well as any index on such a column, uses
    <a class="link" href="mysql-cluster-ndbd-definition.html#ndbparam-ndbd-datamemory">
     <code class="literal">
      DataMemory
     </code>
    </a>
    .
   </p>
  </div>
 </div>
 <br/>
</div>
