博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
确定查询各阶段消耗的时间
阅读量:7107 次
发布时间:2019-06-28

本文共 916 字,大约阅读时间需要 3 分钟。

根据各阶段消耗的时间,确定如何进行优化。

1.使用profile

set profiling=1;

启动profile,这是一个session的配置。

执行需要优化的查询。

使用命令:

show profiles

查看每一个查询所消耗的总时间信息。

show profile for query N;

查询的每个阶段所消耗的时间 ,N 为查询出来的queryID。

 

 

这里可以看到查询每个阶段消耗的时间。

 

show profile cpu for query 1;

 

 

2.使用performmance_schema 衡量。

从5.5开始使用。

启动监控,需执行一下两条语句:

update setup_instruments set enabled='YES',TIMED='YES' WHERE NAME LIKE 'stage%';

update setup_consumers set enabled='YES' WHERE NAME like 'events%';

这个对全局数据库有效。

 

执行语句查看:

 

select a.thread_id ,sql_text,c.event_name,(c.timer_end -c.timer_start) / 1000000000 as 'duration (ms)'

from events_statements_history_long a join threads b on a.thread_id =b.thread_id
join events_stages_history_long c on c.thread_id=b.thread_id
and c.event_id between a.event_id and a.end_event_id
where b.processlist_id=connection_id() and a.event_name='statement/sql/select'
order by a.thread_id,c.event_id;

 

转载于:https://www.cnblogs.com/yg_zhang/p/5935966.html

你可能感兴趣的文章
2019开发者调查:Python 或成赢家,Java 最不赚钱?
查看>>
Android Q 将增强未知来源应用安装的安全性
查看>>
GhostBSD 19.04 发布,注重安全与稳定性的 FreeBSD 发行版
查看>>
5分钟记住列表的使用功能-Python基础前传(7)
查看>>
FreeBuf爬虫
查看>>
python实现冒泡排序算法
查看>>
Unity光照概述
查看>>
扩展jwt解决oauth2 性能瓶颈
查看>>
如何选择合适的基于ARM的MCU
查看>>
Android Gradle进阶配置指南
查看>>
Java 8 - lambda
查看>>
Installing a Dependency Library for Function Compute
查看>>
Java B2B2C多用户商城 springcloud架构 - 企业云架构common-service代码结构分析(六)...
查看>>
SpringBoot b2b2c 多用户商城系统(十五)Springboot整合RabbitMQ
查看>>
【重磅】Spring Boot 2.1.0 权威发布
查看>>
深创投旗下首只天使基金成立 总规模5亿元
查看>>
golang快速扫描
查看>>
「镁客早报」夏普分拆半导体业务;教育部要求高校组织开展基因编辑相关研究项目自查工作...
查看>>
python学习手册15 文档
查看>>
js笔记
查看>>