imran imran - 4 days ago 7
JSON Question

Native JSON support in mysql 5.7 !!! what is the pros and cons of json data type in mysql?

In MySQL 5.7 a new data type for storing JSON data in MySQL tables has been
added. It will obviously great change in mysql. They listed some benefits


Document Validation - Only valid JSON documents can be stored in a
JSON column, so you get automatic validation of your data.

Efficient Access - More importantly, when you store a JSON document in a JSON column, it is not stored as a plain text value. Instead, it is stored
in an optimized binary format that allows for quicker access to object
members and array elements.

Performance - Improve your query
performance by creating indexes on values within the JSON columns.
This can be achieved with “functional indexes” on virtual columns.

Convenience - The additional inline syntax for JSON columns makes it
very natural to integrate Document queries within your SQL. For
example (features.feature is a JSON column):
SELECT feature->"$.properties.STREET" AS property_street FROM features WHERE id = 121254;



WOW ! they include some great features. Now it is easier to manipulate data . Now it is possible to store more complex data in column.
So Mysql is now flavor with NoSql.

Now I can imagine a query for json data something like

SELECT * FROM t1
WHERE JSON_EXTRACT(data,"$.series") IN
(
SELECT JSON_EXTRACT(data,"$.inverted")
FROM t1 | {"series": 3, "inverted": 8}
WHERE JSON_EXTRACT(data,"$.inverted")<4 );


So I never think a complex schema structure and foreign key in mysql . I store complex relation in some few tables . Is it good . is it break normalization. if it is possible then I guess It will act like nosql in a mysql column. I really want to know this future . Pros and cons of mysql json data type support

Answer

The following from MySQL 5.7 brings sexy back with JSON sounds good to me:

Using the JSON Data Type in MySQL comes with two advantages over storing JSON strings in a text field:

Data validation. JSON documents will be automatically validated and invalid documents will produce an error. Improved internal storage format. The JSON data is converted to a format that allows quick read access to the data in a structured format. The server is able to lookup subobjects or nested values by key or index, allowing added flexibility and performance.

...

Specialised flavours of NoSQL stores (Document DBs, Key-value stores and Graph DBs) are probably better options for their specific use cases, but the addition of this datatype might allow you to reduce complexity of your technology stack. The price is coupling to MySQL (or compatible) databases. But that is a non-issue for many users.

Note the language about document validation as it is an important factor. I guess a battery of tests need to be performed for comparisons of the two approaches. Those two being:

  1. Mysql with JSON datatypes
  2. Mysql without

The net has but shallow slideshares as of now on the topic of mysql / json / performance from what I am seeing.

Perhaps your post can be a hub for it. Or perhaps performance is an after thought, not sure, and you are just excited to not create a bunch of tables.

Comments