oracle 11G 添加字段调整性能

要在公司的测试库添加二个pflag,pflag2字段,表的数据量为590W 。

按照以前的方式alter table ehr_healthrecord add (pflag numer default (0));

花费时间为16:15min
alter table  hzwsj.EHR_HEALTHRECORD add  (pflag2 number default(0) not null);

花费时间为407msecs 毫秒!!! 天壤之别!!!
反向把pflag2 设置为null 花时间为15:28 秒 突突。。。。。alter table hzwsj.EHR_HEALTHRECORD modify  pflag2 null;
ORACLE 里面有一段介绍
Adding Table Columns
To add a column to an existing table, use the ALTER TABLE...ADD statement.
The following statement alters the hr.admin_emp table to add a new column named bonus:
ALTER TABLE hr.admin_emp
      ADD (bonus NUMBER (7,2));
If a new column is added to a table, the column is initially NULL unless you specify the DEFAULT clause. When you specify a default value, the database immediately updates each row with the default value. Note that this can take some time, and that during the update, there is an exclusive DML lock on the table. For some types of tables (for example, tables without LOB columns), if you specify both a NOT NULL constraint and a default value, the database can optimize the column add operation and greatly reduce the amount of time that the table is locked for DML.
如果要在一张已经存在的表中添加一个字段,你没有指定默认值的话他默认为NULL,当你指定了默认值的时候数据库直接在每行上直接更新添加的值,这需要花上一段时间,并且会在这段时间内产生DML 锁。对于一些类型表(例如没有lob字段的表) 如果你添加的字段是not null 的并且有一个默认的初始值,数据库能够对添加列进行优化,减少大量数据库被DML锁的时间。
You can add a column with a NOT NULL constraint only if the table does not contain any rows, or you specify a default value.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26764973/viewspace-1458695/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/26764973/viewspace-1458695/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值