while creating a secondary index with plugin, queries are blocked until it ends

在Pulgin的官方文档中这样描述到:

While a secondary index is being created or dropped, the table is locked in shared mode. Any writes to the table are blocked, but the data in the table can be read. read. When you alter the clustered index of a table, the table is locked in exclusive mode, because the data must be copied. Thus, during the creation of a new clustered index, all operations on the table are blocked.

Once a CREATE INDEX or ALTER TABLE statement that creates a secondary index begins executing, queries can access the table for read access, but cannot update the table.

在安装有plugin的mysql中,在创建非主键索引的时候,mysql拷贝主表,对表加的是s lock,其他进程仍然可以访问表中的数据(select),但是从下面的测试的结果看来,在创建非主键索引的时候,select是被阻塞了的。

Test1:

InnoDB plugin 1.0.9/MySQL 5.1.48

root@test 10:09:51>desc test_plg;

+——-+————-+——+—–+———+—————-+

| Field | Type        | Null | Key | Default | Extra          |

+——-+————-+——+—–+———+—————-+

| id    | int(11)     | NO   | PRI | NULL    | auto_increment |

| name  | varchar(30) | YES  | MUL | NULL    |                |

| name2 | varchar(30) | YES  |     | NULL    |                |

| dd    | datetime    | YES  |     | NULL    |                |

| dd2   | datetime    | YES  |     | NULL    |                |

+——-+————-+——+—–+———+—————-+

$mysql -uroot

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 420689

Server version: 5.1.48-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

root@(none) 09:49:50>select @@innodb_version;

+——————+

| @@innodb_version |

+——————+

| 1.0.9            |

+——————+

Sesion1

root@test 09:56:11>select * from test_plg where id =1;

+—-+———+——-+———————+———————+

| id | name    | name2 | dd                  | dd2                 |

+—-+———+——-+———————+———————+

|  1 | ssdsdsd | sdxss | 2011-03-07 22:03:26 | 2011-03-07 22:03:26 |

+—-+———+——-+———————+———————+

1 row in set (0.00 sec)

Session2:create a secondary index:

root@test 10:03:47>alter table test_plg add  index ind_name(name);

Query OK, 0 rows affected (37.16 sec)

Records: 0  Duplicates: 0  Warnings: 0

Session1:

root@test 10:03:50>select * from test_plg where id =1;

+—-+———+——-+———————+———————+

| id | name    | name2 | dd                  | dd2                 |

+—-+———+——-+———————+———————+

|  1 | ssdsdsd | sdxss | 2011-03-07 22:03:26 | 2011-03-07 22:03:26 |

+—-+———+——-+———————+———————+

1 row in set (30.59 sec)

root@(none) 11:15:42>show full processlist;

Id: 420689

User: root

Host: localhost

db: test

Command: Query

Time: 19

State: manage keys

Info: alter table test_plg add  index ind_name(name)

*************************** 3. row ***************************

Id: 425388

User: root

Host: localhost

db: test

Command: Query

Time: 16

State: Waiting for table

Info: select * from test_plg where id =1

Test1:

可以看到session1没有创建索引的时候,发出一条查询,很快返回结果;

Session2创建索引ind_name(该表有1600w记录),同时session1查询刚才同样的查询,直到索引创建完成才返回结果,进程状态位State: Waiting for table

Test2:

InnoDB plugin 1.1.5/MySQL 5.5.9:

$mysql -uroot –socket /home/dongkai.zmj/mysql-5.5.9-linux2.6-x86_64/run/mysql.sock

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 17626

Server version: 5.5.9-log MySQL Community Server (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

root@(none) 09:50:21>select @@innodb_version;

+——————+

| @@innodb_version |

+——————+

| 1.1.5            |

+——————+

1 row in set (0.00 sec)

Sesion1

root@test 10:07:51>select * from test_plg where;

+—-+———+——-+———————+———————+

| id | name    | name2 | dd                  | dd2                 |

+—-+———+——-+———————+———————+

|  1 | ssdsdsd | sdxss | 2011-03-07 21:51:44 | 2011-03-07 21:51:44 |

+—-+———+——-+———————+———————+

1 row in set (0.00 sec)

Session2:create a secondary index:

root@test 10:07:56>alter table test_plg add index ind_name(name);

Query OK, 0 rows affected (1 min 47.59 sec)

Records: 0  Duplicates: 0  Warnings: 0

Session1:

root@test 10:08:05>select * from test_plg where;

+—-+———+——-+———————+———————+

| id | name    | name2 | dd                  | dd2                 |

+—-+———+——-+———————+———————+

|  1 | ssdsdsd | sdxss | 2011-03-07 21:51:44 | 2011-03-07 21:51:44 |

+—-+———+——-+———————+———————+

1 row in set (1 min 45.17 sec)

root@(none) 11:15:42>show full processlist;

+——-+——+———–+——+———+——+———————————+———————————————–+

| Id    | User | Host      | db   | Command | Time | State                           | Info                                          |

+——-+——+———–+——+———+——+———————————+———————————————–+

| 17626 | root | localhost | test | Query   |    6 | manage keys                     | alter table test_plg add index ind_name(name) |

| 17628 | root | localhost | NULL | Query   |    0 | NULL                            | show full processlist                         |

| 17629 | root | localhost | test | Query   |    2 | Waiting for table metadata lock | select * from test_plg where             |

+——-+——+———–+——+———+——+———————————+———————————————-

Test2:和test1一样的的做法,select同样被block,进程状态Waiting for table metadata lock

Test3:

Built-in version

root@test 11:08:05>show variables like ‘%plug%’;

+—————+—————————–+

| Variable_name | Value                       |

+—————+—————————–+

| plugin_dir    | /u01/mysql/lib/mysql/plugin |

+—————+—————————–+

1 row in set (0.00 sec)

Session1:

root@test 11:07:18>alter table test_plg add index ind_name(name);

Query OK, 3145728 rows affected (57.50 sec)

Records: 3145728  Duplicates: 0  Warnings: 0

session2

root@test 11:07:25>select * from test_plg where;

+—-+———+——-+———————+———————+

| id | name    | name2 | dd                  | dd2                 |

+—-+———+——-+———————+———————+

|  1 | ssdsdsd | sdxss | 2011-03-08 11:01:57 | 2011-03-08 11:01:57 |

+—-+———+——-+———————+———————+

1 row in set (0.00 sec)

时间: 2024-08-03 21:12:10

while creating a secondary index with plugin, queries are blocked until it ends的相关文章

(bugfix in 5.6.21) DUPLICATES IN UNIQUE SECONDARY INDEX BECAUSE OF FIX OF BUG#68021

(bugfix in 5.6.21) DUPLICATES IN UNIQUE SECONDARY INDEX BECAUSE OF FIX OF BUG#68021 在MySQL5.6.21版本里,fix了这样一个有趣(坑爹)的bug,影响5.6.12之后及5.6.21之间的版本 InnoDB: With a transaction isolation level less than or equal to READ COMMITTED, gap locks were not taken wh

PostgreSQL 10.0 preview 性能增强 - 间接索引(secondary index)

标签 PostgreSQL , 10.0 , 间接索引 , 第二索引 背景 我们知道,PostgreSQL的MVCC是多版本来实现的,当更新数据时,产生新的版本. 那么如果新版本不在同一个数据块的时候,索引也要随之变化,当新版本在同一个堆表的块里面时,则发生HOT UPDATE,不需要变更没有发生值改变的索引. 但是HOT总不能覆盖100%的更新,所以还是有索引更新的可能存在. 为了解决这个问题,PostgreSQL 10.0引入了第二索引(间接索引)的概念,即在PK或者UK之上,构建其他索引.

Principles and Applications of the Index Types Supported by PostgreSQL

Background PostgreSQL supports a wide range of features: Open data interfaces that allow PostgreSQL to support a wide range of different data types. Apart from those supported by traditional databases, it also supports GIS, JSON, RANGE, IP, ISBN, ima

13.1.17 CREATE TABLE Syntax

13.1.17 CREATE TABLE Syntax   13.1.17.1 CREATE TABLE ... LIKE Syntax 13.1.17.2 CREATE TABLE ... SELECT Syntax 13.1.17.3 Using FOREIGN KEY Constraints 13.1.17.4 Silent Column Specification Changes CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name (cre

11.2.0.3 Patch Set - Availability and Known Issues [ID 1348336.1]

11.2.0.3 Patch Set - Availability and Known Issues [ID 1348336.1] To Bottom Modified:16-Jan-2013Type:READMEStatus:PUBLISHEDPriority:3 Comments (0) Known Issues specific to the 11.2.0.3 Patch Set Please note that 11.2 Patch Sets 11.2.0.2 and higher ar

MySQL 5.6.17/5.5.37 发布

MySQL产品线更新.5.6.17/5.5.37 2014-03-27 之前版本2013-01-31的5.6.16/5.5.36主要是Bug修正.5.1还是5.1.73. 完全改进: MySQL 5.6.17 改进记录 (2014-03-27) 新特性和各种改进 Incompatible Change: The AES_ENCRYPT() and AES_DECRYPT() functions now permit control of the block encryption mode and

【OH】Glossary Oracle词汇表(上)

Glossary [OH]Glossary Oracle词汇表(上) Oracle? Multimedia DICOM Developer's Guide 11g Release 2 (11.2) E10778-03 Glossary ● anonymity document An XML document that specifies the set of attributes to be made anonymous, and defines the actions required to

MYSQL METADATA LOCK(MDL LOCK)学习(1) 理论知识和加锁类型测试

原创,水平有限如有错误请指出共同探讨本文中某些结论性的东西我用黄色标记出来请大家多多留意一下另外我家二娃刚刚出生,大家祝福我一下吧.谢谢!^_^ 本文网址 http://blog.itpub.net/7728585/viewspace-2143093/ 源码版本:5.7.14注意MDL和DML术语的不同. 一.前言    MYSQL中MDL锁一直是一个比较让人比较头疼的问题,我们谈起锁一般更加倾向于INNODB下层的gap lock.next key lock.row lock等, 因为它很好理

数据库案例集锦 - 开发者的《如来神掌》

背景 「剑魔独孤求败,纵横江湖三十馀载,杀尽仇寇,败尽英雄,天下更无抗手,无可柰何,惟隐居深谷,以雕为友.呜呼,生平求一敌手而不可得,诚寂寥难堪也.」 剑冢中,埋的是剑魔独孤求败毕生几个阶段中用过的几柄剑: 利剑无意:第一柄是青光闪闪的利剑,凌厉刚猛,无坚不摧,弱冠前以之与河朔群雄争锋. 软剑无常:第二柄是紫薇软剑,三十岁前所用,误伤义士不祥,悔恨不已,乃弃之深谷. 重剑无锋:第三柄是玄铁重剑,重剑无锋,大巧不工,四十岁之前恃之横行天下. 木剑无俦:第四柄是已腐朽的木剑. 无剑无招:四十岁后,不