For adding values to a new column, I have the following options:
- Using
default
to add value duringALTER TABLE
command. - Doing
ALTER TABLE
withoutdefault
, then fetching all the records and iterating over all of them to save them with the new value.
I am interested to know how much performance difference should I expect?
I am adding a new column to a table with 14+ million records.
The column needs a default, unfortunately, I'll need to change a lot of code to allow putting default value. However, it's easier to iterate over all the records and save them with the value for the new column.
Before making my decision, I am looking for metrics of performance differences between the two options.
I am working on an application to be used in multiple machines, different environments and DBMS. I wouldn't be installing the application, it's the client's job. The application has scripts to aid them with the same. I understand that without system specifications it's hard to make predictions.
Is making broad predictions possible? As in, accessing all records requires O(n) time, similarly information on time requirements of using default during ALTER TABLE
and other processes will also help.
default
option.