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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
|
# Performance schema tests generally depend on specific query plans
# and behavior, and much of the perfschema suite is therefore disabled
# if the hypergraph optimizer is active.
--source include/not_hypergraph.inc
# Tests for PERFORMANCE_SCHEMA
show create table performance_schema.data_lock_waits;
# Debug
let $debug_script = 0;
#setup
let $select_column = COUNT(*);
let $table = performance_schema.data_lock_waits;
connect(con1, localhost, root,,);
--echo # Connection con1
--connection con1
create database explain_test_db;
create table explain_test_db.explain_test_table(a int, b int, PRIMARY KEY (a, b)) engine=innodb
PARTITION BY RANGE( a )
SUBPARTITION BY HASH( b ) (
PARTITION p0 VALUES LESS THAN (1990) (
SUBPARTITION s0,
SUBPARTITION s1
),
PARTITION p1 VALUES LESS THAN (2000) (
SUBPARTITION s2,
SUBPARTITION s3
),
PARTITION p2 VALUES LESS THAN MAXVALUE (
SUBPARTITION s4,
SUBPARTITION s5
)
);
insert into explain_test_db.explain_test_table values (1, 100), (1995, 200);
start transaction;
select * from explain_test_db.explain_test_table where a <= 1990 for update;
connect(con2, localhost, root,,);
--echo # Connection con2
--connection con2
start transaction;
--send
insert into explain_test_db.explain_test_table values (2, 150), (1998, 250);
--echo # Connection default
--connection default
# Wait for con2 to block
-- connection default
let $wait_condition= SELECT COUNT(*)>=1 FROM performance_schema.data_locks
where OBJECT_NAME='explain_test_table' and LOCK_STATUS='WAITING';
--source include/wait_condition.inc
connect(con3, localhost, root,,);
--echo # Connection con3
--connection con3
create table explain_test_db.noise_table(a int, b int, PRIMARY KEY (a, b)) engine=innodb;
insert into explain_test_db.noise_table
values (1, 100), (2, 200), (3, 300), (5, 500);
start transaction;
select * from explain_test_db.noise_table where a >= 2 for update;
connect(con4, localhost, root,,);
--echo # Connection con4
--connection con4
start transaction;
--send
insert into explain_test_db.noise_table values (4, 400);
--connection default
# Wait for con4 to block
-- connection default
let $wait_condition= SELECT COUNT(*)>=1 FROM performance_schema.data_locks
where OBJECT_NAME='noise_table' and LOCK_STATUS='WAITING';
--source include/wait_condition.inc
if (!$success)
{
# wait_condition failed, dumping data for debug
select * from performance_schema.threads;
select * from performance_schema.data_locks;
select * from performance_schema.data_lock_waits;
}
IF ($debug_script == 1)
{
select * from performance_schema.data_locks;
select * from performance_schema.data_lock_waits;
}
# Make sure there are enough records for the test to be valid
select count(*) >= 2 from performance_schema.data_lock_waits;
# Find requesting data lock on hold
select ENGINE, ENGINE_LOCK_ID, ENGINE_TRANSACTION_ID, THREAD_ID, EVENT_ID
from performance_schema.data_locks
where OBJECT_NAME='explain_test_table' and LOCK_STATUS='WAITING'
into @engine, @requesting_lock_id, @requesting_trx_id,
@requesting_thread_id, @requesting_event_id;
# Find blocking data lock
# use upper(ENGINE) to prevent the optimizer from using an index
select
BLOCKING_ENGINE_LOCK_ID,
BLOCKING_ENGINE_TRANSACTION_ID,
BLOCKING_THREAD_ID,
BLOCKING_EVENT_ID
from performance_schema.data_lock_waits
where (upper(ENGINE) = upper(@engine))
and (REQUESTING_ENGINE_LOCK_ID = @requesting_lock_id)
into @blocking_lock_id, @blocking_trx_id, @blocking_thread_id, @blocking_event_id;
IF ($debug_script == 1)
{
select @engine,
@requesting_lock_id,
@requesting_trx_id,
@requesting_thread_id,
@requesting_event_id,
@blocking_lock_id,
@blocking_trx_id,
@blocking_thread_id,
@blocking_event_id;
}
# Make sure this test found a record.
select @engine,
@requesting_lock_id is null,
@requesting_trx_id is null,
@requesting_thread_id is null,
@requesting_event_id is null,
@blocking_lock_id is null,
@blocking_trx_id is null,
@blocking_thread_id is null,
@blocking_event_id is null;
###########################################################################
# Test index on REQUESTING_ENGINE_LOCK_ID, BLOCKING_ENGINE_LOCK_ID, ENGINE
###########################################################################
let $table = performance_schema.data_lock_waits;
let $column_count = 3;
let $col1 = REQUESTING_ENGINE_LOCK_ID;
let $col2 = BLOCKING_ENGINE_LOCK_ID;
let $col3 = ENGINE;
let $col1_act = @requesting_lock_id;
let $col2_act = @blocking_lock_id;
let $col3_act = @engine;
--source ../include/idx_explain_test.inc
# verify actual data
select BLOCKING_ENGINE_LOCK_ID = @blocking_lock_id,
REQUESTING_ENGINE_LOCK_ID = @requesting_lock_id,
ENGINE = @engine
from performance_schema.data_lock_waits
where (ENGINE = @engine)
and (REQUESTING_ENGINE_LOCK_ID = @requesting_lock_id)
and (BLOCKING_ENGINE_LOCK_ID = @blocking_lock_id);
###########################################################################
# Test index on REQUESTING_ENGINE_LOCK_ID, ENGINE
###########################################################################
let $table = performance_schema.data_lock_waits;
let $column_count = 2;
let $col1 = REQUESTING_ENGINE_LOCK_ID;
let $col2 = ENGINE;
let $col1_act = @requesting_lock_id;
let $col2_act = @engine;
--source ../include/idx_explain_test.inc
# verify actual data
select BLOCKING_ENGINE_LOCK_ID = @blocking_lock_id
from performance_schema.data_lock_waits
where (ENGINE = @engine)
and (REQUESTING_ENGINE_LOCK_ID = @requesting_lock_id);
###########################################################################
# Test index on BLOCKING_ENGINE_LOCK_ID, ENGINE
###########################################################################
let $table = performance_schema.data_lock_waits;
let $column_count = 2;
let $col1 = BLOCKING_ENGINE_LOCK_ID;
let $col2 = ENGINE;
let $col1_act = @blocking_lock_id;
let $col2_act = @engine;
--source ../include/idx_explain_test.inc
# verify actual data
select REQUESTING_ENGINE_LOCK_ID = @requesting_lock_id
from performance_schema.data_lock_waits
where (ENGINE = @engine)
and (BLOCKING_ENGINE_LOCK_ID = @blocking_lock_id);
###########################################################################
# Test index on REQUESTING_ENGINE_TRANSACTION_ID, ENGINE
###########################################################################
let $table = performance_schema.data_lock_waits;
let $column_count = 2;
let $col1 = REQUESTING_ENGINE_TRANSACTION_ID;
let $col2 = ENGINE;
let $col1_act = @requesting_trx_id;
let $col2_act = @engine;
--source ../include/idx_explain_test.inc
# verify actual data
select BLOCKING_ENGINE_LOCK_ID = @blocking_lock_id
from performance_schema.data_lock_waits
where (ENGINE = @engine)
and (REQUESTING_ENGINE_TRANSACTION_ID = @requesting_trx_id);
###########################################################################
# Test index on BLOCKING_ENGINE_TRANSACTION_ID, ENGINE
###########################################################################
let $table = performance_schema.data_lock_waits;
let $column_count = 2;
let $col1 = BLOCKING_ENGINE_TRANSACTION_ID;
let $col2 = ENGINE;
let $col1_act = @blocking_trx_id;
let $col2_act = @engine;
--source ../include/idx_explain_test.inc
# verify actual data
select REQUESTING_ENGINE_LOCK_ID = @requesting_lock_id
from performance_schema.data_lock_waits
where (ENGINE = @engine)
and (BLOCKING_ENGINE_TRANSACTION_ID = @blocking_trx_id);
###########################################################################
# Test index on REQUESTING_THREAD_ID, REQUESTING_EVENT_ID
###########################################################################
let $table = performance_schema.data_lock_waits force index(REQUESTING_THREAD_ID);
let $column_count = 2;
let $col1 = REQUESTING_THREAD_ID;
let $col2 = REQUESTING_EVENT_ID;
let $col1_act = @requesting_thread_id;
let $col2_act = @requesting_event_id;
--source ../include/idx_explain_test.inc
# verify actual data
select BLOCKING_ENGINE_LOCK_ID = @blocking_lock_id
from performance_schema.data_lock_waits
where (REQUESTING_THREAD_ID = @requesting_thread_id)
and (REQUESTING_EVENT_ID = @requesting_event_id);
###########################################################################
# Test index on BLOCKING_THREAD_ID, BLOCKING_EVENT_ID
###########################################################################
let $table = performance_schema.data_lock_waits force index(BLOCKING_THREAD_ID);
let $column_count = 2;
let $col1 = BLOCKING_THREAD_ID;
let $col2 = BLOCKING_EVENT_ID;
let $col1_act = @blocking_thread_id;
let $col2_act = @blocking_event_id;
--source ../include/idx_explain_test.inc
# verify actual data
select REQUESTING_ENGINE_LOCK_ID = @requesting_lock_id
from performance_schema.data_lock_waits
where (BLOCKING_THREAD_ID = @blocking_thread_id)
and (BLOCKING_EVENT_ID = @blocking_event_id);
# Cleanup
--echo # Connection con1
--connection con1
commit;
--echo # Connection con2
--connection con2
--reap
commit;
--echo # Connection con3
--connection con3
commit;
--echo # Connection con4
--connection con4
--reap
commit;
--echo # Connection default
--connection default
drop table explain_test_db.explain_test_table;
drop database explain_test_db;
--disconnect con1
--disconnect con2
--disconnect con3
--disconnect con4
|