Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oFWlx-0000u5-S4 for pgsql-hackers@arkaria.postgresql.org; Sun, 24 Jul 2022 08:15:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oFWlw-0005M1-0W for pgsql-hackers@arkaria.postgresql.org; Sun, 24 Jul 2022 08:15:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oFWlv-0005LS-N5 for pgsql-hackers@lists.postgresql.org; Sun, 24 Jul 2022 08:15:31 +0000 Received: from sfr-1.cri.mines-paristech.fr ([77.158.180.225] helo=smtp.cri.ensmp.fr) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oFWlp-0005PY-1N for pgsql-hackers@lists.postgresql.org; Sun, 24 Jul 2022 08:15:31 +0000 Received: from pseudo.home (lfbn-ren-1-1112-177.w92-139.abo.wanadoo.fr [92.139.62.177]) by smtp.cri.ensmp.fr (Postfix) with ESMTPSA id EF8A3C021B; Sun, 24 Jul 2022 10:19:20 +0200 (CEST) Date: Sun, 24 Jul 2022 10:15:22 +0200 (CEST) From: Fabien COELHO X-X-Sender: fabien@pseudo To: Martin Kalcher cc: Dean Rasheed , Tom Lane , Robert Haas , Andrew Dunstan , John Naylor , Thomas Munro , PostgreSQL Hackers Subject: Re: [PATCH] Introduce array_shuffle() and array_sample() In-Reply-To: <036ba529-1f25-d7b5-c5ad-e6c852d928df@aboutsource.net> Message-ID: References: <9d160a44-7675-51e8-60cf-6d64b76db831@aboutsource.net> <1708d95a-629e-5ac5-deab-d20a8d0b2b0e@aboutsource.net> <809171.1658176490@sss.pgh.pa.us> <817328.1658178181@sss.pgh.pa.us> <0b5dea2b-37fa-6c81-ea9d-0341ab6f87d6@aboutsource.net> <091a9f69-1e5d-6558-41a7-2607a5fc9ff7@aboutsource.net> <1064800.1658240423@sss.pgh.pa.us> <7e7cf274-09cb-00cf-1715-979f011e40b0@aboutsource.net> <459f6008-90bc-bc52-6f11-e68570e03ac0@aboutsource.net> <583b6409-df52-86d1-8c0a-ce8e74863ad7@aboutsource.net> <036ba529-1f25-d7b5-c5ad-e6c852d928df@aboutsource.net> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="2056645051-1371466737-1658647823=:1359119" Content-ID: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --2056645051-1371466737-1658647823=:1359119 Content-Type: text/plain; CHARSET=ISO-8859-15; format=flowed Content-Transfer-Encoding: 8BIT Content-ID: >> i came to the same conclusions and went with Option 1 (see patch). Mainly >> because most code in utils/adt is organized by type and this way it is >> clear, that this is a thin wrapper around pg_prng. >> > > Small patch update. I realized the new functions should live > array_userfuncs.c (rather than arrayfuncs.c), fixed some file headers and > added some comments to the code. My 0,02¤ about this patch: Use (void) when declaring no parameters in headers or in functions. Should the exchange be skipped when i == k? I do not see the point of having *only* inline functions in a c file. The external functions should not be inlined? The random and array shuffling functions share a common state. I'm wondering whether it should ot should not be so. It seems ok, but then ISTM that the documentation suggests implicitely that setseed applies to random() only, which is not the case anymore after the patch. If more samples are required than the number of elements, it does not error out. I'm wondering whether it should. Also, the sampling should not return its result in order when the number of elements required is the full array, ISTM that it should be shuffled there as well. I must say that without significant knowledge of the array internal implementation, the swap code looks pretty strange. ISTM that the code would be clearer if pointers and array references style were not intermixed. Maybe you could add a test with a 3D array? Some sample with NULLs? Unrelated: I notice again that (postgre)SQL does not provide a way to generate random integers. I do not see why not. Should we provide one? -- Fabien. --2056645051-1371466737-1658647823=:1359119--