pgsql: doc: mention unusability of dropped CHECK to verify NOT NULL

From: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: doc: mention unusability of dropped CHECK to verify NOT NULL
Date: 2025-08-04 11:29:00
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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 <psy2000usa(at)yahoo(dot)com>
Reviewed-by: David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
Discussion: https://postgr.es/m/[email protected]

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/479ebce12d320d23f960428b5221870c3633f1bd

Modified Files
--------------
doc/src/sgml/ref/alter_table.sgml | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2025-08-04 11:53:51 pgsql: Avoid unexpected shutdown when sync_replication_slots is enabled
Previous Message David Rowley 2025-08-04 05:44:13 pgsql: Fix incorrect comment regarding mod_since_analyze