分析 Mysql 表读写、索引等操作的 sql 语句效率优化问
题
今天小编就为大家分享一篇关于分析 Mysql 表读写、索引等操作的 sql 语句效率优化问题,小编觉得内容挺不错的,
现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
上次我们说到 mysql 的一些 sql 查询方面的优化,包括查看 explain 执行计划,分析索引等等。今天
我们分享一些 分析 mysql 表读写、索引等等操作的 sql 语句。
闲话不多说,直接上代码:
反映表的读写压力
1
2
3
4
5
6
7
8
SELECT le_name AS le,
count_read,
sum_number_of_bytes_read AS total_read,
count_write,
sum_number_of_bytes_write AS total_written,
(sum_number_of_bytes_read + sum_number_of_bytes_write) AS total
FROM performance_schema.le_summary_by_instance
ORDER BY sum_number_of_bytes_read+ sum_number_of_bytes_write DESC;
反映文件的延迟
1
2
3
4
5
6
7
8
SELECT (le_name) AS le,
count_star AS total,
CONCAT(ROUND(sum_timer_wait / 3600000000000000, 2), 'h') AS total_latency,
count_read,
CONCAT(ROUND(sum_timer_read / 1000000000000, 2), 's') AS read_latency,
count_write,
CONCAT(ROUND(sum_timer_write / 3600000000000000, 2), 'h')AS write_latency
FROM performance_schema.le_summary_by_instance
ORDER BY sum_timer_wait DESC;