Re: let ALTER TABLE DROP COLUMN drop whole-row referenced object

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: let ALTER TABLE DROP COLUMN drop whole-row referenced object
Date: 2025-09-23 05:37:44
Message-ID: CACJufxE-PJyKmoDnZDEt+anKdtV1MvfA+u9x_S9CvorYUQ9Bww@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Sep 15, 2025 at 8:40 PM jian he <jian(dot)universality(at)gmail(dot)com> wrote:
>
> Summary of attached v4:
> v4-0001: Handles ALTER TABLE DROP COLUMN when whole-row Vars are
> referenced in check constraints and indexes.
>
> v4-0002: Handles ALTER TABLE ALTER COLUMN SET DATA TYPE when whole-row
> Vars are referenced in check constraints and indexes.
>
> v4-0003: Handle ALTER TABLE ALTER COLUMN SET DATA TYPE and ALTER TABLE DROP
> COLUMN when policy objects reference whole-row Vars. Policy quals and check
> quals may contain whole-row Vars and can include sublinks (unplanned
> subqueries), pull_varattnos is not enough to locate whole-row Var. Instead,
> obtain the whole-row type OID and recursively check each Var in expression node
> to see if its vartype matches the whole-row type OID.

in v4, I use

+ TupleConstr *constr = RelationGetDescr(rel)->constr;
+
+ if (constr && constr->num_check > 0)
+{
+ systable_beginscan
+}
to check if a relation's check constraint expression contains a whole-row or
not. however this will have multiple systable_beginscan if multiple check
constraints contain wholerow expr.

I changed it to systable_beginscan pg_constraint once and check if the scan
returned pg_constraint tuple meets our condition or not.

and some minor adjustments to regression tests.

Attachment Content-Type Size
v5-0001-ALTER-TABLE-DROP-COLUMN-drop-wholerow-referenced-object.patch text/x-patch 11.5 KB
v5-0002-disallow-ALTER-COLUMN-SET-DATA-TYPE-when-wholerow-referenced-cons.patch text/x-patch 7.3 KB
v5-0003-disallow-change-or-drop-column-when-wholerow-referenced-policy-ex.patch text/x-patch 12.1 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-09-23 05:43:47 Re: [PATCH] Add tests for Bitmapset
Previous Message Alena Vinter 2025-09-23 05:04:04 Re: Resetting recovery target parameters in pg_createsubscriber