mysql操作json优点和缺点_MYSQL中的本地JSON支持5.7:MYSQL中JSON数据类型的优缺点是什么?...

In MySQL 5.7 a new data type for storing JSON data in MySQL tables has been

added. It will obviously be a 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 flavored 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 of a complex schema structure and foreign keys in MySQL. I store complex relations using only a few tables. Is it good? Does it break normalization. If this is possible then I guess it will act like NoSQL in a MySQL column. I really want to know more about this feature. Pros and cons of MySQL JSON data type.

解决方案

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:

Mysql with JSON datatypes

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值