Bug #116659 p_s.metadata_locks displaying the wrong LOCK_TYPE after upgrade_shared_lock
Submitted: 14 Nov 2024 13:04 Modified: 15 Nov 2024 10:59
Reporter: zongyi chen Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Performance Schema Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: Marc ALFF CPU Architecture:Any

[14 Nov 2024 13:04] zongyi chen
Description:
in algorithm = instant or copy,ddl will upgrade_shared_lock from SHARED_UPGRADABLE to EXCLUSIVE.but in performance_schema.metadata_locks also display origin LOCK_TYPE.

To make it a better reappearance, add debug_sync after upgrade_shared_lock

diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 4a88abb..b718a1b 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -13540,6 +13540,8 @@ static bool mysql_inplace_alter_table(
     if (wait_while_table_is_used(thd, table, HA_EXTRA_PREPARE_FOR_RENAME))
       goto rollback;
 
+    DEBUG_SYNC(current_thd, "after_lock_upgrade");
+
     if (collect_and_lock_fk_tables_for_complex_alter_table(
             thd, table_list, table_def, alter_ctx, alter_info, db_type, db_type,
             fk_invalidator))
@@ -18098,6 +18100,10 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name,
     goto err_with_mdl; /* purecov: deadcode */
   }

-- session 1
use test;
drop table t1;
CREATE TABLE t1 (a int); 
set debug_sync = 'after_lock_upgrade wait_for go';
alter table t1 add column b int;

-- session 2
select OBJECT_TYPE, OBJECT_SCHEMA, OBJECT_NAME, LOCK_TYPE, LOCK_DURATION from performance_schema.metadata_locks where object_schema='test' and OBJECT_NAME='t1';
+-------------------+---------------+-------------+-------------------+---------------+
| OBJECT_TYPE       | OBJECT_SCHEMA | OBJECT_NAME | LOCK_TYPE         | LOCK_DURATION |
+-------------------+---------------+-------------+-------------------+---------------+
| COLUMN STATISTICS | test          | t1          | SHARED_READ       | STATEMENT     |
| TABLE             | test          | t1          | SHARED_UPGRADABLE | TRANSACTION   |
+-------------------+---------------+-------------+-------------------+---------------+

the second row's LOCK_TYPE has been upgrade to EXCLUSIVE, but show SHARED_UPGRADABLE.

How to repeat:

As described above
[14 Nov 2024 13:33] MySQL Verification Team
Hi Mr. chen,

Thank you for your bug report.

We have added your patch to our debug build of the MySQ server 8.0.40 and we have repeated your results.

This is now a verified bug report for version 8.0 and higher.
[15 Nov 2024 10:59] Marc ALFF
Closing as a duplicate of:

Bug #116625 	The LOCK_TYPE in PFS.metadata_locks not change after MDL upgrade or downgrade
[15 Nov 2024 11:06] MySQL Verification Team
Thank you, Mark.