I'm adding a number of columns with DEFAULT values that are NULLABLE to a large table
e.g
alter table big_table add (col1 varchar2(1) default 0, col2 varchar2(1) default 0);
It's taking a long time to do because Oracle is executing a bit of recursive SQL like this behind the scenes when the ALTER TABLE is submitted;
update big_table set col1 = '0', col2 = '0'
From experience of enabling foreign key constraint in PARALLEL, I did this;
alter session force parallel dml;
alter session force parallel query;
alter session force parallel ddl;
alter table big_table parallel;
-- now do my foreign key constraints => first enable novalidate, then validate
alter table big_table noparallel;
The above works and forces the recursive SQL that Oracle executes when validating the FK constraint to be executed in PARALLEL.
However, applying the same approach I had used for enabling FK constraint in PARALLEL to adding NULLABLE columns with DEFAULT values - it's not working, the recursive UPDATE above is refusing to go PARALLEL (even though the execution PLAN is showing PARALLEL).
Am I missing a "trick" ? Or has this improved in a later version of Oracle, 12c onwards,etc ?
If I can get that recursive UPDATE to go PARALLEL, I know then the ALTER will be much quicker, because as a separate test, I ran that UPDATE standalone in PARALLEL, and it did go PARALLEL and completed very quickly.
All statistics are up to date.
Can you make the column mandatory when you add it, to take advantage of fast column add. Then make it nullable later?
alter table big_table add (
col1 varchar2(1) default 0 not null,
col2 varchar2(1) default 0 not null
);
alter table t
modify ( col1 null, col2 null );