Michael
Michael

Reputation: 1813

MariaDB - is it possible to index JSON arrays?

When working with JSON in MariaDB it is possible to index single-point values using virtual columns e.g.

ALTER TABLE features ADD feature_street VARCHAR(30) AS (JSON_UNQUOTE(feature->"$.properties.STREET"));
ALTER TABLE features ADD INDEX (feature_street);

Does anybody know whether it is possible to index JSON arrays in the same way so that when querying based on the values of the array members, each array does not have to be scanned?

I can't find anything in the docs which suggests this is possible.

Upvotes: 7

Views: 8395

Answers (1)

Rick James
Rick James

Reputation: 142228

Create a "virtual" column of the element of the JSON column and index it.

https://mariadb.com/kb/en/mariadb/virtual-computed-columns/

The elements of an array inside a JSON string -- That is another matter.

Upvotes: 3

Related Questions