当前位置:网站首页>达梦数据库大表添加字段
达梦数据库大表添加字段
2022-08-05 07:29:00 【Asky】
一个1000多万记录的大表,尝试添加字段,语句如下:
alter table "HXL"."TB_OBJECTS" add column(NAME varchar(30)); ##执行很久
该语句执行很久,期间尝试开启另外的一个会话写入数据
insert into tb_objects(owner) values('TT'); ##一直等待
发现无法写入,一直在等待,请问下大表加字段怎么做呢?不能影响到业务使用
采纳答案1:
可以考虑设置参数alter_table_opt,设置为1,添加列采用查询插入法,可能导致rowid变化;ALTER_TABLE_OPT 为 2 时,系统开启快速加列功能,对于没有默认值或者默认值为 NULL 的新列,系统内部会标记为附加列,能够达到瞬间加列的效果, 此时 ROWID 不会改变, 若有默认值且默认值不为 NULL,则仍旧采取查询插入实现。如果设置成3,系统开启快速加列模式,允许指定新增列的默认值,系统会为该列设置附加列标记,查询表中已存在的数据时,会自动为记录设置追加列默认值,rowid不变。
其他答案1:
可以考虑设置参数alter_table_opt,设置为1,添加列采用查询插入法,可能导致rowid变化;ALTER_TABLE_OPT 为 2 时,系统开启快速加列功能,对于没有默认值或者默认值为 NULL 的新列,系统内部会标记为附加列,能够达到瞬间加列的效果, 此时 ROWID 不会改变, 若有默认值且默认值不为 NULL,则仍旧采取查询插入实现。如果设置成3,系统开启快速加列模式,允许指定新增列的默认值,系统会为该列设置附加列标记,查询表中已存在的数据时,会自动为记录设置追加列默认值,rowid不变。
其他答案2:
感谢,试了下,设置成3,添加带默认值字段秒级完成
ALTER_TABLE_OPT=3
[执行语句1]:
alter table HXL.TB_OBJECTS add column(NAME varchar(30) default 'AA' not null);
执行成功, 执行耗时60毫秒. 执行号:700
边栏推荐
猜你喜欢

MySQL: join query | inner join, outer join

Redis常用命令

protobuf is compiled against the associated .proto file

数据库——概述

protobuf根据有关联的.proto文件进行编译

TRACE32——Go.direct

Algorithm Supplements Fifteen Complementary Linked List Related Interview Questions

Put Cloudflare on the website (take Tencent Cloud as an example)

3555. 二叉树

Flink学习12:DataStreaming API
随机推荐
protobuf is compiled against the associated .proto file
After working for 3 years, I recalled the comparison between the past and the present when I first started, and joked about my testing career
Algorithm Supplements Fifteen Complementary Linked List Related Interview Questions
Flink学习11:flink程序并行度
openSource 知:社区贡献
二叉树进阶复习1
Mysql master-slave delay reasons and solutions
算法拾遗十五补链表相关面试题
Flink学习12:DataStreaming API
微信 小程序 之PC端 不支持 wx.previewMedia 方法 故用自定义轮播图进行 模拟照片视频的播放
字符串提取 中文、英文、数字
RNote108---显示R程序的运行进度
爬虫之验证码
Win10 设置锁屏壁纸提示尝试其它图片
Game Thinking 19: Multi-dimensional calculation related to games: point product, cross product, point-line-surface distance calculation
TRACE32——C源码关联1
Mysql 死锁和死锁的解决方案
专用机终端安装软件后报IP冲突
Why does Mysql fail to create a database
《基于R语言的自动数据收集》--第3章 XML和JSON