Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-5826

EXPLAIN acquires metadata locks

    XMLWordPrintable

Details

    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.)

      Attachments

        Activity

          People

            greenman Ian Gilfillan
            f_razzoli Federico Razzoli
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.