创建一个报告的语句在服务器上运行。视图计算基于整体和/或三角洲活动。
这个过程禁用二进制日志记录在其执行过程中通过操纵会议的价值sql_log_bin
系统变量。这是一个受限制的操作,所以过程需要足够的特权设置限制会话变量。看到部分5.1.9.1,“系统变量特权”。
in_action ENUM(“快照”,“整体”,“三角洲”,“create_tmp”,“create_table”,“保存”,“清理”)
:操作。这些值是允许的:快照
:存储快照。默认是当前的快照的内容表现模式events_statements_summary_by_digest
表。通过设置in_table
,这可以覆盖复制指定表的内容。快照存储在sys
模式tmp_digests
临时表。整体
:生成一个分析基于指定的表的内容in_table
。总体分析,in_table
可以现在()
使用新鲜的快照。这覆盖现有的快照。使用零
为in_table
使用现有的快照。如果in_table
是零
和快照不存在,创建一个新的快照。的in_views
参数和statement_performance_analyzer.limit
配置选项影响这个过程的操作。δ
:生成一个增量分析。指定的三角洲之间的计算参考表in_table
快照,必须存在。该操作使用sys
模式tmp_digests_delta
临时表。的in_views
参数和statement_performance_analyzer.limit
配置选项影响这个过程的操作。create_table
:创建一个常规表适合存储快照供以后使用(例如,计算增量)。create_tmp
:创建一个临时表适合存储快照供以后使用(例如,计算增量)。保存
:在指定的表保存快照in_table
。表必须存在,并且有正确的结构。如果快照不存在,创建一个新的快照。清理
:删除临时表用于快照和三角洲。
in_table VARCHAR (129)
:表参数用于指定的动作in_action
参数。使用格式db_name.tbl_name
或tbl_name
不使用任何撇号(”
)identifier-quoting字符。时间(。
)不支持数据库和表名。的意义
in_table
值为每个in_action
详细的个人价值in_action
价值描述。in_views集(“with_runtimes_in_95th_percentile”、“分析”,‘with_errors_or_warnings’,‘with_full_table_scans’,‘with_sorting’,‘with_temp_tables’,“自定义”)
包括:哪个视图。这个参数是一个集
值,因此它可以包含多个视图名称,之间用逗号分隔。除了默认的是包括所有视图自定义
。允许以下值:with_runtimes_in_95th_percentile
:使用statements_with_runtimes_in_95th_percentile
视图。分析
:使用statement_analysis
视图。with_errors_or_warnings
:使用statements_with_errors_or_warnings
视图。with_full_table_scans
:使用statements_with_full_table_scans
视图。with_sorting
:使用statements_with_sorting
视图。with_temp_tables
:使用statements_with_temp_tables
视图。自定义
:使用一个定制的视图。这个观点必须指定使用statement_performance_analyzer.view
配置选项名称查询或现有视图。
statement_performance_analyzer ()
操作使用以下配置选项可以修改或相应的用户定义的变量(见部分28.4.2.1,“sys_config表”):
调试
,@sys.debug
如果这个选项是
在
、生产调试输出。默认值是从
。statement_performance_analyzer.limit
,@sys.statement_performance_analyzer.limit
的最大行数来换取他的意见没有内置的限制。默认值是100。
statement_performance_analyzer.view
,@sys.statement_performance_analyzer.view
要使用自定义查询或视图。如果选项值包含一个空间,它被解释为一个查询。否则,它必须是现有视图的名称查询性能模式
events_statements_summary_by_digest
表。不能有任何限制
查询或视图定义如果条款statement_performance_analyzer.limit
配置选项大于0。如果指定一个视图,至于使用相同的格式in_table
参数。默认值是零
(没有定义自定义视图)。
与查询创建一个报告的最后截断以来的第95个百分位events_statements_summary_by_digest
和一段一分钟三角洲:
创建一个临时表来存储初始快照。
创建初始快照。
最初的快照保存在临时表。
等待一分钟。
创建一个新的快照。
执行分析的基础上,新快照。
基于之间的增量初始执行分析和新快照。
mysql >调用系统。statement_performance_analyzer (' create_tmp ', ' mydb。tmp_digests_ini’, NULL);查询好,0行(0.08秒)mysql >调用系统的影响。statement_performance_analyzer(“快照”,空,空);查询好,0行(0.02秒)mysql >调用系统的影响。statement_performance_analyzer(“保存”、“mydb。tmp_digests_ini’, NULL);查询好,0行影响(0.00秒)mysql >做睡眠(60);查询好,0行影响(1分0.00秒)mysql >调用系统。statement_performance_analyzer(“快照”,空,空);查询好,0行(0.02秒)mysql >调用系统的影响。statement_performance_analyzer(“整体”,NULL, with_runtimes_in_95th_percentile);+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + | |下一个输出+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + | | + 95百分位数与运行时查询- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 1行组(0.05秒)… mysql> CALL sys.statement_performance_analyzer('delta', 'mydb.tmp_digests_ini', 'with_runtimes_in_95th_percentile'); +-----------------------------------------+ | Next Output | +-----------------------------------------+ | Queries with Runtime in 95th Percentile | +-----------------------------------------+ 1 row in set (0.03 sec) ...
创建一个总体报告第95百分位的查询和全表扫描的前10名查询:
mysql >调用系统。statement_performance_analyzer(“快照”,空,空);查询好,0行影响(0.01秒)mysql >设置@sys.statement_performance_analyzer。限制= 10;查询好,0行(0.00秒)mysql >调用系统的影响。statement_performance_analyzer(“整体”,NULL, with_runtimes_in_95th_percentile, with_full_table_scans);+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + | |下一个输出+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + | | + 95百分位数与运行时查询- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 1行组(0.01秒)…+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + | |下一个输出+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +全表扫描| + |前十名查询- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 1行组(0.09秒)…
使用一个定制的视图显示前10名查询按总执行时间,刷新视图使用每一分钟看命令在Linux中:
mysql >创建或替换mydb的看法。my_statements作为选择sys.format_statement (DIGEST_TEXT)查询,SCHEMA_NAME db, COUNT_STAR exec_count, sys.format_time (SUM_TIMER_WAIT) total_latency, sys.format_time (AVG_TIMER_WAIT) avg_latency,圆(IFNULL (SUM_ROWS_SENT / NULLIF (COUNT_STAR, 0), 0))作为rows_sent_avg,圆(IFNULL (SUM_ROWS_EXAMINED / NULLIF (COUNT_STAR, 0), 0))作为rows_examined_avg,圆(IFNULL (SUM_ROWS_AFFECTED / NULLIF (COUNT_STAR, 0), 0))作为rows_affected_avg,消化performance_schema消化。由SUM_TIMER_WAIT DESC events_statements_summary_by_digest秩序;查询好,0行(0.10秒)mysql >调用系统的影响。statement_performance_analyzer (' create_table ', ' mydb。digests_prev’, NULL);查询好,0行影响(0.10秒)>看- n 60美元“mysql sys -表- e \ " >设置@sys.statement_performance_analyzer。视图=“mydb.my_statements”;>设置@sys.statement_performance_analyzer。限制= 10;>调用statement_performance_analyzer(“快照”,空,空);>调用statement_performance_analyzer(“δ”、“mydb。digests_prev”、“自定义”);>调用statement_performance_analyzer(“保存”、“mydb。digests_prev’, NULL);> \”“每60.0 s: mysql sys -表- e”……星期一2014年12月22日10:58:51 + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + | |下一个输出+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + |前十名查询使用自定义视图| + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | + |查询db | exec_count | total_latency | avg_latency | rows_sent_avg | rows_examined_avg | rows_affected_avg | | +消化- - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +……