We have had a look at how MySQL 8 handles JSON recently, but with
all those JSON functions and expressions it is clear that many
JSON accesses cannot be fast. To grab data from a JSON column,
you will use a lot of $->>field
expressions
and similar, and without indexes nothing of this will be fast.
JSON cannot be indexed.
But MySQL 8 offers another feature that comes in handy: Generated columns and indexes on those. Let’s look at the parts, step by step, and how to make them work, because they are useful even outside of the context of JSON.
An example table
For the following example we are going to define a table
t1
with an integer id and two integer data fields,
a
and b
. We will be filling it with
random integers up to 999 for the data values: