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