您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

INFORMATION_SCHEMA.PROFILING

2024/6/25 13:11:04发布41次查看
information_schema profiling tableprofiling表提供了语句分析信息。 其内容对应于show profiles和show profile语句生成的信息.
information_schema nameshow namenotes
query_id query_id 标识
seq
具有相同query_id值的行的显示顺序的序列号
state status 行测量适用的分析状态
duration duration 在给定状态下,多长时间的语句执行保持在几秒钟内
cpu_user cpu_user 用户cpu使用,以秒为单位
cpu_system cpu_system 系统cpu使用,以秒为单位
context_voluntary context_voluntary 自愿上下文切换发生
context_involuntary context_involuntary 非自愿上下文切换发生
block_ops_in block_ops_in 输入块操作的数量
block_ops_out block_ops_out 输出块操作的数量
messages_sent messages_sent 发送的通信消息的数量
messages_received messages_received 接收的通信消息的数量
page_faults_major page_faults_major 主页面错误的数量
page_faults_minor page_faults_minor 次页面错误的数量
swaps swaps 发生了多少次交换
source_function source_function 源代码执行分析状态的位置的信息
source_file source_file 源代码执行分析状态的位置的信息
source_line source_line 源代码执行分析状态的位置的信息
13.7.5.31 show profiles syntaxshow profiles
show profiles语句与show profile一起显示分析信息,指示在当前会话过程中执行的语句的资源使用情况。
13.7.5.30 show profile syntaxshow profile [type [, type] ... ]     [for query n]     [limit row_count [offset offset]] type:     all   | block io   | context switches   | cpu   | ipc   | memory   | page faults   | source   | swaps
可以指定可选类型值以显示特定的其他类型的信息(对应profiling中字段):
typenote
all 显示所有信息
block io 显示块输入和输出操作的计数
context switches 显示自愿和非自愿上下文切换的计数
cpu 显示用户和系统cpu使用时间
ipc 显示发送和接收消息的计数
memory 目前尚未实施
page faults 显示主页和次页错误的计数
source 显示来自源代码的函数的名称以及该函数发生的文件的名称和行号
swaps 显示交换计数
show profile和show profiles语句显示分析信息,指示在当前会话过程中执行的语句的资源使用情况。
profiling由profiling会话变量控制,默认值为0(off)。 通过将profiling设置为1或on可启用分析:
mysql> set profiling = 1;
show profiles显示发送到服务器的最新语句的列表。 列表的大小由profiling_history_size会话变量控制,该变量的默认值为15.最大值为100.将值设置为0具有禁用性能分析的实际效果。
除show profile和show profiles之外,所有语句都进行了概要分析,因此您将不会在配置文件列表中找到这些语句。 对于格式错误的执行语句,例如show profiling是一个非法语句,如果您尝试执行该语句,则会出现语法错误,但会显示在概要分析列表中。
show profile显示有关单个语句的详细信息,如果没有追加for query n子句,输出与最近执行的语句相关;否则展示特定语句的信息。 n的值对应于show profiles显示的query_id值。
可以给出limit row_count子句以将输出限制为row_count行。如果给定了limit,则可以添加offset偏移以将输出偏移行开始到整组行。
默认情况下,show profile显示状态和持续时间列。
每个会话启用分析。会话结束时,其分析信息丢失。
说了那么多,上面这些已经被废弃啦!!!!
note:这些语句已被逐渐弃用,将在未来的mysql版本中被删除。
也就是说新版本包括以后的版本对于性能的监控逐渐使用performance_schem代替information_schema -->详见chapter 25 mysql performance schema
action已知:
mysql root@127.0.0.1:nt> select * from student +------+--------+-------+-------+| id | name | age | sex | |------+--------+-------+-------|| 1 | s1 | 12 | m | | 2 | s2 | 12 | w | | 3 | s3 | 11 | w | +------+--------+-------+-------+3 rows in settime: 0.004s mysql root@127.0.0.1:nt> select * from teacher +------+--------+| id | name | |------+--------|| 1 | han | | 2 | gou | | 3 | eric | +------+--------+3 rows in settime: 0.002s mysql root@127.0.0.1:nt> select * from course +------+--------------+----------------+| id | teacher_id | name | |------+--------------+----------------|| 1 | 1 | advanced maths | | 2 | 2 | english | | 3 | 3 | arts | | 4 | 1 | physics | | 5 | 3 | programming | +------+--------------+----------------+5 rows in settime: 0.003s mysql root@127.0.0.1:nt> select * from score +--------------+-------------+---------+| student_id | course_id | score | |--------------+-------------+---------|| 1 | 1 | 78 | | 1 | 2 | 56 | | 1 | 3 | 89 | | 1 | 4 | 60 | | 1 | 5 | 92 | | 2 | 1 | 92 | | 2 | 2 | 60 | | 2 | 3 | 78 | | 2 | 4 | 77 | | 2 | 5 | 95 | | 3 | 1 | 66 | | 3 | 2 | 50 | | 3 | 3 | 78 | | 3 | 4 | 67 | | 3 | 5 | 86 | +--------------+-------------+---------+15 rows in settime: 0.003s
解:高数比美术分数高的学生信息
select s.* from (select sc1.student_id,sc1.course_id,sc1.score from score sc1) a, (select sc2.student_id,sc2.course_id,sc2.score from score sc2) b, student s where a.student_id=b.student_id and a.course_id=1 and b.course_id=3 and a.score>b.score and a.student_id=s.id;
mysql root@127.0.0.1:nt> select @@profiling +---------------+ | @@profiling | |---------------| | 0 | +---------------+ 1 row in set time: 0.002s mysql root@127.0.0.1:nt> set profiling = 1 query ok, 0 rows affected time: 0.001s mysql root@127.0.0.1:nt> select s.* -> from (select sc1.student_id,sc1.course_id,sc1.score from score sc1) a, -> (select sc2.student_id,sc2.course_id,sc2.score from score sc2) b, -> student s -> where a.student_id=b.student_id -> and a.course_id=1 -> and b.course_id=3 -> and a.score>b.score -> and a.student_id=s.id; +------+--------+-------+-------+ | id | name | age | sex | |------+--------+-------+-------| | 2 | s2 | 12 | w | +------+--------+-------+-------+ 1 row in set time: 0.007s mysql root@127.0.0.1:nt> show profiles +------------+------------+---------------+ | query_id | duration | query | |------------+------------+---------------| | 1 | 4.5e-05 | show warnings | | 2 | 0.000603 | select s.* from (select sc1.student_id,sc1.course_id,sc1.score from score sc1) a, (select sc2.student_id,sc2.course_id,sc2.score from score sc2) b, student s where a.student_id=b.student_id and a.course_id=1 and b.course_id=3 and a.score>b.score and a.student_id=s.id | +------------+------------+---------------+ 2 rows in set time: 0.002s mysql root@127.0.0.1:nt> show profile for query 2 +----------------------+------------+ | status | duration | |----------------------+------------| | starting | 0.000134 | | checking permissions | 1.1e-05 | | checking permissions | 4e-06 | | checking permissions | 7e-06 | | opening tables | 2.4e-05 | | init | 5.2e-05 | | system lock | 1.1e-05 | | optimizing | 1.5e-05 | | statistics | 0.000161 | | preparing | 2.7e-05 | | executing | 4e-06 | | sending data | 6.4e-05 | | end | 6e-06 | | query end | 7e-06 | | closing tables | 8e-06 | | freeing items | 5.4e-05 | | cleaning up | 1.4e-05 | +----------------------+------------+ 17 rows in set time: 0.005s
上面的结果太丑
mysql root@127.0.0.1:nt> set @query_id=2 query ok, 0 rows affected time: 0.001s
使用下面的sql:
select state, sum(duration) as total_r, round(100 * sum(duration)/(select sum(duration) from information_schema.profiling where query_id=@query_id), 2 ) as pct_r, count(*) calls, sum(duration)/count(*) as "r/call" from information_schema.profiling where query_id=@query_id group by state order by total_r desc;
mycli执行上面的sql:
+----------------------+-----------+---------+---------+------------+ | state | total_r | pct_r | calls | r/call | |----------------------+-----------+---------+---------+------------| | statistics | 0.000161 | 26.7 | 1 | 0.000161 | | starting | 0.000134 | 22.22 | 1 | 0.000134 | | sending data | 6.4e-05 | 10.61 | 1 | 6.4e-05 | | freeing items | 5.4e-05 | 8.96 | 1 | 5.4e-05 | | init | 5.2e-05 | 8.62 | 1 | 5.2e-05 | | preparing | 2.7e-05 | 4.48 | 1 | 2.7e-05 | | opening tables | 2.4e-05 | 3.98 | 1 | 2.4e-05 | | checking permissions | 2.2e-05 | 3.65 | 3 | 7.3333e-06 | | optimizing | 1.5e-05 | 2.49 | 1 | 1.5e-05 | | cleaning up | 1.4e-05 | 2.32 | 1 | 1.4e-05 | | system lock | 1.1e-05 | 1.82 | 1 | 1.1e-05 | | closing tables | 8e-06 | 1.33 | 1 | 8e-06 | | query end | 7e-06 | 1.16 | 1 | 7e-06 | | end | 6e-06 | 1 | 1 | 6e-06 | | executing | 4e-06 | 0.66 | 1 | 4e-06 | +----------------------+-----------+---------+---------+------------+ 15 rows in set time: 0.018s
可以看出来,时间消耗占比最高依次:
statistics:服务器正在计算统计信息以开发查询执行计划。如果一个线程长时间处于这种状态,服务器可能是磁盘绑定的,执行其他工作
starting
sending data:线程正在读取和处理select语句的行,并向客户端发送数据。由于在此状态期间发生的操作往往执行大量的磁盘访问(读取),所以在给定查询的整个生命周期内通常是最长的运行状态
freeing items:线程已经执行了一个命令。在这种状态下完成的项目的一些释放涉及查询缓存。这种状态通常是清理
init:这发生在alter table,delete,insert,select或update语句的初始化之前。处于此状态的服务器采取的操作包括刷新二进制日志,innodb日志和一些查询缓存清理操作。
对于最终状态,可能会发生以下操作:
在表中的数据更改后删除查询缓存条目
将事件写入二进制日志
释放内存缓冲区,包括blob
下面看看记录2对应的cpu信息
mysql root@127.0.0.1:nt> show profile cpu for query 2 +----------------------+------------+------------+--------------+ | status | duration | cpu_user | cpu_system | |----------------------+------------+------------+--------------| | starting | 0.000134 | 0.000126 | 8e-06 | | checking permissions | 1.1e-05 | 4e-06 | 6e-06 | | checking permissions | 4e-06 | 2e-06 | 3e-06 | | checking permissions | 7e-06 | 4e-06 | 2e-06 | | opening tables | 2.4e-05 | 2.3e-05 | 2e-06 | | init | 5.2e-05 | 4.8e-05 | 3e-06 | | system lock | 1.1e-05 | 8e-06 | 2e-06 | | optimizing | 1.5e-05 | 1.4e-05 | 2e-06 | | statistics | 0.000161 | 0.000113 | 5.3e-05 | | preparing | 2.7e-05 | 1.9e-05 | 3e-06 | | executing | 4e-06 | 2e-06 | 3e-06 | | sending data | 6.4e-05 | 6.3e-05 | 1e-06 | | end | 6e-06 | 3e-06 | 3e-06 | | query end | 7e-06 | 5e-06 | 1e-06 | | closing tables | 8e-06 | 7e-06 | 1e-06 | | freeing items | 5.4e-05 | 1.3e-05 | 4.2e-05 | | cleaning up | 1.4e-05 | 1.2e-05 | 2e-06 | +----------------------+------------+------------+--------------+ 17 rows in set time: 0.009s
qs:为什么show profiles结果中的duration和直接执行的时间差距那么大?以上就是information_schema.profiling的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product