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

Commit bcb0e93

Browse files
committed
Update the user summary views to support the new 5.7 ONLY_FULL_GROUP_BY mode with functional dependencies
1 parent 63b1783 commit bcb0e93

File tree

4 files changed

+93
-90
lines changed

4 files changed

+93
-90
lines changed

views/p_s/user_summary_57.sql

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ SELECT IF(accounts.user IS NULL, 'background', accounts.user) AS user,
5858
SUM(accounts.current_connections) AS current_connections,
5959
SUM(accounts.total_connections) AS total_connections,
6060
COUNT(DISTINCT host) AS unique_hosts,
61-
sys.format_bytes(mem.current_allocated) AS current_memory,
62-
sys.format_bytes(mem.total_allocated) AS total_memory_allocated
61+
sys.format_bytes(SUM(mem.current_allocated)) AS current_memory,
62+
sys.format_bytes(SUM(mem.total_allocated)) AS total_memory_allocated
6363
FROM performance_schema.accounts
6464
LEFT JOIN sys.x$user_summary_by_statement_latency AS stmt ON IF(accounts.user IS NULL, 'background', accounts.user) = stmt.user
6565
LEFT JOIN sys.x$user_summary_by_file_io AS io ON IF(accounts.user IS NULL, 'background', accounts.user) = io.user
6666
LEFT JOIN sys.x$memory_by_user_by_current_bytes mem ON IF(accounts.user IS NULL, 'background', accounts.user) = mem.user
67-
GROUP BY IF(accounts.user IS NULL, 'background', accounts.user);
67+
GROUP BY IF(accounts.user IS NULL, 'background', accounts.user)
68+
ORDER BY SUM(stmt.total_latency) DESC;
6869

6970
/*
7071
* View: x$user_summary
@@ -111,10 +112,12 @@ SELECT IF(accounts.user IS NULL, 'background', accounts.user) AS user,
111112
SUM(accounts.current_connections) AS current_connections,
112113
SUM(accounts.total_connections) AS total_connections,
113114
COUNT(DISTINCT host) AS unique_hosts,
114-
mem.current_allocated AS current_memory,
115-
mem.total_allocated AS total_memory_allocated
115+
SUM(mem.current_allocated) AS current_memory,
116+
SUM(mem.total_allocated) AS total_memory_allocated
116117
FROM performance_schema.accounts
117118
LEFT JOIN sys.x$user_summary_by_statement_latency AS stmt ON IF(accounts.user IS NULL, 'background', accounts.user) = stmt.user
118119
LEFT JOIN sys.x$user_summary_by_file_io AS io ON IF(accounts.user IS NULL, 'background', accounts.user) = io.user
119120
LEFT JOIN sys.x$memory_by_user_by_current_bytes mem ON IF(accounts.user IS NULL, 'background', accounts.user) = mem.user
120-
GROUP BY IF(accounts.user IS NULL, 'background', accounts.user);
121+
GROUP BY IF(accounts.user IS NULL, 'background', accounts.user)
122+
ORDER BY SUM(stmt.total_latency) DESC;
123+

views/p_s/user_summary_by_file_io.sql

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ VIEW user_summary_by_file_io (
3939
ios,
4040
io_latency
4141
) AS
42-
SELECT user,
43-
SUM(total) AS ios,
44-
sys.format_time(SUM(latency)) AS io_latency
45-
FROM x$user_summary_by_file_io_type
46-
GROUP BY user
47-
ORDER BY SUM(latency) DESC;
42+
SELECT IF(user IS NULL, 'background', user) AS user,
43+
SUM(count_star) AS ios,
44+
sys.format_time(SUM(sum_timer_wait)) AS io_latency
45+
FROM performance_schema.events_waits_summary_by_user_by_event_name
46+
GROUP BY IF(user IS NULL, 'background', user)
47+
ORDER BY SUM(sum_timer_wait) DESC;
4848

4949
/*
5050
* View: x$user_summary_by_file_io
@@ -72,9 +72,9 @@ VIEW x$user_summary_by_file_io (
7272
ios,
7373
io_latency
7474
) AS
75-
SELECT user,
76-
SUM(total) AS ios,
77-
SUM(latency) AS io_latency
78-
FROM x$user_summary_by_file_io_type
79-
GROUP BY user
80-
ORDER BY SUM(latency) DESC;
75+
SELECT IF(user IS NULL, 'background', user) AS user,
76+
SUM(count_star) AS ios,
77+
SUM(sum_timer_wait) AS io_latency
78+
FROM performance_schema.events_waits_summary_by_user_by_event_name
79+
GROUP BY IF(user IS NULL, 'background', user)
80+
ORDER BY SUM(sum_timer_wait) DESC;

views/p_s/user_summary_by_stages.sql

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@
2121
* When the user found is NULL, it is assumed to be a "background" thread.
2222
*
2323
* mysql> select * from user_summary_by_stages;
24-
* +------+--------------------------------+-------+-----------+-----------+
25-
* | user | event_name | total | wait_sum | wait_avg |
26-
* +------+--------------------------------+-------+-----------+-----------+
27-
* | root | stage/sql/Opening tables | 889 | 1.97 ms | 2.22 us |
28-
* | root | stage/sql/Creating sort index | 4 | 1.79 ms | 446.30 us |
29-
* | root | stage/sql/init | 10 | 312.27 us | 31.23 us |
30-
* | root | stage/sql/checking permissions | 10 | 300.62 us | 30.06 us |
31-
* | root | stage/sql/freeing items | 5 | 85.89 us | 17.18 us |
32-
* | root | stage/sql/statistics | 5 | 79.15 us | 15.83 us |
33-
* | root | stage/sql/preparing | 5 | 69.12 us | 13.82 us |
34-
* | root | stage/sql/optimizing | 5 | 53.11 us | 10.62 us |
35-
* | root | stage/sql/Sending data | 5 | 44.66 us | 8.93 us |
36-
* | root | stage/sql/closing tables | 5 | 37.54 us | 7.51 us |
37-
* | root | stage/sql/System lock | 5 | 34.28 us | 6.86 us |
38-
* | root | stage/sql/query end | 5 | 24.37 us | 4.87 us |
39-
* | root | stage/sql/end | 5 | 8.60 us | 1.72 us |
40-
* | root | stage/sql/Sorting result | 5 | 8.33 us | 1.67 us |
41-
* | root | stage/sql/executing | 5 | 5.37 us | 1.07 us |
42-
* | root | stage/sql/cleaning up | 5 | 4.60 us | 919.00 ns |
43-
* +------+--------------------------------+-------+-----------+-----------+
24+
* +------+--------------------------------+-------+---------------+-------------+
25+
* | user | event_name | total | total_latency | avg_latency |
26+
* +------+--------------------------------+-------+---------------+-------------+
27+
* | root | stage/sql/Opening tables | 889 | 1.97 ms | 2.22 us |
28+
* | root | stage/sql/Creating sort index | 4 | 1.79 ms | 446.30 us |
29+
* | root | stage/sql/init | 10 | 312.27 us | 31.23 us |
30+
* | root | stage/sql/checking permissions | 10 | 300.62 us | 30.06 us |
31+
* | root | stage/sql/freeing items | 5 | 85.89 us | 17.18 us |
32+
* | root | stage/sql/statistics | 5 | 79.15 us | 15.83 us |
33+
* | root | stage/sql/preparing | 5 | 69.12 us | 13.82 us |
34+
* | root | stage/sql/optimizing | 5 | 53.11 us | 10.62 us |
35+
* | root | stage/sql/Sending data | 5 | 44.66 us | 8.93 us |
36+
* | root | stage/sql/closing tables | 5 | 37.54 us | 7.51 us |
37+
* | root | stage/sql/System lock | 5 | 34.28 us | 6.86 us |
38+
* | root | stage/sql/query end | 5 | 24.37 us | 4.87 us |
39+
* | root | stage/sql/end | 5 | 8.60 us | 1.72 us |
40+
* | root | stage/sql/Sorting result | 5 | 8.33 us | 1.67 us |
41+
* | root | stage/sql/executing | 5 | 5.37 us | 1.07 us |
42+
* | root | stage/sql/cleaning up | 5 | 4.60 us | 919.00 ns |
43+
* +------+--------------------------------+-------+---------------+-------------+
4444
*
4545
*/
4646

@@ -52,14 +52,14 @@ VIEW user_summary_by_stages (
5252
user,
5353
event_name,
5454
total,
55-
wait_sum,
56-
wait_avg
55+
total_latency,
56+
avg_latency
5757
) AS
5858
SELECT IF(user IS NULL, 'background', user) AS user,
5959
event_name,
6060
count_star AS total,
61-
sys.format_time(sum_timer_wait) AS wait_sum,
62-
sys.format_time(avg_timer_wait) AS wait_avg
61+
sys.format_time(sum_timer_wait) AS total_latency,
62+
sys.format_time(avg_timer_wait) AS avg_latency
6363
FROM performance_schema.events_stages_summary_by_user_by_event_name
6464
WHERE sum_timer_wait != 0
6565
ORDER BY user, sum_timer_wait DESC;
@@ -72,26 +72,26 @@ SELECT IF(user IS NULL, 'background', user) AS user,
7272
* When the user found is NULL, it is assumed to be a "background" thread.
7373
*
7474
* mysql> select * from x$user_summary_by_stages;
75-
* +------+--------------------------------+-------+-------------+-----------+
76-
* | user | event_name | total | wait_sum | wait_avg |
77-
* +------+--------------------------------+-------+-------------+-----------+
78-
* | root | stage/sql/Opening tables | 1114 | 71919037000 | 64559000 |
79-
* | root | stage/sql/Creating sort index | 5 | 2245762000 | 449152000 |
80-
* | root | stage/sql/init | 13 | 428798000 | 32984000 |
81-
* | root | stage/sql/checking permissions | 13 | 363231000 | 27940000 |
82-
* | root | stage/sql/freeing items | 7 | 137728000 | 19675000 |
83-
* | root | stage/sql/statistics | 6 | 93955000 | 15659000 |
84-
* | root | stage/sql/preparing | 6 | 82571000 | 13761000 |
85-
* | root | stage/sql/optimizing | 6 | 63338000 | 10556000 |
86-
* | root | stage/sql/Sending data | 6 | 53400000 | 8900000 |
87-
* | root | stage/sql/closing tables | 7 | 46922000 | 6703000 |
88-
* | root | stage/sql/System lock | 6 | 40175000 | 6695000 |
89-
* | root | stage/sql/query end | 7 | 31723000 | 4531000 |
90-
* | root | stage/sql/Sorting result | 6 | 9855000 | 1642000 |
91-
* | root | stage/sql/end | 6 | 9556000 | 1592000 |
92-
* | root | stage/sql/cleaning up | 7 | 7312000 | 1044000 |
93-
* | root | stage/sql/executing | 6 | 6487000 | 1081000 |
94-
* +------+--------------------------------+-------+-------------+-----------+ *
75+
* +------+--------------------------------+-------+---------------+-------------+
76+
* | user | event_name | total | total_latency | avg_latency |
77+
* +------+--------------------------------+-------+---------------+-------------+
78+
* | root | stage/sql/Opening tables | 1114 | 71919037000 | 64559000 |
79+
* | root | stage/sql/Creating sort index | 5 | 2245762000 | 449152000 |
80+
* | root | stage/sql/init | 13 | 428798000 | 32984000 |
81+
* | root | stage/sql/checking permissions | 13 | 363231000 | 27940000 |
82+
* | root | stage/sql/freeing items | 7 | 137728000 | 19675000 |
83+
* | root | stage/sql/statistics | 6 | 93955000 | 15659000 |
84+
* | root | stage/sql/preparing | 6 | 82571000 | 13761000 |
85+
* | root | stage/sql/optimizing | 6 | 63338000 | 10556000 |
86+
* | root | stage/sql/Sending data | 6 | 53400000 | 8900000 |
87+
* | root | stage/sql/closing tables | 7 | 46922000 | 6703000 |
88+
* | root | stage/sql/System lock | 6 | 40175000 | 6695000 |
89+
* | root | stage/sql/query end | 7 | 31723000 | 4531000 |
90+
* | root | stage/sql/Sorting result | 6 | 9855000 | 1642000 |
91+
* | root | stage/sql/end | 6 | 9556000 | 1592000 |
92+
* | root | stage/sql/cleaning up | 7 | 7312000 | 1044000 |
93+
* | root | stage/sql/executing | 6 | 6487000 | 1081000 |
94+
* +------+--------------------------------+-------+---------------+------------+
9595
*/
9696

9797
CREATE OR REPLACE
@@ -102,14 +102,14 @@ VIEW x$user_summary_by_stages (
102102
user,
103103
event_name,
104104
total,
105-
wait_sum,
106-
wait_avg
105+
total_latency,
106+
avg_latency
107107
) AS
108108
SELECT IF(user IS NULL, 'background', user) AS user,
109109
event_name,
110110
count_star AS total,
111-
sum_timer_wait AS wait_sum,
112-
avg_timer_wait AS wait_avg
111+
sum_timer_wait AS total_latency,
112+
avg_timer_wait AS avg_latency
113113
FROM performance_schema.events_stages_summary_by_user_by_event_name
114114
WHERE sum_timer_wait != 0
115115
ORDER BY user, sum_timer_wait DESC;

views/p_s/user_summary_by_statement_latency.sql

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ VIEW user_summary_by_statement_latency (
4444
rows_affected,
4545
full_scans
4646
) AS
47-
SELECT user,
48-
SUM(total) AS total,
49-
sys.format_time(SUM(total_latency)) AS total_latency,
50-
sys.format_time(SUM(max_latency)) AS max_latency,
51-
sys.format_time(SUM(lock_latency)) AS lock_latency,
52-
SUM(rows_sent) AS rows_sent,
53-
SUM(rows_examined) AS rows_examined,
54-
SUM(rows_affected) AS rows_affected,
55-
SUM(full_scans) AS full_scans
56-
FROM sys.x$user_summary_by_statement_type
57-
GROUP BY user
58-
ORDER BY SUM(total_latency) DESC;
47+
SELECT IF(user IS NULL, 'background', user) AS user,
48+
SUM(count_star) AS total,
49+
sys.format_time(SUM(sum_timer_wait)) AS total_latency,
50+
sys.format_time(SUM(max_timer_wait)) AS max_latency,
51+
sys.format_time(SUM(sum_lock_time)) AS lock_latency,
52+
SUM(sum_rows_sent) AS rows_sent,
53+
SUM(sum_rows_examined) AS rows_examined,
54+
SUM(sum_rows_affected) AS rows_affected,
55+
SUM(sum_no_index_used) + SUM(sum_no_good_index_used) AS full_scans
56+
FROM performance_schema.events_statements_summary_by_user_by_event_name
57+
GROUP BY IF(user IS NULL, 'background', user)
58+
ORDER BY SUM(sum_timer_wait) DESC;
5959

6060
/*
6161
* View: x$user_summary_by_statement_latency
@@ -88,15 +88,15 @@ VIEW x$user_summary_by_statement_latency (
8888
rows_affected,
8989
full_scans
9090
) AS
91-
SELECT user,
92-
SUM(total) AS total,
93-
SUM(total_latency) AS total_latency,
94-
SUM(max_latency) AS max_latency,
95-
SUM(lock_latency) AS lock_latency,
96-
SUM(rows_sent) AS rows_sent,
97-
SUM(rows_examined) AS rows_examined,
98-
SUM(rows_affected) AS rows_affected,
99-
SUM(full_scans) AS full_scans
100-
FROM sys.x$user_summary_by_statement_type
101-
GROUP BY user
102-
ORDER BY SUM(total_latency) DESC;
91+
SELECT IF(user IS NULL, 'background', user) AS user,
92+
SUM(count_star) AS total,
93+
SUM(sum_timer_wait) AS total_latency,
94+
SUM(max_timer_wait) AS max_latency,
95+
SUM(sum_lock_time) AS lock_latency,
96+
SUM(sum_rows_sent) AS rows_sent,
97+
SUM(sum_rows_examined) AS rows_examined,
98+
SUM(sum_rows_affected) AS rows_affected,
99+
SUM(sum_no_index_used) + SUM(sum_no_good_index_used) AS full_scans
100+
FROM performance_schema.events_statements_summary_by_user_by_event_name
101+
GROUP BY IF(user IS NULL, 'background', user)
102+
ORDER BY SUM(sum_timer_wait) DESC;

0 commit comments

Comments
 (0)