One of the many great new features included in MySQL 5.7 is the generated column. A generated column is a column in a table where the data is calculated for you, based on an expression that you provide.
To understand the benefits of using generated columns, let's consider a very simple example. Imagine that I want to find out how many new hires my organization had in the year 2000. Here's my table:
mysql> DESC employees; +------------+---------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+---------------+------+-----+---------+-------+ | emp_no | int(11) | NO | PRI | NULL | | | birth_date | date | NO | | NULL | | | first_name | varchar(14) | NO | | NULL | | | last_name | varchar(16) | NO | | NULL | | | gender | enum('M','F') | NO | | NULL | | | hire_date | date | NO | | NULL | | +------------+---------------+------+-----+---------+-------+ 6 rows in set (#.## sec)
…[Read more]