Skip to content

Commit c3b44a7

Browse files
alvherrehopebo
authored andcommitted
doc: mention unusability of dropped CHECK to verify NOT NULL
It's possible to use a CHECK (col IS NOT NULL) constraint to skip scanning a table for nulls when adding a NOT NULL constraint on the same column. However, if the CHECK constraint is dropped on the same command that the NOT NULL is added, this fails, i.e., makes the NOT NULL addition slow. The best we can do about it at this stage is to document this so that users aren't taken by surprise. (In Postgres 18 you can directly add the NOT NULL constraint as NOT VALID instead, so there's no longer much use for the CHECK constraint, therefore no point in building mechanism to support the case better.) Reported-by: Andrew <[email protected]> Reviewed-by: David G. Johnston <[email protected]> Discussion: https://postgr.es/m/[email protected] (cherry picked from commit a9b4b0665d4599f4cbc441032a01fcfdab741613)
1 parent 29f220c commit c3b44a7

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

doc/src/sgml/ref/alter_table.sgml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
238238
provided none of the records in the table contain a
239239
<literal>NULL</literal> value for the column. Ordinarily this is
240240
checked during the <literal>ALTER TABLE</literal> by scanning the
241-
entire table; however, if a valid <literal>CHECK</literal> constraint is
242-
found which proves no <literal>NULL</literal> can exist, then the
243-
table scan is skipped.
241+
entire table;
242+
however, if a valid <literal>CHECK</literal> constraint exists
243+
(and is not dropped in the same command) which proves no
244+
<literal>NULL</literal> can exist, then the table scan is skipped.
244245
</para>
245246

246247
<para>

0 commit comments

Comments
 (0)