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

Commit 9407008

Browse files
committed
Merge pull request #19 from JesperWisborgKrogh/dev/ps_thread_id
ps_thread_id()
2 parents 5085287 + 671bb21 commit 9407008

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,39 @@ mysql> SELECT sys.ps_is_account_enabled('localhost', 'root');
14241424
1 row in set (0.01 sec)
14251425
```
14261426

1427+
#### ps_thread_id
1428+
1429+
##### Description
1430+
1431+
Return the Performance Schema THREAD_ID for the specified connection ID.
1432+
1433+
##### Parameters
1434+
1435+
* in_connection_id (BIGINT UNSIGNED): The id of the connection to return the thread id for.
1436+
1437+
##### Returns
1438+
1439+
BIGINT UNSIGNED
1440+
1441+
##### Example
1442+
```SQL
1443+
mysql> SELECT sys.ps_thread_id(79);
1444+
+----------------------+
1445+
| sys.ps_thread_id(79) |
1446+
+----------------------+
1447+
| 98 |
1448+
+----------------------+
1449+
1 row in set (0.00 sec)
1450+
1451+
mysql> SELECT sys.ps_thread_id(CONNECTION_ID());
1452+
+-----------------------------------+
1453+
| sys.ps_thread_id(CONNECTION_ID()) |
1454+
+-----------------------------------+
1455+
| 98 |
1456+
+-----------------------------------+
1457+
1 row in set (0.00 sec)
1458+
```
1459+
14271460
#### ps_thread_stack
14281461

14291462
##### Description

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+
;

sys_56.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ SOURCE ./functions/format_path.sql
2222
SOURCE ./functions/format_statement.sql
2323
SOURCE ./functions/format_time.sql
2424
SOURCE ./functions/ps_is_account_enabled.sql
25+
SOURCE ./functions/ps_thread_id.sql
2526
SOURCE ./functions/ps_thread_stack.sql
2627

2728
SOURCE ./procedures/create_synonym_db.sql

sys_57.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ SOURCE ./functions/format_path.sql
2222
SOURCE ./functions/format_statement.sql
2323
SOURCE ./functions/format_time.sql
2424
SOURCE ./functions/ps_is_account_enabled.sql
25+
SOURCE ./functions/ps_thread_id.sql
2526
SOURCE ./functions/ps_thread_stack.sql
2627

2728
SOURCE ./procedures/create_synonym_db.sql

0 commit comments

Comments
 (0)