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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,高可用系列 2核4GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

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

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
数据可视化 数据挖掘 Python
数据分析案例-往届世界杯数据可视化
数据分析案例-往届世界杯数据可视化
794 0
数据分析案例-往届世界杯数据可视化
|
10月前
|
存储 Java Nacos
学成在线笔记+踩坑(4)——【媒资管理模块】上传图片,Nacos+Gateway+MinIO
媒资管理模块简介、MinIO构建分布式文件系统、MinIO数据恢复演示 、【媒资模块】上传图片
学成在线笔记+踩坑(4)——【媒资管理模块】上传图片,Nacos+Gateway+MinIO
|
Java Android开发 iOS开发
深入探讨移动操作系统的性能优化:安卓与iOS的对比分析
在现代移动设备中,操作系统的性能优化至关重要。本文从系统架构、内存管理、电池续航和应用程序运行效率等多个维度,深入探讨了安卓(Android)和iOS两大主流移动操作系统的优化策略及其实际效果,旨在为开发者和用户提供更清晰的了解和选择依据。
686 0
|
8月前
|
人工智能 算法 搜索推荐
探索人工智能与大数据的融合之道####
本文深入探讨了人工智能(AI)与大数据之间的紧密联系与相互促进的关系,揭示了二者如何共同推动科技进步与产业升级。在信息爆炸的时代背景下,大数据为AI提供了丰富的学习材料,而AI则赋予了大数据分析前所未有的深度与效率。通过具体案例分析,本文阐述了这一融合技术如何在医疗健康、智慧城市、金融科技等多个领域展现出巨大潜力,并对未来发展趋势进行了展望,强调了持续创新与伦理考量的重要性。 ####
|
存储 消息中间件 NoSQL
聊一聊数据库的行存与列存
好多人最开始学习数据库的时候,是关系数据库,数据以表格形式存储,一行表示一条记录。其实这种就是典型的行存储(Row-based store),将表按行存储到磁盘分区上。 而一些数据库还支持列存储(Column-based store),它将表按列存储到磁盘分区上。
聊一聊数据库的行存与列存
|
算法 定位技术
连连看核心算法与基本思想(附全部项目代码链接与代码详细注释)
连连看核心算法与基本思想(附全部项目代码链接与代码详细注释)
618 0
|
机器学习/深度学习 人工智能 安全
GPT-4硬核揭秘:能力,操纵性,局限性,聊天GPT Plus等
OpenAI创建了 GPT-4,这是 OpenAI 扩大深度学习努力的最新里程碑...
479 0
|
消息中间件 SQL Kubernetes
DotNet.CAP,或是.NET唯一靠谱的开源分布式框架
DotNet.CAP,或是.NET唯一靠谱的开源分布式框架
794 0
DotNet.CAP,或是.NET唯一靠谱的开源分布式框架
|
监控 安全 数据安全/隐私保护
在开源代码的时候该如何避免安全风险的发生?
作为开发者来讲,不管是在实际开发中使用开源项目,还是直接投身于开源的贡献中,关于开源相关的内容想必都有自己独到的见解。开源与开发者息息相关,可能有的开发者会觉得不使用开源项目,自己就与开源无关了?这种想法是片面的,因为就算没有在实际开发中使用开源项目,但是在实际开发中肯定会用到一些第三方的插件,那么能保证这些插件没有用到开源的内容么?所以,开源与每一位开发者都有联系。
398 2
在开源代码的时候该如何避免安全风险的发生?
|
存储 安全 Linux
阿里云服务器搭建 图文详细教程
首先先确定端口号是否开放
1780 0