File: native_func_thread_id.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (142 lines) | stat: -rw-r--r-- 3,543 bytes parent folder | download
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
--echo #
--echo # Tests for the Performance Schema native functions ps_thread_id()
--echo # and ps_current_thread_id()
--echo
--echo # 'connection ID' is the MySQL server processlist ID
--echo # 'thread ID' is the Performance Schema thread ID assigned to the connection ID
--echo

--echo
USE test;

--echo # Get the connection ID of this connection
SELECT connection_id() INTO @cid;

--echo
--echo # Get the thread ID for this connection
SELECT thread_id FROM performance_schema.threads
  WHERE PROCESSLIST_ID = @cid INTO @tid;

--echo
--echo # Open another connection, get the connection ID
connect(con1, localhost, root,,);
let $con1_id = `SELECT connection_id()`;
# debug eval SELECT $con1_id;

--connection default
--echo
--disable_query_log
eval SELECT $con1_id INTO @cid_1;
--enable_query_log

--echo
--echo # Get the thread ID for the remote thread
SELECT thread_id FROM performance_schema.threads
  WHERE PROCESSLIST_ID = @cid_1 INTO @tid_1;

--echo
--echo # Verify that the remote thread IDs are different
SELECT @cid <> @cid_1 AS "Expect 1";
SELECT @tid <> @tid_1 AS "Expect 1";

## ps_current_thread_id()

--echo
--echo # Returns the current thread ID
SELECT ps_current_thread_id() - @tid AS "Expect 0";

--echo
--echo # Bad parameter count
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
SELECT ps_current_thread_id(1);

## ps_thread_id()

--echo
--echo # A NULL connection ID returns NULL
SELECT ps_thread_id(NULL) AS "Expect NULL";

--echo
--echo # The current connection ID returns the current thread ID
SELECT ps_thread_id(@cid) - @tid AS "Expect 0";

--echo
--echo # Another connection ID returns the corresponding thread ID
SELECT ps_thread_id(@cid_1) - @tid_1 AS "Expect 0";

--echo
--echo # Hybrid parameter
SELECT ps_thread_id(@cid + 0) - @tid AS "Expect 0";

--echo
--echo # Return NULL if connection ID not found
SELECT ps_thread_id(9999999) AS "Expect NULL";

--echo
--echo # Return NULL if bad parameter
SELECT ps_thread_id("foo") AS "Expect NULL";

--echo
--echo # Return NULL if negative number
SELECT ps_thread_id(-1) AS "Expect NULL";

--echo
--echo # Error if bad parameter count
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
SELECT ps_thread_id(1, 2);

--echo
--echo # Error if bad parameter count
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
SELECT ps_thread_id();


## Name collisions

--echo
--echo # Name collision warning
#--warning ER_NATIVE_FCT_NAME_COLLISION
USE test;
CREATE FUNCTION ps_current_thread_id() RETURNS varchar(100) return "This is function ps_current_thread_id()";
--echo
SHOW WARNINGS;
--echo
CREATE FUNCTION ps_thread_id() RETURNS varchar(100) return "This is a function ps_thread_id()";
--echo
SHOW WARNINGS;

--echo
--echo # Local function should work ok
SELECT test.ps_current_thread_id();
SELECT test.ps_thread_id();

--echo
--echo # Global function should still work
SELECT ps_current_thread_id() - @tid AS "Expect 0";
SELECT ps_current_thread_id() - @tid AS "Expect 0";

--echo
--echo # Cleanup
DROP FUNCTION test.ps_current_thread_id;
DROP FUNCTION test.ps_thread_id;
--disconnect con1

--echo
--echo ## 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;