| From: | Nikhil Sontakke <nikhil(at)planetscale(dot)com> |
|---|---|
| To: | Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org, Manu <manuelreyesbravo(at)gmail(dot)com>, 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-18 14:27:51 |
| Message-ID: | CA+UBoq2H8hAu15o1Ezkt5ntJfcCi+Hd1dSYGo2FLs3UBbNuzqQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Zsolt,
Thanks for the review. v5 attached.
> This new check can cause temp tablespace cleanup to fail:
This needs a permanent composite type with an attribute of a temporary
type, stored in a permanent table, which is quite contrived, who'd do it?
:-D.
Still, internal deletions like temp namespace cleanup and autovacuum's
orphan
temp table removal must not fail, and the fix is small: v5 skips the
check for PERFORM_DELETION_INTERNAL deletions, so DISCARD TEMP, session
exit, ON COMMIT DROP and autovacuum behave as before.
> And even in the previous version, BEGIN ATOMIC functions using the row
> type now block DROP COLUMN, even with CASCADE:
Agreed, both are bugs. find_composite_type_dependencies() was written
for ALTER COLUMN TYPE, where any use of the type in a SQL body is a
problem. For a drop, only values of the type held in the body matter;
references to the type or its fields don't, and a use of the dropped
column is already a column dependency.
v5 adds find_composite_type_dependencies_for_drop(), which differs only
in that a function's argument defaults and SQL body block the drop just
if they contain a constant or ROW() constructor of the type. Your
example now behaves as on master: dropping an unused column works, and
dropping a used one gives the usual dependency error, or drops the
function with CASCADE. A body like SELECT '(1,2)'::t = '(1,3)'::t still
blocks it. Views and other expressions are unchanged, and already only
block for such values.
v5 also runs the check for every dropped column after all deletions,
instead of up front in ATExecDropColumn(), so that a function or view
holding such a value no longer blocks a drop whose CASCADE removes it.
The restriction is now documented under ALTER TABLE ... DROP COLUMN and
ALTER TYPE ... DROP ATTRIBUTE.
All of these, including a ROW() constructor in a SQL body, are in the
regression tests. Full meson suite passes on master; v5 also applies
cleanly to REL_18_STABLE.
Regards,
Nikhil
---
Nikhil Sontakke
PlanetScale
| Attachment | Content-Type | Size |
|---|---|---|
| v5-0001-Refuse-to-drop-a-column-whose-row-type-is-stored-.patch | application/octet-stream | 44.3 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | He Kuang | 2026-11-18 14:50:36 | [PATCH v2] Estimate hash join bucket size from the joint ndistinct of the hash keys |
| Previous Message | Alexander Korotkov | 2026-11-18 14:27:04 | Re: test: avoid redundant standby catchup in 049_wait_for_lsn |