Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit 6cfaeb5

Browse files
committed
Create host_summary_by_statement_type.sql
1 parent 7715c3b commit 6cfaeb5

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
2+
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; version 2 of the License.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program; if not, write to the Free Software
14+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15+
16+
/*
17+
* View: host_summary_by_statement_type
18+
*
19+
* Summarizes the types of statements executed by each host.
20+
*
21+
* mysql> select * from host_summary_by_statement_type;
22+
* +------+----------------------+--------+---------------+-------------+--------------+-----------+---------------+---------------+------------+
23+
* | host | statement | total | total_latency | max_latency | lock_latency | rows_sent | rows_examined | rows_affected | full_scans |
24+
* +------+----------------------+--------+---------------+-------------+--------------+-----------+---------------+---------------+------------+
25+
* | hal | create_view | 2063 | 00:05:04.20 | 463.58 ms | 1.42 s | 0 | 0 | 0 | 0 |
26+
* | hal | select | 174 | 40.87 s | 28.83 s | 858.13 ms | 5212 | 157022 | 0 | 82 |
27+
* | hal | stmt | 6645 | 15.31 s | 491.78 ms | 0 ps | 0 | 0 | 7951 | 0 |
28+
* | hal | call_procedure | 17 | 4.78 s | 1.02 s | 37.94 ms | 0 | 0 | 19 | 0 |
29+
* | hal | create_table | 19 | 3.04 s | 431.71 ms | 0 ps | 0 | 0 | 0 | 0 |
30+
* ...
31+
* +------+----------------------+--------+---------------+-------------+--------------+-----------+---------------+---------------+------------+
32+
*
33+
*/
34+
35+
CREATE OR REPLACE
36+
ALGORITHM = MERGE
37+
DEFINER = 'root'@'localhost'
38+
SQL SECURITY INVOKER
39+
VIEW host_summary_by_statement_type (
40+
host,
41+
statement,
42+
total,
43+
total_latency,
44+
max_latency,
45+
lock_latency,
46+
rows_sent,
47+
rows_examined,
48+
rows_affected,
49+
full_scans
50+
) AS
51+
SELECT host,
52+
SUBSTRING_INDEX(event_name, '/', -1) AS statement,
53+
count_star AS total,
54+
sys.format_time(sum_timer_wait) AS total_latency,
55+
sys.format_time(max_timer_wait) AS max_latency,
56+
sys.format_time(sum_lock_time) AS lock_latency,
57+
sum_rows_sent AS rows_sent,
58+
sum_rows_examined AS rows_examined,
59+
sum_rows_affected AS rows_affected,
60+
sum_no_index_used + sum_no_good_index_used AS full_scans
61+
FROM performance_schema.events_statements_summary_by_host_by_event_name
62+
WHERE host IS NOT NULL
63+
AND sum_timer_wait != 0
64+
ORDER BY host, sum_timer_wait DESC;
65+
66+
/*
67+
* View: x$host_summary_by_statement_type
68+
*
69+
* Summarizes the types of statements executed by each host.
70+
*
71+
* mysql> select * from x$host_summary_by_statement_type;
72+
* +------+----------------------+--------+-----------------+----------------+----------------+-----------+---------------+---------------+------------+
73+
* | host | statement | total | total_latency | max_latency | lock_latency | rows_sent | rows_examined | rows_affected | full_scans |
74+
* +------+----------------------+--------+-----------------+----------------+----------------+-----------+---------------+---------------+------------+
75+
* | hal | create_view | 2110 | 312717366332000 | 463578029000 | 1432355000000 | 0 | 0 | 0 | 0 |
76+
* | hal | select | 177 | 41115690428000 | 28827579292000 | 858709000000 | 5254 | 157437 | 0 | 83 |
77+
* | hal | stmt | 6645 | 15305389969000 | 491780297000 | 0 | 0 | 0 | 7951 | 0 |
78+
* | hal | call_procedure | 17 | 4783806053000 | 1016083397000 | 37936000000 | 0 | 0 | 19 | 0 |
79+
* | hal | create_table | 19 | 3035120946000 | 431706815000 | 0 | 0 | 0 | 0 | 0 |
80+
* ...
81+
* +------+----------------------+--------+-----------------+----------------+----------------+-----------+---------------+---------------+------------+
82+
*
83+
*/
84+
85+
CREATE OR REPLACE
86+
ALGORITHM = MERGE
87+
DEFINER = 'root'@'localhost'
88+
SQL SECURITY INVOKER
89+
VIEW x$host_summary_by_statement_type (
90+
host,
91+
statement,
92+
total,
93+
total_latency,
94+
max_latency,
95+
lock_latency,
96+
rows_sent,
97+
rows_examined,
98+
rows_affected,
99+
full_scans
100+
) AS
101+
SELECT host,
102+
SUBSTRING_INDEX(event_name, '/', -1) AS statement,
103+
count_star AS total,
104+
sum_timer_wait AS total_latency,
105+
max_timer_wait AS max_latency,
106+
sum_lock_time AS lock_latency,
107+
sum_rows_sent AS rows_sent,
108+
sum_rows_examined AS rows_examined,
109+
sum_rows_affected AS rows_affected,
110+
sum_no_index_used + sum_no_good_index_used AS full_scans
111+
FROM performance_schema.events_statements_summary_by_host_by_event_name
112+
WHERE host IS NOT NULL
113+
AND sum_timer_wait != 0
114+
ORDER BY host, sum_timer_wait DESC;

0 commit comments

Comments
 (0)