| From: | Manu <manuelreyesbravo(at)gmail(dot)com> |
|---|---|
| To: | Nikhil Sontakke <nikhil(at)planetscale(dot)com> |
| Cc: | Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: Dropping a composite attribute causes data integrity violations |
| Date: | 2026-11-25 03:41:34 |
| Message-ID: | 179557809462.3908349.696595659685140848@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Nikhil,
Short version: with v5 the silent loss is back on every internal path.
I think the temporary case is better handled when the object is
created: refuse a permanent type or table that uses a temporary type,
as master already does for materialized views.
On Wed, Nov 18, 2026 at 7:57 PM Nikhil Sontakke
<nikhil(at)planetscale(dot)com> wrote:
> v5 skips the check for PERFORM_DELETION_INTERNAL deletions, so DISCARD
> TEMP, session exit, ON COMMIT DROP and autovacuum behave as before.
They do, and "as before" is the corruption. On master 93e2b79f5f6
with v5, take a permanent type ct whose attribute b is a temporary
type (a domain, or a temp table's row type), stored in a permanent
table t with UNIQUE (c). Session exit, DISCARD TEMP, DISCARD ALL, ON
COMMIT DROP and the orphan cleanup after a backend crash all drop b
without an error or a warning: t goes from (1,2),(1,3) to (1),(1),
and REINDEX fails on the duplicate.
It also undoes the explicit check. DROP TABLE tt CASCADE is refused
with "cannot alter type "ct" because column "t.c" uses it", but when
that same session disconnects, the drop happens anyway.
> 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?
Agreed, and that's why refusing it up front would cost little. Doing
the check during cleanup can't work either way: erroring there, as v4
did, left autovacuum failing on every naptime (a table in the same
database with 20,000 dead tuples wasn't vacuumed meanwhile) and made
the COMMIT of an ON COMMIT DROP transaction fail, and skipping it
brings the loss back.
Today master accepts both CREATE TYPE p AS (x tmp_tbl) and CREATE
TABLE perm (a int, c tmp_tbl) as permanent objects, with no notice,
and perm silently loses column c at session exit, no composite needed.
Materialized views already refuse this ("materialized views must not
use temporary objects").
To see how big that would be, I tried a flag for CheckAttributeType()
that refuses a temporary type in a permanent relation, set when
creating one and in ADD COLUMN and ALTER COLUMN TYPE: about 40 lines,
and make check, isolation and test_decoding still pass. Two traps:
getBaseType() skips intermediate domains, so a permanent domain over
a temporary one slips through unless each level is checked, and
bootstrap has no syscache. I can send it if you want to go that way.
One more thing, which v4 had too: DROP DOMAIN d CASCADE over 8000
tables, each with a column of d and a primary key, takes 1.1 s with v5
against 168 ms on master (median of 12 runs). For every relation,
find_missing_composite_type_dependencies() scans all of pg_index and
pg_partitioned_table.
Regards,
Manu
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Ayush Tiwari | 2026-11-25 03:49:15 | Re: Small cleanup of leftover pre-1.1.0 OpenSSL code |
| Previous Message | John Naylor | 2026-11-25 03:35:46 | Re: Should we skip foreign key checks in binary upgrade mode? |