MySQL 5.7 Virtual column (Vsan columns)

Source: Internet
Author: User

Resources:

Generated Columns in MySQL 5.7.5

MySQL 5.7 new feature generated Column (function index)

MySQL 5.7 Native JSON format support

Generated Column

In MySQL 5.7, two Generated column, virtual Generated column and stored Generated column, are supported, the former only Generated column is stored in the data dictionary (the table's metadata) and does not persist this column of data to disk, which persists the generated column to disk instead of being computed each time it is read. Obviously, the latter stores data that can be computed from existing data, requires more disk space, and has no advantage over virtual column, so MySQL 5.7 does not specify the type of generated Column, which by default is virtual column.

If you need stored Generated golumn, it might be more appropriate to build an index on the virtual Generated column.

In general, the virtual Generated Column is used, which is the default way of MySQL

Grammar:

<type> [GENERATED always] as (<expression>) [virtual| STORED]
[UNIQUE [KEY]] [[PRIMARY] KEY] [Not NULL] [COMMENT <text>]

Application:

To implement an index query for some of the data in the JSON data, you can use the Virtual column feature in MySQL5.7

Create a table

Create Table User int auto_increment,data JSON,primarykey(UID));

Building data

Insert  into User Values (NULL,'{' "name": "Wang", "Address": "Shenyang"}'); Insert  into User Values (NULL,'{' "name": "Zhao", "Address": "Riben"}');

Build a virtual column of names

Alter Table User Add user_name varchar ( $.name');

Build Index

Alter Table User Add index idx_name (user_name);

Inquire

Select *  from User where user_name = ' "Wang" ';

Query analysis (explain ... \g)

You can see that the index is used.

MySQL 5.7 Virtual column (Vsan columns)

Related Article

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.