| 1 |
# Tests for PERFORMANCE_SCHEMA |
| 2 |
|
| 3 |
--source include/not_embedded.inc |
| 4 |
--source include/have_perfschema.inc |
| 5 |
|
| 6 |
# |
| 7 |
# Important note: |
| 8 |
# this test is extremely sensitive to how threads are running inside the server, |
| 9 |
# so it has it's own -master.opt file, to enforce it runs alone in mysqld |
| 10 |
# |
| 11 |
|
| 12 |
# Setup |
| 13 |
|
| 14 |
flush global status; |
| 15 |
|
| 16 |
SET @saved_thread_cache_size = @@global.thread_cache_size; |
| 17 |
|
| 18 |
set global thread_cache_size = 0; |
| 19 |
|
| 20 |
show global variables like "thread_cache_size"; |
| 21 |
|
| 22 |
connect (con1, localhost, root, , ); |
| 23 |
|
| 24 |
let $con1_ID=`select connection_id()`; |
| 25 |
|
| 26 |
let $con1_THREAD_ID=`select thread_id from performance_schema.threads |
| 27 |
where PROCESSLIST_ID = connection_id()`; |
| 28 |
|
| 29 |
connect (con2, localhost, root, , ); |
| 30 |
|
| 31 |
let $con2_ID=`select connection_id()`; |
| 32 |
|
| 33 |
let $con2_THREAD_ID=`select thread_id from performance_schema.threads |
| 34 |
where PROCESSLIST_ID = connection_id()`; |
| 35 |
|
| 36 |
--connection default |
| 37 |
|
| 38 |
--disable_query_log |
| 39 |
--disable_cursor_protocol |
| 40 |
eval select ($con2_ID - $con1_ID) into @id_increment; |
| 41 |
eval select ($con2_THREAD_ID - $con1_THREAD_ID) into @thread_id_increment; |
| 42 |
--enable_cursor_protocol |
| 43 |
--enable_query_log |
| 44 |
|
| 45 |
# Expect 1, connection_id() is incremented for each new connection |
| 46 |
select @id_increment; |
| 47 |
# Expect 1, THREAD_ID is incremented for each new connection |
| 48 |
select @thread_id_increment; |
| 49 |
|
| 50 |
--disconnect con2 |
| 51 |
|
| 52 |
--connection default |
| 53 |
|
| 54 |
# Debug |
| 55 |
# select * from performance_schema.threads |
| 56 |
# where name like "thread/sql/one_connection"; |
| 57 |
|
| 58 |
# Wait for the disconnect con2 to complete |
| 59 |
let $wait_condition= |
| 60 |
select count(*) = 2 from performance_schema.threads |
| 61 |
where name like "thread/sql/one_connection"; |
| 62 |
--source include/wait_condition.inc |
| 63 |
|
| 64 |
connect (con3, localhost, root, , ); |
| 65 |
|
| 66 |
let $con3_ID=`select connection_id()`; |
| 67 |
|
| 68 |
let $con3_THREAD_ID=`select thread_id from performance_schema.threads |
| 69 |
where PROCESSLIST_ID = connection_id()`; |
| 70 |
|
| 71 |
--disconnect con3 |
| 72 |
--disconnect con1 |
| 73 |
|
| 74 |
--connection default |
| 75 |
|
| 76 |
# Debug |
| 77 |
# select * from performance_schema.threads |
| 78 |
# where name like "thread/sql/one_connection"; |
| 79 |
|
| 80 |
# Wait for the disconnect con1 and con3 to complete |
| 81 |
let $wait_condition= |
| 82 |
select count(*) = 1 from performance_schema.threads |
| 83 |
where name like "thread/sql/one_connection"; |
| 84 |
--source include/wait_condition.inc |
| 85 |
|
| 86 |
--disable_query_log |
| 87 |
--disable_cursor_protocol |
| 88 |
eval select ($con3_ID - $con2_ID) into @id_increment; |
| 89 |
eval select ($con3_THREAD_ID - $con2_THREAD_ID) into @thread_id_increment; |
| 90 |
--enable_cursor_protocol |
| 91 |
--enable_query_log |
| 92 |
|
| 93 |
select @id_increment; |
| 94 |
select @thread_id_increment; |
| 95 |
|
| 96 |
set global thread_cache_size = 100; |
| 97 |
|
| 98 |
show global variables like "thread_cache_size"; |
| 99 |
|
| 100 |
connect (con1, localhost, root, , ); |
| 101 |
|
| 102 |
let $con1_ID=`select connection_id()`; |
| 103 |
|
| 104 |
let $con1_THREAD_ID=`select thread_id from performance_schema.threads |
| 105 |
where PROCESSLIST_ID = connection_id()`; |
| 106 |
|
| 107 |
connect (con2, localhost, root, , ); |
| 108 |
|
| 109 |
let $con2_ID=`select connection_id()`; |
| 110 |
|
| 111 |
let $con2_THREAD_ID=`select thread_id from performance_schema.threads |
| 112 |
where PROCESSLIST_ID = connection_id()`; |
| 113 |
|
| 114 |
--connection default |
| 115 |
|
| 116 |
--disable_query_log |
| 117 |
--disable_cursor_protocol |
| 118 |
eval select ($con2_ID - $con1_ID) into @id_increment; |
| 119 |
eval select ($con2_THREAD_ID - $con1_THREAD_ID) into @thread_id_increment; |
| 120 |
--enable_cursor_protocol |
| 121 |
--enable_query_log |
| 122 |
|
| 123 |
select @id_increment; |
| 124 |
select @thread_id_increment; |
| 125 |
|
| 126 |
--disconnect con2 |
| 127 |
|
| 128 |
--connection default |
| 129 |
|
| 130 |
# Debug |
| 131 |
# select * from performance_schema.threads |
| 132 |
# where name like "thread/sql/one_connection"; |
| 133 |
|
| 134 |
# Wait for the disconnect con2 to complete |
| 135 |
let $wait_condition= |
| 136 |
select count(*) = 2 from performance_schema.threads |
| 137 |
where name like "thread/sql/one_connection"; |
| 138 |
--source include/wait_condition.inc |
| 139 |
|
| 140 |
connect (con3, localhost, root, , ); |
| 141 |
|
| 142 |
let $con3_ID=`select connection_id()`; |
| 143 |
|
| 144 |
let $con3_THREAD_ID=`select thread_id from performance_schema.threads |
| 145 |
where PROCESSLIST_ID = connection_id()`; |
| 146 |
|
| 147 |
--disconnect con3 |
| 148 |
--disconnect con1 |
| 149 |
|
| 150 |
--connection default |
| 151 |
|
| 152 |
# Debug |
| 153 |
# select * from performance_schema.threads |
| 154 |
# where name like "thread/sql/one_connection"; |
| 155 |
|
| 156 |
# Wait for the disconnect con1 and con3 to complete |
| 157 |
let $wait_condition= |
| 158 |
select count(*) = 1 from performance_schema.threads |
| 159 |
where name like "thread/sql/one_connection"; |
| 160 |
--source include/wait_condition.inc |
| 161 |
|
| 162 |
--disable_query_log |
| 163 |
--disable_cursor_protocol |
| 164 |
eval select ($con3_ID - $con2_ID) into @id_increment; |
| 165 |
eval select ($con3_THREAD_ID - $con2_THREAD_ID) into @thread_id_increment; |
| 166 |
--enable_cursor_protocol |
| 167 |
--enable_query_log |
| 168 |
|
| 169 |
# When caching threads, the pthread that executed con2 was parked in the |
| 170 |
# cache on disconnect, and then picked up con3. |
| 171 |
|
| 172 |
# Still expect a new connection_id() |
| 173 |
select @id_increment; |
| 174 |
|
| 175 |
# And expect a new instrumentation: the THREAD_ID of old connections should not be reused. |
| 176 |
select @thread_id_increment; |
| 177 |
|
| 178 |
set global thread_cache_size = @saved_thread_cache_size; |
| 179 |
|
| 180 |
show global status like "performance_schema_thread%"; |
| 181 |
|