UPDATE run check constraints for affected columns only
jian he <jian.universality@gmail.com>
From: jian he <jian.universality@gmail.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2025-12-01T06:20:32Z
Lists: pgsql-hackers
Attachments
- v1-0001-UPDATE-run-check-constraints-for-affected-columns-only.patch (text/x-patch) patch v1-0001
hi. while casually looking at https://wiki.postgresql.org/wiki/Todo then I found out this thread: https://postgr.es/m/1326055327.15293.13.camel%40vanquo.pezone.net Seems easier to do nowadays. The attached patch implements the $subject. regress tests seems not enough to test it. Following the approach in 001_constraint_validation.pl, we use ereport(DEBUG1, errmsg_internal), then grep the logs to check whether the enforced constraint verification was skipped or not. we can not add check constraint to VIEW, tests covered partitioned table scarenio. DEMO: CREATE TABLE upd_check_skip (a int, b int, c int, d int generated always as (b+c) STORED); ALTER TABLE upd_check_skip ADD CONSTRAINT cc2 CHECK(a+c < 100); ALTER TABLE upd_check_skip ADD CONSTRAINT cc3 CHECK(b < 1); ALTER TABLE upd_check_skip ADD CONSTRAINT cc4 CHECK(d < 2); INSERT INTO upd_check_skip DEFAULT VALUES; SET client_min_messages to DEBUG1; --constraint verification will be skipped for cc3, cc4 UPDATE upd_check_skip SET a = 1; --constraint verification will be skipped for cc2 UPDATE upd_check_skip SET b = -1; --constraint verification will be skipped for cc3 UPDATE upd_check_skip SET c = -1; -- jian https://www.enterprisedb.com