Re: [PATCH] Introduce array_shuffle() and array_sample()

From: Martin Kalcher <martin(dot)kalcher(at)aboutsource(dot)net>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, John Naylor <john(dot)naylor(at)enterprisedb(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] Introduce array_shuffle() and array_sample()
Date: 2022-07-21 17:29:12
Message-ID: 89a4a463-0075-7f6c-e8e4-12a6e1d84eee@aboutsource.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Am 21.07.22 um 10:41 schrieb Dean Rasheed:
>
> It's important to mark these new functions as VOLATILE, not IMMUTABLE,
> otherwise they won't work as expected in queries. See
> https://www.postgresql.org/docs/current/xfunc-volatility.html
>
> It would be better to use pg_prng_uint64_range() rather than rand() to
> pick elements. Partly, that's because it uses a higher quality PRNG,
> with a larger internal state, and it ensures that the results are
> unbiased across the range. But more importantly, it interoperates with
> setseed(), allowing predictable sequences of "random" numbers to be
> generated -- something that's useful in writing repeatable regression
> tests.
>
> Assuming these new functions are made to interoperate with setseed(),
> which I think they should be, then they also need to be marked as
> PARALLEL RESTRICTED, rather than PARALLEL SAFE. See
> https://www.postgresql.org/docs/current/parallel-safety.html, which
> explains why setseed() and random() are parallel restricted.
>

Here is an updated patch that marks the functions VOLATILE PARALLEL
RESTRICTED and uses pg_prng_uint64_range() rather than rand().

Attachment Content-Type Size
0001-Introduce-array_shuffle-and-array_sample.patch text/x-patch 10.9 KB

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2022-07-21 17:49:33 Re: FK Constraint sort order with pg_dump
Previous Message Christian Barthel 2022-07-21 17:25:40 FK Constraint sort order with pg_dump

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2022-07-21 17:42:12 Re: Make name optional in CREATE STATISTICS
Previous Message Nathan Bossart 2022-07-21 17:27:26 Re: let's disallow ALTER ROLE bootstrap_superuser NOSUPERUSER