| From: | Henson Choi <assam258(at)gmail(dot)com> |
|---|---|
| To: | Sho Ito <i(dot)sho(dot)0628(at)gmail(dot)com> |
| Cc: | pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: [PATCH v1] Preserve implicit composite casts in ROW deparsing |
| Date: | 2026-11-16 07:09:40 |
| Message-ID: | CAAAe_zCay4ugRnS0Rnm0tZ5oUCtx1JcJid3fCxNACJtt1mti4w@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Sho,
> The stored call correctly refers to `pick(pair)`, but `pg_get_viewdef()`
> prints `pick(ROW(1, 2))` without `::pair`. On reparse, the `record`
> overload wins.
Thanks for the patch. It reproduces on master: the copied view
returns 2. With v1 it prints pick(ROW(1, 2)::pair) and returns 1,
and make check and the pg_upgrade test pass. Other implicit
coercions of function arguments are printed under showimplicit too,
so this looks like the right place for the fix to me; RowExpr was
the only one ignoring that flag.
I used AI to generate a range of cases, and the fix reaches further
than the examples in your mail. Named arguments, operators, aggregate
and window function arguments, GROUP BY and HAVING, whole-row
references to a subquery passed as a composite argument, BEGIN ATOMIC
bodies, and index and CHECK expressions all change results or fail to
restore on master, and are all right with v1. The strongest case is
VARIADIC, where a dump from master does not restore even without
adding an overload later:
CREATE TYPE pair AS (a int, b int);
CREATE FUNCTION pv(VARIADIC pair[]) RETURNS int
LANGUAGE sql AS 'SELECT 1';
CREATE VIEW vv AS SELECT pv(ROW(1, 2), ROW(3, 4)) AS r;
-- master: pv(VARIADIC ARRAY[ROW(1, 2), ROW(3, 4)]) AS r,
-- restore fails: function pv(record[]) does not exist
-- v1: pv(VARIADIC ARRAY[ROW(1, 2)::pair, ROW(3, 4)::pair]) AS r
It may be worth a test.
> The patch also updates existing `EXPLAIN` expectations that now show
> named-type casts.
The EXPLAIN hunks in the patch come from argument positions:
- the two in alter_table from get_func_expr(), which prints
function arguments with showimplicit = true
- the one in updatable_views from get_oper_expr(), which does the
same for operator arguments
To see whether they could be avoided, I passed false at those two
places only while deparsing a plan. The patch's hunks go away, but
the other implicit casts there are hidden too, so other plans change:
- function arguments: 19 lines in six other core regression files
and 3 in postgres_fdw, e.g. sin((two)::double precision) becomes
sin(two)
- operator arguments: 152 lines in 15 files and 13 in postgres_fdw,
e.g. (tenthous)::numeric = '1'::numeric becomes
tenthous = '1'::numeric
So the patch's EXPLAIN changes look like the smaller cost.
> I think this merits backpatching because it can silently change results
> after restore.
Agreed. I tried 15-19: there is only an easily fixed conflict, and no
code changes are needed:
- 19: applies as it is.
- 15-18: only the updatable_views.out hunk fails, as that test (ON
CONFLICT DO SELECT) exists from 19; dropping it is enough, and the
other expected output still matches.
- make check passes on all five branches, and the example from your
mail reproduces on all of them.
- EXPLAIN VERBOSE and pg_dump output change on the back branches
too.
In the tests, all the new cases are function arguments, so dropping
the showimplicit check still passes rowtypes. The case where
showimplicit is false would be pinned by a test like this:
CREATE TABLE rowtypes_deparse_def
(c rowtypes_deparse_a DEFAULT ROW(1, 2));
SELECT pg_get_expr(adbin, adrelid) FROM pg_attrdef
WHERE adrelid = 'rowtypes_deparse_def'::regclass;
-- ROW(1, 2), before and after the patch
The patch covers one case of CF 7452 [1]: a whole-row reference
coerced to an operator's composite input type. 7452 handles it in
the parser, but this patch fixes it in deparse, also for objects
already stored, so once this patch is committed I will drop that
part from 7452.
Best regards,
Henson
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Hayato Kuroda (Fujitsu) | 2026-11-16 07:22:18 | RE: Simplify parallel apply worker error reporting mechanism |
| Previous Message | Ayush Tiwari | 2026-11-16 06:50:10 | Re: 041_checkpoint_at_promote.pl might fail due to race condition on child kill |