作者:马文斌
MySQL爱好者,任职于蓝月亮(中国)有限公司。
本文起源:原创投稿
*爱可生开源社区出品,原创内容未经受权不得随便应用,转载请分割小编并注明起源。
一、性能加强1.1-所有零碎表更换为InnoDB引擎零碎表全副换成事务型的innodb表,默认的MySQL实例将不蕴含任何MyISAM表,除非手动创立MyISAM表。
1.2-DDL原子化InnoDB表的DDL反对事务完整性,要么胜利要么回滚,将DDL操作回滚日志写入到data dictionary 数据字典表 mysql.innodb_ddl_log 中用于回滚操作,该表是暗藏的表,通过show tables无奈看到。通过设置参数,可将ddl操作日志打印输出到mysql谬误日志中。
mysql> set global log_error_verbosity=3;mysql> set global innodb_print_ddl_logs=1;1.3-DDL秒加列只有在 MySQL 8.0.12 以上的版本才反对
mysql> show create table sbtest1; CREATE TABLE `sbtest1` ( `id` int NOT NULL AUTO_INCREMENT, `k` int NOT NULL DEFAULT '0', `c` char(120) NOT NULL DEFAULT '', `pad` char(60) NOT NULL DEFAULT '', `d` int NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `k_1` (`k`)) ENGINE=InnoDB AUTO_INCREMENT=1000001 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci 1 row in set (0.00 sec)mysql> alter table sbtest1 drop column d ;Query OK, 0 rows affected (0.05 sec)Records: 0 Duplicates: 0 Warnings: 0mysql> mysql> insert into sbtest1(k,c,pad) select k,c,pad from sbtest1;Query OK, 1000000 rows affected (19.61 sec)Records: 1000000 Duplicates: 0 Warnings: 0mysql> insert into sbtest1(k,c,pad) select k,c,pad from sbtest1;Query OK, 2000000 rows affected (38.25 sec)Records: 2000000 Duplicates: 0 Warnings: 0mysql> insert into sbtest1(k,c,pad) select k,c,pad from sbtest1;Query OK, 4000000 rows affected (1 min 14.51 sec)Records: 4000000 Duplicates: 0 Warnings: 0mysql> select count(*) from sbtest1;+----------+| count(*) |+----------+| 8000000 |+----------+1 row in set (0.31 sec)mysql> alter table sbtest1 add column d int not null default 0;Query OK, 0 rows affected (1.22 sec)Records: 0 Duplicates: 0 Warnings: 0mysql> alter table sbtest1 add column e int not null default 0;Query OK, 0 rows affected (0.03 sec)Records: 0 Duplicates: 0 Warnings: 01.4-专用表表达式(CTE:Common Table Expression)CTE(Common Table Expression)能够认为是派生表(derived table)的代替,在肯定水平上,CTE简化了简单的join查问和子查问,另外CTE能够很不便地实现递归查问,进步了SQL的可读性和执行性能。CTE是ANSI SQL 99规范的一部分,在MySQL 8.0.1版本被引入。
...