[MDEV-5826] EXPLAIN acquires metadata locks Created: 2014-03-11  Updated: 2014-09-08  Resolved: 2014-09-08

Status: Closed
Project: MariaDB Server
Component/s: None
Affects Version/s: N/A
Fix Version/s: 10.0.14

Type: Bug Priority: Minor
Reporter: Federico Razzoli Assignee: Ian Gilfillan
Resolution: Fixed Votes: 0
Labels: documentation


 Description   

In the following test case, EXPLAIN seems to acquire MDL.

Console1:

MariaDB [test]> SHOW CREATE TABLE myisam1;
+---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table   | Create Table                                                                                                                                                                           |
+---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| myisam1 | CREATE TABLE `myisam1` (
  `a` int(11) NOT NULL,
  `b2` int(11) DEFAULT NULL,
  PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY KEY (a)
PARTITIONS 3 */ |
+---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
 
MariaDB [test]> START TRANSACTION;
Query OK, 0 rows affected (0.01 sec)
 
MariaDB [test]> EXPLAIN SELECT * FROM myisam1 WHERE 0;
+------+-------------+-------+------+---------------+------+---------+------+------+------------------+
| id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra            |
+------+-------------+-------+------+---------------+------+---------+------+------+------------------+
|    1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL | NULL | Impossible WHERE |
+------+-------------+-------+------+---------------+------+---------+------+------+------------------+
1 row in set (0.00 sec)

Console2:

MariaDB [test]> ALTER TABLE myisam1 CHANGE b2  b INT;
Stage: 2 of 2 'enabling keys'      0% of stage done

(it's frozen)

Console3:

MariaDB [(none)]> SELECT * FROM information_schema.METADATA_LOCK_INFO;
+-----------+-------------------------+-----------------+----------------------+--------------+------------+
| THREAD_ID | LOCK_MODE               | LOCK_DURATION   | LOCK_TYPE            | TABLE_SCHEMA | TABLE_NAME |
+-----------+-------------------------+-----------------+----------------------+--------------+------------+
|         5 | MDL_INTENTION_EXCLUSIVE | MDL_STATEMENT   | Global read lock     |              |            |
|         4 | MDL_SHARED_READ         | MDL_TRANSACTION | Table metadata lock  | test         | myisam1    |
|         5 | MDL_SHARED_NO_WRITE     | MDL_TRANSACTION | Table metadata lock  | test         | myisam1    |
|         5 | MDL_INTENTION_EXCLUSIVE | MDL_TRANSACTION | Schema metadata lock | test         |            |
+-----------+-------------------------+-----------------+----------------------+--------------+------------+

Not sure if this is a bug. If it isn't, I suggest to document non-obvious cases when a MDL is acquired. (When doing something similar to this, I locked metadata for some minutes, in production.)



 Comments   
Comment by Sergei Golubchik [ 2014-03-13 ]

I think it's not very surprising — EXPLAIN SELECT acquires metadata locks, just like SELECT does. Because EXPLAIN needs to know table metadata and, sometimes, data too.

Comment by Ian Gilfillan [ 2014-09-08 ]

I have added a note about EXPLAIN acquiring MDL in the KB.

Generated at Thu Feb 08 07:07:20 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.