feature idea: use index when checking for NULLs before SET NOT NULL - Mailing list pgsql-hackers

From John Bachir
Subject feature idea: use index when checking for NULLs before SET NOT NULL
Date
Msg-id 7fc87d44-82de-4592-9cca-14536af274c3@www.fastmail.com
Whole thread Raw
Responses Re: feature idea: use index when checking for NULLs before SET NOT NULL  (Sergei Kornilov <sk@zsrv.org>)
List pgsql-hackers
There's the age-old problem of SET NOT NULL being impossible on large actively used tables, because it needs to lock
thetable and do a table scan to check if there are any existing NULL values. I currently have a table that's not
particularlyhuge but a scan takes 70 seconds, which causes unacceptable downtime for my entire application.
 

Postgres is not able to use an index when doing this check: https://dba.stackexchange.com/questions/267947

Would it be possible to have Postgres use an index for this check? Given the right index, the check could be instant
andthe table would only need to be locked for milliseconds.
 

(I'm sure I'm not the first person to think of this, but I couldn't find any other discussion on this list or
elsewhere.)

Thanks for reading!
John



pgsql-hackers by date:

Previous
From: Kyotaro Horiguchi
Date:
Subject: Re: SIGSEGV from START_REPLICATION 0/XXXXXXX in XLogSendPhysical() at walsender.c:2762
Next
From: John Naylor
Date:
Subject: Re: speed up unicode normalization quick check