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

Commit abfb2db

Browse files
committed
Make the ps_is_thread_instrumented return UNKNOWN when the connection id can not be found
1 parent 619b19d commit abfb2db

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3290,7 +3290,7 @@ Checks whether the provided connection id is instrumented within Performance Sch
32903290

32913291
##### Returns
32923292

3293-
ENUM('YES', 'NO')
3293+
ENUM('YES', 'NO', 'UNKNOWN')
32943294

32953295
##### Example
32963296
```SQL

functions/ps_is_thread_instrumented.sql

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ DELIMITER $$
1919

2020
CREATE DEFINER='root'@'localhost' FUNCTION ps_is_thread_instrumented (
2121
in_connection_id BIGINT UNSIGNED
22-
) RETURNS ENUM('YES', 'NO')
22+
) RETURNS ENUM('YES', 'NO', 'UNKNOWN')
2323
COMMENT '
2424
Description
2525
-----------
@@ -35,7 +35,7 @@ CREATE DEFINER='root'@'localhost' FUNCTION ps_is_thread_instrumented (
3535
Returns
3636
-----------
3737
38-
ENUM(\'YES\', \'NO\')
38+
ENUM(\'YES\', \'NO\', \'UNKNOWN\')
3939
4040
Example
4141
-----------
@@ -52,13 +52,21 @@ CREATE DEFINER='root'@'localhost' FUNCTION ps_is_thread_instrumented (
5252
NOT DETERMINISTIC
5353
READS SQL DATA
5454
BEGIN
55-
DECLARE v_enabled ENUM('YES', 'NO');
55+
DECLARE v_enabled ENUM('YES', 'NO', 'UNKNOWN');
56+
57+
IF (in_connection_id IS NULL) THEN
58+
RETURN NULL;
59+
END IF;
5660

5761
SELECT INSTRUMENTED INTO v_enabled
5862
FROM performance_schema.threads
5963
WHERE PROCESSLIST_ID = in_connection_id;
6064

61-
RETURN v_enabled;
65+
IF (v_enabled IS NULL) THEN
66+
RETURN 'UNKNOWN';
67+
ELSE
68+
RETURN v_enabled;
69+
END IF;
6270
END$$
6371

6472
DELIMITER ;

0 commit comments

Comments
 (0)