| From: | jian he <jian(dot)universality(at)gmail(dot)com> |
|---|---|
| To: | Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: [PATCH] Rebuild CHECK constraints after generated column SET EXPRESSION |
| Date: | 2026-05-13 05:19:36 |
| Message-ID: | CACJufxE3e1jPsKLsjNWMucahFJW7UO_UGWzhRESRvJ+8PeKgkg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi.
In case you are wondering, I already handled the whole-row cases for
ALTER TABLE DROP COLUMN and ALTER COLUMN SET DATA TYPE in
https://commitfest.postgresql.org/patch/5988 and
https://commitfest.postgresql.org/patch/6055
However, I missed the ALTER COLUMN SET EXPRESSION scenario.
RememberAllDependentForRebuilding with (attnum = 0) is essentially
asking any objects depend on this relation,
It will certainly catch many whole-row referenced dependent objects,
however, I wouldn’t be surprised if unintended corner cases exist.
CREATE TABLE r2 (a int, b int GENERATED ALWAYS AS (a * 10) STORED);
ALTER TABLE r2 ADD CONSTRAINT cc CHECK (a IS NOT NULL);
CREATE INDEX r2_idx ON r2 (a);
CREATE POLICY p3 ON r2 AS PERMISSIVE USING (a IS NOT NULL);
select classid::regclass, * from pg_depend where refobjid =
'r2'::regclass::oid and classid in ('pg_policy'::regclass);
The examples above show that RLS policies can have two dependencies on the
relation: one on the specific column, and another on the relation itself.
``RememberAllDependentForRebuilding with (attnum = 0)`` cannot cope with this.
ATRewriteTables->finish_heap_swap->reindex_relation may reindex the
relation, but
AlteredTableInfo->changedIndexOids should still remember the whole-row
Var references index objects.
For ALTER COLUMN SET EXPRESSION, no need to worry about whole-row
referenced triggers.BEFORE trigger referencing the whole-row
(including generated column) is not allowed (see
CreateTriggerFiringOn: ```if (!whenClause &&stmt->whenClause)```), and
ALTER COLUMN SET EXPRESSION will work fine with AFTER
triggersthat have whole-row reference.
The attached v2 includes support for ALTER COLUMN SET EXPRESSION on columns
referenced by whole-row indexes, check constraints, and RLS policies.
The code pattern is more or less simialr to
https://commitfest.postgresql.org/patch/6055.
I should rebase https://commitfest.postgresql.org/patch/6055 BTW.
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Disallow-or-rebuild-dependent-while-ALTER-COLUMN-SET-EXPRESSION.patch | text/x-patch | 24.0 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | shveta malik | 2026-05-13 05:24:20 | Re: Parallel Apply |
| Previous Message | Michael Paquier | 2026-05-13 05:14:50 | Re: Remove invalid SS2/SS3 handling from EUC-KR routines |