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

Commit 65f0731

Browse files
Adding the function ps_thread_id() which returns the Performance Schema thread id for the connection id passed as an argument
1 parent 3d6eaca commit 65f0731

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

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

0 commit comments

Comments
 (0)