mysql8新特性

12月 6, 2021 |

1、8.0.17 将exists转换成simijoin

2、8.0.17 antijoin**

将not in转换为antijoin执行,其实最后使用subquery的firstMath或者Materialization策略

3、8.0.13 index skip scan

CREATE TABLE t1 (f1 INT NOT NULL, f2 INT NOT NULL, PRIMARY KEY(f1, f2));
EXPLAIN SELECT f1, f2 FROM t1 WHERE f2 > 40;

f1列的可选择性很低, 那么会将查询转换成SELECT f1, f2 FROM t1 WHERE f1=constN and f2 > 40 多次执行

4、窗口函数

select emp_no, dept_no, rank() over(partition by dept_no order by emp_no) as cc from dept_manager;

rank() over() 需要指定排序,一个分组的所有行rank=1
row_number() 行号
rank() 有空隙,有两个2,下一个为4
dense_rank()没有空隙,即使有两个2,下一个为3
NTH_VALUE() 返回分组第N个元素

5、8.0.18 EXPLAIN ANALYZE

https://dev.mysql.com/doc/refman/8.0/en/explain.html#explain-analyze

6、8.0.27 multifactor authentication

authentication_policy指定认证策略,应该是为了解决外部认证,比如window域账号或者ldap等
create user 'test'@'%' identified with caching_sha2_password by 'Root@123'
caching_sha2_password认证插件与mysql7客户端不兼容。

7、安全

默认认证方式从caching_sha2_password改为mysql_native_password
caching_sha2_password 要求要么ssl加密链接,要么 password exchange using an RSA key pair用来保护密码,登录一次后服务器会缓存该用户的登录状态,直到超时或者服务器调用flush privileges。
mysql 自带客户端重要参数:
--get-server-public-key=on自动从服务器拉取public-key.pem,
--server-public-key-path=public_key.pem #指定服务器的public key存放位置
--ssl-mode=disable #关闭安全链接

8、 Hash Join(8.0.18)

参考Batched Key Access 与Hash Join

9、Derived Condition Pushdown(8.0.22)

主体思想:将非聚合列推入内层的where,将聚合值推入内层成为having语句
示例:
启用派生表条件推入的执行计划如下:

+----+------------+---------+-------+--------+---------+-----+-------+---------+--------------------------+
| id | select_type| table | type |key | key_len | ref | rows |filtered | Extra |
+----+------------+---------+-------+--------+---------+-----+-------+---------+--------------------------+
| 1 | PRIMARY | derived2| ALL |NULL | NULL | NULL| 73006 | 100.00 | NULL |
| 2 | DERIVED | dept_emp| range |dept_no | 16 | NULL| 73006 | 100.00 | Using where; Using index |
+----+------------+---------+-------+--------+---------+-----+-------+---------+--------------------------+

未启用派生表条件推入的执行计划如下:

+----+------------+---------+-------+---------+--------+------+-------+---------+------------+
| id | select_type| table | type | key | key_len| ref | rows |filtered | Extra |
+----+------------+---------+-------+---------+--------+------+-------+---------+------------+
| 1 | PRIMARY | derived2| ALL | NULL | NULL | NULL | 331143| 6.67 | Using where|
| 2 | DERIVED | dept_emp| index | dept_no | 16 | NULL | 331143| 100.00 | Using index|
+----+------------+---------+-------+---------+--------+------+-------+---------+------------+

10、Descending Indexes【降序索引】(8.0.1)

降序索引为order by f1 desc, f2, asc;提供避免文件排序可能
参考Descending Indexes【降序索引】

11、函数索引(functional key) 8.0.13

支持alter table t1 add index idx_name((CAST(f4->>'$.name' AS CHAR(32)) COLLATE utf8mb4_bin)); 这种格式的索引。
参考:Functional Key Parts

11、Invisible Indexes(8.0.0)

ALTER TABLE t1 ALTER INDEX i_idx INVISIBLE;
参考invisible-indexes.html

参考文档

what-happens-in-a-tls-handshake
mysql encrypted-connections.html

Posted in: database | Tags:

Comments are closed.