Re: general purpose array_sort

Junwang Zhao <zhjwpku@gmail.com>

From: Junwang Zhao <zhjwpku@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: jian he <jian.universality@gmail.com>, Michael Paquier <michael@paquier.xyz>, Aleksander Alekseev <aleksander@timescale.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, "David G. Johnston" <david.g.johnston@gmail.com>, Amit Langote <amitlangote09@gmail.com>, "andreas@proxel.se" <andreas@proxel.se>, Robert Haas <robertmhaas@gmail.com>
Date: 2025-04-01T02:27:24Z
Lists: pgsql-hackers
On Tue, Apr 1, 2025 at 1:11 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Junwang Zhao <zhjwpku@gmail.com> writes:
> > On Mon, Mar 31, 2025 at 5:58 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >> In v18, it's somewhat annoying that the typcache doesn't cache
> >> the typarray field; we would not need a separate get_array_type()
> >> lookup if it did.  I doubt there is any real reason for that except
> >> that pg_type.typarray didn't exist when the typcache was invented.
> >> So I'm tempted to add it.  But I looked at existing callers of
> >> get_array_type() and none of them are adjacent to typcache lookups,
> >> so only array_sort would be helped immediately.  I left it alone
> >> for the moment; wonder if anyone else has an opinion?
>
> > The need for `elmtyp` and `array_type` here because a column can
> > have arrays with varying dimensions. Maybe other callers don't share
> > this behavior?
>
> Maybe.  I think some of what's going on here is that because for a
> long time we only had pg_type.typelem and not pg_type.typarray,
> code was written to not need to look up the array type if at all
> possible.  So there are simply not that many users.  Anyway it
> seems really cheap to add this field to the typcache now.
>
> Attached 0001 is the same as v18, and then 0002 is the proposed
> addition to typcache.

I've applied the patches to master and regression passed.

0002 is neat, I am +1 for this improvement.

>
>                         regards, tom lane
>


-- 
Regards
Junwang Zhao



Commits

  1. Introduce a SQL-callable function array_sort(anyarray).

  2. Fix ARRAY_SUBLINK and ARRAY[] for int2vector and oidvector input.

  3. Re-implement the ereport() macro using __VA_ARGS__.