【待整理】MySQL alter table modify vs alter table add产生state不一样
MySQL:5.6.35
OS:redhat5.8
今天更新数据库某些表字段,有如下两SQL:
①alter table xx modify xxxx;(表大概是77w)
②alter table sb add sbsb;(表大概是95w)
奇怪的是①产生的state为:copy to tmp table
②产生的state为:altering table
两表同样是百万级别的;后者执行虽慢,但是消耗时间不到1200s,而后者跑了2800s。
开始怀疑alter中的add 和modify 两个操作的实现过程有所差异;
官方说法:
MODIFY is an extension to ALTER TABLE for Oracle compatibility. When you use CHANGE or MODIFY, column_definition must include the data type and all attributes that should apply to the new column, other than index attributes such as PRIMARY KEY or UNIQUE. Attributes present in the original definition but not specified for the new definition are not carried forward. Suppose that a column col1 is defined as INT UNSIGNED DEFAULT 1 COMMENT 'my column' and you modify the column as follows: ALTER TABLE t1 MODIFY col1 BIGINT;
The resulting column will be defined as BIGINT, but will not include the attributes UNSIGNED DEFAULT 1 COMMENT 'my column'. To retain them, the statement should be: ALTER TABLE t1 MODIFY col1 BIGINT UNSIGNED DEFAULT 1 COMMENT 'my column';
When you change a data type using CHANGE or MODIFY, MySQL tries to convert existing column values to the new type as well as possible. Warning
This conversion may result in alteration of data. For example, if you shorten a string column, values may be truncated. To prevent the operation from succeeding if conversions to the new data type would result in loss of data, enable strict SQL mode before using ALTER TABLE (see Section 5.1.8, “Server SQL Modes”). To add a column at a specific position within a table row, use FIRST or AFTER col_name. The default is to add the column last. You can also use FIRST and AFTER in CHANGE or MODIFY operations to reorder columns within a table. If you use CHANGE or MODIFY to shorten a column for which an index exists on the column, and the resulting column length is less than the index length, MySQL shortens the index automatically. CHANGE col_name is a MySQL extension to standard SQL. ALTER ... SET DEFAULT or ALTER ... DROP DEFAULT specify a new default value for a column or remove the old default value, respectively. If the old default is removed and the column can be NULL, the new default is NULL. If the column cannot be NULL, MySQL assigns a default value as described in Section 11.6, “Data Type Default Values”.
alter table add ,state状态由 waiting for table metadata lock (持续10s左右)然后到 altering table,最终完成。
【待整理】MySQL alter table modify vs alter table add产生state不一样的更多相关文章
- mysql ALTER COLUMN MODIFY COLUMN CHANGE COLUMN 区别及用法 (转)
-- 设置或删除列的默认值.该操作会直接修改.frm文件而不涉及表数据.此操作很快 -- ALTER COLUMN ALTER TABLE dsp_ad_center.XianDuan ALTER ...
- 【转载】alter table move 和 alter table shrink space的区别
move 和shrink 的共同点1.收缩段2.消除部分行迁移3.消除空间碎片4.使数据更紧密 shrink 语法: alter table TABLE_NAME shrink space [com ...
- [Hive - LanguageManual] Create/Drop/Alter Database Create/Drop/Truncate Table
Hive Data Definition Language Hive Data Definition Language Overview Create/Drop/Alter Database Crea ...
- mysql 命令重命名表RENAME TABLE 句法
mysql 命令重命名表RENAME TABLE 句法 RENAME TABLE tbl_name TO new_tbl_name[, tbl_name2 TO new_tbl_name2,...]更 ...
- 收集整理mysql数据库设计规范与原则
1. 数据库命名规范 采用26个英文字母(区分大小写)和0-9的自然数(经常不需要)加上下划线'_'组成;命名简洁明确(长度不能超过30个字符);例如:user, stat, log, 也可以wifi ...
- MySQL ERROR 1005: Can't create table (errno: 150)的错误解决办法
在mysql 中建立引用约束的时候会出现MySQL ERROR 1005: Can't create table (errno: 150)的错误信息结果是不能建立 引用约束. 出现问题的大致情况 1. ...
- mysql distinct field1,field2,field3, .... from table
mysql distinct field1,field2,field3, .... from table 我们知道 这样的sql可以去掉重复项 (field1的重复项); select distinc ...
- mysqldump导出报错"mysqldump: Error 2013: Lost connection to MySQL server during query when dumping table `file_storage` at row: 29"
今天mysql备份的crontab自动运行的时候,出现了报警,报警内容如下 mysqldump: Error 2013: Lost connection to MySQL server during ...
- Shell脚本使用汇总整理——mysql数据库5.7.8以前备份脚本
Shell脚本使用汇总整理——mysql数据库5.7.8以前备份脚本 Shell脚本使用的基本知识点汇总详情见连接: https://www.cnblogs.com/lsy-blogs/p/92234 ...
随机推荐
- Codeforces 818B Permutation Game
首先看一下题目 B. Permutation Game time limit per test 1 second memory limit per test 256 megabytes input s ...
- 【转】SQL多条件模糊查询解决方案-存储过程
前言: 算法的基本特性在前几篇博客中已经做了详细的说明,经过不断的改进优化,到归仓的时候了,也就是说,该算法告一段落,不再更新. 作为最终的解决方案,简要的总结一下算法特性,以方便读者参阅. l ...
- UGUI 字体背景长度自适应
本文实现以下需求: 在UGUI中 Text为动态添加 要使Text字体背景随着Text的长度而变化 之前还在赞叹UGUI的强大 转念一想,UGUI中好像没有可以实现此功能的组件 也想出了一种办法 把背 ...
- php七牛批量删除空间内的所有文件方法
相信大家都在使用七牛的免费云存储服务的同时,有清空七牛云存储镜像文件或者批量删除七牛云空间文件的需求,该怎么做?官方的工具好像并没有提供批量删除的功能,七牛云官方给出的建议是删除空间,再新建一个这样太 ...
- 从零搭建DotnetCore2.0
右键解决方案>新建项目> 选择Web>ASP.NETCoreWeb应用程序(.NET Core) 选择Web应用程序,暂时不选择启用Docker,身份验证选择个人用户账户(会自动生成 ...
- 虚幻引擎UE4如何制作可拖动(Drag and Drop)的背包(Scrollbox)
本教程适合初学者(学习经历已有30天的UE4初学者). 最终效果 由于隐私保护,不想截实际的效果图,下面给出了示意图,左边是背包A,右边是背包B,将其中的子项目从左侧拖往右侧的背包,然后在插入位置放置 ...
- java基础04 匿名内部类
内部类 (1)把类定义在另一个类的内部,该类就被称为内部类. 举例:把类B定义在类A中,类B就被称为内部类. (2)内部类的访问规则 A:可以直接访问外部类的成员,包括私有 B:外部类要想访问内部类成 ...
- 或许你不知道的10条SQL技巧(转自58沈剑原创)
这几天在写索引,想到一些有意思的TIPS,希望大家有收获. 一.一些常见的SQL实践 (1)负向条件查询不能使用索引 select * from order where status!=0 and s ...
- 将Asp.Net Core和corefx移植到.Net 4.0
引言 因为工作内容的原因需要兼容 XP,而 XP 最多支持到.Net Framework 4.0.因此无法享受到 .Net Core 带来的一堆很好用的库,好在无论 corefx 还是 Asp.Net ...
- Everything 使用记录
背景:在windows环境下,使用系统自带的搜索框经常出现搜索不到指定文件的问题,在网上无意发现了这款软件,真的很好用! 1 文件列表 建立文件列表主要是为了以后可以在指定的目录内查找自己想要的文件, ...