Re: Proposal to introduce a shuffle function to intarray extension

From: Martin Kalcher <martin(dot)kalcher(at)aboutsource(dot)net>
To: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Proposal to introduce a shuffle function to intarray extension
Date: 2022-07-17 02:25:27
Message-ID: b8f44b53-02d6-0be4-42df-cb6f737e6267@aboutsource.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Am 16.07.22 um 23:56 schrieb Thomas Munro:
> On Fri, Jul 15, 2022 at 8:36 PM Martin Kalcher
> <martin(dot)kalcher(at)aboutsource(dot)net> wrote:
>> I would like to see a function like this inside the intarray extension.
>> Is there any way to get to this point? How is the process to deal with
>> such proposals?
>
> Hi Martin,
>
> I'm redirecting this to the pgsql-hackers@ mailing list, where we talk
> about code. For the archives, Martin's initial message to -general
> was:
>
> https://www.postgresql.org/message-id/9d160a44-7675-51e8-60cf-6d64b76db831%40aboutsource.net
>
> The first question is whether such a thing belongs in an external
> extension, or in the contrib/intarray module. The latter seems like a
> reasonable thing to want to me. The first step towards that will be
> to get your code into .patch format, as in git format-patch or git
> diff, that can be applied to the master branch.
>
> https://wiki.postgresql.org/wiki/Submitting_a_Patch
>
> Some initial feedback from me: I'd recommend adding a couple of
> comments to the code, like the algorithm name for someone who wants to
> read more about it (I think it's a Fisher-Yates shuffle?). You'll
> need to have the contrib/intarrays/intarray--1.5--1.6.sql file that
> creates the function. You might want to add something to
> control/intarray/sql/_int.sql that invokes the function when you run
> make check in there (but doesn't display the results, since that'd be
> unstable across machines?), just to have 'code coverage' (I mean, it'd
> prove it doesn't crash at least). Once details are settled, you'd
> also want to add documentation in doc/src/sgml/intarray.sgml. I
> understand that this is a specialised int[] shuffle, but I wonder if
> someone would ever want to have a general array shuffle, and how that
> would work, in terms of naming convention etc.

Hello Thomas,

Thank you for pointing me towards the correct list.

I do not feel qualified to answer the question wether this belongs in an
external extension or in contrib/intarray. That reason i would like to
see it in contrib/intarray is, that it is lot easier for me to get our
operations team to upgrade our database system, because of new features
we need, than to get them to install a self-maintained extension on our
database servers.

Thank you for your feedback. I tried to address all your points and made
a first patch. Some points are still open:

- Documentation is postponed until further feedback.

- I am not shure about the naming. intarray has generic names like
sort() and uniq() and specialised names like icount(). I guess in case
someone wants to have a general array shuffle it could be accomplished
with function overloading. Or am i wrong here?

- I added a second function sample(), because it is a lot faster to take
some elements from an array than to shuffle the whole array and
slice it. This function can be removed if it is not wanted. The
important one is shuffle().

Martin

Attachment Content-Type Size
0001-Introduce-shuffle-and-sample-to-intarray-extension.patch text/x-patch 7.8 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2022-07-17 03:18:29 Re: Proposal to introduce a shuffle function to intarray extension
Previous Message Thomas Munro 2022-07-16 21:56:27 Re: Proposal to introduce a shuffle function to intarray extension

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-07-17 03:18:29 Re: Proposal to introduce a shuffle function to intarray extension
Previous Message David G. Johnston 2022-07-16 23:50:28 Re: Move Section 9.27.7 (Data Object Management Functions) to System Information Chapter