JSON columns!
🤔 "But I can already index data from a JSON column."
Previously you could only index a single value from a JSON column.
These indexes can be used for queries that use the following JSON functions:
Â
(We'll discuss the latter two)
ALTER TABLE posts
ADD INDEX tags( (CAST(metadata->'$.tags' AS char(60) ARRAY)) )
Combine `CAST` with the same JSON path you will use in your queries:
ALTER TABLE posts
ADD INDEX tags_composite(
category,
owner_id,
(CAST(metadata->'$.tags' AS char(60) ARRAY))
)
Be sure to read the documentation thoroughly, because there are caveats/restrictions:
Â
https://dev.mysql.com/doc/refman/8.0/en/create-index.html#create-index-multi-valued
Among others:
Â