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)

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
目录
相关文章
|
3月前
|
人工智能 运维 安全
AI行业这一周:Agent竞速加速,安全共识却让Altman、Musk罕见站在了一起
过去三天,AI行业呈现“竞速”与“刹车”并存的矛盾图景:企业级Agent加速嵌入工作流,华为、飞书等密集发布;资本市场却对纯故事估值降温;Anthropic等巨头罕见呼吁放缓前沿模型迭代,安全治理共识初现。
236 26
|
3月前
|
人工智能 自然语言处理 小程序
10万人里只有3个人做,他2个月赚6万:AI法律按结果收费OPC深度拆解
本文是「OPC一人公司通关手册」第14篇,拆解一个真实法律类一人公司案例:前央国企风控法务+法律自媒体人,上线微信小程序专注小额维权(交通事故、工伤、欠薪等),2个月营收6万元、获客成本仅10元、毛利率65%,核心在于“AI初诊+真人兜底+按结果收费”,验证了“服务先行、工具自生”的OPC正循环路径。(239字)
|
3月前
|
人工智能 IDE 测试技术
AI工程级编程工作台Qoder CN解析:Subagent子智能体、Repowiki知识库、命令案例与排坑指南
Qoder CN依托Quest2.0任务引擎、专家团多智能体协同、Repowiki工程知识库、终端沙箱安全隔离、Hook扩展机制,完成从简单代码补全向工程级自主开发工作台的跨越。提供原生IDE、主流IDE插件、CLI命令行多形态接入,兼容多款主流大模型,兼顾个人开发者与企业团队的研发场景。
475 0
|
3月前
|
弹性计算 固态存储 前端开发
阿里云服务器多少钱一年?2026年9月最新价格38元、99元和199元配置详解
2026年阿里云三大入门价:38元/年(轻量服务器,适合新手博客)、99元/年(经济型ECS,4GB内存,性价比之选)、199元/年(通用u1实例,5Mbps带宽,商用首选)。三档覆盖学习、开发到生产场景,需重点关注首年优惠与续费价格差异。(239字)
603 0
|
3月前
|
人工智能 弹性计算 小程序
阿里云便宜云服务器新手选购指南参考:轻量云服务器38元与云服务器99元和199元对比与选择参考
阿里云服务器特惠活动目前主要有三款核心入门机型:38元/年轻量应用服务器为新用户秒杀款,2核2G配200M峰值带宽,内置丰富应用镜像,开箱即用,适合新手快速上云。99元/年经济型e实例与199元/年通用算力型u1实例新老用户同享,支持续费同价至2029年,分别适配个人长期建站与小微企业商用场景。活动同步开放多款进阶实例折扣,覆盖从入门学习到高性能生产的全层级算力需求。
|
5月前
|
安全 关系型数据库 MySQL
阿里云代理商零度云lingducloud教新手快速部署数据库!
新手部署阿里云RDS MySQL常被VPC、可用区、ESSD等术语困扰。本文以通俗语言讲清核心概念,手把手指导选型、创建、白名单配置、账号设置及连接验证,并提醒避坑要点,助你30分钟快速上手安全可用的云数据库。
|
消息中间件 缓存 NoSQL
Redis + Java 架构实战:从锁机制到消息队列的整合
本文深入解析Redis与Java的整合实践,涵盖分布式锁、消息队列、缓存策略、高性能数据结构及容错机制。结合电商场景,助力构建高并发、高可用的分布式系统。
516 8
|
数据采集 人工智能 算法
GEO 技术落地教育与创业:周有贵博士与张弛教授共探校企协同技术赋能新路径
近日,湖南师范大学新闻传播学院张弛教授与 GEO 技术团队负责人 —— 巴黎学院人工智能博士、法国 GGI 商学院 GEO 首席技术专家周有贵,围绕 GEO 生成式引擎优化技术落地展开深度交流,为高校技术人才培养、学生创业冷启动及中小企业 AI 获客提供协同方案,对开发者社区关注的技术下沉与场景赋能具参考价值。
|
传感器 编解码 资源调度
相位编码调频连续波雷达:融合传统与创新的智能感知技术
相位编码调频连续波雷达(PC-FMCW)融合FMCW的硬件简洁性与相位编码的抗干扰优势,通过频域扩频提升多雷达共存能力,支持MIMO与联合通信,适用于自动驾驶与智能交通系统。
1263 6
|
机器学习/深度学习 自然语言处理 并行计算
基于DJL的机器学习
本文介绍了基于Java的深度学习框架DJL,涵盖机器学习与深度学习的核心概念、神经网络结构及生命周期,并通过MNIST数据集展示了从模型构建、训练到推理的完整流程。内容深入浅出,适合初学者入门。
957 5
基于DJL的机器学习

热门文章

最新文章