MySQL5.7查询性能改进
发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,1.子查询1.1 MySQL5.5mysql> explain extended select id,k,c,pad from sbtest1 where id in (select id from
千家信息网最后更新 2025年11月07日MySQL5.7查询性能改进
1.子查询
1.1 MySQL5.5
mysql> explain extended select id,k,c,pad from sbtest1 where id in (select id from sbtest1 where k in ('50385','50011','43490','504922'));+----+--------------------+---------+-----------------+---------------+---------+---------+------+--------+----------+-------------+| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |+----+--------------------+---------+-----------------+---------------+---------+---------+------+--------+----------+-------------+| 1 | PRIMARY | sbtest1 | ALL | NULL | NULL | NULL | NULL | 612555 | 100.00 | Using where || 2 | DEPENDENT SUBQUERY | sbtest1 | unique_subquery | PRIMARY,k_1 | PRIMARY | 4 | func | 1 | 100.00 | Using where |+----+--------------------+---------+-----------------+---------------+---------+---------+------+--------+----------+-------------+2 rows in set, 1 warning (0.00 sec)1.2 MySQL5.7
mysql> explain select id,k,c,pad from sbtest1 where id in (select id from sbtest1 where k in ('50385','50011','43490','50492'));+----+-------------+---------+------------+--------+---------------+---------+---------+-------------------+------+----------+--------------------------+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |+----+-------------+---------+------------+--------+---------------+---------+---------+-------------------+------+----------+--------------------------+| 1 | SIMPLE | sbtest1 | NULL | range | PRIMARY,k_1 | k_1 | 4 | NULL | 253 | 100.00 | Using where; Using index || 1 | SIMPLE | sbtest1 | NULL | eq_ref | PRIMARY | PRIMARY | 4 | sbtest.sbtest1.id | 1 | 100.00 | NULL |+----+-------------+---------+------------+--------+---------------+---------+---------+-------------------+------+----------+--------------------------+2 rows in set, 1 warning (0.00 sec)2.union all
2.1 MySQL5.5,会将结果存在临时表中
mysql> explain (select k from sbtest1 order by k) union all (select k from sbtest2 order by k);+----+--------------+------------+-------+---------------+------+---------+------+--------+-------------+| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |+----+--------------+------------+-------+---------------+------+---------+------+--------+-------------+| 1 | PRIMARY | sbtest1 | index | NULL | k_1 | 4 | NULL | 612555 | Using index || 2 | UNION | sbtest2 | index | NULL | k_2 | 4 | NULL | 615365 | Using index || NULL | UNION RESULT | | ALL | NULL | NULL | NULL | NULL | NULL | |+----+--------------+------------+-------+---------------+------+---------+------+--------+-------------+3 rows in set (0.00 sec) 2.2 MySQL5.7,直接展示结果
mysql> explain (select k from sbtest1 order by k) union all (select k from sbtest2 order by k);+----+-------------+---------+------------+-------+---------------+------+---------+------+--------+----------+-------------+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |+----+-------------+---------+------------+-------+---------------+------+---------+------+--------+----------+-------------+| 1 | PRIMARY | sbtest1 | NULL | index | NULL | k_1 | 4 | NULL | 597600 | 100.00 | Using index || 2 | UNION | sbtest2 | NULL | index | NULL | k_2 | 4 | NULL | 597744 | 100.00 | Using index |+----+-------------+---------+------------+-------+---------------+------+---------+------+--------+----------+-------------+2 rows in set, 1 warning (0.00 sec)3 in查询
3.1 MySQL5.5
mysql> explain select * from sbtest1 where (k,pad) in ((43490,'24909597713-10795827686-60824686337-78820064088-50914299985'),(50088,'56702105543-74313438035-88959810983-96828764563-29757615888'));+----+-------------+---------+------+---------------+------+---------+------+--------+-------------+| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |+----+-------------+---------+------+---------------+------+---------+------+--------+-------------+| 1 | SIMPLE | sbtest1 | ALL | NULL | NULL | NULL | NULL | 612555 | Using where |+----+-------------+---------+------+---------------+------+---------+------+--------+-------------+1 row in set (0.00 sec)3.2 MySQL5.7
mysql> explain select * from sbtest1 where (k,pad) in ((43490,'24909597713-10795827686-60824686337-78820064088-50914299985'),(50088,'56702105543-74313438035-88959810983-96828764563-29757615888'));+----+-------------+---------+------------+-------+---------------+------+---------+------+------+----------+-------------+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |+----+-------------+---------+------------+-------+---------------+------+---------+------+------+----------+-------------+| 1 | SIMPLE | sbtest1 | NULL | range | k_1 | k_1 | 4 | NULL | 77 | 20.00 | Using where |+----+-------------+---------+------------+-------+---------------+------+---------+------+------+----------+-------------+1 row in set, 1 warning (0.00 sec)
查询
结果
性能
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
mac连接远程服务器命令
如何把手机版的服务器改为联机
数据库安全性的总结
国际的棋牌游戏应用服务器
揭阳定制软件开发
杭州千家万户软件开发
鹿鸣网络技术服务工作室
陕西dns服务器地址
pmo与软件开发相比怎么样
陕西奋斗猫网络技术有限公司
论文评语 软件开发
数据库记录日志文件
胡润中国网络安全排行
数据库技术关系体
萝卜圈网络技术有限公司
工行软件开发中心视频
3分钟看懂网络安全
怎么查看本机的服务器ip地址
无网络技术原理
传奇数据库字段详解
航天安全接入服务器地址测试
网络安全保障能力 信息化
王牌战争怎么看最新的服务器
网络安全教育筑牢思想防线
国家网络安全宣传周的新闻
网络安全两套安全体系
关闭轻松阅读服务器的应用
网络安全11不准
网络安全病毒及防火墙的应用
海贼王声优软件开发