MySQL 5.7 New Support--------JSON index creation combat

Source: Internet
Author: User

1. Background

* in MySQL 5.7.8, MySQL supports the native JSON data type defined by RFC 7159, which supports effective access to data in JSON (JavaScript object tagging) documents.

* MySQL automatically validates DML JSON data. An invalid DML JSON data operation generates an error.

* optimized storage format. JSON documents stored in JSON columns are converted to an internal format that allows for fast read access to JSON elements.

* MySQL JSON type supports indexing with virtual columns to increase query performance.


2. Json Index

* Create a JSON index table Json_key [name is a virtual column, and virtual indicates that it does not occupy disk space]

[GENERATED always and virtual can not write]

Specify to get the name key in the JSON

Mysql> CREATE TABLE json_key (uid BIGINT PRIMARY key NOT NULL auto_increment, data JSON is not NULL, Name VARCHAR (+) GENERATED always as (json_extract (data, ' $.name ')) Engine=innodb CHARSET=UTF8MB4 ;


* Insert data with the name key [need to display specified non-virtual columns when inserting data]

Mysql> INSERT into Json_key (UID, data) SELECT NULL, Json_object (' name ', ' Tom ', ' sex ', ' male ', ' age ', ' 26 '); Query OK, 1 row affected (0.02 sec) records:1 duplicates:0 warnings:0


* Insert data without the name Key

Mysql> INSERT into Json_key (UID, data) SELECT NULL, json_object (' sex ', ' female ', ' age ', ' 29 '); Query OK, 1 row affected (0.01 sec) records:1 duplicates:0 warnings:0


* View all json_key data

mysql> select * from json_key;+-----+------------ ---------------------------------+-------+| uid | data                                          | name   |+-----+---------------------------------------------+-------+|   1 | {" Age ": ",  "Sex":  "male",  "name":  "Tom"} |  "Tom"  | |    2 | {"Age":  ", " Sex ": " female "}               | null  |+-----+------------------------- --------------------+-------+2 rows in set  (0.01 sec) 


4. Summary


To demand-driven technology, the technology itself does not have a better point, only the division of business.

This article is from the "Sea" blog, be sure to keep this source http://lisea.blog.51cto.com/5491873/1943389

MySQL 5.7 New Support--------JSON index creation combat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.