| From: | Manu <manuelreyesbravo(at)gmail(dot)com> |
|---|---|
| To: | Yilin Zhang <jiezhilove(at)126(dot)com> |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>, Nikhil Sontakke <nikhil(at)planetscale(dot)com>, Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Andres Freund <andres(at)anarazel(dot)de> |
| Subject: | Re: Reject columns of permanent relations that depend on temporary objects |
| Date: | 2026-12-01 00:49:42 |
| Message-ID: | 179608618290.482166.4214564363768781040@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Yilin,
Thanks for the review. You are right, and the attached v2 rejects
your case.
> The v1 patch fixes the direct temporary object path,
> but it does not fix the indirectly effectively-temporary function path.
v1 followed pg_depend only through types, and for anything else it
looked at the object's schema. eff_f() lives in public and is
temporary only through its dependency on eff_tt, so the walk never
went into it. My first mail was wrong to say that domains were all
covered.
v2 follows pg_depend from the column's type through objects of any
kind, the way the drop at session exit does. The new tests cover
your domain, an array of it, a range whose subtype_diff reads a
temporary table, its multirange, a composite type, a view used as a
type, and the row type of a table with a generated column that calls
an effectively temporary function.
Your CHECK variant does not lose data: at session exit only the
domain's constraint is dropped, because the constraint depends on the
domain and not the other way around. v2 follows dependencies
backwards only from an object to its internal parts, such as from a
view to its rule, and a domain's constraint is not one of those, so
v2 leaves that case out. It belongs with the CHECK constraints and
defaults of the second patch.
The wider walk costs more than v1, so I measured again. 1000 domain
columns still show no measurable difference, and a column of a
composite type nested 16 levels deep takes 1 to 2% longer (about
0.2 ms). The most expensive case I measured, a column whose domain
default calls a function whose SQL body reads 1000 permanent tables,
goes from 0.5 ms to 10.5 ms, about 10 microseconds per table the
function reads; the cost grows with the objects reachable from the
column's type. A column of a built-in type still costs no catalog
lookup in the check.
One thing my first mail did not say: the check runs whenever a
permanent relation is created, so it also applies to views and
materialized views. With the wider walk, v2 rejects two relations
that master keeps: a plain view and a materialized view, each with a
column of a composite type that loses an attribute at session exit.
The materialized view stores values of that type, so it is rejected
for the same reason as a table. A plain view stores no data, so if
skipping plain views is preferred, I can send a v3 that does that.
Regards,
Manu
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Reject-temporary-objects-in-columns-of-permanent-.patch | text/x-patch | 39.0 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | shihao zhong | 2026-12-01 01:01:01 | Re: [PATCH] Planner support function for generate_subscripts() |
| Previous Message | Haibo Yan | 2026-12-01 00:41:57 | Re: [PATCH v1 0/2] Preserve input sign across numeric parameter parsing |