https://www.postgresql.org/message-id/CAASwCXeaTgAC0o_eNQwD4SnFagBAdBFBUmjFq-6pczBi53tgRA@mail.gmail.com
> If you are fully confident you have no NULL values, (snip) and you have checked all the rows in a table are NOT NULL for the column,
would it be completely crazy to just set pg_attribute.attnotnull to
TRUE for the column?
大胆な…。
Adding a NOT NULL CONSTRAINT on PG Faster with Minimal Locking https://medium.com/doctolib/adding-a-not-null-constraint-on-pg-faster-with-minimal-locking-38b2c00c4d1c
NOT VALIDなCHECK制約を経由するとロックを緩くできるという話。
PostgreSQL: Documentation: 11: 5.5. Modifying Tables https://www.postgresql.org/docs/11/ddl-alter.html#DDL-ALTER-ADDING-A-COLUMN
> From PostgreSQL 11, adding a column with a constant default value no longer means that each row of the table needs to be updated when the ALTER TABLE statement 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 ALTER TABLE very fast even on large tables.
ほー。