国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

分析Mysql表讀寫、索引等操作的sql語句效率優化問題

2024-07-24 12:49:32
字體:
來源:轉載
供稿:網友

上次我們說到mysql的一些sql查詢方面的優化,包括查看explain執行計劃,分析索引等等。今天我們分享一些 分析mysql表讀寫、索引等等操作的sql語句。

閑話不多說,直接上代碼:

反映表的讀寫壓力

SELECT file_name AS file, 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.file_summary_by_instanceORDER BY sum_number_of_bytes_read+ sum_number_of_bytes_write DESC;

反映文件的延遲

SELECT (file_name) AS file, 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.file_summary_by_instanceORDER BY sum_timer_wait DESC;

table 的讀寫延遲

SELECT object_schema AS table_schema, object_name AS table_name, count_star AS total, CONCAT(ROUND(sum_timer_wait / 3600000000000000, 2), 'h') as total_latency, CONCAT(ROUND((sum_timer_wait / count_star) / 1000000, 2), 'us') AS avg_latency, CONCAT(ROUND(max_timer_wait / 1000000000, 2), 'ms') AS max_latency FROM performance_schema.objects_summary_global_by_type ORDER BY sum_timer_wait DESC;

查看表操作頻度

SELECT object_schema AS table_schema, object_name AS table_name, count_star AS rows_io_total, count_read AS rows_read, count_write AS rows_write, count_fetch AS rows_fetchs, count_insert AS rows_inserts, count_update AS rows_updates, count_delete AS rows_deletes, CONCAT(ROUND(sum_timer_fetch / 3600000000000000, 2), 'h') AS fetch_latency, CONCAT(ROUND(sum_timer_insert / 3600000000000000, 2), 'h') AS insert_latency, CONCAT(ROUND(sum_timer_update / 3600000000000000, 2), 'h') AS update_latency, CONCAT(ROUND(sum_timer_delete / 3600000000000000, 2), 'h') AS delete_latency FROM performance_schema.table_io_waits_summary_by_table ORDER BY sum_timer_wait DESC ;

索引狀況

SELECT OBJECT_SCHEMA AS table_schema, OBJECT_NAME AS table_name, INDEX_NAME as index_name, COUNT_FETCH AS rows_fetched, CONCAT(ROUND(SUM_TIMER_FETCH / 3600000000000000, 2), 'h') AS select_latency, COUNT_INSERT AS rows_inserted, CONCAT(ROUND(SUM_TIMER_INSERT / 3600000000000000, 2), 'h') AS insert_latency, COUNT_UPDATE AS rows_updated, CONCAT(ROUND(SUM_TIMER_UPDATE / 3600000000000000, 2), 'h') AS update_latency, COUNT_DELETE AS rows_deleted, CONCAT(ROUND(SUM_TIMER_DELETE / 3600000000000000, 2), 'h')AS delete_latencyFROM performance_schema.table_io_waits_summary_by_index_usageWHERE index_name IS NOT NULLORDER BY sum_timer_wait DESC;
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 颍上县| 桂林市| 景德镇市| 大石桥市| 石渠县| 郓城县| 牟定县| 绥滨县| 三亚市| 曲靖市| 县级市| 高台县| 濉溪县| 潍坊市| 平乡县| 扎鲁特旗| 元谋县| 铜鼓县| 黑河市| 酉阳| 大埔县| 镇江市| 衡水市| 冕宁县| 呈贡县| 乌兰浩特市| 普洱| 介休市| 阿克陶县| 彩票| 乌什县| 调兵山市| 武山县| 凤台县| 河间市| 班玛县| 德保县| 北海市| 旬邑县| 靖宇县| 夏津县|