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