From 0c3c593e1a6ee60ca4e5184e87099457b6759e49 Mon Sep 17 00:00:00 2001
From: James Coleman <jtc331@gmail.com>
Date: Fri, 24 Sep 2021 09:59:27 -0400
Subject: [PATCH v2 1/2] Document atthasmissing default avoids verification
 table scan

When PG11 added the ability for ALTER TABLE ADD COLUMN to set a constant
default value without rewriting the table the doc changes did not note
how the new feature interplayed with ADD COLUMN DEFAULT NOT NULL.
Since adding a NOT NULL constraint requires a verification table scan to
ensure no values are null, users want to know that the combined
operation also avoids the table scan.
---
 doc/src/sgml/ddl.sgml             | 2 ++
 doc/src/sgml/ref/alter_table.sgml | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index 22f6c5c7ab..6c21191515 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -1412,6 +1412,8 @@ ALTER TABLE products ADD COLUMN description text;
      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 <command>ALTER TABLE</command> very fast even on large tables.
+     Additionally adding a column with a constant default value avoids a
+     a table scan to verify no <literal>NULL</literal> values are present.
     </para>
 
     <para>
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index a76e2e7322..1dde16fa39 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -1355,7 +1355,9 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
     evaluated at the time of the statement and the result stored in the
     table's metadata.  That value will be used for the column for all existing
     rows.  If no <literal>DEFAULT</literal> is specified, NULL is used.  In
-    neither case is a rewrite of the table required.
+    neither case is a rewrite of the table required.  A <literal>NOT NULL</literal>
+    constraint may be added to the new column in the same statement without
+    requiring scanning the table to verify the constraint.
    </para>
 
    <para>
-- 
2.20.1

