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

Commit ebce8fe

Browse files
Merge remote branch 'upstream/development' into dev/issue_15_reset_to_default
Conflicts: README.md sys_56.sql sys_57.sql
2 parents a8693af + 7c98db9 commit ebce8fe

15 files changed

+188
-67
lines changed

README.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,12 @@ mysql> select * from latest_file_io limit 5;
251251

252252
Summarizes memory use by user using the 5.7 Performance Schema instrumentation.
253253

254+
When the user found is NULL, it is assumed to be a "background" thread.
255+
254256
##### Example
255257

256258
```SQL
257-
mysql> select * from memory_by_user_by_current_bytes WHERE user IS NOT NULL;
259+
mysql> select * from memory_by_user_by_current_bytes;
258260
+------+--------------------+-------------------+-------------------+-------------------+-----------------+
259261
| user | current_count_used | current_allocated | current_avg_alloc | current_max_alloc | total_allocated |
260262
+------+--------------------+-------------------+-------------------+-------------------+-----------------+
@@ -742,6 +744,8 @@ avg_tmp_tables_per_query: 189
742744
743745
Summarizes statement activity, file IO and connections by user.
744746
747+
When the user found is NULL, it is assumed to be a "background" thread.
748+
745749
##### Example
746750
747751
```SQL
@@ -823,6 +827,8 @@ mysql> select * from user_summary_by_file_io_type;
823827
824828
Summarizes stages by user, ordered by user and total latency per stage.
825829
830+
When the user found is NULL, it is assumed to be a "background" thread.
831+
826832
##### Example
827833
828834
```SQL
@@ -855,6 +861,8 @@ mysql> select * from user_summary_by_stages;
855861
856862
Summarizes overall statement statistics by user.
857863
864+
When the user found is NULL, it is assumed to be a "background" thread.
865+
858866
##### Example
859867
860868
```SQL
@@ -872,6 +880,8 @@ mysql> select * from user_summary_by_statement_latency;
872880
873881
Summarizes the types of statements executed by each user.
874882
883+
When the user found is NULL, it is assumed to be a "background" thread.
884+
875885
##### Example
876886
877887
```SQL
@@ -1206,7 +1216,7 @@ Currently relies on the fact that a table data file will be within a specified d
12061216
12071217
##### Returns
12081218
1209-
VARCHAR(512)
1219+
VARCHAR(64)
12101220
12111221
##### Example
12121222
```SQL
@@ -1233,7 +1243,7 @@ Useful for when interacting with Performance Schema data concerning IO statistic
12331243
12341244
##### Returns
12351245
1236-
VARCHAR(512)
1246+
VARCHAR(64)
12371247
12381248
##### Example
12391249
```SQL
@@ -1474,6 +1484,39 @@ mysql> SELECT sys.ps_is_instrument_default_timed('statement/sql/select');
14741484
1 row in set (0.00 sec)
14751485
```
14761486

1487+
#### ps_thread_id
1488+
1489+
##### Description
1490+
1491+
Return the Performance Schema THREAD_ID for the specified connection ID.
1492+
1493+
##### Parameters
1494+
1495+
* in_connection_id (BIGINT UNSIGNED): The id of the connection to return the thread id for.
1496+
1497+
##### Returns
1498+
1499+
BIGINT UNSIGNED
1500+
1501+
##### Example
1502+
```SQL
1503+
mysql> SELECT sys.ps_thread_id(79);
1504+
+----------------------+
1505+
| sys.ps_thread_id(79) |
1506+
+----------------------+
1507+
| 98 |
1508+
+----------------------+
1509+
1 row in set (0.00 sec)
1510+
1511+
mysql> SELECT sys.ps_thread_id(CONNECTION_ID());
1512+
+-----------------------------------+
1513+
| sys.ps_thread_id(CONNECTION_ID()) |
1514+
+-----------------------------------+
1515+
| 98 |
1516+
+-----------------------------------+
1517+
1 row in set (0.00 sec)
1518+
```
1519+
14771520
#### ps_thread_stack
14781521

14791522
##### Description

functions/extract_schema_from_file_name.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ DELIMITER $$
2020
CREATE DEFINER='root'@'localhost' FUNCTION extract_schema_from_file_name (
2121
path VARCHAR(512)
2222
)
23-
RETURNS VARCHAR(512)
23+
RETURNS VARCHAR(64)
2424
COMMENT '
2525
Description
2626
-----------
@@ -43,7 +43,7 @@ CREATE DEFINER='root'@'localhost' FUNCTION extract_schema_from_file_name (
4343
Returns
4444
-----------
4545
46-
VARCHAR(512)
46+
VARCHAR(64)
4747
4848
Example
4949
-----------
@@ -59,7 +59,7 @@ CREATE DEFINER='root'@'localhost' FUNCTION extract_schema_from_file_name (
5959
SQL SECURITY INVOKER
6060
DETERMINISTIC
6161
NO SQL
62-
RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(REPLACE(path, '\\', '/'), '/', -2), '/', 1)
62+
RETURN LEFT(SUBSTRING_INDEX(SUBSTRING_INDEX(REPLACE(path, '\\', '/'), '/', -2), '/', 1), 64);
6363
$$
6464

6565
DELIMITER ;

functions/extract_table_from_file_name.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ DELIMITER $$
2020
CREATE DEFINER='root'@'localhost' FUNCTION extract_table_from_file_name (
2121
path VARCHAR(512)
2222
)
23-
RETURNS VARCHAR(512)
23+
RETURNS VARCHAR(64)
2424
COMMENT '
2525
Description
2626
-----------
@@ -39,7 +39,7 @@ CREATE DEFINER='root'@'localhost' FUNCTION extract_table_from_file_name (
3939
Returns
4040
-----------
4141
42-
VARCHAR(512)
42+
VARCHAR(64)
4343
4444
Example
4545
-----------
@@ -55,7 +55,7 @@ CREATE DEFINER='root'@'localhost' FUNCTION extract_table_from_file_name (
5555
SQL SECURITY INVOKER
5656
DETERMINISTIC
5757
NO SQL
58-
RETURN SUBSTRING_INDEX(REPLACE(SUBSTRING_INDEX(REPLACE(path, '\\', '/'), '/', -1), '@0024', '$'), '.', 1);
58+
RETURN LEFT(SUBSTRING_INDEX(REPLACE(SUBSTRING_INDEX(REPLACE(path, '\\', '/'), '/', -1), '@0024', '$'), '.', 1), 64);
5959
$$
6060

6161
DELIMITER ;

functions/ps_thread_id.sql

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
DROP FUNCTION IF EXISTS ps_thread_id;
17+
18+
CREATE DEFINER='root'@'localhost' FUNCTION ps_thread_id(
19+
in_connection_id BIGINT UNSIGNED
20+
) RETURNS BIGINT UNSIGNED
21+
COMMENT '
22+
Description
23+
-----------
24+
25+
Return the Performance Schema THREAD_ID for the specified connection ID.
26+
27+
Parameters
28+
-----------
29+
30+
in_connection_id (BIGINT UNSIGNED):
31+
The id of the connection to return the thread id for.
32+
33+
Example
34+
-----------
35+
36+
mysql> SELECT sys.ps_thread_id(79);
37+
+----------------------+
38+
| sys.ps_thread_id(79) |
39+
+----------------------+
40+
| 98 |
41+
+----------------------+
42+
1 row in set (0.00 sec)
43+
44+
mysql> SELECT sys.ps_thread_id(CONNECTION_ID());
45+
+-----------------------------------+
46+
| sys.ps_thread_id(CONNECTION_ID()) |
47+
+-----------------------------------+
48+
| 98 |
49+
+-----------------------------------+
50+
1 row in set (0.00 sec)
51+
'
52+
53+
SQL SECURITY INVOKER
54+
NOT DETERMINISTIC
55+
READS SQL DATA
56+
RETURN (SELECT THREAD_ID
57+
FROM `performance_schema`.`threads`
58+
WHERE PROCESSLIST_ID = in_connection_id
59+
)
60+
;

functions/ps_thread_stack.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ DROP FUNCTION IF EXISTS ps_thread_stack;
1818
DELIMITER $$
1919

2020
CREATE DEFINER='root'@'localhost' FUNCTION ps_thread_stack (
21-
thd_id INT,
21+
thd_id BIGINT UNSIGNED,
2222
debug BOOLEAN
2323
)
2424
RETURNS LONGTEXT CHARSET latin1
@@ -32,7 +32,7 @@ RETURNS LONGTEXT CHARSET latin1
3232
Parameters
3333
-----------
3434
35-
thd_id (BIGINT):
35+
thd_id (BIGINT UNSIGNED):
3636
The id of the thread to trace. This should match the thread_id
3737
column from the performance_schema.threads table.
3838
in_verbose (BOOLEAN):

procedures/ps_trace_statement_digest.sql

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -157,29 +157,29 @@ BEGIN
157157

158158
DROP TEMPORARY TABLE IF EXISTS stmt_trace;
159159
CREATE TEMPORARY TABLE stmt_trace (
160-
thread_id BIGINT,
161-
timer_start BIGINT,
162-
event_id BIGINT,
160+
thread_id BIGINT UNSIGNED,
161+
timer_start BIGINT UNSIGNED,
162+
event_id BIGINT UNSIGNED,
163163
sql_text longtext,
164-
timer_wait BIGINT,
165-
lock_time BIGINT,
166-
errors BIGINT,
167-
mysql_errno BIGINT,
168-
rows_sent BIGINT,
169-
rows_affected BIGINT,
170-
rows_examined BIGINT,
171-
created_tmp_tables BIGINT,
172-
created_tmp_disk_tables BIGINT,
173-
no_index_used BIGINT,
164+
timer_wait BIGINT UNSIGNED,
165+
lock_time BIGINT UNSIGNED,
166+
errors BIGINT UNSIGNED,
167+
mysql_errno INT,
168+
rows_sent BIGINT UNSIGNED,
169+
rows_affected BIGINT UNSIGNED,
170+
rows_examined BIGINT UNSIGNED,
171+
created_tmp_tables BIGINT UNSIGNED,
172+
created_tmp_disk_tables BIGINT UNSIGNED,
173+
no_index_used BIGINT UNSIGNED,
174174
PRIMARY KEY (thread_id, timer_start)
175175
);
176176

177177
DROP TEMPORARY TABLE IF EXISTS stmt_stages;
178178
CREATE TEMPORARY TABLE stmt_stages (
179-
event_id BIGINT,
180-
stmt_id BIGINT,
179+
event_id BIGINT UNSIGNED,
180+
stmt_id BIGINT UNSIGNED,
181181
event_name VARCHAR(128),
182-
timer_wait BIGINT,
182+
timer_wait BIGINT UNSIGNED,
183183
PRIMARY KEY (event_id)
184184
);
185185

procedures/ps_trace_thread.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ DROP PROCEDURE IF EXISTS ps_trace_thread;
1717

1818
DELIMITER $$
1919
CREATE DEFINER='root'@'localhost' PROCEDURE ps_trace_thread (
20-
IN in_thread_id INT,
20+
IN in_thread_id BIGINT UNSIGNED,
2121
IN in_outfile VARCHAR(255),
2222
IN in_max_runtime DECIMAL(20,2),
2323
IN in_interval DECIMAL(20,2),
@@ -39,7 +39,7 @@ CREATE DEFINER='root'@'localhost' PROCEDURE ps_trace_thread (
3939
Parameters
4040
-----------
4141
42-
in_thread_id (INT):
42+
in_thread_id (BIGINT UNSIGNED):
4343
The thread that you would like a stack trace for
4444
in_outfile (VARCHAR(255)):
4545
The filename the dot file will be written to

sys_56.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ SOURCE ./functions/format_time.sql
2424
SOURCE ./functions/ps_is_account_enabled.sql
2525
SOURCE ./functions/ps_is_instrument_default_enabled.sql
2626
SOURCE ./functions/ps_is_instrument_default_timed.sql
27+
SOURCE ./functions/ps_thread_id.sql
2728
SOURCE ./functions/ps_thread_stack.sql
2829

2930
SOURCE ./procedures/create_synonym_db.sql

sys_57.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ SOURCE ./functions/format_time.sql
2424
SOURCE ./functions/ps_is_account_enabled.sql
2525
SOURCE ./functions/ps_is_instrument_default_enabled.sql
2626
SOURCE ./functions/ps_is_instrument_default_timed.sql
27+
SOURCE ./functions/ps_thread_id.sql
2728
SOURCE ./functions/ps_thread_stack.sql
2829

2930
SOURCE ./procedures/create_synonym_db.sql

views/p_s/memory_by_user.sql

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
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
*
21-
* mysql> select * from memory_by_user_by_current_bytes WHERE user IS NOT NULL;
23+
* mysql> select * from memory_by_user_by_current_bytes;
2224
* +------+--------------------+-------------------+-------------------+-------------------+-----------------+
2325
* | user | current_count_used | current_allocated | current_avg_alloc | current_max_alloc | total_allocated |
2426
* +------+--------------------+-------------------+-------------------+-------------------+-----------------+
@@ -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,8 +56,10 @@ 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
*
58-
* mysql> select * from x$memory_by_user_by_current_bytes WHERE user IS NOT NULL;
62+
* mysql> select * from x$memory_by_user_by_current_bytes;
5963
* +------+--------------------+-------------------+-------------------+-------------------+-----------------+
6064
* | user | current_count_used | current_allocated | current_avg_alloc | current_max_alloc | total_allocated |
6165
* +------+--------------------+-------------------+-------------------+-------------------+-----------------+
@@ -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,

0 commit comments

Comments
 (0)