Re: Dropping a composite attribute causes data integrity violations

From: Nikhil Sontakke <nikhil(at)planetscale(dot)com>
To: Manu <manuelreyesbravo(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: Dropping a composite attribute causes data integrity violations
Date: 2026-11-16 13:53:31
Message-ID: CA+UBoq1Ba0UB0fwj_6FRvfF1M6vKnqioepozcs1516sOfStW8g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Manu,

Thanks for testing/reproducing this. V4 attached.

> same-version run of 009 no longer upgrades a stored value whose dropped
> attribute held data, and

Fixed. When the server refuses the drop, 009 now keeps the datum in a
PL/pgSQL variable across the drop and stores it afterwards, so the
stored datum still holds the dropped attribute's data (29 bytes vs 25
for a fresh ROW(1)).

> compositetable_drop no longer drops the column
> during the UPDATE.
>

That can't happen to a stored value any more, so that test now checks
the refusal.

> My earlier patch is no longer needed for these cases, on master or on
> REL_18_STABLE. There the ten drops also go through without v3, and v3
> applies with git am and refuses the same ones.
>
>
v3 missed columns dropped by cascading from their datatype:

CREATE DOMAIN d AS int;
CREATE TYPE ct AS (a int, b d);
CREATE TABLE t (c ct UNIQUE);
INSERT INTO t VALUES (ROW(1,2)), (ROW(1,3));
DROP DOMAIN d CASCADE; -- accepted by v3; t now has duplicates

v4 checks such columns in deleteObjectsInList(), after all objects are
deleted, so that anything storing the row type that the same command
drops doesn't count. Checking in RemoveAttributeById() would wrongly
refuse e.g. DROP DOMAIN d CASCADE that also drops an older partitioned
table storing ct, since deletion goes in reverse OID order.

v4 also applies cleanly to REL_18_STABLE and passes there, tests
included. Again, whether to back-patch is the committers' decision.

Regards,
Nikhil
---
Nikhil Sontakke
PlanetScale

Attachment Content-Type Size
v4-0001-Refuse-to-drop-a-column-whose-row-type-is-stored-.patch application/octet-stream 38.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Joao Rito 2026-11-16 14:02:29 Re: [PATCH] Check interrupts while draining received WAL
Previous Message Bertrand Drouvot 2026-11-16 13:44:57 Re: Document prepared transaction lock waits with two_phase subscriptions