select 里面带的值居然是估算的?

本文通过对比在MySQL中使用不同计数方式的性能差异,展示了如何利用MySQL的性能剖析功能来深入理解查询执行过程中的各个阶段耗时,从而帮助优化数据库查询效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


mysql> set profiling=1;
Query OK, 0 rows affected, 1 warning (0.07 sec)

mysql> select count(1) from wl;
+----------+
| count(1) |
+----------+
| 2 |
+----------+
1 row in set (0.06 sec)

mysql> select count(*) from wl;
+----------+
| count(*) |
+----------+
| 2 |
+----------+
1 row in set (0.00 sec)

mysql> show profiles;
+----------+------------+-------------------------+
| Query_ID | Duration | Query |
+----------+------------+-------------------------+
| 1 | 0.05240750 | select count(1) from wl |
| 2 | 0.00019200 | select count(*) from wl |
+----------+------------+-------------------------+
2 rows in set, 1 warning (0.03 sec)

mysql> show profile for query 1;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000113 |
| checking permissions | 0.000010 |
| Opening tables | 0.000021 |
| init | 0.000037 |
| System lock | 0.000014 |
| optimizing | 0.000009 |
| statistics | 0.000017 |
| preparing | 0.000020 |
| executing | 0.000004 |
| Sending data | 0.051994 |
| end | 0.000010 |
| query end | 0.000012 |
| closing tables | 0.000011 |
| freeing items | 0.000123 |
| cleaning up | 0.000015 |
+----------------------+----------+
15 rows in set, 1 warning (0.02 sec)

mysql> show profile for query 2;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000040 |
| checking permissions | 0.000006 |
| Opening tables | 0.000019 |
| init | 0.000014 |
| System lock | 0.000007 |
| optimizing | 0.000005 |
| statistics | 0.000014 |
| preparing | 0.000015 |
| executing | 0.000003 |
| Sending data | 0.000034 |
| end | 0.000004 |
| query end | 0.000006 |
| closing tables | 0.000008 |
| freeing items | 0.000009 |
| cleaning up | 0.000011 |
+----------------------+----------+
15 rows in set, 1 warning (0.00 sec)

转载于:https://www.cnblogs.com/lehao/p/4026193.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值