SQL执行流程
8.0后删除了查询缓存,5.7 也是默认关闭。
两个查询请求在任何字符上的不同(例如:空格、注释、 大小写),都会导致缓存不会命中。因此 MySQL 的 查询缓存命中率不高 。
优化器:选择成本最小的执行计划去执行。逻辑查询优化,物理查询优化。
这种设置方式是session级别的,关闭此次连接后就失效了。
mysql> show profiles;
+----------+------------+-------------------------+
| Query_ID | Duration | Query |
+----------+------------+-------------------------+
| 1 | 0.10196850 | show databases |
| 2 | 0.00020675 | select atguigudb |
| 3 | 0.01624650 | SELECT DATABASE() |
| 4 | 0.00069400 | show databases |
| 5 | 0.02270850 | show tables |
| 6 | 0.00281600 | show tables |
| 7 | 0.03908150 | select * from dmployees |
| 8 | 0.05737375 | select * from employees |
+----------+------------+-------------------------+
8 rows in set, 1 warning (0.05 sec)
mysql> show profile for query 7;
+--------------------------------+----------+
| Status | Duration |
+--------------------------------+----------+
| starting | 0.000050 |
| Executing hook on transaction | 0.000005 |
| starting | 0.000007 |
| checking permissions | 0.000005 |
| Opening tables | 0.038910 |
| end | 0.000016 |
| query end | 0.000006 |
| closing tables | 0.000004 |
| freeing items | 0.000035 |
| cleaning up | 0.000046 |
+--------------------------------+----------+
10 rows in set, 1 warning (0.00 sec)
mysql> show profile cpu,block io for query 6;