From c58e3e1c710e2f97924ef387f7a9dff75491bacc Mon Sep 17 00:00:00 2001 From: jcoleman Date: Fri, 21 Jan 2022 18:50:39 +0000 Subject: [PATCH v2 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, 4 insertions(+), 20 deletions(-) diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml index 6c21191515..c146dfa01e 100644 --- a/doc/src/sgml/ddl.sgml +++ b/doc/src/sgml/ddl.sgml @@ -1406,26 +1406,10 @@ 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. - Additionally adding a column with a constant default value avoids a - a table scan to verify no NULL values are present. - - - - 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 - column with no default, insert the correct values using - UPDATE, and then add any desired default as described - below. + Before PostgreSQL 11, adding a new column to a + table required rewriting that table, making it a very slow operation. + More recent versions can sometimes optimize away this rewrite and related + validation scans. See the notes in ALTER TABLE for details. -- 2.20.1