title: MySQL: index json arrays of variable length?
body: <p>I want to make a <code>tags</code> column of type <code>json</code>:</p>
  <p>e.g.,</p>
  <pre><code>id  |  tags
  =========================================
  1   |  '[&quot;tag1&quot;, &quot;tag2&quot;, &quot;tag3&quot;]'
  2   |  '[&quot;tag1&quot;, &quot;tag3&quot;, &quot;tag5&quot;, &quot;tag7&quot;]'
  3   |  '[&quot;tag2&quot;, &quot;tag5&quot;]'
  </code></pre>
  <p>I want to index each <code>tag</code> in the arrays, without knowing the length of the arrays (variable length).</p>
  <p>So then if I query for rows that contain <code>tag2</code>, it should return rows 1, 3.</p>
  <blockquote>
  <p><a href="https://dev.mysql.com/doc/refman/5.7/en/json.html" rel="noreferrer">https://dev.mysql.com/doc/refman/5.7/en/json.html</a></p>
  <p>JSON columns cannot be indexed. You can work around this restriction
  by creating an index on a generated column that extracts a scalar
  value from the JSON column</p>
  </blockquote>
  <p>By &quot;extracts a scalar value&quot;, does this mean I must extract &amp; index each item in the arrays individually (meaning I must know the maximum length of the array to index them all)? How do I index a variable length array?</p>