1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
#
# Tests for the Performance Schema native functions ps_thread_id()
# and ps_current_thread_id()
# 'connection ID' is the MySQL server processlist ID
# 'thread ID' is the Performance Schema thread ID assigned to the connection ID
USE test;
# Get the connection ID of this connection
SELECT connection_id() INTO @cid;
# Get the thread ID for this connection
SELECT thread_id FROM performance_schema.threads
WHERE PROCESSLIST_ID = @cid INTO @tid;
# Open another connection, get the connection ID
# Get the thread ID for the remote thread
SELECT thread_id FROM performance_schema.threads
WHERE PROCESSLIST_ID = @cid_1 INTO @tid_1;
# Verify that the remote thread IDs are different
SELECT @cid <> @cid_1 AS "Expect 1";
Expect 1
1
SELECT @tid <> @tid_1 AS "Expect 1";
Expect 1
1
# Returns the current thread ID
SELECT ps_current_thread_id() - @tid AS "Expect 0";
Expect 0
0
# Bad parameter count
SELECT ps_current_thread_id(1);
ERROR 42000: Incorrect parameter count in the call to native function 'ps_current_thread_id'
# A NULL connection ID returns NULL
SELECT ps_thread_id(NULL) AS "Expect NULL";
Expect NULL
NULL
# The current connection ID returns the current thread ID
SELECT ps_thread_id(@cid) - @tid AS "Expect 0";
Expect 0
0
# Another connection ID returns the corresponding thread ID
SELECT ps_thread_id(@cid_1) - @tid_1 AS "Expect 0";
Expect 0
0
# Hybrid parameter
SELECT ps_thread_id(@cid + 0) - @tid AS "Expect 0";
Expect 0
0
# Return NULL if connection ID not found
SELECT ps_thread_id(9999999) AS "Expect NULL";
Expect NULL
NULL
# Return NULL if bad parameter
SELECT ps_thread_id("foo") AS "Expect NULL";
Expect NULL
NULL
Warnings:
Warning 1292 Truncated incorrect INTEGER value: 'foo'
# Return NULL if negative number
SELECT ps_thread_id(-1) AS "Expect NULL";
Expect NULL
NULL
# Error if bad parameter count
SELECT ps_thread_id(1, 2);
ERROR 42000: Incorrect parameter count in the call to native function 'ps_thread_id'
# Error if bad parameter count
SELECT ps_thread_id();
ERROR 42000: Incorrect parameter count in the call to native function 'ps_thread_id'
# Name collision warning
USE test;
CREATE FUNCTION ps_current_thread_id() RETURNS varchar(100) return "This is function ps_current_thread_id()";
Warnings:
Note 1585 This function 'ps_current_thread_id' has the same name as a native function
SHOW WARNINGS;
Level Code Message
Note 1585 This function 'ps_current_thread_id' has the same name as a native function
CREATE FUNCTION ps_thread_id() RETURNS varchar(100) return "This is a function ps_thread_id()";
Warnings:
Note 1585 This function 'ps_thread_id' has the same name as a native function
SHOW WARNINGS;
Level Code Message
Note 1585 This function 'ps_thread_id' has the same name as a native function
# Local function should work ok
SELECT test.ps_current_thread_id();
test.ps_current_thread_id()
This is function ps_current_thread_id()
Warnings:
Note 1585 This function 'ps_current_thread_id' has the same name as a native function
SELECT test.ps_thread_id();
test.ps_thread_id()
This is a function ps_thread_id()
Warnings:
Note 1585 This function 'ps_thread_id' has the same name as a native function
# Global function should still work
SELECT ps_current_thread_id() - @tid AS "Expect 0";
Expect 0
0
SELECT ps_current_thread_id() - @tid AS "Expect 0";
Expect 0
0
# Cleanup
DROP FUNCTION test.ps_current_thread_id;
DROP FUNCTION test.ps_thread_id;
## Handling of NULL (bug#30525561)
SELECT PS_CURRENT_THREAD_ID() into @this_tid;
SELECT CONNECTION_ID() into @this_cid;
SELECT PS_THREAD_ID(my_cid) = @this_tid AS PS_TID_CHECK,
sys.ps_thread_id(my_cid) = @this_tid AS SYS_TID_CHECK
FROM (SELECT @this_cid AS my_cid
UNION ALL
SELECT CAST(1234567890 AS UNSIGNED)
UNION ALL
SELECT NULL
UNION ALL
SELECT @this_cid
UNION ALL
SELECT CAST(1234567890 AS UNSIGNED)
) t;
PS_TID_CHECK SYS_TID_CHECK
1 1
1 1
NULL 1
1 1
1 1
Warnings:
Note 1585 This function 'ps_thread_id' has the same name as a native function
|