MySQL 5.7: How to create an Index on JSON Data Type Column

In the previous two articles, I have shared basic detail about MySQL 5.7 JSON Data Type.
Our next question is, How we can create an Index on JSON Data Type in MySQL 5.7.

As per the official document, actually we cannot directly create an Index on JSON column in MySQL.

We have to add generated column in Table by extracting require JSON Key data.
Once require JSON key data extracted, we can apply index on that column like any other column.

Actually, this is not a good way, but as of now we have only this option to create an indirect Index on JSON Column in MySQL 5.7.

Create sample table using JSON data type:

Insert few sample JSON formatted record:

Create aditional generated column for JSON Field EmployeeDetails->firstName:

Create Index on generated column which indirectly work as Index on JSON EmployeeDetails->firstName:

Check the execution plan of below query, where you can find usage of newly created Index:

Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from

Leave a Reply

Be the First to Comment!

Notify of