给一个含有21个字段的一千六百万大表增加一个字段需要多长时间?0.1秒
以前做过一个一千六百万大表增添字段实验https://www.cnblogs.com/xiandedanteng/p/12323537.html,实验证明表无论大小增添字段都很快,或者说增添字段的耗时与表规模无关。
但上次表字段有点少,于是这次把表增加到了21字段再实验。
表结构:
create table tb_20cols( id number(9,0), col01 integer not null, col02 integer not null, col03 integer not null, col04 integer not null, col05 integer not null, col06 integer not null, col07 integer not null, col08 integer not null, col09 integer not null, col10 integer not null, col11 integer not null, col12 integer not null, col13 integer not null, col14 integer not null, col15 integer not null, col16 integer not null, col17 integer not null, col18 integer not null, col19 integer not null, col20 integer not null)
初次充值:
insert into tb_20cols select 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 from dual connect by level<2000001
然后把以下语句重复三次就得到了一千六百万大表:
insert into tb_20cols select * from tb_20cols;
SQL> insert into tb_20cols select * from tb_20cols; 已创建2000000行。 SQL> insert into tb_20cols select * from tb_20cols; 已创建4000000行。 SQL> insert into tb_20cols select * from tb_20cols; 已创建8000000行。 SQL> select count(*) from tb_20cols; COUNT(*) ---------- 16000000
最后见证奇迹的时刻:
SQL> set timing on; SQL> alter table tb_20cols add remark nvarchar2(60); 表已更改。 已用时间: 00: 00: 00.10
结果证明增添字段耗时不但与规模无关,和列数也没关系。
道听途说的结论,网文的论断,可以姑且听之,但一定要做了实验后才能取信或是摒弃。
--2020.04.11--
分类:
Oracle.DBA
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
2018-04-11 【nodejs】修改了下对股票表进行crud操作的代码