Must see! Analysis of MySQL8.0 Features (Continuous Update)

One, basic introduction to MySQL8.0

  MySQL 8.0 has the fastest adoption rate so far. The adoption rate in August 2019 has reached 26%, 5.7 to 47%, and 5.6 to 24%.

  • 2016-09-12, the first DM (development milestone) version MySQL 8.0.0, development milestone...
  • 2018-04-19 The first GA (General Availability) version, 8.0.11 released;
  • 2018-07-27 The second GA (General Availability) version, 8.0.12 released;
  • 2018-10-22 The third GA (General Availability) version, 8.0.13 released;
  • 2019-01-21 The fourth GA (General Availability) version, 8.0.14 released;
  • 2019-02-01 The fifth GA (General Availability) version, 8.0.15 released;
  • 2019-04-25 The sixth GA (General Availability) version, 8.0.16 released;
  • 2019-07-22 The seventh GA (General Availability) version, 8.0.17 released;
  • 2019-10-14 The eighth GA (General Availability) version, 8.0.18 released;
  • 2020-01-13 The ninth GA (General Availability) version, 8.0.19 released;
  • 2020-04-27 The tenth GA (General Availability) version, 8.0.20 released;
  • 2020-07-13 The eleventh GA (General Availability) version, 8.0.21 released;
    Insert picture description here

Two, MySQL8.0 key features

2.1 The default character set is changed from latin1 to utf8mb4

  Before version 8.0, the default character set was latin1, the default character set of version 8.0 was utf8mb4, and the collation rule was utf8mb4_0900_ai_ci. Utf8 used to point to utf8mb3. In the future, utf8 will also point to utf8mb4 by default.
MySQL5
Insert picture description here
MySQL8
Insert picture description here

2.2 Replace all MyISAM system tables with InnoDB tables

  All system tables are replaced with transactional innodb tables. The default MySQL instance will not contain any MyISAM tables, unless MyISAM tables are created manually.
MySQL5
Insert picture description here
MySQL8
Insert picture description here

2.3 Persistence of Incremental Variables

  In versions prior to 8.0, if the value of the auto-incrementing primary key AUTO_INCREMENT is greater than max(primary key)+1, after MySQL restarts, it will reset AUTO_INCREMENT=max(primary key)+1. This phenomenon can lead to Business primary key conflicts or other problems that are difficult to find. The 8.0 version will persist the AUTO_INCREMENT value, and the value will not change after MySQL restarts.
MySQL5
Insert picture description here
Insert picture description here

MySQL8
Insert picture description here
Insert picture description here

2.4 DDL atomization

  In 8.0, the DDL of the InnoDB table supports transaction integrity, either succeeds or rolls back. The DDL operation rollback log is written to the data dictionary data dictionary table mysql.innodb_ddl_log for rollback operations. This table is a hidden table. The show tables cannot be seen. Print out the ddl operation log to the mysql error log by setting parameters.
  Let’s look at another example. There is only one t1 table in the library, drop table t1, t2; trying to delete two tables t1, t2, before 8.0, an error was reported, but the t1 table was deleted, and an error was reported in 8.0, but the t1 table It has not been deleted, which proves the atomicity of 8.0 DDL operations, either all succeeded or rolled back.
MySQL5
Insert picture description here
MySQL8
Insert picture description here
Insert picture description here

2.5 parameter modification persistence

  MySQL 8.0 version supports online modification and persistence of global parameters. By adding the PERSIST keyword, the modified parameters can be persisted to a new configuration file (mysqld-auto.cnf), which can be obtained from the configuration file when MySQL is restarted. To the latest configuration parameters. For example, execute: SET PERSIST @@global.sync_binlog=100; The system will generate a file containing mysqld-auto.cnf in json format in the data directory. After formatting, it will look like the following, when my.cnf and mysqld-auto.cnf When both exist, the latter has higher priority.
Insert picture description here

2.6 Descending Index

  MySQL has grammatically supported descending index for a long time, but in fact it is still creating ascending index. As shown in MySQL 5.7 below, the c2 field is in descending order, but c2 is still in ascending order from the show create table. 8.0 you can see that the c2 field is in descending order.
MySQL5
Insert picture description here
Insert picture description here
MySQL8
Insert picture description here
Insert picture description here

2.7 group by no longer implicitly sort

  Before version 8.0, group by will sort by default, after 8.0, implicit sorting is no longer performed.
MySQL5
Insert picture description here
MySQL8
Insert picture description here

2.8 JSON feature enhancement

  MySQL 8 has greatly improved the support for JSON, adding the JSON_EXTRACT() function to extract data from JSON fields based on path query parameters, and the JSON_ARRAYAGG() and JSON_OBJECTAGG() aggregations for combining data into JSON arrays and objects, respectively function.
  In the master-slave replication, the new parameter binlog_row_value_options is added to control the transmission mode of JSON data, and allow the modification of the Json type part. Only the modified part is recorded in the binlog, which reduces the resource occupation of json big data when there are only a few modifications. .

2.9 Redo & undo log encryption

  Add the following two parameters to control the encryption of redo and undo logs.

  • innodb_undo_log_encrypt
  • innodb_undo_log_encrypt

2.10 innodb select for update skip lock waiting

  select… for update, select… for share (new syntax in 8.0) Add NOWAIT, SKIP LOCKED syntax, skip lock waiting, or skip lock. In versions 5.7 and before, select...for update, if the lock cannot be obtained, it will wait until innodb_lock_wait_timeout times out. In version 8.0, by adding nowait, skip locked syntax, it can return immediately. If the query row has been locked, then nowait will report an error and return immediately, and skip locked will also return immediately, but the returned result does not contain the locked row.
Insert picture description here
Insert picture description here

2.11 Add SET_VAR syntax

  Adding SET_VAR grammar to sql grammar and dynamically adjusting some parameters will help improve statement performance.

  • select /*+ SET_VAR(sort_buffer_size = 16M) */ id from test order id ;
  • insert /*+ SET_VAR(foreign_key_checks=OFF) */ into test(name) values(1);

2.12 Added innodb_dedicated_server parameter

  Allow InnoDB to automatically configure the three parameters innodb_buffer_pool_size, innodb_log_file_size, and innodb_flush_method according to the memory size detected on the server.

2.13 Automatic recovery of undo space

  The default value of the innodb_undo_log_truncate parameter in version 8.0.2 is changed from OFF to ON, and automatic recovery of undo log tablespace is enabled by default.
  The innodb_undo_tablespaces parameter defaults to 2 in version 8.0.2. When one undo tablespace is recycled, there is another one that provides normal services.
  The innodb_max_undo_log_size parameter defines the maximum value of undo tablespace recovery. When the undo tablespace exceeds this value, the tablespace is marked as recyclable.

2.14 Support invisible index

  Use the INVISIBLE keyword to set whether the index is visible during table creation or table changes. The index is not visible but the optimizer does not use the index during query. Even if force index is used, the optimizer will not use the index, and the optimizer will not report the error that the index does not exist, because the index still exists, when necessary , Can also be quickly restored to be visible.
Insert picture description here

2.15 Support histogram

  The optimizer will use the data of column_statistics to determine the distribution of field values ​​and get a more accurate execution plan.
  You can use ANALYZE TABLE table_name [UPDATE HISTOGRAM on col_name with N BUCKETS |DROP HISTOGRAM ON clo_name] to collect or delete histogram information.
  The histogram counts the data distribution of certain fields in the table, and provides a reference for optimizing the selection of an efficient execution plan. The histogram is essentially different from an index, and maintaining an index has a cost. Every insert, update, and delete will need to update the index, which will have a certain impact on performance. The histogram is created once and never updated unless it is explicitly updated. So it will not affect the performance of insert, update, and delete.
Insert picture description here

2.16 More detailed log classification

  Added the error message number [MY-010311] and the subsystem to which the error belongs [Server] in the error message
Insert picture description here

2.17 Change of authentication encryption plug-in

  MySQL8.0 started using caching_sha2_password as the default authentication plug-in. Caching_sha2_password provides more secure password encryption than mysql_native_password plug-in, and caching_sha2_password provides better performance. Due to these superior security and performance features, caching_sha2_password is the preferred authentication plugin for MySQL 8.0, and it is also the default authentication plugin instead of mysql_native_password. This change will affect the server and the libmysqlclient client library; currently it is not compatible with frequently used client software.

2.18 Add resource group and role management

  MySQL 8.0 adds a new resource group function for adjusting thread priority and binding CPU cores. MySQL users need to have RESOURCE_GROUP_ADMIN permission to create, modify, and delete resource groups. In the Linux environment, the MySQL process needs CAP_SYS_NICE permission to use the full functionality of the resource group.
Insert picture description here
  A role can be considered as a collection of some permissions, and a unified role is assigned to the user, and the modification of the permission is directly carried out through the role, without requiring separate authorization for each user.
Two resource groups are provided by default, namely USR_default and SYS_default.

Insert picture description here
Insert picture description here
Insert picture description here

2.19 Instance clone

  In many scenarios, we need to clone a MySQL instance. For example, in MGR, we need to create a new instance using a backup before adding it to the group replication. In the traditional master-slave architecture, if you need to add a slave library, you also use backup to restore, create a new instance, and then add this instance to the master-slave replication. The clone function implemented in version 8.0.17 supports local or remote. The cloned data is the data stored in the physical snapshot, which can realize the MySQL instance clone more quickly and efficiently.
  The clone plug-in developed by MySQL 8.0.17 solves this problem and simplifies the process of instance replication. Just by executing a few commands through the mysql client, a running MySQL instance can be automatically cloned to another new instance without too many steps and manual involvement.
Precautions:

  • MySQL configuration parameters will not be cloned.
  • Binlog files will not be cloned.
  • Tables that only support InnoDB storage engine, MyISAM and CSV engines are empty tables after being cloned.
  • During the cloning process, all DDL operations are blocked.
  • During the cloning operation, the instance's own data and Binlog will be lost. If necessary, please make a backup before cloning.

2.20 NoSQL document storage

  MySQL document storage provides developers with the greatest flexibility, that is, it supports traditional SQL relational applications, and it also supports NoSQL-mode free document database applications. Therefore, it is no longer necessary to configure a separate NoSQL document database. MySQL documents are stored as schemaless JSON documents, providing multi-document transaction support and full ACID compatibility.
Insert picture description here

2.21 Window function

  Similar to group aggregate functions, window functions perform some calculations on a group of rows, such as COUNT or SUM. However, if group aggregation collapses this group of rows into a single row, the window function will perform aggregation on each row in the result set. Window functions have two forms: SQL aggregate functions used as window functions and dedicated window functions. This is a set of aggregate functions that support windows in MySQL: COUNT, SUM, AVG, MIN, MAX, BIT_OR, BIT_AND, BIT_XOR, STDDEV_POP (and its synonyms STD, STDDEV), STDDEV_SAMP, VAR_POP (and its synonyms VARIANCE) and VAR_SAMP. A set of specialized window functions are: RANK, DENSE_RANK, PERCENT_RANK, CUME_DIST, NTILE, ROW_NUMBER, FIRST_VALUE, LAST_VALUE, NTH_VALUE, LEAD and LAG.
Insert picture description here

2.22 Common Table Expression (CTE)

  MySQL 8.0 provides Common Table Expressions (CTE). Before MySQL8.0, you need to use subqueries to implement complex queries. SQL statements are not only complex and low in performance, but also not clear enough. The appearance of CTE simplifies the writing of complex query statements and improves SQL performance.
  Compared with subquery or derived query, CTE can reuse the last query result, that is, query once, and at the same time, CTE can refer to each other.
Insert picture description here
Insert picture description here

2.23 Skip Range Scan

  Jump range scan is a new feature added by MySQL to improve performance in version 8.0.13. Jump range scan can make some SQL that cannot use the joint index to query with the joint index, and can use the joint index more efficiently. This is of great significance to the use of MySQL joint index for query applications.
Insert picture description here

2.24 hash join

  Before 8.0.18, MySQL only supported the Nest Loop Join algorithm. The simplest one is Simple Nest Loop Join. MySQL has made several optimizations for this algorithm, implementing Block Nest Loop Join, Index Nest Loop Join and Batched Key Access. With these Optimization can alleviate the urgency of HashJoin to a certain extent.
  Hash Join is an optimization for the equivalent join scenario. The basic idea is to load the external table data into the memory and create a hash table, so that you only need to traverse the internal table once to complete the join operation and output matching records.

2.25 Other characteristics

1. Removal of some system tables, enhancement of system tables
2. Parallel writing of redo, new slow log parameters, more detailed
3. Replication optimization, count(*) optimization
4. Distributed transaction support by default
5. Remove query cache And mysql_upgrade, add check integrity
6. The default index of the temporary table is innodb
7. The UNDO table space is enabled by default, and the number of online adjustments is supported
8. Grant no longer implicitly creates users, add auxiliary password
9. Remove PASSWORD() Function
10, dynamic permissions
11, MySQL8.0 supports configurable cost constants, optimizes the optimizer's overhead, supports more hints, and the optimizer considers whether the data is in the Buffer Pool when formulating the execution plan.
12. MySQL 8.0 has a very high improvement in the support of GIS, catching up with or even surpassing PostgreSQL in function.
13, MGR optimization
14, redo archive
15, new architecture innodb replicaSet
16, double write independent
17, explain analyze support
18, backup lock support

Guess you like

Origin blog.csdn.net/qq_42979842/article/details/108332159