将not in转换为antijoin执行,其实最后使用subquery的firstMath或者Materialization策略
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 多次执行
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个元素
https://dev.mysql.com/doc/refman/8.0/en/explain.html#explain-analyze
authentication_policy指定认证策略,应该是为了解决外部认证,比如window域账号或者ldap等
create user 'test'@'%' identified with caching_sha2_password by 'Root@123'
caching_sha2_password认证插件与mysql7客户端不兼容。
默认认证方式从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 #关闭安全链接
参考Batched Key Access 与Hash Join
主体思想:将非聚合列推入内层的where,将聚合值推入内层成为having语句
示例:
启用派生表条件推入的执行计划如下:
1 2 3 4 |
mysql> explain select /*+ DERIVED_CONDITION_PUSHDOWN() */ * from (select dept_no, count(emp_no) as cc from dept_emp group by dept_no) as t where dept_no in ('d008','d003') and cc > 20000; |
+----+------------+---------+-------+--------+---------+-----+-------+---------+--------------------------+
| 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 |
+----+------------+---------+-------+--------+---------+-----+-------+---------+--------------------------+
1 2 3 4 5 6 7 8 9 10 11 |
mysql> show warnings; /* select#1 */ select /*+ DERIVED_CONDITION_PUSHDOWN(@`select#1`) */ `t`.`dept_no` AS `dept_no`,`t`.`cc` AS `cc` from (/* select#2 */ select `employees`.`dept_emp`.`dept_no` AS `dept_no`, count(`employees`.`dept_emp`.`emp_no`) AS `cc` from `employees`.`dept_emp` where (`employees`.`dept_emp`.`dept_no` in ('d008','d003')) group by `employees`.`dept_emp`.`dept_no` having (count(`employees`.`dept_emp`.`emp_no`) > 20000) ) `t` |
未启用派生表条件推入的执行计划如下:
1 2 3 |
mysql> explain select /*+ NO_DERIVED_CONDITION_PUSHDOWN() */ * from (select dept_no, count(emp_no) as cc from dept_emp group by dept_no) as t where dept_no in ('d008','d003') and cc > 20000; |
+----+------------+---------+-------+---------+--------+------+-------+---------+------------+
| 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|
+----+------------+---------+-------+---------+--------+------+-------+---------+------------+
降序索引为order by f1 desc, f2, asc;提供避免文件排序可能
参考Descending Indexes【降序索引】
支持alter table t1 add index idx_name((CAST(f4->>'$.name' AS CHAR(32)) COLLATE utf8mb4_bin));
这种格式的索引。
参考:Functional Key Parts
ALTER TABLE t1 ALTER INDEX i_idx INVISIBLE;
参考invisible-indexes.html
what-happens-in-a-tls-handshake
mysql encrypted-connections.html
Comments are closed.