summaryrefslogtreecommitdiff
path: root/mysql-test/suite/perfschema/t/thread_cache.test
blob: e839552ed19734ce9da1bd1021a5e645ffeabaea (plain)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA

# Tests for PERFORMANCE_SCHEMA

--source include/not_embedded.inc
--source include/have_perfschema.inc

# Setup

flush status;

SET @saved_thread_cache_size = @@global.thread_cache_size;

set global thread_cache_size = 0;

show variables like "thread_cache_size";

connect (con1, localhost, root, , );

let $con1_ID=`select connection_id()`;

let $con1_THREAD_ID=`select thread_id from performance_schema.threads
  where PROCESSLIST_ID = connection_id()`;

connect (con2, localhost, root, , );

let $con2_ID=`select connection_id()`;

let $con2_THREAD_ID=`select thread_id from performance_schema.threads
  where PROCESSLIST_ID = connection_id()`;

--connection default

--disable_query_log
eval select ($con2_ID - $con1_ID) into @id_increment;
eval select ($con2_THREAD_ID - $con1_THREAD_ID) into @thread_id_increment;
--enable_query_log

# Expect 1, connection_id() is incremented for each new connection
select @id_increment;
# Expect 1, THREAD_ID is incremented for each new connection
select @thread_id_increment;

--disconnect con2

--connection default

# Wait for the disconnect con2 to complete
let $wait_condition=
  select count(*) = 2 from performance_schema.threads
  where name like "thread/sql/one_connection";
--source include/wait_condition.inc

connect (con3, localhost, root, , );

let $con3_ID=`select connection_id()`;

let $con3_THREAD_ID=`select thread_id from performance_schema.threads
  where PROCESSLIST_ID = connection_id()`;

--disconnect con3
--disconnect con1

--connection default

# Wait for the disconnect con1 and con3 to complete
let $wait_condition=
  select count(*) = 1 from performance_schema.threads
  where name like "thread/sql/one_connection";
--source include/wait_condition.inc

--disable_query_log
eval select ($con3_ID - $con2_ID) into @id_increment;
eval select ($con3_THREAD_ID - $con2_THREAD_ID) into @thread_id_increment;
--enable_query_log

select @id_increment;
select @thread_id_increment;

set global thread_cache_size = 100;

show variables like "thread_cache_size";

connect (con1, localhost, root, , );

let $con1_ID=`select connection_id()`;

let $con1_THREAD_ID=`select thread_id from performance_schema.threads
  where PROCESSLIST_ID = connection_id()`;

connect (con2, localhost, root, , );

let $con2_ID=`select connection_id()`;

let $con2_THREAD_ID=`select thread_id from performance_schema.threads
  where PROCESSLIST_ID = connection_id()`;

--connection default

--disable_query_log
eval select ($con2_ID - $con1_ID) into @id_increment;
eval select ($con2_THREAD_ID - $con1_THREAD_ID) into @thread_id_increment;
--enable_query_log

select @id_increment;
select @thread_id_increment;

--disconnect con2

--connection default

# Wait for the disconnect con2 to complete
let $wait_condition=
  select count(*) = 2 from performance_schema.threads
  where name like "thread/sql/one_connection";
--source include/wait_condition.inc

connect (con3, localhost, root, , );

let $con3_ID=`select connection_id()`;

let $con3_THREAD_ID=`select thread_id from performance_schema.threads
  where PROCESSLIST_ID = connection_id()`;

--disconnect con3
--disconnect con1

--connection default

# Wait for the disconnect con1 and con3 to complete
let $wait_condition=
  select count(*) = 1 from performance_schema.threads
  where name like "thread/sql/one_connection";
--source include/wait_condition.inc

--disable_query_log
eval select ($con3_ID - $con2_ID) into @id_increment;
eval select ($con3_THREAD_ID - $con2_THREAD_ID) into @thread_id_increment;
--enable_query_log

# When caching threads, the pthread that executed con2 was parked in the
# cache on disconnect, and then picked up con3.

# Still expect a new connection_id()
select @id_increment;

# And expect a new instrumentation: the THREAD_ID of old connections should not be reused.
select @thread_id_increment;

set global thread_cache_size = @saved_thread_cache_size;

show status like "performance_schema_thread%";