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

Commit 2690abb

Browse files
author
Joe Grasse
committed
All user summaries should include background thread
Adding background thread to the reset of the user summary views so that they are consistent.
1 parent dd795bb commit 2690abb

File tree

6 files changed

+52
-36
lines changed

6 files changed

+52
-36
lines changed

views/p_s/memory_by_user.sql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* View: memory_by_user_by_current_bytes
1818
*
1919
* Summarizes memory use by user using the 5.7 Performance Schema instrumentation.
20+
*
21+
* When the user found is NULL, it is assumed to be a "background" thread.
2022
*
2123
* mysql> select * from memory_by_user_by_current_bytes WHERE user IS NOT NULL;
2224
* +------+--------------------+-------------------+-------------------+-------------------+-----------------+
@@ -40,7 +42,7 @@ VIEW memory_by_user_by_current_bytes (
4042
current_max_alloc,
4143
total_allocated
4244
) AS
43-
SELECT user,
45+
SELECT IF(user IS NULL, 'background', user) AS user,
4446
SUM(current_count_used) AS current_count_used,
4547
sys.format_bytes(SUM(current_number_of_bytes_used)) AS current_allocated,
4648
sys.format_bytes(IFNULL(SUM(current_number_of_bytes_used) / NULLIF(SUM(current_count_used), 0), 0)) AS current_avg_alloc,
@@ -54,6 +56,8 @@ SELECT user,
5456
* View: x$memory_by_user_by_current_bytes
5557
*
5658
* Summarizes memory use by user
59+
*
60+
* When the user found is NULL, it is assumed to be a "background" thread.
5761
*
5862
* mysql> select * from x$memory_by_user_by_current_bytes WHERE user IS NOT NULL;
5963
* +------+--------------------+-------------------+-------------------+-------------------+-----------------+
@@ -77,7 +81,7 @@ VIEW x$memory_by_user_by_current_bytes (
7781
current_max_alloc,
7882
total_allocated
7983
) AS
80-
SELECT user,
84+
SELECT IF(user IS NULL, 'background', user) AS user,
8185
SUM(current_count_used) AS current_count_used,
8286
SUM(current_number_of_bytes_used) AS current_allocated,
8387
IFNULL(SUM(current_number_of_bytes_used) / NULLIF(SUM(current_count_used), 0), 0) AS current_avg_alloc,

views/p_s/user_summary.sql

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* View: user_summary
1818
*
1919
* Summarizes statement activity, file IO and connections by user.
20+
*
21+
* When the user found is NULL, it is assumed to be a "background" thread.
2022
*
2123
* mysql> select * from user_summary;
2224
* +------+------------+-------------------+-----------------------+-------------+----------+-----------------+---------------------+-------------------+--------------+
@@ -43,7 +45,7 @@ VIEW user_summary (
4345
total_connections,
4446
unique_hosts
4547
) AS
46-
SELECT accounts.user,
48+
SELECT IF(accounts.user IS NULL, 'background', accounts.user) AS user,
4749
SUM(stmt.total) AS statements,
4850
sys.format_time(SUM(stmt.total_latency)) AS statement_latency,
4951
sys.format_time(IFNULL(SUM(stmt.total_latency) / NULLIF(SUM(stmt.total), 0), 0)) AS statement_avg_latency,
@@ -54,15 +56,16 @@ SELECT accounts.user,
5456
SUM(accounts.total_connections) AS total_connections,
5557
COUNT(DISTINCT host) AS unique_hosts
5658
FROM performance_schema.accounts
57-
LEFT JOIN sys.x$user_summary_by_statement_latency AS stmt ON accounts.user = stmt.user
58-
LEFT JOIN sys.x$user_summary_by_file_io AS io ON accounts.user = io.user
59-
WHERE accounts.user IS NOT NULL
60-
GROUP BY accounts.user;
59+
LEFT JOIN sys.x$user_summary_by_statement_latency AS stmt ON IF(accounts.user IS NULL, 'background', accounts.user) = stmt.user
60+
LEFT JOIN sys.x$user_summary_by_file_io AS io ON IF(accounts.user IS NULL, 'background', accounts.user) = io.user
61+
GROUP BY IF(accounts.user IS NULL, 'background', accounts.user);
6162

6263
/*
6364
* View: x$user_summary
6465
*
6566
* Summarizes statement activity, file IO and connections by user.
67+
*
68+
* When the user found is NULL, it is assumed to be a "background" thread.
6669
*
6770
* mysql> select * from x$user_summary;
6871
* +------+------------+-------------------+-----------------------+-------------+----------+-----------------+---------------------+-------------------+--------------+
@@ -89,7 +92,7 @@ VIEW x$user_summary (
8992
total_connections,
9093
unique_hosts
9194
) AS
92-
SELECT accounts.user,
95+
SELECT IF(accounts.user IS NULL, 'background', accounts.user) AS user,
9396
SUM(stmt.total) AS statements,
9497
SUM(stmt.total_latency) AS statement_latency,
9598
IFNULL(SUM(stmt.total_latency) / NULLIF(SUM(stmt.total), 0), 0) AS statement_avg_latency,
@@ -100,7 +103,6 @@ SELECT accounts.user,
100103
SUM(accounts.total_connections) AS total_connections,
101104
COUNT(DISTINCT host) AS unique_hosts
102105
FROM performance_schema.accounts
103-
LEFT JOIN sys.x$user_summary_by_statement_latency AS stmt ON accounts.user = stmt.user
104-
LEFT JOIN sys.x$user_summary_by_file_io AS io ON accounts.user = io.user
105-
WHERE accounts.user IS NOT NULL
106-
GROUP BY accounts.user;
106+
LEFT JOIN sys.x$user_summary_by_statement_latency AS stmt ON IF(accounts.user IS NULL, 'background', accounts.user) = stmt.user
107+
LEFT JOIN sys.x$user_summary_by_file_io AS io ON IF(accounts.user IS NULL, 'background', accounts.user) = io.user
108+
GROUP BY IF(accounts.user IS NULL, 'background', accounts.user);

views/p_s/user_summary_57.sql

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* View: user_summary
1818
*
1919
* Summarizes statement activity and connections by user
20+
*
21+
* When the user found is NULL, it is assumed to be a "background" thread.
2022
*
2123
* mysql> select * from user_summary;
2224
* +------+------------+---------------+-------------+---------------------+-------------------+--------------+----------------+------------------------+
@@ -46,7 +48,7 @@ VIEW user_summary (
4648
current_memory,
4749
total_memory_allocated
4850
) AS
49-
SELECT accounts.user,
51+
SELECT IF(accounts.user IS NULL, 'background', accounts.user) AS user,
5052
SUM(stmt.total) AS statements,
5153
sys.format_time(SUM(stmt.total_latency)) AS statement_latency,
5254
sys.format_time(IFNULL(SUM(stmt.total_latency) / NULLIF(SUM(stmt.total), 0), 0)) AS statement_avg_latency,
@@ -59,16 +61,17 @@ SELECT accounts.user,
5961
sys.format_bytes(mem.current_allocated) AS current_memory,
6062
sys.format_bytes(mem.total_allocated) AS total_memory_allocated
6163
FROM performance_schema.accounts
62-
JOIN sys.x$user_summary_by_statement_latency AS stmt ON accounts.user = stmt.user
63-
JOIN sys.x$user_summary_by_file_io AS io ON accounts.user = io.user
64-
JOIN sys.x$memory_by_user_by_current_bytes mem ON accounts.user = mem.user
65-
WHERE accounts.user IS NOT NULL
66-
GROUP BY accounts.user;
64+
LEFT JOIN sys.x$user_summary_by_statement_latency AS stmt ON IF(accounts.user IS NULL, 'background', accounts.user) = stmt.user
65+
LEFT JOIN sys.x$user_summary_by_file_io AS io ON IF(accounts.user IS NULL, 'background', accounts.user) = io.user
66+
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);
6768

6869
/*
6970
* View: x$user_summary
7071
*
7172
* Summarizes statement activity and connections by user
73+
*
74+
* When the user found is NULL, it is assumed to be a "background" thread.
7275
*
7376
* mysql> select * from x$user_summary;
7477
* +------+------------+-----------------+------------------+---------------------+-------------------+--------------+----------------+------------------------+
@@ -98,7 +101,7 @@ VIEW x$user_summary (
98101
current_memory,
99102
total_memory_allocated
100103
) AS
101-
SELECT accounts.user,
104+
SELECT IF(accounts.user IS NULL, 'background', accounts.user) AS user,
102105
SUM(stmt.total) AS statements,
103106
SUM(stmt.total_latency) AS statement_latency,
104107
IFNULL(SUM(stmt.total_latency) / NULLIF(SUM(stmt.total), 0), 0) AS statement_avg_latency,
@@ -111,8 +114,7 @@ SELECT accounts.user,
111114
mem.current_allocated AS current_memory,
112115
mem.total_allocated AS total_memory_allocated
113116
FROM performance_schema.accounts
114-
JOIN sys.x$user_summary_by_statement_latency AS stmt ON accounts.user = stmt.user
115-
JOIN sys.x$user_summary_by_file_io AS io ON accounts.user = io.user
116-
JOIN sys.x$memory_by_user_by_current_bytes mem ON accounts.user = mem.user
117-
WHERE accounts.user IS NOT NULL
118-
GROUP BY accounts.user;
117+
LEFT JOIN sys.x$user_summary_by_statement_latency AS stmt ON IF(accounts.user IS NULL, 'background', accounts.user) = stmt.user
118+
LEFT JOIN sys.x$user_summary_by_file_io AS io ON IF(accounts.user IS NULL, 'background', accounts.user) = io.user
119+
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);

views/p_s/user_summary_by_stages.sql

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*
1919
* Summarizes stages by user, ordered by user and total latency per stage.
2020
*
21+
* When the user found is NULL, it is assumed to be a "background" thread.
22+
*
2123
* mysql> select * from user_summary_by_stages;
2224
* +------+--------------------------------+-------+-----------+-----------+
2325
* | user | event_name | total | wait_sum | wait_avg |
@@ -53,21 +55,22 @@ VIEW user_summary_by_stages (
5355
wait_sum,
5456
wait_avg
5557
) AS
56-
SELECT user,
58+
SELECT IF(user IS NULL, 'background', user) AS user,
5759
event_name,
5860
count_star AS total,
5961
sys.format_time(sum_timer_wait) AS wait_sum,
6062
sys.format_time(avg_timer_wait) AS wait_avg
6163
FROM performance_schema.events_stages_summary_by_user_by_event_name
62-
WHERE user IS NOT NULL
63-
AND sum_timer_wait != 0
64+
WHERE sum_timer_wait != 0
6465
ORDER BY user, sum_timer_wait DESC;
6566

6667
/*
6768
* View: x$user_summary_by_stages
6869
*
6970
* Summarizes stages by user, ordered by user and total latency per stage.
7071
*
72+
* When the user found is NULL, it is assumed to be a "background" thread.
73+
*
7174
* mysql> select * from x$user_summary_by_stages;
7275
* +------+--------------------------------+-------+-------------+-----------+
7376
* | user | event_name | total | wait_sum | wait_avg |
@@ -102,12 +105,11 @@ VIEW x$user_summary_by_stages (
102105
wait_sum,
103106
wait_avg
104107
) AS
105-
SELECT user,
108+
SELECT IF(user IS NULL, 'background', user) AS user,
106109
event_name,
107110
count_star AS total,
108111
sum_timer_wait AS wait_sum,
109112
avg_timer_wait AS wait_avg
110113
FROM performance_schema.events_stages_summary_by_user_by_event_name
111-
WHERE user IS NOT NULL
112-
AND sum_timer_wait != 0
114+
WHERE sum_timer_wait != 0
113115
ORDER BY user, sum_timer_wait DESC;

views/p_s/user_summary_by_statement_latency.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* View: user_summary_by_statement_latency
1818
*
1919
* Summarizes overall statement statistics by user.
20+
*
21+
* When the user found is NULL, it is assumed to be a "background" thread.
2022
*
2123
* mysql> select * from user_summary_by_statement_latency;
2224
* +------+-------+---------------+-------------+--------------+-----------+---------------+---------------+------------+
@@ -59,6 +61,8 @@ SELECT user,
5961
* View: x$user_summary_by_statement_latency
6062
*
6163
* Summarizes overall statement statistics by user.
64+
*
65+
* When the user found is NULL, it is assumed to be a "background" thread.
6266
*
6367
* mysql> select * from x$user_summary_by_statement_latency;
6468
* +------+-------+-----------------+---------------+---------------+-----------+---------------+---------------+------------+

views/p_s/user_summary_by_statement_type.sql

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* View: user_summary_by_statement_type
1818
*
1919
* Summarizes the types of statements executed by each user.
20+
*
21+
* When the user found is NULL, it is assumed to be a "background" thread.
2022
*
2123
* mysql> select * from user_summary_by_statement_type;
2224
* +------+----------------------+--------+---------------+-------------+--------------+-----------+---------------+---------------+------------+
@@ -48,7 +50,7 @@ VIEW user_summary_by_statement_type (
4850
rows_affected,
4951
full_scans
5052
) AS
51-
SELECT user,
53+
SELECT IF(user IS NULL, 'background', user) AS user,
5254
SUBSTRING_INDEX(event_name, '/', -1) AS statement,
5355
count_star AS total,
5456
sys.format_time(sum_timer_wait) AS total_latency,
@@ -59,14 +61,15 @@ SELECT user,
5961
sum_rows_affected AS rows_affected,
6062
sum_no_index_used + sum_no_good_index_used AS full_scans
6163
FROM performance_schema.events_statements_summary_by_user_by_event_name
62-
WHERE user IS NOT NULL
63-
AND sum_timer_wait != 0
64+
WHERE sum_timer_wait != 0
6465
ORDER BY user, sum_timer_wait DESC;
6566

6667
/*
6768
* View: x$user_summary_by_statement_type
6869
*
6970
* Summarizes the types of statements executed by each user.
71+
*
72+
* When the user found is NULL, it is assumed to be a "background" thread.
7073
*
7174
* mysql> select * from x$user_summary_by_statement_type;
7275
* +------+----------------------+--------+-----------------+----------------+----------------+-----------+---------------+---------------+------------+
@@ -98,7 +101,7 @@ VIEW x$user_summary_by_statement_type (
98101
rows_affected,
99102
full_scans
100103
) AS
101-
SELECT user,
104+
SELECT IF(user IS NULL, 'background', user) AS user,
102105
SUBSTRING_INDEX(event_name, '/', -1) AS statement,
103106
count_star AS total,
104107
sum_timer_wait AS total_latency,
@@ -109,6 +112,5 @@ SELECT user,
109112
sum_rows_affected AS rows_affected,
110113
sum_no_index_used + sum_no_good_index_used AS full_scans
111114
FROM performance_schema.events_statements_summary_by_user_by_event_name
112-
WHERE user IS NOT NULL
113-
AND sum_timer_wait != 0
115+
WHERE sum_timer_wait != 0
114116
ORDER BY user, sum_timer_wait DESC;

0 commit comments

Comments
 (0)