I am creating a DB-schema for a website on which users can write the Articles
. I was almost done with the design and suddenly I read few blogs on JSON datatype
in MySQL
.
As per blogs, there are certain use cases where JSON
can be used:
- for storing metadata. e.g a product having its height, widths, colour stored as JSON.
- for storing the non-standard schema type data
- for storing the tags as JSON. e.g this question could have tags -
mysql, JSON. So the blogs recommended using a JSON structure that
holds all the
tags
.
The last one is doubtful to me. Why?
Ok I have stored the tag value in JSON as {"tags": ["mysql", "JSON", "mysql-datatype"]}
. I agree this helps in easily maintaining the tags with the Article.
But suppose a user wants to read all the article related to mysql
tags!! If I have been maintained a separate table for article_id
- tags_id
, I could have easily get all the Articles
based on the tags
. But with JSON
this could be a very hectic requirement, though this can be solved but with a cost. Slower queries ofcourse.
This is my schema for Article:
Is my way of thinking correct or am I missing something here? Love to hear some suggestions.