要在公司的测试库添加二个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.
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/