Re: [PATCH] Introduce array_shuffle() and array_sample()
Martin Kalcher <martin.kalcher@aboutsource.net>
From: Martin Kalcher <martin.kalcher@aboutsource.net>
To: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Robert Haas <robertmhaas@gmail.com>,
Andrew Dunstan <andrew@dunslane.net>,
John Naylor <john.naylor@enterprisedb.com>,
Thomas Munro <thomas.munro@gmail.com>,
PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-07-21T17:29:12Z
Lists: pgsql-hackers, pgsql-general
Attachments
- 0001-Introduce-array_shuffle-and-array_sample.patch (text/x-patch) patch 0001
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().
Commits
-
Add array_sample() and array_shuffle() functions.
- 888f2ea0a81f 16.0 landed
-
Use a separate random seed for SQL random()/setseed() functions.
- 6645ad6bdd81 12.0 cited