【待整理】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 ...
随机推荐
- 【原创】源码角度分析Android的消息机制系列(六)——Handler的工作原理
ι 版权声明:本文为博主原创文章,未经博主允许不得转载. 先看Handler的定义: /** * A Handler allows you to send and process {@link Mes ...
- 推荐一个基于Vue2.0的的一款移动端开发的UI框架,特别好用。。。
一丶YDUI 一只注重审美,且性能高效的移动端&微信UI. 下面为地址自己研究去吧! 我的项目正在用,以前用的Mint-ui但是现在感觉还是这个好一点,官方给出的解释很清楚,很实用. 官方地址 ...
- Java程序性能优化-读书笔记(一) 单例模式
单例模式: 目的: 确保系统中一个类只产生一个实例. 好处: 1.对于频繁使用的对象,可以省略创建对象所花费的时间,这对于那些重量级对象而言,是非常可观的一笔系统开销. 2.由于new操作的次数减少, ...
- 底层码农的Stanford梦 --- 从SCPD开始 [转]
转载自知乎: https://zhuanlan.zhihu.com/p/25010074 一开始让我写这篇文章的时候,我是拒绝的.毕竟,我不是Stanford毕业的,出来写文章介绍Stanford,难 ...
- Vijos 1006 晴天小猪历险记之Hill 单源单汇最短路
背景 在很久很久以前,有一个动物村庄,那里是猪的乐园(^_^),村民们勤劳.勇敢.善良.团结-- 不过有一天,最小的小小猪生病了,而这种病是极其罕见的,因此大家都没有储存这种药物.所以晴天小猪自告奋勇 ...
- 详解Linux chgrp和chown命令的用法
Linux chgrp和chown命令是管理员的常用命令,对于初学Linux系统管理的人来说,这对Linux chgrp和chown命令具体的用法这里做一介绍. Linux chgrp命令 功能:改变 ...
- 推荐系统那点事 —— 基于Spark MLlib的特征选择
在机器学习中,一般都会按照下面几个步骤:特征提取.数据预处理.特征选择.模型训练.检验优化.那么特征的选择就很关键了,一般模型最后效果的好坏往往都是跟特征的选择有关系的,因为模型本身的参数并没有太多优 ...
- <jsp:include>和<%@include%>的区别
个人笔记(并非自己总结,而是从别人的博客上看到的) <jsp:include> :动态包含 1.<jsp:include>包含的是html文件 举例: DynamicInclu ...
- 如何在一个Eclipse同时启动两个Tomcat
比如:有两个版本的tomcat,一个5.*,一个6.*,此时由于两个工程分别部署在两个版本的tomcat下,需要同时启动两个tomcat,以下是方法: 1.特别要注意: 不要设置CATALINA_HO ...
- ChartCtrl源码剖析之——CChartObject类
首先,做一些简单的铺垫,目前针对ChartCtrl源码的剖析只针对V.15版本.名义上说是剖析,倒不如说是记录下自己针对该控件的理解,非常感谢Cedric Moonen大神,一切的功劳与掌声都该赠予给 ...