From 3f119b3f67f6452ff7594d4f19d60ca17a09e19f Mon Sep 17 00:00:00 2001 From: jcoleman Date: Fri, 21 Jan 2022 18:50:39 +0000 Subject: [PATCH v3 2/2] Don't double document ADD COLUMN optimization details Instead point people to the source of truth. This also avoids using different language ("constant" versus "non-volatile"). --- doc/src/sgml/ddl.sgml | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml index 22f6c5c7ab..efd9542252 100644 --- a/doc/src/sgml/ddl.sgml +++ b/doc/src/sgml/ddl.sgml @@ -1406,25 +1406,17 @@ ALTER TABLE products ADD COLUMN description text; - From PostgreSQL 11, adding a column with - a constant default value no longer means that each row of the table - needs to be updated when the ALTER TABLE statement - is executed. Instead, the default value will be returned the next time - the row is accessed, and applied when the table is rewritten, making - the ALTER TABLE very fast even on large tables. - + Adding a new column can require rewriting the whole table, + making it slow for large tables. However, the rewrite can be optimized + away in some cases, depending on what default value is given to the + column. See for details. - - However, if the default value is volatile (e.g., - clock_timestamp()) - each row will need to be updated with the value calculated at the time - ALTER TABLE is executed. To avoid a potentially - lengthy update operation, particularly if you intend to fill the column - with mostly nondefault values anyway, it may be preferable to add the + When a rewrite is required (e.g., a volatile default value like + clock_timestamp()) it may be preferable to add the column with no default, insert the correct values using UPDATE, and then add any desired default as described - below. - + below. This is particularly true if you intend to fill the column + with mostly nondefault values anyway. -- 2.17.1