Bug #115513 DML with Online DDL cause a deadlock which is not logged anywhere
Submitted: 4 Jul 2024 12:49 Modified: 4 Jul 2024 12:55
Reporter: Yunus UYANIK Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.6, 5.7, 8.0.37 OS:Any
Assigned to: CPU Architecture:Any
Tags: DML, DML, online ddl cause deadlock

[4 Jul 2024 12:49] Yunus UYANIK
Description:
Online DDLs support DML statements, but apparently, if there is any SELECT statement before that, MySQL threw a deadlock. I tested in many versions, 5.6,5.7, and even 8.0.37, and all behavior is the same. I couldn't find any documents to explain this behavior.

Also, the deadlock is not logging anywhere. I enabled innodb_print_all_deadlocks and also checked the SHOW ENGINE INNODB STATUS;
 

How to repeat:
session1:
mysql [localhost:8037] {msandbox} ((none)) > begin;
Query OK, 0 rows affected (0.00 sec)

mysql [localhost:8037] {msandbox} ((none)) > select count(1) from test.t3;
+----------+
| count(1) |
+----------+
|   100000 |
+----------+
1 row in set (0.01 sec)

session2:
mysql [localhost:8037] {msandbox} ((none)) > alter table test.t3 add column d varchar(100), ALGORITHM=INPLACE;

session1:
mysql [localhost:8037] {msandbox} ((none)) > update test.t3 set tcol01=10 where tcol2=136;
ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction

session2:
mysql [localhost:8037] {msandbox} ((none)) > alter table test.t3 add column d varchar(100), ALGORITHM=INPLACE;
Query OK, 0 rows affected (13.52 sec)
Records: 0  Duplicates: 0  Warnings: 0

Here is the output SHOW ENGINE INNODB STATUS;

mysql [localhost:8037] {msandbox} ((none)) > SHOW ENGINE INNODB STATUS\G
*************************** 1. row ***************************
  Type: InnoDB
  Name:
Status:
=====================================
2024-07-04 12:47:20 139963925579520 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 8 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 136 srv_active, 0 srv_shutdown, 3599 srv_idle
srv_master_thread log flush and writes: 0
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 135
OS WAIT ARRAY INFO: signal count 127
RW-shared spins 0, rounds 0, OS waits 0
RW-excl spins 0, rounds 0, OS waits 0
RW-sx spins 0, rounds 0, OS waits 0
Spin rounds per wait: 0.00 RW-shared, 0.00 RW-excl, 0.00 RW-sx
------------
TRANSACTIONS
------------
Trx id counter 1572
Purge done for trx's n:o < 1571 undo n:o < 0 state: running but idle
History list length 0
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 421439378787544, not started
0 lock struct(s), heap size 1128, 0 row lock(s)
---TRANSACTION 421439378788352, not started
0 lock struct(s), heap size 1128, 0 row lock(s)
---TRANSACTION 421439378786736, not started
0 lock struct(s), heap size 1128, 0 row lock(s)
---TRANSACTION 421439378785928, not started
0 lock struct(s), heap size 1128, 0 row lock(s)
[4 Jul 2024 12:55] MySQL Verification Team
HI Mr. UYANIK,

Thank you for your bug report.

However this is not a bug.

Simply, this is not an InnoDB deadlock, this is a metadata deadlock.

Hence, InnoDB has nothing to report. This is expected behaviour.

This is all explained in our Reference Manual.

Not a bug.
[30 Dec 2024 21:54] Sveta Smirnova
Dear Bugs Verification Team,

I believe the reporter missed a very important detail when creating this feature request. We need a way to see past MDL deadlocks and what is causing them. Table METADATA_LOCKS does not help here, because once the transaction is finished, it is gone from this table. We need something similar to the InnoDB deadlock logger.

Please reconsider this report type and status.