Re: Difference between "add column" and "add column" with default

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Difference between "add column" and "add column" with default
Дата
Msg-id 8402.1142893892@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Difference between "add column" and "add column" with default  (Guido Neitzer <guido.neitzer@pharmaline.de>)
Список pgsql-general
Guido Neitzer <guido.neitzer@pharmaline.de> writes:
> What is the technical difference between adding a column to a table
> and then apply a "set value = ..." to all columns and adding a column
> with a default value = ...?

"ADD COLUMN DEFAULT ..." is implemented via a full-table rewrite,
so you end up with a version of the table that has no dead space.
Unfortunately this requires an exclusive table lock while the rewrite
happens, so you lock out other processes from the table for a
considerably longer period of time than the UPDATE approach.  IIRC it's
also not completely MVCC-safe --- committed-dead rows will get removed
even if there are old open transactions that should still see those rows
as current.  Bottom line: there's no free lunch.

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: ambuild parameters
Следующее
От: Bruno Wolff III
Дата:
Сообщение: Re: How I can get the real data type result instead of integer data type?